Patch for geoip to make it work with Linux kernel 2.6.22.x
A message that is not in the archive (sent off-list or not yet received): [email protected]
Hi,
After upgrading to kernel 2.6.22, I found that the geoip patchlet did not compile. I have made a patch that works on my system with kernel 2.6.22.
The patch is against geoip match as of Dec 6th 2006 from http://people.netfilter.org/peejix/patchlets/
I made a patch for kernel 2.6.21 as well, but it has not been applied to the official geoip patchlet, and is therefor included in this patch.
You can download the patch by using the following URL:
http://bjerkeset.com/patches/geoip-match-2.6.22.patch.gz
Regards
Svein Olav Bjerkeset,
Quoted 24 lines · Svein Olav Bjerkeset
After upgrading to kernel 2.6.22, I found that the geoip patchlet did not compile.
I have made a patch that works on my system with kernel 2.6.22. [...]
You can download the patch by using the following URL:
http://bjerkeset.com/patches/geoip-match-2.6.22.patch.gzdiff -urN
geoip-20061206/linux-2.6/net/ipv4/netfilter/ipt_geoip.cgeoip/linux-2.6/net/ipv4/netfilter/ipt_geoip.clinux-2.6/net/ipv4/netfilter/ipt_geoip.c +4
-0@@ -110,7 +110,11 @@ {const struct ipt_geoip_info *info = matchinfo;const struct geoip_info *node;/* This keeps the code sexy */ +#if LINUX_VERSION_CODE >=KERNEL_VERSION (2 ,6 ,22 ) +const struct iphdr *iph =ip_hdr (skb); +#else const struct iphdr *iph = skb->nh.iph; +#endif u_int32_t ip, j;u_int8_t i;
linux-2.6/net/ipv4/netfilter/ipt_geoip.c line 282
Quoted 3 lines
linux-2.6/net/ipv4/netfilter/ipt_geoip.c +0
-0@@ -276,7 +280,10 @@ }static struct ipt_match geoip_match = {
ipt_match is not defined anymore, and hence should have thrown a compile error right away.
linux-2.6/net/ipv4/netfilter/ipt_geoip.c line 286
Quoted 5 lines
linux-2.6/net/ipv4/netfilter/ipt_geoip.c +4
-1- .name = "geoip", + .name = "geoip", +#if LINUX_VERSION_CODE >=KERNEL_VERSION (2 ,6 ,21 ) + .family = AF_INET, +#endif
.family and is required when using xt_register_match. xt_register_match exists since at least 2.6.18.
Quoted 14 lines
linux-2.6/net/ipv4/netfilter/ipt_geoip.c +4
-0.match = &match,#if LINUX_VERSION_CODE >=KERNEL_VERSION (2 ,6 ,17 ) .matchsize = sizeof (struct ipt_geoip_info),@@ -288,12 +295,20 @@static int __init init (void ) { +#if LINUX_VERSION_CODE >=KERNEL_VERSION (2 ,6 ,21 ) +return xt_register_match (&geoip_match); +#else return ipt_register_match (&geoip_match); +#endif }
linux-2.6/net/ipv4/netfilter/ipt_geoip.c line 314
Quoted 10 lines
linux-2.6/net/ipv4/netfilter/ipt_geoip.c +4
-0static void __exit fini(void) { +#if LINUX_VERSION_CODE >=KERNEL_VERSION (2 ,6 ,21 ) +xt_unregister_match (&geoip_match); +#else ipt_unregister_match (&geoip_match); +#endif return ; }
Jan
Hi,
In the kernel (2.6.22) I downloaded from www.kernel.org yesterday, ipt_match is certainly defined:
highbury:/opt/kernel> grep ipt_match linux-2.6.22/include/linux/netfilter_ipv4/ip_tables.h #define ipt_match xt_match
Whether the code should use xt_match directly instead of ipt_match, is another matter. I have just made the changes needed to get the patchlet to compile and work. I do not know the netfilter or geoip code well enough to tidy up the code in general. Maybe Samuel can comment on this issue?
As for xt_register_match, it may have existed before 2.6.21, but as far as I can recall, it was not until 2.6.21 that ipt_register_match was removed, and geoip match compiled/worked with ipt_register_match until 2.6.21. I did not quite understand what you were saying about .family and xt_register_match?
Regards,
Svein Olav Bjerkeset
----- Original Message ----- From: "Jan Engelhardt" <[email protected]>
To: "Svein Olav Bjerkeset" <[email protected]>
Cc: <[email protected]>; <[email protected]>
Sent: Tuesday, July 10, 2007 6:58 PM
Subject: Re: Patch for geoip to make it work with Linux kernel 2.6.22.x
Quoted 74 lines · Svein Olav Bjerkeset
Quoted 26 lines
After upgrading to kernel 2.6.22, I found that the geoip patchlet did not compile.
I have made a patch that works on my system with kernel 2.6.22. [...]
You can download the patch by using the following URL:
http://bjerkeset.com/patches/geoip-match-2.6.22.patch.gzdiff -urN
geoip-20061206/linux-2.6/net/ipv4/netfilter/ipt_geoip.cgeoip/linux-2.6/net/ipv4/netfilter/ipt_geoip.c---geoip-20061206/linux-2.6/net/ipv4/netfilter/ipt_geoip.c2006-12-06
03:47:46.000000000 +0100
+++geoip/linux-2.6/net/ipv4/netfilter/ipt_geoip.c2007-07-10
17:17:11.599991698 +0200(quoted diff) +4
-0@@ -110,7 +110,11 @@ { const struct ipt_geoip_info *info = matchinfo; const struct geoip_info *node; /* This keeps the code sexy */ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22) + const struct iphdr *iph = ip_hdr(skb); +#else const struct iphdr *iph = skb->nh.iph; +#endif u_int32_t ip, j; u_int8_t i;Review line 282
Quoted 3 lines
(quoted diff) +0
-0@@ -276,7 +280,10 @@ } static struct ipt_match geoip_match = {
ipt_matchis not defined anymore, and hence should have thrown a compile error right away.Review line 286
Quoted 5 lines
(quoted diff) +4
-1- .name = "geoip", + .name = "geoip", +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21) + .family = AF_INET, +#endif.family and is required when using
xt_register_match.xt_register_matchexists since at least 2.6.18.Quoted 14 lines
(quoted diff) +4
-0.match = &match, #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17) .matchsize = sizeof (struct ipt_geoip_info),@@ -288,12 +295,20 @@ static int __init init(void) { +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21) + return xt_register_match(&geoip_match); +#else return ipt_register_match(&geoip_match); +#endif }Review line 314
Quoted 10 lines
(quoted diff) +4
-0static void __exit fini(void) { +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21) + xt_unregister_match(&geoip_match); +#else ipt_unregister_match(&geoip_match); +#endif return; }Jan
Quoted 5 lines · Svein Olav Bjerkeset
As for
xt_register_match, it may have existed before 2.6.21, but as far as I can recall, it was not until 2.6.21 thatipt_register_matchwas removed, and geoip match compiled/worked withipt_register_matchuntil 2.6.21. I did not quite understand what you were saying about .family andxt_register_match?
'was saying that when using xt_register_match(), you _do_ need the ".family" member in xt_match, because this is what ipt_register_match is:
#define ipt_register_match(x) \
do { \
(x)->family = AF_INET; \
xt_register_match(x); \
} while (0);
JanHi,
Just wanted to repost that there is a userspace daemon for this too..
http://bladerunner.mine.nu/CJ/
So if there is a bug in the code only the daemon fails and not the entire kernel.. =)
It also eliminates the issues with kernel-revision incompatibility and should make it easier for people to setup. Have not really had any time lately to work anything on this, but current release seems to be stable and has a current uptime of around a month (my last reboot of that system).
Just don't laugh to much when reading the code... LOTS of really ugly code, but it works.. :)
/Patric
Quoted 77 lines · Jan Engelhardt
Quoted 25 lines · Svein Olav Bjerkeset
After upgrading to kernel 2.6.22, I found that the geoip patchlet did not compile.
I have made a patch that works on my system with kernel 2.6.22. [...]
You can download the patch by using the following URL:
http://bjerkeset.com/patches/geoip-match-2.6.22.patch.gzdiff -urN
geoip-20061206/linux-2.6/net/ipv4/netfilter/ipt_geoip.cgeoip/linux-2.6/net/ipv4/netfilter/ipt_geoip.clinux-2.6/net/ipv4/netfilter/ipt_geoip.c +4
-0@@ -110,7 +110,11 @@ {const struct ipt_geoip_info *info = matchinfo;const struct geoip_info *node;/* This keeps the code sexy */ +#if LINUX_VERSION_CODE >=KERNEL_VERSION (2 ,6 ,22 ) +const struct iphdr *iph =ip_hdr (skb); +#else const struct iphdr *iph = skb->nh.iph; +#endif u_int32_t ip, j;u_int8_t i;linux-2.6/net/ipv4/netfilter/ipt_geoip.c line 283
Quoted 4 lines
linux-2.6/net/ipv4/netfilter/ipt_geoip.c +0
-0@@ -276,7 +280,10 @@ }static struct ipt_match geoip_match = {
ipt_matchis not defined anymore, and hence should have thrown a compile error right away.linux-2.6/net/ipv4/netfilter/ipt_geoip.c line 288
Quoted 6 lines
linux-2.6/net/ipv4/netfilter/ipt_geoip.c +4
-1- .name = "geoip", + .name = "geoip", +#if LINUX_VERSION_CODE >=KERNEL_VERSION (2 ,6 ,21 ) + .family = AF_INET, +#endif .family and is required when using
xt_register_match.xt_register_matchexists since at least 2.6.18.Quoted 15 lines
linux-2.6/net/ipv4/netfilter/ipt_geoip.c +0
-0.match = &match,#if
LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,17)
.matchsize = sizeof (structipt_geoip_info),linux-2.6/net/ipv4/netfilter/ipt_geoip.c +4
-0@@ -288,12 +295,20 @@static int __init init (void ) { +#if LINUX_VERSION_CODE >=KERNEL_VERSION (2 ,6 ,21 ) +return xt_register_match (&geoip_match); +#else return ipt_register_match (&geoip_match); +#endif }linux-2.6/net/ipv4/netfilter/ipt_geoip.c line 314
Quoted 10 lines
linux-2.6/net/ipv4/netfilter/ipt_geoip.c +4
-0static void __exit fini(void) { +#if LINUX_VERSION_CODE >=KERNEL_VERSION (2 ,6 ,21 ) +xt_unregister_match (&geoip_match); +#else ipt_unregister_match (&geoip_match); +#endif return ; }Jan
Quoted 10 lines · patric
Just wanted to repost that there is a userspace daemon for this too..
http://bladerunner.mine.nu/CJ/
So if there is a bug in the code only the daemon fails and not the entire kernel.. =)
It also eliminates the issues with kernel-revision incompatibility and should make it easier for people to setup.
As far as I know you can only have one NFQUEUE userspace program at a time.
Quoted 8 lines
Have not really had any time lately to
work anything on this, but current release seems to be stable and has a current uptime of around a month (my last reboot of that system).Just don't laugh to much when reading the code... LOTS of really ugly code, but it works.. :)
Jan
Yea, that's true as far as i know too.... And that's one con with this...
/Patric
Quoted 28 lines · Jan Engelhardt
Quoted 10 lines · patric
Just wanted to repost that there is a userspace daemon for this too..
http://bladerunner.mine.nu/CJ/
So if there is a bug in the code only the daemon fails and not the entire kernel.. =)
It also eliminates the issues with kernel-revision incompatibility and should make it easier for people to setup.
As far as I know you can only have one NFQUEUE userspace program at a time.
Quoted 9 lines
Have not really had any time lately to
work anything on this, but current release seems to be stable and has a current uptime of around a month (my last reboot of that system).Just don't laugh to much when reading the code... LOTS of really ugly code, but it works.. :)
Jan
Or... just did some research on this, and there is a possibility for multiple queues...
----------------------------------------------------
NFQUEUE target
The NFQUEUE target is used much the same way as the QUEUE target, and is basically an extension of it. The NFQUEUE target allows for sending packets for separate and specific queues. The queue is identified by a 16-bit id.
This target requires the nfnetlink_queue kernel support to run. For more information on what you can do with the NFQUEUE target, see the QUEUE target.
Table 11-12. NFQUEUE target options
Option --queue-num
Example iptables -t nat -A PREROUTING -p tcp --dport 80 -j NFQUEUE --queue-num 30
Explanation The --queue-num option specifies which queue to use and to send the queue'd data to. If this option is skipped, the default queue 0 is used. The queue number is a 16 bit unsigned integer, which means it can take any value between 0 and 65535. The default 0 queue is also used by the QUEUE target.
* Works under Linux kernel 2.6.14 and later.
---------------------------------------------------
So i think it's time to update the kernel and do some mods on my code :)
/Patric
Quoted 39 lines · patric
Yea, that's true as far as i know too.... And that's one con with this...
/Patric
Quoted 28 lines · Jan Engelhardt
Quoted 10 lines · patric
Just wanted to repost that there is a userspace daemon for this too..
http://bladerunner.mine.nu/CJ/
So if there is a bug in the code only the daemon fails and not the entire kernel.. =)
It also eliminates the issues with kernel-revision incompatibility and should make it easier for people to setup.
As far as I know you can only have one NFQUEUE userspace program at a time.
Quoted 9 lines
Have not really had any time lately to
work anything on this, but current release seems to be stable and has a current uptime of around a month (my last reboot of that system).Just don't laugh to much when reading the code... LOTS of really ugly code, but it works.. :)
Jan
Quoted 2 lines · Svein Olav Bjerkeset
I made a patch for kernel 2.6.21 as well, but it has not been applied to the official geoip patchlet, and is therefor included in this patch.
I am sorry for that, Svein. I merged your patch with my local SVN geoip version but I had some compiler errors (not related with your patch).
I've got no time to debug, fix, test and release it yet.
Quoted 2 lines
You can download the patch by using the following URL:
http://bjerkeset.com/patches/geoip-match-2.6.22.patch.gz
Thank you!
Regards,
Samuel