Skip to contentSkip to conversation

New netfilter match module : kernel patch

RFC Alex Davis 3 participants 4 messages Jun 2, 2006 – Jun 21, 2006

Subsystems (2)
lore
Share & tools
lore

Alex Davis

author
#0 lore raw

This is an update the kernel netfilter patch that allows matching the source or destination address of an IP packet to a network interface.

Instead of hard-coding the dimension of the ifname struct member, use the IFNAMSIZ macro.

diff -u -Pr linux-2.6.16.16/include/linux/netfilter/xt_ipisforif.h linux-2.6.16.16-ipisforif/include/linux/netfilter/xt_ipisforif.h
--- linux-2.6.16.16/include/linux/netfilter/xt_ipisforif.h 1969-12-31 19:00:00.000000000 -0500
+++ linux-2.6.16.16-ipisforif/include/linux/netfilter/xt_ipisforif.h 2006-06-02 10:18:22.000000000
-0400
@@ -0,0 +1,15 @@
+#ifndef _XT_IPISFORIF_H
+#define _XT_IPISFORIF_H
+
+#include <linux/if.h>
+
+#define TYPE_SRC 1
+#define TYPE_DST 2
+
+struct xt_ipisforif_info {
+ int type;
+ int invert;
+ char ifname[IFNAMSIZ];
+};
+
+#endif /*_XT_IPISFORIF_H*/
diff -u -Pr linux-2.6.16.16/include/linux/netfilter_ipv4/ipt_ipisforif.h linux-2.6.16.16-ipisforif/include/linux/netfilter_ipv4/ipt_ipisforif.h
--- linux-2.6.16.16/include/linux/netfilter_ipv4/ipt_ipisforif.h 1969-12-31 19:00:00.000000000
-0500
+++ linux-2.6.16.16-ipisforif/include/linux/netfilter_ipv4/ipt_ipisforif.h 2006-05-30
02:20:06.000000000 -0400
@@ -0,0 +1,9 @@
+#ifndef _IPT_IPISFORIF_H
+#define _IPT_IPISFORIF_H
+#include <linux/netfilter/xt_ipisforif.h>
+
+/* Backwards compatibility for old userspace */
+
+#define ipt_ipisforif_info xt_ipisforif_info
+
+#endif /*_IPT_IPISFORIF_H*/

net/netfilter/Kconfig +9 -0
diff -u -Pr linux-2.6.16.16/net/netfilter/Kconfig linux-2.6.16.16-ipisforif/net/netfilter/Kconfig
@@ -336,6 +336,15 @@
 
 	  To compile it as a module, choose M here.  If unsure, say N.
 
+config NETFILTER_XT_MATCH_IPISFORIF
+	tristate '"interface ip" match support'
+	depends on NETFILTER_XTABLES
+	help
+	  This matches the source or destination IP address of a packet
+	  against the local address of a network interface.
+
+	  To compile it as a module, choose M here.  If unsure, say N.
+
 config NETFILTER_XT_MATCH_STRING
 	tristate  '"string" match support'
 	depends on NETFILTER_XTABLES

diff -u -Pr linux-2.6.16.16/net/netfilter/Makefile linux-2.6.16.16-ipisforif/net/netfilter/Makefile

net/netfilter/Makefile +1 -0
@@ -47,3 +47,4 @@
 obj-$(CONFIG_NETFILTER_XT_MATCH_STRING) += xt_string.o
 obj-$(CONFIG_NETFILTER_XT_MATCH_TCPMSS) += xt_tcpmss.o
 obj-$(CONFIG_NETFILTER_XT_MATCH_PHYSDEV) += xt_physdev.o
+obj-$(CONFIG_NETFILTER_XT_MATCH_IPISFORIF) += xt_ipisforif.o

diff -u -Pr linux-2.6.16.16/net/netfilter/xt_ipisforif.c linux-2.6.16.16-ipisforif/net/netfilter/xt_ipisforif.c

net/netfilter/xt_ipisforif.c +106 -0

106 lines not on this page · raw message

I code, therefore I am

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

#1 lore raw
Quoted 3 lines · Alex Davis

This is an update the kernel netfilter patch that allows matching the source or destination address of an IP packet to a network interface.

I can't see any other way to do this, but I'm not so thrilled to add a whole new match just for this. It's not a perfect match, but how about adding this as an option to the addrtype match for RTN_LOCAL addresses?

Better suggestions where we can put this are welcome.

#2 lore raw
Quoted 7 lines · Patrick McHardy
Quoted 3 lines · Alex Davis

This is an update the kernel netfilter patch that allows matching the source or destination address of an IP packet to a network interface.

I can't see any other way to do this, but I'm not so thrilled to add a whole new match just for this.

My current solution for this is to reinstall the iptables rules from the dhcp client script hooks, or from the ppp ip-up script.

Another option that doesn't require reinstalling rules would be to use an ipset in the rule, and then use the scripts to update the address in the ipset.

author
#3 lore raw
Quoted 6 lines · --- Philip Craig
Quoted 5 lines · Patrick McHardy
Quoted 3 lines · Alex Davis

This is an update the kernel netfilter patch that allows matching the source or destination address of an IP packet to a network interface.

Quoted 7 lines
Quoted 2 lines

I can't see any other way to do this, but I'm not so thrilled to add a whole new match just for this.

My current solution for this is to reinstall the iptables rules from the dhcp client script hooks, or from the ppp ip-up script.

I had thought about that, but I think this new match is a cleaner way to accomplish it.

Quoted 3 lines

Another option that doesn't require reinstalling rules would be to use an ipset in the rule, and then use the scripts to update the address in the ipset.

Hadn't thought about that, but still.....

I code, therefore I am

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com