1 --- linux-2.4.29/net/bridge/br_private.h 2004-08-08 01:26:06.000000000 +0200
2 +++ linux-2.4.29-ebt-brnf/net/bridge/br_private.h 2005-03-14 21:24:04.000000000 +0100
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.29/include/linux/if_bridge.h 2001-11-22 20:47:12.000000000 +0100
36 +++ linux-2.4.29-ebt-brnf/include/linux/if_bridge.h 2005-03-14 21:11:28.000000000 +0100
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.29/net/core/dev.c 2004-04-14 15:05:41.000000000 +0200
48 +++ linux-2.4.29-ebt-brnf/net/core/dev.c 2005-03-14 00:00:29.000000000 +0100
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.29/net/bridge/br_input.c 2003-08-25 13:44:44.000000000 +0200
81 +++ linux-2.4.29-ebt-brnf/net/bridge/br_input.c 2005-03-14 00:00:29.000000000 +0100
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 @@ -112,7 +115,7 @@ err_nolock:
105 -void br_handle_frame(struct sk_buff *skb)
106 +int br_handle_frame(struct sk_buff *skb)
108 struct net_bridge *br;
110 @@ -146,26 +149,35 @@ void br_handle_frame(struct sk_buff *skb
111 goto handle_special_frame;
113 if (p->state == BR_STATE_FORWARDING) {
114 + if (br_should_route_hook && br_should_route_hook(&skb)) {
115 + read_unlock(&br->lock);
119 + if (!memcmp(p->br->dev.dev_addr, dest, ETH_ALEN))
120 + skb->pkt_type = PACKET_HOST;
122 NF_HOOK(PF_BRIDGE, NF_BR_PRE_ROUTING, skb, skb->dev, NULL,
123 br_handle_frame_finish);
124 read_unlock(&br->lock);
130 read_unlock(&br->lock);
136 handle_special_frame:
138 NF_HOOK(PF_BRIDGE, NF_BR_LOCAL_IN, skb, skb->dev,NULL,
140 read_unlock(&br->lock);
145 read_unlock(&br->lock);
149 --- linux-2.4.29/net/bridge/br_forward.c 2003-11-28 19:26:21.000000000 +0100
150 +++ linux-2.4.29-ebt-brnf/net/bridge/br_forward.c 2005-03-14 00:00:29.000000000 +0100
151 @@ -30,18 +30,21 @@ static inline int should_deliver(struct
155 -static int __dev_queue_push_xmit(struct sk_buff *skb)
156 +int br_dev_queue_push_xmit(struct sk_buff *skb)
158 +#ifdef CONFIG_NETFILTER
159 + nf_bridge_maybe_copy_header(skb);
161 skb_push(skb, ETH_HLEN);
167 -static int __br_forward_finish(struct sk_buff *skb)
168 +int br_forward_finish(struct sk_buff *skb)
170 NF_HOOK(PF_BRIDGE, NF_BR_POST_ROUTING, skb, NULL, skb->dev,
171 - __dev_queue_push_xmit);
172 + br_dev_queue_push_xmit);
176 @@ -49,8 +52,11 @@ static int __br_forward_finish(struct sk
177 static void __br_deliver(struct net_bridge_port *to, struct sk_buff *skb)
180 +#ifdef CONFIG_NETFILTER_DEBUG
183 NF_HOOK(PF_BRIDGE, NF_BR_LOCAL_OUT, skb, NULL, skb->dev,
184 - __br_forward_finish);
185 + br_forward_finish);
188 static void __br_forward(struct net_bridge_port *to, struct sk_buff *skb)
189 @@ -62,7 +68,7 @@ static void __br_forward(struct net_brid
190 skb->ip_summed = CHECKSUM_NONE;
192 NF_HOOK(PF_BRIDGE, NF_BR_FORWARD, skb, indev, skb->dev,
193 - __br_forward_finish);
194 + br_forward_finish);
197 /* called under bridge lock */
198 --- linux-2.4.29/net/bridge/br.c 2004-08-08 01:26:06.000000000 +0200
199 +++ linux-2.4.29-ebt-brnf/net/bridge/br.c 2005-03-14 00:00:29.000000000 +0100
201 #include "../atm/lec.h"
204 +int (*br_should_route_hook) (struct sk_buff **pskb) = NULL;
206 void br_dec_use_count()
209 @@ -44,6 +46,10 @@ static int __init br_init(void)
211 printk(KERN_INFO "NET4: Ethernet Bridge 008 for NET4.0\n");
213 +#ifdef CONFIG_NETFILTER
214 + if (br_netfilter_init())
217 br_handle_frame_hook = br_handle_frame;
218 br_ioctl_hook = br_ioctl_deviceless_stub;
219 #if defined(CONFIG_ATM_LANE) || defined(CONFIG_ATM_LANE_MODULE)
220 @@ -57,6 +63,9 @@ static int __init br_init(void)
222 static void __exit br_deinit(void)
224 +#ifdef CONFIG_NETFILTER
225 + br_netfilter_fini();
227 unregister_netdevice_notifier(&br_device_notifier);
230 @@ -73,7 +82,7 @@ static void __exit br_deinit(void)
235 +EXPORT_SYMBOL(br_should_route_hook);
238 module_exit(br_deinit)
239 --- linux-2.4.29/net/bridge/Makefile 2000-12-29 23:07:24.000000000 +0100
240 +++ linux-2.4.29-ebt-brnf/net/bridge/Makefile 2005-03-14 00:00:29.000000000 +0100
243 # Note 2! The CFLAGS definition is now in the main makefile...
248 obj-y := br.o br_device.o br_fdb.o br_forward.o br_if.o br_input.o \
249 br_ioctl.o br_notify.o br_stp.o br_stp_bpdu.o \
250 br_stp_if.o br_stp_timer.o
252 +ifeq ($(CONFIG_NETFILTER),y)
253 +obj-y += br_netfilter.o
258 include $(TOPDIR)/Rules.make
259 --- linux-2.4.29/include/linux/netfilter_bridge.h 2001-06-12 04:15:27.000000000 +0200
260 +++ linux-2.4.29-ebt-brnf/include/linux/netfilter_bridge.h 2005-03-14 21:24:06.000000000 +0100
263 #include <linux/config.h>
264 #include <linux/netfilter.h>
265 +#if defined(__KERNEL__) && defined(CONFIG_NETFILTER)
266 +#include <asm/atomic.h>
267 +#include <linux/if_ether.h>
271 /* After promisc drops, checksum checks. */
273 #define NF_BR_LOCAL_OUT 3
274 /* Packets about to hit the wire. */
275 #define NF_BR_POST_ROUTING 4
276 -#define NF_BR_NUMHOOKS 5
277 +/* Not really a hook, but used for the ebtables broute table */
278 +#define NF_BR_BROUTING 5
279 +#define NF_BR_NUMHOOKS 6
283 +#define BRNF_PKT_TYPE 0x01
284 +#define BRNF_BRIDGED_DNAT 0x02
285 +#define BRNF_DONT_TAKE_PARENT 0x04
286 +#define BRNF_BRIDGED 0x08
287 +#define BRNF_NF_BRIDGE_PREROUTING 0x10
289 +enum nf_br_hook_priorities {
290 + NF_BR_PRI_FIRST = INT_MIN,
291 + NF_BR_PRI_NAT_DST_BRIDGED = -300,
292 + NF_BR_PRI_FILTER_BRIDGED = -200,
293 + NF_BR_PRI_BRNF = 0,
294 + NF_BR_PRI_NAT_DST_OTHER = 100,
295 + NF_BR_PRI_FILTER_OTHER = 200,
296 + NF_BR_PRI_NAT_SRC = 300,
297 + NF_BR_PRI_LAST = INT_MAX,
300 +#ifdef CONFIG_NETFILTER
302 +struct nf_bridge_info *nf_bridge_alloc(struct sk_buff *skb)
304 + struct nf_bridge_info **nf_bridge = &(skb->nf_bridge);
306 + if ((*nf_bridge = kmalloc(sizeof(**nf_bridge), GFP_ATOMIC)) != NULL) {
307 + atomic_set(&(*nf_bridge)->use, 1);
308 + (*nf_bridge)->mask = 0;
309 + (*nf_bridge)->physindev = (*nf_bridge)->physoutdev = NULL;
310 +#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
311 + (*nf_bridge)->netoutdev = NULL;
318 +/* Only used in br_forward.c */
320 +void nf_bridge_maybe_copy_header(struct sk_buff *skb)
322 + if (skb->nf_bridge) {
323 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
324 + memcpy(skb->data - 18, skb->nf_bridge->data, 18);
327 + memcpy(skb->data - 16, skb->nf_bridge->data, 16);
332 +void nf_bridge_save_header(struct sk_buff *skb)
334 + int header_size = 16;
336 + if (skb->protocol == __constant_htons(ETH_P_8021Q))
338 + memcpy(skb->nf_bridge->data, skb->data - header_size, header_size);
341 +struct bridge_skb_cb {
346 +#endif /* CONFIG_NETFILTER */
348 +#endif /* __KERNEL__ */
350 --- linux-2.4.29/include/linux/netfilter_ipv4/ip_tables.h 2004-08-08 01:26:06.000000000 +0200
351 +++ linux-2.4.29-ebt-brnf/include/linux/netfilter_ipv4/ip_tables.h 2005-03-14 21:24:28.000000000 +0100
352 @@ -159,7 +159,7 @@ struct ipt_entry
353 #define IPT_CONTINUE 0xFFFFFFFF
355 /* For standard target */
356 -#define IPT_RETURN (-NF_MAX_VERDICT - 1)
357 +#define IPT_RETURN (-NF_REPEAT - 1)
359 /* TCP matching stuff */
361 --- linux-2.4.29/include/linux/netfilter_ipv6/ip6_tables.h 2004-08-08 01:26:06.000000000 +0200
362 +++ linux-2.4.29-ebt-brnf/include/linux/netfilter_ipv6/ip6_tables.h 2005-03-14 00:00:29.000000000 +0100
363 @@ -167,7 +167,7 @@ struct ip6t_entry
364 #define IP6T_CONTINUE 0xFFFFFFFF
366 /* For standard target */
367 -#define IP6T_RETURN (-NF_MAX_VERDICT - 1)
368 +#define IP6T_RETURN (-NF_REPEAT - 1)
370 /* TCP matching stuff */
372 --- linux-2.4.29/include/linux/netfilter_arp/arp_tables.h 2003-08-25 13:44:44.000000000 +0200
373 +++ linux-2.4.29-ebt-brnf/include/linux/netfilter_arp/arp_tables.h 2005-03-14 21:24:31.000000000 +0100
374 @@ -154,7 +154,7 @@ struct arpt_entry
375 #define ARPT_CONTINUE 0xFFFFFFFF
377 /* For standard target */
378 -#define ARPT_RETURN (-NF_MAX_VERDICT - 1)
379 +#define ARPT_RETURN (-NF_REPEAT - 1)
381 /* The argument to ARPT_SO_GET_INFO */
383 --- linux-2.4.29/net/Makefile 2004-08-08 01:26:06.000000000 +0200
384 +++ linux-2.4.29-ebt-brnf/net/Makefile 2005-03-14 00:00:29.000000000 +0100
387 O_TARGET := network.o
389 -mod-subdirs := ipv4/netfilter ipv6/netfilter ipx irda bluetooth atm netlink sched core sctp 802
390 +mod-subdirs := ipv4/netfilter ipv6/netfilter bridge/netfilter ipx irda \
391 + bluetooth atm netlink sched core sctp 802
392 export-objs := netsyms.o
394 subdir-y := core ethernet
395 @@ -27,6 +28,12 @@ subdir-$(CONFIG_NETFILTER) += ipv6/netfi
399 +ifneq ($(CONFIG_BRIDGE),n)
400 +ifneq ($(CONFIG_BRIDGE),)
401 +subdir-$(CONFIG_BRIDGE) += bridge/netfilter
405 subdir-$(CONFIG_KHTTPD) += khttpd
406 subdir-$(CONFIG_PACKET) += packet
407 subdir-$(CONFIG_NET_SCHED) += sched
408 --- linux-2.4.29/net/Config.in 2005-01-19 15:10:13.000000000 +0100
409 +++ linux-2.4.29-ebt-brnf/net/Config.in 2005-03-14 00:00:29.000000000 +0100
410 @@ -70,6 +70,9 @@ if [ "$CONFIG_DECNET" != "n" ]; then
411 source net/decnet/Config.in
413 dep_tristate '802.1d Ethernet Bridging' CONFIG_BRIDGE $CONFIG_INET
414 +if [ "$CONFIG_BRIDGE" != "n" -a "$CONFIG_NETFILTER" != "n" ]; then
415 + source net/bridge/netfilter/Config.in
417 if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then
418 tristate 'CCITT X.25 Packet Layer (EXPERIMENTAL)' CONFIG_X25
419 tristate 'LAPB Data Link Driver (EXPERIMENTAL)' CONFIG_LAPB
420 --- /dev/null 2005-03-14 20:10:29.001600248 +0100
421 +++ linux-2.4.29-ebt-brnf/net/bridge/netfilter/Makefile 2005-03-14 00:00:29.000000000 +0100
424 +# Makefile for the netfilter modules on top of bridging.
426 +# Note! Dependencies are done automagically by 'make dep', which also
427 +# removes any old dependencies. DON'T put your own dependencies here
428 +# unless it's something special (ie not a .c file).
430 +# Note 2! The CFLAGS definition is now in the main makefile...
432 +O_TARGET := netfilter.o
434 +export-objs := ebtables.o
436 +obj-$(CONFIG_BRIDGE_NF_EBTABLES) += ebtables.o
437 +obj-$(CONFIG_BRIDGE_EBT_T_FILTER) += ebtable_filter.o
438 +obj-$(CONFIG_BRIDGE_EBT_T_NAT) += ebtable_nat.o
439 +obj-$(CONFIG_BRIDGE_EBT_BROUTE) += ebtable_broute.o
440 +obj-$(CONFIG_BRIDGE_EBT_802_3) += ebt_802_3.o
441 +obj-$(CONFIG_BRIDGE_EBT_ARPF) += ebt_arp.o
442 +obj-$(CONFIG_BRIDGE_EBT_AMONG) += ebt_among.o
443 +obj-$(CONFIG_BRIDGE_EBT_IPF) += ebt_ip.o
444 +obj-$(CONFIG_BRIDGE_EBT_LIMIT) += ebt_limit.o
445 +obj-$(CONFIG_BRIDGE_EBT_MARKF) += ebt_mark_m.o
446 +obj-$(CONFIG_BRIDGE_EBT_PKTTYPE) += ebt_pkttype.o
447 +obj-$(CONFIG_BRIDGE_EBT_STP) += ebt_stp.o
448 +obj-$(CONFIG_BRIDGE_EBT_VLANF) += ebt_vlan.o
449 +obj-$(CONFIG_BRIDGE_EBT_LOG) += ebt_log.o
450 +obj-$(CONFIG_BRIDGE_EBT_LOG) += ebt_ulog.o
451 +obj-$(CONFIG_BRIDGE_EBT_ARPREPLY) += ebt_arpreply.o
452 +obj-$(CONFIG_BRIDGE_EBT_DNAT) += ebt_dnat.o
453 +obj-$(CONFIG_BRIDGE_EBT_MARK_T) += ebt_mark.o
454 +obj-$(CONFIG_BRIDGE_EBT_REDIRECT) += ebt_redirect.o
455 +obj-$(CONFIG_BRIDGE_EBT_SNAT) += ebt_snat.o
456 +include $(TOPDIR)/Rules.make
457 --- /dev/null 2005-03-14 20:10:29.001600248 +0100
458 +++ linux-2.4.29-ebt-brnf/net/bridge/netfilter/Config.in 2005-03-14 00:00:29.000000000 +0100
461 +# Bridge netfilter configuration
463 +dep_tristate ' Bridge: ebtables' CONFIG_BRIDGE_NF_EBTABLES $CONFIG_BRIDGE
464 +dep_tristate ' ebt: filter table support' CONFIG_BRIDGE_EBT_T_FILTER $CONFIG_BRIDGE_NF_EBTABLES
465 +dep_tristate ' ebt: nat table support' CONFIG_BRIDGE_EBT_T_NAT $CONFIG_BRIDGE_NF_EBTABLES
466 +dep_tristate ' ebt: broute table support' CONFIG_BRIDGE_EBT_BROUTE $CONFIG_BRIDGE_NF_EBTABLES
467 +dep_tristate ' ebt: log support' CONFIG_BRIDGE_EBT_LOG $CONFIG_BRIDGE_NF_EBTABLES
468 +dep_tristate ' ebt: ulog support' CONFIG_BRIDGE_EBT_LOG $CONFIG_BRIDGE_NF_EBTABLES
469 +dep_tristate ' ebt: IP filter support' CONFIG_BRIDGE_EBT_IPF $CONFIG_BRIDGE_NF_EBTABLES
470 +dep_tristate ' ebt: ARP filter support' CONFIG_BRIDGE_EBT_ARPF $CONFIG_BRIDGE_NF_EBTABLES
471 +dep_tristate ' ebt: among filter support' CONFIG_BRIDGE_EBT_AMONG $CONFIG_BRIDGE_NF_EBTABLES
472 +dep_tristate ' ebt: limit filter support' CONFIG_BRIDGE_EBT_LIMIT $CONFIG_BRIDGE_NF_EBTABLES
473 +dep_tristate ' ebt: 802.1Q VLAN filter support' CONFIG_BRIDGE_EBT_VLANF $CONFIG_BRIDGE_NF_EBTABLES
474 +dep_tristate ' ebt: 802.3 filter support' CONFIG_BRIDGE_EBT_802_3 $CONFIG_BRIDGE_NF_EBTABLES
475 +dep_tristate ' ebt: packet type filter support' CONFIG_BRIDGE_EBT_PKTTYPE $CONFIG_BRIDGE_NF_EBTABLES
476 +dep_tristate ' ebt: STP filter support' CONFIG_BRIDGE_EBT_STP $CONFIG_BRIDGE_NF_EBTABLES
477 +dep_tristate ' ebt: mark filter support' CONFIG_BRIDGE_EBT_MARKF $CONFIG_BRIDGE_NF_EBTABLES
478 +dep_tristate ' ebt: arp reply target support' CONFIG_BRIDGE_EBT_ARPREPLY $CONFIG_BRIDGE_NF_EBTABLES
479 +dep_tristate ' ebt: snat target support' CONFIG_BRIDGE_EBT_SNAT $CONFIG_BRIDGE_NF_EBTABLES
480 +dep_tristate ' ebt: dnat target support' CONFIG_BRIDGE_EBT_DNAT $CONFIG_BRIDGE_NF_EBTABLES
481 +dep_tristate ' ebt: redirect target support' CONFIG_BRIDGE_EBT_REDIRECT $CONFIG_BRIDGE_NF_EBTABLES
482 +dep_tristate ' ebt: mark target support' CONFIG_BRIDGE_EBT_MARK_T $CONFIG_BRIDGE_NF_EBTABLES
483 --- /dev/null 2005-03-14 20:10:29.001600248 +0100
484 +++ linux-2.4.29-ebt-brnf/net/bridge/netfilter/ebtable_filter.c 2005-03-14 00:00:29.000000000 +0100
490 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
496 +#include <linux/netfilter_bridge/ebtables.h>
497 +#include <linux/module.h>
499 +#define FILTER_VALID_HOOKS ((1 << NF_BR_LOCAL_IN) | (1 << NF_BR_FORWARD) | \
500 + (1 << NF_BR_LOCAL_OUT))
502 +static struct ebt_entries initial_chains[] =
504 + {0, "INPUT", 0, EBT_ACCEPT, 0},
505 + {0, "FORWARD", 0, EBT_ACCEPT, 0},
506 + {0, "OUTPUT", 0, EBT_ACCEPT, 0}
509 +static struct ebt_replace initial_table =
511 + "filter", FILTER_VALID_HOOKS, 0, 3 * sizeof(struct ebt_entries),
512 + { [NF_BR_LOCAL_IN]&initial_chains[0], [NF_BR_FORWARD]&initial_chains[1],
513 + [NF_BR_LOCAL_OUT]&initial_chains[2] }, 0, NULL, (char *)initial_chains
516 +static int check(const struct ebt_table_info *info, unsigned int valid_hooks)
518 + if (valid_hooks & ~FILTER_VALID_HOOKS)
523 +static struct ebt_table frame_filter =
525 + {NULL, NULL}, "filter", &initial_table, FILTER_VALID_HOOKS,
526 + RW_LOCK_UNLOCKED, check, NULL
530 +ebt_hook (unsigned int hook, struct sk_buff **pskb, const struct net_device *in,
531 + const struct net_device *out, int (*okfn)(struct sk_buff *))
533 + return ebt_do_table(hook, pskb, in, out, &frame_filter);
536 +static struct nf_hook_ops ebt_ops_filter[] = {
537 + { { NULL, NULL }, ebt_hook, PF_BRIDGE, NF_BR_LOCAL_IN,
538 + NF_BR_PRI_FILTER_BRIDGED},
539 + { { NULL, NULL }, ebt_hook, PF_BRIDGE, NF_BR_FORWARD,
540 + NF_BR_PRI_FILTER_BRIDGED},
541 + { { NULL, NULL }, ebt_hook, PF_BRIDGE, NF_BR_LOCAL_OUT,
542 + NF_BR_PRI_FILTER_OTHER}
545 +static int __init init(void)
549 + ret = ebt_register_table(&frame_filter);
552 + for (i = 0; i < sizeof(ebt_ops_filter) / sizeof(ebt_ops_filter[0]); i++)
553 + if ((ret = nf_register_hook(&ebt_ops_filter[i])) < 0)
557 + for (j = 0; j < i; j++)
558 + nf_unregister_hook(&ebt_ops_filter[j]);
559 + ebt_unregister_table(&frame_filter);
563 +static void __exit fini(void)
567 + for (i = 0; i < sizeof(ebt_ops_filter) / sizeof(ebt_ops_filter[0]); i++)
568 + nf_unregister_hook(&ebt_ops_filter[i]);
569 + ebt_unregister_table(&frame_filter);
575 +MODULE_LICENSE("GPL");
576 --- /dev/null 2005-03-14 20:10:29.001600248 +0100
577 +++ linux-2.4.29-ebt-brnf/net/bridge/netfilter/ebtable_nat.c 2005-03-14 00:00:29.000000000 +0100
583 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
589 +#include <linux/netfilter_bridge/ebtables.h>
590 +#include <linux/module.h>
591 +#define NAT_VALID_HOOKS ((1 << NF_BR_PRE_ROUTING) | (1 << NF_BR_LOCAL_OUT) | \
592 + (1 << NF_BR_POST_ROUTING))
594 +static struct ebt_entries initial_chains[] =
596 + {0, "PREROUTING", 0, EBT_ACCEPT, 0},
597 + {0, "OUTPUT", 0, EBT_ACCEPT, 0},
598 + {0, "POSTROUTING", 0, EBT_ACCEPT, 0}
601 +static struct ebt_replace initial_table =
603 + "nat", NAT_VALID_HOOKS, 0, 3 * sizeof(struct ebt_entries),
604 + { [NF_BR_PRE_ROUTING]&initial_chains[0], [NF_BR_LOCAL_OUT]&initial_chains[1],
605 + [NF_BR_POST_ROUTING]&initial_chains[2] }, 0, NULL, (char *)initial_chains
608 +static int check(const struct ebt_table_info *info, unsigned int valid_hooks)
610 + if (valid_hooks & ~NAT_VALID_HOOKS)
615 +static struct ebt_table frame_nat =
617 + {NULL, NULL}, "nat", &initial_table, NAT_VALID_HOOKS,
618 + RW_LOCK_UNLOCKED, check, NULL
622 +ebt_nat_dst(unsigned int hook, struct sk_buff **pskb, const struct net_device *in
623 + , const struct net_device *out, int (*okfn)(struct sk_buff *))
625 + return ebt_do_table(hook, pskb, in, out, &frame_nat);
629 +ebt_nat_src(unsigned int hook, struct sk_buff **pskb, const struct net_device *in
630 + , const struct net_device *out, int (*okfn)(struct sk_buff *))
632 + return ebt_do_table(hook, pskb, in, out, &frame_nat);
635 +static struct nf_hook_ops ebt_ops_nat[] = {
636 + { { NULL, NULL }, ebt_nat_dst, PF_BRIDGE, NF_BR_LOCAL_OUT,
637 + NF_BR_PRI_NAT_DST_OTHER},
638 + { { NULL, NULL }, ebt_nat_src, PF_BRIDGE, NF_BR_POST_ROUTING,
639 + NF_BR_PRI_NAT_SRC},
640 + { { NULL, NULL }, ebt_nat_dst, PF_BRIDGE, NF_BR_PRE_ROUTING,
641 + NF_BR_PRI_NAT_DST_BRIDGED},
644 +static int __init init(void)
648 + ret = ebt_register_table(&frame_nat);
651 + for (i = 0; i < sizeof(ebt_ops_nat) / sizeof(ebt_ops_nat[0]); i++)
652 + if ((ret = nf_register_hook(&ebt_ops_nat[i])) < 0)
656 + for (j = 0; j < i; j++)
657 + nf_unregister_hook(&ebt_ops_nat[j]);
658 + ebt_unregister_table(&frame_nat);
662 +static void __exit fini(void)
666 + for (i = 0; i < sizeof(ebt_ops_nat) / sizeof(ebt_ops_nat[0]); i++)
667 + nf_unregister_hook(&ebt_ops_nat[i]);
668 + ebt_unregister_table(&frame_nat);
674 +MODULE_LICENSE("GPL");
675 --- /dev/null 2005-03-14 20:10:29.001600248 +0100
676 +++ linux-2.4.29-ebt-brnf/net/bridge/netfilter/ebtable_broute.c 2005-03-14 00:00:29.000000000 +0100
682 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
686 + * This table lets you choose between routing and bridging for frames
687 + * entering on a bridge enslaved nic. This table is traversed before any
688 + * other ebtables table. See net/bridge/br_input.c.
691 +#include <linux/netfilter_bridge/ebtables.h>
692 +#include <linux/module.h>
693 +#include <linux/if_bridge.h>
694 +#include <linux/brlock.h>
696 +// EBT_ACCEPT means the frame will be bridged
697 +// EBT_DROP means the frame will be routed
698 +static struct ebt_entries initial_chain =
699 + {0, "BROUTING", 0, EBT_ACCEPT, 0};
701 +static struct ebt_replace initial_table =
703 + "broute", 1 << NF_BR_BROUTING, 0, sizeof(struct ebt_entries),
704 + { [NF_BR_BROUTING]&initial_chain}, 0, NULL, (char *)&initial_chain
707 +static int check(const struct ebt_table_info *info, unsigned int valid_hooks)
709 + if (valid_hooks & ~(1 << NF_BR_BROUTING))
714 +static struct ebt_table broute_table =
716 + {NULL, NULL}, "broute", &initial_table, 1 << NF_BR_BROUTING,
717 + RW_LOCK_UNLOCKED, check, NULL
720 +static int ebt_broute(struct sk_buff **pskb)
724 + ret = ebt_do_table(NF_BR_BROUTING, pskb, (*pskb)->dev, NULL,
726 + if (ret == NF_DROP)
727 + return 1; // route it
728 + return 0; // bridge it
731 +static int __init init(void)
735 + ret = ebt_register_table(&broute_table);
738 + br_write_lock_bh(BR_NETPROTO_LOCK);
740 + br_should_route_hook = ebt_broute;
741 + br_write_unlock_bh(BR_NETPROTO_LOCK);
745 +static void __exit fini(void)
747 + br_write_lock_bh(BR_NETPROTO_LOCK);
748 + br_should_route_hook = NULL;
749 + br_write_unlock_bh(BR_NETPROTO_LOCK);
750 + ebt_unregister_table(&broute_table);
756 +MODULE_LICENSE("GPL");
757 --- /dev/null 2005-03-14 20:10:29.001600248 +0100
758 +++ linux-2.4.29-ebt-brnf/net/bridge/netfilter/ebt_among.c 2005-03-14 00:00:29.000000000 +0100
764 + * Grzegorz Borowiak <grzes@gnu.univ.gda.pl>
770 +#include <linux/netfilter_bridge/ebtables.h>
771 +#include <linux/netfilter_bridge/ebt_among.h>
772 +#include <linux/ip.h>
773 +#include <linux/if_arp.h>
774 +#include <linux/module.h>
776 +static int ebt_mac_wormhash_contains(const struct ebt_mac_wormhash *wh,
777 + const char *mac, uint32_t ip)
779 + /* You may be puzzled as to how this code works.
780 + * Some tricks were used, refer to
781 + * include/linux/netfilter_bridge/ebt_among.h
782 + * as there you can find a solution of this mystery.
784 + const struct ebt_mac_wormhash_tuple *p;
785 + int start, limit, i;
786 + uint32_t cmp[2] = { 0, 0 };
787 + int key = (const unsigned char) mac[5];
789 + memcpy(((char *) cmp) + 2, mac, 6);
790 + start = wh->table[key];
791 + limit = wh->table[key + 1];
793 + for (i = start; i < limit; i++) {
795 + if (cmp[1] == p->cmp[1] && cmp[0] == p->cmp[0]) {
796 + if (p->ip == 0 || p->ip == ip) {
802 + for (i = start; i < limit; i++) {
804 + if (cmp[1] == p->cmp[1] && cmp[0] == p->cmp[0]) {
814 +static int ebt_mac_wormhash_check_integrity(const struct ebt_mac_wormhash
819 + for (i = 0; i < 256; i++) {
820 + if (wh->table[i] > wh->table[i + 1])
822 + if (wh->table[i] < 0)
824 + if (wh->table[i] > wh->poolsize)
827 + if (wh->table[256] > wh->poolsize)
832 +static int get_ip_dst(const struct sk_buff *skb, uint32_t * addr)
834 + if (skb->mac.ethernet->h_proto == __constant_htons(ETH_P_IP))
835 + *addr = skb->nh.iph->daddr;
836 + else if (skb->mac.ethernet->h_proto == __constant_htons(ETH_P_ARP)) {
837 + uint32_t arp_len = sizeof(struct arphdr) +
838 + (2 * (((*skb).nh.arph)->ar_hln)) +
839 + (2 * (((*skb).nh.arph)->ar_pln));
841 + /* Make sure the packet is long enough. */
842 + if ((((*skb).nh.raw) + arp_len) > (*skb).tail)
844 + /* IPv4 addresses are always 4 bytes. */
845 + if (((*skb).nh.arph)->ar_pln != sizeof(uint32_t))
848 + memcpy(addr, ((*skb).nh.raw) + sizeof(struct arphdr) +
849 + (2 * (((*skb).nh.arph)->ar_hln)) +
850 + (((*skb).nh.arph)->ar_pln), sizeof(uint32_t));
856 +static int get_ip_src(const struct sk_buff *skb, uint32_t * addr)
858 + if (skb->mac.ethernet->h_proto == __constant_htons(ETH_P_IP))
859 + *addr = skb->nh.iph->saddr;
860 + else if (skb->mac.ethernet->h_proto == __constant_htons(ETH_P_ARP)) {
861 + uint32_t arp_len = sizeof(struct arphdr) +
862 + (2 * (((*skb).nh.arph)->ar_hln)) +
863 + (2 * (((*skb).nh.arph)->ar_pln));
865 + /* Make sure the packet is long enough. */
866 + if ((((*skb).nh.raw) + arp_len) > (*skb).tail)
868 + /* IPv4 addresses are always 4 bytes. */
869 + if (((*skb).nh.arph)->ar_pln != sizeof(uint32_t))
872 + memcpy(addr, ((*skb).nh.raw) + sizeof(struct arphdr) +
873 + ((((*skb).nh.arph)->ar_hln)), sizeof(uint32_t));
879 +static int ebt_filter_among(const struct sk_buff *skb,
880 + const struct net_device *in,
881 + const struct net_device *out, const void *data,
882 + unsigned int datalen)
884 + struct ebt_among_info *info = (struct ebt_among_info *) data;
885 + const char *dmac, *smac;
886 + const struct ebt_mac_wormhash *wh_dst, *wh_src;
887 + uint32_t dip = 0, sip = 0;
889 + wh_dst = ebt_among_wh_dst(info);
890 + wh_src = ebt_among_wh_src(info);
893 + smac = skb->mac.ethernet->h_source;
894 + if (get_ip_src(skb, &sip))
895 + return EBT_NOMATCH;
896 + if (!(info->bitmask & EBT_AMONG_SRC_NEG)) {
897 + /* we match only if it contains */
898 + if (!ebt_mac_wormhash_contains(wh_src, smac, sip))
899 + return EBT_NOMATCH;
901 + /* we match only if it DOES NOT contain */
902 + if (ebt_mac_wormhash_contains(wh_src, smac, sip))
903 + return EBT_NOMATCH;
908 + dmac = skb->mac.ethernet->h_dest;
909 + if (get_ip_dst(skb, &dip))
910 + return EBT_NOMATCH;
911 + if (!(info->bitmask & EBT_AMONG_DST_NEG)) {
912 + /* we match only if it contains */
913 + if (!ebt_mac_wormhash_contains(wh_dst, dmac, dip))
914 + return EBT_NOMATCH;
916 + /* we match only if it DOES NOT contain */
917 + if (ebt_mac_wormhash_contains(wh_dst, dmac, dip))
918 + return EBT_NOMATCH;
925 +static int ebt_among_check(const char *tablename, unsigned int hookmask,
926 + const struct ebt_entry *e, void *data,
927 + unsigned int datalen)
929 + struct ebt_among_info *info = (struct ebt_among_info *) data;
930 + int expected_length = sizeof(struct ebt_among_info);
931 + const struct ebt_mac_wormhash *wh_dst, *wh_src;
934 + wh_dst = ebt_among_wh_dst(info);
935 + wh_src = ebt_among_wh_src(info);
936 + expected_length += ebt_mac_wormhash_size(wh_dst);
937 + expected_length += ebt_mac_wormhash_size(wh_src);
939 + if (datalen != EBT_ALIGN(expected_length)) {
940 + printk(KERN_WARNING
941 + "ebtables: among: wrong size: %d"
942 + "against expected %d, rounded to %d\n",
943 + datalen, expected_length,
944 + EBT_ALIGN(expected_length));
947 + if (wh_dst && (err = ebt_mac_wormhash_check_integrity(wh_dst))) {
948 + printk(KERN_WARNING
949 + "ebtables: among: dst integrity fail: %x\n", -err);
952 + if (wh_src && (err = ebt_mac_wormhash_check_integrity(wh_src))) {
953 + printk(KERN_WARNING
954 + "ebtables: among: src integrity fail: %x\n", -err);
960 +static struct ebt_match filter_among = {
969 +static int __init init(void)
971 + return ebt_register_match(&filter_among);
974 +static void __exit fini(void)
976 + ebt_unregister_match(&filter_among);
982 +MODULE_LICENSE("GPL");
983 --- /dev/null 2005-03-14 20:10:29.001600248 +0100
984 +++ linux-2.4.29-ebt-brnf/net/bridge/netfilter/ebt_limit.c 2005-03-14 00:00:29.000000000 +0100
990 + * Tom Marshall <tommy@home.tig-grr.com>
992 + * Mostly copied from netfilter's ipt_limit.c, see that file for explanation
998 +#include <linux/netfilter_bridge/ebtables.h>
999 +#include <linux/netfilter_bridge/ebt_limit.h>
1000 +#include <linux/module.h>
1002 +#include <linux/netdevice.h>
1003 +#include <linux/spinlock.h>
1005 +static spinlock_t limit_lock = SPIN_LOCK_UNLOCKED;
1007 +#define CREDITS_PER_JIFFY 128
1009 +static int ebt_limit_match(const struct sk_buff *skb, const struct net_device *in,
1010 + const struct net_device *out, const void *data, unsigned int datalen)
1012 + struct ebt_limit_info *info = (struct ebt_limit_info *)data;
1013 + unsigned long now = jiffies;
1015 + spin_lock_bh(&limit_lock);
1016 + info->credit += (now - xchg(&info->prev, now)) * CREDITS_PER_JIFFY;
1017 + if (info->credit > info->credit_cap)
1018 + info->credit = info->credit_cap;
1020 + if (info->credit >= info->cost) {
1021 + /* We're not limited. */
1022 + info->credit -= info->cost;
1023 + spin_unlock_bh(&limit_lock);
1027 + spin_unlock_bh(&limit_lock);
1028 + return EBT_NOMATCH;
1031 +/* Precision saver. */
1033 +user2credits(u_int32_t user)
1035 + /* If multiplying would overflow... */
1036 + if (user > 0xFFFFFFFF / (HZ*CREDITS_PER_JIFFY))
1037 + /* Divide first. */
1038 + return (user / EBT_LIMIT_SCALE) * HZ * CREDITS_PER_JIFFY;
1040 + return (user * HZ * CREDITS_PER_JIFFY) / EBT_LIMIT_SCALE;
1043 +static int ebt_limit_check(const char *tablename, unsigned int hookmask,
1044 + const struct ebt_entry *e, void *data, unsigned int datalen)
1046 + struct ebt_limit_info *info = (struct ebt_limit_info *)data;
1048 + if (datalen != EBT_ALIGN(sizeof(struct ebt_limit_info)))
1051 + /* Check for overflow. */
1052 + if (info->burst == 0
1053 + || user2credits(info->avg * info->burst) < user2credits(info->avg)) {
1054 + printk("Overflow in ebt_limit: %u/%u\n",
1055 + info->avg, info->burst);
1059 + /* User avg in seconds * EBT_LIMIT_SCALE: convert to jiffies * 128. */
1060 + info->prev = jiffies;
1061 + info->credit = user2credits(info->avg * info->burst);
1062 + info->credit_cap = user2credits(info->avg * info->burst);
1063 + info->cost = user2credits(info->avg);
1067 +static struct ebt_match ebt_limit_reg =
1069 + {NULL, NULL}, EBT_LIMIT_MATCH, ebt_limit_match, ebt_limit_check, NULL,
1073 +static int __init init(void)
1075 + return ebt_register_match(&ebt_limit_reg);
1078 +static void __exit fini(void)
1080 + ebt_unregister_match(&ebt_limit_reg);
1086 +MODULE_LICENSE("GPL");
1087 --- /dev/null 2005-03-14 20:10:29.001600248 +0100
1088 +++ linux-2.4.29-ebt-brnf/net/bridge/netfilter/ebt_arpreply.c 2005-03-14 00:00:30.000000000 +0100
1094 + * Grzegorz Borowiak <grzes@gnu.univ.gda.pl>
1095 + * Bart De Schuymer <bdschuym@pandora.be>
1101 +#include <linux/netfilter_bridge/ebtables.h>
1102 +#include <linux/netfilter_bridge/ebt_arpreply.h>
1103 +#include <linux/if_arp.h>
1104 +#include <net/arp.h>
1105 +#include <linux/module.h>
1107 +static int ebt_target_reply(struct sk_buff **pskb, unsigned int hooknr,
1108 + const struct net_device *in, const struct net_device *out,
1109 + const void *data, unsigned int datalen)
1111 + struct ebt_arpreply_info *info = (struct ebt_arpreply_info *)data;
1112 + struct arphdr *ah;
1113 + unsigned char *sha, *arp_ptr;
1116 + ah = (**pskb).nh.arph;
1117 + if (ah->ar_op != __constant_htons(ARPOP_REQUEST) ||
1118 + ah->ar_hln != ETH_ALEN || ah->ar_pro != htons(ETH_P_IP) ||
1120 + return EBT_CONTINUE;
1122 + arp_ptr = (unsigned char *)(ah + 1);
1124 + /* get source and target IP */
1126 + arp_ptr += ETH_ALEN;
1127 + memcpy(&sip, arp_ptr, 4);
1128 + arp_ptr += 4 + ETH_ALEN;
1129 + memcpy(&tip, arp_ptr, 4);
1131 + arp_send(ARPOP_REPLY, ETH_P_ARP, sip, in, tip, sha, info->mac, sha);
1133 + return info->target;
1136 +static int ebt_target_reply_check(const char *tablename, unsigned int hookmask,
1137 + const struct ebt_entry *e, void *data, unsigned int datalen)
1139 + struct ebt_arpreply_info *info = (struct ebt_arpreply_info *)data;
1141 + if (datalen != EBT_ALIGN(sizeof(struct ebt_arpreply_info)))
1143 + if (BASE_CHAIN && info->target == EBT_RETURN)
1145 + if (e->ethproto != __constant_htons(ETH_P_ARP) ||
1146 + e->invflags & EBT_IPROTO)
1148 + CLEAR_BASE_CHAIN_BIT;
1149 + if (strcmp(tablename, "nat") || hookmask & ~(1 << NF_BR_PRE_ROUTING))
1154 +static struct ebt_target reply_target =
1156 + .name = EBT_ARPREPLY_TARGET,
1157 + .target = ebt_target_reply,
1158 + .check = ebt_target_reply_check,
1159 + .me = THIS_MODULE,
1162 +static int __init init(void)
1164 + return ebt_register_target(&reply_target);
1167 +static void __exit fini(void)
1169 + ebt_unregister_target(&reply_target);
1175 +MODULE_LICENSE("GPL");
1176 --- /dev/null 2005-03-14 20:10:29.001600248 +0100
1177 +++ linux-2.4.29-ebt-brnf/net/bridge/netfilter/ebt_802_3.c 2005-03-14 00:00:30.000000000 +0100
1183 + * Chris Vitale csv@bluetail.com
1189 +#include <linux/netfilter_bridge/ebtables.h>
1190 +#include <linux/netfilter_bridge/ebt_802_3.h>
1191 +#include <linux/module.h>
1193 +static int ebt_filter_802_3(const struct sk_buff *skb, const struct net_device *in,
1194 + const struct net_device *out, const void *data, unsigned int datalen)
1196 + struct ebt_802_3_info *info = (struct ebt_802_3_info *)data;
1197 + struct ebt_802_3_hdr *hdr = (struct ebt_802_3_hdr *)skb->mac.ethernet;
1198 + uint16_t type = hdr->llc.ui.ctrl & IS_UI ? hdr->llc.ui.type : hdr->llc.ni.type;
1200 + if (info->bitmask & EBT_802_3_SAP) {
1201 + if (FWINV(info->sap != hdr->llc.ui.ssap, EBT_802_3_SAP))
1202 + return EBT_NOMATCH;
1203 + if (FWINV(info->sap != hdr->llc.ui.dsap, EBT_802_3_SAP))
1204 + return EBT_NOMATCH;
1207 + if (info->bitmask & EBT_802_3_TYPE) {
1208 + if (!(hdr->llc.ui.dsap == CHECK_TYPE && hdr->llc.ui.ssap == CHECK_TYPE))
1209 + return EBT_NOMATCH;
1210 + if (FWINV(info->type != type, EBT_802_3_TYPE))
1211 + return EBT_NOMATCH;
1217 +static struct ebt_match filter_802_3;
1218 +static int ebt_802_3_check(const char *tablename, unsigned int hookmask,
1219 + const struct ebt_entry *e, void *data, unsigned int datalen)
1221 + struct ebt_802_3_info *info = (struct ebt_802_3_info *)data;
1223 + if (datalen != EBT_ALIGN(sizeof(struct ebt_802_3_info)))
1225 + if (info->bitmask & ~EBT_802_3_MASK || info->invflags & ~EBT_802_3_MASK)
1231 +static struct ebt_match filter_802_3 =
1233 + .name = EBT_802_3_MATCH,
1234 + .match = ebt_filter_802_3,
1235 + .check = ebt_802_3_check,
1236 + .me = THIS_MODULE,
1239 +static int __init init(void)
1241 + return ebt_register_match(&filter_802_3);
1244 +static void __exit fini(void)
1246 + ebt_unregister_match(&filter_802_3);
1252 +MODULE_LICENSE("GPL");
1253 --- /dev/null 2005-03-14 20:10:29.001600248 +0100
1254 +++ linux-2.4.29-ebt-brnf/net/bridge/netfilter/ebt_mark.c 2005-03-14 00:00:30.000000000 +0100
1260 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
1266 +// The mark target can be used in any chain
1267 +// I believe adding a mangle table just for marking is total overkill
1268 +// Marking a frame doesn't really change anything in the frame anyway
1270 +#include <linux/netfilter_bridge/ebtables.h>
1271 +#include <linux/netfilter_bridge/ebt_mark_t.h>
1272 +#include <linux/module.h>
1274 +static int ebt_target_mark(struct sk_buff **pskb, unsigned int hooknr,
1275 + const struct net_device *in, const struct net_device *out,
1276 + const void *data, unsigned int datalen)
1278 + struct ebt_mark_t_info *info = (struct ebt_mark_t_info *)data;
1280 + if ((*pskb)->nfmark != info->mark) {
1281 + (*pskb)->nfmark = info->mark;
1282 + (*pskb)->nfcache |= NFC_ALTERED;
1284 + return info->target;
1287 +static int ebt_target_mark_check(const char *tablename, unsigned int hookmask,
1288 + const struct ebt_entry *e, void *data, unsigned int datalen)
1290 + struct ebt_mark_t_info *info = (struct ebt_mark_t_info *)data;
1292 + if (datalen != EBT_ALIGN(sizeof(struct ebt_mark_t_info)))
1294 + if (BASE_CHAIN && info->target == EBT_RETURN)
1296 + CLEAR_BASE_CHAIN_BIT;
1297 + if (INVALID_TARGET)
1302 +static struct ebt_target mark_target =
1304 + {NULL, NULL}, EBT_MARK_TARGET, ebt_target_mark,
1305 + ebt_target_mark_check, NULL, THIS_MODULE
1308 +static int __init init(void)
1310 + return ebt_register_target(&mark_target);
1313 +static void __exit fini(void)
1315 + ebt_unregister_target(&mark_target);
1321 +MODULE_LICENSE("GPL");
1322 --- /dev/null 2005-03-14 20:10:29.001600248 +0100
1323 +++ linux-2.4.29-ebt-brnf/net/bridge/netfilter/ebt_mark_m.c 2005-03-14 00:00:30.000000000 +0100
1329 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
1335 +#include <linux/netfilter_bridge/ebtables.h>
1336 +#include <linux/netfilter_bridge/ebt_mark_m.h>
1337 +#include <linux/module.h>
1339 +static int ebt_filter_mark(const struct sk_buff *skb,
1340 + const struct net_device *in, const struct net_device *out, const void *data,
1341 + unsigned int datalen)
1343 + struct ebt_mark_m_info *info = (struct ebt_mark_m_info *) data;
1345 + if (info->bitmask & EBT_MARK_OR)
1346 + return !(!!(skb->nfmark & info->mask) ^ info->invert);
1347 + return !(((skb->nfmark & info->mask) == info->mark) ^ info->invert);
1350 +static int ebt_mark_check(const char *tablename, unsigned int hookmask,
1351 + const struct ebt_entry *e, void *data, unsigned int datalen)
1353 + struct ebt_mark_m_info *info = (struct ebt_mark_m_info *) data;
1355 + if (datalen != EBT_ALIGN(sizeof(struct ebt_mark_m_info)))
1357 + if (info->bitmask & ~EBT_MARK_MASK)
1359 + if ((info->bitmask & EBT_MARK_OR) && (info->bitmask & EBT_MARK_AND))
1361 + if (!info->bitmask)
1366 +static struct ebt_match filter_mark =
1368 + {NULL, NULL}, EBT_MARK_MATCH, ebt_filter_mark, ebt_mark_check, NULL,
1372 +static int __init init(void)
1374 + return ebt_register_match(&filter_mark);
1377 +static void __exit fini(void)
1379 + ebt_unregister_match(&filter_mark);
1385 +MODULE_LICENSE("GPL");
1386 --- /dev/null 2005-03-14 20:10:29.001600248 +0100
1387 +++ linux-2.4.29-ebt-brnf/net/bridge/netfilter/ebt_pkttype.c 2005-03-14 00:00:30.000000000 +0100
1393 + * Bart De Schuymer <bdschuym@pandora.be>
1399 +#include <linux/netfilter_bridge/ebtables.h>
1400 +#include <linux/netfilter_bridge/ebt_pkttype.h>
1401 +#include <linux/module.h>
1403 +static int ebt_filter_pkttype(const struct sk_buff *skb,
1404 + const struct net_device *in,
1405 + const struct net_device *out,
1407 + unsigned int datalen)
1409 + struct ebt_pkttype_info *info = (struct ebt_pkttype_info *)data;
1411 + return (skb->pkt_type != info->pkt_type) ^ info->invert;
1414 +static int ebt_pkttype_check(const char *tablename, unsigned int hookmask,
1415 + const struct ebt_entry *e, void *data, unsigned int datalen)
1417 + struct ebt_pkttype_info *info = (struct ebt_pkttype_info *)data;
1419 + if (datalen != EBT_ALIGN(sizeof(struct ebt_pkttype_info)))
1421 + if (info->invert != 0 && info->invert != 1)
1423 + /* Allow any pkt_type value */
1427 +static struct ebt_match filter_pkttype =
1429 + .name = EBT_PKTTYPE_MATCH,
1430 + .match = ebt_filter_pkttype,
1431 + .check = ebt_pkttype_check,
1432 + .me = THIS_MODULE,
1435 +static int __init init(void)
1437 + return ebt_register_match(&filter_pkttype);
1440 +static void __exit fini(void)
1442 + ebt_unregister_match(&filter_pkttype);
1448 +MODULE_LICENSE("GPL");
1449 --- /dev/null 2005-03-14 20:10:29.001600248 +0100
1450 +++ linux-2.4.29-ebt-brnf/net/bridge/netfilter/ebt_stp.c 2005-03-14 00:00:30.000000000 +0100
1456 + * Bart De Schuymer <bdschuym@pandora.be>
1457 + * Stephen Hemminger <shemminger@osdl.org>
1462 +#include <linux/netfilter_bridge/ebtables.h>
1463 +#include <linux/netfilter_bridge/ebt_stp.h>
1464 +#include <linux/module.h>
1466 +#define BPDU_TYPE_CONFIG 0
1467 +#define BPDU_TYPE_TCN 0x80
1469 +struct stp_header {
1478 +struct stp_config_pdu {
1481 + uint8_t root_cost[4];
1482 + uint8_t sender[8];
1484 + uint8_t msg_age[2];
1485 + uint8_t max_age[2];
1486 + uint8_t hello_time[2];
1487 + uint8_t forward_delay[2];
1490 +#define NR16(p) (p[0] << 8 | p[1])
1491 +#define NR32(p) ((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3])
1493 +static int ebt_filter_config(struct ebt_stp_info *info,
1494 + struct stp_config_pdu *stpc)
1496 + struct ebt_stp_config_info *c;
1501 + c = &info->config;
1502 + if ((info->bitmask & EBT_STP_FLAGS) &&
1503 + FWINV(c->flags != stpc->flags, EBT_STP_FLAGS))
1504 + return EBT_NOMATCH;
1505 + if (info->bitmask & EBT_STP_ROOTPRIO) {
1506 + v16 = NR16(stpc->root);
1507 + if (FWINV(v16 < c->root_priol ||
1508 + v16 > c->root_priou, EBT_STP_ROOTPRIO))
1509 + return EBT_NOMATCH;
1511 + if (info->bitmask & EBT_STP_ROOTADDR) {
1513 + for (i = 0; i < 6; i++)
1514 + verdict |= (stpc->root[2+i] ^ c->root_addr[i]) &
1515 + c->root_addrmsk[i];
1516 + if (FWINV(verdict != 0, EBT_STP_ROOTADDR))
1517 + return EBT_NOMATCH;
1519 + if (info->bitmask & EBT_STP_ROOTCOST) {
1520 + v32 = NR32(stpc->root_cost);
1521 + if (FWINV(v32 < c->root_costl ||
1522 + v32 > c->root_costu, EBT_STP_ROOTCOST))
1523 + return EBT_NOMATCH;
1525 + if (info->bitmask & EBT_STP_SENDERPRIO) {
1526 + v16 = NR16(stpc->sender);
1527 + if (FWINV(v16 < c->sender_priol ||
1528 + v16 > c->sender_priou, EBT_STP_SENDERPRIO))
1529 + return EBT_NOMATCH;
1531 + if (info->bitmask & EBT_STP_SENDERADDR) {
1533 + for (i = 0; i < 6; i++)
1534 + verdict |= (stpc->sender[2+i] ^ c->sender_addr[i]) &
1535 + c->sender_addrmsk[i];
1536 + if (FWINV(verdict != 0, EBT_STP_SENDERADDR))
1537 + return EBT_NOMATCH;
1539 + if (info->bitmask & EBT_STP_PORT) {
1540 + v16 = NR16(stpc->port);
1541 + if (FWINV(v16 < c->portl ||
1542 + v16 > c->portu, EBT_STP_PORT))
1543 + return EBT_NOMATCH;
1545 + if (info->bitmask & EBT_STP_MSGAGE) {
1546 + v16 = NR16(stpc->msg_age);
1547 + if (FWINV(v16 < c->msg_agel ||
1548 + v16 > c->msg_ageu, EBT_STP_MSGAGE))
1549 + return EBT_NOMATCH;
1551 + if (info->bitmask & EBT_STP_MAXAGE) {
1552 + v16 = NR16(stpc->max_age);
1553 + if (FWINV(v16 < c->max_agel ||
1554 + v16 > c->max_ageu, EBT_STP_MAXAGE))
1555 + return EBT_NOMATCH;
1557 + if (info->bitmask & EBT_STP_HELLOTIME) {
1558 + v16 = NR16(stpc->hello_time);
1559 + if (FWINV(v16 < c->hello_timel ||
1560 + v16 > c->hello_timeu, EBT_STP_HELLOTIME))
1561 + return EBT_NOMATCH;
1563 + if (info->bitmask & EBT_STP_FWDD) {
1564 + v16 = NR16(stpc->forward_delay);
1565 + if (FWINV(v16 < c->forward_delayl ||
1566 + v16 > c->forward_delayu, EBT_STP_FWDD))
1567 + return EBT_NOMATCH;
1572 +static int ebt_filter_stp(const struct sk_buff *skb, const struct net_device *in,
1573 + const struct net_device *out, const void *data, unsigned int datalen)
1575 + struct ebt_stp_info *info = (struct ebt_stp_info *)data;
1576 + struct stp_header stph;
1577 + uint8_t header[6] = {0x42, 0x42, 0x03, 0x00, 0x00, 0x00};
1578 + if (skb_copy_bits(skb, 0, &stph, sizeof(stph)))
1579 + return EBT_NOMATCH;
1581 + /* The stp code only considers these */
1582 + if (memcmp(&stph, header, sizeof(header)))
1583 + return EBT_NOMATCH;
1585 + if (info->bitmask & EBT_STP_TYPE
1586 + && FWINV(info->type != stph.type, EBT_STP_TYPE))
1587 + return EBT_NOMATCH;
1589 + if (stph.type == BPDU_TYPE_CONFIG &&
1590 + info->bitmask & EBT_STP_CONFIG_MASK) {
1591 + struct stp_config_pdu stpc;
1593 + if (skb_copy_bits(skb, sizeof(stph), &stpc, sizeof(stpc)))
1594 + return EBT_NOMATCH;
1595 + return ebt_filter_config(info, &stpc);
1600 +static int ebt_stp_check(const char *tablename, unsigned int hookmask,
1601 + const struct ebt_entry *e, void *data, unsigned int datalen)
1603 + struct ebt_stp_info *info = (struct ebt_stp_info *)data;
1604 + int len = EBT_ALIGN(sizeof(struct ebt_stp_info));
1605 + uint8_t bridge_ula[6] = { 0x01, 0x80, 0xc2, 0x00, 0x00, 0x00 };
1606 + uint8_t msk[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
1608 + if (info->bitmask & ~EBT_STP_MASK || info->invflags & ~EBT_STP_MASK ||
1609 + !(info->bitmask & EBT_STP_MASK))
1611 + if (datalen != len)
1613 + /* Make sure the match only receives stp frames */
1614 + if (memcmp(e->destmac, bridge_ula, ETH_ALEN) ||
1615 + memcmp(e->destmsk, msk, ETH_ALEN) || !(e->bitmask & EBT_DESTMAC))
1621 +static struct ebt_match filter_stp =
1623 + .name = EBT_STP_MATCH,
1624 + .match = ebt_filter_stp,
1625 + .check = ebt_stp_check,
1626 + .me = THIS_MODULE,
1629 +static int __init init(void)
1631 + return ebt_register_match(&filter_stp);
1634 +static void __exit fini(void)
1636 + ebt_unregister_match(&filter_stp);
1642 +MODULE_LICENSE("GPL");
1643 --- /dev/null 2005-03-14 20:10:29.001600248 +0100
1644 +++ linux-2.4.29-ebt-brnf/net/bridge/netfilter/ebt_redirect.c 2005-03-14 00:00:30.000000000 +0100
1650 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
1656 +#include <linux/netfilter_bridge/ebtables.h>
1657 +#include <linux/netfilter_bridge/ebt_redirect.h>
1658 +#include <linux/module.h>
1659 +#include <net/sock.h>
1660 +#include "../br_private.h"
1662 +static int ebt_target_redirect(struct sk_buff **pskb, unsigned int hooknr,
1663 + const struct net_device *in, const struct net_device *out,
1664 + const void *data, unsigned int datalen)
1666 + struct ebt_redirect_info *info = (struct ebt_redirect_info *)data;
1668 + if (hooknr != NF_BR_BROUTING)
1669 + memcpy((**pskb).mac.ethernet->h_dest,
1670 + in->br_port->br->dev.dev_addr, ETH_ALEN);
1672 + memcpy((**pskb).mac.ethernet->h_dest,
1673 + in->dev_addr, ETH_ALEN);
1674 + (*pskb)->pkt_type = PACKET_HOST;
1676 + return info->target;
1679 +static int ebt_target_redirect_check(const char *tablename, unsigned int hookmask,
1680 + const struct ebt_entry *e, void *data, unsigned int datalen)
1682 + struct ebt_redirect_info *info = (struct ebt_redirect_info *)data;
1684 + if (datalen != EBT_ALIGN(sizeof(struct ebt_redirect_info)))
1686 + if (BASE_CHAIN && info->target == EBT_RETURN)
1688 + CLEAR_BASE_CHAIN_BIT;
1689 + if ( (strcmp(tablename, "nat") || hookmask & ~(1 << NF_BR_PRE_ROUTING)) &&
1690 + (strcmp(tablename, "broute") || hookmask & ~(1 << NF_BR_BROUTING)) )
1692 + if (INVALID_TARGET)
1697 +static struct ebt_target redirect_target =
1699 + {NULL, NULL}, EBT_REDIRECT_TARGET, ebt_target_redirect,
1700 + ebt_target_redirect_check, NULL, THIS_MODULE
1703 +static int __init init(void)
1705 + return ebt_register_target(&redirect_target);
1708 +static void __exit fini(void)
1710 + ebt_unregister_target(&redirect_target);
1716 +MODULE_LICENSE("GPL");
1717 --- /dev/null 2005-03-14 20:10:29.001600248 +0100
1718 +++ linux-2.4.29-ebt-brnf/net/bridge/netfilter/ebt_arp.c 2005-03-14 00:00:30.000000000 +0100
1724 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
1725 + * Tim Gardner <timg@tpi.com>
1731 +#include <linux/netfilter_bridge/ebtables.h>
1732 +#include <linux/netfilter_bridge/ebt_arp.h>
1733 +#include <linux/if_arp.h>
1734 +#include <linux/if_ether.h>
1735 +#include <linux/module.h>
1737 +static int ebt_filter_arp(const struct sk_buff *skb, const struct net_device *in,
1738 + const struct net_device *out, const void *data, unsigned int datalen)
1740 + struct ebt_arp_info *info = (struct ebt_arp_info *)data;
1742 + if (info->bitmask & EBT_ARP_OPCODE && FWINV(info->opcode !=
1743 + ((*skb).nh.arph)->ar_op, EBT_ARP_OPCODE))
1744 + return EBT_NOMATCH;
1745 + if (info->bitmask & EBT_ARP_HTYPE && FWINV(info->htype !=
1746 + ((*skb).nh.arph)->ar_hrd, EBT_ARP_HTYPE))
1747 + return EBT_NOMATCH;
1748 + if (info->bitmask & EBT_ARP_PTYPE && FWINV(info->ptype !=
1749 + ((*skb).nh.arph)->ar_pro, EBT_ARP_PTYPE))
1750 + return EBT_NOMATCH;
1752 + if (info->bitmask & (EBT_ARP_SRC_IP | EBT_ARP_DST_IP))
1754 + uint32_t arp_len = sizeof(struct arphdr) +
1755 + (2 * (((*skb).nh.arph)->ar_hln)) +
1756 + (2 * (((*skb).nh.arph)->ar_pln));
1760 + // Make sure the packet is long enough.
1761 + if ((((*skb).nh.raw) + arp_len) > (*skb).tail)
1762 + return EBT_NOMATCH;
1763 + // IPv4 addresses are always 4 bytes.
1764 + if (((*skb).nh.arph)->ar_pln != sizeof(uint32_t))
1765 + return EBT_NOMATCH;
1767 + if (info->bitmask & EBT_ARP_SRC_IP) {
1768 + memcpy(&src, ((*skb).nh.raw) + sizeof(struct arphdr) +
1769 + ((*skb).nh.arph)->ar_hln, sizeof(uint32_t));
1770 + if (FWINV(info->saddr != (src & info->smsk),
1772 + return EBT_NOMATCH;
1775 + if (info->bitmask & EBT_ARP_DST_IP) {
1776 + memcpy(&dst, ((*skb).nh.raw)+sizeof(struct arphdr) +
1777 + (2*(((*skb).nh.arph)->ar_hln)) +
1778 + (((*skb).nh.arph)->ar_pln), sizeof(uint32_t));
1779 + if (FWINV(info->daddr != (dst & info->dmsk),
1781 + return EBT_NOMATCH;
1785 + if (info->bitmask & (EBT_ARP_SRC_MAC | EBT_ARP_DST_MAC))
1787 + uint32_t arp_len = sizeof(struct arphdr) +
1788 + (2 * (((*skb).nh.arph)->ar_hln)) +
1789 + (2 * (((*skb).nh.arph)->ar_pln));
1790 + unsigned char dst[ETH_ALEN];
1791 + unsigned char src[ETH_ALEN];
1793 + // Make sure the packet is long enough.
1794 + if ((((*skb).nh.raw) + arp_len) > (*skb).tail)
1795 + return EBT_NOMATCH;
1796 + // MAC addresses are 6 bytes.
1797 + if (((*skb).nh.arph)->ar_hln != ETH_ALEN)
1798 + return EBT_NOMATCH;
1799 + if (info->bitmask & EBT_ARP_SRC_MAC) {
1800 + uint8_t verdict, i;
1802 + memcpy(&src, ((*skb).nh.raw) +
1803 + sizeof(struct arphdr),
1806 + for (i = 0; i < 6; i++)
1807 + verdict |= (src[i] ^ info->smaddr[i]) &
1809 + if (FWINV(verdict != 0, EBT_ARP_SRC_MAC))
1810 + return EBT_NOMATCH;
1813 + if (info->bitmask & EBT_ARP_DST_MAC) {
1814 + uint8_t verdict, i;
1816 + memcpy(&dst, ((*skb).nh.raw) +
1817 + sizeof(struct arphdr) +
1818 + (((*skb).nh.arph)->ar_hln) +
1819 + (((*skb).nh.arph)->ar_pln),
1822 + for (i = 0; i < 6; i++)
1823 + verdict |= (dst[i] ^ info->dmaddr[i]) &
1825 + if (FWINV(verdict != 0, EBT_ARP_DST_MAC))
1826 + return EBT_NOMATCH;
1833 +static int ebt_arp_check(const char *tablename, unsigned int hookmask,
1834 + const struct ebt_entry *e, void *data, unsigned int datalen)
1836 + struct ebt_arp_info *info = (struct ebt_arp_info *)data;
1838 + if (datalen != EBT_ALIGN(sizeof(struct ebt_arp_info)))
1840 + if ((e->ethproto != __constant_htons(ETH_P_ARP) &&
1841 + e->ethproto != __constant_htons(ETH_P_RARP)) ||
1842 + e->invflags & EBT_IPROTO)
1844 + if (info->bitmask & ~EBT_ARP_MASK || info->invflags & ~EBT_ARP_MASK)
1849 +static struct ebt_match filter_arp =
1851 + {NULL, NULL}, EBT_ARP_MATCH, ebt_filter_arp, ebt_arp_check, NULL,
1855 +static int __init init(void)
1857 + return ebt_register_match(&filter_arp);
1860 +static void __exit fini(void)
1862 + ebt_unregister_match(&filter_arp);
1868 +MODULE_LICENSE("GPL");
1869 --- /dev/null 2005-03-14 20:10:29.001600248 +0100
1870 +++ linux-2.4.29-ebt-brnf/net/bridge/netfilter/ebt_ip.c 2005-03-14 00:00:30.000000000 +0100
1876 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
1881 + * added ip-sport and ip-dport
1882 + * Innominate Security Technologies AG <mhopf@innominate.com>
1886 +#include <linux/netfilter_bridge/ebtables.h>
1887 +#include <linux/netfilter_bridge/ebt_ip.h>
1888 +#include <linux/ip.h>
1889 +#include <linux/in.h>
1890 +#include <linux/module.h>
1898 + unsigned char *raw;
1899 + struct tcpudphdr *tuh;
1902 +static int ebt_filter_ip(const struct sk_buff *skb, const struct net_device *in,
1903 + const struct net_device *out, const void *data,
1904 + unsigned int datalen)
1906 + struct ebt_ip_info *info = (struct ebt_ip_info *)data;
1908 + if (info->bitmask & EBT_IP_TOS &&
1909 + FWINV(info->tos != ((*skb).nh.iph)->tos, EBT_IP_TOS))
1910 + return EBT_NOMATCH;
1911 + if (info->bitmask & EBT_IP_PROTO) {
1912 + if (FWINV(info->protocol != ((*skb).nh.iph)->protocol,
1914 + return EBT_NOMATCH;
1915 + if ( info->protocol == IPPROTO_TCP ||
1916 + info->protocol == IPPROTO_UDP )
1919 + h.raw = skb->data + skb->nh.iph->ihl*4;
1920 + if (info->bitmask & EBT_IP_DPORT) {
1921 + uint16_t port = ntohs(h.tuh->dst);
1922 + if (FWINV(port < info->dport[0] ||
1923 + port > info->dport[1],
1925 + return EBT_NOMATCH;
1927 + if (info->bitmask & EBT_IP_SPORT) {
1928 + uint16_t port = ntohs(h.tuh->src);
1929 + if (FWINV(port < info->sport[0] ||
1930 + port > info->sport[1],
1932 + return EBT_NOMATCH;
1936 + if (info->bitmask & EBT_IP_SOURCE &&
1937 + FWINV((((*skb).nh.iph)->saddr & info->smsk) !=
1938 + info->saddr, EBT_IP_SOURCE))
1939 + return EBT_NOMATCH;
1940 + if ((info->bitmask & EBT_IP_DEST) &&
1941 + FWINV((((*skb).nh.iph)->daddr & info->dmsk) !=
1942 + info->daddr, EBT_IP_DEST))
1943 + return EBT_NOMATCH;
1947 +static int ebt_ip_check(const char *tablename, unsigned int hookmask,
1948 + const struct ebt_entry *e, void *data, unsigned int datalen)
1950 + struct ebt_ip_info *info = (struct ebt_ip_info *)data;
1952 + if (datalen != EBT_ALIGN(sizeof(struct ebt_ip_info)))
1954 + if (e->ethproto != __constant_htons(ETH_P_IP) ||
1955 + e->invflags & EBT_IPROTO)
1957 + if (info->bitmask & ~EBT_IP_MASK || info->invflags & ~EBT_IP_MASK)
1959 + if (info->bitmask & (EBT_IP_DPORT | EBT_IP_SPORT)) {
1960 + if (!info->bitmask & EBT_IPROTO)
1962 + if (info->protocol != IPPROTO_TCP &&
1963 + info->protocol != IPPROTO_UDP)
1966 + if (info->bitmask & EBT_IP_DPORT && info->dport[0] > info->dport[1])
1968 + if (info->bitmask & EBT_IP_SPORT && info->sport[0] > info->sport[1])
1973 +static struct ebt_match filter_ip =
1975 + {NULL, NULL}, EBT_IP_MATCH, ebt_filter_ip, ebt_ip_check, NULL,
1979 +static int __init init(void)
1981 + return ebt_register_match(&filter_ip);
1984 +static void __exit fini(void)
1986 + ebt_unregister_match(&filter_ip);
1992 +MODULE_LICENSE("GPL");
1993 --- /dev/null 2005-03-14 20:10:29.001600248 +0100
1994 +++ linux-2.4.29-ebt-brnf/net/bridge/netfilter/ebt_vlan.c 2005-03-14 00:00:30.000000000 +0100
1997 + * Description: EBTables 802.1Q match extension kernelspace module.
1998 + * Authors: Nick Fedchik <nick@fedchik.org.ua>
1999 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
2001 + * This program is free software; you can redistribute it and/or modify
2002 + * it under the terms of the GNU General Public License as published by
2003 + * the Free Software Foundation; either version 2 of the License, or
2004 + * (at your option) any later version.
2006 + * This program is distributed in the hope that it will be useful,
2007 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2008 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2009 + * GNU General Public License for more details.
2011 + * You should have received a copy of the GNU General Public License
2012 + * along with this program; if not, write to the Free Software
2013 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2016 +#include <linux/if_ether.h>
2017 +#include <linux/if_vlan.h>
2018 +#include <linux/module.h>
2019 +#include <linux/netfilter_bridge/ebtables.h>
2020 +#include <linux/netfilter_bridge/ebt_vlan.h>
2022 +static unsigned char debug;
2023 +#define MODULE_VERSION "0.6"
2025 +MODULE_PARM(debug, "0-1b");
2026 +MODULE_PARM_DESC(debug, "debug=1 is turn on debug messages");
2027 +MODULE_AUTHOR("Nick Fedchik <nick@fedchik.org.ua>");
2028 +MODULE_DESCRIPTION("802.1Q match module (ebtables extension), v"
2030 +MODULE_LICENSE("GPL");
2033 +#define DEBUG_MSG(args...) if (debug) printk (KERN_DEBUG "ebt_vlan: " args)
2034 +#define INV_FLAG(_inv_flag_) (info->invflags & _inv_flag_) ? "!" : ""
2035 +#define GET_BITMASK(_BIT_MASK_) info->bitmask & _BIT_MASK_
2036 +#define SET_BITMASK(_BIT_MASK_) info->bitmask |= _BIT_MASK_
2037 +#define EXIT_ON_MISMATCH(_MATCH_,_MASK_) if (!((info->_MATCH_ == _MATCH_)^!!(info->invflags & _MASK_))) return 1;
2040 + * Function description: ebt_filter_vlan() is main engine for
2041 + * checking passed 802.1Q frame according to
2042 + * the passed extension parameters (in the *data buffer)
2043 + * ebt_filter_vlan() is called after successfull check the rule params
2044 + * by ebt_check_vlan() function.
2046 + * const struct sk_buff *skb - pointer to passed ethernet frame buffer
2047 + * const void *data - pointer to passed extension parameters
2048 + * unsigned int datalen - length of passed *data buffer
2049 + * const struct net_device *in -
2050 + * const struct net_device *out -
2051 + * const struct ebt_counter *c -
2052 + * Returned values:
2053 + * 0 - ok (all rule params matched)
2054 + * 1 - miss (rule params not acceptable to the parsed frame)
2057 +ebt_filter_vlan(const struct sk_buff *skb,
2058 + const struct net_device *in,
2059 + const struct net_device *out,
2060 + const void *data, unsigned int datalen)
2062 + struct ebt_vlan_info *info = (struct ebt_vlan_info *) data; /* userspace data */
2063 + struct vlan_ethhdr *frame = (struct vlan_ethhdr *) skb->mac.raw; /* Passed tagged frame */
2065 + unsigned short TCI; /* Whole TCI, given from parsed frame */
2066 + unsigned short id; /* VLAN ID, given from frame TCI */
2067 + unsigned char prio; /* user_priority, given from frame TCI */
2068 + unsigned short encap; /* VLAN encapsulated Type/Length field, given from orig frame */
2071 + * Tag Control Information (TCI) consists of the following elements:
2072 + * - User_priority. The user_priority field is three bits in length,
2073 + * interpreted as a binary number.
2074 + * - Canonical Format Indicator (CFI). The Canonical Format Indicator
2075 + * (CFI) is a single bit flag value. Currently ignored.
2076 + * - VLAN Identifier (VID). The VID is encoded as
2077 + * an unsigned binary number.
2079 + TCI = ntohs(frame->h_vlan_TCI);
2080 + id = TCI & VLAN_VID_MASK;
2081 + prio = (TCI >> 13) & 0x7;
2082 + encap = frame->h_vlan_encapsulated_proto;
2085 + * Checking VLAN Identifier (VID)
2087 + if (GET_BITMASK(EBT_VLAN_ID)) { /* Is VLAN ID parsed? */
2088 + EXIT_ON_MISMATCH(id, EBT_VLAN_ID);
2091 + * Checking user_priority
2093 + if (GET_BITMASK(EBT_VLAN_PRIO)) { /* Is VLAN user_priority parsed? */
2094 + EXIT_ON_MISMATCH(prio, EBT_VLAN_PRIO);
2097 + * Checking Encapsulated Proto (Length/Type) field
2099 + if (GET_BITMASK(EBT_VLAN_ENCAP)) { /* Is VLAN Encap parsed? */
2100 + EXIT_ON_MISMATCH(encap, EBT_VLAN_ENCAP);
2103 + * All possible extension parameters was parsed.
2104 + * If rule never returned by missmatch, then all ok.
2110 + * Function description: ebt_vlan_check() is called when userspace
2111 + * delivers the table entry to the kernel,
2112 + * and to check that userspace doesn't give a bad table.
2114 + * const char *tablename - table name string
2115 + * unsigned int hooknr - hook number
2116 + * const struct ebt_entry *e - ebtables entry basic set
2117 + * const void *data - pointer to passed extension parameters
2118 + * unsigned int datalen - length of passed *data buffer
2119 + * Returned values:
2120 + * 0 - ok (all delivered rule params are correct)
2121 + * 1 - miss (rule params is out of range, invalid, incompatible, etc.)
2124 +ebt_check_vlan(const char *tablename,
2125 + unsigned int hooknr,
2126 + const struct ebt_entry *e, void *data, unsigned int datalen)
2128 + struct ebt_vlan_info *info = (struct ebt_vlan_info *) data;
2131 + * Parameters buffer overflow check
2133 + if (datalen != EBT_ALIGN(sizeof(struct ebt_vlan_info))) {
2135 + ("passed size %d is not eq to ebt_vlan_info (%d)\n",
2136 + datalen, sizeof(struct ebt_vlan_info));
2141 + * Is it 802.1Q frame checked?
2143 + if (e->ethproto != __constant_htons(ETH_P_8021Q)) {
2145 + ("passed entry proto %2.4X is not 802.1Q (8100)\n",
2146 + (unsigned short) ntohs(e->ethproto));
2151 + * Check for bitmask range
2152 + * True if even one bit is out of mask
2154 + if (info->bitmask & ~EBT_VLAN_MASK) {
2155 + DEBUG_MSG("bitmask %2X is out of mask (%2X)\n",
2156 + info->bitmask, EBT_VLAN_MASK);
2161 + * Check for inversion flags range
2163 + if (info->invflags & ~EBT_VLAN_MASK) {
2164 + DEBUG_MSG("inversion flags %2X is out of mask (%2X)\n",
2165 + info->invflags, EBT_VLAN_MASK);
2170 + * Reserved VLAN ID (VID) values
2171 + * -----------------------------
2172 + * 0 - The null VLAN ID.
2173 + * 1 - The default Port VID (PVID)
2174 + * 0x0FFF - Reserved for implementation use.
2175 + * if_vlan.h: VLAN_GROUP_ARRAY_LEN 4096.
2177 + if (GET_BITMASK(EBT_VLAN_ID)) { /* when vlan-id param was spec-ed */
2178 + if (!!info->id) { /* if id!=0 => check vid range */
2179 + if (info->id > VLAN_GROUP_ARRAY_LEN) {
2181 + ("id %d is out of range (1-4096)\n",
2186 + * Note: This is valid VLAN-tagged frame point.
2187 + * Any value of user_priority are acceptable,
2188 + * but should be ignored according to 802.1Q Std.
2189 + * So we just drop the prio flag.
2191 + info->bitmask &= ~EBT_VLAN_PRIO;
2194 + * Else, id=0 (null VLAN ID) => user_priority range (any?)
2198 + if (GET_BITMASK(EBT_VLAN_PRIO)) {
2199 + if ((unsigned char) info->prio > 7) {
2201 + ("prio %d is out of range (0-7)\n",
2207 + * Check for encapsulated proto range - it is possible to be
2208 + * any value for u_short range.
2209 + * if_ether.h: ETH_ZLEN 60 - Min. octets in frame sans FCS
2211 + if (GET_BITMASK(EBT_VLAN_ENCAP)) {
2212 + if ((unsigned short) ntohs(info->encap) < ETH_ZLEN) {
2214 + ("encap frame length %d is less than minimal\n",
2215 + ntohs(info->encap));
2223 +static struct ebt_match filter_vlan = {
2233 + * Module initialization function.
2235 +static int __init init(void)
2237 + DEBUG_MSG("ebtables 802.1Q extension module v"
2238 + MODULE_VERSION "\n");
2239 + DEBUG_MSG("module debug=%d\n", !!debug);
2240 + return ebt_register_match(&filter_vlan);
2244 + * Module "finalization" function
2246 +static void __exit fini(void)
2248 + ebt_unregister_match(&filter_vlan);
2255 --- /dev/null 2005-03-14 20:10:29.001600248 +0100
2256 +++ linux-2.4.29-ebt-brnf/net/bridge/netfilter/ebt_log.c 2005-03-14 00:00:30.000000000 +0100
2262 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
2268 +#include <linux/netfilter_bridge/ebtables.h>
2269 +#include <linux/netfilter_bridge/ebt_log.h>
2270 +#include <linux/module.h>
2271 +#include <linux/ip.h>
2272 +#include <linux/in.h>
2273 +#include <linux/if_arp.h>
2274 +#include <linux/spinlock.h>
2276 +static spinlock_t ebt_log_lock = SPIN_LOCK_UNLOCKED;
2278 +static int ebt_log_check(const char *tablename, unsigned int hookmask,
2279 + const struct ebt_entry *e, void *data, unsigned int datalen)
2281 + struct ebt_log_info *info = (struct ebt_log_info *)data;
2283 + if (datalen != EBT_ALIGN(sizeof(struct ebt_log_info)))
2285 + if (info->bitmask & ~EBT_LOG_MASK)
2287 + if (info->loglevel >= 8)
2289 + info->prefix[EBT_LOG_PREFIX_SIZE - 1] = '\0';
2301 + unsigned char mac_src[ETH_ALEN];
2302 + unsigned char ip_src[4];
2303 + unsigned char mac_dst[ETH_ALEN];
2304 + unsigned char ip_dst[4];
2307 +static void print_MAC(unsigned char *p)
2311 + for (i = 0; i < ETH_ALEN; i++, p++)
2312 + printk("%02x%c", *p, i == ETH_ALEN - 1 ? ' ':':');
2315 +#define myNIPQUAD(a) a[0], a[1], a[2], a[3]
2316 +static void ebt_log(const struct sk_buff *skb, unsigned int hooknr,
2317 + const struct net_device *in, const struct net_device *out,
2318 + const void *data, unsigned int datalen)
2320 + struct ebt_log_info *info = (struct ebt_log_info *)data;
2321 + char level_string[4] = "< >";
2322 + level_string[1] = '0' + info->loglevel;
2324 + spin_lock_bh(&ebt_log_lock);
2325 + printk(level_string);
2326 + printk("%s IN=%s OUT=%s ", info->prefix, in ? in->name : "",
2327 + out ? out->name : "");
2329 + printk("MAC source = ");
2330 + print_MAC((skb->mac.ethernet)->h_source);
2331 + printk("MAC dest = ");
2332 + print_MAC((skb->mac.ethernet)->h_dest);
2334 + printk("proto = 0x%04x", ntohs(((*skb).mac.ethernet)->h_proto));
2336 + if ((info->bitmask & EBT_LOG_IP) && skb->mac.ethernet->h_proto ==
2338 + struct iphdr *iph = skb->nh.iph;
2339 + printk(" IP SRC=%u.%u.%u.%u IP DST=%u.%u.%u.%u,",
2340 + NIPQUAD(iph->saddr), NIPQUAD(iph->daddr));
2341 + printk(" IP tos=0x%02X, IP proto=%d", iph->tos, iph->protocol);
2342 + if (iph->protocol == IPPROTO_TCP ||
2343 + iph->protocol == IPPROTO_UDP) {
2344 + struct tcpudphdr *ports = (struct tcpudphdr *)(skb->data + iph->ihl*4);
2346 + if (skb->data + iph->ihl*4 > skb->tail) {
2347 + printk(" INCOMPLETE TCP/UDP header");
2350 + printk(" SPT=%u DPT=%u", ntohs(ports->src),
2351 + ntohs(ports->dst));
2356 + if ((info->bitmask & EBT_LOG_ARP) &&
2357 + ((skb->mac.ethernet->h_proto == __constant_htons(ETH_P_ARP)) ||
2358 + (skb->mac.ethernet->h_proto == __constant_htons(ETH_P_RARP)))) {
2359 + struct arphdr * arph = skb->nh.arph;
2360 + printk(" ARP HTYPE=%d, PTYPE=0x%04x, OPCODE=%d",
2361 + ntohs(arph->ar_hrd), ntohs(arph->ar_pro),
2362 + ntohs(arph->ar_op));
2363 + /* If it's for Ethernet and the lengths are OK,
2364 + * then log the ARP payload */
2365 + if (arph->ar_hrd == __constant_htons(1) &&
2366 + arph->ar_hln == ETH_ALEN &&
2367 + arph->ar_pln == sizeof(uint32_t)) {
2368 + struct arppayload *arpp = (struct arppayload *)(skb->data + sizeof(*arph));
2370 + if (skb->data + sizeof(*arph) > skb->tail) {
2371 + printk(" INCOMPLETE ARP header");
2375 + printk(" ARP MAC SRC=");
2376 + print_MAC(arpp->mac_src);
2377 + printk(" ARP IP SRC=%u.%u.%u.%u",
2378 + myNIPQUAD(arpp->ip_src));
2379 + printk(" ARP MAC DST=");
2380 + print_MAC(arpp->mac_dst);
2381 + printk(" ARP IP DST=%u.%u.%u.%u",
2382 + myNIPQUAD(arpp->ip_dst));
2388 + spin_unlock_bh(&ebt_log_lock);
2391 +static struct ebt_watcher log =
2393 + {NULL, NULL}, EBT_LOG_WATCHER, ebt_log, ebt_log_check, NULL,
2397 +static int __init init(void)
2399 + return ebt_register_watcher(&log);
2402 +static void __exit fini(void)
2404 + ebt_unregister_watcher(&log);
2410 +MODULE_LICENSE("GPL");
2411 --- /dev/null 2005-03-14 20:10:29.001600248 +0100
2412 +++ linux-2.4.29-ebt-brnf/net/bridge/netfilter/ebt_ulog.c 2005-03-14 00:00:30.000000000 +0100
2415 + * netfilter module for userspace bridged Ethernet frames logging daemons
2418 + * Bart De Schuymer <bdschuym@pandora.be>
2422 + * Based on ipt_ULOG.c, which is
2423 + * (C) 2000-2002 by Harald Welte <laforge@netfilter.org>
2425 + * This module accepts two parameters:
2428 + * The parameter specifies how big the buffer for each netlink multicast
2429 + * group is. e.g. If you say nlbufsiz=8192, up to eight kb of packets will
2430 + * get accumulated in the kernel until they are sent to userspace. It is
2431 + * NOT possible to allocate more than 128kB, and it is strongly discouraged,
2432 + * because atomically allocating 128kB inside the network rx softirq is not
2433 + * reliable. Please also keep in mind that this buffer size is allocated for
2434 + * each nlgroup you are using, so the total kernel memory usage increases
2438 + * Specify, after how many hundredths of a second the queue should be
2439 + * flushed even if it is not full yet.
2443 +#include <linux/module.h>
2444 +#include <linux/config.h>
2445 +#include <linux/spinlock.h>
2446 +#include <linux/socket.h>
2447 +#include <linux/skbuff.h>
2448 +#include <linux/kernel.h>
2449 +#include <linux/timer.h>
2450 +#include <linux/netlink.h>
2451 +#include <linux/netdevice.h>
2452 +#include <linux/module.h>
2453 +#include <linux/netfilter_bridge/ebtables.h>
2454 +#include <linux/netfilter_bridge/ebt_ulog.h>
2455 +#include <net/sock.h>
2456 +#include "../br_private.h"
2458 +#define PRINTR(format, args...) do { if (net_ratelimit()) \
2459 + printk(format , ## args); } while (0)
2461 +static unsigned int nlbufsiz = 4096;
2462 +MODULE_PARM(nlbufsiz, "i");
2463 +MODULE_PARM_DESC(nlbufsiz, "netlink buffer size (number of bytes) "
2464 + "(defaults to 4096)");
2466 +static unsigned int flushtimeout = 10;
2467 +MODULE_PARM(flushtimeout, "i");
2468 +MODULE_PARM_DESC(flushtimeout, "buffer flush timeout (hundredths of a second) "
2469 + "(defaults to 10)");
2472 + unsigned int qlen; /* number of nlmsgs' in the skb */
2473 + struct nlmsghdr *lastnlh; /* netlink header of last msg in skb */
2474 + struct sk_buff *skb; /* the pre-allocated skb */
2475 + struct timer_list timer; /* the timer function */
2476 + spinlock_t lock; /* the per-queue lock */
2479 +static ebt_ulog_buff_t ulog_buffers[EBT_ULOG_MAXNLGROUPS];
2480 +static struct sock *ebtlognl;
2482 +/* send one ulog_buff_t to userspace */
2483 +static void ulog_send(unsigned int nlgroup)
2485 + ebt_ulog_buff_t *ub = &ulog_buffers[nlgroup];
2487 + if (timer_pending(&ub->timer))
2488 + del_timer(&ub->timer);
2490 + /* last nlmsg needs NLMSG_DONE */
2492 + ub->lastnlh->nlmsg_type = NLMSG_DONE;
2494 + NETLINK_CB(ub->skb).dst_groups = 1 << nlgroup;
2495 + netlink_broadcast(ebtlognl, ub->skb, 0, 1 << nlgroup, GFP_ATOMIC);
2501 +/* timer function to flush queue in flushtimeout time */
2502 +static void ulog_timer(unsigned long data)
2504 + spin_lock_bh(&ulog_buffers[data].lock);
2505 + if (ulog_buffers[data].skb)
2507 + spin_unlock_bh(&ulog_buffers[data].lock);
2510 +static struct sk_buff *ulog_alloc_skb(unsigned int size)
2512 + struct sk_buff *skb;
2514 + skb = alloc_skb(nlbufsiz, GFP_ATOMIC);
2516 + PRINTR(KERN_ERR "ebt_ulog: can't alloc whole buffer "
2517 + "of size %ub!\n", nlbufsiz);
2518 + if (size < nlbufsiz) {
2519 + /* try to allocate only as much as we need for
2520 + * current packet */
2521 + skb = alloc_skb(size, GFP_ATOMIC);
2523 + PRINTR(KERN_ERR "ebt_ulog: can't even allocate "
2524 + "buffer of size %ub\n", size);
2531 +static void ebt_ulog(const struct sk_buff *skb, unsigned int hooknr,
2532 + const struct net_device *in, const struct net_device *out,
2533 + const void *data, unsigned int datalen)
2535 + ebt_ulog_packet_msg_t *pm;
2536 + size_t size, copy_len;
2537 + struct nlmsghdr *nlh;
2538 + struct ebt_ulog_info *loginfo = (struct ebt_ulog_info *)data;
2539 + unsigned int group = loginfo->nlgroup;
2540 + ebt_ulog_buff_t *ub = &ulog_buffers[group];
2541 + spinlock_t *lock = &ub->lock;
2543 + if ((loginfo->cprange == 0) ||
2544 + (loginfo->cprange > skb->len + ETH_HLEN))
2545 + copy_len = skb->len + ETH_HLEN;
2547 + copy_len = loginfo->cprange;
2549 + size = NLMSG_SPACE(sizeof(*pm) + copy_len);
2551 + spin_lock_bh(lock);
2554 + if (!(ub->skb = ulog_alloc_skb(size)))
2555 + goto alloc_failure;
2556 + } else if (size > skb_tailroom(ub->skb)) {
2559 + if (!(ub->skb = ulog_alloc_skb(size)))
2560 + goto alloc_failure;
2563 + nlh = NLMSG_PUT(ub->skb, 0, ub->qlen, 0,
2564 + size - NLMSG_ALIGN(sizeof(*nlh)));
2567 + pm = NLMSG_DATA(nlh);
2569 + /* Fill in the ulog data */
2570 + do_gettimeofday(&pm->stamp);
2571 + if (ub->qlen == 1)
2572 + ub->skb->stamp = pm->stamp;
2573 + pm->data_len = copy_len;
2574 + pm->mark = skb->nfmark;
2575 + pm->hook = hooknr;
2576 + if (loginfo->prefix != NULL)
2577 + strcpy(pm->prefix, loginfo->prefix);
2579 + *(pm->prefix) = '\0';
2582 + strcpy(pm->physindev, in->name);
2583 + strcpy(pm->indev, in->br_port->br->dev.name);
2585 + pm->indev[0] = pm->physindev[0] = '\0';
2588 + strcpy(pm->physoutdev, out->name);
2589 + strcpy(pm->outdev, out->br_port->br->dev.name);
2591 + pm->outdev[0] = pm->physoutdev[0] = '\0';
2593 + if (skb_copy_bits(skb, -ETH_HLEN, pm->data, copy_len) < 0)
2597 + ub->lastnlh->nlmsg_flags |= NLM_F_MULTI;
2599 + ub->lastnlh = nlh;
2601 + if (ub->qlen >= loginfo->qthreshold)
2603 + else if (!timer_pending(&ub->timer)) {
2604 + ub->timer.expires = jiffies + flushtimeout * HZ / 100;
2605 + add_timer(&ub->timer);
2609 + spin_unlock_bh(lock);
2614 + PRINTR(KERN_ERR "ebt_ULOG: error during NLMSG_PUT.\n");
2620 +static int ebt_ulog_check(const char *tablename, unsigned int hookmask,
2621 + const struct ebt_entry *e, void *data, unsigned int datalen)
2623 + struct ebt_ulog_info *loginfo = (struct ebt_ulog_info *)data;
2625 + if (datalen != EBT_ALIGN(sizeof(struct ebt_ulog_info)) ||
2626 + loginfo->nlgroup > 31)
2629 + loginfo->prefix[EBT_ULOG_PREFIX_LEN - 1] = '\0';
2631 + if (loginfo->qthreshold > EBT_ULOG_MAX_QLEN)
2632 + loginfo->qthreshold = EBT_ULOG_MAX_QLEN;
2637 +static struct ebt_watcher ulog = {
2638 + {NULL, NULL}, EBT_ULOG_WATCHER, ebt_ulog, ebt_ulog_check, NULL,
2642 +static int __init init(void)
2646 + if (nlbufsiz >= 128*1024) {
2647 + printk(KERN_NOTICE "ebt_ulog: Netlink buffer has to be <= 128kB,"
2648 + " please try a smaller nlbufsiz parameter.\n");
2652 + /* initialize ulog_buffers */
2653 + for (i = 0; i < EBT_ULOG_MAXNLGROUPS; i++) {
2654 + init_timer(&ulog_buffers[i].timer);
2655 + ulog_buffers[i].timer.function = ulog_timer;
2656 + ulog_buffers[i].timer.data = i;
2657 + ulog_buffers[i].lock = SPIN_LOCK_UNLOCKED;
2660 + ebtlognl = netlink_kernel_create(NETLINK_NFLOG, NULL);
2663 + else if ((ret = ebt_register_watcher(&ulog)))
2664 + sock_release(ebtlognl->socket);
2669 +static void __exit fini(void)
2671 + ebt_ulog_buff_t *ub;
2674 + ebt_unregister_watcher(&ulog);
2675 + for (i = 0; i < EBT_ULOG_MAXNLGROUPS; i++) {
2676 + ub = &ulog_buffers[i];
2677 + if (timer_pending(&ub->timer))
2678 + del_timer(&ub->timer);
2679 + spin_lock_bh(&ub->lock);
2681 + kfree_skb(ub->skb);
2684 + spin_unlock_bh(&ub->lock);
2686 + sock_release(ebtlognl->socket);
2691 +MODULE_LICENSE("GPL");
2692 +MODULE_AUTHOR("Bart De Schuymer <bdschuym@pandora.be>");
2693 +MODULE_DESCRIPTION("ebtables userspace logging module for bridged Ethernet"
2695 --- /dev/null 2005-03-14 20:10:29.001600248 +0100
2696 +++ linux-2.4.29-ebt-brnf/net/bridge/netfilter/ebt_snat.c 2005-03-14 00:00:30.000000000 +0100
2702 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
2708 +#include <linux/netfilter_bridge/ebtables.h>
2709 +#include <linux/netfilter_bridge/ebt_nat.h>
2710 +#include <linux/module.h>
2712 +static int ebt_target_snat(struct sk_buff **pskb, unsigned int hooknr,
2713 + const struct net_device *in, const struct net_device *out,
2714 + const void *data, unsigned int datalen)
2716 + struct ebt_nat_info *info = (struct ebt_nat_info *) data;
2718 + memcpy(((**pskb).mac.ethernet)->h_source, info->mac,
2719 + ETH_ALEN * sizeof(unsigned char));
2720 + return info->target;
2723 +static int ebt_target_snat_check(const char *tablename, unsigned int hookmask,
2724 + const struct ebt_entry *e, void *data, unsigned int datalen)
2726 + struct ebt_nat_info *info = (struct ebt_nat_info *) data;
2728 + if (datalen != EBT_ALIGN(sizeof(struct ebt_nat_info)))
2730 + if (BASE_CHAIN && info->target == EBT_RETURN)
2732 + CLEAR_BASE_CHAIN_BIT;
2733 + if (strcmp(tablename, "nat"))
2735 + if (hookmask & ~(1 << NF_BR_POST_ROUTING))
2737 + if (INVALID_TARGET)
2742 +static struct ebt_target snat =
2744 + {NULL, NULL}, EBT_SNAT_TARGET, ebt_target_snat, ebt_target_snat_check,
2748 +static int __init init(void)
2750 + return ebt_register_target(&snat);
2753 +static void __exit fini(void)
2755 + ebt_unregister_target(&snat);
2761 +MODULE_LICENSE("GPL");
2762 --- /dev/null 2005-03-14 20:10:29.001600248 +0100
2763 +++ linux-2.4.29-ebt-brnf/net/bridge/netfilter/ebt_dnat.c 2005-03-14 00:00:30.000000000 +0100
2769 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
2775 +#include <linux/netfilter_bridge/ebtables.h>
2776 +#include <linux/netfilter_bridge/ebt_nat.h>
2777 +#include <linux/module.h>
2778 +#include <net/sock.h>
2780 +static int ebt_target_dnat(struct sk_buff **pskb, unsigned int hooknr,
2781 + const struct net_device *in, const struct net_device *out,
2782 + const void *data, unsigned int datalen)
2784 + struct ebt_nat_info *info = (struct ebt_nat_info *)data;
2786 + memcpy(((**pskb).mac.ethernet)->h_dest, info->mac,
2787 + ETH_ALEN * sizeof(unsigned char));
2788 + return info->target;
2791 +static int ebt_target_dnat_check(const char *tablename, unsigned int hookmask,
2792 + const struct ebt_entry *e, void *data, unsigned int datalen)
2794 + struct ebt_nat_info *info = (struct ebt_nat_info *)data;
2796 + if (BASE_CHAIN && info->target == EBT_RETURN)
2798 + CLEAR_BASE_CHAIN_BIT;
2799 + if ( (strcmp(tablename, "nat") ||
2800 + (hookmask & ~((1 << NF_BR_PRE_ROUTING) | (1 << NF_BR_LOCAL_OUT)))) &&
2801 + (strcmp(tablename, "broute") || hookmask & ~(1 << NF_BR_BROUTING)) )
2803 + if (datalen != EBT_ALIGN(sizeof(struct ebt_nat_info)))
2805 + if (INVALID_TARGET)
2810 +static struct ebt_target dnat =
2812 + {NULL, NULL}, EBT_DNAT_TARGET, ebt_target_dnat, ebt_target_dnat_check,
2816 +static int __init init(void)
2818 + return ebt_register_target(&dnat);
2821 +static void __exit fini(void)
2823 + ebt_unregister_target(&dnat);
2829 +MODULE_LICENSE("GPL");
2830 --- /dev/null 2005-03-14 20:10:29.001600248 +0100
2831 +++ linux-2.4.29-ebt-brnf/net/bridge/netfilter/ebtables.c 2005-03-14 21:04:05.155913576 +0100
2837 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
2839 + * ebtables.c,v 2.0, July, 2002
2841 + * This code is stongly inspired on the iptables code which is
2842 + * Copyright (C) 1999 Paul `Rusty' Russell & Michael J. Neuling
2844 + * This program is free software; you can redistribute it and/or
2845 + * modify it under the terms of the GNU General Public License
2846 + * as published by the Free Software Foundation; either version
2847 + * 2 of the License, or (at your option) any later version.
2850 +// used for print_string
2851 +#include <linux/sched.h>
2852 +#include <linux/tty.h>
2854 +#include <linux/kmod.h>
2855 +#include <linux/module.h>
2856 +#include <linux/vmalloc.h>
2857 +#include <linux/netfilter_bridge/ebtables.h>
2858 +#include <linux/spinlock.h>
2859 +#include <asm/uaccess.h>
2860 +#include <linux/smp.h>
2861 +#include <net/sock.h>
2862 +// needed for logical [in,out]-dev filtering
2863 +#include "../br_private.h"
2866 +#define ASSERT_READ_LOCK(x)
2867 +#define ASSERT_WRITE_LOCK(x)
2868 +#include <linux/netfilter_ipv4/listhelp.h>
2870 +#if 0 // use this for remote debugging
2871 +// Copyright (C) 1998 by Ori Pomerantz
2872 +// Print the string to the appropriate tty, the one
2873 +// the current task uses
2874 +static void print_string(char *str)
2876 + struct tty_struct *my_tty;
2878 + /* The tty for the current task */
2879 + my_tty = current->tty;
2880 + if (my_tty != NULL) {
2881 + (*(my_tty->driver).write)(my_tty, 0, str, strlen(str));
2882 + (*(my_tty->driver).write)(my_tty, 0, "\015\012", 2);
2886 +#define BUGPRINT(args) print_string(args);
2888 +#define BUGPRINT(format, args...) printk("kernel msg: ebtables bug: please "\
2889 + "report to author: "format, ## args)
2890 +// #define BUGPRINT(format, args...)
2892 +#define MEMPRINT(format, args...) printk("kernel msg: ebtables "\
2893 + ": out of memory: "format, ## args)
2894 +// #define MEMPRINT(format, args...)
2898 +// Each cpu has its own set of counters, so there is no need for write_lock in
2900 +// For reading or updating the counters, the user context needs to
2901 +// get a write_lock
2903 +// The size of each set of counters is altered to get cache alignment
2904 +#define SMP_ALIGN(x) (((x) + SMP_CACHE_BYTES-1) & ~(SMP_CACHE_BYTES-1))
2905 +#define COUNTER_OFFSET(n) (SMP_ALIGN(n * sizeof(struct ebt_counter)))
2906 +#define COUNTER_BASE(c, n, cpu) ((struct ebt_counter *)(((char *)c) + \
2907 + COUNTER_OFFSET(n) * cpu))
2911 +static DECLARE_MUTEX(ebt_mutex);
2912 +static LIST_HEAD(ebt_tables);
2913 +static LIST_HEAD(ebt_targets);
2914 +static LIST_HEAD(ebt_matches);
2915 +static LIST_HEAD(ebt_watchers);
2917 +static struct ebt_target ebt_standard_target =
2918 +{ {NULL, NULL}, EBT_STANDARD_TARGET, NULL, NULL, NULL, NULL};
2920 +static inline int ebt_do_watcher (struct ebt_entry_watcher *w,
2921 + const struct sk_buff *skb, unsigned int hooknr, const struct net_device *in,
2922 + const struct net_device *out)
2924 + w->u.watcher->watcher(skb, hooknr, in, out, w->data,
2926 + // watchers don't give a verdict
2930 +static inline int ebt_do_match (struct ebt_entry_match *m,
2931 + const struct sk_buff *skb, const struct net_device *in,
2932 + const struct net_device *out)
2934 + return m->u.match->match(skb, in, out, m->data,
2938 +static inline int ebt_dev_check(char *entry, const struct net_device *device)
2941 + char *devname = device->name;
2943 + if (*entry == '\0')
2947 + /* 1 is the wildcard token */
2948 + while (entry[i] != '\0' && entry[i] != 1 && entry[i] == devname[i])
2950 + return (devname[i] != entry[i] && entry[i] != 1);
2953 +#define FWINV2(bool,invflg) ((bool) ^ !!(e->invflags & invflg))
2954 +// process standard matches
2955 +static inline int ebt_basic_match(struct ebt_entry *e, struct ethhdr *h,
2956 + const struct net_device *in, const struct net_device *out)
2960 + if (e->bitmask & EBT_802_3) {
2961 + if (FWINV2(ntohs(h->h_proto) >= 1536, EBT_IPROTO))
2963 + } else if (!(e->bitmask & EBT_NOPROTO) &&
2964 + FWINV2(e->ethproto != h->h_proto, EBT_IPROTO))
2967 + if (FWINV2(ebt_dev_check(e->in, in), EBT_IIN))
2969 + if (FWINV2(ebt_dev_check(e->out, out), EBT_IOUT))
2971 + if ((!in || !in->br_port) ? 0 : FWINV2(ebt_dev_check(
2972 + e->logical_in, &in->br_port->br->dev), EBT_ILOGICALIN))
2974 + if ((!out || !out->br_port) ? 0 : FWINV2(ebt_dev_check(
2975 + e->logical_out, &out->br_port->br->dev), EBT_ILOGICALOUT))
2978 + if (e->bitmask & EBT_SOURCEMAC) {
2980 + for (i = 0; i < 6; i++)
2981 + verdict |= (h->h_source[i] ^ e->sourcemac[i]) &
2983 + if (FWINV2(verdict != 0, EBT_ISOURCE) )
2986 + if (e->bitmask & EBT_DESTMAC) {
2988 + for (i = 0; i < 6; i++)
2989 + verdict |= (h->h_dest[i] ^ e->destmac[i]) &
2991 + if (FWINV2(verdict != 0, EBT_IDEST) )
2997 +// Do some firewalling
2998 +unsigned int ebt_do_table (unsigned int hook, struct sk_buff **pskb,
2999 + const struct net_device *in, const struct net_device *out,
3000 + struct ebt_table *table)
3003 + struct ebt_entry *point;
3004 + struct ebt_counter *counter_base, *cb_base;
3005 + struct ebt_entry_target *t;
3006 + int verdict, sp = 0;
3007 + struct ebt_chainstack *cs;
3008 + struct ebt_entries *chaininfo;
3010 + struct ebt_table_info *private;
3012 + read_lock_bh(&table->lock);
3013 + private = table->private;
3014 + cb_base = COUNTER_BASE(private->counters, private->nentries,
3015 + cpu_number_map(smp_processor_id()));
3016 + if (private->chainstack)
3017 + cs = private->chainstack[cpu_number_map(smp_processor_id())];
3020 + chaininfo = private->hook_entry[hook];
3021 + nentries = private->hook_entry[hook]->nentries;
3022 + point = (struct ebt_entry *)(private->hook_entry[hook]->data);
3023 + counter_base = cb_base + private->hook_entry[hook]->counter_offset;
3024 + // base for chain jumps
3025 + base = private->entries;
3027 + while (i < nentries) {
3028 + if (ebt_basic_match(point, (**pskb).mac.ethernet, in, out))
3029 + goto letscontinue;
3031 + if (EBT_MATCH_ITERATE(point, ebt_do_match, *pskb, in, out) != 0)
3032 + goto letscontinue;
3034 + // increase counter
3035 + (*(counter_base + i)).pcnt++;
3036 + (*(counter_base + i)).bcnt+=(**pskb).len;
3038 + // these should only watch: not modify, nor tell us
3039 + // what to do with the packet
3040 + EBT_WATCHER_ITERATE(point, ebt_do_watcher, *pskb, hook, in,
3043 + t = (struct ebt_entry_target *)
3044 + (((char *)point) + point->target_offset);
3045 + // standard target
3046 + if (!t->u.target->target)
3047 + verdict = ((struct ebt_standard_target *)t)->verdict;
3049 + verdict = t->u.target->target(pskb, hook,
3050 + in, out, t->data, t->target_size);
3051 + if (verdict == EBT_ACCEPT) {
3052 + read_unlock_bh(&table->lock);
3055 + if (verdict == EBT_DROP) {
3056 + read_unlock_bh(&table->lock);
3059 + if (verdict == EBT_RETURN) {
3061 +#ifdef CONFIG_NETFILTER_DEBUG
3063 + BUGPRINT("RETURN on base chain");
3064 + // act like this is EBT_CONTINUE
3065 + goto letscontinue;
3069 + // put all the local variables right
3071 + chaininfo = cs[sp].chaininfo;
3072 + nentries = chaininfo->nentries;
3074 + counter_base = cb_base +
3075 + chaininfo->counter_offset;
3078 + if (verdict == EBT_CONTINUE)
3079 + goto letscontinue;
3080 +#ifdef CONFIG_NETFILTER_DEBUG
3081 + if (verdict < 0) {
3082 + BUGPRINT("bogus standard verdict\n");
3083 + read_unlock_bh(&table->lock);
3089 + cs[sp].chaininfo = chaininfo;
3090 + cs[sp].e = (struct ebt_entry *)
3091 + (((char *)point) + point->next_offset);
3093 + chaininfo = (struct ebt_entries *) (base + verdict);
3094 +#ifdef CONFIG_NETFILTER_DEBUG
3095 + if (chaininfo->distinguisher) {
3096 + BUGPRINT("jump to non-chain\n");
3097 + read_unlock_bh(&table->lock);
3101 + nentries = chaininfo->nentries;
3102 + point = (struct ebt_entry *)chaininfo->data;
3103 + counter_base = cb_base + chaininfo->counter_offset;
3107 + point = (struct ebt_entry *)
3108 + (((char *)point) + point->next_offset);
3112 + // I actually like this :)
3113 + if (chaininfo->policy == EBT_RETURN)
3115 + if (chaininfo->policy == EBT_ACCEPT) {
3116 + read_unlock_bh(&table->lock);
3119 + read_unlock_bh(&table->lock);
3123 +// If it succeeds, returns element and locks mutex
3124 +static inline void *
3125 +find_inlist_lock_noload(struct list_head *head, const char *name, int *error,
3126 + struct semaphore *mutex)
3130 + *error = down_interruptible(mutex);
3134 + ret = list_named_find(head, name);
3142 +#ifndef CONFIG_KMOD
3143 +#define find_inlist_lock(h,n,p,e,m) find_inlist_lock_noload((h),(n),(e),(m))
3146 +find_inlist_lock(struct list_head *head, const char *name, const char *prefix,
3147 + int *error, struct semaphore *mutex)
3151 + ret = find_inlist_lock_noload(head, name, error, mutex);
3153 + char modulename[EBT_FUNCTION_MAXNAMELEN + strlen(prefix) + 1];
3154 + strcpy(modulename, prefix);
3155 + strcat(modulename, name);
3156 + request_module(modulename);
3157 + ret = find_inlist_lock_noload(head, name, error, mutex);
3163 +static inline struct ebt_table *
3164 +find_table_lock(const char *name, int *error, struct semaphore *mutex)
3166 + return find_inlist_lock(&ebt_tables, name, "ebtable_", error, mutex);
3169 +static inline struct ebt_match *
3170 +find_match_lock(const char *name, int *error, struct semaphore *mutex)
3172 + return find_inlist_lock(&ebt_matches, name, "ebt_", error, mutex);
3175 +static inline struct ebt_watcher *
3176 +find_watcher_lock(const char *name, int *error, struct semaphore *mutex)
3178 + return find_inlist_lock(&ebt_watchers, name, "ebt_", error, mutex);
3181 +static inline struct ebt_target *
3182 +find_target_lock(const char *name, int *error, struct semaphore *mutex)
3184 + return find_inlist_lock(&ebt_targets, name, "ebt_", error, mutex);
3188 +ebt_check_match(struct ebt_entry_match *m, struct ebt_entry *e,
3189 + const char *name, unsigned int hookmask, unsigned int *cnt)
3191 + struct ebt_match *match;
3194 + if (((char *)m) + m->match_size + sizeof(struct ebt_entry_match) >
3195 + ((char *)e) + e->watchers_offset)
3197 + match = find_match_lock(m->u.name, &ret, &ebt_mutex);
3200 + m->u.match = match;
3202 + __MOD_INC_USE_COUNT(match->me);
3204 + if (match->check &&
3205 + match->check(name, hookmask, e, m->data, m->match_size) != 0) {
3206 + BUGPRINT("match->check failed\n");
3208 + __MOD_DEC_USE_COUNT(match->me);
3216 +ebt_check_watcher(struct ebt_entry_watcher *w, struct ebt_entry *e,
3217 + const char *name, unsigned int hookmask, unsigned int *cnt)
3219 + struct ebt_watcher *watcher;
3222 + if (((char *)w) + w->watcher_size + sizeof(struct ebt_entry_watcher) >
3223 + ((char *)e) + e->target_offset)
3225 + watcher = find_watcher_lock(w->u.name, &ret, &ebt_mutex);
3228 + w->u.watcher = watcher;
3230 + __MOD_INC_USE_COUNT(watcher->me);
3232 + if (watcher->check &&
3233 + watcher->check(name, hookmask, e, w->data, w->watcher_size) != 0) {
3234 + BUGPRINT("watcher->check failed\n");
3236 + __MOD_DEC_USE_COUNT(watcher->me);
3243 +// this one is very careful, as it is the first function
3244 +// to parse the userspace data
3246 +ebt_check_entry_size_and_hooks(struct ebt_entry *e,
3247 + struct ebt_table_info *newinfo, char *base, char *limit,
3248 + struct ebt_entries **hook_entries, unsigned int *n, unsigned int *cnt,
3249 + unsigned int *totalcnt, unsigned int *udc_cnt, unsigned int valid_hooks)
3253 + for (i = 0; i < NF_BR_NUMHOOKS; i++) {
3254 + if ((valid_hooks & (1 << i)) == 0)
3256 + if ( (char *)hook_entries[i] - base ==
3257 + (char *)e - newinfo->entries)
3260 + // beginning of a new chain
3261 + // if i == NF_BR_NUMHOOKS it must be a user defined chain
3262 + if (i != NF_BR_NUMHOOKS || !(e->bitmask & EBT_ENTRY_OR_ENTRIES)) {
3263 + if ((e->bitmask & EBT_ENTRY_OR_ENTRIES) != 0) {
3264 + // we make userspace set this right,
3265 + // so there is no misunderstanding
3266 + BUGPRINT("EBT_ENTRY_OR_ENTRIES shouldn't be set "
3267 + "in distinguisher\n");
3270 + // this checks if the previous chain has as many entries
3271 + // as it said it has
3273 + BUGPRINT("nentries does not equal the nr of entries "
3274 + "in the chain\n");
3277 + // before we look at the struct, be sure it is not too big
3278 + if ((char *)hook_entries[i] + sizeof(struct ebt_entries)
3280 + BUGPRINT("entries_size too small\n");
3283 + if (((struct ebt_entries *)e)->policy != EBT_DROP &&
3284 + ((struct ebt_entries *)e)->policy != EBT_ACCEPT) {
3285 + // only RETURN from udc
3286 + if (i != NF_BR_NUMHOOKS ||
3287 + ((struct ebt_entries *)e)->policy != EBT_RETURN) {
3288 + BUGPRINT("bad policy\n");
3292 + if (i == NF_BR_NUMHOOKS) // it's a user defined chain
3295 + newinfo->hook_entry[i] = (struct ebt_entries *)e;
3296 + if (((struct ebt_entries *)e)->counter_offset != *totalcnt) {
3297 + BUGPRINT("counter_offset != totalcnt");
3300 + *n = ((struct ebt_entries *)e)->nentries;
3304 + // a plain old entry, heh
3305 + if (sizeof(struct ebt_entry) > e->watchers_offset ||
3306 + e->watchers_offset > e->target_offset ||
3307 + e->target_offset >= e->next_offset) {
3308 + BUGPRINT("entry offsets not in right order\n");
3311 + // this is not checked anywhere else
3312 + if (e->next_offset - e->target_offset < sizeof(struct ebt_entry_target)) {
3313 + BUGPRINT("target size too small\n");
3322 +struct ebt_cl_stack
3324 + struct ebt_chainstack cs;
3326 + unsigned int hookmask;
3329 +// we need these positions to check that the jumps to a different part of the
3330 +// entries is a jump to the beginning of a new chain.
3332 +ebt_get_udc_positions(struct ebt_entry *e, struct ebt_table_info *newinfo,
3333 + struct ebt_entries **hook_entries, unsigned int *n, unsigned int valid_hooks,
3334 + struct ebt_cl_stack *udc)
3338 + // we're only interested in chain starts
3339 + if (e->bitmask & EBT_ENTRY_OR_ENTRIES)
3341 + for (i = 0; i < NF_BR_NUMHOOKS; i++) {
3342 + if ((valid_hooks & (1 << i)) == 0)
3344 + if (newinfo->hook_entry[i] == (struct ebt_entries *)e)
3347 + // only care about udc
3348 + if (i != NF_BR_NUMHOOKS)
3351 + udc[*n].cs.chaininfo = (struct ebt_entries *)e;
3352 + // these initialisations are depended on later in check_chainloops()
3354 + udc[*n].hookmask = 0;
3361 +ebt_cleanup_match(struct ebt_entry_match *m, unsigned int *i)
3363 + if (i && (*i)-- == 0)
3365 + if (m->u.match->destroy)
3366 + m->u.match->destroy(m->data, m->match_size);
3367 + if (m->u.match->me)
3368 + __MOD_DEC_USE_COUNT(m->u.match->me);
3374 +ebt_cleanup_watcher(struct ebt_entry_watcher *w, unsigned int *i)
3376 + if (i && (*i)-- == 0)
3378 + if (w->u.watcher->destroy)
3379 + w->u.watcher->destroy(w->data, w->watcher_size);
3380 + if (w->u.watcher->me)
3381 + __MOD_DEC_USE_COUNT(w->u.watcher->me);
3387 +ebt_cleanup_entry(struct ebt_entry *e, unsigned int *cnt)
3389 + struct ebt_entry_target *t;
3391 + if ((e->bitmask & EBT_ENTRY_OR_ENTRIES) == 0)
3394 + if (cnt && (*cnt)-- == 0)
3396 + EBT_WATCHER_ITERATE(e, ebt_cleanup_watcher, NULL);
3397 + EBT_MATCH_ITERATE(e, ebt_cleanup_match, NULL);
3398 + t = (struct ebt_entry_target *)(((char *)e) + e->target_offset);
3399 + if (t->u.target->destroy)
3400 + t->u.target->destroy(t->data, t->target_size);
3401 + if (t->u.target->me)
3402 + __MOD_DEC_USE_COUNT(t->u.target->me);
3408 +ebt_check_entry(struct ebt_entry *e, struct ebt_table_info *newinfo,
3409 + const char *name, unsigned int *cnt, unsigned int valid_hooks,
3410 + struct ebt_cl_stack *cl_s, unsigned int udc_cnt)
3412 + struct ebt_entry_target *t;
3413 + struct ebt_target *target;
3414 + unsigned int i, j, hook = 0, hookmask = 0;
3417 + // Don't mess with the struct ebt_entries
3418 + if ((e->bitmask & EBT_ENTRY_OR_ENTRIES) == 0)
3421 + if (e->bitmask & ~EBT_F_MASK) {
3422 + BUGPRINT("Unknown flag for bitmask\n");
3425 + if (e->invflags & ~EBT_INV_MASK) {
3426 + BUGPRINT("Unknown flag for inv bitmask\n");
3429 + if ( (e->bitmask & EBT_NOPROTO) && (e->bitmask & EBT_802_3) ) {
3430 + BUGPRINT("NOPROTO & 802_3 not allowed\n");
3433 + // what hook do we belong to?
3434 + for (i = 0; i < NF_BR_NUMHOOKS; i++) {
3435 + if ((valid_hooks & (1 << i)) == 0)
3437 + if ((char *)newinfo->hook_entry[i] < (char *)e)
3442 + // (1 << NF_BR_NUMHOOKS) tells the check functions the rule is on
3444 + if (i < NF_BR_NUMHOOKS)
3445 + hookmask = (1 << hook) | (1 << NF_BR_NUMHOOKS);
3447 + for (i = 0; i < udc_cnt; i++)
3448 + if ((char *)(cl_s[i].cs.chaininfo) > (char *)e)
3451 + hookmask = (1 << hook) | (1 << NF_BR_NUMHOOKS);
3453 + hookmask = cl_s[i - 1].hookmask;
3456 + ret = EBT_MATCH_ITERATE(e, ebt_check_match, e, name, hookmask, &i);
3458 + goto cleanup_matches;
3460 + ret = EBT_WATCHER_ITERATE(e, ebt_check_watcher, e, name, hookmask, &j);
3462 + goto cleanup_watchers;
3463 + t = (struct ebt_entry_target *)(((char *)e) + e->target_offset);
3464 + target = find_target_lock(t->u.name, &ret, &ebt_mutex);
3466 + goto cleanup_watchers;
3468 + __MOD_INC_USE_COUNT(target->me);
3471 + t->u.target = target;
3472 + if (t->u.target == &ebt_standard_target) {
3473 + if (e->target_offset + sizeof(struct ebt_standard_target) >
3475 + BUGPRINT("Standard target size too big\n");
3477 + goto cleanup_watchers;
3479 + if (((struct ebt_standard_target *)t)->verdict <
3480 + -NUM_STANDARD_TARGETS) {
3481 + BUGPRINT("Invalid standard target\n");
3483 + goto cleanup_watchers;
3485 + } else if ((e->target_offset + t->target_size +
3486 + sizeof(struct ebt_entry_target) > e->next_offset) ||
3487 + (t->u.target->check &&
3488 + t->u.target->check(name, hookmask, e, t->data, t->target_size) != 0)){
3489 + if (t->u.target->me)
3490 + __MOD_DEC_USE_COUNT(t->u.target->me);
3492 + goto cleanup_watchers;
3497 + EBT_WATCHER_ITERATE(e, ebt_cleanup_watcher, &j);
3499 + EBT_MATCH_ITERATE(e, ebt_cleanup_match, &i);
3503 +// checks for loops and sets the hook mask for udc
3504 +// the hook mask for udc tells us from which base chains the udc can be
3505 +// accessed. This mask is a parameter to the check() functions of the extensions
3506 +static int check_chainloops(struct ebt_entries *chain,
3507 + struct ebt_cl_stack *cl_s, unsigned int udc_cnt,
3508 + unsigned int hooknr, char *base)
3510 + int i, chain_nr = -1, pos = 0, nentries = chain->nentries, verdict;
3511 + struct ebt_entry *e = (struct ebt_entry *)chain->data;
3512 + struct ebt_entry_target *t;
3514 + while (pos < nentries || chain_nr != -1) {
3515 + // end of udc, go back one 'recursion' step
3516 + if (pos == nentries) {
3517 + // put back values of the time when this chain was called
3518 + e = cl_s[chain_nr].cs.e;
3519 + if (cl_s[chain_nr].from != -1)
3521 + cl_s[cl_s[chain_nr].from].cs.chaininfo->nentries;
3523 + nentries = chain->nentries;
3524 + pos = cl_s[chain_nr].cs.n;
3525 + // make sure we won't see a loop that isn't one
3526 + cl_s[chain_nr].cs.n = 0;
3527 + chain_nr = cl_s[chain_nr].from;
3528 + if (pos == nentries)
3531 + t = (struct ebt_entry_target *)
3532 + (((char *)e) + e->target_offset);
3533 + if (strcmp(t->u.name, EBT_STANDARD_TARGET))
3534 + goto letscontinue;
3535 + if (e->target_offset + sizeof(struct ebt_standard_target) >
3537 + BUGPRINT("Standard target size too big\n");
3540 + verdict = ((struct ebt_standard_target *)t)->verdict;
3541 + if (verdict >= 0) { // jump to another chain
3542 + struct ebt_entries *hlp2 =
3543 + (struct ebt_entries *)(base + verdict);
3544 + for (i = 0; i < udc_cnt; i++)
3545 + if (hlp2 == cl_s[i].cs.chaininfo)
3547 + // bad destination or loop
3548 + if (i == udc_cnt) {
3549 + BUGPRINT("bad destination\n");
3552 + if (cl_s[i].cs.n) {
3553 + BUGPRINT("loop\n");
3556 + // this can't be 0, so the above test is correct
3557 + cl_s[i].cs.n = pos + 1;
3559 + cl_s[i].cs.e = ((void *)e + e->next_offset);
3560 + e = (struct ebt_entry *)(hlp2->data);
3561 + nentries = hlp2->nentries;
3562 + cl_s[i].from = chain_nr;
3564 + // this udc is accessible from the base chain for hooknr
3565 + cl_s[i].hookmask |= (1 << hooknr);
3569 + e = (void *)e + e->next_offset;
3575 +// do the parsing of the table/chains/entries/matches/watchers/targets, heh
3576 +static int translate_table(struct ebt_replace *repl,
3577 + struct ebt_table_info *newinfo)
3579 + unsigned int i, j, k, udc_cnt;
3581 + struct ebt_cl_stack *cl_s = NULL; // used in the checking for chain loops
3584 + while (i < NF_BR_NUMHOOKS && !(repl->valid_hooks & (1 << i)))
3586 + if (i == NF_BR_NUMHOOKS) {
3587 + BUGPRINT("No valid hooks specified\n");
3590 + if (repl->hook_entry[i] != (struct ebt_entries *)repl->entries) {
3591 + BUGPRINT("Chains don't start at beginning\n");
3594 + // make sure chains are ordered after each other in same order
3595 + // as their corresponding hooks
3596 + for (j = i + 1; j < NF_BR_NUMHOOKS; j++) {
3597 + if (!(repl->valid_hooks & (1 << j)))
3599 + if ( repl->hook_entry[j] <= repl->hook_entry[i] ) {
3600 + BUGPRINT("Hook order must be followed\n");
3606 + for (i = 0; i < NF_BR_NUMHOOKS; i++)
3607 + newinfo->hook_entry[i] = NULL;
3609 + newinfo->entries_size = repl->entries_size;
3610 + newinfo->nentries = repl->nentries;
3612 + // do some early checkings and initialize some things
3613 + i = 0; // holds the expected nr. of entries for the chain
3614 + j = 0; // holds the up to now counted entries for the chain
3615 + k = 0; // holds the total nr. of entries, should equal
3616 + // newinfo->nentries afterwards
3617 + udc_cnt = 0; // will hold the nr. of user defined chains (udc)
3618 + ret = EBT_ENTRY_ITERATE(newinfo->entries, newinfo->entries_size,
3619 + ebt_check_entry_size_and_hooks, newinfo, repl->entries,
3620 + repl->entries + repl->entries_size, repl->hook_entry, &i, &j, &k,
3621 + &udc_cnt, repl->valid_hooks);
3627 + BUGPRINT("nentries does not equal the nr of entries in the "
3628 + "(last) chain\n");
3631 + if (k != newinfo->nentries) {
3632 + BUGPRINT("Total nentries is wrong\n");
3636 + // check if all valid hooks have a chain
3637 + for (i = 0; i < NF_BR_NUMHOOKS; i++) {
3638 + if (newinfo->hook_entry[i] == NULL &&
3639 + (repl->valid_hooks & (1 << i))) {
3640 + BUGPRINT("Valid hook without chain\n");
3645 + // Get the location of the udc, put them in an array
3646 + // While we're at it, allocate the chainstack
3648 + // this will get free'd in do_replace()/ebt_register_table()
3649 + // if an error occurs
3650 + newinfo->chainstack = (struct ebt_chainstack **)
3651 + vmalloc(smp_num_cpus * sizeof(struct ebt_chainstack));
3652 + if (!newinfo->chainstack)
3654 + for (i = 0; i < smp_num_cpus; i++) {
3655 + newinfo->chainstack[i] =
3656 + vmalloc(udc_cnt * sizeof(struct ebt_chainstack));
3657 + if (!newinfo->chainstack[i]) {
3659 + vfree(newinfo->chainstack[--i]);
3660 + vfree(newinfo->chainstack);
3661 + newinfo->chainstack = NULL;
3666 + cl_s = (struct ebt_cl_stack *)
3667 + vmalloc(udc_cnt * sizeof(struct ebt_cl_stack));
3670 + i = 0; // the i'th udc
3671 + EBT_ENTRY_ITERATE(newinfo->entries, newinfo->entries_size,
3672 + ebt_get_udc_positions, newinfo, repl->hook_entry, &i,
3673 + repl->valid_hooks, cl_s);
3675 + if (i != udc_cnt) {
3676 + BUGPRINT("i != udc_cnt\n");
3682 + // Check for loops
3683 + for (i = 0; i < NF_BR_NUMHOOKS; i++)
3684 + if (repl->valid_hooks & (1 << i))
3685 + if (check_chainloops(newinfo->hook_entry[i],
3686 + cl_s, udc_cnt, i, newinfo->entries)) {
3692 + // we now know the following (along with E=mc):
3693 + // - the nr of entries in each chain is right
3694 + // - the size of the allocated space is right
3695 + // - all valid hooks have a corresponding chain
3696 + // - there are no loops
3697 + // - wrong data can still be on the level of a single entry
3698 + // - could be there are jumps to places that are not the
3699 + // beginning of a chain. This can only occur in chains that
3700 + // are not accessible from any base chains, so we don't care.
3702 + // used to know what we need to clean up if something goes wrong
3704 + ret = EBT_ENTRY_ITERATE(newinfo->entries, newinfo->entries_size,
3705 + ebt_check_entry, newinfo, repl->name, &i, repl->valid_hooks,
3708 + EBT_ENTRY_ITERATE(newinfo->entries, newinfo->entries_size,
3709 + ebt_cleanup_entry, &i);
3716 +// called under write_lock
3717 +static void get_counters(struct ebt_counter *oldcounters,
3718 + struct ebt_counter *counters, unsigned int nentries)
3721 + struct ebt_counter *counter_base;
3723 + // counters of cpu 0
3724 + memcpy(counters, oldcounters,
3725 + sizeof(struct ebt_counter) * nentries);
3726 + // add other counters to those of cpu 0
3727 + for (cpu = 1; cpu < smp_num_cpus; cpu++) {
3728 + counter_base = COUNTER_BASE(oldcounters, nentries, cpu);
3729 + for (i = 0; i < nentries; i++) {
3730 + counters[i].pcnt += counter_base[i].pcnt;
3731 + counters[i].bcnt += counter_base[i].bcnt;
3736 +// replace the table
3737 +static int do_replace(void *user, unsigned int len)
3739 + int ret, i, countersize;
3740 + struct ebt_table_info *newinfo;
3741 + struct ebt_replace tmp;
3742 + struct ebt_table *t;
3743 + struct ebt_counter *counterstmp = NULL;
3744 + // used to be able to unlock earlier
3745 + struct ebt_table_info *table;
3747 + if (copy_from_user(&tmp, user, sizeof(tmp)) != 0)
3750 + if (len != sizeof(tmp) + tmp.entries_size) {
3751 + BUGPRINT("Wrong len argument\n");
3755 + if (tmp.entries_size == 0) {
3756 + BUGPRINT("Entries_size never zero\n");
3759 + countersize = COUNTER_OFFSET(tmp.nentries) * smp_num_cpus;
3760 + newinfo = (struct ebt_table_info *)
3761 + vmalloc(sizeof(struct ebt_table_info) + countersize);
3766 + memset(newinfo->counters, 0, countersize);
3768 + newinfo->entries = (char *)vmalloc(tmp.entries_size);
3769 + if (!newinfo->entries) {
3771 + goto free_newinfo;
3773 + if (copy_from_user(
3774 + newinfo->entries, tmp.entries, tmp.entries_size) != 0) {
3775 + BUGPRINT("Couldn't copy entries from userspace\n");
3777 + goto free_entries;
3780 + // the user wants counters back
3781 + // the check on the size is done later, when we have the lock
3782 + if (tmp.num_counters) {
3783 + counterstmp = (struct ebt_counter *)
3784 + vmalloc(tmp.num_counters * sizeof(struct ebt_counter));
3785 + if (!counterstmp) {
3787 + goto free_entries;
3791 + counterstmp = NULL;
3793 + // this can get initialized by translate_table()
3794 + newinfo->chainstack = NULL;
3795 + ret = translate_table(&tmp, newinfo);
3798 + goto free_counterstmp;
3800 + t = find_table_lock(tmp.name, &ret, &ebt_mutex);
3802 + goto free_iterate;
3804 + // the table doesn't like it
3805 + if (t->check && (ret = t->check(newinfo, tmp.valid_hooks)))
3808 + if (tmp.num_counters && tmp.num_counters != t->private->nentries) {
3809 + BUGPRINT("Wrong nr. of counters requested\n");
3814 + // we have the mutex lock, so no danger in reading this pointer
3815 + table = t->private;
3816 + // we need an atomic snapshot of the counters
3817 + write_lock_bh(&t->lock);
3818 + if (tmp.num_counters)
3819 + get_counters(t->private->counters, counterstmp,
3820 + t->private->nentries);
3822 + t->private = newinfo;
3823 + write_unlock_bh(&t->lock);
3825 + // So, a user can change the chains while having messed up her counter
3826 + // allocation. Only reason why this is done is because this way the lock
3827 + // is held only once, while this doesn't bring the kernel into a
3828 + // dangerous state.
3829 + if (tmp.num_counters &&
3830 + copy_to_user(tmp.counters, counterstmp,
3831 + tmp.num_counters * sizeof(struct ebt_counter))) {
3832 + BUGPRINT("Couldn't copy counters to userspace\n");
3838 + // decrease module count and free resources
3839 + EBT_ENTRY_ITERATE(table->entries, table->entries_size,
3840 + ebt_cleanup_entry, NULL);
3842 + vfree(table->entries);
3843 + if (table->chainstack) {
3844 + for (i = 0; i < smp_num_cpus; i++)
3845 + vfree(table->chainstack[i]);
3846 + vfree(table->chainstack);
3851 + vfree(counterstmp);
3857 + EBT_ENTRY_ITERATE(newinfo->entries, newinfo->entries_size,
3858 + ebt_cleanup_entry, NULL);
3861 + vfree(counterstmp);
3862 + // can be initialized in translate_table()
3863 + if (newinfo->chainstack) {
3864 + for (i = 0; i < smp_num_cpus; i++)
3865 + vfree(newinfo->chainstack[i]);
3866 + vfree(newinfo->chainstack);
3869 + if (newinfo->entries)
3870 + vfree(newinfo->entries);
3877 +int ebt_register_target(struct ebt_target *target)
3881 + ret = down_interruptible(&ebt_mutex);
3884 + if (!list_named_insert(&ebt_targets, target)) {
3889 + MOD_INC_USE_COUNT;
3894 +void ebt_unregister_target(struct ebt_target *target)
3897 + LIST_DELETE(&ebt_targets, target);
3899 + MOD_DEC_USE_COUNT;
3902 +int ebt_register_match(struct ebt_match *match)
3906 + ret = down_interruptible(&ebt_mutex);
3909 + if (!list_named_insert(&ebt_matches, match)) {
3914 + MOD_INC_USE_COUNT;
3919 +void ebt_unregister_match(struct ebt_match *match)
3922 + LIST_DELETE(&ebt_matches, match);
3924 + MOD_DEC_USE_COUNT;
3927 +int ebt_register_watcher(struct ebt_watcher *watcher)
3931 + ret = down_interruptible(&ebt_mutex);
3934 + if (!list_named_insert(&ebt_watchers, watcher)) {
3939 + MOD_INC_USE_COUNT;
3944 +void ebt_unregister_watcher(struct ebt_watcher *watcher)
3947 + LIST_DELETE(&ebt_watchers, watcher);
3949 + MOD_DEC_USE_COUNT;
3952 +int ebt_register_table(struct ebt_table *table)
3954 + struct ebt_table_info *newinfo;
3955 + int ret, i, countersize;
3957 + if (!table || !table->table ||!table->table->entries ||
3958 + table->table->entries_size == 0 ||
3959 + table->table->counters || table->private) {
3960 + BUGPRINT("Bad table data for ebt_register_table!!!\n");
3964 + countersize = COUNTER_OFFSET(table->table->nentries) * smp_num_cpus;
3965 + newinfo = (struct ebt_table_info *)
3966 + vmalloc(sizeof(struct ebt_table_info) + countersize);
3971 + newinfo->entries = (char *)vmalloc(table->table->entries_size);
3972 + if (!(newinfo->entries))
3973 + goto free_newinfo;
3975 + memcpy(newinfo->entries, table->table->entries,
3976 + table->table->entries_size);
3979 + memset(newinfo->counters, 0, countersize);
3981 + // fill in newinfo and parse the entries
3982 + newinfo->chainstack = NULL;
3983 + ret = translate_table(table->table, newinfo);
3985 + BUGPRINT("Translate_table failed\n");
3986 + goto free_chainstack;
3989 + if (table->check && table->check(newinfo, table->valid_hooks)) {
3990 + BUGPRINT("The table doesn't like its own initial data, lol\n");
3994 + table->private = newinfo;
3995 + table->lock = RW_LOCK_UNLOCKED;
3996 + ret = down_interruptible(&ebt_mutex);
3998 + goto free_chainstack;
4000 + if (list_named_find(&ebt_tables, table->name)) {
4002 + BUGPRINT("Table name already exists\n");
4006 + list_prepend(&ebt_tables, table);
4008 + MOD_INC_USE_COUNT;
4013 + if (newinfo->chainstack) {
4014 + for (i = 0; i < smp_num_cpus; i++)
4015 + vfree(newinfo->chainstack[i]);
4016 + vfree(newinfo->chainstack);
4018 + vfree(newinfo->entries);
4024 +void ebt_unregister_table(struct ebt_table *table)
4029 + BUGPRINT("Request to unregister NULL table!!!\n");
4033 + LIST_DELETE(&ebt_tables, table);
4035 + EBT_ENTRY_ITERATE(table->private->entries,
4036 + table->private->entries_size, ebt_cleanup_entry, NULL);
4037 + if (table->private->entries)
4038 + vfree(table->private->entries);
4039 + if (table->private->chainstack) {
4040 + for (i = 0; i < smp_num_cpus; i++)
4041 + vfree(table->private->chainstack[i]);
4042 + vfree(table->private->chainstack);
4044 + vfree(table->private);
4045 + MOD_DEC_USE_COUNT;
4048 +// userspace just supplied us with counters
4049 +static int update_counters(void *user, unsigned int len)
4052 + struct ebt_counter *tmp;
4053 + struct ebt_replace hlp;
4054 + struct ebt_table *t;
4056 + if (copy_from_user(&hlp, user, sizeof(hlp)))
4059 + if (len != sizeof(hlp) + hlp.num_counters * sizeof(struct ebt_counter))
4061 + if (hlp.num_counters == 0)
4064 + if ( !(tmp = (struct ebt_counter *)
4065 + vmalloc(hlp.num_counters * sizeof(struct ebt_counter))) ){
4066 + MEMPRINT("Update_counters && nomemory\n");
4070 + t = find_table_lock(hlp.name, &ret, &ebt_mutex);
4074 + if (hlp.num_counters != t->private->nentries) {
4075 + BUGPRINT("Wrong nr of counters\n");
4077 + goto unlock_mutex;
4080 + if ( copy_from_user(tmp, hlp.counters,
4081 + hlp.num_counters * sizeof(struct ebt_counter)) ) {
4082 + BUGPRINT("Updata_counters && !cfu\n");
4084 + goto unlock_mutex;
4087 + // we want an atomic add of the counters
4088 + write_lock_bh(&t->lock);
4090 + // we add to the counters of the first cpu
4091 + for (i = 0; i < hlp.num_counters; i++) {
4092 + t->private->counters[i].pcnt += tmp[i].pcnt;
4093 + t->private->counters[i].bcnt += tmp[i].bcnt;
4096 + write_unlock_bh(&t->lock);
4105 +static inline int ebt_make_matchname(struct ebt_entry_match *m,
4106 + char *base, char *ubase)
4108 + char *hlp = ubase - base + (char *)m;
4109 + if (copy_to_user(hlp, m->u.match->name, EBT_FUNCTION_MAXNAMELEN))
4114 +static inline int ebt_make_watchername(struct ebt_entry_watcher *w,
4115 + char *base, char *ubase)
4117 + char *hlp = ubase - base + (char *)w;
4118 + if (copy_to_user(hlp , w->u.watcher->name, EBT_FUNCTION_MAXNAMELEN))
4123 +static inline int ebt_make_names(struct ebt_entry *e, char *base, char *ubase)
4127 + struct ebt_entry_target *t;
4129 + if ((e->bitmask & EBT_ENTRY_OR_ENTRIES) == 0)
4132 + hlp = ubase - base + (char *)e + e->target_offset;
4133 + t = (struct ebt_entry_target *)(((char *)e) + e->target_offset);
4135 + ret = EBT_MATCH_ITERATE(e, ebt_make_matchname, base, ubase);
4138 + ret = EBT_WATCHER_ITERATE(e, ebt_make_watchername, base, ubase);
4141 + if (copy_to_user(hlp, t->u.target->name, EBT_FUNCTION_MAXNAMELEN))
4146 +// called with ebt_mutex down
4147 +static int copy_everything_to_user(struct ebt_table *t, void *user,
4148 + int *len, int cmd)
4150 + struct ebt_replace tmp;
4151 + struct ebt_counter *counterstmp, *oldcounters;
4152 + unsigned int entries_size, nentries;
4155 + if (cmd == EBT_SO_GET_ENTRIES) {
4156 + entries_size = t->private->entries_size;
4157 + nentries = t->private->nentries;
4158 + entries = t->private->entries;
4159 + oldcounters = t->private->counters;
4161 + entries_size = t->table->entries_size;
4162 + nentries = t->table->nentries;
4163 + entries = t->table->entries;
4164 + oldcounters = t->table->counters;
4167 + if (copy_from_user(&tmp, user, sizeof(tmp))) {
4168 + BUGPRINT("Cfu didn't work\n");
4172 + if (*len != sizeof(struct ebt_replace) + entries_size +
4173 + (tmp.num_counters? nentries * sizeof(struct ebt_counter): 0)) {
4174 + BUGPRINT("Wrong size\n");
4178 + if (tmp.nentries != nentries) {
4179 + BUGPRINT("Nentries wrong\n");
4183 + if (tmp.entries_size != entries_size) {
4184 + BUGPRINT("Wrong size\n");
4188 + // userspace might not need the counters
4189 + if (tmp.num_counters) {
4190 + if (tmp.num_counters != nentries) {
4191 + BUGPRINT("Num_counters wrong\n");
4194 + counterstmp = (struct ebt_counter *)
4195 + vmalloc(nentries * sizeof(struct ebt_counter));
4196 + if (!counterstmp) {
4197 + MEMPRINT("Couldn't copy counters, out of memory\n");
4200 + write_lock_bh(&t->lock);
4201 + get_counters(oldcounters, counterstmp, nentries);
4202 + write_unlock_bh(&t->lock);
4204 + if (copy_to_user(tmp.counters, counterstmp,
4205 + nentries * sizeof(struct ebt_counter))) {
4206 + BUGPRINT("Couldn't copy counters to userspace\n");
4207 + vfree(counterstmp);
4210 + vfree(counterstmp);
4213 + if (copy_to_user(tmp.entries, entries, entries_size)) {
4214 + BUGPRINT("Couldn't copy entries to userspace\n");
4217 + // set the match/watcher/target names right
4218 + return EBT_ENTRY_ITERATE(entries, entries_size,
4219 + ebt_make_names, entries, tmp.entries);
4222 +static int do_ebt_set_ctl(struct sock *sk,
4223 + int cmd, void *user, unsigned int len)
4228 + case EBT_SO_SET_ENTRIES:
4229 + ret = do_replace(user, len);
4231 + case EBT_SO_SET_COUNTERS:
4232 + ret = update_counters(user, len);
4240 +static int do_ebt_get_ctl(struct sock *sk, int cmd, void *user, int *len)
4243 + struct ebt_replace tmp;
4244 + struct ebt_table *t;
4246 + if (copy_from_user(&tmp, user, sizeof(tmp)))
4249 + t = find_table_lock(tmp.name, &ret, &ebt_mutex);
4254 + case EBT_SO_GET_INFO:
4255 + case EBT_SO_GET_INIT_INFO:
4256 + if (*len != sizeof(struct ebt_replace)){
4261 + if (cmd == EBT_SO_GET_INFO) {
4262 + tmp.nentries = t->private->nentries;
4263 + tmp.entries_size = t->private->entries_size;
4264 + tmp.valid_hooks = t->valid_hooks;
4266 + tmp.nentries = t->table->nentries;
4267 + tmp.entries_size = t->table->entries_size;
4268 + tmp.valid_hooks = t->table->valid_hooks;
4271 + if (copy_to_user(user, &tmp, *len) != 0){
4272 + BUGPRINT("c2u Didn't work\n");
4279 + case EBT_SO_GET_ENTRIES:
4280 + case EBT_SO_GET_INIT_ENTRIES:
4281 + ret = copy_everything_to_user(t, user, len, cmd);
4293 +static struct nf_sockopt_ops ebt_sockopts =
4294 +{ { NULL, NULL }, PF_INET, EBT_BASE_CTL, EBT_SO_SET_MAX + 1, do_ebt_set_ctl,
4295 + EBT_BASE_CTL, EBT_SO_GET_MAX + 1, do_ebt_get_ctl, 0, NULL
4298 +static int __init init(void)
4303 + list_named_insert(&ebt_targets, &ebt_standard_target);
4305 + if ((ret = nf_register_sockopt(&ebt_sockopts)) < 0)
4308 + printk(KERN_NOTICE "Ebtables v2.0 registered\n");
4312 +static void __exit fini(void)
4314 + nf_unregister_sockopt(&ebt_sockopts);
4315 + printk(KERN_NOTICE "Ebtables v2.0 unregistered\n");
4318 +EXPORT_SYMBOL(ebt_register_table);
4319 +EXPORT_SYMBOL(ebt_unregister_table);
4320 +EXPORT_SYMBOL(ebt_register_match);
4321 +EXPORT_SYMBOL(ebt_unregister_match);
4322 +EXPORT_SYMBOL(ebt_register_watcher);
4323 +EXPORT_SYMBOL(ebt_unregister_watcher);
4324 +EXPORT_SYMBOL(ebt_register_target);
4325 +EXPORT_SYMBOL(ebt_unregister_target);
4326 +EXPORT_SYMBOL(ebt_do_table);
4329 +MODULE_LICENSE("GPL");
4330 --- /dev/null 2005-03-14 20:10:29.001600248 +0100
4331 +++ linux-2.4.29-ebt-brnf/include/linux/netfilter_bridge/ebtables.h 2005-03-14 21:24:12.000000000 +0100
4337 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
4339 + * ebtables.c,v 2.0, September, 2002
4341 + * This code is stongly inspired on the iptables code which is
4342 + * Copyright (C) 1999 Paul `Rusty' Russell & Michael J. Neuling
4345 +#ifndef __LINUX_BRIDGE_EFF_H
4346 +#define __LINUX_BRIDGE_EFF_H
4347 +#include <linux/if.h>
4348 +#include <linux/netfilter_bridge.h>
4349 +#include <linux/if_ether.h>
4351 +#define EBT_TABLE_MAXNAMELEN 32
4352 +#define EBT_CHAIN_MAXNAMELEN EBT_TABLE_MAXNAMELEN
4353 +#define EBT_FUNCTION_MAXNAMELEN EBT_TABLE_MAXNAMELEN
4355 +// verdicts >0 are "branches"
4356 +#define EBT_ACCEPT -1
4357 +#define EBT_DROP -2
4358 +#define EBT_CONTINUE -3
4359 +#define EBT_RETURN -4
4360 +#define NUM_STANDARD_TARGETS 4
4368 +struct ebt_entries {
4369 + // this field is always set to zero
4370 + // See EBT_ENTRY_OR_ENTRIES.
4371 + // Must be same size as ebt_entry.bitmask
4372 + unsigned int distinguisher;
4374 + char name[EBT_CHAIN_MAXNAMELEN];
4375 + // counter offset for this chain
4376 + unsigned int counter_offset;
4377 + // one standard (accept, drop, return) per hook
4380 + unsigned int nentries;
4385 +// used for the bitmask of struct ebt_entry
4387 +// This is a hack to make a difference between an ebt_entry struct and an
4388 +// ebt_entries struct when traversing the entries from start to end.
4389 +// Using this simplifies the code alot, while still being able to use
4391 +// Contrary, iptables doesn't use something like ebt_entries and therefore uses
4392 +// different techniques for naming the policy and such. So, iptables doesn't
4393 +// need a hack like this.
4394 +#define EBT_ENTRY_OR_ENTRIES 0x01
4395 +// these are the normal masks
4396 +#define EBT_NOPROTO 0x02
4397 +#define EBT_802_3 0x04
4398 +#define EBT_SOURCEMAC 0x08
4399 +#define EBT_DESTMAC 0x10
4400 +#define EBT_F_MASK (EBT_NOPROTO | EBT_802_3 | EBT_SOURCEMAC | EBT_DESTMAC \
4401 + | EBT_ENTRY_OR_ENTRIES)
4403 +#define EBT_IPROTO 0x01
4404 +#define EBT_IIN 0x02
4405 +#define EBT_IOUT 0x04
4406 +#define EBT_ISOURCE 0x8
4407 +#define EBT_IDEST 0x10
4408 +#define EBT_ILOGICALIN 0x20
4409 +#define EBT_ILOGICALOUT 0x40
4410 +#define EBT_INV_MASK (EBT_IPROTO | EBT_IIN | EBT_IOUT | EBT_ILOGICALIN \
4411 + | EBT_ILOGICALOUT | EBT_ISOURCE | EBT_IDEST)
4413 +struct ebt_entry_match
4416 + char name[EBT_FUNCTION_MAXNAMELEN];
4417 + struct ebt_match *match;
4420 + unsigned int match_size;
4421 + unsigned char data[0];
4424 +struct ebt_entry_watcher
4427 + char name[EBT_FUNCTION_MAXNAMELEN];
4428 + struct ebt_watcher *watcher;
4431 + unsigned int watcher_size;
4432 + unsigned char data[0];
4435 +struct ebt_entry_target
4438 + char name[EBT_FUNCTION_MAXNAMELEN];
4439 + struct ebt_target *target;
4442 + unsigned int target_size;
4443 + unsigned char data[0];
4446 +#define EBT_STANDARD_TARGET "standard"
4447 +struct ebt_standard_target
4449 + struct ebt_entry_target target;
4455 + // this needs to be the first field
4456 + unsigned int bitmask;
4457 + unsigned int invflags;
4458 + uint16_t ethproto;
4459 + // the physical in-dev
4460 + char in[IFNAMSIZ];
4461 + // the logical in-dev
4462 + char logical_in[IFNAMSIZ];
4463 + // the physical out-dev
4464 + char out[IFNAMSIZ];
4465 + // the logical out-dev
4466 + char logical_out[IFNAMSIZ];
4467 + unsigned char sourcemac[ETH_ALEN];
4468 + unsigned char sourcemsk[ETH_ALEN];
4469 + unsigned char destmac[ETH_ALEN];
4470 + unsigned char destmsk[ETH_ALEN];
4471 + // sizeof ebt_entry + matches
4472 + unsigned int watchers_offset;
4473 + // sizeof ebt_entry + matches + watchers
4474 + unsigned int target_offset;
4475 + // sizeof ebt_entry + matches + watchers + target
4476 + unsigned int next_offset;
4477 + unsigned char elems[0];
4482 + char name[EBT_TABLE_MAXNAMELEN];
4483 + unsigned int valid_hooks;
4484 + // nr of rules in the table
4485 + unsigned int nentries;
4486 + // total size of the entries
4487 + unsigned int entries_size;
4488 + // start of the chains
4489 + struct ebt_entries *hook_entry[NF_BR_NUMHOOKS];
4490 + // nr of counters userspace expects back
4491 + unsigned int num_counters;
4492 + // where the kernel will put the old counters
4493 + struct ebt_counter *counters;
4497 +// [gs]etsockopt numbers
4498 +#define EBT_BASE_CTL 128
4500 +#define EBT_SO_SET_ENTRIES (EBT_BASE_CTL)
4501 +#define EBT_SO_SET_COUNTERS (EBT_SO_SET_ENTRIES+1)
4502 +#define EBT_SO_SET_MAX (EBT_SO_SET_COUNTERS+1)
4504 +#define EBT_SO_GET_INFO (EBT_BASE_CTL)
4505 +#define EBT_SO_GET_ENTRIES (EBT_SO_GET_INFO+1)
4506 +#define EBT_SO_GET_INIT_INFO (EBT_SO_GET_ENTRIES+1)
4507 +#define EBT_SO_GET_INIT_ENTRIES (EBT_SO_GET_INIT_INFO+1)
4508 +#define EBT_SO_GET_MAX (EBT_SO_GET_INIT_ENTRIES+1)
4512 +// return values for match() functions
4513 +#define EBT_MATCH 0
4514 +#define EBT_NOMATCH 1
4518 + struct list_head list;
4519 + const char name[EBT_FUNCTION_MAXNAMELEN];
4520 + // 0 == it matches
4521 + int (*match)(const struct sk_buff *skb, const struct net_device *in,
4522 + const struct net_device *out, const void *matchdata,
4523 + unsigned int datalen);
4525 + int (*check)(const char *tablename, unsigned int hookmask,
4526 + const struct ebt_entry *e, void *matchdata, unsigned int datalen);
4527 + void (*destroy)(void *matchdata, unsigned int datalen);
4528 + struct module *me;
4533 + struct list_head list;
4534 + const char name[EBT_FUNCTION_MAXNAMELEN];
4535 + void (*watcher)(const struct sk_buff *skb, unsigned int hooknr,
4536 + const struct net_device *in, const struct net_device *out,
4537 + const void *watcherdata, unsigned int datalen);
4539 + int (*check)(const char *tablename, unsigned int hookmask,
4540 + const struct ebt_entry *e, void *watcherdata, unsigned int datalen);
4541 + void (*destroy)(void *watcherdata, unsigned int datalen);
4542 + struct module *me;
4547 + struct list_head list;
4548 + const char name[EBT_FUNCTION_MAXNAMELEN];
4549 + // returns one of the standard verdicts
4550 + int (*target)(struct sk_buff **pskb, unsigned int hooknr,
4551 + const struct net_device *in, const struct net_device *out,
4552 + const void *targetdata, unsigned int datalen);
4554 + int (*check)(const char *tablename, unsigned int hookmask,
4555 + const struct ebt_entry *e, void *targetdata, unsigned int datalen);
4556 + void (*destroy)(void *targetdata, unsigned int datalen);
4557 + struct module *me;
4560 +// used for jumping from and into user defined chains (udc)
4561 +struct ebt_chainstack
4563 + struct ebt_entries *chaininfo; // pointer to chain data
4564 + struct ebt_entry *e; // pointer to entry data
4565 + unsigned int n; // n'th entry
4568 +struct ebt_table_info
4570 + // total size of the entries
4571 + unsigned int entries_size;
4572 + unsigned int nentries;
4573 + // pointers to the start of the chains
4574 + struct ebt_entries *hook_entry[NF_BR_NUMHOOKS];
4575 + // room to maintain the stack used for jumping from and into udc
4576 + struct ebt_chainstack **chainstack;
4578 + struct ebt_counter counters[0] ____cacheline_aligned;
4583 + struct list_head list;
4584 + char name[EBT_TABLE_MAXNAMELEN];
4585 + struct ebt_replace *table;
4586 + unsigned int valid_hooks;
4588 + // e.g. could be the table explicitly only allows certain
4589 + // matches, targets, ... 0 == let it in
4590 + int (*check)(const struct ebt_table_info *info,
4591 + unsigned int valid_hooks);
4592 + // the data used by the kernel
4593 + struct ebt_table_info *private;
4596 +#define EBT_ALIGN(s) (((s) + (__alignof__(struct ebt_entry_target)-1)) & \
4597 + ~(__alignof__(struct ebt_entry_target)-1))
4598 +extern int ebt_register_table(struct ebt_table *table);
4599 +extern void ebt_unregister_table(struct ebt_table *table);
4600 +extern int ebt_register_match(struct ebt_match *match);
4601 +extern void ebt_unregister_match(struct ebt_match *match);
4602 +extern int ebt_register_watcher(struct ebt_watcher *watcher);
4603 +extern void ebt_unregister_watcher(struct ebt_watcher *watcher);
4604 +extern int ebt_register_target(struct ebt_target *target);
4605 +extern void ebt_unregister_target(struct ebt_target *target);
4606 +extern unsigned int ebt_do_table(unsigned int hook, struct sk_buff **pskb,
4607 + const struct net_device *in, const struct net_device *out,
4608 + struct ebt_table *table);
4610 + // Used in the kernel match() functions
4611 +#define FWINV(bool,invflg) ((bool) ^ !!(info->invflags & invflg))
4612 +// True if the hook mask denotes that the rule is in a base chain,
4613 +// used in the check() functions
4614 +#define BASE_CHAIN (hookmask & (1 << NF_BR_NUMHOOKS))
4615 +// Clear the bit in the hook mask that tells if the rule is on a base chain
4616 +#define CLEAR_BASE_CHAIN_BIT (hookmask &= ~(1 << NF_BR_NUMHOOKS))
4617 +// True if the target is not a standard target
4618 +#define INVALID_TARGET (info->target < -NUM_STANDARD_TARGETS || info->target >= 0)
4620 +#endif /* __KERNEL__ */
4622 +// blatently stolen from ip_tables.h
4623 +// fn returns 0 to continue iteration
4624 +#define EBT_MATCH_ITERATE(e, fn, args...) \
4626 + unsigned int __i; \
4628 + struct ebt_entry_match *__match; \
4630 + for (__i = sizeof(struct ebt_entry); \
4631 + __i < (e)->watchers_offset; \
4632 + __i += __match->match_size + \
4633 + sizeof(struct ebt_entry_match)) { \
4634 + __match = (void *)(e) + __i; \
4636 + __ret = fn(__match , ## args); \
4640 + if (__ret == 0) { \
4641 + if (__i != (e)->watchers_offset) \
4642 + __ret = -EINVAL; \
4647 +#define EBT_WATCHER_ITERATE(e, fn, args...) \
4649 + unsigned int __i; \
4651 + struct ebt_entry_watcher *__watcher; \
4653 + for (__i = e->watchers_offset; \
4654 + __i < (e)->target_offset; \
4655 + __i += __watcher->watcher_size + \
4656 + sizeof(struct ebt_entry_watcher)) { \
4657 + __watcher = (void *)(e) + __i; \
4659 + __ret = fn(__watcher , ## args); \
4663 + if (__ret == 0) { \
4664 + if (__i != (e)->target_offset) \
4665 + __ret = -EINVAL; \
4670 +#define EBT_ENTRY_ITERATE(entries, size, fn, args...) \
4672 + unsigned int __i; \
4674 + struct ebt_entry *__entry; \
4676 + for (__i = 0; __i < (size);) { \
4677 + __entry = (void *)(entries) + __i; \
4678 + __ret = fn(__entry , ## args); \
4681 + if (__entry->bitmask != 0) \
4682 + __i += __entry->next_offset; \
4684 + __i += sizeof(struct ebt_entries); \
4686 + if (__ret == 0) { \
4687 + if (__i != (size)) \
4688 + __ret = -EINVAL; \
4694 --- /dev/null 2005-03-14 20:10:29.001600248 +0100
4695 +++ linux-2.4.29-ebt-brnf/include/linux/netfilter_bridge/ebt_among.h 2005-03-14 00:00:30.000000000 +0100
4697 +#ifndef __LINUX_BRIDGE_EBT_AMONG_H
4698 +#define __LINUX_BRIDGE_EBT_AMONG_H
4700 +#define EBT_AMONG_DST 0x01
4701 +#define EBT_AMONG_SRC 0x02
4703 +/* Grzegorz Borowiak <grzes@gnu.univ.gda.pl> 2003
4705 + * Write-once-read-many hash table, used for checking if a given
4706 + * MAC address belongs to a set or not and possibly for checking
4707 + * if it is related with a given IPv4 address.
4709 + * The hash value of an address is its last byte.
4711 + * In real-world ethernet addresses, values of the last byte are
4712 + * evenly distributed and there is no need to consider other bytes.
4713 + * It would only slow the routines down.
4715 + * For MAC address comparison speedup reasons, we introduce a trick.
4716 + * MAC address is mapped onto an array of two 32-bit integers.
4717 + * This pair of integers is compared with MAC addresses in the
4718 + * hash table, which are stored also in form of pairs of integers
4719 + * (in `cmp' array). This is quick as it requires only two elementary
4720 + * number comparisons in worst case. Further, we take advantage of
4721 + * fact that entropy of 3 last bytes of address is larger than entropy
4722 + * of 3 first bytes. So first we compare 4 last bytes of addresses and
4723 + * if they are the same we compare 2 first.
4725 + * Yes, it is a memory overhead, but in 2003 AD, who cares?
4728 +struct ebt_mac_wormhash_tuple
4734 +struct ebt_mac_wormhash
4738 + struct ebt_mac_wormhash_tuple pool[0];
4741 +#define ebt_mac_wormhash_size(x) ((x) ? sizeof(struct ebt_mac_wormhash) \
4742 + + (x)->poolsize * sizeof(struct ebt_mac_wormhash_tuple) : 0)
4744 +struct ebt_among_info
4751 +#define EBT_AMONG_DST_NEG 0x1
4752 +#define EBT_AMONG_SRC_NEG 0x2
4754 +#define ebt_among_wh_dst(x) ((x)->wh_dst_ofs ? \
4755 + (struct ebt_mac_wormhash*)((char*)(x) + (x)->wh_dst_ofs) : NULL)
4756 +#define ebt_among_wh_src(x) ((x)->wh_src_ofs ? \
4757 + (struct ebt_mac_wormhash*)((char*)(x) + (x)->wh_src_ofs) : NULL)
4759 +#define EBT_AMONG_MATCH "among"
4762 --- /dev/null 2005-03-14 20:10:29.001600248 +0100
4763 +++ linux-2.4.29-ebt-brnf/include/linux/netfilter_bridge/ebt_limit.h 2005-03-14 00:00:30.000000000 +0100
4765 +#ifndef __LINUX_BRIDGE_EBT_LIMIT_H
4766 +#define __LINUX_BRIDGE_EBT_LIMIT_H
4768 +#define EBT_LIMIT_MATCH "limit"
4770 +/* timings are in milliseconds. */
4771 +#define EBT_LIMIT_SCALE 10000
4773 +/* 1/10,000 sec period => max of 10,000/sec. Min rate is then 429490
4774 + seconds, or one every 59 hours. */
4776 +struct ebt_limit_info
4778 + u_int32_t avg; /* Average secs between packets * scale */
4779 + u_int32_t burst; /* Period multiplier for upper limit. */
4781 + /* Used internally by the kernel */
4782 + unsigned long prev;
4784 + u_int32_t credit_cap, cost;
4788 --- /dev/null 2005-03-14 20:10:29.001600248 +0100
4789 +++ linux-2.4.29-ebt-brnf/include/linux/netfilter_bridge/ebt_arpreply.h 2005-03-14 00:00:30.000000000 +0100
4791 +#ifndef __LINUX_BRIDGE_EBT_ARPREPLY_H
4792 +#define __LINUX_BRIDGE_EBT_ARPREPLY_H
4794 +struct ebt_arpreply_info
4796 + unsigned char mac[ETH_ALEN];
4799 +#define EBT_ARPREPLY_TARGET "arpreply"
4802 --- /dev/null 2005-03-14 20:10:29.001600248 +0100
4803 +++ linux-2.4.29-ebt-brnf/include/linux/netfilter_bridge/ebt_802_3.h 2005-03-14 00:00:30.000000000 +0100
4805 +#ifndef __LINUX_BRIDGE_EBT_802_3_H
4806 +#define __LINUX_BRIDGE_EBT_802_3_H
4808 +#define EBT_802_3_SAP 0x01
4809 +#define EBT_802_3_TYPE 0x02
4811 +#define EBT_802_3_MATCH "802_3"
4814 + * If frame has DSAP/SSAP value 0xaa you must check the SNAP type
4815 + * to discover what kind of packet we're carrying.
4817 +#define CHECK_TYPE 0xaa
4820 + * Control field may be one or two bytes. If the first byte has
4821 + * the value 0x03 then the entire length is one byte, otherwise it is two.
4822 + * One byte controls are used in Unnumbered Information frames.
4823 + * Two byte controls are used in Numbered Information frames.
4827 +#define EBT_802_3_MASK (EBT_802_3_SAP | EBT_802_3_TYPE | EBT_802_3)
4829 +/* ui has one byte ctrl, ni has two */
4846 +struct ebt_802_3_hdr {
4856 +struct ebt_802_3_info
4865 --- /dev/null 2005-03-14 20:10:29.001600248 +0100
4866 +++ linux-2.4.29-ebt-brnf/include/linux/netfilter_bridge/ebt_arp.h 2005-03-14 00:00:30.000000000 +0100
4868 +#ifndef __LINUX_BRIDGE_EBT_ARP_H
4869 +#define __LINUX_BRIDGE_EBT_ARP_H
4871 +#define EBT_ARP_OPCODE 0x01
4872 +#define EBT_ARP_HTYPE 0x02
4873 +#define EBT_ARP_PTYPE 0x04
4874 +#define EBT_ARP_SRC_IP 0x08
4875 +#define EBT_ARP_DST_IP 0x10
4876 +#define EBT_ARP_SRC_MAC 0x20
4877 +#define EBT_ARP_DST_MAC 0x40
4878 +#define EBT_ARP_MASK (EBT_ARP_OPCODE | EBT_ARP_HTYPE | EBT_ARP_PTYPE | \
4879 + EBT_ARP_SRC_IP | EBT_ARP_DST_IP | EBT_ARP_SRC_MAC | EBT_ARP_DST_MAC)
4880 +#define EBT_ARP_MATCH "arp"
4882 +struct ebt_arp_info
4891 + unsigned char smaddr[ETH_ALEN];
4892 + unsigned char smmsk[ETH_ALEN];
4893 + unsigned char dmaddr[ETH_ALEN];
4894 + unsigned char dmmsk[ETH_ALEN];
4900 --- /dev/null 2005-03-14 20:10:29.001600248 +0100
4901 +++ linux-2.4.29-ebt-brnf/include/linux/netfilter_bridge/ebt_ip.h 2005-03-14 00:00:30.000000000 +0100
4907 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
4912 + * added ip-sport and ip-dport
4913 + * Innominate Security Technologies AG <mhopf@innominate.com>
4917 +#ifndef __LINUX_BRIDGE_EBT_IP_H
4918 +#define __LINUX_BRIDGE_EBT_IP_H
4920 +#define EBT_IP_SOURCE 0x01
4921 +#define EBT_IP_DEST 0x02
4922 +#define EBT_IP_TOS 0x04
4923 +#define EBT_IP_PROTO 0x08
4924 +#define EBT_IP_SPORT 0x10
4925 +#define EBT_IP_DPORT 0x20
4926 +#define EBT_IP_MASK (EBT_IP_SOURCE | EBT_IP_DEST | EBT_IP_TOS | EBT_IP_PROTO |\
4927 + EBT_IP_SPORT | EBT_IP_DPORT )
4928 +#define EBT_IP_MATCH "ip"
4930 +// the same values are used for the invflags
4941 + uint16_t sport[2];
4942 + uint16_t dport[2];
4946 --- /dev/null 2005-03-14 20:10:29.001600248 +0100
4947 +++ linux-2.4.29-ebt-brnf/include/linux/netfilter_bridge/ebt_pkttype.h 2005-03-14 00:00:30.000000000 +0100
4949 +#ifndef __LINUX_BRIDGE_EBT_PKTTYPE_H
4950 +#define __LINUX_BRIDGE_EBT_PKTTYPE_H
4952 +struct ebt_pkttype_info
4957 +#define EBT_PKTTYPE_MATCH "pkttype"
4960 --- /dev/null 2005-03-14 20:10:29.001600248 +0100
4961 +++ linux-2.4.29-ebt-brnf/include/linux/netfilter_bridge/ebt_stp.h 2005-03-14 00:00:30.000000000 +0100
4963 +#ifndef __LINUX_BRIDGE_EBT_STP_H
4964 +#define __LINUX_BRIDGE_EBT_STP_H
4966 +#define EBT_STP_TYPE 0x0001
4968 +#define EBT_STP_FLAGS 0x0002
4969 +#define EBT_STP_ROOTPRIO 0x0004
4970 +#define EBT_STP_ROOTADDR 0x0008
4971 +#define EBT_STP_ROOTCOST 0x0010
4972 +#define EBT_STP_SENDERPRIO 0x0020
4973 +#define EBT_STP_SENDERADDR 0x0040
4974 +#define EBT_STP_PORT 0x0080
4975 +#define EBT_STP_MSGAGE 0x0100
4976 +#define EBT_STP_MAXAGE 0x0200
4977 +#define EBT_STP_HELLOTIME 0x0400
4978 +#define EBT_STP_FWDD 0x0800
4980 +#define EBT_STP_MASK 0x0fff
4981 +#define EBT_STP_CONFIG_MASK 0x0ffe
4983 +#define EBT_STP_MATCH "stp"
4985 +struct ebt_stp_config_info
4988 + uint16_t root_priol, root_priou;
4989 + char root_addr[6], root_addrmsk[6];
4990 + uint32_t root_costl, root_costu;
4991 + uint16_t sender_priol, sender_priou;
4992 + char sender_addr[6], sender_addrmsk[6];
4993 + uint16_t portl, portu;
4994 + uint16_t msg_agel, msg_ageu;
4995 + uint16_t max_agel, max_ageu;
4996 + uint16_t hello_timel, hello_timeu;
4997 + uint16_t forward_delayl, forward_delayu;
5000 +struct ebt_stp_info
5003 + struct ebt_stp_config_info config;
5005 + uint16_t invflags;
5009 --- /dev/null 2005-03-14 20:10:29.001600248 +0100
5010 +++ linux-2.4.29-ebt-brnf/include/linux/netfilter_bridge/ebt_vlan.h 2005-03-14 00:00:30.000000000 +0100
5012 +#ifndef __LINUX_BRIDGE_EBT_VLAN_H
5013 +#define __LINUX_BRIDGE_EBT_VLAN_H
5015 +#define EBT_VLAN_ID 0x01
5016 +#define EBT_VLAN_PRIO 0x02
5017 +#define EBT_VLAN_ENCAP 0x04
5018 +#define EBT_VLAN_MASK (EBT_VLAN_ID | EBT_VLAN_PRIO | EBT_VLAN_ENCAP)
5019 +#define EBT_VLAN_MATCH "vlan"
5021 +struct ebt_vlan_info {
5022 + uint16_t id; /* VLAN ID {1-4095} */
5023 + uint8_t prio; /* VLAN User Priority {0-7} */
5024 + uint16_t encap; /* VLAN Encapsulated frame code {0-65535} */
5025 + uint8_t bitmask; /* Args bitmask bit 1=1 - ID arg,
5026 + bit 2=1 User-Priority arg, bit 3=1 encap*/
5027 + uint8_t invflags; /* Inverse bitmask bit 1=1 - inversed ID arg,
5028 + bit 2=1 - inversed Pirority arg */
5032 --- /dev/null 2005-03-14 20:10:29.001600248 +0100
5033 +++ linux-2.4.29-ebt-brnf/include/linux/netfilter_bridge/ebt_log.h 2005-03-14 00:00:30.000000000 +0100
5035 +#ifndef __LINUX_BRIDGE_EBT_LOG_H
5036 +#define __LINUX_BRIDGE_EBT_LOG_H
5038 +#define EBT_LOG_IP 0x01 // if the frame is made by ip, log the ip information
5039 +#define EBT_LOG_ARP 0x02
5040 +#define EBT_LOG_MASK (EBT_LOG_IP | EBT_LOG_ARP)
5041 +#define EBT_LOG_PREFIX_SIZE 30
5042 +#define EBT_LOG_WATCHER "log"
5044 +struct ebt_log_info
5047 + uint8_t prefix[EBT_LOG_PREFIX_SIZE];
5052 --- /dev/null 2005-03-14 20:10:29.001600248 +0100
5053 +++ linux-2.4.29-ebt-brnf/include/linux/netfilter_bridge/ebt_ulog.h 2005-03-14 00:00:30.000000000 +0100
5055 +#ifndef _EBT_ULOG_H
5056 +#define _EBT_ULOG_H
5058 +#define EBT_ULOG_DEFAULT_NLGROUP 0
5059 +#define EBT_ULOG_DEFAULT_QTHRESHOLD 1
5060 +#define EBT_ULOG_MAXNLGROUPS 32 /* hardcoded netlink max */
5061 +#define EBT_ULOG_PREFIX_LEN 32
5062 +#define EBT_ULOG_MAX_QLEN 50
5063 +#define EBT_ULOG_WATCHER "ulog"
5065 +struct ebt_ulog_info {
5067 + unsigned int cprange;
5068 + unsigned int qthreshold;
5069 + char prefix[EBT_ULOG_PREFIX_LEN];
5072 +typedef struct ebt_ulog_packet_msg {
5073 + char indev[IFNAMSIZ];
5074 + char outdev[IFNAMSIZ];
5075 + char physindev[IFNAMSIZ];
5076 + char physoutdev[IFNAMSIZ];
5077 + char prefix[EBT_ULOG_PREFIX_LEN];
5078 + struct timeval stamp;
5079 + unsigned long mark;
5080 + unsigned int hook;
5082 + /* The complete packet, including Ethernet header and perhaps
5083 + * the VLAN header is appended */
5084 + unsigned char data[0] __attribute__ ((aligned (__alignof__(int))));
5085 +} ebt_ulog_packet_msg_t;
5087 +#endif /* _EBT_ULOG_H */
5088 --- /dev/null 2005-03-14 20:10:29.001600248 +0100
5089 +++ linux-2.4.29-ebt-brnf/include/linux/netfilter_bridge/ebt_nat.h 2005-03-14 00:00:30.000000000 +0100
5091 +#ifndef __LINUX_BRIDGE_EBT_NAT_H
5092 +#define __LINUX_BRIDGE_EBT_NAT_H
5094 +struct ebt_nat_info
5096 + unsigned char mac[ETH_ALEN];
5097 + // EBT_ACCEPT, EBT_DROP, EBT_CONTINUE or EBT_RETURN
5100 +#define EBT_SNAT_TARGET "snat"
5101 +#define EBT_DNAT_TARGET "dnat"
5104 --- /dev/null 2005-03-14 20:10:29.001600248 +0100
5105 +++ linux-2.4.29-ebt-brnf/include/linux/netfilter_bridge/ebt_redirect.h 2005-03-14 00:00:30.000000000 +0100
5107 +#ifndef __LINUX_BRIDGE_EBT_REDIRECT_H
5108 +#define __LINUX_BRIDGE_EBT_REDIRECT_H
5110 +struct ebt_redirect_info
5112 + // EBT_ACCEPT, EBT_DROP or EBT_CONTINUE or EBT_RETURN
5115 +#define EBT_REDIRECT_TARGET "redirect"
5118 --- /dev/null 2005-03-14 20:10:29.001600248 +0100
5119 +++ linux-2.4.29-ebt-brnf/include/linux/netfilter_bridge/ebt_mark_m.h 2005-03-14 00:00:30.000000000 +0100
5121 +#ifndef __LINUX_BRIDGE_EBT_MARK_M_H
5122 +#define __LINUX_BRIDGE_EBT_MARK_M_H
5124 +#define EBT_MARK_AND 0x01
5125 +#define EBT_MARK_OR 0x02
5126 +#define EBT_MARK_MASK (EBT_MARK_AND | EBT_MARK_OR)
5127 +struct ebt_mark_m_info
5129 + unsigned long mark, mask;
5133 +#define EBT_MARK_MATCH "mark_m"
5136 --- /dev/null 2005-03-14 20:10:29.001600248 +0100
5137 +++ linux-2.4.29-ebt-brnf/include/linux/netfilter_bridge/ebt_mark_t.h 2005-03-14 00:00:30.000000000 +0100
5139 +#ifndef __LINUX_BRIDGE_EBT_MARK_T_H
5140 +#define __LINUX_BRIDGE_EBT_MARK_T_H
5142 +struct ebt_mark_t_info
5144 + unsigned long mark;
5145 + // EBT_ACCEPT, EBT_DROP or EBT_CONTINUE or EBT_RETURN
5148 +#define EBT_MARK_TARGET "mark"
5151 --- linux-2.4.29/include/linux/netfilter.h 2005-01-19 15:10:12.000000000 +0100
5152 +++ linux-2.4.29-ebt-brnf/include/linux/netfilter.h 2005-03-14 21:11:36.000000000 +0100
5157 -#define NF_MAX_VERDICT NF_REPEAT
5159 +#define NF_MAX_VERDICT NF_STOP
5161 /* Generic cache responses from hook functions.
5162 <= 0x2000 is used for protocol-flags. */
5163 @@ -118,17 +119,34 @@ extern struct list_head nf_hooks[NPROTO]
5164 /* This is gross, but inline doesn't cut it for avoiding the function
5165 call in fast path: gcc doesn't inline (needs value tracking?). --RR */
5166 #ifdef CONFIG_NETFILTER_DEBUG
5167 -#define NF_HOOK nf_hook_slow
5168 +#define NF_HOOK(pf, hook, skb, indev, outdev, okfn) \
5170 +if ((__ret=nf_hook_slow(pf, hook, &(skb), indev, outdev, okfn, INT_MIN)) == 1) \
5171 + __ret = (okfn)(skb); \
5173 +#define NF_HOOK_THRESH(pf, hook, skb, indev, outdev, okfn, thresh) \
5175 +if ((__ret=nf_hook_slow(pf, hook, &(skb), indev, outdev, okfn, thresh)) == 1) \
5176 + __ret = (okfn)(skb); \
5179 -#define NF_HOOK(pf, hook, skb, indev, outdev, okfn) \
5180 -(list_empty(&nf_hooks[(pf)][(hook)]) \
5182 - : nf_hook_slow((pf), (hook), (skb), (indev), (outdev), (okfn)))
5183 +#define NF_HOOK(pf, hook, skb, indev, outdev, okfn) \
5185 +if (list_empty(&nf_hooks[pf][hook]) || \
5186 + (__ret=nf_hook_slow(pf, hook, &(skb), indev, outdev, okfn, INT_MIN)) == 1) \
5187 + __ret = (okfn)(skb); \
5189 +#define NF_HOOK_THRESH(pf, hook, skb, indev, outdev, okfn, thresh) \
5191 +if (list_empty(&nf_hooks[pf][hook]) || \
5192 + (__ret=nf_hook_slow(pf, hook, &(skb), indev, outdev, okfn, thresh)) == 1) \
5193 + __ret = (okfn)(skb); \
5197 -int nf_hook_slow(int pf, unsigned int hook, struct sk_buff *skb,
5198 +int nf_hook_slow(int pf, unsigned int hook, struct sk_buff **pskb,
5199 struct net_device *indev, struct net_device *outdev,
5200 - int (*okfn)(struct sk_buff *));
5201 + int (*okfn)(struct sk_buff *), int thresh);
5203 /* Call setsockopt() */
5204 int nf_setsockopt(struct sock *sk, int pf, int optval, char *opt,
5205 --- linux-2.4.29/include/linux/netfilter_ipv4.h 2002-02-25 20:38:13.000000000 +0100
5206 +++ linux-2.4.29-ebt-brnf/include/linux/netfilter_ipv4.h 2005-03-14 21:11:36.000000000 +0100
5208 enum nf_ip_hook_priorities {
5209 NF_IP_PRI_FIRST = INT_MIN,
5210 NF_IP_PRI_CONNTRACK = -200,
5211 + NF_IP_PRI_BRIDGE_SABOTAGE_FORWARD = -175,
5212 NF_IP_PRI_MANGLE = -150,
5213 NF_IP_PRI_NAT_DST = -100,
5214 + NF_IP_PRI_BRIDGE_SABOTAGE_LOCAL_OUT = -50,
5215 NF_IP_PRI_FILTER = 0,
5216 NF_IP_PRI_NAT_SRC = 100,
5217 NF_IP_PRI_LAST = INT_MAX,
5218 --- linux-2.4.29/include/linux/netfilter_ipv6.h 2001-01-02 01:17:54.000000000 +0100
5219 +++ linux-2.4.29-ebt-brnf/include/linux/netfilter_ipv6.h 2005-03-14 21:24:11.000000000 +0100
5221 enum nf_ip6_hook_priorities {
5222 NF_IP6_PRI_FIRST = INT_MIN,
5223 NF_IP6_PRI_CONNTRACK = -200,
5224 + NF_IP6_PRI_BRIDGE_SABOTAGE_FORWARD = -175,
5225 NF_IP6_PRI_MANGLE = -150,
5226 NF_IP6_PRI_NAT_DST = -100,
5227 + NF_IP6_PRI_BRIDGE_SABOTAGE_LOCAL_OUT = -50,
5228 NF_IP6_PRI_FILTER = 0,
5229 NF_IP6_PRI_NAT_SRC = 100,
5230 NF_IP6_PRI_LAST = INT_MAX,
5231 --- linux-2.4.29/include/linux/skbuff.h 2004-08-08 01:26:06.000000000 +0200
5232 +++ linux-2.4.29-ebt-brnf/include/linux/skbuff.h 2005-03-14 21:07:31.000000000 +0100
5233 @@ -92,6 +92,20 @@ struct nf_conntrack {
5235 struct nf_conntrack *master;
5238 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
5239 +struct nf_bridge_info {
5241 + struct net_device *physindev;
5242 + struct net_device *physoutdev;
5243 +#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
5244 + struct net_device *netoutdev;
5246 + unsigned int mask;
5247 + unsigned long data[32 / sizeof(unsigned long)];
5253 struct sk_buff_head {
5254 @@ -208,6 +222,9 @@ struct sk_buff {
5255 #ifdef CONFIG_NETFILTER_DEBUG
5256 unsigned int nf_debug;
5258 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
5259 + struct nf_bridge_info *nf_bridge; /* Saved data about a bridged frame - see br_netfilter.c */
5261 #endif /*CONFIG_NETFILTER*/
5263 #if defined(CONFIG_HIPPI)
5264 @@ -1175,6 +1192,20 @@ nf_reset(struct sk_buff *skb)
5269 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
5270 +static inline void nf_bridge_put(struct nf_bridge_info *nf_bridge)
5272 + if (nf_bridge && atomic_dec_and_test(&nf_bridge->use))
5275 +static inline void nf_bridge_get(struct nf_bridge_info *nf_bridge)
5278 + atomic_inc(&nf_bridge->use);
5282 #else /* CONFIG_NETFILTER */
5283 static inline void nf_reset(struct sk_buff *skb) {}
5284 #endif /* CONFIG_NETFILTER */
5285 --- linux-2.4.29/net/core/netfilter.c 2005-01-19 15:10:13.000000000 +0100
5286 +++ linux-2.4.29-ebt-brnf/net/core/netfilter.c 2005-03-14 21:21:41.825275416 +0100
5287 @@ -342,32 +342,29 @@ static unsigned int nf_iterate(struct li
5288 const struct net_device *indev,
5289 const struct net_device *outdev,
5290 struct list_head **i,
5291 - int (*okfn)(struct sk_buff *))
5292 + int (*okfn)(struct sk_buff *),
5295 + unsigned int verdict;
5297 for (*i = (*i)->next; *i != head; *i = (*i)->next) {
5298 struct nf_hook_ops *elem = (struct nf_hook_ops *)*i;
5299 - switch (elem->hook(hook, skb, indev, outdev, okfn)) {
5312 + if (hook_thresh > elem->priority)
5315 + verdict = elem->hook(hook, skb, indev, outdev, okfn);
5316 + if (verdict != NF_ACCEPT) {
5317 #ifdef CONFIG_NETFILTER_DEBUG
5322 - NFDEBUG("Evil return from %p(%u).\n",
5323 - elem->hook, hook);
5324 + if (unlikely(verdict > NF_MAX_VERDICT)) {
5325 + NFDEBUG("Evil return from %p(%u).\n",
5326 + elem->hook, hook);
5330 + if (verdict != NF_REPEAT)
5336 @@ -413,6 +410,10 @@ static void nf_queue(struct sk_buff *skb
5339 struct nf_info *info;
5340 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
5341 + struct net_device *physindev = NULL;
5342 + struct net_device *physoutdev = NULL;
5345 if (!queue_handler[pf].outfn) {
5347 @@ -435,36 +436,52 @@ static void nf_queue(struct sk_buff *skb
5348 if (indev) dev_hold(indev);
5349 if (outdev) dev_hold(outdev);
5351 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
5352 + if (skb->nf_bridge) {
5353 + physindev = skb->nf_bridge->physindev;
5354 + if (physindev) dev_hold(physindev);
5355 + physoutdev = skb->nf_bridge->physoutdev;
5356 + if (physoutdev) dev_hold(physoutdev);
5360 status = queue_handler[pf].outfn(skb, info, queue_handler[pf].data);
5362 /* James M doesn't say fuck enough. */
5363 if (indev) dev_put(indev);
5364 if (outdev) dev_put(outdev);
5365 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
5366 + if (physindev) dev_put(physindev);
5367 + if (physoutdev) dev_put(physoutdev);
5375 -int nf_hook_slow(int pf, unsigned int hook, struct sk_buff *skb,
5376 +/* Returns 1 if okfn() needs to be executed by the caller,
5377 + * -EPERM for NF_DROP, 0 otherwise. */
5378 +int nf_hook_slow(int pf, unsigned int hook, struct sk_buff **pskb,
5379 struct net_device *indev,
5380 struct net_device *outdev,
5381 - int (*okfn)(struct sk_buff *))
5382 + int (*okfn)(struct sk_buff *),
5385 struct list_head *elem;
5386 unsigned int verdict;
5389 /* This stopgap cannot be removed until all the hooks are audited. */
5390 - if (skb_is_nonlinear(skb) && skb_linearize(skb, GFP_ATOMIC) != 0) {
5392 + if (skb_is_nonlinear(*pskb) && skb_linearize(*pskb, GFP_ATOMIC) != 0) {
5396 - if (skb->ip_summed == CHECKSUM_HW) {
5397 + if ((*pskb)->ip_summed == CHECKSUM_HW) {
5398 if (outdev == NULL) {
5399 - skb->ip_summed = CHECKSUM_NONE;
5400 + (*pskb)->ip_summed = CHECKSUM_NONE;
5402 - skb_checksum_help(skb);
5403 + skb_checksum_help(*pskb);
5407 @@ -472,30 +489,24 @@ int nf_hook_slow(int pf, unsigned int ho
5408 br_read_lock_bh(BR_NETPROTO_LOCK);
5410 #ifdef CONFIG_NETFILTER_DEBUG
5411 - if (skb->nf_debug & (1 << hook)) {
5412 + if (unlikely((*pskb)->nf_debug & (1 << hook))) {
5413 printk("nf_hook: hook %i already set.\n", hook);
5414 - nf_dump_skb(pf, skb);
5415 + nf_dump_skb(pf, *pskb);
5417 - skb->nf_debug |= (1 << hook);
5418 + (*pskb)->nf_debug |= (1 << hook);
5421 elem = &nf_hooks[pf][hook];
5422 - verdict = nf_iterate(&nf_hooks[pf][hook], &skb, hook, indev,
5423 - outdev, &elem, okfn);
5424 - if (verdict == NF_QUEUE) {
5425 - NFDEBUG("nf_hook: Verdict = QUEUE.\n");
5426 - nf_queue(skb, elem, pf, hook, indev, outdev, okfn);
5429 - switch (verdict) {
5436 + verdict = nf_iterate(&nf_hooks[pf][hook], pskb, hook, indev,
5437 + outdev, &elem, okfn, hook_thresh);
5438 + if (verdict == NF_ACCEPT || verdict == NF_STOP)
5440 + else if (verdict == NF_DROP) {
5444 + } else if (verdict == NF_QUEUE) {
5445 + NFDEBUG("nf_hook: Verdict = QUEUE.\n");
5446 + nf_queue(*pskb, elem, pf, hook, indev, outdev, okfn);
5449 br_read_unlock_bh(BR_NETPROTO_LOCK);
5450 @@ -510,6 +521,14 @@ void nf_reinject(struct sk_buff *skb, st
5452 /* We don't have BR_NETPROTO_LOCK here */
5453 br_read_lock_bh(BR_NETPROTO_LOCK);
5454 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
5455 + if (skb->nf_bridge) {
5456 + if (skb->nf_bridge->physindev)
5457 + dev_put(skb->nf_bridge->physindev);
5458 + if (skb->nf_bridge->physoutdev)
5459 + dev_put(skb->nf_bridge->physoutdev);
5462 for (i = nf_hooks[info->pf][info->hook].next; i != elem; i = i->next) {
5463 if (i == &nf_hooks[info->pf][info->hook]) {
5464 /* The module which sent it to userspace is gone. */
5465 @@ -530,7 +549,7 @@ void nf_reinject(struct sk_buff *skb, st
5466 verdict = nf_iterate(&nf_hooks[info->pf][info->hook],
5468 info->indev, info->outdev, &elem,
5470 + info->okfn, INT_MIN);
5474 --- linux-2.4.29/net/core/skbuff.c 2003-08-25 13:44:44.000000000 +0200
5475 +++ linux-2.4.29-ebt-brnf/net/core/skbuff.c 2005-03-14 00:00:30.000000000 +0100
5476 @@ -246,6 +246,9 @@ static inline void skb_headerinit(void *
5477 #ifdef CONFIG_NETFILTER_DEBUG
5480 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
5481 + skb->nf_bridge = NULL;
5484 #ifdef CONFIG_NET_SCHED
5486 @@ -326,6 +329,9 @@ void __kfree_skb(struct sk_buff *skb)
5488 #ifdef CONFIG_NETFILTER
5489 nf_conntrack_put(skb->nfct);
5490 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
5491 + nf_bridge_put(skb->nf_bridge);
5494 skb_headerinit(skb, NULL, 0); /* clean state */
5496 @@ -393,6 +399,9 @@ struct sk_buff *skb_clone(struct sk_buff
5497 #ifdef CONFIG_NETFILTER_DEBUG
5500 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
5503 #endif /*CONFIG_NETFILTER*/
5504 #if defined(CONFIG_HIPPI)
5506 @@ -405,6 +414,9 @@ struct sk_buff *skb_clone(struct sk_buff
5508 #ifdef CONFIG_NETFILTER
5509 nf_conntrack_get(skb->nfct);
5510 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
5511 + nf_bridge_get(skb->nf_bridge);
5516 @@ -440,6 +452,10 @@ static void copy_skb_header(struct sk_bu
5517 #ifdef CONFIG_NETFILTER_DEBUG
5518 new->nf_debug=old->nf_debug;
5520 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
5521 + new->nf_bridge=old->nf_bridge;
5522 + nf_bridge_get(new->nf_bridge);
5525 #ifdef CONFIG_NET_SCHED
5526 new->tc_index = old->tc_index;
5527 @@ -726,9 +742,9 @@ struct sk_buff *skb_copy_expand(const st
5528 /* Set the tail pointer and length */
5529 skb_put(n,skb->len);
5531 - /* Copy the data only. */
5532 - if (skb_copy_bits(skb, 0, n->data, skb->len))
5534 + /* Copy the linear data and header. */
5535 + if (skb_copy_bits(skb, -newheadroom, n->head, newheadroom + skb->len))
5538 copy_skb_header(n, skb);
5540 --- linux-2.4.29/net/ipv4/netfilter/ip_tables.c 2005-01-19 15:10:13.000000000 +0100
5541 +++ linux-2.4.29-ebt-brnf/net/ipv4/netfilter/ip_tables.c 2005-03-14 00:00:30.000000000 +0100
5542 @@ -118,12 +118,19 @@ static LIST_HEAD(ipt_tables);
5544 ip_packet_match(const struct iphdr *ip,
5546 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
5547 + const char *physindev,
5550 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
5551 + const char *physoutdev,
5553 const struct ipt_ip *ipinfo,
5558 + unsigned long ret2 = 1;
5560 #define FWINV(bool,invflg) ((bool) ^ !!(ipinfo->invflags & invflg))
5562 @@ -153,7 +160,15 @@ ip_packet_match(const struct iphdr *ip,
5563 & ((const unsigned long *)ipinfo->iniface_mask)[i];
5566 - if (FWINV(ret != 0, IPT_INV_VIA_IN)) {
5567 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
5568 + for (i = 0, ret2 = 0; i < IFNAMSIZ/sizeof(unsigned long); i++) {
5569 + ret2 |= (((const unsigned long *)physindev)[i]
5570 + ^ ((const unsigned long *)ipinfo->iniface)[i])
5571 + & ((const unsigned long *)ipinfo->iniface_mask)[i];
5575 + if (FWINV(ret != 0 && ret2 != 0, IPT_INV_VIA_IN)) {
5576 dprintf("VIA in mismatch (%s vs %s).%s\n",
5577 indev, ipinfo->iniface,
5578 ipinfo->invflags&IPT_INV_VIA_IN ?" (INV)":"");
5579 @@ -166,7 +181,15 @@ ip_packet_match(const struct iphdr *ip,
5580 & ((const unsigned long *)ipinfo->outiface_mask)[i];
5583 - if (FWINV(ret != 0, IPT_INV_VIA_OUT)) {
5584 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
5585 + for (i = 0, ret2 = 0; i < IFNAMSIZ/sizeof(unsigned long); i++) {
5586 + ret2 |= (((const unsigned long *)physoutdev)[i]
5587 + ^ ((const unsigned long *)ipinfo->outiface)[i])
5588 + & ((const unsigned long *)ipinfo->outiface_mask)[i];
5592 + if (FWINV(ret != 0 && ret2 != 0, IPT_INV_VIA_OUT)) {
5593 dprintf("VIA out mismatch (%s vs %s).%s\n",
5594 outdev, ipinfo->outiface,
5595 ipinfo->invflags&IPT_INV_VIA_OUT ?" (INV)":"");
5596 @@ -265,6 +288,9 @@ ipt_do_table(struct sk_buff **pskb,
5597 /* Initializing verdict to NF_DROP keeps gcc happy. */
5598 unsigned int verdict = NF_DROP;
5599 const char *indev, *outdev;
5600 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
5601 + const char *physindev, *physoutdev;
5604 struct ipt_entry *e, *back;
5606 @@ -274,6 +300,13 @@ ipt_do_table(struct sk_buff **pskb,
5607 datalen = (*pskb)->len - ip->ihl * 4;
5608 indev = in ? in->name : nulldevname;
5609 outdev = out ? out->name : nulldevname;
5610 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
5611 + physindev = ((*pskb)->nf_bridge && (*pskb)->nf_bridge->physindev) ?
5612 + (*pskb)->nf_bridge->physindev->name : nulldevname;
5613 + physoutdev = ((*pskb)->nf_bridge && (*pskb)->nf_bridge->physoutdev) ?
5614 + (*pskb)->nf_bridge->physoutdev->name : nulldevname;
5617 /* We handle fragments by dealing with the first fragment as
5618 * if it was a normal packet. All other fragments are treated
5619 * normally, except that they will NEVER match rules that ask
5620 @@ -309,7 +342,15 @@ ipt_do_table(struct sk_buff **pskb,
5623 (*pskb)->nfcache |= e->nfcache;
5624 - if (ip_packet_match(ip, indev, outdev, &e->ip, offset)) {
5625 + if (ip_packet_match(ip, indev,
5626 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
5630 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
5633 + &e->ip, offset)) {
5634 struct ipt_entry_target *t;
5636 if (IPT_MATCH_ITERATE(e, do_match,
5637 --- linux-2.4.29/net/ipv4/ip_output.c 2005-01-19 15:10:13.000000000 +0100
5638 +++ linux-2.4.29-ebt-brnf/net/ipv4/ip_output.c 2005-03-14 00:00:30.000000000 +0100
5639 @@ -890,6 +890,10 @@ int ip_fragment(struct sk_buff *skb, int
5640 /* Connection association is same as pre-frag packet */
5641 skb2->nfct = skb->nfct;
5642 nf_conntrack_get(skb2->nfct);
5643 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
5644 + skb2->nf_bridge = skb->nf_bridge;
5645 + nf_bridge_get(skb2->nf_bridge);
5647 #ifdef CONFIG_NETFILTER_DEBUG
5648 skb2->nf_debug = skb->nf_debug;
5650 --- linux-2.4.29/net/ipv4/netfilter/ipt_LOG.c 2003-11-28 19:26:21.000000000 +0100
5651 +++ linux-2.4.29-ebt-brnf/net/ipv4/netfilter/ipt_LOG.c 2005-03-14 00:00:30.000000000 +0100
5652 @@ -316,6 +316,18 @@ ipt_log_target(struct sk_buff **pskb,
5655 out ? out->name : "");
5656 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
5657 + if ((*pskb)->nf_bridge) {
5658 + struct net_device *physindev = (*pskb)->nf_bridge->physindev;
5659 + struct net_device *physoutdev = (*pskb)->nf_bridge->physoutdev;
5661 + if (physindev && in != physindev)
5662 + printk("PHYSIN=%s ", physindev->name);
5663 + if (physoutdev && out != physoutdev)
5664 + printk("PHYSOUT=%s ", physoutdev->name);
5669 /* MAC logging for input chain only. */
5671 --- linux-2.4.29/net/ipv4/netfilter/Makefile 2003-08-25 13:44:44.000000000 +0200
5672 +++ linux-2.4.29-ebt-brnf/net/ipv4/netfilter/Makefile 2005-03-14 00:00:30.000000000 +0100
5673 @@ -87,6 +87,8 @@ obj-$(CONFIG_IP_NF_MATCH_CONNTRACK) += i
5674 obj-$(CONFIG_IP_NF_MATCH_UNCLEAN) += ipt_unclean.o
5675 obj-$(CONFIG_IP_NF_MATCH_TCPMSS) += ipt_tcpmss.o
5677 +obj-$(CONFIG_IP_NF_MATCH_PHYSDEV) += ipt_physdev.o
5680 obj-$(CONFIG_IP_NF_TARGET_REJECT) += ipt_REJECT.o
5681 obj-$(CONFIG_IP_NF_TARGET_MIRROR) += ipt_MIRROR.o
5682 --- linux-2.4.29/net/ipv4/netfilter/Config.in 2005-01-19 15:10:13.000000000 +0100
5683 +++ linux-2.4.29-ebt-brnf/net/ipv4/netfilter/Config.in 2005-03-14 00:00:30.000000000 +0100
5684 @@ -44,6 +44,9 @@ if [ "$CONFIG_IP_NF_IPTABLES" != "n" ];
5685 dep_tristate ' Unclean match support (EXPERIMENTAL)' CONFIG_IP_NF_MATCH_UNCLEAN $CONFIG_IP_NF_IPTABLES
5686 dep_tristate ' Owner match support (EXPERIMENTAL)' CONFIG_IP_NF_MATCH_OWNER $CONFIG_IP_NF_IPTABLES
5688 + if [ "$CONFIG_BRIDGE" != "n" ]; then
5689 + dep_tristate ' Physdev match support' CONFIG_IP_NF_MATCH_PHYSDEV $CONFIG_IP_NF_IPTABLES
5692 dep_tristate ' Packet filtering' CONFIG_IP_NF_FILTER $CONFIG_IP_NF_IPTABLES
5693 if [ "$CONFIG_IP_NF_FILTER" != "n" ]; then
5694 --- /dev/null 2005-03-14 20:10:29.001600248 +0100
5695 +++ linux-2.4.29-ebt-brnf/net/bridge/br_netfilter.c 2005-03-14 00:00:30.000000000 +0100
5698 + * Handle firewalling
5699 + * Linux ethernet bridge
5702 + * Lennert Buytenhek <buytenh@gnu.org>
5703 + * Bart De Schuymer (maintainer) <bdschuym@pandora.be>
5706 + * Apr 29 2003: physdev module support (bdschuym)
5707 + * Jun 19 2003: let arptables see bridged ARP traffic (bdschuym)
5708 + * Oct 06 2003: filter encapsulated IP/ARP VLAN traffic on untagged bridge
5710 + * Aug 28 2004: add IPv6 filtering (bdschuym)
5712 + * This program is free software; you can redistribute it and/or
5713 + * modify it under the terms of the GNU General Public License
5714 + * as published by the Free Software Foundation; either version
5715 + * 2 of the License, or (at your option) any later version.
5717 + * Lennert dedicates this file to Kerstin Wurdinger.
5720 +#include <linux/module.h>
5721 +#include <linux/kernel.h>
5722 +#include <linux/ip.h>
5723 +#include <linux/netdevice.h>
5724 +#include <linux/skbuff.h>
5725 +#include <linux/if_ether.h>
5726 +#include <linux/if_vlan.h>
5727 +#include <linux/netfilter_bridge.h>
5728 +#include <linux/netfilter_ipv4.h>
5729 +#include <linux/netfilter_ipv6.h>
5730 +#include <linux/in_route.h>
5731 +#include <net/ip.h>
5732 +#include <net/ipv6.h>
5733 +#include <asm/uaccess.h>
5734 +#include <asm/checksum.h>
5735 +#include "br_private.h"
5736 +#ifdef CONFIG_SYSCTL
5737 +#include <linux/sysctl.h>
5740 +#define skb_origaddr(skb) (((struct bridge_skb_cb *) \
5741 + (skb->nf_bridge->data))->daddr.ipv4)
5742 +#define store_orig_dstaddr(skb) (skb_origaddr(skb) = (skb)->nh.iph->daddr)
5743 +#define dnat_took_place(skb) (skb_origaddr(skb) != (skb)->nh.iph->daddr)
5745 +#define has_bridge_parent(device) ((device)->br_port != NULL)
5746 +#define bridge_parent(device) (&((device)->br_port->br->dev))
5748 +#ifdef CONFIG_SYSCTL
5749 +static struct ctl_table_header *brnf_sysctl_header;
5750 +static int brnf_call_iptables = 1;
5751 +static int brnf_call_ip6tables = 1;
5752 +static int brnf_call_arptables = 1;
5753 +static int brnf_filter_vlan_tagged = 1;
5755 +#define brnf_filter_vlan_tagged 1
5758 +#define IS_VLAN_IP (skb->protocol == __constant_htons(ETH_P_8021Q) && \
5759 + hdr->h_vlan_encapsulated_proto == __constant_htons(ETH_P_IP) && \
5760 + brnf_filter_vlan_tagged)
5761 +#define IS_VLAN_IPV6 (skb->protocol == __constant_htons(ETH_P_8021Q) && \
5762 + hdr->h_vlan_encapsulated_proto == __constant_htons(ETH_P_IPV6) && \
5763 + brnf_filter_vlan_tagged)
5765 +#define IS_VLAN_ARP (skb->protocol == __constant_htons(ETH_P_8021Q) && \
5766 + hdr->h_vlan_encapsulated_proto == __constant_htons(ETH_P_ARP) && \
5767 + brnf_filter_vlan_tagged)
5770 +/* We need these fake structures to make netfilter happy --
5771 + * lots of places assume that skb->dst != NULL, which isn't
5772 + * all that unreasonable.
5774 + * Currently, we fill in the PMTU entry because netfilter
5775 + * refragmentation needs it, and the rt_flags entry because
5776 + * ipt_REJECT needs it. Future netfilter modules might
5777 + * require us to fill additional fields.
5779 +static struct net_device __fake_net_device = {
5780 + .hard_header_len = ETH_HLEN
5783 +static struct rtable __fake_rtable = {
5786 + __refcnt: ATOMIC_INIT(1),
5787 + dev: &__fake_net_device,
5796 +/* PF_BRIDGE/PRE_ROUTING *********************************************/
5797 +/* Undo the changes made for ip6tables PREROUTING and continue the
5798 + * bridge PRE_ROUTING hook. */
5799 +static int br_nf_pre_routing_finish_ipv6(struct sk_buff *skb)
5801 + struct nf_bridge_info *nf_bridge = skb->nf_bridge;
5803 +#ifdef CONFIG_NETFILTER_DEBUG
5804 + skb->nf_debug ^= (1 << NF_BR_PRE_ROUTING);
5807 + if (nf_bridge->mask & BRNF_PKT_TYPE) {
5808 + skb->pkt_type = PACKET_OTHERHOST;
5809 + nf_bridge->mask ^= BRNF_PKT_TYPE;
5811 + nf_bridge->mask ^= BRNF_NF_BRIDGE_PREROUTING;
5813 + skb->dst = (struct dst_entry *)&__fake_rtable;
5814 + dst_hold(skb->dst);
5816 + skb->dev = nf_bridge->physindev;
5817 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
5818 + skb_push(skb, VLAN_HLEN);
5819 + skb->nh.raw -= VLAN_HLEN;
5821 + NF_HOOK_THRESH(PF_BRIDGE, NF_BR_PRE_ROUTING, skb, skb->dev, NULL,
5822 + br_handle_frame_finish, 1);
5827 +static void __br_dnat_complain(void)
5829 + static unsigned long last_complaint;
5831 + if (jiffies - last_complaint >= 5 * HZ) {
5832 + printk(KERN_WARNING "Performing cross-bridge DNAT requires IP "
5833 + "forwarding to be enabled\n");
5834 + last_complaint = jiffies;
5839 +/* This requires some explaining. If DNAT has taken place,
5840 + * we will need to fix up the destination Ethernet address,
5841 + * and this is a tricky process.
5843 + * There are two cases to consider:
5844 + * 1. The packet was DNAT'ed to a device in the same bridge
5845 + * port group as it was received on. We can still bridge
5847 + * 2. The packet was DNAT'ed to a different device, either
5848 + * a non-bridged device or another bridge port group.
5849 + * The packet will need to be routed.
5851 + * The correct way of distinguishing between these two cases is to
5852 + * call ip_route_input() and to look at skb->dst->dev, which is
5853 + * changed to the destination device if ip_route_input() succeeds.
5855 + * Let us first consider the case that ip_route_input() succeeds:
5857 + * If skb->dst->dev equals the logical bridge device the packet
5858 + * came in on, we can consider this bridging. We then call
5859 + * skb->dst->output() which will make the packet enter br_nf_local_out()
5860 + * not much later. In that function it is assured that the iptables
5861 + * FORWARD chain is traversed for the packet.
5863 + * Otherwise, the packet is considered to be routed and we just
5864 + * change the destination MAC address so that the packet will
5865 + * later be passed up to the IP stack to be routed.
5867 + * Let us now consider the case that ip_route_input() fails:
5869 + * After a "echo '0' > /proc/sys/net/ipv4/ip_forward" ip_route_input()
5870 + * will fail, while __ip_route_output_key() will return success. The source
5871 + * address for __ip_route_output_key() is set to zero, so __ip_route_output_key
5872 + * thinks we're handling a locally generated packet and won't care
5873 + * if IP forwarding is allowed. We send a warning message to the users's
5874 + * log telling her to put IP forwarding on.
5876 + * ip_route_input() will also fail if there is no route available.
5877 + * In that case we just drop the packet.
5879 + * --Lennert, 20020411
5880 + * --Bart, 20020416 (updated)
5881 + * --Bart, 20021007 (updated)
5884 +static int br_nf_pre_routing_finish_bridge(struct sk_buff *skb)
5886 +#ifdef CONFIG_NETFILTER_DEBUG
5887 + skb->nf_debug |= (1 << NF_BR_PRE_ROUTING) | (1 << NF_BR_FORWARD);
5890 + if (skb->pkt_type == PACKET_OTHERHOST) {
5891 + skb->pkt_type = PACKET_HOST;
5892 + skb->nf_bridge->mask |= BRNF_PKT_TYPE;
5894 + skb->nf_bridge->mask ^= BRNF_NF_BRIDGE_PREROUTING;
5896 + skb->dev = bridge_parent(skb->dev);
5897 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
5898 + skb_pull(skb, VLAN_HLEN);
5899 + skb->nh.raw += VLAN_HLEN;
5901 + skb->dst->output(skb);
5905 +static int br_nf_pre_routing_finish(struct sk_buff *skb)
5907 + struct net_device *dev = skb->dev;
5908 + struct iphdr *iph = skb->nh.iph;
5909 + struct nf_bridge_info *nf_bridge = skb->nf_bridge;
5911 +#ifdef CONFIG_NETFILTER_DEBUG
5912 + skb->nf_debug ^= (1 << NF_BR_PRE_ROUTING);
5915 + if (nf_bridge->mask & BRNF_PKT_TYPE) {
5916 + skb->pkt_type = PACKET_OTHERHOST;
5917 + nf_bridge->mask ^= BRNF_PKT_TYPE;
5919 + nf_bridge->mask ^= BRNF_NF_BRIDGE_PREROUTING;
5921 + if (dnat_took_place(skb)) {
5922 + if (ip_route_input(skb, iph->daddr, iph->saddr, iph->tos,
5924 + struct rtable *rt;
5926 + if (!ip_route_output(&rt, iph->daddr, 0, iph->tos, 0)) {
5927 + /* Bridged-and-DNAT'ed traffic doesn't
5928 + * require ip_forwarding.
5930 + if (((struct dst_entry *)rt)->dev == dev) {
5931 + skb->dst = (struct dst_entry *)rt;
5932 + goto bridged_dnat;
5934 + __br_dnat_complain();
5935 + dst_release((struct dst_entry *)rt);
5940 + if (skb->dst->dev == dev) {
5942 + /* Tell br_nf_local_out this is a
5945 + nf_bridge->mask |= BRNF_BRIDGED_DNAT;
5946 + skb->dev = nf_bridge->physindev;
5947 + if (skb->protocol ==
5948 + __constant_htons(ETH_P_8021Q)) {
5949 + skb_push(skb, VLAN_HLEN);
5950 + skb->nh.raw -= VLAN_HLEN;
5952 + NF_HOOK_THRESH(PF_BRIDGE, NF_BR_PRE_ROUTING,
5953 + skb, skb->dev, NULL,
5954 + br_nf_pre_routing_finish_bridge,
5958 + memcpy(skb->mac.ethernet->h_dest, dev->dev_addr,
5960 + skb->pkt_type = PACKET_HOST;
5963 + skb->dst = (struct dst_entry *)&__fake_rtable;
5964 + dst_hold(skb->dst);
5967 + skb->dev = nf_bridge->physindev;
5968 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
5969 + skb_push(skb, VLAN_HLEN);
5970 + skb->nh.raw -= VLAN_HLEN;
5972 + NF_HOOK_THRESH(PF_BRIDGE, NF_BR_PRE_ROUTING, skb, skb->dev, NULL,
5973 + br_handle_frame_finish, 1);
5978 +/* Some common code for IPv4/IPv6 */
5979 +static void setup_pre_routing(struct sk_buff *skb)
5981 + struct nf_bridge_info *nf_bridge = skb->nf_bridge;
5983 + if (skb->pkt_type == PACKET_OTHERHOST) {
5984 + skb->pkt_type = PACKET_HOST;
5985 + nf_bridge->mask |= BRNF_PKT_TYPE;
5988 + nf_bridge->mask |= BRNF_NF_BRIDGE_PREROUTING;
5989 + nf_bridge->physindev = skb->dev;
5990 + skb->dev = bridge_parent(skb->dev);
5993 +/* We only check the length. A bridge shouldn't do any hop-by-hop stuff anyway */
5994 +static int check_hbh_len(struct sk_buff *skb)
5996 + unsigned char *raw = (u8*)(skb->nh.ipv6h+1);
5998 + int off = raw - skb->nh.raw;
5999 + int len = (raw[1]+1)<<3;
6001 + if ((raw + len) - skb->data > skb_headlen(skb))
6008 + int optlen = raw[off+1]+2;
6010 + switch (skb->nh.raw[off]) {
6011 + case IPV6_TLV_PAD0:
6015 + case IPV6_TLV_PADN:
6018 + case IPV6_TLV_JUMBO:
6019 + if (skb->nh.raw[off+1] != 4 || (off&3) != 2)
6022 + pkt_len = ntohl(*(u32*)(skb->nh.raw+off+2));
6024 + if (pkt_len > skb->len - sizeof(struct ipv6hdr))
6026 + if (pkt_len + sizeof(struct ipv6hdr) < skb->len) {
6027 + if (__pskb_trim(skb,
6028 + pkt_len + sizeof(struct ipv6hdr)))
6030 + if (skb->ip_summed == CHECKSUM_HW)
6031 + skb->ip_summed = CHECKSUM_NONE;
6049 +/* Replicate the checks that IPv6 does on packet reception and pass the packet
6050 + * to ip6tables, which doesn't support NAT, so things are fairly simple. */
6051 +static unsigned int br_nf_pre_routing_ipv6(unsigned int hook,
6052 + struct sk_buff *skb, const struct net_device *in,
6053 + const struct net_device *out, int (*okfn)(struct sk_buff *))
6055 + struct ipv6hdr *hdr;
6057 + struct nf_bridge_info *nf_bridge;
6059 + if (skb->len < sizeof(struct ipv6hdr))
6062 + if (!pskb_may_pull(skb, sizeof(struct ipv6hdr)))
6065 + hdr = skb->nh.ipv6h;
6067 + if (hdr->version != 6)
6070 + pkt_len = ntohs(hdr->payload_len);
6072 + if (pkt_len || hdr->nexthdr != NEXTHDR_HOP) {
6073 + if (pkt_len + sizeof(struct ipv6hdr) > skb->len)
6075 + if (pkt_len + sizeof(struct ipv6hdr) < skb->len) {
6076 + if (__pskb_trim(skb, pkt_len + sizeof(struct ipv6hdr)))
6078 + if (skb->ip_summed == CHECKSUM_HW)
6079 + skb->ip_summed = CHECKSUM_NONE;
6082 + if (hdr->nexthdr == NEXTHDR_HOP && check_hbh_len(skb))
6085 +#ifdef CONFIG_NETFILTER_DEBUG
6086 + skb->nf_debug ^= (1 << NF_IP6_PRE_ROUTING);
6088 + if ((nf_bridge = nf_bridge_alloc(skb)) == NULL)
6090 + setup_pre_routing(skb);
6092 + NF_HOOK(PF_INET6, NF_IP6_PRE_ROUTING, skb, skb->dev, NULL,
6093 + br_nf_pre_routing_finish_ipv6);
6101 +/* Direct IPv6 traffic to br_nf_pre_routing_ipv6.
6102 + * Replicate the checks that IPv4 does on packet reception.
6103 + * Set skb->dev to the bridge device (i.e. parent of the
6104 + * receiving device) to make netfilter happy, the REDIRECT
6105 + * target in particular. Save the original destination IP
6106 + * address to be able to detect DNAT afterwards.
6108 +static unsigned int br_nf_pre_routing(unsigned int hook, struct sk_buff **pskb,
6109 + const struct net_device *in, const struct net_device *out,
6110 + int (*okfn)(struct sk_buff *))
6112 + struct iphdr *iph;
6114 + struct sk_buff *skb = *pskb;
6115 + struct nf_bridge_info *nf_bridge;
6116 + struct vlan_ethhdr *hdr = (struct vlan_ethhdr *)
6117 + ((*pskb)->mac.ethernet);
6119 + if (skb->protocol == __constant_htons(ETH_P_IPV6) || IS_VLAN_IPV6) {
6120 +#ifdef CONFIG_SYSCTL
6121 + if (!brnf_call_ip6tables)
6124 + if ((skb = skb_share_check(*pskb, GFP_ATOMIC)) == NULL)
6127 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
6128 + skb_pull(skb, VLAN_HLEN);
6129 + (skb)->nh.raw += VLAN_HLEN;
6131 + return br_nf_pre_routing_ipv6(hook, skb, in, out, okfn);
6134 +#ifdef CONFIG_SYSCTL
6135 + if (!brnf_call_iptables)
6139 + if (skb->protocol != __constant_htons(ETH_P_IP) && !IS_VLAN_IP)
6141 + if ((skb = skb_share_check(*pskb, GFP_ATOMIC)) == NULL)
6144 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
6145 + skb_pull(skb, VLAN_HLEN);
6146 + (skb)->nh.raw += VLAN_HLEN;
6149 + if (!pskb_may_pull(skb, sizeof(struct iphdr)))
6152 + iph = skb->nh.iph;
6153 + if (iph->ihl < 5 || iph->version != 4)
6156 + if (!pskb_may_pull(skb, 4*iph->ihl))
6159 + iph = skb->nh.iph;
6160 + if (ip_fast_csum((__u8 *)iph, iph->ihl) != 0)
6163 + len = ntohs(iph->tot_len);
6164 + if (skb->len < len || len < 4*iph->ihl)
6167 + if (skb->len > len) {
6168 + __pskb_trim(skb, len);
6169 + if (skb->ip_summed == CHECKSUM_HW)
6170 + skb->ip_summed = CHECKSUM_NONE;
6173 +#ifdef CONFIG_NETFILTER_DEBUG
6174 + skb->nf_debug ^= (1 << NF_IP_PRE_ROUTING);
6176 + if ((nf_bridge = nf_bridge_alloc(skb)) == NULL)
6179 + setup_pre_routing(skb);
6180 + store_orig_dstaddr(skb);
6182 + NF_HOOK(PF_INET, NF_IP_PRE_ROUTING, skb, skb->dev, NULL,
6183 + br_nf_pre_routing_finish);
6188 +// IP_INC_STATS_BH(IpInHdrErrors);
6194 +/* PF_BRIDGE/LOCAL_IN ************************************************/
6195 +/* The packet is locally destined, which requires a real
6196 + * dst_entry, so detach the fake one. On the way up, the
6197 + * packet would pass through PRE_ROUTING again (which already
6198 + * took place when the packet entered the bridge), but we
6199 + * register an IPv4 PRE_ROUTING 'sabotage' hook that will
6200 + * prevent this from happening.
6202 +static unsigned int br_nf_local_in(unsigned int hook, struct sk_buff **pskb,
6203 + const struct net_device *in, const struct net_device *out,
6204 + int (*okfn)(struct sk_buff *))
6206 + struct sk_buff *skb = *pskb;
6208 + if (skb->dst == (struct dst_entry *)&__fake_rtable) {
6209 + dst_release(skb->dst);
6216 +/* PF_BRIDGE/FORWARD *************************************************/
6217 +static int br_nf_forward_finish(struct sk_buff *skb)
6219 + struct nf_bridge_info *nf_bridge = skb->nf_bridge;
6220 + struct net_device *in;
6221 +/* struct vlan_ethhdr *hdr = (struct vlan_ethhdr *)(skb->mac.ethernet);*/
6223 +#ifdef CONFIG_NETFILTER_DEBUG
6224 + skb->nf_debug ^= (1 << NF_BR_FORWARD);
6227 +/* if (skb->protocol != __constant_htons(ETH_P_ARP) && !IS_VLAN_ARP) {*/
6228 + in = nf_bridge->physindev;
6229 + if (nf_bridge->mask & BRNF_PKT_TYPE) {
6230 + skb->pkt_type = PACKET_OTHERHOST;
6231 + nf_bridge->mask ^= BRNF_PKT_TYPE;
6234 + in = *((struct net_device **)(skb->cb));
6236 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
6237 + skb_push(skb, VLAN_HLEN);
6238 + skb->nh.raw -= VLAN_HLEN;
6240 + NF_HOOK_THRESH(PF_BRIDGE, NF_BR_FORWARD, skb, in,
6241 + skb->dev, br_forward_finish, 1);
6245 +/* This is the 'purely bridged' case. For IP, we pass the packet to
6246 + * netfilter with indev and outdev set to the bridge device,
6247 + * but we are still able to filter on the 'real' indev/outdev
6248 + * because of the ipt_physdev.c module. For ARP, indev and outdev are the
6251 +static unsigned int br_nf_forward_ip(unsigned int hook, struct sk_buff **pskb,
6252 + const struct net_device *in, const struct net_device *out,
6253 + int (*okfn)(struct sk_buff *))
6255 + struct sk_buff *skb = *pskb;
6256 + struct nf_bridge_info *nf_bridge;
6257 + struct vlan_ethhdr *hdr = (struct vlan_ethhdr *)(skb->mac.ethernet);
6260 + if (!skb->nf_bridge)
6263 + if (skb->protocol == __constant_htons(ETH_P_IP) || IS_VLAN_IP)
6268 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
6269 + skb_pull(*pskb, VLAN_HLEN);
6270 + (*pskb)->nh.raw += VLAN_HLEN;
6273 +#ifdef CONFIG_NETFILTER_DEBUG
6274 + skb->nf_debug ^= (1 << NF_BR_FORWARD);
6276 + nf_bridge = skb->nf_bridge;
6277 + if (skb->pkt_type == PACKET_OTHERHOST) {
6278 + skb->pkt_type = PACKET_HOST;
6279 + nf_bridge->mask |= BRNF_PKT_TYPE;
6282 + /* The physdev module checks on this */
6283 + nf_bridge->mask |= BRNF_BRIDGED;
6284 + nf_bridge->physoutdev = skb->dev;
6286 + NF_HOOK(pf, NF_IP_FORWARD, skb, bridge_parent(in),
6287 + bridge_parent(out), br_nf_forward_finish);
6293 +static unsigned int br_nf_forward_arp(unsigned int hook, struct sk_buff **pskb,
6294 + const struct net_device *in, const struct net_device *out,
6295 + int (*okfn)(struct sk_buff *))
6297 + struct sk_buff *skb = *pskb;
6298 + struct vlan_ethhdr *hdr = (struct vlan_ethhdr *)(skb->mac.ethernet);
6299 + struct net_device **d = (struct net_device **)(skb->cb);
6301 + if (!brnf_call_arptables)
6304 + if (skb->protocol != __constant_htons(ETH_P_ARP)) {
6307 + skb_pull(*pskb, VLAN_HLEN);
6308 + (*pskb)->nh.raw += VLAN_HLEN;
6311 +#ifdef CONFIG_NETFILTER_DEBUG
6312 + skb->nf_debug ^= (1 << NF_BR_FORWARD);
6315 + if (skb->nh.arph->ar_pln != 4) {
6316 + if (IS_VLAN_ARP) {
6317 + skb_push(*pskb, VLAN_HLEN);
6318 + (*pskb)->nh.raw -= VLAN_HLEN;
6322 + *d = (struct net_device *)in;
6323 + NF_HOOK(NF_ARP, NF_ARP_FORWARD, skb, (struct net_device *)in,
6324 + (struct net_device *)out, br_nf_forward_finish);
6330 +/* PF_BRIDGE/LOCAL_OUT ***********************************************/
6331 +static int br_nf_local_out_finish(struct sk_buff *skb)
6333 +#ifdef CONFIG_NETFILTER_DEBUG
6334 + skb->nf_debug &= ~(1 << NF_BR_LOCAL_OUT);
6336 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
6337 + skb_push(skb, VLAN_HLEN);
6338 + skb->nh.raw -= VLAN_HLEN;
6341 + NF_HOOK_THRESH(PF_BRIDGE, NF_BR_LOCAL_OUT, skb, NULL, skb->dev,
6342 + br_forward_finish, NF_BR_PRI_FIRST + 1);
6348 +/* This function sees both locally originated IP packets and forwarded
6349 + * IP packets (in both cases the destination device is a bridge
6350 + * device). It also sees bridged-and-DNAT'ed packets.
6351 + * To be able to filter on the physical bridge devices (with the ipt_physdev.c
6352 + * module), we steal packets destined to a bridge device away from the
6353 + * PF_INET/FORWARD and PF_INET/OUTPUT hook functions, and give them back later,
6354 + * when we have determined the real output device. This is done in here.
6356 + * If (nf_bridge->mask & BRNF_BRIDGED_DNAT) then the packet is bridged
6357 + * and we fake the PF_BRIDGE/FORWARD hook. The function br_nf_forward()
6358 + * will then fake the PF_INET/FORWARD hook. br_nf_local_out() has priority
6359 + * NF_BR_PRI_FIRST, so no relevant PF_BRIDGE/INPUT functions have been nor
6360 + * will be executed.
6361 + * Otherwise, if nf_bridge->physindev is NULL, the bridge-nf code never touched
6362 + * this packet before, and so the packet was locally originated. We fake
6363 + * the PF_INET/LOCAL_OUT hook.
6364 + * Finally, if nf_bridge->physindev isn't NULL, then the packet was IP routed,
6365 + * so we fake the PF_INET/FORWARD hook. ipv4_sabotage_out() makes sure
6366 + * even routed packets that didn't arrive on a bridge interface have their
6367 + * nf_bridge->physindev set.
6370 +static unsigned int br_nf_local_out(unsigned int hook, struct sk_buff **pskb,
6371 + const struct net_device *in, const struct net_device *out,
6372 + int (*okfn)(struct sk_buff *))
6374 + struct net_device *realindev, *realoutdev;
6375 + struct sk_buff *skb = *pskb;
6376 + struct nf_bridge_info *nf_bridge;
6377 + struct vlan_ethhdr *hdr = (struct vlan_ethhdr *)(skb->mac.ethernet);
6380 + if (!skb->nf_bridge)
6383 + if (skb->protocol == __constant_htons(ETH_P_IP) || IS_VLAN_IP)
6388 +#ifdef CONFIG_NETFILTER_DEBUG
6389 + /* Sometimes we get packets with NULL ->dst here (for example,
6390 + * running a dhcp client daemon triggers this). This should now
6391 + * be fixed, but let's keep the check around. */
6392 + if (skb->dst == NULL) {
6393 + printk(KERN_CRIT "br_netfilter: skb->dst == NULL.");
6398 + nf_bridge = skb->nf_bridge;
6399 + nf_bridge->physoutdev = skb->dev;
6400 + realindev = nf_bridge->physindev;
6402 + /* Bridged, take PF_BRIDGE/FORWARD.
6403 + * (see big note in front of br_nf_pre_routing_finish)
6405 + if (nf_bridge->mask & BRNF_BRIDGED_DNAT) {
6406 + if (nf_bridge->mask & BRNF_PKT_TYPE) {
6407 + skb->pkt_type = PACKET_OTHERHOST;
6408 + nf_bridge->mask ^= BRNF_PKT_TYPE;
6410 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
6411 + skb_push(skb, VLAN_HLEN);
6412 + skb->nh.raw -= VLAN_HLEN;
6415 + NF_HOOK(PF_BRIDGE, NF_BR_FORWARD, skb, realindev,
6416 + skb->dev, br_forward_finish);
6419 + realoutdev = bridge_parent(skb->dev);
6421 +#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
6422 + /* iptables should match -o br0.x */
6423 + if (nf_bridge->netoutdev)
6424 + realoutdev = nf_bridge->netoutdev;
6426 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
6427 + skb_pull(skb, VLAN_HLEN);
6428 + (*pskb)->nh.raw += VLAN_HLEN;
6430 + /* IP forwarded traffic has a physindev, locally
6431 + * generated traffic hasn't.
6433 + if (realindev != NULL) {
6434 + if (((nf_bridge->mask & BRNF_DONT_TAKE_PARENT) == 0) &&
6435 + has_bridge_parent(realindev))
6436 + realindev = bridge_parent(realindev);
6437 + NF_HOOK_THRESH(pf, NF_IP_FORWARD, skb, realindev,
6439 + NF_IP_PRI_BRIDGE_SABOTAGE_FORWARD + 1);
6441 +#ifdef CONFIG_NETFILTER_DEBUG
6442 + skb->nf_debug ^= (1 << NF_IP_LOCAL_OUT);
6445 + NF_HOOK_THRESH(pf, NF_IP_LOCAL_OUT, skb, realindev,
6447 + NF_IP_PRI_BRIDGE_SABOTAGE_LOCAL_OUT + 1);
6455 +/* PF_BRIDGE/POST_ROUTING ********************************************/
6456 +static unsigned int br_nf_post_routing(unsigned int hook, struct sk_buff **pskb,
6457 + const struct net_device *in, const struct net_device *out,
6458 + int (*okfn)(struct sk_buff *))
6460 + struct sk_buff *skb = *pskb;
6461 + struct nf_bridge_info *nf_bridge = (*pskb)->nf_bridge;
6462 + struct vlan_ethhdr *hdr = (struct vlan_ethhdr *)(skb->mac.ethernet);
6463 + struct net_device *realoutdev = bridge_parent(skb->dev);
6466 +#ifdef CONFIG_NETFILTER_DEBUG
6467 + /* Be very paranoid. This probably won't happen anymore, but let's
6468 + * keep the check just to be sure... */
6469 + if (skb->mac.raw < skb->head || skb->mac.raw + ETH_HLEN > skb->data) {
6470 + printk(KERN_CRIT "br_netfilter: Argh!! br_nf_post_routing: "
6471 + "bad mac.raw pointer.");
6479 + if (skb->protocol == __constant_htons(ETH_P_IP) || IS_VLAN_IP)
6484 + /* Sometimes we get packets with NULL ->dst here (for example,
6485 + * running a dhcp client daemon triggers this).
6487 + if (skb->dst == NULL)
6490 +#ifdef CONFIG_NETFILTER_DEBUG
6491 + /* Sometimes we get packets with NULL ->dst here (for example,
6492 + * running a dhcp client daemon triggers this). This should now
6493 + * be fixed, but let's keep the check around.
6495 + if (skb->dst == NULL) {
6496 + printk(KERN_CRIT "br_netfilter: skb->dst == NULL.");
6500 + skb->nf_debug ^= (1 << NF_IP_POST_ROUTING);
6503 + /* We assume any code from br_dev_queue_push_xmit onwards doesn't care
6504 + * about the value of skb->pkt_type.
6506 + if (skb->pkt_type == PACKET_OTHERHOST) {
6507 + skb->pkt_type = PACKET_HOST;
6508 + nf_bridge->mask |= BRNF_PKT_TYPE;
6511 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
6512 + skb_pull(skb, VLAN_HLEN);
6513 + skb->nh.raw += VLAN_HLEN;
6516 + nf_bridge_save_header(skb);
6518 +#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
6519 + if (nf_bridge->netoutdev)
6520 + realoutdev = nf_bridge->netoutdev;
6522 + NF_HOOK(pf, NF_IP_POST_ROUTING, skb, NULL,
6523 + realoutdev, br_dev_queue_push_xmit);
6527 +#ifdef CONFIG_NETFILTER_DEBUG
6529 + if (skb->dev != NULL) {
6530 + printk("[%s]", skb->dev->name);
6531 + if (has_bridge_parent(skb->dev))
6532 + printk("[%s]", bridge_parent(skb->dev)->name);
6534 + printk(" head:%p, raw:%p, data:%p\n", skb->head, skb->mac.raw,
6541 +/* IPv4/SABOTAGE *****************************************************/
6543 +/* Don't hand locally destined packets to PF_INET/PRE_ROUTING
6544 + * for the second time.
6546 +static unsigned int ip_sabotage_in(unsigned int hook, struct sk_buff **pskb,
6547 + const struct net_device *in, const struct net_device *out,
6548 + int (*okfn)(struct sk_buff *))
6550 + if ((*pskb)->nf_bridge &&
6551 + !((*pskb)->nf_bridge->mask & BRNF_NF_BRIDGE_PREROUTING)) {
6558 +/* Postpone execution of PF_INET/FORWARD, PF_INET/LOCAL_OUT
6559 + * and PF_INET/POST_ROUTING until we have done the forwarding
6560 + * decision in the bridge code and have determined skb->physoutdev.
6562 +static unsigned int ip_sabotage_out(unsigned int hook, struct sk_buff **pskb,
6563 + const struct net_device *in, const struct net_device *out,
6564 + int (*okfn)(struct sk_buff *))
6566 + struct sk_buff *skb = *pskb;
6568 + if ((out->hard_start_xmit == br_dev_xmit &&
6569 + okfn != br_nf_forward_finish &&
6570 + okfn != br_nf_local_out_finish &&
6571 + okfn != br_dev_queue_push_xmit)
6572 +#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
6573 + || ((out->priv_flags & IFF_802_1Q_VLAN) &&
6574 + VLAN_DEV_INFO(out)->real_dev->hard_start_xmit == br_dev_xmit)
6577 + struct nf_bridge_info *nf_bridge;
6579 + if (!skb->nf_bridge) {
6580 +#ifdef CONFIG_SYSCTL
6581 + /* This code is executed while in the IP(v6) stack,
6582 + the version should be 4 or 6. We can't use
6583 + skb->protocol because that isn't set on
6584 + PF_INET(6)/LOCAL_OUT. */
6585 + struct iphdr *ip = skb->nh.iph;
6587 + if (ip->version == 4 && !brnf_call_iptables)
6589 + else if (ip->version == 6 && !brnf_call_ip6tables)
6592 + if (hook == NF_IP_POST_ROUTING)
6594 + if (!nf_bridge_alloc(skb))
6598 + nf_bridge = skb->nf_bridge;
6600 + /* This frame will arrive on PF_BRIDGE/LOCAL_OUT and we
6601 + * will need the indev then. For a brouter, the real indev
6602 + * can be a bridge port, so we make sure br_nf_local_out()
6603 + * doesn't use the bridge parent of the indev by using
6604 + * the BRNF_DONT_TAKE_PARENT mask.
6606 + if (hook == NF_IP_FORWARD && nf_bridge->physindev == NULL) {
6607 + nf_bridge->mask &= BRNF_DONT_TAKE_PARENT;
6608 + nf_bridge->physindev = (struct net_device *)in;
6610 +#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
6611 + /* the iptables outdev is br0.x, not br0 */
6612 + if (out->priv_flags & IFF_802_1Q_VLAN)
6613 + nf_bridge->netoutdev = (struct net_device *)out;
6621 +/* For br_nf_local_out we need (prio = NF_BR_PRI_FIRST), to insure that innocent
6622 + * PF_BRIDGE/NF_BR_LOCAL_OUT functions don't get bridged traffic as input.
6623 + * For br_nf_post_routing, we need (prio = NF_BR_PRI_LAST), because
6624 + * ip_refrag() can return NF_STOLEN.
6626 +static struct nf_hook_ops br_nf_ops[] = {
6627 + { .hook = br_nf_pre_routing,
6629 + .hooknum = NF_BR_PRE_ROUTING,
6630 + .priority = NF_BR_PRI_BRNF, },
6631 + { .hook = br_nf_local_in,
6633 + .hooknum = NF_BR_LOCAL_IN,
6634 + .priority = NF_BR_PRI_BRNF, },
6635 + { .hook = br_nf_forward_ip,
6637 + .hooknum = NF_BR_FORWARD,
6638 + .priority = NF_BR_PRI_BRNF /*- 1*/, },
6639 +/* { .hook = br_nf_forward_arp,
6641 + .hooknum = NF_BR_FORWARD,
6642 + .priority = NF_BR_PRI_BRNF, },*/
6643 + { .hook = br_nf_local_out,
6645 + .hooknum = NF_BR_LOCAL_OUT,
6646 + .priority = NF_BR_PRI_FIRST, },
6647 + { .hook = br_nf_post_routing,
6649 + .hooknum = NF_BR_POST_ROUTING,
6650 + .priority = NF_BR_PRI_LAST, },
6651 + { .hook = ip_sabotage_in,
6653 + .hooknum = NF_IP_PRE_ROUTING,
6654 + .priority = NF_IP_PRI_FIRST, },
6655 + { .hook = ip_sabotage_in,
6657 + .hooknum = NF_IP6_PRE_ROUTING,
6658 + .priority = NF_IP6_PRI_FIRST, },
6659 + { .hook = ip_sabotage_out,
6661 + .hooknum = NF_IP_FORWARD,
6662 + .priority = NF_IP_PRI_BRIDGE_SABOTAGE_FORWARD, },
6663 + { .hook = ip_sabotage_out,
6665 + .hooknum = NF_IP6_FORWARD,
6666 + .priority = NF_IP6_PRI_BRIDGE_SABOTAGE_FORWARD, },
6667 + { .hook = ip_sabotage_out,
6669 + .hooknum = NF_IP_LOCAL_OUT,
6670 + .priority = NF_IP_PRI_BRIDGE_SABOTAGE_LOCAL_OUT, },
6671 + { .hook = ip_sabotage_out,
6673 + .hooknum = NF_IP6_LOCAL_OUT,
6674 + .priority = NF_IP6_PRI_BRIDGE_SABOTAGE_LOCAL_OUT, },
6675 + { .hook = ip_sabotage_out,
6677 + .hooknum = NF_IP_POST_ROUTING,
6678 + .priority = NF_IP_PRI_FIRST, },
6679 + { .hook = ip_sabotage_out,
6681 + .hooknum = NF_IP6_POST_ROUTING,
6682 + .priority = NF_IP6_PRI_FIRST, },
6685 +#ifdef CONFIG_SYSCTL
6687 +int brnf_sysctl_call_tables(ctl_table *ctl, int write, struct file * filp,
6688 + void *buffer, size_t *lenp)
6692 + ret = proc_dointvec(ctl, write, filp, buffer, lenp);
6694 + if (write && *(int *)(ctl->data))
6695 + *(int *)(ctl->data) = 1;
6699 +static ctl_table brnf_table[] = {
6701 + .ctl_name = NET_BRIDGE_NF_CALL_ARPTABLES,
6702 + .procname = "bridge-nf-call-arptables",
6703 + .data = &brnf_call_arptables,
6704 + .maxlen = sizeof(int),
6706 + .proc_handler = &brnf_sysctl_call_tables,
6709 + .ctl_name = NET_BRIDGE_NF_CALL_IPTABLES,
6710 + .procname = "bridge-nf-call-iptables",
6711 + .data = &brnf_call_iptables,
6712 + .maxlen = sizeof(int),
6714 + .proc_handler = &brnf_sysctl_call_tables,
6717 + .ctl_name = NET_BRIDGE_NF_CALL_IP6TABLES,
6718 + .procname = "bridge-nf-call-ip6tables",
6719 + .data = &brnf_call_ip6tables,
6720 + .maxlen = sizeof(int),
6722 + .proc_handler = &brnf_sysctl_call_tables,
6725 + .ctl_name = NET_BRIDGE_NF_FILTER_VLAN_TAGGED,
6726 + .procname = "bridge-nf-filter-vlan-tagged",
6727 + .data = &brnf_filter_vlan_tagged,
6728 + .maxlen = sizeof(int),
6730 + .proc_handler = &brnf_sysctl_call_tables,
6735 +static ctl_table brnf_bridge_table[] = {
6737 + .ctl_name = NET_BRIDGE,
6738 + .procname = "bridge",
6740 + .child = brnf_table,
6745 +static ctl_table brnf_net_table[] = {
6747 + .ctl_name = CTL_NET,
6748 + .procname = "net",
6750 + .child = brnf_bridge_table,
6756 +int br_netfilter_init(void)
6760 + for (i = 0; i < ARRAY_SIZE(br_nf_ops); i++) {
6763 + if ((ret = nf_register_hook(&br_nf_ops[i])) >= 0)
6767 + nf_unregister_hook(&br_nf_ops[i]);
6772 +#ifdef CONFIG_SYSCTL
6773 + brnf_sysctl_header = register_sysctl_table(brnf_net_table, 0);
6774 + if (brnf_sysctl_header == NULL) {
6775 + printk(KERN_WARNING "br_netfilter: can't register to sysctl.\n");
6776 + for (i = 0; i < ARRAY_SIZE(br_nf_ops); i++)
6777 + nf_unregister_hook(&br_nf_ops[i]);
6782 + printk(KERN_NOTICE "Bridge firewalling registered\n");
6787 +void br_netfilter_fini(void)
6791 + for (i = ARRAY_SIZE(br_nf_ops) - 1; i >= 0; i--)
6792 + nf_unregister_hook(&br_nf_ops[i]);
6793 +#ifdef CONFIG_SYSCTL
6794 + unregister_sysctl_table(brnf_sysctl_header);
6798 --- /dev/null 2005-03-14 20:10:29.001600248 +0100
6799 +++ linux-2.4.29-ebt-brnf/net/ipv4/netfilter/ipt_physdev.c 2005-03-14 00:00:30.000000000 +0100
6801 +/* Kernel module to match the bridge port in and
6802 + * out device for IP packets coming into contact with a bridge. */
6803 +#include <linux/module.h>
6804 +#include <linux/skbuff.h>
6805 +#include <linux/netfilter_ipv4/ipt_physdev.h>
6806 +#include <linux/netfilter_ipv4/ip_tables.h>
6807 +#include <linux/netfilter_bridge.h>
6808 +#include <linux/netdevice.h>
6813 +match(const struct sk_buff *skb,
6814 + const struct net_device *in,
6815 + const struct net_device *out,
6816 + const void *matchinfo,
6819 + u_int16_t datalen,
6823 + static const char nulldevname[IFNAMSIZ] = { 0 };
6824 + const struct ipt_physdev_info *info = matchinfo;
6825 + unsigned long ret;
6826 + const char *indev, *outdev;
6827 + struct nf_bridge_info *nf_bridge;
6829 + /* Not a bridged IP packet or no info available yet:
6830 + * LOCAL_OUT/mangle and LOCAL_OUT/nat don't know if
6831 + * the destination device will be a bridge. */
6832 + if (!(nf_bridge = skb->nf_bridge)) {
6833 + /* Return MATCH if the invert flags of the used options are on */
6834 + if ((info->bitmask & IPT_PHYSDEV_OP_BRIDGED) &&
6835 + !(info->invert & IPT_PHYSDEV_OP_BRIDGED))
6837 + if ((info->bitmask & IPT_PHYSDEV_OP_ISIN) &&
6838 + !(info->invert & IPT_PHYSDEV_OP_ISIN))
6840 + if ((info->bitmask & IPT_PHYSDEV_OP_ISOUT) &&
6841 + !(info->invert & IPT_PHYSDEV_OP_ISOUT))
6843 + if ((info->bitmask & IPT_PHYSDEV_OP_IN) &&
6844 + !(info->invert & IPT_PHYSDEV_OP_IN))
6846 + if ((info->bitmask & IPT_PHYSDEV_OP_OUT) &&
6847 + !(info->invert & IPT_PHYSDEV_OP_OUT))
6852 + /* This only makes sense in the FORWARD and POSTROUTING chains */
6853 + if ((info->bitmask & IPT_PHYSDEV_OP_BRIDGED) &&
6854 + (!!(nf_bridge->mask & BRNF_BRIDGED) ^
6855 + !(info->invert & IPT_PHYSDEV_OP_BRIDGED)))
6858 + if ((info->bitmask & IPT_PHYSDEV_OP_ISIN &&
6859 + (!nf_bridge->physindev ^ !!(info->invert & IPT_PHYSDEV_OP_ISIN))) ||
6860 + (info->bitmask & IPT_PHYSDEV_OP_ISOUT &&
6861 + (!nf_bridge->physoutdev ^ !!(info->invert & IPT_PHYSDEV_OP_ISOUT))))
6864 + if (!(info->bitmask & IPT_PHYSDEV_OP_IN))
6865 + goto match_outdev;
6866 + indev = nf_bridge->physindev ? nf_bridge->physindev->name : nulldevname;
6867 + for (i = 0, ret = 0; i < IFNAMSIZ/sizeof(unsigned long); i++) {
6868 + ret |= (((const unsigned long *)indev)[i]
6869 + ^ ((const unsigned long *)info->physindev)[i])
6870 + & ((const unsigned long *)info->in_mask)[i];
6873 + if ((ret == 0) ^ !(info->invert & IPT_PHYSDEV_OP_IN))
6877 + if (!(info->bitmask & IPT_PHYSDEV_OP_OUT))
6879 + outdev = nf_bridge->physoutdev ?
6880 + nf_bridge->physoutdev->name : nulldevname;
6881 + for (i = 0, ret = 0; i < IFNAMSIZ/sizeof(unsigned long); i++) {
6882 + ret |= (((const unsigned long *)outdev)[i]
6883 + ^ ((const unsigned long *)info->physoutdev)[i])
6884 + & ((const unsigned long *)info->out_mask)[i];
6887 + return (ret != 0) ^ !(info->invert & IPT_PHYSDEV_OP_OUT);
6891 +checkentry(const char *tablename,
6892 + const struct ipt_ip *ip,
6894 + unsigned int matchsize,
6895 + unsigned int hook_mask)
6897 + const struct ipt_physdev_info *info = matchinfo;
6899 + if (matchsize != IPT_ALIGN(sizeof(struct ipt_physdev_info)))
6901 + if (!(info->bitmask & IPT_PHYSDEV_OP_MASK) ||
6902 + info->bitmask & ~IPT_PHYSDEV_OP_MASK)
6907 +static struct ipt_match physdev_match = {
6908 + .name = "physdev",
6910 + .checkentry = &checkentry,
6911 + .me = THIS_MODULE,
6914 +static int __init init(void)
6916 + return ipt_register_match(&physdev_match);
6919 +static void __exit fini(void)
6921 + ipt_unregister_match(&physdev_match);
6926 +MODULE_LICENSE("GPL");
6928 --- /dev/null 2005-03-14 20:10:29.001600248 +0100
6929 +++ linux-2.4.29-ebt-brnf/include/linux/netfilter_ipv4/ipt_physdev.h 2005-03-14 21:24:30.000000000 +0100
6931 +#ifndef _IPT_PHYSDEV_H
6932 +#define _IPT_PHYSDEV_H
6935 +#include <linux/if.h>
6938 +#define IPT_PHYSDEV_OP_IN 0x01
6939 +#define IPT_PHYSDEV_OP_OUT 0x02
6940 +#define IPT_PHYSDEV_OP_BRIDGED 0x04
6941 +#define IPT_PHYSDEV_OP_ISIN 0x08
6942 +#define IPT_PHYSDEV_OP_ISOUT 0x10
6943 +#define IPT_PHYSDEV_OP_MASK (0x20 - 1)
6945 +struct ipt_physdev_info {
6946 + char physindev[IFNAMSIZ];
6947 + char in_mask[IFNAMSIZ];
6948 + char physoutdev[IFNAMSIZ];
6949 + char out_mask[IFNAMSIZ];
6954 +#endif /*_IPT_PHYSDEV_H*/
6955 --- linux-2.4.29/net/8021q/vlan_dev.c 2005-01-19 15:10:13.000000000 +0100
6956 +++ linux-2.4.29-ebt-brnf/net/8021q/vlan_dev.c 2005-03-14 00:00:30.000000000 +0100
6957 @@ -488,6 +488,10 @@ int vlan_dev_hard_start_xmit(struct sk_b
6958 stats->tx_packets++; /* for statics only */
6959 stats->tx_bytes += skb->len;
6961 + skb->protocol = __constant_htons(ETH_P_8021Q);
6962 + skb->mac.raw -= VLAN_HLEN;
6963 + skb->nh.raw -= VLAN_HLEN;
6965 skb->dev = VLAN_DEV_INFO(dev)->real_dev;
6966 dev_queue_xmit(skb);
6968 --- linux-2.4.29/include/linux/sysctl.h 2005-01-19 15:10:13.000000000 +0100
6969 +++ linux-2.4.29-ebt-brnf/include/linux/sysctl.h 2005-03-14 21:07:18.000000000 +0100
6970 @@ -608,6 +608,15 @@ enum {
6971 NET_DECNET_CONF_DEV_STATE = 7
6974 +/* /proc/sys/net/bridge */
6976 + NET_BRIDGE_NF_CALL_ARPTABLES = 1,
6977 + NET_BRIDGE_NF_CALL_IPTABLES = 2,
6978 + NET_BRIDGE_NF_CALL_IP6TABLES = 3,
6979 + NET_BRIDGE_NF_FILTER_VLAN_TAGGED = 4,
6983 /* CTL_PROC names: */
6986 --- linux-2.4.29/net/ipv4/netfilter/ipt_REJECT.c 2005-01-19 15:10:13.000000000 +0100
6987 +++ linux-2.4.29-ebt-brnf/net/ipv4/netfilter/ipt_REJECT.c 2005-03-14 00:00:30.000000000 +0100
6989 #include <net/route.h>
6990 #include <linux/netfilter_ipv4/ip_tables.h>
6991 #include <linux/netfilter_ipv4/ipt_REJECT.h>
6992 +#ifdef CONFIG_BRIDGE_NETFILTER
6993 +#include <linux/netfilter_bridge.h>
6997 #define DEBUGP printk
6998 @@ -29,7 +32,13 @@ static inline struct rtable *route_rever
6999 struct rt_key key = {};
7002 - if (hook != NF_IP_FORWARD) {
7003 + /* We don't require ip forwarding to be enabled to be able to
7004 + * send a RST reply for bridged traffic. */
7005 + if (hook != NF_IP_FORWARD
7006 +#ifdef CONFIG_BRIDGE_NETFILTER
7007 + || (skb->nf_bridge && skb->nf_bridge->mask & BRNF_BRIDGED)
7010 key.dst = iph->saddr;
7011 if (hook == NF_IP_LOCAL_IN)
7012 key.src = iph->daddr;