diff options
| author | Yasuyuki Kozakai <yasuyuki.kozakai@toshiba.co.jp> | 2006-04-01 05:22:54 -0500 |
|---|---|---|
| committer | David S. Miller <davem@davemloft.net> | 2006-04-01 05:22:54 -0500 |
| commit | a89ecb6a2ef732d04058d87801e2b6bd7e5c7089 (patch) | |
| tree | c84c5b3167c116f0c419a2bbb04877bdac38dd07 | |
| parent | dc5ab2faece3b7473931357db7f63f596678481d (diff) | |
[NETFILTER]: x_tables: unify IPv4/IPv6 multiport match
This unifies ipt_multiport and ip6t_multiport to xt_multiport.
As a result, this addes support for inversion and port range match
to IPv6 packets.
Signed-off-by: Yasuyuki Kozakai <yasuyuki.kozakai@toshiba.co.jp>
Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
| -rw-r--r-- | include/linux/netfilter/xt_multiport.h | 30 | ||||
| -rw-r--r-- | include/linux/netfilter_ipv4/ipt_multiport.h | 31 | ||||
| -rw-r--r-- | include/linux/netfilter_ipv6/ip6t_multiport.h | 25 | ||||
| -rw-r--r-- | net/ipv4/netfilter/Kconfig | 10 | ||||
| -rw-r--r-- | net/ipv4/netfilter/Makefile | 1 | ||||
| -rw-r--r-- | net/ipv4/netfilter/ipt_multiport.c | 195 | ||||
| -rw-r--r-- | net/ipv6/netfilter/Kconfig | 10 | ||||
| -rw-r--r-- | net/ipv6/netfilter/Makefile | 1 | ||||
| -rw-r--r-- | net/ipv6/netfilter/ip6t_multiport.c | 125 | ||||
| -rw-r--r-- | net/netfilter/Kconfig | 10 | ||||
| -rw-r--r-- | net/netfilter/Makefile | 1 | ||||
| -rw-r--r-- | net/netfilter/xt_multiport.c | 314 |
12 files changed, 372 insertions, 381 deletions
diff --git a/include/linux/netfilter/xt_multiport.h b/include/linux/netfilter/xt_multiport.h new file mode 100644 index 0000000000..d49ee41837 --- /dev/null +++ b/include/linux/netfilter/xt_multiport.h | |||
| @@ -0,0 +1,30 @@ | |||
| 1 | #ifndef _XT_MULTIPORT_H | ||
| 2 | #define _XT_MULTIPORT_H | ||
| 3 | |||
| 4 | enum xt_multiport_flags | ||
| 5 | { | ||
| 6 | XT_MULTIPORT_SOURCE, | ||
| 7 | XT_MULTIPORT_DESTINATION, | ||
| 8 | XT_MULTIPORT_EITHER | ||
| 9 | }; | ||
| 10 | |||
| 11 | #define XT_MULTI_PORTS 15 | ||
| 12 | |||
| 13 | /* Must fit inside union xt_matchinfo: 16 bytes */ | ||
| 14 | struct xt_multiport | ||
| 15 | { | ||
| 16 | u_int8_t flags; /* Type of comparison */ | ||
| 17 | u_int8_t count; /* Number of ports */ | ||
| 18 | u_int16_t ports[XT_MULTI_PORTS]; /* Ports */ | ||
| 19 | }; | ||
| 20 | |||
| 21 | struct xt_multiport_v1 | ||
| 22 | { | ||
| 23 | u_int8_t flags; /* Type of comparison */ | ||
| 24 | u_int8_t count; /* Number of ports */ | ||
| 25 | u_int16_t ports[XT_MULTI_PORTS]; /* Ports */ | ||
| 26 | u_int8_t pflags[XT_MULTI_PORTS]; /* Port flags */ | ||
| 27 | u_int8_t invert; /* Invert flag */ | ||
| 28 | }; | ||
| 29 | |||
| 30 | #endif /*_XT_MULTIPORT_H*/ | ||
diff --git a/include/linux/netfilter_ipv4/ipt_multiport.h b/include/linux/netfilter_ipv4/ipt_multiport.h index e6b6fff811..55fe85eca8 100644 --- a/include/linux/netfilter_ipv4/ipt_multiport.h +++ b/include/linux/netfilter_ipv4/ipt_multiport.h | |||
| @@ -1,30 +1,15 @@ | |||
| 1 | #ifndef _IPT_MULTIPORT_H | 1 | #ifndef _IPT_MULTIPORT_H |
| 2 | #define _IPT_MULTIPORT_H | 2 | #define _IPT_MULTIPORT_H |
| 3 | #include <linux/netfilter_ipv4/ip_tables.h> | ||
| 4 | 3 | ||
| 5 | enum ipt_multiport_flags | 4 | #include <linux/netfilter/xt_multiport.h> |
| 6 | { | ||
| 7 | IPT_MULTIPORT_SOURCE, | ||
| 8 | IPT_MULTIPORT_DESTINATION, | ||
| 9 | IPT_MULTIPORT_EITHER | ||
| 10 | }; | ||
| 11 | 5 | ||
| 12 | #define IPT_MULTI_PORTS 15 | 6 | #define IPT_MULTIPORT_SOURCE XT_MULTIPORT_SOURCE |
| 7 | #define IPT_MULTIPORT_DESTINATION XT_MULTIPORT_DESTINATION | ||
| 8 | #define IPT_MULTIPORT_EITHER XT_MULTIPORT_EITHER | ||
| 13 | 9 | ||
| 14 | /* Must fit inside union ipt_matchinfo: 16 bytes */ | 10 | #define IPT_MULTI_PORTS XT_MULTI_PORTS |
| 15 | struct ipt_multiport | 11 | |
| 16 | { | 12 | #define ipt_multiport xt_multiport |
| 17 | u_int8_t flags; /* Type of comparison */ | 13 | #define ipt_multiport_v1 xt_multiport_v1 |
| 18 | u_int8_t count; /* Number of ports */ | ||
| 19 | u_int16_t ports[IPT_MULTI_PORTS]; /* Ports */ | ||
| 20 | }; | ||
| 21 | 14 | ||
| 22 | struct ipt_multiport_v1 | ||
| 23 | { | ||
| 24 | u_int8_t flags; /* Type of comparison */ | ||
| 25 | u_int8_t count; /* Number of ports */ | ||
| 26 | u_int16_t ports[IPT_MULTI_PORTS]; /* Ports */ | ||
| 27 | u_int8_t pflags[IPT_MULTI_PORTS]; /* Port flags */ | ||
| 28 | u_int8_t invert; /* Invert flag */ | ||
| 29 | }; | ||
| 30 | #endif /*_IPT_MULTIPORT_H*/ | 15 | #endif /*_IPT_MULTIPORT_H*/ |
diff --git a/include/linux/netfilter_ipv6/ip6t_multiport.h b/include/linux/netfilter_ipv6/ip6t_multiport.h index efe4954a86..042c92661c 100644 --- a/include/linux/netfilter_ipv6/ip6t_multiport.h +++ b/include/linux/netfilter_ipv6/ip6t_multiport.h | |||
| @@ -1,21 +1,14 @@ | |||
| 1 | #ifndef _IP6T_MULTIPORT_H | 1 | #ifndef _IP6T_MULTIPORT_H |
| 2 | #define _IP6T_MULTIPORT_H | 2 | #define _IP6T_MULTIPORT_H |
| 3 | #include <linux/netfilter_ipv6/ip6_tables.h> | ||
| 4 | 3 | ||
| 5 | enum ip6t_multiport_flags | 4 | #include <linux/netfilter/xt_multiport.h> |
| 6 | { | ||
| 7 | IP6T_MULTIPORT_SOURCE, | ||
| 8 | IP6T_MULTIPORT_DESTINATION, | ||
| 9 | IP6T_MULTIPORT_EITHER | ||
| 10 | }; | ||
| 11 | 5 | ||
| 12 | #define IP6T_MULTI_PORTS 15 | 6 | #define IP6T_MULTIPORT_SOURCE XT_MULTIPORT_SOURCE |
| 7 | #define IP6T_MULTIPORT_DESTINATION XT_MULTIPORT_DESTINATION | ||
| 8 | #define IP6T_MULTIPORT_EITHER XT_MULTIPORT_EITHER | ||
| 13 | 9 | ||
| 14 | /* Must fit inside union ip6t_matchinfo: 16 bytes */ | 10 | #define IP6T_MULTI_PORTS XT_MULTI_PORTS |
| 15 | struct ip6t_multiport | 11 | |
| 16 | { | 12 | #define ip6t_multiport xt_multiport |
| 17 | u_int8_t flags; /* Type of comparison */ | 13 | |
| 18 | u_int8_t count; /* Number of ports */ | 14 | #endif /*_IP6T_MULTIPORT_H*/ |
| 19 | u_int16_t ports[IP6T_MULTI_PORTS]; /* Ports */ | ||
| 20 | }; | ||
| 21 | #endif /*_IPT_MULTIPORT_H*/ | ||
diff --git a/net/ipv4/netfilter/Kconfig b/net/ipv4/netfilter/Kconfig index ebbd644fa8..77855ccd6b 100644 --- a/net/ipv4/netfilter/Kconfig +++ b/net/ipv4/netfilter/Kconfig | |||
| @@ -221,16 +221,6 @@ config IP_NF_MATCH_IPRANGE | |||
| 221 | 221 | ||
| 222 | To compile it as a module, choose M here. If unsure, say N. | 222 | To compile it as a module, choose M here. If unsure, say N. |
| 223 | 223 | ||
| 224 | config IP_NF_MATCH_MULTIPORT | ||
| 225 | tristate "Multiple port match support" | ||
| 226 | depends on IP_NF_IPTABLES | ||
| 227 | help | ||
| 228 | Multiport matching allows you to match TCP or UDP packets based on | ||
| 229 | a series of source or destination ports: normally a rule can only | ||
| 230 | match a single range of ports. | ||
| 231 | |||
| 232 | To compile it as a module, choose M here. If unsure, say N. | ||
| 233 | |||
| 234 | config IP_NF_MATCH_TOS | 224 | config IP_NF_MATCH_TOS |
| 235 | tristate "TOS match support" | 225 | tristate "TOS match support" |
| 236 | depends on IP_NF_IPTABLES | 226 | depends on IP_NF_IPTABLES |
diff --git a/net/ipv4/netfilter/Makefile b/net/ipv4/netfilter/Makefile index 09ae167632..461cb1eb5d 100644 --- a/net/ipv4/netfilter/Makefile +++ b/net/ipv4/netfilter/Makefile | |||
| @@ -53,7 +53,6 @@ obj-$(CONFIG_IP_NF_RAW) += iptable_raw.o | |||
| 53 | # matches | 53 | # matches |
| 54 | obj-$(CONFIG_IP_NF_MATCH_HASHLIMIT) += ipt_hashlimit.o | 54 | obj-$(CONFIG_IP_NF_MATCH_HASHLIMIT) += ipt_hashlimit.o |
| 55 | obj-$(CONFIG_IP_NF_MATCH_IPRANGE) += ipt_iprange.o | 55 | obj-$(CONFIG_IP_NF_MATCH_IPRANGE) += ipt_iprange.o |
| 56 | obj-$(CONFIG_IP_NF_MATCH_MULTIPORT) += ipt_multiport.o | ||
| 57 | obj-$(CONFIG_IP_NF_MATCH_OWNER) += ipt_owner.o | 56 | obj-$(CONFIG_IP_NF_MATCH_OWNER) += ipt_owner.o |
| 58 | obj-$(CONFIG_IP_NF_MATCH_TOS) += ipt_tos.o | 57 | obj-$(CONFIG_IP_NF_MATCH_TOS) += ipt_tos.o |
| 59 | obj-$(CONFIG_IP_NF_MATCH_RECENT) += ipt_recent.o | 58 | obj-$(CONFIG_IP_NF_MATCH_RECENT) += ipt_recent.o |
diff --git a/net/ipv4/netfilter/ipt_multiport.c b/net/ipv4/netfilter/ipt_multiport.c deleted file mode 100644 index ac95d8390b..0000000000 --- a/net/ipv4/netfilter/ipt_multiport.c +++ /dev/null | |||
| @@ -1,195 +0,0 @@ | |||
| 1 | /* Kernel module to match one of a list of TCP/UDP ports: ports are in | ||
| 2 | the same place so we can treat them as equal. */ | ||
| 3 | |||
| 4 | /* (C) 1999-2001 Paul `Rusty' Russell | ||
| 5 | * (C) 2002-2004 Netfilter Core Team <coreteam@netfilter.org> | ||
| 6 | * | ||
| 7 | * This program is free software; you can redistribute it and/or modify | ||
| 8 | * it under the terms of the GNU General Public License version 2 as | ||
| 9 | * published by the Free Software Foundation. | ||
| 10 | */ | ||
| 11 | |||
| 12 | #include <linux/module.h> | ||
| 13 | #include <linux/types.h> | ||
| 14 | #include <linux/udp.h> | ||
| 15 | #include <linux/skbuff.h> | ||
| 16 | |||
| 17 | #include <linux/netfilter_ipv4/ipt_multiport.h> | ||
| 18 | #include <linux/netfilter_ipv4/ip_tables.h> | ||
| 19 | |||
| 20 | MODULE_LICENSE("GPL"); | ||
| 21 | MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>"); | ||
| 22 | MODULE_DESCRIPTION("iptables multiple port match module"); | ||
| 23 | |||
| 24 | #if 0 | ||
| 25 | #define duprintf(format, args...) printk(format , ## args) | ||
| 26 | #else | ||
| 27 | #define duprintf(format, args...) | ||
| 28 | #endif | ||
| 29 | |||
| 30 | /* Returns 1 if the port is matched by the test, 0 otherwise. */ | ||
| 31 | static inline int | ||
| 32 | ports_match(const u_int16_t *portlist, enum ipt_multiport_flags flags, | ||
| 33 | u_int8_t count, u_int16_t src, u_int16_t dst) | ||
| 34 | { | ||
| 35 | unsigned int i; | ||
| 36 | for (i=0; i<count; i++) { | ||
| 37 | if (flags != IPT_MULTIPORT_DESTINATION | ||
| 38 | && portlist[i] == src) | ||
| 39 | return 1; | ||
| 40 | |||
| 41 | if (flags != IPT_MULTIPORT_SOURCE | ||
| 42 | && portlist[i] == dst) | ||
| 43 | return 1; | ||
| 44 | } | ||
| 45 | |||
| 46 | return 0; | ||
| 47 | } | ||
| 48 | |||
| 49 | /* Returns 1 if the port is matched by the test, 0 otherwise. */ | ||
| 50 | static inline int | ||
| 51 | ports_match_v1(const struct ipt_multiport_v1 *minfo, | ||
| 52< | |||
