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:23:54.318518250 +0100
6 #define IPT_MULTI_PORTS 15
8 -/* Must fit inside union ipt_matchinfo: 16 bytes */
10 +struct ipt_multiport_v1
12 u_int8_t flags; /* Type of comparison */
13 u_int8_t count; /* Number of ports */
14 u_int16_t ports[IPT_MULTI_PORTS]; /* Ports */
15 + u_int8_t pflags[IPT_MULTI_PORTS]; /* Port flags */
16 + u_int8_t invert; /* Invert flag */
18 #endif /*_IPT_MULTIPORT_H*/
19 diff -urN linux.old/net/ipv4/netfilter/ipt_multiport.c linux.dev/net/ipv4/netfilter/ipt_multiport.c
20 --- linux.old/net/ipv4/netfilter/ipt_multiport.c 2003-06-13 16:51:39.000000000 +0200
21 +++ linux.dev/net/ipv4/netfilter/ipt_multiport.c 2006-02-04 05:34:27.362081000 +0100
23 /* Kernel module to match one of a list of TCP/UDP ports: ports are in
24 the same place so we can treat them as equal. */
26 +/* (C) 1999-2001 Paul `Rusty' Russell
27 + * (C) 2002-2004 Netfilter Core Team <coreteam@netfilter.org>
29 + * This program is free software; you can redistribute it and/or modify
30 + * it under the terms of the GNU General Public License version 2 as
31 + * published by the Free Software Foundation.
34 #include <linux/module.h>
35 #include <linux/types.h>
36 #include <linux/udp.h>
38 #include <linux/netfilter_ipv4/ipt_multiport.h>
39 #include <linux/netfilter_ipv4/ip_tables.h>
41 +MODULE_LICENSE("GPL");
42 +MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>");
43 +MODULE_DESCRIPTION("iptables multiple port match module");
46 #define duprintf(format, args...) printk(format , ## args)
48 #define duprintf(format, args...)
51 +/* from linux 2.6 skbuff.h */
52 +static inline void *skb_header_pointer(const struct sk_buff *skb, int offset,
53 + int len, void *buffer)
55 + int hlen = skb_headlen(skb);
57 + if (hlen - offset >= len)
58 + return skb->data + offset;
60 + if (skb_copy_bits(skb, offset, buffer, len) < 0)
67 /* Returns 1 if the port is matched by the test, 0 otherwise. */
69 -ports_match(const u_int16_t *portlist, enum ipt_multiport_flags flags,
70 - u_int8_t count, u_int16_t src, u_int16_t dst)
71 +ports_match_v1(const struct ipt_multiport_v1 *minfo,
72 + u_int16_t src, u_int16_t dst)
75 - for (i=0; i<count; i++) {
76 - if (flags != IPT_MULTIPORT_DESTINATION
77 - && portlist[i] == src)
80 - if (flags != IPT_MULTIPORT_SOURCE
81 - && portlist[i] == dst)
87 + for (i=0; i < minfo->count; i++) {
88 + s = minfo->ports[i];
90 + if (minfo->pflags[i]) {
91 + /* range port matching */
92 + e = minfo->ports[++i];
93 + duprintf("src or dst matches with %d-%d?\n", s, e);
95 + if (minfo->flags == IPT_MULTIPORT_SOURCE
96 + && src >= s && src <= e)
97 + return 1 ^ minfo->invert;
98 + if (minfo->flags == IPT_MULTIPORT_DESTINATION
99 + && dst >= s && dst <= e)
100 + return 1 ^ minfo->invert;
101 + if (minfo->flags == IPT_MULTIPORT_EITHER
102 + && ((dst >= s && dst <= e)
103 + || (src >= s && src <= e)))
104 + return 1 ^ minfo->invert;
106 + /* exact port matching */
107 + duprintf("src or dst matches with %d?\n", s);
109 + if (minfo->flags == IPT_MULTIPORT_SOURCE
111 + return 1 ^ minfo->invert;
112 + if (minfo->flags == IPT_MULTIPORT_DESTINATION
114 + return 1 ^ minfo->invert;
115 + if (minfo->flags == IPT_MULTIPORT_EITHER
116 + && (src == s || dst == s))
117 + return 1 ^ minfo->invert;
121 + return minfo->invert;
125 -match(const struct sk_buff *skb,
126 - const struct net_device *in,
127 - const struct net_device *out,
128 - const void *matchinfo,
133 +match_v1(const struct sk_buff *skb,
134 + const struct net_device *in,
135 + const struct net_device *out,
136 + const void *matchinfo,
140 - const struct udphdr *udp = hdr;
141 - const struct ipt_multiport *multiinfo = matchinfo;
142 + u16 _ports[2], *pptr;
143 + const struct ipt_multiport_v1 *multiinfo = matchinfo;
148 - /* Must be big enough to read ports. */
149 - if (offset == 0 && datalen < sizeof(struct udphdr)) {
150 + pptr = skb_header_pointer(skb, skb->nh.iph->ihl * 4,
151 + sizeof(_ports), _ports);
152 + if (pptr == NULL) {
153 /* We've been asked to examine this packet, and we
154 - can't. Hence, no choice but to drop. */
155 - duprintf("ipt_multiport:"
156 - " Dropping evil offset=0 tinygram.\n");
159 + * can't. Hence, no choice but to drop.
161 + duprintf("ipt_multiport:"
162 + " Dropping evil offset=0 tinygram.\n");
167 - /* Must not be a fragment. */
169 - && ports_match(multiinfo->ports,
170 - multiinfo->flags, multiinfo->count,
171 - ntohs(udp->source), ntohs(udp->dest));
172 + return ports_match_v1(multiinfo, ntohs(pptr[0]), ntohs(pptr[1]));
175 -/* Called when user tries to insert an entry of this type. */
177 -checkentry(const char *tablename,
178 - const struct ipt_ip *ip,
180 - unsigned int matchsize,
181 - unsigned int hook_mask)
182 +checkentry_v1(const char *tablename,
183 + const struct ipt_ip *ip,
185 + unsigned int matchsize,
186 + unsigned int hook_mask)
188 - const struct ipt_multiport *multiinfo = matchinfo;
190 - if (matchsize != IPT_ALIGN(sizeof(struct ipt_multiport)))
193 - /* Must specify proto == TCP/UDP, no unknown flags or bad count */
194 - return (ip->proto == IPPROTO_TCP || ip->proto == IPPROTO_UDP)
195 - && !(ip->invflags & IPT_INV_PROTO)
196 - && matchsize == IPT_ALIGN(sizeof(struct ipt_multiport))
197 - && (multiinfo->flags == IPT_MULTIPORT_SOURCE
198 - || multiinfo->flags == IPT_MULTIPORT_DESTINATION
199 - || multiinfo->flags == IPT_MULTIPORT_EITHER)
200 - && multiinfo->count <= IPT_MULTI_PORTS;
201 + return (matchsize == IPT_ALIGN(sizeof(struct ipt_multiport_v1)));
204 -static struct ipt_match multiport_match
205 -= { { NULL, NULL }, "multiport", &match, &checkentry, NULL, THIS_MODULE };
206 +static struct ipt_match multiport_match_v1 = {
207 + .name = "multiport",
208 + .match = &match_v1,
209 + .checkentry = &checkentry_v1,
213 static int __init init(void)
215 - return ipt_register_match(&multiport_match);
218 + err = ipt_register_match(&multiport_match_v1);
223 static void __exit fini(void)
225 - ipt_unregister_match(&multiport_match);
226 + ipt_unregister_match(&multiport_match_v1);
231 -MODULE_LICENSE("GPL");