pppoe hooks
[openwrt.git] / obsolete-buildroot / sources / ebtables-brnf-5.patch
1 diff -Nurb src/linux/linux.stock/include/linux/if_bridge.h src/linux/linux/include/linux/if_bridge.h
2 --- src/linux/linux.stock/include/linux/if_bridge.h 2003-10-14 04:09:25.000000000 -0400
3 +++ src/linux/linux/include/linux/if_bridge.h 2004-07-10 23:46:39.000000000 -0400
4 @@ -102,7 +102,8 @@
5 struct net_bridge_port;
6
7 extern int (*br_ioctl_hook)(unsigned long arg);
8 -extern void (*br_handle_frame_hook)(struct sk_buff *skb);
9 +extern int (*br_handle_frame_hook)(struct sk_buff *skb);
10 +extern int (*br_should_route_hook)(struct sk_buff **pskb);
11
12 #endif
13
14 diff -Nurb src/linux/linux.stock/include/linux/netfilter.h src/linux/linux/include/linux/netfilter.h
15 --- src/linux/linux.stock/include/linux/netfilter.h 2004-07-10 23:30:09.000000000 -0400
16 +++ src/linux/linux/include/linux/netfilter.h 2004-07-10 23:46:39.000000000 -0400
17 @@ -119,17 +119,23 @@
18 /* This is gross, but inline doesn't cut it for avoiding the function
19 call in fast path: gcc doesn't inline (needs value tracking?). --RR */
20 #ifdef CONFIG_NETFILTER_DEBUG
21 -#define NF_HOOK nf_hook_slow
22 +#define NF_HOOK(pf, hook, skb, indev, outdev, okfn) \
23 +nf_hook_slow((pf), (hook), (skb), (indev), (outdev), (okfn), INT_MIN)
24 +#define NF_HOOK_THRESH nf_hook_slow
25 #else
26 #define NF_HOOK(pf, hook, skb, indev, outdev, okfn) \
27 (list_empty(&nf_hooks[(pf)][(hook)]) \
28 ? (okfn)(skb) \
29 - : nf_hook_slow((pf), (hook), (skb), (indev), (outdev), (okfn)))
30 + : nf_hook_slow((pf), (hook), (skb), (indev), (outdev), (okfn), INT_MIN))
31 +#define NF_HOOK_THRESH(pf, hook, skb, indev, outdev, okfn, thresh) \
32 +(list_empty(&nf_hooks[(pf)][(hook)]) \
33 + ? (okfn)(skb) \
34 + : nf_hook_slow((pf), (hook), (skb), (indev), (outdev), (okfn), (thresh)))
35 #endif
36
37 int nf_hook_slow(int pf, unsigned int hook, struct sk_buff *skb,
38 struct net_device *indev, struct net_device *outdev,
39 - int (*okfn)(struct sk_buff *));
40 + int (*okfn)(struct sk_buff *), int thresh);
41
42 /* Call setsockopt() */
43 int nf_setsockopt(struct sock *sk, int pf, int optval, char *opt,
44 diff -Nurb src/linux/linux.stock/include/linux/netfilter_bridge/ebt_802_3.h src/linux/linux/include/linux/netfilter_bridge/ebt_802_3.h
45 --- src/linux/linux.stock/include/linux/netfilter_bridge/ebt_802_3.h 1969-12-31 19:00:00.000000000 -0500
46 +++ src/linux/linux/include/linux/netfilter_bridge/ebt_802_3.h 2004-07-10 23:46:39.000000000 -0400
47 @@ -0,0 +1,60 @@
48 +#ifndef __LINUX_BRIDGE_EBT_802_3_H
49 +#define __LINUX_BRIDGE_EBT_802_3_H
50 +
51 +#define EBT_802_3_SAP 0x01
52 +#define EBT_802_3_TYPE 0x02
53 +
54 +#define EBT_802_3_MATCH "802_3"
55 +
56 +/*
57 + * If frame has DSAP/SSAP value 0xaa you must check the SNAP type
58 + * to discover what kind of packet we're carrying.
59 + */
60 +#define CHECK_TYPE 0xaa
61 +
62 +/*
63 + * Control field may be one or two bytes. If the first byte has
64 + * the value 0x03 then the entire length is one byte, otherwise it is two.
65 + * One byte controls are used in Unnumbered Information frames.
66 + * Two byte controls are used in Numbered Information frames.
67 + */
68 +#define IS_UI 0x03
69 +
70 +#define EBT_802_3_MASK (EBT_802_3_SAP | EBT_802_3_TYPE | EBT_802_3)
71 +
72 +/* ui has one byte ctrl, ni has two */
73 +struct hdr_ui {
74 + uint8_t dsap;
75 + uint8_t ssap;
76 + uint8_t ctrl;
77 + uint8_t orig[3];
78 + uint16_t type;
79 +};
80 +
81 +struct hdr_ni {
82 + uint8_t dsap;
83 + uint8_t ssap;
84 + uint16_t ctrl;
85 + uint8_t orig[3];
86 + uint16_t type;
87 +};
88 +
89 +struct ebt_802_3_hdr {
90 + uint8_t daddr[6];
91 + uint8_t saddr[6];
92 + uint16_t len;
93 + union {
94 + struct hdr_ui ui;
95 + struct hdr_ni ni;
96 + } llc;
97 +};
98 +
99 +struct ebt_802_3_info
100 +{
101 + uint8_t sap;
102 + uint16_t type;
103 + uint8_t bitmask;
104 + uint8_t invflags;
105 +};
106 +
107 +#endif
108 diff -Nurb src/linux/linux.stock/include/linux/netfilter_bridge/ebt_among.h src/linux/linux/include/linux/netfilter_bridge/ebt_among.h
109 --- src/linux/linux.stock/include/linux/netfilter_bridge/ebt_among.h 1969-12-31 19:00:00.000000000 -0500
110 +++ src/linux/linux/include/linux/netfilter_bridge/ebt_among.h 2004-07-10 23:46:39.000000000 -0400
111 @@ -0,0 +1,65 @@
112 +#ifndef __LINUX_BRIDGE_EBT_AMONG_H
113 +#define __LINUX_BRIDGE_EBT_AMONG_H
114 +
115 +#define EBT_AMONG_DST 0x01
116 +#define EBT_AMONG_SRC 0x02
117 +
118 +/* Grzegorz Borowiak <grzes@gnu.univ.gda.pl> 2003
119 + *
120 + * Write-once-read-many hash table, used for checking if a given
121 + * MAC address belongs to a set or not and possibly for checking
122 + * if it is related with a given IPv4 address.
123 + *
124 + * The hash value of an address is its last byte.
125 + *
126 + * In real-world ethernet addresses, values of the last byte are
127 + * evenly distributed and there is no need to consider other bytes.
128 + * It would only slow the routines down.
129 + *
130 + * For MAC address comparison speedup reasons, we introduce a trick.
131 + * MAC address is mapped onto an array of two 32-bit integers.
132 + * This pair of integers is compared with MAC addresses in the
133 + * hash table, which are stored also in form of pairs of integers
134 + * (in `cmp' array). This is quick as it requires only two elementary
135 + * number comparisons in worst case. Further, we take advantage of
136 + * fact that entropy of 3 last bytes of address is larger than entropy
137 + * of 3 first bytes. So first we compare 4 last bytes of addresses and
138 + * if they are the same we compare 2 first.
139 + *
140 + * Yes, it is a memory overhead, but in 2003 AD, who cares?
141 + */
142 +
143 +struct ebt_mac_wormhash_tuple
144 +{
145 + uint32_t cmp[2];
146 + uint32_t ip;
147 +};
148 +
149 +struct ebt_mac_wormhash
150 +{
151 + int table[257];
152 + int poolsize;
153 + struct ebt_mac_wormhash_tuple pool[0];
154 +};
155 +
156 +#define ebt_mac_wormhash_size(x) ((x) ? sizeof(struct ebt_mac_wormhash) \
157 + + (x)->poolsize * sizeof(struct ebt_mac_wormhash_tuple) : 0)
158 +
159 +struct ebt_among_info
160 +{
161 + int wh_dst_ofs;
162 + int wh_src_ofs;
163 + int bitmask;
164 +};
165 +
166 +#define EBT_AMONG_DST_NEG 0x1
167 +#define EBT_AMONG_SRC_NEG 0x2
168 +
169 +#define ebt_among_wh_dst(x) ((x)->wh_dst_ofs ? \
170 + (struct ebt_mac_wormhash*)((char*)(x) + (x)->wh_dst_ofs) : NULL)
171 +#define ebt_among_wh_src(x) ((x)->wh_src_ofs ? \
172 + (struct ebt_mac_wormhash*)((char*)(x) + (x)->wh_src_ofs) : NULL)
173 +
174 +#define EBT_AMONG_MATCH "among"
175 +
176 +#endif
177 diff -Nurb src/linux/linux.stock/include/linux/netfilter_bridge/ebt_arp.h src/linux/linux/include/linux/netfilter_bridge/ebt_arp.h
178 --- src/linux/linux.stock/include/linux/netfilter_bridge/ebt_arp.h 1969-12-31 19:00:00.000000000 -0500
179 +++ src/linux/linux/include/linux/netfilter_bridge/ebt_arp.h 2004-07-10 23:46:39.000000000 -0400
180 @@ -0,0 +1,32 @@
181 +#ifndef __LINUX_BRIDGE_EBT_ARP_H
182 +#define __LINUX_BRIDGE_EBT_ARP_H
183 +
184 +#define EBT_ARP_OPCODE 0x01
185 +#define EBT_ARP_HTYPE 0x02
186 +#define EBT_ARP_PTYPE 0x04
187 +#define EBT_ARP_SRC_IP 0x08
188 +#define EBT_ARP_DST_IP 0x10
189 +#define EBT_ARP_SRC_MAC 0x20
190 +#define EBT_ARP_DST_MAC 0x40
191 +#define EBT_ARP_MASK (EBT_ARP_OPCODE | EBT_ARP_HTYPE | EBT_ARP_PTYPE | \
192 + EBT_ARP_SRC_IP | EBT_ARP_DST_IP | EBT_ARP_SRC_MAC | EBT_ARP_DST_MAC)
193 +#define EBT_ARP_MATCH "arp"
194 +
195 +struct ebt_arp_info
196 +{
197 + uint16_t htype;
198 + uint16_t ptype;
199 + uint16_t opcode;
200 + uint32_t saddr;
201 + uint32_t smsk;
202 + uint32_t daddr;
203 + uint32_t dmsk;
204 + unsigned char smaddr[ETH_ALEN];
205 + unsigned char smmsk[ETH_ALEN];
206 + unsigned char dmaddr[ETH_ALEN];
207 + unsigned char dmmsk[ETH_ALEN];
208 + uint8_t bitmask;
209 + uint8_t invflags;
210 +};
211 +
212 +#endif
213 diff -Nurb src/linux/linux.stock/include/linux/netfilter_bridge/ebt_arpreply.h src/linux/linux/include/linux/netfilter_bridge/ebt_arpreply.h
214 --- src/linux/linux.stock/include/linux/netfilter_bridge/ebt_arpreply.h 1969-12-31 19:00:00.000000000 -0500
215 +++ src/linux/linux/include/linux/netfilter_bridge/ebt_arpreply.h 2004-07-10 23:46:39.000000000 -0400
216 @@ -0,0 +1,11 @@
217 +#ifndef __LINUX_BRIDGE_EBT_ARPREPLY_H
218 +#define __LINUX_BRIDGE_EBT_ARPREPLY_H
219 +
220 +struct ebt_arpreply_info
221 +{
222 + unsigned char mac[ETH_ALEN];
223 + int target;
224 +};
225 +#define EBT_ARPREPLY_TARGET "arpreply"
226 +
227 +#endif
228 diff -Nurb src/linux/linux.stock/include/linux/netfilter_bridge/ebt_ip.h src/linux/linux/include/linux/netfilter_bridge/ebt_ip.h
229 --- src/linux/linux.stock/include/linux/netfilter_bridge/ebt_ip.h 1969-12-31 19:00:00.000000000 -0500
230 +++ src/linux/linux/include/linux/netfilter_bridge/ebt_ip.h 2004-07-10 23:46:39.000000000 -0400
231 @@ -0,0 +1,43 @@
232 +/*
233 + * ebt_ip
234 + *
235 + * Authors:
236 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
237 + *
238 + * April, 2002
239 + *
240 + * Changes:
241 + * added ip-sport and ip-dport
242 + * Innominate Security Technologies AG <mhopf@innominate.com>
243 + * September, 2002
244 + */
245 +
246 +#ifndef __LINUX_BRIDGE_EBT_IP_H
247 +#define __LINUX_BRIDGE_EBT_IP_H
248 +
249 +#define EBT_IP_SOURCE 0x01
250 +#define EBT_IP_DEST 0x02
251 +#define EBT_IP_TOS 0x04
252 +#define EBT_IP_PROTO 0x08
253 +#define EBT_IP_SPORT 0x10
254 +#define EBT_IP_DPORT 0x20
255 +#define EBT_IP_MASK (EBT_IP_SOURCE | EBT_IP_DEST | EBT_IP_TOS | EBT_IP_PROTO |\
256 + EBT_IP_SPORT | EBT_IP_DPORT )
257 +#define EBT_IP_MATCH "ip"
258 +
259 +// the same values are used for the invflags
260 +struct ebt_ip_info
261 +{
262 + uint32_t saddr;
263 + uint32_t daddr;
264 + uint32_t smsk;
265 + uint32_t dmsk;
266 + uint8_t tos;
267 + uint8_t protocol;
268 + uint8_t bitmask;
269 + uint8_t invflags;
270 + uint16_t sport[2];
271 + uint16_t dport[2];
272 +};
273 +
274 +#endif
275 diff -Nurb src/linux/linux.stock/include/linux/netfilter_bridge/ebt_limit.h src/linux/linux/include/linux/netfilter_bridge/ebt_limit.h
276 --- src/linux/linux.stock/include/linux/netfilter_bridge/ebt_limit.h 1969-12-31 19:00:00.000000000 -0500
277 +++ src/linux/linux/include/linux/netfilter_bridge/ebt_limit.h 2004-07-10 23:46:39.000000000 -0400
278 @@ -0,0 +1,23 @@
279 +#ifndef __LINUX_BRIDGE_EBT_LIMIT_H
280 +#define __LINUX_BRIDGE_EBT_LIMIT_H
281 +
282 +#define EBT_LIMIT_MATCH "limit"
283 +
284 +/* timings are in milliseconds. */
285 +#define EBT_LIMIT_SCALE 10000
286 +
287 +/* 1/10,000 sec period => max of 10,000/sec. Min rate is then 429490
288 + seconds, or one every 59 hours. */
289 +
290 +struct ebt_limit_info
291 +{
292 + u_int32_t avg; /* Average secs between packets * scale */
293 + u_int32_t burst; /* Period multiplier for upper limit. */
294 +
295 + /* Used internally by the kernel */
296 + unsigned long prev;
297 + u_int32_t credit;
298 + u_int32_t credit_cap, cost;
299 +};
300 +
301 +#endif
302 diff -Nurb src/linux/linux.stock/include/linux/netfilter_bridge/ebt_log.h src/linux/linux/include/linux/netfilter_bridge/ebt_log.h
303 --- src/linux/linux.stock/include/linux/netfilter_bridge/ebt_log.h 1969-12-31 19:00:00.000000000 -0500
304 +++ src/linux/linux/include/linux/netfilter_bridge/ebt_log.h 2004-07-10 23:46:39.000000000 -0400
305 @@ -0,0 +1,17 @@
306 +#ifndef __LINUX_BRIDGE_EBT_LOG_H
307 +#define __LINUX_BRIDGE_EBT_LOG_H
308 +
309 +#define EBT_LOG_IP 0x01 // if the frame is made by ip, log the ip information
310 +#define EBT_LOG_ARP 0x02
311 +#define EBT_LOG_MASK (EBT_LOG_IP | EBT_LOG_ARP)
312 +#define EBT_LOG_PREFIX_SIZE 30
313 +#define EBT_LOG_WATCHER "log"
314 +
315 +struct ebt_log_info
316 +{
317 + uint8_t loglevel;
318 + uint8_t prefix[EBT_LOG_PREFIX_SIZE];
319 + uint32_t bitmask;
320 +};
321 +
322 +#endif
323 diff -Nurb src/linux/linux.stock/include/linux/netfilter_bridge/ebt_mark_m.h src/linux/linux/include/linux/netfilter_bridge/ebt_mark_m.h
324 --- src/linux/linux.stock/include/linux/netfilter_bridge/ebt_mark_m.h 1969-12-31 19:00:00.000000000 -0500
325 +++ src/linux/linux/include/linux/netfilter_bridge/ebt_mark_m.h 2004-07-10 23:46:39.000000000 -0400
326 @@ -0,0 +1,15 @@
327 +#ifndef __LINUX_BRIDGE_EBT_MARK_M_H
328 +#define __LINUX_BRIDGE_EBT_MARK_M_H
329 +
330 +#define EBT_MARK_AND 0x01
331 +#define EBT_MARK_OR 0x02
332 +#define EBT_MARK_MASK (EBT_MARK_AND | EBT_MARK_OR)
333 +struct ebt_mark_m_info
334 +{
335 + unsigned long mark, mask;
336 + uint8_t invert;
337 + uint8_t bitmask;
338 +};
339 +#define EBT_MARK_MATCH "mark_m"
340 +
341 +#endif
342 diff -Nurb src/linux/linux.stock/include/linux/netfilter_bridge/ebt_mark_t.h src/linux/linux/include/linux/netfilter_bridge/ebt_mark_t.h
343 --- src/linux/linux.stock/include/linux/netfilter_bridge/ebt_mark_t.h 1969-12-31 19:00:00.000000000 -0500
344 +++ src/linux/linux/include/linux/netfilter_bridge/ebt_mark_t.h 2004-07-10 23:46:39.000000000 -0400
345 @@ -0,0 +1,12 @@
346 +#ifndef __LINUX_BRIDGE_EBT_MARK_T_H
347 +#define __LINUX_BRIDGE_EBT_MARK_T_H
348 +
349 +struct ebt_mark_t_info
350 +{
351 + unsigned long mark;
352 + // EBT_ACCEPT, EBT_DROP or EBT_CONTINUE or EBT_RETURN
353 + int target;
354 +};
355 +#define EBT_MARK_TARGET "mark"
356 +
357 +#endif
358 diff -Nurb src/linux/linux.stock/include/linux/netfilter_bridge/ebt_nat.h src/linux/linux/include/linux/netfilter_bridge/ebt_nat.h
359 --- src/linux/linux.stock/include/linux/netfilter_bridge/ebt_nat.h 1969-12-31 19:00:00.000000000 -0500
360 +++ src/linux/linux/include/linux/netfilter_bridge/ebt_nat.h 2004-07-10 23:46:39.000000000 -0400
361 @@ -0,0 +1,13 @@
362 +#ifndef __LINUX_BRIDGE_EBT_NAT_H
363 +#define __LINUX_BRIDGE_EBT_NAT_H
364 +
365 +struct ebt_nat_info
366 +{
367 + unsigned char mac[ETH_ALEN];
368 + // EBT_ACCEPT, EBT_DROP, EBT_CONTINUE or EBT_RETURN
369 + int target;
370 +};
371 +#define EBT_SNAT_TARGET "snat"
372 +#define EBT_DNAT_TARGET "dnat"
373 +
374 +#endif
375 diff -Nurb src/linux/linux.stock/include/linux/netfilter_bridge/ebt_pkttype.h src/linux/linux/include/linux/netfilter_bridge/ebt_pkttype.h
376 --- src/linux/linux.stock/include/linux/netfilter_bridge/ebt_pkttype.h 1969-12-31 19:00:00.000000000 -0500
377 +++ src/linux/linux/include/linux/netfilter_bridge/ebt_pkttype.h 2004-07-10 23:46:39.000000000 -0400
378 @@ -0,0 +1,11 @@
379 +#ifndef __LINUX_BRIDGE_EBT_PKTTYPE_H
380 +#define __LINUX_BRIDGE_EBT_PKTTYPE_H
381 +
382 +struct ebt_pkttype_info
383 +{
384 + uint8_t pkt_type;
385 + uint8_t invert;
386 +};
387 +#define EBT_PKTTYPE_MATCH "pkttype"
388 +
389 +#endif
390 diff -Nurb src/linux/linux.stock/include/linux/netfilter_bridge/ebt_redirect.h src/linux/linux/include/linux/netfilter_bridge/ebt_redirect.h
391 --- src/linux/linux.stock/include/linux/netfilter_bridge/ebt_redirect.h 1969-12-31 19:00:00.000000000 -0500
392 +++ src/linux/linux/include/linux/netfilter_bridge/ebt_redirect.h 2004-07-10 23:46:39.000000000 -0400
393 @@ -0,0 +1,11 @@
394 +#ifndef __LINUX_BRIDGE_EBT_REDIRECT_H
395 +#define __LINUX_BRIDGE_EBT_REDIRECT_H
396 +
397 +struct ebt_redirect_info
398 +{
399 + // EBT_ACCEPT, EBT_DROP or EBT_CONTINUE or EBT_RETURN
400 + int target;
401 +};
402 +#define EBT_REDIRECT_TARGET "redirect"
403 +
404 +#endif
405 diff -Nurb src/linux/linux.stock/include/linux/netfilter_bridge/ebt_stp.h src/linux/linux/include/linux/netfilter_bridge/ebt_stp.h
406 --- src/linux/linux.stock/include/linux/netfilter_bridge/ebt_stp.h 1969-12-31 19:00:00.000000000 -0500
407 +++ src/linux/linux/include/linux/netfilter_bridge/ebt_stp.h 2004-07-10 23:46:39.000000000 -0400
408 @@ -0,0 +1,46 @@
409 +#ifndef __LINUX_BRIDGE_EBT_STP_H
410 +#define __LINUX_BRIDGE_EBT_STP_H
411 +
412 +#define EBT_STP_TYPE 0x0001
413 +
414 +#define EBT_STP_FLAGS 0x0002
415 +#define EBT_STP_ROOTPRIO 0x0004
416 +#define EBT_STP_ROOTADDR 0x0008
417 +#define EBT_STP_ROOTCOST 0x0010
418 +#define EBT_STP_SENDERPRIO 0x0020
419 +#define EBT_STP_SENDERADDR 0x0040
420 +#define EBT_STP_PORT 0x0080
421 +#define EBT_STP_MSGAGE 0x0100
422 +#define EBT_STP_MAXAGE 0x0200
423 +#define EBT_STP_HELLOTIME 0x0400
424 +#define EBT_STP_FWDD 0x0800
425 +
426 +#define EBT_STP_MASK 0x0fff
427 +#define EBT_STP_CONFIG_MASK 0x0ffe
428 +
429 +#define EBT_STP_MATCH "stp"
430 +
431 +struct ebt_stp_config_info
432 +{
433 + uint8_t flags;
434 + uint16_t root_priol, root_priou;
435 + char root_addr[6], root_addrmsk[6];
436 + uint32_t root_costl, root_costu;
437 + uint16_t sender_priol, sender_priou;
438 + char sender_addr[6], sender_addrmsk[6];
439 + uint16_t portl, portu;
440 + uint16_t msg_agel, msg_ageu;
441 + uint16_t max_agel, max_ageu;
442 + uint16_t hello_timel, hello_timeu;
443 + uint16_t forward_delayl, forward_delayu;
444 +};
445 +
446 +struct ebt_stp_info
447 +{
448 + uint8_t type;
449 + struct ebt_stp_config_info config;
450 + uint16_t bitmask;
451 + uint16_t invflags;
452 +};
453 +
454 +#endif
455 diff -Nurb src/linux/linux.stock/include/linux/netfilter_bridge/ebt_vlan.h src/linux/linux/include/linux/netfilter_bridge/ebt_vlan.h
456 --- src/linux/linux.stock/include/linux/netfilter_bridge/ebt_vlan.h 1969-12-31 19:00:00.000000000 -0500
457 +++ src/linux/linux/include/linux/netfilter_bridge/ebt_vlan.h 2004-07-10 23:46:39.000000000 -0400
458 @@ -0,0 +1,20 @@
459 +#ifndef __LINUX_BRIDGE_EBT_VLAN_H
460 +#define __LINUX_BRIDGE_EBT_VLAN_H
461 +
462 +#define EBT_VLAN_ID 0x01
463 +#define EBT_VLAN_PRIO 0x02
464 +#define EBT_VLAN_ENCAP 0x04
465 +#define EBT_VLAN_MASK (EBT_VLAN_ID | EBT_VLAN_PRIO | EBT_VLAN_ENCAP)
466 +#define EBT_VLAN_MATCH "vlan"
467 +
468 +struct ebt_vlan_info {
469 + uint16_t id; /* VLAN ID {1-4095} */
470 + uint8_t prio; /* VLAN User Priority {0-7} */
471 + uint16_t encap; /* VLAN Encapsulated frame code {0-65535} */
472 + uint8_t bitmask; /* Args bitmask bit 1=1 - ID arg,
473 + bit 2=1 User-Priority arg, bit 3=1 encap*/
474 + uint8_t invflags; /* Inverse bitmask bit 1=1 - inversed ID arg,
475 + bit 2=1 - inversed Pirority arg */
476 +};
477 +
478 +#endif
479 diff -Nurb src/linux/linux.stock/include/linux/netfilter_bridge/ebtables.h src/linux/linux/include/linux/netfilter_bridge/ebtables.h
480 --- src/linux/linux.stock/include/linux/netfilter_bridge/ebtables.h 1969-12-31 19:00:00.000000000 -0500
481 +++ src/linux/linux/include/linux/netfilter_bridge/ebtables.h 2004-07-10 23:46:39.000000000 -0400
482 @@ -0,0 +1,361 @@
483 +/*
484 + * ebtables
485 + *
486 + * Authors:
487 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
488 + *
489 + * ebtables.c,v 2.0, September, 2002
490 + *
491 + * This code is stongly inspired on the iptables code which is
492 + * Copyright (C) 1999 Paul `Rusty' Russell & Michael J. Neuling
493 + */
494 +
495 +#ifndef __LINUX_BRIDGE_EFF_H
496 +#define __LINUX_BRIDGE_EFF_H
497 +#include <linux/if.h>
498 +#include <linux/netfilter_bridge.h>
499 +#include <linux/if_ether.h>
500 +
501 +#define EBT_TABLE_MAXNAMELEN 32
502 +#define EBT_CHAIN_MAXNAMELEN EBT_TABLE_MAXNAMELEN
503 +#define EBT_FUNCTION_MAXNAMELEN EBT_TABLE_MAXNAMELEN
504 +
505 +// verdicts >0 are "branches"
506 +#define EBT_ACCEPT -1
507 +#define EBT_DROP -2
508 +#define EBT_CONTINUE -3
509 +#define EBT_RETURN -4
510 +#define NUM_STANDARD_TARGETS 4
511 +
512 +struct ebt_counter
513 +{
514 + uint64_t pcnt;
515 + uint64_t bcnt;
516 +};
517 +
518 +struct ebt_entries {
519 + // this field is always set to zero
520 + // See EBT_ENTRY_OR_ENTRIES.
521 + // Must be same size as ebt_entry.bitmask
522 + unsigned int distinguisher;
523 + // the chain name
524 + char name[EBT_CHAIN_MAXNAMELEN];
525 + // counter offset for this chain
526 + unsigned int counter_offset;
527 + // one standard (accept, drop, return) per hook
528 + int policy;
529 + // nr. of entries
530 + unsigned int nentries;
531 + // entry list
532 + char data[0];
533 +};
534 +
535 +// used for the bitmask of struct ebt_entry
536 +
537 +// This is a hack to make a difference between an ebt_entry struct and an
538 +// ebt_entries struct when traversing the entries from start to end.
539 +// Using this simplifies the code alot, while still being able to use
540 +// ebt_entries.
541 +// Contrary, iptables doesn't use something like ebt_entries and therefore uses
542 +// different techniques for naming the policy and such. So, iptables doesn't
543 +// need a hack like this.
544 +#define EBT_ENTRY_OR_ENTRIES 0x01
545 +// these are the normal masks
546 +#define EBT_NOPROTO 0x02
547 +#define EBT_802_3 0x04
548 +#define EBT_SOURCEMAC 0x08
549 +#define EBT_DESTMAC 0x10
550 +#define EBT_F_MASK (EBT_NOPROTO | EBT_802_3 | EBT_SOURCEMAC | EBT_DESTMAC \
551 + | EBT_ENTRY_OR_ENTRIES)
552 +
553 +#define EBT_IPROTO 0x01
554 +#define EBT_IIN 0x02
555 +#define EBT_IOUT 0x04
556 +#define EBT_ISOURCE 0x8
557 +#define EBT_IDEST 0x10
558 +#define EBT_ILOGICALIN 0x20
559 +#define EBT_ILOGICALOUT 0x40
560 +#define EBT_INV_MASK (EBT_IPROTO | EBT_IIN | EBT_IOUT | EBT_ILOGICALIN \
561 + | EBT_ILOGICALOUT | EBT_ISOURCE | EBT_IDEST)
562 +
563 +struct ebt_entry_match
564 +{
565 + union {
566 + char name[EBT_FUNCTION_MAXNAMELEN];
567 + struct ebt_match *match;
568 + } u;
569 + // size of data
570 + unsigned int match_size;
571 + unsigned char data[0];
572 +};
573 +
574 +struct ebt_entry_watcher
575 +{
576 + union {
577 + char name[EBT_FUNCTION_MAXNAMELEN];
578 + struct ebt_watcher *watcher;
579 + } u;
580 + // size of data
581 + unsigned int watcher_size;
582 + unsigned char data[0];
583 +};
584 +
585 +struct ebt_entry_target
586 +{
587 + union {
588 + char name[EBT_FUNCTION_MAXNAMELEN];
589 + struct ebt_target *target;
590 + } u;
591 + // size of data
592 + unsigned int target_size;
593 + unsigned char data[0];
594 +};
595 +
596 +#define EBT_STANDARD_TARGET "standard"
597 +struct ebt_standard_target
598 +{
599 + struct ebt_entry_target target;
600 + int verdict;
601 +};
602 +
603 +// one entry
604 +struct ebt_entry {
605 + // this needs to be the first field
606 + unsigned int bitmask;
607 + unsigned int invflags;
608 + uint16_t ethproto;
609 + // the physical in-dev
610 + char in[IFNAMSIZ];
611 + // the logical in-dev
612 + char logical_in[IFNAMSIZ];
613 + // the physical out-dev
614 + char out[IFNAMSIZ];
615 + // the logical out-dev
616 + char logical_out[IFNAMSIZ];
617 + unsigned char sourcemac[ETH_ALEN];
618 + unsigned char sourcemsk[ETH_ALEN];
619 + unsigned char destmac[ETH_ALEN];
620 + unsigned char destmsk[ETH_ALEN];
621 + // sizeof ebt_entry + matches
622 + unsigned int watchers_offset;
623 + // sizeof ebt_entry + matches + watchers
624 + unsigned int target_offset;
625 + // sizeof ebt_entry + matches + watchers + target
626 + unsigned int next_offset;
627 + unsigned char elems[0];
628 +};
629 +
630 +struct ebt_replace
631 +{
632 + char name[EBT_TABLE_MAXNAMELEN];
633 + unsigned int valid_hooks;
634 + // nr of rules in the table
635 + unsigned int nentries;
636 + // total size of the entries
637 + unsigned int entries_size;
638 + // start of the chains
639 + struct ebt_entries *hook_entry[NF_BR_NUMHOOKS];
640 + // nr of counters userspace expects back
641 + unsigned int num_counters;
642 + // where the kernel will put the old counters
643 + struct ebt_counter *counters;
644 + char *entries;
645 +};
646 +
647 +// [gs]etsockopt numbers
648 +#define EBT_BASE_CTL 128
649 +
650 +#define EBT_SO_SET_ENTRIES (EBT_BASE_CTL)
651 +#define EBT_SO_SET_COUNTERS (EBT_SO_SET_ENTRIES+1)
652 +#define EBT_SO_SET_MAX (EBT_SO_SET_COUNTERS+1)
653 +
654 +#define EBT_SO_GET_INFO (EBT_BASE_CTL)
655 +#define EBT_SO_GET_ENTRIES (EBT_SO_GET_INFO+1)
656 +#define EBT_SO_GET_INIT_INFO (EBT_SO_GET_ENTRIES+1)
657 +#define EBT_SO_GET_INIT_ENTRIES (EBT_SO_GET_INIT_INFO+1)
658 +#define EBT_SO_GET_MAX (EBT_SO_GET_INIT_ENTRIES+1)
659 +
660 +#ifdef __KERNEL__
661 +
662 +// return values for match() functions
663 +#define EBT_MATCH 0
664 +#define EBT_NOMATCH 1
665 +
666 +struct ebt_match
667 +{
668 + struct list_head list;
669 + const char name[EBT_FUNCTION_MAXNAMELEN];
670 + // 0 == it matches
671 + int (*match)(const struct sk_buff *skb, const struct net_device *in,
672 + const struct net_device *out, const void *matchdata,
673 + unsigned int datalen);
674 + // 0 == let it in
675 + int (*check)(const char *tablename, unsigned int hookmask,
676 + const struct ebt_entry *e, void *matchdata, unsigned int datalen);
677 + void (*destroy)(void *matchdata, unsigned int datalen);
678 + struct module *me;
679 +};
680 +
681 +struct ebt_watcher
682 +{
683 + struct list_head list;
684 + const char name[EBT_FUNCTION_MAXNAMELEN];
685 + void (*watcher)(const struct sk_buff *skb, const struct net_device *in,
686 + const struct net_device *out, const void *watcherdata,
687 + unsigned int datalen);
688 + // 0 == let it in
689 + int (*check)(const char *tablename, unsigned int hookmask,
690 + const struct ebt_entry *e, void *watcherdata, unsigned int datalen);
691 + void (*destroy)(void *watcherdata, unsigned int datalen);
692 + struct module *me;
693 +};
694 +
695 +struct ebt_target
696 +{
697 + struct list_head list;
698 + const char name[EBT_FUNCTION_MAXNAMELEN];
699 + // returns one of the standard verdicts
700 + int (*target)(struct sk_buff **pskb, unsigned int hooknr,
701 + const struct net_device *in, const struct net_device *out,
702 + const void *targetdata, unsigned int datalen);
703 + // 0 == let it in
704 + int (*check)(const char *tablename, unsigned int hookmask,
705 + const struct ebt_entry *e, void *targetdata, unsigned int datalen);
706 + void (*destroy)(void *targetdata, unsigned int datalen);
707 + struct module *me;
708 +};
709 +
710 +// used for jumping from and into user defined chains (udc)
711 +struct ebt_chainstack
712 +{
713 + struct ebt_entries *chaininfo; // pointer to chain data
714 + struct ebt_entry *e; // pointer to entry data
715 + unsigned int n; // n'th entry
716 +};
717 +
718 +struct ebt_table_info
719 +{
720 + // total size of the entries
721 + unsigned int entries_size;
722 + unsigned int nentries;
723 + // pointers to the start of the chains
724 + struct ebt_entries *hook_entry[NF_BR_NUMHOOKS];
725 + // room to maintain the stack used for jumping from and into udc
726 + struct ebt_chainstack **chainstack;
727 + char *entries;
728 + struct ebt_counter counters[0] ____cacheline_aligned;
729 +};
730 +
731 +struct ebt_table
732 +{
733 + struct list_head list;
734 + char name[EBT_TABLE_MAXNAMELEN];
735 + struct ebt_replace *table;
736 + unsigned int valid_hooks;
737 + rwlock_t lock;
738 + // e.g. could be the table explicitly only allows certain
739 + // matches, targets, ... 0 == let it in
740 + int (*check)(const struct ebt_table_info *info,
741 + unsigned int valid_hooks);
742 + // the data used by the kernel
743 + struct ebt_table_info *private;
744 +};
745 +
746 +#define EBT_ALIGN(s) (((s) + (__alignof__(struct ebt_entry_target)-1)) & \
747 + ~(__alignof__(struct ebt_entry_target)-1))
748 +extern int ebt_register_table(struct ebt_table *table);
749 +extern void ebt_unregister_table(struct ebt_table *table);
750 +extern int ebt_register_match(struct ebt_match *match);
751 +extern void ebt_unregister_match(struct ebt_match *match);
752 +extern int ebt_register_watcher(struct ebt_watcher *watcher);
753 +extern void ebt_unregister_watcher(struct ebt_watcher *watcher);
754 +extern int ebt_register_target(struct ebt_target *target);
755 +extern void ebt_unregister_target(struct ebt_target *target);
756 +extern unsigned int ebt_do_table(unsigned int hook, struct sk_buff **pskb,
757 + const struct net_device *in, const struct net_device *out,
758 + struct ebt_table *table);
759 +
760 + // Used in the kernel match() functions
761 +#define FWINV(bool,invflg) ((bool) ^ !!(info->invflags & invflg))
762 +// True if the hook mask denotes that the rule is in a base chain,
763 +// used in the check() functions
764 +#define BASE_CHAIN (hookmask & (1 << NF_BR_NUMHOOKS))
765 +// Clear the bit in the hook mask that tells if the rule is on a base chain
766 +#define CLEAR_BASE_CHAIN_BIT (hookmask &= ~(1 << NF_BR_NUMHOOKS))
767 +// True if the target is not a standard target
768 +#define INVALID_TARGET (info->target < -NUM_STANDARD_TARGETS || info->target >= 0)
769 +
770 +#endif /* __KERNEL__ */
771 +
772 +// blatently stolen from ip_tables.h
773 +// fn returns 0 to continue iteration
774 +#define EBT_MATCH_ITERATE(e, fn, args...) \
775 +({ \
776 + unsigned int __i; \
777 + int __ret = 0; \
778 + struct ebt_entry_match *__match; \
779 + \
780 + for (__i = sizeof(struct ebt_entry); \
781 + __i < (e)->watchers_offset; \
782 + __i += __match->match_size + \
783 + sizeof(struct ebt_entry_match)) { \
784 + __match = (void *)(e) + __i; \
785 + \
786 + __ret = fn(__match , ## args); \
787 + if (__ret != 0) \
788 + break; \
789 + } \
790 + if (__ret == 0) { \
791 + if (__i != (e)->watchers_offset) \
792 + __ret = -EINVAL; \
793 + } \
794 + __ret; \
795 +})
796 +
797 +#define EBT_WATCHER_ITERATE(e, fn, args...) \
798 +({ \
799 + unsigned int __i; \
800 + int __ret = 0; \
801 + struct ebt_entry_watcher *__watcher; \
802 + \
803 + for (__i = e->watchers_offset; \
804 + __i < (e)->target_offset; \
805 + __i += __watcher->watcher_size + \
806 + sizeof(struct ebt_entry_watcher)) { \
807 + __watcher = (void *)(e) + __i; \
808 + \
809 + __ret = fn(__watcher , ## args); \
810 + if (__ret != 0) \
811 + break; \
812 + } \
813 + if (__ret == 0) { \
814 + if (__i != (e)->target_offset) \
815 + __ret = -EINVAL; \
816 + } \
817 + __ret; \
818 +})
819 +
820 +#define EBT_ENTRY_ITERATE(entries, size, fn, args...) \
821 +({ \
822 + unsigned int __i; \
823 + int __ret = 0; \
824 + struct ebt_entry *__entry; \
825 + \
826 + for (__i = 0; __i < (size);) { \
827 + __entry = (void *)(entries) + __i; \
828 + __ret = fn(__entry , ## args); \
829 + if (__ret != 0) \
830 + break; \
831 + if (__entry->bitmask != 0) \
832 + __i += __entry->next_offset; \
833 + else \
834 + __i += sizeof(struct ebt_entries); \
835 + } \
836 + if (__ret == 0) { \
837 + if (__i != (size)) \
838 + __ret = -EINVAL; \
839 + } \
840 + __ret; \
841 +})
842 +
843 +#endif
844 diff -Nurb src/linux/linux.stock/include/linux/netfilter_bridge.h src/linux/linux/include/linux/netfilter_bridge.h
845 --- src/linux/linux.stock/include/linux/netfilter_bridge.h 2003-07-04 04:12:26.000000000 -0400
846 +++ src/linux/linux/include/linux/netfilter_bridge.h 2004-07-10 23:46:39.000000000 -0400
847 @@ -6,6 +6,10 @@
848
849 #include <linux/config.h>
850 #include <linux/netfilter.h>
851 +#if defined(__KERNEL__) && defined(CONFIG_NETFILTER)
852 +#include <asm/atomic.h>
853 +#include <linux/if_ether.h>
854 +#endif
855
856 /* Bridge Hooks */
857 /* After promisc drops, checksum checks. */
858 @@ -18,7 +22,76 @@
859 #define NF_BR_LOCAL_OUT 3
860 /* Packets about to hit the wire. */
861 #define NF_BR_POST_ROUTING 4
862 -#define NF_BR_NUMHOOKS 5
863 +/* Not really a hook, but used for the ebtables broute table */
864 +#define NF_BR_BROUTING 5
865 +#define NF_BR_NUMHOOKS 6
866 +
867 +#ifdef __KERNEL__
868 +
869 +#define BRNF_PKT_TYPE 0x01
870 +#define BRNF_BRIDGED_DNAT 0x02
871 +#define BRNF_DONT_TAKE_PARENT 0x04
872 +#define BRNF_BRIDGED 0x08
873 +#define BRNF_NF_BRIDGE_PREROUTING 0x10
874 +
875 +enum nf_br_hook_priorities {
876 + NF_BR_PRI_FIRST = INT_MIN,
877 + NF_BR_PRI_NAT_DST_BRIDGED = -300,
878 + NF_BR_PRI_FILTER_BRIDGED = -200,
879 + NF_BR_PRI_BRNF = 0,
880 + NF_BR_PRI_NAT_DST_OTHER = 100,
881 + NF_BR_PRI_FILTER_OTHER = 200,
882 + NF_BR_PRI_NAT_SRC = 300,
883 + NF_BR_PRI_LAST = INT_MAX,
884 +};
885 +
886 +#ifdef CONFIG_NETFILTER
887 +static inline
888 +struct nf_bridge_info *nf_bridge_alloc(struct sk_buff *skb)
889 +{
890 + struct nf_bridge_info **nf_bridge = &(skb->nf_bridge);
891 +
892 + if ((*nf_bridge = kmalloc(sizeof(**nf_bridge), GFP_ATOMIC)) != NULL) {
893 + atomic_set(&(*nf_bridge)->use, 1);
894 + (*nf_bridge)->mask = 0;
895 + (*nf_bridge)->physindev = (*nf_bridge)->physoutdev = NULL;
896 +#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
897 + (*nf_bridge)->netoutdev = NULL;
898 +#endif
899 + }
900 +
901 + return *nf_bridge;
902 +}
903 +
904 +/* Only used in br_forward.c */
905 +static inline
906 +void nf_bridge_maybe_copy_header(struct sk_buff *skb)
907 +{
908 + if (skb->nf_bridge) {
909 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
910 + memcpy(skb->data - 18, skb->nf_bridge->data, 18);
911 + skb_push(skb, 4);
912 + } else
913 + memcpy(skb->data - 16, skb->nf_bridge->data, 16);
914 + }
915 +}
916 +
917 +static inline
918 +void nf_bridge_save_header(struct sk_buff *skb)
919 +{
920 + int header_size = 16;
921 +
922 + if (skb->protocol == __constant_htons(ETH_P_8021Q))
923 + header_size = 18;
924 + memcpy(skb->nf_bridge->data, skb->data - header_size, header_size);
925 +}
926
927 +struct bridge_skb_cb {
928 + union {
929 + __u32 ipv4;
930 + } daddr;
931 +};
932 +#endif /* CONFIG_NETFILTER */
933
934 +#endif /* __KERNEL__ */
935 #endif
936 diff -Nurb src/linux/linux.stock/include/linux/netfilter_ipv4/ipt_physdev.h src/linux/linux/include/linux/netfilter_ipv4/ipt_physdev.h
937 --- src/linux/linux.stock/include/linux/netfilter_ipv4/ipt_physdev.h 1969-12-31 19:00:00.000000000 -0500
938 +++ src/linux/linux/include/linux/netfilter_ipv4/ipt_physdev.h 2004-07-10 23:46:39.000000000 -0400
939 @@ -0,0 +1,24 @@
940 +#ifndef _IPT_PHYSDEV_H
941 +#define _IPT_PHYSDEV_H
942 +
943 +#ifdef __KERNEL__
944 +#include <linux/if.h>
945 +#endif
946 +
947 +#define IPT_PHYSDEV_OP_IN 0x01
948 +#define IPT_PHYSDEV_OP_OUT 0x02
949 +#define IPT_PHYSDEV_OP_BRIDGED 0x04
950 +#define IPT_PHYSDEV_OP_ISIN 0x08
951 +#define IPT_PHYSDEV_OP_ISOUT 0x10
952 +#define IPT_PHYSDEV_OP_MASK (0x20 - 1)
953 +
954 +struct ipt_physdev_info {
955 + char physindev[IFNAMSIZ];
956 + char in_mask[IFNAMSIZ];
957 + char physoutdev[IFNAMSIZ];
958 + char out_mask[IFNAMSIZ];
959 + u_int8_t invert;
960 + u_int8_t bitmask;
961 +};
962 +
963 +#endif /*_IPT_PHYSDEV_H*/
964 diff -Nurb src/linux/linux.stock/include/linux/netfilter_ipv4.h src/linux/linux/include/linux/netfilter_ipv4.h
965 --- src/linux/linux.stock/include/linux/netfilter_ipv4.h 2004-07-10 23:30:09.000000000 -0400
966 +++ src/linux/linux/include/linux/netfilter_ipv4.h 2004-07-10 23:46:39.000000000 -0400
967 @@ -54,8 +54,10 @@
968 NF_IP_PRI_CONNTRACK_DEFRAG = -400,
969 NF_IP_PRI_RAW = -300,
970 NF_IP_PRI_CONNTRACK = -200,
971 + NF_IP_PRI_BRIDGE_SABOTAGE_FORWARD = -175,
972 NF_IP_PRI_MANGLE = -150,
973 NF_IP_PRI_NAT_DST = -100,
974 + NF_IP_PRI_BRIDGE_SABOTAGE_LOCAL_OUT = -50,
975 NF_IP_PRI_FILTER = 0,
976 NF_IP_PRI_NAT_SRC = 100,
977 NF_IP_PRI_LAST = INT_MAX,
978 diff -Nurb src/linux/linux.stock/include/linux/skbuff.h src/linux/linux/include/linux/skbuff.h
979 --- src/linux/linux.stock/include/linux/skbuff.h 2003-07-04 04:12:26.000000000 -0400
980 +++ src/linux/linux/include/linux/skbuff.h 2004-07-10 23:46:39.000000000 -0400
981 @@ -92,6 +92,20 @@
982 struct nf_ct_info {
983 struct nf_conntrack *master;
984 };
985 +
986 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
987 +struct nf_bridge_info {
988 + atomic_t use;
989 + struct net_device *physindev;
990 + struct net_device *physoutdev;
991 +#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
992 + struct net_device *netoutdev;
993 +#endif
994 + unsigned int mask;
995 + unsigned long data[32 / sizeof(unsigned long)];
996 +};
997 +#endif
998 +
999 #endif
1000
1001 struct sk_buff_head {
1002 @@ -204,6 +218,9 @@
1003 #ifdef CONFIG_NETFILTER_DEBUG
1004 unsigned int nf_debug;
1005 #endif
1006 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
1007 + struct nf_bridge_info *nf_bridge; /* Saved data about a bridged frame - see br_netfilter.c */
1008 +#endif
1009 #endif /*CONFIG_NETFILTER*/
1010
1011 #if defined(CONFIG_HIPPI)
1012 @@ -1143,6 +1160,20 @@
1013 if (nfct)
1014 atomic_inc(&nfct->master->use);
1015 }
1016 +
1017 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
1018 +static inline void nf_bridge_put(struct nf_bridge_info *nf_bridge)
1019 +{
1020 + if (nf_bridge && atomic_dec_and_test(&nf_bridge->use))
1021 + kfree(nf_bridge);
1022 +}
1023 +static inline void nf_bridge_get(struct nf_bridge_info *nf_bridge)
1024 +{
1025 + if (nf_bridge)
1026 + atomic_inc(&nf_bridge->use);
1027 +}
1028 +#endif
1029 +
1030 #endif
1031
1032 #endif /* __KERNEL__ */
1033 diff -Nurb src/linux/linux.stock/include/linux/sysctl.h src/linux/linux/include/linux/sysctl.h
1034 --- src/linux/linux.stock/include/linux/sysctl.h 2004-07-10 23:29:55.000000000 -0400
1035 +++ src/linux/linux/include/linux/sysctl.h 2004-07-10 23:46:39.000000000 -0400
1036 @@ -547,6 +547,15 @@
1037 NET_DECNET_CONF_DEV_STATE = 7
1038 };
1039
1040 +/* /proc/sys/net/bridge */
1041 +enum {
1042 + NET_BRIDGE_NF_CALL_ARPTABLES = 1,
1043 + NET_BRIDGE_NF_CALL_IPTABLES = 2,
1044 + NET_BRIDGE_NF_CALL_IP6TABLES = 3,
1045 + NET_BRIDGE_NF_FILTER_VLAN_TAGGED = 4,
1046 +};
1047 +
1048 +
1049 /* CTL_PROC names: */
1050
1051 /* CTL_FS names: */
1052 diff -Nurb src/linux/linux.stock/net/8021q/vlan_dev.c src/linux/linux/net/8021q/vlan_dev.c
1053 --- src/linux/linux.stock/net/8021q/vlan_dev.c 2003-07-04 04:12:29.000000000 -0400
1054 +++ src/linux/linux/net/8021q/vlan_dev.c 2004-07-10 23:46:39.000000000 -0400
1055 @@ -503,6 +503,10 @@
1056 stats->tx_packets++; /* for statics only */
1057 stats->tx_bytes += skb->len;
1058
1059 + skb->protocol = __constant_htons(ETH_P_8021Q);
1060 + skb->mac.raw -= VLAN_HLEN;
1061 + skb->nh.raw -= VLAN_HLEN;
1062 +
1063 dev_queue_xmit(skb);
1064
1065 return 0;
1066 diff -Nurb src/linux/linux.stock/net/Config.in src/linux/linux/net/Config.in
1067 --- src/linux/linux.stock/net/Config.in 2004-07-10 23:29:49.000000000 -0400
1068 +++ src/linux/linux/net/Config.in 2004-07-10 23:46:39.000000000 -0400
1069 @@ -68,6 +68,9 @@
1070 source net/decnet/Config.in
1071 fi
1072 dep_tristate '802.1d Ethernet Bridging' CONFIG_BRIDGE $CONFIG_INET
1073 +if [ "$CONFIG_BRIDGE" != "n" -a "$CONFIG_NETFILTER" != "n" ]; then
1074 + source net/bridge/netfilter/Config.in
1075 +fi
1076 if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then
1077 tristate 'CCITT X.25 Packet Layer (EXPERIMENTAL)' CONFIG_X25
1078 tristate 'LAPB Data Link Driver (EXPERIMENTAL)' CONFIG_LAPB
1079 diff -Nurb src/linux/linux.stock/net/Makefile src/linux/linux/net/Makefile
1080 --- src/linux/linux.stock/net/Makefile 2004-07-10 23:29:49.000000000 -0400
1081 +++ src/linux/linux/net/Makefile 2004-07-10 23:49:10.000000000 -0400
1082 @@ -26,6 +26,12 @@
1083 endif
1084 endif
1085
1086 +ifneq ($(CONFIG_BRIDGE),n)
1087 +ifneq ($(CONFIG_BRIDGE),)
1088 +subdir-$(CONFIG_BRIDGE) += bridge/netfilter
1089 +endif
1090 +endif
1091 +
1092 subdir-$(CONFIG_KHTTPD) += khttpd
1093 subdir-$(CONFIG_PACKET) += packet
1094 subdir-$(CONFIG_NET_SCHED) += sched
1095 diff -Nurb src/linux/linux.stock/net/bridge/Makefile src/linux/linux/net/bridge/Makefile
1096 --- src/linux/linux.stock/net/bridge/Makefile 2003-07-04 04:12:30.000000000 -0400
1097 +++ src/linux/linux/net/bridge/Makefile 2004-07-10 23:46:39.000000000 -0400
1098 @@ -7,10 +7,17 @@
1099 #
1100 # Note 2! The CFLAGS definition is now in the main makefile...
1101
1102 +export-objs := br.o
1103 +
1104 O_TARGET := bridge.o
1105 obj-y := br.o br_device.o br_fdb.o br_forward.o br_if.o br_input.o \
1106 br_ioctl.o br_notify.o br_stp.o br_stp_bpdu.o \
1107 br_stp_if.o br_stp_timer.o
1108 +
1109 +ifeq ($(CONFIG_NETFILTER),y)
1110 +obj-y += br_netfilter.o
1111 +endif
1112 +
1113 obj-m := $(O_TARGET)
1114
1115 include $(TOPDIR)/Rules.make
1116 diff -Nurb src/linux/linux.stock/net/bridge/br.c src/linux/linux/net/bridge/br.c
1117 --- src/linux/linux.stock/net/bridge/br.c 2003-10-14 04:09:32.000000000 -0400
1118 +++ src/linux/linux/net/bridge/br.c 2004-07-10 23:46:39.000000000 -0400
1119 @@ -29,6 +29,8 @@
1120 #include "../atm/lec.h"
1121 #endif
1122
1123 +int (*br_should_route_hook) (struct sk_buff **pskb) = NULL;
1124 +
1125 void br_dec_use_count()
1126 {
1127 MOD_DEC_USE_COUNT;
1128 @@ -43,6 +45,10 @@
1129 {
1130 printk(KERN_INFO "NET4: Ethernet Bridge 008 for NET4.0\n");
1131
1132 +#ifdef CONFIG_NETFILTER
1133 + if (br_netfilter_init())
1134 + return 1;
1135 +#endif
1136 br_handle_frame_hook = br_handle_frame;
1137 br_ioctl_hook = br_ioctl_deviceless_stub;
1138 #if defined(CONFIG_ATM_LANE) || defined(CONFIG_ATM_LANE_MODULE)
1139 @@ -61,6 +67,9 @@
1140
1141 static void __exit br_deinit(void)
1142 {
1143 +#ifdef CONFIG_NETFILTER
1144 + br_netfilter_fini();
1145 +#endif
1146 unregister_netdevice_notifier(&br_device_notifier);
1147 br_call_ioctl_atomic(__br_clear_ioctl_hook);
1148
1149 @@ -74,7 +83,7 @@
1150 #endif
1151 }
1152
1153 -EXPORT_NO_SYMBOLS;
1154 +EXPORT_SYMBOL(br_should_route_hook);
1155
1156 module_init(br_init)
1157 module_exit(br_deinit)
1158 diff -Nurb src/linux/linux.stock/net/bridge/br_forward.c src/linux/linux/net/bridge/br_forward.c
1159 --- src/linux/linux.stock/net/bridge/br_forward.c 2003-10-14 04:09:32.000000000 -0400
1160 +++ src/linux/linux/net/bridge/br_forward.c 2004-07-10 23:46:39.000000000 -0400
1161 @@ -30,18 +30,21 @@
1162 return 1;
1163 }
1164
1165 -static int __dev_queue_push_xmit(struct sk_buff *skb)
1166 +int br_dev_queue_push_xmit(struct sk_buff *skb)
1167 {
1168 +#ifdef CONFIG_NETFILTER
1169 + nf_bridge_maybe_copy_header(skb);
1170 +#endif
1171 skb_push(skb, ETH_HLEN);
1172 dev_queue_xmit(skb);
1173
1174 return 0;
1175 }
1176
1177 -static int __br_forward_finish(struct sk_buff *skb)
1178 +int br_forward_finish(struct sk_buff *skb)
1179 {
1180 NF_HOOK(PF_BRIDGE, NF_BR_POST_ROUTING, skb, NULL, skb->dev,
1181 - __dev_queue_push_xmit);
1182 + br_dev_queue_push_xmit);
1183
1184 return 0;
1185 }
1186 @@ -49,8 +52,11 @@
1187 static void __br_deliver(struct net_bridge_port *to, struct sk_buff *skb)
1188 {
1189 skb->dev = to->dev;
1190 +#ifdef CONFIG_NETFILTER_DEBUG
1191 + skb->nf_debug = 0;
1192 +#endif
1193 NF_HOOK(PF_BRIDGE, NF_BR_LOCAL_OUT, skb, NULL, skb->dev,
1194 - __br_forward_finish);
1195 + br_forward_finish);
1196 }
1197
1198 static void __br_forward(struct net_bridge_port *to, struct sk_buff *skb)
1199 @@ -61,7 +67,7 @@
1200 skb->dev = to->dev;
1201
1202 NF_HOOK(PF_BRIDGE, NF_BR_FORWARD, skb, indev, skb->dev,
1203 - __br_forward_finish);
1204 + br_forward_finish);
1205 }
1206
1207 /* called under bridge lock */
1208 diff -Nurb src/linux/linux.stock/net/bridge/br_input.c src/linux/linux/net/bridge/br_input.c
1209 --- src/linux/linux.stock/net/bridge/br_input.c 2003-10-14 04:09:32.000000000 -0400
1210 +++ src/linux/linux/net/bridge/br_input.c 2004-07-10 23:48:36.000000000 -0400
1211 @@ -24,6 +24,9 @@
1212
1213 static int br_pass_frame_up_finish(struct sk_buff *skb)
1214 {
1215 +#ifdef CONFIG_NETFILTER_DEBUG
1216 + skb->nf_debug = 0;
1217 +#endif
1218 netif_rx(skb);
1219
1220 return 0;
1221 @@ -46,7 +49,7 @@
1222 br_pass_frame_up_finish);
1223 }
1224
1225 -static int br_handle_frame_finish(struct sk_buff *skb)
1226 +int br_handle_frame_finish(struct sk_buff *skb)
1227 {
1228 struct net_bridge *br;
1229 unsigned char *dest;
1230 @@ -112,7 +115,7 @@
1231 return 0;
1232 }
1233
1234 -void br_handle_frame(struct sk_buff *skb)
1235 +int br_handle_frame(struct sk_buff *skb)
1236 {
1237 struct net_bridge *br;
1238 unsigned char *dest;
1239 @@ -146,25 +149,34 @@
1240 goto handle_special_frame;
1241
1242 if (p->state == BR_STATE_FORWARDING) {
1243 + if (br_should_route_hook && br_should_route_hook(&skb)) {
1244 + read_unlock(&br->lock);
1245 + return -1;
1246 + }
1247 +
1248 + if (!memcmp(p->br->dev.dev_addr, dest, ETH_ALEN))
1249 + skb->pkt_type = PACKET_HOST;
1250 +
1251 NF_HOOK(PF_BRIDGE, NF_BR_PRE_ROUTING, skb, skb->dev, NULL,
1252 br_handle_frame_finish);
1253 read_unlock(&br->lock);
1254 - return;
1255 + return 0;
1256 }
1257
1258 err:
1259 read_unlock(&br->lock);
1260 err_nolock:
1261 kfree_skb(skb);
1262 - return;
1263 + return 0;
1264
1265 handle_special_frame:
1266 if (!dest[5]) {
1267 br_stp_handle_bpdu(skb);
1268 read_unlock(&br->lock);
1269 - return;
1270 + return 0;
1271 }
1272
1273 read_unlock(&br->lock);
1274 kfree_skb(skb);
1275 + return 0;
1276 }
1277 diff -Nurb src/linux/linux.stock/net/bridge/br_netfilter.c src/linux/linux/net/bridge/br_netfilter.c
1278 --- src/linux/linux.stock/net/bridge/br_netfilter.c 1969-12-31 19:00:00.000000000 -0500
1279 +++ src/linux/linux/net/bridge/br_netfilter.c 2004-07-10 23:46:39.000000000 -0400
1280 @@ -0,0 +1,896 @@
1281 +/*
1282 + * Handle firewalling
1283 + * Linux ethernet bridge
1284 + *
1285 + * Authors:
1286 + * Lennert Buytenhek <buytenh@gnu.org>
1287 + * Bart De Schuymer (maintainer) <bdschuym@pandora.be>
1288 + *
1289 + * Changes:
1290 + * Apr 29 2003: physdev module support (bdschuym)
1291 + * Jun 19 2003: let arptables see bridged ARP traffic (bdschuym)
1292 + * Oct 06 2003: filter encapsulated IP/ARP VLAN traffic on untagged bridge
1293 + * (bdschuym)
1294 + *
1295 + * This program is free software; you can redistribute it and/or
1296 + * modify it under the terms of the GNU General Public License
1297 + * as published by the Free Software Foundation; either version
1298 + * 2 of the License, or (at your option) any later version.
1299 + *
1300 + * Lennert dedicates this file to Kerstin Wurdinger.
1301 + */
1302 +
1303 +#include <linux/module.h>
1304 +#include <linux/kernel.h>
1305 +#include <linux/ip.h>
1306 +#include <linux/netdevice.h>
1307 +#include <linux/skbuff.h>
1308 +#include <linux/if_ether.h>
1309 +#include <linux/if_vlan.h>
1310 +#include <linux/netfilter_bridge.h>
1311 +#include <linux/netfilter_ipv4.h>
1312 +#include <linux/in_route.h>
1313 +#include <net/ip.h>
1314 +#include <asm/uaccess.h>
1315 +#include <asm/checksum.h>
1316 +#include "br_private.h"
1317 +#ifdef CONFIG_SYSCTL
1318 +#include <linux/sysctl.h>
1319 +#endif
1320 +
1321 +
1322 +#define skb_origaddr(skb) (((struct bridge_skb_cb *) \
1323 + (skb->nf_bridge->data))->daddr.ipv4)
1324 +#define store_orig_dstaddr(skb) (skb_origaddr(skb) = (skb)->nh.iph->daddr)
1325 +#define dnat_took_place(skb) (skb_origaddr(skb) != (skb)->nh.iph->daddr)
1326 +
1327 +#define has_bridge_parent(device) ((device)->br_port != NULL)
1328 +#define bridge_parent(device) (&((device)->br_port->br->dev))
1329 +
1330 +#ifdef CONFIG_SYSCTL
1331 +static struct ctl_table_header *brnf_sysctl_header;
1332 +static int brnf_call_iptables = 1;
1333 +static int brnf_call_arptables = 1;
1334 +static int brnf_filter_vlan_tagged = 1;
1335 +#else
1336 +#define brnf_filter_vlan_tagged 1
1337 +#endif
1338 +
1339 +#define IS_VLAN_IP (skb->protocol == __constant_htons(ETH_P_8021Q) && \
1340 + hdr->h_vlan_encapsulated_proto == __constant_htons(ETH_P_IP) && \
1341 + brnf_filter_vlan_tagged)
1342 +/*
1343 +#define IS_VLAN_ARP (skb->protocol == __constant_htons(ETH_P_8021Q) && \
1344 + hdr->h_vlan_encapsulated_proto == __constant_htons(ETH_P_ARP) && \
1345 + brnf_filter_vlan_tagged)
1346 +*/
1347 +
1348 +/* We need these fake structures to make netfilter happy --
1349 + * lots of places assume that skb->dst != NULL, which isn't
1350 + * all that unreasonable.
1351 + *
1352 + * Currently, we fill in the PMTU entry because netfilter
1353 + * refragmentation needs it, and the rt_flags entry because
1354 + * ipt_REJECT needs it. Future netfilter modules might
1355 + * require us to fill additional fields.
1356 + */
1357 +static struct net_device __fake_net_device = {
1358 + .hard_header_len = ETH_HLEN
1359 +};
1360 +
1361 +static struct rtable __fake_rtable = {
1362 + u: {
1363 + dst: {
1364 + __refcnt: ATOMIC_INIT(1),
1365 + dev: &__fake_net_device,
1366 + pmtu: 1500
1367 + }
1368 + },
1369 +
1370 + rt_flags: 0
1371 +};
1372 +
1373 +
1374 +/* PF_BRIDGE/PRE_ROUTING *********************************************/
1375 +static void __br_dnat_complain(void)
1376 +{
1377 + static unsigned long last_complaint;
1378 +
1379 + if (jiffies - last_complaint >= 5 * HZ) {
1380 + printk(KERN_WARNING "Performing cross-bridge DNAT requires IP "
1381 + "forwarding to be enabled\n");
1382 + last_complaint = jiffies;
1383 + }
1384 +}
1385 +
1386 +
1387 +/* This requires some explaining. If DNAT has taken place,
1388 + * we will need to fix up the destination Ethernet address,
1389 + * and this is a tricky process.
1390 + *
1391 + * There are two cases to consider:
1392 + * 1. The packet was DNAT'ed to a device in the same bridge
1393 + * port group as it was received on. We can still bridge
1394 + * the packet.
1395 + * 2. The packet was DNAT'ed to a different device, either
1396 + * a non-bridged device or another bridge port group.
1397 + * The packet will need to be routed.
1398 + *
1399 + * The correct way of distinguishing between these two cases is to
1400 + * call ip_route_input() and to look at skb->dst->dev, which is
1401 + * changed to the destination device if ip_route_input() succeeds.
1402 + *
1403 + * Let us first consider the case that ip_route_input() succeeds:
1404 + *
1405 + * If skb->dst->dev equals the logical bridge device the packet
1406 + * came in on, we can consider this bridging. We then call
1407 + * skb->dst->output() which will make the packet enter br_nf_local_out()
1408 + * not much later. In that function it is assured that the iptables
1409 + * FORWARD chain is traversed for the packet.
1410 + *
1411 + * Otherwise, the packet is considered to be routed and we just
1412 + * change the destination MAC address so that the packet will
1413 + * later be passed up to the IP stack to be routed.
1414 + *
1415 + * Let us now consider the case that ip_route_input() fails:
1416 + *
1417 + * After a "echo '0' > /proc/sys/net/ipv4/ip_forward" ip_route_input()
1418 + * will fail, while __ip_route_output_key() will return success. The source
1419 + * address for __ip_route_output_key() is set to zero, so __ip_route_output_key
1420 + * thinks we're handling a locally generated packet and won't care
1421 + * if IP forwarding is allowed. We send a warning message to the users's
1422 + * log telling her to put IP forwarding on.
1423 + *
1424 + * ip_route_input() will also fail if there is no route available.
1425 + * In that case we just drop the packet.
1426 + *
1427 + * --Lennert, 20020411
1428 + * --Bart, 20020416 (updated)
1429 + * --Bart, 20021007 (updated)
1430 + */
1431 +
1432 +static int br_nf_pre_routing_finish_bridge(struct sk_buff *skb)
1433 +{
1434 +#ifdef CONFIG_NETFILTER_DEBUG
1435 + skb->nf_debug |= (1 << NF_BR_PRE_ROUTING) | (1 << NF_BR_FORWARD);
1436 +#endif
1437 +
1438 + if (skb->pkt_type == PACKET_OTHERHOST) {
1439 + skb->pkt_type = PACKET_HOST;
1440 + skb->nf_bridge->mask |= BRNF_PKT_TYPE;
1441 + }
1442 + skb->nf_bridge->mask ^= BRNF_NF_BRIDGE_PREROUTING;
1443 +
1444 + skb->dev = bridge_parent(skb->dev);
1445 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
1446 + skb_pull(skb, VLAN_HLEN);
1447 + skb->nh.raw += VLAN_HLEN;
1448 + }
1449 + skb->dst->output(skb);
1450 + return 0;
1451 +}
1452 +
1453 +static int br_nf_pre_routing_finish(struct sk_buff *skb)
1454 +{
1455 + struct net_device *dev = skb->dev;
1456 + struct iphdr *iph = skb->nh.iph;
1457 + struct nf_bridge_info *nf_bridge = skb->nf_bridge;
1458 +
1459 +#ifdef CONFIG_NETFILTER_DEBUG
1460 + skb->nf_debug ^= (1 << NF_BR_PRE_ROUTING);
1461 +#endif
1462 +
1463 + if (nf_bridge->mask & BRNF_PKT_TYPE) {
1464 + skb->pkt_type = PACKET_OTHERHOST;
1465 + nf_bridge->mask ^= BRNF_PKT_TYPE;
1466 + }
1467 + nf_bridge->mask ^= BRNF_NF_BRIDGE_PREROUTING;
1468 +
1469 + if (dnat_took_place(skb)) {
1470 + if (ip_route_input(skb, iph->daddr, iph->saddr, iph->tos,
1471 + dev)) {
1472 + struct rtable *rt;
1473 +
1474 + if (!ip_route_output(&rt, iph->daddr, 0, iph->tos, 0)) {
1475 + /* Bridged-and-DNAT'ed traffic doesn't
1476 + * require ip_forwarding.
1477 + */
1478 + if (((struct dst_entry *)rt)->dev == dev) {
1479 + skb->dst = (struct dst_entry *)rt;
1480 + goto bridged_dnat;
1481 + }
1482 + __br_dnat_complain();
1483 + dst_release((struct dst_entry *)rt);
1484 + }
1485 + kfree_skb(skb);
1486 + return 0;
1487 + } else {
1488 + if (skb->dst->dev == dev) {
1489 +bridged_dnat:
1490 + /* Tell br_nf_local_out this is a
1491 + * bridged frame
1492 + */
1493 + nf_bridge->mask |= BRNF_BRIDGED_DNAT;
1494 + skb->dev = nf_bridge->physindev;
1495 + if (skb->protocol ==
1496 + __constant_htons(ETH_P_8021Q)) {
1497 + skb_push(skb, VLAN_HLEN);
1498 + skb->nh.raw -= VLAN_HLEN;
1499 + }
1500 + NF_HOOK_THRESH(PF_BRIDGE, NF_BR_PRE_ROUTING,
1501 + skb, skb->dev, NULL,
1502 + br_nf_pre_routing_finish_bridge,
1503 + 1);
1504 + return 0;
1505 + }
1506 + memcpy(skb->mac.ethernet->h_dest, dev->dev_addr,
1507 + ETH_ALEN);
1508 + skb->pkt_type = PACKET_HOST;
1509 + }
1510 + } else {
1511 + skb->dst = (struct dst_entry *)&__fake_rtable;
1512 + dst_hold(skb->dst);
1513 + }
1514 +
1515 + skb->dev = nf_bridge->physindev;
1516 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
1517 + skb_push(skb, VLAN_HLEN);
1518 + skb->nh.raw -= VLAN_HLEN;
1519 + }
1520 + NF_HOOK_THRESH(PF_BRIDGE, NF_BR_PRE_ROUTING, skb, skb->dev, NULL,
1521 + br_handle_frame_finish, 1);
1522 +
1523 + return 0;
1524 +}
1525 +
1526 +/* Replicate the checks that IPv4 does on packet reception.
1527 + * Set skb->dev to the bridge device (i.e. parent of the
1528 + * receiving device) to make netfilter happy, the REDIRECT
1529 + * target in particular. Save the original destination IP
1530 + * address to be able to detect DNAT afterwards.
1531 + */
1532 +static unsigned int br_nf_pre_routing(unsigned int hook, struct sk_buff **pskb,
1533 + const struct net_device *in, const struct net_device *out,
1534 + int (*okfn)(struct sk_buff *))
1535 +{
1536 + struct iphdr *iph;
1537 + __u32 len;
1538 + struct sk_buff *skb = *pskb;
1539 + struct nf_bridge_info *nf_bridge;
1540 +
1541 +#ifdef CONFIG_SYSCTL
1542 + if (!brnf_call_iptables)
1543 + return NF_ACCEPT;
1544 +#endif
1545 +
1546 + if (skb->protocol != __constant_htons(ETH_P_IP)) {
1547 + struct vlan_ethhdr *hdr = (struct vlan_ethhdr *)
1548 + ((*pskb)->mac.ethernet);
1549 +
1550 + if (!IS_VLAN_IP)
1551 + return NF_ACCEPT;
1552 + if ((skb = skb_share_check(*pskb, GFP_ATOMIC)) == NULL)
1553 + goto out;
1554 + skb_pull(*pskb, VLAN_HLEN);
1555 + (*pskb)->nh.raw += VLAN_HLEN;
1556 + } else if ((skb = skb_share_check(*pskb, GFP_ATOMIC)) == NULL)
1557 + goto out;
1558 +
1559 + if (!pskb_may_pull(skb, sizeof(struct iphdr)))
1560 + goto inhdr_error;
1561 +
1562 + iph = skb->nh.iph;
1563 + if (iph->ihl < 5 || iph->version != 4)
1564 + goto inhdr_error;
1565 +
1566 + if (!pskb_may_pull(skb, 4*iph->ihl))
1567 + goto inhdr_error;
1568 +
1569 + iph = skb->nh.iph;
1570 + if (ip_fast_csum((__u8 *)iph, iph->ihl) != 0)
1571 + goto inhdr_error;
1572 +
1573 + len = ntohs(iph->tot_len);
1574 + if (skb->len < len || len < 4*iph->ihl)
1575 + goto inhdr_error;
1576 +
1577 + if (skb->len > len) {
1578 + __pskb_trim(skb, len);
1579 + if (skb->ip_summed == CHECKSUM_HW)
1580 + skb->ip_summed = CHECKSUM_NONE;
1581 + }
1582 +
1583 +#ifdef CONFIG_NETFILTER_DEBUG
1584 + skb->nf_debug ^= (1 << NF_IP_PRE_ROUTING);
1585 +#endif
1586 + if ((nf_bridge = nf_bridge_alloc(skb)) == NULL)
1587 + return NF_DROP;
1588 +
1589 + if (skb->pkt_type == PACKET_OTHERHOST) {
1590 + skb->pkt_type = PACKET_HOST;
1591 + nf_bridge->mask |= BRNF_PKT_TYPE;
1592 + }
1593 +
1594 + nf_bridge->mask |= BRNF_NF_BRIDGE_PREROUTING;
1595 + nf_bridge->physindev = skb->dev;
1596 + skb->dev = bridge_parent(skb->dev);
1597 + store_orig_dstaddr(skb);
1598 +
1599 + NF_HOOK(PF_INET, NF_IP_PRE_ROUTING, skb, skb->dev, NULL,
1600 + br_nf_pre_routing_finish);
1601 +
1602 + return NF_STOLEN;
1603 +
1604 +inhdr_error:
1605 +// IP_INC_STATS_BH(IpInHdrErrors);
1606 +out:
1607 + return NF_DROP;
1608 +}
1609 +
1610 +
1611 +/* PF_BRIDGE/LOCAL_IN ************************************************/
1612 +/* The packet is locally destined, which requires a real
1613 + * dst_entry, so detach the fake one. On the way up, the
1614 + * packet would pass through PRE_ROUTING again (which already
1615 + * took place when the packet entered the bridge), but we
1616 + * register an IPv4 PRE_ROUTING 'sabotage' hook that will
1617 + * prevent this from happening.
1618 + */
1619 +static unsigned int br_nf_local_in(unsigned int hook, struct sk_buff **pskb,
1620 + const struct net_device *in, const struct net_device *out,
1621 + int (*okfn)(struct sk_buff *))
1622 +{
1623 + struct sk_buff *skb = *pskb;
1624 +
1625 + if (skb->dst == (struct dst_entry *)&__fake_rtable) {
1626 + dst_release(skb->dst);
1627 + skb->dst = NULL;
1628 + }
1629 +
1630 + return NF_ACCEPT;
1631 +}
1632 +
1633 +/* PF_BRIDGE/FORWARD *************************************************/
1634 +static int br_nf_forward_finish(struct sk_buff *skb)
1635 +{
1636 + struct nf_bridge_info *nf_bridge = skb->nf_bridge;
1637 + struct net_device *in;
1638 + struct vlan_ethhdr *hdr = (struct vlan_ethhdr *)(skb->mac.ethernet);
1639 +
1640 +#ifdef CONFIG_NETFILTER_DEBUG
1641 + skb->nf_debug ^= (1 << NF_BR_FORWARD);
1642 +#endif
1643 +
1644 + if (skb->protocol == __constant_htons(ETH_P_IP) || IS_VLAN_IP) {
1645 + in = nf_bridge->physindev;
1646 + if (nf_bridge->mask & BRNF_PKT_TYPE) {
1647 + skb->pkt_type = PACKET_OTHERHOST;
1648 + nf_bridge->mask ^= BRNF_PKT_TYPE;
1649 + }
1650 + } else {
1651 + in = *((struct net_device **)(skb->cb));
1652 + }
1653 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
1654 + skb_push(skb, VLAN_HLEN);
1655 + skb->nh.raw -= VLAN_HLEN;
1656 + }
1657 + NF_HOOK_THRESH(PF_BRIDGE, NF_BR_FORWARD, skb, in,
1658 + skb->dev, br_forward_finish, 1);
1659 + return 0;
1660 +}
1661 +
1662 +/* This is the 'purely bridged' case. For IP, we pass the packet to
1663 + * netfilter with indev and outdev set to the bridge device,
1664 + * but we are still able to filter on the 'real' indev/outdev
1665 + * because of the ipt_physdev.c module. For ARP, indev and outdev are the
1666 + * bridge ports.
1667 + */
1668 +static unsigned int br_nf_forward_ip(unsigned int hook, struct sk_buff **pskb,
1669 + const struct net_device *in, const struct net_device *out,
1670 + int (*okfn)(struct sk_buff *))
1671 +{
1672 + struct sk_buff *skb = *pskb;
1673 + struct nf_bridge_info *nf_bridge;
1674 + struct vlan_ethhdr *hdr = (struct vlan_ethhdr *)(skb->mac.ethernet);
1675 +
1676 +#ifdef CONFIG_SYSCTL
1677 + if (!skb->nf_bridge)
1678 + return NF_ACCEPT;
1679 +#endif
1680 +
1681 + if (skb->protocol != __constant_htons(ETH_P_IP)) {
1682 + if (!IS_VLAN_IP)
1683 + return NF_ACCEPT;
1684 + skb_pull(*pskb, VLAN_HLEN);
1685 + (*pskb)->nh.raw += VLAN_HLEN;
1686 + }
1687 +
1688 +#ifdef CONFIG_NETFILTER_DEBUG
1689 + skb->nf_debug ^= (1 << NF_BR_FORWARD);
1690 +#endif
1691 + nf_bridge = skb->nf_bridge;
1692 + if (skb->pkt_type == PACKET_OTHERHOST) {
1693 + skb->pkt_type = PACKET_HOST;
1694 + nf_bridge->mask |= BRNF_PKT_TYPE;
1695 + }
1696 +
1697 + /* The physdev module checks on this */
1698 + nf_bridge->mask |= BRNF_BRIDGED;
1699 + nf_bridge->physoutdev = skb->dev;
1700 +
1701 + NF_HOOK(PF_INET, NF_IP_FORWARD, skb, bridge_parent(in),
1702 + bridge_parent(out), br_nf_forward_finish);
1703 +
1704 + return NF_STOLEN;
1705 +}
1706 +
1707 +/*
1708 +static unsigned int br_nf_forward_arp(unsigned int hook, struct sk_buff **pskb,
1709 + const struct net_device *in, const struct net_device *out,
1710 + int (*okfn)(struct sk_buff *))
1711 +{
1712 + struct sk_buff *skb = *pskb;
1713 + struct vlan_ethhdr *hdr = (struct vlan_ethhdr *)(skb->mac.ethernet);
1714 + struct net_device **d = (struct net_device **)(skb->cb);
1715 +
1716 + if (!brnf_call_arptables)
1717 + return NF_ACCEPT;
1718 +
1719 + if (skb->protocol != __constant_htons(ETH_P_ARP)) {
1720 + if (!IS_VLAN_ARP)
1721 + return NF_ACCEPT;
1722 + skb_pull(*pskb, VLAN_HLEN);
1723 + (*pskb)->nh.raw += VLAN_HLEN;
1724 + }
1725 +
1726 +#ifdef CONFIG_NETFILTER_DEBUG
1727 + skb->nf_debug ^= (1 << NF_BR_FORWARD);
1728 +#endif
1729 +
1730 + if (skb->nh.arph->ar_pln != 4) {
1731 + if (IS_VLAN_ARP) {
1732 + skb_push(*pskb, VLAN_HLEN);
1733 + (*pskb)->nh.raw -= VLAN_HLEN;
1734 + }
1735 + return NF_ACCEPT;
1736 + }
1737 + *d = (struct net_device *)in;
1738 + NF_HOOK(NF_ARP, NF_ARP_FORWARD, skb, (struct net_device *)in,
1739 + (struct net_device *)out, br_nf_forward_finish);
1740 +
1741 + return NF_STOLEN;
1742 +}
1743 +*/
1744 +
1745 +/* PF_BRIDGE/LOCAL_OUT ***********************************************/
1746 +static int br_nf_local_out_finish(struct sk_buff *skb)
1747 +{
1748 +#ifdef CONFIG_NETFILTER_DEBUG
1749 + skb->nf_debug &= ~(1 << NF_BR_LOCAL_OUT);
1750 +#endif
1751 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
1752 + skb_push(skb, VLAN_HLEN);
1753 + skb->nh.raw -= VLAN_HLEN;
1754 + }
1755 +
1756 + NF_HOOK_THRESH(PF_BRIDGE, NF_BR_LOCAL_OUT, skb, NULL, skb->dev,
1757 + br_forward_finish, NF_BR_PRI_FIRST + 1);
1758 +
1759 + return 0;
1760 +}
1761 +
1762 +
1763 +/* This function sees both locally originated IP packets and forwarded
1764 + * IP packets (in both cases the destination device is a bridge
1765 + * device). It also sees bridged-and-DNAT'ed packets.
1766 + * To be able to filter on the physical bridge devices (with the ipt_physdev.c
1767 + * module), we steal packets destined to a bridge device away from the
1768 + * PF_INET/FORWARD and PF_INET/OUTPUT hook functions, and give them back later,
1769 + * when we have determined the real output device. This is done in here.
1770 + *
1771 + * If (nf_bridge->mask & BRNF_BRIDGED_DNAT) then the packet is bridged
1772 + * and we fake the PF_BRIDGE/FORWARD hook. The function br_nf_forward()
1773 + * will then fake the PF_INET/FORWARD hook. br_nf_local_out() has priority
1774 + * NF_BR_PRI_FIRST, so no relevant PF_BRIDGE/INPUT functions have been nor
1775 + * will be executed.
1776 + * Otherwise, if nf_bridge->physindev is NULL, the bridge-nf code never touched
1777 + * this packet before, and so the packet was locally originated. We fake
1778 + * the PF_INET/LOCAL_OUT hook.
1779 + * Finally, if nf_bridge->physindev isn't NULL, then the packet was IP routed,
1780 + * so we fake the PF_INET/FORWARD hook. ipv4_sabotage_out() makes sure
1781 + * even routed packets that didn't arrive on a bridge interface have their
1782 + * nf_bridge->physindev set.
1783 + */
1784 +
1785 +static unsigned int br_nf_local_out(unsigned int hook, struct sk_buff **pskb,
1786 + const struct net_device *in, const struct net_device *out,
1787 + int (*_okfn)(struct sk_buff *))
1788 +{
1789 + int (*okfn)(struct sk_buff *skb);
1790 + struct net_device *realindev;
1791 + struct sk_buff *skb = *pskb;
1792 + struct nf_bridge_info *nf_bridge;
1793 + struct vlan_ethhdr *hdr = (struct vlan_ethhdr *)(skb->mac.ethernet);
1794 +
1795 +#ifdef CONFIG_SYSCTL
1796 + if (!skb->nf_bridge)
1797 + return NF_ACCEPT;
1798 +#endif
1799 +
1800 + if (skb->protocol != __constant_htons(ETH_P_IP) && !IS_VLAN_IP)
1801 + return NF_ACCEPT;
1802 +
1803 + /* Sometimes we get packets with NULL ->dst here (for example,
1804 + * running a dhcp client daemon triggers this).
1805 + */
1806 + if (skb->dst == NULL)
1807 + return NF_ACCEPT;
1808 +
1809 + nf_bridge = skb->nf_bridge;
1810 + nf_bridge->physoutdev = skb->dev;
1811 + realindev = nf_bridge->physindev;
1812 +
1813 + /* Bridged, take PF_BRIDGE/FORWARD.
1814 + * (see big note in front of br_nf_pre_routing_finish)
1815 + */
1816 + if (nf_bridge->mask & BRNF_BRIDGED_DNAT) {
1817 + okfn = br_forward_finish;
1818 +
1819 + if (nf_bridge->mask & BRNF_PKT_TYPE) {
1820 + skb->pkt_type = PACKET_OTHERHOST;
1821 + nf_bridge->mask ^= BRNF_PKT_TYPE;
1822 + }
1823 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
1824 + skb_push(skb, VLAN_HLEN);
1825 + skb->nh.raw -= VLAN_HLEN;
1826 + }
1827 +
1828 + NF_HOOK(PF_BRIDGE, NF_BR_FORWARD, skb, realindev,
1829 + skb->dev, okfn);
1830 + } else {
1831 + struct net_device *realoutdev = bridge_parent(skb->dev);
1832 +
1833 +#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
1834 + /* iptables should match -o br0.x */
1835 + if (nf_bridge->netoutdev)
1836 + realoutdev = nf_bridge->netoutdev;
1837 +#endif
1838 + okfn = br_nf_local_out_finish;
1839 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
1840 + skb_pull(skb, VLAN_HLEN);
1841 + (*pskb)->nh.raw += VLAN_HLEN;
1842 + }
1843 + /* IP forwarded traffic has a physindev, locally
1844 + * generated traffic hasn't.
1845 + */
1846 + if (realindev != NULL) {
1847 + if (((nf_bridge->mask & BRNF_DONT_TAKE_PARENT) == 0) &&
1848 + has_bridge_parent(realindev))
1849 + realindev = bridge_parent(realindev);
1850 + NF_HOOK_THRESH(PF_INET, NF_IP_FORWARD, skb, realindev,
1851 + realoutdev, okfn,
1852 + NF_IP_PRI_BRIDGE_SABOTAGE_FORWARD + 1);
1853 + } else {
1854 +#ifdef CONFIG_NETFILTER_DEBUG
1855 + skb->nf_debug ^= (1 << NF_IP_LOCAL_OUT);
1856 +#endif
1857 +
1858 + NF_HOOK_THRESH(PF_INET, NF_IP_LOCAL_OUT, skb, realindev,
1859 + realoutdev, okfn,
1860 + NF_IP_PRI_BRIDGE_SABOTAGE_LOCAL_OUT + 1);
1861 + }
1862 + }
1863 +
1864 + return NF_STOLEN;
1865 +}
1866 +
1867 +
1868 +/* PF_BRIDGE/POST_ROUTING ********************************************/
1869 +static unsigned int br_nf_post_routing(unsigned int hook, struct sk_buff **pskb,
1870 + const struct net_device *in, const struct net_device *out,
1871 + int (*okfn)(struct sk_buff *))
1872 +{
1873 + struct sk_buff *skb = *pskb;
1874 + struct nf_bridge_info *nf_bridge = (*pskb)->nf_bridge;
1875 + struct vlan_ethhdr *hdr = (struct vlan_ethhdr *)(skb->mac.ethernet);
1876 + struct net_device *realoutdev = bridge_parent(skb->dev);
1877 +
1878 +#ifdef CONFIG_NETFILTER_DEBUG
1879 + /* Be very paranoid. This probably won't happen anymore, but let's
1880 + * keep the check just to be sure... */
1881 + if (skb->mac.raw < skb->head || skb->mac.raw + ETH_HLEN > skb->data) {
1882 + printk(KERN_CRIT "br_netfilter: Argh!! br_nf_post_routing: "
1883 + "bad mac.raw pointer.");
1884 + goto print_error;
1885 + }
1886 +#endif
1887 +
1888 +#ifdef CONFIG_SYSCTL
1889 + if (!nf_bridge)
1890 + return NF_ACCEPT;
1891 +#endif
1892 +
1893 + if (skb->protocol != __constant_htons(ETH_P_IP) && !IS_VLAN_IP)
1894 + return NF_ACCEPT;
1895 +
1896 + /* Sometimes we get packets with NULL ->dst here (for example,
1897 + * running a dhcp client daemon triggers this).
1898 + */
1899 + if (skb->dst == NULL)
1900 + return NF_ACCEPT;
1901 +
1902 +#ifdef CONFIG_NETFILTER_DEBUG
1903 + /* Sometimes we get packets with NULL ->dst here (for example,
1904 + * running a dhcp client daemon triggers this). This should now
1905 + * be fixed, but let's keep the check around.
1906 + */
1907 + if (skb->dst == NULL) {
1908 + printk(KERN_CRIT "br_netfilter: skb->dst == NULL.");
1909 + goto print_error;
1910 + }
1911 +
1912 + skb->nf_debug ^= (1 << NF_IP_POST_ROUTING);
1913 +#endif
1914 +
1915 + /* We assume any code from br_dev_queue_push_xmit onwards doesn't care
1916 + * about the value of skb->pkt_type.
1917 + */
1918 + if (skb->pkt_type == PACKET_OTHERHOST) {
1919 + skb->pkt_type = PACKET_HOST;
1920 + nf_bridge->mask |= BRNF_PKT_TYPE;
1921 + }
1922 +
1923 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
1924 + skb_pull(skb, VLAN_HLEN);
1925 + skb->nh.raw += VLAN_HLEN;
1926 + }
1927 +
1928 + nf_bridge_save_header(skb);
1929 +
1930 +#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
1931 + if (nf_bridge->netoutdev)
1932 + realoutdev = nf_bridge->netoutdev;
1933 +#endif
1934 + NF_HOOK(PF_INET, NF_IP_POST_ROUTING, skb, NULL,
1935 + realoutdev, br_dev_queue_push_xmit);
1936 +
1937 + return NF_STOLEN;
1938 +
1939 +#ifdef CONFIG_NETFILTER_DEBUG
1940 +print_error:
1941 + if (skb->dev != NULL) {
1942 + printk("[%s]", skb->dev->name);
1943 + if (has_bridge_parent(skb->dev))
1944 + printk("[%s]", bridge_parent(skb->dev)->name);
1945 + }
1946 + printk(" head:%p, raw:%p, data:%p\n", skb->head, skb->mac.raw,
1947 + skb->data);
1948 + return NF_ACCEPT;
1949 +#endif
1950 +}
1951 +
1952 +
1953 +/* IPv4/SABOTAGE *****************************************************/
1954 +
1955 +/* Don't hand locally destined packets to PF_INET/PRE_ROUTING
1956 + * for the second time.
1957 + */
1958 +static unsigned int ipv4_sabotage_in(unsigned int hook, struct sk_buff **pskb,
1959 + const struct net_device *in, const struct net_device *out,
1960 + int (*okfn)(struct sk_buff *))
1961 +{
1962 + if ((*pskb)->nf_bridge &&
1963 + !((*pskb)->nf_bridge->mask & BRNF_NF_BRIDGE_PREROUTING)) {
1964 + okfn(*pskb);
1965 + return NF_STOLEN;
1966 + }
1967 +
1968 + return NF_ACCEPT;
1969 +}
1970 +
1971 +/* Postpone execution of PF_INET/FORWARD, PF_INET/LOCAL_OUT
1972 + * and PF_INET/POST_ROUTING until we have done the forwarding
1973 + * decision in the bridge code and have determined skb->physoutdev.
1974 + */
1975 +static unsigned int ipv4_sabotage_out(unsigned int hook, struct sk_buff **pskb,
1976 + const struct net_device *in, const struct net_device *out,
1977 + int (*okfn)(struct sk_buff *))
1978 +{
1979 + struct sk_buff *skb = *pskb;
1980 +
1981 +#ifdef CONFIG_SYSCTL
1982 + if (!brnf_call_iptables && !skb->nf_bridge)
1983 + return NF_ACCEPT;
1984 +#endif
1985 +
1986 + if ((out->hard_start_xmit == br_dev_xmit &&
1987 + okfn != br_nf_forward_finish &&
1988 + okfn != br_nf_local_out_finish &&
1989 + okfn != br_dev_queue_push_xmit)
1990 +#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
1991 + || ((out->priv_flags & IFF_802_1Q_VLAN) &&
1992 + VLAN_DEV_INFO(out)->real_dev->hard_start_xmit == br_dev_xmit)
1993 +#endif
1994 + ) {
1995 + struct nf_bridge_info *nf_bridge;
1996 +
1997 + if (!skb->nf_bridge && !nf_bridge_alloc(skb))
1998 + return NF_DROP;
1999 +
2000 + nf_bridge = skb->nf_bridge;
2001 +
2002 + /* This frame will arrive on PF_BRIDGE/LOCAL_OUT and we
2003 + * will need the indev then. For a brouter, the real indev
2004 + * can be a bridge port, so we make sure br_nf_local_out()
2005 + * doesn't use the bridge parent of the indev by using
2006 + * the BRNF_DONT_TAKE_PARENT mask.
2007 + */
2008 + if (hook == NF_IP_FORWARD && nf_bridge->physindev == NULL) {
2009 + nf_bridge->mask &= BRNF_DONT_TAKE_PARENT;
2010 + nf_bridge->physindev = (struct net_device *)in;
2011 + }
2012 +#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
2013 + /* the iptables outdev is br0.x, not br0 */
2014 + if (out->priv_flags & IFF_802_1Q_VLAN)
2015 + nf_bridge->netoutdev = (struct net_device *)out;
2016 +#endif
2017 + okfn(skb);
2018 + return NF_STOLEN;
2019 + }
2020 +
2021 + return NF_ACCEPT;
2022 +}
2023 +
2024 +/* For br_nf_local_out we need (prio = NF_BR_PRI_FIRST), to insure that innocent
2025 + * PF_BRIDGE/NF_BR_LOCAL_OUT functions don't get bridged traffic as input.
2026 + * For br_nf_post_routing, we need (prio = NF_BR_PRI_LAST), because
2027 + * ip_refrag() can return NF_STOLEN.
2028 + */
2029 +static struct nf_hook_ops br_nf_ops[] = {
2030 + { .hook = br_nf_pre_routing,
2031 + .pf = PF_BRIDGE,
2032 + .hooknum = NF_BR_PRE_ROUTING,
2033 + .priority = NF_BR_PRI_BRNF, },
2034 + { .hook = br_nf_local_in,
2035 + .pf = PF_BRIDGE,
2036 + .hooknum = NF_BR_LOCAL_IN,
2037 + .priority = NF_BR_PRI_BRNF, },
2038 + { .hook = br_nf_forward_ip,
2039 + .pf = PF_BRIDGE,
2040 + .hooknum = NF_BR_FORWARD,
2041 + .priority = NF_BR_PRI_BRNF /*- 1*/, },
2042 +/* { .hook = br_nf_forward_arp,
2043 + .pf = PF_BRIDGE,
2044 + .hooknum = NF_BR_FORWARD,
2045 + .priority = NF_BR_PRI_BRNF, },*/
2046 + { .hook = br_nf_local_out,
2047 + .pf = PF_BRIDGE,
2048 + .hooknum = NF_BR_LOCAL_OUT,
2049 + .priority = NF_BR_PRI_FIRST, },
2050 + { .hook = br_nf_post_routing,
2051 + .pf = PF_BRIDGE,
2052 + .hooknum = NF_BR_POST_ROUTING,
2053 + .priority = NF_BR_PRI_LAST, },
2054 + { .hook = ipv4_sabotage_in,
2055 + .pf = PF_INET,
2056 + .hooknum = NF_IP_PRE_ROUTING,
2057 + .priority = NF_IP_PRI_FIRST, },
2058 + { .hook = ipv4_sabotage_out,
2059 + .pf = PF_INET,
2060 + .hooknum = NF_IP_FORWARD,
2061 + .priority = NF_IP_PRI_BRIDGE_SABOTAGE_FORWARD, },
2062 + { .hook = ipv4_sabotage_out,
2063 + .pf = PF_INET,
2064 + .hooknum = NF_IP_LOCAL_OUT,
2065 + .priority = NF_IP_PRI_BRIDGE_SABOTAGE_LOCAL_OUT, },
2066 + { .hook = ipv4_sabotage_out,
2067 + .pf = PF_INET,
2068 + .hooknum = NF_IP_POST_ROUTING,
2069 + .priority = NF_IP_PRI_FIRST, },
2070 +};
2071 +
2072 +#ifdef CONFIG_SYSCTL
2073 +static
2074 +int brnf_sysctl_call_tables(ctl_table *ctl, int write, struct file * filp,
2075 + void *buffer, size_t *lenp)
2076 +{
2077 + int ret;
2078 +
2079 + ret = proc_dointvec(ctl, write, filp, buffer, lenp);
2080 +
2081 + if (write && *(int *)(ctl->data))
2082 + *(int *)(ctl->data) = 1;
2083 + return ret;
2084 +}
2085 +
2086 +static ctl_table brnf_table[] = {
2087 + {
2088 + .ctl_name = NET_BRIDGE_NF_CALL_ARPTABLES,
2089 + .procname = "bridge-nf-call-arptables",
2090 + .data = &brnf_call_arptables,
2091 + .maxlen = sizeof(int),
2092 + .mode = 0644,
2093 + .proc_handler = &brnf_sysctl_call_tables,
2094 + },
2095 + {
2096 + .ctl_name = NET_BRIDGE_NF_CALL_IPTABLES,
2097 + .procname = "bridge-nf-call-iptables",
2098 + .data = &brnf_call_iptables,
2099 + .maxlen = sizeof(int),
2100 + .mode = 0644,
2101 + .proc_handler = &brnf_sysctl_call_tables,
2102 + },
2103 + {
2104 + .ctl_name = NET_BRIDGE_NF_FILTER_VLAN_TAGGED,
2105 + .procname = "bridge-nf-filter-vlan-tagged",
2106 + .data = &brnf_filter_vlan_tagged,
2107 + .maxlen = sizeof(int),
2108 + .mode = 0644,
2109 + .proc_handler = &brnf_sysctl_call_tables,
2110 + },
2111 + { .ctl_name = 0 }
2112 +};
2113 +
2114 +static ctl_table brnf_bridge_table[] = {
2115 + {
2116 + .ctl_name = NET_BRIDGE,
2117 + .procname = "bridge",
2118 + .mode = 0555,
2119 + .child = brnf_table,
2120 + },
2121 + { .ctl_name = 0 }
2122 +};
2123 +
2124 +static ctl_table brnf_net_table[] = {
2125 + {
2126 + .ctl_name = CTL_NET,
2127 + .procname = "net",
2128 + .mode = 0555,
2129 + .child = brnf_bridge_table,
2130 + },
2131 + { .ctl_name = 0 }
2132 +};
2133 +#endif
2134 +
2135 +int br_netfilter_init(void)
2136 +{
2137 + int i;
2138 +
2139 + for (i = 0; i < ARRAY_SIZE(br_nf_ops); i++) {
2140 + int ret;
2141 +
2142 + if ((ret = nf_register_hook(&br_nf_ops[i])) >= 0)
2143 + continue;
2144 +
2145 + while (i--)
2146 + nf_unregister_hook(&br_nf_ops[i]);
2147 +
2148 + return ret;
2149 + }
2150 +
2151 +#ifdef CONFIG_SYSCTL
2152 + brnf_sysctl_header = register_sysctl_table(brnf_net_table, 0);
2153 + if (brnf_sysctl_header == NULL) {
2154 + printk(KERN_WARNING "br_netfilter: can't register to sysctl.\n");
2155 + for (i = 0; i < ARRAY_SIZE(br_nf_ops); i++)
2156 + nf_unregister_hook(&br_nf_ops[i]);
2157 + return -EFAULT;
2158 + }
2159 +#endif
2160 +
2161 + printk(KERN_NOTICE "Bridge firewalling registered\n");
2162 +
2163 + return 0;
2164 +}
2165 +
2166 +void br_netfilter_fini(void)
2167 +{
2168 + int i;
2169 +
2170 + for (i = ARRAY_SIZE(br_nf_ops) - 1; i >= 0; i--)
2171 + nf_unregister_hook(&br_nf_ops[i]);
2172 +#ifdef CONFIG_SYSCTL
2173 + unregister_sysctl_table(brnf_sysctl_header);
2174 +#endif
2175 +
2176 +}
2177 diff -Nurb src/linux/linux.stock/net/bridge/br_private.h src/linux/linux/net/bridge/br_private.h
2178 --- src/linux/linux.stock/net/bridge/br_private.h 2003-10-14 04:09:32.000000000 -0400
2179 +++ src/linux/linux/net/bridge/br_private.h 2004-07-10 23:46:39.000000000 -0400
2180 @@ -145,8 +145,10 @@
2181 /* br_forward.c */
2182 extern void br_deliver(struct net_bridge_port *to,
2183 struct sk_buff *skb);
2184 +extern int br_dev_queue_push_xmit(struct sk_buff *skb);
2185 extern void br_forward(struct net_bridge_port *to,
2186 struct sk_buff *skb);
2187 +extern int br_forward_finish(struct sk_buff *skb);
2188 extern void br_flood_deliver(struct net_bridge *br,
2189 struct sk_buff *skb,
2190 int clone);
2191 @@ -167,7 +169,8 @@
2192 int *ifindices);
2193
2194 /* br_input.c */
2195 -extern void br_handle_frame(struct sk_buff *skb);
2196 +extern int br_handle_frame_finish(struct sk_buff *skb);
2197 +extern int br_handle_frame(struct sk_buff *skb);
2198
2199 /* br_ioctl.c */
2200 extern void br_call_ioctl_atomic(void (*fn)(void));
2201 @@ -178,6 +181,10 @@
2202 unsigned long arg2);
2203 extern int br_ioctl_deviceless_stub(unsigned long arg);
2204
2205 +/* br_netfilter.c */
2206 +extern int br_netfilter_init(void);
2207 +extern void br_netfilter_fini(void);
2208 +
2209 /* br_stp.c */
2210 extern int br_is_root_bridge(struct net_bridge *br);
2211 extern struct net_bridge_port *br_get_port(struct net_bridge *br,
2212 diff -Nurb src/linux/linux.stock/net/bridge/netfilter/Config.in src/linux/linux/net/bridge/netfilter/Config.in
2213 --- src/linux/linux.stock/net/bridge/netfilter/Config.in 1969-12-31 19:00:00.000000000 -0500
2214 +++ src/linux/linux/net/bridge/netfilter/Config.in 2004-07-10 23:46:39.000000000 -0400
2215 @@ -0,0 +1,22 @@
2216 +#
2217 +# Bridge netfilter configuration
2218 +#
2219 +dep_tristate ' Bridge: ebtables' CONFIG_BRIDGE_NF_EBTABLES $CONFIG_BRIDGE
2220 +dep_tristate ' ebt: filter table support' CONFIG_BRIDGE_EBT_T_FILTER $CONFIG_BRIDGE_NF_EBTABLES
2221 +dep_tristate ' ebt: nat table support' CONFIG_BRIDGE_EBT_T_NAT $CONFIG_BRIDGE_NF_EBTABLES
2222 +dep_tristate ' ebt: broute table support' CONFIG_BRIDGE_EBT_BROUTE $CONFIG_BRIDGE_NF_EBTABLES
2223 +dep_tristate ' ebt: log support' CONFIG_BRIDGE_EBT_LOG $CONFIG_BRIDGE_NF_EBTABLES
2224 +dep_tristate ' ebt: IP filter support' CONFIG_BRIDGE_EBT_IPF $CONFIG_BRIDGE_NF_EBTABLES
2225 +dep_tristate ' ebt: ARP filter support' CONFIG_BRIDGE_EBT_ARPF $CONFIG_BRIDGE_NF_EBTABLES
2226 +dep_tristate ' ebt: among filter support' CONFIG_BRIDGE_EBT_AMONG $CONFIG_BRIDGE_NF_EBTABLES
2227 +dep_tristate ' ebt: limit filter support' CONFIG_BRIDGE_EBT_LIMIT $CONFIG_BRIDGE_NF_EBTABLES
2228 +dep_tristate ' ebt: 802.1Q VLAN filter support' CONFIG_BRIDGE_EBT_VLANF $CONFIG_BRIDGE_NF_EBTABLES
2229 +dep_tristate ' ebt: 802.3 filter support' CONFIG_BRIDGE_EBT_802_3 $CONFIG_BRIDGE_NF_EBTABLES
2230 +dep_tristate ' ebt: packet type filter support' CONFIG_BRIDGE_EBT_PKTTYPE $CONFIG_BRIDGE_NF_EBTABLES
2231 +dep_tristate ' ebt: STP filter support' CONFIG_BRIDGE_EBT_STP $CONFIG_BRIDGE_NF_EBTABLES
2232 +dep_tristate ' ebt: mark filter support' CONFIG_BRIDGE_EBT_MARKF $CONFIG_BRIDGE_NF_EBTABLES
2233 +dep_tristate ' ebt: arp reply target support' CONFIG_BRIDGE_EBT_ARPREPLY $CONFIG_BRIDGE_NF_EBTABLES
2234 +dep_tristate ' ebt: snat target support' CONFIG_BRIDGE_EBT_SNAT $CONFIG_BRIDGE_NF_EBTABLES
2235 +dep_tristate ' ebt: dnat target support' CONFIG_BRIDGE_EBT_DNAT $CONFIG_BRIDGE_NF_EBTABLES
2236 +dep_tristate ' ebt: redirect target support' CONFIG_BRIDGE_EBT_REDIRECT $CONFIG_BRIDGE_NF_EBTABLES
2237 +dep_tristate ' ebt: mark target support' CONFIG_BRIDGE_EBT_MARK_T $CONFIG_BRIDGE_NF_EBTABLES
2238 diff -Nurb src/linux/linux.stock/net/bridge/netfilter/Makefile src/linux/linux/net/bridge/netfilter/Makefile
2239 --- src/linux/linux.stock/net/bridge/netfilter/Makefile 1969-12-31 19:00:00.000000000 -0500
2240 +++ src/linux/linux/net/bridge/netfilter/Makefile 2004-07-10 23:46:39.000000000 -0400
2241 @@ -0,0 +1,33 @@
2242 +#
2243 +# Makefile for the netfilter modules on top of bridging.
2244 +#
2245 +# Note! Dependencies are done automagically by 'make dep', which also
2246 +# removes any old dependencies. DON'T put your own dependencies here
2247 +# unless it's something special (ie not a .c file).
2248 +#
2249 +# Note 2! The CFLAGS definition is now in the main makefile...
2250 +
2251 +O_TARGET := netfilter.o
2252 +
2253 +export-objs := ebtables.o
2254 +
2255 +obj-$(CONFIG_BRIDGE_NF_EBTABLES) += ebtables.o
2256 +obj-$(CONFIG_BRIDGE_EBT_T_FILTER) += ebtable_filter.o
2257 +obj-$(CONFIG_BRIDGE_EBT_T_NAT) += ebtable_nat.o
2258 +obj-$(CONFIG_BRIDGE_EBT_BROUTE) += ebtable_broute.o
2259 +obj-$(CONFIG_BRIDGE_EBT_802_3) += ebt_802_3.o
2260 +obj-$(CONFIG_BRIDGE_EBT_ARPF) += ebt_arp.o
2261 +obj-$(CONFIG_BRIDGE_EBT_AMONG) += ebt_among.o
2262 +obj-$(CONFIG_BRIDGE_EBT_IPF) += ebt_ip.o
2263 +obj-$(CONFIG_BRIDGE_EBT_LIMIT) += ebt_limit.o
2264 +obj-$(CONFIG_BRIDGE_EBT_MARKF) += ebt_mark_m.o
2265 +obj-$(CONFIG_BRIDGE_EBT_PKTTYPE) += ebt_pkttype.o
2266 +obj-$(CONFIG_BRIDGE_EBT_STP) += ebt_stp.o
2267 +obj-$(CONFIG_BRIDGE_EBT_VLANF) += ebt_vlan.o
2268 +obj-$(CONFIG_BRIDGE_EBT_LOG) += ebt_log.o
2269 +obj-$(CONFIG_BRIDGE_EBT_ARPREPLY) += ebt_arpreply.o
2270 +obj-$(CONFIG_BRIDGE_EBT_DNAT) += ebt_dnat.o
2271 +obj-$(CONFIG_BRIDGE_EBT_MARK_T) += ebt_mark.o
2272 +obj-$(CONFIG_BRIDGE_EBT_REDIRECT) += ebt_redirect.o
2273 +obj-$(CONFIG_BRIDGE_EBT_SNAT) += ebt_snat.o
2274 +include $(TOPDIR)/Rules.make
2275 diff -Nurb src/linux/linux.stock/net/bridge/netfilter/ebt_802_3.c src/linux/linux/net/bridge/netfilter/ebt_802_3.c
2276 --- src/linux/linux.stock/net/bridge/netfilter/ebt_802_3.c 1969-12-31 19:00:00.000000000 -0500
2277 +++ src/linux/linux/net/bridge/netfilter/ebt_802_3.c 2004-07-10 23:46:39.000000000 -0400
2278 @@ -0,0 +1,74 @@
2279 +/*
2280 + * 802_3
2281 + *
2282 + * Author:
2283 + * Chris Vitale csv@bluetail.com
2284 + *
2285 + * May 2003
2286 + *
2287 + */
2288 +
2289 +#include <linux/netfilter_bridge/ebtables.h>
2290 +#include <linux/netfilter_bridge/ebt_802_3.h>
2291 +#include <linux/module.h>
2292 +
2293 +static int ebt_filter_802_3(const struct sk_buff *skb, const struct net_device *in,
2294 + const struct net_device *out, const void *data, unsigned int datalen)
2295 +{
2296 + struct ebt_802_3_info *info = (struct ebt_802_3_info *)data;
2297 + struct ebt_802_3_hdr *hdr = (struct ebt_802_3_hdr *)skb->mac.ethernet;
2298 + uint16_t type = hdr->llc.ui.ctrl & IS_UI ? hdr->llc.ui.type : hdr->llc.ni.type;
2299 +
2300 + if (info->bitmask & EBT_802_3_SAP) {
2301 + if (FWINV(info->sap != hdr->llc.ui.ssap, EBT_802_3_SAP))
2302 + return EBT_NOMATCH;
2303 + if (FWINV(info->sap != hdr->llc.ui.dsap, EBT_802_3_SAP))
2304 + return EBT_NOMATCH;
2305 + }
2306 +
2307 + if (info->bitmask & EBT_802_3_TYPE) {
2308 + if (!(hdr->llc.ui.dsap == CHECK_TYPE && hdr->llc.ui.ssap == CHECK_TYPE))
2309 + return EBT_NOMATCH;
2310 + if (FWINV(info->type != type, EBT_802_3_TYPE))
2311 + return EBT_NOMATCH;
2312 + }
2313 +
2314 + return EBT_MATCH;
2315 +}
2316 +
2317 +static struct ebt_match filter_802_3;
2318 +static int ebt_802_3_check(const char *tablename, unsigned int hookmask,
2319 + const struct ebt_entry *e, void *data, unsigned int datalen)
2320 +{
2321 + struct ebt_802_3_info *info = (struct ebt_802_3_info *)data;
2322 +
2323 + if (datalen != EBT_ALIGN(sizeof(struct ebt_802_3_info)))
2324 + return -EINVAL;
2325 + if (info->bitmask & ~EBT_802_3_MASK || info->invflags & ~EBT_802_3_MASK)
2326 + return -EINVAL;
2327 +
2328 + return 0;
2329 +}
2330 +
2331 +static struct ebt_match filter_802_3 =
2332 +{
2333 + .name = EBT_802_3_MATCH,
2334 + .match = ebt_filter_802_3,
2335 + .check = ebt_802_3_check,
2336 + .me = THIS_MODULE,
2337 +};
2338 +
2339 +static int __init init(void)
2340 +{
2341 + return ebt_register_match(&filter_802_3);
2342 +}
2343 +
2344 +static void __exit fini(void)
2345 +{
2346 + ebt_unregister_match(&filter_802_3);
2347 +}
2348 +
2349 +module_init(init);
2350 +module_exit(fini);
2351 +EXPORT_NO_SYMBOLS;
2352 +MODULE_LICENSE("GPL");
2353 diff -Nurb src/linux/linux.stock/net/bridge/netfilter/ebt_among.c src/linux/linux/net/bridge/netfilter/ebt_among.c
2354 --- src/linux/linux.stock/net/bridge/netfilter/ebt_among.c 1969-12-31 19:00:00.000000000 -0500
2355 +++ src/linux/linux/net/bridge/netfilter/ebt_among.c 2004-07-10 23:46:39.000000000 -0400
2356 @@ -0,0 +1,223 @@
2357 +/*
2358 + * ebt_among
2359 + *
2360 + * Authors:
2361 + * Grzegorz Borowiak <grzes@gnu.univ.gda.pl>
2362 + *
2363 + * August, 2003
2364 + *
2365 + */
2366 +
2367 +#include <linux/netfilter_bridge/ebtables.h>
2368 +#include <linux/netfilter_bridge/ebt_among.h>
2369 +#include <linux/ip.h>
2370 +#include <linux/if_arp.h>
2371 +#include <linux/module.h>
2372 +
2373 +static int ebt_mac_wormhash_contains(const struct ebt_mac_wormhash *wh,
2374 + const char *mac, uint32_t ip)
2375 +{
2376 + /* You may be puzzled as to how this code works.
2377 + * Some tricks were used, refer to
2378 + * include/linux/netfilter_bridge/ebt_among.h
2379 + * as there you can find a solution of this mystery.
2380 + */
2381 + const struct ebt_mac_wormhash_tuple *p;
2382 + int start, limit, i;
2383 + uint32_t cmp[2] = { 0, 0 };
2384 + int key = (const unsigned char) mac[5];
2385 +
2386 + memcpy(((char *) cmp) + 2, mac, 6);
2387 + start = wh->table[key];
2388 + limit = wh->table[key + 1];
2389 + if (ip) {
2390 + for (i = start; i < limit; i++) {
2391 + p = &wh->pool[i];
2392 + if (cmp[1] == p->cmp[1] && cmp[0] == p->cmp[0]) {
2393 + if (p->ip == 0 || p->ip == ip) {
2394 + return 1;
2395 + }
2396 + }
2397 + }
2398 + } else {
2399 + for (i = start; i < limit; i++) {
2400 + p = &wh->pool[i];
2401 + if (cmp[1] == p->cmp[1] && cmp[0] == p->cmp[0]) {
2402 + if (p->ip == 0) {
2403 + return 1;
2404 + }
2405 + }
2406 + }
2407 + }
2408 + return 0;
2409 +}
2410 +
2411 +static int ebt_mac_wormhash_check_integrity(const struct ebt_mac_wormhash
2412 + *wh)
2413 +{
2414 + int i;
2415 +
2416 + for (i = 0; i < 256; i++) {
2417 + if (wh->table[i] > wh->table[i + 1])
2418 + return -0x100 - i;
2419 + if (wh->table[i] < 0)
2420 + return -0x200 - i;
2421 + if (wh->table[i] > wh->poolsize)
2422 + return -0x300 - i;
2423 + }
2424 + if (wh->table[256] > wh->poolsize)
2425 + return -0xc00;
2426 + return 0;
2427 +}
2428 +
2429 +static int get_ip_dst(const struct sk_buff *skb, uint32_t * addr)
2430 +{
2431 + if (skb->mac.ethernet->h_proto == __constant_htons(ETH_P_IP))
2432 + *addr = skb->nh.iph->daddr;
2433 + else if (skb->mac.ethernet->h_proto == __constant_htons(ETH_P_ARP)) {
2434 + uint32_t arp_len = sizeof(struct arphdr) +
2435 + (2 * (((*skb).nh.arph)->ar_hln)) +
2436 + (2 * (((*skb).nh.arph)->ar_pln));
2437 +
2438 + /* Make sure the packet is long enough. */
2439 + if ((((*skb).nh.raw) + arp_len) > (*skb).tail)
2440 + return -1;
2441 + /* IPv4 addresses are always 4 bytes. */
2442 + if (((*skb).nh.arph)->ar_pln != sizeof(uint32_t))
2443 + return -1;
2444 +
2445 + memcpy(addr, ((*skb).nh.raw) + sizeof(struct arphdr) +
2446 + (2 * (((*skb).nh.arph)->ar_hln)) +
2447 + (((*skb).nh.arph)->ar_pln), sizeof(uint32_t));
2448 +
2449 + }
2450 + return 0;
2451 +}
2452 +
2453 +static int get_ip_src(const struct sk_buff *skb, uint32_t * addr)
2454 +{
2455 + if (skb->mac.ethernet->h_proto == __constant_htons(ETH_P_IP))
2456 + *addr = skb->nh.iph->saddr;
2457 + else if (skb->mac.ethernet->h_proto == __constant_htons(ETH_P_ARP)) {
2458 + uint32_t arp_len = sizeof(struct arphdr) +
2459 + (2 * (((*skb).nh.arph)->ar_hln)) +
2460 + (2 * (((*skb).nh.arph)->ar_pln));
2461 +
2462 + /* Make sure the packet is long enough. */
2463 + if ((((*skb).nh.raw) + arp_len) > (*skb).tail)
2464 + return -1;
2465 + /* IPv4 addresses are always 4 bytes. */
2466 + if (((*skb).nh.arph)->ar_pln != sizeof(uint32_t))
2467 + return -1;
2468 +
2469 + memcpy(addr, ((*skb).nh.raw) + sizeof(struct arphdr) +
2470 + ((((*skb).nh.arph)->ar_hln)), sizeof(uint32_t));
2471 +
2472 + }
2473 + return 0;
2474 +}
2475 +
2476 +static int ebt_filter_among(const struct sk_buff *skb,
2477 + const struct net_device *in,
2478 + const struct net_device *out, const void *data,
2479 + unsigned int datalen)
2480 +{
2481 + struct ebt_among_info *info = (struct ebt_among_info *) data;
2482 + const char *dmac, *smac;
2483 + const struct ebt_mac_wormhash *wh_dst, *wh_src;
2484 + uint32_t dip = 0, sip = 0;
2485 +
2486 + wh_dst = ebt_among_wh_dst(info);
2487 + wh_src = ebt_among_wh_src(info);
2488 +
2489 + if (wh_src) {
2490 + smac = skb->mac.ethernet->h_source;
2491 + if (get_ip_src(skb, &sip))
2492 + return EBT_NOMATCH;
2493 + if (!(info->bitmask & EBT_AMONG_SRC_NEG)) {
2494 + /* we match only if it contains */
2495 + if (!ebt_mac_wormhash_contains(wh_src, smac, sip))
2496 + return EBT_NOMATCH;
2497 + } else {
2498 + /* we match only if it DOES NOT contain */
2499 + if (ebt_mac_wormhash_contains(wh_src, smac, sip))
2500 + return EBT_NOMATCH;
2501 + }
2502 + }
2503 +
2504 + if (wh_dst) {
2505 + dmac = skb->mac.ethernet->h_dest;
2506 + if (get_ip_dst(skb, &dip))
2507 + return EBT_NOMATCH;
2508 + if (!(info->bitmask & EBT_AMONG_DST_NEG)) {
2509 + /* we match only if it contains */
2510 + if (!ebt_mac_wormhash_contains(wh_dst, dmac, dip))
2511 + return EBT_NOMATCH;
2512 + } else {
2513 + /* we match only if it DOES NOT contain */
2514 + if (ebt_mac_wormhash_contains(wh_dst, dmac, dip))
2515 + return EBT_NOMATCH;
2516 + }
2517 + }
2518 +
2519 + return EBT_MATCH;
2520 +}
2521 +
2522 +static int ebt_among_check(const char *tablename, unsigned int hookmask,
2523 + const struct ebt_entry *e, void *data,
2524 + unsigned int datalen)
2525 +{
2526 + struct ebt_among_info *info = (struct ebt_among_info *) data;
2527 + int expected_length = sizeof(struct ebt_among_info);
2528 + const struct ebt_mac_wormhash *wh_dst, *wh_src;
2529 + int err;
2530 +
2531 + wh_dst = ebt_among_wh_dst(info);
2532 + wh_src = ebt_among_wh_src(info);
2533 + expected_length += ebt_mac_wormhash_size(wh_dst);
2534 + expected_length += ebt_mac_wormhash_size(wh_src);
2535 +
2536 + if (datalen != EBT_ALIGN(expected_length)) {
2537 + printk(KERN_WARNING
2538 + "ebtables: among: wrong size: %d"
2539 + "against expected %d, rounded to %d\n",
2540 + datalen, expected_length,
2541 + EBT_ALIGN(expected_length));
2542 + return -EINVAL;
2543 + }
2544 + if (wh_dst && (err = ebt_mac_wormhash_check_integrity(wh_dst))) {
2545 + printk(KERN_WARNING
2546 + "ebtables: among: dst integrity fail: %x\n", -err);
2547 + return -EINVAL;
2548 + }
2549 + if (wh_src && (err = ebt_mac_wormhash_check_integrity(wh_src))) {
2550 + printk(KERN_WARNING
2551 + "ebtables: among: src integrity fail: %x\n", -err);
2552 + return -EINVAL;
2553 + }
2554 + return 0;
2555 +}
2556 +
2557 +static struct ebt_match filter_among = {
2558 + {NULL, NULL},
2559 + EBT_AMONG_MATCH,
2560 + ebt_filter_among,
2561 + ebt_among_check,
2562 + NULL,
2563 + THIS_MODULE
2564 +};
2565 +
2566 +static int __init init(void)
2567 +{
2568 + return ebt_register_match(&filter_among);
2569 +}
2570 +
2571 +static void __exit fini(void)
2572 +{
2573 + ebt_unregister_match(&filter_among);
2574 +}
2575 +
2576 +module_init(init);
2577 +module_exit(fini);
2578 +EXPORT_NO_SYMBOLS;
2579 +MODULE_LICENSE("GPL");
2580 diff -Nurb src/linux/linux.stock/net/bridge/netfilter/ebt_arp.c src/linux/linux/net/bridge/netfilter/ebt_arp.c
2581 --- src/linux/linux.stock/net/bridge/netfilter/ebt_arp.c 1969-12-31 19:00:00.000000000 -0500
2582 +++ src/linux/linux/net/bridge/netfilter/ebt_arp.c 2004-07-10 23:46:39.000000000 -0400
2583 @@ -0,0 +1,149 @@
2584 +/*
2585 + * ebt_arp
2586 + *
2587 + * Authors:
2588 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
2589 + * Tim Gardner <timg@tpi.com>
2590 + *
2591 + * April, 2002
2592 + *
2593 + */
2594 +
2595 +#include <linux/netfilter_bridge/ebtables.h>
2596 +#include <linux/netfilter_bridge/ebt_arp.h>
2597 +#include <linux/if_arp.h>
2598 +#include <linux/if_ether.h>
2599 +#include <linux/module.h>
2600 +
2601 +static int ebt_filter_arp(const struct sk_buff *skb, const struct net_device *in,
2602 + const struct net_device *out, const void *data, unsigned int datalen)
2603 +{
2604 + struct ebt_arp_info *info = (struct ebt_arp_info *)data;
2605 +
2606 + if (info->bitmask & EBT_ARP_OPCODE && FWINV(info->opcode !=
2607 + ((*skb).nh.arph)->ar_op, EBT_ARP_OPCODE))
2608 + return EBT_NOMATCH;
2609 + if (info->bitmask & EBT_ARP_HTYPE && FWINV(info->htype !=
2610 + ((*skb).nh.arph)->ar_hrd, EBT_ARP_HTYPE))
2611 + return EBT_NOMATCH;
2612 + if (info->bitmask & EBT_ARP_PTYPE && FWINV(info->ptype !=
2613 + ((*skb).nh.arph)->ar_pro, EBT_ARP_PTYPE))
2614 + return EBT_NOMATCH;
2615 +
2616 + if (info->bitmask & (EBT_ARP_SRC_IP | EBT_ARP_DST_IP))
2617 + {
2618 + uint32_t arp_len = sizeof(struct arphdr) +
2619 + (2 * (((*skb).nh.arph)->ar_hln)) +
2620 + (2 * (((*skb).nh.arph)->ar_pln));
2621 + uint32_t dst;
2622 + uint32_t src;
2623 +
2624 + // Make sure the packet is long enough.
2625 + if ((((*skb).nh.raw) + arp_len) > (*skb).tail)
2626 + return EBT_NOMATCH;
2627 + // IPv4 addresses are always 4 bytes.
2628 + if (((*skb).nh.arph)->ar_pln != sizeof(uint32_t))
2629 + return EBT_NOMATCH;
2630 +
2631 + if (info->bitmask & EBT_ARP_SRC_IP) {
2632 + memcpy(&src, ((*skb).nh.raw) + sizeof(struct arphdr) +
2633 + ((*skb).nh.arph)->ar_hln, sizeof(uint32_t));
2634 + if (FWINV(info->saddr != (src & info->smsk),
2635 + EBT_ARP_SRC_IP))
2636 + return EBT_NOMATCH;
2637 + }
2638 +
2639 + if (info->bitmask & EBT_ARP_DST_IP) {
2640 + memcpy(&dst, ((*skb).nh.raw)+sizeof(struct arphdr) +
2641 + (2*(((*skb).nh.arph)->ar_hln)) +
2642 + (((*skb).nh.arph)->ar_pln), sizeof(uint32_t));
2643 + if (FWINV(info->daddr != (dst & info->dmsk),
2644 + EBT_ARP_DST_IP))
2645 + return EBT_NOMATCH;
2646 + }
2647 + }
2648 +
2649 + if (info->bitmask & (EBT_ARP_SRC_MAC | EBT_ARP_DST_MAC))
2650 + {
2651 + uint32_t arp_len = sizeof(struct arphdr) +
2652 + (2 * (((*skb).nh.arph)->ar_hln)) +
2653 + (2 * (((*skb).nh.arph)->ar_pln));
2654 + unsigned char dst[ETH_ALEN];
2655 + unsigned char src[ETH_ALEN];
2656 +
2657 + // Make sure the packet is long enough.
2658 + if ((((*skb).nh.raw) + arp_len) > (*skb).tail)
2659 + return EBT_NOMATCH;
2660 + // MAC addresses are 6 bytes.
2661 + if (((*skb).nh.arph)->ar_hln != ETH_ALEN)
2662 + return EBT_NOMATCH;
2663 + if (info->bitmask & EBT_ARP_SRC_MAC) {
2664 + uint8_t verdict, i;
2665 +
2666 + memcpy(&src, ((*skb).nh.raw) +
2667 + sizeof(struct arphdr),
2668 + ETH_ALEN);
2669 + verdict = 0;
2670 + for (i = 0; i < 6; i++)
2671 + verdict |= (src[i] ^ info->smaddr[i]) &
2672 + info->smmsk[i];
2673 + if (FWINV(verdict != 0, EBT_ARP_SRC_MAC))
2674 + return EBT_NOMATCH;
2675 + }
2676 +
2677 + if (info->bitmask & EBT_ARP_DST_MAC) {
2678 + uint8_t verdict, i;
2679 +
2680 + memcpy(&dst, ((*skb).nh.raw) +
2681 + sizeof(struct arphdr) +
2682 + (((*skb).nh.arph)->ar_hln) +
2683 + (((*skb).nh.arph)->ar_pln),
2684 + ETH_ALEN);
2685 + verdict = 0;
2686 + for (i = 0; i < 6; i++)
2687 + verdict |= (dst[i] ^ info->dmaddr[i]) &
2688 + info->dmmsk[i];
2689 + if (FWINV(verdict != 0, EBT_ARP_DST_MAC))
2690 + return EBT_NOMATCH;
2691 + }
2692 + }
2693 +
2694 + return EBT_MATCH;
2695 +}
2696 +
2697 +static int ebt_arp_check(const char *tablename, unsigned int hookmask,
2698 + const struct ebt_entry *e, void *data, unsigned int datalen)
2699 +{
2700 + struct ebt_arp_info *info = (struct ebt_arp_info *)data;
2701 +
2702 + if (datalen != EBT_ALIGN(sizeof(struct ebt_arp_info)))
2703 + return -EINVAL;
2704 + if ((e->ethproto != __constant_htons(ETH_P_ARP) &&
2705 + e->ethproto != __constant_htons(ETH_P_RARP)) ||
2706 + e->invflags & EBT_IPROTO)
2707 + return -EINVAL;
2708 + if (info->bitmask & ~EBT_ARP_MASK || info->invflags & ~EBT_ARP_MASK)
2709 + return -EINVAL;
2710 + return 0;
2711 +}
2712 +
2713 +static struct ebt_match filter_arp =
2714 +{
2715 + {NULL, NULL}, EBT_ARP_MATCH, ebt_filter_arp, ebt_arp_check, NULL,
2716 + THIS_MODULE
2717 +};
2718 +
2719 +static int __init init(void)
2720 +{
2721 + return ebt_register_match(&filter_arp);
2722 +}
2723 +
2724 +static void __exit fini(void)
2725 +{
2726 + ebt_unregister_match(&filter_arp);
2727 +}
2728 +
2729 +module_init(init);
2730 +module_exit(fini);
2731 +EXPORT_NO_SYMBOLS;
2732 +MODULE_LICENSE("GPL");
2733 diff -Nurb src/linux/linux.stock/net/bridge/netfilter/ebt_arpreply.c src/linux/linux/net/bridge/netfilter/ebt_arpreply.c
2734 --- src/linux/linux.stock/net/bridge/netfilter/ebt_arpreply.c 1969-12-31 19:00:00.000000000 -0500
2735 +++ src/linux/linux/net/bridge/netfilter/ebt_arpreply.c 2004-07-10 23:46:39.000000000 -0400
2736 @@ -0,0 +1,86 @@
2737 +/*
2738 + * ebt_arpreply
2739 + *
2740 + * Authors:
2741 + * Grzegorz Borowiak <grzes@gnu.univ.gda.pl>
2742 + * Bart De Schuymer <bdschuym@pandora.be>
2743 + *
2744 + * August, 2003
2745 + *
2746 + */
2747 +
2748 +#include <linux/netfilter_bridge/ebtables.h>
2749 +#include <linux/netfilter_bridge/ebt_arpreply.h>
2750 +#include <linux/if_arp.h>
2751 +#include <net/arp.h>
2752 +#include <linux/module.h>
2753 +
2754 +static int ebt_target_reply(struct sk_buff **pskb, unsigned int hooknr,
2755 + const struct net_device *in, const struct net_device *out,
2756 + const void *data, unsigned int datalen)
2757 +{
2758 + struct ebt_arpreply_info *info = (struct ebt_arpreply_info *)data;
2759 + struct arphdr *ah;
2760 + unsigned char *sha, *arp_ptr;
2761 + u32 sip, tip;
2762 +
2763 + ah = (**pskb).nh.arph;
2764 + if (ah->ar_op != __constant_htons(ARPOP_REQUEST) ||
2765 + ah->ar_hln != ETH_ALEN || ah->ar_pro != htons(ETH_P_IP) ||
2766 + ah->ar_pln != 4)
2767 + return EBT_CONTINUE;
2768 +
2769 + arp_ptr = (unsigned char *)(ah + 1);
2770 +
2771 + /* get source and target IP */
2772 + sha = arp_ptr;
2773 + arp_ptr += ETH_ALEN;
2774 + memcpy(&sip, arp_ptr, 4);
2775 + arp_ptr += 4 + ETH_ALEN;
2776 + memcpy(&tip, arp_ptr, 4);
2777 +
2778 + arp_send(ARPOP_REPLY, ETH_P_ARP, sip, in, tip, sha, info->mac, sha);
2779 +
2780 + return info->target;
2781 +}
2782 +
2783 +static int ebt_target_reply_check(const char *tablename, unsigned int hookmask,
2784 + const struct ebt_entry *e, void *data, unsigned int datalen)
2785 +{
2786 + struct ebt_arpreply_info *info = (struct ebt_arpreply_info *)data;
2787 +
2788 + if (datalen != EBT_ALIGN(sizeof(struct ebt_arpreply_info)))
2789 + return -EINVAL;
2790 + if (BASE_CHAIN && info->target == EBT_RETURN)
2791 + return -EINVAL;
2792 + if (e->ethproto != __constant_htons(ETH_P_ARP) ||
2793 + e->invflags & EBT_IPROTO)
2794 + return -EINVAL;
2795 + CLEAR_BASE_CHAIN_BIT;
2796 + if (strcmp(tablename, "nat") || hookmask & ~(1 << NF_BR_PRE_ROUTING))
2797 + return -EINVAL;
2798 + return 0;
2799 +}
2800 +
2801 +static struct ebt_target reply_target =
2802 +{
2803 + .name = EBT_ARPREPLY_TARGET,
2804 + .target = ebt_target_reply,
2805 + .check = ebt_target_reply_check,
2806 + .me = THIS_MODULE,
2807 +};
2808 +
2809 +static int __init init(void)
2810 +{
2811 + return ebt_register_target(&reply_target);
2812 +}
2813 +
2814 +static void __exit fini(void)
2815 +{
2816 + ebt_unregister_target(&reply_target);
2817 +}
2818 +
2819 +module_init(init);
2820 +module_exit(fini);
2821 +EXPORT_NO_SYMBOLS;
2822 +MODULE_LICENSE("GPL");
2823 diff -Nurb src/linux/linux.stock/net/bridge/netfilter/ebt_dnat.c src/linux/linux/net/bridge/netfilter/ebt_dnat.c
2824 --- src/linux/linux.stock/net/bridge/netfilter/ebt_dnat.c 1969-12-31 19:00:00.000000000 -0500
2825 +++ src/linux/linux/net/bridge/netfilter/ebt_dnat.c 2004-07-10 23:46:39.000000000 -0400
2826 @@ -0,0 +1,65 @@
2827 +/*
2828 + * ebt_dnat
2829 + *
2830 + * Authors:
2831 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
2832 + *
2833 + * June, 2002
2834 + *
2835 + */
2836 +
2837 +#include <linux/netfilter_bridge/ebtables.h>
2838 +#include <linux/netfilter_bridge/ebt_nat.h>
2839 +#include <linux/module.h>
2840 +#include <net/sock.h>
2841 +
2842 +static int ebt_target_dnat(struct sk_buff **pskb, unsigned int hooknr,
2843 + const struct net_device *in, const struct net_device *out,
2844 + const void *data, unsigned int datalen)
2845 +{
2846 + struct ebt_nat_info *info = (struct ebt_nat_info *)data;
2847 +
2848 + memcpy(((**pskb).mac.ethernet)->h_dest, info->mac,
2849 + ETH_ALEN * sizeof(unsigned char));
2850 + return info->target;
2851 +}
2852 +
2853 +static int ebt_target_dnat_check(const char *tablename, unsigned int hookmask,
2854 + const struct ebt_entry *e, void *data, unsigned int datalen)
2855 +{
2856 + struct ebt_nat_info *info = (struct ebt_nat_info *)data;
2857 +
2858 + if (BASE_CHAIN && info->target == EBT_RETURN)
2859 + return -EINVAL;
2860 + CLEAR_BASE_CHAIN_BIT;
2861 + if ( (strcmp(tablename, "nat") ||
2862 + (hookmask & ~((1 << NF_BR_PRE_ROUTING) | (1 << NF_BR_LOCAL_OUT)))) &&
2863 + (strcmp(tablename, "broute") || hookmask & ~(1 << NF_BR_BROUTING)) )
2864 + return -EINVAL;
2865 + if (datalen != EBT_ALIGN(sizeof(struct ebt_nat_info)))
2866 + return -EINVAL;
2867 + if (INVALID_TARGET)
2868 + return -EINVAL;
2869 + return 0;
2870 +}
2871 +
2872 +static struct ebt_target dnat =
2873 +{
2874 + {NULL, NULL}, EBT_DNAT_TARGET, ebt_target_dnat, ebt_target_dnat_check,
2875 + NULL, THIS_MODULE
2876 +};
2877 +
2878 +static int __init init(void)
2879 +{
2880 + return ebt_register_target(&dnat);
2881 +}
2882 +
2883 +static void __exit fini(void)
2884 +{
2885 + ebt_unregister_target(&dnat);
2886 +}
2887 +
2888 +module_init(init);
2889 +module_exit(fini);
2890 +EXPORT_NO_SYMBOLS;
2891 +MODULE_LICENSE("GPL");
2892 diff -Nurb src/linux/linux.stock/net/bridge/netfilter/ebt_ip.c src/linux/linux/net/bridge/netfilter/ebt_ip.c
2893 --- src/linux/linux.stock/net/bridge/netfilter/ebt_ip.c 1969-12-31 19:00:00.000000000 -0500
2894 +++ src/linux/linux/net/bridge/netfilter/ebt_ip.c 2004-07-10 23:46:39.000000000 -0400
2895 @@ -0,0 +1,121 @@
2896 +/*
2897 + * ebt_ip
2898 + *
2899 + * Authors:
2900 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
2901 + *
2902 + * April, 2002
2903 + *
2904 + * Changes:
2905 + * added ip-sport and ip-dport
2906 + * Innominate Security Technologies AG <mhopf@innominate.com>
2907 + * September, 2002
2908 + */
2909 +
2910 +#include <linux/netfilter_bridge/ebtables.h>
2911 +#include <linux/netfilter_bridge/ebt_ip.h>
2912 +#include <linux/ip.h>
2913 +#include <linux/in.h>
2914 +#include <linux/module.h>
2915 +
2916 +struct tcpudphdr {
2917 + uint16_t src;
2918 + uint16_t dst;
2919 +};
2920 +
2921 +union h_u {
2922 + unsigned char *raw;
2923 + struct tcpudphdr *tuh;
2924 +};
2925 +
2926 +static int ebt_filter_ip(const struct sk_buff *skb, const struct net_device *in,
2927 + const struct net_device *out, const void *data,
2928 + unsigned int datalen)
2929 +{
2930 + struct ebt_ip_info *info = (struct ebt_ip_info *)data;
2931 +
2932 + if (info->bitmask & EBT_IP_TOS &&
2933 + FWINV(info->tos != ((*skb).nh.iph)->tos, EBT_IP_TOS))
2934 + return EBT_NOMATCH;
2935 + if (info->bitmask & EBT_IP_PROTO) {
2936 + if (FWINV(info->protocol != ((*skb).nh.iph)->protocol,
2937 + EBT_IP_PROTO))
2938 + return EBT_NOMATCH;
2939 + if ( info->protocol == IPPROTO_TCP ||
2940 + info->protocol == IPPROTO_UDP )
2941 + {
2942 + union h_u h;
2943 + h.raw = skb->data + skb->nh.iph->ihl*4;
2944 + if (info->bitmask & EBT_IP_DPORT) {
2945 + uint16_t port = ntohs(h.tuh->dst);
2946 + if (FWINV(port < info->dport[0] ||
2947 + port > info->dport[1],
2948 + EBT_IP_DPORT))
2949 + return EBT_NOMATCH;
2950 + }
2951 + if (info->bitmask & EBT_IP_SPORT) {
2952 + uint16_t port = ntohs(h.tuh->src);
2953 + if (FWINV(port < info->sport[0] ||
2954 + port > info->sport[1],
2955 + EBT_IP_SPORT))
2956 + return EBT_NOMATCH;
2957 + }
2958 + }
2959 + }
2960 + if (info->bitmask & EBT_IP_SOURCE &&
2961 + FWINV((((*skb).nh.iph)->saddr & info->smsk) !=
2962 + info->saddr, EBT_IP_SOURCE))
2963 + return EBT_NOMATCH;
2964 + if ((info->bitmask & EBT_IP_DEST) &&
2965 + FWINV((((*skb).nh.iph)->daddr & info->dmsk) !=
2966 + info->daddr, EBT_IP_DEST))
2967 + return EBT_NOMATCH;
2968 + return EBT_MATCH;
2969 +}
2970 +
2971 +static int ebt_ip_check(const char *tablename, unsigned int hookmask,
2972 + const struct ebt_entry *e, void *data, unsigned int datalen)
2973 +{
2974 + struct ebt_ip_info *info = (struct ebt_ip_info *)data;
2975 +
2976 + if (datalen != EBT_ALIGN(sizeof(struct ebt_ip_info)))
2977 + return -EINVAL;
2978 + if (e->ethproto != __constant_htons(ETH_P_IP) ||
2979 + e->invflags & EBT_IPROTO)
2980 + return -EINVAL;
2981 + if (info->bitmask & ~EBT_IP_MASK || info->invflags & ~EBT_IP_MASK)
2982 + return -EINVAL;
2983 + if (info->bitmask & (EBT_IP_DPORT | EBT_IP_SPORT)) {
2984 + if (!info->bitmask & EBT_IPROTO)
2985 + return -EINVAL;
2986 + if (info->protocol != IPPROTO_TCP &&
2987 + info->protocol != IPPROTO_UDP)
2988 + return -EINVAL;
2989 + }
2990 + if (info->bitmask & EBT_IP_DPORT && info->dport[0] > info->dport[1])
2991 + return -EINVAL;
2992 + if (info->bitmask & EBT_IP_SPORT && info->sport[0] > info->sport[1])
2993 + return -EINVAL;
2994 + return 0;
2995 +}
2996 +
2997 +static struct ebt_match filter_ip =
2998 +{
2999 + {NULL, NULL}, EBT_IP_MATCH, ebt_filter_ip, ebt_ip_check, NULL,
3000 + THIS_MODULE
3001 +};
3002 +
3003 +static int __init init(void)
3004 +{
3005 + return ebt_register_match(&filter_ip);
3006 +}
3007 +
3008 +static void __exit fini(void)
3009 +{
3010 + ebt_unregister_match(&filter_ip);
3011 +}
3012 +
3013 +module_init(init);
3014 +module_exit(fini);
3015 +EXPORT_NO_SYMBOLS;
3016 +MODULE_LICENSE("GPL");
3017 diff -Nurb src/linux/linux.stock/net/bridge/netfilter/ebt_limit.c src/linux/linux/net/bridge/netfilter/ebt_limit.c
3018 --- src/linux/linux.stock/net/bridge/netfilter/ebt_limit.c 1969-12-31 19:00:00.000000000 -0500
3019 +++ src/linux/linux/net/bridge/netfilter/ebt_limit.c 2004-07-10 23:46:39.000000000 -0400
3020 @@ -0,0 +1,101 @@
3021 +/*
3022 + * ebt_limit
3023 + *
3024 + * Authors:
3025 + * Tom Marshall <tommy@home.tig-grr.com>
3026 + *
3027 + * Mostly copied from netfilter's ipt_limit.c, see that file for explanation
3028 + *
3029 + * September, 2003
3030 + *
3031 + */
3032 +
3033 +#include <linux/netfilter_bridge/ebtables.h>
3034 +#include <linux/netfilter_bridge/ebt_limit.h>
3035 +#include <linux/module.h>
3036 +
3037 +#include <linux/netdevice.h>
3038 +#include <linux/spinlock.h>
3039 +
3040 +static spinlock_t limit_lock = SPIN_LOCK_UNLOCKED;
3041 +
3042 +#define CREDITS_PER_JIFFY 128
3043 +
3044 +static int ebt_limit_match(const struct sk_buff *skb, const struct net_device *in,
3045 + const struct net_device *out, const void *data, unsigned int datalen)
3046 +{
3047 + struct ebt_limit_info *info = (struct ebt_limit_info *)data;
3048 + unsigned long now = jiffies;
3049 +
3050 + spin_lock_bh(&limit_lock);
3051 + info->credit += (now - xchg(&info->prev, now)) * CREDITS_PER_JIFFY;
3052 + if (info->credit > info->credit_cap)
3053 + info->credit = info->credit_cap;
3054 +
3055 + if (info->credit >= info->cost) {
3056 + /* We're not limited. */
3057 + info->credit -= info->cost;
3058 + spin_unlock_bh(&limit_lock);
3059 + return EBT_MATCH;
3060 + }
3061 +
3062 + spin_unlock_bh(&limit_lock);
3063 + return EBT_NOMATCH;
3064 +}
3065 +
3066 +/* Precision saver. */
3067 +static u_int32_t
3068 +user2credits(u_int32_t user)
3069 +{
3070 + /* If multiplying would overflow... */
3071 + if (user > 0xFFFFFFFF / (HZ*CREDITS_PER_JIFFY))
3072 + /* Divide first. */
3073 + return (user / EBT_LIMIT_SCALE) * HZ * CREDITS_PER_JIFFY;
3074 +
3075 + return (user * HZ * CREDITS_PER_JIFFY) / EBT_LIMIT_SCALE;
3076 +}
3077 +
3078 +static int ebt_limit_check(const char *tablename, unsigned int hookmask,
3079 + const struct ebt_entry *e, void *data, unsigned int datalen)
3080 +{
3081 + struct ebt_limit_info *info = (struct ebt_limit_info *)data;
3082 +
3083 + if (datalen != EBT_ALIGN(sizeof(struct ebt_limit_info)))
3084 + return -EINVAL;
3085 +
3086 + /* Check for overflow. */
3087 + if (info->burst == 0
3088 + || user2credits(info->avg * info->burst) < user2credits(info->avg)) {
3089 + printk("Overflow in ebt_limit: %u/%u\n",
3090 + info->avg, info->burst);
3091 + return -EINVAL;
3092 + }
3093 +
3094 + /* User avg in seconds * EBT_LIMIT_SCALE: convert to jiffies * 128. */
3095 + info->prev = jiffies;
3096 + info->credit = user2credits(info->avg * info->burst);
3097 + info->credit_cap = user2credits(info->avg * info->burst);
3098 + info->cost = user2credits(info->avg);
3099 + return 0;
3100 +}
3101 +
3102 +static struct ebt_match ebt_limit_reg =
3103 +{
3104 + {NULL, NULL}, EBT_LIMIT_MATCH, ebt_limit_match, ebt_limit_check, NULL,
3105 + THIS_MODULE
3106 +};
3107 +
3108 +static int __init init(void)
3109 +{
3110 + return ebt_register_match(&ebt_limit_reg);
3111 +}
3112 +
3113 +static void __exit fini(void)
3114 +{
3115 + ebt_unregister_match(&ebt_limit_reg);
3116 +}
3117 +
3118 +module_init(init);
3119 +module_exit(fini);
3120 +EXPORT_NO_SYMBOLS;
3121 +MODULE_LICENSE("GPL");
3122 diff -Nurb src/linux/linux.stock/net/bridge/netfilter/ebt_log.c src/linux/linux/net/bridge/netfilter/ebt_log.c
3123 --- src/linux/linux.stock/net/bridge/netfilter/ebt_log.c 1969-12-31 19:00:00.000000000 -0500
3124 +++ src/linux/linux/net/bridge/netfilter/ebt_log.c 2004-07-10 23:46:39.000000000 -0400
3125 @@ -0,0 +1,152 @@
3126 +/*
3127 + * ebt_log
3128 + *
3129 + * Authors:
3130 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
3131 + *
3132 + * April, 2002
3133 + *
3134 + */
3135 +
3136 +#include <linux/netfilter_bridge/ebtables.h>
3137 +#include <linux/netfilter_bridge/ebt_log.h>
3138 +#include <linux/module.h>
3139 +#include <linux/ip.h>
3140 +#include <linux/in.h>
3141 +#include <linux/if_arp.h>
3142 +#include <linux/spinlock.h>
3143 +
3144 +static spinlock_t ebt_log_lock = SPIN_LOCK_UNLOCKED;
3145 +
3146 +static int ebt_log_check(const char *tablename, unsigned int hookmask,
3147 + const struct ebt_entry *e, void *data, unsigned int datalen)
3148 +{
3149 + struct ebt_log_info *info = (struct ebt_log_info *)data;
3150 +
3151 + if (datalen != EBT_ALIGN(sizeof(struct ebt_log_info)))
3152 + return -EINVAL;
3153 + if (info->bitmask & ~EBT_LOG_MASK)
3154 + return -EINVAL;
3155 + if (info->loglevel >= 8)
3156 + return -EINVAL;
3157 + info->prefix[EBT_LOG_PREFIX_SIZE - 1] = '\0';
3158 + return 0;
3159 +}
3160 +
3161 +struct tcpudphdr
3162 +{
3163 + uint16_t src;
3164 + uint16_t dst;
3165 +};
3166 +
3167 +struct arppayload
3168 +{
3169 + unsigned char mac_src[ETH_ALEN];
3170 + unsigned char ip_src[4];
3171 + unsigned char mac_dst[ETH_ALEN];
3172 + unsigned char ip_dst[4];
3173 +};
3174 +
3175 +static void print_MAC(unsigned char *p)
3176 +{
3177 + int i;
3178 +
3179 + for (i = 0; i < ETH_ALEN; i++, p++)
3180 + printk("%02x%c", *p, i == ETH_ALEN - 1 ? ' ':':');
3181 +}
3182 +
3183 +#define myNIPQUAD(a) a[0], a[1], a[2], a[3]
3184 +static void ebt_log(const struct sk_buff *skb, const struct net_device *in,
3185 + const struct net_device *out, const void *data, unsigned int datalen)
3186 +{
3187 + struct ebt_log_info *info = (struct ebt_log_info *)data;
3188 + char level_string[4] = "< >";
3189 + level_string[1] = '0' + info->loglevel;
3190 +
3191 + spin_lock_bh(&ebt_log_lock);
3192 + printk(level_string);
3193 + printk("%s IN=%s OUT=%s ", info->prefix, in ? in->name : "",
3194 + out ? out->name : "");
3195 +
3196 + printk("MAC source = ");
3197 + print_MAC((skb->mac.ethernet)->h_source);
3198 + printk("MAC dest = ");
3199 + print_MAC((skb->mac.ethernet)->h_dest);
3200 +
3201 + printk("proto = 0x%04x", ntohs(((*skb).mac.ethernet)->h_proto));
3202 +
3203 + if ((info->bitmask & EBT_LOG_IP) && skb->mac.ethernet->h_proto ==
3204 + htons(ETH_P_IP)){
3205 + struct iphdr *iph = skb->nh.iph;
3206 + printk(" IP SRC=%u.%u.%u.%u IP DST=%u.%u.%u.%u,",
3207 + NIPQUAD(iph->saddr), NIPQUAD(iph->daddr));
3208 + printk(" IP tos=0x%02X, IP proto=%d", iph->tos, iph->protocol);
3209 + if (iph->protocol == IPPROTO_TCP ||
3210 + iph->protocol == IPPROTO_UDP) {
3211 + struct tcpudphdr *ports = (struct tcpudphdr *)(skb->data + iph->ihl*4);
3212 +
3213 + if (skb->data + iph->ihl*4 > skb->tail) {
3214 + printk(" INCOMPLETE TCP/UDP header");
3215 + goto out;
3216 + }
3217 + printk(" SPT=%u DPT=%u", ntohs(ports->src),
3218 + ntohs(ports->dst));
3219 + }
3220 + goto out;
3221 + }
3222 +
3223 + if ((info->bitmask & EBT_LOG_ARP) &&
3224 + ((skb->mac.ethernet->h_proto == __constant_htons(ETH_P_ARP)) ||
3225 + (skb->mac.ethernet->h_proto == __constant_htons(ETH_P_RARP)))) {
3226 + struct arphdr * arph = skb->nh.arph;
3227 + printk(" ARP HTYPE=%d, PTYPE=0x%04x, OPCODE=%d",
3228 + ntohs(arph->ar_hrd), ntohs(arph->ar_pro),
3229 + ntohs(arph->ar_op));
3230 + /* If it's for Ethernet and the lengths are OK,
3231 + * then log the ARP payload */
3232 + if (arph->ar_hrd == __constant_htons(1) &&
3233 + arph->ar_hln == ETH_ALEN &&
3234 + arph->ar_pln == sizeof(uint32_t)) {
3235 + struct arppayload *arpp = (struct arppayload *)(skb->data + sizeof(*arph));
3236 +
3237 + if (skb->data + sizeof(*arph) > skb->tail) {
3238 + printk(" INCOMPLETE ARP header");
3239 + goto out;
3240 + }
3241 +
3242 + printk(" ARP MAC SRC=");
3243 + print_MAC(arpp->mac_src);
3244 + printk(" ARP IP SRC=%u.%u.%u.%u",
3245 + myNIPQUAD(arpp->ip_src));
3246 + printk(" ARP MAC DST=");
3247 + print_MAC(arpp->mac_dst);
3248 + printk(" ARP IP DST=%u.%u.%u.%u",
3249 + myNIPQUAD(arpp->ip_dst));
3250 + }
3251 +
3252 + }
3253 +out:
3254 + printk("\n");
3255 + spin_unlock_bh(&ebt_log_lock);
3256 +}
3257 +
3258 +static struct ebt_watcher log =
3259 +{
3260 + {NULL, NULL}, EBT_LOG_WATCHER, ebt_log, ebt_log_check, NULL,
3261 + THIS_MODULE
3262 +};
3263 +
3264 +static int __init init(void)
3265 +{
3266 + return ebt_register_watcher(&log);
3267 +}
3268 +
3269 +static void __exit fini(void)
3270 +{
3271 + ebt_unregister_watcher(&log);
3272 +}
3273 +
3274 +module_init(init);
3275 +module_exit(fini);
3276 +EXPORT_NO_SYMBOLS;
3277 +MODULE_LICENSE("GPL");
3278 diff -Nurb src/linux/linux.stock/net/bridge/netfilter/ebt_mark.c src/linux/linux/net/bridge/netfilter/ebt_mark.c
3279 --- src/linux/linux.stock/net/bridge/netfilter/ebt_mark.c 1969-12-31 19:00:00.000000000 -0500
3280 +++ src/linux/linux/net/bridge/netfilter/ebt_mark.c 2004-07-10 23:46:39.000000000 -0400
3281 @@ -0,0 +1,66 @@
3282 +/*
3283 + * ebt_mark
3284 + *
3285 + * Authors:
3286 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
3287 + *
3288 + * July, 2002
3289 + *
3290 + */
3291 +
3292 +// The mark target can be used in any chain
3293 +// I believe adding a mangle table just for marking is total overkill
3294 +// Marking a frame doesn't really change anything in the frame anyway
3295 +
3296 +#include <linux/netfilter_bridge/ebtables.h>
3297 +#include <linux/netfilter_bridge/ebt_mark_t.h>
3298 +#include <linux/module.h>
3299 +
3300 +static int ebt_target_mark(struct sk_buff **pskb, unsigned int hooknr,
3301 + const struct net_device *in, const struct net_device *out,
3302 + const void *data, unsigned int datalen)
3303 +{
3304 + struct ebt_mark_t_info *info = (struct ebt_mark_t_info *)data;
3305 +
3306 + if ((*pskb)->nfmark != info->mark) {
3307 + (*pskb)->nfmark = info->mark;
3308 + (*pskb)->nfcache |= NFC_ALTERED;
3309 + }
3310 + return info->target;
3311 +}
3312 +
3313 +static int ebt_target_mark_check(const char *tablename, unsigned int hookmask,
3314 + const struct ebt_entry *e, void *data, unsigned int datalen)
3315 +{
3316 + struct ebt_mark_t_info *info = (struct ebt_mark_t_info *)data;
3317 +
3318 + if (datalen != EBT_ALIGN(sizeof(struct ebt_mark_t_info)))
3319 + return -EINVAL;
3320 + if (BASE_CHAIN && info->target == EBT_RETURN)
3321 + return -EINVAL;
3322 + CLEAR_BASE_CHAIN_BIT;
3323 + if (INVALID_TARGET)
3324 + return -EINVAL;
3325 + return 0;
3326 +}
3327 +
3328 +static struct ebt_target mark_target =
3329 +{
3330 + {NULL, NULL}, EBT_MARK_TARGET, ebt_target_mark,
3331 + ebt_target_mark_check, NULL, THIS_MODULE
3332 +};
3333 +
3334 +static int __init init(void)
3335 +{
3336 + return ebt_register_target(&mark_target);
3337 +}
3338 +
3339 +static void __exit fini(void)
3340 +{
3341 + ebt_unregister_target(&mark_target);
3342 +}
3343 +
3344 +module_init(init);
3345 +module_exit(fini);
3346 +EXPORT_NO_SYMBOLS;
3347 +MODULE_LICENSE("GPL");
3348 diff -Nurb src/linux/linux.stock/net/bridge/netfilter/ebt_mark_m.c src/linux/linux/net/bridge/netfilter/ebt_mark_m.c
3349 --- src/linux/linux.stock/net/bridge/netfilter/ebt_mark_m.c 1969-12-31 19:00:00.000000000 -0500
3350 +++ src/linux/linux/net/bridge/netfilter/ebt_mark_m.c 2004-07-10 23:46:39.000000000 -0400
3351 @@ -0,0 +1,61 @@
3352 +/*
3353 + * ebt_mark_m
3354 + *
3355 + * Authors:
3356 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
3357 + *
3358 + * July, 2002
3359 + *
3360 + */
3361 +
3362 +#include <linux/netfilter_bridge/ebtables.h>
3363 +#include <linux/netfilter_bridge/ebt_mark_m.h>
3364 +#include <linux/module.h>
3365 +
3366 +static int ebt_filter_mark(const struct sk_buff *skb,
3367 + const struct net_device *in, const struct net_device *out, const void *data,
3368 + unsigned int datalen)
3369 +{
3370 + struct ebt_mark_m_info *info = (struct ebt_mark_m_info *) data;
3371 +
3372 + if (info->bitmask & EBT_MARK_OR)
3373 + return !(!!(skb->nfmark & info->mask) ^ info->invert);
3374 + return !(((skb->nfmark & info->mask) == info->mark) ^ info->invert);
3375 +}
3376 +
3377 +static int ebt_mark_check(const char *tablename, unsigned int hookmask,
3378 + const struct ebt_entry *e, void *data, unsigned int datalen)
3379 +{
3380 + struct ebt_mark_m_info *info = (struct ebt_mark_m_info *) data;
3381 +
3382 + if (datalen != EBT_ALIGN(sizeof(struct ebt_mark_m_info)))
3383 + return -EINVAL;
3384 + if (info->bitmask & ~EBT_MARK_MASK)
3385 + return -EINVAL;
3386 + if ((info->bitmask & EBT_MARK_OR) && (info->bitmask & EBT_MARK_AND))
3387 + return -EINVAL;
3388 + if (!info->bitmask)
3389 + return -EINVAL;
3390 + return 0;
3391 +}
3392 +
3393 +static struct ebt_match filter_mark =
3394 +{
3395 + {NULL, NULL}, EBT_MARK_MATCH, ebt_filter_mark, ebt_mark_check, NULL,
3396 + THIS_MODULE
3397 +};
3398 +
3399 +static int __init init(void)
3400 +{
3401 + return ebt_register_match(&filter_mark);
3402 +}
3403 +
3404 +static void __exit fini(void)
3405 +{
3406 + ebt_unregister_match(&filter_mark);
3407 +}
3408 +
3409 +module_init(init);
3410 +module_exit(fini);
3411 +EXPORT_NO_SYMBOLS;
3412 +MODULE_LICENSE("GPL");
3413 diff -Nurb src/linux/linux.stock/net/bridge/netfilter/ebt_pkttype.c src/linux/linux/net/bridge/netfilter/ebt_pkttype.c
3414 --- src/linux/linux.stock/net/bridge/netfilter/ebt_pkttype.c 1969-12-31 19:00:00.000000000 -0500
3415 +++ src/linux/linux/net/bridge/netfilter/ebt_pkttype.c 2004-07-10 23:46:39.000000000 -0400
3416 @@ -0,0 +1,60 @@
3417 +/*
3418 + * ebt_pkttype
3419 + *
3420 + * Authors:
3421 + * Bart De Schuymer <bdschuym@pandora.be>
3422 + *
3423 + * April, 2003
3424 + *
3425 + */
3426 +
3427 +#include <linux/netfilter_bridge/ebtables.h>
3428 +#include <linux/netfilter_bridge/ebt_pkttype.h>
3429 +#include <linux/module.h>
3430 +
3431 +static int ebt_filter_pkttype(const struct sk_buff *skb,
3432 + const struct net_device *in,
3433 + const struct net_device *out,
3434 + const void *data,
3435 + unsigned int datalen)
3436 +{
3437 + struct ebt_pkttype_info *info = (struct ebt_pkttype_info *)data;
3438 +
3439 + return (skb->pkt_type != info->pkt_type) ^ info->invert;
3440 +}
3441 +
3442 +static int ebt_pkttype_check(const char *tablename, unsigned int hookmask,
3443 + const struct ebt_entry *e, void *data, unsigned int datalen)
3444 +{
3445 + struct ebt_pkttype_info *info = (struct ebt_pkttype_info *)data;
3446 +
3447 + if (datalen != EBT_ALIGN(sizeof(struct ebt_pkttype_info)))
3448 + return -EINVAL;
3449 + if (info->invert != 0 && info->invert != 1)
3450 + return -EINVAL;
3451 + /* Allow any pkt_type value */
3452 + return 0;
3453 +}
3454 +
3455 +static struct ebt_match filter_pkttype =
3456 +{
3457 + .name = EBT_PKTTYPE_MATCH,
3458 + .match = ebt_filter_pkttype,
3459 + .check = ebt_pkttype_check,
3460 + .me = THIS_MODULE,
3461 +};
3462 +
3463 +static int __init init(void)
3464 +{
3465 + return ebt_register_match(&filter_pkttype);
3466 +}
3467 +
3468 +static void __exit fini(void)
3469 +{
3470 + ebt_unregister_match(&filter_pkttype);
3471 +}
3472 +
3473 +module_init(init);
3474 +module_exit(fini);
3475 +EXPORT_NO_SYMBOLS;
3476 +MODULE_LICENSE("GPL");
3477 diff -Nurb src/linux/linux.stock/net/bridge/netfilter/ebt_redirect.c src/linux/linux/net/bridge/netfilter/ebt_redirect.c
3478 --- src/linux/linux.stock/net/bridge/netfilter/ebt_redirect.c 1969-12-31 19:00:00.000000000 -0500
3479 +++ src/linux/linux/net/bridge/netfilter/ebt_redirect.c 2004-07-10 23:46:39.000000000 -0400
3480 @@ -0,0 +1,71 @@
3481 +/*
3482 + * ebt_redirect
3483 + *
3484 + * Authors:
3485 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
3486 + *
3487 + * April, 2002
3488 + *
3489 + */
3490 +
3491 +#include <linux/netfilter_bridge/ebtables.h>
3492 +#include <linux/netfilter_bridge/ebt_redirect.h>
3493 +#include <linux/module.h>
3494 +#include <net/sock.h>
3495 +#include "../br_private.h"
3496 +
3497 +static int ebt_target_redirect(struct sk_buff **pskb, unsigned int hooknr,
3498 + const struct net_device *in, const struct net_device *out,
3499 + const void *data, unsigned int datalen)
3500 +{
3501 + struct ebt_redirect_info *info = (struct ebt_redirect_info *)data;
3502 +
3503 + if (hooknr != NF_BR_BROUTING)
3504 + memcpy((**pskb).mac.ethernet->h_dest,
3505 + in->br_port->br->dev.dev_addr, ETH_ALEN);
3506 + else {
3507 + memcpy((**pskb).mac.ethernet->h_dest,
3508 + in->dev_addr, ETH_ALEN);
3509 + (*pskb)->pkt_type = PACKET_HOST;
3510 + }
3511 + return info->target;
3512 +}
3513 +
3514 +static int ebt_target_redirect_check(const char *tablename, unsigned int hookmask,
3515 + const struct ebt_entry *e, void *data, unsigned int datalen)
3516 +{
3517 + struct ebt_redirect_info *info = (struct ebt_redirect_info *)data;
3518 +
3519 + if (datalen != EBT_ALIGN(sizeof(struct ebt_redirect_info)))
3520 + return -EINVAL;
3521 + if (BASE_CHAIN && info->target == EBT_RETURN)
3522 + return -EINVAL;
3523 + CLEAR_BASE_CHAIN_BIT;
3524 + if ( (strcmp(tablename, "nat") || hookmask & ~(1 << NF_BR_PRE_ROUTING)) &&
3525 + (strcmp(tablename, "broute") || hookmask & ~(1 << NF_BR_BROUTING)) )
3526 + return -EINVAL;
3527 + if (INVALID_TARGET)
3528 + return -EINVAL;
3529 + return 0;
3530 +}
3531 +
3532 +static struct ebt_target redirect_target =
3533 +{
3534 + {NULL, NULL}, EBT_REDIRECT_TARGET, ebt_target_redirect,
3535 + ebt_target_redirect_check, NULL, THIS_MODULE
3536 +};
3537 +
3538 +static int __init init(void)
3539 +{
3540 + return ebt_register_target(&redirect_target);
3541 +}
3542 +
3543 +static void __exit fini(void)
3544 +{
3545 + ebt_unregister_target(&redirect_target);
3546 +}
3547 +
3548 +module_init(init);
3549 +module_exit(fini);
3550 +EXPORT_NO_SYMBOLS;
3551 +MODULE_LICENSE("GPL");
3552 diff -Nurb src/linux/linux.stock/net/bridge/netfilter/ebt_snat.c src/linux/linux/net/bridge/netfilter/ebt_snat.c
3553 --- src/linux/linux.stock/net/bridge/netfilter/ebt_snat.c 1969-12-31 19:00:00.000000000 -0500
3554 +++ src/linux/linux/net/bridge/netfilter/ebt_snat.c 2004-07-10 23:46:39.000000000 -0400
3555 @@ -0,0 +1,64 @@
3556 +/*
3557 + * ebt_snat
3558 + *
3559 + * Authors:
3560 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
3561 + *
3562 + * June, 2002
3563 + *
3564 + */
3565 +
3566 +#include <linux/netfilter_bridge/ebtables.h>
3567 +#include <linux/netfilter_bridge/ebt_nat.h>
3568 +#include <linux/module.h>
3569 +
3570 +static int ebt_target_snat(struct sk_buff **pskb, unsigned int hooknr,
3571 + const struct net_device *in, const struct net_device *out,
3572 + const void *data, unsigned int datalen)
3573 +{
3574 + struct ebt_nat_info *info = (struct ebt_nat_info *) data;
3575 +
3576 + memcpy(((**pskb).mac.ethernet)->h_source, info->mac,
3577 + ETH_ALEN * sizeof(unsigned char));
3578 + return info->target;
3579 +}
3580 +
3581 +static int ebt_target_snat_check(const char *tablename, unsigned int hookmask,
3582 + const struct ebt_entry *e, void *data, unsigned int datalen)
3583 +{
3584 + struct ebt_nat_info *info = (struct ebt_nat_info *) data;
3585 +
3586 + if (datalen != EBT_ALIGN(sizeof(struct ebt_nat_info)))
3587 + return -EINVAL;
3588 + if (BASE_CHAIN && info->target == EBT_RETURN)
3589 + return -EINVAL;
3590 + CLEAR_BASE_CHAIN_BIT;
3591 + if (strcmp(tablename, "nat"))
3592 + return -EINVAL;
3593 + if (hookmask & ~(1 << NF_BR_POST_ROUTING))
3594 + return -EINVAL;
3595 + if (INVALID_TARGET)
3596 + return -EINVAL;
3597 + return 0;
3598 +}
3599 +
3600 +static struct ebt_target snat =
3601 +{
3602 + {NULL, NULL}, EBT_SNAT_TARGET, ebt_target_snat, ebt_target_snat_check,
3603 + NULL, THIS_MODULE
3604 +};
3605 +
3606 +static int __init init(void)
3607 +{
3608 + return ebt_register_target(&snat);
3609 +}
3610 +
3611 +static void __exit fini(void)
3612 +{
3613 + ebt_unregister_target(&snat);
3614 +}
3615 +
3616 +module_init(init);
3617 +module_exit(fini);
3618 +EXPORT_NO_SYMBOLS;
3619 +MODULE_LICENSE("GPL");
3620 diff -Nurb src/linux/linux.stock/net/bridge/netfilter/ebt_stp.c src/linux/linux/net/bridge/netfilter/ebt_stp.c
3621 --- src/linux/linux.stock/net/bridge/netfilter/ebt_stp.c 1969-12-31 19:00:00.000000000 -0500
3622 +++ src/linux/linux/net/bridge/netfilter/ebt_stp.c 2004-07-10 23:46:39.000000000 -0400
3623 @@ -0,0 +1,191 @@
3624 +/*
3625 + * ebt_stp
3626 + *
3627 + * Authors:
3628 + * Bart De Schuymer <bdschuym@pandora.be>
3629 + * Stephen Hemminger <shemminger@osdl.org>
3630 + *
3631 + * June, 2003
3632 + */
3633 +
3634 +#include <linux/netfilter_bridge/ebtables.h>
3635 +#include <linux/netfilter_bridge/ebt_stp.h>
3636 +#include <linux/module.h>
3637 +
3638 +#define BPDU_TYPE_CONFIG 0
3639 +#define BPDU_TYPE_TCN 0x80
3640 +
3641 +struct stp_header {
3642 + uint8_t dsap;
3643 + uint8_t ssap;
3644 + uint8_t ctrl;
3645 + uint8_t pid;
3646 + uint8_t vers;
3647 + uint8_t type;
3648 +};
3649 +
3650 +struct stp_config_pdu {
3651 + uint8_t flags;
3652 + uint8_t root[8];
3653 + uint8_t root_cost[4];
3654 + uint8_t sender[8];
3655 + uint8_t port[2];
3656 + uint8_t msg_age[2];
3657 + uint8_t max_age[2];
3658 + uint8_t hello_time[2];
3659 + uint8_t forward_delay[2];
3660 +};
3661 +
3662 +#define NR16(p) (p[0] << 8 | p[1])
3663 +#define NR32(p) ((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3])
3664 +
3665 +static int ebt_filter_config(struct ebt_stp_info *info,
3666 + struct stp_config_pdu *stpc)
3667 +{
3668 + struct ebt_stp_config_info *c;
3669 + uint16_t v16;
3670 + uint32_t v32;
3671 + int verdict, i;
3672 +
3673 + c = &info->config;
3674 + if ((info->bitmask & EBT_STP_FLAGS) &&
3675 + FWINV(c->flags != stpc->flags, EBT_STP_FLAGS))
3676 + return EBT_NOMATCH;
3677 + if (info->bitmask & EBT_STP_ROOTPRIO) {
3678 + v16 = NR16(stpc->root);
3679 + if (FWINV(v16 < c->root_priol ||
3680 + v16 > c->root_priou, EBT_STP_ROOTPRIO))
3681 + return EBT_NOMATCH;
3682 + }
3683 + if (info->bitmask & EBT_STP_ROOTADDR) {
3684 + verdict = 0;
3685 + for (i = 0; i < 6; i++)
3686 + verdict |= (stpc->root[2+i] ^ c->root_addr[i]) &
3687 + c->root_addrmsk[i];
3688 + if (FWINV(verdict != 0, EBT_STP_ROOTADDR))
3689 + return EBT_NOMATCH;
3690 + }
3691 + if (info->bitmask & EBT_STP_ROOTCOST) {
3692 + v32 = NR32(stpc->root_cost);
3693 + if (FWINV(v32 < c->root_costl ||
3694 + v32 > c->root_costu, EBT_STP_ROOTCOST))
3695 + return EBT_NOMATCH;
3696 + }
3697 + if (info->bitmask & EBT_STP_SENDERPRIO) {
3698 + v16 = NR16(stpc->sender);
3699 + if (FWINV(v16 < c->sender_priol ||
3700 + v16 > c->sender_priou, EBT_STP_SENDERPRIO))
3701 + return EBT_NOMATCH;
3702 + }
3703 + if (info->bitmask & EBT_STP_SENDERADDR) {
3704 + verdict = 0;
3705 + for (i = 0; i < 6; i++)
3706 + verdict |= (stpc->sender[2+i] ^ c->sender_addr[i]) &
3707 + c->sender_addrmsk[i];
3708 + if (FWINV(verdict != 0, EBT_STP_SENDERADDR))
3709 + return EBT_NOMATCH;
3710 + }
3711 + if (info->bitmask & EBT_STP_PORT) {
3712 + v16 = NR16(stpc->port);
3713 + if (FWINV(v16 < c->portl ||
3714 + v16 > c->portu, EBT_STP_PORT))
3715 + return EBT_NOMATCH;
3716 + }
3717 + if (info->bitmask & EBT_STP_MSGAGE) {
3718 + v16 = NR16(stpc->msg_age);
3719 + if (FWINV(v16 < c->msg_agel ||
3720 + v16 > c->msg_ageu, EBT_STP_MSGAGE))
3721 + return EBT_NOMATCH;
3722 + }
3723 + if (info->bitmask & EBT_STP_MAXAGE) {
3724 + v16 = NR16(stpc->max_age);
3725 + if (FWINV(v16 < c->max_agel ||
3726 + v16 > c->max_ageu, EBT_STP_MAXAGE))
3727 + return EBT_NOMATCH;
3728 + }
3729 + if (info->bitmask & EBT_STP_HELLOTIME) {
3730 + v16 = NR16(stpc->hello_time);
3731 + if (FWINV(v16 < c->hello_timel ||
3732 + v16 > c->hello_timeu, EBT_STP_HELLOTIME))
3733 + return EBT_NOMATCH;
3734 + }
3735 + if (info->bitmask & EBT_STP_FWDD) {
3736 + v16 = NR16(stpc->forward_delay);
3737 + if (FWINV(v16 < c->forward_delayl ||
3738 + v16 > c->forward_delayu, EBT_STP_FWDD))
3739 + return EBT_NOMATCH;
3740 + }
3741 + return EBT_MATCH;
3742 +}
3743 +
3744 +static int ebt_filter_stp(const struct sk_buff *skb, const struct net_device *in,
3745 + const struct net_device *out, const void *data, unsigned int datalen)
3746 +{
3747 + struct ebt_stp_info *info = (struct ebt_stp_info *)data;
3748 + struct stp_header stph;
3749 + uint8_t header[6] = {0x42, 0x42, 0x03, 0x00, 0x00, 0x00};
3750 + if (skb_copy_bits(skb, 0, &stph, sizeof(stph)))
3751 + return EBT_NOMATCH;
3752 +
3753 + /* The stp code only considers these */
3754 + if (memcmp(&stph, header, sizeof(header)))
3755 + return EBT_NOMATCH;
3756 +
3757 + if (info->bitmask & EBT_STP_TYPE
3758 + && FWINV(info->type != stph.type, EBT_STP_TYPE))
3759 + return EBT_NOMATCH;
3760 +
3761 + if (stph.type == BPDU_TYPE_CONFIG &&
3762 + info->bitmask & EBT_STP_CONFIG_MASK) {
3763 + struct stp_config_pdu stpc;
3764 +
3765 + if (skb_copy_bits(skb, sizeof(stph), &stpc, sizeof(stpc)))
3766 + return EBT_NOMATCH;
3767 + return ebt_filter_config(info, &stpc);
3768 + }
3769 + return EBT_MATCH;
3770 +}
3771 +
3772 +static int ebt_stp_check(const char *tablename, unsigned int hookmask,
3773 + const struct ebt_entry *e, void *data, unsigned int datalen)
3774 +{
3775 + struct ebt_stp_info *info = (struct ebt_stp_info *)data;
3776 + int len = EBT_ALIGN(sizeof(struct ebt_stp_info));
3777 + uint8_t bridge_ula[6] = { 0x01, 0x80, 0xc2, 0x00, 0x00, 0x00 };
3778 + uint8_t msk[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
3779 +
3780 + if (info->bitmask & ~EBT_STP_MASK || info->invflags & ~EBT_STP_MASK ||
3781 + !(info->bitmask & EBT_STP_MASK))
3782 + return -EINVAL;
3783 + if (datalen != len)
3784 + return -EINVAL;
3785 + /* Make sure the match only receives stp frames */
3786 + if (memcmp(e->destmac, bridge_ula, ETH_ALEN) ||
3787 + memcmp(e->destmsk, msk, ETH_ALEN) || !(e->bitmask & EBT_DESTMAC))
3788 + return -EINVAL;
3789 +
3790 + return 0;
3791 +}
3792 +
3793 +static struct ebt_match filter_stp =
3794 +{
3795 + .name = EBT_STP_MATCH,
3796 + .match = ebt_filter_stp,
3797 + .check = ebt_stp_check,
3798 + .me = THIS_MODULE,
3799 +};
3800 +
3801 +static int __init init(void)
3802 +{
3803 + return ebt_register_match(&filter_stp);
3804 +}
3805 +
3806 +static void __exit fini(void)
3807 +{
3808 + ebt_unregister_match(&filter_stp);
3809 +}
3810 +
3811 +module_init(init);
3812 +module_exit(fini);
3813 +EXPORT_NO_SYMBOLS;
3814 +MODULE_LICENSE("GPL");
3815 diff -Nurb src/linux/linux.stock/net/bridge/netfilter/ebt_vlan.c src/linux/linux/net/bridge/netfilter/ebt_vlan.c
3816 --- src/linux/linux.stock/net/bridge/netfilter/ebt_vlan.c 1969-12-31 19:00:00.000000000 -0500
3817 +++ src/linux/linux/net/bridge/netfilter/ebt_vlan.c 2004-07-10 23:46:39.000000000 -0400
3818 @@ -0,0 +1,259 @@
3819 +/*
3820 + * Description: EBTables 802.1Q match extension kernelspace module.
3821 + * Authors: Nick Fedchik <nick@fedchik.org.ua>
3822 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
3823 + *
3824 + * This program is free software; you can redistribute it and/or modify
3825 + * it under the terms of the GNU General Public License as published by
3826 + * the Free Software Foundation; either version 2 of the License, or
3827 + * (at your option) any later version.
3828 + *
3829 + * This program is distributed in the hope that it will be useful,
3830 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3831 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3832 + * GNU General Public License for more details.
3833 + *
3834 + * You should have received a copy of the GNU General Public License
3835 + * along with this program; if not, write to the Free Software
3836 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
3837 + */
3838 +
3839 +#include <linux/if_ether.h>
3840 +#include <linux/if_vlan.h>
3841 +#include <linux/module.h>
3842 +#include <linux/netfilter_bridge/ebtables.h>
3843 +#include <linux/netfilter_bridge/ebt_vlan.h>
3844 +
3845 +static unsigned char debug;
3846 +#define MODULE_VERSION "0.6"
3847 +
3848 +MODULE_PARM(debug, "0-1b");
3849 +MODULE_PARM_DESC(debug, "debug=1 is turn on debug messages");
3850 +MODULE_AUTHOR("Nick Fedchik <nick@fedchik.org.ua>");
3851 +MODULE_DESCRIPTION("802.1Q match module (ebtables extension), v"
3852 + MODULE_VERSION);
3853 +MODULE_LICENSE("GPL");
3854 +
3855 +
3856 +#define DEBUG_MSG(args...) if (debug) printk (KERN_DEBUG "ebt_vlan: " args)
3857 +#define INV_FLAG(_inv_flag_) (info->invflags & _inv_flag_) ? "!" : ""
3858 +#define GET_BITMASK(_BIT_MASK_) info->bitmask & _BIT_MASK_
3859 +#define SET_BITMASK(_BIT_MASK_) info->bitmask |= _BIT_MASK_
3860 +#define EXIT_ON_MISMATCH(_MATCH_,_MASK_) if (!((info->_MATCH_ == _MATCH_)^!!(info->invflags & _MASK_))) return 1;
3861 +
3862 +/*
3863 + * Function description: ebt_filter_vlan() is main engine for
3864 + * checking passed 802.1Q frame according to
3865 + * the passed extension parameters (in the *data buffer)
3866 + * ebt_filter_vlan() is called after successfull check the rule params
3867 + * by ebt_check_vlan() function.
3868 + * Parameters:
3869 + * const struct sk_buff *skb - pointer to passed ethernet frame buffer
3870 + * const void *data - pointer to passed extension parameters
3871 + * unsigned int datalen - length of passed *data buffer
3872 + * const struct net_device *in -
3873 + * const struct net_device *out -
3874 + * const struct ebt_counter *c -
3875 + * Returned values:
3876 + * 0 - ok (all rule params matched)
3877 + * 1 - miss (rule params not acceptable to the parsed frame)
3878 + */
3879 +static int
3880 +ebt_filter_vlan(const struct sk_buff *skb,
3881 + const struct net_device *in,
3882 + const struct net_device *out,
3883 + const void *data, unsigned int datalen)
3884 +{
3885 + struct ebt_vlan_info *info = (struct ebt_vlan_info *) data; /* userspace data */
3886 + struct vlan_ethhdr *frame = (struct vlan_ethhdr *) skb->mac.raw; /* Passed tagged frame */
3887 +
3888 + unsigned short TCI; /* Whole TCI, given from parsed frame */
3889 + unsigned short id; /* VLAN ID, given from frame TCI */
3890 + unsigned char prio; /* user_priority, given from frame TCI */
3891 + unsigned short encap; /* VLAN encapsulated Type/Length field, given from orig frame */
3892 +
3893 + /*
3894 + * Tag Control Information (TCI) consists of the following elements:
3895 + * - User_priority. The user_priority field is three bits in length,
3896 + * interpreted as a binary number.
3897 + * - Canonical Format Indicator (CFI). The Canonical Format Indicator
3898 + * (CFI) is a single bit flag value. Currently ignored.
3899 + * - VLAN Identifier (VID). The VID is encoded as
3900 + * an unsigned binary number.
3901 + */
3902 + TCI = ntohs(frame->h_vlan_TCI);
3903 + id = TCI & VLAN_VID_MASK;
3904 + prio = (TCI >> 13) & 0x7;
3905 + encap = frame->h_vlan_encapsulated_proto;
3906 +
3907 + /*
3908 + * Checking VLAN Identifier (VID)
3909 + */
3910 + if (GET_BITMASK(EBT_VLAN_ID)) { /* Is VLAN ID parsed? */
3911 + EXIT_ON_MISMATCH(id, EBT_VLAN_ID);
3912 + }
3913 + /*
3914 + * Checking user_priority
3915 + */
3916 + if (GET_BITMASK(EBT_VLAN_PRIO)) { /* Is VLAN user_priority parsed? */
3917 + EXIT_ON_MISMATCH(prio, EBT_VLAN_PRIO);
3918 + }
3919 + /*
3920 + * Checking Encapsulated Proto (Length/Type) field
3921 + */
3922 + if (GET_BITMASK(EBT_VLAN_ENCAP)) { /* Is VLAN Encap parsed? */
3923 + EXIT_ON_MISMATCH(encap, EBT_VLAN_ENCAP);
3924 + }
3925 + /*
3926 + * All possible extension parameters was parsed.
3927 + * If rule never returned by missmatch, then all ok.
3928 + */
3929 + return 0;
3930 +}
3931 +
3932 +/*
3933 + * Function description: ebt_vlan_check() is called when userspace
3934 + * delivers the table entry to the kernel,
3935 + * and to check that userspace doesn't give a bad table.
3936 + * Parameters:
3937 + * const char *tablename - table name string
3938 + * unsigned int hooknr - hook number
3939 + * const struct ebt_entry *e - ebtables entry basic set
3940 + * const void *data - pointer to passed extension parameters
3941 + * unsigned int datalen - length of passed *data buffer
3942 + * Returned values:
3943 + * 0 - ok (all delivered rule params are correct)
3944 + * 1 - miss (rule params is out of range, invalid, incompatible, etc.)
3945 + */
3946 +static int
3947 +ebt_check_vlan(const char *tablename,
3948 + unsigned int hooknr,
3949 + const struct ebt_entry *e, void *data, unsigned int datalen)
3950 +{
3951 + struct ebt_vlan_info *info = (struct ebt_vlan_info *) data;
3952 +
3953 + /*
3954 + * Parameters buffer overflow check
3955 + */
3956 + if (datalen != EBT_ALIGN(sizeof(struct ebt_vlan_info))) {
3957 + DEBUG_MSG
3958 + ("passed size %d is not eq to ebt_vlan_info (%d)\n",
3959 + datalen, sizeof(struct ebt_vlan_info));
3960 + return -EINVAL;
3961 + }
3962 +
3963 + /*
3964 + * Is it 802.1Q frame checked?
3965 + */
3966 + if (e->ethproto != __constant_htons(ETH_P_8021Q)) {
3967 + DEBUG_MSG
3968 + ("passed entry proto %2.4X is not 802.1Q (8100)\n",
3969 + (unsigned short) ntohs(e->ethproto));
3970 + return -EINVAL;
3971 + }
3972 +
3973 + /*
3974 + * Check for bitmask range
3975 + * True if even one bit is out of mask
3976 + */
3977 + if (info->bitmask & ~EBT_VLAN_MASK) {
3978 + DEBUG_MSG("bitmask %2X is out of mask (%2X)\n",
3979 + info->bitmask, EBT_VLAN_MASK);
3980 + return -EINVAL;
3981 + }
3982 +
3983 + /*
3984 + * Check for inversion flags range
3985 + */
3986 + if (info->invflags & ~EBT_VLAN_MASK) {
3987 + DEBUG_MSG("inversion flags %2X is out of mask (%2X)\n",
3988 + info->invflags, EBT_VLAN_MASK);
3989 + return -EINVAL;
3990 + }
3991 +
3992 + /*
3993 + * Reserved VLAN ID (VID) values
3994 + * -----------------------------
3995 + * 0 - The null VLAN ID.
3996 + * 1 - The default Port VID (PVID)
3997 + * 0x0FFF - Reserved for implementation use.
3998 + * if_vlan.h: VLAN_GROUP_ARRAY_LEN 4096.
3999 + */
4000 + if (GET_BITMASK(EBT_VLAN_ID)) { /* when vlan-id param was spec-ed */
4001 + if (!!info->id) { /* if id!=0 => check vid range */
4002 + if (info->id > VLAN_GROUP_ARRAY_LEN) {
4003 + DEBUG_MSG
4004 + ("id %d is out of range (1-4096)\n",
4005 + info->id);
4006 + return -EINVAL;
4007 + }
4008 + /*
4009 + * Note: This is valid VLAN-tagged frame point.
4010 + * Any value of user_priority are acceptable,
4011 + * but should be ignored according to 802.1Q Std.
4012 + * So we just drop the prio flag.
4013 + */
4014 + info->bitmask &= ~EBT_VLAN_PRIO;
4015 + }
4016 + /*
4017 + * Else, id=0 (null VLAN ID) => user_priority range (any?)
4018 + */
4019 + }
4020 +
4021 + if (GET_BITMASK(EBT_VLAN_PRIO)) {
4022 + if ((unsigned char) info->prio > 7) {
4023 + DEBUG_MSG
4024 + ("prio %d is out of range (0-7)\n",
4025 + info->prio);
4026 + return -EINVAL;
4027 + }
4028 + }
4029 + /*
4030 + * Check for encapsulated proto range - it is possible to be
4031 + * any value for u_short range.
4032 + * if_ether.h: ETH_ZLEN 60 - Min. octets in frame sans FCS
4033 + */
4034 + if (GET_BITMASK(EBT_VLAN_ENCAP)) {
4035 + if ((unsigned short) ntohs(info->encap) < ETH_ZLEN) {
4036 + DEBUG_MSG
4037 + ("encap frame length %d is less than minimal\n",
4038 + ntohs(info->encap));
4039 + return -EINVAL;
4040 + }
4041 + }
4042 +
4043 + return 0;
4044 +}
4045 +
4046 +static struct ebt_match filter_vlan = {
4047 + {NULL, NULL},
4048 + EBT_VLAN_MATCH,
4049 + ebt_filter_vlan,
4050 + ebt_check_vlan,
4051 + NULL,
4052 + THIS_MODULE
4053 +};
4054 +
4055 +/*
4056 + * Module initialization function.
4057 + */
4058 +static int __init init(void)
4059 +{
4060 + DEBUG_MSG("ebtables 802.1Q extension module v"
4061 + MODULE_VERSION "\n");
4062 + DEBUG_MSG("module debug=%d\n", !!debug);
4063 + return ebt_register_match(&filter_vlan);
4064 +}
4065 +
4066 +/*
4067 + * Module "finalization" function
4068 + */
4069 +static void __exit fini(void)
4070 +{
4071 + ebt_unregister_match(&filter_vlan);
4072 +}
4073 +
4074 +module_init(init);
4075 +module_exit(fini);
4076 +
4077 +EXPORT_NO_SYMBOLS;
4078 diff -Nurb src/linux/linux.stock/net/bridge/netfilter/ebtable_broute.c src/linux/linux/net/bridge/netfilter/ebtable_broute.c
4079 --- src/linux/linux.stock/net/bridge/netfilter/ebtable_broute.c 1969-12-31 19:00:00.000000000 -0500
4080 +++ src/linux/linux/net/bridge/netfilter/ebtable_broute.c 2004-07-10 23:46:39.000000000 -0400
4081 @@ -0,0 +1,79 @@
4082 +/*
4083 + * ebtable_broute
4084 + *
4085 + * Authors:
4086 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
4087 + *
4088 + * April, 2002
4089 + *
4090 + * This table lets you choose between routing and bridging for frames
4091 + * entering on a bridge enslaved nic. This table is traversed before any
4092 + * other ebtables table. See net/bridge/br_input.c.
4093 + */
4094 +
4095 +#include <linux/netfilter_bridge/ebtables.h>
4096 +#include <linux/module.h>
4097 +#include <linux/if_bridge.h>
4098 +#include <linux/brlock.h>
4099 +
4100 +// EBT_ACCEPT means the frame will be bridged
4101 +// EBT_DROP means the frame will be routed
4102 +static struct ebt_entries initial_chain =
4103 + {0, "BROUTING", 0, EBT_ACCEPT, 0};
4104 +
4105 +static struct ebt_replace initial_table =
4106 +{
4107 + "broute", 1 << NF_BR_BROUTING, 0, sizeof(struct ebt_entries),
4108 + { [NF_BR_BROUTING]&initial_chain}, 0, NULL, (char *)&initial_chain
4109 +};
4110 +
4111 +static int check(const struct ebt_table_info *info, unsigned int valid_hooks)
4112 +{
4113 + if (valid_hooks & ~(1 << NF_BR_BROUTING))
4114 + return -EINVAL;
4115 + return 0;
4116 +}
4117 +
4118 +static struct ebt_table broute_table =
4119 +{
4120 + {NULL, NULL}, "broute", &initial_table, 1 << NF_BR_BROUTING,
4121 + RW_LOCK_UNLOCKED, check, NULL
4122 +};
4123 +
4124 +static int ebt_broute(struct sk_buff **pskb)
4125 +{
4126 + int ret;
4127 +
4128 + ret = ebt_do_table(NF_BR_BROUTING, pskb, (*pskb)->dev, NULL,
4129 + &broute_table);
4130 + if (ret == NF_DROP)
4131 + return 1; // route it
4132 + return 0; // bridge it
4133 +}
4134 +
4135 +static int __init init(void)
4136 +{
4137 + int ret;
4138 +
4139 + ret = ebt_register_table(&broute_table);
4140 + if (ret < 0)
4141 + return ret;
4142 + br_write_lock_bh(BR_NETPROTO_LOCK);
4143 + // see br_input.c
4144 + br_should_route_hook = ebt_broute;
4145 + br_write_unlock_bh(BR_NETPROTO_LOCK);
4146 + return ret;
4147 +}
4148 +
4149 +static void __exit fini(void)
4150 +{
4151 + br_write_lock_bh(BR_NETPROTO_LOCK);
4152 + br_should_route_hook = NULL;
4153 + br_write_unlock_bh(BR_NETPROTO_LOCK);
4154 + ebt_unregister_table(&broute_table);
4155 +}
4156 +
4157 +module_init(init);
4158 +module_exit(fini);
4159 +EXPORT_NO_SYMBOLS;
4160 +MODULE_LICENSE("GPL");
4161 diff -Nurb src/linux/linux.stock/net/bridge/netfilter/ebtable_filter.c src/linux/linux/net/bridge/netfilter/ebtable_filter.c
4162 --- src/linux/linux.stock/net/bridge/netfilter/ebtable_filter.c 1969-12-31 19:00:00.000000000 -0500
4163 +++ src/linux/linux/net/bridge/netfilter/ebtable_filter.c 2004-07-10 23:46:39.000000000 -0400
4164 @@ -0,0 +1,90 @@
4165 +/*
4166 + * ebtable_filter
4167 + *
4168 + * Authors:
4169 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
4170 + *
4171 + * April, 2002
4172 + *
4173 + */
4174 +
4175 +#include <linux/netfilter_bridge/ebtables.h>
4176 +#include <linux/module.h>
4177 +
4178 +#define FILTER_VALID_HOOKS ((1 << NF_BR_LOCAL_IN) | (1 << NF_BR_FORWARD) | \
4179 + (1 << NF_BR_LOCAL_OUT))
4180 +
4181 +static struct ebt_entries initial_chains[] =
4182 +{
4183 + {0, "INPUT", 0, EBT_ACCEPT, 0},
4184 + {0, "FORWARD", 0, EBT_ACCEPT, 0},
4185 + {0, "OUTPUT", 0, EBT_ACCEPT, 0}
4186 +};
4187 +
4188 +static struct ebt_replace initial_table =
4189 +{
4190 + "filter", FILTER_VALID_HOOKS, 0, 3 * sizeof(struct ebt_entries),
4191 + { [NF_BR_LOCAL_IN]&initial_chains[0], [NF_BR_FORWARD]&initial_chains[1],
4192 + [NF_BR_LOCAL_OUT]&initial_chains[2] }, 0, NULL, (char *)initial_chains
4193 +};
4194 +
4195 +static int check(const struct ebt_table_info *info, unsigned int valid_hooks)
4196 +{
4197 + if (valid_hooks & ~FILTER_VALID_HOOKS)
4198 + return -EINVAL;
4199 + return 0;
4200 +}
4201 +
4202 +static struct ebt_table frame_filter =
4203 +{
4204 + {NULL, NULL}, "filter", &initial_table, FILTER_VALID_HOOKS,
4205 + RW_LOCK_UNLOCKED, check, NULL
4206 +};
4207 +
4208 +static unsigned int
4209 +ebt_hook (unsigned int hook, struct sk_buff **pskb, const struct net_device *in,
4210 + const struct net_device *out, int (*okfn)(struct sk_buff *))
4211 +{
4212 + return ebt_do_table(hook, pskb, in, out, &frame_filter);
4213 +}
4214 +
4215 +static struct nf_hook_ops ebt_ops_filter[] = {
4216 + { { NULL, NULL }, ebt_hook, PF_BRIDGE, NF_BR_LOCAL_IN,
4217 + NF_BR_PRI_FILTER_BRIDGED},
4218 + { { NULL, NULL }, ebt_hook, PF_BRIDGE, NF_BR_FORWARD,
4219 + NF_BR_PRI_FILTER_BRIDGED},
4220 + { { NULL, NULL }, ebt_hook, PF_BRIDGE, NF_BR_LOCAL_OUT,
4221 + NF_BR_PRI_FILTER_OTHER}
4222 +};
4223 +
4224 +static int __init init(void)
4225 +{
4226 + int i, j, ret;
4227 +
4228 + ret = ebt_register_table(&frame_filter);
4229 + if (ret < 0)
4230 + return ret;
4231 + for (i = 0; i < sizeof(ebt_ops_filter) / sizeof(ebt_ops_filter[0]); i++)
4232 + if ((ret = nf_register_hook(&ebt_ops_filter[i])) < 0)
4233 + goto cleanup;
4234 + return ret;
4235 +cleanup:
4236 + for (j = 0; j < i; j++)
4237 + nf_unregister_hook(&ebt_ops_filter[j]);
4238 + ebt_unregister_table(&frame_filter);
4239 + return ret;
4240 +}
4241 +
4242 +static void __exit fini(void)
4243 +{
4244 + int i;
4245 +
4246 + for (i = 0; i < sizeof(ebt_ops_filter) / sizeof(ebt_ops_filter[0]); i++)
4247 + nf_unregister_hook(&ebt_ops_filter[i]);
4248 + ebt_unregister_table(&frame_filter);
4249 +}
4250 +
4251 +module_init(init);
4252 +module_exit(fini);
4253 +EXPORT_NO_SYMBOLS;
4254 +MODULE_LICENSE("GPL");
4255 diff -Nurb src/linux/linux.stock/net/bridge/netfilter/ebtable_nat.c src/linux/linux/net/bridge/netfilter/ebtable_nat.c
4256 --- src/linux/linux.stock/net/bridge/netfilter/ebtable_nat.c 1969-12-31 19:00:00.000000000 -0500
4257 +++ src/linux/linux/net/bridge/netfilter/ebtable_nat.c 2004-07-10 23:46:39.000000000 -0400
4258 @@ -0,0 +1,96 @@
4259 +/*
4260 + * ebtable_nat
4261 + *
4262 + * Authors:
4263 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
4264 + *
4265 + * April, 2002
4266 + *
4267 + */
4268 +
4269 +#include <linux/netfilter_bridge/ebtables.h>
4270 +#include <linux/module.h>
4271 +#define NAT_VALID_HOOKS ((1 << NF_BR_PRE_ROUTING) | (1 << NF_BR_LOCAL_OUT) | \
4272 + (1 << NF_BR_POST_ROUTING))
4273 +
4274 +static struct ebt_entries initial_chains[] =
4275 +{
4276 + {0, "PREROUTING", 0, EBT_ACCEPT, 0},
4277 + {0, "OUTPUT", 0, EBT_ACCEPT, 0},
4278 + {0, "POSTROUTING", 0, EBT_ACCEPT, 0}
4279 +};
4280 +
4281 +static struct ebt_replace initial_table =
4282 +{
4283 + "nat", NAT_VALID_HOOKS, 0, 3 * sizeof(struct ebt_entries),
4284 + { [NF_BR_PRE_ROUTING]&initial_chains[0], [NF_BR_LOCAL_OUT]&initial_chains[1],
4285 + [NF_BR_POST_ROUTING]&initial_chains[2] }, 0, NULL, (char *)initial_chains
4286 +};
4287 +
4288 +static int check(const struct ebt_table_info *info, unsigned int valid_hooks)
4289 +{
4290 + if (valid_hooks & ~NAT_VALID_HOOKS)
4291 + return -EINVAL;
4292 + return 0;
4293 +}
4294 +
4295 +static struct ebt_table frame_nat =
4296 +{
4297 + {NULL, NULL}, "nat", &initial_table, NAT_VALID_HOOKS,
4298 + RW_LOCK_UNLOCKED, check, NULL
4299 +};
4300 +
4301 +static unsigned int
4302 +ebt_nat_dst(unsigned int hook, struct sk_buff **pskb, const struct net_device *in
4303 + , const struct net_device *out, int (*okfn)(struct sk_buff *))
4304 +{
4305 + return ebt_do_table(hook, pskb, in, out, &frame_nat);
4306 +}
4307 +
4308 +static unsigned int
4309 +ebt_nat_src(unsigned int hook, struct sk_buff **pskb, const struct net_device *in
4310 + , const struct net_device *out, int (*okfn)(struct sk_buff *))
4311 +{
4312 + return ebt_do_table(hook, pskb, in, out, &frame_nat);
4313 +}
4314 +
4315 +static struct nf_hook_ops ebt_ops_nat[] = {
4316 + { { NULL, NULL }, ebt_nat_dst, PF_BRIDGE, NF_BR_LOCAL_OUT,
4317 + NF_BR_PRI_NAT_DST_OTHER},
4318 + { { NULL, NULL }, ebt_nat_src, PF_BRIDGE, NF_BR_POST_ROUTING,
4319 + NF_BR_PRI_NAT_SRC},
4320 + { { NULL, NULL }, ebt_nat_dst, PF_BRIDGE, NF_BR_PRE_ROUTING,
4321 + NF_BR_PRI_NAT_DST_BRIDGED},
4322 +};
4323 +
4324 +static int __init init(void)
4325 +{
4326 + int i, ret, j;
4327 +
4328 + ret = ebt_register_table(&frame_nat);
4329 + if (ret < 0)
4330 + return ret;
4331 + for (i = 0; i < sizeof(ebt_ops_nat) / sizeof(ebt_ops_nat[0]); i++)
4332 + if ((ret = nf_register_hook(&ebt_ops_nat[i])) < 0)
4333 + goto cleanup;
4334 + return ret;
4335 +cleanup:
4336 + for (j = 0; j < i; j++)
4337 + nf_unregister_hook(&ebt_ops_nat[j]);
4338 + ebt_unregister_table(&frame_nat);
4339 + return ret;
4340 +}
4341 +
4342 +static void __exit fini(void)
4343 +{
4344 + int i;
4345 +
4346 + for (i = 0; i < sizeof(ebt_ops_nat) / sizeof(ebt_ops_nat[0]); i++)
4347 + nf_unregister_hook(&ebt_ops_nat[i]);
4348 + ebt_unregister_table(&frame_nat);
4349 +}
4350 +
4351 +module_init(init);
4352 +module_exit(fini);
4353 +EXPORT_NO_SYMBOLS;
4354 +MODULE_LICENSE("GPL");
4355 diff -Nurb src/linux/linux.stock/net/bridge/netfilter/ebtables.c src/linux/linux/net/bridge/netfilter/ebtables.c
4356 --- src/linux/linux.stock/net/bridge/netfilter/ebtables.c 1969-12-31 19:00:00.000000000 -0500
4357 +++ src/linux/linux/net/bridge/netfilter/ebtables.c 2004-07-10 23:46:39.000000000 -0400
4358 @@ -0,0 +1,1490 @@
4359 +/*
4360 + * ebtables
4361 + *
4362 + * Author:
4363 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
4364 + *
4365 + * ebtables.c,v 2.0, July, 2002
4366 + *
4367 + * This code is stongly inspired on the iptables code which is
4368 + * Copyright (C) 1999 Paul `Rusty' Russell & Michael J. Neuling
4369 + *
4370 + * This program is free software; you can redistribute it and/or
4371 + * modify it under the terms of the GNU General Public License
4372 + * as published by the Free Software Foundation; either version
4373 + * 2 of the License, or (at your option) any later version.
4374 + */
4375 +
4376 +// used for print_string
4377 +#include <linux/sched.h>
4378 +#include <linux/tty.h>
4379 +
4380 +#include <linux/kmod.h>
4381 +#include <linux/module.h>
4382 +#include <linux/vmalloc.h>
4383 +#include <linux/netfilter_bridge/ebtables.h>
4384 +#include <linux/spinlock.h>
4385 +#include <asm/uaccess.h>
4386 +#include <linux/smp.h>
4387 +#include <net/sock.h>
4388 +// needed for logical [in,out]-dev filtering
4389 +#include "../br_private.h"
4390 +
4391 +// list_named_find
4392 +#define ASSERT_READ_LOCK(x)
4393 +#define ASSERT_WRITE_LOCK(x)
4394 +#include <linux/netfilter_ipv4/listhelp.h>
4395 +
4396 +#if 0 // use this for remote debugging
4397 +// Copyright (C) 1998 by Ori Pomerantz
4398 +// Print the string to the appropriate tty, the one
4399 +// the current task uses
4400 +static void print_string(char *str)
4401 +{
4402 + struct tty_struct *my_tty;
4403 +
4404 + /* The tty for the current task */
4405 + my_tty = current->tty;
4406 + if (my_tty != NULL) {
4407 + (*(my_tty->driver).write)(my_tty, 0, str, strlen(str));
4408 + (*(my_tty->driver).write)(my_tty, 0, "\015\012", 2);
4409 + }
4410 +}
4411 +
4412 +#define BUGPRINT(args) print_string(args);
4413 +#else
4414 +#define BUGPRINT(format, args...) printk("kernel msg: ebtables bug: please "\
4415 + "report to author: "format, ## args)
4416 +// #define BUGPRINT(format, args...)
4417 +#endif
4418 +#define MEMPRINT(format, args...) printk("kernel msg: ebtables "\
4419 + ": out of memory: "format, ## args)
4420 +// #define MEMPRINT(format, args...)
4421 +
4422 +
4423 +
4424 +// Each cpu has its own set of counters, so there is no need for write_lock in
4425 +// the softirq
4426 +// For reading or updating the counters, the user context needs to
4427 +// get a write_lock
4428 +
4429 +// The size of each set of counters is altered to get cache alignment
4430 +#define SMP_ALIGN(x) (((x) + SMP_CACHE_BYTES-1) & ~(SMP_CACHE_BYTES-1))
4431 +#define COUNTER_OFFSET(n) (SMP_ALIGN(n * sizeof(struct ebt_counter)))
4432 +#define COUNTER_BASE(c, n, cpu) ((struct ebt_counter *)(((char *)c) + \
4433 + COUNTER_OFFSET(n) * cpu))
4434 +
4435 +
4436 +
4437 +static DECLARE_MUTEX(ebt_mutex);
4438 +static LIST_HEAD(ebt_tables);
4439 +static LIST_HEAD(ebt_targets);
4440 +static LIST_HEAD(ebt_matches);
4441 +static LIST_HEAD(ebt_watchers);
4442 +
4443 +static struct ebt_target ebt_standard_target =
4444 +{ {NULL, NULL}, EBT_STANDARD_TARGET, NULL, NULL, NULL, NULL};
4445 +
4446 +static inline int ebt_do_watcher (struct ebt_entry_watcher *w,
4447 + const struct sk_buff *skb, const struct net_device *in,
4448 + const struct net_device *out)
4449 +{
4450 + w->u.watcher->watcher(skb, in, out, w->data,
4451 + w->watcher_size);
4452 + // watchers don't give a verdict
4453 + return 0;
4454 +}
4455 +
4456 +static inline int ebt_do_match (struct ebt_entry_match *m,
4457 + const struct sk_buff *skb, const struct net_device *in,
4458 + const struct net_device *out)
4459 +{
4460 + return m->u.match->match(skb, in, out, m->data,
4461 + m->match_size);
4462 +}
4463 +
4464 +static inline int ebt_dev_check(char *entry, const struct net_device *device)
4465 +{
4466 + if (*entry == '\0')
4467 + return 0;
4468 + if (!device)
4469 + return 1;
4470 + return !!strcmp(entry, device->name);
4471 +}
4472 +
4473 +#define FWINV2(bool,invflg) ((bool) ^ !!(e->invflags & invflg))
4474 +// process standard matches
4475 +static inline int ebt_basic_match(struct ebt_entry *e, struct ethhdr *h,
4476 + const struct net_device *in, const struct net_device *out)
4477 +{
4478 + int verdict, i;
4479 +
4480 + if (e->bitmask & EBT_802_3) {
4481 + if (FWINV2(ntohs(h->h_proto) >= 1536, EBT_IPROTO))
4482 + return 1;
4483 + } else if (!(e->bitmask & EBT_NOPROTO) &&
4484 + FWINV2(e->ethproto != h->h_proto, EBT_IPROTO))
4485 + return 1;
4486 +
4487 + if (FWINV2(ebt_dev_check(e->in, in), EBT_IIN))
4488 + return 1;
4489 + if (FWINV2(ebt_dev_check(e->out, out), EBT_IOUT))
4490 + return 1;
4491 + if ((!in || !in->br_port) ? 0 : FWINV2(ebt_dev_check(
4492 + e->logical_in, &in->br_port->br->dev), EBT_ILOGICALIN))
4493 + return 1;
4494 + if ((!out || !out->br_port) ? 0 : FWINV2(ebt_dev_check(
4495 + e->logical_out, &out->br_port->br->dev), EBT_ILOGICALOUT))
4496 + return 1;
4497 +
4498 + if (e->bitmask & EBT_SOURCEMAC) {
4499 + verdict = 0;
4500 + for (i = 0; i < 6; i++)
4501 + verdict |= (h->h_source[i] ^ e->sourcemac[i]) &
4502 + e->sourcemsk[i];
4503 + if (FWINV2(verdict != 0, EBT_ISOURCE) )
4504 + return 1;
4505 + }
4506 + if (e->bitmask & EBT_DESTMAC) {
4507 + verdict = 0;
4508 + for (i = 0; i < 6; i++)
4509 + verdict |= (h->h_dest[i] ^ e->destmac[i]) &
4510 + e->destmsk[i];
4511 + if (FWINV2(verdict != 0, EBT_IDEST) )
4512 + return 1;
4513 + }
4514 + return 0;
4515 +}
4516 +
4517 +// Do some firewalling
4518 +unsigned int ebt_do_table (unsigned int hook, struct sk_buff **pskb,
4519 + const struct net_device *in, const struct net_device *out,
4520 + struct ebt_table *table)
4521 +{
4522 + int i, nentries;
4523 + struct ebt_entry *point;
4524 + struct ebt_counter *counter_base, *cb_base;
4525 + struct ebt_entry_target *t;
4526 + int verdict, sp = 0;
4527 + struct ebt_chainstack *cs;
4528 + struct ebt_entries *chaininfo;
4529 + char *base;
4530 + struct ebt_table_info *private = table->private;
4531 +
4532 + read_lock_bh(&table->lock);
4533 + cb_base = COUNTER_BASE(private->counters, private->nentries,
4534 + cpu_number_map(smp_processor_id()));
4535 + if (private->chainstack)
4536 + cs = private->chainstack[cpu_number_map(smp_processor_id())];
4537 + else
4538 + cs = NULL;
4539 + chaininfo = private->hook_entry[hook];
4540 + nentries = private->hook_entry[hook]->nentries;
4541 + point = (struct ebt_entry *)(private->hook_entry[hook]->data);
4542 + counter_base = cb_base + private->hook_entry[hook]->counter_offset;
4543 + // base for chain jumps
4544 + base = private->entries;
4545 + i = 0;
4546 + while (i < nentries) {
4547 + if (ebt_basic_match(point, (**pskb).mac.ethernet, in, out))
4548 + goto letscontinue;
4549 +
4550 + if (EBT_MATCH_ITERATE(point, ebt_do_match, *pskb, in, out) != 0)
4551 + goto letscontinue;
4552 +
4553 + // increase counter
4554 + (*(counter_base + i)).pcnt++;
4555 + (*(counter_base + i)).bcnt+=(**pskb).len;
4556 +
4557 + // these should only watch: not modify, nor tell us
4558 + // what to do with the packet
4559 + EBT_WATCHER_ITERATE(point, ebt_do_watcher, *pskb, in,
4560 + out);
4561 +
4562 + t = (struct ebt_entry_target *)
4563 + (((char *)point) + point->target_offset);
4564 + // standard target
4565 + if (!t->u.target->target)
4566 + verdict = ((struct ebt_standard_target *)t)->verdict;
4567 + else
4568 + verdict = t->u.target->target(pskb, hook,
4569 + in, out, t->data, t->target_size);
4570 + if (verdict == EBT_ACCEPT) {
4571 + read_unlock_bh(&table->lock);
4572 + return NF_ACCEPT;
4573 + }
4574 + if (verdict == EBT_DROP) {
4575 + read_unlock_bh(&table->lock);
4576 + return NF_DROP;
4577 + }
4578 + if (verdict == EBT_RETURN) {
4579 +letsreturn:
4580 +#ifdef CONFIG_NETFILTER_DEBUG
4581 + if (sp == 0) {
4582 + BUGPRINT("RETURN on base chain");
4583 + // act like this is EBT_CONTINUE
4584 + goto letscontinue;
4585 + }
4586 +#endif
4587 + sp--;
4588 + // put all the local variables right
4589 + i = cs[sp].n;
4590 + chaininfo = cs[sp].chaininfo;
4591 + nentries = chaininfo->nentries;
4592 + point = cs[sp].e;
4593 + counter_base = cb_base +
4594 + chaininfo->counter_offset;
4595 + continue;
4596 + }
4597 + if (verdict == EBT_CONTINUE)
4598 + goto letscontinue;
4599 +#ifdef CONFIG_NETFILTER_DEBUG
4600 + if (verdict < 0) {
4601 + BUGPRINT("bogus standard verdict\n");
4602 + read_unlock_bh(&table->lock);
4603 + return NF_DROP;
4604 + }
4605 +#endif
4606 + // jump to a udc
4607 + cs[sp].n = i + 1;
4608 + cs[sp].chaininfo = chaininfo;
4609 + cs[sp].e = (struct ebt_entry *)
4610 + (((char *)point) + point->next_offset);
4611 + i = 0;
4612 + chaininfo = (struct ebt_entries *) (base + verdict);
4613 +#ifdef CONFIG_NETFILTER_DEBUG
4614 + if (chaininfo->distinguisher) {
4615 + BUGPRINT("jump to non-chain\n");
4616 + read_unlock_bh(&table->lock);
4617 + return NF_DROP;
4618 + }
4619 +#endif
4620 + nentries = chaininfo->nentries;
4621 + point = (struct ebt_entry *)chaininfo->data;
4622 + counter_base = cb_base + chaininfo->counter_offset;
4623 + sp++;
4624 + continue;
4625 +letscontinue:
4626 + point = (struct ebt_entry *)
4627 + (((char *)point) + point->next_offset);
4628 + i++;
4629 + }
4630 +
4631 + // I actually like this :)
4632 + if (chaininfo->policy == EBT_RETURN)
4633 + goto letsreturn;
4634 + if (chaininfo->policy == EBT_ACCEPT) {
4635 + read_unlock_bh(&table->lock);
4636 + return NF_ACCEPT;
4637 + }
4638 + read_unlock_bh(&table->lock);
4639 + return NF_DROP;
4640 +}
4641 +
4642 +// If it succeeds, returns element and locks mutex
4643 +static inline void *
4644 +find_inlist_lock_noload(struct list_head *head, const char *name, int *error,
4645 + struct semaphore *mutex)
4646 +{
4647 + void *ret;
4648 +
4649 + *error = down_interruptible(mutex);
4650 + if (*error != 0)
4651 + return NULL;
4652 +
4653 + ret = list_named_find(head, name);
4654 + if (!ret) {
4655 + *error = -ENOENT;
4656 + up(mutex);
4657 + }
4658 + return ret;
4659 +}
4660 +
4661 +#ifndef CONFIG_KMOD
4662 +#define find_inlist_lock(h,n,p,e,m) find_inlist_lock_noload((h),(n),(e),(m))
4663 +#else
4664 +static void *
4665 +find_inlist_lock(struct list_head *head, const char *name, const char *prefix,
4666 + int *error, struct semaphore *mutex)
4667 +{
4668 + void *ret;
4669 +
4670 + ret = find_inlist_lock_noload(head, name, error, mutex);
4671 + if (!ret) {
4672 + char modulename[EBT_FUNCTION_MAXNAMELEN + strlen(prefix) + 1];
4673 + strcpy(modulename, prefix);
4674 + strcat(modulename, name);
4675 + request_module(modulename);
4676 + ret = find_inlist_lock_noload(head, name, error, mutex);
4677 + }
4678 + return ret;
4679 +}
4680 +#endif
4681 +
4682 +static inline struct ebt_table *
4683 +find_table_lock(const char *name, int *error, struct semaphore *mutex)
4684 +{
4685 + return find_inlist_lock(&ebt_tables, name, "ebtable_", error, mutex);
4686 +}
4687 +
4688 +static inline struct ebt_match *
4689 +find_match_lock(const char *name, int *error, struct semaphore *mutex)
4690 +{
4691 + return find_inlist_lock(&ebt_matches, name, "ebt_", error, mutex);
4692 +}
4693 +
4694 +static inline struct ebt_watcher *
4695 +find_watcher_lock(const char *name, int *error, struct semaphore *mutex)
4696 +{
4697 + return find_inlist_lock(&ebt_watchers, name, "ebt_", error, mutex);
4698 +}
4699 +
4700 +static inline struct ebt_target *
4701 +find_target_lock(const char *name, int *error, struct semaphore *mutex)
4702 +{
4703 + return find_inlist_lock(&ebt_targets, name, "ebt_", error, mutex);
4704 +}
4705 +
4706 +static inline int
4707 +ebt_check_match(struct ebt_entry_match *m, struct ebt_entry *e,
4708 + const char *name, unsigned int hookmask, unsigned int *cnt)
4709 +{
4710 + struct ebt_match *match;
4711 + int ret;
4712 +
4713 + if (((char *)m) + m->match_size + sizeof(struct ebt_entry_match) >
4714 + ((char *)e) + e->watchers_offset)
4715 + return -EINVAL;
4716 + match = find_match_lock(m->u.name, &ret, &ebt_mutex);
4717 + if (!match)
4718 + return ret;
4719 + m->u.match = match;
4720 + if (match->me)
4721 + __MOD_INC_USE_COUNT(match->me);
4722 + up(&ebt_mutex);
4723 + if (match->check &&
4724 + match->check(name, hookmask, e, m->data, m->match_size) != 0) {
4725 + BUGPRINT("match->check failed\n");
4726 + if (match->me)
4727 + __MOD_DEC_USE_COUNT(match->me);
4728 + return -EINVAL;
4729 + }
4730 + (*cnt)++;
4731 + return 0;
4732 +}
4733 +
4734 +static inline int
4735 +ebt_check_watcher(struct ebt_entry_watcher *w, struct ebt_entry *e,
4736 + const char *name, unsigned int hookmask, unsigned int *cnt)
4737 +{
4738 + struct ebt_watcher *watcher;
4739 + int ret;
4740 +
4741 + if (((char *)w) + w->watcher_size + sizeof(struct ebt_entry_watcher) >
4742 + ((char *)e) + e->target_offset)
4743 + return -EINVAL;
4744 + watcher = find_watcher_lock(w->u.name, &ret, &ebt_mutex);
4745 + if (!watcher)
4746 + return ret;
4747 + w->u.watcher = watcher;
4748 + if (watcher->me)
4749 + __MOD_INC_USE_COUNT(watcher->me);
4750 + up(&ebt_mutex);
4751 + if (watcher->check &&
4752 + watcher->check(name, hookmask, e, w->data, w->watcher_size) != 0) {
4753 + BUGPRINT("watcher->check failed\n");
4754 + if (watcher->me)
4755 + __MOD_DEC_USE_COUNT(watcher->me);
4756 + return -EINVAL;
4757 + }
4758 + (*cnt)++;
4759 + return 0;
4760 +}
4761 +
4762 +// this one is very careful, as it is the first function
4763 +// to parse the userspace data
4764 +static inline int
4765 +ebt_check_entry_size_and_hooks(struct ebt_entry *e,
4766 + struct ebt_table_info *newinfo, char *base, char *limit,
4767 + struct ebt_entries **hook_entries, unsigned int *n, unsigned int *cnt,
4768 + unsigned int *totalcnt, unsigned int *udc_cnt, unsigned int valid_hooks)
4769 +{
4770 + int i;
4771 +
4772 + for (i = 0; i < NF_BR_NUMHOOKS; i++) {
4773 + if ((valid_hooks & (1 << i)) == 0)
4774 + continue;
4775 + if ( (char *)hook_entries[i] - base ==
4776 + (char *)e - newinfo->entries)
4777 + break;
4778 + }
4779 + // beginning of a new chain
4780 + // if i == NF_BR_NUMHOOKS it must be a user defined chain
4781 + if (i != NF_BR_NUMHOOKS || !(e->bitmask & EBT_ENTRY_OR_ENTRIES)) {
4782 + if ((e->bitmask & EBT_ENTRY_OR_ENTRIES) != 0) {
4783 + // we make userspace set this right,
4784 + // so there is no misunderstanding
4785 + BUGPRINT("EBT_ENTRY_OR_ENTRIES shouldn't be set "
4786 + "in distinguisher\n");
4787 + return -EINVAL;
4788 + }
4789 + // this checks if the previous chain has as many entries
4790 + // as it said it has
4791 + if (*n != *cnt) {
4792 + BUGPRINT("nentries does not equal the nr of entries "
4793 + "in the chain\n");
4794 + return -EINVAL;
4795 + }
4796 + // before we look at the struct, be sure it is not too big
4797 + if ((char *)hook_entries[i] + sizeof(struct ebt_entries)
4798 + > limit) {
4799 + BUGPRINT("entries_size too small\n");
4800 + return -EINVAL;
4801 + }
4802 + if (((struct ebt_entries *)e)->policy != EBT_DROP &&
4803 + ((struct ebt_entries *)e)->policy != EBT_ACCEPT) {
4804 + // only RETURN from udc
4805 + if (i != NF_BR_NUMHOOKS ||
4806 + ((struct ebt_entries *)e)->policy != EBT_RETURN) {
4807 + BUGPRINT("bad policy\n");
4808 + return -EINVAL;
4809 + }
4810 + }
4811 + if (i == NF_BR_NUMHOOKS) // it's a user defined chain
4812 + (*udc_cnt)++;
4813 + else
4814 + newinfo->hook_entry[i] = (struct ebt_entries *)e;
4815 + if (((struct ebt_entries *)e)->counter_offset != *totalcnt) {
4816 + BUGPRINT("counter_offset != totalcnt");
4817 + return -EINVAL;
4818 + }
4819 + *n = ((struct ebt_entries *)e)->nentries;
4820 + *cnt = 0;
4821 + return 0;
4822 + }
4823 + // a plain old entry, heh
4824 + if (sizeof(struct ebt_entry) > e->watchers_offset ||
4825 + e->watchers_offset > e->target_offset ||
4826 + e->target_offset >= e->next_offset) {
4827 + BUGPRINT("entry offsets not in right order\n");
4828 + return -EINVAL;
4829 + }
4830 + // this is not checked anywhere else
4831 + if (e->next_offset - e->target_offset < sizeof(struct ebt_entry_target)) {
4832 + BUGPRINT("target size too small\n");
4833 + return -EINVAL;
4834 + }
4835 +
4836 + (*cnt)++;
4837 + (*totalcnt)++;
4838 + return 0;
4839 +}
4840 +
4841 +struct ebt_cl_stack
4842 +{
4843 + struct ebt_chainstack cs;
4844 + int from;
4845 + unsigned int hookmask;
4846 +};
4847 +
4848 +// we need these positions to check that the jumps to a different part of the
4849 +// entries is a jump to the beginning of a new chain.
4850 +static inline int
4851 +ebt_get_udc_positions(struct ebt_entry *e, struct ebt_table_info *newinfo,
4852 + struct ebt_entries **hook_entries, unsigned int *n, unsigned int valid_hooks,
4853 + struct ebt_cl_stack *udc)
4854 +{
4855 + int i;
4856 +
4857 + // we're only interested in chain starts
4858 + if (e->bitmask & EBT_ENTRY_OR_ENTRIES)
4859 + return 0;
4860 + for (i = 0; i < NF_BR_NUMHOOKS; i++) {
4861 + if ((valid_hooks & (1 << i)) == 0)
4862 + continue;
4863 + if (newinfo->hook_entry[i] == (struct ebt_entries *)e)
4864 + break;
4865 + }
4866 + // only care about udc
4867 + if (i != NF_BR_NUMHOOKS)
4868 + return 0;
4869 +
4870 + udc[*n].cs.chaininfo = (struct ebt_entries *)e;
4871 + // these initialisations are depended on later in check_chainloops()
4872 + udc[*n].cs.n = 0;
4873 + udc[*n].hookmask = 0;
4874 +
4875 + (*n)++;
4876 + return 0;
4877 +}
4878 +
4879 +static inline int
4880 +ebt_cleanup_match(struct ebt_entry_match *m, unsigned int *i)
4881 +{
4882 + if (i && (*i)-- == 0)
4883 + return 1;
4884 + if (m->u.match->destroy)
4885 + m->u.match->destroy(m->data, m->match_size);
4886 + if (m->u.match->me)
4887 + __MOD_DEC_USE_COUNT(m->u.match->me);
4888 +
4889 + return 0;
4890 +}
4891 +
4892 +static inline int
4893 +ebt_cleanup_watcher(struct ebt_entry_watcher *w, unsigned int *i)
4894 +{
4895 + if (i && (*i)-- == 0)
4896 + return 1;
4897 + if (w->u.watcher->destroy)
4898 + w->u.watcher->destroy(w->data, w->watcher_size);
4899 + if (w->u.watcher->me)
4900 + __MOD_DEC_USE_COUNT(w->u.watcher->me);
4901 +
4902 + return 0;
4903 +}
4904 +
4905 +static inline int
4906 +ebt_cleanup_entry(struct ebt_entry *e, unsigned int *cnt)
4907 +{
4908 + struct ebt_entry_target *t;
4909 +
4910 + if ((e->bitmask & EBT_ENTRY_OR_ENTRIES) == 0)
4911 + return 0;
4912 + // we're done
4913 + if (cnt && (*cnt)-- == 0)
4914 + return 1;
4915 + EBT_WATCHER_ITERATE(e, ebt_cleanup_watcher, NULL);
4916 + EBT_MATCH_ITERATE(e, ebt_cleanup_match, NULL);
4917 + t = (struct ebt_entry_target *)(((char *)e) + e->target_offset);
4918 + if (t->u.target->destroy)
4919 + t->u.target->destroy(t->data, t->target_size);
4920 + if (t->u.target->me)
4921 + __MOD_DEC_USE_COUNT(t->u.target->me);
4922 +
4923 + return 0;
4924 +}
4925 +
4926 +static inline int
4927 +ebt_check_entry(struct ebt_entry *e, struct ebt_table_info *newinfo,
4928 + const char *name, unsigned int *cnt, unsigned int valid_hooks,
4929 + struct ebt_cl_stack *cl_s, unsigned int udc_cnt)
4930 +{
4931 + struct ebt_entry_target *t;
4932 + struct ebt_target *target;
4933 + unsigned int i, j, hook = 0, hookmask = 0;
4934 + int ret;
4935 +
4936 + // Don't mess with the struct ebt_entries
4937 + if ((e->bitmask & EBT_ENTRY_OR_ENTRIES) == 0)
4938 + return 0;
4939 +
4940 + if (e->bitmask & ~EBT_F_MASK) {
4941 + BUGPRINT("Unknown flag for bitmask\n");
4942 + return -EINVAL;
4943 + }
4944 + if (e->invflags & ~EBT_INV_MASK) {
4945 + BUGPRINT("Unknown flag for inv bitmask\n");
4946 + return -EINVAL;
4947 + }
4948 + if ( (e->bitmask & EBT_NOPROTO) && (e->bitmask & EBT_802_3) ) {
4949 + BUGPRINT("NOPROTO & 802_3 not allowed\n");
4950 + return -EINVAL;
4951 + }
4952 + // what hook do we belong to?
4953 + for (i = 0; i < NF_BR_NUMHOOKS; i++) {
4954 + if ((valid_hooks & (1 << i)) == 0)
4955 + continue;
4956 + if ((char *)newinfo->hook_entry[i] < (char *)e)
4957 + hook = i;
4958 + else
4959 + break;
4960 + }
4961 + // (1 << NF_BR_NUMHOOKS) tells the check functions the rule is on
4962 + // a base chain
4963 + if (i < NF_BR_NUMHOOKS)
4964 + hookmask = (1 << hook) | (1 << NF_BR_NUMHOOKS);
4965 + else {
4966 + for (i = 0; i < udc_cnt; i++)
4967 + if ((char *)(cl_s[i].cs.chaininfo) > (char *)e)
4968 + break;
4969 + if (i == 0)
4970 + hookmask = (1 << hook) | (1 << NF_BR_NUMHOOKS);
4971 + else
4972 + hookmask = cl_s[i - 1].hookmask;
4973 + }
4974 + i = 0;
4975 + ret = EBT_MATCH_ITERATE(e, ebt_check_match, e, name, hookmask, &i);
4976 + if (ret != 0)
4977 + goto cleanup_matches;
4978 + j = 0;
4979 + ret = EBT_WATCHER_ITERATE(e, ebt_check_watcher, e, name, hookmask, &j);
4980 + if (ret != 0)
4981 + goto cleanup_watchers;
4982 + t = (struct ebt_entry_target *)(((char *)e) + e->target_offset);
4983 + target = find_target_lock(t->u.name, &ret, &ebt_mutex);
4984 + if (!target)
4985 + goto cleanup_watchers;
4986 + if (target->me)
4987 + __MOD_INC_USE_COUNT(target->me);
4988 + up(&ebt_mutex);
4989 +
4990 + t->u.target = target;
4991 + if (t->u.target == &ebt_standard_target) {
4992 + if (e->target_offset + sizeof(struct ebt_standard_target) >
4993 + e->next_offset) {
4994 + BUGPRINT("Standard target size too big\n");
4995 + ret = -EFAULT;
4996 + goto cleanup_watchers;
4997 + }
4998 + if (((struct ebt_standard_target *)t)->verdict <
4999 + -NUM_STANDARD_TARGETS) {
5000 + BUGPRINT("Invalid standard target\n");
5001 + ret = -EFAULT;
5002 + goto cleanup_watchers;
5003 + }
5004 + } else if ((e->target_offset + t->target_size +
5005 + sizeof(struct ebt_entry_target) > e->next_offset) ||
5006 + (t->u.target->check &&
5007 + t->u.target->check(name, hookmask, e, t->data, t->target_size) != 0)){
5008 + if (t->u.target->me)
5009 + __MOD_DEC_USE_COUNT(t->u.target->me);
5010 + ret = -EFAULT;
5011 + goto cleanup_watchers;
5012 + }
5013 + (*cnt)++;
5014 + return 0;
5015 +cleanup_watchers:
5016 + EBT_WATCHER_ITERATE(e, ebt_cleanup_watcher, &j);
5017 +cleanup_matches:
5018 + EBT_MATCH_ITERATE(e, ebt_cleanup_match, &i);
5019 + return ret;
5020 +}
5021 +
5022 +// checks for loops and sets the hook mask for udc
5023 +// the hook mask for udc tells us from which base chains the udc can be
5024 +// accessed. This mask is a parameter to the check() functions of the extensions
5025 +static int check_chainloops(struct ebt_entries *chain,
5026 + struct ebt_cl_stack *cl_s, unsigned int udc_cnt,
5027 + unsigned int hooknr, char *base)
5028 +{
5029 + int i, chain_nr = -1, pos = 0, nentries = chain->nentries, verdict;
5030 + struct ebt_entry *e = (struct ebt_entry *)chain->data;
5031 + struct ebt_entry_target *t;
5032 +
5033 + while (pos < nentries || chain_nr != -1) {
5034 + // end of udc, go back one 'recursion' step
5035 + if (pos == nentries) {
5036 + // put back values of the time when this chain was called
5037 + e = cl_s[chain_nr].cs.e;
5038 + if (cl_s[chain_nr].from != -1)
5039 + nentries =
5040 + cl_s[cl_s[chain_nr].from].cs.chaininfo->nentries;
5041 + else
5042 + nentries = chain->nentries;
5043 + pos = cl_s[chain_nr].cs.n;
5044 + // make sure we won't see a loop that isn't one
5045 + cl_s[chain_nr].cs.n = 0;
5046 + chain_nr = cl_s[chain_nr].from;
5047 + if (pos == nentries)
5048 + continue;
5049 + }
5050 + t = (struct ebt_entry_target *)
5051 + (((char *)e) + e->target_offset);
5052 + if (strcmp(t->u.name, EBT_STANDARD_TARGET))
5053 + goto letscontinue;
5054 + if (e->target_offset + sizeof(struct ebt_standard_target) >
5055 + e->next_offset) {
5056 + BUGPRINT("Standard target size too big\n");
5057 + return -1;
5058 + }
5059 + verdict = ((struct ebt_standard_target *)t)->verdict;
5060 + if (verdict >= 0) { // jump to another chain
5061 + struct ebt_entries *hlp2 =
5062 + (struct ebt_entries *)(base + verdict);
5063 + for (i = 0; i < udc_cnt; i++)
5064 + if (hlp2 == cl_s[i].cs.chaininfo)
5065 + break;
5066 + // bad destination or loop
5067 + if (i == udc_cnt) {
5068 + BUGPRINT("bad destination\n");
5069 + return -1;
5070 + }
5071 + if (cl_s[i].cs.n) {
5072 + BUGPRINT("loop\n");
5073 + return -1;
5074 + }
5075 + // this can't be 0, so the above test is correct
5076 + cl_s[i].cs.n = pos + 1;
5077 + pos = 0;
5078 + cl_s[i].cs.e = ((void *)e + e->next_offset);
5079 + e = (struct ebt_entry *)(hlp2->data);
5080 + nentries = hlp2->nentries;
5081 + cl_s[i].from = chain_nr;
5082 + chain_nr = i;
5083 + // this udc is accessible from the base chain for hooknr
5084 + cl_s[i].hookmask |= (1 << hooknr);
5085 + continue;
5086 + }
5087 +letscontinue:
5088 + e = (void *)e + e->next_offset;
5089 + pos++;
5090 + }
5091 + return 0;
5092 +}
5093 +
5094 +// do the parsing of the table/chains/entries/matches/watchers/targets, heh
5095 +static int translate_table(struct ebt_replace *repl,
5096 + struct ebt_table_info *newinfo)
5097 +{
5098 + unsigned int i, j, k, udc_cnt;
5099 + int ret;
5100 + struct ebt_cl_stack *cl_s = NULL; // used in the checking for chain loops
5101 +
5102 + i = 0;
5103 + while (i < NF_BR_NUMHOOKS && !(repl->valid_hooks & (1 << i)))
5104 + i++;
5105 + if (i == NF_BR_NUMHOOKS) {
5106 + BUGPRINT("No valid hooks specified\n");
5107 + return -EINVAL;
5108 + }
5109 + if (repl->hook_entry[i] != (struct ebt_entries *)repl->entries) {
5110 + BUGPRINT("Chains don't start at beginning\n");
5111 + return -EINVAL;
5112 + }
5113 + // make sure chains are ordered after each other in same order
5114 + // as their corresponding hooks
5115 + for (j = i + 1; j < NF_BR_NUMHOOKS; j++) {
5116 + if (!(repl->valid_hooks & (1 << j)))
5117 + continue;
5118 + if ( repl->hook_entry[j] <= repl->hook_entry[i] ) {
5119 + BUGPRINT("Hook order must be followed\n");
5120 + return -EINVAL;
5121 + }
5122 + i = j;
5123 + }
5124 +
5125 + for (i = 0; i < NF_BR_NUMHOOKS; i++)
5126 + newinfo->hook_entry[i] = NULL;
5127 +
5128 + newinfo->entries_size = repl->entries_size;
5129 + newinfo->nentries = repl->nentries;
5130 +
5131 + // do some early checkings and initialize some things
5132 + i = 0; // holds the expected nr. of entries for the chain
5133 + j = 0; // holds the up to now counted entries for the chain
5134 + k = 0; // holds the total nr. of entries, should equal
5135 + // newinfo->nentries afterwards
5136 + udc_cnt = 0; // will hold the nr. of user defined chains (udc)
5137 + ret = EBT_ENTRY_ITERATE(newinfo->entries, newinfo->entries_size,
5138 + ebt_check_entry_size_and_hooks, newinfo, repl->entries,
5139 + repl->entries + repl->entries_size, repl->hook_entry, &i, &j, &k,
5140 + &udc_cnt, repl->valid_hooks);
5141 +
5142 + if (ret != 0)
5143 + return ret;
5144 +
5145 + if (i != j) {
5146 + BUGPRINT("nentries does not equal the nr of entries in the "
5147 + "(last) chain\n");
5148 + return -EINVAL;
5149 + }
5150 + if (k != newinfo->nentries) {
5151 + BUGPRINT("Total nentries is wrong\n");
5152 + return -EINVAL;
5153 + }
5154 +
5155 + // check if all valid hooks have a chain
5156 + for (i = 0; i < NF_BR_NUMHOOKS; i++) {
5157 + if (newinfo->hook_entry[i] == NULL &&
5158 + (repl->valid_hooks & (1 << i))) {
5159 + BUGPRINT("Valid hook without chain\n");
5160 + return -EINVAL;
5161 + }
5162 + }
5163 +
5164 + // Get the location of the udc, put them in an array
5165 + // While we're at it, allocate the chainstack
5166 + if (udc_cnt) {
5167 + // this will get free'd in do_replace()/ebt_register_table()
5168 + // if an error occurs
5169 + newinfo->chainstack = (struct ebt_chainstack **)
5170 + vmalloc(smp_num_cpus * sizeof(struct ebt_chainstack));
5171 + if (!newinfo->chainstack)
5172 + return -ENOMEM;
5173 + for (i = 0; i < smp_num_cpus; i++) {
5174 + newinfo->chainstack[i] =
5175 + vmalloc(udc_cnt * sizeof(struct ebt_chainstack));
5176 + if (!newinfo->chainstack[i]) {
5177 + while (i)
5178 + vfree(newinfo->chainstack[--i]);
5179 + vfree(newinfo->chainstack);
5180 + newinfo->chainstack = NULL;
5181 + return -ENOMEM;
5182 + }
5183 + }
5184 +
5185 + cl_s = (struct ebt_cl_stack *)
5186 + vmalloc(udc_cnt * sizeof(struct ebt_cl_stack));
5187 + if (!cl_s)
5188 + return -ENOMEM;
5189 + i = 0; // the i'th udc
5190 + EBT_ENTRY_ITERATE(newinfo->entries, newinfo->entries_size,
5191 + ebt_get_udc_positions, newinfo, repl->hook_entry, &i,
5192 + repl->valid_hooks, cl_s);
5193 + // sanity check
5194 + if (i != udc_cnt) {
5195 + BUGPRINT("i != udc_cnt\n");
5196 + vfree(cl_s);
5197 + return -EFAULT;
5198 + }
5199 + }
5200 +
5201 + // Check for loops
5202 + for (i = 0; i < NF_BR_NUMHOOKS; i++)
5203 + if (repl->valid_hooks & (1 << i))
5204 + if (check_chainloops(newinfo->hook_entry[i],
5205 + cl_s, udc_cnt, i, newinfo->entries)) {
5206 + if (cl_s)
5207 + vfree(cl_s);
5208 + return -EINVAL;
5209 + }
5210 +
5211 + // we now know the following (along with E=mc²):
5212 + // - the nr of entries in each chain is right
5213 + // - the size of the allocated space is right
5214 + // - all valid hooks have a corresponding chain
5215 + // - there are no loops
5216 + // - wrong data can still be on the level of a single entry
5217 + // - could be there are jumps to places that are not the
5218 + // beginning of a chain. This can only occur in chains that
5219 + // are not accessible from any base chains, so we don't care.
5220 +
5221 + // used to know what we need to clean up if something goes wrong
5222 + i = 0;
5223 + ret = EBT_ENTRY_ITERATE(newinfo->entries, newinfo->entries_size,
5224 + ebt_check_entry, newinfo, repl->name, &i, repl->valid_hooks,
5225 + cl_s, udc_cnt);
5226 + if (ret != 0) {
5227 + EBT_ENTRY_ITERATE(newinfo->entries, newinfo->entries_size,
5228 + ebt_cleanup_entry, &i);
5229 + }
5230 + if (cl_s)
5231 + vfree(cl_s);
5232 + return ret;
5233 +}
5234 +
5235 +// called under write_lock
5236 +static void get_counters(struct ebt_counter *oldcounters,
5237 + struct ebt_counter *counters, unsigned int nentries)
5238 +{
5239 + int i, cpu;
5240 + struct ebt_counter *counter_base;
5241 +
5242 + // counters of cpu 0
5243 + memcpy(counters, oldcounters,
5244 + sizeof(struct ebt_counter) * nentries);
5245 + // add other counters to those of cpu 0
5246 + for (cpu = 1; cpu < smp_num_cpus; cpu++) {
5247 + counter_base = COUNTER_BASE(oldcounters, nentries, cpu);
5248 + for (i = 0; i < nentries; i++) {
5249 + counters[i].pcnt += counter_base[i].pcnt;
5250 + counters[i].bcnt += counter_base[i].bcnt;
5251 + }
5252 + }
5253 +}
5254 +
5255 +// replace the table
5256 +static int do_replace(void *user, unsigned int len)
5257 +{
5258 + int ret, i, countersize;
5259 + struct ebt_table_info *newinfo;
5260 + struct ebt_replace tmp;
5261 + struct ebt_table *t;
5262 + struct ebt_counter *counterstmp = NULL;
5263 + // used to be able to unlock earlier
5264 + struct ebt_table_info *table;
5265 +
5266 + if (copy_from_user(&tmp, user, sizeof(tmp)) != 0)
5267 + return -EFAULT;
5268 +
5269 + if (len != sizeof(tmp) + tmp.entries_size) {
5270 + BUGPRINT("Wrong len argument\n");
5271 + return -EINVAL;
5272 + }
5273 +
5274 + if (tmp.entries_size == 0) {
5275 + BUGPRINT("Entries_size never zero\n");
5276 + return -EINVAL;
5277 + }
5278 + countersize = COUNTER_OFFSET(tmp.nentries) * smp_num_cpus;
5279 + newinfo = (struct ebt_table_info *)
5280 + vmalloc(sizeof(struct ebt_table_info) + countersize);
5281 + if (!newinfo)
5282 + return -ENOMEM;
5283 +
5284 + if (countersize)
5285 + memset(newinfo->counters, 0, countersize);
5286 +
5287 + newinfo->entries = (char *)vmalloc(tmp.entries_size);
5288 + if (!newinfo->entries) {
5289 + ret = -ENOMEM;
5290 + goto free_newinfo;
5291 + }
5292 + if (copy_from_user(
5293 + newinfo->entries, tmp.entries, tmp.entries_size) != 0) {
5294 + BUGPRINT("Couldn't copy entries from userspace\n");
5295 + ret = -EFAULT;
5296 + goto free_entries;
5297 + }
5298 +
5299 + // the user wants counters back
5300 + // the check on the size is done later, when we have the lock
5301 + if (tmp.num_counters) {
5302 + counterstmp = (struct ebt_counter *)
5303 + vmalloc(tmp.num_counters * sizeof(struct ebt_counter));
5304 + if (!counterstmp) {
5305 + ret = -ENOMEM;
5306 + goto free_entries;
5307 + }
5308 + }
5309 + else
5310 + counterstmp = NULL;
5311 +
5312 + // this can get initialized by translate_table()
5313 + newinfo->chainstack = NULL;
5314 + ret = translate_table(&tmp, newinfo);
5315 +
5316 + if (ret != 0)
5317 + goto free_counterstmp;
5318 +
5319 + t = find_table_lock(tmp.name, &ret, &ebt_mutex);
5320 + if (!t)
5321 + goto free_iterate;
5322 +
5323 + // the table doesn't like it
5324 + if (t->check && (ret = t->check(newinfo, tmp.valid_hooks)))
5325 + goto free_unlock;
5326 +
5327 + if (tmp.num_counters && tmp.num_counters != t->private->nentries) {
5328 + BUGPRINT("Wrong nr. of counters requested\n");
5329 + ret = -EINVAL;
5330 + goto free_unlock;
5331 + }
5332 +
5333 + // we have the mutex lock, so no danger in reading this pointer
5334 + table = t->private;
5335 + // we need an atomic snapshot of the counters
5336 + write_lock_bh(&t->lock);
5337 + if (tmp.num_counters)
5338 + get_counters(t->private->counters, counterstmp,
5339 + t->private->nentries);
5340 +
5341 + t->private = newinfo;
5342 + write_unlock_bh(&t->lock);
5343 + up(&ebt_mutex);
5344 + // So, a user can change the chains while having messed up her counter
5345 + // allocation. Only reason why this is done is because this way the lock
5346 + // is held only once, while this doesn't bring the kernel into a
5347 + // dangerous state.
5348 + if (tmp.num_counters &&
5349 + copy_to_user(tmp.counters, counterstmp,
5350 + tmp.num_counters * sizeof(struct ebt_counter))) {
5351 + BUGPRINT("Couldn't copy counters to userspace\n");
5352 + ret = -EFAULT;
5353 + }
5354 + else
5355 + ret = 0;
5356 +
5357 + // decrease module count and free resources
5358 + EBT_ENTRY_ITERATE(table->entries, table->entries_size,
5359 + ebt_cleanup_entry, NULL);
5360 +
5361 + vfree(table->entries);
5362 + if (table->chainstack) {
5363 + for (i = 0; i < smp_num_cpus; i++)
5364 + vfree(table->chainstack[i]);
5365 + vfree(table->chainstack);
5366 + }
5367 + vfree(table);
5368 +
5369 + if (counterstmp)
5370 + vfree(counterstmp);
5371 + return ret;
5372 +
5373 +free_unlock:
5374 + up(&ebt_mutex);
5375 +free_iterate:
5376 + EBT_ENTRY_ITERATE(newinfo->entries, newinfo->entries_size,
5377 + ebt_cleanup_entry, NULL);
5378 +free_counterstmp:
5379 + if (counterstmp)
5380 + vfree(counterstmp);
5381 + // can be initialized in translate_table()
5382 + if (newinfo->chainstack) {
5383 + for (i = 0; i < smp_num_cpus; i++)
5384 + vfree(newinfo->chainstack[i]);
5385 + vfree(newinfo->chainstack);
5386 + }
5387 +free_entries:
5388 + if (newinfo->entries)
5389 + vfree(newinfo->entries);
5390 +free_newinfo:
5391 + if (newinfo)
5392 + vfree(newinfo);
5393 + return ret;
5394 +}
5395 +
5396 +int ebt_register_target(struct ebt_target *target)
5397 +{
5398 + int ret;
5399 +
5400 + ret = down_interruptible(&ebt_mutex);
5401 + if (ret != 0)
5402 + return ret;
5403 + if (!list_named_insert(&ebt_targets, target)) {
5404 + up(&ebt_mutex);
5405 + return -EEXIST;
5406 + }
5407 + up(&ebt_mutex);
5408 + MOD_INC_USE_COUNT;
5409 +
5410 + return 0;
5411 +}
5412 +
5413 +void ebt_unregister_target(struct ebt_target *target)
5414 +{
5415 + down(&ebt_mutex);
5416 + LIST_DELETE(&ebt_targets, target);
5417 + up(&ebt_mutex);
5418 + MOD_DEC_USE_COUNT;
5419 +}
5420 +
5421 +int ebt_register_match(struct ebt_match *match)
5422 +{
5423 + int ret;
5424 +
5425 + ret = down_interruptible(&ebt_mutex);
5426 + if (ret != 0)
5427 + return ret;
5428 + if (!list_named_insert(&ebt_matches, match)) {
5429 + up(&ebt_mutex);
5430 + return -EEXIST;
5431 + }
5432 + up(&ebt_mutex);
5433 + MOD_INC_USE_COUNT;
5434 +
5435 + return 0;
5436 +}
5437 +
5438 +void ebt_unregister_match(struct ebt_match *match)
5439 +{
5440 + down(&ebt_mutex);
5441 + LIST_DELETE(&ebt_matches, match);
5442 + up(&ebt_mutex);
5443 + MOD_DEC_USE_COUNT;
5444 +}
5445 +
5446 +int ebt_register_watcher(struct ebt_watcher *watcher)
5447 +{
5448 + int ret;
5449 +
5450 + ret = down_interruptible(&ebt_mutex);
5451 + if (ret != 0)
5452 + return ret;
5453 + if (!list_named_insert(&ebt_watchers, watcher)) {
5454 + up(&ebt_mutex);
5455 + return -EEXIST;
5456 + }
5457 + up(&ebt_mutex);
5458 + MOD_INC_USE_COUNT;
5459 +
5460 + return 0;
5461 +}
5462 +
5463 +void ebt_unregister_watcher(struct ebt_watcher *watcher)
5464 +{
5465 + down(&ebt_mutex);
5466 + LIST_DELETE(&ebt_watchers, watcher);
5467 + up(&ebt_mutex);
5468 + MOD_DEC_USE_COUNT;
5469 +}
5470 +
5471 +int ebt_register_table(struct ebt_table *table)
5472 +{
5473 + struct ebt_table_info *newinfo;
5474 + int ret, i, countersize;
5475 +
5476 + if (!table || !table->table ||!table->table->entries ||
5477 + table->table->entries_size == 0 ||
5478 + table->table->counters || table->private) {
5479 + BUGPRINT("Bad table data for ebt_register_table!!!\n");
5480 + return -EINVAL;
5481 + }
5482 +
5483 + countersize = COUNTER_OFFSET(table->table->nentries) * smp_num_cpus;
5484 + newinfo = (struct ebt_table_info *)
5485 + vmalloc(sizeof(struct ebt_table_info) + countersize);
5486 + ret = -ENOMEM;
5487 + if (!newinfo)
5488 + return -ENOMEM;
5489 +
5490 + newinfo->entries = (char *)vmalloc(table->table->entries_size);
5491 + if (!(newinfo->entries))
5492 + goto free_newinfo;
5493 +
5494 + memcpy(newinfo->entries, table->table->entries,
5495 + table->table->entries_size);
5496 +
5497 + if (countersize)
5498 + memset(newinfo->counters, 0, countersize);
5499 +
5500 + // fill in newinfo and parse the entries
5501 + newinfo->chainstack = NULL;
5502 + ret = translate_table(table->table, newinfo);
5503 + if (ret != 0) {
5504 + BUGPRINT("Translate_table failed\n");
5505 + goto free_chainstack;
5506 + }
5507 +
5508 + if (table->check && table->check(newinfo, table->valid_hooks)) {
5509 + BUGPRINT("The table doesn't like its own initial data, lol\n");
5510 + return -EINVAL;
5511 + }
5512 +
5513 + table->private = newinfo;
5514 + table->lock = RW_LOCK_UNLOCKED;
5515 + ret = down_interruptible(&ebt_mutex);
5516 + if (ret != 0)
5517 + goto free_chainstack;
5518 +
5519 + if (list_named_find(&ebt_tables, table->name)) {
5520 + ret = -EEXIST;
5521 + BUGPRINT("Table name already exists\n");
5522 + goto free_unlock;
5523 + }
5524 +
5525 + list_prepend(&ebt_tables, table);
5526 + up(&ebt_mutex);
5527 + MOD_INC_USE_COUNT;
5528 + return 0;
5529 +free_unlock:
5530 + up(&ebt_mutex);
5531 +free_chainstack:
5532 + if (newinfo->chainstack) {
5533 + for (i = 0; i < smp_num_cpus; i++)
5534 + vfree(newinfo->chainstack[i]);
5535 + vfree(newinfo->chainstack);
5536 + }
5537 + vfree(newinfo->entries);
5538 +free_newinfo:
5539 + vfree(newinfo);
5540 + return ret;
5541 +}
5542 +
5543 +void ebt_unregister_table(struct ebt_table *table)
5544 +{
5545 + int i;
5546 +
5547 + if (!table) {
5548 + BUGPRINT("Request to unregister NULL table!!!\n");
5549 + return;
5550 + }
5551 + down(&ebt_mutex);
5552 + LIST_DELETE(&ebt_tables, table);
5553 + up(&ebt_mutex);
5554 + EBT_ENTRY_ITERATE(table->private->entries,
5555 + table->private->entries_size, ebt_cleanup_entry, NULL);
5556 + if (table->private->entries)
5557 + vfree(table->private->entries);
5558 + if (table->private->chainstack) {
5559 + for (i = 0; i < smp_num_cpus; i++)
5560 + vfree(table->private->chainstack[i]);
5561 + vfree(table->private->chainstack);
5562 + }
5563 + vfree(table->private);
5564 + MOD_DEC_USE_COUNT;
5565 +}
5566 +
5567 +// userspace just supplied us with counters
5568 +static int update_counters(void *user, unsigned int len)
5569 +{
5570 + int i, ret;
5571 + struct ebt_counter *tmp;
5572 + struct ebt_replace hlp;
5573 + struct ebt_table *t;
5574 +
5575 + if (copy_from_user(&hlp, user, sizeof(hlp)))
5576 + return -EFAULT;
5577 +
5578 + if (len != sizeof(hlp) + hlp.num_counters * sizeof(struct ebt_counter))
5579 + return -EINVAL;
5580 + if (hlp.num_counters == 0)
5581 + return -EINVAL;
5582 +
5583 + if ( !(tmp = (struct ebt_counter *)
5584 + vmalloc(hlp.num_counters * sizeof(struct ebt_counter))) ){
5585 + MEMPRINT("Update_counters && nomemory\n");
5586 + return -ENOMEM;
5587 + }
5588 +
5589 + t = find_table_lock(hlp.name, &ret, &ebt_mutex);
5590 + if (!t)
5591 + goto free_tmp;
5592 +
5593 + if (hlp.num_counters != t->private->nentries) {
5594 + BUGPRINT("Wrong nr of counters\n");
5595 + ret = -EINVAL;
5596 + goto unlock_mutex;
5597 + }
5598 +
5599 + if ( copy_from_user(tmp, hlp.counters,
5600 + hlp.num_counters * sizeof(struct ebt_counter)) ) {
5601 + BUGPRINT("Updata_counters && !cfu\n");
5602 + ret = -EFAULT;
5603 + goto unlock_mutex;
5604 + }
5605 +
5606 + // we want an atomic add of the counters
5607 + write_lock_bh(&t->lock);
5608 +
5609 + // we add to the counters of the first cpu
5610 + for (i = 0; i < hlp.num_counters; i++) {
5611 + t->private->counters[i].pcnt += tmp[i].pcnt;
5612 + t->private->counters[i].bcnt += tmp[i].bcnt;
5613 + }
5614 +
5615 + write_unlock_bh(&t->lock);
5616 + ret = 0;
5617 +unlock_mutex:
5618 + up(&ebt_mutex);
5619 +free_tmp:
5620 + vfree(tmp);
5621 + return ret;
5622 +}
5623 +
5624 +static inline int ebt_make_matchname(struct ebt_entry_match *m,
5625 + char *base, char *ubase)
5626 +{
5627 + char *hlp = ubase - base + (char *)m;
5628 + if (copy_to_user(hlp, m->u.match->name, EBT_FUNCTION_MAXNAMELEN))
5629 + return -EFAULT;
5630 + return 0;
5631 +}
5632 +
5633 +static inline int ebt_make_watchername(struct ebt_entry_watcher *w,
5634 + char *base, char *ubase)
5635 +{
5636 + char *hlp = ubase - base + (char *)w;
5637 + if (copy_to_user(hlp , w->u.watcher->name, EBT_FUNCTION_MAXNAMELEN))
5638 + return -EFAULT;
5639 + return 0;
5640 +}
5641 +
5642 +static inline int ebt_make_names(struct ebt_entry *e, char *base, char *ubase)
5643 +{
5644 + int ret;
5645 + char *hlp;
5646 + struct ebt_entry_target *t;
5647 +
5648 + if ((e->bitmask & EBT_ENTRY_OR_ENTRIES) == 0)
5649 + return 0;
5650 +
5651 + hlp = ubase - base + (char *)e + e->target_offset;
5652 + t = (struct ebt_entry_target *)(((char *)e) + e->target_offset);
5653 +
5654 + ret = EBT_MATCH_ITERATE(e, ebt_make_matchname, base, ubase);
5655 + if (ret != 0)
5656 + return ret;
5657 + ret = EBT_WATCHER_ITERATE(e, ebt_make_watchername, base, ubase);
5658 + if (ret != 0)
5659 + return ret;
5660 + if (copy_to_user(hlp, t->u.target->name, EBT_FUNCTION_MAXNAMELEN))
5661 + return -EFAULT;
5662 + return 0;
5663 +}
5664 +
5665 +// called with ebt_mutex down
5666 +static int copy_everything_to_user(struct ebt_table *t, void *user,
5667 + int *len, int cmd)
5668 +{
5669 + struct ebt_replace tmp;
5670 + struct ebt_counter *counterstmp, *oldcounters;
5671 + unsigned int entries_size, nentries;
5672 + char *entries;
5673 +
5674 + if (cmd == EBT_SO_GET_ENTRIES) {
5675 + entries_size = t->private->entries_size;
5676 + nentries = t->private->nentries;
5677 + entries = t->private->entries;
5678 + oldcounters = t->private->counters;
5679 + } else {
5680 + entries_size = t->table->entries_size;
5681 + nentries = t->table->nentries;
5682 + entries = t->table->entries;
5683 + oldcounters = t->table->counters;
5684 + }
5685 +
5686 + if (copy_from_user(&tmp, user, sizeof(tmp))) {
5687 + BUGPRINT("Cfu didn't work\n");
5688 + return -EFAULT;
5689 + }
5690 +
5691 + if (*len != sizeof(struct ebt_replace) + entries_size +
5692 + (tmp.num_counters? nentries * sizeof(struct ebt_counter): 0)) {
5693 + BUGPRINT("Wrong size\n");
5694 + return -EINVAL;
5695 + }
5696 +
5697 + if (tmp.nentries != nentries) {
5698 + BUGPRINT("Nentries wrong\n");
5699 + return -EINVAL;
5700 + }
5701 +
5702 + if (tmp.entries_size != entries_size) {
5703 + BUGPRINT("Wrong size\n");
5704 + return -EINVAL;
5705 + }
5706 +
5707 + // userspace might not need the counters
5708 + if (tmp.num_counters) {
5709 + if (tmp.num_counters != nentries) {
5710 + BUGPRINT("Num_counters wrong\n");
5711 + return -EINVAL;
5712 + }
5713 + counterstmp = (struct ebt_counter *)
5714 + vmalloc(nentries * sizeof(struct ebt_counter));
5715 + if (!counterstmp) {
5716 + MEMPRINT("Couldn't copy counters, out of memory\n");
5717 + return -ENOMEM;
5718 + }
5719 + write_lock_bh(&t->lock);
5720 + get_counters(oldcounters, counterstmp, nentries);
5721 + write_unlock_bh(&t->lock);
5722 +
5723 + if (copy_to_user(tmp.counters, counterstmp,
5724 + nentries * sizeof(struct ebt_counter))) {
5725 + BUGPRINT("Couldn't copy counters to userspace\n");
5726 + vfree(counterstmp);
5727 + return -EFAULT;
5728 + }
5729 + vfree(counterstmp);
5730 + }
5731 +
5732 + if (copy_to_user(tmp.entries, entries, entries_size)) {
5733 + BUGPRINT("Couldn't copy entries to userspace\n");
5734 + return -EFAULT;
5735 + }
5736 + // set the match/watcher/target names right
5737 + return EBT_ENTRY_ITERATE(entries, entries_size,
5738 + ebt_make_names, entries, tmp.entries);
5739 +}
5740 +
5741 +static int do_ebt_set_ctl(struct sock *sk,
5742 + int cmd, void *user, unsigned int len)
5743 +{
5744 + int ret;
5745 +
5746 + switch(cmd) {
5747 + case EBT_SO_SET_ENTRIES:
5748 + ret = do_replace(user, len);
5749 + break;
5750 + case EBT_SO_SET_COUNTERS:
5751 + ret = update_counters(user, len);
5752 + break;
5753 + default:
5754 + ret = -EINVAL;
5755 + }
5756 + return ret;
5757 +}
5758 +
5759 +static int do_ebt_get_ctl(struct sock *sk, int cmd, void *user, int *len)
5760 +{
5761 + int ret;
5762 + struct ebt_replace tmp;
5763 + struct ebt_table *t;
5764 +
5765 + if (copy_from_user(&tmp, user, sizeof(tmp)))
5766 + return -EFAULT;
5767 +
5768 + t = find_table_lock(tmp.name, &ret, &ebt_mutex);
5769 + if (!t)
5770 + return ret;
5771 +
5772 + switch(cmd) {
5773 + case EBT_SO_GET_INFO:
5774 + case EBT_SO_GET_INIT_INFO:
5775 + if (*len != sizeof(struct ebt_replace)){
5776 + ret = -EINVAL;
5777 + up(&ebt_mutex);
5778 + break;
5779 + }
5780 + if (cmd == EBT_SO_GET_INFO) {
5781 + tmp.nentries = t->private->nentries;
5782 + tmp.entries_size = t->private->entries_size;
5783 + tmp.valid_hooks = t->valid_hooks;
5784 + } else {
5785 + tmp.nentries = t->table->nentries;
5786 + tmp.entries_size = t->table->entries_size;
5787 + tmp.valid_hooks = t->table->valid_hooks;
5788 + }
5789 + up(&ebt_mutex);
5790 + if (copy_to_user(user, &tmp, *len) != 0){
5791 + BUGPRINT("c2u Didn't work\n");
5792 + ret = -EFAULT;
5793 + break;
5794 + }
5795 + ret = 0;
5796 + break;
5797 +
5798 + case EBT_SO_GET_ENTRIES:
5799 + case EBT_SO_GET_INIT_ENTRIES:
5800 + ret = copy_everything_to_user(t, user, len, cmd);
5801 + up(&ebt_mutex);
5802 + break;
5803 +
5804 + default:
5805 + up(&ebt_mutex);
5806 + ret = -EINVAL;
5807 + }
5808 +
5809 + return ret;
5810 +}
5811 +
5812 +static struct nf_sockopt_ops ebt_sockopts =
5813 +{ { NULL, NULL }, PF_INET, EBT_BASE_CTL, EBT_SO_SET_MAX + 1, do_ebt_set_ctl,
5814 + EBT_BASE_CTL, EBT_SO_GET_MAX + 1, do_ebt_get_ctl, 0, NULL
5815 +};
5816 +
5817 +static int __init init(void)
5818 +{
5819 + int ret;
5820 +
5821 + down(&ebt_mutex);
5822 + list_named_insert(&ebt_targets, &ebt_standard_target);
5823 + up(&ebt_mutex);
5824 + if ((ret = nf_register_sockopt(&ebt_sockopts)) < 0)
5825 + return ret;
5826 +
5827 + printk(KERN_NOTICE "Ebtables v2.0 registered\n");
5828 + return 0;
5829 +}
5830 +
5831 +static void __exit fini(void)
5832 +{
5833 + nf_unregister_sockopt(&ebt_sockopts);
5834 + printk(KERN_NOTICE "Ebtables v2.0 unregistered\n");
5835 +}
5836 +
5837 +EXPORT_SYMBOL(ebt_register_table);
5838 +EXPORT_SYMBOL(ebt_unregister_table);
5839 +EXPORT_SYMBOL(ebt_register_match);
5840 +EXPORT_SYMBOL(ebt_unregister_match);
5841 +EXPORT_SYMBOL(ebt_register_watcher);
5842 +EXPORT_SYMBOL(ebt_unregister_watcher);
5843 +EXPORT_SYMBOL(ebt_register_target);
5844 +EXPORT_SYMBOL(ebt_unregister_target);
5845 +EXPORT_SYMBOL(ebt_do_table);
5846 +module_init(init);
5847 +module_exit(fini);
5848 +MODULE_LICENSE("GPL");
5849 diff -Nurb src/linux/linux.stock/net/core/dev.c src/linux/linux/net/core/dev.c
5850 --- src/linux/linux.stock/net/core/dev.c 2003-10-14 04:02:55.000000000 -0400
5851 +++ src/linux/linux/net/core/dev.c 2004-07-10 23:46:39.000000000 -0400
5852 @@ -1393,7 +1393,7 @@
5853
5854
5855 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
5856 -void (*br_handle_frame_hook)(struct sk_buff *skb) = NULL;
5857 +int (*br_handle_frame_hook)(struct sk_buff *skb) = NULL;
5858 #endif
5859
5860 static __inline__ int handle_bridge(struct sk_buff *skb,
5861 @@ -1410,7 +1410,6 @@
5862 }
5863 }
5864
5865 - br_handle_frame_hook(skb);
5866 return ret;
5867 }
5868
5869 @@ -1470,7 +1469,12 @@
5870 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
5871 if (skb->dev->br_port != NULL &&
5872 br_handle_frame_hook != NULL) {
5873 - return handle_bridge(skb, pt_prev);
5874 + int ret;
5875 +
5876 + ret = handle_bridge(skb, pt_prev);
5877 + if (br_handle_frame_hook(skb) == 0)
5878 + return ret;
5879 + pt_prev = NULL;
5880 }
5881 #endif
5882
5883 diff -Nurb src/linux/linux.stock/net/core/netfilter.c src/linux/linux/net/core/netfilter.c
5884 --- src/linux/linux.stock/net/core/netfilter.c 2004-07-10 23:29:56.000000000 -0400
5885 +++ src/linux/linux/net/core/netfilter.c 2004-07-10 23:46:39.000000000 -0400
5886 @@ -344,10 +344,15 @@
5887 const struct net_device *indev,
5888 const struct net_device *outdev,
5889 struct list_head **i,
5890 - int (*okfn)(struct sk_buff *))
5891 + int (*okfn)(struct sk_buff *),
5892 + int hook_thresh)
5893 {
5894 for (*i = (*i)->next; *i != head; *i = (*i)->next) {
5895 struct nf_hook_ops *elem = (struct nf_hook_ops *)*i;
5896 +
5897 + if (hook_thresh > elem->priority)
5898 + continue;
5899 +
5900 switch (elem->hook(hook, skb, indev, outdev, okfn)) {
5901 case NF_QUEUE:
5902 return NF_QUEUE;
5903 @@ -415,6 +420,10 @@
5904 {
5905 int status;
5906 struct nf_info *info;
5907 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
5908 + struct net_device *physindev = NULL;
5909 + struct net_device *physoutdev = NULL;
5910 +#endif
5911
5912 if (!queue_handler[pf].outfn) {
5913 kfree_skb(skb);
5914 @@ -437,11 +446,24 @@
5915 if (indev) dev_hold(indev);
5916 if (outdev) dev_hold(outdev);
5917
5918 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
5919 + if (skb->nf_bridge) {
5920 + physindev = skb->nf_bridge->physindev;
5921 + if (physindev) dev_hold(physindev);
5922 + physoutdev = skb->nf_bridge->physoutdev;
5923 + if (physoutdev) dev_hold(physoutdev);
5924 + }
5925 +#endif
5926 +
5927 status = queue_handler[pf].outfn(skb, info, queue_handler[pf].data);
5928 if (status < 0) {
5929 /* James M doesn't say fuck enough. */
5930 if (indev) dev_put(indev);
5931 if (outdev) dev_put(outdev);
5932 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
5933 + if (physindev) dev_put(physindev);
5934 + if (physoutdev) dev_put(physoutdev);
5935 +#endif
5936 kfree(info);
5937 kfree_skb(skb);
5938 return;
5939 @@ -451,7 +473,8 @@
5940 int nf_hook_slow(int pf, unsigned int hook, struct sk_buff *skb,
5941 struct net_device *indev,
5942 struct net_device *outdev,
5943 - int (*okfn)(struct sk_buff *))
5944 + int (*okfn)(struct sk_buff *),
5945 + int hook_thresh)
5946 {
5947 struct list_head *elem;
5948 unsigned int verdict;
5949 @@ -483,7 +506,7 @@
5950
5951 elem = &nf_hooks[pf][hook];
5952 verdict = nf_iterate(&nf_hooks[pf][hook], &skb, hook, indev,
5953 - outdev, &elem, okfn);
5954 + outdev, &elem, okfn, hook_thresh);
5955 if (verdict == NF_QUEUE) {
5956 NFDEBUG("nf_hook: Verdict = QUEUE.\n");
5957 nf_queue(skb, elem, pf, hook, indev, outdev, okfn);
5958 @@ -512,6 +535,14 @@
5959
5960 /* We don't have BR_NETPROTO_LOCK here */
5961 br_read_lock_bh(BR_NETPROTO_LOCK);
5962 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
5963 + if (skb->nf_bridge) {
5964 + if (skb->nf_bridge->physindev)
5965 + dev_put(skb->nf_bridge->physindev);
5966 + if (skb->nf_bridge->physoutdev)
5967 + dev_put(skb->nf_bridge->physoutdev);
5968 + }
5969 +#endif
5970 for (i = nf_hooks[info->pf][info->hook].next; i != elem; i = i->next) {
5971 if (i == &nf_hooks[info->pf][info->hook]) {
5972 /* The module which sent it to userspace is gone. */
5973 @@ -532,7 +563,7 @@
5974 verdict = nf_iterate(&nf_hooks[info->pf][info->hook],
5975 &skb, info->hook,
5976 info->indev, info->outdev, &elem,
5977 - info->okfn);
5978 + info->okfn, INT_MIN);
5979 }
5980
5981 switch (verdict) {
5982 diff -Nurb src/linux/linux.stock/net/core/skbuff.c src/linux/linux/net/core/skbuff.c
5983 --- src/linux/linux.stock/net/core/skbuff.c 2003-10-14 04:09:32.000000000 -0400
5984 +++ src/linux/linux/net/core/skbuff.c 2004-07-10 23:46:39.000000000 -0400
5985 @@ -244,6 +244,9 @@
5986 #ifdef CONFIG_NETFILTER_DEBUG
5987 skb->nf_debug = 0;
5988 #endif
5989 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
5990 + skb->nf_bridge = NULL;
5991 +#endif
5992 #endif
5993 #ifdef CONFIG_NET_SCHED
5994 skb->tc_index = 0;
5995 @@ -324,6 +327,9 @@
5996 }
5997 #ifdef CONFIG_NETFILTER
5998 nf_conntrack_put(skb->nfct);
5999 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6000 + nf_bridge_put(skb->nf_bridge);
6001 +#endif
6002 #endif
6003 skb_headerinit(skb, NULL, 0); /* clean state */
6004 kfree_skbmem(skb);
6005 @@ -390,6 +396,9 @@
6006 #ifdef CONFIG_NETFILTER_DEBUG
6007 C(nf_debug);
6008 #endif
6009 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6010 + C(nf_bridge);
6011 +#endif
6012 #endif /*CONFIG_NETFILTER*/
6013 #if defined(CONFIG_HIPPI)
6014 C(private);
6015 @@ -402,6 +411,9 @@
6016 skb->cloned = 1;
6017 #ifdef CONFIG_NETFILTER
6018 nf_conntrack_get(skb->nfct);
6019 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6020 + nf_bridge_get(skb->nf_bridge);
6021 +#endif
6022 #endif
6023 return n;
6024 }
6025 @@ -436,6 +448,10 @@
6026 #ifdef CONFIG_NETFILTER_DEBUG
6027 new->nf_debug=old->nf_debug;
6028 #endif
6029 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6030 + new->nf_bridge=old->nf_bridge;
6031 + nf_bridge_get(new->nf_bridge);
6032 +#endif
6033 #endif
6034 #ifdef CONFIG_NET_SCHED
6035 new->tc_index = old->tc_index;
6036 @@ -722,8 +738,8 @@
6037 /* Set the tail pointer and length */
6038 skb_put(n,skb->len);
6039
6040 - /* Copy the data only. */
6041 - if (skb_copy_bits(skb, 0, n->data, skb->len))
6042 + /* Copy the linear data and header. */
6043 + if (skb_copy_bits(skb, -newheadroom, n->head, newheadroom + skb->len))
6044 BUG();
6045
6046 copy_skb_header(n, skb);
6047 diff -Nurb src/linux/linux.stock/net/ipv4/ip_output.c src/linux/linux/net/ipv4/ip_output.c
6048 --- src/linux/linux.stock/net/ipv4/ip_output.c 2003-10-14 04:09:33.000000000 -0400
6049 +++ src/linux/linux/net/ipv4/ip_output.c 2004-07-10 23:46:39.000000000 -0400
6050 @@ -879,6 +879,10 @@
6051 /* Connection association is same as pre-frag packet */
6052 skb2->nfct = skb->nfct;
6053 nf_conntrack_get(skb2->nfct);
6054 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6055 + skb2->nf_bridge = skb->nf_bridge;
6056 + nf_bridge_get(skb2->nf_bridge);
6057 +#endif
6058 #ifdef CONFIG_NETFILTER_DEBUG
6059 skb2->nf_debug = skb->nf_debug;
6060 #endif
6061 diff -Nurb src/linux/linux.stock/net/ipv4/netfilter/Config.in src/linux/linux/net/ipv4/netfilter/Config.in
6062 --- src/linux/linux.stock/net/ipv4/netfilter/Config.in 2004-07-10 23:30:19.000000000 -0400
6063 +++ src/linux/linux/net/ipv4/netfilter/Config.in 2004-07-10 23:46:39.000000000 -0400
6064 @@ -83,6 +83,9 @@
6065 dep_tristate ' String match support (EXPERIMENTAL)' CONFIG_IP_NF_MATCH_STRING $CONFIG_IP_NF_IPTABLES
6066 dep_tristate ' Owner match support (EXPERIMENTAL)' CONFIG_IP_NF_MATCH_OWNER $CONFIG_IP_NF_IPTABLES
6067 fi
6068 + if [ "$CONFIG_BRIDGE" != "n" ]; then
6069 + dep_tristate ' Physdev match support' CONFIG_IP_NF_MATCH_PHYSDEV $CONFIG_IP_NF_IPTABLES
6070 + fi
6071 # The targets
6072 dep_tristate ' Packet filtering' CONFIG_IP_NF_FILTER $CONFIG_IP_NF_IPTABLES
6073 if [ "$CONFIG_IP_NF_FILTER" != "n" ]; then
6074 diff -Nurb src/linux/linux.stock/net/ipv4/netfilter/Makefile src/linux/linux/net/ipv4/netfilter/Makefile
6075 --- src/linux/linux.stock/net/ipv4/netfilter/Makefile 2004-07-10 23:30:19.000000000 -0400
6076 +++ src/linux/linux/net/ipv4/netfilter/Makefile 2004-07-10 23:46:39.000000000 -0400
6077 @@ -149,6 +149,8 @@
6078 obj-$(CONFIG_IP_NF_MATCH_TCPMSS) += ipt_tcpmss.o
6079 obj-$(CONFIG_IP_NF_MATCH_REALM) += ipt_realm.o
6080
6081 +obj-$(CONFIG_IP_NF_MATCH_PHYSDEV) += ipt_physdev.o
6082 +
6083 # targets
6084 obj-$(CONFIG_IP_NF_TARGET_REJECT) += ipt_REJECT.o
6085 obj-$(CONFIG_IP_NF_TARGET_MIRROR) += ipt_MIRROR.o
6086 diff -Nurb src/linux/linux.stock/net/ipv4/netfilter/ip_tables.c src/linux/linux/net/ipv4/netfilter/ip_tables.c
6087 --- src/linux/linux.stock/net/ipv4/netfilter/ip_tables.c 2004-07-10 23:29:53.000000000 -0400
6088 +++ src/linux/linux/net/ipv4/netfilter/ip_tables.c 2004-07-10 23:46:39.000000000 -0400
6089 @@ -121,12 +121,19 @@
6090 static inline int
6091 ip_packet_match(const struct iphdr *ip,
6092 const char *indev,
6093 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6094 + const char *physindev,
6095 +#endif
6096 const char *outdev,
6097 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6098 + const char *physoutdev,
6099 +#endif
6100 const struct ipt_ip *ipinfo,
6101 int isfrag)
6102 {
6103 size_t i;
6104 unsigned long ret;
6105 + unsigned long ret2 = 1;
6106
6107 #define FWINV(bool,invflg) ((bool) ^ !!(ipinfo->invflags & invflg))
6108
6109 @@ -156,7 +163,15 @@
6110 & ((const unsigned long *)ipinfo->iniface_mask)[i];
6111 }
6112
6113 - if (FWINV(ret != 0, IPT_INV_VIA_IN)) {
6114 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6115 + for (i = 0, ret2 = 0; i < IFNAMSIZ/sizeof(unsigned long); i++) {
6116 + ret2 |= (((const unsigned long *)physindev)[i]
6117 + ^ ((const unsigned long *)ipinfo->iniface)[i])
6118 + & ((const unsigned long *)ipinfo->iniface_mask)[i];
6119 + }
6120 +#endif
6121 +
6122 + if (FWINV(ret != 0 && ret2 != 0, IPT_INV_VIA_IN)) {
6123 dprintf("VIA in mismatch (%s vs %s).%s\n",
6124 indev, ipinfo->iniface,
6125 ipinfo->invflags&IPT_INV_VIA_IN ?" (INV)":"");
6126 @@ -169,7 +184,15 @@
6127 & ((const unsigned long *)ipinfo->outiface_mask)[i];
6128 }
6129
6130 - if (FWINV(ret != 0, IPT_INV_VIA_OUT)) {
6131 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6132 + for (i = 0, ret2 = 0; i < IFNAMSIZ/sizeof(unsigned long); i++) {
6133 + ret2 |= (((const unsigned long *)physoutdev)[i]
6134 + ^ ((const unsigned long *)ipinfo->outiface)[i])
6135 + & ((const unsigned long *)ipinfo->outiface_mask)[i];
6136 + }
6137 +#endif
6138 +
6139 + if (FWINV(ret != 0 && ret2 != 0, IPT_INV_VIA_OUT)) {
6140 dprintf("VIA out mismatch (%s vs %s).%s\n",
6141 outdev, ipinfo->outiface,
6142 ipinfo->invflags&IPT_INV_VIA_OUT ?" (INV)":"");
6143 @@ -272,6 +295,9 @@
6144 /* Initializing verdict to NF_DROP keeps gcc happy. */
6145 unsigned int verdict = NF_DROP;
6146 const char *indev, *outdev;
6147 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6148 + const char *physindev, *physoutdev;
6149 +#endif
6150 void *table_base;
6151 struct ipt_entry *e, *back;
6152
6153 @@ -281,6 +307,13 @@
6154 datalen = (*pskb)->len - ip->ihl * 4;
6155 indev = in ? in->name : nulldevname;
6156 outdev = out ? out->name : nulldevname;
6157 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6158 + physindev = ((*pskb)->nf_bridge && (*pskb)->nf_bridge->physindev) ?
6159 + (*pskb)->nf_bridge->physindev->name : nulldevname;
6160 + physoutdev = ((*pskb)->nf_bridge && (*pskb)->nf_bridge->physoutdev) ?
6161 + (*pskb)->nf_bridge->physoutdev->name : nulldevname;
6162 +#endif
6163 +
6164 /* We handle fragments by dealing with the first fragment as
6165 * if it was a normal packet. All other fragments are treated
6166 * normally, except that they will NEVER match rules that ask
6167 @@ -316,7 +349,15 @@
6168 IP_NF_ASSERT(e);
6169 IP_NF_ASSERT(back);
6170 (*pskb)->nfcache |= e->nfcache;
6171 - if (ip_packet_match(ip, indev, outdev, &e->ip, offset)) {
6172 + if (ip_packet_match(ip, indev,
6173 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6174 + physindev,
6175 +#endif
6176 + outdev,
6177 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6178 + physoutdev,
6179 +#endif
6180 + &e->ip, offset)) {
6181 struct ipt_entry_target *t;
6182
6183 if (IPT_MATCH_ITERATE(e, do_match,
6184 diff -Nurb src/linux/linux.stock/net/ipv4/netfilter/ipt_LOG.c src/linux/linux/net/ipv4/netfilter/ipt_LOG.c
6185 --- src/linux/linux.stock/net/ipv4/netfilter/ipt_LOG.c 2004-07-10 23:29:56.000000000 -0400
6186 +++ src/linux/linux/net/ipv4/netfilter/ipt_LOG.c 2004-07-10 23:46:39.000000000 -0400
6187 @@ -319,6 +319,18 @@
6188 prefix == NULL ? loginfo->prefix : prefix,
6189 in ? in->name : "",
6190 out ? out->name : "");
6191 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6192 + if ((*pskb)->nf_bridge) {
6193 + struct net_device *physindev = (*pskb)->nf_bridge->physindev;
6194 + struct net_device *physoutdev = (*pskb)->nf_bridge->physoutdev;
6195 +
6196 + if (physindev && in != physindev)
6197 + printk("PHYSIN=%s ", physindev->name);
6198 + if (physoutdev && out != physoutdev)
6199 + printk("PHYSOUT=%s ", physoutdev->name);
6200 + }
6201 +#endif
6202 +
6203 if (in && !out) {
6204 /* MAC logging for input chain only. */
6205 printk("MAC=");
6206 diff -Nurb src/linux/linux.stock/net/ipv4/netfilter/ipt_physdev.c src/linux/linux/net/ipv4/netfilter/ipt_physdev.c
6207 --- src/linux/linux.stock/net/ipv4/netfilter/ipt_physdev.c 1969-12-31 19:00:00.000000000 -0500
6208 +++ src/linux/linux/net/ipv4/netfilter/ipt_physdev.c 2004-07-10 23:46:39.000000000 -0400
6209 @@ -0,0 +1,127 @@
6210 +/* Kernel module to match the bridge port in and
6211 + * out device for IP packets coming into contact with a bridge. */
6212 +#include <linux/module.h>
6213 +#include <linux/skbuff.h>
6214 +#include <linux/netfilter_ipv4/ipt_physdev.h>
6215 +#include <linux/netfilter_ipv4/ip_tables.h>
6216 +#include <linux/netfilter_bridge.h>
6217 +#include <linux/netdevice.h>
6218 +#define MATCH 1
6219 +#define NOMATCH 0
6220 +
6221 +static int
6222 +match(const struct sk_buff *skb,
6223 + const struct net_device *in,
6224 + const struct net_device *out,
6225 + const void *matchinfo,
6226 + int offset,
6227 + const void *hdr,
6228 + u_int16_t datalen,
6229 + int *hotdrop)
6230 +{
6231 + int i;
6232 + static const char nulldevname[IFNAMSIZ] = { 0 };
6233 + const struct ipt_physdev_info *info = matchinfo;
6234 + unsigned long ret;
6235 + const char *indev, *outdev;
6236 + struct nf_bridge_info *nf_bridge;
6237 +
6238 + /* Not a bridged IP packet or no info available yet:
6239 + * LOCAL_OUT/mangle and LOCAL_OUT/nat don't know if
6240 + * the destination device will be a bridge. */
6241 + if (!(nf_bridge = skb->nf_bridge)) {
6242 + /* Return MATCH if the invert flags of the used options are on */
6243 + if ((info->bitmask & IPT_PHYSDEV_OP_BRIDGED) &&
6244 + !(info->invert & IPT_PHYSDEV_OP_BRIDGED))
6245 + return NOMATCH;
6246 + if ((info->bitmask & IPT_PHYSDEV_OP_ISIN) &&
6247 + !(info->invert & IPT_PHYSDEV_OP_ISIN))
6248 + return NOMATCH;
6249 + if ((info->bitmask & IPT_PHYSDEV_OP_ISOUT) &&
6250 + !(info->invert & IPT_PHYSDEV_OP_ISOUT))
6251 + return NOMATCH;
6252 + if ((info->bitmask & IPT_PHYSDEV_OP_IN) &&
6253 + !(info->invert & IPT_PHYSDEV_OP_IN))
6254 + return NOMATCH;
6255 + if ((info->bitmask & IPT_PHYSDEV_OP_OUT) &&
6256 + !(info->invert & IPT_PHYSDEV_OP_OUT))
6257 + return NOMATCH;
6258 + return MATCH;
6259 + }
6260 +
6261 + /* This only makes sense in the FORWARD and POSTROUTING chains */
6262 + if ((info->bitmask & IPT_PHYSDEV_OP_BRIDGED) &&
6263 + (!!(nf_bridge->mask & BRNF_BRIDGED) ^
6264 + !(info->invert & IPT_PHYSDEV_OP_BRIDGED)))
6265 + return NOMATCH;
6266 +
6267 + if ((info->bitmask & IPT_PHYSDEV_OP_ISIN &&
6268 + (!nf_bridge->physindev ^ !!(info->invert & IPT_PHYSDEV_OP_ISIN))) ||
6269 + (info->bitmask & IPT_PHYSDEV_OP_ISOUT &&
6270 + (!nf_bridge->physoutdev ^ !!(info->invert & IPT_PHYSDEV_OP_ISOUT))))
6271 + return NOMATCH;
6272 +
6273 + if (!(info->bitmask & IPT_PHYSDEV_OP_IN))
6274 + goto match_outdev;
6275 + indev = nf_bridge->physindev ? nf_bridge->physindev->name : nulldevname;
6276 + for (i = 0, ret = 0; i < IFNAMSIZ/sizeof(unsigned long); i++) {
6277 + ret |= (((const unsigned long *)indev)[i]
6278 + ^ ((const unsigned long *)info->physindev)[i])
6279 + & ((const unsigned long *)info->in_mask)[i];
6280 + }
6281 +
6282 + if ((ret == 0) ^ !(info->invert & IPT_PHYSDEV_OP_IN))
6283 + return NOMATCH;
6284 +
6285 +match_outdev:
6286 + if (!(info->bitmask & IPT_PHYSDEV_OP_OUT))
6287 + return MATCH;
6288 + outdev = nf_bridge->physoutdev ?
6289 + nf_bridge->physoutdev->name : nulldevname;
6290 + for (i = 0, ret = 0; i < IFNAMSIZ/sizeof(unsigned long); i++) {
6291 + ret |= (((const unsigned long *)outdev)[i]
6292 + ^ ((const unsigned long *)info->physoutdev)[i])
6293 + & ((const unsigned long *)info->out_mask)[i];
6294 + }
6295 +
6296 + return (ret != 0) ^ !(info->invert & IPT_PHYSDEV_OP_OUT);
6297 +}
6298 +
6299 +static int
6300 +checkentry(const char *tablename,
6301 + const struct ipt_ip *ip,
6302 + void *matchinfo,
6303 + unsigned int matchsize,
6304 + unsigned int hook_mask)
6305 +{
6306 + const struct ipt_physdev_info *info = matchinfo;
6307 +
6308 + if (matchsize != IPT_ALIGN(sizeof(struct ipt_physdev_info)))
6309 + return 0;
6310 + if (!(info->bitmask & IPT_PHYSDEV_OP_MASK) ||
6311 + info->bitmask & ~IPT_PHYSDEV_OP_MASK)
6312 + return 0;
6313 + return 1;
6314 +}
6315 +
6316 +static struct ipt_match physdev_match = {
6317 + .name = "physdev",
6318 + .match = &match,
6319 + .checkentry = &checkentry,
6320 + .me = THIS_MODULE,
6321 +};
6322 +
6323 +static int __init init(void)
6324 +{
6325 + return ipt_register_match(&physdev_match);
6326 +}
6327 +
6328 +static void __exit fini(void)
6329 +{
6330 + ipt_unregister_match(&physdev_match);
6331 +}
6332 +
6333 +module_init(init);
6334 +module_exit(fini);
6335 +MODULE_LICENSE("GPL");
6336 +EXPORT_NO_SYMBOLS;
This page took 0.28527 seconds and 5 git commands to generate.