Skip to content

Commit

Permalink
Fixed ioctl change for newer kernels > 3.13.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus-Go committed May 9, 2016
1 parent f1de8f2 commit 86db24e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
26 changes: 16 additions & 10 deletions nf-hishape.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ static unsigned int

static struct nf_hook_ops hishape_ops = {
.hook = hishape_hook,
.owner = THIS_MODULE,
//.owner = THIS_MODULE,
.pf = PF_INET,
.hooknum = NF_INET_FORWARD,
.priority = NF_IP_PRI_FIRST + 1
Expand All @@ -222,7 +222,7 @@ static int reserve(int n) {
if(statsNew != NULL)
vfree(statsNew);
printk(KERN_INFO "IOCTL_HISHAPE_SET_RANGES: memory allocation of %lu bytes failed :(\n",
n*sizeof(HiShapeRange) + n*sizeof(HiShapeStat));
(long unsigned int)(n*sizeof(HiShapeRange) + n*sizeof(HiShapeStat)));
return ENOMEM;
}
}
Expand Down Expand Up @@ -258,8 +258,11 @@ static int device_release(struct inode *inode, struct file *file) {
module_put(THIS_MODULE);
return SUCCESS;
}

int device_ioctl(struct inode *inode, struct file *file, unsigned int ioctl_num, unsigned long ioctl_param) {
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35))
int device_ioctl(struct inode *inode, struct file *file, unsigned int ioctl_num, unsigned long ioctl_param) {
#else
long device_ioctl(struct file *f, unsigned int ioctl_num, unsigned long ioctl_param) {
#endif
int i;
int returnValue = SUCCESS;
#ifdef DEBUG
Expand Down Expand Up @@ -350,8 +353,11 @@ int device_ioctl(struct inode *inode, struct file *file, unsigned int ioctl_num,
struct file_operations ops = {
.read = NULL,
.write = NULL,
//.ioctl = device_ioctl,
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35))
.ioctl = device_ioctl,
#else
.unlocked_ioctl = device_ioctl,
#endif
.open = device_open,
.release = device_release,
};
Expand All @@ -363,15 +369,15 @@ int init_module(void) {

// -- determine hook num --
if(hook != NULL) {
if(!strnicmp(hook,"pre",3))
if(!strncasecmp(hook,"pre",3))
hishape_ops.hooknum = NF_INET_PRE_ROUTING;
else if(!strnicmp(hook,"in",2))
else if(!strncasecmp(hook,"in",2))
hishape_ops.hooknum = NF_INET_LOCAL_IN;
else if(!strnicmp(hook,"for",3))
else if(!strncasecmp(hook,"for",3))
hishape_ops.hooknum = NF_INET_FORWARD;
else if(!strnicmp(hook,"post",4))
else if(!strncasecmp(hook,"post",4))
hishape_ops.hooknum = NF_INET_POST_ROUTING;
else if(!strnicmp(hook,"out",3))
else if(!strncasecmp(hook,"out",3))
hishape_ops.hooknum = NF_INET_LOCAL_OUT;
else
printk(KERN_INFO "Unknown hook: %s, using NF_INET_FORWARD\n", hook);
Expand Down
5 changes: 5 additions & 0 deletions nf-hishape.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,17 @@
//#include <linux/time.h>
//#include <linux/spinlock.h>
#include <linux/param.h>
#include <linux/version.h>

#define MAJOR_NUM 100
#define RAND_MAX_VALUE 255
#define N_RAND 1000
#define MAX_DEVICE_LENGTH 256

#if LINUX_VERSION_CODE < KERNEL_VERSION(4,0,0)
#define strncasecmp strnicmp
#endif

// 250 - 4
// 500 - 2

Expand Down

0 comments on commit 86db24e

Please sign in to comment.