1 diff -urN linux.old/include/linux/netfilter_ipv4/ipt_multiport.h linux.dev/include/linux/netfilter_ipv4/ipt_multiport.h
2 --- linux.old/include/linux/netfilter_ipv4/ipt_multiport.h 2000-12-11 22:31:30.000000000 +0100
3 +++ linux.dev/include/linux/netfilter_ipv4/ipt_multiport.h 2006-02-04 05:05:51.928476750 +0100
5 u_int8_t count; /* Number of ports */
6 u_int16_t ports[IPT_MULTI_PORTS]; /* Ports */
9 +struct ipt_multiport_v1
11 + u_int8_t flags; /* Type of comparison */
12 + u_int8_t count; /* Number of ports */
13 + u_int16_t ports[IPT_MULTI_PORTS]; /* Ports */
14 + u_int8_t pflags[IPT_MULTI_PORTS]; /* Port flags */
15 + u_int8_t invert; /* Invert flag */
17 #endif /*_IPT_MULTIPORT_H*/
18 diff -urN linux.old/net/ipv4/netfilter/ipt_multiport.c linux.dev/net/ipv4/netfilter/ipt_multiport.c
19 --- linux.old/net/ipv4/netfilter/ipt_multiport.c 2003-06-13 16:51:39.000000000 +0200
20 +++ linux.dev/net/ipv4/netfilter/ipt_multiport.c 2006-02-04 05:05:03.701462750 +0100
22 /* Kernel module to match one of a list of TCP/UDP ports: ports are in
23 the same place so we can treat them as equal. */
25 +/* (C) 1999-2001 Paul `Rusty' Russell
26 + * (C) 2002-2004 Netfilter Core Team <coreteam@netfilter.org>
28 + * This program is free software; you can redistribute it and/or modify
29 + * it under the terms of the GNU General Public License version 2 as
30 + * published by the Free Software Foundation.
33 #include <linux/module.h>
34 #include <linux/types.h>
35 #include <linux/udp.h>
37 #include <linux/netfilter_ipv4/ipt_multiport.h>
38 #include <linux/netfilter_ipv4/ip_tables.h>
40 +MODULE_LICENSE("GPL");
41 +MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>");
42 +MODULE_DESCRIPTION("iptables multiple port match module");
45 #define duprintf(format, args...) printk(format , ## args)
51 +/* Returns 1 if the port is matched by the test, 0 otherwise. */
53 +ports_match_v1(const struct ipt_multiport_v1 *minfo,
54 + u_int16_t src, u_int16_t dst)
59 + for (i=0; i < minfo->count; i++) {
60 + s = minfo->ports[i];
62 + if (minfo->pflags[i]) {
63 + /* range port matching */
64 + e = minfo->ports[++i];
65 + duprintf("src or dst matches with %d-%d?\n", s, e);
67 + if (minfo->flags == IPT_MULTIPORT_SOURCE
68 + && src >= s && src <= e)
69 + return 1 ^ minfo->invert;
70 + if (minfo->flags == IPT_MULTIPORT_DESTINATION
71 + && dst >= s && dst <= e)
72 + return 1 ^ minfo->invert;
73 + if (minfo->flags == IPT_MULTIPORT_EITHER
74 + && ((dst >= s && dst <= e)
75 + || (src >= s && src <= e)))
76 + return 1 ^ minfo->invert;
78 + /* exact port matching */
79 + duprintf("src or dst matches with %d?\n", s);
81 + if (minfo->flags == IPT_MULTIPORT_SOURCE
83 + return 1 ^ minfo->invert;
84 + if (minfo->flags == IPT_MULTIPORT_DESTINATION
86 + return 1 ^ minfo->invert;
87 + if (minfo->flags == IPT_MULTIPORT_EITHER
88 + && (src == s || dst == s))
89 + return 1 ^ minfo->invert;
93 + return minfo->invert;
97 match(const struct sk_buff *skb,
98 const struct net_device *in,
99 const struct net_device *out,
100 const void *matchinfo,
106 - const struct udphdr *udp = hdr;
107 + u16 _ports[2], *pptr;
108 const struct ipt_multiport *multiinfo = matchinfo;
110 - /* Must be big enough to read ports. */
111 - if (offset == 0 && datalen < sizeof(struct udphdr)) {
115 + pptr = skb_header_pointer(skb, skb->nh.iph->ihl * 4,
116 + sizeof(_ports), _ports);
117 + if (pptr == NULL) {
118 /* We've been asked to examine this packet, and we
119 - can't. Hence, no choice but to drop. */
120 - duprintf("ipt_multiport:"
121 - " Dropping evil offset=0 tinygram.\n");
124 + * can't. Hence, no choice but to drop.
126 + duprintf("ipt_multiport:"
127 + " Dropping evil offset=0 tinygram.\n");
132 - /* Must not be a fragment. */
134 - && ports_match(multiinfo->ports,
135 - multiinfo->flags, multiinfo->count,
136 - ntohs(udp->source), ntohs(udp->dest));
137 + return ports_match(multiinfo->ports,
138 + multiinfo->flags, multiinfo->count,
139 + ntohs(pptr[0]), ntohs(pptr[1]));
143 +match_v1(const struct sk_buff *skb,
144 + const struct net_device *in,
145 + const struct net_device *out,
146 + const void *matchinfo,
150 + u16 _ports[2], *pptr;
151 + const struct ipt_multiport_v1 *multiinfo = matchinfo;
156 + pptr = skb_header_pointer(skb, skb->nh.iph->ihl * 4,
157 + sizeof(_ports), _ports);
158 + if (pptr == NULL) {
159 + /* We've been asked to examine this packet, and we
160 + * can't. Hence, no choice but to drop.
162 + duprintf("ipt_multiport:"
163 + " Dropping evil offset=0 tinygram.\n");
168 + return ports_match_v1(multiinfo, ntohs(pptr[0]), ntohs(pptr[1]));
171 /* Called when user tries to insert an entry of this type. */
173 unsigned int matchsize,
174 unsigned int hook_mask)
176 - const struct ipt_multiport *multiinfo = matchinfo;
178 - if (matchsize != IPT_ALIGN(sizeof(struct ipt_multiport)))
180 + return (matchsize == IPT_ALIGN(sizeof(struct ipt_multiport)));
183 - /* Must specify proto == TCP/UDP, no unknown flags or bad count */
184 - return (ip->proto == IPPROTO_TCP || ip->proto == IPPROTO_UDP)
185 - && !(ip->invflags & IPT_INV_PROTO)
186 - && matchsize == IPT_ALIGN(sizeof(struct ipt_multiport))
187 - && (multiinfo->flags == IPT_MULTIPORT_SOURCE
188 - || multiinfo->flags == IPT_MULTIPORT_DESTINATION
189 - || multiinfo->flags == IPT_MULTIPORT_EITHER)
190 - && multiinfo->count <= IPT_MULTI_PORTS;
192 +checkentry_v1(const char *tablename,
193 + const struct ipt_ip *ip,
195 + unsigned int matchsize,
196 + unsigned int hook_mask)
198 + return (matchsize == IPT_ALIGN(sizeof(struct ipt_multiport_v1)));
201 -static struct ipt_match multiport_match
202 -= { { NULL, NULL }, "multiport", &match, &checkentry, NULL, THIS_MODULE };
203 +static struct ipt_match multiport_match = {
204 + .name = "multiport",
207 + .checkentry = &checkentry,
211 +static struct ipt_match multiport_match_v1 = {
212 + .name = "multiport",
214 + .match = &match_v1,
215 + .checkentry = &checkentry_v1,
219 static int __init init(void)
221 - return ipt_register_match(&multiport_match);
224 + err = ipt_register_match(&multiport_match);
226 + err = ipt_register_match(&multiport_match_v1);
228 + ipt_unregister_match(&multiport_match);
234 static void __exit fini(void)
236 ipt_unregister_match(&multiport_match);
237 + ipt_unregister_match(&multiport_match_v1);
242 -MODULE_LICENSE("GPL");