1 --- linux-2.4.31/net/bridge/br_private.h 2004-08-07 23:26:06.000000000 +0000
2 +++ linux-2.4.31-ebt-brnf/net/bridge/br_private.h 2005-09-15 16:57:22.000000000 +0000
3 @@ -143,8 +143,10 @@ extern void br_fdb_insert(struct net_bri
5 extern void br_deliver(struct net_bridge_port *to,
7 +extern int br_dev_queue_push_xmit(struct sk_buff *skb);
8 extern void br_forward(struct net_bridge_port *to,
10 +extern int br_forward_finish(struct sk_buff *skb);
11 extern void br_flood_deliver(struct net_bridge *br,
14 @@ -165,7 +167,8 @@ extern void br_get_port_ifindices(struct
18 -extern void br_handle_frame(struct sk_buff *skb);
19 +extern int br_handle_frame_finish(struct sk_buff *skb);
20 +extern int br_handle_frame(struct sk_buff *skb);
23 extern int br_ioctl(struct net_bridge *br,
24 @@ -175,6 +178,10 @@ extern int br_ioctl(struct net_bridge *b
26 extern int br_ioctl_deviceless_stub(unsigned long arg);
29 +extern int br_netfilter_init(void);
30 +extern void br_netfilter_fini(void);
33 extern int br_is_root_bridge(struct net_bridge *br);
34 extern struct net_bridge_port *br_get_port(struct net_bridge *br,
35 --- linux-2.4.31/include/linux/if_bridge.h 2001-11-22 19:47:12.000000000 +0000
36 +++ linux-2.4.31-ebt-brnf/include/linux/if_bridge.h 2005-09-15 16:57:23.000000000 +0000
37 @@ -102,7 +102,8 @@ struct net_bridge;
38 struct net_bridge_port;
40 extern int (*br_ioctl_hook)(unsigned long arg);
41 -extern void (*br_handle_frame_hook)(struct sk_buff *skb);
42 +extern int (*br_handle_frame_hook)(struct sk_buff *skb);
43 +extern int (*br_should_route_hook)(struct sk_buff **pskb);
47 --- linux-2.4.31/net/core/dev.c 2005-04-04 01:42:20.000000000 +0000
48 +++ linux-2.4.31-ebt-brnf/net/core/dev.c 2005-09-15 16:57:23.000000000 +0000
49 @@ -1426,7 +1426,7 @@ static void net_tx_action(struct softirq
52 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
53 -void (*br_handle_frame_hook)(struct sk_buff *skb) = NULL;
54 +int (*br_handle_frame_hook)(struct sk_buff *skb) = NULL;
57 static __inline__ int handle_bridge(struct sk_buff *skb,
58 @@ -1443,7 +1443,6 @@ static __inline__ int handle_bridge(stru
62 - br_handle_frame_hook(skb);
66 @@ -1503,7 +1502,12 @@ int netif_receive_skb(struct sk_buff *sk
67 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
68 if (skb->dev->br_port != NULL && br_handle_frame_hook != NULL &&
69 skb->pkt_type != PACKET_LOOPBACK) {
70 - return handle_bridge(skb, pt_prev);
73 + ret = handle_bridge(skb, pt_prev);
74 + if (br_handle_frame_hook(skb) == 0)
80 --- linux-2.4.31/net/bridge/br_input.c 2003-08-25 11:44:44.000000000 +0000
81 +++ linux-2.4.31-ebt-brnf/net/bridge/br_input.c 2005-09-22 17:19:52.212834152 +0000
82 @@ -24,6 +24,9 @@ unsigned char bridge_ula[6] = { 0x01, 0x
84 static int br_pass_frame_up_finish(struct sk_buff *skb)
86 +#ifdef CONFIG_NETFILTER_DEBUG
92 @@ -46,7 +49,7 @@ static void br_pass_frame_up(struct net_
93 br_pass_frame_up_finish);
96 -static int br_handle_frame_finish(struct sk_buff *skb)
97 +int br_handle_frame_finish(struct sk_buff *skb)
99 struct net_bridge *br;
101 @@ -61,6 +64,9 @@ static int br_handle_frame_finish(struct
105 + /* insert into forwarding database after filtering to avoid spoofing */
106 + br_fdb_insert(br, p, skb->mac.ethernet->h_source, 0);
108 read_lock(&br->lock);
109 if (skb->dev->br_port == NULL)
111 @@ -112,7 +118,7 @@ err_nolock:
115 -void br_handle_frame(struct sk_buff *skb)
116 +int br_handle_frame(struct sk_buff *skb)
118 struct net_bridge *br;
120 @@ -136,8 +142,7 @@ void br_handle_frame(struct sk_buff *skb
121 if (skb->mac.ethernet->h_source[0] & 1)
124 - if (p->state == BR_STATE_LEARNING ||
125 - p->state == BR_STATE_FORWARDING)
126 + if (p->state == BR_STATE_LEARNING)
127 br_fdb_insert(br, p, skb->mac.ethernet->h_source, 0);
129 if (br->stp_enabled &&
130 @@ -146,26 +151,35 @@ void br_handle_frame(struct sk_buff *skb
131 goto handle_special_frame;
133 if (p->state == BR_STATE_FORWARDING) {
134 + if (br_should_route_hook && br_should_route_hook(&skb)) {
135 + read_unlock(&br->lock);
139 + if (!memcmp(p->br->dev.dev_addr, dest, ETH_ALEN))
140 + skb->pkt_type = PACKET_HOST;
142 NF_HOOK(PF_BRIDGE, NF_BR_PRE_ROUTING, skb, skb->dev, NULL,
143 br_handle_frame_finish);
144 read_unlock(&br->lock);
150 read_unlock(&br->lock);
156 handle_special_frame:
158 NF_HOOK(PF_BRIDGE, NF_BR_LOCAL_IN, skb, skb->dev,NULL,
160 read_unlock(&br->lock);
165 read_unlock(&br->lock);
169 --- linux-2.4.31/net/bridge/br_stp_bpdu.c 2003-11-28 18:26:21.000000000 +0000
170 +++ linux-2.4.31-ebt-brnf/net/bridge/br_stp_bpdu.c 2005-09-22 17:20:13.385615400 +0000
171 @@ -142,6 +142,9 @@ int br_stp_handle_bpdu(struct sk_buff *s
173 p = skb->dev->br_port;
175 + /* insert into forwarding database after filtering to avoid spoofing */
176 + br_fdb_insert(p->br, p, skb->mac.ethernet->h_source, 0);
178 if (!p->br->stp_enabled ||
179 !pskb_may_pull(skb, sizeof(header)+1) ||
180 memcmp(skb->data, header, sizeof(header)))
181 --- linux-2.4.31/net/bridge/br_forward.c 2003-11-28 18:26:21.000000000 +0000
182 +++ linux-2.4.31-ebt-brnf/net/bridge/br_forward.c 2005-09-15 16:57:23.000000000 +0000
183 @@ -30,18 +30,21 @@ static inline int should_deliver(struct
187 -static int __dev_queue_push_xmit(struct sk_buff *skb)
188 +int br_dev_queue_push_xmit(struct sk_buff *skb)
190 +#ifdef CONFIG_NETFILTER
191 + nf_bridge_maybe_copy_header(skb);
193 skb_push(skb, ETH_HLEN);
199 -static int __br_forward_finish(struct sk_buff *skb)
200 +int br_forward_finish(struct sk_buff *skb)
202 NF_HOOK(PF_BRIDGE, NF_BR_POST_ROUTING, skb, NULL, skb->dev,
203 - __dev_queue_push_xmit);
204 + br_dev_queue_push_xmit);
208 @@ -49,8 +52,11 @@ static int __br_forward_finish(struct sk
209 static void __br_deliver(struct net_bridge_port *to, struct sk_buff *skb)
212 +#ifdef CONFIG_NETFILTER_DEBUG
215 NF_HOOK(PF_BRIDGE, NF_BR_LOCAL_OUT, skb, NULL, skb->dev,
216 - __br_forward_finish);
217 + br_forward_finish);
220 static void __br_forward(struct net_bridge_port *to, struct sk_buff *skb)
221 @@ -62,7 +68,7 @@ static void __br_forward(struct net_brid
222 skb->ip_summed = CHECKSUM_NONE;
224 NF_HOOK(PF_BRIDGE, NF_BR_FORWARD, skb, indev, skb->dev,
225 - __br_forward_finish);
226 + br_forward_finish);
229 /* called under bridge lock */
230 --- linux-2.4.31/net/bridge/br.c 2004-08-07 23:26:06.000000000 +0000
231 +++ linux-2.4.31-ebt-brnf/net/bridge/br.c 2005-09-15 16:57:23.000000000 +0000
233 #include "../atm/lec.h"
236 +int (*br_should_route_hook) (struct sk_buff **pskb) = NULL;
238 void br_dec_use_count()
241 @@ -44,6 +46,10 @@ static int __init br_init(void)
243 printk(KERN_INFO "NET4: Ethernet Bridge 008 for NET4.0\n");
245 +#ifdef CONFIG_NETFILTER
246 + if (br_netfilter_init())
249 br_handle_frame_hook = br_handle_frame;
250 br_ioctl_hook = br_ioctl_deviceless_stub;
251 #if defined(CONFIG_ATM_LANE) || defined(CONFIG_ATM_LANE_MODULE)
252 @@ -57,6 +63,9 @@ static int __init br_init(void)
254 static void __exit br_deinit(void)
256 +#ifdef CONFIG_NETFILTER
257 + br_netfilter_fini();
259 unregister_netdevice_notifier(&br_device_notifier);
262 @@ -73,7 +82,7 @@ static void __exit br_deinit(void)
267 +EXPORT_SYMBOL(br_should_route_hook);
270 module_exit(br_deinit)
271 --- linux-2.4.31/net/bridge/Makefile 2000-12-29 22:07:24.000000000 +0000
272 +++ linux-2.4.31-ebt-brnf/net/bridge/Makefile 2005-09-15 16:57:23.000000000 +0000
275 # Note 2! The CFLAGS definition is now in the main makefile...
280 obj-y := br.o br_device.o br_fdb.o br_forward.o br_if.o br_input.o \
281 br_ioctl.o br_notify.o br_stp.o br_stp_bpdu.o \
282 br_stp_if.o br_stp_timer.o
284 +ifeq ($(CONFIG_NETFILTER),y)
285 +obj-y += br_netfilter.o
290 include $(TOPDIR)/Rules.make
291 --- linux-2.4.31/include/linux/netfilter_bridge.h 2001-06-12 02:15:27.000000000 +0000
292 +++ linux-2.4.31-ebt-brnf/include/linux/netfilter_bridge.h 2005-09-15 16:57:23.000000000 +0000
295 #include <linux/config.h>
296 #include <linux/netfilter.h>
297 +#if defined(__KERNEL__) && defined(CONFIG_NETFILTER)
298 +#include <asm/atomic.h>
299 +#include <linux/if_ether.h>
303 /* After promisc drops, checksum checks. */
305 #define NF_BR_LOCAL_OUT 3
306 /* Packets about to hit the wire. */
307 #define NF_BR_POST_ROUTING 4
308 -#define NF_BR_NUMHOOKS 5
309 +/* Not really a hook, but used for the ebtables broute table */
310 +#define NF_BR_BROUTING 5
311 +#define NF_BR_NUMHOOKS 6
315 +#define BRNF_PKT_TYPE 0x01
316 +#define BRNF_BRIDGED_DNAT 0x02
317 +#define BRNF_DONT_TAKE_PARENT 0x04
318 +#define BRNF_BRIDGED 0x08
319 +#define BRNF_NF_BRIDGE_PREROUTING 0x10
321 +enum nf_br_hook_priorities {
322 + NF_BR_PRI_FIRST = INT_MIN,
323 + NF_BR_PRI_NAT_DST_BRIDGED = -300,
324 + NF_BR_PRI_FILTER_BRIDGED = -200,
325 + NF_BR_PRI_BRNF = 0,
326 + NF_BR_PRI_NAT_DST_OTHER = 100,
327 + NF_BR_PRI_FILTER_OTHER = 200,
328 + NF_BR_PRI_NAT_SRC = 300,
329 + NF_BR_PRI_LAST = INT_MAX,
332 +#ifdef CONFIG_NETFILTER
334 +struct nf_bridge_info *nf_bridge_alloc(struct sk_buff *skb)
336 + struct nf_bridge_info **nf_bridge = &(skb->nf_bridge);
338 + if ((*nf_bridge = kmalloc(sizeof(**nf_bridge), GFP_ATOMIC)) != NULL) {
339 + atomic_set(&(*nf_bridge)->use, 1);
340 + (*nf_bridge)->mask = 0;
341 + (*nf_bridge)->physindev = (*nf_bridge)->physoutdev = NULL;
342 +#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
343 + (*nf_bridge)->netoutdev = NULL;
350 +/* Only used in br_forward.c */
352 +void nf_bridge_maybe_copy_header(struct sk_buff *skb)
354 + if (skb->nf_bridge) {
355 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
356 + memcpy(skb->data - 18, skb->nf_bridge->data, 18);
359 + memcpy(skb->data - 16, skb->nf_bridge->data, 16);
364 +void nf_bridge_save_header(struct sk_buff *skb)
366 + int header_size = 16;
368 + if (skb->protocol == __constant_htons(ETH_P_8021Q))
370 + memcpy(skb->nf_bridge->data, skb->data - header_size, header_size);
373 +struct bridge_skb_cb {
380 +/* This is called by the IP fragmenting code and it ensures there is
381 + * enough room for the encapsulating header (if there is one). */
383 +int nf_bridge_pad(struct sk_buff *skb)
385 + if (skb->nf_bridge) {
386 + if (skb->protocol == __constant_htons(ETH_P_8021Q))
391 +#endif /* CONFIG_NETFILTER */
393 +#endif /* __KERNEL__ */
395 --- linux-2.4.31/include/linux/netfilter_ipv4/ip_tables.h 2005-04-04 01:42:20.000000000 +0000
396 +++ linux-2.4.31-ebt-brnf/include/linux/netfilter_ipv4/ip_tables.h 2005-09-15 16:57:23.000000000 +0000
397 @@ -159,7 +159,7 @@ struct ipt_entry
398 #define IPT_CONTINUE 0xFFFFFFFF
400 /* For standard target */
401 -#define IPT_RETURN (-NF_MAX_VERDICT - 1)
402 +#define IPT_RETURN (-NF_REPEAT - 1)
404 /* TCP matching stuff */
406 --- linux-2.4.31/include/linux/netfilter_ipv6/ip6_tables.h 2005-04-04 01:42:20.000000000 +0000
407 +++ linux-2.4.31-ebt-brnf/include/linux/netfilter_ipv6/ip6_tables.h 2005-09-15 16:57:23.000000000 +0000
408 @@ -165,7 +165,7 @@ struct ip6t_entry
409 #define IP6T_CONTINUE 0xFFFFFFFF
411 /* For standard target */
412 -#define IP6T_RETURN (-NF_MAX_VERDICT - 1)
413 +#define IP6T_RETURN (-NF_REPEAT - 1)
415 /* TCP matching stuff */
417 --- linux-2.4.31/include/linux/netfilter_arp/arp_tables.h 2003-08-25 11:44:44.000000000 +0000
418 +++ linux-2.4.31-ebt-brnf/include/linux/netfilter_arp/arp_tables.h 2005-09-15 16:57:23.000000000 +0000
419 @@ -154,7 +154,7 @@ struct arpt_entry
420 #define ARPT_CONTINUE 0xFFFFFFFF
422 /* For standard target */
423 -#define ARPT_RETURN (-NF_MAX_VERDICT - 1)
424 +#define ARPT_RETURN (-NF_REPEAT - 1)
426 /* The argument to ARPT_SO_GET_INFO */
428 --- linux-2.4.31/net/Makefile 2004-08-07 23:26:06.000000000 +0000
429 +++ linux-2.4.31-ebt-brnf/net/Makefile 2005-09-15 16:57:23.000000000 +0000
432 O_TARGET := network.o
434 -mod-subdirs := ipv4/netfilter ipv6/netfilter ipx irda bluetooth atm netlink sched core sctp 802
435 +mod-subdirs := ipv4/netfilter ipv6/netfilter bridge/netfilter ipx irda \
436 + bluetooth atm netlink sched core sctp 802
437 export-objs := netsyms.o
439 subdir-y := core ethernet
440 @@ -27,6 +28,12 @@ subdir-$(CONFIG_NETFILTER) += ipv6/netfi
444 +ifneq ($(CONFIG_BRIDGE),n)
445 +ifneq ($(CONFIG_BRIDGE),)
446 +subdir-$(CONFIG_BRIDGE) += bridge/netfilter
450 subdir-$(CONFIG_KHTTPD) += khttpd
451 subdir-$(CONFIG_PACKET) += packet
452 subdir-$(CONFIG_NET_SCHED) += sched
453 --- linux-2.4.31/net/Config.in 2005-01-19 14:10:13.000000000 +0000
454 +++ linux-2.4.31-ebt-brnf/net/Config.in 2005-09-15 16:57:23.000000000 +0000
455 @@ -70,6 +70,9 @@ if [ "$CONFIG_DECNET" != "n" ]; then
456 source net/decnet/Config.in
458 dep_tristate '802.1d Ethernet Bridging' CONFIG_BRIDGE $CONFIG_INET
459 +if [ "$CONFIG_BRIDGE" != "n" -a "$CONFIG_NETFILTER" != "n" ]; then
460 + source net/bridge/netfilter/Config.in
462 if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then
463 tristate 'CCITT X.25 Packet Layer (EXPERIMENTAL)' CONFIG_X25
464 tristate 'LAPB Data Link Driver (EXPERIMENTAL)' CONFIG_LAPB
465 --- /dev/null 2005-09-22 15:53:13.374707688 +0000
466 +++ linux-2.4.31-ebt-brnf/net/bridge/netfilter/Makefile 2005-09-15 16:57:23.000000000 +0000
469 +# Makefile for the netfilter modules on top of bridging.
471 +# Note! Dependencies are done automagically by 'make dep', which also
472 +# removes any old dependencies. DON'T put your own dependencies here
473 +# unless it's something special (ie not a .c file).
475 +# Note 2! The CFLAGS definition is now in the main makefile...
477 +O_TARGET := netfilter.o
479 +export-objs := ebtables.o
481 +obj-$(CONFIG_BRIDGE_NF_EBTABLES) += ebtables.o
482 +obj-$(CONFIG_BRIDGE_EBT_T_FILTER) += ebtable_filter.o
483 +obj-$(CONFIG_BRIDGE_EBT_T_NAT) += ebtable_nat.o
484 +obj-$(CONFIG_BRIDGE_EBT_BROUTE) += ebtable_broute.o
485 +obj-$(CONFIG_BRIDGE_EBT_802_3) += ebt_802_3.o
486 +obj-$(CONFIG_BRIDGE_EBT_ARPF) += ebt_arp.o
487 +obj-$(CONFIG_BRIDGE_EBT_AMONG) += ebt_among.o
488 +obj-$(CONFIG_BRIDGE_EBT_IPF) += ebt_ip.o
489 +obj-$(CONFIG_BRIDGE_EBT_LIMIT) += ebt_limit.o
490 +obj-$(CONFIG_BRIDGE_EBT_MARKF) += ebt_mark_m.o
491 +obj-$(CONFIG_BRIDGE_EBT_PKTTYPE) += ebt_pkttype.o
492 +obj-$(CONFIG_BRIDGE_EBT_STP) += ebt_stp.o
493 +obj-$(CONFIG_BRIDGE_EBT_VLANF) += ebt_vlan.o
494 +obj-$(CONFIG_BRIDGE_EBT_LOG) += ebt_log.o
495 +obj-$(CONFIG_BRIDGE_EBT_LOG) += ebt_ulog.o
496 +obj-$(CONFIG_BRIDGE_EBT_ARPREPLY) += ebt_arpreply.o
497 +obj-$(CONFIG_BRIDGE_EBT_DNAT) += ebt_dnat.o
498 +obj-$(CONFIG_BRIDGE_EBT_MARK_T) += ebt_mark.o
499 +obj-$(CONFIG_BRIDGE_EBT_REDIRECT) += ebt_redirect.o
500 +obj-$(CONFIG_BRIDGE_EBT_SNAT) += ebt_snat.o
501 +include $(TOPDIR)/Rules.make
502 --- /dev/null 2005-09-22 15:53:13.374707688 +0000
503 +++ linux-2.4.31-ebt-brnf/net/bridge/netfilter/Config.in 2005-09-15 16:57:23.000000000 +0000
506 +# Bridge netfilter configuration
508 +dep_tristate ' Bridge: ebtables' CONFIG_BRIDGE_NF_EBTABLES $CONFIG_BRIDGE
509 +dep_tristate ' ebt: filter table support' CONFIG_BRIDGE_EBT_T_FILTER $CONFIG_BRIDGE_NF_EBTABLES
510 +dep_tristate ' ebt: nat table support' CONFIG_BRIDGE_EBT_T_NAT $CONFIG_BRIDGE_NF_EBTABLES
511 +dep_tristate ' ebt: broute table support' CONFIG_BRIDGE_EBT_BROUTE $CONFIG_BRIDGE_NF_EBTABLES
512 +dep_tristate ' ebt: log support' CONFIG_BRIDGE_EBT_LOG $CONFIG_BRIDGE_NF_EBTABLES
513 +dep_tristate ' ebt: ulog support' CONFIG_BRIDGE_EBT_LOG $CONFIG_BRIDGE_NF_EBTABLES
514 +dep_tristate ' ebt: IP filter support' CONFIG_BRIDGE_EBT_IPF $CONFIG_BRIDGE_NF_EBTABLES
515 +dep_tristate ' ebt: ARP filter support' CONFIG_BRIDGE_EBT_ARPF $CONFIG_BRIDGE_NF_EBTABLES
516 +dep_tristate ' ebt: among filter support' CONFIG_BRIDGE_EBT_AMONG $CONFIG_BRIDGE_NF_EBTABLES
517 +dep_tristate ' ebt: limit filter support' CONFIG_BRIDGE_EBT_LIMIT $CONFIG_BRIDGE_NF_EBTABLES
518 +dep_tristate ' ebt: 802.1Q VLAN filter support' CONFIG_BRIDGE_EBT_VLANF $CONFIG_BRIDGE_NF_EBTABLES
519 +dep_tristate ' ebt: 802.3 filter support' CONFIG_BRIDGE_EBT_802_3 $CONFIG_BRIDGE_NF_EBTABLES
520 +dep_tristate ' ebt: packet type filter support' CONFIG_BRIDGE_EBT_PKTTYPE $CONFIG_BRIDGE_NF_EBTABLES
521 +dep_tristate ' ebt: STP filter support' CONFIG_BRIDGE_EBT_STP $CONFIG_BRIDGE_NF_EBTABLES
522 +dep_tristate ' ebt: mark filter support' CONFIG_BRIDGE_EBT_MARKF $CONFIG_BRIDGE_NF_EBTABLES
523 +dep_tristate ' ebt: arp reply target support' CONFIG_BRIDGE_EBT_ARPREPLY $CONFIG_BRIDGE_NF_EBTABLES
524 +dep_tristate ' ebt: snat target support' CONFIG_BRIDGE_EBT_SNAT $CONFIG_BRIDGE_NF_EBTABLES
525 +dep_tristate ' ebt: dnat target support' CONFIG_BRIDGE_EBT_DNAT $CONFIG_BRIDGE_NF_EBTABLES
526 +dep_tristate ' ebt: redirect target support' CONFIG_BRIDGE_EBT_REDIRECT $CONFIG_BRIDGE_NF_EBTABLES
527 +dep_tristate ' ebt: mark target support' CONFIG_BRIDGE_EBT_MARK_T $CONFIG_BRIDGE_NF_EBTABLES
528 --- /dev/null 2005-09-22 15:53:13.374707688 +0000
529 +++ linux-2.4.31-ebt-brnf/net/bridge/netfilter/ebtable_filter.c 2005-09-15 16:57:23.000000000 +0000
535 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
541 +#include <linux/netfilter_bridge/ebtables.h>
542 +#include <linux/module.h>
544 +#define FILTER_VALID_HOOKS ((1 << NF_BR_LOCAL_IN) | (1 << NF_BR_FORWARD) | \
545 + (1 << NF_BR_LOCAL_OUT))
547 +static struct ebt_entries initial_chains[] =
549 + {0, "INPUT", 0, EBT_ACCEPT, 0},
550 + {0, "FORWARD", 0, EBT_ACCEPT, 0},
551 + {0, "OUTPUT", 0, EBT_ACCEPT, 0}
554 +static struct ebt_replace initial_table =
556 + "filter", FILTER_VALID_HOOKS, 0, 3 * sizeof(struct ebt_entries),
557 + { [NF_BR_LOCAL_IN]&initial_chains[0], [NF_BR_FORWARD]&initial_chains[1],
558 + [NF_BR_LOCAL_OUT]&initial_chains[2] }, 0, NULL, (char *)initial_chains
561 +static int check(const struct ebt_table_info *info, unsigned int valid_hooks)
563 + if (valid_hooks & ~FILTER_VALID_HOOKS)
568 +static struct ebt_table frame_filter =
570 + {NULL, NULL}, "filter", &initial_table, FILTER_VALID_HOOKS,
571 + RW_LOCK_UNLOCKED, check, NULL
575 +ebt_hook (unsigned int hook, struct sk_buff **pskb, const struct net_device *in,
576 + const struct net_device *out, int (*okfn)(struct sk_buff *))
578 + return ebt_do_table(hook, pskb, in, out, &frame_filter);
581 +static struct nf_hook_ops ebt_ops_filter[] = {
582 + { { NULL, NULL }, ebt_hook, PF_BRIDGE, NF_BR_LOCAL_IN,
583 + NF_BR_PRI_FILTER_BRIDGED},
584 + { { NULL, NULL }, ebt_hook, PF_BRIDGE, NF_BR_FORWARD,
585 + NF_BR_PRI_FILTER_BRIDGED},
586 + { { NULL, NULL }, ebt_hook, PF_BRIDGE, NF_BR_LOCAL_OUT,
587 + NF_BR_PRI_FILTER_OTHER}
590 +static int __init init(void)
594 + ret = ebt_register_table(&frame_filter);
597 + for (i = 0; i < sizeof(ebt_ops_filter) / sizeof(ebt_ops_filter[0]); i++)
598 + if ((ret = nf_register_hook(&ebt_ops_filter[i])) < 0)
602 + for (j = 0; j < i; j++)
603 + nf_unregister_hook(&ebt_ops_filter[j]);
604 + ebt_unregister_table(&frame_filter);
608 +static void __exit fini(void)
612 + for (i = 0; i < sizeof(ebt_ops_filter) / sizeof(ebt_ops_filter[0]); i++)
613 + nf_unregister_hook(&ebt_ops_filter[i]);
614 + ebt_unregister_table(&frame_filter);
620 +MODULE_LICENSE("GPL");
621 --- /dev/null 2005-09-22 15:53:13.374707688 +0000
622 +++ linux-2.4.31-ebt-brnf/net/bridge/netfilter/ebtable_nat.c 2005-09-15 16:57:23.000000000 +0000
628 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
634 +#include <linux/netfilter_bridge/ebtables.h>
635 +#include <linux/module.h>
636 +#define NAT_VALID_HOOKS ((1 << NF_BR_PRE_ROUTING) | (1 << NF_BR_LOCAL_OUT) | \
637 + (1 << NF_BR_POST_ROUTING))
639 +static struct ebt_entries initial_chains[] =
641 + {0, "PREROUTING", 0, EBT_ACCEPT, 0},
642 + {0, "OUTPUT", 0, EBT_ACCEPT, 0},
643 + {0, "POSTROUTING", 0, EBT_ACCEPT, 0}
646 +static struct ebt_replace initial_table =
648 + "nat", NAT_VALID_HOOKS, 0, 3 * sizeof(struct ebt_entries),
649 + { [NF_BR_PRE_ROUTING]&initial_chains[0], [NF_BR_LOCAL_OUT]&initial_chains[1],
650 + [NF_BR_POST_ROUTING]&initial_chains[2] }, 0, NULL, (char *)initial_chains
653 +static int check(const struct ebt_table_info *info, unsigned int valid_hooks)
655 + if (valid_hooks & ~NAT_VALID_HOOKS)
660 +static struct ebt_table frame_nat =
662 + {NULL, NULL}, "nat", &initial_table, NAT_VALID_HOOKS,
663 + RW_LOCK_UNLOCKED, check, NULL
667 +ebt_nat_dst(unsigned int hook, struct sk_buff **pskb, const struct net_device *in
668 + , const struct net_device *out, int (*okfn)(struct sk_buff *))
670 + return ebt_do_table(hook, pskb, in, out, &frame_nat);
674 +ebt_nat_src(unsigned int hook, struct sk_buff **pskb, const struct net_device *in
675 + , const struct net_device *out, int (*okfn)(struct sk_buff *))
677 + return ebt_do_table(hook, pskb, in, out, &frame_nat);
680 +static struct nf_hook_ops ebt_ops_nat[] = {
681 + { { NULL, NULL }, ebt_nat_dst, PF_BRIDGE, NF_BR_LOCAL_OUT,
682 + NF_BR_PRI_NAT_DST_OTHER},
683 + { { NULL, NULL }, ebt_nat_src, PF_BRIDGE, NF_BR_POST_ROUTING,
684 + NF_BR_PRI_NAT_SRC},
685 + { { NULL, NULL }, ebt_nat_dst, PF_BRIDGE, NF_BR_PRE_ROUTING,
686 + NF_BR_PRI_NAT_DST_BRIDGED},
689 +static int __init init(void)
693 + ret = ebt_register_table(&frame_nat);
696 + for (i = 0; i < sizeof(ebt_ops_nat) / sizeof(ebt_ops_nat[0]); i++)
697 + if ((ret = nf_register_hook(&ebt_ops_nat[i])) < 0)
701 + for (j = 0; j < i; j++)
702 + nf_unregister_hook(&ebt_ops_nat[j]);
703 + ebt_unregister_table(&frame_nat);
707 +static void __exit fini(void)
711 + for (i = 0; i < sizeof(ebt_ops_nat) / sizeof(ebt_ops_nat[0]); i++)
712 + nf_unregister_hook(&ebt_ops_nat[i]);
713 + ebt_unregister_table(&frame_nat);
719 +MODULE_LICENSE("GPL");
720 --- /dev/null 2005-09-22 15:53:13.374707688 +0000
721 +++ linux-2.4.31-ebt-brnf/net/bridge/netfilter/ebtable_broute.c 2005-09-15 16:57:23.000000000 +0000
727 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
731 + * This table lets you choose between routing and bridging for frames
732 + * entering on a bridge enslaved nic. This table is traversed before any
733 + * other ebtables table. See net/bridge/br_input.c.
736 +#include <linux/netfilter_bridge/ebtables.h>
737 +#include <linux/module.h>
738 +#include <linux/if_bridge.h>
739 +#include <linux/brlock.h>
741 +// EBT_ACCEPT means the frame will be bridged
742 +// EBT_DROP means the frame will be routed
743 +static struct ebt_entries initial_chain =
744 + {0, "BROUTING", 0, EBT_ACCEPT, 0};
746 +static struct ebt_replace initial_table =
748 + "broute", 1 << NF_BR_BROUTING, 0, sizeof(struct ebt_entries),
749 + { [NF_BR_BROUTING]&initial_chain}, 0, NULL, (char *)&initial_chain
752 +static int check(const struct ebt_table_info *info, unsigned int valid_hooks)
754 + if (valid_hooks & ~(1 << NF_BR_BROUTING))
759 +static struct ebt_table broute_table =
761 + {NULL, NULL}, "broute", &initial_table, 1 << NF_BR_BROUTING,
762 + RW_LOCK_UNLOCKED, check, NULL
765 +static int ebt_broute(struct sk_buff **pskb)
769 + ret = ebt_do_table(NF_BR_BROUTING, pskb, (*pskb)->dev, NULL,
771 + if (ret == NF_DROP)
772 + return 1; // route it
773 + return 0; // bridge it
776 +static int __init init(void)
780 + ret = ebt_register_table(&broute_table);
783 + br_write_lock_bh(BR_NETPROTO_LOCK);
785 + br_should_route_hook = ebt_broute;
786 + br_write_unlock_bh(BR_NETPROTO_LOCK);
790 +static void __exit fini(void)
792 + br_write_lock_bh(BR_NETPROTO_LOCK);
793 + br_should_route_hook = NULL;
794 + br_write_unlock_bh(BR_NETPROTO_LOCK);
795 + ebt_unregister_table(&broute_table);
801 +MODULE_LICENSE("GPL");
802 --- /dev/null 2005-09-22 15:53:13.374707688 +0000
803 +++ linux-2.4.31-ebt-brnf/net/bridge/netfilter/ebt_among.c 2005-09-15 16:57:23.000000000 +0000
809 + * Grzegorz Borowiak <grzes@gnu.univ.gda.pl>
815 +#include <linux/netfilter_bridge/ebtables.h>
816 +#include <linux/netfilter_bridge/ebt_among.h>
817 +#include <linux/ip.h>
818 +#include <linux/if_arp.h>
819 +#include <linux/module.h>
821 +static int ebt_mac_wormhash_contains(const struct ebt_mac_wormhash *wh,
822 + const char *mac, uint32_t ip)
824 + /* You may be puzzled as to how this code works.
825 + * Some tricks were used, refer to
826 + * include/linux/netfilter_bridge/ebt_among.h
827 + * as there you can find a solution of this mystery.
829 + const struct ebt_mac_wormhash_tuple *p;
830 + int start, limit, i;
831 + uint32_t cmp[2] = { 0, 0 };
832 + int key = (const unsigned char) mac[5];
834 + memcpy(((char *) cmp) + 2, mac, 6);
835 + start = wh->table[key];
836 + limit = wh->table[key + 1];
838 + for (i = start; i < limit; i++) {
840 + if (cmp[1] == p->cmp[1] && cmp[0] == p->cmp[0]) {
841 + if (p->ip == 0 || p->ip == ip) {
847 + for (i = start; i < limit; i++) {
849 + if (cmp[1] == p->cmp[1] && cmp[0] == p->cmp[0]) {
859 +static int ebt_mac_wormhash_check_integrity(const struct ebt_mac_wormhash
864 + for (i = 0; i < 256; i++) {
865 + if (wh->table[i] > wh->table[i + 1])
867 + if (wh->table[i] < 0)
869 + if (wh->table[i] > wh->poolsize)
872 + if (wh->table[256] > wh->poolsize)
877 +static int get_ip_dst(const struct sk_buff *skb, uint32_t * addr)
879 + if (skb->mac.ethernet->h_proto == __constant_htons(ETH_P_IP))
880 + *addr = skb->nh.iph->daddr;
881 + else if (skb->mac.ethernet->h_proto == __constant_htons(ETH_P_ARP)) {
882 + uint32_t arp_len = sizeof(struct arphdr) +
883 + (2 * (((*skb).nh.arph)->ar_hln)) +
884 + (2 * (((*skb).nh.arph)->ar_pln));
886 + /* Make sure the packet is long enough. */
887 + if ((((*skb).nh.raw) + arp_len) > (*skb).tail)
889 + /* IPv4 addresses are always 4 bytes. */
890 + if (((*skb).nh.arph)->ar_pln != sizeof(uint32_t))
893 + memcpy(addr, ((*skb).nh.raw) + sizeof(struct arphdr) +
894 + (2 * (((*skb).nh.arph)->ar_hln)) +
895 + (((*skb).nh.arph)->ar_pln), sizeof(uint32_t));
901 +static int get_ip_src(const struct sk_buff *skb, uint32_t * addr)
903 + if (skb->mac.ethernet->h_proto == __constant_htons(ETH_P_IP))
904 + *addr = skb->nh.iph->saddr;
905 + else if (skb->mac.ethernet->h_proto == __constant_htons(ETH_P_ARP)) {
906 + uint32_t arp_len = sizeof(struct arphdr) +
907 + (2 * (((*skb).nh.arph)->ar_hln)) +
908 + (2 * (((*skb).nh.arph)->ar_pln));
910 + /* Make sure the packet is long enough. */
911 + if ((((*skb).nh.raw) + arp_len) > (*skb).tail)
913 + /* IPv4 addresses are always 4 bytes. */
914 + if (((*skb).nh.arph)->ar_pln != sizeof(uint32_t))
917 + memcpy(addr, ((*skb).nh.raw) + sizeof(struct arphdr) +
918 + ((((*skb).nh.arph)->ar_hln)), sizeof(uint32_t));
924 +static int ebt_filter_among(const struct sk_buff *skb,
925 + const struct net_device *in,
926 + const struct net_device *out, const void *data,
927 + unsigned int datalen)
929 + struct ebt_among_info *info = (struct ebt_among_info *) data;
930 + const char *dmac, *smac;
931 + const struct ebt_mac_wormhash *wh_dst, *wh_src;
932 + uint32_t dip = 0, sip = 0;
934 + wh_dst = ebt_among_wh_dst(info);
935 + wh_src = ebt_among_wh_src(info);
938 + smac = skb->mac.ethernet->h_source;
939 + if (get_ip_src(skb, &sip))
940 + return EBT_NOMATCH;
941 + if (!(info->bitmask & EBT_AMONG_SRC_NEG)) {
942 + /* we match only if it contains */
943 + if (!ebt_mac_wormhash_contains(wh_src, smac, sip))
944 + return EBT_NOMATCH;
946 + /* we match only if it DOES NOT contain */
947 + if (ebt_mac_wormhash_contains(wh_src, smac, sip))
948 + return EBT_NOMATCH;
953 + dmac = skb->mac.ethernet->h_dest;
954 + if (get_ip_dst(skb, &dip))
955 + return EBT_NOMATCH;
956 + if (!(info->bitmask & EBT_AMONG_DST_NEG)) {
957 + /* we match only if it contains */
958 + if (!ebt_mac_wormhash_contains(wh_dst, dmac, dip))
959 + return EBT_NOMATCH;
961 + /* we match only if it DOES NOT contain */
962 + if (ebt_mac_wormhash_contains(wh_dst, dmac, dip))
963 + return EBT_NOMATCH;
970 +static int ebt_among_check(const char *tablename, unsigned int hookmask,
971 + const struct ebt_entry *e, void *data,
972 + unsigned int datalen)
974 + struct ebt_among_info *info = (struct ebt_among_info *) data;
975 + int expected_length = sizeof(struct ebt_among_info);
976 + const struct ebt_mac_wormhash *wh_dst, *wh_src;
979 + wh_dst = ebt_among_wh_dst(info);
980 + wh_src = ebt_among_wh_src(info);
981 + expected_length += ebt_mac_wormhash_size(wh_dst);
982 + expected_length += ebt_mac_wormhash_size(wh_src);
984 + if (datalen != EBT_ALIGN(expected_length)) {
985 + printk(KERN_WARNING
986 + "ebtables: among: wrong size: %d"
987 + "against expected %d, rounded to %d\n",
988 + datalen, expected_length,
989 + EBT_ALIGN(expected_length));
992 + if (wh_dst && (err = ebt_mac_wormhash_check_integrity(wh_dst))) {
993 + printk(KERN_WARNING
994 + "ebtables: among: dst integrity fail: %x\n", -err);
997 + if (wh_src && (err = ebt_mac_wormhash_check_integrity(wh_src))) {
998 + printk(KERN_WARNING
999 + "ebtables: among: src integrity fail: %x\n", -err);
1005 +static struct ebt_match filter_among = {
1014 +static int __init init(void)
1016 + return ebt_register_match(&filter_among);
1019 +static void __exit fini(void)
1021 + ebt_unregister_match(&filter_among);
1027 +MODULE_LICENSE("GPL");
1028 --- /dev/null 2005-09-22 15:53:13.374707688 +0000
1029 +++ linux-2.4.31-ebt-brnf/net/bridge/netfilter/ebt_limit.c 2005-09-15 16:57:23.000000000 +0000
1035 + * Tom Marshall <tommy@home.tig-grr.com>
1037 + * Mostly copied from netfilter's ipt_limit.c, see that file for explanation
1043 +#include <linux/netfilter_bridge/ebtables.h>
1044 +#include <linux/netfilter_bridge/ebt_limit.h>
1045 +#include <linux/module.h>
1047 +#include <linux/netdevice.h>
1048 +#include <linux/spinlock.h>
1050 +static spinlock_t limit_lock = SPIN_LOCK_UNLOCKED;
1052 +#define CREDITS_PER_JIFFY 128
1054 +static int ebt_limit_match(const struct sk_buff *skb, const struct net_device *in,
1055 + const struct net_device *out, const void *data, unsigned int datalen)
1057 + struct ebt_limit_info *info = (struct ebt_limit_info *)data;
1058 + unsigned long now = jiffies;
1060 + spin_lock_bh(&limit_lock);
1061 + info->credit += (now - xchg(&info->prev, now)) * CREDITS_PER_JIFFY;
1062 + if (info->credit > info->credit_cap)
1063 + info->credit = info->credit_cap;
1065 + if (info->credit >= info->cost) {
1066 + /* We're not limited. */
1067 + info->credit -= info->cost;
1068 + spin_unlock_bh(&limit_lock);
1072 + spin_unlock_bh(&limit_lock);
1073 + return EBT_NOMATCH;
1076 +/* Precision saver. */
1078 +user2credits(u_int32_t user)
1080 + /* If multiplying would overflow... */
1081 + if (user > 0xFFFFFFFF / (HZ*CREDITS_PER_JIFFY))
1082 + /* Divide first. */
1083 + return (user / EBT_LIMIT_SCALE) * HZ * CREDITS_PER_JIFFY;
1085 + return (user * HZ * CREDITS_PER_JIFFY) / EBT_LIMIT_SCALE;
1088 +static int ebt_limit_check(const char *tablename, unsigned int hookmask,
1089 + const struct ebt_entry *e, void *data, unsigned int datalen)
1091 + struct ebt_limit_info *info = (struct ebt_limit_info *)data;
1093 + if (datalen != EBT_ALIGN(sizeof(struct ebt_limit_info)))
1096 + /* Check for overflow. */
1097 + if (info->burst == 0
1098 + || user2credits(info->avg * info->burst) < user2credits(info->avg)) {
1099 + printk("Overflow in ebt_limit: %u/%u\n",
1100 + info->avg, info->burst);
1104 + /* User avg in seconds * EBT_LIMIT_SCALE: convert to jiffies * 128. */
1105 + info->prev = jiffies;
1106 + info->credit = user2credits(info->avg * info->burst);
1107 + info->credit_cap = user2credits(info->avg * info->burst);
1108 + info->cost = user2credits(info->avg);
1112 +static struct ebt_match ebt_limit_reg =
1114 + {NULL, NULL}, EBT_LIMIT_MATCH, ebt_limit_match, ebt_limit_check, NULL,
1118 +static int __init init(void)
1120 + return ebt_register_match(&ebt_limit_reg);
1123 +static void __exit fini(void)
1125 + ebt_unregister_match(&ebt_limit_reg);
1131 +MODULE_LICENSE("GPL");
1132 --- /dev/null 2005-09-22 15:53:13.374707688 +0000
1133 +++ linux-2.4.31-ebt-brnf/net/bridge/netfilter/ebt_arpreply.c 2005-09-15 16:57:23.000000000 +0000
1139 + * Grzegorz Borowiak <grzes@gnu.univ.gda.pl>
1140 + * Bart De Schuymer <bdschuym@pandora.be>
1146 +#include <linux/netfilter_bridge/ebtables.h>
1147 +#include <linux/netfilter_bridge/ebt_arpreply.h>
1148 +#include <linux/if_arp.h>
1149 +#include <net/arp.h>
1150 +#include <linux/module.h>
1152 +static int ebt_target_reply(struct sk_buff **pskb, unsigned int hooknr,
1153 + const struct net_device *in, const struct net_device *out,
1154 + const void *data, unsigned int datalen)
1156 + struct ebt_arpreply_info *info = (struct ebt_arpreply_info *)data;
1157 + struct arphdr *ah;
1158 + unsigned char *sha, *arp_ptr;
1161 + ah = (**pskb).nh.arph;
1162 + if (ah->ar_op != __constant_htons(ARPOP_REQUEST) ||
1163 + ah->ar_hln != ETH_ALEN || ah->ar_pro != htons(ETH_P_IP) ||
1165 + return EBT_CONTINUE;
1167 + arp_ptr = (unsigned char *)(ah + 1);
1169 + /* get source and target IP */
1171 + arp_ptr += ETH_ALEN;
1172 + memcpy(&sip, arp_ptr, 4);
1173 + arp_ptr += 4 + ETH_ALEN;
1174 + memcpy(&tip, arp_ptr, 4);
1176 + arp_send(ARPOP_REPLY, ETH_P_ARP, sip, in, tip, sha, info->mac, sha);
1178 + return info->target;
1181 +static int ebt_target_reply_check(const char *tablename, unsigned int hookmask,
1182 + const struct ebt_entry *e, void *data, unsigned int datalen)
1184 + struct ebt_arpreply_info *info = (struct ebt_arpreply_info *)data;
1186 + if (datalen != EBT_ALIGN(sizeof(struct ebt_arpreply_info)))
1188 + if (BASE_CHAIN && info->target == EBT_RETURN)
1190 + if (e->ethproto != __constant_htons(ETH_P_ARP) ||
1191 + e->invflags & EBT_IPROTO)
1193 + CLEAR_BASE_CHAIN_BIT;
1194 + if (strcmp(tablename, "nat") || hookmask & ~(1 << NF_BR_PRE_ROUTING))
1199 +static struct ebt_target reply_target =
1201 + .name = EBT_ARPREPLY_TARGET,
1202 + .target = ebt_target_reply,
1203 + .check = ebt_target_reply_check,
1204 + .me = THIS_MODULE,
1207 +static int __init init(void)
1209 + return ebt_register_target(&reply_target);
1212 +static void __exit fini(void)
1214 + ebt_unregister_target(&reply_target);
1220 +MODULE_LICENSE("GPL");
1221 --- /dev/null 2005-09-22 15:53:13.374707688 +0000
1222 +++ linux-2.4.31-ebt-brnf/net/bridge/netfilter/ebt_802_3.c 2005-09-15 16:57:23.000000000 +0000
1228 + * Chris Vitale csv@bluetail.com
1234 +#include <linux/netfilter_bridge/ebtables.h>
1235 +#include <linux/netfilter_bridge/ebt_802_3.h>
1236 +#include <linux/module.h>
1238 +static int ebt_filter_802_3(const struct sk_buff *skb, const struct net_device *in,
1239 + const struct net_device *out, const void *data, unsigned int datalen)
1241 + struct ebt_802_3_info *info = (struct ebt_802_3_info *)data;
1242 + struct ebt_802_3_hdr *hdr = (struct ebt_802_3_hdr *)skb->mac.ethernet;
1243 + uint16_t type = hdr->llc.ui.ctrl & IS_UI ? hdr->llc.ui.type : hdr->llc.ni.type;
1245 + if (info->bitmask & EBT_802_3_SAP) {
1246 + if (FWINV(info->sap != hdr->llc.ui.ssap, EBT_802_3_SAP))
1247 + return EBT_NOMATCH;
1248 + if (FWINV(info->sap != hdr->llc.ui.dsap, EBT_802_3_SAP))
1249 + return EBT_NOMATCH;
1252 + if (info->bitmask & EBT_802_3_TYPE) {
1253 + if (!(hdr->llc.ui.dsap == CHECK_TYPE && hdr->llc.ui.ssap == CHECK_TYPE))
1254 + return EBT_NOMATCH;
1255 + if (FWINV(info->type != type, EBT_802_3_TYPE))
1256 + return EBT_NOMATCH;
1262 +static struct ebt_match filter_802_3;
1263 +static int ebt_802_3_check(const char *tablename, unsigned int hookmask,
1264 + const struct ebt_entry *e, void *data, unsigned int datalen)
1266 + struct ebt_802_3_info *info = (struct ebt_802_3_info *)data;
1268 + if (datalen != EBT_ALIGN(sizeof(struct ebt_802_3_info)))
1270 + if (info->bitmask & ~EBT_802_3_MASK || info->invflags & ~EBT_802_3_MASK)
1276 +static struct ebt_match filter_802_3 =
1278 + .name = EBT_802_3_MATCH,
1279 + .match = ebt_filter_802_3,
1280 + .check = ebt_802_3_check,
1281 + .me = THIS_MODULE,
1284 +static int __init init(void)
1286 + return ebt_register_match(&filter_802_3);
1289 +static void __exit fini(void)
1291 + ebt_unregister_match(&filter_802_3);
1297 +MODULE_LICENSE("GPL");
1298 --- /dev/null 2005-09-22 15:53:13.374707688 +0000
1299 +++ linux-2.4.31-ebt-brnf/net/bridge/netfilter/ebt_mark.c 2005-09-15 16:57:23.000000000 +0000
1305 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
1311 +// The mark target can be used in any chain
1312 +// I believe adding a mangle table just for marking is total overkill
1313 +// Marking a frame doesn't really change anything in the frame anyway
1315 +#include <linux/netfilter_bridge/ebtables.h>
1316 +#include <linux/netfilter_bridge/ebt_mark_t.h>
1317 +#include <linux/module.h>
1319 +static int ebt_target_mark(struct sk_buff **pskb, unsigned int hooknr,
1320 + const struct net_device *in, const struct net_device *out,
1321 + const void *data, unsigned int datalen)
1323 + struct ebt_mark_t_info *info = (struct ebt_mark_t_info *)data;
1325 + if ((*pskb)->nfmark != info->mark) {
1326 + (*pskb)->nfmark = info->mark;
1327 + (*pskb)->nfcache |= NFC_ALTERED;
1329 + return info->target;
1332 +static int ebt_target_mark_check(const char *tablename, unsigned int hookmask,
1333 + const struct ebt_entry *e, void *data, unsigned int datalen)
1335 + struct ebt_mark_t_info *info = (struct ebt_mark_t_info *)data;
1337 + if (datalen != EBT_ALIGN(sizeof(struct ebt_mark_t_info)))
1339 + if (BASE_CHAIN && info->target == EBT_RETURN)
1341 + CLEAR_BASE_CHAIN_BIT;
1342 + if (INVALID_TARGET)
1347 +static struct ebt_target mark_target =
1349 + {NULL, NULL}, EBT_MARK_TARGET, ebt_target_mark,
1350 + ebt_target_mark_check, NULL, THIS_MODULE
1353 +static int __init init(void)
1355 + return ebt_register_target(&mark_target);
1358 +static void __exit fini(void)
1360 + ebt_unregister_target(&mark_target);
1366 +MODULE_LICENSE("GPL");
1367 --- /dev/null 2005-09-22 15:53:13.374707688 +0000
1368 +++ linux-2.4.31-ebt-brnf/net/bridge/netfilter/ebt_mark_m.c 2005-09-15 16:57:23.000000000 +0000
1374 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
1380 +#include <linux/netfilter_bridge/ebtables.h>
1381 +#include <linux/netfilter_bridge/ebt_mark_m.h>
1382 +#include <linux/module.h>
1384 +static int ebt_filter_mark(const struct sk_buff *skb,
1385 + const struct net_device *in, const struct net_device *out, const void *data,
1386 + unsigned int datalen)
1388 + struct ebt_mark_m_info *info = (struct ebt_mark_m_info *) data;
1390 + if (info->bitmask & EBT_MARK_OR)
1391 + return !(!!(skb->nfmark & info->mask) ^ info->invert);
1392 + return !(((skb->nfmark & info->mask) == info->mark) ^ info->invert);
1395 +static int ebt_mark_check(const char *tablename, unsigned int hookmask,
1396 + const struct ebt_entry *e, void *data, unsigned int datalen)
1398 + struct ebt_mark_m_info *info = (struct ebt_mark_m_info *) data;
1400 + if (datalen != EBT_ALIGN(sizeof(struct ebt_mark_m_info)))
1402 + if (info->bitmask & ~EBT_MARK_MASK)
1404 + if ((info->bitmask & EBT_MARK_OR) && (info->bitmask & EBT_MARK_AND))
1406 + if (!info->bitmask)
1411 +static struct ebt_match filter_mark =
1413 + {NULL, NULL}, EBT_MARK_MATCH, ebt_filter_mark, ebt_mark_check, NULL,
1417 +static int __init init(void)
1419 + return ebt_register_match(&filter_mark);
1422 +static void __exit fini(void)
1424 + ebt_unregister_match(&filter_mark);
1430 +MODULE_LICENSE("GPL");
1431 --- /dev/null 2005-09-22 15:53:13.374707688 +0000
1432 +++ linux-2.4.31-ebt-brnf/net/bridge/netfilter/ebt_pkttype.c 2005-09-15 16:57:23.000000000 +0000
1438 + * Bart De Schuymer <bdschuym@pandora.be>
1444 +#include <linux/netfilter_bridge/ebtables.h>
1445 +#include <linux/netfilter_bridge/ebt_pkttype.h>
1446 +#include <linux/module.h>
1448 +static int ebt_filter_pkttype(const struct sk_buff *skb,
1449 + const struct net_device *in,
1450 + const struct net_device *out,
1452 + unsigned int datalen)
1454 + struct ebt_pkttype_info *info = (struct ebt_pkttype_info *)data;
1456 + return (skb->pkt_type != info->pkt_type) ^ info->invert;
1459 +static int ebt_pkttype_check(const char *tablename, unsigned int hookmask,
1460 + const struct ebt_entry *e, void *data, unsigned int datalen)
1462 + struct ebt_pkttype_info *info = (struct ebt_pkttype_info *)data;
1464 + if (datalen != EBT_ALIGN(sizeof(struct ebt_pkttype_info)))
1466 + if (info->invert != 0 && info->invert != 1)
1468 + /* Allow any pkt_type value */
1472 +static struct ebt_match filter_pkttype =
1474 + .name = EBT_PKTTYPE_MATCH,
1475 + .match = ebt_filter_pkttype,
1476 + .check = ebt_pkttype_check,
1477 + .me = THIS_MODULE,
1480 +static int __init init(void)
1482 + return ebt_register_match(&filter_pkttype);
1485 +static void __exit fini(void)
1487 + ebt_unregister_match(&filter_pkttype);
1493 +MODULE_LICENSE("GPL");
1494 --- /dev/null 2005-09-22 15:53:13.374707688 +0000
1495 +++ linux-2.4.31-ebt-brnf/net/bridge/netfilter/ebt_stp.c 2005-09-15 16:57:23.000000000 +0000
1501 + * Bart De Schuymer <bdschuym@pandora.be>
1502 + * Stephen Hemminger <shemminger@osdl.org>
1507 +#include <linux/netfilter_bridge/ebtables.h>
1508 +#include <linux/netfilter_bridge/ebt_stp.h>
1509 +#include <linux/module.h>
1511 +#define BPDU_TYPE_CONFIG 0
1512 +#define BPDU_TYPE_TCN 0x80
1514 +struct stp_header {
1523 +struct stp_config_pdu {
1526 + uint8_t root_cost[4];
1527 + uint8_t sender[8];
1529 + uint8_t msg_age[2];
1530 + uint8_t max_age[2];
1531 + uint8_t hello_time[2];
1532 + uint8_t forward_delay[2];
1535 +#define NR16(p) (p[0] << 8 | p[1])
1536 +#define NR32(p) ((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3])
1538 +static int ebt_filter_config(struct ebt_stp_info *info,
1539 + struct stp_config_pdu *stpc)
1541 + struct ebt_stp_config_info *c;
1546 + c = &info->config;
1547 + if ((info->bitmask & EBT_STP_FLAGS) &&
1548 + FWINV(c->flags != stpc->flags, EBT_STP_FLAGS))
1549 + return EBT_NOMATCH;
1550 + if (info->bitmask & EBT_STP_ROOTPRIO) {
1551 + v16 = NR16(stpc->root);
1552 + if (FWINV(v16 < c->root_priol ||
1553 + v16 > c->root_priou, EBT_STP_ROOTPRIO))
1554 + return EBT_NOMATCH;
1556 + if (info->bitmask & EBT_STP_ROOTADDR) {
1558 + for (i = 0; i < 6; i++)
1559 + verdict |= (stpc->root[2+i] ^ c->root_addr[i]) &
1560 + c->root_addrmsk[i];
1561 + if (FWINV(verdict != 0, EBT_STP_ROOTADDR))
1562 + return EBT_NOMATCH;
1564 + if (info->bitmask & EBT_STP_ROOTCOST) {
1565 + v32 = NR32(stpc->root_cost);
1566 + if (FWINV(v32 < c->root_costl ||
1567 + v32 > c->root_costu, EBT_STP_ROOTCOST))
1568 + return EBT_NOMATCH;
1570 + if (info->bitmask & EBT_STP_SENDERPRIO) {
1571 + v16 = NR16(stpc->sender);
1572 + if (FWINV(v16 < c->sender_priol ||
1573 + v16 > c->sender_priou, EBT_STP_SENDERPRIO))
1574 + return EBT_NOMATCH;
1576 + if (info->bitmask & EBT_STP_SENDERADDR) {
1578 + for (i = 0; i < 6; i++)
1579 + verdict |= (stpc->sender[2+i] ^ c->sender_addr[i]) &
1580 + c->sender_addrmsk[i];
1581 + if (FWINV(verdict != 0, EBT_STP_SENDERADDR))
1582 + return EBT_NOMATCH;
1584 + if (info->bitmask & EBT_STP_PORT) {
1585 + v16 = NR16(stpc->port);
1586 + if (FWINV(v16 < c->portl ||
1587 + v16 > c->portu, EBT_STP_PORT))
1588 + return EBT_NOMATCH;
1590 + if (info->bitmask & EBT_STP_MSGAGE) {
1591 + v16 = NR16(stpc->msg_age);
1592 + if (FWINV(v16 < c->msg_agel ||
1593 + v16 > c->msg_ageu, EBT_STP_MSGAGE))
1594 + return EBT_NOMATCH;
1596 + if (info->bitmask & EBT_STP_MAXAGE) {
1597 + v16 = NR16(stpc->max_age);
1598 + if (FWINV(v16 < c->max_agel ||
1599 + v16 > c->max_ageu, EBT_STP_MAXAGE))
1600 + return EBT_NOMATCH;
1602 + if (info->bitmask & EBT_STP_HELLOTIME) {
1603 + v16 = NR16(stpc->hello_time);
1604 + if (FWINV(v16 < c->hello_timel ||
1605 + v16 > c->hello_timeu, EBT_STP_HELLOTIME))
1606 + return EBT_NOMATCH;
1608 + if (info->bitmask & EBT_STP_FWDD) {
1609 + v16 = NR16(stpc->forward_delay);
1610 + if (FWINV(v16 < c->forward_delayl ||
1611 + v16 > c->forward_delayu, EBT_STP_FWDD))
1612 + return EBT_NOMATCH;
1617 +static int ebt_filter_stp(const struct sk_buff *skb, const struct net_device *in,
1618 + const struct net_device *out, const void *data, unsigned int datalen)
1620 + struct ebt_stp_info *info = (struct ebt_stp_info *)data;
1621 + struct stp_header stph;
1622 + uint8_t header[6] = {0x42, 0x42, 0x03, 0x00, 0x00, 0x00};
1623 + if (skb_copy_bits(skb, 0, &stph, sizeof(stph)))
1624 + return EBT_NOMATCH;
1626 + /* The stp code only considers these */
1627 + if (memcmp(&stph, header, sizeof(header)))
1628 + return EBT_NOMATCH;
1630 + if (info->bitmask & EBT_STP_TYPE
1631 + && FWINV(info->type != stph.type, EBT_STP_TYPE))
1632 + return EBT_NOMATCH;
1634 + if (stph.type == BPDU_TYPE_CONFIG &&
1635 + info->bitmask & EBT_STP_CONFIG_MASK) {
1636 + struct stp_config_pdu stpc;
1638 + if (skb_copy_bits(skb, sizeof(stph), &stpc, sizeof(stpc)))
1639 + return EBT_NOMATCH;
1640 + return ebt_filter_config(info, &stpc);
1645 +static int ebt_stp_check(const char *tablename, unsigned int hookmask,
1646 + const struct ebt_entry *e, void *data, unsigned int datalen)
1648 + struct ebt_stp_info *info = (struct ebt_stp_info *)data;
1649 + int len = EBT_ALIGN(sizeof(struct ebt_stp_info));
1650 + uint8_t bridge_ula[6] = { 0x01, 0x80, 0xc2, 0x00, 0x00, 0x00 };
1651 + uint8_t msk[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
1653 + if (info->bitmask & ~EBT_STP_MASK || info->invflags & ~EBT_STP_MASK ||
1654 + !(info->bitmask & EBT_STP_MASK))
1656 + if (datalen != len)
1658 + /* Make sure the match only receives stp frames */
1659 + if (memcmp(e->destmac, bridge_ula, ETH_ALEN) ||
1660 + memcmp(e->destmsk, msk, ETH_ALEN) || !(e->bitmask & EBT_DESTMAC))
1666 +static struct ebt_match filter_stp =
1668 + .name = EBT_STP_MATCH,
1669 + .match = ebt_filter_stp,
1670 + .check = ebt_stp_check,
1671 + .me = THIS_MODULE,
1674 +static int __init init(void)
1676 + return ebt_register_match(&filter_stp);
1679 +static void __exit fini(void)
1681 + ebt_unregister_match(&filter_stp);
1687 +MODULE_LICENSE("GPL");
1688 --- /dev/null 2005-09-22 15:53:13.374707688 +0000
1689 +++ linux-2.4.31-ebt-brnf/net/bridge/netfilter/ebt_redirect.c 2005-09-15 16:57:23.000000000 +0000
1695 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
1701 +#include <linux/netfilter_bridge/ebtables.h>
1702 +#include <linux/netfilter_bridge/ebt_redirect.h>
1703 +#include <linux/module.h>
1704 +#include <net/sock.h>
1705 +#include "../br_private.h"
1707 +static int ebt_target_redirect(struct sk_buff **pskb, unsigned int hooknr,
1708 + const struct net_device *in, const struct net_device *out,
1709 + const void *data, unsigned int datalen)
1711 + struct ebt_redirect_info *info = (struct ebt_redirect_info *)data;
1713 + if (hooknr != NF_BR_BROUTING)
1714 + memcpy((**pskb).mac.ethernet->h_dest,
1715 + in->br_port->br->dev.dev_addr, ETH_ALEN);
1717 + memcpy((**pskb).mac.ethernet->h_dest,
1718 + in->dev_addr, ETH_ALEN);
1719 + (*pskb)->pkt_type = PACKET_HOST;
1721 + return info->target;
1724 +static int ebt_target_redirect_check(const char *tablename, unsigned int hookmask,
1725 + const struct ebt_entry *e, void *data, unsigned int datalen)
1727 + struct ebt_redirect_info *info = (struct ebt_redirect_info *)data;
1729 + if (datalen != EBT_ALIGN(sizeof(struct ebt_redirect_info)))
1731 + if (BASE_CHAIN && info->target == EBT_RETURN)
1733 + CLEAR_BASE_CHAIN_BIT;
1734 + if ( (strcmp(tablename, "nat") || hookmask & ~(1 << NF_BR_PRE_ROUTING)) &&
1735 + (strcmp(tablename, "broute") || hookmask & ~(1 << NF_BR_BROUTING)) )
1737 + if (INVALID_TARGET)
1742 +static struct ebt_target redirect_target =
1744 + {NULL, NULL}, EBT_REDIRECT_TARGET, ebt_target_redirect,
1745 + ebt_target_redirect_check, NULL, THIS_MODULE
1748 +static int __init init(void)
1750 + return ebt_register_target(&redirect_target);
1753 +static void __exit fini(void)
1755 + ebt_unregister_target(&redirect_target);
1761 +MODULE_LICENSE("GPL");
1762 --- /dev/null 2005-09-22 15:53:13.374707688 +0000
1763 +++ linux-2.4.31-ebt-brnf/net/bridge/netfilter/ebt_arp.c 2005-09-15 16:57:23.000000000 +0000
1769 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
1770 + * Tim Gardner <timg@tpi.com>
1776 +#include <linux/netfilter_bridge/ebtables.h>
1777 +#include <linux/netfilter_bridge/ebt_arp.h>
1778 +#include <linux/if_arp.h>
1779 +#include <linux/if_ether.h>
1780 +#include <linux/module.h>
1782 +static int ebt_filter_arp(const struct sk_buff *skb, const struct net_device *in,
1783 + const struct net_device *out, const void *data, unsigned int datalen)
1785 + struct ebt_arp_info *info = (struct ebt_arp_info *)data;
1787 + if (info->bitmask & EBT_ARP_OPCODE && FWINV(info->opcode !=
1788 + ((*skb).nh.arph)->ar_op, EBT_ARP_OPCODE))
1789 + return EBT_NOMATCH;
1790 + if (info->bitmask & EBT_ARP_HTYPE && FWINV(info->htype !=
1791 + ((*skb).nh.arph)->ar_hrd, EBT_ARP_HTYPE))
1792 + return EBT_NOMATCH;
1793 + if (info->bitmask & EBT_ARP_PTYPE && FWINV(info->ptype !=
1794 + ((*skb).nh.arph)->ar_pro, EBT_ARP_PTYPE))
1795 + return EBT_NOMATCH;
1797 + if (info->bitmask & (EBT_ARP_SRC_IP | EBT_ARP_DST_IP))
1799 + uint32_t arp_len = sizeof(struct arphdr) +
1800 + (2 * (((*skb).nh.arph)->ar_hln)) +
1801 + (2 * (((*skb).nh.arph)->ar_pln));
1805 + // Make sure the packet is long enough.
1806 + if ((((*skb).nh.raw) + arp_len) > (*skb).tail)
1807 + return EBT_NOMATCH;
1808 + // IPv4 addresses are always 4 bytes.
1809 + if (((*skb).nh.arph)->ar_pln != sizeof(uint32_t))
1810 + return EBT_NOMATCH;
1812 + if (info->bitmask & EBT_ARP_SRC_IP) {
1813 + memcpy(&src, ((*skb).nh.raw) + sizeof(struct arphdr) +
1814 + ((*skb).nh.arph)->ar_hln, sizeof(uint32_t));
1815 + if (FWINV(info->saddr != (src & info->smsk),
1817 + return EBT_NOMATCH;
1820 + if (info->bitmask & EBT_ARP_DST_IP) {
1821 + memcpy(&dst, ((*skb).nh.raw)+sizeof(struct arphdr) +
1822 + (2*(((*skb).nh.arph)->ar_hln)) +
1823 + (((*skb).nh.arph)->ar_pln), sizeof(uint32_t));
1824 + if (FWINV(info->daddr != (dst & info->dmsk),
1826 + return EBT_NOMATCH;
1830 + if (info->bitmask & (EBT_ARP_SRC_MAC | EBT_ARP_DST_MAC))
1832 + uint32_t arp_len = sizeof(struct arphdr) +
1833 + (2 * (((*skb).nh.arph)->ar_hln)) +
1834 + (2 * (((*skb).nh.arph)->ar_pln));
1835 + unsigned char dst[ETH_ALEN];
1836 + unsigned char src[ETH_ALEN];
1838 + // Make sure the packet is long enough.
1839 + if ((((*skb).nh.raw) + arp_len) > (*skb).tail)
1840 + return EBT_NOMATCH;
1841 + // MAC addresses are 6 bytes.
1842 + if (((*skb).nh.arph)->ar_hln != ETH_ALEN)
1843 + return EBT_NOMATCH;
1844 + if (info->bitmask & EBT_ARP_SRC_MAC) {
1845 + uint8_t verdict, i;
1847 + memcpy(&src, ((*skb).nh.raw) +
1848 + sizeof(struct arphdr),
1851 + for (i = 0; i < 6; i++)
1852 + verdict |= (src[i] ^ info->smaddr[i]) &
1854 + if (FWINV(verdict != 0, EBT_ARP_SRC_MAC))
1855 + return EBT_NOMATCH;
1858 + if (info->bitmask & EBT_ARP_DST_MAC) {
1859 + uint8_t verdict, i;
1861 + memcpy(&dst, ((*skb).nh.raw) +
1862 + sizeof(struct arphdr) +
1863 + (((*skb).nh.arph)->ar_hln) +
1864 + (((*skb).nh.arph)->ar_pln),
1867 + for (i = 0; i < 6; i++)
1868 + verdict |= (dst[i] ^ info->dmaddr[i]) &
1870 + if (FWINV(verdict != 0, EBT_ARP_DST_MAC))
1871 + return EBT_NOMATCH;
1878 +static int ebt_arp_check(const char *tablename, unsigned int hookmask,
1879 + const struct ebt_entry *e, void *data, unsigned int datalen)
1881 + struct ebt_arp_info *info = (struct ebt_arp_info *)data;
1883 + if (datalen != EBT_ALIGN(sizeof(struct ebt_arp_info)))
1885 + if ((e->ethproto != __constant_htons(ETH_P_ARP) &&
1886 + e->ethproto != __constant_htons(ETH_P_RARP)) ||
1887 + e->invflags & EBT_IPROTO)
1889 + if (info->bitmask & ~EBT_ARP_MASK || info->invflags & ~EBT_ARP_MASK)
1894 +static struct ebt_match filter_arp =
1896 + {NULL, NULL}, EBT_ARP_MATCH, ebt_filter_arp, ebt_arp_check, NULL,
1900 +static int __init init(void)
1902 + return ebt_register_match(&filter_arp);
1905 +static void __exit fini(void)
1907 + ebt_unregister_match(&filter_arp);
1913 +MODULE_LICENSE("GPL");
1914 --- /dev/null 2005-09-22 15:53:13.374707688 +0000
1915 +++ linux-2.4.31-ebt-brnf/net/bridge/netfilter/ebt_ip.c 2005-09-15 16:57:23.000000000 +0000
1921 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
1926 + * added ip-sport and ip-dport
1927 + * Innominate Security Technologies AG <mhopf@innominate.com>
1931 +#include <linux/netfilter_bridge/ebtables.h>
1932 +#include <linux/netfilter_bridge/ebt_ip.h>
1933 +#include <linux/ip.h>
1934 +#include <linux/in.h>
1935 +#include <linux/module.h>
1943 + unsigned char *raw;
1944 + struct tcpudphdr *tuh;
1947 +static int ebt_filter_ip(const struct sk_buff *skb, const struct net_device *in,
1948 + const struct net_device *out, const void *data,
1949 + unsigned int datalen)
1951 + struct ebt_ip_info *info = (struct ebt_ip_info *)data;
1953 + if (info->bitmask & EBT_IP_TOS &&
1954 + FWINV(info->tos != ((*skb).nh.iph)->tos, EBT_IP_TOS))
1955 + return EBT_NOMATCH;
1956 + if (info->bitmask & EBT_IP_PROTO) {
1957 + if (FWINV(info->protocol != ((*skb).nh.iph)->protocol,
1959 + return EBT_NOMATCH;
1960 + if ( info->protocol == IPPROTO_TCP ||
1961 + info->protocol == IPPROTO_UDP )
1964 + h.raw = skb->data + skb->nh.iph->ihl*4;
1965 + if (info->bitmask & EBT_IP_DPORT) {
1966 + uint16_t port = ntohs(h.tuh->dst);
1967 + if (FWINV(port < info->dport[0] ||
1968 + port > info->dport[1],
1970 + return EBT_NOMATCH;
1972 + if (info->bitmask & EBT_IP_SPORT) {
1973 + uint16_t port = ntohs(h.tuh->src);
1974 + if (FWINV(port < info->sport[0] ||
1975 + port > info->sport[1],
1977 + return EBT_NOMATCH;
1981 + if (info->bitmask & EBT_IP_SOURCE &&
1982 + FWINV((((*skb).nh.iph)->saddr & info->smsk) !=
1983 + info->saddr, EBT_IP_SOURCE))
1984 + return EBT_NOMATCH;
1985 + if ((info->bitmask & EBT_IP_DEST) &&
1986 + FWINV((((*skb).nh.iph)->daddr & info->dmsk) !=
1987 + info->daddr, EBT_IP_DEST))
1988 + return EBT_NOMATCH;
1992 +static int ebt_ip_check(const char *tablename, unsigned int hookmask,
1993 + const struct ebt_entry *e, void *data, unsigned int datalen)
1995 + struct ebt_ip_info *info = (struct ebt_ip_info *)data;
1997 + if (datalen != EBT_ALIGN(sizeof(struct ebt_ip_info)))
1999 + if (e->ethproto != __constant_htons(ETH_P_IP) ||
2000 + e->invflags & EBT_IPROTO)
2002 + if (info->bitmask & ~EBT_IP_MASK || info->invflags & ~EBT_IP_MASK)
2004 + if (info->bitmask & (EBT_IP_DPORT | EBT_IP_SPORT)) {
2005 + if (!info->bitmask & EBT_IPROTO)
2007 + if (info->protocol != IPPROTO_TCP &&
2008 + info->protocol != IPPROTO_UDP)
2011 + if (info->bitmask & EBT_IP_DPORT && info->dport[0] > info->dport[1])
2013 + if (info->bitmask & EBT_IP_SPORT && info->sport[0] > info->sport[1])
2018 +static struct ebt_match filter_ip =
2020 + {NULL, NULL}, EBT_IP_MATCH, ebt_filter_ip, ebt_ip_check, NULL,
2024 +static int __init init(void)
2026 + return ebt_register_match(&filter_ip);
2029 +static void __exit fini(void)
2031 + ebt_unregister_match(&filter_ip);
2037 +MODULE_LICENSE("GPL");
2038 --- /dev/null 2005-09-22 15:53:13.374707688 +0000
2039 +++ linux-2.4.31-ebt-brnf/net/bridge/netfilter/ebt_vlan.c 2005-09-15 16:57:23.000000000 +0000
2042 + * Description: EBTables 802.1Q match extension kernelspace module.
2043 + * Authors: Nick Fedchik <nick@fedchik.org.ua>
2044 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
2046 + * This program is free software; you can redistribute it and/or modify
2047 + * it under the terms of the GNU General Public License as published by
2048 + * the Free Software Foundation; either version 2 of the License, or
2049 + * (at your option) any later version.
2051 + * This program is distributed in the hope that it will be useful,
2052 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2053 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2054 + * GNU General Public License for more details.
2056 + * You should have received a copy of the GNU General Public License
2057 + * along with this program; if not, write to the Free Software
2058 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2061 +#include <linux/if_ether.h>
2062 +#include <linux/if_vlan.h>
2063 +#include <linux/module.h>
2064 +#include <linux/netfilter_bridge/ebtables.h>
2065 +#include <linux/netfilter_bridge/ebt_vlan.h>
2067 +static unsigned char debug;
2068 +#define MODULE_VERSION "0.6"
2070 +MODULE_PARM(debug, "0-1b");
2071 +MODULE_PARM_DESC(debug, "debug=1 is turn on debug messages");
2072 +MODULE_AUTHOR("Nick Fedchik <nick@fedchik.org.ua>");
2073 +MODULE_DESCRIPTION("802.1Q match module (ebtables extension), v"
2075 +MODULE_LICENSE("GPL");
2078 +#define DEBUG_MSG(args...) if (debug) printk (KERN_DEBUG "ebt_vlan: " args)
2079 +#define INV_FLAG(_inv_flag_) (info->invflags & _inv_flag_) ? "!" : ""
2080 +#define GET_BITMASK(_BIT_MASK_) info->bitmask & _BIT_MASK_
2081 +#define SET_BITMASK(_BIT_MASK_) info->bitmask |= _BIT_MASK_
2082 +#define EXIT_ON_MISMATCH(_MATCH_,_MASK_) if (!((info->_MATCH_ == _MATCH_)^!!(info->invflags & _MASK_))) return 1;
2085 + * Function description: ebt_filter_vlan() is main engine for
2086 + * checking passed 802.1Q frame according to
2087 + * the passed extension parameters (in the *data buffer)
2088 + * ebt_filter_vlan() is called after successfull check the rule params
2089 + * by ebt_check_vlan() function.
2091 + * const struct sk_buff *skb - pointer to passed ethernet frame buffer
2092 + * const void *data - pointer to passed extension parameters
2093 + * unsigned int datalen - length of passed *data buffer
2094 + * const struct net_device *in -
2095 + * const struct net_device *out -
2096 + * const struct ebt_counter *c -
2097 + * Returned values:
2098 + * 0 - ok (all rule params matched)
2099 + * 1 - miss (rule params not acceptable to the parsed frame)
2102 +ebt_filter_vlan(const struct sk_buff *skb,
2103 + const struct net_device *in,
2104 + const struct net_device *out,
2105 + const void *data, unsigned int datalen)
2107 + struct ebt_vlan_info *info = (struct ebt_vlan_info *) data; /* userspace data */
2108 + struct vlan_ethhdr *frame = (struct vlan_ethhdr *) skb->mac.raw; /* Passed tagged frame */
2110 + unsigned short TCI; /* Whole TCI, given from parsed frame */
2111 + unsigned short id; /* VLAN ID, given from frame TCI */
2112 + unsigned char prio; /* user_priority, given from frame TCI */
2113 + unsigned short encap; /* VLAN encapsulated Type/Length field, given from orig frame */
2116 + * Tag Control Information (TCI) consists of the following elements:
2117 + * - User_priority. The user_priority field is three bits in length,
2118 + * interpreted as a binary number.
2119 + * - Canonical Format Indicator (CFI). The Canonical Format Indicator
2120 + * (CFI) is a single bit flag value. Currently ignored.
2121 + * - VLAN Identifier (VID). The VID is encoded as
2122 + * an unsigned binary number.
2124 + TCI = ntohs(frame->h_vlan_TCI);
2125 + id = TCI & VLAN_VID_MASK;
2126 + prio = (TCI >> 13) & 0x7;
2127 + encap = frame->h_vlan_encapsulated_proto;
2130 + * Checking VLAN Identifier (VID)
2132 + if (GET_BITMASK(EBT_VLAN_ID)) { /* Is VLAN ID parsed? */
2133 + EXIT_ON_MISMATCH(id, EBT_VLAN_ID);
2136 + * Checking user_priority
2138 + if (GET_BITMASK(EBT_VLAN_PRIO)) { /* Is VLAN user_priority parsed? */
2139 + EXIT_ON_MISMATCH(prio, EBT_VLAN_PRIO);
2142 + * Checking Encapsulated Proto (Length/Type) field
2144 + if (GET_BITMASK(EBT_VLAN_ENCAP)) { /* Is VLAN Encap parsed? */
2145 + EXIT_ON_MISMATCH(encap, EBT_VLAN_ENCAP);
2148 + * All possible extension parameters was parsed.
2149 + * If rule never returned by missmatch, then all ok.
2155 + * Function description: ebt_vlan_check() is called when userspace
2156 + * delivers the table entry to the kernel,
2157 + * and to check that userspace doesn't give a bad table.
2159 + * const char *tablename - table name string
2160 + * unsigned int hooknr - hook number
2161 + * const struct ebt_entry *e - ebtables entry basic set
2162 + * const void *data - pointer to passed extension parameters
2163 + * unsigned int datalen - length of passed *data buffer
2164 + * Returned values:
2165 + * 0 - ok (all delivered rule params are correct)
2166 + * 1 - miss (rule params is out of range, invalid, incompatible, etc.)
2169 +ebt_check_vlan(const char *tablename,
2170 + unsigned int hooknr,
2171 + const struct ebt_entry *e, void *data, unsigned int datalen)
2173 + struct ebt_vlan_info *info = (struct ebt_vlan_info *) data;
2176 + * Parameters buffer overflow check
2178 + if (datalen != EBT_ALIGN(sizeof(struct ebt_vlan_info))) {
2180 + ("passed size %d is not eq to ebt_vlan_info (%d)\n",
2181 + datalen, sizeof(struct ebt_vlan_info));
2186 + * Is it 802.1Q frame checked?
2188 + if (e->ethproto != __constant_htons(ETH_P_8021Q)) {
2190 + ("passed entry proto %2.4X is not 802.1Q (8100)\n",
2191 + (unsigned short) ntohs(e->ethproto));
2196 + * Check for bitmask range
2197 + * True if even one bit is out of mask
2199 + if (info->bitmask & ~EBT_VLAN_MASK) {
2200 + DEBUG_MSG("bitmask %2X is out of mask (%2X)\n",
2201 + info->bitmask, EBT_VLAN_MASK);
2206 + * Check for inversion flags range
2208 + if (info->invflags & ~EBT_VLAN_MASK) {
2209 + DEBUG_MSG("inversion flags %2X is out of mask (%2X)\n",
2210 + info->invflags, EBT_VLAN_MASK);
2215 + * Reserved VLAN ID (VID) values
2216 + * -----------------------------
2217 + * 0 - The null VLAN ID.
2218 + * 1 - The default Port VID (PVID)
2219 + * 0x0FFF - Reserved for implementation use.
2220 + * if_vlan.h: VLAN_GROUP_ARRAY_LEN 4096.
2222 + if (GET_BITMASK(EBT_VLAN_ID)) { /* when vlan-id param was spec-ed */
2223 + if (!!info->id) { /* if id!=0 => check vid range */
2224 + if (info->id > VLAN_GROUP_ARRAY_LEN) {
2226 + ("id %d is out of range (1-4096)\n",
2231 + * Note: This is valid VLAN-tagged frame point.
2232 + * Any value of user_priority are acceptable,
2233 + * but should be ignored according to 802.1Q Std.
2234 + * So we just drop the prio flag.
2236 + info->bitmask &= ~EBT_VLAN_PRIO;
2239 + * Else, id=0 (null VLAN ID) => user_priority range (any?)
2243 + if (GET_BITMASK(EBT_VLAN_PRIO)) {
2244 + if ((unsigned char) info->prio > 7) {
2246 + ("prio %d is out of range (0-7)\n",
2252 + * Check for encapsulated proto range - it is possible to be
2253 + * any value for u_short range.
2254 + * if_ether.h: ETH_ZLEN 60 - Min. octets in frame sans FCS
2256 + if (GET_BITMASK(EBT_VLAN_ENCAP)) {
2257 + if ((unsigned short) ntohs(info->encap) < ETH_ZLEN) {
2259 + ("encap frame length %d is less than minimal\n",
2260 + ntohs(info->encap));
2268 +static struct ebt_match filter_vlan = {
2278 + * Module initialization function.
2280 +static int __init init(void)
2282 + DEBUG_MSG("ebtables 802.1Q extension module v"
2283 + MODULE_VERSION "\n");
2284 + DEBUG_MSG("module debug=%d\n", !!debug);
2285 + return ebt_register_match(&filter_vlan);
2289 + * Module "finalization" function
2291 +static void __exit fini(void)
2293 + ebt_unregister_match(&filter_vlan);
2300 --- /dev/null 2005-09-22 15:53:13.374707688 +0000
2301 +++ linux-2.4.31-ebt-brnf/net/bridge/netfilter/ebt_log.c 2005-09-15 16:57:23.000000000 +0000
2307 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
2313 +#include <linux/netfilter_bridge/ebtables.h>
2314 +#include <linux/netfilter_bridge/ebt_log.h>
2315 +#include <linux/module.h>
2316 +#include <linux/ip.h>
2317 +#include <linux/in.h>
2318 +#include <linux/if_arp.h>
2319 +#include <linux/spinlock.h>
2321 +static spinlock_t ebt_log_lock = SPIN_LOCK_UNLOCKED;
2323 +static int ebt_log_check(const char *tablename, unsigned int hookmask,
2324 + const struct ebt_entry *e, void *data, unsigned int datalen)
2326 + struct ebt_log_info *info = (struct ebt_log_info *)data;
2328 + if (datalen != EBT_ALIGN(sizeof(struct ebt_log_info)))
2330 + if (info->bitmask & ~EBT_LOG_MASK)
2332 + if (info->loglevel >= 8)
2334 + info->prefix[EBT_LOG_PREFIX_SIZE - 1] = '\0';
2346 + unsigned char mac_src[ETH_ALEN];
2347 + unsigned char ip_src[4];
2348 + unsigned char mac_dst[ETH_ALEN];
2349 + unsigned char ip_dst[4];
2352 +static void print_MAC(unsigned char *p)
2356 + for (i = 0; i < ETH_ALEN; i++, p++)
2357 + printk("%02x%c", *p, i == ETH_ALEN - 1 ? ' ':':');
2360 +#define myNIPQUAD(a) a[0], a[1], a[2], a[3]
2361 +static void ebt_log(const struct sk_buff *skb, unsigned int hooknr,
2362 + const struct net_device *in, const struct net_device *out,
2363 + const void *data, unsigned int datalen)
2365 + struct ebt_log_info *info = (struct ebt_log_info *)data;
2366 + char level_string[4] = "< >";
2367 + level_string[1] = '0' + info->loglevel;
2369 + spin_lock_bh(&ebt_log_lock);
2370 + printk(level_string);
2371 + printk("%s IN=%s OUT=%s ", info->prefix, in ? in->name : "",
2372 + out ? out->name : "");
2374 + printk("MAC source = ");
2375 + print_MAC((skb->mac.ethernet)->h_source);
2376 + printk("MAC dest = ");
2377 + print_MAC((skb->mac.ethernet)->h_dest);
2379 + printk("proto = 0x%04x", ntohs(((*skb).mac.ethernet)->h_proto));
2381 + if ((info->bitmask & EBT_LOG_IP) && skb->mac.ethernet->h_proto ==
2383 + struct iphdr *iph = skb->nh.iph;
2384 + printk(" IP SRC=%u.%u.%u.%u IP DST=%u.%u.%u.%u,",
2385 + NIPQUAD(iph->saddr), NIPQUAD(iph->daddr));
2386 + printk(" IP tos=0x%02X, IP proto=%d", iph->tos, iph->protocol);
2387 + if (iph->protocol == IPPROTO_TCP ||
2388 + iph->protocol == IPPROTO_UDP) {
2389 + struct tcpudphdr *ports = (struct tcpudphdr *)(skb->data + iph->ihl*4);
2391 + if (skb->data + iph->ihl*4 > skb->tail) {
2392 + printk(" INCOMPLETE TCP/UDP header");
2395 + printk(" SPT=%u DPT=%u", ntohs(ports->src),
2396 + ntohs(ports->dst));
2401 + if ((info->bitmask & EBT_LOG_ARP) &&
2402 + ((skb->mac.ethernet->h_proto == __constant_htons(ETH_P_ARP)) ||
2403 + (skb->mac.ethernet->h_proto == __constant_htons(ETH_P_RARP)))) {
2404 + struct arphdr * arph = skb->nh.arph;
2405 + printk(" ARP HTYPE=%d, PTYPE=0x%04x, OPCODE=%d",
2406 + ntohs(arph->ar_hrd), ntohs(arph->ar_pro),
2407 + ntohs(arph->ar_op));
2408 + /* If it's for Ethernet and the lengths are OK,
2409 + * then log the ARP payload */
2410 + if (arph->ar_hrd == __constant_htons(1) &&
2411 + arph->ar_hln == ETH_ALEN &&
2412 + arph->ar_pln == sizeof(uint32_t)) {
2413 + struct arppayload *arpp = (struct arppayload *)(skb->data + sizeof(*arph));
2415 + if (skb->data + sizeof(*arph) > skb->tail) {
2416 + printk(" INCOMPLETE ARP header");
2420 + printk(" ARP MAC SRC=");
2421 + print_MAC(arpp->mac_src);
2422 + printk(" ARP IP SRC=%u.%u.%u.%u",
2423 + myNIPQUAD(arpp->ip_src));
2424 + printk(" ARP MAC DST=");
2425 + print_MAC(arpp->mac_dst);
2426 + printk(" ARP IP DST=%u.%u.%u.%u",
2427 + myNIPQUAD(arpp->ip_dst));
2433 + spin_unlock_bh(&ebt_log_lock);
2436 +static struct ebt_watcher log =
2438 + {NULL, NULL}, EBT_LOG_WATCHER, ebt_log, ebt_log_check, NULL,
2442 +static int __init init(void)
2444 + return ebt_register_watcher(&log);
2447 +static void __exit fini(void)
2449 + ebt_unregister_watcher(&log);
2455 +MODULE_LICENSE("GPL");
2456 --- /dev/null 2005-09-22 15:53:13.374707688 +0000
2457 +++ linux-2.4.31-ebt-brnf/net/bridge/netfilter/ebt_ulog.c 2005-09-15 16:57:23.000000000 +0000
2460 + * netfilter module for userspace bridged Ethernet frames logging daemons
2463 + * Bart De Schuymer <bdschuym@pandora.be>
2467 + * Based on ipt_ULOG.c, which is
2468 + * (C) 2000-2002 by Harald Welte <laforge@netfilter.org>
2470 + * This module accepts two parameters:
2473 + * The parameter specifies how big the buffer for each netlink multicast
2474 + * group is. e.g. If you say nlbufsiz=8192, up to eight kb of packets will
2475 + * get accumulated in the kernel until they are sent to userspace. It is
2476 + * NOT possible to allocate more than 128kB, and it is strongly discouraged,
2477 + * because atomically allocating 128kB inside the network rx softirq is not
2478 + * reliable. Please also keep in mind that this buffer size is allocated for
2479 + * each nlgroup you are using, so the total kernel memory usage increases
2483 + * Specify, after how many hundredths of a second the queue should be
2484 + * flushed even if it is not full yet.
2488 +#include <linux/module.h>
2489 +#include <linux/config.h>
2490 +#include <linux/spinlock.h>
2491 +#include <linux/socket.h>
2492 +#include <linux/skbuff.h>
2493 +#include <linux/kernel.h>
2494 +#include <linux/timer.h>
2495 +#include <linux/netlink.h>
2496 +#include <linux/netdevice.h>
2497 +#include <linux/module.h>
2498 +#include <linux/netfilter_bridge/ebtables.h>
2499 +#include <linux/netfilter_bridge/ebt_ulog.h>
2500 +#include <net/sock.h>
2501 +#include "../br_private.h"
2503 +#define PRINTR(format, args...) do { if (net_ratelimit()) \
2504 + printk(format , ## args); } while (0)
2506 +static unsigned int nlbufsiz = 4096;
2507 +MODULE_PARM(nlbufsiz, "i");
2508 +MODULE_PARM_DESC(nlbufsiz, "netlink buffer size (number of bytes) "
2509 + "(defaults to 4096)");
2511 +static unsigned int flushtimeout = 10;
2512 +MODULE_PARM(flushtimeout, "i");
2513 +MODULE_PARM_DESC(flushtimeout, "buffer flush timeout (hundredths of a second) "
2514 + "(defaults to 10)");
2517 + unsigned int qlen; /* number of nlmsgs' in the skb */
2518 + struct nlmsghdr *lastnlh; /* netlink header of last msg in skb */
2519 + struct sk_buff *skb; /* the pre-allocated skb */
2520 + struct timer_list timer; /* the timer function */
2521 + spinlock_t lock; /* the per-queue lock */
2524 +static ebt_ulog_buff_t ulog_buffers[EBT_ULOG_MAXNLGROUPS];
2525 +static struct sock *ebtlognl;
2527 +/* send one ulog_buff_t to userspace */
2528 +static void ulog_send(unsigned int nlgroup)
2530 + ebt_ulog_buff_t *ub = &ulog_buffers[nlgroup];
2532 + if (timer_pending(&ub->timer))
2533 + del_timer(&ub->timer);
2535 + /* last nlmsg needs NLMSG_DONE */
2537 + ub->lastnlh->nlmsg_type = NLMSG_DONE;
2539 + NETLINK_CB(ub->skb).dst_groups = 1 << nlgroup;
2540 + netlink_broadcast(ebtlognl, ub->skb, 0, 1 << nlgroup, GFP_ATOMIC);
2546 +/* timer function to flush queue in flushtimeout time */
2547 +static void ulog_timer(unsigned long data)
2549 + spin_lock_bh(&ulog_buffers[data].lock);
2550 + if (ulog_buffers[data].skb)
2552 + spin_unlock_bh(&ulog_buffers[data].lock);
2555 +static struct sk_buff *ulog_alloc_skb(unsigned int size)
2557 + struct sk_buff *skb;
2559 + skb = alloc_skb(nlbufsiz, GFP_ATOMIC);
2561 + PRINTR(KERN_ERR "ebt_ulog: can't alloc whole buffer "
2562 + "of size %ub!\n", nlbufsiz);
2563 + if (size < nlbufsiz) {
2564 + /* try to allocate only as much as we need for
2565 + * current packet */
2566 + skb = alloc_skb(size, GFP_ATOMIC);
2568 + PRINTR(KERN_ERR "ebt_ulog: can't even allocate "
2569 + "buffer of size %ub\n", size);
2576 +static void ebt_ulog(const struct sk_buff *skb, unsigned int hooknr,
2577 + const struct net_device *in, const struct net_device *out,
2578 + const void *data, unsigned int datalen)
2580 + ebt_ulog_packet_msg_t *pm;
2581 + size_t size, copy_len;
2582 + struct nlmsghdr *nlh;
2583 + struct ebt_ulog_info *loginfo = (struct ebt_ulog_info *)data;
2584 + unsigned int group = loginfo->nlgroup;
2585 + ebt_ulog_buff_t *ub = &ulog_buffers[group];
2586 + spinlock_t *lock = &ub->lock;
2588 + if ((loginfo->cprange == 0) ||
2589 + (loginfo->cprange > skb->len + ETH_HLEN))
2590 + copy_len = skb->len + ETH_HLEN;
2592 + copy_len = loginfo->cprange;
2594 + size = NLMSG_SPACE(sizeof(*pm) + copy_len);
2596 + spin_lock_bh(lock);
2599 + if (!(ub->skb = ulog_alloc_skb(size)))
2600 + goto alloc_failure;
2601 + } else if (size > skb_tailroom(ub->skb)) {
2604 + if (!(ub->skb = ulog_alloc_skb(size)))
2605 + goto alloc_failure;
2608 + nlh = NLMSG_PUT(ub->skb, 0, ub->qlen, 0,
2609 + size - NLMSG_ALIGN(sizeof(*nlh)));
2612 + pm = NLMSG_DATA(nlh);
2614 + /* Fill in the ulog data */
2615 + do_gettimeofday(&pm->stamp);
2616 + if (ub->qlen == 1)
2617 + ub->skb->stamp = pm->stamp;
2618 + pm->data_len = copy_len;
2619 + pm->mark = skb->nfmark;
2620 + pm->hook = hooknr;
2621 + if (loginfo->prefix != NULL)
2622 + strcpy(pm->prefix, loginfo->prefix);
2624 + *(pm->prefix) = '\0';
2627 + strcpy(pm->physindev, in->name);
2628 + strcpy(pm->indev, in->br_port->br->dev.name);
2630 + pm->indev[0] = pm->physindev[0] = '\0';
2633 + strcpy(pm->physoutdev, out->name);
2634 + strcpy(pm->outdev, out->br_port->br->dev.name);
2636 + pm->outdev[0] = pm->physoutdev[0] = '\0';
2638 + if (skb_copy_bits(skb, -ETH_HLEN, pm->data, copy_len) < 0)
2642 + ub->lastnlh->nlmsg_flags |= NLM_F_MULTI;
2644 + ub->lastnlh = nlh;
2646 + if (ub->qlen >= loginfo->qthreshold)
2648 + else if (!timer_pending(&ub->timer)) {
2649 + ub->timer.expires = jiffies + flushtimeout * HZ / 100;
2650 + add_timer(&ub->timer);
2654 + spin_unlock_bh(lock);
2659 + PRINTR(KERN_ERR "ebt_ULOG: error during NLMSG_PUT.\n");
2665 +static int ebt_ulog_check(const char *tablename, unsigned int hookmask,
2666 + const struct ebt_entry *e, void *data, unsigned int datalen)
2668 + struct ebt_ulog_info *loginfo = (struct ebt_ulog_info *)data;
2670 + if (datalen != EBT_ALIGN(sizeof(struct ebt_ulog_info)) ||
2671 + loginfo->nlgroup > 31)
2674 + loginfo->prefix[EBT_ULOG_PREFIX_LEN - 1] = '\0';
2676 + if (loginfo->qthreshold > EBT_ULOG_MAX_QLEN)
2677 + loginfo->qthreshold = EBT_ULOG_MAX_QLEN;
2682 +static struct ebt_watcher ulog = {
2683 + {NULL, NULL}, EBT_ULOG_WATCHER, ebt_ulog, ebt_ulog_check, NULL,
2687 +static int __init init(void)
2691 + if (nlbufsiz >= 128*1024) {
2692 + printk(KERN_NOTICE "ebt_ulog: Netlink buffer has to be <= 128kB,"
2693 + " please try a smaller nlbufsiz parameter.\n");
2697 + /* initialize ulog_buffers */
2698 + for (i = 0; i < EBT_ULOG_MAXNLGROUPS; i++) {
2699 + init_timer(&ulog_buffers[i].timer);
2700 + ulog_buffers[i].timer.function = ulog_timer;
2701 + ulog_buffers[i].timer.data = i;
2702 + ulog_buffers[i].lock = SPIN_LOCK_UNLOCKED;
2705 + ebtlognl = netlink_kernel_create(NETLINK_NFLOG, NULL);
2708 + else if ((ret = ebt_register_watcher(&ulog)))
2709 + sock_release(ebtlognl->socket);
2714 +static void __exit fini(void)
2716 + ebt_ulog_buff_t *ub;
2719 + ebt_unregister_watcher(&ulog);
2720 + for (i = 0; i < EBT_ULOG_MAXNLGROUPS; i++) {
2721 + ub = &ulog_buffers[i];
2722 + if (timer_pending(&ub->timer))
2723 + del_timer(&ub->timer);
2724 + spin_lock_bh(&ub->lock);
2726 + kfree_skb(ub->skb);
2729 + spin_unlock_bh(&ub->lock);
2731 + sock_release(ebtlognl->socket);
2736 +MODULE_LICENSE("GPL");
2737 +MODULE_AUTHOR("Bart De Schuymer <bdschuym@pandora.be>");
2738 +MODULE_DESCRIPTION("ebtables userspace logging module for bridged Ethernet"
2740 --- /dev/null 2005-09-22 15:53:13.374707688 +0000
2741 +++ linux-2.4.31-ebt-brnf/net/bridge/netfilter/ebt_snat.c 2005-09-15 16:57:23.000000000 +0000
2747 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
2753 +#include <linux/netfilter_bridge/ebtables.h>
2754 +#include <linux/netfilter_bridge/ebt_nat.h>
2755 +#include <linux/module.h>
2757 +static int ebt_target_snat(struct sk_buff **pskb, unsigned int hooknr,
2758 + const struct net_device *in, const struct net_device *out,
2759 + const void *data, unsigned int datalen)
2761 + struct ebt_nat_info *info = (struct ebt_nat_info *) data;
2763 + memcpy(((**pskb).mac.ethernet)->h_source, info->mac,
2764 + ETH_ALEN * sizeof(unsigned char));
2765 + return info->target;
2768 +static int ebt_target_snat_check(const char *tablename, unsigned int hookmask,
2769 + const struct ebt_entry *e, void *data, unsigned int datalen)
2771 + struct ebt_nat_info *info = (struct ebt_nat_info *) data;
2773 + if (datalen != EBT_ALIGN(sizeof(struct ebt_nat_info)))
2775 + if (BASE_CHAIN && info->target == EBT_RETURN)
2777 + CLEAR_BASE_CHAIN_BIT;
2778 + if (strcmp(tablename, "nat"))
2780 + if (hookmask & ~(1 << NF_BR_POST_ROUTING))
2782 + if (INVALID_TARGET)
2787 +static struct ebt_target snat =
2789 + {NULL, NULL}, EBT_SNAT_TARGET, ebt_target_snat, ebt_target_snat_check,
2793 +static int __init init(void)
2795 + return ebt_register_target(&snat);
2798 +static void __exit fini(void)
2800 + ebt_unregister_target(&snat);
2806 +MODULE_LICENSE("GPL");
2807 --- /dev/null 2005-09-22 15:53:13.374707688 +0000
2808 +++ linux-2.4.31-ebt-brnf/net/bridge/netfilter/ebt_dnat.c 2005-09-15 16:57:23.000000000 +0000
2814 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
2820 +#include <linux/netfilter_bridge/ebtables.h>
2821 +#include <linux/netfilter_bridge/ebt_nat.h>
2822 +#include <linux/module.h>
2823 +#include <net/sock.h>
2825 +static int ebt_target_dnat(struct sk_buff **pskb, unsigned int hooknr,
2826 + const struct net_device *in, const struct net_device *out,
2827 + const void *data, unsigned int datalen)
2829 + struct ebt_nat_info *info = (struct ebt_nat_info *)data;
2831 + memcpy(((**pskb).mac.ethernet)->h_dest, info->mac,
2832 + ETH_ALEN * sizeof(unsigned char));
2833 + return info->target;
2836 +static int ebt_target_dnat_check(const char *tablename, unsigned int hookmask,
2837 + const struct ebt_entry *e, void *data, unsigned int datalen)
2839 + struct ebt_nat_info *info = (struct ebt_nat_info *)data;
2841 + if (BASE_CHAIN && info->target == EBT_RETURN)
2843 + CLEAR_BASE_CHAIN_BIT;
2844 + if ( (strcmp(tablename, "nat") ||
2845 + (hookmask & ~((1 << NF_BR_PRE_ROUTING) | (1 << NF_BR_LOCAL_OUT)))) &&
2846 + (strcmp(tablename, "broute") || hookmask & ~(1 << NF_BR_BROUTING)) )
2848 + if (datalen != EBT_ALIGN(sizeof(struct ebt_nat_info)))
2850 + if (INVALID_TARGET)
2855 +static struct ebt_target dnat =
2857 + {NULL, NULL}, EBT_DNAT_TARGET, ebt_target_dnat, ebt_target_dnat_check,
2861 +static int __init init(void)
2863 + return ebt_register_target(&dnat);
2866 +static void __exit fini(void)
2868 + ebt_unregister_target(&dnat);
2874 +MODULE_LICENSE("GPL");
2875 --- /dev/null 2005-09-22 15:53:13.374707688 +0000
2876 +++ linux-2.4.31-ebt-brnf/net/bridge/netfilter/ebtables.c 2005-09-15 16:57:23.000000000 +0000
2882 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
2884 + * ebtables.c,v 2.0, July, 2002
2886 + * This code is stongly inspired on the iptables code which is
2887 + * Copyright (C) 1999 Paul `Rusty' Russell & Michael J. Neuling
2889 + * This program is free software; you can redistribute it and/or
2890 + * modify it under the terms of the GNU General Public License
2891 + * as published by the Free Software Foundation; either version
2892 + * 2 of the License, or (at your option) any later version.
2895 +// used for print_string
2896 +#include <linux/sched.h>
2897 +#include <linux/tty.h>
2899 +#include <linux/kmod.h>
2900 +#include <linux/module.h>
2901 +#include <linux/vmalloc.h>
2902 +#include <linux/netfilter_bridge/ebtables.h>
2903 +#include <linux/spinlock.h>
2904 +#include <asm/uaccess.h>
2905 +#include <linux/smp.h>
2906 +#include <net/sock.h>
2907 +// needed for logical [in,out]-dev filtering
2908 +#include "../br_private.h"
2911 +#define ASSERT_READ_LOCK(x)
2912 +#define ASSERT_WRITE_LOCK(x)
2913 +#include <linux/netfilter_ipv4/listhelp.h>
2915 +#if 0 // use this for remote debugging
2916 +// Copyright (C) 1998 by Ori Pomerantz
2917 +// Print the string to the appropriate tty, the one
2918 +// the current task uses
2919 +static void print_string(char *str)
2921 + struct tty_struct *my_tty;
2923 + /* The tty for the current task */
2924 + my_tty = current->tty;
2925 + if (my_tty != NULL) {
2926 + (*(my_tty->driver).write)(my_tty, 0, str, strlen(str));
2927 + (*(my_tty->driver).write)(my_tty, 0, "\015\012", 2);
2931 +#define BUGPRINT(args) print_string(args);
2933 +#define BUGPRINT(format, args...) printk("kernel msg: ebtables bug: please "\
2934 + "report to author: "format, ## args)
2935 +// #define BUGPRINT(format, args...)
2937 +#define MEMPRINT(format, args...) printk("kernel msg: ebtables "\
2938 + ": out of memory: "format, ## args)
2939 +// #define MEMPRINT(format, args...)
2943 +// Each cpu has its own set of counters, so there is no need for write_lock in
2945 +// For reading or updating the counters, the user context needs to
2946 +// get a write_lock
2948 +// The size of each set of counters is altered to get cache alignment
2949 +#define SMP_ALIGN(x) (((x) + SMP_CACHE_BYTES-1) & ~(SMP_CACHE_BYTES-1))
2950 +#define COUNTER_OFFSET(n) (SMP_ALIGN(n * sizeof(struct ebt_counter)))
2951 +#define COUNTER_BASE(c, n, cpu) ((struct ebt_counter *)(((char *)c) + \
2952 + COUNTER_OFFSET(n) * cpu))
2956 +static DECLARE_MUTEX(ebt_mutex);
2957 +static LIST_HEAD(ebt_tables);
2958 +static LIST_HEAD(ebt_targets);
2959 +static LIST_HEAD(ebt_matches);
2960 +static LIST_HEAD(ebt_watchers);
2962 +static struct ebt_target ebt_standard_target =
2963 +{ {NULL, NULL}, EBT_STANDARD_TARGET, NULL, NULL, NULL, NULL};
2965 +static inline int ebt_do_watcher (struct ebt_entry_watcher *w,
2966 + const struct sk_buff *skb, unsigned int hooknr, const struct net_device *in,
2967 + const struct net_device *out)
2969 + w->u.watcher->watcher(skb, hooknr, in, out, w->data,
2971 + // watchers don't give a verdict
2975 +static inline int ebt_do_match (struct ebt_entry_match *m,
2976 + const struct sk_buff *skb, const struct net_device *in,
2977 + const struct net_device *out)
2979 + return m->u.match->match(skb, in, out, m->data,
2983 +static inline int ebt_dev_check(char *entry, const struct net_device *device)
2986 + char *devname = device->name;
2988 + if (*entry == '\0')
2992 + /* 1 is the wildcard token */
2993 + while (entry[i] != '\0' && entry[i] != 1 && entry[i] == devname[i])
2995 + return (devname[i] != entry[i] && entry[i] != 1);
2998 +#define FWINV2(bool,invflg) ((bool) ^ !!(e->invflags & invflg))
2999 +// process standard matches
3000 +static inline int ebt_basic_match(struct ebt_entry *e, struct ethhdr *h,
3001 + const struct net_device *in, const struct net_device *out)
3005 + if (e->bitmask & EBT_802_3) {
3006 + if (FWINV2(ntohs(h->h_proto) >= 1536, EBT_IPROTO))
3008 + } else if (!(e->bitmask & EBT_NOPROTO) &&
3009 + FWINV2(e->ethproto != h->h_proto, EBT_IPROTO))
3012 + if (FWINV2(ebt_dev_check(e->in, in), EBT_IIN))
3014 + if (FWINV2(ebt_dev_check(e->out, out), EBT_IOUT))
3016 + if ((!in || !in->br_port) ? 0 : FWINV2(ebt_dev_check(
3017 + e->logical_in, &in->br_port->br->dev), EBT_ILOGICALIN))
3019 + if ((!out || !out->br_port) ? 0 : FWINV2(ebt_dev_check(
3020 + e->logical_out, &out->br_port->br->dev), EBT_ILOGICALOUT))
3023 + if (e->bitmask & EBT_SOURCEMAC) {
3025 + for (i = 0; i < 6; i++)
3026 + verdict |= (h->h_source[i] ^ e->sourcemac[i]) &
3028 + if (FWINV2(verdict != 0, EBT_ISOURCE) )
3031 + if (e->bitmask & EBT_DESTMAC) {
3033 + for (i = 0; i < 6; i++)
3034 + verdict |= (h->h_dest[i] ^ e->destmac[i]) &
3036 + if (FWINV2(verdict != 0, EBT_IDEST) )
3042 +// Do some firewalling
3043 +unsigned int ebt_do_table (unsigned int hook, struct sk_buff **pskb,
3044 + const struct net_device *in, const struct net_device *out,
3045 + struct ebt_table *table)
3048 + struct ebt_entry *point;
3049 + struct ebt_counter *counter_base, *cb_base;
3050 + struct ebt_entry_target *t;
3051 + int verdict, sp = 0;
3052 + struct ebt_chainstack *cs;
3053 + struct ebt_entries *chaininfo;
3055 + struct ebt_table_info *private;
3057 + read_lock_bh(&table->lock);
3058 + private = table->private;
3059 + cb_base = COUNTER_BASE(private->counters, private->nentries,
3060 + cpu_number_map(smp_processor_id()));
3061 + if (private->chainstack)
3062 + cs = private->chainstack[cpu_number_map(smp_processor_id())];
3065 + chaininfo = private->hook_entry[hook];
3066 + nentries = private->hook_entry[hook]->nentries;
3067 + point = (struct ebt_entry *)(private->hook_entry[hook]->data);
3068 + counter_base = cb_base + private->hook_entry[hook]->counter_offset;
3069 + // base for chain jumps
3070 + base = private->entries;
3072 + while (i < nentries) {
3073 + if (ebt_basic_match(point, (**pskb).mac.ethernet, in, out))
3074 + goto letscontinue;
3076 + if (EBT_MATCH_ITERATE(point, ebt_do_match, *pskb, in, out) != 0)
3077 + goto letscontinue;
3079 + // increase counter
3080 + (*(counter_base + i)).pcnt++;
3081 + (*(counter_base + i)).bcnt+=(**pskb).len;
3083 + // these should only watch: not modify, nor tell us
3084 + // what to do with the packet
3085 + EBT_WATCHER_ITERATE(point, ebt_do_watcher, *pskb, hook, in,
3088 + t = (struct ebt_entry_target *)
3089 + (((char *)point) + point->target_offset);
3090 + // standard target
3091 + if (!t->u.target->target)
3092 + verdict = ((struct ebt_standard_target *)t)->verdict;
3094 + verdict = t->u.target->target(pskb, hook,
3095 + in, out, t->data, t->target_size);
3096 + if (verdict == EBT_ACCEPT) {
3097 + read_unlock_bh(&table->lock);
3100 + if (verdict == EBT_DROP) {
3101 + read_unlock_bh(&table->lock);
3104 + if (verdict == EBT_RETURN) {
3106 +#ifdef CONFIG_NETFILTER_DEBUG
3108 + BUGPRINT("RETURN on base chain");
3109 + // act like this is EBT_CONTINUE
3110 + goto letscontinue;
3114 + // put all the local variables right
3116 + chaininfo = cs[sp].chaininfo;
3117 + nentries = chaininfo->nentries;
3119 + counter_base = cb_base +
3120 + chaininfo->counter_offset;
3123 + if (verdict == EBT_CONTINUE)
3124 + goto letscontinue;
3125 +#ifdef CONFIG_NETFILTER_DEBUG
3126 + if (verdict < 0) {
3127 + BUGPRINT("bogus standard verdict\n");
3128 + read_unlock_bh(&table->lock);
3134 + cs[sp].chaininfo = chaininfo;
3135 + cs[sp].e = (struct ebt_entry *)
3136 + (((char *)point) + point->next_offset);
3138 + chaininfo = (struct ebt_entries *) (base + verdict);
3139 +#ifdef CONFIG_NETFILTER_DEBUG
3140 + if (chaininfo->distinguisher) {
3141 + BUGPRINT("jump to non-chain\n");
3142 + read_unlock_bh(&table->lock);
3146 + nentries = chaininfo->nentries;
3147 + point = (struct ebt_entry *)chaininfo->data;
3148 + counter_base = cb_base + chaininfo->counter_offset;
3152 + point = (struct ebt_entry *)
3153 + (((char *)point) + point->next_offset);
3157 + // I actually like this :)
3158 + if (chaininfo->policy == EBT_RETURN)
3160 + if (chaininfo->policy == EBT_ACCEPT) {
3161 + read_unlock_bh(&table->lock);
3164 + read_unlock_bh(&table->lock);
3168 +// If it succeeds, returns element and locks mutex
3169 +static inline void *
3170 +find_inlist_lock_noload(struct list_head *head, const char *name, int *error,
3171 + struct semaphore *mutex)
3175 + *error = down_interruptible(mutex);
3179 + ret = list_named_find(head, name);
3187 +#ifndef CONFIG_KMOD
3188 +#define find_inlist_lock(h,n,p,e,m) find_inlist_lock_noload((h),(n),(e),(m))
3191 +find_inlist_lock(struct list_head *head, const char *name, const char *prefix,
3192 + int *error, struct semaphore *mutex)
3196 + ret = find_inlist_lock_noload(head, name, error, mutex);
3198 + char modulename[EBT_FUNCTION_MAXNAMELEN + strlen(prefix) + 1];
3199 + strcpy(modulename, prefix);
3200 + strcat(modulename, name);
3201 + request_module(modulename);
3202 + ret = find_inlist_lock_noload(head, name, error, mutex);
3208 +static inline struct ebt_table *
3209 +find_table_lock(const char *name, int *error, struct semaphore *mutex)
3211 + return find_inlist_lock(&ebt_tables, name, "ebtable_", error, mutex);
3214 +static inline struct ebt_match *
3215 +find_match_lock(const char *name, int *error, struct semaphore *mutex)
3217 + return find_inlist_lock(&ebt_matches, name, "ebt_", error, mutex);
3220 +static inline struct ebt_watcher *
3221 +find_watcher_lock(const char *name, int *error, struct semaphore *mutex)
3223 + return find_inlist_lock(&ebt_watchers, name, "ebt_", error, mutex);
3226 +static inline struct ebt_target *
3227 +find_target_lock(const char *name, int *error, struct semaphore *mutex)
3229 + return find_inlist_lock(&ebt_targets, name, "ebt_", error, mutex);
3233 +ebt_check_match(struct ebt_entry_match *m, struct ebt_entry *e,
3234 + const char *name, unsigned int hookmask, unsigned int *cnt)
3236 + struct ebt_match *match;
3239 + if (((char *)m) + m->match_size + sizeof(struct ebt_entry_match) >
3240 + ((char *)e) + e->watchers_offset)
3242 + match = find_match_lock(m->u.name, &ret, &ebt_mutex);
3245 + m->u.match = match;
3247 + __MOD_INC_USE_COUNT(match->me);
3249 + if (match->check &&
3250 + match->check(name, hookmask, e, m->data, m->match_size) != 0) {
3251 + BUGPRINT("match->check failed\n");
3253 + __MOD_DEC_USE_COUNT(match->me);
3261 +ebt_check_watcher(struct ebt_entry_watcher *w, struct ebt_entry *e,
3262 + const char *name, unsigned int hookmask, unsigned int *cnt)
3264 + struct ebt_watcher *watcher;
3267 + if (((char *)w) + w->watcher_size + sizeof(struct ebt_entry_watcher) >
3268 + ((char *)e) + e->target_offset)
3270 + watcher = find_watcher_lock(w->u.name, &ret, &ebt_mutex);
3273 + w->u.watcher = watcher;
3275 + __MOD_INC_USE_COUNT(watcher->me);
3277 + if (watcher->check &&
3278 + watcher->check(name, hookmask, e, w->data, w->watcher_size) != 0) {
3279 + BUGPRINT("watcher->check failed\n");
3281 + __MOD_DEC_USE_COUNT(watcher->me);
3288 +// this one is very careful, as it is the first function
3289 +// to parse the userspace data
3291 +ebt_check_entry_size_and_hooks(struct ebt_entry *e,
3292 + struct ebt_table_info *newinfo, char *base, char *limit,
3293 + struct ebt_entries **hook_entries, unsigned int *n, unsigned int *cnt,
3294 + unsigned int *totalcnt, unsigned int *udc_cnt, unsigned int valid_hooks)
3298 + for (i = 0; i < NF_BR_NUMHOOKS; i++) {
3299 + if ((valid_hooks & (1 << i)) == 0)
3301 + if ( (char *)hook_entries[i] - base ==
3302 + (char *)e - newinfo->entries)
3305 + // beginning of a new chain
3306 + // if i == NF_BR_NUMHOOKS it must be a user defined chain
3307 + if (i != NF_BR_NUMHOOKS || !(e->bitmask & EBT_ENTRY_OR_ENTRIES)) {
3308 + if ((e->bitmask & EBT_ENTRY_OR_ENTRIES) != 0) {
3309 + // we make userspace set this right,
3310 + // so there is no misunderstanding
3311 + BUGPRINT("EBT_ENTRY_OR_ENTRIES shouldn't be set "
3312 + "in distinguisher\n");
3315 + // this checks if the previous chain has as many entries
3316 + // as it said it has
3318 + BUGPRINT("nentries does not equal the nr of entries "
3319 + "in the chain\n");
3322 + // before we look at the struct, be sure it is not too big
3323 + if ((char *)hook_entries[i] + sizeof(struct ebt_entries)
3325 + BUGPRINT("entries_size too small\n");
3328 + if (((struct ebt_entries *)e)->policy != EBT_DROP &&
3329 + ((struct ebt_entries *)e)->policy != EBT_ACCEPT) {
3330 + // only RETURN from udc
3331 + if (i != NF_BR_NUMHOOKS ||
3332 + ((struct ebt_entries *)e)->policy != EBT_RETURN) {
3333 + BUGPRINT("bad policy\n");
3337 + if (i == NF_BR_NUMHOOKS) // it's a user defined chain
3340 + newinfo->hook_entry[i] = (struct ebt_entries *)e;
3341 + if (((struct ebt_entries *)e)->counter_offset != *totalcnt) {
3342 + BUGPRINT("counter_offset != totalcnt");
3345 + *n = ((struct ebt_entries *)e)->nentries;
3349 + // a plain old entry, heh
3350 + if (sizeof(struct ebt_entry) > e->watchers_offset ||
3351 + e->watchers_offset > e->target_offset ||
3352 + e->target_offset >= e->next_offset) {
3353 + BUGPRINT("entry offsets not in right order\n");
3356 + // this is not checked anywhere else
3357 + if (e->next_offset - e->target_offset < sizeof(struct ebt_entry_target)) {
3358 + BUGPRINT("target size too small\n");
3367 +struct ebt_cl_stack
3369 + struct ebt_chainstack cs;
3371 + unsigned int hookmask;
3374 +// we need these positions to check that the jumps to a different part of the
3375 +// entries is a jump to the beginning of a new chain.
3377 +ebt_get_udc_positions(struct ebt_entry *e, struct ebt_table_info *newinfo,
3378 + struct ebt_entries **hook_entries, unsigned int *n, unsigned int valid_hooks,
3379 + struct ebt_cl_stack *udc)
3383 + // we're only interested in chain starts
3384 + if (e->bitmask & EBT_ENTRY_OR_ENTRIES)
3386 + for (i = 0; i < NF_BR_NUMHOOKS; i++) {
3387 + if ((valid_hooks & (1 << i)) == 0)
3389 + if (newinfo->hook_entry[i] == (struct ebt_entries *)e)
3392 + // only care about udc
3393 + if (i != NF_BR_NUMHOOKS)
3396 + udc[*n].cs.chaininfo = (struct ebt_entries *)e;
3397 + // these initialisations are depended on later in check_chainloops()
3399 + udc[*n].hookmask = 0;
3406 +ebt_cleanup_match(struct ebt_entry_match *m, unsigned int *i)
3408 + if (i && (*i)-- == 0)
3410 + if (m->u.match->destroy)
3411 + m->u.match->destroy(m->data, m->match_size);
3412 + if (m->u.match->me)
3413 + __MOD_DEC_USE_COUNT(m->u.match->me);
3419 +ebt_cleanup_watcher(struct ebt_entry_watcher *w, unsigned int *i)
3421 + if (i && (*i)-- == 0)
3423 + if (w->u.watcher->destroy)
3424 + w->u.watcher->destroy(w->data, w->watcher_size);
3425 + if (w->u.watcher->me)
3426 + __MOD_DEC_USE_COUNT(w->u.watcher->me);
3432 +ebt_cleanup_entry(struct ebt_entry *e, unsigned int *cnt)
3434 + struct ebt_entry_target *t;
3436 + if ((e->bitmask & EBT_ENTRY_OR_ENTRIES) == 0)
3439 + if (cnt && (*cnt)-- == 0)
3441 + EBT_WATCHER_ITERATE(e, ebt_cleanup_watcher, NULL);
3442 + EBT_MATCH_ITERATE(e, ebt_cleanup_match, NULL);
3443 + t = (struct ebt_entry_target *)(((char *)e) + e->target_offset);
3444 + if (t->u.target->destroy)
3445 + t->u.target->destroy(t->data, t->target_size);
3446 + if (t->u.target->me)
3447 + __MOD_DEC_USE_COUNT(t->u.target->me);
3453 +ebt_check_entry(struct ebt_entry *e, struct ebt_table_info *newinfo,
3454 + const char *name, unsigned int *cnt, unsigned int valid_hooks,
3455 + struct ebt_cl_stack *cl_s, unsigned int udc_cnt)
3457 + struct ebt_entry_target *t;
3458 + struct ebt_target *target;
3459 + unsigned int i, j, hook = 0, hookmask = 0;
3462 + // Don't mess with the struct ebt_entries
3463 + if ((e->bitmask & EBT_ENTRY_OR_ENTRIES) == 0)
3466 + if (e->bitmask & ~EBT_F_MASK) {
3467 + BUGPRINT("Unknown flag for bitmask\n");
3470 + if (e->invflags & ~EBT_INV_MASK) {
3471 + BUGPRINT("Unknown flag for inv bitmask\n");
3474 + if ( (e->bitmask & EBT_NOPROTO) && (e->bitmask & EBT_802_3) ) {
3475 + BUGPRINT("NOPROTO & 802_3 not allowed\n");
3478 + // what hook do we belong to?
3479 + for (i = 0; i < NF_BR_NUMHOOKS; i++) {
3480 + if ((valid_hooks & (1 << i)) == 0)
3482 + if ((char *)newinfo->hook_entry[i] < (char *)e)
3487 + // (1 << NF_BR_NUMHOOKS) tells the check functions the rule is on
3489 + if (i < NF_BR_NUMHOOKS)
3490 + hookmask = (1 << hook) | (1 << NF_BR_NUMHOOKS);
3492 + for (i = 0; i < udc_cnt; i++)
3493 + if ((char *)(cl_s[i].cs.chaininfo) > (char *)e)
3496 + hookmask = (1 << hook) | (1 << NF_BR_NUMHOOKS);
3498 + hookmask = cl_s[i - 1].hookmask;
3501 + ret = EBT_MATCH_ITERATE(e, ebt_check_match, e, name, hookmask, &i);
3503 + goto cleanup_matches;
3505 + ret = EBT_WATCHER_ITERATE(e, ebt_check_watcher, e, name, hookmask, &j);
3507 + goto cleanup_watchers;
3508 + t = (struct ebt_entry_target *)(((char *)e) + e->target_offset);
3509 + target = find_target_lock(t->u.name, &ret, &ebt_mutex);
3511 + goto cleanup_watchers;
3513 + __MOD_INC_USE_COUNT(target->me);
3516 + t->u.target = target;
3517 + if (t->u.target == &ebt_standard_target) {
3518 + if (e->target_offset + sizeof(struct ebt_standard_target) >
3520 + BUGPRINT("Standard target size too big\n");
3522 + goto cleanup_watchers;
3524 + if (((struct ebt_standard_target *)t)->verdict <
3525 + -NUM_STANDARD_TARGETS) {
3526 + BUGPRINT("Invalid standard target\n");
3528 + goto cleanup_watchers;
3530 + } else if ((e->target_offset + t->target_size +
3531 + sizeof(struct ebt_entry_target) > e->next_offset) ||
3532 + (t->u.target->check &&
3533 + t->u.target->check(name, hookmask, e, t->data, t->target_size) != 0)){
3534 + if (t->u.target->me)
3535 + __MOD_DEC_USE_COUNT(t->u.target->me);
3537 + goto cleanup_watchers;
3542 + EBT_WATCHER_ITERATE(e, ebt_cleanup_watcher, &j);
3544 + EBT_MATCH_ITERATE(e, ebt_cleanup_match, &i);
3548 +// checks for loops and sets the hook mask for udc
3549 +// the hook mask for udc tells us from which base chains the udc can be
3550 +// accessed. This mask is a parameter to the check() functions of the extensions
3551 +static int check_chainloops(struct ebt_entries *chain,
3552 + struct ebt_cl_stack *cl_s, unsigned int udc_cnt,
3553 + unsigned int hooknr, char *base)
3555 + int i, chain_nr = -1, pos = 0, nentries = chain->nentries, verdict;
3556 + struct ebt_entry *e = (struct ebt_entry *)chain->data;
3557 + struct ebt_entry_target *t;
3559 + while (pos < nentries || chain_nr != -1) {
3560 + // end of udc, go back one 'recursion' step
3561 + if (pos == nentries) {
3562 + // put back values of the time when this chain was called
3563 + e = cl_s[chain_nr].cs.e;
3564 + if (cl_s[chain_nr].from != -1)
3566 + cl_s[cl_s[chain_nr].from].cs.chaininfo->nentries;
3568 + nentries = chain->nentries;
3569 + pos = cl_s[chain_nr].cs.n;
3570 + // make sure we won't see a loop that isn't one
3571 + cl_s[chain_nr].cs.n = 0;
3572 + chain_nr = cl_s[chain_nr].from;
3573 + if (pos == nentries)
3576 + t = (struct ebt_entry_target *)
3577 + (((char *)e) + e->target_offset);
3578 + if (strcmp(t->u.name, EBT_STANDARD_TARGET))
3579 + goto letscontinue;
3580 + if (e->target_offset + sizeof(struct ebt_standard_target) >
3582 + BUGPRINT("Standard target size too big\n");
3585 + verdict = ((struct ebt_standard_target *)t)->verdict;
3586 + if (verdict >= 0) { // jump to another chain
3587 + struct ebt_entries *hlp2 =
3588 + (struct ebt_entries *)(base + verdict);
3589 + for (i = 0; i < udc_cnt; i++)
3590 + if (hlp2 == cl_s[i].cs.chaininfo)
3592 + // bad destination or loop
3593 + if (i == udc_cnt) {
3594 + BUGPRINT("bad destination\n");
3597 + if (cl_s[i].cs.n) {
3598 + BUGPRINT("loop\n");
3601 + // this can't be 0, so the above test is correct
3602 + cl_s[i].cs.n = pos + 1;
3604 + cl_s[i].cs.e = ((void *)e + e->next_offset);
3605 + e = (struct ebt_entry *)(hlp2->data);
3606 + nentries = hlp2->nentries;
3607 + cl_s[i].from = chain_nr;
3609 + // this udc is accessible from the base chain for hooknr
3610 + cl_s[i].hookmask |= (1 << hooknr);
3614 + e = (void *)e + e->next_offset;
3620 +// do the parsing of the table/chains/entries/matches/watchers/targets, heh
3621 +static int translate_table(struct ebt_replace *repl,
3622 + struct ebt_table_info *newinfo)
3624 + unsigned int i, j, k, udc_cnt;
3626 + struct ebt_cl_stack *cl_s = NULL; // used in the checking for chain loops
3629 + while (i < NF_BR_NUMHOOKS && !(repl->valid_hooks & (1 << i)))
3631 + if (i == NF_BR_NUMHOOKS) {
3632 + BUGPRINT("No valid hooks specified\n");
3635 + if (repl->hook_entry[i] != (struct ebt_entries *)repl->entries) {
3636 + BUGPRINT("Chains don't start at beginning\n");
3639 + // make sure chains are ordered after each other in same order
3640 + // as their corresponding hooks
3641 + for (j = i + 1; j < NF_BR_NUMHOOKS; j++) {
3642 + if (!(repl->valid_hooks & (1 << j)))
3644 + if ( repl->hook_entry[j] <= repl->hook_entry[i] ) {
3645 + BUGPRINT("Hook order must be followed\n");
3651 + for (i = 0; i < NF_BR_NUMHOOKS; i++)
3652 + newinfo->hook_entry[i] = NULL;
3654 + newinfo->entries_size = repl->entries_size;
3655 + newinfo->nentries = repl->nentries;
3657 + // do some early checkings and initialize some things
3658 + i = 0; // holds the expected nr. of entries for the chain
3659 + j = 0; // holds the up to now counted entries for the chain
3660 + k = 0; // holds the total nr. of entries, should equal
3661 + // newinfo->nentries afterwards
3662 + udc_cnt = 0; // will hold the nr. of user defined chains (udc)
3663 + ret = EBT_ENTRY_ITERATE(newinfo->entries, newinfo->entries_size,
3664 + ebt_check_entry_size_and_hooks, newinfo, repl->entries,
3665 + repl->entries + repl->entries_size, repl->hook_entry, &i, &j, &k,
3666 + &udc_cnt, repl->valid_hooks);
3672 + BUGPRINT("nentries does not equal the nr of entries in the "
3673 + "(last) chain\n");
3676 + if (k != newinfo->nentries) {
3677 + BUGPRINT("Total nentries is wrong\n");
3681 + // check if all valid hooks have a chain
3682 + for (i = 0; i < NF_BR_NUMHOOKS; i++) {
3683 + if (newinfo->hook_entry[i] == NULL &&
3684 + (repl->valid_hooks & (1 << i))) {
3685 + BUGPRINT("Valid hook without chain\n");
3690 + // Get the location of the udc, put them in an array
3691 + // While we're at it, allocate the chainstack
3693 + // this will get free'd in do_replace()/ebt_register_table()
3694 + // if an error occurs
3695 + newinfo->chainstack = (struct ebt_chainstack **)
3696 + vmalloc(smp_num_cpus * sizeof(struct ebt_chainstack));
3697 + if (!newinfo->chainstack)
3699 + for (i = 0; i < smp_num_cpus; i++) {
3700 + newinfo->chainstack[i] =
3701 + vmalloc(udc_cnt * sizeof(struct ebt_chainstack));
3702 + if (!newinfo->chainstack[i]) {
3704 + vfree(newinfo->chainstack[--i]);
3705 + vfree(newinfo->chainstack);
3706 + newinfo->chainstack = NULL;
3711 + cl_s = (struct ebt_cl_stack *)
3712 + vmalloc(udc_cnt * sizeof(struct ebt_cl_stack));
3715 + i = 0; // the i'th udc
3716 + EBT_ENTRY_ITERATE(newinfo->entries, newinfo->entries_size,
3717 + ebt_get_udc_positions, newinfo, repl->hook_entry, &i,
3718 + repl->valid_hooks, cl_s);
3720 + if (i != udc_cnt) {
3721 + BUGPRINT("i != udc_cnt\n");
3727 + // Check for loops
3728 + for (i = 0; i < NF_BR_NUMHOOKS; i++)
3729 + if (repl->valid_hooks & (1 << i))
3730 + if (check_chainloops(newinfo->hook_entry[i],
3731 + cl_s, udc_cnt, i, newinfo->entries)) {
3737 + // we now know the following (along with E=mc):
3738 + // - the nr of entries in each chain is right
3739 + // - the size of the allocated space is right
3740 + // - all valid hooks have a corresponding chain
3741 + // - there are no loops
3742 + // - wrong data can still be on the level of a single entry
3743 + // - could be there are jumps to places that are not the
3744 + // beginning of a chain. This can only occur in chains that
3745 + // are not accessible from any base chains, so we don't care.
3747 + // used to know what we need to clean up if something goes wrong
3749 + ret = EBT_ENTRY_ITERATE(newinfo->entries, newinfo->entries_size,
3750 + ebt_check_entry, newinfo, repl->name, &i, repl->valid_hooks,
3753 + EBT_ENTRY_ITERATE(newinfo->entries, newinfo->entries_size,
3754 + ebt_cleanup_entry, &i);
3761 +// called under write_lock
3762 +static void get_counters(struct ebt_counter *oldcounters,
3763 + struct ebt_counter *counters, unsigned int nentries)
3766 + struct ebt_counter *counter_base;
3768 + // counters of cpu 0
3769 + memcpy(counters, oldcounters,
3770 + sizeof(struct ebt_counter) * nentries);
3771 + // add other counters to those of cpu 0
3772 + for (cpu = 1; cpu < smp_num_cpus; cpu++) {
3773 + counter_base = COUNTER_BASE(oldcounters, nentries, cpu);
3774 + for (i = 0; i < nentries; i++) {
3775 + counters[i].pcnt += counter_base[i].pcnt;
3776 + counters[i].bcnt += counter_base[i].bcnt;
3781 +// replace the table
3782 +static int do_replace(void *user, unsigned int len)
3784 + int ret, i, countersize;
3785 + struct ebt_table_info *newinfo;
3786 + struct ebt_replace tmp;
3787 + struct ebt_table *t;
3788 + struct ebt_counter *counterstmp = NULL;
3789 + // used to be able to unlock earlier
3790 + struct ebt_table_info *table;
3792 + if (copy_from_user(&tmp, user, sizeof(tmp)) != 0)
3795 + if (len != sizeof(tmp) + tmp.entries_size) {
3796 + BUGPRINT("Wrong len argument\n");
3800 + if (tmp.entries_size == 0) {
3801 + BUGPRINT("Entries_size never zero\n");
3804 + countersize = COUNTER_OFFSET(tmp.nentries) * smp_num_cpus;
3805 + newinfo = (struct ebt_table_info *)
3806 + vmalloc(sizeof(struct ebt_table_info) + countersize);
3811 + memset(newinfo->counters, 0, countersize);
3813 + newinfo->entries = (char *)vmalloc(tmp.entries_size);
3814 + if (!newinfo->entries) {
3816 + goto free_newinfo;
3818 + if (copy_from_user(
3819 + newinfo->entries, tmp.entries, tmp.entries_size) != 0) {
3820 + BUGPRINT("Couldn't copy entries from userspace\n");
3822 + goto free_entries;
3825 + // the user wants counters back
3826 + // the check on the size is done later, when we have the lock
3827 + if (tmp.num_counters) {
3828 + counterstmp = (struct ebt_counter *)
3829 + vmalloc(tmp.num_counters * sizeof(struct ebt_counter));
3830 + if (!counterstmp) {
3832 + goto free_entries;
3836 + counterstmp = NULL;
3838 + // this can get initialized by translate_table()
3839 + newinfo->chainstack = NULL;
3840 + ret = translate_table(&tmp, newinfo);
3843 + goto free_counterstmp;
3845 + t = find_table_lock(tmp.name, &ret, &ebt_mutex);
3847 + goto free_iterate;
3849 + // the table doesn't like it
3850 + if (t->check && (ret = t->check(newinfo, tmp.valid_hooks)))
3853 + if (tmp.num_counters && tmp.num_counters != t->private->nentries) {
3854 + BUGPRINT("Wrong nr. of counters requested\n");
3859 + // we have the mutex lock, so no danger in reading this pointer
3860 + table = t->private;
3861 + // we need an atomic snapshot of the counters
3862 + write_lock_bh(&t->lock);
3863 + if (tmp.num_counters)
3864 + get_counters(t->private->counters, counterstmp,
3865 + t->private->nentries);
3867 + t->private = newinfo;
3868 + write_unlock_bh(&t->lock);
3870 + // So, a user can change the chains while having messed up her counter
3871 + // allocation. Only reason why this is done is because this way the lock
3872 + // is held only once, while this doesn't bring the kernel into a
3873 + // dangerous state.
3874 + if (tmp.num_counters &&
3875 + copy_to_user(tmp.counters, counterstmp,
3876 + tmp.num_counters * sizeof(struct ebt_counter))) {
3877 + BUGPRINT("Couldn't copy counters to userspace\n");
3883 + // decrease module count and free resources
3884 + EBT_ENTRY_ITERATE(table->entries, table->entries_size,
3885 + ebt_cleanup_entry, NULL);
3887 + vfree(table->entries);
3888 + if (table->chainstack) {
3889 + for (i = 0; i < smp_num_cpus; i++)
3890 + vfree(table->chainstack[i]);
3891 + vfree(table->chainstack);
3896 + vfree(counterstmp);
3902 + EBT_ENTRY_ITERATE(newinfo->entries, newinfo->entries_size,
3903 + ebt_cleanup_entry, NULL);
3906 + vfree(counterstmp);
3907 + // can be initialized in translate_table()
3908 + if (newinfo->chainstack) {
3909 + for (i = 0; i < smp_num_cpus; i++)
3910 + vfree(newinfo->chainstack[i]);
3911 + vfree(newinfo->chainstack);
3914 + if (newinfo->entries)
3915 + vfree(newinfo->entries);
3922 +int ebt_register_target(struct ebt_target *target)
3926 + ret = down_interruptible(&ebt_mutex);
3929 + if (!list_named_insert(&ebt_targets, target)) {
3934 + MOD_INC_USE_COUNT;
3939 +void ebt_unregister_target(struct ebt_target *target)
3942 + LIST_DELETE(&ebt_targets, target);
3944 + MOD_DEC_USE_COUNT;
3947 +int ebt_register_match(struct ebt_match *match)
3951 + ret = down_interruptible(&ebt_mutex);
3954 + if (!list_named_insert(&ebt_matches, match)) {
3959 + MOD_INC_USE_COUNT;
3964 +void ebt_unregister_match(struct ebt_match *match)
3967 + LIST_DELETE(&ebt_matches, match);
3969 + MOD_DEC_USE_COUNT;
3972 +int ebt_register_watcher(struct ebt_watcher *watcher)
3976 + ret = down_interruptible(&ebt_mutex);
3979 + if (!list_named_insert(&ebt_watchers, watcher)) {
3984 + MOD_INC_USE_COUNT;
3989 +void ebt_unregister_watcher(struct ebt_watcher *watcher)
3992 + LIST_DELETE(&ebt_watchers, watcher);
3994 + MOD_DEC_USE_COUNT;
3997 +int ebt_register_table(struct ebt_table *table)
3999 + struct ebt_table_info *newinfo;
4000 + int ret, i, countersize;
4002 + if (!table || !table->table ||!table->table->entries ||
4003 + table->table->entries_size == 0 ||
4004 + table->table->counters || table->private) {
4005 + BUGPRINT("Bad table data for ebt_register_table!!!\n");
4009 + countersize = COUNTER_OFFSET(table->table->nentries) * smp_num_cpus;
4010 + newinfo = (struct ebt_table_info *)
4011 + vmalloc(sizeof(struct ebt_table_info) + countersize);
4016 + newinfo->entries = (char *)vmalloc(table->table->entries_size);
4017 + if (!(newinfo->entries))
4018 + goto free_newinfo;
4020 + memcpy(newinfo->entries, table->table->entries,
4021 + table->table->entries_size);
4024 + memset(newinfo->counters, 0, countersize);
4026 + // fill in newinfo and parse the entries
4027 + newinfo->chainstack = NULL;
4028 + ret = translate_table(table->table, newinfo);
4030 + BUGPRINT("Translate_table failed\n");
4031 + goto free_chainstack;
4034 + if (table->check && table->check(newinfo, table->valid_hooks)) {
4035 + BUGPRINT("The table doesn't like its own initial data, lol\n");
4039 + table->private = newinfo;
4040 + table->lock = RW_LOCK_UNLOCKED;
4041 + ret = down_interruptible(&ebt_mutex);
4043 + goto free_chainstack;
4045 + if (list_named_find(&ebt_tables, table->name)) {
4047 + BUGPRINT("Table name already exists\n");
4051 + list_prepend(&ebt_tables, table);
4053 + MOD_INC_USE_COUNT;
4058 + if (newinfo->chainstack) {
4059 + for (i = 0; i < smp_num_cpus; i++)
4060 + vfree(newinfo->chainstack[i]);
4061 + vfree(newinfo->chainstack);
4063 + vfree(newinfo->entries);
4069 +void ebt_unregister_table(struct ebt_table *table)
4074 + BUGPRINT("Request to unregister NULL table!!!\n");
4078 + LIST_DELETE(&ebt_tables, table);
4080 + EBT_ENTRY_ITERATE(table->private->entries,
4081 + table->private->entries_size, ebt_cleanup_entry, NULL);
4082 + if (table->private->entries)
4083 + vfree(table->private->entries);
4084 + if (table->private->chainstack) {
4085 + for (i = 0; i < smp_num_cpus; i++)
4086 + vfree(table->private->chainstack[i]);
4087 + vfree(table->private->chainstack);
4089 + vfree(table->private);
4090 + MOD_DEC_USE_COUNT;
4093 +// userspace just supplied us with counters
4094 +static int update_counters(void *user, unsigned int len)
4097 + struct ebt_counter *tmp;
4098 + struct ebt_replace hlp;
4099 + struct ebt_table *t;
4101 + if (copy_from_user(&hlp, user, sizeof(hlp)))
4104 + if (len != sizeof(hlp) + hlp.num_counters * sizeof(struct ebt_counter))
4106 + if (hlp.num_counters == 0)
4109 + if ( !(tmp = (struct ebt_counter *)
4110 + vmalloc(hlp.num_counters * sizeof(struct ebt_counter))) ){
4111 + MEMPRINT("Update_counters && nomemory\n");
4115 + t = find_table_lock(hlp.name, &ret, &ebt_mutex);
4119 + if (hlp.num_counters != t->private->nentries) {
4120 + BUGPRINT("Wrong nr of counters\n");
4122 + goto unlock_mutex;
4125 + if ( copy_from_user(tmp, hlp.counters,
4126 + hlp.num_counters * sizeof(struct ebt_counter)) ) {
4127 + BUGPRINT("Updata_counters && !cfu\n");
4129 + goto unlock_mutex;
4132 + // we want an atomic add of the counters
4133 + write_lock_bh(&t->lock);
4135 + // we add to the counters of the first cpu
4136 + for (i = 0; i < hlp.num_counters; i++) {
4137 + t->private->counters[i].pcnt += tmp[i].pcnt;
4138 + t->private->counters[i].bcnt += tmp[i].bcnt;
4141 + write_unlock_bh(&t->lock);
4150 +static inline int ebt_make_matchname(struct ebt_entry_match *m,
4151 + char *base, char *ubase)
4153 + char *hlp = ubase - base + (char *)m;
4154 + if (copy_to_user(hlp, m->u.match->name, EBT_FUNCTION_MAXNAMELEN))
4159 +static inline int ebt_make_watchername(struct ebt_entry_watcher *w,
4160 + char *base, char *ubase)
4162 + char *hlp = ubase - base + (char *)w;
4163 + if (copy_to_user(hlp , w->u.watcher->name, EBT_FUNCTION_MAXNAMELEN))
4168 +static inline int ebt_make_names(struct ebt_entry *e, char *base, char *ubase)
4172 + struct ebt_entry_target *t;
4174 + if ((e->bitmask & EBT_ENTRY_OR_ENTRIES) == 0)
4177 + hlp = ubase - base + (char *)e + e->target_offset;
4178 + t = (struct ebt_entry_target *)(((char *)e) + e->target_offset);
4180 + ret = EBT_MATCH_ITERATE(e, ebt_make_matchname, base, ubase);
4183 + ret = EBT_WATCHER_ITERATE(e, ebt_make_watchername, base, ubase);
4186 + if (copy_to_user(hlp, t->u.target->name, EBT_FUNCTION_MAXNAMELEN))
4191 +// called with ebt_mutex down
4192 +static int copy_everything_to_user(struct ebt_table *t, void *user,
4193 + int *len, int cmd)
4195 + struct ebt_replace tmp;
4196 + struct ebt_counter *counterstmp, *oldcounters;
4197 + unsigned int entries_size, nentries;
4200 + if (cmd == EBT_SO_GET_ENTRIES) {
4201 + entries_size = t->private->entries_size;
4202 + nentries = t->private->nentries;
4203 + entries = t->private->entries;
4204 + oldcounters = t->private->counters;
4206 + entries_size = t->table->entries_size;
4207 + nentries = t->table->nentries;
4208 + entries = t->table->entries;
4209 + oldcounters = t->table->counters;
4212 + if (copy_from_user(&tmp, user, sizeof(tmp))) {
4213 + BUGPRINT("Cfu didn't work\n");
4217 + if (*len != sizeof(struct ebt_replace) + entries_size +
4218 + (tmp.num_counters? nentries * sizeof(struct ebt_counter): 0)) {
4219 + BUGPRINT("Wrong size\n");
4223 + if (tmp.nentries != nentries) {
4224 + BUGPRINT("Nentries wrong\n");
4228 + if (tmp.entries_size != entries_size) {
4229 + BUGPRINT("Wrong size\n");
4233 + // userspace might not need the counters
4234 + if (tmp.num_counters) {
4235 + if (tmp.num_counters != nentries) {
4236 + BUGPRINT("Num_counters wrong\n");
4239 + counterstmp = (struct ebt_counter *)
4240 + vmalloc(nentries * sizeof(struct ebt_counter));
4241 + if (!counterstmp) {
4242 + MEMPRINT("Couldn't copy counters, out of memory\n");
4245 + write_lock_bh(&t->lock);
4246 + get_counters(oldcounters, counterstmp, nentries);
4247 + write_unlock_bh(&t->lock);
4249 + if (copy_to_user(tmp.counters, counterstmp,
4250 + nentries * sizeof(struct ebt_counter))) {
4251 + BUGPRINT("Couldn't copy counters to userspace\n");
4252 + vfree(counterstmp);
4255 + vfree(counterstmp);
4258 + if (copy_to_user(tmp.entries, entries, entries_size)) {
4259 + BUGPRINT("Couldn't copy entries to userspace\n");
4262 + // set the match/watcher/target names right
4263 + return EBT_ENTRY_ITERATE(entries, entries_size,
4264 + ebt_make_names, entries, tmp.entries);
4267 +static int do_ebt_set_ctl(struct sock *sk,
4268 + int cmd, void *user, unsigned int len)
4273 + case EBT_SO_SET_ENTRIES:
4274 + ret = do_replace(user, len);
4276 + case EBT_SO_SET_COUNTERS:
4277 + ret = update_counters(user, len);
4285 +static int do_ebt_get_ctl(struct sock *sk, int cmd, void *user, int *len)
4288 + struct ebt_replace tmp;
4289 + struct ebt_table *t;
4291 + if (copy_from_user(&tmp, user, sizeof(tmp)))
4294 + t = find_table_lock(tmp.name, &ret, &ebt_mutex);
4299 + case EBT_SO_GET_INFO:
4300 + case EBT_SO_GET_INIT_INFO:
4301 + if (*len != sizeof(struct ebt_replace)){
4306 + if (cmd == EBT_SO_GET_INFO) {
4307 + tmp.nentries = t->private->nentries;
4308 + tmp.entries_size = t->private->entries_size;
4309 + tmp.valid_hooks = t->valid_hooks;
4311 + tmp.nentries = t->table->nentries;
4312 + tmp.entries_size = t->table->entries_size;
4313 + tmp.valid_hooks = t->table->valid_hooks;
4316 + if (copy_to_user(user, &tmp, *len) != 0){
4317 + BUGPRINT("c2u Didn't work\n");
4324 + case EBT_SO_GET_ENTRIES:
4325 + case EBT_SO_GET_INIT_ENTRIES:
4326 + ret = copy_everything_to_user(t, user, len, cmd);
4338 +static struct nf_sockopt_ops ebt_sockopts =
4339 +{ { NULL, NULL }, PF_INET, EBT_BASE_CTL, EBT_SO_SET_MAX + 1, do_ebt_set_ctl,
4340 + EBT_BASE_CTL, EBT_SO_GET_MAX + 1, do_ebt_get_ctl, 0, NULL
4343 +static int __init init(void)
4348 + list_named_insert(&ebt_targets, &ebt_standard_target);
4350 + if ((ret = nf_register_sockopt(&ebt_sockopts)) < 0)
4353 + printk(KERN_NOTICE "Ebtables v2.0 registered\n");
4357 +static void __exit fini(void)
4359 + nf_unregister_sockopt(&ebt_sockopts);
4360 + printk(KERN_NOTICE "Ebtables v2.0 unregistered\n");
4363 +EXPORT_SYMBOL(ebt_register_table);
4364 +EXPORT_SYMBOL(ebt_unregister_table);
4365 +EXPORT_SYMBOL(ebt_register_match);
4366 +EXPORT_SYMBOL(ebt_unregister_match);
4367 +EXPORT_SYMBOL(ebt_register_watcher);
4368 +EXPORT_SYMBOL(ebt_unregister_watcher);
4369 +EXPORT_SYMBOL(ebt_register_target);
4370 +EXPORT_SYMBOL(ebt_unregister_target);
4371 +EXPORT_SYMBOL(ebt_do_table);
4374 +MODULE_LICENSE("GPL");
4375 --- /dev/null 2005-09-22 15:53:13.374707688 +0000
4376 +++ linux-2.4.31-ebt-brnf/include/linux/netfilter_bridge/ebtables.h 2005-09-15 16:57:23.000000000 +0000
4382 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
4384 + * ebtables.c,v 2.0, September, 2002
4386 + * This code is stongly inspired on the iptables code which is
4387 + * Copyright (C) 1999 Paul `Rusty' Russell & Michael J. Neuling
4390 +#ifndef __LINUX_BRIDGE_EFF_H
4391 +#define __LINUX_BRIDGE_EFF_H
4392 +#include <linux/if.h>
4393 +#include <linux/netfilter_bridge.h>
4394 +#include <linux/if_ether.h>
4396 +#define EBT_TABLE_MAXNAMELEN 32
4397 +#define EBT_CHAIN_MAXNAMELEN EBT_TABLE_MAXNAMELEN
4398 +#define EBT_FUNCTION_MAXNAMELEN EBT_TABLE_MAXNAMELEN
4400 +// verdicts >0 are "branches"
4401 +#define EBT_ACCEPT -1
4402 +#define EBT_DROP -2
4403 +#define EBT_CONTINUE -3
4404 +#define EBT_RETURN -4
4405 +#define NUM_STANDARD_TARGETS 4
4413 +struct ebt_entries {
4414 + // this field is always set to zero
4415 + // See EBT_ENTRY_OR_ENTRIES.
4416 + // Must be same size as ebt_entry.bitmask
4417 + unsigned int distinguisher;
4419 + char name[EBT_CHAIN_MAXNAMELEN];
4420 + // counter offset for this chain
4421 + unsigned int counter_offset;
4422 + // one standard (accept, drop, return) per hook
4425 + unsigned int nentries;
4430 +// used for the bitmask of struct ebt_entry
4432 +// This is a hack to make a difference between an ebt_entry struct and an
4433 +// ebt_entries struct when traversing the entries from start to end.
4434 +// Using this simplifies the code alot, while still being able to use
4436 +// Contrary, iptables doesn't use something like ebt_entries and therefore uses
4437 +// different techniques for naming the policy and such. So, iptables doesn't
4438 +// need a hack like this.
4439 +#define EBT_ENTRY_OR_ENTRIES 0x01
4440 +// these are the normal masks
4441 +#define EBT_NOPROTO 0x02
4442 +#define EBT_802_3 0x04
4443 +#define EBT_SOURCEMAC 0x08
4444 +#define EBT_DESTMAC 0x10
4445 +#define EBT_F_MASK (EBT_NOPROTO | EBT_802_3 | EBT_SOURCEMAC | EBT_DESTMAC \
4446 + | EBT_ENTRY_OR_ENTRIES)
4448 +#define EBT_IPROTO 0x01
4449 +#define EBT_IIN 0x02
4450 +#define EBT_IOUT 0x04
4451 +#define EBT_ISOURCE 0x8
4452 +#define EBT_IDEST 0x10
4453 +#define EBT_ILOGICALIN 0x20
4454 +#define EBT_ILOGICALOUT 0x40
4455 +#define EBT_INV_MASK (EBT_IPROTO | EBT_IIN | EBT_IOUT | EBT_ILOGICALIN \
4456 + | EBT_ILOGICALOUT | EBT_ISOURCE | EBT_IDEST)
4458 +struct ebt_entry_match
4461 + char name[EBT_FUNCTION_MAXNAMELEN];
4462 + struct ebt_match *match;
4465 + unsigned int match_size;
4466 + unsigned char data[0];
4469 +struct ebt_entry_watcher
4472 + char name[EBT_FUNCTION_MAXNAMELEN];
4473 + struct ebt_watcher *watcher;
4476 + unsigned int watcher_size;
4477 + unsigned char data[0];
4480 +struct ebt_entry_target
4483 + char name[EBT_FUNCTION_MAXNAMELEN];
4484 + struct ebt_target *target;
4487 + unsigned int target_size;
4488 + unsigned char data[0];
4491 +#define EBT_STANDARD_TARGET "standard"
4492 +struct ebt_standard_target
4494 + struct ebt_entry_target target;
4500 + // this needs to be the first field
4501 + unsigned int bitmask;
4502 + unsigned int invflags;
4503 + uint16_t ethproto;
4504 + // the physical in-dev
4505 + char in[IFNAMSIZ];
4506 + // the logical in-dev
4507 + char logical_in[IFNAMSIZ];
4508 + // the physical out-dev
4509 + char out[IFNAMSIZ];
4510 + // the logical out-dev
4511 + char logical_out[IFNAMSIZ];
4512 + unsigned char sourcemac[ETH_ALEN];
4513 + unsigned char sourcemsk[ETH_ALEN];
4514 + unsigned char destmac[ETH_ALEN];
4515 + unsigned char destmsk[ETH_ALEN];
4516 + // sizeof ebt_entry + matches
4517 + unsigned int watchers_offset;
4518 + // sizeof ebt_entry + matches + watchers
4519 + unsigned int target_offset;
4520 + // sizeof ebt_entry + matches + watchers + target
4521 + unsigned int next_offset;
4522 + unsigned char elems[0];
4527 + char name[EBT_TABLE_MAXNAMELEN];
4528 + unsigned int valid_hooks;
4529 + // nr of rules in the table
4530 + unsigned int nentries;
4531 + // total size of the entries
4532 + unsigned int entries_size;
4533 + // start of the chains
4534 + struct ebt_entries *hook_entry[NF_BR_NUMHOOKS];
4535 + // nr of counters userspace expects back
4536 + unsigned int num_counters;
4537 + // where the kernel will put the old counters
4538 + struct ebt_counter *counters;
4542 +// [gs]etsockopt numbers
4543 +#define EBT_BASE_CTL 128
4545 +#define EBT_SO_SET_ENTRIES (EBT_BASE_CTL)
4546 +#define EBT_SO_SET_COUNTERS (EBT_SO_SET_ENTRIES+1)
4547 +#define EBT_SO_SET_MAX (EBT_SO_SET_COUNTERS+1)
4549 +#define EBT_SO_GET_INFO (EBT_BASE_CTL)
4550 +#define EBT_SO_GET_ENTRIES (EBT_SO_GET_INFO+1)
4551 +#define EBT_SO_GET_INIT_INFO (EBT_SO_GET_ENTRIES+1)
4552 +#define EBT_SO_GET_INIT_ENTRIES (EBT_SO_GET_INIT_INFO+1)
4553 +#define EBT_SO_GET_MAX (EBT_SO_GET_INIT_ENTRIES+1)
4557 +// return values for match() functions
4558 +#define EBT_MATCH 0
4559 +#define EBT_NOMATCH 1
4563 + struct list_head list;
4564 + const char name[EBT_FUNCTION_MAXNAMELEN];
4565 + // 0 == it matches
4566 + int (*match)(const struct sk_buff *skb, const struct net_device *in,
4567 + const struct net_device *out, const void *matchdata,
4568 + unsigned int datalen);
4570 + int (*check)(const char *tablename, unsigned int hookmask,
4571 + const struct ebt_entry *e, void *matchdata, unsigned int datalen);
4572 + void (*destroy)(void *matchdata, unsigned int datalen);
4573 + struct module *me;
4578 + struct list_head list;
4579 + const char name[EBT_FUNCTION_MAXNAMELEN];
4580 + void (*watcher)(const struct sk_buff *skb, unsigned int hooknr,
4581 + const struct net_device *in, const struct net_device *out,
4582 + const void *watcherdata, unsigned int datalen);
4584 + int (*check)(const char *tablename, unsigned int hookmask,
4585 + const struct ebt_entry *e, void *watcherdata, unsigned int datalen);
4586 + void (*destroy)(void *watcherdata, unsigned int datalen);
4587 + struct module *me;
4592 + struct list_head list;
4593 + const char name[EBT_FUNCTION_MAXNAMELEN];
4594 + // returns one of the standard verdicts
4595 + int (*target)(struct sk_buff **pskb, unsigned int hooknr,
4596 + const struct net_device *in, const struct net_device *out,
4597 + const void *targetdata, unsigned int datalen);
4599 + int (*check)(const char *tablename, unsigned int hookmask,
4600 + const struct ebt_entry *e, void *targetdata, unsigned int datalen);
4601 + void (*destroy)(void *targetdata, unsigned int datalen);
4602 + struct module *me;
4605 +// used for jumping from and into user defined chains (udc)
4606 +struct ebt_chainstack
4608 + struct ebt_entries *chaininfo; // pointer to chain data
4609 + struct ebt_entry *e; // pointer to entry data
4610 + unsigned int n; // n'th entry
4613 +struct ebt_table_info
4615 + // total size of the entries
4616 + unsigned int entries_size;
4617 + unsigned int nentries;
4618 + // pointers to the start of the chains
4619 + struct ebt_entries *hook_entry[NF_BR_NUMHOOKS];
4620 + // room to maintain the stack used for jumping from and into udc
4621 + struct ebt_chainstack **chainstack;
4623 + struct ebt_counter counters[0] ____cacheline_aligned;
4628 + struct list_head list;
4629 + char name[EBT_TABLE_MAXNAMELEN];
4630 + struct ebt_replace *table;
4631 + unsigned int valid_hooks;
4633 + // e.g. could be the table explicitly only allows certain
4634 + // matches, targets, ... 0 == let it in
4635 + int (*check)(const struct ebt_table_info *info,
4636 + unsigned int valid_hooks);
4637 + // the data used by the kernel
4638 + struct ebt_table_info *private;
4641 +#define EBT_ALIGN(s) (((s) + (__alignof__(struct ebt_entry_target)-1)) & \
4642 + ~(__alignof__(struct ebt_entry_target)-1))
4643 +extern int ebt_register_table(struct ebt_table *table);
4644 +extern void ebt_unregister_table(struct ebt_table *table);
4645 +extern int ebt_register_match(struct ebt_match *match);
4646 +extern void ebt_unregister_match(struct ebt_match *match);
4647 +extern int ebt_register_watcher(struct ebt_watcher *watcher);
4648 +extern void ebt_unregister_watcher(struct ebt_watcher *watcher);
4649 +extern int ebt_register_target(struct ebt_target *target);
4650 +extern void ebt_unregister_target(struct ebt_target *target);
4651 +extern unsigned int ebt_do_table(unsigned int hook, struct sk_buff **pskb,
4652 + const struct net_device *in, const struct net_device *out,
4653 + struct ebt_table *table);
4655 + // Used in the kernel match() functions
4656 +#define FWINV(bool,invflg) ((bool) ^ !!(info->invflags & invflg))
4657 +// True if the hook mask denotes that the rule is in a base chain,
4658 +// used in the check() functions
4659 +#define BASE_CHAIN (hookmask & (1 << NF_BR_NUMHOOKS))
4660 +// Clear the bit in the hook mask that tells if the rule is on a base chain
4661 +#define CLEAR_BASE_CHAIN_BIT (hookmask &= ~(1 << NF_BR_NUMHOOKS))
4662 +// True if the target is not a standard target
4663 +#define INVALID_TARGET (info->target < -NUM_STANDARD_TARGETS || info->target >= 0)
4665 +#endif /* __KERNEL__ */
4667 +// blatently stolen from ip_tables.h
4668 +// fn returns 0 to continue iteration
4669 +#define EBT_MATCH_ITERATE(e, fn, args...) \
4671 + unsigned int __i; \
4673 + struct ebt_entry_match *__match; \
4675 + for (__i = sizeof(struct ebt_entry); \
4676 + __i < (e)->watchers_offset; \
4677 + __i += __match->match_size + \
4678 + sizeof(struct ebt_entry_match)) { \
4679 + __match = (void *)(e) + __i; \
4681 + __ret = fn(__match , ## args); \
4685 + if (__ret == 0) { \
4686 + if (__i != (e)->watchers_offset) \
4687 + __ret = -EINVAL; \
4692 +#define EBT_WATCHER_ITERATE(e, fn, args...) \
4694 + unsigned int __i; \
4696 + struct ebt_entry_watcher *__watcher; \
4698 + for (__i = e->watchers_offset; \
4699 + __i < (e)->target_offset; \
4700 + __i += __watcher->watcher_size + \
4701 + sizeof(struct ebt_entry_watcher)) { \
4702 + __watcher = (void *)(e) + __i; \
4704 + __ret = fn(__watcher , ## args); \
4708 + if (__ret == 0) { \
4709 + if (__i != (e)->target_offset) \
4710 + __ret = -EINVAL; \
4715 +#define EBT_ENTRY_ITERATE(entries, size, fn, args...) \
4717 + unsigned int __i; \
4719 + struct ebt_entry *__entry; \
4721 + for (__i = 0; __i < (size);) { \
4722 + __entry = (void *)(entries) + __i; \
4723 + __ret = fn(__entry , ## args); \
4726 + if (__entry->bitmask != 0) \
4727 + __i += __entry->next_offset; \
4729 + __i += sizeof(struct ebt_entries); \
4731 + if (__ret == 0) { \
4732 + if (__i != (size)) \
4733 + __ret = -EINVAL; \
4739 --- /dev/null 2005-09-22 15:53:13.374707688 +0000
4740 +++ linux-2.4.31-ebt-brnf/include/linux/netfilter_bridge/ebt_among.h 2005-09-15 16:57:23.000000000 +0000
4742 +#ifndef __LINUX_BRIDGE_EBT_AMONG_H
4743 +#define __LINUX_BRIDGE_EBT_AMONG_H
4745 +#define EBT_AMONG_DST 0x01
4746 +#define EBT_AMONG_SRC 0x02
4748 +/* Grzegorz Borowiak <grzes@gnu.univ.gda.pl> 2003
4750 + * Write-once-read-many hash table, used for checking if a given
4751 + * MAC address belongs to a set or not and possibly for checking
4752 + * if it is related with a given IPv4 address.
4754 + * The hash value of an address is its last byte.
4756 + * In real-world ethernet addresses, values of the last byte are
4757 + * evenly distributed and there is no need to consider other bytes.
4758 + * It would only slow the routines down.
4760 + * For MAC address comparison speedup reasons, we introduce a trick.
4761 + * MAC address is mapped onto an array of two 32-bit integers.
4762 + * This pair of integers is compared with MAC addresses in the
4763 + * hash table, which are stored also in form of pairs of integers
4764 + * (in `cmp' array). This is quick as it requires only two elementary
4765 + * number comparisons in worst case. Further, we take advantage of
4766 + * fact that entropy of 3 last bytes of address is larger than entropy
4767 + * of 3 first bytes. So first we compare 4 last bytes of addresses and
4768 + * if they are the same we compare 2 first.
4770 + * Yes, it is a memory overhead, but in 2003 AD, who cares?
4773 +struct ebt_mac_wormhash_tuple
4779 +struct ebt_mac_wormhash
4783 + struct ebt_mac_wormhash_tuple pool[0];
4786 +#define ebt_mac_wormhash_size(x) ((x) ? sizeof(struct ebt_mac_wormhash) \
4787 + + (x)->poolsize * sizeof(struct ebt_mac_wormhash_tuple) : 0)
4789 +struct ebt_among_info
4796 +#define EBT_AMONG_DST_NEG 0x1
4797 +#define EBT_AMONG_SRC_NEG 0x2
4799 +#define ebt_among_wh_dst(x) ((x)->wh_dst_ofs ? \
4800 + (struct ebt_mac_wormhash*)((char*)(x) + (x)->wh_dst_ofs) : NULL)
4801 +#define ebt_among_wh_src(x) ((x)->wh_src_ofs ? \
4802 + (struct ebt_mac_wormhash*)((char*)(x) + (x)->wh_src_ofs) : NULL)
4804 +#define EBT_AMONG_MATCH "among"
4807 --- /dev/null 2005-09-22 15:53:13.374707688 +0000
4808 +++ linux-2.4.31-ebt-brnf/include/linux/netfilter_bridge/ebt_limit.h 2005-09-15 16:57:23.000000000 +0000
4810 +#ifndef __LINUX_BRIDGE_EBT_LIMIT_H
4811 +#define __LINUX_BRIDGE_EBT_LIMIT_H
4813 +#define EBT_LIMIT_MATCH "limit"
4815 +/* timings are in milliseconds. */
4816 +#define EBT_LIMIT_SCALE 10000
4818 +/* 1/10,000 sec period => max of 10,000/sec. Min rate is then 429490
4819 + seconds, or one every 59 hours. */
4821 +struct ebt_limit_info
4823 + u_int32_t avg; /* Average secs between packets * scale */
4824 + u_int32_t burst; /* Period multiplier for upper limit. */
4826 + /* Used internally by the kernel */
4827 + unsigned long prev;
4829 + u_int32_t credit_cap, cost;
4833 --- /dev/null 2005-09-22 15:53:13.374707688 +0000
4834 +++ linux-2.4.31-ebt-brnf/include/linux/netfilter_bridge/ebt_arpreply.h 2005-09-15 16:57:23.000000000 +0000
4836 +#ifndef __LINUX_BRIDGE_EBT_ARPREPLY_H
4837 +#define __LINUX_BRIDGE_EBT_ARPREPLY_H
4839 +struct ebt_arpreply_info
4841 + unsigned char mac[ETH_ALEN];
4844 +#define EBT_ARPREPLY_TARGET "arpreply"
4847 --- /dev/null 2005-09-22 15:53:13.374707688 +0000
4848 +++ linux-2.4.31-ebt-brnf/include/linux/netfilter_bridge/ebt_802_3.h 2005-09-15 16:57:23.000000000 +0000
4850 +#ifndef __LINUX_BRIDGE_EBT_802_3_H
4851 +#define __LINUX_BRIDGE_EBT_802_3_H
4853 +#define EBT_802_3_SAP 0x01
4854 +#define EBT_802_3_TYPE 0x02
4856 +#define EBT_802_3_MATCH "802_3"
4859 + * If frame has DSAP/SSAP value 0xaa you must check the SNAP type
4860 + * to discover what kind of packet we're carrying.
4862 +#define CHECK_TYPE 0xaa
4865 + * Control field may be one or two bytes. If the first byte has
4866 + * the value 0x03 then the entire length is one byte, otherwise it is two.
4867 + * One byte controls are used in Unnumbered Information frames.
4868 + * Two byte controls are used in Numbered Information frames.
4872 +#define EBT_802_3_MASK (EBT_802_3_SAP | EBT_802_3_TYPE | EBT_802_3)
4874 +/* ui has one byte ctrl, ni has two */
4891 +struct ebt_802_3_hdr {
4901 +struct ebt_802_3_info
4910 --- /dev/null 2005-09-22 15:53:13.374707688 +0000
4911 +++ linux-2.4.31-ebt-brnf/include/linux/netfilter_bridge/ebt_arp.h 2005-09-15 16:57:23.000000000 +0000
4913 +#ifndef __LINUX_BRIDGE_EBT_ARP_H
4914 +#define __LINUX_BRIDGE_EBT_ARP_H
4916 +#define EBT_ARP_OPCODE 0x01
4917 +#define EBT_ARP_HTYPE 0x02
4918 +#define EBT_ARP_PTYPE 0x04
4919 +#define EBT_ARP_SRC_IP 0x08
4920 +#define EBT_ARP_DST_IP 0x10
4921 +#define EBT_ARP_SRC_MAC 0x20
4922 +#define EBT_ARP_DST_MAC 0x40
4923 +#define EBT_ARP_MASK (EBT_ARP_OPCODE | EBT_ARP_HTYPE | EBT_ARP_PTYPE | \
4924 + EBT_ARP_SRC_IP | EBT_ARP_DST_IP | EBT_ARP_SRC_MAC | EBT_ARP_DST_MAC)
4925 +#define EBT_ARP_MATCH "arp"
4927 +struct ebt_arp_info
4936 + unsigned char smaddr[ETH_ALEN];
4937 + unsigned char smmsk[ETH_ALEN];
4938 + unsigned char dmaddr[ETH_ALEN];
4939 + unsigned char dmmsk[ETH_ALEN];
4945 --- /dev/null 2005-09-22 15:53:13.374707688 +0000
4946 +++ linux-2.4.31-ebt-brnf/include/linux/netfilter_bridge/ebt_ip.h 2005-09-15 16:57:23.000000000 +0000
4952 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
4957 + * added ip-sport and ip-dport
4958 + * Innominate Security Technologies AG <mhopf@innominate.com>
4962 +#ifndef __LINUX_BRIDGE_EBT_IP_H
4963 +#define __LINUX_BRIDGE_EBT_IP_H
4965 +#define EBT_IP_SOURCE 0x01
4966 +#define EBT_IP_DEST 0x02
4967 +#define EBT_IP_TOS 0x04
4968 +#define EBT_IP_PROTO 0x08
4969 +#define EBT_IP_SPORT 0x10
4970 +#define EBT_IP_DPORT 0x20
4971 +#define EBT_IP_MASK (EBT_IP_SOURCE | EBT_IP_DEST | EBT_IP_TOS | EBT_IP_PROTO |\
4972 + EBT_IP_SPORT | EBT_IP_DPORT )
4973 +#define EBT_IP_MATCH "ip"
4975 +// the same values are used for the invflags
4986 + uint16_t sport[2];
4987 + uint16_t dport[2];
4991 --- /dev/null 2005-09-22 15:53:13.374707688 +0000
4992 +++ linux-2.4.31-ebt-brnf/include/linux/netfilter_bridge/ebt_pkttype.h 2005-09-15 16:57:23.000000000 +0000
4994 +#ifndef __LINUX_BRIDGE_EBT_PKTTYPE_H
4995 +#define __LINUX_BRIDGE_EBT_PKTTYPE_H
4997 +struct ebt_pkttype_info
5002 +#define EBT_PKTTYPE_MATCH "pkttype"
5005 --- /dev/null 2005-09-22 15:53:13.374707688 +0000
5006 +++ linux-2.4.31-ebt-brnf/include/linux/netfilter_bridge/ebt_stp.h 2005-09-15 16:57:23.000000000 +0000
5008 +#ifndef __LINUX_BRIDGE_EBT_STP_H
5009 +#define __LINUX_BRIDGE_EBT_STP_H
5011 +#define EBT_STP_TYPE 0x0001
5013 +#define EBT_STP_FLAGS 0x0002
5014 +#define EBT_STP_ROOTPRIO 0x0004
5015 +#define EBT_STP_ROOTADDR 0x0008
5016 +#define EBT_STP_ROOTCOST 0x0010
5017 +#define EBT_STP_SENDERPRIO 0x0020
5018 +#define EBT_STP_SENDERADDR 0x0040
5019 +#define EBT_STP_PORT 0x0080
5020 +#define EBT_STP_MSGAGE 0x0100
5021 +#define EBT_STP_MAXAGE 0x0200
5022 +#define EBT_STP_HELLOTIME 0x0400
5023 +#define EBT_STP_FWDD 0x0800
5025 +#define EBT_STP_MASK 0x0fff
5026 +#define EBT_STP_CONFIG_MASK 0x0ffe
5028 +#define EBT_STP_MATCH "stp"
5030 +struct ebt_stp_config_info
5033 + uint16_t root_priol, root_priou;
5034 + char root_addr[6], root_addrmsk[6];
5035 + uint32_t root_costl, root_costu;
5036 + uint16_t sender_priol, sender_priou;
5037 + char sender_addr[6], sender_addrmsk[6];
5038 + uint16_t portl, portu;
5039 + uint16_t msg_agel, msg_ageu;
5040 + uint16_t max_agel, max_ageu;
5041 + uint16_t hello_timel, hello_timeu;
5042 + uint16_t forward_delayl, forward_delayu;
5045 +struct ebt_stp_info
5048 + struct ebt_stp_config_info config;
5050 + uint16_t invflags;
5054 --- /dev/null 2005-09-22 15:53:13.374707688 +0000
5055 +++ linux-2.4.31-ebt-brnf/include/linux/netfilter_bridge/ebt_vlan.h 2005-09-15 16:57:23.000000000 +0000
5057 +#ifndef __LINUX_BRIDGE_EBT_VLAN_H
5058 +#define __LINUX_BRIDGE_EBT_VLAN_H
5060 +#define EBT_VLAN_ID 0x01
5061 +#define EBT_VLAN_PRIO 0x02
5062 +#define EBT_VLAN_ENCAP 0x04
5063 +#define EBT_VLAN_MASK (EBT_VLAN_ID | EBT_VLAN_PRIO | EBT_VLAN_ENCAP)
5064 +#define EBT_VLAN_MATCH "vlan"
5066 +struct ebt_vlan_info {
5067 + uint16_t id; /* VLAN ID {1-4095} */
5068 + uint8_t prio; /* VLAN User Priority {0-7} */
5069 + uint16_t encap; /* VLAN Encapsulated frame code {0-65535} */
5070 + uint8_t bitmask; /* Args bitmask bit 1=1 - ID arg,
5071 + bit 2=1 User-Priority arg, bit 3=1 encap*/
5072 + uint8_t invflags; /* Inverse bitmask bit 1=1 - inversed ID arg,
5073 + bit 2=1 - inversed Pirority arg */
5077 --- /dev/null 2005-09-22 15:53:13.374707688 +0000
5078 +++ linux-2.4.31-ebt-brnf/include/linux/netfilter_bridge/ebt_log.h 2005-09-15 16:57:23.000000000 +0000
5080 +#ifndef __LINUX_BRIDGE_EBT_LOG_H
5081 +#define __LINUX_BRIDGE_EBT_LOG_H
5083 +#define EBT_LOG_IP 0x01 // if the frame is made by ip, log the ip information
5084 +#define EBT_LOG_ARP 0x02
5085 +#define EBT_LOG_MASK (EBT_LOG_IP | EBT_LOG_ARP)
5086 +#define EBT_LOG_PREFIX_SIZE 30
5087 +#define EBT_LOG_WATCHER "log"
5089 +struct ebt_log_info
5092 + uint8_t prefix[EBT_LOG_PREFIX_SIZE];
5097 --- /dev/null 2005-09-22 15:53:13.374707688 +0000
5098 +++ linux-2.4.31-ebt-brnf/include/linux/netfilter_bridge/ebt_ulog.h 2005-09-15 16:57:23.000000000 +0000
5100 +#ifndef _EBT_ULOG_H
5101 +#define _EBT_ULOG_H
5103 +#define EBT_ULOG_DEFAULT_NLGROUP 0
5104 +#define EBT_ULOG_DEFAULT_QTHRESHOLD 1
5105 +#define EBT_ULOG_MAXNLGROUPS 32 /* hardcoded netlink max */
5106 +#define EBT_ULOG_PREFIX_LEN 32
5107 +#define EBT_ULOG_MAX_QLEN 50
5108 +#define EBT_ULOG_WATCHER "ulog"
5110 +struct ebt_ulog_info {
5112 + unsigned int cprange;
5113 + unsigned int qthreshold;
5114 + char prefix[EBT_ULOG_PREFIX_LEN];
5117 +typedef struct ebt_ulog_packet_msg {
5118 + char indev[IFNAMSIZ];
5119 + char outdev[IFNAMSIZ];
5120 + char physindev[IFNAMSIZ];
5121 + char physoutdev[IFNAMSIZ];
5122 + char prefix[EBT_ULOG_PREFIX_LEN];
5123 + struct timeval stamp;
5124 + unsigned long mark;
5125 + unsigned int hook;
5127 + /* The complete packet, including Ethernet header and perhaps
5128 + * the VLAN header is appended */
5129 + unsigned char data[0] __attribute__ ((aligned (__alignof__(int))));
5130 +} ebt_ulog_packet_msg_t;
5132 +#endif /* _EBT_ULOG_H */
5133 --- /dev/null 2005-09-22 15:53:13.374707688 +0000
5134 +++ linux-2.4.31-ebt-brnf/include/linux/netfilter_bridge/ebt_nat.h 2005-09-15 16:57:23.000000000 +0000
5136 +#ifndef __LINUX_BRIDGE_EBT_NAT_H
5137 +#define __LINUX_BRIDGE_EBT_NAT_H
5139 +struct ebt_nat_info
5141 + unsigned char mac[ETH_ALEN];
5142 + // EBT_ACCEPT, EBT_DROP, EBT_CONTINUE or EBT_RETURN
5145 +#define EBT_SNAT_TARGET "snat"
5146 +#define EBT_DNAT_TARGET "dnat"
5149 --- /dev/null 2005-09-22 15:53:13.374707688 +0000
5150 +++ linux-2.4.31-ebt-brnf/include/linux/netfilter_bridge/ebt_redirect.h 2005-09-15 16:57:23.000000000 +0000
5152 +#ifndef __LINUX_BRIDGE_EBT_REDIRECT_H
5153 +#define __LINUX_BRIDGE_EBT_REDIRECT_H
5155 +struct ebt_redirect_info
5157 + // EBT_ACCEPT, EBT_DROP or EBT_CONTINUE or EBT_RETURN
5160 +#define EBT_REDIRECT_TARGET "redirect"
5163 --- /dev/null 2005-09-22 15:53:13.374707688 +0000
5164 +++ linux-2.4.31-ebt-brnf/include/linux/netfilter_bridge/ebt_mark_m.h 2005-09-15 16:57:23.000000000 +0000
5166 +#ifndef __LINUX_BRIDGE_EBT_MARK_M_H
5167 +#define __LINUX_BRIDGE_EBT_MARK_M_H
5169 +#define EBT_MARK_AND 0x01
5170 +#define EBT_MARK_OR 0x02
5171 +#define EBT_MARK_MASK (EBT_MARK_AND | EBT_MARK_OR)
5172 +struct ebt_mark_m_info
5174 + unsigned long mark, mask;
5178 +#define EBT_MARK_MATCH "mark_m"
5181 --- /dev/null 2005-09-22 15:53:13.374707688 +0000
5182 +++ linux-2.4.31-ebt-brnf/include/linux/netfilter_bridge/ebt_mark_t.h 2005-09-15 16:57:23.000000000 +0000
5184 +#ifndef __LINUX_BRIDGE_EBT_MARK_T_H
5185 +#define __LINUX_BRIDGE_EBT_MARK_T_H
5187 +struct ebt_mark_t_info
5189 + unsigned long mark;
5190 + // EBT_ACCEPT, EBT_DROP or EBT_CONTINUE or EBT_RETURN
5193 +#define EBT_MARK_TARGET "mark"
5196 --- linux-2.4.31/include/linux/netfilter.h 2005-01-19 14:10:12.000000000 +0000
5197 +++ linux-2.4.31-ebt-brnf/include/linux/netfilter.h 2005-09-15 16:57:23.000000000 +0000
5202 -#define NF_MAX_VERDICT NF_REPEAT
5204 +#define NF_MAX_VERDICT NF_STOP
5206 /* Generic cache responses from hook functions.
5207 <= 0x2000 is used for protocol-flags. */
5208 @@ -118,17 +119,34 @@ extern struct list_head nf_hooks[NPROTO]
5209 /* This is gross, but inline doesn't cut it for avoiding the function
5210 call in fast path: gcc doesn't inline (needs value tracking?). --RR */
5211 #ifdef CONFIG_NETFILTER_DEBUG
5212 -#define NF_HOOK nf_hook_slow
5213 +#define NF_HOOK(pf, hook, skb, indev, outdev, okfn) \
5215 +if ((__ret=nf_hook_slow(pf, hook, &(skb), indev, outdev, okfn, INT_MIN)) == 1) \
5216 + __ret = (okfn)(skb); \
5218 +#define NF_HOOK_THRESH(pf, hook, skb, indev, outdev, okfn, thresh) \
5220 +if ((__ret=nf_hook_slow(pf, hook, &(skb), indev, outdev, okfn, thresh)) == 1) \
5221 + __ret = (okfn)(skb); \
5224 -#define NF_HOOK(pf, hook, skb, indev, outdev, okfn) \
5225 -(list_empty(&nf_hooks[(pf)][(hook)]) \
5227 - : nf_hook_slow((pf), (hook), (skb), (indev), (outdev), (okfn)))
5228 +#define NF_HOOK(pf, hook, skb, indev, outdev, okfn) \
5230 +if (list_empty(&nf_hooks[pf][hook]) || \
5231 + (__ret=nf_hook_slow(pf, hook, &(skb), indev, outdev, okfn, INT_MIN)) == 1) \
5232 + __ret = (okfn)(skb); \
5234 +#define NF_HOOK_THRESH(pf, hook, skb, indev, outdev, okfn, thresh) \
5236 +if (list_empty(&nf_hooks[pf][hook]) || \
5237 + (__ret=nf_hook_slow(pf, hook, &(skb), indev, outdev, okfn, thresh)) == 1) \
5238 + __ret = (okfn)(skb); \
5242 -int nf_hook_slow(int pf, unsigned int hook, struct sk_buff *skb,
5243 +int nf_hook_slow(int pf, unsigned int hook, struct sk_buff **pskb,
5244 struct net_device *indev, struct net_device *outdev,
5245 - int (*okfn)(struct sk_buff *));
5246 + int (*okfn)(struct sk_buff *), int thresh);
5248 /* Call setsockopt() */
5249 int nf_setsockopt(struct sock *sk, int pf, int optval, char *opt,
5250 --- linux-2.4.31/include/linux/netfilter_ipv4.h 2002-02-25 19:38:13.000000000 +0000
5251 +++ linux-2.4.31-ebt-brnf/include/linux/netfilter_ipv4.h 2005-09-15 16:57:23.000000000 +0000
5253 enum nf_ip_hook_priorities {
5254 NF_IP_PRI_FIRST = INT_MIN,
5255 NF_IP_PRI_CONNTRACK = -200,
5256 + NF_IP_PRI_BRIDGE_SABOTAGE_FORWARD = -175,
5257 NF_IP_PRI_MANGLE = -150,
5258 NF_IP_PRI_NAT_DST = -100,
5259 + NF_IP_PRI_BRIDGE_SABOTAGE_LOCAL_OUT = -50,
5260 NF_IP_PRI_FILTER = 0,
5261 NF_IP_PRI_NAT_SRC = 100,
5262 NF_IP_PRI_LAST = INT_MAX,
5263 --- linux-2.4.31/include/linux/netfilter_ipv6.h 2001-01-02 00:17:54.000000000 +0000
5264 +++ linux-2.4.31-ebt-brnf/include/linux/netfilter_ipv6.h 2005-09-15 16:57:23.000000000 +0000
5266 enum nf_ip6_hook_priorities {
5267 NF_IP6_PRI_FIRST = INT_MIN,
5268 NF_IP6_PRI_CONNTRACK = -200,
5269 + NF_IP6_PRI_BRIDGE_SABOTAGE_FORWARD = -175,
5270 NF_IP6_PRI_MANGLE = -150,
5271 NF_IP6_PRI_NAT_DST = -100,
5272 + NF_IP6_PRI_BRIDGE_SABOTAGE_LOCAL_OUT = -50,
5273 NF_IP6_PRI_FILTER = 0,
5274 NF_IP6_PRI_NAT_SRC = 100,
5275 NF_IP6_PRI_LAST = INT_MAX,
5276 --- linux-2.4.31/include/linux/skbuff.h 2005-04-04 01:42:20.000000000 +0000
5277 +++ linux-2.4.31-ebt-brnf/include/linux/skbuff.h 2005-09-15 16:57:23.000000000 +0000
5278 @@ -92,6 +92,20 @@ struct nf_conntrack {
5280 struct nf_conntrack *master;
5283 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
5284 +struct nf_bridge_info {
5286 + struct net_device *physindev;
5287 + struct net_device *physoutdev;
5288 +#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
5289 + struct net_device *netoutdev;
5291 + unsigned int mask;
5292 + unsigned long data[32 / sizeof(unsigned long)];
5298 struct sk_buff_head {
5299 @@ -208,6 +222,9 @@ struct sk_buff {
5300 #ifdef CONFIG_NETFILTER_DEBUG
5301 unsigned int nf_debug;
5303 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
5304 + struct nf_bridge_info *nf_bridge; /* Saved data about a bridged frame - see br_netfilter.c */
5306 #endif /*CONFIG_NETFILTER*/
5308 #if defined(CONFIG_HIPPI)
5309 @@ -1171,6 +1188,20 @@ nf_reset(struct sk_buff *skb)
5314 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
5315 +static inline void nf_bridge_put(struct nf_bridge_info *nf_bridge)
5317 + if (nf_bridge && atomic_dec_and_test(&nf_bridge->use))
5320 +static inline void nf_bridge_get(struct nf_bridge_info *nf_bridge)
5323 + atomic_inc(&nf_bridge->use);
5327 #else /* CONFIG_NETFILTER */
5328 static inline void nf_reset(struct sk_buff *skb) {}
5329 #endif /* CONFIG_NETFILTER */
5330 --- linux-2.4.31/net/core/netfilter.c 2005-01-19 14:10:13.000000000 +0000
5331 +++ linux-2.4.31-ebt-brnf/net/core/netfilter.c 2005-09-15 16:57:23.000000000 +0000
5332 @@ -342,32 +342,29 @@ static unsigned int nf_iterate(struct li
5333 const struct net_device *indev,
5334 const struct net_device *outdev,
5335 struct list_head **i,
5336 - int (*okfn)(struct sk_buff *))
5337 + int (*okfn)(struct sk_buff *),
5340 + unsigned int verdict;
5342 for (*i = (*i)->next; *i != head; *i = (*i)->next) {
5343 struct nf_hook_ops *elem = (struct nf_hook_ops *)*i;
5344 - switch (elem->hook(hook, skb, indev, outdev, okfn)) {
5357 + if (hook_thresh > elem->priority)
5360 + verdict = elem->hook(hook, skb, indev, outdev, okfn);
5361 + if (verdict != NF_ACCEPT) {
5362 #ifdef CONFIG_NETFILTER_DEBUG
5367 - NFDEBUG("Evil return from %p(%u).\n",
5368 - elem->hook, hook);
5369 + if (unlikely(verdict > NF_MAX_VERDICT)) {
5370 + NFDEBUG("Evil return from %p(%u).\n",
5371 + elem->hook, hook);
5375 + if (verdict != NF_REPEAT)
5381 @@ -413,6 +410,10 @@ static void nf_queue(struct sk_buff *skb
5384 struct nf_info *info;
5385 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
5386 + struct net_device *physindev = NULL;
5387 + struct net_device *physoutdev = NULL;
5390 if (!queue_handler[pf].outfn) {
5392 @@ -435,36 +436,52 @@ static void nf_queue(struct sk_buff *skb
5393 if (indev) dev_hold(indev);
5394 if (outdev) dev_hold(outdev);
5396 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
5397 + if (skb->nf_bridge) {
5398 + physindev = skb->nf_bridge->physindev;
5399 + if (physindev) dev_hold(physindev);
5400 + physoutdev = skb->nf_bridge->physoutdev;
5401 + if (physoutdev) dev_hold(physoutdev);
5405 status = queue_handler[pf].outfn(skb, info, queue_handler[pf].data);
5407 /* James M doesn't say fuck enough. */
5408 if (indev) dev_put(indev);
5409 if (outdev) dev_put(outdev);
5410 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
5411 + if (physindev) dev_put(physindev);
5412 + if (physoutdev) dev_put(physoutdev);
5420 -int nf_hook_slow(int pf, unsigned int hook, struct sk_buff *skb,
5421 +/* Returns 1 if okfn() needs to be executed by the caller,
5422 + * -EPERM for NF_DROP, 0 otherwise. */
5423 +int nf_hook_slow(int pf, unsigned int hook, struct sk_buff **pskb,
5424 struct net_device *indev,
5425 struct net_device *outdev,
5426 - int (*okfn)(struct sk_buff *))
5427 + int (*okfn)(struct sk_buff *),
5430 struct list_head *elem;
5431 unsigned int verdict;
5434 /* This stopgap cannot be removed until all the hooks are audited. */
5435 - if (skb_is_nonlinear(skb) && skb_linearize(skb, GFP_ATOMIC) != 0) {
5437 + if (skb_is_nonlinear(*pskb) && skb_linearize(*pskb, GFP_ATOMIC) != 0) {
5441 - if (skb->ip_summed == CHECKSUM_HW) {
5442 + if ((*pskb)->ip_summed == CHECKSUM_HW) {
5443 if (outdev == NULL) {
5444 - skb->ip_summed = CHECKSUM_NONE;
5445 + (*pskb)->ip_summed = CHECKSUM_NONE;
5447 - skb_checksum_help(skb);
5448 + skb_checksum_help(*pskb);
5452 @@ -472,30 +489,24 @@ int nf_hook_slow(int pf, unsigned int ho
5453 br_read_lock_bh(BR_NETPROTO_LOCK);
5455 #ifdef CONFIG_NETFILTER_DEBUG
5456 - if (skb->nf_debug & (1 << hook)) {
5457 + if (unlikely((*pskb)->nf_debug & (1 << hook))) {
5458 printk("nf_hook: hook %i already set.\n", hook);
5459 - nf_dump_skb(pf, skb);
5460 + nf_dump_skb(pf, *pskb);
5462 - skb->nf_debug |= (1 << hook);
5463 + (*pskb)->nf_debug |= (1 << hook);
5466 elem = &nf_hooks[pf][hook];
5467 - verdict = nf_iterate(&nf_hooks[pf][hook], &skb, hook, indev,
5468 - outdev, &elem, okfn);
5469 - if (verdict == NF_QUEUE) {
5470 - NFDEBUG("nf_hook: Verdict = QUEUE.\n");
5471 - nf_queue(skb, elem, pf, hook, indev, outdev, okfn);
5474 - switch (verdict) {
5481 + verdict = nf_iterate(&nf_hooks[pf][hook], pskb, hook, indev,
5482 + outdev, &elem, okfn, hook_thresh);
5483 + if (verdict == NF_ACCEPT || verdict == NF_STOP)
5485 + else if (verdict == NF_DROP) {
5489 + } else if (verdict == NF_QUEUE) {
5490 + NFDEBUG("nf_hook: Verdict = QUEUE.\n");
5491 + nf_queue(*pskb, elem, pf, hook, indev, outdev, okfn);
5494 br_read_unlock_bh(BR_NETPROTO_LOCK);
5495 @@ -510,6 +521,14 @@ void nf_reinject(struct sk_buff *skb, st
5497 /* We don't have BR_NETPROTO_LOCK here */
5498 br_read_lock_bh(BR_NETPROTO_LOCK);
5499 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
5500 + if (skb->nf_bridge) {
5501 + if (skb->nf_bridge->physindev)
5502 + dev_put(skb->nf_bridge->physindev);
5503 + if (skb->nf_bridge->physoutdev)
5504 + dev_put(skb->nf_bridge->physoutdev);
5507 for (i = nf_hooks[info->pf][info->hook].next; i != elem; i = i->next) {
5508 if (i == &nf_hooks[info->pf][info->hook]) {
5509 /* The module which sent it to userspace is gone. */
5510 @@ -530,7 +549,7 @@ void nf_reinject(struct sk_buff *skb, st
5511 verdict = nf_iterate(&nf_hooks[info->pf][info->hook],
5513 info->indev, info->outdev, &elem,
5515 + info->okfn, INT_MIN);
5519 --- linux-2.4.31/net/core/skbuff.c 2003-08-25 11:44:44.000000000 +0000
5520 +++ linux-2.4.31-ebt-brnf/net/core/skbuff.c 2005-09-15 16:57:23.000000000 +0000
5521 @@ -246,6 +246,9 @@ static inline void skb_headerinit(void *
5522 #ifdef CONFIG_NETFILTER_DEBUG
5525 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
5526 + skb->nf_bridge = NULL;
5529 #ifdef CONFIG_NET_SCHED
5531 @@ -326,6 +329,9 @@ void __kfree_skb(struct sk_buff *skb)
5533 #ifdef CONFIG_NETFILTER
5534 nf_conntrack_put(skb->nfct);
5535 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
5536 + nf_bridge_put(skb->nf_bridge);
5539 skb_headerinit(skb, NULL, 0); /* clean state */
5541 @@ -393,6 +399,9 @@ struct sk_buff *skb_clone(struct sk_buff
5542 #ifdef CONFIG_NETFILTER_DEBUG
5545 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
5548 #endif /*CONFIG_NETFILTER*/
5549 #if defined(CONFIG_HIPPI)
5551 @@ -405,6 +414,9 @@ struct sk_buff *skb_clone(struct sk_buff
5553 #ifdef CONFIG_NETFILTER
5554 nf_conntrack_get(skb->nfct);
5555 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
5556 + nf_bridge_get(skb->nf_bridge);
5561 @@ -440,6 +452,10 @@ static void copy_skb_header(struct sk_bu
5562 #ifdef CONFIG_NETFILTER_DEBUG
5563 new->nf_debug=old->nf_debug;
5565 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
5566 + new->nf_bridge=old->nf_bridge;
5567 + nf_bridge_get(new->nf_bridge);
5570 #ifdef CONFIG_NET_SCHED
5571 new->tc_index = old->tc_index;
5572 @@ -726,9 +742,9 @@ struct sk_buff *skb_copy_expand(const st
5573 /* Set the tail pointer and length */
5574 skb_put(n,skb->len);
5576 - /* Copy the data only. */
5577 - if (skb_copy_bits(skb, 0, n->data, skb->len))
5579 + /* Copy the linear data and header. */
5580 + if (skb_copy_bits(skb, -newheadroom, n->head, newheadroom + skb->len))
5583 copy_skb_header(n, skb);
5585 --- linux-2.4.31/net/ipv4/netfilter/ip_tables.c 2005-04-04 01:42:20.000000000 +0000
5586 +++ linux-2.4.31-ebt-brnf/net/ipv4/netfilter/ip_tables.c 2005-09-15 16:57:23.000000000 +0000
5587 @@ -120,12 +120,19 @@ static LIST_HEAD(ipt_tables);
5589 ip_packet_match(const struct iphdr *ip,
5591 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
5592 + const char *physindev,
5595 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
5596 + const char *physoutdev,
5598 const struct ipt_ip *ipinfo,
5603 + unsigned long ret2 = 1;
5605 #define FWINV(bool,invflg) ((bool) ^ !!(ipinfo->invflags & invflg))
5607 @@ -155,7 +162,15 @@ ip_packet_match(const struct iphdr *ip,
5608 & ((const unsigned long *)ipinfo->iniface_mask)[i];
5611 - if (FWINV(ret != 0, IPT_INV_VIA_IN)) {
5612 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
5613 + for (i = 0, ret2 = 0; i < IFNAMSIZ/sizeof(unsigned long); i++) {
5614 + ret2 |= (((const unsigned long *)physindev)[i]
5615 + ^ ((const unsigned long *)ipinfo->iniface)[i])
5616 + & ((const unsigned long *)ipinfo->iniface_mask)[i];
5620 + if (FWINV(ret != 0 && ret2 != 0, IPT_INV_VIA_IN)) {
5621 dprintf("VIA in mismatch (%s vs %s).%s\n",
5622 indev, ipinfo->iniface,
5623 ipinfo->invflags&IPT_INV_VIA_IN ?" (INV)":"");
5624 @@ -168,7 +183,15 @@ ip_packet_match(const struct iphdr *ip,
5625 & ((const unsigned long *)ipinfo->outiface_mask)[i];
5628 - if (FWINV(ret != 0, IPT_INV_VIA_OUT)) {
5629 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
5630 + for (i = 0, ret2 = 0; i < IFNAMSIZ/sizeof(unsigned long); i++) {
5631 + ret2 |= (((const unsigned long *)physoutdev)[i]
5632 + ^ ((const unsigned long *)ipinfo->outiface)[i])
5633 + & ((const unsigned long *)ipinfo->outiface_mask)[i];
5637 + if (FWINV(ret != 0 && ret2 != 0, IPT_INV_VIA_OUT)) {
5638 dprintf("VIA out mismatch (%s vs %s).%s\n",
5639 outdev, ipinfo->outiface,
5640 ipinfo->invflags&IPT_INV_VIA_OUT ?" (INV)":"");
5641 @@ -267,6 +290,9 @@ ipt_do_table(struct sk_buff **pskb,
5642 /* Initializing verdict to NF_DROP keeps gcc happy. */
5643 unsigned int verdict = NF_DROP;
5644 const char *indev, *outdev;
5645 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
5646 + const char *physindev, *physoutdev;
5649 struct ipt_entry *e, *back;
5651 @@ -276,6 +302,13 @@ ipt_do_table(struct sk_buff **pskb,
5652 datalen = (*pskb)->len - ip->ihl * 4;
5653 indev = in ? in->name : nulldevname;
5654 outdev = out ? out->name : nulldevname;
5655 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
5656 + physindev = ((*pskb)->nf_bridge && (*pskb)->nf_bridge->physindev) ?
5657 + (*pskb)->nf_bridge->physindev->name : nulldevname;
5658 + physoutdev = ((*pskb)->nf_bridge && (*pskb)->nf_bridge->physoutdev) ?
5659 + (*pskb)->nf_bridge->physoutdev->name : nulldevname;
5662 /* We handle fragments by dealing with the first fragment as
5663 * if it was a normal packet. All other fragments are treated
5664 * normally, except that they will NEVER match rules that ask
5665 @@ -311,7 +344,15 @@ ipt_do_table(struct sk_buff **pskb,
5668 (*pskb)->nfcache |= e->nfcache;
5669 - if (ip_packet_match(ip, indev, outdev, &e->ip, offset)) {
5670 + if (ip_packet_match(ip, indev,
5671 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
5675 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
5678 + &e->ip, offset)) {
5679 struct ipt_entry_target *t;
5681 if (IPT_MATCH_ITERATE(e, do_match,
5682 --- linux-2.4.31/net/ipv4/ip_output.c 2005-01-19 14:10:13.000000000 +0000
5683 +++ linux-2.4.31-ebt-brnf/net/ipv4/ip_output.c 2005-09-15 16:57:23.000000000 +0000
5685 #include <linux/netfilter_ipv4.h>
5686 #include <linux/mroute.h>
5687 #include <linux/netlink.h>
5688 +#include <linux/netfilter_bridge.h>
5691 * Shall we try to damage output packets if routing dev changes?
5692 @@ -769,7 +770,8 @@ int ip_fragment(struct sk_buff *skb, int
5694 struct rtable *rt = (struct rtable*)skb->dst;
5697 + unsigned int ll_rs = 0;
5699 dev = rt->u.dst.dev;
5702 @@ -785,6 +787,10 @@ int ip_fragment(struct sk_buff *skb, int
5703 hlen = iph->ihl * 4;
5704 left = skb->len - hlen; /* Space per frame */
5705 mtu = rt->u.dst.pmtu - hlen; /* Size of data space */
5706 +#ifdef CONFIG_NETFILTER
5707 + ll_rs = nf_bridge_pad(skb);
5710 ptr = raw + hlen; /* Where to start from */
5713 @@ -812,7 +818,7 @@ int ip_fragment(struct sk_buff *skb, int
5717 - if ((skb2 = alloc_skb(len+hlen+dev->hard_header_len+15,GFP_ATOMIC)) == NULL) {
5718 + if ((skb2 = alloc_skb(len+hlen+dev->hard_header_len+15+ll_rs,GFP_ATOMIC)) == NULL) {
5719 NETDEBUG(printk(KERN_INFO "IP: frag: no memory for new fragment!\n"));
5722 @@ -824,7 +830,7 @@ int ip_fragment(struct sk_buff *skb, int
5724 skb2->pkt_type = skb->pkt_type;
5725 skb2->priority = skb->priority;
5726 - skb_reserve(skb2, (dev->hard_header_len+15)&~15);
5727 + skb_reserve(skb2, (dev->hard_header_len+15+ll_rs)&~15);
5728 skb_put(skb2, len + hlen);
5729 skb2->nh.raw = skb2->data;
5730 skb2->h.raw = skb2->data + hlen;
5731 @@ -890,6 +896,10 @@ int ip_fragment(struct sk_buff *skb, int
5732 /* Connection association is same as pre-frag packet */
5733 skb2->nfct = skb->nfct;
5734 nf_conntrack_get(skb2->nfct);
5735 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
5736 + skb2->nf_bridge = skb->nf_bridge;
5737 + nf_bridge_get(skb2->nf_bridge);
5739 #ifdef CONFIG_NETFILTER_DEBUG
5740 skb2->nf_debug = skb->nf_debug;
5742 --- linux-2.4.31/net/ipv4/netfilter/ipt_LOG.c 2005-04-04 01:42:20.000000000 +0000
5743 +++ linux-2.4.31-ebt-brnf/net/ipv4/netfilter/ipt_LOG.c 2005-09-15 16:57:23.000000000 +0000
5744 @@ -317,6 +317,18 @@ ipt_log_target(struct sk_buff **pskb,
5747 out ? out->name : "");
5748 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
5749 + if ((*pskb)->nf_bridge) {
5750 + struct net_device *physindev = (*pskb)->nf_bridge->physindev;
5751 + struct net_device *physoutdev = (*pskb)->nf_bridge->physoutdev;
5753 + if (physindev && in != physindev)
5754 + printk("PHYSIN=%s ", physindev->name);
5755 + if (physoutdev && out != physoutdev)
5756 + printk("PHYSOUT=%s ", physoutdev->name);
5761 /* MAC logging for input chain only. */
5763 --- linux-2.4.31/net/ipv4/netfilter/Makefile 2003-08-25 11:44:44.000000000 +0000
5764 +++ linux-2.4.31-ebt-brnf/net/ipv4/netfilter/Makefile 2005-09-15 16:57:23.000000000 +0000
5765 @@ -87,6 +87,8 @@ obj-$(CONFIG_IP_NF_MATCH_CONNTRACK) += i
5766 obj-$(CONFIG_IP_NF_MATCH_UNCLEAN) += ipt_unclean.o
5767 obj-$(CONFIG_IP_NF_MATCH_TCPMSS) += ipt_tcpmss.o
5769 +obj-$(CONFIG_IP_NF_MATCH_PHYSDEV) += ipt_physdev.o
5772 obj-$(CONFIG_IP_NF_TARGET_REJECT) += ipt_REJECT.o
5773 obj-$(CONFIG_IP_NF_TARGET_MIRROR) += ipt_MIRROR.o
5774 --- linux-2.4.31/net/ipv4/netfilter/Config.in 2005-01-19 14:10:13.000000000 +0000
5775 +++ linux-2.4.31-ebt-brnf/net/ipv4/netfilter/Config.in 2005-09-15 16:57:23.000000000 +0000
5776 @@ -44,6 +44,9 @@ if [ "$CONFIG_IP_NF_IPTABLES" != "n" ];
5777 dep_tristate ' Unclean match support (EXPERIMENTAL)' CONFIG_IP_NF_MATCH_UNCLEAN $CONFIG_IP_NF_IPTABLES
5778 dep_tristate ' Owner match support (EXPERIMENTAL)' CONFIG_IP_NF_MATCH_OWNER $CONFIG_IP_NF_IPTABLES
5780 + if [ "$CONFIG_BRIDGE" != "n" ]; then
5781 + dep_tristate ' Physdev match support' CONFIG_IP_NF_MATCH_PHYSDEV $CONFIG_IP_NF_IPTABLES
5784 dep_tristate ' Packet filtering' CONFIG_IP_NF_FILTER $CONFIG_IP_NF_IPTABLES
5785 if [ "$CONFIG_IP_NF_FILTER" != "n" ]; then
5786 --- /dev/null 2005-09-22 15:53:13.374707688 +0000
5787 +++ linux-2.4.31-ebt-brnf/net/bridge/br_netfilter.c 2005-09-15 17:00:24.000000000 +0000
5790 + * Handle firewalling
5791 + * Linux ethernet bridge
5794 + * Lennert Buytenhek <buytenh@gnu.org>
5795 + * Bart De Schuymer (maintainer) <bdschuym@pandora.be>
5798 + * Apr 29 2003: physdev module support (bdschuym)
5799 + * Jun 19 2003: let arptables see bridged ARP traffic (bdschuym)
5800 + * Oct 06 2003: filter encapsulated IP/ARP VLAN traffic on untagged bridge
5802 + * Aug 28 2004: add IPv6 filtering (bdschuym)
5804 + * This program is free software; you can redistribute it and/or
5805 + * modify it under the terms of the GNU General Public License
5806 + * as published by the Free Software Foundation; either version
5807 + * 2 of the License, or (at your option) any later version.
5809 + * Lennert dedicates this file to Kerstin Wurdinger.
5812 +#include <linux/module.h>
5813 +#include <linux/kernel.h>
5814 +#include <linux/ip.h>
5815 +#include <linux/netdevice.h>
5816 +#include <linux/skbuff.h>
5817 +#include <linux/if_ether.h>
5818 +#include <linux/if_vlan.h>
5819 +#include <linux/netfilter_bridge.h>
5820 +#include <linux/netfilter_ipv4.h>
5821 +#include <linux/netfilter_ipv6.h>
5822 +#include <linux/in_route.h>
5823 +#include <net/ip.h>
5824 +#include <net/ipv6.h>
5825 +#include <asm/uaccess.h>
5826 +#include <asm/checksum.h>
5827 +#include "br_private.h"
5828 +#ifdef CONFIG_SYSCTL
5829 +#include <linux/sysctl.h>
5832 +#define skb_origaddr(skb) (((struct bridge_skb_cb *) \
5833 + (skb->nf_bridge->data))->daddr.ipv4)
5834 +#define store_orig_dstaddr(skb) (skb_origaddr(skb) = (skb)->nh.iph->daddr)
5835 +#define dnat_took_place(skb) (skb_origaddr(skb) != (skb)->nh.iph->daddr)
5837 +#define has_bridge_parent(device) ((device)->br_port != NULL)
5838 +#define bridge_parent(device) (&((device)->br_port->br->dev))
5840 +#ifdef CONFIG_SYSCTL
5841 +static struct ctl_table_header *brnf_sysctl_header;
5842 +static int brnf_call_iptables = 1;
5843 +static int brnf_call_ip6tables = 1;
5844 +static int brnf_call_arptables = 1;
5845 +static int brnf_filter_vlan_tagged = 1;
5847 +#define brnf_filter_vlan_tagged 1
5850 +#define IS_VLAN_IP (skb->protocol == __constant_htons(ETH_P_8021Q) && \
5851 + hdr->h_vlan_encapsulated_proto == __constant_htons(ETH_P_IP) && \
5852 + brnf_filter_vlan_tagged)
5853 +#define IS_VLAN_IPV6 (skb->protocol == __constant_htons(ETH_P_8021Q) && \
5854 + hdr->h_vlan_encapsulated_proto == __constant_htons(ETH_P_IPV6) && \
5855 + brnf_filter_vlan_tagged)
5857 +#define IS_VLAN_ARP (skb->protocol == __constant_htons(ETH_P_8021Q) && \
5858 + hdr->h_vlan_encapsulated_proto == __constant_htons(ETH_P_ARP) && \
5859 + brnf_filter_vlan_tagged)
5862 +/* We need these fake structures to make netfilter happy --
5863 + * lots of places assume that skb->dst != NULL, which isn't
5864 + * all that unreasonable.
5866 + * Currently, we fill in the PMTU entry because netfilter
5867 + * refragmentation needs it, and the rt_flags entry because
5868 + * ipt_REJECT needs it. Future netfilter modules might
5869 + * require us to fill additional fields.
5871 +static struct net_device __fake_net_device = {
5872 + .hard_header_len = ETH_HLEN
5875 +static struct rtable __fake_rtable = {
5878 + __refcnt: ATOMIC_INIT(1),
5879 + dev: &__fake_net_device,
5888 +/* PF_BRIDGE/PRE_ROUTING *********************************************/
5889 +/* Undo the changes made for ip6tables PREROUTING and continue the
5890 + * bridge PRE_ROUTING hook. */
5891 +static int br_nf_pre_routing_finish_ipv6(struct sk_buff *skb)
5893 + struct nf_bridge_info *nf_bridge = skb->nf_bridge;
5895 +#ifdef CONFIG_NETFILTER_DEBUG
5896 + skb->nf_debug ^= (1 << NF_BR_PRE_ROUTING);
5899 + if (nf_bridge->mask & BRNF_PKT_TYPE) {
5900 + skb->pkt_type = PACKET_OTHERHOST;
5901 + nf_bridge->mask ^= BRNF_PKT_TYPE;
5903 + nf_bridge->mask ^= BRNF_NF_BRIDGE_PREROUTING;
5905 + skb->dst = (struct dst_entry *)&__fake_rtable;
5906 + dst_hold(skb->dst);
5908 + skb->dev = nf_bridge->physindev;
5909 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
5910 + skb_push(skb, VLAN_HLEN);
5911 + skb->nh.raw -= VLAN_HLEN;
5913 + NF_HOOK_THRESH(PF_BRIDGE, NF_BR_PRE_ROUTING, skb, skb->dev, NULL,
5914 + br_handle_frame_finish, 1);
5919 +static void __br_dnat_complain(void)
5921 + static unsigned long last_complaint;
5923 + if (jiffies - last_complaint >= 5 * HZ) {
5924 + printk(KERN_WARNING "Performing cross-bridge DNAT requires IP "
5925 + "forwarding to be enabled\n");
5926 + last_complaint = jiffies;
5931 +/* This requires some explaining. If DNAT has taken place,
5932 + * we will need to fix up the destination Ethernet address,
5933 + * and this is a tricky process.
5935 + * There are two cases to consider:
5936 + * 1. The packet was DNAT'ed to a device in the same bridge
5937 + * port group as it was received on. We can still bridge
5939 + * 2. The packet was DNAT'ed to a different device, either
5940 + * a non-bridged device or another bridge port group.
5941 + * The packet will need to be routed.
5943 + * The correct way of distinguishing between these two cases is to
5944 + * call ip_route_input() and to look at skb->dst->dev, which is
5945 + * changed to the destination device if ip_route_input() succeeds.
5947 + * Let us first consider the case that ip_route_input() succeeds:
5949 + * If skb->dst->dev equals the logical bridge device the packet
5950 + * came in on, we can consider this bridging. We then call
5951 + * skb->dst->output() which will make the packet enter br_nf_local_out()
5952 + * not much later. In that function it is assured that the iptables
5953 + * FORWARD chain is traversed for the packet.
5955 + * Otherwise, the packet is considered to be routed and we just
5956 + * change the destination MAC address so that the packet will
5957 + * later be passed up to the IP stack to be routed.
5959 + * Let us now consider the case that ip_route_input() fails:
5961 + * After a "echo '0' > /proc/sys/net/ipv4/ip_forward" ip_route_input()
5962 + * will fail, while __ip_route_output_key() will return success. The source
5963 + * address for __ip_route_output_key() is set to zero, so __ip_route_output_key
5964 + * thinks we're handling a locally generated packet and won't care
5965 + * if IP forwarding is allowed. We send a warning message to the users's
5966 + * log telling her to put IP forwarding on.
5968 + * ip_route_input() will also fail if there is no route available.
5969 + * In that case we just drop the packet.
5971 + * --Lennert, 20020411
5972 + * --Bart, 20020416 (updated)
5973 + * --Bart, 20021007 (updated)
5976 +static int br_nf_pre_routing_finish_bridge(struct sk_buff *skb)
5978 +#ifdef CONFIG_NETFILTER_DEBUG
5979 + skb->nf_debug |= (1 << NF_BR_PRE_ROUTING) | (1 << NF_BR_FORWARD);
5982 + if (skb->pkt_type == PACKET_OTHERHOST) {
5983 + skb->pkt_type = PACKET_HOST;
5984 + skb->nf_bridge->mask |= BRNF_PKT_TYPE;
5986 + skb->nf_bridge->mask ^= BRNF_NF_BRIDGE_PREROUTING;
5988 + skb->dev = bridge_parent(skb->dev);
5989 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
5990 + skb_pull(skb, VLAN_HLEN);
5991 + skb->nh.raw += VLAN_HLEN;
5993 + skb->dst->output(skb);
5997 +static int br_nf_pre_routing_finish(struct sk_buff *skb)
5999 + struct net_device *dev = skb->dev;
6000 + struct iphdr *iph = skb->nh.iph;
6001 + struct nf_bridge_info *nf_bridge = skb->nf_bridge;
6003 +#ifdef CONFIG_NETFILTER_DEBUG
6004 + skb->nf_debug ^= (1 << NF_BR_PRE_ROUTING);
6007 + if (nf_bridge->mask & BRNF_PKT_TYPE) {
6008 + skb->pkt_type = PACKET_OTHERHOST;
6009 + nf_bridge->mask ^= BRNF_PKT_TYPE;
6011 + nf_bridge->mask ^= BRNF_NF_BRIDGE_PREROUTING;
6013 + if (dnat_took_place(skb)) {
6014 + if (ip_route_input(skb, iph->daddr, iph->saddr, iph->tos,
6016 + struct rtable *rt;
6018 + if (!ip_route_output(&rt, iph->daddr, 0, iph->tos, 0)) {
6019 + /* - Bridged-and-DNAT'ed traffic doesn't
6020 + * require ip_forwarding.
6021 + * - Deal with redirected traffic. */
6022 + if (((struct dst_entry *)rt)->dev == dev ||
6023 + rt->rt_type == RTN_LOCAL) {
6024 + skb->dst = (struct dst_entry *)rt;
6025 + goto bridged_dnat;
6027 + __br_dnat_complain();
6028 + dst_release((struct dst_entry *)rt);
6033 + if (skb->dst->dev == dev) {
6035 + /* Tell br_nf_local_out this is a
6038 + nf_bridge->mask |= BRNF_BRIDGED_DNAT;
6039 + skb->dev = nf_bridge->physindev;
6040 + if (skb->protocol ==
6041 + __constant_htons(ETH_P_8021Q)) {
6042 + skb_push(skb, VLAN_HLEN);
6043 + skb->nh.raw -= VLAN_HLEN;
6045 + NF_HOOK_THRESH(PF_BRIDGE, NF_BR_PRE_ROUTING,
6046 + skb, skb->dev, NULL,
6047 + br_nf_pre_routing_finish_bridge,
6051 + memcpy(skb->mac.ethernet->h_dest, dev->dev_addr,
6053 + skb->pkt_type = PACKET_HOST;
6056 + skb->dst = (struct dst_entry *)&__fake_rtable;
6057 + dst_hold(skb->dst);
6060 + skb->dev = nf_bridge->physindev;
6061 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
6062 + skb_push(skb, VLAN_HLEN);
6063 + skb->nh.raw -= VLAN_HLEN;
6065 + NF_HOOK_THRESH(PF_BRIDGE, NF_BR_PRE_ROUTING, skb, skb->dev, NULL,
6066 + br_handle_frame_finish, 1);
6071 +/* Some common code for IPv4/IPv6 */
6072 +static void setup_pre_routing(struct sk_buff *skb)
6074 + struct nf_bridge_info *nf_bridge = skb->nf_bridge;
6076 + if (skb->pkt_type == PACKET_OTHERHOST) {
6077 + skb->pkt_type = PACKET_HOST;
6078 + nf_bridge->mask |= BRNF_PKT_TYPE;
6081 + nf_bridge->mask |= BRNF_NF_BRIDGE_PREROUTING;
6082 + nf_bridge->physindev = skb->dev;
6083 + skb->dev = bridge_parent(skb->dev);
6086 +/* We only check the length. A bridge shouldn't do any hop-by-hop stuff anyway */
6087 +static int check_hbh_len(struct sk_buff *skb)
6089 + unsigned char *raw = (u8*)(skb->nh.ipv6h+1);
6091 + int off = raw - skb->nh.raw;
6092 + int len = (raw[1]+1)<<3;
6094 + if ((raw + len) - skb->data > skb_headlen(skb))
6101 + int optlen = raw[off+1]+2;
6103 + switch (skb->nh.raw[off]) {
6104 + case IPV6_TLV_PAD0:
6108 + case IPV6_TLV_PADN:
6111 + case IPV6_TLV_JUMBO:
6112 + if (skb->nh.raw[off+1] != 4 || (off&3) != 2)
6115 + pkt_len = ntohl(*(u32*)(skb->nh.raw+off+2));
6117 + if (pkt_len > skb->len - sizeof(struct ipv6hdr))
6119 + if (pkt_len + sizeof(struct ipv6hdr) < skb->len) {
6120 + if (__pskb_trim(skb,
6121 + pkt_len + sizeof(struct ipv6hdr)))
6123 + if (skb->ip_summed == CHECKSUM_HW)
6124 + skb->ip_summed = CHECKSUM_NONE;
6142 +/* Replicate the checks that IPv6 does on packet reception and pass the packet
6143 + * to ip6tables, which doesn't support NAT, so things are fairly simple. */
6144 +static unsigned int br_nf_pre_routing_ipv6(unsigned int hook,
6145 + struct sk_buff *skb, const struct net_device *in,
6146 + const struct net_device *out, int (*okfn)(struct sk_buff *))
6148 + struct ipv6hdr *hdr;
6150 + struct nf_bridge_info *nf_bridge;
6152 + if (skb->len < sizeof(struct ipv6hdr))
6155 + if (!pskb_may_pull(skb, sizeof(struct ipv6hdr)))
6158 + hdr = skb->nh.ipv6h;
6160 + if (hdr->version != 6)
6163 + pkt_len = ntohs(hdr->payload_len);
6165 + if (pkt_len || hdr->nexthdr != NEXTHDR_HOP) {
6166 + if (pkt_len + sizeof(struct ipv6hdr) > skb->len)
6168 + if (pkt_len + sizeof(struct ipv6hdr) < skb->len) {
6169 + if (__pskb_trim(skb, pkt_len + sizeof(struct ipv6hdr)))
6171 + if (skb->ip_summed == CHECKSUM_HW)
6172 + skb->ip_summed = CHECKSUM_NONE;
6175 + if (hdr->nexthdr == NEXTHDR_HOP && check_hbh_len(skb))
6178 +#ifdef CONFIG_NETFILTER_DEBUG
6179 + skb->nf_debug ^= (1 << NF_IP6_PRE_ROUTING);
6181 + if ((nf_bridge = nf_bridge_alloc(skb)) == NULL)
6183 + setup_pre_routing(skb);
6185 + NF_HOOK(PF_INET6, NF_IP6_PRE_ROUTING, skb, skb->dev, NULL,
6186 + br_nf_pre_routing_finish_ipv6);
6194 +/* Direct IPv6 traffic to br_nf_pre_routing_ipv6.
6195 + * Replicate the checks that IPv4 does on packet reception.
6196 + * Set skb->dev to the bridge device (i.e. parent of the
6197 + * receiving device) to make netfilter happy, the REDIRECT
6198 + * target in particular. Save the original destination IP
6199 + * address to be able to detect DNAT afterwards.
6201 +static unsigned int br_nf_pre_routing(unsigned int hook, struct sk_buff **pskb,
6202 + const struct net_device *in, const struct net_device *out,
6203 + int (*okfn)(struct sk_buff *))
6205 + struct iphdr *iph;
6207 + struct sk_buff *skb = *pskb;
6208 + struct nf_bridge_info *nf_bridge;
6209 + struct vlan_ethhdr *hdr = (struct vlan_ethhdr *)
6210 + ((*pskb)->mac.ethernet);
6212 + if (skb->protocol == __constant_htons(ETH_P_IPV6) || IS_VLAN_IPV6) {
6213 +#ifdef CONFIG_SYSCTL
6214 + if (!brnf_call_ip6tables)
6217 + if ((skb = skb_share_check(*pskb, GFP_ATOMIC)) == NULL)
6220 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
6221 + skb_pull(skb, VLAN_HLEN);
6222 + (skb)->nh.raw += VLAN_HLEN;
6224 + return br_nf_pre_routing_ipv6(hook, skb, in, out, okfn);
6227 +#ifdef CONFIG_SYSCTL
6228 + if (!brnf_call_iptables)
6232 + if (skb->protocol != __constant_htons(ETH_P_IP) && !IS_VLAN_IP)
6234 + if ((skb = skb_share_check(*pskb, GFP_ATOMIC)) == NULL)
6237 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
6238 + skb_pull(skb, VLAN_HLEN);
6239 + (skb)->nh.raw += VLAN_HLEN;
6242 + if (!pskb_may_pull(skb, sizeof(struct iphdr)))
6245 + iph = skb->nh.iph;
6246 + if (iph->ihl < 5 || iph->version != 4)
6249 + if (!pskb_may_pull(skb, 4*iph->ihl))
6252 + iph = skb->nh.iph;
6253 + if (ip_fast_csum((__u8 *)iph, iph->ihl) != 0)
6256 + len = ntohs(iph->tot_len);
6257 + if (skb->len < len || len < 4*iph->ihl)
6260 + if (skb->len > len) {
6261 + __pskb_trim(skb, len);
6262 + if (skb->ip_summed == CHECKSUM_HW)
6263 + skb->ip_summed = CHECKSUM_NONE;
6266 +#ifdef CONFIG_NETFILTER_DEBUG
6267 + skb->nf_debug ^= (1 << NF_IP_PRE_ROUTING);
6269 + if ((nf_bridge = nf_bridge_alloc(skb)) == NULL)
6272 + setup_pre_routing(skb);
6273 + store_orig_dstaddr(skb);
6275 + NF_HOOK(PF_INET, NF_IP_PRE_ROUTING, skb, skb->dev, NULL,
6276 + br_nf_pre_routing_finish);
6281 +// IP_INC_STATS_BH(IpInHdrErrors);
6287 +/* PF_BRIDGE/LOCAL_IN ************************************************/
6288 +/* The packet is locally destined, which requires a real
6289 + * dst_entry, so detach the fake one. On the way up, the
6290 + * packet would pass through PRE_ROUTING again (which already
6291 + * took place when the packet entered the bridge), but we
6292 + * register an IPv4 PRE_ROUTING 'sabotage' hook that will
6293 + * prevent this from happening.
6295 +static unsigned int br_nf_local_in(unsigned int hook, struct sk_buff **pskb,
6296 + const struct net_device *in, const struct net_device *out,
6297 + int (*okfn)(struct sk_buff *))
6299 + struct sk_buff *skb = *pskb;
6301 + if (skb->dst == (struct dst_entry *)&__fake_rtable) {
6302 + dst_release(skb->dst);
6309 +/* PF_BRIDGE/FORWARD *************************************************/
6310 +static int br_nf_forward_finish(struct sk_buff *skb)
6312 + struct nf_bridge_info *nf_bridge = skb->nf_bridge;
6313 + struct net_device *in;
6314 +/* struct vlan_ethhdr *hdr = (struct vlan_ethhdr *)(skb->mac.ethernet);*/
6316 +#ifdef CONFIG_NETFILTER_DEBUG
6317 + skb->nf_debug ^= (1 << NF_BR_FORWARD);
6320 +/* if (skb->protocol != __constant_htons(ETH_P_ARP) && !IS_VLAN_ARP) {*/
6321 + in = nf_bridge->physindev;
6322 + if (nf_bridge->mask & BRNF_PKT_TYPE) {
6323 + skb->pkt_type = PACKET_OTHERHOST;
6324 + nf_bridge->mask ^= BRNF_PKT_TYPE;
6327 + in = *((struct net_device **)(skb->cb));
6329 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
6330 + skb_push(skb, VLAN_HLEN);
6331 + skb->nh.raw -= VLAN_HLEN;
6333 + NF_HOOK_THRESH(PF_BRIDGE, NF_BR_FORWARD, skb, in,
6334 + skb->dev, br_forward_finish, 1);
6338 +/* This is the 'purely bridged' case. For IP, we pass the packet to
6339 + * netfilter with indev and outdev set to the bridge device,
6340 + * but we are still able to filter on the 'real' indev/outdev
6341 + * because of the ipt_physdev.c module. For ARP, indev and outdev are the
6344 +static unsigned int br_nf_forward_ip(unsigned int hook, struct sk_buff **pskb,
6345 + const struct net_device *in, const struct net_device *out,
6346 + int (*okfn)(struct sk_buff *))
6348 + struct sk_buff *skb = *pskb;
6349 + struct nf_bridge_info *nf_bridge;
6350 + struct vlan_ethhdr *hdr = (struct vlan_ethhdr *)(skb->mac.ethernet);
6353 + if (!skb->nf_bridge)
6356 + if (skb->protocol == __constant_htons(ETH_P_IP) || IS_VLAN_IP)
6361 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
6362 + skb_pull(*pskb, VLAN_HLEN);
6363 + (*pskb)->nh.raw += VLAN_HLEN;
6366 +#ifdef CONFIG_NETFILTER_DEBUG
6367 + skb->nf_debug ^= (1 << NF_BR_FORWARD);
6369 + nf_bridge = skb->nf_bridge;
6370 + if (skb->pkt_type == PACKET_OTHERHOST) {
6371 + skb->pkt_type = PACKET_HOST;
6372 + nf_bridge->mask |= BRNF_PKT_TYPE;
6375 + /* The physdev module checks on this */
6376 + nf_bridge->mask |= BRNF_BRIDGED;
6377 + nf_bridge->physoutdev = skb->dev;
6379 + NF_HOOK(pf, NF_IP_FORWARD, skb, bridge_parent(in),
6380 + bridge_parent(out), br_nf_forward_finish);
6386 +static unsigned int br_nf_forward_arp(unsigned int hook, struct sk_buff **pskb,
6387 + const struct net_device *in, const struct net_device *out,
6388 + int (*okfn)(struct sk_buff *))
6390 + struct sk_buff *skb = *pskb;
6391 + struct vlan_ethhdr *hdr = (struct vlan_ethhdr *)(skb->mac.ethernet);
6392 + struct net_device **d = (struct net_device **)(skb->cb);
6394 + if (!brnf_call_arptables)
6397 + if (skb->protocol != __constant_htons(ETH_P_ARP)) {
6400 + skb_pull(*pskb, VLAN_HLEN);
6401 + (*pskb)->nh.raw += VLAN_HLEN;
6404 +#ifdef CONFIG_NETFILTER_DEBUG
6405 + skb->nf_debug ^= (1 << NF_BR_FORWARD);
6408 + if (skb->nh.arph->ar_pln != 4) {
6409 + if (IS_VLAN_ARP) {
6410 + skb_push(*pskb, VLAN_HLEN);
6411 + (*pskb)->nh.raw -= VLAN_HLEN;
6415 + *d = (struct net_device *)in;
6416 + NF_HOOK(NF_ARP, NF_ARP_FORWARD, skb, (struct net_device *)in,
6417 + (struct net_device *)out, br_nf_forward_finish);
6423 +/* PF_BRIDGE/LOCAL_OUT ***********************************************/
6424 +static int br_nf_local_out_finish(struct sk_buff *skb)
6426 +#ifdef CONFIG_NETFILTER_DEBUG
6427 + skb->nf_debug &= ~(1 << NF_BR_LOCAL_OUT);
6429 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
6430 + skb_push(skb, VLAN_HLEN);
6431 + skb->nh.raw -= VLAN_HLEN;
6434 + NF_HOOK_THRESH(PF_BRIDGE, NF_BR_LOCAL_OUT, skb, NULL, skb->dev,
6435 + br_forward_finish, NF_BR_PRI_FIRST + 1);
6441 +/* This function sees both locally originated IP packets and forwarded
6442 + * IP packets (in both cases the destination device is a bridge
6443 + * device). It also sees bridged-and-DNAT'ed packets.
6444 + * To be able to filter on the physical bridge devices (with the ipt_physdev.c
6445 + * module), we steal packets destined to a bridge device away from the
6446 + * PF_INET/FORWARD and PF_INET/OUTPUT hook functions, and give them back later,
6447 + * when we have determined the real output device. This is done in here.
6449 + * If (nf_bridge->mask & BRNF_BRIDGED_DNAT) then the packet is bridged
6450 + * and we fake the PF_BRIDGE/FORWARD hook. The function br_nf_forward()
6451 + * will then fake the PF_INET/FORWARD hook. br_nf_local_out() has priority
6452 + * NF_BR_PRI_FIRST, so no relevant PF_BRIDGE/INPUT functions have been nor
6453 + * will be executed.
6454 + * Otherwise, if nf_bridge->physindev is NULL, the bridge-nf code never touched
6455 + * this packet before, and so the packet was locally originated. We fake
6456 + * the PF_INET/LOCAL_OUT hook.
6457 + * Finally, if nf_bridge->physindev isn't NULL, then the packet was IP routed,
6458 + * so we fake the PF_INET/FORWARD hook. ipv4_sabotage_out() makes sure
6459 + * even routed packets that didn't arrive on a bridge interface have their
6460 + * nf_bridge->physindev set.
6463 +static unsigned int br_nf_local_out(unsigned int hook, struct sk_buff **pskb,
6464 + const struct net_device *in, const struct net_device *out,
6465 + int (*okfn)(struct sk_buff *))
6467 + struct net_device *realindev, *realoutdev;
6468 + struct sk_buff *skb = *pskb;
6469 + struct nf_bridge_info *nf_bridge;
6470 + struct vlan_ethhdr *hdr = (struct vlan_ethhdr *)(skb->mac.ethernet);
6473 + if (!skb->nf_bridge)
6476 + if (skb->protocol == __constant_htons(ETH_P_IP) || IS_VLAN_IP)
6481 +#ifdef CONFIG_NETFILTER_DEBUG
6482 + /* Sometimes we get packets with NULL ->dst here (for example,
6483 + * running a dhcp client daemon triggers this). This should now
6484 + * be fixed, but let's keep the check around. */
6485 + if (skb->dst == NULL) {
6486 + printk(KERN_CRIT "br_netfilter: skb->dst == NULL.");
6491 + nf_bridge = skb->nf_bridge;
6492 + nf_bridge->physoutdev = skb->dev;
6493 + realindev = nf_bridge->physindev;
6495 + /* Bridged, take PF_BRIDGE/FORWARD.
6496 + * (see big note in front of br_nf_pre_routing_finish)
6498 + if (nf_bridge->mask & BRNF_BRIDGED_DNAT) {
6499 + if (nf_bridge->mask & BRNF_PKT_TYPE) {
6500 + skb->pkt_type = PACKET_OTHERHOST;
6501 + nf_bridge->mask ^= BRNF_PKT_TYPE;
6503 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
6504 + skb_push(skb, VLAN_HLEN);
6505 + skb->nh.raw -= VLAN_HLEN;
6508 + NF_HOOK(PF_BRIDGE, NF_BR_FORWARD, skb, realindev,
6509 + skb->dev, br_forward_finish);
6512 + realoutdev = bridge_parent(skb->dev);
6514 +#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
6515 + /* iptables should match -o br0.x */
6516 + if (nf_bridge->netoutdev)
6517 + realoutdev = nf_bridge->netoutdev;
6519 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
6520 + skb_pull(skb, VLAN_HLEN);
6521 + (*pskb)->nh.raw += VLAN_HLEN;
6523 + /* IP forwarded traffic has a physindev, locally
6524 + * generated traffic hasn't.
6526 + if (realindev != NULL) {
6527 + if (((nf_bridge->mask & BRNF_DONT_TAKE_PARENT) == 0) &&
6528 + has_bridge_parent(realindev))
6529 + realindev = bridge_parent(realindev);
6530 + NF_HOOK_THRESH(pf, NF_IP_FORWARD, skb, realindev,
6532 + NF_IP_PRI_BRIDGE_SABOTAGE_FORWARD + 1);
6534 +#ifdef CONFIG_NETFILTER_DEBUG
6535 + skb->nf_debug ^= (1 << NF_IP_LOCAL_OUT);
6538 + NF_HOOK_THRESH(pf, NF_IP_LOCAL_OUT, skb, realindev,
6540 + NF_IP_PRI_BRIDGE_SABOTAGE_LOCAL_OUT + 1);
6548 +/* PF_BRIDGE/POST_ROUTING ********************************************/
6549 +static unsigned int br_nf_post_routing(unsigned int hook, struct sk_buff **pskb,
6550 + const struct net_device *in, const struct net_device *out,
6551 + int (*okfn)(struct sk_buff *))
6553 + struct sk_buff *skb = *pskb;
6554 + struct nf_bridge_info *nf_bridge = (*pskb)->nf_bridge;
6555 + struct vlan_ethhdr *hdr = (struct vlan_ethhdr *)(skb->mac.ethernet);
6556 + struct net_device *realoutdev = bridge_parent(skb->dev);
6559 +#ifdef CONFIG_NETFILTER_DEBUG
6560 + /* Be very paranoid. This probably won't happen anymore, but let's
6561 + * keep the check just to be sure... */
6562 + if (skb->mac.raw < skb->head || skb->mac.raw + ETH_HLEN > skb->data) {
6563 + printk(KERN_CRIT "br_netfilter: Argh!! br_nf_post_routing: "
6564 + "bad mac.raw pointer.");
6572 + if (skb->protocol == __constant_htons(ETH_P_IP) || IS_VLAN_IP)
6577 + /* Sometimes we get packets with NULL ->dst here (for example,
6578 + * running a dhcp client daemon triggers this).
6580 + if (skb->dst == NULL)
6583 +#ifdef CONFIG_NETFILTER_DEBUG
6584 + /* Sometimes we get packets with NULL ->dst here (for example,
6585 + * running a dhcp client daemon triggers this). This should now
6586 + * be fixed, but let's keep the check around.
6588 + if (skb->dst == NULL) {
6589 + printk(KERN_CRIT "br_netfilter: skb->dst == NULL.");
6593 + skb->nf_debug ^= (1 << NF_IP_POST_ROUTING);
6596 + /* We assume any code from br_dev_queue_push_xmit onwards doesn't care
6597 + * about the value of skb->pkt_type.
6599 + if (skb->pkt_type == PACKET_OTHERHOST) {
6600 + skb->pkt_type = PACKET_HOST;
6601 + nf_bridge->mask |= BRNF_PKT_TYPE;
6604 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
6605 + skb_pull(skb, VLAN_HLEN);
6606 + skb->nh.raw += VLAN_HLEN;
6609 + nf_bridge_save_header(skb);
6611 +#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
6612 + if (nf_bridge->netoutdev)
6613 + realoutdev = nf_bridge->netoutdev;
6615 + NF_HOOK(pf, NF_IP_POST_ROUTING, skb, NULL,
6616 + realoutdev, br_dev_queue_push_xmit);
6620 +#ifdef CONFIG_NETFILTER_DEBUG
6622 + if (skb->dev != NULL) {
6623 + printk("[%s]", skb->dev->name);
6624 + if (has_bridge_parent(skb->dev))
6625 + printk("[%s]", bridge_parent(skb->dev)->name);
6627 + printk(" head:%p, raw:%p, data:%p\n", skb->head, skb->mac.raw,
6634 +/* IPv4/SABOTAGE *****************************************************/
6636 +/* Don't hand locally destined packets to PF_INET/PRE_ROUTING
6637 + * for the second time.
6639 +static unsigned int ip_sabotage_in(unsigned int hook, struct sk_buff **pskb,
6640 + const struct net_device *in, const struct net_device *out,
6641 + int (*okfn)(struct sk_buff *))
6643 + if ((*pskb)->nf_bridge &&
6644 + !((*pskb)->nf_bridge->mask & BRNF_NF_BRIDGE_PREROUTING)) {
6651 +/* Postpone execution of PF_INET/FORWARD, PF_INET/LOCAL_OUT
6652 + * and PF_INET/POST_ROUTING until we have done the forwarding
6653 + * decision in the bridge code and have determined skb->physoutdev.
6655 +static unsigned int ip_sabotage_out(unsigned int hook, struct sk_buff **pskb,
6656 + const struct net_device *in, const struct net_device *out,
6657 + int (*okfn)(struct sk_buff *))
6659 + struct sk_buff *skb = *pskb;
6661 + if ((out->hard_start_xmit == br_dev_xmit &&
6662 + okfn != br_nf_forward_finish &&
6663 + okfn != br_nf_local_out_finish &&
6664 + okfn != br_dev_queue_push_xmit)
6665 +#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
6666 + || ((out->priv_flags & IFF_802_1Q_VLAN) &&
6667 + VLAN_DEV_INFO(out)->real_dev->hard_start_xmit == br_dev_xmit)
6670 + struct nf_bridge_info *nf_bridge;
6672 + if (!skb->nf_bridge) {
6673 +#ifdef CONFIG_SYSCTL
6674 + /* This code is executed while in the IP(v6) stack,
6675 + the version should be 4 or 6. We can't use
6676 + skb->protocol because that isn't set on
6677 + PF_INET(6)/LOCAL_OUT. */
6678 + struct iphdr *ip = skb->nh.iph;
6680 + if (ip->version == 4 && !brnf_call_iptables)
6682 + else if (ip->version == 6 && !brnf_call_ip6tables)
6685 + if (hook == NF_IP_POST_ROUTING)
6687 + if (!nf_bridge_alloc(skb))
6691 + nf_bridge = skb->nf_bridge;
6693 + /* This frame will arrive on PF_BRIDGE/LOCAL_OUT and we
6694 + * will need the indev then. For a brouter, the real indev
6695 + * can be a bridge port, so we make sure br_nf_local_out()
6696 + * doesn't use the bridge parent of the indev by using
6697 + * the BRNF_DONT_TAKE_PARENT mask.
6699 + if (hook == NF_IP_FORWARD && nf_bridge->physindev == NULL) {
6700 + nf_bridge->mask &= BRNF_DONT_TAKE_PARENT;
6701 + nf_bridge->physindev = (struct net_device *)in;
6703 +#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
6704 + /* the iptables outdev is br0.x, not br0 */
6705 + if (out->priv_flags & IFF_802_1Q_VLAN)
6706 + nf_bridge->netoutdev = (struct net_device *)out;
6714 +/* For br_nf_local_out we need (prio = NF_BR_PRI_FIRST), to insure that innocent
6715 + * PF_BRIDGE/NF_BR_LOCAL_OUT functions don't get bridged traffic as input.
6716 + * For br_nf_post_routing, we need (prio = NF_BR_PRI_LAST), because
6717 + * ip_refrag() can return NF_STOLEN.
6719 +static struct nf_hook_ops br_nf_ops[] = {
6720 + { .hook = br_nf_pre_routing,
6722 + .hooknum = NF_BR_PRE_ROUTING,
6723 + .priority = NF_BR_PRI_BRNF, },
6724 + { .hook = br_nf_local_in,
6726 + .hooknum = NF_BR_LOCAL_IN,
6727 + .priority = NF_BR_PRI_BRNF, },
6728 + { .hook = br_nf_forward_ip,
6730 + .hooknum = NF_BR_FORWARD,
6731 + .priority = NF_BR_PRI_BRNF /*- 1*/, },
6732 +/* { .hook = br_nf_forward_arp,
6734 + .hooknum = NF_BR_FORWARD,
6735 + .priority = NF_BR_PRI_BRNF, },*/
6736 + { .hook = br_nf_local_out,
6738 + .hooknum = NF_BR_LOCAL_OUT,
6739 + .priority = NF_BR_PRI_FIRST, },
6740 + { .hook = br_nf_post_routing,
6742 + .hooknum = NF_BR_POST_ROUTING,
6743 + .priority = NF_BR_PRI_LAST, },
6744 + { .hook = ip_sabotage_in,
6746 + .hooknum = NF_IP_PRE_ROUTING,
6747 + .priority = NF_IP_PRI_FIRST, },
6748 + { .hook = ip_sabotage_in,
6750 + .hooknum = NF_IP6_PRE_ROUTING,
6751 + .priority = NF_IP6_PRI_FIRST, },
6752 + { .hook = ip_sabotage_out,
6754 + .hooknum = NF_IP_FORWARD,
6755 + .priority = NF_IP_PRI_BRIDGE_SABOTAGE_FORWARD, },
6756 + { .hook = ip_sabotage_out,
6758 + .hooknum = NF_IP6_FORWARD,
6759 + .priority = NF_IP6_PRI_BRIDGE_SABOTAGE_FORWARD, },
6760 + { .hook = ip_sabotage_out,
6762 + .hooknum = NF_IP_LOCAL_OUT,
6763 + .priority = NF_IP_PRI_BRIDGE_SABOTAGE_LOCAL_OUT, },
6764 + { .hook = ip_sabotage_out,
6766 + .hooknum = NF_IP6_LOCAL_OUT,
6767 + .priority = NF_IP6_PRI_BRIDGE_SABOTAGE_LOCAL_OUT, },
6768 + { .hook = ip_sabotage_out,
6770 + .hooknum = NF_IP_POST_ROUTING,
6771 + .priority = NF_IP_PRI_FIRST, },
6772 + { .hook = ip_sabotage_out,
6774 + .hooknum = NF_IP6_POST_ROUTING,
6775 + .priority = NF_IP6_PRI_FIRST, },
6778 +#ifdef CONFIG_SYSCTL
6780 +int brnf_sysctl_call_tables(ctl_table *ctl, int write, struct file * filp,
6781 + void *buffer, size_t *lenp)
6785 + ret = proc_dointvec(ctl, write, filp, buffer, lenp);
6787 + if (write && *(int *)(ctl->data))
6788 + *(int *)(ctl->data) = 1;
6792 +static ctl_table brnf_table[] = {
6794 + .ctl_name = NET_BRIDGE_NF_CALL_ARPTABLES,
6795 + .procname = "bridge-nf-call-arptables",
6796 + .data = &brnf_call_arptables,
6797 + .maxlen = sizeof(int),
6799 + .proc_handler = &brnf_sysctl_call_tables,
6802 + .ctl_name = NET_BRIDGE_NF_CALL_IPTABLES,
6803 + .procname = "bridge-nf-call-iptables",
6804 + .data = &brnf_call_iptables,
6805 + .maxlen = sizeof(int),
6807 + .proc_handler = &brnf_sysctl_call_tables,
6810 + .ctl_name = NET_BRIDGE_NF_CALL_IP6TABLES,
6811 + .procname = "bridge-nf-call-ip6tables",
6812 + .data = &brnf_call_ip6tables,
6813 + .maxlen = sizeof(int),
6815 + .proc_handler = &brnf_sysctl_call_tables,
6818 + .ctl_name = NET_BRIDGE_NF_FILTER_VLAN_TAGGED,
6819 + .procname = "bridge-nf-filter-vlan-tagged",
6820 + .data = &brnf_filter_vlan_tagged,
6821 + .maxlen = sizeof(int),
6823 + .proc_handler = &brnf_sysctl_call_tables,
6828 +static ctl_table brnf_bridge_table[] = {
6830 + .ctl_name = NET_BRIDGE,
6831 + .procname = "bridge",
6833 + .child = brnf_table,
6838 +static ctl_table brnf_net_table[] = {
6840 + .ctl_name = CTL_NET,
6841 + .procname = "net",
6843 + .child = brnf_bridge_table,
6849 +int br_netfilter_init(void)
6853 + for (i = 0; i < ARRAY_SIZE(br_nf_ops); i++) {
6856 + if ((ret = nf_register_hook(&br_nf_ops[i])) >= 0)
6860 + nf_unregister_hook(&br_nf_ops[i]);
6865 +#ifdef CONFIG_SYSCTL
6866 + brnf_sysctl_header = register_sysctl_table(brnf_net_table, 0);
6867 + if (brnf_sysctl_header == NULL) {
6868 + printk(KERN_WARNING "br_netfilter: can't register to sysctl.\n");
6869 + for (i = 0; i < ARRAY_SIZE(br_nf_ops); i++)
6870 + nf_unregister_hook(&br_nf_ops[i]);
6875 + printk(KERN_NOTICE "Bridge firewalling registered\n");
6880 +void br_netfilter_fini(void)
6884 + for (i = ARRAY_SIZE(br_nf_ops) - 1; i >= 0; i--)
6885 + nf_unregister_hook(&br_nf_ops[i]);
6886 +#ifdef CONFIG_SYSCTL
6887 + unregister_sysctl_table(brnf_sysctl_header);
6891 --- /dev/null 2005-09-22 15:53:13.374707688 +0000
6892 +++ linux-2.4.31-ebt-brnf/net/ipv4/netfilter/ipt_physdev.c 2005-09-15 16:57:23.000000000 +0000
6894 +/* Kernel module to match the bridge port in and
6895 + * out device for IP packets coming into contact with a bridge. */
6896 +#include <linux/module.h>
6897 +#include <linux/skbuff.h>
6898 +#include <linux/netfilter_ipv4/ipt_physdev.h>
6899 +#include <linux/netfilter_ipv4/ip_tables.h>
6900 +#include <linux/netfilter_bridge.h>
6901 +#include <linux/netdevice.h>
6906 +match(const struct sk_buff *skb,
6907 + const struct net_device *in,
6908 + const struct net_device *out,
6909 + const void *matchinfo,
6912 + u_int16_t datalen,
6916 + static const char nulldevname[IFNAMSIZ] = { 0 };
6917 + const struct ipt_physdev_info *info = matchinfo;
6918 + unsigned long ret;
6919 + const char *indev, *outdev;
6920 + struct nf_bridge_info *nf_bridge;
6922 + /* Not a bridged IP packet or no info available yet:
6923 + * LOCAL_OUT/mangle and LOCAL_OUT/nat don't know if
6924 + * the destination device will be a bridge. */
6925 + if (!(nf_bridge = skb->nf_bridge)) {
6926 + /* Return MATCH if the invert flags of the used options are on */
6927 + if ((info->bitmask & IPT_PHYSDEV_OP_BRIDGED) &&
6928 + !(info->invert & IPT_PHYSDEV_OP_BRIDGED))
6930 + if ((info->bitmask & IPT_PHYSDEV_OP_ISIN) &&
6931 + !(info->invert & IPT_PHYSDEV_OP_ISIN))
6933 + if ((info->bitmask & IPT_PHYSDEV_OP_ISOUT) &&
6934 + !(info->invert & IPT_PHYSDEV_OP_ISOUT))
6936 + if ((info->bitmask & IPT_PHYSDEV_OP_IN) &&
6937 + !(info->invert & IPT_PHYSDEV_OP_IN))
6939 + if ((info->bitmask & IPT_PHYSDEV_OP_OUT) &&
6940 + !(info->invert & IPT_PHYSDEV_OP_OUT))
6945 + /* This only makes sense in the FORWARD and POSTROUTING chains */
6946 + if ((info->bitmask & IPT_PHYSDEV_OP_BRIDGED) &&
6947 + (!!(nf_bridge->mask & BRNF_BRIDGED) ^
6948 + !(info->invert & IPT_PHYSDEV_OP_BRIDGED)))
6951 + if ((info->bitmask & IPT_PHYSDEV_OP_ISIN &&
6952 + (!nf_bridge->physindev ^ !!(info->invert & IPT_PHYSDEV_OP_ISIN))) ||
6953 + (info->bitmask & IPT_PHYSDEV_OP_ISOUT &&
6954 + (!nf_bridge->physoutdev ^ !!(info->invert & IPT_PHYSDEV_OP_ISOUT))))
6957 + if (!(info->bitmask & IPT_PHYSDEV_OP_IN))
6958 + goto match_outdev;
6959 + indev = nf_bridge->physindev ? nf_bridge->physindev->name : nulldevname;
6960 + for (i = 0, ret = 0; i < IFNAMSIZ/sizeof(unsigned long); i++) {
6961 + ret |= (((const unsigned long *)indev)[i]
6962 + ^ ((const unsigned long *)info->physindev)[i])
6963 + & ((const unsigned long *)info->in_mask)[i];
6966 + if ((ret == 0) ^ !(info->invert & IPT_PHYSDEV_OP_IN))
6970 + if (!(info->bitmask & IPT_PHYSDEV_OP_OUT))
6972 + outdev = nf_bridge->physoutdev ?
6973 + nf_bridge->physoutdev->name : nulldevname;
6974 + for (i = 0, ret = 0; i < IFNAMSIZ/sizeof(unsigned long); i++) {
6975 + ret |= (((const unsigned long *)outdev)[i]
6976 + ^ ((const unsigned long *)info->physoutdev)[i])
6977 + & ((const unsigned long *)info->out_mask)[i];
6980 + return (ret != 0) ^ !(info->invert & IPT_PHYSDEV_OP_OUT);
6984 +checkentry(const char *tablename,
6985 + const struct ipt_ip *ip,
6987 + unsigned int matchsize,
6988 + unsigned int hook_mask)
6990 + const struct ipt_physdev_info *info = matchinfo;
6992 + if (matchsize != IPT_ALIGN(sizeof(struct ipt_physdev_info)))
6994 + if (!(info->bitmask & IPT_PHYSDEV_OP_MASK) ||
6995 + info->bitmask & ~IPT_PHYSDEV_OP_MASK)
7000 +static struct ipt_match physdev_match = {
7001 + .name = "physdev",
7003 + .checkentry = &checkentry,
7004 + .me = THIS_MODULE,
7007 +static int __init init(void)
7009 + return ipt_register_match(&physdev_match);
7012 +static void __exit fini(void)
7014 + ipt_unregister_match(&physdev_match);
7019 +MODULE_LICENSE("GPL");
7021 --- /dev/null 2005-09-22 15:53:13.374707688 +0000
7022 +++ linux-2.4.31-ebt-brnf/include/linux/netfilter_ipv4/ipt_physdev.h 2005-09-15 16:57:23.000000000 +0000
7024 +#ifndef _IPT_PHYSDEV_H
7025 +#define _IPT_PHYSDEV_H
7028 +#include <linux/if.h>
7031 +#define IPT_PHYSDEV_OP_IN 0x01
7032 +#define IPT_PHYSDEV_OP_OUT 0x02
7033 +#define IPT_PHYSDEV_OP_BRIDGED 0x04
7034 +#define IPT_PHYSDEV_OP_ISIN 0x08
7035 +#define IPT_PHYSDEV_OP_ISOUT 0x10
7036 +#define IPT_PHYSDEV_OP_MASK (0x20 - 1)
7038 +struct ipt_physdev_info {
7039 + char physindev[IFNAMSIZ];
7040 + char in_mask[IFNAMSIZ];
7041 + char physoutdev[IFNAMSIZ];
7042 + char out_mask[IFNAMSIZ];
7047 +#endif /*_IPT_PHYSDEV_H*/
7048 --- linux-2.4.31/net/8021q/vlan_dev.c 2005-01-19 14:10:13.000000000 +0000
7049 +++ linux-2.4.31-ebt-brnf/net/8021q/vlan_dev.c 2005-09-15 16:57:23.000000000 +0000
7050 @@ -488,6 +488,10 @@ int vlan_dev_hard_start_xmit(struct sk_b
7051 stats->tx_packets++; /* for statics only */
7052 stats->tx_bytes += skb->len;
7054 + skb->protocol = __constant_htons(ETH_P_8021Q);
7055 + skb->mac.raw -= VLAN_HLEN;
7056 + skb->nh.raw -= VLAN_HLEN;
7058 skb->dev = VLAN_DEV_INFO(dev)->real_dev;
7059 dev_queue_xmit(skb);
7061 --- linux-2.4.31/include/linux/sysctl.h 2005-04-04 01:42:20.000000000 +0000
7062 +++ linux-2.4.31-ebt-brnf/include/linux/sysctl.h 2005-09-15 16:57:23.000000000 +0000
7063 @@ -609,6 +609,15 @@ enum {
7064 NET_DECNET_CONF_DEV_STATE = 7
7067 +/* /proc/sys/net/bridge */
7069 + NET_BRIDGE_NF_CALL_ARPTABLES = 1,
7070 + NET_BRIDGE_NF_CALL_IPTABLES = 2,
7071 + NET_BRIDGE_NF_CALL_IP6TABLES = 3,
7072 + NET_BRIDGE_NF_FILTER_VLAN_TAGGED = 4,
7076 /* CTL_PROC names: */
7079 --- linux-2.4.31/net/ipv4/netfilter/ipt_REJECT.c 2005-01-19 14:10:13.000000000 +0000
7080 +++ linux-2.4.31-ebt-brnf/net/ipv4/netfilter/ipt_REJECT.c 2005-09-15 16:57:23.000000000 +0000
7082 #include <net/route.h>
7083 #include <linux/netfilter_ipv4/ip_tables.h>
7084 #include <linux/netfilter_ipv4/ipt_REJECT.h>
7085 +#ifdef CONFIG_BRIDGE_NETFILTER
7086 +#include <linux/netfilter_bridge.h>
7090 #define DEBUGP printk
7091 @@ -29,7 +32,13 @@ static inline struct rtable *route_rever
7092 struct rt_key key = {};
7095 - if (hook != NF_IP_FORWARD) {
7096 + /* We don't require ip forwarding to be enabled to be able to
7097 + * send a RST reply for bridged traffic. */
7098 + if (hook != NF_IP_FORWARD
7099 +#ifdef CONFIG_BRIDGE_NETFILTER
7100 + || (skb->nf_bridge && skb->nf_bridge->mask & BRNF_BRIDGED)
7103 key.dst = iph->saddr;
7104 if (hook == NF_IP_LOCAL_IN)
7105 key.src = iph->daddr;