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
5 struct net_bridge_port;
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);
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
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
26 #define NF_HOOK(pf, hook, skb, indev, outdev, okfn) \
27 (list_empty(&nf_hooks[(pf)][(hook)]) \
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)]) \
34 + : nf_hook_slow((pf), (hook), (skb), (indev), (outdev), (okfn), (thresh)))
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);
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
48 +#ifndef __LINUX_BRIDGE_EBT_802_3_H
49 +#define __LINUX_BRIDGE_EBT_802_3_H
51 +#define EBT_802_3_SAP 0x01
52 +#define EBT_802_3_TYPE 0x02
54 +#define EBT_802_3_MATCH "802_3"
57 + * If frame has DSAP/SSAP value 0xaa you must check the SNAP type
58 + * to discover what kind of packet we're carrying.
60 +#define CHECK_TYPE 0xaa
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.
70 +#define EBT_802_3_MASK (EBT_802_3_SAP | EBT_802_3_TYPE | EBT_802_3)
72 +/* ui has one byte ctrl, ni has two */
89 +struct ebt_802_3_hdr {
99 +struct ebt_802_3_info
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
112 +#ifndef __LINUX_BRIDGE_EBT_AMONG_H
113 +#define __LINUX_BRIDGE_EBT_AMONG_H
115 +#define EBT_AMONG_DST 0x01
116 +#define EBT_AMONG_SRC 0x02
118 +/* Grzegorz Borowiak <grzes@gnu.univ.gda.pl> 2003
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.
124 + * The hash value of an address is its last byte.
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.
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.
140 + * Yes, it is a memory overhead, but in 2003 AD, who cares?
143 +struct ebt_mac_wormhash_tuple
149 +struct ebt_mac_wormhash
153 + struct ebt_mac_wormhash_tuple pool[0];
156 +#define ebt_mac_wormhash_size(x) ((x) ? sizeof(struct ebt_mac_wormhash) \
157 + + (x)->poolsize * sizeof(struct ebt_mac_wormhash_tuple) : 0)
159 +struct ebt_among_info
166 +#define EBT_AMONG_DST_NEG 0x1
167 +#define EBT_AMONG_SRC_NEG 0x2
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)
174 +#define EBT_AMONG_MATCH "among"
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
181 +#ifndef __LINUX_BRIDGE_EBT_ARP_H
182 +#define __LINUX_BRIDGE_EBT_ARP_H
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"
204 + unsigned char smaddr[ETH_ALEN];
205 + unsigned char smmsk[ETH_ALEN];
206 + unsigned char dmaddr[ETH_ALEN];
207 + unsigned char dmmsk[ETH_ALEN];
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
217 +#ifndef __LINUX_BRIDGE_EBT_ARPREPLY_H
218 +#define __LINUX_BRIDGE_EBT_ARPREPLY_H
220 +struct ebt_arpreply_info
222 + unsigned char mac[ETH_ALEN];
225 +#define EBT_ARPREPLY_TARGET "arpreply"
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
236 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
241 + * added ip-sport and ip-dport
242 + * Innominate Security Technologies AG <mhopf@innominate.com>
246 +#ifndef __LINUX_BRIDGE_EBT_IP_H
247 +#define __LINUX_BRIDGE_EBT_IP_H
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"
259 +// the same values are used for the invflags
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
279 +#ifndef __LINUX_BRIDGE_EBT_LIMIT_H
280 +#define __LINUX_BRIDGE_EBT_LIMIT_H
282 +#define EBT_LIMIT_MATCH "limit"
284 +/* timings are in milliseconds. */
285 +#define EBT_LIMIT_SCALE 10000
287 +/* 1/10,000 sec period => max of 10,000/sec. Min rate is then 429490
288 + seconds, or one every 59 hours. */
290 +struct ebt_limit_info
292 + u_int32_t avg; /* Average secs between packets * scale */
293 + u_int32_t burst; /* Period multiplier for upper limit. */
295 + /* Used internally by the kernel */
296 + unsigned long prev;
298 + u_int32_t credit_cap, cost;
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
306 +#ifndef __LINUX_BRIDGE_EBT_LOG_H
307 +#define __LINUX_BRIDGE_EBT_LOG_H
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"
318 + uint8_t prefix[EBT_LOG_PREFIX_SIZE];
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
327 +#ifndef __LINUX_BRIDGE_EBT_MARK_M_H
328 +#define __LINUX_BRIDGE_EBT_MARK_M_H
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
335 + unsigned long mark, mask;
339 +#define EBT_MARK_MATCH "mark_m"
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
346 +#ifndef __LINUX_BRIDGE_EBT_MARK_T_H
347 +#define __LINUX_BRIDGE_EBT_MARK_T_H
349 +struct ebt_mark_t_info
351 + unsigned long mark;
352 + // EBT_ACCEPT, EBT_DROP or EBT_CONTINUE or EBT_RETURN
355 +#define EBT_MARK_TARGET "mark"
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
362 +#ifndef __LINUX_BRIDGE_EBT_NAT_H
363 +#define __LINUX_BRIDGE_EBT_NAT_H
367 + unsigned char mac[ETH_ALEN];
368 + // EBT_ACCEPT, EBT_DROP, EBT_CONTINUE or EBT_RETURN
371 +#define EBT_SNAT_TARGET "snat"
372 +#define EBT_DNAT_TARGET "dnat"
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
379 +#ifndef __LINUX_BRIDGE_EBT_PKTTYPE_H
380 +#define __LINUX_BRIDGE_EBT_PKTTYPE_H
382 +struct ebt_pkttype_info
387 +#define EBT_PKTTYPE_MATCH "pkttype"
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
394 +#ifndef __LINUX_BRIDGE_EBT_REDIRECT_H
395 +#define __LINUX_BRIDGE_EBT_REDIRECT_H
397 +struct ebt_redirect_info
399 + // EBT_ACCEPT, EBT_DROP or EBT_CONTINUE or EBT_RETURN
402 +#define EBT_REDIRECT_TARGET "redirect"
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
409 +#ifndef __LINUX_BRIDGE_EBT_STP_H
410 +#define __LINUX_BRIDGE_EBT_STP_H
412 +#define EBT_STP_TYPE 0x0001
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
426 +#define EBT_STP_MASK 0x0fff
427 +#define EBT_STP_CONFIG_MASK 0x0ffe
429 +#define EBT_STP_MATCH "stp"
431 +struct ebt_stp_config_info
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;
449 + struct ebt_stp_config_info config;
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
459 +#ifndef __LINUX_BRIDGE_EBT_VLAN_H
460 +#define __LINUX_BRIDGE_EBT_VLAN_H
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"
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 */
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
487 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
489 + * ebtables.c,v 2.0, September, 2002
491 + * This code is stongly inspired on the iptables code which is
492 + * Copyright (C) 1999 Paul `Rusty' Russell & Michael J. Neuling
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>
501 +#define EBT_TABLE_MAXNAMELEN 32
502 +#define EBT_CHAIN_MAXNAMELEN EBT_TABLE_MAXNAMELEN
503 +#define EBT_FUNCTION_MAXNAMELEN EBT_TABLE_MAXNAMELEN
505 +// verdicts >0 are "branches"
506 +#define EBT_ACCEPT -1
508 +#define EBT_CONTINUE -3
509 +#define EBT_RETURN -4
510 +#define NUM_STANDARD_TARGETS 4
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;
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
530 + unsigned int nentries;
535 +// used for the bitmask of struct ebt_entry
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
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)
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)
563 +struct ebt_entry_match
566 + char name[EBT_FUNCTION_MAXNAMELEN];
567 + struct ebt_match *match;
570 + unsigned int match_size;
571 + unsigned char data[0];
574 +struct ebt_entry_watcher
577 + char name[EBT_FUNCTION_MAXNAMELEN];
578 + struct ebt_watcher *watcher;
581 + unsigned int watcher_size;
582 + unsigned char data[0];
585 +struct ebt_entry_target
588 + char name[EBT_FUNCTION_MAXNAMELEN];
589 + struct ebt_target *target;
592 + unsigned int target_size;
593 + unsigned char data[0];
596 +#define EBT_STANDARD_TARGET "standard"
597 +struct ebt_standard_target
599 + struct ebt_entry_target target;
605 + // this needs to be the first field
606 + unsigned int bitmask;
607 + unsigned int invflags;
609 + // the physical in-dev
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];
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;
647 +// [gs]etsockopt numbers
648 +#define EBT_BASE_CTL 128
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)
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)
662 +// return values for match() functions
664 +#define EBT_NOMATCH 1
668 + struct list_head list;
669 + const char name[EBT_FUNCTION_MAXNAMELEN];
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);
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);
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);
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);
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);
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);
710 +// used for jumping from and into user defined chains (udc)
711 +struct ebt_chainstack
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
718 +struct ebt_table_info
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;
728 + struct ebt_counter counters[0] ____cacheline_aligned;
733 + struct list_head list;
734 + char name[EBT_TABLE_MAXNAMELEN];
735 + struct ebt_replace *table;
736 + unsigned int valid_hooks;
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;
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);
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)
770 +#endif /* __KERNEL__ */
772 +// blatently stolen from ip_tables.h
773 +// fn returns 0 to continue iteration
774 +#define EBT_MATCH_ITERATE(e, fn, args...) \
776 + unsigned int __i; \
778 + struct ebt_entry_match *__match; \
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; \
786 + __ret = fn(__match , ## args); \
790 + if (__ret == 0) { \
791 + if (__i != (e)->watchers_offset) \
797 +#define EBT_WATCHER_ITERATE(e, fn, args...) \
799 + unsigned int __i; \
801 + struct ebt_entry_watcher *__watcher; \
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; \
809 + __ret = fn(__watcher , ## args); \
813 + if (__ret == 0) { \
814 + if (__i != (e)->target_offset) \
820 +#define EBT_ENTRY_ITERATE(entries, size, fn, args...) \
822 + unsigned int __i; \
824 + struct ebt_entry *__entry; \
826 + for (__i = 0; __i < (size);) { \
827 + __entry = (void *)(entries) + __i; \
828 + __ret = fn(__entry , ## args); \
831 + if (__entry->bitmask != 0) \
832 + __i += __entry->next_offset; \
834 + __i += sizeof(struct ebt_entries); \
836 + if (__ret == 0) { \
837 + if (__i != (size)) \
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
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>
857 /* After promisc drops, checksum checks. */
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
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
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,
886 +#ifdef CONFIG_NETFILTER
888 +struct nf_bridge_info *nf_bridge_alloc(struct sk_buff *skb)
890 + struct nf_bridge_info **nf_bridge = &(skb->nf_bridge);
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;
904 +/* Only used in br_forward.c */
906 +void nf_bridge_maybe_copy_header(struct sk_buff *skb)
908 + if (skb->nf_bridge) {
909 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
910 + memcpy(skb->data - 18, skb->nf_bridge->data, 18);
913 + memcpy(skb->data - 16, skb->nf_bridge->data, 16);
918 +void nf_bridge_save_header(struct sk_buff *skb)
920 + int header_size = 16;
922 + if (skb->protocol == __constant_htons(ETH_P_8021Q))
924 + memcpy(skb->nf_bridge->data, skb->data - header_size, header_size);
927 +struct bridge_skb_cb {
932 +#endif /* CONFIG_NETFILTER */
934 +#endif /* __KERNEL__ */
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
940 +#ifndef _IPT_PHYSDEV_H
941 +#define _IPT_PHYSDEV_H
944 +#include <linux/if.h>
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)
954 +struct ipt_physdev_info {
955 + char physindev[IFNAMSIZ];
956 + char in_mask[IFNAMSIZ];
957 + char physoutdev[IFNAMSIZ];
958 + char out_mask[IFNAMSIZ];
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
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
983 struct nf_conntrack *master;
986 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
987 +struct nf_bridge_info {
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;
995 + unsigned long data[32 / sizeof(unsigned long)];
1001 struct sk_buff_head {
1003 #ifdef CONFIG_NETFILTER_DEBUG
1004 unsigned int nf_debug;
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 */
1009 #endif /*CONFIG_NETFILTER*/
1011 #if defined(CONFIG_HIPPI)
1012 @@ -1143,6 +1160,20 @@
1014 atomic_inc(&nfct->master->use);
1017 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
1018 +static inline void nf_bridge_put(struct nf_bridge_info *nf_bridge)
1020 + if (nf_bridge && atomic_dec_and_test(&nf_bridge->use))
1023 +static inline void nf_bridge_get(struct nf_bridge_info *nf_bridge)
1026 + atomic_inc(&nf_bridge->use);
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
1040 +/* /proc/sys/net/bridge */
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,
1049 /* CTL_PROC 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;
1059 + skb->protocol = __constant_htons(ETH_P_8021Q);
1060 + skb->mac.raw -= VLAN_HLEN;
1061 + skb->nh.raw -= VLAN_HLEN;
1063 dev_queue_xmit(skb);
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
1070 source net/decnet/Config.in
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
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
1086 +ifneq ($(CONFIG_BRIDGE),n)
1087 +ifneq ($(CONFIG_BRIDGE),)
1088 +subdir-$(CONFIG_BRIDGE) += bridge/netfilter
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
1100 # Note 2! The CFLAGS definition is now in the main makefile...
1102 +export-objs := br.o
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
1109 +ifeq ($(CONFIG_NETFILTER),y)
1110 +obj-y += br_netfilter.o
1113 obj-m := $(O_TARGET)
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
1120 #include "../atm/lec.h"
1123 +int (*br_should_route_hook) (struct sk_buff **pskb) = NULL;
1125 void br_dec_use_count()
1130 printk(KERN_INFO "NET4: Ethernet Bridge 008 for NET4.0\n");
1132 +#ifdef CONFIG_NETFILTER
1133 + if (br_netfilter_init())
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)
1141 static void __exit br_deinit(void)
1143 +#ifdef CONFIG_NETFILTER
1144 + br_netfilter_fini();
1146 unregister_netdevice_notifier(&br_device_notifier);
1147 br_call_ioctl_atomic(__br_clear_ioctl_hook);
1154 +EXPORT_SYMBOL(br_should_route_hook);
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
1165 -static int __dev_queue_push_xmit(struct sk_buff *skb)
1166 +int br_dev_queue_push_xmit(struct sk_buff *skb)
1168 +#ifdef CONFIG_NETFILTER
1169 + nf_bridge_maybe_copy_header(skb);
1171 skb_push(skb, ETH_HLEN);
1172 dev_queue_xmit(skb);
1177 -static int __br_forward_finish(struct sk_buff *skb)
1178 +int br_forward_finish(struct sk_buff *skb)
1180 NF_HOOK(PF_BRIDGE, NF_BR_POST_ROUTING, skb, NULL, skb->dev,
1181 - __dev_queue_push_xmit);
1182 + br_dev_queue_push_xmit);
1187 static void __br_deliver(struct net_bridge_port *to, struct sk_buff *skb)
1190 +#ifdef CONFIG_NETFILTER_DEBUG
1191 + skb->nf_debug = 0;
1193 NF_HOOK(PF_BRIDGE, NF_BR_LOCAL_OUT, skb, NULL, skb->dev,
1194 - __br_forward_finish);
1195 + br_forward_finish);
1198 static void __br_forward(struct net_bridge_port *to, struct sk_buff *skb)
1202 NF_HOOK(PF_BRIDGE, NF_BR_FORWARD, skb, indev, skb->dev,
1203 - __br_forward_finish);
1204 + br_forward_finish);
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
1213 static int br_pass_frame_up_finish(struct sk_buff *skb)
1215 +#ifdef CONFIG_NETFILTER_DEBUG
1216 + skb->nf_debug = 0;
1222 br_pass_frame_up_finish);
1225 -static int br_handle_frame_finish(struct sk_buff *skb)
1226 +int br_handle_frame_finish(struct sk_buff *skb)
1228 struct net_bridge *br;
1229 unsigned char *dest;
1234 -void br_handle_frame(struct sk_buff *skb)
1235 +int br_handle_frame(struct sk_buff *skb)
1237 struct net_bridge *br;
1238 unsigned char *dest;
1239 @@ -146,25 +149,34 @@
1240 goto handle_special_frame;
1242 if (p->state == BR_STATE_FORWARDING) {
1243 + if (br_should_route_hook && br_should_route_hook(&skb)) {
1244 + read_unlock(&br->lock);
1248 + if (!memcmp(p->br->dev.dev_addr, dest, ETH_ALEN))
1249 + skb->pkt_type = PACKET_HOST;
1251 NF_HOOK(PF_BRIDGE, NF_BR_PRE_ROUTING, skb, skb->dev, NULL,
1252 br_handle_frame_finish);
1253 read_unlock(&br->lock);
1259 read_unlock(&br->lock);
1265 handle_special_frame:
1267 br_stp_handle_bpdu(skb);
1268 read_unlock(&br->lock);
1273 read_unlock(&br->lock);
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
1282 + * Handle firewalling
1283 + * Linux ethernet bridge
1286 + * Lennert Buytenhek <buytenh@gnu.org>
1287 + * Bart De Schuymer (maintainer) <bdschuym@pandora.be>
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
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.
1300 + * Lennert dedicates this file to Kerstin Wurdinger.
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>
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)
1327 +#define has_bridge_parent(device) ((device)->br_port != NULL)
1328 +#define bridge_parent(device) (&((device)->br_port->br->dev))
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;
1336 +#define brnf_filter_vlan_tagged 1
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)
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)
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.
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.
1357 +static struct net_device __fake_net_device = {
1358 + .hard_header_len = ETH_HLEN
1361 +static struct rtable __fake_rtable = {
1364 + __refcnt: ATOMIC_INIT(1),
1365 + dev: &__fake_net_device,
1374 +/* PF_BRIDGE/PRE_ROUTING *********************************************/
1375 +static void __br_dnat_complain(void)
1377 + static unsigned long last_complaint;
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;
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.
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
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.
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.
1403 + * Let us first consider the case that ip_route_input() succeeds:
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.
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.
1415 + * Let us now consider the case that ip_route_input() fails:
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.
1424 + * ip_route_input() will also fail if there is no route available.
1425 + * In that case we just drop the packet.
1427 + * --Lennert, 20020411
1428 + * --Bart, 20020416 (updated)
1429 + * --Bart, 20021007 (updated)
1432 +static int br_nf_pre_routing_finish_bridge(struct sk_buff *skb)
1434 +#ifdef CONFIG_NETFILTER_DEBUG
1435 + skb->nf_debug |= (1 << NF_BR_PRE_ROUTING) | (1 << NF_BR_FORWARD);
1438 + if (skb->pkt_type == PACKET_OTHERHOST) {
1439 + skb->pkt_type = PACKET_HOST;
1440 + skb->nf_bridge->mask |= BRNF_PKT_TYPE;
1442 + skb->nf_bridge->mask ^= BRNF_NF_BRIDGE_PREROUTING;
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;
1449 + skb->dst->output(skb);
1453 +static int br_nf_pre_routing_finish(struct sk_buff *skb)
1455 + struct net_device *dev = skb->dev;
1456 + struct iphdr *iph = skb->nh.iph;
1457 + struct nf_bridge_info *nf_bridge = skb->nf_bridge;
1459 +#ifdef CONFIG_NETFILTER_DEBUG
1460 + skb->nf_debug ^= (1 << NF_BR_PRE_ROUTING);
1463 + if (nf_bridge->mask & BRNF_PKT_TYPE) {
1464 + skb->pkt_type = PACKET_OTHERHOST;
1465 + nf_bridge->mask ^= BRNF_PKT_TYPE;
1467 + nf_bridge->mask ^= BRNF_NF_BRIDGE_PREROUTING;
1469 + if (dnat_took_place(skb)) {
1470 + if (ip_route_input(skb, iph->daddr, iph->saddr, iph->tos,
1472 + struct rtable *rt;
1474 + if (!ip_route_output(&rt, iph->daddr, 0, iph->tos, 0)) {
1475 + /* Bridged-and-DNAT'ed traffic doesn't
1476 + * require ip_forwarding.
1478 + if (((struct dst_entry *)rt)->dev == dev) {
1479 + skb->dst = (struct dst_entry *)rt;
1480 + goto bridged_dnat;
1482 + __br_dnat_complain();
1483 + dst_release((struct dst_entry *)rt);
1488 + if (skb->dst->dev == dev) {
1490 + /* Tell br_nf_local_out this is a
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;
1500 + NF_HOOK_THRESH(PF_BRIDGE, NF_BR_PRE_ROUTING,
1501 + skb, skb->dev, NULL,
1502 + br_nf_pre_routing_finish_bridge,
1506 + memcpy(skb->mac.ethernet->h_dest, dev->dev_addr,
1508 + skb->pkt_type = PACKET_HOST;
1511 + skb->dst = (struct dst_entry *)&__fake_rtable;
1512 + dst_hold(skb->dst);
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;
1520 + NF_HOOK_THRESH(PF_BRIDGE, NF_BR_PRE_ROUTING, skb, skb->dev, NULL,
1521 + br_handle_frame_finish, 1);
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.
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 *))
1536 + struct iphdr *iph;
1538 + struct sk_buff *skb = *pskb;
1539 + struct nf_bridge_info *nf_bridge;
1541 +#ifdef CONFIG_SYSCTL
1542 + if (!brnf_call_iptables)
1546 + if (skb->protocol != __constant_htons(ETH_P_IP)) {
1547 + struct vlan_ethhdr *hdr = (struct vlan_ethhdr *)
1548 + ((*pskb)->mac.ethernet);
1552 + if ((skb = skb_share_check(*pskb, GFP_ATOMIC)) == NULL)
1554 + skb_pull(*pskb, VLAN_HLEN);
1555 + (*pskb)->nh.raw += VLAN_HLEN;
1556 + } else if ((skb = skb_share_check(*pskb, GFP_ATOMIC)) == NULL)
1559 + if (!pskb_may_pull(skb, sizeof(struct iphdr)))
1562 + iph = skb->nh.iph;
1563 + if (iph->ihl < 5 || iph->version != 4)
1566 + if (!pskb_may_pull(skb, 4*iph->ihl))
1569 + iph = skb->nh.iph;
1570 + if (ip_fast_csum((__u8 *)iph, iph->ihl) != 0)
1573 + len = ntohs(iph->tot_len);
1574 + if (skb->len < len || len < 4*iph->ihl)
1577 + if (skb->len > len) {
1578 + __pskb_trim(skb, len);
1579 + if (skb->ip_summed == CHECKSUM_HW)
1580 + skb->ip_summed = CHECKSUM_NONE;
1583 +#ifdef CONFIG_NETFILTER_DEBUG
1584 + skb->nf_debug ^= (1 << NF_IP_PRE_ROUTING);
1586 + if ((nf_bridge = nf_bridge_alloc(skb)) == NULL)
1589 + if (skb->pkt_type == PACKET_OTHERHOST) {
1590 + skb->pkt_type = PACKET_HOST;
1591 + nf_bridge->mask |= BRNF_PKT_TYPE;
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);
1599 + NF_HOOK(PF_INET, NF_IP_PRE_ROUTING, skb, skb->dev, NULL,
1600 + br_nf_pre_routing_finish);
1605 +// IP_INC_STATS_BH(IpInHdrErrors);
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.
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 *))
1623 + struct sk_buff *skb = *pskb;
1625 + if (skb->dst == (struct dst_entry *)&__fake_rtable) {
1626 + dst_release(skb->dst);
1633 +/* PF_BRIDGE/FORWARD *************************************************/
1634 +static int br_nf_forward_finish(struct sk_buff *skb)
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);
1640 +#ifdef CONFIG_NETFILTER_DEBUG
1641 + skb->nf_debug ^= (1 << NF_BR_FORWARD);
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;
1651 + in = *((struct net_device **)(skb->cb));
1653 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
1654 + skb_push(skb, VLAN_HLEN);
1655 + skb->nh.raw -= VLAN_HLEN;
1657 + NF_HOOK_THRESH(PF_BRIDGE, NF_BR_FORWARD, skb, in,
1658 + skb->dev, br_forward_finish, 1);
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
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 *))
1672 + struct sk_buff *skb = *pskb;
1673 + struct nf_bridge_info *nf_bridge;
1674 + struct vlan_ethhdr *hdr = (struct vlan_ethhdr *)(skb->mac.ethernet);
1676 +#ifdef CONFIG_SYSCTL
1677 + if (!skb->nf_bridge)
1681 + if (skb->protocol != __constant_htons(ETH_P_IP)) {
1684 + skb_pull(*pskb, VLAN_HLEN);
1685 + (*pskb)->nh.raw += VLAN_HLEN;
1688 +#ifdef CONFIG_NETFILTER_DEBUG
1689 + skb->nf_debug ^= (1 << NF_BR_FORWARD);
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;
1697 + /* The physdev module checks on this */
1698 + nf_bridge->mask |= BRNF_BRIDGED;
1699 + nf_bridge->physoutdev = skb->dev;
1701 + NF_HOOK(PF_INET, NF_IP_FORWARD, skb, bridge_parent(in),
1702 + bridge_parent(out), br_nf_forward_finish);
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 *))
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);
1716 + if (!brnf_call_arptables)
1719 + if (skb->protocol != __constant_htons(ETH_P_ARP)) {
1722 + skb_pull(*pskb, VLAN_HLEN);
1723 + (*pskb)->nh.raw += VLAN_HLEN;
1726 +#ifdef CONFIG_NETFILTER_DEBUG
1727 + skb->nf_debug ^= (1 << NF_BR_FORWARD);
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;
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);
1745 +/* PF_BRIDGE/LOCAL_OUT ***********************************************/
1746 +static int br_nf_local_out_finish(struct sk_buff *skb)
1748 +#ifdef CONFIG_NETFILTER_DEBUG
1749 + skb->nf_debug &= ~(1 << NF_BR_LOCAL_OUT);
1751 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
1752 + skb_push(skb, VLAN_HLEN);
1753 + skb->nh.raw -= VLAN_HLEN;
1756 + NF_HOOK_THRESH(PF_BRIDGE, NF_BR_LOCAL_OUT, skb, NULL, skb->dev,
1757 + br_forward_finish, NF_BR_PRI_FIRST + 1);
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.
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.
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 *))
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);
1795 +#ifdef CONFIG_SYSCTL
1796 + if (!skb->nf_bridge)
1800 + if (skb->protocol != __constant_htons(ETH_P_IP) && !IS_VLAN_IP)
1803 + /* Sometimes we get packets with NULL ->dst here (for example,
1804 + * running a dhcp client daemon triggers this).
1806 + if (skb->dst == NULL)
1809 + nf_bridge = skb->nf_bridge;
1810 + nf_bridge->physoutdev = skb->dev;
1811 + realindev = nf_bridge->physindev;
1813 + /* Bridged, take PF_BRIDGE/FORWARD.
1814 + * (see big note in front of br_nf_pre_routing_finish)
1816 + if (nf_bridge->mask & BRNF_BRIDGED_DNAT) {
1817 + okfn = br_forward_finish;
1819 + if (nf_bridge->mask & BRNF_PKT_TYPE) {
1820 + skb->pkt_type = PACKET_OTHERHOST;
1821 + nf_bridge->mask ^= BRNF_PKT_TYPE;
1823 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
1824 + skb_push(skb, VLAN_HLEN);
1825 + skb->nh.raw -= VLAN_HLEN;
1828 + NF_HOOK(PF_BRIDGE, NF_BR_FORWARD, skb, realindev,
1831 + struct net_device *realoutdev = bridge_parent(skb->dev);
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;
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;
1843 + /* IP forwarded traffic has a physindev, locally
1844 + * generated traffic hasn't.
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,
1852 + NF_IP_PRI_BRIDGE_SABOTAGE_FORWARD + 1);
1854 +#ifdef CONFIG_NETFILTER_DEBUG
1855 + skb->nf_debug ^= (1 << NF_IP_LOCAL_OUT);
1858 + NF_HOOK_THRESH(PF_INET, NF_IP_LOCAL_OUT, skb, realindev,
1860 + NF_IP_PRI_BRIDGE_SABOTAGE_LOCAL_OUT + 1);
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 *))
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);
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.");
1888 +#ifdef CONFIG_SYSCTL
1893 + if (skb->protocol != __constant_htons(ETH_P_IP) && !IS_VLAN_IP)
1896 + /* Sometimes we get packets with NULL ->dst here (for example,
1897 + * running a dhcp client daemon triggers this).
1899 + if (skb->dst == NULL)
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.
1907 + if (skb->dst == NULL) {
1908 + printk(KERN_CRIT "br_netfilter: skb->dst == NULL.");
1912 + skb->nf_debug ^= (1 << NF_IP_POST_ROUTING);
1915 + /* We assume any code from br_dev_queue_push_xmit onwards doesn't care
1916 + * about the value of skb->pkt_type.
1918 + if (skb->pkt_type == PACKET_OTHERHOST) {
1919 + skb->pkt_type = PACKET_HOST;
1920 + nf_bridge->mask |= BRNF_PKT_TYPE;
1923 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
1924 + skb_pull(skb, VLAN_HLEN);
1925 + skb->nh.raw += VLAN_HLEN;
1928 + nf_bridge_save_header(skb);
1930 +#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
1931 + if (nf_bridge->netoutdev)
1932 + realoutdev = nf_bridge->netoutdev;
1934 + NF_HOOK(PF_INET, NF_IP_POST_ROUTING, skb, NULL,
1935 + realoutdev, br_dev_queue_push_xmit);
1939 +#ifdef CONFIG_NETFILTER_DEBUG
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);
1946 + printk(" head:%p, raw:%p, data:%p\n", skb->head, skb->mac.raw,
1953 +/* IPv4/SABOTAGE *****************************************************/
1955 +/* Don't hand locally destined packets to PF_INET/PRE_ROUTING
1956 + * for the second time.
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 *))
1962 + if ((*pskb)->nf_bridge &&
1963 + !((*pskb)->nf_bridge->mask & BRNF_NF_BRIDGE_PREROUTING)) {
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.
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 *))
1979 + struct sk_buff *skb = *pskb;
1981 +#ifdef CONFIG_SYSCTL
1982 + if (!brnf_call_iptables && !skb->nf_bridge)
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)
1995 + struct nf_bridge_info *nf_bridge;
1997 + if (!skb->nf_bridge && !nf_bridge_alloc(skb))
2000 + nf_bridge = skb->nf_bridge;
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.
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;
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;
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.
2029 +static struct nf_hook_ops br_nf_ops[] = {
2030 + { .hook = br_nf_pre_routing,
2032 + .hooknum = NF_BR_PRE_ROUTING,
2033 + .priority = NF_BR_PRI_BRNF, },
2034 + { .hook = br_nf_local_in,
2036 + .hooknum = NF_BR_LOCAL_IN,
2037 + .priority = NF_BR_PRI_BRNF, },
2038 + { .hook = br_nf_forward_ip,
2040 + .hooknum = NF_BR_FORWARD,
2041 + .priority = NF_BR_PRI_BRNF /*- 1*/, },
2042 +/* { .hook = br_nf_forward_arp,
2044 + .hooknum = NF_BR_FORWARD,
2045 + .priority = NF_BR_PRI_BRNF, },*/
2046 + { .hook = br_nf_local_out,
2048 + .hooknum = NF_BR_LOCAL_OUT,
2049 + .priority = NF_BR_PRI_FIRST, },
2050 + { .hook = br_nf_post_routing,
2052 + .hooknum = NF_BR_POST_ROUTING,
2053 + .priority = NF_BR_PRI_LAST, },
2054 + { .hook = ipv4_sabotage_in,
2056 + .hooknum = NF_IP_PRE_ROUTING,
2057 + .priority = NF_IP_PRI_FIRST, },
2058 + { .hook = ipv4_sabotage_out,
2060 + .hooknum = NF_IP_FORWARD,
2061 + .priority = NF_IP_PRI_BRIDGE_SABOTAGE_FORWARD, },
2062 + { .hook = ipv4_sabotage_out,
2064 + .hooknum = NF_IP_LOCAL_OUT,
2065 + .priority = NF_IP_PRI_BRIDGE_SABOTAGE_LOCAL_OUT, },
2066 + { .hook = ipv4_sabotage_out,
2068 + .hooknum = NF_IP_POST_ROUTING,
2069 + .priority = NF_IP_PRI_FIRST, },
2072 +#ifdef CONFIG_SYSCTL
2074 +int brnf_sysctl_call_tables(ctl_table *ctl, int write, struct file * filp,
2075 + void *buffer, size_t *lenp)
2079 + ret = proc_dointvec(ctl, write, filp, buffer, lenp);
2081 + if (write && *(int *)(ctl->data))
2082 + *(int *)(ctl->data) = 1;
2086 +static ctl_table brnf_table[] = {
2088 + .ctl_name = NET_BRIDGE_NF_CALL_ARPTABLES,
2089 + .procname = "bridge-nf-call-arptables",
2090 + .data = &brnf_call_arptables,
2091 + .maxlen = sizeof(int),
2093 + .proc_handler = &brnf_sysctl_call_tables,
2096 + .ctl_name = NET_BRIDGE_NF_CALL_IPTABLES,
2097 + .procname = "bridge-nf-call-iptables",
2098 + .data = &brnf_call_iptables,
2099 + .maxlen = sizeof(int),
2101 + .proc_handler = &brnf_sysctl_call_tables,
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),
2109 + .proc_handler = &brnf_sysctl_call_tables,
2114 +static ctl_table brnf_bridge_table[] = {
2116 + .ctl_name = NET_BRIDGE,
2117 + .procname = "bridge",
2119 + .child = brnf_table,
2124 +static ctl_table brnf_net_table[] = {
2126 + .ctl_name = CTL_NET,
2127 + .procname = "net",
2129 + .child = brnf_bridge_table,
2135 +int br_netfilter_init(void)
2139 + for (i = 0; i < ARRAY_SIZE(br_nf_ops); i++) {
2142 + if ((ret = nf_register_hook(&br_nf_ops[i])) >= 0)
2146 + nf_unregister_hook(&br_nf_ops[i]);
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]);
2161 + printk(KERN_NOTICE "Bridge firewalling registered\n");
2166 +void br_netfilter_fini(void)
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);
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 @@
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,
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);
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);
2205 +/* br_netfilter.c */
2206 +extern int br_netfilter_init(void);
2207 +extern void br_netfilter_fini(void);
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
2217 +# Bridge netfilter configuration
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
2243 +# Makefile for the netfilter modules on top of bridging.
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).
2249 +# Note 2! The CFLAGS definition is now in the main makefile...
2251 +O_TARGET := netfilter.o
2253 +export-objs := ebtables.o
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
2283 + * Chris Vitale csv@bluetail.com
2289 +#include <linux/netfilter_bridge/ebtables.h>
2290 +#include <linux/netfilter_bridge/ebt_802_3.h>
2291 +#include <linux/module.h>
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)
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;
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;
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;
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)
2321 + struct ebt_802_3_info *info = (struct ebt_802_3_info *)data;
2323 + if (datalen != EBT_ALIGN(sizeof(struct ebt_802_3_info)))
2325 + if (info->bitmask & ~EBT_802_3_MASK || info->invflags & ~EBT_802_3_MASK)
2331 +static struct ebt_match filter_802_3 =
2333 + .name = EBT_802_3_MATCH,
2334 + .match = ebt_filter_802_3,
2335 + .check = ebt_802_3_check,
2336 + .me = THIS_MODULE,
2339 +static int __init init(void)
2341 + return ebt_register_match(&filter_802_3);
2344 +static void __exit fini(void)
2346 + ebt_unregister_match(&filter_802_3);
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
2361 + * Grzegorz Borowiak <grzes@gnu.univ.gda.pl>
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>
2373 +static int ebt_mac_wormhash_contains(const struct ebt_mac_wormhash *wh,
2374 + const char *mac, uint32_t ip)
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.
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];
2386 + memcpy(((char *) cmp) + 2, mac, 6);
2387 + start = wh->table[key];
2388 + limit = wh->table[key + 1];
2390 + for (i = start; i < limit; i++) {
2392 + if (cmp[1] == p->cmp[1] && cmp[0] == p->cmp[0]) {
2393 + if (p->ip == 0 || p->ip == ip) {
2399 + for (i = start; i < limit; i++) {
2401 + if (cmp[1] == p->cmp[1] && cmp[0] == p->cmp[0]) {
2411 +static int ebt_mac_wormhash_check_integrity(const struct ebt_mac_wormhash
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;
2424 + if (wh->table[256] > wh->poolsize)
2429 +static int get_ip_dst(const struct sk_buff *skb, uint32_t * addr)
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));
2438 + /* Make sure the packet is long enough. */
2439 + if ((((*skb).nh.raw) + arp_len) > (*skb).tail)
2441 + /* IPv4 addresses are always 4 bytes. */
2442 + if (((*skb).nh.arph)->ar_pln != sizeof(uint32_t))
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));
2453 +static int get_ip_src(const struct sk_buff *skb, uint32_t * addr)
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));
2462 + /* Make sure the packet is long enough. */
2463 + if ((((*skb).nh.raw) + arp_len) > (*skb).tail)
2465 + /* IPv4 addresses are always 4 bytes. */
2466 + if (((*skb).nh.arph)->ar_pln != sizeof(uint32_t))
2469 + memcpy(addr, ((*skb).nh.raw) + sizeof(struct arphdr) +
2470 + ((((*skb).nh.arph)->ar_hln)), sizeof(uint32_t));
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)
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;
2486 + wh_dst = ebt_among_wh_dst(info);
2487 + wh_src = ebt_among_wh_src(info);
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;
2498 + /* we match only if it DOES NOT contain */
2499 + if (ebt_mac_wormhash_contains(wh_src, smac, sip))
2500 + return EBT_NOMATCH;
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;
2513 + /* we match only if it DOES NOT contain */
2514 + if (ebt_mac_wormhash_contains(wh_dst, dmac, dip))
2515 + return EBT_NOMATCH;
2522 +static int ebt_among_check(const char *tablename, unsigned int hookmask,
2523 + const struct ebt_entry *e, void *data,
2524 + unsigned int datalen)
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;
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);
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));
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);
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);
2557 +static struct ebt_match filter_among = {
2566 +static int __init init(void)
2568 + return ebt_register_match(&filter_among);
2571 +static void __exit fini(void)
2573 + ebt_unregister_match(&filter_among);
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
2588 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
2589 + * Tim Gardner <timg@tpi.com>
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>
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)
2604 + struct ebt_arp_info *info = (struct ebt_arp_info *)data;
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;
2616 + if (info->bitmask & (EBT_ARP_SRC_IP | EBT_ARP_DST_IP))
2618 + uint32_t arp_len = sizeof(struct arphdr) +
2619 + (2 * (((*skb).nh.arph)->ar_hln)) +
2620 + (2 * (((*skb).nh.arph)->ar_pln));
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;
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),
2636 + return EBT_NOMATCH;
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),
2645 + return EBT_NOMATCH;
2649 + if (info->bitmask & (EBT_ARP_SRC_MAC | EBT_ARP_DST_MAC))
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];
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;
2666 + memcpy(&src, ((*skb).nh.raw) +
2667 + sizeof(struct arphdr),
2670 + for (i = 0; i < 6; i++)
2671 + verdict |= (src[i] ^ info->smaddr[i]) &
2673 + if (FWINV(verdict != 0, EBT_ARP_SRC_MAC))
2674 + return EBT_NOMATCH;
2677 + if (info->bitmask & EBT_ARP_DST_MAC) {
2678 + uint8_t verdict, i;
2680 + memcpy(&dst, ((*skb).nh.raw) +
2681 + sizeof(struct arphdr) +
2682 + (((*skb).nh.arph)->ar_hln) +
2683 + (((*skb).nh.arph)->ar_pln),
2686 + for (i = 0; i < 6; i++)
2687 + verdict |= (dst[i] ^ info->dmaddr[i]) &
2689 + if (FWINV(verdict != 0, EBT_ARP_DST_MAC))
2690 + return EBT_NOMATCH;
2697 +static int ebt_arp_check(const char *tablename, unsigned int hookmask,
2698 + const struct ebt_entry *e, void *data, unsigned int datalen)
2700 + struct ebt_arp_info *info = (struct ebt_arp_info *)data;
2702 + if (datalen != EBT_ALIGN(sizeof(struct ebt_arp_info)))
2704 + if ((e->ethproto != __constant_htons(ETH_P_ARP) &&
2705 + e->ethproto != __constant_htons(ETH_P_RARP)) ||
2706 + e->invflags & EBT_IPROTO)
2708 + if (info->bitmask & ~EBT_ARP_MASK || info->invflags & ~EBT_ARP_MASK)
2713 +static struct ebt_match filter_arp =
2715 + {NULL, NULL}, EBT_ARP_MATCH, ebt_filter_arp, ebt_arp_check, NULL,
2719 +static int __init init(void)
2721 + return ebt_register_match(&filter_arp);
2724 +static void __exit fini(void)
2726 + ebt_unregister_match(&filter_arp);
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
2741 + * Grzegorz Borowiak <grzes@gnu.univ.gda.pl>
2742 + * Bart De Schuymer <bdschuym@pandora.be>
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>
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)
2758 + struct ebt_arpreply_info *info = (struct ebt_arpreply_info *)data;
2759 + struct arphdr *ah;
2760 + unsigned char *sha, *arp_ptr;
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) ||
2767 + return EBT_CONTINUE;
2769 + arp_ptr = (unsigned char *)(ah + 1);
2771 + /* get source and target IP */
2773 + arp_ptr += ETH_ALEN;
2774 + memcpy(&sip, arp_ptr, 4);
2775 + arp_ptr += 4 + ETH_ALEN;
2776 + memcpy(&tip, arp_ptr, 4);
2778 + arp_send(ARPOP_REPLY, ETH_P_ARP, sip, in, tip, sha, info->mac, sha);
2780 + return info->target;
2783 +static int ebt_target_reply_check(const char *tablename, unsigned int hookmask,
2784 + const struct ebt_entry *e, void *data, unsigned int datalen)
2786 + struct ebt_arpreply_info *info = (struct ebt_arpreply_info *)data;
2788 + if (datalen != EBT_ALIGN(sizeof(struct ebt_arpreply_info)))
2790 + if (BASE_CHAIN && info->target == EBT_RETURN)
2792 + if (e->ethproto != __constant_htons(ETH_P_ARP) ||
2793 + e->invflags & EBT_IPROTO)
2795 + CLEAR_BASE_CHAIN_BIT;
2796 + if (strcmp(tablename, "nat") || hookmask & ~(1 << NF_BR_PRE_ROUTING))
2801 +static struct ebt_target reply_target =
2803 + .name = EBT_ARPREPLY_TARGET,
2804 + .target = ebt_target_reply,
2805 + .check = ebt_target_reply_check,
2806 + .me = THIS_MODULE,
2809 +static int __init init(void)
2811 + return ebt_register_target(&reply_target);
2814 +static void __exit fini(void)
2816 + ebt_unregister_target(&reply_target);
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
2831 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
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>
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)
2846 + struct ebt_nat_info *info = (struct ebt_nat_info *)data;
2848 + memcpy(((**pskb).mac.ethernet)->h_dest, info->mac,
2849 + ETH_ALEN * sizeof(unsigned char));
2850 + return info->target;
2853 +static int ebt_target_dnat_check(const char *tablename, unsigned int hookmask,
2854 + const struct ebt_entry *e, void *data, unsigned int datalen)
2856 + struct ebt_nat_info *info = (struct ebt_nat_info *)data;
2858 + if (BASE_CHAIN && info->target == EBT_RETURN)
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)) )
2865 + if (datalen != EBT_ALIGN(sizeof(struct ebt_nat_info)))
2867 + if (INVALID_TARGET)
2872 +static struct ebt_target dnat =
2874 + {NULL, NULL}, EBT_DNAT_TARGET, ebt_target_dnat, ebt_target_dnat_check,
2878 +static int __init init(void)
2880 + return ebt_register_target(&dnat);
2883 +static void __exit fini(void)
2885 + ebt_unregister_target(&dnat);
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
2900 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
2905 + * added ip-sport and ip-dport
2906 + * Innominate Security Technologies AG <mhopf@innominate.com>
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>
2922 + unsigned char *raw;
2923 + struct tcpudphdr *tuh;
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)
2930 + struct ebt_ip_info *info = (struct ebt_ip_info *)data;
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,
2938 + return EBT_NOMATCH;
2939 + if ( info->protocol == IPPROTO_TCP ||
2940 + info->protocol == IPPROTO_UDP )
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],
2949 + return EBT_NOMATCH;
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],
2956 + return EBT_NOMATCH;
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;
2971 +static int ebt_ip_check(const char *tablename, unsigned int hookmask,
2972 + const struct ebt_entry *e, void *data, unsigned int datalen)
2974 + struct ebt_ip_info *info = (struct ebt_ip_info *)data;
2976 + if (datalen != EBT_ALIGN(sizeof(struct ebt_ip_info)))
2978 + if (e->ethproto != __constant_htons(ETH_P_IP) ||
2979 + e->invflags & EBT_IPROTO)
2981 + if (info->bitmask & ~EBT_IP_MASK || info->invflags & ~EBT_IP_MASK)
2983 + if (info->bitmask & (EBT_IP_DPORT | EBT_IP_SPORT)) {
2984 + if (!info->bitmask & EBT_IPROTO)
2986 + if (info->protocol != IPPROTO_TCP &&
2987 + info->protocol != IPPROTO_UDP)
2990 + if (info->bitmask & EBT_IP_DPORT && info->dport[0] > info->dport[1])
2992 + if (info->bitmask & EBT_IP_SPORT && info->sport[0] > info->sport[1])
2997 +static struct ebt_match filter_ip =
2999 + {NULL, NULL}, EBT_IP_MATCH, ebt_filter_ip, ebt_ip_check, NULL,
3003 +static int __init init(void)
3005 + return ebt_register_match(&filter_ip);
3008 +static void __exit fini(void)
3010 + ebt_unregister_match(&filter_ip);
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
3025 + * Tom Marshall <tommy@home.tig-grr.com>
3027 + * Mostly copied from netfilter's ipt_limit.c, see that file for explanation
3033 +#include <linux/netfilter_bridge/ebtables.h>
3034 +#include <linux/netfilter_bridge/ebt_limit.h>
3035 +#include <linux/module.h>
3037 +#include <linux/netdevice.h>
3038 +#include <linux/spinlock.h>
3040 +static spinlock_t limit_lock = SPIN_LOCK_UNLOCKED;
3042 +#define CREDITS_PER_JIFFY 128
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)
3047 + struct ebt_limit_info *info = (struct ebt_limit_info *)data;
3048 + unsigned long now = jiffies;
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;
3055 + if (info->credit >= info->cost) {
3056 + /* We're not limited. */
3057 + info->credit -= info->cost;
3058 + spin_unlock_bh(&limit_lock);
3062 + spin_unlock_bh(&limit_lock);
3063 + return EBT_NOMATCH;
3066 +/* Precision saver. */
3068 +user2credits(u_int32_t user)
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;
3075 + return (user * HZ * CREDITS_PER_JIFFY) / EBT_LIMIT_SCALE;
3078 +static int ebt_limit_check(const char *tablename, unsigned int hookmask,
3079 + const struct ebt_entry *e, void *data, unsigned int datalen)
3081 + struct ebt_limit_info *info = (struct ebt_limit_info *)data;
3083 + if (datalen != EBT_ALIGN(sizeof(struct ebt_limit_info)))
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);
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);
3102 +static struct ebt_match ebt_limit_reg =
3104 + {NULL, NULL}, EBT_LIMIT_MATCH, ebt_limit_match, ebt_limit_check, NULL,
3108 +static int __init init(void)
3110 + return ebt_register_match(&ebt_limit_reg);
3113 +static void __exit fini(void)
3115 + ebt_unregister_match(&ebt_limit_reg);
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
3130 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
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>
3144 +static spinlock_t ebt_log_lock = SPIN_LOCK_UNLOCKED;
3146 +static int ebt_log_check(const char *tablename, unsigned int hookmask,
3147 + const struct ebt_entry *e, void *data, unsigned int datalen)
3149 + struct ebt_log_info *info = (struct ebt_log_info *)data;
3151 + if (datalen != EBT_ALIGN(sizeof(struct ebt_log_info)))
3153 + if (info->bitmask & ~EBT_LOG_MASK)
3155 + if (info->loglevel >= 8)
3157 + info->prefix[EBT_LOG_PREFIX_SIZE - 1] = '\0';
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];
3175 +static void print_MAC(unsigned char *p)
3179 + for (i = 0; i < ETH_ALEN; i++, p++)
3180 + printk("%02x%c", *p, i == ETH_ALEN - 1 ? ' ':':');
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)
3187 + struct ebt_log_info *info = (struct ebt_log_info *)data;
3188 + char level_string[4] = "< >";
3189 + level_string[1] = '0' + info->loglevel;
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 : "");
3196 + printk("MAC source = ");
3197 + print_MAC((skb->mac.ethernet)->h_source);
3198 + printk("MAC dest = ");
3199 + print_MAC((skb->mac.ethernet)->h_dest);
3201 + printk("proto = 0x%04x", ntohs(((*skb).mac.ethernet)->h_proto));
3203 + if ((info->bitmask & EBT_LOG_IP) && skb->mac.ethernet->h_proto ==
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);
3213 + if (skb->data + iph->ihl*4 > skb->tail) {
3214 + printk(" INCOMPLETE TCP/UDP header");
3217 + printk(" SPT=%u DPT=%u", ntohs(ports->src),
3218 + ntohs(ports->dst));
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));
3237 + if (skb->data + sizeof(*arph) > skb->tail) {
3238 + printk(" INCOMPLETE ARP header");
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));
3255 + spin_unlock_bh(&ebt_log_lock);
3258 +static struct ebt_watcher log =
3260 + {NULL, NULL}, EBT_LOG_WATCHER, ebt_log, ebt_log_check, NULL,
3264 +static int __init init(void)
3266 + return ebt_register_watcher(&log);
3269 +static void __exit fini(void)
3271 + ebt_unregister_watcher(&log);
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
3286 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
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
3296 +#include <linux/netfilter_bridge/ebtables.h>
3297 +#include <linux/netfilter_bridge/ebt_mark_t.h>
3298 +#include <linux/module.h>
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)
3304 + struct ebt_mark_t_info *info = (struct ebt_mark_t_info *)data;
3306 + if ((*pskb)->nfmark != info->mark) {
3307 + (*pskb)->nfmark = info->mark;
3308 + (*pskb)->nfcache |= NFC_ALTERED;
3310 + return info->target;
3313 +static int ebt_target_mark_check(const char *tablename, unsigned int hookmask,
3314 + const struct ebt_entry *e, void *data, unsigned int datalen)
3316 + struct ebt_mark_t_info *info = (struct ebt_mark_t_info *)data;
3318 + if (datalen != EBT_ALIGN(sizeof(struct ebt_mark_t_info)))
3320 + if (BASE_CHAIN && info->target == EBT_RETURN)
3322 + CLEAR_BASE_CHAIN_BIT;
3323 + if (INVALID_TARGET)
3328 +static struct ebt_target mark_target =
3330 + {NULL, NULL}, EBT_MARK_TARGET, ebt_target_mark,
3331 + ebt_target_mark_check, NULL, THIS_MODULE
3334 +static int __init init(void)
3336 + return ebt_register_target(&mark_target);
3339 +static void __exit fini(void)
3341 + ebt_unregister_target(&mark_target);
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
3356 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
3362 +#include <linux/netfilter_bridge/ebtables.h>
3363 +#include <linux/netfilter_bridge/ebt_mark_m.h>
3364 +#include <linux/module.h>
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)
3370 + struct ebt_mark_m_info *info = (struct ebt_mark_m_info *) data;
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);
3377 +static int ebt_mark_check(const char *tablename, unsigned int hookmask,
3378 + const struct ebt_entry *e, void *data, unsigned int datalen)
3380 + struct ebt_mark_m_info *info = (struct ebt_mark_m_info *) data;
3382 + if (datalen != EBT_ALIGN(sizeof(struct ebt_mark_m_info)))
3384 + if (info->bitmask & ~EBT_MARK_MASK)
3386 + if ((info->bitmask & EBT_MARK_OR) && (info->bitmask & EBT_MARK_AND))
3388 + if (!info->bitmask)
3393 +static struct ebt_match filter_mark =
3395 + {NULL, NULL}, EBT_MARK_MATCH, ebt_filter_mark, ebt_mark_check, NULL,
3399 +static int __init init(void)
3401 + return ebt_register_match(&filter_mark);
3404 +static void __exit fini(void)
3406 + ebt_unregister_match(&filter_mark);
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
3421 + * Bart De Schuymer <bdschuym@pandora.be>
3427 +#include <linux/netfilter_bridge/ebtables.h>
3428 +#include <linux/netfilter_bridge/ebt_pkttype.h>
3429 +#include <linux/module.h>
3431 +static int ebt_filter_pkttype(const struct sk_buff *skb,
3432 + const struct net_device *in,
3433 + const struct net_device *out,
3435 + unsigned int datalen)
3437 + struct ebt_pkttype_info *info = (struct ebt_pkttype_info *)data;
3439 + return (skb->pkt_type != info->pkt_type) ^ info->invert;
3442 +static int ebt_pkttype_check(const char *tablename, unsigned int hookmask,
3443 + const struct ebt_entry *e, void *data, unsigned int datalen)
3445 + struct ebt_pkttype_info *info = (struct ebt_pkttype_info *)data;
3447 + if (datalen != EBT_ALIGN(sizeof(struct ebt_pkttype_info)))
3449 + if (info->invert != 0 && info->invert != 1)
3451 + /* Allow any pkt_type value */
3455 +static struct ebt_match filter_pkttype =
3457 + .name = EBT_PKTTYPE_MATCH,
3458 + .match = ebt_filter_pkttype,
3459 + .check = ebt_pkttype_check,
3460 + .me = THIS_MODULE,
3463 +static int __init init(void)
3465 + return ebt_register_match(&filter_pkttype);
3468 +static void __exit fini(void)
3470 + ebt_unregister_match(&filter_pkttype);
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
3485 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
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"
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)
3501 + struct ebt_redirect_info *info = (struct ebt_redirect_info *)data;
3503 + if (hooknr != NF_BR_BROUTING)
3504 + memcpy((**pskb).mac.ethernet->h_dest,
3505 + in->br_port->br->dev.dev_addr, ETH_ALEN);
3507 + memcpy((**pskb).mac.ethernet->h_dest,
3508 + in->dev_addr, ETH_ALEN);
3509 + (*pskb)->pkt_type = PACKET_HOST;
3511 + return info->target;
3514 +static int ebt_target_redirect_check(const char *tablename, unsigned int hookmask,
3515 + const struct ebt_entry *e, void *data, unsigned int datalen)
3517 + struct ebt_redirect_info *info = (struct ebt_redirect_info *)data;
3519 + if (datalen != EBT_ALIGN(sizeof(struct ebt_redirect_info)))
3521 + if (BASE_CHAIN && info->target == EBT_RETURN)
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)) )
3527 + if (INVALID_TARGET)
3532 +static struct ebt_target redirect_target =
3534 + {NULL, NULL}, EBT_REDIRECT_TARGET, ebt_target_redirect,
3535 + ebt_target_redirect_check, NULL, THIS_MODULE
3538 +static int __init init(void)
3540 + return ebt_register_target(&redirect_target);
3543 +static void __exit fini(void)
3545 + ebt_unregister_target(&redirect_target);
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
3560 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
3566 +#include <linux/netfilter_bridge/ebtables.h>
3567 +#include <linux/netfilter_bridge/ebt_nat.h>
3568 +#include <linux/module.h>
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)
3574 + struct ebt_nat_info *info = (struct ebt_nat_info *) data;
3576 + memcpy(((**pskb).mac.ethernet)->h_source, info->mac,
3577 + ETH_ALEN * sizeof(unsigned char));
3578 + return info->target;
3581 +static int ebt_target_snat_check(const char *tablename, unsigned int hookmask,
3582 + const struct ebt_entry *e, void *data, unsigned int datalen)
3584 + struct ebt_nat_info *info = (struct ebt_nat_info *) data;
3586 + if (datalen != EBT_ALIGN(sizeof(struct ebt_nat_info)))
3588 + if (BASE_CHAIN && info->target == EBT_RETURN)
3590 + CLEAR_BASE_CHAIN_BIT;
3591 + if (strcmp(tablename, "nat"))
3593 + if (hookmask & ~(1 << NF_BR_POST_ROUTING))
3595 + if (INVALID_TARGET)
3600 +static struct ebt_target snat =
3602 + {NULL, NULL}, EBT_SNAT_TARGET, ebt_target_snat, ebt_target_snat_check,
3606 +static int __init init(void)
3608 + return ebt_register_target(&snat);
3611 +static void __exit fini(void)
3613 + ebt_unregister_target(&snat);
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
3628 + * Bart De Schuymer <bdschuym@pandora.be>
3629 + * Stephen Hemminger <shemminger@osdl.org>
3634 +#include <linux/netfilter_bridge/ebtables.h>
3635 +#include <linux/netfilter_bridge/ebt_stp.h>
3636 +#include <linux/module.h>
3638 +#define BPDU_TYPE_CONFIG 0
3639 +#define BPDU_TYPE_TCN 0x80
3641 +struct stp_header {
3650 +struct stp_config_pdu {
3653 + uint8_t root_cost[4];
3654 + uint8_t sender[8];
3656 + uint8_t msg_age[2];
3657 + uint8_t max_age[2];
3658 + uint8_t hello_time[2];
3659 + uint8_t forward_delay[2];
3662 +#define NR16(p) (p[0] << 8 | p[1])
3663 +#define NR32(p) ((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3])
3665 +static int ebt_filter_config(struct ebt_stp_info *info,
3666 + struct stp_config_pdu *stpc)
3668 + struct ebt_stp_config_info *c;
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;
3683 + if (info->bitmask & EBT_STP_ROOTADDR) {
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;
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;
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;
3703 + if (info->bitmask & EBT_STP_SENDERADDR) {
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;
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;
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;
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;
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;
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;
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)
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;
3753 + /* The stp code only considers these */
3754 + if (memcmp(&stph, header, sizeof(header)))
3755 + return EBT_NOMATCH;
3757 + if (info->bitmask & EBT_STP_TYPE
3758 + && FWINV(info->type != stph.type, EBT_STP_TYPE))
3759 + return EBT_NOMATCH;
3761 + if (stph.type == BPDU_TYPE_CONFIG &&
3762 + info->bitmask & EBT_STP_CONFIG_MASK) {
3763 + struct stp_config_pdu stpc;
3765 + if (skb_copy_bits(skb, sizeof(stph), &stpc, sizeof(stpc)))
3766 + return EBT_NOMATCH;
3767 + return ebt_filter_config(info, &stpc);
3772 +static int ebt_stp_check(const char *tablename, unsigned int hookmask,
3773 + const struct ebt_entry *e, void *data, unsigned int datalen)
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 };
3780 + if (info->bitmask & ~EBT_STP_MASK || info->invflags & ~EBT_STP_MASK ||
3781 + !(info->bitmask & EBT_STP_MASK))
3783 + if (datalen != len)
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))
3793 +static struct ebt_match filter_stp =
3795 + .name = EBT_STP_MATCH,
3796 + .match = ebt_filter_stp,
3797 + .check = ebt_stp_check,
3798 + .me = THIS_MODULE,
3801 +static int __init init(void)
3803 + return ebt_register_match(&filter_stp);
3806 +static void __exit fini(void)
3808 + ebt_unregister_match(&filter_stp);
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
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>
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.
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.
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
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>
3845 +static unsigned char debug;
3846 +#define MODULE_VERSION "0.6"
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"
3853 +MODULE_LICENSE("GPL");
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;
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.
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)
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)
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 */
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 */
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.
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;
3908 + * Checking VLAN Identifier (VID)
3910 + if (GET_BITMASK(EBT_VLAN_ID)) { /* Is VLAN ID parsed? */
3911 + EXIT_ON_MISMATCH(id, EBT_VLAN_ID);
3914 + * Checking user_priority
3916 + if (GET_BITMASK(EBT_VLAN_PRIO)) { /* Is VLAN user_priority parsed? */
3917 + EXIT_ON_MISMATCH(prio, EBT_VLAN_PRIO);
3920 + * Checking Encapsulated Proto (Length/Type) field
3922 + if (GET_BITMASK(EBT_VLAN_ENCAP)) { /* Is VLAN Encap parsed? */
3923 + EXIT_ON_MISMATCH(encap, EBT_VLAN_ENCAP);
3926 + * All possible extension parameters was parsed.
3927 + * If rule never returned by missmatch, then all ok.
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.
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.)
3947 +ebt_check_vlan(const char *tablename,
3948 + unsigned int hooknr,
3949 + const struct ebt_entry *e, void *data, unsigned int datalen)
3951 + struct ebt_vlan_info *info = (struct ebt_vlan_info *) data;
3954 + * Parameters buffer overflow check
3956 + if (datalen != EBT_ALIGN(sizeof(struct ebt_vlan_info))) {
3958 + ("passed size %d is not eq to ebt_vlan_info (%d)\n",
3959 + datalen, sizeof(struct ebt_vlan_info));
3964 + * Is it 802.1Q frame checked?
3966 + if (e->ethproto != __constant_htons(ETH_P_8021Q)) {
3968 + ("passed entry proto %2.4X is not 802.1Q (8100)\n",
3969 + (unsigned short) ntohs(e->ethproto));
3974 + * Check for bitmask range
3975 + * True if even one bit is out of mask
3977 + if (info->bitmask & ~EBT_VLAN_MASK) {
3978 + DEBUG_MSG("bitmask %2X is out of mask (%2X)\n",
3979 + info->bitmask, EBT_VLAN_MASK);
3984 + * Check for inversion flags range
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);
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.
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) {
4004 + ("id %d is out of range (1-4096)\n",
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.
4014 + info->bitmask &= ~EBT_VLAN_PRIO;
4017 + * Else, id=0 (null VLAN ID) => user_priority range (any?)
4021 + if (GET_BITMASK(EBT_VLAN_PRIO)) {
4022 + if ((unsigned char) info->prio > 7) {
4024 + ("prio %d is out of range (0-7)\n",
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
4034 + if (GET_BITMASK(EBT_VLAN_ENCAP)) {
4035 + if ((unsigned short) ntohs(info->encap) < ETH_ZLEN) {
4037 + ("encap frame length %d is less than minimal\n",
4038 + ntohs(info->encap));
4046 +static struct ebt_match filter_vlan = {
4056 + * Module initialization function.
4058 +static int __init init(void)
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);
4067 + * Module "finalization" function
4069 +static void __exit fini(void)
4071 + ebt_unregister_match(&filter_vlan);
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
4086 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
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.
4095 +#include <linux/netfilter_bridge/ebtables.h>
4096 +#include <linux/module.h>
4097 +#include <linux/if_bridge.h>
4098 +#include <linux/brlock.h>
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};
4105 +static struct ebt_replace initial_table =
4107 + "broute", 1 << NF_BR_BROUTING, 0, sizeof(struct ebt_entries),
4108 + { [NF_BR_BROUTING]&initial_chain}, 0, NULL, (char *)&initial_chain
4111 +static int check(const struct ebt_table_info *info, unsigned int valid_hooks)
4113 + if (valid_hooks & ~(1 << NF_BR_BROUTING))
4118 +static struct ebt_table broute_table =
4120 + {NULL, NULL}, "broute", &initial_table, 1 << NF_BR_BROUTING,
4121 + RW_LOCK_UNLOCKED, check, NULL
4124 +static int ebt_broute(struct sk_buff **pskb)
4128 + ret = ebt_do_table(NF_BR_BROUTING, pskb, (*pskb)->dev, NULL,
4130 + if (ret == NF_DROP)
4131 + return 1; // route it
4132 + return 0; // bridge it
4135 +static int __init init(void)
4139 + ret = ebt_register_table(&broute_table);
4142 + br_write_lock_bh(BR_NETPROTO_LOCK);
4144 + br_should_route_hook = ebt_broute;
4145 + br_write_unlock_bh(BR_NETPROTO_LOCK);
4149 +static void __exit fini(void)
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);
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
4169 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
4175 +#include <linux/netfilter_bridge/ebtables.h>
4176 +#include <linux/module.h>
4178 +#define FILTER_VALID_HOOKS ((1 << NF_BR_LOCAL_IN) | (1 << NF_BR_FORWARD) | \
4179 + (1 << NF_BR_LOCAL_OUT))
4181 +static struct ebt_entries initial_chains[] =
4183 + {0, "INPUT", 0, EBT_ACCEPT, 0},
4184 + {0, "FORWARD", 0, EBT_ACCEPT, 0},
4185 + {0, "OUTPUT", 0, EBT_ACCEPT, 0}
4188 +static struct ebt_replace initial_table =
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
4195 +static int check(const struct ebt_table_info *info, unsigned int valid_hooks)
4197 + if (valid_hooks & ~FILTER_VALID_HOOKS)
4202 +static struct ebt_table frame_filter =
4204 + {NULL, NULL}, "filter", &initial_table, FILTER_VALID_HOOKS,
4205 + RW_LOCK_UNLOCKED, check, NULL
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 *))
4212 + return ebt_do_table(hook, pskb, in, out, &frame_filter);
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}
4224 +static int __init init(void)
4228 + ret = ebt_register_table(&frame_filter);
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)
4236 + for (j = 0; j < i; j++)
4237 + nf_unregister_hook(&ebt_ops_filter[j]);
4238 + ebt_unregister_table(&frame_filter);
4242 +static void __exit fini(void)
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);
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
4263 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
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))
4274 +static struct ebt_entries initial_chains[] =
4276 + {0, "PREROUTING", 0, EBT_ACCEPT, 0},
4277 + {0, "OUTPUT", 0, EBT_ACCEPT, 0},
4278 + {0, "POSTROUTING", 0, EBT_ACCEPT, 0}
4281 +static struct ebt_replace initial_table =
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
4288 +static int check(const struct ebt_table_info *info, unsigned int valid_hooks)
4290 + if (valid_hooks & ~NAT_VALID_HOOKS)
4295 +static struct ebt_table frame_nat =
4297 + {NULL, NULL}, "nat", &initial_table, NAT_VALID_HOOKS,
4298 + RW_LOCK_UNLOCKED, check, NULL
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 *))
4305 + return ebt_do_table(hook, pskb, in, out, &frame_nat);
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 *))
4312 + return ebt_do_table(hook, pskb, in, out, &frame_nat);
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},
4324 +static int __init init(void)
4328 + ret = ebt_register_table(&frame_nat);
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)
4336 + for (j = 0; j < i; j++)
4337 + nf_unregister_hook(&ebt_ops_nat[j]);
4338 + ebt_unregister_table(&frame_nat);
4342 +static void __exit fini(void)
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);
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
4363 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
4365 + * ebtables.c,v 2.0, July, 2002
4367 + * This code is stongly inspired on the iptables code which is
4368 + * Copyright (C) 1999 Paul `Rusty' Russell & Michael J. Neuling
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.
4376 +// used for print_string
4377 +#include <linux/sched.h>
4378 +#include <linux/tty.h>
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"
4392 +#define ASSERT_READ_LOCK(x)
4393 +#define ASSERT_WRITE_LOCK(x)
4394 +#include <linux/netfilter_ipv4/listhelp.h>
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)
4402 + struct tty_struct *my_tty;
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);
4412 +#define BUGPRINT(args) print_string(args);
4414 +#define BUGPRINT(format, args...) printk("kernel msg: ebtables bug: please "\
4415 + "report to author: "format, ## args)
4416 +// #define BUGPRINT(format, args...)
4418 +#define MEMPRINT(format, args...) printk("kernel msg: ebtables "\
4419 + ": out of memory: "format, ## args)
4420 +// #define MEMPRINT(format, args...)
4424 +// Each cpu has its own set of counters, so there is no need for write_lock in
4426 +// For reading or updating the counters, the user context needs to
4427 +// get a write_lock
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))
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);
4443 +static struct ebt_target ebt_standard_target =
4444 +{ {NULL, NULL}, EBT_STANDARD_TARGET, NULL, NULL, NULL, NULL};
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)
4450 + w->u.watcher->watcher(skb, in, out, w->data,
4452 + // watchers don't give a verdict
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)
4460 + return m->u.match->match(skb, in, out, m->data,
4464 +static inline int ebt_dev_check(char *entry, const struct net_device *device)
4466 + if (*entry == '\0')
4470 + return !!strcmp(entry, device->name);
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)
4480 + if (e->bitmask & EBT_802_3) {
4481 + if (FWINV2(ntohs(h->h_proto) >= 1536, EBT_IPROTO))
4483 + } else if (!(e->bitmask & EBT_NOPROTO) &&
4484 + FWINV2(e->ethproto != h->h_proto, EBT_IPROTO))
4487 + if (FWINV2(ebt_dev_check(e->in, in), EBT_IIN))
4489 + if (FWINV2(ebt_dev_check(e->out, out), EBT_IOUT))
4491 + if ((!in || !in->br_port) ? 0 : FWINV2(ebt_dev_check(
4492 + e->logical_in, &in->br_port->br->dev), EBT_ILOGICALIN))
4494 + if ((!out || !out->br_port) ? 0 : FWINV2(ebt_dev_check(
4495 + e->logical_out, &out->br_port->br->dev), EBT_ILOGICALOUT))
4498 + if (e->bitmask & EBT_SOURCEMAC) {
4500 + for (i = 0; i < 6; i++)
4501 + verdict |= (h->h_source[i] ^ e->sourcemac[i]) &
4503 + if (FWINV2(verdict != 0, EBT_ISOURCE) )
4506 + if (e->bitmask & EBT_DESTMAC) {
4508 + for (i = 0; i < 6; i++)
4509 + verdict |= (h->h_dest[i] ^ e->destmac[i]) &
4511 + if (FWINV2(verdict != 0, EBT_IDEST) )
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)
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;
4530 + struct ebt_table_info *private = table->private;
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())];
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;
4546 + while (i < nentries) {
4547 + if (ebt_basic_match(point, (**pskb).mac.ethernet, in, out))
4548 + goto letscontinue;
4550 + if (EBT_MATCH_ITERATE(point, ebt_do_match, *pskb, in, out) != 0)
4551 + goto letscontinue;
4553 + // increase counter
4554 + (*(counter_base + i)).pcnt++;
4555 + (*(counter_base + i)).bcnt+=(**pskb).len;
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,
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;
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);
4574 + if (verdict == EBT_DROP) {
4575 + read_unlock_bh(&table->lock);
4578 + if (verdict == EBT_RETURN) {
4580 +#ifdef CONFIG_NETFILTER_DEBUG
4582 + BUGPRINT("RETURN on base chain");
4583 + // act like this is EBT_CONTINUE
4584 + goto letscontinue;
4588 + // put all the local variables right
4590 + chaininfo = cs[sp].chaininfo;
4591 + nentries = chaininfo->nentries;
4593 + counter_base = cb_base +
4594 + chaininfo->counter_offset;
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);
4608 + cs[sp].chaininfo = chaininfo;
4609 + cs[sp].e = (struct ebt_entry *)
4610 + (((char *)point) + point->next_offset);
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);
4620 + nentries = chaininfo->nentries;
4621 + point = (struct ebt_entry *)chaininfo->data;
4622 + counter_base = cb_base + chaininfo->counter_offset;
4626 + point = (struct ebt_entry *)
4627 + (((char *)point) + point->next_offset);
4631 + // I actually like this :)
4632 + if (chaininfo->policy == EBT_RETURN)
4634 + if (chaininfo->policy == EBT_ACCEPT) {
4635 + read_unlock_bh(&table->lock);
4638 + read_unlock_bh(&table->lock);
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)
4649 + *error = down_interruptible(mutex);
4653 + ret = list_named_find(head, name);
4661 +#ifndef CONFIG_KMOD
4662 +#define find_inlist_lock(h,n,p,e,m) find_inlist_lock_noload((h),(n),(e),(m))
4665 +find_inlist_lock(struct list_head *head, const char *name, const char *prefix,
4666 + int *error, struct semaphore *mutex)
4670 + ret = find_inlist_lock_noload(head, name, error, mutex);
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);
4682 +static inline struct ebt_table *
4683 +find_table_lock(const char *name, int *error, struct semaphore *mutex)
4685 + return find_inlist_lock(&ebt_tables, name, "ebtable_", error, mutex);
4688 +static inline struct ebt_match *
4689 +find_match_lock(const char *name, int *error, struct semaphore *mutex)
4691 + return find_inlist_lock(&ebt_matches, name, "ebt_", error, mutex);
4694 +static inline struct ebt_watcher *
4695 +find_watcher_lock(const char *name, int *error, struct semaphore *mutex)
4697 + return find_inlist_lock(&ebt_watchers, name, "ebt_", error, mutex);
4700 +static inline struct ebt_target *
4701 +find_target_lock(const char *name, int *error, struct semaphore *mutex)
4703 + return find_inlist_lock(&ebt_targets, name, "ebt_", error, mutex);
4707 +ebt_check_match(struct ebt_entry_match *m, struct ebt_entry *e,
4708 + const char *name, unsigned int hookmask, unsigned int *cnt)
4710 + struct ebt_match *match;
4713 + if (((char *)m) + m->match_size + sizeof(struct ebt_entry_match) >
4714 + ((char *)e) + e->watchers_offset)
4716 + match = find_match_lock(m->u.name, &ret, &ebt_mutex);
4719 + m->u.match = match;
4721 + __MOD_INC_USE_COUNT(match->me);
4723 + if (match->check &&
4724 + match->check(name, hookmask, e, m->data, m->match_size) != 0) {
4725 + BUGPRINT("match->check failed\n");
4727 + __MOD_DEC_USE_COUNT(match->me);
4735 +ebt_check_watcher(struct ebt_entry_watcher *w, struct ebt_entry *e,
4736 + const char *name, unsigned int hookmask, unsigned int *cnt)
4738 + struct ebt_watcher *watcher;
4741 + if (((char *)w) + w->watcher_size + sizeof(struct ebt_entry_watcher) >
4742 + ((char *)e) + e->target_offset)
4744 + watcher = find_watcher_lock(w->u.name, &ret, &ebt_mutex);
4747 + w->u.watcher = watcher;
4749 + __MOD_INC_USE_COUNT(watcher->me);
4751 + if (watcher->check &&
4752 + watcher->check(name, hookmask, e, w->data, w->watcher_size) != 0) {
4753 + BUGPRINT("watcher->check failed\n");
4755 + __MOD_DEC_USE_COUNT(watcher->me);
4762 +// this one is very careful, as it is the first function
4763 +// to parse the userspace data
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)
4772 + for (i = 0; i < NF_BR_NUMHOOKS; i++) {
4773 + if ((valid_hooks & (1 << i)) == 0)
4775 + if ( (char *)hook_entries[i] - base ==
4776 + (char *)e - newinfo->entries)
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");
4789 + // this checks if the previous chain has as many entries
4790 + // as it said it has
4792 + BUGPRINT("nentries does not equal the nr of entries "
4793 + "in the chain\n");
4796 + // before we look at the struct, be sure it is not too big
4797 + if ((char *)hook_entries[i] + sizeof(struct ebt_entries)
4799 + BUGPRINT("entries_size too small\n");
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");
4811 + if (i == NF_BR_NUMHOOKS) // it's a user defined chain
4814 + newinfo->hook_entry[i] = (struct ebt_entries *)e;
4815 + if (((struct ebt_entries *)e)->counter_offset != *totalcnt) {
4816 + BUGPRINT("counter_offset != totalcnt");
4819 + *n = ((struct ebt_entries *)e)->nentries;
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");
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");
4841 +struct ebt_cl_stack
4843 + struct ebt_chainstack cs;
4845 + unsigned int hookmask;
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.
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)
4857 + // we're only interested in chain starts
4858 + if (e->bitmask & EBT_ENTRY_OR_ENTRIES)
4860 + for (i = 0; i < NF_BR_NUMHOOKS; i++) {
4861 + if ((valid_hooks & (1 << i)) == 0)
4863 + if (newinfo->hook_entry[i] == (struct ebt_entries *)e)
4866 + // only care about udc
4867 + if (i != NF_BR_NUMHOOKS)
4870 + udc[*n].cs.chaininfo = (struct ebt_entries *)e;
4871 + // these initialisations are depended on later in check_chainloops()
4873 + udc[*n].hookmask = 0;
4880 +ebt_cleanup_match(struct ebt_entry_match *m, unsigned int *i)
4882 + if (i && (*i)-- == 0)
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);
4893 +ebt_cleanup_watcher(struct ebt_entry_watcher *w, unsigned int *i)
4895 + if (i && (*i)-- == 0)
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);
4906 +ebt_cleanup_entry(struct ebt_entry *e, unsigned int *cnt)
4908 + struct ebt_entry_target *t;
4910 + if ((e->bitmask & EBT_ENTRY_OR_ENTRIES) == 0)
4913 + if (cnt && (*cnt)-- == 0)
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);
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)
4931 + struct ebt_entry_target *t;
4932 + struct ebt_target *target;
4933 + unsigned int i, j, hook = 0, hookmask = 0;
4936 + // Don't mess with the struct ebt_entries
4937 + if ((e->bitmask & EBT_ENTRY_OR_ENTRIES) == 0)
4940 + if (e->bitmask & ~EBT_F_MASK) {
4941 + BUGPRINT("Unknown flag for bitmask\n");
4944 + if (e->invflags & ~EBT_INV_MASK) {
4945 + BUGPRINT("Unknown flag for inv bitmask\n");
4948 + if ( (e->bitmask & EBT_NOPROTO) && (e->bitmask & EBT_802_3) ) {
4949 + BUGPRINT("NOPROTO & 802_3 not allowed\n");
4952 + // what hook do we belong to?
4953 + for (i = 0; i < NF_BR_NUMHOOKS; i++) {
4954 + if ((valid_hooks & (1 << i)) == 0)
4956 + if ((char *)newinfo->hook_entry[i] < (char *)e)
4961 + // (1 << NF_BR_NUMHOOKS) tells the check functions the rule is on
4963 + if (i < NF_BR_NUMHOOKS)
4964 + hookmask = (1 << hook) | (1 << NF_BR_NUMHOOKS);
4966 + for (i = 0; i < udc_cnt; i++)
4967 + if ((char *)(cl_s[i].cs.chaininfo) > (char *)e)
4970 + hookmask = (1 << hook) | (1 << NF_BR_NUMHOOKS);
4972 + hookmask = cl_s[i - 1].hookmask;
4975 + ret = EBT_MATCH_ITERATE(e, ebt_check_match, e, name, hookmask, &i);
4977 + goto cleanup_matches;
4979 + ret = EBT_WATCHER_ITERATE(e, ebt_check_watcher, e, name, hookmask, &j);
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);
4985 + goto cleanup_watchers;
4987 + __MOD_INC_USE_COUNT(target->me);
4990 + t->u.target = target;
4991 + if (t->u.target == &ebt_standard_target) {
4992 + if (e->target_offset + sizeof(struct ebt_standard_target) >
4994 + BUGPRINT("Standard target size too big\n");
4996 + goto cleanup_watchers;
4998 + if (((struct ebt_standard_target *)t)->verdict <
4999 + -NUM_STANDARD_TARGETS) {
5000 + BUGPRINT("Invalid standard target\n");
5002 + goto cleanup_watchers;
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);
5011 + goto cleanup_watchers;
5016 + EBT_WATCHER_ITERATE(e, ebt_cleanup_watcher, &j);
5018 + EBT_MATCH_ITERATE(e, ebt_cleanup_match, &i);
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)
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;
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)
5040 + cl_s[cl_s[chain_nr].from].cs.chaininfo->nentries;
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)
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) >
5056 + BUGPRINT("Standard target size too big\n");
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)
5066 + // bad destination or loop
5067 + if (i == udc_cnt) {
5068 + BUGPRINT("bad destination\n");
5071 + if (cl_s[i].cs.n) {
5072 + BUGPRINT("loop\n");
5075 + // this can't be 0, so the above test is correct
5076 + cl_s[i].cs.n = pos + 1;
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;
5083 + // this udc is accessible from the base chain for hooknr
5084 + cl_s[i].hookmask |= (1 << hooknr);
5088 + e = (void *)e + e->next_offset;
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)
5098 + unsigned int i, j, k, udc_cnt;
5100 + struct ebt_cl_stack *cl_s = NULL; // used in the checking for chain loops
5103 + while (i < NF_BR_NUMHOOKS && !(repl->valid_hooks & (1 << i)))
5105 + if (i == NF_BR_NUMHOOKS) {
5106 + BUGPRINT("No valid hooks specified\n");
5109 + if (repl->hook_entry[i] != (struct ebt_entries *)repl->entries) {
5110 + BUGPRINT("Chains don't start at beginning\n");
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)))
5118 + if ( repl->hook_entry[j] <= repl->hook_entry[i] ) {
5119 + BUGPRINT("Hook order must be followed\n");
5125 + for (i = 0; i < NF_BR_NUMHOOKS; i++)
5126 + newinfo->hook_entry[i] = NULL;
5128 + newinfo->entries_size = repl->entries_size;
5129 + newinfo->nentries = repl->nentries;
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);
5146 + BUGPRINT("nentries does not equal the nr of entries in the "
5147 + "(last) chain\n");
5150 + if (k != newinfo->nentries) {
5151 + BUGPRINT("Total nentries is wrong\n");
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");
5164 + // Get the location of the udc, put them in an array
5165 + // While we're at it, allocate the chainstack
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)
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]) {
5178 + vfree(newinfo->chainstack[--i]);
5179 + vfree(newinfo->chainstack);
5180 + newinfo->chainstack = NULL;
5185 + cl_s = (struct ebt_cl_stack *)
5186 + vmalloc(udc_cnt * sizeof(struct ebt_cl_stack));
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);
5194 + if (i != udc_cnt) {
5195 + BUGPRINT("i != udc_cnt\n");
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)) {
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.
5221 + // used to know what we need to clean up if something goes wrong
5223 + ret = EBT_ENTRY_ITERATE(newinfo->entries, newinfo->entries_size,
5224 + ebt_check_entry, newinfo, repl->name, &i, repl->valid_hooks,
5227 + EBT_ENTRY_ITERATE(newinfo->entries, newinfo->entries_size,
5228 + ebt_cleanup_entry, &i);
5235 +// called under write_lock
5236 +static void get_counters(struct ebt_counter *oldcounters,
5237 + struct ebt_counter *counters, unsigned int nentries)
5240 + struct ebt_counter *counter_base;
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;
5255 +// replace the table
5256 +static int do_replace(void *user, unsigned int len)
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;
5266 + if (copy_from_user(&tmp, user, sizeof(tmp)) != 0)
5269 + if (len != sizeof(tmp) + tmp.entries_size) {
5270 + BUGPRINT("Wrong len argument\n");
5274 + if (tmp.entries_size == 0) {
5275 + BUGPRINT("Entries_size never zero\n");
5278 + countersize = COUNTER_OFFSET(tmp.nentries) * smp_num_cpus;
5279 + newinfo = (struct ebt_table_info *)
5280 + vmalloc(sizeof(struct ebt_table_info) + countersize);
5285 + memset(newinfo->counters, 0, countersize);
5287 + newinfo->entries = (char *)vmalloc(tmp.entries_size);
5288 + if (!newinfo->entries) {
5290 + goto free_newinfo;
5292 + if (copy_from_user(
5293 + newinfo->entries, tmp.entries, tmp.entries_size) != 0) {
5294 + BUGPRINT("Couldn't copy entries from userspace\n");
5296 + goto free_entries;
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) {
5306 + goto free_entries;
5310 + counterstmp = NULL;
5312 + // this can get initialized by translate_table()
5313 + newinfo->chainstack = NULL;
5314 + ret = translate_table(&tmp, newinfo);
5317 + goto free_counterstmp;
5319 + t = find_table_lock(tmp.name, &ret, &ebt_mutex);
5321 + goto free_iterate;
5323 + // the table doesn't like it
5324 + if (t->check && (ret = t->check(newinfo, tmp.valid_hooks)))
5327 + if (tmp.num_counters && tmp.num_counters != t->private->nentries) {
5328 + BUGPRINT("Wrong nr. of counters requested\n");
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);
5341 + t->private = newinfo;
5342 + write_unlock_bh(&t->lock);
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");
5357 + // decrease module count and free resources
5358 + EBT_ENTRY_ITERATE(table->entries, table->entries_size,
5359 + ebt_cleanup_entry, NULL);
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);
5370 + vfree(counterstmp);
5376 + EBT_ENTRY_ITERATE(newinfo->entries, newinfo->entries_size,
5377 + ebt_cleanup_entry, NULL);
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);
5388 + if (newinfo->entries)
5389 + vfree(newinfo->entries);
5396 +int ebt_register_target(struct ebt_target *target)
5400 + ret = down_interruptible(&ebt_mutex);
5403 + if (!list_named_insert(&ebt_targets, target)) {
5408 + MOD_INC_USE_COUNT;
5413 +void ebt_unregister_target(struct ebt_target *target)
5416 + LIST_DELETE(&ebt_targets, target);
5418 + MOD_DEC_USE_COUNT;
5421 +int ebt_register_match(struct ebt_match *match)
5425 + ret = down_interruptible(&ebt_mutex);
5428 + if (!list_named_insert(&ebt_matches, match)) {
5433 + MOD_INC_USE_COUNT;
5438 +void ebt_unregister_match(struct ebt_match *match)
5441 + LIST_DELETE(&ebt_matches, match);
5443 + MOD_DEC_USE_COUNT;
5446 +int ebt_register_watcher(struct ebt_watcher *watcher)
5450 + ret = down_interruptible(&ebt_mutex);
5453 + if (!list_named_insert(&ebt_watchers, watcher)) {
5458 + MOD_INC_USE_COUNT;
5463 +void ebt_unregister_watcher(struct ebt_watcher *watcher)
5466 + LIST_DELETE(&ebt_watchers, watcher);
5468 + MOD_DEC_USE_COUNT;
5471 +int ebt_register_table(struct ebt_table *table)
5473 + struct ebt_table_info *newinfo;
5474 + int ret, i, countersize;
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");
5483 + countersize = COUNTER_OFFSET(table->table->nentries) * smp_num_cpus;
5484 + newinfo = (struct ebt_table_info *)
5485 + vmalloc(sizeof(struct ebt_table_info) + countersize);
5490 + newinfo->entries = (char *)vmalloc(table->table->entries_size);
5491 + if (!(newinfo->entries))
5492 + goto free_newinfo;
5494 + memcpy(newinfo->entries, table->table->entries,
5495 + table->table->entries_size);
5498 + memset(newinfo->counters, 0, countersize);
5500 + // fill in newinfo and parse the entries
5501 + newinfo->chainstack = NULL;
5502 + ret = translate_table(table->table, newinfo);
5504 + BUGPRINT("Translate_table failed\n");
5505 + goto free_chainstack;
5508 + if (table->check && table->check(newinfo, table->valid_hooks)) {
5509 + BUGPRINT("The table doesn't like its own initial data, lol\n");
5513 + table->private = newinfo;
5514 + table->lock = RW_LOCK_UNLOCKED;
5515 + ret = down_interruptible(&ebt_mutex);
5517 + goto free_chainstack;
5519 + if (list_named_find(&ebt_tables, table->name)) {
5521 + BUGPRINT("Table name already exists\n");
5525 + list_prepend(&ebt_tables, table);
5527 + MOD_INC_USE_COUNT;
5532 + if (newinfo->chainstack) {
5533 + for (i = 0; i < smp_num_cpus; i++)
5534 + vfree(newinfo->chainstack[i]);
5535 + vfree(newinfo->chainstack);
5537 + vfree(newinfo->entries);
5543 +void ebt_unregister_table(struct ebt_table *table)
5548 + BUGPRINT("Request to unregister NULL table!!!\n");
5552 + LIST_DELETE(&ebt_tables, table);
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);
5563 + vfree(table->private);
5564 + MOD_DEC_USE_COUNT;
5567 +// userspace just supplied us with counters
5568 +static int update_counters(void *user, unsigned int len)
5571 + struct ebt_counter *tmp;
5572 + struct ebt_replace hlp;
5573 + struct ebt_table *t;
5575 + if (copy_from_user(&hlp, user, sizeof(hlp)))
5578 + if (len != sizeof(hlp) + hlp.num_counters * sizeof(struct ebt_counter))
5580 + if (hlp.num_counters == 0)
5583 + if ( !(tmp = (struct ebt_counter *)
5584 + vmalloc(hlp.num_counters * sizeof(struct ebt_counter))) ){
5585 + MEMPRINT("Update_counters && nomemory\n");
5589 + t = find_table_lock(hlp.name, &ret, &ebt_mutex);
5593 + if (hlp.num_counters != t->private->nentries) {
5594 + BUGPRINT("Wrong nr of counters\n");
5596 + goto unlock_mutex;
5599 + if ( copy_from_user(tmp, hlp.counters,
5600 + hlp.num_counters * sizeof(struct ebt_counter)) ) {
5601 + BUGPRINT("Updata_counters && !cfu\n");
5603 + goto unlock_mutex;
5606 + // we want an atomic add of the counters
5607 + write_lock_bh(&t->lock);
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;
5615 + write_unlock_bh(&t->lock);
5624 +static inline int ebt_make_matchname(struct ebt_entry_match *m,
5625 + char *base, char *ubase)
5627 + char *hlp = ubase - base + (char *)m;
5628 + if (copy_to_user(hlp, m->u.match->name, EBT_FUNCTION_MAXNAMELEN))
5633 +static inline int ebt_make_watchername(struct ebt_entry_watcher *w,
5634 + char *base, char *ubase)
5636 + char *hlp = ubase - base + (char *)w;
5637 + if (copy_to_user(hlp , w->u.watcher->name, EBT_FUNCTION_MAXNAMELEN))
5642 +static inline int ebt_make_names(struct ebt_entry *e, char *base, char *ubase)
5646 + struct ebt_entry_target *t;
5648 + if ((e->bitmask & EBT_ENTRY_OR_ENTRIES) == 0)
5651 + hlp = ubase - base + (char *)e + e->target_offset;
5652 + t = (struct ebt_entry_target *)(((char *)e) + e->target_offset);
5654 + ret = EBT_MATCH_ITERATE(e, ebt_make_matchname, base, ubase);
5657 + ret = EBT_WATCHER_ITERATE(e, ebt_make_watchername, base, ubase);
5660 + if (copy_to_user(hlp, t->u.target->name, EBT_FUNCTION_MAXNAMELEN))
5665 +// called with ebt_mutex down
5666 +static int copy_everything_to_user(struct ebt_table *t, void *user,
5667 + int *len, int cmd)
5669 + struct ebt_replace tmp;
5670 + struct ebt_counter *counterstmp, *oldcounters;
5671 + unsigned int entries_size, nentries;
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;
5680 + entries_size = t->table->entries_size;
5681 + nentries = t->table->nentries;
5682 + entries = t->table->entries;
5683 + oldcounters = t->table->counters;
5686 + if (copy_from_user(&tmp, user, sizeof(tmp))) {
5687 + BUGPRINT("Cfu didn't work\n");
5691 + if (*len != sizeof(struct ebt_replace) + entries_size +
5692 + (tmp.num_counters? nentries * sizeof(struct ebt_counter): 0)) {
5693 + BUGPRINT("Wrong size\n");
5697 + if (tmp.nentries != nentries) {
5698 + BUGPRINT("Nentries wrong\n");
5702 + if (tmp.entries_size != entries_size) {
5703 + BUGPRINT("Wrong size\n");
5707 + // userspace might not need the counters
5708 + if (tmp.num_counters) {
5709 + if (tmp.num_counters != nentries) {
5710 + BUGPRINT("Num_counters wrong\n");
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");
5719 + write_lock_bh(&t->lock);
5720 + get_counters(oldcounters, counterstmp, nentries);
5721 + write_unlock_bh(&t->lock);
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);
5729 + vfree(counterstmp);
5732 + if (copy_to_user(tmp.entries, entries, entries_size)) {
5733 + BUGPRINT("Couldn't copy entries to userspace\n");
5736 + // set the match/watcher/target names right
5737 + return EBT_ENTRY_ITERATE(entries, entries_size,
5738 + ebt_make_names, entries, tmp.entries);
5741 +static int do_ebt_set_ctl(struct sock *sk,
5742 + int cmd, void *user, unsigned int len)
5747 + case EBT_SO_SET_ENTRIES:
5748 + ret = do_replace(user, len);
5750 + case EBT_SO_SET_COUNTERS:
5751 + ret = update_counters(user, len);
5759 +static int do_ebt_get_ctl(struct sock *sk, int cmd, void *user, int *len)
5762 + struct ebt_replace tmp;
5763 + struct ebt_table *t;
5765 + if (copy_from_user(&tmp, user, sizeof(tmp)))
5768 + t = find_table_lock(tmp.name, &ret, &ebt_mutex);
5773 + case EBT_SO_GET_INFO:
5774 + case EBT_SO_GET_INIT_INFO:
5775 + if (*len != sizeof(struct ebt_replace)){
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;
5785 + tmp.nentries = t->table->nentries;
5786 + tmp.entries_size = t->table->entries_size;
5787 + tmp.valid_hooks = t->table->valid_hooks;
5790 + if (copy_to_user(user, &tmp, *len) != 0){
5791 + BUGPRINT("c2u Didn't work\n");
5798 + case EBT_SO_GET_ENTRIES:
5799 + case EBT_SO_GET_INIT_ENTRIES:
5800 + ret = copy_everything_to_user(t, user, len, cmd);
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
5817 +static int __init init(void)
5822 + list_named_insert(&ebt_targets, &ebt_standard_target);
5824 + if ((ret = nf_register_sockopt(&ebt_sockopts)) < 0)
5827 + printk(KERN_NOTICE "Ebtables v2.0 registered\n");
5831 +static void __exit fini(void)
5833 + nf_unregister_sockopt(&ebt_sockopts);
5834 + printk(KERN_NOTICE "Ebtables v2.0 unregistered\n");
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);
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 @@
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;
5860 static __inline__ int handle_bridge(struct sk_buff *skb,
5861 @@ -1410,7 +1410,6 @@
5865 - br_handle_frame_hook(skb);
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);
5876 + ret = handle_bridge(skb, pt_prev);
5877 + if (br_handle_frame_hook(skb) == 0)
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 *),
5894 for (*i = (*i)->next; *i != head; *i = (*i)->next) {
5895 struct nf_hook_ops *elem = (struct nf_hook_ops *)*i;
5897 + if (hook_thresh > elem->priority)
5900 switch (elem->hook(hook, skb, indev, outdev, okfn)) {
5903 @@ -415,6 +420,10 @@
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;
5912 if (!queue_handler[pf].outfn) {
5914 @@ -437,11 +446,24 @@
5915 if (indev) dev_hold(indev);
5916 if (outdev) dev_hold(outdev);
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);
5927 status = queue_handler[pf].outfn(skb, info, queue_handler[pf].data);
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);
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 *),
5947 struct list_head *elem;
5948 unsigned int verdict;
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 @@
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);
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. */
5974 verdict = nf_iterate(&nf_hooks[info->pf][info->hook],
5976 info->indev, info->outdev, &elem,
5978 + info->okfn, INT_MIN);
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
5986 #ifdef CONFIG_NETFILTER_DEBUG
5989 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
5990 + skb->nf_bridge = NULL;
5993 #ifdef CONFIG_NET_SCHED
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);
6003 skb_headerinit(skb, NULL, 0); /* clean state */
6006 #ifdef CONFIG_NETFILTER_DEBUG
6009 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6012 #endif /*CONFIG_NETFILTER*/
6013 #if defined(CONFIG_HIPPI)
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);
6025 @@ -436,6 +448,10 @@
6026 #ifdef CONFIG_NETFILTER_DEBUG
6027 new->nf_debug=old->nf_debug;
6029 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6030 + new->nf_bridge=old->nf_bridge;
6031 + nf_bridge_get(new->nf_bridge);
6034 #ifdef CONFIG_NET_SCHED
6035 new->tc_index = old->tc_index;
6037 /* Set the tail pointer and length */
6038 skb_put(n,skb->len);
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))
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);
6058 #ifdef CONFIG_NETFILTER_DEBUG
6059 skb2->nf_debug = skb->nf_debug;
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
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
6068 + if [ "$CONFIG_BRIDGE" != "n" ]; then
6069 + dep_tristate ' Physdev match support' CONFIG_IP_NF_MATCH_PHYSDEV $CONFIG_IP_NF_IPTABLES
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
6078 obj-$(CONFIG_IP_NF_MATCH_TCPMSS) += ipt_tcpmss.o
6079 obj-$(CONFIG_IP_NF_MATCH_REALM) += ipt_realm.o
6081 +obj-$(CONFIG_IP_NF_MATCH_PHYSDEV) += ipt_physdev.o
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 @@
6091 ip_packet_match(const struct iphdr *ip,
6093 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6094 + const char *physindev,
6097 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6098 + const char *physoutdev,
6100 const struct ipt_ip *ipinfo,
6105 + unsigned long ret2 = 1;
6107 #define FWINV(bool,invflg) ((bool) ^ !!(ipinfo->invflags & invflg))
6109 @@ -156,7 +163,15 @@
6110 & ((const unsigned long *)ipinfo->iniface_mask)[i];
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];
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];
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];
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)":"");
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;
6151 struct ipt_entry *e, *back;
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;
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 @@
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)
6177 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6180 + &e->ip, offset)) {
6181 struct ipt_entry_target *t;
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,
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;
6196 + if (physindev && in != physindev)
6197 + printk("PHYSIN=%s ", physindev->name);
6198 + if (physoutdev && out != physoutdev)
6199 + printk("PHYSOUT=%s ", physoutdev->name);
6204 /* MAC logging for input chain only. */
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
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>
6222 +match(const struct sk_buff *skb,
6223 + const struct net_device *in,
6224 + const struct net_device *out,
6225 + const void *matchinfo,
6228 + u_int16_t datalen,
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;
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))
6246 + if ((info->bitmask & IPT_PHYSDEV_OP_ISIN) &&
6247 + !(info->invert & IPT_PHYSDEV_OP_ISIN))
6249 + if ((info->bitmask & IPT_PHYSDEV_OP_ISOUT) &&
6250 + !(info->invert & IPT_PHYSDEV_OP_ISOUT))
6252 + if ((info->bitmask & IPT_PHYSDEV_OP_IN) &&
6253 + !(info->invert & IPT_PHYSDEV_OP_IN))
6255 + if ((info->bitmask & IPT_PHYSDEV_OP_OUT) &&
6256 + !(info->invert & IPT_PHYSDEV_OP_OUT))
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)))
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))))
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];
6282 + if ((ret == 0) ^ !(info->invert & IPT_PHYSDEV_OP_IN))
6286 + if (!(info->bitmask & IPT_PHYSDEV_OP_OUT))
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];
6296 + return (ret != 0) ^ !(info->invert & IPT_PHYSDEV_OP_OUT);
6300 +checkentry(const char *tablename,
6301 + const struct ipt_ip *ip,
6303 + unsigned int matchsize,
6304 + unsigned int hook_mask)
6306 + const struct ipt_physdev_info *info = matchinfo;
6308 + if (matchsize != IPT_ALIGN(sizeof(struct ipt_physdev_info)))
6310 + if (!(info->bitmask & IPT_PHYSDEV_OP_MASK) ||
6311 + info->bitmask & ~IPT_PHYSDEV_OP_MASK)
6316 +static struct ipt_match physdev_match = {
6317 + .name = "physdev",
6319 + .checkentry = &checkentry,
6320 + .me = THIS_MODULE,
6323 +static int __init init(void)
6325 + return ipt_register_match(&physdev_match);
6328 +static void __exit fini(void)
6330 + ipt_unregister_match(&physdev_match);
6335 +MODULE_LICENSE("GPL");