1 diff -Nur linux.old/include/linux/if_bridge.h linux.dev/include/linux/if_bridge.h
2 --- linux.old/include/linux/if_bridge.h 2001-11-22 20:47:12.000000000 +0100
3 +++ linux.dev/include/linux/if_bridge.h 2005-10-10 10:36:45.953860750 +0200
5 struct net_bridge_port;
7 extern int (*br_ioctl_hook)(unsigned long arg);
8 -extern void (*br_handle_frame_hook)(struct sk_buff *skb);
9 +extern int (*br_handle_frame_hook)(struct sk_buff *skb);
10 +extern int (*br_should_route_hook)(struct sk_buff **pskb);
14 diff -Nur linux.old/include/linux/netfilter.h linux.dev/include/linux/netfilter.h
15 --- linux.old/include/linux/netfilter.h 2005-01-19 15:10:12.000000000 +0100
16 +++ linux.dev/include/linux/netfilter.h 2005-10-10 10:36:46.145872750 +0200
21 -#define NF_MAX_VERDICT NF_REPEAT
23 +#define NF_MAX_VERDICT NF_STOP
25 /* Generic cache responses from hook functions.
26 <= 0x2000 is used for protocol-flags. */
28 /* This is gross, but inline doesn't cut it for avoiding the function
29 call in fast path: gcc doesn't inline (needs value tracking?). --RR */
30 #ifdef CONFIG_NETFILTER_DEBUG
31 -#define NF_HOOK nf_hook_slow
32 +#define NF_HOOK(pf, hook, skb, indev, outdev, okfn) \
34 +if ((__ret=nf_hook_slow(pf, hook, &(skb), indev, outdev, okfn, INT_MIN)) == 1) \
35 + __ret = (okfn)(skb); \
37 +#define NF_HOOK_THRESH(pf, hook, skb, indev, outdev, okfn, thresh) \
39 +if ((__ret=nf_hook_slow(pf, hook, &(skb), indev, outdev, okfn, thresh)) == 1) \
40 + __ret = (okfn)(skb); \
43 -#define NF_HOOK(pf, hook, skb, indev, outdev, okfn) \
44 -(list_empty(&nf_hooks[(pf)][(hook)]) \
46 - : nf_hook_slow((pf), (hook), (skb), (indev), (outdev), (okfn)))
47 +#define NF_HOOK(pf, hook, skb, indev, outdev, okfn) \
49 +if (list_empty(&nf_hooks[pf][hook]) || \
50 + (__ret=nf_hook_slow(pf, hook, &(skb), indev, outdev, okfn, INT_MIN)) == 1) \
51 + __ret = (okfn)(skb); \
53 +#define NF_HOOK_THRESH(pf, hook, skb, indev, outdev, okfn, thresh) \
55 +if (list_empty(&nf_hooks[pf][hook]) || \
56 + (__ret=nf_hook_slow(pf, hook, &(skb), indev, outdev, okfn, thresh)) == 1) \
57 + __ret = (okfn)(skb); \
61 -int nf_hook_slow(int pf, unsigned int hook, struct sk_buff *skb,
62 +int nf_hook_slow(int pf, unsigned int hook, struct sk_buff **pskb,
63 struct net_device *indev, struct net_device *outdev,
64 - int (*okfn)(struct sk_buff *));
65 + int (*okfn)(struct sk_buff *), int thresh);
67 /* Call setsockopt() */
68 int nf_setsockopt(struct sock *sk, int pf, int optval, char *opt,
69 diff -Nur linux.old/include/linux/netfilter_arp/arp_tables.h linux.dev/include/linux/netfilter_arp/arp_tables.h
70 --- linux.old/include/linux/netfilter_arp/arp_tables.h 2003-08-25 13:44:44.000000000 +0200
71 +++ linux.dev/include/linux/netfilter_arp/arp_tables.h 2005-10-10 10:36:46.065867750 +0200
73 #define ARPT_CONTINUE 0xFFFFFFFF
75 /* For standard target */
76 -#define ARPT_RETURN (-NF_MAX_VERDICT - 1)
77 +#define ARPT_RETURN (-NF_REPEAT - 1)
79 /* The argument to ARPT_SO_GET_INFO */
81 diff -Nur linux.old/include/linux/netfilter_bridge/ebt_802_3.h linux.dev/include/linux/netfilter_bridge/ebt_802_3.h
82 --- linux.old/include/linux/netfilter_bridge/ebt_802_3.h 1970-01-01 01:00:00.000000000 +0100
83 +++ linux.dev/include/linux/netfilter_bridge/ebt_802_3.h 2005-10-10 10:36:46.125871500 +0200
85 +#ifndef __LINUX_BRIDGE_EBT_802_3_H
86 +#define __LINUX_BRIDGE_EBT_802_3_H
88 +#define EBT_802_3_SAP 0x01
89 +#define EBT_802_3_TYPE 0x02
91 +#define EBT_802_3_MATCH "802_3"
94 + * If frame has DSAP/SSAP value 0xaa you must check the SNAP type
95 + * to discover what kind of packet we're carrying.
97 +#define CHECK_TYPE 0xaa
100 + * Control field may be one or two bytes. If the first byte has
101 + * the value 0x03 then the entire length is one byte, otherwise it is two.
102 + * One byte controls are used in Unnumbered Information frames.
103 + * Two byte controls are used in Numbered Information frames.
107 +#define EBT_802_3_MASK (EBT_802_3_SAP | EBT_802_3_TYPE | EBT_802_3)
109 +/* ui has one byte ctrl, ni has two */
126 +struct ebt_802_3_hdr {
136 +struct ebt_802_3_info
145 diff -Nur linux.old/include/linux/netfilter_bridge/ebt_among.h linux.dev/include/linux/netfilter_bridge/ebt_among.h
146 --- linux.old/include/linux/netfilter_bridge/ebt_among.h 1970-01-01 01:00:00.000000000 +0100
147 +++ linux.dev/include/linux/netfilter_bridge/ebt_among.h 2005-10-10 10:36:46.125871500 +0200
149 +#ifndef __LINUX_BRIDGE_EBT_AMONG_H
150 +#define __LINUX_BRIDGE_EBT_AMONG_H
152 +#define EBT_AMONG_DST 0x01
153 +#define EBT_AMONG_SRC 0x02
155 +/* Grzegorz Borowiak <grzes@gnu.univ.gda.pl> 2003
157 + * Write-once-read-many hash table, used for checking if a given
158 + * MAC address belongs to a set or not and possibly for checking
159 + * if it is related with a given IPv4 address.
161 + * The hash value of an address is its last byte.
163 + * In real-world ethernet addresses, values of the last byte are
164 + * evenly distributed and there is no need to consider other bytes.
165 + * It would only slow the routines down.
167 + * For MAC address comparison speedup reasons, we introduce a trick.
168 + * MAC address is mapped onto an array of two 32-bit integers.
169 + * This pair of integers is compared with MAC addresses in the
170 + * hash table, which are stored also in form of pairs of integers
171 + * (in `cmp' array). This is quick as it requires only two elementary
172 + * number comparisons in worst case. Further, we take advantage of
173 + * fact that entropy of 3 last bytes of address is larger than entropy
174 + * of 3 first bytes. So first we compare 4 last bytes of addresses and
175 + * if they are the same we compare 2 first.
177 + * Yes, it is a memory overhead, but in 2003 AD, who cares?
180 +struct ebt_mac_wormhash_tuple
186 +struct ebt_mac_wormhash
190 + struct ebt_mac_wormhash_tuple pool[0];
193 +#define ebt_mac_wormhash_size(x) ((x) ? sizeof(struct ebt_mac_wormhash) \
194 + + (x)->poolsize * sizeof(struct ebt_mac_wormhash_tuple) : 0)
196 +struct ebt_among_info
203 +#define EBT_AMONG_DST_NEG 0x1
204 +#define EBT_AMONG_SRC_NEG 0x2
206 +#define ebt_among_wh_dst(x) ((x)->wh_dst_ofs ? \
207 + (struct ebt_mac_wormhash*)((char*)(x) + (x)->wh_dst_ofs) : NULL)
208 +#define ebt_among_wh_src(x) ((x)->wh_src_ofs ? \
209 + (struct ebt_mac_wormhash*)((char*)(x) + (x)->wh_src_ofs) : NULL)
211 +#define EBT_AMONG_MATCH "among"
214 diff -Nur linux.old/include/linux/netfilter_bridge/ebt_arp.h linux.dev/include/linux/netfilter_bridge/ebt_arp.h
215 --- linux.old/include/linux/netfilter_bridge/ebt_arp.h 1970-01-01 01:00:00.000000000 +0100
216 +++ linux.dev/include/linux/netfilter_bridge/ebt_arp.h 2005-10-10 10:36:46.125871500 +0200
218 +#ifndef __LINUX_BRIDGE_EBT_ARP_H
219 +#define __LINUX_BRIDGE_EBT_ARP_H
221 +#define EBT_ARP_OPCODE 0x01
222 +#define EBT_ARP_HTYPE 0x02
223 +#define EBT_ARP_PTYPE 0x04
224 +#define EBT_ARP_SRC_IP 0x08
225 +#define EBT_ARP_DST_IP 0x10
226 +#define EBT_ARP_SRC_MAC 0x20
227 +#define EBT_ARP_DST_MAC 0x40
228 +#define EBT_ARP_MASK (EBT_ARP_OPCODE | EBT_ARP_HTYPE | EBT_ARP_PTYPE | \
229 + EBT_ARP_SRC_IP | EBT_ARP_DST_IP | EBT_ARP_SRC_MAC | EBT_ARP_DST_MAC)
230 +#define EBT_ARP_MATCH "arp"
241 + unsigned char smaddr[ETH_ALEN];
242 + unsigned char smmsk[ETH_ALEN];
243 + unsigned char dmaddr[ETH_ALEN];
244 + unsigned char dmmsk[ETH_ALEN];
250 diff -Nur linux.old/include/linux/netfilter_bridge/ebt_arpreply.h linux.dev/include/linux/netfilter_bridge/ebt_arpreply.h
251 --- linux.old/include/linux/netfilter_bridge/ebt_arpreply.h 1970-01-01 01:00:00.000000000 +0100
252 +++ linux.dev/include/linux/netfilter_bridge/ebt_arpreply.h 2005-10-10 10:36:46.125871500 +0200
254 +#ifndef __LINUX_BRIDGE_EBT_ARPREPLY_H
255 +#define __LINUX_BRIDGE_EBT_ARPREPLY_H
257 +struct ebt_arpreply_info
259 + unsigned char mac[ETH_ALEN];
262 +#define EBT_ARPREPLY_TARGET "arpreply"
265 diff -Nur linux.old/include/linux/netfilter_bridge/ebt_ip.h linux.dev/include/linux/netfilter_bridge/ebt_ip.h
266 --- linux.old/include/linux/netfilter_bridge/ebt_ip.h 1970-01-01 01:00:00.000000000 +0100
267 +++ linux.dev/include/linux/netfilter_bridge/ebt_ip.h 2005-10-10 10:36:46.125871500 +0200
273 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
278 + * added ip-sport and ip-dport
279 + * Innominate Security Technologies AG <mhopf@innominate.com>
283 +#ifndef __LINUX_BRIDGE_EBT_IP_H
284 +#define __LINUX_BRIDGE_EBT_IP_H
286 +#define EBT_IP_SOURCE 0x01
287 +#define EBT_IP_DEST 0x02
288 +#define EBT_IP_TOS 0x04
289 +#define EBT_IP_PROTO 0x08
290 +#define EBT_IP_SPORT 0x10
291 +#define EBT_IP_DPORT 0x20
292 +#define EBT_IP_MASK (EBT_IP_SOURCE | EBT_IP_DEST | EBT_IP_TOS | EBT_IP_PROTO |\
293 + EBT_IP_SPORT | EBT_IP_DPORT )
294 +#define EBT_IP_MATCH "ip"
296 +// the same values are used for the invflags
312 diff -Nur linux.old/include/linux/netfilter_bridge/ebt_limit.h linux.dev/include/linux/netfilter_bridge/ebt_limit.h
313 --- linux.old/include/linux/netfilter_bridge/ebt_limit.h 1970-01-01 01:00:00.000000000 +0100
314 +++ linux.dev/include/linux/netfilter_bridge/ebt_limit.h 2005-10-10 10:36:46.125871500 +0200
316 +#ifndef __LINUX_BRIDGE_EBT_LIMIT_H
317 +#define __LINUX_BRIDGE_EBT_LIMIT_H
319 +#define EBT_LIMIT_MATCH "limit"
321 +/* timings are in milliseconds. */
322 +#define EBT_LIMIT_SCALE 10000
324 +/* 1/10,000 sec period => max of 10,000/sec. Min rate is then 429490
325 + seconds, or one every 59 hours. */
327 +struct ebt_limit_info
329 + u_int32_t avg; /* Average secs between packets * scale */
330 + u_int32_t burst; /* Period multiplier for upper limit. */
332 + /* Used internally by the kernel */
333 + unsigned long prev;
335 + u_int32_t credit_cap, cost;
339 diff -Nur linux.old/include/linux/netfilter_bridge/ebt_log.h linux.dev/include/linux/netfilter_bridge/ebt_log.h
340 --- linux.old/include/linux/netfilter_bridge/ebt_log.h 1970-01-01 01:00:00.000000000 +0100
341 +++ linux.dev/include/linux/netfilter_bridge/ebt_log.h 2005-10-10 10:36:46.125871500 +0200
343 +#ifndef __LINUX_BRIDGE_EBT_LOG_H
344 +#define __LINUX_BRIDGE_EBT_LOG_H
346 +#define EBT_LOG_IP 0x01 // if the frame is made by ip, log the ip information
347 +#define EBT_LOG_ARP 0x02
348 +#define EBT_LOG_MASK (EBT_LOG_IP | EBT_LOG_ARP)
349 +#define EBT_LOG_PREFIX_SIZE 30
350 +#define EBT_LOG_WATCHER "log"
355 + uint8_t prefix[EBT_LOG_PREFIX_SIZE];
360 diff -Nur linux.old/include/linux/netfilter_bridge/ebt_mark_m.h linux.dev/include/linux/netfilter_bridge/ebt_mark_m.h
361 --- linux.old/include/linux/netfilter_bridge/ebt_mark_m.h 1970-01-01 01:00:00.000000000 +0100
362 +++ linux.dev/include/linux/netfilter_bridge/ebt_mark_m.h 2005-10-10 10:36:46.129871750 +0200
364 +#ifndef __LINUX_BRIDGE_EBT_MARK_M_H
365 +#define __LINUX_BRIDGE_EBT_MARK_M_H
367 +#define EBT_MARK_AND 0x01
368 +#define EBT_MARK_OR 0x02
369 +#define EBT_MARK_MASK (EBT_MARK_AND | EBT_MARK_OR)
370 +struct ebt_mark_m_info
372 + unsigned long mark, mask;
376 +#define EBT_MARK_MATCH "mark_m"
379 diff -Nur linux.old/include/linux/netfilter_bridge/ebt_mark_t.h linux.dev/include/linux/netfilter_bridge/ebt_mark_t.h
380 --- linux.old/include/linux/netfilter_bridge/ebt_mark_t.h 1970-01-01 01:00:00.000000000 +0100
381 +++ linux.dev/include/linux/netfilter_bridge/ebt_mark_t.h 2005-10-10 10:36:46.129871750 +0200
383 +#ifndef __LINUX_BRIDGE_EBT_MARK_T_H
384 +#define __LINUX_BRIDGE_EBT_MARK_T_H
386 +struct ebt_mark_t_info
388 + unsigned long mark;
389 + // EBT_ACCEPT, EBT_DROP or EBT_CONTINUE or EBT_RETURN
392 +#define EBT_MARK_TARGET "mark"
395 diff -Nur linux.old/include/linux/netfilter_bridge/ebt_nat.h linux.dev/include/linux/netfilter_bridge/ebt_nat.h
396 --- linux.old/include/linux/netfilter_bridge/ebt_nat.h 1970-01-01 01:00:00.000000000 +0100
397 +++ linux.dev/include/linux/netfilter_bridge/ebt_nat.h 2005-10-10 10:36:46.129871750 +0200
399 +#ifndef __LINUX_BRIDGE_EBT_NAT_H
400 +#define __LINUX_BRIDGE_EBT_NAT_H
404 + unsigned char mac[ETH_ALEN];
405 + // EBT_ACCEPT, EBT_DROP, EBT_CONTINUE or EBT_RETURN
408 +#define EBT_SNAT_TARGET "snat"
409 +#define EBT_DNAT_TARGET "dnat"
412 diff -Nur linux.old/include/linux/netfilter_bridge/ebt_pkttype.h linux.dev/include/linux/netfilter_bridge/ebt_pkttype.h
413 --- linux.old/include/linux/netfilter_bridge/ebt_pkttype.h 1970-01-01 01:00:00.000000000 +0100
414 +++ linux.dev/include/linux/netfilter_bridge/ebt_pkttype.h 2005-10-10 10:36:46.125871500 +0200
416 +#ifndef __LINUX_BRIDGE_EBT_PKTTYPE_H
417 +#define __LINUX_BRIDGE_EBT_PKTTYPE_H
419 +struct ebt_pkttype_info
424 +#define EBT_PKTTYPE_MATCH "pkttype"
427 diff -Nur linux.old/include/linux/netfilter_bridge/ebt_redirect.h linux.dev/include/linux/netfilter_bridge/ebt_redirect.h
428 --- linux.old/include/linux/netfilter_bridge/ebt_redirect.h 1970-01-01 01:00:00.000000000 +0100
429 +++ linux.dev/include/linux/netfilter_bridge/ebt_redirect.h 2005-10-10 10:36:46.129871750 +0200
431 +#ifndef __LINUX_BRIDGE_EBT_REDIRECT_H
432 +#define __LINUX_BRIDGE_EBT_REDIRECT_H
434 +struct ebt_redirect_info
436 + // EBT_ACCEPT, EBT_DROP or EBT_CONTINUE or EBT_RETURN
439 +#define EBT_REDIRECT_TARGET "redirect"
442 diff -Nur linux.old/include/linux/netfilter_bridge/ebt_stp.h linux.dev/include/linux/netfilter_bridge/ebt_stp.h
443 --- linux.old/include/linux/netfilter_bridge/ebt_stp.h 1970-01-01 01:00:00.000000000 +0100
444 +++ linux.dev/include/linux/netfilter_bridge/ebt_stp.h 2005-10-10 10:36:46.125871500 +0200
446 +#ifndef __LINUX_BRIDGE_EBT_STP_H
447 +#define __LINUX_BRIDGE_EBT_STP_H
449 +#define EBT_STP_TYPE 0x0001
451 +#define EBT_STP_FLAGS 0x0002
452 +#define EBT_STP_ROOTPRIO 0x0004
453 +#define EBT_STP_ROOTADDR 0x0008
454 +#define EBT_STP_ROOTCOST 0x0010
455 +#define EBT_STP_SENDERPRIO 0x0020
456 +#define EBT_STP_SENDERADDR 0x0040
457 +#define EBT_STP_PORT 0x0080
458 +#define EBT_STP_MSGAGE 0x0100
459 +#define EBT_STP_MAXAGE 0x0200
460 +#define EBT_STP_HELLOTIME 0x0400
461 +#define EBT_STP_FWDD 0x0800
463 +#define EBT_STP_MASK 0x0fff
464 +#define EBT_STP_CONFIG_MASK 0x0ffe
466 +#define EBT_STP_MATCH "stp"
468 +struct ebt_stp_config_info
471 + uint16_t root_priol, root_priou;
472 + char root_addr[6], root_addrmsk[6];
473 + uint32_t root_costl, root_costu;
474 + uint16_t sender_priol, sender_priou;
475 + char sender_addr[6], sender_addrmsk[6];
476 + uint16_t portl, portu;
477 + uint16_t msg_agel, msg_ageu;
478 + uint16_t max_agel, max_ageu;
479 + uint16_t hello_timel, hello_timeu;
480 + uint16_t forward_delayl, forward_delayu;
486 + struct ebt_stp_config_info config;
492 diff -Nur linux.old/include/linux/netfilter_bridge/ebt_ulog.h linux.dev/include/linux/netfilter_bridge/ebt_ulog.h
493 --- linux.old/include/linux/netfilter_bridge/ebt_ulog.h 1970-01-01 01:00:00.000000000 +0100
494 +++ linux.dev/include/linux/netfilter_bridge/ebt_ulog.h 2005-10-10 10:36:46.129871750 +0200
499 +#define EBT_ULOG_DEFAULT_NLGROUP 0
500 +#define EBT_ULOG_DEFAULT_QTHRESHOLD 1
501 +#define EBT_ULOG_MAXNLGROUPS 32 /* hardcoded netlink max */
502 +#define EBT_ULOG_PREFIX_LEN 32
503 +#define EBT_ULOG_MAX_QLEN 50
504 +#define EBT_ULOG_WATCHER "ulog"
506 +struct ebt_ulog_info {
508 + unsigned int cprange;
509 + unsigned int qthreshold;
510 + char prefix[EBT_ULOG_PREFIX_LEN];
513 +typedef struct ebt_ulog_packet_msg {
514 + char indev[IFNAMSIZ];
515 + char outdev[IFNAMSIZ];
516 + char physindev[IFNAMSIZ];
517 + char physoutdev[IFNAMSIZ];
518 + char prefix[EBT_ULOG_PREFIX_LEN];
519 + struct timeval stamp;
520 + unsigned long mark;
523 + /* The complete packet, including Ethernet header and perhaps
524 + * the VLAN header is appended */
525 + unsigned char data[0] __attribute__ ((aligned (__alignof__(int))));
526 +} ebt_ulog_packet_msg_t;
528 +#endif /* _EBT_ULOG_H */
529 diff -Nur linux.old/include/linux/netfilter_bridge/ebt_vlan.h linux.dev/include/linux/netfilter_bridge/ebt_vlan.h
530 --- linux.old/include/linux/netfilter_bridge/ebt_vlan.h 1970-01-01 01:00:00.000000000 +0100
531 +++ linux.dev/include/linux/netfilter_bridge/ebt_vlan.h 2005-10-10 10:36:46.125871500 +0200
533 +#ifndef __LINUX_BRIDGE_EBT_VLAN_H
534 +#define __LINUX_BRIDGE_EBT_VLAN_H
536 +#define EBT_VLAN_ID 0x01
537 +#define EBT_VLAN_PRIO 0x02
538 +#define EBT_VLAN_ENCAP 0x04
539 +#define EBT_VLAN_MASK (EBT_VLAN_ID | EBT_VLAN_PRIO | EBT_VLAN_ENCAP)
540 +#define EBT_VLAN_MATCH "vlan"
542 +struct ebt_vlan_info {
543 + uint16_t id; /* VLAN ID {1-4095} */
544 + uint8_t prio; /* VLAN User Priority {0-7} */
545 + uint16_t encap; /* VLAN Encapsulated frame code {0-65535} */
546 + uint8_t bitmask; /* Args bitmask bit 1=1 - ID arg,
547 + bit 2=1 User-Priority arg, bit 3=1 encap*/
548 + uint8_t invflags; /* Inverse bitmask bit 1=1 - inversed ID arg,
549 + bit 2=1 - inversed Pirority arg */
553 diff -Nur linux.old/include/linux/netfilter_bridge/ebtables.h linux.dev/include/linux/netfilter_bridge/ebtables.h
554 --- linux.old/include/linux/netfilter_bridge/ebtables.h 1970-01-01 01:00:00.000000000 +0100
555 +++ linux.dev/include/linux/netfilter_bridge/ebtables.h 2005-10-10 10:36:46.125871500 +0200
561 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
563 + * ebtables.c,v 2.0, September, 2002
565 + * This code is stongly inspired on the iptables code which is
566 + * Copyright (C) 1999 Paul `Rusty' Russell & Michael J. Neuling
569 +#ifndef __LINUX_BRIDGE_EFF_H
570 +#define __LINUX_BRIDGE_EFF_H
571 +#include <linux/if.h>
572 +#include <linux/netfilter_bridge.h>
573 +#include <linux/if_ether.h>
575 +#define EBT_TABLE_MAXNAMELEN 32
576 +#define EBT_CHAIN_MAXNAMELEN EBT_TABLE_MAXNAMELEN
577 +#define EBT_FUNCTION_MAXNAMELEN EBT_TABLE_MAXNAMELEN
579 +// verdicts >0 are "branches"
580 +#define EBT_ACCEPT -1
582 +#define EBT_CONTINUE -3
583 +#define EBT_RETURN -4
584 +#define NUM_STANDARD_TARGETS 4
592 +struct ebt_entries {
593 + // this field is always set to zero
594 + // See EBT_ENTRY_OR_ENTRIES.
595 + // Must be same size as ebt_entry.bitmask
596 + unsigned int distinguisher;
598 + char name[EBT_CHAIN_MAXNAMELEN];
599 + // counter offset for this chain
600 + unsigned int counter_offset;
601 + // one standard (accept, drop, return) per hook
604 + unsigned int nentries;
609 +// used for the bitmask of struct ebt_entry
611 +// This is a hack to make a difference between an ebt_entry struct and an
612 +// ebt_entries struct when traversing the entries from start to end.
613 +// Using this simplifies the code alot, while still being able to use
615 +// Contrary, iptables doesn't use something like ebt_entries and therefore uses
616 +// different techniques for naming the policy and such. So, iptables doesn't
617 +// need a hack like this.
618 +#define EBT_ENTRY_OR_ENTRIES 0x01
619 +// these are the normal masks
620 +#define EBT_NOPROTO 0x02
621 +#define EBT_802_3 0x04
622 +#define EBT_SOURCEMAC 0x08
623 +#define EBT_DESTMAC 0x10
624 +#define EBT_F_MASK (EBT_NOPROTO | EBT_802_3 | EBT_SOURCEMAC | EBT_DESTMAC \
625 + | EBT_ENTRY_OR_ENTRIES)
627 +#define EBT_IPROTO 0x01
628 +#define EBT_IIN 0x02
629 +#define EBT_IOUT 0x04
630 +#define EBT_ISOURCE 0x8
631 +#define EBT_IDEST 0x10
632 +#define EBT_ILOGICALIN 0x20
633 +#define EBT_ILOGICALOUT 0x40
634 +#define EBT_INV_MASK (EBT_IPROTO | EBT_IIN | EBT_IOUT | EBT_ILOGICALIN \
635 + | EBT_ILOGICALOUT | EBT_ISOURCE | EBT_IDEST)
637 +struct ebt_entry_match
640 + char name[EBT_FUNCTION_MAXNAMELEN];
641 + struct ebt_match *match;
644 + unsigned int match_size;
645 + unsigned char data[0];
648 +struct ebt_entry_watcher
651 + char name[EBT_FUNCTION_MAXNAMELEN];
652 + struct ebt_watcher *watcher;
655 + unsigned int watcher_size;
656 + unsigned char data[0];
659 +struct ebt_entry_target
662 + char name[EBT_FUNCTION_MAXNAMELEN];
663 + struct ebt_target *target;
666 + unsigned int target_size;
667 + unsigned char data[0];
670 +#define EBT_STANDARD_TARGET "standard"
671 +struct ebt_standard_target
673 + struct ebt_entry_target target;
679 + // this needs to be the first field
680 + unsigned int bitmask;
681 + unsigned int invflags;
683 + // the physical in-dev
685 + // the logical in-dev
686 + char logical_in[IFNAMSIZ];
687 + // the physical out-dev
688 + char out[IFNAMSIZ];
689 + // the logical out-dev
690 + char logical_out[IFNAMSIZ];
691 + unsigned char sourcemac[ETH_ALEN];
692 + unsigned char sourcemsk[ETH_ALEN];
693 + unsigned char destmac[ETH_ALEN];
694 + unsigned char destmsk[ETH_ALEN];
695 + // sizeof ebt_entry + matches
696 + unsigned int watchers_offset;
697 + // sizeof ebt_entry + matches + watchers
698 + unsigned int target_offset;
699 + // sizeof ebt_entry + matches + watchers + target
700 + unsigned int next_offset;
701 + unsigned char elems[0];
706 + char name[EBT_TABLE_MAXNAMELEN];
707 + unsigned int valid_hooks;
708 + // nr of rules in the table
709 + unsigned int nentries;
710 + // total size of the entries
711 + unsigned int entries_size;
712 + // start of the chains
713 + struct ebt_entries *hook_entry[NF_BR_NUMHOOKS];
714 + // nr of counters userspace expects back
715 + unsigned int num_counters;
716 + // where the kernel will put the old counters
717 + struct ebt_counter *counters;
721 +// [gs]etsockopt numbers
722 +#define EBT_BASE_CTL 128
724 +#define EBT_SO_SET_ENTRIES (EBT_BASE_CTL)
725 +#define EBT_SO_SET_COUNTERS (EBT_SO_SET_ENTRIES+1)
726 +#define EBT_SO_SET_MAX (EBT_SO_SET_COUNTERS+1)
728 +#define EBT_SO_GET_INFO (EBT_BASE_CTL)
729 +#define EBT_SO_GET_ENTRIES (EBT_SO_GET_INFO+1)
730 +#define EBT_SO_GET_INIT_INFO (EBT_SO_GET_ENTRIES+1)
731 +#define EBT_SO_GET_INIT_ENTRIES (EBT_SO_GET_INIT_INFO+1)
732 +#define EBT_SO_GET_MAX (EBT_SO_GET_INIT_ENTRIES+1)
736 +// return values for match() functions
738 +#define EBT_NOMATCH 1
742 + struct list_head list;
743 + const char name[EBT_FUNCTION_MAXNAMELEN];
745 + int (*match)(const struct sk_buff *skb, const struct net_device *in,
746 + const struct net_device *out, const void *matchdata,
747 + unsigned int datalen);
749 + int (*check)(const char *tablename, unsigned int hookmask,
750 + const struct ebt_entry *e, void *matchdata, unsigned int datalen);
751 + void (*destroy)(void *matchdata, unsigned int datalen);
757 + struct list_head list;
758 + const char name[EBT_FUNCTION_MAXNAMELEN];
759 + void (*watcher)(const struct sk_buff *skb, unsigned int hooknr,
760 + const struct net_device *in, const struct net_device *out,
761 + const void *watcherdata, unsigned int datalen);
763 + int (*check)(const char *tablename, unsigned int hookmask,
764 + const struct ebt_entry *e, void *watcherdata, unsigned int datalen);
765 + void (*destroy)(void *watcherdata, unsigned int datalen);
771 + struct list_head list;
772 + const char name[EBT_FUNCTION_MAXNAMELEN];
773 + // returns one of the standard verdicts
774 + int (*target)(struct sk_buff **pskb, unsigned int hooknr,
775 + const struct net_device *in, const struct net_device *out,
776 + const void *targetdata, unsigned int datalen);
778 + int (*check)(const char *tablename, unsigned int hookmask,
779 + const struct ebt_entry *e, void *targetdata, unsigned int datalen);
780 + void (*destroy)(void *targetdata, unsigned int datalen);
784 +// used for jumping from and into user defined chains (udc)
785 +struct ebt_chainstack
787 + struct ebt_entries *chaininfo; // pointer to chain data
788 + struct ebt_entry *e; // pointer to entry data
789 + unsigned int n; // n'th entry
792 +struct ebt_table_info
794 + // total size of the entries
795 + unsigned int entries_size;
796 + unsigned int nentries;
797 + // pointers to the start of the chains
798 + struct ebt_entries *hook_entry[NF_BR_NUMHOOKS];
799 + // room to maintain the stack used for jumping from and into udc
800 + struct ebt_chainstack **chainstack;
802 + struct ebt_counter counters[0] ____cacheline_aligned;
807 + struct list_head list;
808 + char name[EBT_TABLE_MAXNAMELEN];
809 + struct ebt_replace *table;
810 + unsigned int valid_hooks;
812 + // e.g. could be the table explicitly only allows certain
813 + // matches, targets, ... 0 == let it in
814 + int (*check)(const struct ebt_table_info *info,
815 + unsigned int valid_hooks);
816 + // the data used by the kernel
817 + struct ebt_table_info *private;
820 +#define EBT_ALIGN(s) (((s) + (__alignof__(struct ebt_entry_target)-1)) & \
821 + ~(__alignof__(struct ebt_entry_target)-1))
822 +extern int ebt_register_table(struct ebt_table *table);
823 +extern void ebt_unregister_table(struct ebt_table *table);
824 +extern int ebt_register_match(struct ebt_match *match);
825 +extern void ebt_unregister_match(struct ebt_match *match);
826 +extern int ebt_register_watcher(struct ebt_watcher *watcher);
827 +extern void ebt_unregister_watcher(struct ebt_watcher *watcher);
828 +extern int ebt_register_target(struct ebt_target *target);
829 +extern void ebt_unregister_target(struct ebt_target *target);
830 +extern unsigned int ebt_do_table(unsigned int hook, struct sk_buff **pskb,
831 + const struct net_device *in, const struct net_device *out,
832 + struct ebt_table *table);
834 + // Used in the kernel match() functions
835 +#define FWINV(bool,invflg) ((bool) ^ !!(info->invflags & invflg))
836 +// True if the hook mask denotes that the rule is in a base chain,
837 +// used in the check() functions
838 +#define BASE_CHAIN (hookmask & (1 << NF_BR_NUMHOOKS))
839 +// Clear the bit in the hook mask that tells if the rule is on a base chain
840 +#define CLEAR_BASE_CHAIN_BIT (hookmask &= ~(1 << NF_BR_NUMHOOKS))
841 +// True if the target is not a standard target
842 +#define INVALID_TARGET (info->target < -NUM_STANDARD_TARGETS || info->target >= 0)
844 +#endif /* __KERNEL__ */
846 +// blatently stolen from ip_tables.h
847 +// fn returns 0 to continue iteration
848 +#define EBT_MATCH_ITERATE(e, fn, args...) \
850 + unsigned int __i; \
852 + struct ebt_entry_match *__match; \
854 + for (__i = sizeof(struct ebt_entry); \
855 + __i < (e)->watchers_offset; \
856 + __i += __match->match_size + \
857 + sizeof(struct ebt_entry_match)) { \
858 + __match = (void *)(e) + __i; \
860 + __ret = fn(__match , ## args); \
864 + if (__ret == 0) { \
865 + if (__i != (e)->watchers_offset) \
871 +#define EBT_WATCHER_ITERATE(e, fn, args...) \
873 + unsigned int __i; \
875 + struct ebt_entry_watcher *__watcher; \
877 + for (__i = e->watchers_offset; \
878 + __i < (e)->target_offset; \
879 + __i += __watcher->watcher_size + \
880 + sizeof(struct ebt_entry_watcher)) { \
881 + __watcher = (void *)(e) + __i; \
883 + __ret = fn(__watcher , ## args); \
887 + if (__ret == 0) { \
888 + if (__i != (e)->target_offset) \
894 +#define EBT_ENTRY_ITERATE(entries, size, fn, args...) \
896 + unsigned int __i; \
898 + struct ebt_entry *__entry; \
900 + for (__i = 0; __i < (size);) { \
901 + __entry = (void *)(entries) + __i; \
902 + __ret = fn(__entry , ## args); \
905 + if (__entry->bitmask != 0) \
906 + __i += __entry->next_offset; \
908 + __i += sizeof(struct ebt_entries); \
910 + if (__ret == 0) { \
911 + if (__i != (size)) \
918 diff -Nur linux.old/include/linux/netfilter_bridge.h linux.dev/include/linux/netfilter_bridge.h
919 --- linux.old/include/linux/netfilter_bridge.h 2001-06-12 04:15:27.000000000 +0200
920 +++ linux.dev/include/linux/netfilter_bridge.h 2005-10-10 10:36:45.989863000 +0200
923 #include <linux/config.h>
924 #include <linux/netfilter.h>
925 +#if defined(__KERNEL__) && defined(CONFIG_NETFILTER)
926 +#include <asm/atomic.h>
927 +#include <linux/if_ether.h>
931 /* After promisc drops, checksum checks. */
933 #define NF_BR_LOCAL_OUT 3
934 /* Packets about to hit the wire. */
935 #define NF_BR_POST_ROUTING 4
936 -#define NF_BR_NUMHOOKS 5
937 +/* Not really a hook, but used for the ebtables broute table */
938 +#define NF_BR_BROUTING 5
939 +#define NF_BR_NUMHOOKS 6
943 +#define BRNF_PKT_TYPE 0x01
944 +#define BRNF_BRIDGED_DNAT 0x02
945 +#define BRNF_DONT_TAKE_PARENT 0x04
946 +#define BRNF_BRIDGED 0x08
947 +#define BRNF_NF_BRIDGE_PREROUTING 0x10
949 +enum nf_br_hook_priorities {
950 + NF_BR_PRI_FIRST = INT_MIN,
951 + NF_BR_PRI_NAT_DST_BRIDGED = -300,
952 + NF_BR_PRI_FILTER_BRIDGED = -200,
953 + NF_BR_PRI_BRNF = 0,
954 + NF_BR_PRI_NAT_DST_OTHER = 100,
955 + NF_BR_PRI_FILTER_OTHER = 200,
956 + NF_BR_PRI_NAT_SRC = 300,
957 + NF_BR_PRI_LAST = INT_MAX,
960 +#ifdef CONFIG_NETFILTER
962 +struct nf_bridge_info *nf_bridge_alloc(struct sk_buff *skb)
964 + struct nf_bridge_info **nf_bridge = &(skb->nf_bridge);
966 + if ((*nf_bridge = kmalloc(sizeof(**nf_bridge), GFP_ATOMIC)) != NULL) {
967 + atomic_set(&(*nf_bridge)->use, 1);
968 + (*nf_bridge)->mask = 0;
969 + (*nf_bridge)->physindev = (*nf_bridge)->physoutdev = NULL;
970 +#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
971 + (*nf_bridge)->netoutdev = NULL;
978 +/* Only used in br_forward.c */
980 +void nf_bridge_maybe_copy_header(struct sk_buff *skb)
982 + if (skb->nf_bridge) {
983 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
984 + memcpy(skb->data - 18, skb->nf_bridge->data, 18);
987 + memcpy(skb->data - 16, skb->nf_bridge->data, 16);
992 +void nf_bridge_save_header(struct sk_buff *skb)
994 + int header_size = 16;
996 + if (skb->protocol == __constant_htons(ETH_P_8021Q))
998 + memcpy(skb->nf_bridge->data, skb->data - header_size, header_size);
1001 +struct bridge_skb_cb {
1008 +/* This is called by the IP fragmenting code and it ensures there is
1009 + * enough room for the encapsulating header (if there is one). */
1011 +int nf_bridge_pad(struct sk_buff *skb)
1013 + if (skb->nf_bridge) {
1014 + if (skb->protocol == __constant_htons(ETH_P_8021Q))
1019 +#endif /* CONFIG_NETFILTER */
1021 +#endif /* __KERNEL__ */
1023 diff -Nur linux.old/include/linux/netfilter_ipv4/ip_tables.h linux.dev/include/linux/netfilter_ipv4/ip_tables.h
1024 --- linux.old/include/linux/netfilter_ipv4/ip_tables.h 2005-10-10 10:33:04.011990250 +0200
1025 +++ linux.dev/include/linux/netfilter_ipv4/ip_tables.h 2005-10-10 10:36:46.021865000 +0200
1027 #define IPT_CONTINUE 0xFFFFFFFF
1029 /* For standard target */
1030 -#define IPT_RETURN (-NF_MAX_VERDICT - 1)
1031 +#define IPT_RETURN (-NF_REPEAT - 1)
1033 /* TCP matching stuff */
1035 diff -Nur linux.old/include/linux/netfilter_ipv4/ipt_physdev.h linux.dev/include/linux/netfilter_ipv4/ipt_physdev.h
1036 --- linux.old/include/linux/netfilter_ipv4/ipt_physdev.h 1970-01-01 01:00:00.000000000 +0100
1037 +++ linux.dev/include/linux/netfilter_ipv4/ipt_physdev.h 2005-10-10 10:36:46.293882000 +0200
1039 +#ifndef _IPT_PHYSDEV_H
1040 +#define _IPT_PHYSDEV_H
1043 +#include <linux/if.h>
1046 +#define IPT_PHYSDEV_OP_IN 0x01
1047 +#define IPT_PHYSDEV_OP_OUT 0x02
1048 +#define IPT_PHYSDEV_OP_BRIDGED 0x04
1049 +#define IPT_PHYSDEV_OP_ISIN 0x08
1050 +#define IPT_PHYSDEV_OP_ISOUT 0x10
1051 +#define IPT_PHYSDEV_OP_MASK (0x20 - 1)
1053 +struct ipt_physdev_info {
1054 + char physindev[IFNAMSIZ];
1055 + char in_mask[IFNAMSIZ];
1056 + char physoutdev[IFNAMSIZ];
1057 + char out_mask[IFNAMSIZ];
1062 +#endif /*_IPT_PHYSDEV_H*/
1063 diff -Nur linux.old/include/linux/netfilter_ipv4.h linux.dev/include/linux/netfilter_ipv4.h
1064 --- linux.old/include/linux/netfilter_ipv4.h 2002-02-25 20:38:13.000000000 +0100
1065 +++ linux.dev/include/linux/netfilter_ipv4.h 2005-10-10 10:36:46.161873750 +0200
1067 enum nf_ip_hook_priorities {
1068 NF_IP_PRI_FIRST = INT_MIN,
1069 NF_IP_PRI_CONNTRACK = -200,
1070 + NF_IP_PRI_BRIDGE_SABOTAGE_FORWARD = -175,
1071 NF_IP_PRI_MANGLE = -150,
1072 NF_IP_PRI_NAT_DST = -100,
1073 + NF_IP_PRI_BRIDGE_SABOTAGE_LOCAL_OUT = -50,
1074 NF_IP_PRI_FILTER = 0,
1075 NF_IP_PRI_NAT_SRC = 100,
1076 NF_IP_PRI_LAST = INT_MAX,
1077 diff -Nur linux.old/include/linux/netfilter_ipv6/ip6_tables.h linux.dev/include/linux/netfilter_ipv6/ip6_tables.h
1078 --- linux.old/include/linux/netfilter_ipv6/ip6_tables.h 2005-04-04 03:42:20.000000000 +0200
1079 +++ linux.dev/include/linux/netfilter_ipv6/ip6_tables.h 2005-10-10 10:36:46.037866000 +0200
1081 #define IP6T_CONTINUE 0xFFFFFFFF
1083 /* For standard target */
1084 -#define IP6T_RETURN (-NF_MAX_VERDICT - 1)
1085 +#define IP6T_RETURN (-NF_REPEAT - 1)
1087 /* TCP matching stuff */
1089 diff -Nur linux.old/include/linux/netfilter_ipv6.h linux.dev/include/linux/netfilter_ipv6.h
1090 --- linux.old/include/linux/netfilter_ipv6.h 2001-01-02 01:17:54.000000000 +0100
1091 +++ linux.dev/include/linux/netfilter_ipv6.h 2005-10-10 10:36:46.169874250 +0200
1093 enum nf_ip6_hook_priorities {
1094 NF_IP6_PRI_FIRST = INT_MIN,
1095 NF_IP6_PRI_CONNTRACK = -200,
1096 + NF_IP6_PRI_BRIDGE_SABOTAGE_FORWARD = -175,
1097 NF_IP6_PRI_MANGLE = -150,
1098 NF_IP6_PRI_NAT_DST = -100,
1099 + NF_IP6_PRI_BRIDGE_SABOTAGE_LOCAL_OUT = -50,
1100 NF_IP6_PRI_FILTER = 0,
1101 NF_IP6_PRI_NAT_SRC = 100,
1102 NF_IP6_PRI_LAST = INT_MAX,
1103 diff -Nur linux.old/include/linux/skbuff.h linux.dev/include/linux/skbuff.h
1104 --- linux.old/include/linux/skbuff.h 2005-10-10 10:33:06.840167000 +0200
1105 +++ linux.dev/include/linux/skbuff.h 2005-10-10 10:36:46.185875250 +0200
1108 struct nf_conntrack *master;
1111 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
1112 +struct nf_bridge_info {
1114 + struct net_device *physindev;
1115 + struct net_device *physoutdev;
1116 +#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
1117 + struct net_device *netoutdev;
1119 + unsigned int mask;
1120 + unsigned long data[32 / sizeof(unsigned long)];
1125 #if defined(CONFIG_IMQ) || defined(CONFIG_IMQ_MODULE)
1128 #ifdef CONFIG_NETFILTER_DEBUG
1129 unsigned int nf_debug;
1131 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
1132 + struct nf_bridge_info *nf_bridge; /* Saved data about a bridged frame - see br_netfilter.c */
1134 #endif /*CONFIG_NETFILTER*/
1136 #if defined(CONFIG_HIPPI)
1137 @@ -1177,6 +1194,20 @@
1142 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
1143 +static inline void nf_bridge_put(struct nf_bridge_info *nf_bridge)
1145 + if (nf_bridge && atomic_dec_and_test(&nf_bridge->use))
1148 +static inline void nf_bridge_get(struct nf_bridge_info *nf_bridge)
1151 + atomic_inc(&nf_bridge->use);
1155 #else /* CONFIG_NETFILTER */
1156 static inline void nf_reset(struct sk_buff *skb) {}
1157 #endif /* CONFIG_NETFILTER */
1158 diff -Nur linux.old/include/linux/sysctl.h linux.dev/include/linux/sysctl.h
1159 --- linux.old/include/linux/sysctl.h 2005-04-04 03:42:20.000000000 +0200
1160 +++ linux.dev/include/linux/sysctl.h 2005-10-10 10:36:46.333884500 +0200
1161 @@ -609,6 +609,15 @@
1162 NET_DECNET_CONF_DEV_STATE = 7
1165 +/* /proc/sys/net/bridge */
1167 + NET_BRIDGE_NF_CALL_ARPTABLES = 1,
1168 + NET_BRIDGE_NF_CALL_IPTABLES = 2,
1169 + NET_BRIDGE_NF_CALL_IP6TABLES = 3,
1170 + NET_BRIDGE_NF_FILTER_VLAN_TAGGED = 4,
1174 /* CTL_PROC names: */
1177 diff -Nur linux.old/net/8021q/vlan_dev.c linux.dev/net/8021q/vlan_dev.c
1178 --- linux.old/net/8021q/vlan_dev.c 2005-01-19 15:10:13.000000000 +0100
1179 +++ linux.dev/net/8021q/vlan_dev.c 2005-10-10 10:36:46.317883500 +0200
1180 @@ -488,6 +488,10 @@
1181 stats->tx_packets++; /* for statics only */
1182 stats->tx_bytes += skb->len;
1184 + skb->protocol = __constant_htons(ETH_P_8021Q);
1185 + skb->mac.raw -= VLAN_HLEN;
1186 + skb->nh.raw -= VLAN_HLEN;
1188 skb->dev = VLAN_DEV_INFO(dev)->real_dev;
1189 dev_queue_xmit(skb);
1191 diff -Nur linux.old/net/Config.in linux.dev/net/Config.in
1192 --- linux.old/net/Config.in 2005-10-10 10:33:00.299758250 +0200
1193 +++ linux.dev/net/Config.in 2005-10-10 10:36:46.085869000 +0200
1195 source net/decnet/Config.in
1197 dep_tristate '802.1d Ethernet Bridging' CONFIG_BRIDGE $CONFIG_INET
1198 +if [ "$CONFIG_BRIDGE" != "n" -a "$CONFIG_NETFILTER" != "n" ]; then
1199 + source net/bridge/netfilter/Config.in
1201 if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then
1202 tristate 'CCITT X.25 Packet Layer (EXPERIMENTAL)' CONFIG_X25
1203 tristate 'LAPB Data Link Driver (EXPERIMENTAL)' CONFIG_LAPB
1204 diff -Nur linux.old/net/Makefile linux.dev/net/Makefile
1205 --- linux.old/net/Makefile 2004-08-08 01:26:06.000000000 +0200
1206 +++ linux.dev/net/Makefile 2005-10-10 10:36:46.077868500 +0200
1209 O_TARGET := network.o
1211 -mod-subdirs := ipv4/netfilter ipv6/netfilter ipx irda bluetooth atm netlink sched core sctp 802
1212 +mod-subdirs := ipv4/netfilter ipv6/netfilter bridge/netfilter ipx irda \
1213 + bluetooth atm netlink sched core sctp 802
1214 export-objs := netsyms.o
1216 subdir-y := core ethernet
1221 +ifneq ($(CONFIG_BRIDGE),n)
1222 +ifneq ($(CONFIG_BRIDGE),)
1223 +subdir-$(CONFIG_BRIDGE) += bridge/netfilter
1227 subdir-$(CONFIG_KHTTPD) += khttpd
1228 subdir-$(CONFIG_PACKET) += packet
1229 subdir-$(CONFIG_NET_SCHED) += sched
1230 diff -Nur linux.old/net/bridge/Makefile linux.dev/net/bridge/Makefile
1231 --- linux.old/net/bridge/Makefile 2000-12-29 23:07:24.000000000 +0100
1232 +++ linux.dev/net/bridge/Makefile 2005-10-10 11:32:01.347058000 +0200
1235 # Note 2! The CFLAGS definition is now in the main makefile...
1237 +export-objs := br.o
1239 O_TARGET := bridge.o
1240 obj-y := br.o br_device.o br_fdb.o br_forward.o br_if.o br_input.o \
1241 br_ioctl.o br_notify.o br_stp.o br_stp_bpdu.o \
1242 br_stp_if.o br_stp_timer.o
1244 +ifeq ($(CONFIG_NETFILTER),y)
1245 +export-objs += br_netfilter.o
1246 +obj-y += br_netfilter.o
1249 obj-m := $(O_TARGET)
1251 include $(TOPDIR)/Rules.make
1252 diff -Nur linux.old/net/bridge/br.c linux.dev/net/bridge/br.c
1253 --- linux.old/net/bridge/br.c 2004-08-08 01:26:06.000000000 +0200
1254 +++ linux.dev/net/bridge/br.c 2005-10-10 10:40:13.694843750 +0200
1256 #include "../atm/lec.h"
1259 +int (*br_should_route_hook) (struct sk_buff **pskb) = NULL;
1261 void br_dec_use_count()
1269 +EXPORT_SYMBOL(br_should_route_hook);
1271 module_init(br_init)
1272 module_exit(br_deinit)
1273 diff -Nur linux.old/net/bridge/br_forward.c linux.dev/net/bridge/br_forward.c
1274 --- linux.old/net/bridge/br_forward.c 2003-11-28 19:26:21.000000000 +0100
1275 +++ linux.dev/net/bridge/br_forward.c 2005-10-10 10:36:45.981862500 +0200
1280 -static int __dev_queue_push_xmit(struct sk_buff *skb)
1281 +int br_dev_queue_push_xmit(struct sk_buff *skb)
1283 +#ifdef CONFIG_NETFILTER
1284 + nf_bridge_maybe_copy_header(skb);
1286 skb_push(skb, ETH_HLEN);
1287 dev_queue_xmit(skb);
1292 -static int __br_forward_finish(struct sk_buff *skb)
1293 +int br_forward_finish(struct sk_buff *skb)
1295 NF_HOOK(PF_BRIDGE, NF_BR_POST_ROUTING, skb, NULL, skb->dev,
1296 - __dev_queue_push_xmit);
1297 + br_dev_queue_push_xmit);
1302 static void __br_deliver(struct net_bridge_port *to, struct sk_buff *skb)
1305 +#ifdef CONFIG_NETFILTER_DEBUG
1306 + skb->nf_debug = 0;
1308 NF_HOOK(PF_BRIDGE, NF_BR_LOCAL_OUT, skb, NULL, skb->dev,
1309 - __br_forward_finish);
1310 + br_forward_finish);
1313 static void __br_forward(struct net_bridge_port *to, struct sk_buff *skb)
1315 skb->ip_summed = CHECKSUM_NONE;
1317 NF_HOOK(PF_BRIDGE, NF_BR_FORWARD, skb, indev, skb->dev,
1318 - __br_forward_finish);
1319 + br_forward_finish);
1322 /* called under bridge lock */
1323 diff -Nur linux.old/net/bridge/br_input.c linux.dev/net/bridge/br_input.c
1324 --- linux.old/net/bridge/br_input.c 2003-08-25 13:44:44.000000000 +0200
1325 +++ linux.dev/net/bridge/br_input.c 2005-10-10 10:36:45.981862500 +0200
1328 static int br_pass_frame_up_finish(struct sk_buff *skb)
1330 +#ifdef CONFIG_NETFILTER_DEBUG
1331 + skb->nf_debug = 0;
1337 br_pass_frame_up_finish);
1340 -static int br_handle_frame_finish(struct sk_buff *skb)
1341 +int br_handle_frame_finish(struct sk_buff *skb)
1343 struct net_bridge *br;
1344 unsigned char *dest;
1349 -void br_handle_frame(struct sk_buff *skb)
1350 +int br_handle_frame(struct sk_buff *skb)
1352 struct net_bridge *br;
1353 unsigned char *dest;
1354 @@ -146,26 +149,35 @@
1355 goto handle_special_frame;
1357 if (p->state == BR_STATE_FORWARDING) {
1358 + if (br_should_route_hook && br_should_route_hook(&skb)) {
1359 + read_unlock(&br->lock);
1363 + if (!memcmp(p->br->dev.dev_addr, dest, ETH_ALEN))
1364 + skb->pkt_type = PACKET_HOST;
1366 NF_HOOK(PF_BRIDGE, NF_BR_PRE_ROUTING, skb, skb->dev, NULL,
1367 br_handle_frame_finish);
1368 read_unlock(&br->lock);
1374 read_unlock(&br->lock);
1380 handle_special_frame:
1382 NF_HOOK(PF_BRIDGE, NF_BR_LOCAL_IN, skb, skb->dev,NULL,
1383 br_stp_handle_bpdu);
1384 read_unlock(&br->lock);
1389 read_unlock(&br->lock);
1393 diff -Nur linux.old/net/bridge/br_netfilter.c linux.dev/net/bridge/br_netfilter.c
1394 --- linux.old/net/bridge/br_netfilter.c 1970-01-01 01:00:00.000000000 +0100
1395 +++ linux.dev/net/bridge/br_netfilter.c 2005-10-10 11:43:47.019159750 +0200
1398 + * Handle firewalling
1399 + * Linux ethernet bridge
1402 + * Lennert Buytenhek <buytenh@gnu.org>
1403 + * Bart De Schuymer (maintainer) <bdschuym@pandora.be>
1406 + * Apr 29 2003: physdev module support (bdschuym)
1407 + * Jun 19 2003: let arptables see bridged ARP traffic (bdschuym)
1408 + * Oct 06 2003: filter encapsulated IP/ARP VLAN traffic on untagged bridge
1410 + * Aug 28 2004: add IPv6 filtering (bdschuym)
1412 + * This program is free software; you can redistribute it and/or
1413 + * modify it under the terms of the GNU General Public License
1414 + * as published by the Free Software Foundation; either version
1415 + * 2 of the License, or (at your option) any later version.
1417 + * Lennert dedicates this file to Kerstin Wurdinger.
1420 +#include <linux/module.h>
1421 +#include <linux/kernel.h>
1422 +#include <linux/ip.h>
1423 +#include <linux/netdevice.h>
1424 +#include <linux/skbuff.h>
1425 +#include <linux/if_ether.h>
1426 +#include <linux/if_vlan.h>
1427 +#include <linux/netfilter_bridge.h>
1428 +#include <linux/netfilter_ipv4.h>
1429 +#include <linux/netfilter_ipv6.h>
1430 +#include <linux/in_route.h>
1431 +#include <net/ip.h>
1432 +#include <net/ipv6.h>
1433 +#include <asm/uaccess.h>
1434 +#include <asm/checksum.h>
1435 +#include "br_private.h"
1436 +#ifdef CONFIG_SYSCTL
1437 +#include <linux/sysctl.h>
1440 +#define skb_origaddr(skb) (((struct bridge_skb_cb *) \
1441 + (skb->nf_bridge->data))->daddr.ipv4)
1442 +#define store_orig_dstaddr(skb) (skb_origaddr(skb) = (skb)->nh.iph->daddr)
1443 +#define dnat_took_place(skb) (skb_origaddr(skb) != (skb)->nh.iph->daddr)
1445 +#define has_bridge_parent(device) ((device)->br_port != NULL)
1446 +#define bridge_parent(device) (&((device)->br_port->br->dev))
1448 +#ifdef CONFIG_SYSCTL
1449 +static struct ctl_table_header *brnf_sysctl_header;
1450 +static int brnf_call_iptables = 1;
1451 +static int brnf_call_ip6tables = 1;
1452 +static int brnf_call_arptables = 1;
1453 +static int brnf_filter_vlan_tagged = 1;
1455 +#define brnf_filter_vlan_tagged 1
1458 +#define IS_VLAN_IP (skb->protocol == __constant_htons(ETH_P_8021Q) && \
1459 + hdr->h_vlan_encapsulated_proto == __constant_htons(ETH_P_IP) && \
1460 + brnf_filter_vlan_tagged)
1461 +#define IS_VLAN_IPV6 (skb->protocol == __constant_htons(ETH_P_8021Q) && \
1462 + hdr->h_vlan_encapsulated_proto == __constant_htons(ETH_P_IPV6) && \
1463 + brnf_filter_vlan_tagged)
1465 +#define IS_VLAN_ARP (skb->protocol == __constant_htons(ETH_P_8021Q) && \
1466 + hdr->h_vlan_encapsulated_proto == __constant_htons(ETH_P_ARP) && \
1467 + brnf_filter_vlan_tagged)
1470 +/* We need these fake structures to make netfilter happy --
1471 + * lots of places assume that skb->dst != NULL, which isn't
1472 + * all that unreasonable.
1474 + * Currently, we fill in the PMTU entry because netfilter
1475 + * refragmentation needs it, and the rt_flags entry because
1476 + * ipt_REJECT needs it. Future netfilter modules might
1477 + * require us to fill additional fields.
1479 +static struct net_device __fake_net_device = {
1480 + .hard_header_len = ETH_HLEN
1483 +static struct rtable __fake_rtable = {
1486 + __refcnt: ATOMIC_INIT(1),
1487 + dev: &__fake_net_device,
1496 +/* PF_BRIDGE/PRE_ROUTING *********************************************/
1497 +/* Undo the changes made for ip6tables PREROUTING and continue the
1498 + * bridge PRE_ROUTING hook. */
1499 +static int br_nf_pre_routing_finish_ipv6(struct sk_buff *skb)
1501 + struct nf_bridge_info *nf_bridge = skb->nf_bridge;
1503 +#ifdef CONFIG_NETFILTER_DEBUG
1504 + skb->nf_debug ^= (1 << NF_BR_PRE_ROUTING);
1507 + if (nf_bridge->mask & BRNF_PKT_TYPE) {
1508 + skb->pkt_type = PACKET_OTHERHOST;
1509 + nf_bridge->mask ^= BRNF_PKT_TYPE;
1511 + nf_bridge->mask ^= BRNF_NF_BRIDGE_PREROUTING;
1513 + skb->dst = (struct dst_entry *)&__fake_rtable;
1514 + dst_hold(skb->dst);
1516 + skb->dev = nf_bridge->physindev;
1517 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
1518 + skb_push(skb, VLAN_HLEN);
1519 + skb->nh.raw -= VLAN_HLEN;
1521 + NF_HOOK_THRESH(PF_BRIDGE, NF_BR_PRE_ROUTING, skb, skb->dev, NULL,
1522 + br_handle_frame_finish, 1);
1527 +static void __br_dnat_complain(void)
1529 + static unsigned long last_complaint;
1531 + if (jiffies - last_complaint >= 5 * HZ) {
1532 + printk(KERN_WARNING "Performing cross-bridge DNAT requires IP "
1533 + "forwarding to be enabled\n");
1534 + last_complaint = jiffies;
1539 +/* This requires some explaining. If DNAT has taken place,
1540 + * we will need to fix up the destination Ethernet address,
1541 + * and this is a tricky process.
1543 + * There are two cases to consider:
1544 + * 1. The packet was DNAT'ed to a device in the same bridge
1545 + * port group as it was received on. We can still bridge
1547 + * 2. The packet was DNAT'ed to a different device, either
1548 + * a non-bridged device or another bridge port group.
1549 + * The packet will need to be routed.
1551 + * The correct way of distinguishing between these two cases is to
1552 + * call ip_route_input() and to look at skb->dst->dev, which is
1553 + * changed to the destination device if ip_route_input() succeeds.
1555 + * Let us first consider the case that ip_route_input() succeeds:
1557 + * If skb->dst->dev equals the logical bridge device the packet
1558 + * came in on, we can consider this bridging. We then call
1559 + * skb->dst->output() which will make the packet enter br_nf_local_out()
1560 + * not much later. In that function it is assured that the iptables
1561 + * FORWARD chain is traversed for the packet.
1563 + * Otherwise, the packet is considered to be routed and we just
1564 + * change the destination MAC address so that the packet will
1565 + * later be passed up to the IP stack to be routed.
1567 + * Let us now consider the case that ip_route_input() fails:
1569 + * After a "echo '0' > /proc/sys/net/ipv4/ip_forward" ip_route_input()
1570 + * will fail, while __ip_route_output_key() will return success. The source
1571 + * address for __ip_route_output_key() is set to zero, so __ip_route_output_key
1572 + * thinks we're handling a locally generated packet and won't care
1573 + * if IP forwarding is allowed. We send a warning message to the users's
1574 + * log telling her to put IP forwarding on.
1576 + * ip_route_input() will also fail if there is no route available.
1577 + * In that case we just drop the packet.
1579 + * --Lennert, 20020411
1580 + * --Bart, 20020416 (updated)
1581 + * --Bart, 20021007 (updated)
1584 +static int br_nf_pre_routing_finish_bridge(struct sk_buff *skb)
1586 +#ifdef CONFIG_NETFILTER_DEBUG
1587 + skb->nf_debug |= (1 << NF_BR_PRE_ROUTING) | (1 << NF_BR_FORWARD);
1590 + if (skb->pkt_type == PACKET_OTHERHOST) {
1591 + skb->pkt_type = PACKET_HOST;
1592 + skb->nf_bridge->mask |= BRNF_PKT_TYPE;
1594 + skb->nf_bridge->mask ^= BRNF_NF_BRIDGE_PREROUTING;
1596 + skb->dev = bridge_parent(skb->dev);
1597 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
1598 + skb_pull(skb, VLAN_HLEN);
1599 + skb->nh.raw += VLAN_HLEN;
1601 + skb->dst->output(skb);
1605 +static int br_nf_pre_routing_finish(struct sk_buff *skb)
1607 + struct net_device *dev = skb->dev;
1608 + struct iphdr *iph = skb->nh.iph;
1609 + struct nf_bridge_info *nf_bridge = skb->nf_bridge;
1611 +#ifdef CONFIG_NETFILTER_DEBUG
1612 + skb->nf_debug ^= (1 << NF_BR_PRE_ROUTING);
1615 + if (nf_bridge->mask & BRNF_PKT_TYPE) {
1616 + skb->pkt_type = PACKET_OTHERHOST;
1617 + nf_bridge->mask ^= BRNF_PKT_TYPE;
1619 + nf_bridge->mask ^= BRNF_NF_BRIDGE_PREROUTING;
1621 + if (dnat_took_place(skb)) {
1622 + if (ip_route_input(skb, iph->daddr, iph->saddr, iph->tos,
1624 + struct rtable *rt;
1626 + if (!ip_route_output(&rt, iph->daddr, 0, iph->tos, 0)) {
1627 + /* Bridged-and-DNAT'ed traffic doesn't
1628 + * require ip_forwarding.
1630 + if (((struct dst_entry *)rt)->dev == dev) {
1631 + skb->dst = (struct dst_entry *)rt;
1632 + goto bridged_dnat;
1634 + __br_dnat_complain();
1635 + dst_release((struct dst_entry *)rt);
1640 + if (skb->dst->dev == dev) {
1642 + /* Tell br_nf_local_out this is a
1645 + nf_bridge->mask |= BRNF_BRIDGED_DNAT;
1646 + skb->dev = nf_bridge->physindev;
1647 + if (skb->protocol ==
1648 + __constant_htons(ETH_P_8021Q)) {
1649 + skb_push(skb, VLAN_HLEN);
1650 + skb->nh.raw -= VLAN_HLEN;
1652 + NF_HOOK_THRESH(PF_BRIDGE, NF_BR_PRE_ROUTING,
1653 + skb, skb->dev, NULL,
1654 + br_nf_pre_routing_finish_bridge,
1658 + memcpy(skb->mac.ethernet->h_dest, dev->dev_addr,
1660 + skb->pkt_type = PACKET_HOST;
1663 + skb->dst = (struct dst_entry *)&__fake_rtable;
1664 + dst_hold(skb->dst);
1667 + skb->dev = nf_bridge->physindev;
1668 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
1669 + skb_push(skb, VLAN_HLEN);
1670 + skb->nh.raw -= VLAN_HLEN;
1672 + NF_HOOK_THRESH(PF_BRIDGE, NF_BR_PRE_ROUTING, skb, skb->dev, NULL,
1673 + br_handle_frame_finish, 1);
1678 +/* Some common code for IPv4/IPv6 */
1679 +static void setup_pre_routing(struct sk_buff *skb)
1681 + struct nf_bridge_info *nf_bridge = skb->nf_bridge;
1683 + if (skb->pkt_type == PACKET_OTHERHOST) {
1684 + skb->pkt_type = PACKET_HOST;
1685 + nf_bridge->mask |= BRNF_PKT_TYPE;
1688 + nf_bridge->mask |= BRNF_NF_BRIDGE_PREROUTING;
1689 + nf_bridge->physindev = skb->dev;
1690 + skb->dev = bridge_parent(skb->dev);
1693 +/* We only check the length. A bridge shouldn't do any hop-by-hop stuff anyway */
1694 +static int check_hbh_len(struct sk_buff *skb)
1696 + unsigned char *raw = (u8*)(skb->nh.ipv6h+1);
1698 + int off = raw - skb->nh.raw;
1699 + int len = (raw[1]+1)<<3;
1701 + if ((raw + len) - skb->data > skb_headlen(skb))
1708 + int optlen = raw[off+1]+2;
1710 + switch (skb->nh.raw[off]) {
1711 + case IPV6_TLV_PAD0:
1715 + case IPV6_TLV_PADN:
1718 + case IPV6_TLV_JUMBO:
1719 + if (skb->nh.raw[off+1] != 4 || (off&3) != 2)
1722 + pkt_len = ntohl(*(u32*)(skb->nh.raw+off+2));
1724 + if (pkt_len > skb->len - sizeof(struct ipv6hdr))
1726 + if (pkt_len + sizeof(struct ipv6hdr) < skb->len) {
1727 + if (__pskb_trim(skb,
1728 + pkt_len + sizeof(struct ipv6hdr)))
1730 + if (skb->ip_summed == CHECKSUM_HW)
1731 + skb->ip_summed = CHECKSUM_NONE;
1749 +/* Replicate the checks that IPv6 does on packet reception and pass the packet
1750 + * to ip6tables, which doesn't support NAT, so things are fairly simple. */
1751 +static unsigned int br_nf_pre_routing_ipv6(unsigned int hook,
1752 + struct sk_buff *skb, const struct net_device *in,
1753 + const struct net_device *out, int (*okfn)(struct sk_buff *))
1755 + struct ipv6hdr *hdr;
1757 + struct nf_bridge_info *nf_bridge;
1759 + if (skb->len < sizeof(struct ipv6hdr))
1762 + if (!pskb_may_pull(skb, sizeof(struct ipv6hdr)))
1765 + hdr = skb->nh.ipv6h;
1767 + if (hdr->version != 6)
1770 + pkt_len = ntohs(hdr->payload_len);
1772 + if (pkt_len || hdr->nexthdr != NEXTHDR_HOP) {
1773 + if (pkt_len + sizeof(struct ipv6hdr) > skb->len)
1775 + if (pkt_len + sizeof(struct ipv6hdr) < skb->len) {
1776 + if (__pskb_trim(skb, pkt_len + sizeof(struct ipv6hdr)))
1778 + if (skb->ip_summed == CHECKSUM_HW)
1779 + skb->ip_summed = CHECKSUM_NONE;
1782 + if (hdr->nexthdr == NEXTHDR_HOP && check_hbh_len(skb))
1785 +#ifdef CONFIG_NETFILTER_DEBUG
1786 + skb->nf_debug ^= (1 << NF_IP6_PRE_ROUTING);
1788 + if ((nf_bridge = nf_bridge_alloc(skb)) == NULL)
1790 + setup_pre_routing(skb);
1792 + NF_HOOK(PF_INET6, NF_IP6_PRE_ROUTING, skb, skb->dev, NULL,
1793 + br_nf_pre_routing_finish_ipv6);
1801 +/* Direct IPv6 traffic to br_nf_pre_routing_ipv6.
1802 + * Replicate the checks that IPv4 does on packet reception.
1803 + * Set skb->dev to the bridge device (i.e. parent of the
1804 + * receiving device) to make netfilter happy, the REDIRECT
1805 + * target in particular. Save the original destination IP
1806 + * address to be able to detect DNAT afterwards.
1808 +static unsigned int br_nf_pre_routing(unsigned int hook, struct sk_buff **pskb,
1809 + const struct net_device *in, const struct net_device *out,
1810 + int (*okfn)(struct sk_buff *))
1812 + struct iphdr *iph;
1814 + struct sk_buff *skb = *pskb;
1815 + struct nf_bridge_info *nf_bridge;
1816 + struct vlan_ethhdr *hdr = (struct vlan_ethhdr *)
1817 + ((*pskb)->mac.ethernet);
1819 + if (skb->protocol == __constant_htons(ETH_P_IPV6) || IS_VLAN_IPV6) {
1820 +#ifdef CONFIG_SYSCTL
1821 + if (!brnf_call_ip6tables)
1824 + if ((skb = skb_share_check(*pskb, GFP_ATOMIC)) == NULL)
1827 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
1828 + skb_pull(skb, VLAN_HLEN);
1829 + (skb)->nh.raw += VLAN_HLEN;
1831 + return br_nf_pre_routing_ipv6(hook, skb, in, out, okfn);
1834 +#ifdef CONFIG_SYSCTL
1835 + if (!brnf_call_iptables)
1839 + if (skb->protocol != __constant_htons(ETH_P_IP) && !IS_VLAN_IP)
1841 + if ((skb = skb_share_check(*pskb, GFP_ATOMIC)) == NULL)
1844 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
1845 + skb_pull(skb, VLAN_HLEN);
1846 + (skb)->nh.raw += VLAN_HLEN;
1849 + if (!pskb_may_pull(skb, sizeof(struct iphdr)))
1852 + iph = skb->nh.iph;
1853 + if (iph->ihl < 5 || iph->version != 4)
1856 + if (!pskb_may_pull(skb, 4*iph->ihl))
1859 + iph = skb->nh.iph;
1860 + if (ip_fast_csum((__u8 *)iph, iph->ihl) != 0)
1863 + len = ntohs(iph->tot_len);
1864 + if (skb->len < len || len < 4*iph->ihl)
1867 + if (skb->len > len) {
1868 + __pskb_trim(skb, len);
1869 + if (skb->ip_summed == CHECKSUM_HW)
1870 + skb->ip_summed = CHECKSUM_NONE;
1873 +#ifdef CONFIG_NETFILTER_DEBUG
1874 + skb->nf_debug ^= (1 << NF_IP_PRE_ROUTING);
1876 + if ((nf_bridge = nf_bridge_alloc(skb)) == NULL)
1879 + setup_pre_routing(skb);
1880 + store_orig_dstaddr(skb);
1882 + NF_HOOK(PF_INET, NF_IP_PRE_ROUTING, skb, skb->dev, NULL,
1883 + br_nf_pre_routing_finish);
1888 +// IP_INC_STATS_BH(IpInHdrErrors);
1894 +/* PF_BRIDGE/LOCAL_IN ************************************************/
1895 +/* The packet is locally destined, which requires a real
1896 + * dst_entry, so detach the fake one. On the way up, the
1897 + * packet would pass through PRE_ROUTING again (which already
1898 + * took place when the packet entered the bridge), but we
1899 + * register an IPv4 PRE_ROUTING 'sabotage' hook that will
1900 + * prevent this from happening.
1902 +static unsigned int br_nf_local_in(unsigned int hook, struct sk_buff **pskb,
1903 + const struct net_device *in, const struct net_device *out,
1904 + int (*okfn)(struct sk_buff *))
1906 + struct sk_buff *skb = *pskb;
1908 + if (skb->dst == (struct dst_entry *)&__fake_rtable) {
1909 + dst_release(skb->dst);
1916 +/* PF_BRIDGE/FORWARD *************************************************/
1917 +static int br_nf_forward_finish(struct sk_buff *skb)
1919 + struct nf_bridge_info *nf_bridge = skb->nf_bridge;
1920 + struct net_device *in;
1921 +/* struct vlan_ethhdr *hdr = (struct vlan_ethhdr *)(skb->mac.ethernet);*/
1923 +#ifdef CONFIG_NETFILTER_DEBUG
1924 + skb->nf_debug ^= (1 << NF_BR_FORWARD);
1927 +/* if (skb->protocol != __constant_htons(ETH_P_ARP) && !IS_VLAN_ARP) {*/
1928 + in = nf_bridge->physindev;
1929 + if (nf_bridge->mask & BRNF_PKT_TYPE) {
1930 + skb->pkt_type = PACKET_OTHERHOST;
1931 + nf_bridge->mask ^= BRNF_PKT_TYPE;
1934 + in = *((struct net_device **)(skb->cb));
1936 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
1937 + skb_push(skb, VLAN_HLEN);
1938 + skb->nh.raw -= VLAN_HLEN;
1940 + NF_HOOK_THRESH(PF_BRIDGE, NF_BR_FORWARD, skb, in,
1941 + skb->dev, br_forward_finish, 1);
1945 +/* This is the 'purely bridged' case. For IP, we pass the packet to
1946 + * netfilter with indev and outdev set to the bridge device,
1947 + * but we are still able to filter on the 'real' indev/outdev
1948 + * because of the ipt_physdev.c module. For ARP, indev and outdev are the
1951 +static unsigned int br_nf_forward_ip(unsigned int hook, struct sk_buff **pskb,
1952 + const struct net_device *in, const struct net_device *out,
1953 + int (*okfn)(struct sk_buff *))
1955 + struct sk_buff *skb = *pskb;
1956 + struct nf_bridge_info *nf_bridge;
1957 + struct vlan_ethhdr *hdr = (struct vlan_ethhdr *)(skb->mac.ethernet);
1960 + if (!skb->nf_bridge)
1963 + if (skb->protocol == __constant_htons(ETH_P_IP) || IS_VLAN_IP)
1968 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
1969 + skb_pull(*pskb, VLAN_HLEN);
1970 + (*pskb)->nh.raw += VLAN_HLEN;
1973 +#ifdef CONFIG_NETFILTER_DEBUG
1974 + skb->nf_debug ^= (1 << NF_BR_FORWARD);
1976 + nf_bridge = skb->nf_bridge;
1977 + if (skb->pkt_type == PACKET_OTHERHOST) {
1978 + skb->pkt_type = PACKET_HOST;
1979 + nf_bridge->mask |= BRNF_PKT_TYPE;
1982 + /* The physdev module checks on this */
1983 + nf_bridge->mask |= BRNF_BRIDGED;
1984 + nf_bridge->physoutdev = skb->dev;
1986 + NF_HOOK(pf, NF_IP_FORWARD, skb, bridge_parent(in),
1987 + bridge_parent(out), br_nf_forward_finish);
1993 +static unsigned int br_nf_forward_arp(unsigned int hook, struct sk_buff **pskb,
1994 + const struct net_device *in, const struct net_device *out,
1995 + int (*okfn)(struct sk_buff *))
1997 + struct sk_buff *skb = *pskb;
1998 + struct vlan_ethhdr *hdr = (struct vlan_ethhdr *)(skb->mac.ethernet);
1999 + struct net_device **d = (struct net_device **)(skb->cb);
2001 + if (!brnf_call_arptables)
2004 + if (skb->protocol != __constant_htons(ETH_P_ARP)) {
2007 + skb_pull(*pskb, VLAN_HLEN);
2008 + (*pskb)->nh.raw += VLAN_HLEN;
2011 +#ifdef CONFIG_NETFILTER_DEBUG
2012 + skb->nf_debug ^= (1 << NF_BR_FORWARD);
2015 + if (skb->nh.arph->ar_pln != 4) {
2016 + if (IS_VLAN_ARP) {
2017 + skb_push(*pskb, VLAN_HLEN);
2018 + (*pskb)->nh.raw -= VLAN_HLEN;
2022 + *d = (struct net_device *)in;
2023 + NF_HOOK(NF_ARP, NF_ARP_FORWARD, skb, (struct net_device *)in,
2024 + (struct net_device *)out, br_nf_forward_finish);
2030 +/* PF_BRIDGE/LOCAL_OUT ***********************************************/
2031 +static int br_nf_local_out_finish(struct sk_buff *skb)
2033 +#ifdef CONFIG_NETFILTER_DEBUG
2034 + skb->nf_debug &= ~(1 << NF_BR_LOCAL_OUT);
2036 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
2037 + skb_push(skb, VLAN_HLEN);
2038 + skb->nh.raw -= VLAN_HLEN;
2041 + NF_HOOK_THRESH(PF_BRIDGE, NF_BR_LOCAL_OUT, skb, NULL, skb->dev,
2042 + br_forward_finish, NF_BR_PRI_FIRST + 1);
2048 +/* This function sees both locally originated IP packets and forwarded
2049 + * IP packets (in both cases the destination device is a bridge
2050 + * device). It also sees bridged-and-DNAT'ed packets.
2051 + * To be able to filter on the physical bridge devices (with the ipt_physdev.c
2052 + * module), we steal packets destined to a bridge device away from the
2053 + * PF_INET/FORWARD and PF_INET/OUTPUT hook functions, and give them back later,
2054 + * when we have determined the real output device. This is done in here.
2056 + * If (nf_bridge->mask & BRNF_BRIDGED_DNAT) then the packet is bridged
2057 + * and we fake the PF_BRIDGE/FORWARD hook. The function br_nf_forward()
2058 + * will then fake the PF_INET/FORWARD hook. br_nf_local_out() has priority
2059 + * NF_BR_PRI_FIRST, so no relevant PF_BRIDGE/INPUT functions have been nor
2060 + * will be executed.
2061 + * Otherwise, if nf_bridge->physindev is NULL, the bridge-nf code never touched
2062 + * this packet before, and so the packet was locally originated. We fake
2063 + * the PF_INET/LOCAL_OUT hook.
2064 + * Finally, if nf_bridge->physindev isn't NULL, then the packet was IP routed,
2065 + * so we fake the PF_INET/FORWARD hook. ipv4_sabotage_out() makes sure
2066 + * even routed packets that didn't arrive on a bridge interface have their
2067 + * nf_bridge->physindev set.
2070 +static unsigned int br_nf_local_out(unsigned int hook, struct sk_buff **pskb,
2071 + const struct net_device *in, const struct net_device *out,
2072 + int (*okfn)(struct sk_buff *))
2074 + struct net_device *realindev, *realoutdev;
2075 + struct sk_buff *skb = *pskb;
2076 + struct nf_bridge_info *nf_bridge;
2077 + struct vlan_ethhdr *hdr = (struct vlan_ethhdr *)(skb->mac.ethernet);
2080 + if (!skb->nf_bridge)
2083 + if (skb->protocol == __constant_htons(ETH_P_IP) || IS_VLAN_IP)
2088 +#ifdef CONFIG_NETFILTER_DEBUG
2089 + /* Sometimes we get packets with NULL ->dst here (for example,
2090 + * running a dhcp client daemon triggers this). This should now
2091 + * be fixed, but let's keep the check around. */
2092 + if (skb->dst == NULL) {
2093 + printk(KERN_CRIT "br_netfilter: skb->dst == NULL.");
2098 + nf_bridge = skb->nf_bridge;
2099 + nf_bridge->physoutdev = skb->dev;
2100 + realindev = nf_bridge->physindev;
2102 + /* Bridged, take PF_BRIDGE/FORWARD.
2103 + * (see big note in front of br_nf_pre_routing_finish)
2105 + if (nf_bridge->mask & BRNF_BRIDGED_DNAT) {
2106 + if (nf_bridge->mask & BRNF_PKT_TYPE) {
2107 + skb->pkt_type = PACKET_OTHERHOST;
2108 + nf_bridge->mask ^= BRNF_PKT_TYPE;
2110 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
2111 + skb_push(skb, VLAN_HLEN);
2112 + skb->nh.raw -= VLAN_HLEN;
2115 + NF_HOOK(PF_BRIDGE, NF_BR_FORWARD, skb, realindev,
2116 + skb->dev, br_forward_finish);
2119 + realoutdev = bridge_parent(skb->dev);
2121 +#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
2122 + /* iptables should match -o br0.x */
2123 + if (nf_bridge->netoutdev)
2124 + realoutdev = nf_bridge->netoutdev;
2126 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
2127 + skb_pull(skb, VLAN_HLEN);
2128 + (*pskb)->nh.raw += VLAN_HLEN;
2130 + /* IP forwarded traffic has a physindev, locally
2131 + * generated traffic hasn't.
2133 + if (realindev != NULL) {
2134 + if (((nf_bridge->mask & BRNF_DONT_TAKE_PARENT) == 0) &&
2135 + has_bridge_parent(realindev))
2136 + realindev = bridge_parent(realindev);
2137 + NF_HOOK_THRESH(pf, NF_IP_FORWARD, skb, realindev,
2139 + NF_IP_PRI_BRIDGE_SABOTAGE_FORWARD + 1);
2141 +#ifdef CONFIG_NETFILTER_DEBUG
2142 + skb->nf_debug ^= (1 << NF_IP_LOCAL_OUT);
2145 + NF_HOOK_THRESH(pf, NF_IP_LOCAL_OUT, skb, realindev,
2147 + NF_IP_PRI_BRIDGE_SABOTAGE_LOCAL_OUT + 1);
2155 +/* PF_BRIDGE/POST_ROUTING ********************************************/
2156 +static unsigned int br_nf_post_routing(unsigned int hook, struct sk_buff **pskb,
2157 + const struct net_device *in, const struct net_device *out,
2158 + int (*okfn)(struct sk_buff *))
2160 + struct sk_buff *skb = *pskb;
2161 + struct nf_bridge_info *nf_bridge = (*pskb)->nf_bridge;
2162 + struct vlan_ethhdr *hdr = (struct vlan_ethhdr *)(skb->mac.ethernet);
2163 + struct net_device *realoutdev = bridge_parent(skb->dev);
2166 +#ifdef CONFIG_NETFILTER_DEBUG
2167 + /* Be very paranoid. This probably won't happen anymore, but let's
2168 + * keep the check just to be sure... */
2169 + if (skb->mac.raw < skb->head || skb->mac.raw + ETH_HLEN > skb->data) {
2170 + printk(KERN_CRIT "br_netfilter: Argh!! br_nf_post_routing: "
2171 + "bad mac.raw pointer.");
2179 + if (skb->protocol == __constant_htons(ETH_P_IP) || IS_VLAN_IP)
2184 + /* Sometimes we get packets with NULL ->dst here (for example,
2185 + * running a dhcp client daemon triggers this).
2187 + if (skb->dst == NULL)
2190 +#ifdef CONFIG_NETFILTER_DEBUG
2191 + /* Sometimes we get packets with NULL ->dst here (for example,
2192 + * running a dhcp client daemon triggers this). This should now
2193 + * be fixed, but let's keep the check around.
2195 + if (skb->dst == NULL) {
2196 + printk(KERN_CRIT "br_netfilter: skb->dst == NULL.");
2200 + skb->nf_debug ^= (1 << NF_IP_POST_ROUTING);
2203 + /* We assume any code from br_dev_queue_push_xmit onwards doesn't care
2204 + * about the value of skb->pkt_type.
2206 + if (skb->pkt_type == PACKET_OTHERHOST) {
2207 + skb->pkt_type = PACKET_HOST;
2208 + nf_bridge->mask |= BRNF_PKT_TYPE;
2211 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
2212 + skb_pull(skb, VLAN_HLEN);
2213 + skb->nh.raw += VLAN_HLEN;
2216 + nf_bridge_save_header(skb);
2218 +#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
2219 + if (nf_bridge->netoutdev)
2220 + realoutdev = nf_bridge->netoutdev;
2222 + NF_HOOK(pf, NF_IP_POST_ROUTING, skb, NULL,
2223 + realoutdev, br_dev_queue_push_xmit);
2227 +#ifdef CONFIG_NETFILTER_DEBUG
2229 + if (skb->dev != NULL) {
2230 + printk("[%s]", skb->dev->name);
2231 + if (has_bridge_parent(skb->dev))
2232 + printk("[%s]", bridge_parent(skb->dev)->name);
2234 + printk(" head:%p, raw:%p, data:%p\n", skb->head, skb->mac.raw,
2241 +/* IPv4/SABOTAGE *****************************************************/
2243 +/* Don't hand locally destined packets to PF_INET/PRE_ROUTING
2244 + * for the second time.
2246 +static unsigned int ip_sabotage_in(unsigned int hook, struct sk_buff **pskb,
2247 + const struct net_device *in, const struct net_device *out,
2248 + int (*okfn)(struct sk_buff *))
2250 + if ((*pskb)->nf_bridge &&
2251 + !((*pskb)->nf_bridge->mask & BRNF_NF_BRIDGE_PREROUTING)) {
2258 +/* Postpone execution of PF_INET/FORWARD, PF_INET/LOCAL_OUT
2259 + * and PF_INET/POST_ROUTING until we have done the forwarding
2260 + * decision in the bridge code and have determined skb->physoutdev.
2262 +static unsigned int ip_sabotage_out(unsigned int hook, struct sk_buff **pskb,
2263 + const struct net_device *in, const struct net_device *out,
2264 + int (*okfn)(struct sk_buff *))
2266 + struct sk_buff *skb = *pskb;
2268 + if ((out->hard_start_xmit == br_dev_xmit &&
2269 + okfn != br_nf_forward_finish &&
2270 + okfn != br_nf_local_out_finish &&
2271 + okfn != br_dev_queue_push_xmit)
2272 +#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
2273 + || ((out->priv_flags & IFF_802_1Q_VLAN) &&
2274 + VLAN_DEV_INFO(out)->real_dev->hard_start_xmit == br_dev_xmit)
2277 + struct nf_bridge_info *nf_bridge;
2279 + if (!skb->nf_bridge) {
2280 +#ifdef CONFIG_SYSCTL
2281 + /* This code is executed while in the IP(v6) stack,
2282 + the version should be 4 or 6. We can't use
2283 + skb->protocol because that isn't set on
2284 + PF_INET(6)/LOCAL_OUT. */
2285 + struct iphdr *ip = skb->nh.iph;
2287 + if (ip->version == 4 && !brnf_call_iptables)
2289 + else if (ip->version == 6 && !brnf_call_ip6tables)
2292 + if (hook == NF_IP_POST_ROUTING)
2294 + if (!nf_bridge_alloc(skb))
2298 + nf_bridge = skb->nf_bridge;
2300 + /* This frame will arrive on PF_BRIDGE/LOCAL_OUT and we
2301 + * will need the indev then. For a brouter, the real indev
2302 + * can be a bridge port, so we make sure br_nf_local_out()
2303 + * doesn't use the bridge parent of the indev by using
2304 + * the BRNF_DONT_TAKE_PARENT mask.
2306 + if (hook == NF_IP_FORWARD && nf_bridge->physindev == NULL) {
2307 + nf_bridge->mask &= BRNF_DONT_TAKE_PARENT;
2308 + nf_bridge->physindev = (struct net_device *)in;
2310 +#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
2311 + /* the iptables outdev is br0.x, not br0 */
2312 + if (out->priv_flags & IFF_802_1Q_VLAN)
2313 + nf_bridge->netoutdev = (struct net_device *)out;
2321 +/* For br_nf_local_out we need (prio = NF_BR_PRI_FIRST), to insure that innocent
2322 + * PF_BRIDGE/NF_BR_LOCAL_OUT functions don't get bridged traffic as input.
2323 + * For br_nf_post_routing, we need (prio = NF_BR_PRI_LAST), because
2324 + * ip_refrag() can return NF_STOLEN.
2326 +static struct nf_hook_ops br_nf_ops[] = {
2327 + { .hook = br_nf_pre_routing,
2329 + .hooknum = NF_BR_PRE_ROUTING,
2330 + .priority = NF_BR_PRI_BRNF, },
2331 + { .hook = br_nf_local_in,
2333 + .hooknum = NF_BR_LOCAL_IN,
2334 + .priority = NF_BR_PRI_BRNF, },
2335 + { .hook = br_nf_forward_ip,
2337 + .hooknum = NF_BR_FORWARD,
2338 + .priority = NF_BR_PRI_BRNF /*- 1*/, },
2339 +/* { .hook = br_nf_forward_arp,
2341 + .hooknum = NF_BR_FORWARD,
2342 + .priority = NF_BR_PRI_BRNF, },*/
2343 + { .hook = br_nf_local_out,
2345 + .hooknum = NF_BR_LOCAL_OUT,
2346 + .priority = NF_BR_PRI_FIRST, },
2347 + { .hook = br_nf_post_routing,
2349 + .hooknum = NF_BR_POST_ROUTING,
2350 + .priority = NF_BR_PRI_LAST, },
2351 + { .hook = ip_sabotage_in,
2353 + .hooknum = NF_IP_PRE_ROUTING,
2354 + .priority = NF_IP_PRI_FIRST, },
2355 + { .hook = ip_sabotage_in,
2357 + .hooknum = NF_IP6_PRE_ROUTING,
2358 + .priority = NF_IP6_PRI_FIRST, },
2359 + { .hook = ip_sabotage_out,
2361 + .hooknum = NF_IP_FORWARD,
2362 + .priority = NF_IP_PRI_BRIDGE_SABOTAGE_FORWARD, },
2363 + { .hook = ip_sabotage_out,
2365 + .hooknum = NF_IP6_FORWARD,
2366 + .priority = NF_IP6_PRI_BRIDGE_SABOTAGE_FORWARD, },
2367 + { .hook = ip_sabotage_out,
2369 + .hooknum = NF_IP_LOCAL_OUT,
2370 + .priority = NF_IP_PRI_BRIDGE_SABOTAGE_LOCAL_OUT, },
2371 + { .hook = ip_sabotage_out,
2373 + .hooknum = NF_IP6_LOCAL_OUT,
2374 + .priority = NF_IP6_PRI_BRIDGE_SABOTAGE_LOCAL_OUT, },
2375 + { .hook = ip_sabotage_out,
2377 + .hooknum = NF_IP_POST_ROUTING,
2378 + .priority = NF_IP_PRI_FIRST, },
2379 + { .hook = ip_sabotage_out,
2381 + .hooknum = NF_IP6_POST_ROUTING,
2382 + .priority = NF_IP6_PRI_FIRST, },
2385 +#ifdef CONFIG_SYSCTL
2387 +int brnf_sysctl_call_tables(ctl_table *ctl, int write, struct file * filp,
2388 + void *buffer, size_t *lenp)
2392 + ret = proc_dointvec(ctl, write, filp, buffer, lenp);
2394 + if (write && *(int *)(ctl->data))
2395 + *(int *)(ctl->data) = 1;
2399 +static ctl_table brnf_table[] = {
2401 + .ctl_name = NET_BRIDGE_NF_CALL_ARPTABLES,
2402 + .procname = "bridge-nf-call-arptables",
2403 + .data = &brnf_call_arptables,
2404 + .maxlen = sizeof(int),
2406 + .proc_handler = &brnf_sysctl_call_tables,
2409 + .ctl_name = NET_BRIDGE_NF_CALL_IPTABLES,
2410 + .procname = "bridge-nf-call-iptables",
2411 + .data = &brnf_call_iptables,
2412 + .maxlen = sizeof(int),
2414 + .proc_handler = &brnf_sysctl_call_tables,
2417 + .ctl_name = NET_BRIDGE_NF_CALL_IP6TABLES,
2418 + .procname = "bridge-nf-call-ip6tables",
2419 + .data = &brnf_call_ip6tables,
2420 + .maxlen = sizeof(int),
2422 + .proc_handler = &brnf_sysctl_call_tables,
2425 + .ctl_name = NET_BRIDGE_NF_FILTER_VLAN_TAGGED,
2426 + .procname = "bridge-nf-filter-vlan-tagged",
2427 + .data = &brnf_filter_vlan_tagged,
2428 + .maxlen = sizeof(int),
2430 + .proc_handler = &brnf_sysctl_call_tables,
2435 +static ctl_table brnf_bridge_table[] = {
2437 + .ctl_name = NET_BRIDGE,
2438 + .procname = "bridge",
2440 + .child = brnf_table,
2445 +static ctl_table brnf_net_table[] = {
2447 + .ctl_name = CTL_NET,
2448 + .procname = "net",
2450 + .child = brnf_bridge_table,
2456 +int br_netfilter_init(void)
2460 + for (i = 0; i < ARRAY_SIZE(br_nf_ops); i++) {
2463 + if ((ret = nf_register_hook(&br_nf_ops[i])) >= 0)
2467 + nf_unregister_hook(&br_nf_ops[i]);
2472 +#ifdef CONFIG_SYSCTL
2473 + brnf_sysctl_header = register_sysctl_table(brnf_net_table, 0);
2474 + if (brnf_sysctl_header == NULL) {
2475 + printk(KERN_WARNING "br_netfilter: can't register to sysctl.\n");
2476 + for (i = 0; i < ARRAY_SIZE(br_nf_ops); i++)
2477 + nf_unregister_hook(&br_nf_ops[i]);
2482 + printk(KERN_NOTICE "Bridge firewalling registered\n");
2487 +void br_netfilter_fini(void)
2491 + for (i = ARRAY_SIZE(br_nf_ops) - 1; i >= 0; i--)
2492 + nf_unregister_hook(&br_nf_ops[i]);
2493 +#ifdef CONFIG_SYSCTL
2494 + unregister_sysctl_table(brnf_sysctl_header);
2500 +EXPORT_SYMBOL(br_netfilter_init);
2501 +EXPORT_SYMBOL(br_netfilter_fini);
2502 diff -Nur linux.old/net/bridge/br_private.h linux.dev/net/bridge/br_private.h
2503 --- linux.old/net/bridge/br_private.h 2004-08-08 01:26:06.000000000 +0200
2504 +++ linux.dev/net/bridge/br_private.h 2005-10-10 10:36:45.913858250 +0200
2505 @@ -143,8 +143,10 @@
2507 extern void br_deliver(struct net_bridge_port *to,
2508 struct sk_buff *skb);
2509 +extern int br_dev_queue_push_xmit(struct sk_buff *skb);
2510 extern void br_forward(struct net_bridge_port *to,
2511 struct sk_buff *skb);
2512 +extern int br_forward_finish(struct sk_buff *skb);
2513 extern void br_flood_deliver(struct net_bridge *br,
2514 struct sk_buff *skb,
2520 -extern void br_handle_frame(struct sk_buff *skb);
2521 +extern int br_handle_frame_finish(struct sk_buff *skb);
2522 +extern int br_handle_frame(struct sk_buff *skb);
2525 extern int br_ioctl(struct net_bridge *br,
2526 @@ -175,6 +178,10 @@
2527 unsigned long arg2);
2528 extern int br_ioctl_deviceless_stub(unsigned long arg);
2530 +/* br_netfilter.c */
2531 +extern int br_netfilter_init(void);
2532 +extern void br_netfilter_fini(void);
2535 extern int br_is_root_bridge(struct net_bridge *br);
2536 extern struct net_bridge_port *br_get_port(struct net_bridge *br,
2537 diff -Nur linux.old/net/bridge/netfilter/Config.in linux.dev/net/bridge/netfilter/Config.in
2538 --- linux.old/net/bridge/netfilter/Config.in 1970-01-01 01:00:00.000000000 +0100
2539 +++ linux.dev/net/bridge/netfilter/Config.in 2005-10-10 10:36:46.089869250 +0200
2542 +# Bridge netfilter configuration
2544 +dep_tristate ' Bridge: ebtables' CONFIG_BRIDGE_NF_EBTABLES $CONFIG_BRIDGE
2545 +dep_tristate ' ebt: filter table support' CONFIG_BRIDGE_EBT_T_FILTER $CONFIG_BRIDGE_NF_EBTABLES
2546 +dep_tristate ' ebt: nat table support' CONFIG_BRIDGE_EBT_T_NAT $CONFIG_BRIDGE_NF_EBTABLES
2547 +dep_tristate ' ebt: broute table support' CONFIG_BRIDGE_EBT_BROUTE $CONFIG_BRIDGE_NF_EBTABLES
2548 +dep_tristate ' ebt: log support' CONFIG_BRIDGE_EBT_LOG $CONFIG_BRIDGE_NF_EBTABLES
2549 +dep_tristate ' ebt: ulog support' CONFIG_BRIDGE_EBT_LOG $CONFIG_BRIDGE_NF_EBTABLES
2550 +dep_tristate ' ebt: IP filter support' CONFIG_BRIDGE_EBT_IPF $CONFIG_BRIDGE_NF_EBTABLES
2551 +dep_tristate ' ebt: ARP filter support' CONFIG_BRIDGE_EBT_ARPF $CONFIG_BRIDGE_NF_EBTABLES
2552 +dep_tristate ' ebt: among filter support' CONFIG_BRIDGE_EBT_AMONG $CONFIG_BRIDGE_NF_EBTABLES
2553 +dep_tristate ' ebt: limit filter support' CONFIG_BRIDGE_EBT_LIMIT $CONFIG_BRIDGE_NF_EBTABLES
2554 +dep_tristate ' ebt: 802.1Q VLAN filter support' CONFIG_BRIDGE_EBT_VLANF $CONFIG_BRIDGE_NF_EBTABLES
2555 +dep_tristate ' ebt: 802.3 filter support' CONFIG_BRIDGE_EBT_802_3 $CONFIG_BRIDGE_NF_EBTABLES
2556 +dep_tristate ' ebt: packet type filter support' CONFIG_BRIDGE_EBT_PKTTYPE $CONFIG_BRIDGE_NF_EBTABLES
2557 +dep_tristate ' ebt: STP filter support' CONFIG_BRIDGE_EBT_STP $CONFIG_BRIDGE_NF_EBTABLES
2558 +dep_tristate ' ebt: mark filter support' CONFIG_BRIDGE_EBT_MARKF $CONFIG_BRIDGE_NF_EBTABLES
2559 +dep_tristate ' ebt: arp reply target support' CONFIG_BRIDGE_EBT_ARPREPLY $CONFIG_BRIDGE_NF_EBTABLES
2560 +dep_tristate ' ebt: snat target support' CONFIG_BRIDGE_EBT_SNAT $CONFIG_BRIDGE_NF_EBTABLES
2561 +dep_tristate ' ebt: dnat target support' CONFIG_BRIDGE_EBT_DNAT $CONFIG_BRIDGE_NF_EBTABLES
2562 +dep_tristate ' ebt: redirect target support' CONFIG_BRIDGE_EBT_REDIRECT $CONFIG_BRIDGE_NF_EBTABLES
2563 +dep_tristate ' ebt: mark target support' CONFIG_BRIDGE_EBT_MARK_T $CONFIG_BRIDGE_NF_EBTABLES
2564 diff -Nur linux.old/net/bridge/netfilter/Makefile linux.dev/net/bridge/netfilter/Makefile
2565 --- linux.old/net/bridge/netfilter/Makefile 1970-01-01 01:00:00.000000000 +0100
2566 +++ linux.dev/net/bridge/netfilter/Makefile 2005-10-10 10:36:46.089869250 +0200
2569 +# Makefile for the netfilter modules on top of bridging.
2571 +# Note! Dependencies are done automagically by 'make dep', which also
2572 +# removes any old dependencies. DON'T put your own dependencies here
2573 +# unless it's something special (ie not a .c file).
2575 +# Note 2! The CFLAGS definition is now in the main makefile...
2577 +O_TARGET := netfilter.o
2579 +export-objs := ebtables.o
2581 +obj-$(CONFIG_BRIDGE_NF_EBTABLES) += ebtables.o
2582 +obj-$(CONFIG_BRIDGE_EBT_T_FILTER) += ebtable_filter.o
2583 +obj-$(CONFIG_BRIDGE_EBT_T_NAT) += ebtable_nat.o
2584 +obj-$(CONFIG_BRIDGE_EBT_BROUTE) += ebtable_broute.o
2585 +obj-$(CONFIG_BRIDGE_EBT_802_3) += ebt_802_3.o
2586 +obj-$(CONFIG_BRIDGE_EBT_ARPF) += ebt_arp.o
2587 +obj-$(CONFIG_BRIDGE_EBT_AMONG) += ebt_among.o
2588 +obj-$(CONFIG_BRIDGE_EBT_IPF) += ebt_ip.o
2589 +obj-$(CONFIG_BRIDGE_EBT_LIMIT) += ebt_limit.o
2590 +obj-$(CONFIG_BRIDGE_EBT_MARKF) += ebt_mark_m.o
2591 +obj-$(CONFIG_BRIDGE_EBT_PKTTYPE) += ebt_pkttype.o
2592 +obj-$(CONFIG_BRIDGE_EBT_STP) += ebt_stp.o
2593 +obj-$(CONFIG_BRIDGE_EBT_VLANF) += ebt_vlan.o
2594 +obj-$(CONFIG_BRIDGE_EBT_LOG) += ebt_log.o
2595 +obj-$(CONFIG_BRIDGE_EBT_LOG) += ebt_ulog.o
2596 +obj-$(CONFIG_BRIDGE_EBT_ARPREPLY) += ebt_arpreply.o
2597 +obj-$(CONFIG_BRIDGE_EBT_DNAT) += ebt_dnat.o
2598 +obj-$(CONFIG_BRIDGE_EBT_MARK_T) += ebt_mark.o
2599 +obj-$(CONFIG_BRIDGE_EBT_REDIRECT) += ebt_redirect.o
2600 +obj-$(CONFIG_BRIDGE_EBT_SNAT) += ebt_snat.o
2601 +include $(TOPDIR)/Rules.make
2602 diff -Nur linux.old/net/bridge/netfilter/ebt_802_3.c linux.dev/net/bridge/netfilter/ebt_802_3.c
2603 --- linux.old/net/bridge/netfilter/ebt_802_3.c 1970-01-01 01:00:00.000000000 +0100
2604 +++ linux.dev/net/bridge/netfilter/ebt_802_3.c 2005-10-10 10:36:46.089869250 +0200
2610 + * Chris Vitale csv@bluetail.com
2616 +#include <linux/netfilter_bridge/ebtables.h>
2617 +#include <linux/netfilter_bridge/ebt_802_3.h>
2618 +#include <linux/module.h>
2620 +static int ebt_filter_802_3(const struct sk_buff *skb, const struct net_device *in,
2621 + const struct net_device *out, const void *data, unsigned int datalen)
2623 + struct ebt_802_3_info *info = (struct ebt_802_3_info *)data;
2624 + struct ebt_802_3_hdr *hdr = (struct ebt_802_3_hdr *)skb->mac.ethernet;
2625 + uint16_t type = hdr->llc.ui.ctrl & IS_UI ? hdr->llc.ui.type : hdr->llc.ni.type;
2627 + if (info->bitmask & EBT_802_3_SAP) {
2628 + if (FWINV(info->sap != hdr->llc.ui.ssap, EBT_802_3_SAP))
2629 + return EBT_NOMATCH;
2630 + if (FWINV(info->sap != hdr->llc.ui.dsap, EBT_802_3_SAP))
2631 + return EBT_NOMATCH;
2634 + if (info->bitmask & EBT_802_3_TYPE) {
2635 + if (!(hdr->llc.ui.dsap == CHECK_TYPE && hdr->llc.ui.ssap == CHECK_TYPE))
2636 + return EBT_NOMATCH;
2637 + if (FWINV(info->type != type, EBT_802_3_TYPE))
2638 + return EBT_NOMATCH;
2644 +static struct ebt_match filter_802_3;
2645 +static int ebt_802_3_check(const char *tablename, unsigned int hookmask,
2646 + const struct ebt_entry *e, void *data, unsigned int datalen)
2648 + struct ebt_802_3_info *info = (struct ebt_802_3_info *)data;
2650 + if (datalen != EBT_ALIGN(sizeof(struct ebt_802_3_info)))
2652 + if (info->bitmask & ~EBT_802_3_MASK || info->invflags & ~EBT_802_3_MASK)
2658 +static struct ebt_match filter_802_3 =
2660 + .name = EBT_802_3_MATCH,
2661 + .match = ebt_filter_802_3,
2662 + .check = ebt_802_3_check,
2663 + .me = THIS_MODULE,
2666 +static int __init init(void)
2668 + return ebt_register_match(&filter_802_3);
2671 +static void __exit fini(void)
2673 + ebt_unregister_match(&filter_802_3);
2679 +MODULE_LICENSE("GPL");
2680 diff -Nur linux.old/net/bridge/netfilter/ebt_among.c linux.dev/net/bridge/netfilter/ebt_among.c
2681 --- linux.old/net/bridge/netfilter/ebt_among.c 1970-01-01 01:00:00.000000000 +0100
2682 +++ linux.dev/net/bridge/netfilter/ebt_among.c 2005-10-10 10:36:46.089869250 +0200
2688 + * Grzegorz Borowiak <grzes@gnu.univ.gda.pl>
2694 +#include <linux/netfilter_bridge/ebtables.h>
2695 +#include <linux/netfilter_bridge/ebt_among.h>
2696 +#include <linux/ip.h>
2697 +#include <linux/if_arp.h>
2698 +#include <linux/module.h>
2700 +static int ebt_mac_wormhash_contains(const struct ebt_mac_wormhash *wh,
2701 + const char *mac, uint32_t ip)
2703 + /* You may be puzzled as to how this code works.
2704 + * Some tricks were used, refer to
2705 + * include/linux/netfilter_bridge/ebt_among.h
2706 + * as there you can find a solution of this mystery.
2708 + const struct ebt_mac_wormhash_tuple *p;
2709 + int start, limit, i;
2710 + uint32_t cmp[2] = { 0, 0 };
2711 + int key = (const unsigned char) mac[5];
2713 + memcpy(((char *) cmp) + 2, mac, 6);
2714 + start = wh->table[key];
2715 + limit = wh->table[key + 1];
2717 + for (i = start; i < limit; i++) {
2719 + if (cmp[1] == p->cmp[1] && cmp[0] == p->cmp[0]) {
2720 + if (p->ip == 0 || p->ip == ip) {
2726 + for (i = start; i < limit; i++) {
2728 + if (cmp[1] == p->cmp[1] && cmp[0] == p->cmp[0]) {
2738 +static int ebt_mac_wormhash_check_integrity(const struct ebt_mac_wormhash
2743 + for (i = 0; i < 256; i++) {
2744 + if (wh->table[i] > wh->table[i + 1])
2745 + return -0x100 - i;
2746 + if (wh->table[i] < 0)
2747 + return -0x200 - i;
2748 + if (wh->table[i] > wh->poolsize)
2749 + return -0x300 - i;
2751 + if (wh->table[256] > wh->poolsize)
2756 +static int get_ip_dst(const struct sk_buff *skb, uint32_t * addr)
2758 + if (skb->mac.ethernet->h_proto == __constant_htons(ETH_P_IP))
2759 + *addr = skb->nh.iph->daddr;
2760 + else if (skb->mac.ethernet->h_proto == __constant_htons(ETH_P_ARP)) {
2761 + uint32_t arp_len = sizeof(struct arphdr) +
2762 + (2 * (((*skb).nh.arph)->ar_hln)) +
2763 + (2 * (((*skb).nh.arph)->ar_pln));
2765 + /* Make sure the packet is long enough. */
2766 + if ((((*skb).nh.raw) + arp_len) > (*skb).tail)
2768 + /* IPv4 addresses are always 4 bytes. */
2769 + if (((*skb).nh.arph)->ar_pln != sizeof(uint32_t))
2772 + memcpy(addr, ((*skb).nh.raw) + sizeof(struct arphdr) +
2773 + (2 * (((*skb).nh.arph)->ar_hln)) +
2774 + (((*skb).nh.arph)->ar_pln), sizeof(uint32_t));
2780 +static int get_ip_src(const struct sk_buff *skb, uint32_t * addr)
2782 + if (skb->mac.ethernet->h_proto == __constant_htons(ETH_P_IP))
2783 + *addr = skb->nh.iph->saddr;
2784 + else if (skb->mac.ethernet->h_proto == __constant_htons(ETH_P_ARP)) {
2785 + uint32_t arp_len = sizeof(struct arphdr) +
2786 + (2 * (((*skb).nh.arph)->ar_hln)) +
2787 + (2 * (((*skb).nh.arph)->ar_pln));
2789 + /* Make sure the packet is long enough. */
2790 + if ((((*skb).nh.raw) + arp_len) > (*skb).tail)
2792 + /* IPv4 addresses are always 4 bytes. */
2793 + if (((*skb).nh.arph)->ar_pln != sizeof(uint32_t))
2796 + memcpy(addr, ((*skb).nh.raw) + sizeof(struct arphdr) +
2797 + ((((*skb).nh.arph)->ar_hln)), sizeof(uint32_t));
2803 +static int ebt_filter_among(const struct sk_buff *skb,
2804 + const struct net_device *in,
2805 + const struct net_device *out, const void *data,
2806 + unsigned int datalen)
2808 + struct ebt_among_info *info = (struct ebt_among_info *) data;
2809 + const char *dmac, *smac;
2810 + const struct ebt_mac_wormhash *wh_dst, *wh_src;
2811 + uint32_t dip = 0, sip = 0;
2813 + wh_dst = ebt_among_wh_dst(info);
2814 + wh_src = ebt_among_wh_src(info);
2817 + smac = skb->mac.ethernet->h_source;
2818 + if (get_ip_src(skb, &sip))
2819 + return EBT_NOMATCH;
2820 + if (!(info->bitmask & EBT_AMONG_SRC_NEG)) {
2821 + /* we match only if it contains */
2822 + if (!ebt_mac_wormhash_contains(wh_src, smac, sip))
2823 + return EBT_NOMATCH;
2825 + /* we match only if it DOES NOT contain */
2826 + if (ebt_mac_wormhash_contains(wh_src, smac, sip))
2827 + return EBT_NOMATCH;
2832 + dmac = skb->mac.ethernet->h_dest;
2833 + if (get_ip_dst(skb, &dip))
2834 + return EBT_NOMATCH;
2835 + if (!(info->bitmask & EBT_AMONG_DST_NEG)) {
2836 + /* we match only if it contains */
2837 + if (!ebt_mac_wormhash_contains(wh_dst, dmac, dip))
2838 + return EBT_NOMATCH;
2840 + /* we match only if it DOES NOT contain */
2841 + if (ebt_mac_wormhash_contains(wh_dst, dmac, dip))
2842 + return EBT_NOMATCH;
2849 +static int ebt_among_check(const char *tablename, unsigned int hookmask,
2850 + const struct ebt_entry *e, void *data,
2851 + unsigned int datalen)
2853 + struct ebt_among_info *info = (struct ebt_among_info *) data;
2854 + int expected_length = sizeof(struct ebt_among_info);
2855 + const struct ebt_mac_wormhash *wh_dst, *wh_src;
2858 + wh_dst = ebt_among_wh_dst(info);
2859 + wh_src = ebt_among_wh_src(info);
2860 + expected_length += ebt_mac_wormhash_size(wh_dst);
2861 + expected_length += ebt_mac_wormhash_size(wh_src);
2863 + if (datalen != EBT_ALIGN(expected_length)) {
2864 + printk(KERN_WARNING
2865 + "ebtables: among: wrong size: %d"
2866 + "against expected %d, rounded to %d\n",
2867 + datalen, expected_length,
2868 + EBT_ALIGN(expected_length));
2871 + if (wh_dst && (err = ebt_mac_wormhash_check_integrity(wh_dst))) {
2872 + printk(KERN_WARNING
2873 + "ebtables: among: dst integrity fail: %x\n", -err);
2876 + if (wh_src && (err = ebt_mac_wormhash_check_integrity(wh_src))) {
2877 + printk(KERN_WARNING
2878 + "ebtables: among: src integrity fail: %x\n", -err);
2884 +static struct ebt_match filter_among = {
2893 +static int __init init(void)
2895 + return ebt_register_match(&filter_among);
2898 +static void __exit fini(void)
2900 + ebt_unregister_match(&filter_among);
2906 +MODULE_LICENSE("GPL");
2907 diff -Nur linux.old/net/bridge/netfilter/ebt_arp.c linux.dev/net/bridge/netfilter/ebt_arp.c
2908 --- linux.old/net/bridge/netfilter/ebt_arp.c 1970-01-01 01:00:00.000000000 +0100
2909 +++ linux.dev/net/bridge/netfilter/ebt_arp.c 2005-10-10 10:36:46.093869500 +0200
2915 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
2916 + * Tim Gardner <timg@tpi.com>
2922 +#include <linux/netfilter_bridge/ebtables.h>
2923 +#include <linux/netfilter_bridge/ebt_arp.h>
2924 +#include <linux/if_arp.h>
2925 +#include <linux/if_ether.h>
2926 +#include <linux/module.h>
2928 +static int ebt_filter_arp(const struct sk_buff *skb, const struct net_device *in,
2929 + const struct net_device *out, const void *data, unsigned int datalen)
2931 + struct ebt_arp_info *info = (struct ebt_arp_info *)data;
2933 + if (info->bitmask & EBT_ARP_OPCODE && FWINV(info->opcode !=
2934 + ((*skb).nh.arph)->ar_op, EBT_ARP_OPCODE))
2935 + return EBT_NOMATCH;
2936 + if (info->bitmask & EBT_ARP_HTYPE && FWINV(info->htype !=
2937 + ((*skb).nh.arph)->ar_hrd, EBT_ARP_HTYPE))
2938 + return EBT_NOMATCH;
2939 + if (info->bitmask & EBT_ARP_PTYPE && FWINV(info->ptype !=
2940 + ((*skb).nh.arph)->ar_pro, EBT_ARP_PTYPE))
2941 + return EBT_NOMATCH;
2943 + if (info->bitmask & (EBT_ARP_SRC_IP | EBT_ARP_DST_IP))
2945 + uint32_t arp_len = sizeof(struct arphdr) +
2946 + (2 * (((*skb).nh.arph)->ar_hln)) +
2947 + (2 * (((*skb).nh.arph)->ar_pln));
2951 + // Make sure the packet is long enough.
2952 + if ((((*skb).nh.raw) + arp_len) > (*skb).tail)
2953 + return EBT_NOMATCH;
2954 + // IPv4 addresses are always 4 bytes.
2955 + if (((*skb).nh.arph)->ar_pln != sizeof(uint32_t))
2956 + return EBT_NOMATCH;
2958 + if (info->bitmask & EBT_ARP_SRC_IP) {
2959 + memcpy(&src, ((*skb).nh.raw) + sizeof(struct arphdr) +
2960 + ((*skb).nh.arph)->ar_hln, sizeof(uint32_t));
2961 + if (FWINV(info->saddr != (src & info->smsk),
2963 + return EBT_NOMATCH;
2966 + if (info->bitmask & EBT_ARP_DST_IP) {
2967 + memcpy(&dst, ((*skb).nh.raw)+sizeof(struct arphdr) +
2968 + (2*(((*skb).nh.arph)->ar_hln)) +
2969 + (((*skb).nh.arph)->ar_pln), sizeof(uint32_t));
2970 + if (FWINV(info->daddr != (dst & info->dmsk),
2972 + return EBT_NOMATCH;
2976 + if (info->bitmask & (EBT_ARP_SRC_MAC | EBT_ARP_DST_MAC))
2978 + uint32_t arp_len = sizeof(struct arphdr) +
2979 + (2 * (((*skb).nh.arph)->ar_hln)) +
2980 + (2 * (((*skb).nh.arph)->ar_pln));
2981 + unsigned char dst[ETH_ALEN];
2982 + unsigned char src[ETH_ALEN];
2984 + // Make sure the packet is long enough.
2985 + if ((((*skb).nh.raw) + arp_len) > (*skb).tail)
2986 + return EBT_NOMATCH;
2987 + // MAC addresses are 6 bytes.
2988 + if (((*skb).nh.arph)->ar_hln != ETH_ALEN)
2989 + return EBT_NOMATCH;
2990 + if (info->bitmask & EBT_ARP_SRC_MAC) {
2991 + uint8_t verdict, i;
2993 + memcpy(&src, ((*skb).nh.raw) +
2994 + sizeof(struct arphdr),
2997 + for (i = 0; i < 6; i++)
2998 + verdict |= (src[i] ^ info->smaddr[i]) &
3000 + if (FWINV(verdict != 0, EBT_ARP_SRC_MAC))
3001 + return EBT_NOMATCH;
3004 + if (info->bitmask & EBT_ARP_DST_MAC) {
3005 + uint8_t verdict, i;
3007 + memcpy(&dst, ((*skb).nh.raw) +
3008 + sizeof(struct arphdr) +
3009 + (((*skb).nh.arph)->ar_hln) +
3010 + (((*skb).nh.arph)->ar_pln),
3013 + for (i = 0; i < 6; i++)
3014 + verdict |= (dst[i] ^ info->dmaddr[i]) &
3016 + if (FWINV(verdict != 0, EBT_ARP_DST_MAC))
3017 + return EBT_NOMATCH;
3024 +static int ebt_arp_check(const char *tablename, unsigned int hookmask,
3025 + const struct ebt_entry *e, void *data, unsigned int datalen)
3027 + struct ebt_arp_info *info = (struct ebt_arp_info *)data;
3029 + if (datalen != EBT_ALIGN(sizeof(struct ebt_arp_info)))
3031 + if ((e->ethproto != __constant_htons(ETH_P_ARP) &&
3032 + e->ethproto != __constant_htons(ETH_P_RARP)) ||
3033 + e->invflags & EBT_IPROTO)
3035 + if (info->bitmask & ~EBT_ARP_MASK || info->invflags & ~EBT_ARP_MASK)
3040 +static struct ebt_match filter_arp =
3042 + {NULL, NULL}, EBT_ARP_MATCH, ebt_filter_arp, ebt_arp_check, NULL,
3046 +static int __init init(void)
3048 + return ebt_register_match(&filter_arp);
3051 +static void __exit fini(void)
3053 + ebt_unregister_match(&filter_arp);
3059 +MODULE_LICENSE("GPL");
3060 diff -Nur linux.old/net/bridge/netfilter/ebt_arpreply.c linux.dev/net/bridge/netfilter/ebt_arpreply.c
3061 --- linux.old/net/bridge/netfilter/ebt_arpreply.c 1970-01-01 01:00:00.000000000 +0100
3062 +++ linux.dev/net/bridge/netfilter/ebt_arpreply.c 2005-10-10 10:36:46.089869250 +0200
3068 + * Grzegorz Borowiak <grzes@gnu.univ.gda.pl>
3069 + * Bart De Schuymer <bdschuym@pandora.be>
3075 +#include <linux/netfilter_bridge/ebtables.h>
3076 +#include <linux/netfilter_bridge/ebt_arpreply.h>
3077 +#include <linux/if_arp.h>
3078 +#include <net/arp.h>
3079 +#include <linux/module.h>
3081 +static int ebt_target_reply(struct sk_buff **pskb, unsigned int hooknr,
3082 + const struct net_device *in, const struct net_device *out,
3083 + const void *data, unsigned int datalen)
3085 + struct ebt_arpreply_info *info = (struct ebt_arpreply_info *)data;
3086 + struct arphdr *ah;
3087 + unsigned char *sha, *arp_ptr;
3090 + ah = (**pskb).nh.arph;
3091 + if (ah->ar_op != __constant_htons(ARPOP_REQUEST) ||
3092 + ah->ar_hln != ETH_ALEN || ah->ar_pro != htons(ETH_P_IP) ||
3094 + return EBT_CONTINUE;
3096 + arp_ptr = (unsigned char *)(ah + 1);
3098 + /* get source and target IP */
3100 + arp_ptr += ETH_ALEN;
3101 + memcpy(&sip, arp_ptr, 4);
3102 + arp_ptr += 4 + ETH_ALEN;
3103 + memcpy(&tip, arp_ptr, 4);
3105 + arp_send(ARPOP_REPLY, ETH_P_ARP, sip, in, tip, sha, info->mac, sha);
3107 + return info->target;
3110 +static int ebt_target_reply_check(const char *tablename, unsigned int hookmask,
3111 + const struct ebt_entry *e, void *data, unsigned int datalen)
3113 + struct ebt_arpreply_info *info = (struct ebt_arpreply_info *)data;
3115 + if (datalen != EBT_ALIGN(sizeof(struct ebt_arpreply_info)))
3117 + if (BASE_CHAIN && info->target == EBT_RETURN)
3119 + if (e->ethproto != __constant_htons(ETH_P_ARP) ||
3120 + e->invflags & EBT_IPROTO)
3122 + CLEAR_BASE_CHAIN_BIT;
3123 + if (strcmp(tablename, "nat") || hookmask & ~(1 << NF_BR_PRE_ROUTING))
3128 +static struct ebt_target reply_target =
3130 + .name = EBT_ARPREPLY_TARGET,
3131 + .target = ebt_target_reply,
3132 + .check = ebt_target_reply_check,
3133 + .me = THIS_MODULE,
3136 +static int __init init(void)
3138 + return ebt_register_target(&reply_target);
3141 +static void __exit fini(void)
3143 + ebt_unregister_target(&reply_target);
3149 +MODULE_LICENSE("GPL");
3150 diff -Nur linux.old/net/bridge/netfilter/ebt_dnat.c linux.dev/net/bridge/netfilter/ebt_dnat.c
3151 --- linux.old/net/bridge/netfilter/ebt_dnat.c 1970-01-01 01:00:00.000000000 +0100
3152 +++ linux.dev/net/bridge/netfilter/ebt_dnat.c 2005-10-10 10:36:46.109870500 +0200
3158 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
3164 +#include <linux/netfilter_bridge/ebtables.h>
3165 +#include <linux/netfilter_bridge/ebt_nat.h>
3166 +#include <linux/module.h>
3167 +#include <net/sock.h>
3169 +static int ebt_target_dnat(struct sk_buff **pskb, unsigned int hooknr,
3170 + const struct net_device *in, const struct net_device *out,
3171 + const void *data, unsigned int datalen)
3173 + struct ebt_nat_info *info = (struct ebt_nat_info *)data;
3175 + memcpy(((**pskb).mac.ethernet)->h_dest, info->mac,
3176 + ETH_ALEN * sizeof(unsigned char));
3177 + return info->target;
3180 +static int ebt_target_dnat_check(const char *tablename, unsigned int hookmask,
3181 + const struct ebt_entry *e, void *data, unsigned int datalen)
3183 + struct ebt_nat_info *info = (struct ebt_nat_info *)data;
3185 + if (BASE_CHAIN && info->target == EBT_RETURN)
3187 + CLEAR_BASE_CHAIN_BIT;
3188 + if ( (strcmp(tablename, "nat") ||
3189 + (hookmask & ~((1 << NF_BR_PRE_ROUTING) | (1 << NF_BR_LOCAL_OUT)))) &&
3190 + (strcmp(tablename, "broute") || hookmask & ~(1 << NF_BR_BROUTING)) )
3192 + if (datalen != EBT_ALIGN(sizeof(struct ebt_nat_info)))
3194 + if (INVALID_TARGET)
3199 +static struct ebt_target dnat =
3201 + {NULL, NULL}, EBT_DNAT_TARGET, ebt_target_dnat, ebt_target_dnat_check,
3205 +static int __init init(void)
3207 + return ebt_register_target(&dnat);
3210 +static void __exit fini(void)
3212 + ebt_unregister_target(&dnat);
3218 +MODULE_LICENSE("GPL");
3219 diff -Nur linux.old/net/bridge/netfilter/ebt_ip.c linux.dev/net/bridge/netfilter/ebt_ip.c
3220 --- linux.old/net/bridge/netfilter/ebt_ip.c 1970-01-01 01:00:00.000000000 +0100
3221 +++ linux.dev/net/bridge/netfilter/ebt_ip.c 2005-10-10 10:36:46.093869500 +0200
3227 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
3232 + * added ip-sport and ip-dport
3233 + * Innominate Security Technologies AG <mhopf@innominate.com>
3237 +#include <linux/netfilter_bridge/ebtables.h>
3238 +#include <linux/netfilter_bridge/ebt_ip.h>
3239 +#include <linux/ip.h>
3240 +#include <linux/in.h>
3241 +#include <linux/module.h>
3249 + unsigned char *raw;
3250 + struct tcpudphdr *tuh;
3253 +static int ebt_filter_ip(const struct sk_buff *skb, const struct net_device *in,
3254 + const struct net_device *out, const void *data,
3255 + unsigned int datalen)
3257 + struct ebt_ip_info *info = (struct ebt_ip_info *)data;
3259 + if (info->bitmask & EBT_IP_TOS &&
3260 + FWINV(info->tos != ((*skb).nh.iph)->tos, EBT_IP_TOS))
3261 + return EBT_NOMATCH;
3262 + if (info->bitmask & EBT_IP_PROTO) {
3263 + if (FWINV(info->protocol != ((*skb).nh.iph)->protocol,
3265 + return EBT_NOMATCH;
3266 + if ( info->protocol == IPPROTO_TCP ||
3267 + info->protocol == IPPROTO_UDP )
3270 + h.raw = skb->data + skb->nh.iph->ihl*4;
3271 + if (info->bitmask & EBT_IP_DPORT) {
3272 + uint16_t port = ntohs(h.tuh->dst);
3273 + if (FWINV(port < info->dport[0] ||
3274 + port > info->dport[1],
3276 + return EBT_NOMATCH;
3278 + if (info->bitmask & EBT_IP_SPORT) {
3279 + uint16_t port = ntohs(h.tuh->src);
3280 + if (FWINV(port < info->sport[0] ||
3281 + port > info->sport[1],
3283 + return EBT_NOMATCH;
3287 + if (info->bitmask & EBT_IP_SOURCE &&
3288 + FWINV((((*skb).nh.iph)->saddr & info->smsk) !=
3289 + info->saddr, EBT_IP_SOURCE))
3290 + return EBT_NOMATCH;
3291 + if ((info->bitmask & EBT_IP_DEST) &&
3292 + FWINV((((*skb).nh.iph)->daddr & info->dmsk) !=
3293 + info->daddr, EBT_IP_DEST))
3294 + return EBT_NOMATCH;
3298 +static int ebt_ip_check(const char *tablename, unsigned int hookmask,
3299 + const struct ebt_entry *e, void *data, unsigned int datalen)
3301 + struct ebt_ip_info *info = (struct ebt_ip_info *)data;
3303 + if (datalen != EBT_ALIGN(sizeof(struct ebt_ip_info)))
3305 + if (e->ethproto != __constant_htons(ETH_P_IP) ||
3306 + e->invflags & EBT_IPROTO)
3308 + if (info->bitmask & ~EBT_IP_MASK || info->invflags & ~EBT_IP_MASK)
3310 + if (info->bitmask & (EBT_IP_DPORT | EBT_IP_SPORT)) {
3311 + if (!info->bitmask & EBT_IPROTO)
3313 + if (info->protocol != IPPROTO_TCP &&
3314 + info->protocol != IPPROTO_UDP)
3317 + if (info->bitmask & EBT_IP_DPORT && info->dport[0] > info->dport[1])
3319 + if (info->bitmask & EBT_IP_SPORT && info->sport[0] > info->sport[1])
3324 +static struct ebt_match filter_ip =
3326 + {NULL, NULL}, EBT_IP_MATCH, ebt_filter_ip, ebt_ip_check, NULL,
3330 +static int __init init(void)
3332 + return ebt_register_match(&filter_ip);
3335 +static void __exit fini(void)
3337 + ebt_unregister_match(&filter_ip);
3343 +MODULE_LICENSE("GPL");
3344 diff -Nur linux.old/net/bridge/netfilter/ebt_limit.c linux.dev/net/bridge/netfilter/ebt_limit.c
3345 --- linux.old/net/bridge/netfilter/ebt_limit.c 1970-01-01 01:00:00.000000000 +0100
3346 +++ linux.dev/net/bridge/netfilter/ebt_limit.c 2005-10-10 10:36:46.089869250 +0200
3352 + * Tom Marshall <tommy@home.tig-grr.com>
3354 + * Mostly copied from netfilter's ipt_limit.c, see that file for explanation
3360 +#include <linux/netfilter_bridge/ebtables.h>
3361 +#include <linux/netfilter_bridge/ebt_limit.h>
3362 +#include <linux/module.h>
3364 +#include <linux/netdevice.h>
3365 +#include <linux/spinlock.h>
3367 +static spinlock_t limit_lock = SPIN_LOCK_UNLOCKED;
3369 +#define CREDITS_PER_JIFFY 128
3371 +static int ebt_limit_match(const struct sk_buff *skb, const struct net_device *in,
3372 + const struct net_device *out, const void *data, unsigned int datalen)
3374 + struct ebt_limit_info *info = (struct ebt_limit_info *)data;
3375 + unsigned long now = jiffies;
3377 + spin_lock_bh(&limit_lock);
3378 + info->credit += (now - xchg(&info->prev, now)) * CREDITS_PER_JIFFY;
3379 + if (info->credit > info->credit_cap)
3380 + info->credit = info->credit_cap;
3382 + if (info->credit >= info->cost) {
3383 + /* We're not limited. */
3384 + info->credit -= info->cost;
3385 + spin_unlock_bh(&limit_lock);
3389 + spin_unlock_bh(&limit_lock);
3390 + return EBT_NOMATCH;
3393 +/* Precision saver. */
3395 +user2credits(u_int32_t user)
3397 + /* If multiplying would overflow... */
3398 + if (user > 0xFFFFFFFF / (HZ*CREDITS_PER_JIFFY))
3399 + /* Divide first. */
3400 + return (user / EBT_LIMIT_SCALE) * HZ * CREDITS_PER_JIFFY;
3402 + return (user * HZ * CREDITS_PER_JIFFY) / EBT_LIMIT_SCALE;
3405 +static int ebt_limit_check(const char *tablename, unsigned int hookmask,
3406 + const struct ebt_entry *e, void *data, unsigned int datalen)
3408 + struct ebt_limit_info *info = (struct ebt_limit_info *)data;
3410 + if (datalen != EBT_ALIGN(sizeof(struct ebt_limit_info)))
3413 + /* Check for overflow. */
3414 + if (info->burst == 0
3415 + || user2credits(info->avg * info->burst) < user2credits(info->avg)) {
3416 + printk("Overflow in ebt_limit: %u/%u\n",
3417 + info->avg, info->burst);
3421 + /* User avg in seconds * EBT_LIMIT_SCALE: convert to jiffies * 128. */
3422 + info->prev = jiffies;
3423 + info->credit = user2credits(info->avg * info->burst);
3424 + info->credit_cap = user2credits(info->avg * info->burst);
3425 + info->cost = user2credits(info->avg);
3429 +static struct ebt_match ebt_limit_reg =
3431 + {NULL, NULL}, EBT_LIMIT_MATCH, ebt_limit_match, ebt_limit_check, NULL,
3435 +static int __init init(void)
3437 + return ebt_register_match(&ebt_limit_reg);
3440 +static void __exit fini(void)
3442 + ebt_unregister_match(&ebt_limit_reg);
3448 +MODULE_LICENSE("GPL");
3449 diff -Nur linux.old/net/bridge/netfilter/ebt_log.c linux.dev/net/bridge/netfilter/ebt_log.c
3450 --- linux.old/net/bridge/netfilter/ebt_log.c 1970-01-01 01:00:00.000000000 +0100
3451 +++ linux.dev/net/bridge/netfilter/ebt_log.c 2005-10-10 10:36:46.105870250 +0200
3457 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
3463 +#include <linux/netfilter_bridge/ebtables.h>
3464 +#include <linux/netfilter_bridge/ebt_log.h>
3465 +#include <linux/module.h>
3466 +#include <linux/ip.h>
3467 +#include <linux/in.h>
3468 +#include <linux/if_arp.h>
3469 +#include <linux/spinlock.h>
3471 +static spinlock_t ebt_log_lock = SPIN_LOCK_UNLOCKED;
3473 +static int ebt_log_check(const char *tablename, unsigned int hookmask,
3474 + const struct ebt_entry *e, void *data, unsigned int datalen)
3476 + struct ebt_log_info *info = (struct ebt_log_info *)data;
3478 + if (datalen != EBT_ALIGN(sizeof(struct ebt_log_info)))
3480 + if (info->bitmask & ~EBT_LOG_MASK)
3482 + if (info->loglevel >= 8)
3484 + info->prefix[EBT_LOG_PREFIX_SIZE - 1] = '\0';
3496 + unsigned char mac_src[ETH_ALEN];
3497 + unsigned char ip_src[4];
3498 + unsigned char mac_dst[ETH_ALEN];
3499 + unsigned char ip_dst[4];
3502 +static void print_MAC(unsigned char *p)
3506 + for (i = 0; i < ETH_ALEN; i++, p++)
3507 + printk("%02x%c", *p, i == ETH_ALEN - 1 ? ' ':':');
3510 +#define myNIPQUAD(a) a[0], a[1], a[2], a[3]
3511 +static void ebt_log(const struct sk_buff *skb, unsigned int hooknr,
3512 + const struct net_device *in, const struct net_device *out,
3513 + const void *data, unsigned int datalen)
3515 + struct ebt_log_info *info = (struct ebt_log_info *)data;
3516 + char level_string[4] = "< >";
3517 + level_string[1] = '0' + info->loglevel;
3519 + spin_lock_bh(&ebt_log_lock);
3520 + printk(level_string);
3521 + printk("%s IN=%s OUT=%s ", info->prefix, in ? in->name : "",
3522 + out ? out->name : "");
3524 + printk("MAC source = ");
3525 + print_MAC((skb->mac.ethernet)->h_source);
3526 + printk("MAC dest = ");
3527 + print_MAC((skb->mac.ethernet)->h_dest);
3529 + printk("proto = 0x%04x", ntohs(((*skb).mac.ethernet)->h_proto));
3531 + if ((info->bitmask & EBT_LOG_IP) && skb->mac.ethernet->h_proto ==
3533 + struct iphdr *iph = skb->nh.iph;
3534 + printk(" IP SRC=%u.%u.%u.%u IP DST=%u.%u.%u.%u,",
3535 + NIPQUAD(iph->saddr), NIPQUAD(iph->daddr));
3536 + printk(" IP tos=0x%02X, IP proto=%d", iph->tos, iph->protocol);
3537 + if (iph->protocol == IPPROTO_TCP ||
3538 + iph->protocol == IPPROTO_UDP) {
3539 + struct tcpudphdr *ports = (struct tcpudphdr *)(skb->data + iph->ihl*4);
3541 + if (skb->data + iph->ihl*4 > skb->tail) {
3542 + printk(" INCOMPLETE TCP/UDP header");
3545 + printk(" SPT=%u DPT=%u", ntohs(ports->src),
3546 + ntohs(ports->dst));
3551 + if ((info->bitmask & EBT_LOG_ARP) &&
3552 + ((skb->mac.ethernet->h_proto == __constant_htons(ETH_P_ARP)) ||
3553 + (skb->mac.ethernet->h_proto == __constant_htons(ETH_P_RARP)))) {
3554 + struct arphdr * arph = skb->nh.arph;
3555 + printk(" ARP HTYPE=%d, PTYPE=0x%04x, OPCODE=%d",
3556 + ntohs(arph->ar_hrd), ntohs(arph->ar_pro),
3557 + ntohs(arph->ar_op));
3558 + /* If it's for Ethernet and the lengths are OK,
3559 + * then log the ARP payload */
3560 + if (arph->ar_hrd == __constant_htons(1) &&
3561 + arph->ar_hln == ETH_ALEN &&
3562 + arph->ar_pln == sizeof(uint32_t)) {
3563 + struct arppayload *arpp = (struct arppayload *)(skb->data + sizeof(*arph));
3565 + if (skb->data + sizeof(*arph) > skb->tail) {
3566 + printk(" INCOMPLETE ARP header");
3570 + printk(" ARP MAC SRC=");
3571 + print_MAC(arpp->mac_src);
3572 + printk(" ARP IP SRC=%u.%u.%u.%u",
3573 + myNIPQUAD(arpp->ip_src));
3574 + printk(" ARP MAC DST=");
3575 + print_MAC(arpp->mac_dst);
3576 + printk(" ARP IP DST=%u.%u.%u.%u",
3577 + myNIPQUAD(arpp->ip_dst));
3583 + spin_unlock_bh(&ebt_log_lock);
3586 +static struct ebt_watcher log =
3588 + {NULL, NULL}, EBT_LOG_WATCHER, ebt_log, ebt_log_check, NULL,
3592 +static int __init init(void)
3594 + return ebt_register_watcher(&log);
3597 +static void __exit fini(void)
3599 + ebt_unregister_watcher(&log);
3605 +MODULE_LICENSE("GPL");
3606 diff -Nur linux.old/net/bridge/netfilter/ebt_mark.c linux.dev/net/bridge/netfilter/ebt_mark.c
3607 --- linux.old/net/bridge/netfilter/ebt_mark.c 1970-01-01 01:00:00.000000000 +0100
3608 +++ linux.dev/net/bridge/netfilter/ebt_mark.c 2005-10-10 10:36:46.089869250 +0200
3614 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
3620 +// The mark target can be used in any chain
3621 +// I believe adding a mangle table just for marking is total overkill
3622 +// Marking a frame doesn't really change anything in the frame anyway
3624 +#include <linux/netfilter_bridge/ebtables.h>
3625 +#include <linux/netfilter_bridge/ebt_mark_t.h>
3626 +#include <linux/module.h>
3628 +static int ebt_target_mark(struct sk_buff **pskb, unsigned int hooknr,
3629 + const struct net_device *in, const struct net_device *out,
3630 + const void *data, unsigned int datalen)
3632 + struct ebt_mark_t_info *info = (struct ebt_mark_t_info *)data;
3634 + if ((*pskb)->nfmark != info->mark) {
3635 + (*pskb)->nfmark = info->mark;
3636 + (*pskb)->nfcache |= NFC_ALTERED;
3638 + return info->target;
3641 +static int ebt_target_mark_check(const char *tablename, unsigned int hookmask,
3642 + const struct ebt_entry *e, void *data, unsigned int datalen)
3644 + struct ebt_mark_t_info *info = (struct ebt_mark_t_info *)data;
3646 + if (datalen != EBT_ALIGN(sizeof(struct ebt_mark_t_info)))
3648 + if (BASE_CHAIN && info->target == EBT_RETURN)
3650 + CLEAR_BASE_CHAIN_BIT;
3651 + if (INVALID_TARGET)
3656 +static struct ebt_target mark_target =
3658 + {NULL, NULL}, EBT_MARK_TARGET, ebt_target_mark,
3659 + ebt_target_mark_check, NULL, THIS_MODULE
3662 +static int __init init(void)
3664 + return ebt_register_target(&mark_target);
3667 +static void __exit fini(void)
3669 + ebt_unregister_target(&mark_target);
3675 +MODULE_LICENSE("GPL");
3676 diff -Nur linux.old/net/bridge/netfilter/ebt_mark_m.c linux.dev/net/bridge/netfilter/ebt_mark_m.c
3677 --- linux.old/net/bridge/netfilter/ebt_mark_m.c 1970-01-01 01:00:00.000000000 +0100
3678 +++ linux.dev/net/bridge/netfilter/ebt_mark_m.c 2005-10-10 10:36:46.093869500 +0200
3684 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
3690 +#include <linux/netfilter_bridge/ebtables.h>
3691 +#include <linux/netfilter_bridge/ebt_mark_m.h>
3692 +#include <linux/module.h>
3694 +static int ebt_filter_mark(const struct sk_buff *skb,
3695 + const struct net_device *in, const struct net_device *out, const void *data,
3696 + unsigned int datalen)
3698 + struct ebt_mark_m_info *info = (struct ebt_mark_m_info *) data;
3700 + if (info->bitmask & EBT_MARK_OR)
3701 + return !(!!(skb->nfmark & info->mask) ^ info->invert);
3702 + return !(((skb->nfmark & info->mask) == info->mark) ^ info->invert);
3705 +static int ebt_mark_check(const char *tablename, unsigned int hookmask,
3706 + const struct ebt_entry *e, void *data, unsigned int datalen)
3708 + struct ebt_mark_m_info *info = (struct ebt_mark_m_info *) data;
3710 + if (datalen != EBT_ALIGN(sizeof(struct ebt_mark_m_info)))
3712 + if (info->bitmask & ~EBT_MARK_MASK)
3714 + if ((info->bitmask & EBT_MARK_OR) && (info->bitmask & EBT_MARK_AND))
3716 + if (!info->bitmask)
3721 +static struct ebt_match filter_mark =
3723 + {NULL, NULL}, EBT_MARK_MATCH, ebt_filter_mark, ebt_mark_check, NULL,
3727 +static int __init init(void)
3729 + return ebt_register_match(&filter_mark);
3732 +static void __exit fini(void)
3734 + ebt_unregister_match(&filter_mark);
3740 +MODULE_LICENSE("GPL");
3741 diff -Nur linux.old/net/bridge/netfilter/ebt_pkttype.c linux.dev/net/bridge/netfilter/ebt_pkttype.c
3742 --- linux.old/net/bridge/netfilter/ebt_pkttype.c 1970-01-01 01:00:00.000000000 +0100
3743 +++ linux.dev/net/bridge/netfilter/ebt_pkttype.c 2005-10-10 10:36:46.093869500 +0200
3749 + * Bart De Schuymer <bdschuym@pandora.be>
3755 +#include <linux/netfilter_bridge/ebtables.h>
3756 +#include <linux/netfilter_bridge/ebt_pkttype.h>
3757 +#include <linux/module.h>
3759 +static int ebt_filter_pkttype(const struct sk_buff *skb,
3760 + const struct net_device *in,
3761 + const struct net_device *out,
3763 + unsigned int datalen)
3765 + struct ebt_pkttype_info *info = (struct ebt_pkttype_info *)data;
3767 + return (skb->pkt_type != info->pkt_type) ^ info->invert;
3770 +static int ebt_pkttype_check(const char *tablename, unsigned int hookmask,
3771 + const struct ebt_entry *e, void *data, unsigned int datalen)
3773 + struct ebt_pkttype_info *info = (struct ebt_pkttype_info *)data;
3775 + if (datalen != EBT_ALIGN(sizeof(struct ebt_pkttype_info)))
3777 + if (info->invert != 0 && info->invert != 1)
3779 + /* Allow any pkt_type value */
3783 +static struct ebt_match filter_pkttype =
3785 + .name = EBT_PKTTYPE_MATCH,
3786 + .match = ebt_filter_pkttype,
3787 + .check = ebt_pkttype_check,
3788 + .me = THIS_MODULE,
3791 +static int __init init(void)
3793 + return ebt_register_match(&filter_pkttype);
3796 +static void __exit fini(void)
3798 + ebt_unregister_match(&filter_pkttype);
3804 +MODULE_LICENSE("GPL");
3805 diff -Nur linux.old/net/bridge/netfilter/ebt_redirect.c linux.dev/net/bridge/netfilter/ebt_redirect.c
3806 --- linux.old/net/bridge/netfilter/ebt_redirect.c 1970-01-01 01:00:00.000000000 +0100
3807 +++ linux.dev/net/bridge/netfilter/ebt_redirect.c 2005-10-10 10:36:46.093869500 +0200
3813 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
3819 +#include <linux/netfilter_bridge/ebtables.h>
3820 +#include <linux/netfilter_bridge/ebt_redirect.h>
3821 +#include <linux/module.h>
3822 +#include <net/sock.h>
3823 +#include "../br_private.h"
3825 +static int ebt_target_redirect(struct sk_buff **pskb, unsigned int hooknr,
3826 + const struct net_device *in, const struct net_device *out,
3827 + const void *data, unsigned int datalen)
3829 + struct ebt_redirect_info *info = (struct ebt_redirect_info *)data;
3831 + if (hooknr != NF_BR_BROUTING)
3832 + memcpy((**pskb).mac.ethernet->h_dest,
3833 + in->br_port->br->dev.dev_addr, ETH_ALEN);
3835 + memcpy((**pskb).mac.ethernet->h_dest,
3836 + in->dev_addr, ETH_ALEN);
3837 + (*pskb)->pkt_type = PACKET_HOST;
3839 + return info->target;
3842 +static int ebt_target_redirect_check(const char *tablename, unsigned int hookmask,
3843 + const struct ebt_entry *e, void *data, unsigned int datalen)
3845 + struct ebt_redirect_info *info = (struct ebt_redirect_info *)data;
3847 + if (datalen != EBT_ALIGN(sizeof(struct ebt_redirect_info)))
3849 + if (BASE_CHAIN && info->target == EBT_RETURN)
3851 + CLEAR_BASE_CHAIN_BIT;
3852 + if ( (strcmp(tablename, "nat") || hookmask & ~(1 << NF_BR_PRE_ROUTING)) &&
3853 + (strcmp(tablename, "broute") || hookmask & ~(1 << NF_BR_BROUTING)) )
3855 + if (INVALID_TARGET)
3860 +static struct ebt_target redirect_target =
3862 + {NULL, NULL}, EBT_REDIRECT_TARGET, ebt_target_redirect,
3863 + ebt_target_redirect_check, NULL, THIS_MODULE
3866 +static int __init init(void)
3868 + return ebt_register_target(&redirect_target);
3871 +static void __exit fini(void)
3873 + ebt_unregister_target(&redirect_target);
3879 +MODULE_LICENSE("GPL");
3880 diff -Nur linux.old/net/bridge/netfilter/ebt_snat.c linux.dev/net/bridge/netfilter/ebt_snat.c
3881 --- linux.old/net/bridge/netfilter/ebt_snat.c 1970-01-01 01:00:00.000000000 +0100
3882 +++ linux.dev/net/bridge/netfilter/ebt_snat.c 2005-10-10 10:36:46.109870500 +0200
3888 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
3894 +#include <linux/netfilter_bridge/ebtables.h>
3895 +#include <linux/netfilter_bridge/ebt_nat.h>
3896 +#include <linux/module.h>
3898 +static int ebt_target_snat(struct sk_buff **pskb, unsigned int hooknr,
3899 + const struct net_device *in, const struct net_device *out,
3900 + const void *data, unsigned int datalen)
3902 + struct ebt_nat_info *info = (struct ebt_nat_info *) data;
3904 + memcpy(((**pskb).mac.ethernet)->h_source, info->mac,
3905 + ETH_ALEN * sizeof(unsigned char));
3906 + return info->target;
3909 +static int ebt_target_snat_check(const char *tablename, unsigned int hookmask,
3910 + const struct ebt_entry *e, void *data, unsigned int datalen)
3912 + struct ebt_nat_info *info = (struct ebt_nat_info *) data;
3914 + if (datalen != EBT_ALIGN(sizeof(struct ebt_nat_info)))
3916 + if (BASE_CHAIN && info->target == EBT_RETURN)
3918 + CLEAR_BASE_CHAIN_BIT;
3919 + if (strcmp(tablename, "nat"))
3921 + if (hookmask & ~(1 << NF_BR_POST_ROUTING))
3923 + if (INVALID_TARGET)
3928 +static struct ebt_target snat =
3930 + {NULL, NULL}, EBT_SNAT_TARGET, ebt_target_snat, ebt_target_snat_check,
3934 +static int __init init(void)
3936 + return ebt_register_target(&snat);
3939 +static void __exit fini(void)
3941 + ebt_unregister_target(&snat);
3947 +MODULE_LICENSE("GPL");
3948 diff -Nur linux.old/net/bridge/netfilter/ebt_stp.c linux.dev/net/bridge/netfilter/ebt_stp.c
3949 --- linux.old/net/bridge/netfilter/ebt_stp.c 1970-01-01 01:00:00.000000000 +0100
3950 +++ linux.dev/net/bridge/netfilter/ebt_stp.c 2005-10-10 10:36:46.093869500 +0200
3956 + * Bart De Schuymer <bdschuym@pandora.be>
3957 + * Stephen Hemminger <shemminger@osdl.org>
3962 +#include <linux/netfilter_bridge/ebtables.h>
3963 +#include <linux/netfilter_bridge/ebt_stp.h>
3964 +#include <linux/module.h>
3966 +#define BPDU_TYPE_CONFIG 0
3967 +#define BPDU_TYPE_TCN 0x80
3969 +struct stp_header {
3978 +struct stp_config_pdu {
3981 + uint8_t root_cost[4];
3982 + uint8_t sender[8];
3984 + uint8_t msg_age[2];
3985 + uint8_t max_age[2];
3986 + uint8_t hello_time[2];
3987 + uint8_t forward_delay[2];
3990 +#define NR16(p) (p[0] << 8 | p[1])
3991 +#define NR32(p) ((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3])
3993 +static int ebt_filter_config(struct ebt_stp_info *info,
3994 + struct stp_config_pdu *stpc)
3996 + struct ebt_stp_config_info *c;
4001 + c = &info->config;
4002 + if ((info->bitmask & EBT_STP_FLAGS) &&
4003 + FWINV(c->flags != stpc->flags, EBT_STP_FLAGS))
4004 + return EBT_NOMATCH;
4005 + if (info->bitmask & EBT_STP_ROOTPRIO) {
4006 + v16 = NR16(stpc->root);
4007 + if (FWINV(v16 < c->root_priol ||
4008 + v16 > c->root_priou, EBT_STP_ROOTPRIO))
4009 + return EBT_NOMATCH;
4011 + if (info->bitmask & EBT_STP_ROOTADDR) {
4013 + for (i = 0; i < 6; i++)
4014 + verdict |= (stpc->root[2+i] ^ c->root_addr[i]) &
4015 + c->root_addrmsk[i];
4016 + if (FWINV(verdict != 0, EBT_STP_ROOTADDR))
4017 + return EBT_NOMATCH;
4019 + if (info->bitmask & EBT_STP_ROOTCOST) {
4020 + v32 = NR32(stpc->root_cost);
4021 + if (FWINV(v32 < c->root_costl ||
4022 + v32 > c->root_costu, EBT_STP_ROOTCOST))
4023 + return EBT_NOMATCH;
4025 + if (info->bitmask & EBT_STP_SENDERPRIO) {
4026 + v16 = NR16(stpc->sender);
4027 + if (FWINV(v16 < c->sender_priol ||
4028 + v16 > c->sender_priou, EBT_STP_SENDERPRIO))
4029 + return EBT_NOMATCH;
4031 + if (info->bitmask & EBT_STP_SENDERADDR) {
4033 + for (i = 0; i < 6; i++)
4034 + verdict |= (stpc->sender[2+i] ^ c->sender_addr[i]) &
4035 + c->sender_addrmsk[i];
4036 + if (FWINV(verdict != 0, EBT_STP_SENDERADDR))
4037 + return EBT_NOMATCH;
4039 + if (info->bitmask & EBT_STP_PORT) {
4040 + v16 = NR16(stpc->port);
4041 + if (FWINV(v16 < c->portl ||
4042 + v16 > c->portu, EBT_STP_PORT))
4043 + return EBT_NOMATCH;
4045 + if (info->bitmask & EBT_STP_MSGAGE) {
4046 + v16 = NR16(stpc->msg_age);
4047 + if (FWINV(v16 < c->msg_agel ||
4048 + v16 > c->msg_ageu, EBT_STP_MSGAGE))
4049 + return EBT_NOMATCH;
4051 + if (info->bitmask & EBT_STP_MAXAGE) {
4052 + v16 = NR16(stpc->max_age);
4053 + if (FWINV(v16 < c->max_agel ||
4054 + v16 > c->max_ageu, EBT_STP_MAXAGE))
4055 + return EBT_NOMATCH;
4057 + if (info->bitmask & EBT_STP_HELLOTIME) {
4058 + v16 = NR16(stpc->hello_time);
4059 + if (FWINV(v16 < c->hello_timel ||
4060 + v16 > c->hello_timeu, EBT_STP_HELLOTIME))
4061 + return EBT_NOMATCH;
4063 + if (info->bitmask & EBT_STP_FWDD) {
4064 + v16 = NR16(stpc->forward_delay);
4065 + if (FWINV(v16 < c->forward_delayl ||
4066 + v16 > c->forward_delayu, EBT_STP_FWDD))
4067 + return EBT_NOMATCH;
4072 +static int ebt_filter_stp(const struct sk_buff *skb, const struct net_device *in,
4073 + const struct net_device *out, const void *data, unsigned int datalen)
4075 + struct ebt_stp_info *info = (struct ebt_stp_info *)data;
4076 + struct stp_header stph;
4077 + uint8_t header[6] = {0x42, 0x42, 0x03, 0x00, 0x00, 0x00};
4078 + if (skb_copy_bits(skb, 0, &stph, sizeof(stph)))
4079 + return EBT_NOMATCH;
4081 + /* The stp code only considers these */
4082 + if (memcmp(&stph, header, sizeof(header)))
4083 + return EBT_NOMATCH;
4085 + if (info->bitmask & EBT_STP_TYPE
4086 + && FWINV(info->type != stph.type, EBT_STP_TYPE))
4087 + return EBT_NOMATCH;
4089 + if (stph.type == BPDU_TYPE_CONFIG &&
4090 + info->bitmask & EBT_STP_CONFIG_MASK) {
4091 + struct stp_config_pdu stpc;
4093 + if (skb_copy_bits(skb, sizeof(stph), &stpc, sizeof(stpc)))
4094 + return EBT_NOMATCH;
4095 + return ebt_filter_config(info, &stpc);
4100 +static int ebt_stp_check(const char *tablename, unsigned int hookmask,
4101 + const struct ebt_entry *e, void *data, unsigned int datalen)
4103 + struct ebt_stp_info *info = (struct ebt_stp_info *)data;
4104 + int len = EBT_ALIGN(sizeof(struct ebt_stp_info));
4105 + uint8_t bridge_ula[6] = { 0x01, 0x80, 0xc2, 0x00, 0x00, 0x00 };
4106 + uint8_t msk[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
4108 + if (info->bitmask & ~EBT_STP_MASK || info->invflags & ~EBT_STP_MASK ||
4109 + !(info->bitmask & EBT_STP_MASK))
4111 + if (datalen != len)
4113 + /* Make sure the match only receives stp frames */
4114 + if (memcmp(e->destmac, bridge_ula, ETH_ALEN) ||
4115 + memcmp(e->destmsk, msk, ETH_ALEN) || !(e->bitmask & EBT_DESTMAC))
4121 +static struct ebt_match filter_stp =
4123 + .name = EBT_STP_MATCH,
4124 + .match = ebt_filter_stp,
4125 + .check = ebt_stp_check,
4126 + .me = THIS_MODULE,
4129 +static int __init init(void)
4131 + return ebt_register_match(&filter_stp);
4134 +static void __exit fini(void)
4136 + ebt_unregister_match(&filter_stp);
4142 +MODULE_LICENSE("GPL");
4143 diff -Nur linux.old/net/bridge/netfilter/ebt_ulog.c linux.dev/net/bridge/netfilter/ebt_ulog.c
4144 --- linux.old/net/bridge/netfilter/ebt_ulog.c 1970-01-01 01:00:00.000000000 +0100
4145 +++ linux.dev/net/bridge/netfilter/ebt_ulog.c 2005-10-10 10:36:46.105870250 +0200
4148 + * netfilter module for userspace bridged Ethernet frames logging daemons
4151 + * Bart De Schuymer <bdschuym@pandora.be>
4155 + * Based on ipt_ULOG.c, which is
4156 + * (C) 2000-2002 by Harald Welte <laforge@netfilter.org>
4158 + * This module accepts two parameters:
4161 + * The parameter specifies how big the buffer for each netlink multicast
4162 + * group is. e.g. If you say nlbufsiz=8192, up to eight kb of packets will
4163 + * get accumulated in the kernel until they are sent to userspace. It is
4164 + * NOT possible to allocate more than 128kB, and it is strongly discouraged,
4165 + * because atomically allocating 128kB inside the network rx softirq is not
4166 + * reliable. Please also keep in mind that this buffer size is allocated for
4167 + * each nlgroup you are using, so the total kernel memory usage increases
4171 + * Specify, after how many hundredths of a second the queue should be
4172 + * flushed even if it is not full yet.
4176 +#include <linux/module.h>
4177 +#include <linux/config.h>
4178 +#include <linux/spinlock.h>
4179 +#include <linux/socket.h>
4180 +#include <linux/skbuff.h>
4181 +#include <linux/kernel.h>
4182 +#include <linux/timer.h>
4183 +#include <linux/netlink.h>
4184 +#include <linux/netdevice.h>
4185 +#include <linux/module.h>
4186 +#include <linux/netfilter_bridge/ebtables.h>
4187 +#include <linux/netfilter_bridge/ebt_ulog.h>
4188 +#include <net/sock.h>
4189 +#include "../br_private.h"
4191 +#define PRINTR(format, args...) do { if (net_ratelimit()) \
4192 + printk(format , ## args); } while (0)
4194 +static unsigned int nlbufsiz = 4096;
4195 +MODULE_PARM(nlbufsiz, "i");
4196 +MODULE_PARM_DESC(nlbufsiz, "netlink buffer size (number of bytes) "
4197 + "(defaults to 4096)");
4199 +static unsigned int flushtimeout = 10;
4200 +MODULE_PARM(flushtimeout, "i");
4201 +MODULE_PARM_DESC(flushtimeout, "buffer flush timeout (hundredths of a second) "
4202 + "(defaults to 10)");
4205 + unsigned int qlen; /* number of nlmsgs' in the skb */
4206 + struct nlmsghdr *lastnlh; /* netlink header of last msg in skb */
4207 + struct sk_buff *skb; /* the pre-allocated skb */
4208 + struct timer_list timer; /* the timer function */
4209 + spinlock_t lock; /* the per-queue lock */
4212 +static ebt_ulog_buff_t ulog_buffers[EBT_ULOG_MAXNLGROUPS];
4213 +static struct sock *ebtlognl;
4215 +/* send one ulog_buff_t to userspace */
4216 +static void ulog_send(unsigned int nlgroup)
4218 + ebt_ulog_buff_t *ub = &ulog_buffers[nlgroup];
4220 + if (timer_pending(&ub->timer))
4221 + del_timer(&ub->timer);
4223 + /* last nlmsg needs NLMSG_DONE */
4225 + ub->lastnlh->nlmsg_type = NLMSG_DONE;
4227 + NETLINK_CB(ub->skb).dst_groups = 1 << nlgroup;
4228 + netlink_broadcast(ebtlognl, ub->skb, 0, 1 << nlgroup, GFP_ATOMIC);
4234 +/* timer function to flush queue in flushtimeout time */
4235 +static void ulog_timer(unsigned long data)
4237 + spin_lock_bh(&ulog_buffers[data].lock);
4238 + if (ulog_buffers[data].skb)
4240 + spin_unlock_bh(&ulog_buffers[data].lock);
4243 +static struct sk_buff *ulog_alloc_skb(unsigned int size)
4245 + struct sk_buff *skb;
4247 + skb = alloc_skb(nlbufsiz, GFP_ATOMIC);
4249 + PRINTR(KERN_ERR "ebt_ulog: can't alloc whole buffer "
4250 + "of size %ub!\n", nlbufsiz);
4251 + if (size < nlbufsiz) {
4252 + /* try to allocate only as much as we need for
4253 + * current packet */
4254 + skb = alloc_skb(size, GFP_ATOMIC);
4256 + PRINTR(KERN_ERR "ebt_ulog: can't even allocate "
4257 + "buffer of size %ub\n", size);
4264 +static void ebt_ulog(const struct sk_buff *skb, unsigned int hooknr,
4265 + const struct net_device *in, const struct net_device *out,
4266 + const void *data, unsigned int datalen)
4268 + ebt_ulog_packet_msg_t *pm;
4269 + size_t size, copy_len;
4270 + struct nlmsghdr *nlh;
4271 + struct ebt_ulog_info *loginfo = (struct ebt_ulog_info *)data;
4272 + unsigned int group = loginfo->nlgroup;
4273 + ebt_ulog_buff_t *ub = &ulog_buffers[group];
4274 + spinlock_t *lock = &ub->lock;
4276 + if ((loginfo->cprange == 0) ||
4277 + (loginfo->cprange > skb->len + ETH_HLEN))
4278 + copy_len = skb->len + ETH_HLEN;
4280 + copy_len = loginfo->cprange;
4282 + size = NLMSG_SPACE(sizeof(*pm) + copy_len);
4284 + spin_lock_bh(lock);
4287 + if (!(ub->skb = ulog_alloc_skb(size)))
4288 + goto alloc_failure;
4289 + } else if (size > skb_tailroom(ub->skb)) {
4292 + if (!(ub->skb = ulog_alloc_skb(size)))
4293 + goto alloc_failure;
4296 + nlh = NLMSG_PUT(ub->skb, 0, ub->qlen, 0,
4297 + size - NLMSG_ALIGN(sizeof(*nlh)));
4300 + pm = NLMSG_DATA(nlh);
4302 + /* Fill in the ulog data */
4303 + do_gettimeofday(&pm->stamp);
4304 + if (ub->qlen == 1)
4305 + ub->skb->stamp = pm->stamp;
4306 + pm->data_len = copy_len;
4307 + pm->mark = skb->nfmark;
4308 + pm->hook = hooknr;
4309 + if (loginfo->prefix != NULL)
4310 + strcpy(pm->prefix, loginfo->prefix);
4312 + *(pm->prefix) = '\0';
4315 + strcpy(pm->physindev, in->name);
4316 + strcpy(pm->indev, in->br_port->br->dev.name);
4318 + pm->indev[0] = pm->physindev[0] = '\0';
4321 + strcpy(pm->physoutdev, out->name);
4322 + strcpy(pm->outdev, out->br_port->br->dev.name);
4324 + pm->outdev[0] = pm->physoutdev[0] = '\0';
4326 + if (skb_copy_bits(skb, -ETH_HLEN, pm->data, copy_len) < 0)
4330 + ub->lastnlh->nlmsg_flags |= NLM_F_MULTI;
4332 + ub->lastnlh = nlh;
4334 + if (ub->qlen >= loginfo->qthreshold)
4336 + else if (!timer_pending(&ub->timer)) {
4337 + ub->timer.expires = jiffies + flushtimeout * HZ / 100;
4338 + add_timer(&ub->timer);
4342 + spin_unlock_bh(lock);
4347 + PRINTR(KERN_ERR "ebt_ULOG: error during NLMSG_PUT.\n");
4353 +static int ebt_ulog_check(const char *tablename, unsigned int hookmask,
4354 + const struct ebt_entry *e, void *data, unsigned int datalen)
4356 + struct ebt_ulog_info *loginfo = (struct ebt_ulog_info *)data;
4358 + if (datalen != EBT_ALIGN(sizeof(struct ebt_ulog_info)) ||
4359 + loginfo->nlgroup > 31)
4362 + loginfo->prefix[EBT_ULOG_PREFIX_LEN - 1] = '\0';
4364 + if (loginfo->qthreshold > EBT_ULOG_MAX_QLEN)
4365 + loginfo->qthreshold = EBT_ULOG_MAX_QLEN;
4370 +static struct ebt_watcher ulog = {
4371 + {NULL, NULL}, EBT_ULOG_WATCHER, ebt_ulog, ebt_ulog_check, NULL,
4375 +static int __init init(void)
4379 + if (nlbufsiz >= 128*1024) {
4380 + printk(KERN_NOTICE "ebt_ulog: Netlink buffer has to be <= 128kB,"
4381 + " please try a smaller nlbufsiz parameter.\n");
4385 + /* initialize ulog_buffers */
4386 + for (i = 0; i < EBT_ULOG_MAXNLGROUPS; i++) {
4387 + init_timer(&ulog_buffers[i].timer);
4388 + ulog_buffers[i].timer.function = ulog_timer;
4389 + ulog_buffers[i].timer.data = i;
4390 + ulog_buffers[i].lock = SPIN_LOCK_UNLOCKED;
4393 + ebtlognl = netlink_kernel_create(NETLINK_NFLOG, NULL);
4396 + else if ((ret = ebt_register_watcher(&ulog)))
4397 + sock_release(ebtlognl->socket);
4402 +static void __exit fini(void)
4404 + ebt_ulog_buff_t *ub;
4407 + ebt_unregister_watcher(&ulog);
4408 + for (i = 0; i < EBT_ULOG_MAXNLGROUPS; i++) {
4409 + ub = &ulog_buffers[i];
4410 + if (timer_pending(&ub->timer))
4411 + del_timer(&ub->timer);
4412 + spin_lock_bh(&ub->lock);
4414 + kfree_skb(ub->skb);
4417 + spin_unlock_bh(&ub->lock);
4419 + sock_release(ebtlognl->socket);
4424 +MODULE_LICENSE("GPL");
4425 +MODULE_AUTHOR("Bart De Schuymer <bdschuym@pandora.be>");
4426 +MODULE_DESCRIPTION("ebtables userspace logging module for bridged Ethernet"
4428 diff -Nur linux.old/net/bridge/netfilter/ebt_vlan.c linux.dev/net/bridge/netfilter/ebt_vlan.c
4429 --- linux.old/net/bridge/netfilter/ebt_vlan.c 1970-01-01 01:00:00.000000000 +0100
4430 +++ linux.dev/net/bridge/netfilter/ebt_vlan.c 2005-10-10 10:36:46.093869500 +0200
4433 + * Description: EBTables 802.1Q match extension kernelspace module.
4434 + * Authors: Nick Fedchik <nick@fedchik.org.ua>
4435 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
4437 + * This program is free software; you can redistribute it and/or modify
4438 + * it under the terms of the GNU General Public License as published by
4439 + * the Free Software Foundation; either version 2 of the License, or
4440 + * (at your option) any later version.
4442 + * This program is distributed in the hope that it will be useful,
4443 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4444 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4445 + * GNU General Public License for more details.
4447 + * You should have received a copy of the GNU General Public License
4448 + * along with this program; if not, write to the Free Software
4449 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
4452 +#include <linux/if_ether.h>
4453 +#include <linux/if_vlan.h>
4454 +#include <linux/module.h>
4455 +#include <linux/netfilter_bridge/ebtables.h>
4456 +#include <linux/netfilter_bridge/ebt_vlan.h>
4458 +static unsigned char debug;
4459 +#define MODULE_VERSION "0.6"
4461 +MODULE_PARM(debug, "0-1b");
4462 +MODULE_PARM_DESC(debug, "debug=1 is turn on debug messages");
4463 +MODULE_AUTHOR("Nick Fedchik <nick@fedchik.org.ua>");
4464 +MODULE_DESCRIPTION("802.1Q match module (ebtables extension), v"
4466 +MODULE_LICENSE("GPL");
4469 +#define DEBUG_MSG(args...) if (debug) printk (KERN_DEBUG "ebt_vlan: " args)
4470 +#define INV_FLAG(_inv_flag_) (info->invflags & _inv_flag_) ? "!" : ""
4471 +#define GET_BITMASK(_BIT_MASK_) info->bitmask & _BIT_MASK_
4472 +#define SET_BITMASK(_BIT_MASK_) info->bitmask |= _BIT_MASK_
4473 +#define EXIT_ON_MISMATCH(_MATCH_,_MASK_) if (!((info->_MATCH_ == _MATCH_)^!!(info->invflags & _MASK_))) return 1;
4476 + * Function description: ebt_filter_vlan() is main engine for
4477 + * checking passed 802.1Q frame according to
4478 + * the passed extension parameters (in the *data buffer)
4479 + * ebt_filter_vlan() is called after successfull check the rule params
4480 + * by ebt_check_vlan() function.
4482 + * const struct sk_buff *skb - pointer to passed ethernet frame buffer
4483 + * const void *data - pointer to passed extension parameters
4484 + * unsigned int datalen - length of passed *data buffer
4485 + * const struct net_device *in -
4486 + * const struct net_device *out -
4487 + * const struct ebt_counter *c -
4488 + * Returned values:
4489 + * 0 - ok (all rule params matched)
4490 + * 1 - miss (rule params not acceptable to the parsed frame)
4493 +ebt_filter_vlan(const struct sk_buff *skb,
4494 + const struct net_device *in,
4495 + const struct net_device *out,
4496 + const void *data, unsigned int datalen)
4498 + struct ebt_vlan_info *info = (struct ebt_vlan_info *) data; /* userspace data */
4499 + struct vlan_ethhdr *frame = (struct vlan_ethhdr *) skb->mac.raw; /* Passed tagged frame */
4501 + unsigned short TCI; /* Whole TCI, given from parsed frame */
4502 + unsigned short id; /* VLAN ID, given from frame TCI */
4503 + unsigned char prio; /* user_priority, given from frame TCI */
4504 + unsigned short encap; /* VLAN encapsulated Type/Length field, given from orig frame */
4507 + * Tag Control Information (TCI) consists of the following elements:
4508 + * - User_priority. The user_priority field is three bits in length,
4509 + * interpreted as a binary number.
4510 + * - Canonical Format Indicator (CFI). The Canonical Format Indicator
4511 + * (CFI) is a single bit flag value. Currently ignored.
4512 + * - VLAN Identifier (VID). The VID is encoded as
4513 + * an unsigned binary number.
4515 + TCI = ntohs(frame->h_vlan_TCI);
4516 + id = TCI & VLAN_VID_MASK;
4517 + prio = (TCI >> 13) & 0x7;
4518 + encap = frame->h_vlan_encapsulated_proto;
4521 + * Checking VLAN Identifier (VID)
4523 + if (GET_BITMASK(EBT_VLAN_ID)) { /* Is VLAN ID parsed? */
4524 + EXIT_ON_MISMATCH(id, EBT_VLAN_ID);
4527 + * Checking user_priority
4529 + if (GET_BITMASK(EBT_VLAN_PRIO)) { /* Is VLAN user_priority parsed? */
4530 + EXIT_ON_MISMATCH(prio, EBT_VLAN_PRIO);
4533 + * Checking Encapsulated Proto (Length/Type) field
4535 + if (GET_BITMASK(EBT_VLAN_ENCAP)) { /* Is VLAN Encap parsed? */
4536 + EXIT_ON_MISMATCH(encap, EBT_VLAN_ENCAP);
4539 + * All possible extension parameters was parsed.
4540 + * If rule never returned by missmatch, then all ok.
4546 + * Function description: ebt_vlan_check() is called when userspace
4547 + * delivers the table entry to the kernel,
4548 + * and to check that userspace doesn't give a bad table.
4550 + * const char *tablename - table name string
4551 + * unsigned int hooknr - hook number
4552 + * const struct ebt_entry *e - ebtables entry basic set
4553 + * const void *data - pointer to passed extension parameters
4554 + * unsigned int datalen - length of passed *data buffer
4555 + * Returned values:
4556 + * 0 - ok (all delivered rule params are correct)
4557 + * 1 - miss (rule params is out of range, invalid, incompatible, etc.)
4560 +ebt_check_vlan(const char *tablename,
4561 + unsigned int hooknr,
4562 + const struct ebt_entry *e, void *data, unsigned int datalen)
4564 + struct ebt_vlan_info *info = (struct ebt_vlan_info *) data;
4567 + * Parameters buffer overflow check
4569 + if (datalen != EBT_ALIGN(sizeof(struct ebt_vlan_info))) {
4571 + ("passed size %d is not eq to ebt_vlan_info (%d)\n",
4572 + datalen, sizeof(struct ebt_vlan_info));
4577 + * Is it 802.1Q frame checked?
4579 + if (e->ethproto != __constant_htons(ETH_P_8021Q)) {
4581 + ("passed entry proto %2.4X is not 802.1Q (8100)\n",
4582 + (unsigned short) ntohs(e->ethproto));
4587 + * Check for bitmask range
4588 + * True if even one bit is out of mask
4590 + if (info->bitmask & ~EBT_VLAN_MASK) {
4591 + DEBUG_MSG("bitmask %2X is out of mask (%2X)\n",
4592 + info->bitmask, EBT_VLAN_MASK);
4597 + * Check for inversion flags range
4599 + if (info->invflags & ~EBT_VLAN_MASK) {
4600 + DEBUG_MSG("inversion flags %2X is out of mask (%2X)\n",
4601 + info->invflags, EBT_VLAN_MASK);
4606 + * Reserved VLAN ID (VID) values
4607 + * -----------------------------
4608 + * 0 - The null VLAN ID.
4609 + * 1 - The default Port VID (PVID)
4610 + * 0x0FFF - Reserved for implementation use.
4611 + * if_vlan.h: VLAN_GROUP_ARRAY_LEN 4096.
4613 + if (GET_BITMASK(EBT_VLAN_ID)) { /* when vlan-id param was spec-ed */
4614 + if (!!info->id) { /* if id!=0 => check vid range */
4615 + if (info->id > VLAN_GROUP_ARRAY_LEN) {
4617 + ("id %d is out of range (1-4096)\n",
4622 + * Note: This is valid VLAN-tagged frame point.
4623 + * Any value of user_priority are acceptable,
4624 + * but should be ignored according to 802.1Q Std.
4625 + * So we just drop the prio flag.
4627 + info->bitmask &= ~EBT_VLAN_PRIO;
4630 + * Else, id=0 (null VLAN ID) => user_priority range (any?)
4634 + if (GET_BITMASK(EBT_VLAN_PRIO)) {
4635 + if ((unsigned char) info->prio > 7) {
4637 + ("prio %d is out of range (0-7)\n",
4643 + * Check for encapsulated proto range - it is possible to be
4644 + * any value for u_short range.
4645 + * if_ether.h: ETH_ZLEN 60 - Min. octets in frame sans FCS
4647 + if (GET_BITMASK(EBT_VLAN_ENCAP)) {
4648 + if ((unsigned short) ntohs(info->encap) < ETH_ZLEN) {
4650 + ("encap frame length %d is less than minimal\n",
4651 + ntohs(info->encap));
4659 +static struct ebt_match filter_vlan = {
4669 + * Module initialization function.
4671 +static int __init init(void)
4673 + DEBUG_MSG("ebtables 802.1Q extension module v"
4674 + MODULE_VERSION "\n");
4675 + DEBUG_MSG("module debug=%d\n", !!debug);
4676 + return ebt_register_match(&filter_vlan);
4680 + * Module "finalization" function
4682 +static void __exit fini(void)
4684 + ebt_unregister_match(&filter_vlan);
4691 diff -Nur linux.old/net/bridge/netfilter/ebtable_broute.c linux.dev/net/bridge/netfilter/ebtable_broute.c
4692 --- linux.old/net/bridge/netfilter/ebtable_broute.c 1970-01-01 01:00:00.000000000 +0100
4693 +++ linux.dev/net/bridge/netfilter/ebtable_broute.c 2005-10-10 10:36:46.089869250 +0200
4699 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
4703 + * This table lets you choose between routing and bridging for frames
4704 + * entering on a bridge enslaved nic. This table is traversed before any
4705 + * other ebtables table. See net/bridge/br_input.c.
4708 +#include <linux/netfilter_bridge/ebtables.h>
4709 +#include <linux/module.h>
4710 +#include <linux/if_bridge.h>
4711 +#include <linux/brlock.h>
4713 +// EBT_ACCEPT means the frame will be bridged
4714 +// EBT_DROP means the frame will be routed
4715 +static struct ebt_entries initial_chain =
4716 + {0, "BROUTING", 0, EBT_ACCEPT, 0};
4718 +static struct ebt_replace initial_table =
4720 + "broute", 1 << NF_BR_BROUTING, 0, sizeof(struct ebt_entries),
4721 + { [NF_BR_BROUTING]&initial_chain}, 0, NULL, (char *)&initial_chain
4724 +static int check(const struct ebt_table_info *info, unsigned int valid_hooks)
4726 + if (valid_hooks & ~(1 << NF_BR_BROUTING))
4731 +static struct ebt_table broute_table =
4733 + {NULL, NULL}, "broute", &initial_table, 1 << NF_BR_BROUTING,
4734 + RW_LOCK_UNLOCKED, check, NULL
4737 +static int ebt_broute(struct sk_buff **pskb)
4741 + ret = ebt_do_table(NF_BR_BROUTING, pskb, (*pskb)->dev, NULL,
4743 + if (ret == NF_DROP)
4744 + return 1; // route it
4745 + return 0; // bridge it
4748 +static int __init init(void)
4752 + ret = ebt_register_table(&broute_table);
4755 + br_write_lock_bh(BR_NETPROTO_LOCK);
4757 + br_should_route_hook = ebt_broute;
4758 + br_write_unlock_bh(BR_NETPROTO_LOCK);
4762 +static void __exit fini(void)
4764 + br_write_lock_bh(BR_NETPROTO_LOCK);
4765 + br_should_route_hook = NULL;
4766 + br_write_unlock_bh(BR_NETPROTO_LOCK);
4767 + ebt_unregister_table(&broute_table);
4773 +MODULE_LICENSE("GPL");
4774 diff -Nur linux.old/net/bridge/netfilter/ebtable_filter.c linux.dev/net/bridge/netfilter/ebtable_filter.c
4775 --- linux.old/net/bridge/netfilter/ebtable_filter.c 1970-01-01 01:00:00.000000000 +0100
4776 +++ linux.dev/net/bridge/netfilter/ebtable_filter.c 2005-10-10 10:36:46.089869250 +0200
4782 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
4788 +#include <linux/netfilter_bridge/ebtables.h>
4789 +#include <linux/module.h>
4791 +#define FILTER_VALID_HOOKS ((1 << NF_BR_LOCAL_IN) | (1 << NF_BR_FORWARD) | \
4792 + (1 << NF_BR_LOCAL_OUT))
4794 +static struct ebt_entries initial_chains[] =
4796 + {0, "INPUT", 0, EBT_ACCEPT, 0},
4797 + {0, "FORWARD", 0, EBT_ACCEPT, 0},
4798 + {0, "OUTPUT", 0, EBT_ACCEPT, 0}
4801 +static struct ebt_replace initial_table =
4803 + "filter", FILTER_VALID_HOOKS, 0, 3 * sizeof(struct ebt_entries),
4804 + { [NF_BR_LOCAL_IN]&initial_chains[0], [NF_BR_FORWARD]&initial_chains[1],
4805 + [NF_BR_LOCAL_OUT]&initial_chains[2] }, 0, NULL, (char *)initial_chains
4808 +static int check(const struct ebt_table_info *info, unsigned int valid_hooks)
4810 + if (valid_hooks & ~FILTER_VALID_HOOKS)
4815 +static struct ebt_table frame_filter =
4817 + {NULL, NULL}, "filter", &initial_table, FILTER_VALID_HOOKS,
4818 + RW_LOCK_UNLOCKED, check, NULL
4821 +static unsigned int
4822 +ebt_hook (unsigned int hook, struct sk_buff **pskb, const struct net_device *in,
4823 + const struct net_device *out, int (*okfn)(struct sk_buff *))
4825 + return ebt_do_table(hook, pskb, in, out, &frame_filter);
4828 +static struct nf_hook_ops ebt_ops_filter[] = {
4829 + { { NULL, NULL }, ebt_hook, PF_BRIDGE, NF_BR_LOCAL_IN,
4830 + NF_BR_PRI_FILTER_BRIDGED},
4831 + { { NULL, NULL }, ebt_hook, PF_BRIDGE, NF_BR_FORWARD,
4832 + NF_BR_PRI_FILTER_BRIDGED},
4833 + { { NULL, NULL }, ebt_hook, PF_BRIDGE, NF_BR_LOCAL_OUT,
4834 + NF_BR_PRI_FILTER_OTHER}
4837 +static int __init init(void)
4841 + ret = ebt_register_table(&frame_filter);
4844 + for (i = 0; i < sizeof(ebt_ops_filter) / sizeof(ebt_ops_filter[0]); i++)
4845 + if ((ret = nf_register_hook(&ebt_ops_filter[i])) < 0)
4849 + for (j = 0; j < i; j++)
4850 + nf_unregister_hook(&ebt_ops_filter[j]);
4851 + ebt_unregister_table(&frame_filter);
4855 +static void __exit fini(void)
4859 + for (i = 0; i < sizeof(ebt_ops_filter) / sizeof(ebt_ops_filter[0]); i++)
4860 + nf_unregister_hook(&ebt_ops_filter[i]);
4861 + ebt_unregister_table(&frame_filter);
4867 +MODULE_LICENSE("GPL");
4868 diff -Nur linux.old/net/bridge/netfilter/ebtable_nat.c linux.dev/net/bridge/netfilter/ebtable_nat.c
4869 --- linux.old/net/bridge/netfilter/ebtable_nat.c 1970-01-01 01:00:00.000000000 +0100
4870 +++ linux.dev/net/bridge/netfilter/ebtable_nat.c 2005-10-10 10:36:46.089869250 +0200
4876 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
4882 +#include <linux/netfilter_bridge/ebtables.h>
4883 +#include <linux/module.h>
4884 +#define NAT_VALID_HOOKS ((1 << NF_BR_PRE_ROUTING) | (1 << NF_BR_LOCAL_OUT) | \
4885 + (1 << NF_BR_POST_ROUTING))
4887 +static struct ebt_entries initial_chains[] =
4889 + {0, "PREROUTING", 0, EBT_ACCEPT, 0},
4890 + {0, "OUTPUT", 0, EBT_ACCEPT, 0},
4891 + {0, "POSTROUTING", 0, EBT_ACCEPT, 0}
4894 +static struct ebt_replace initial_table =
4896 + "nat", NAT_VALID_HOOKS, 0, 3 * sizeof(struct ebt_entries),
4897 + { [NF_BR_PRE_ROUTING]&initial_chains[0], [NF_BR_LOCAL_OUT]&initial_chains[1],
4898 + [NF_BR_POST_ROUTING]&initial_chains[2] }, 0, NULL, (char *)initial_chains
4901 +static int check(const struct ebt_table_info *info, unsigned int valid_hooks)
4903 + if (valid_hooks & ~NAT_VALID_HOOKS)
4908 +static struct ebt_table frame_nat =
4910 + {NULL, NULL}, "nat", &initial_table, NAT_VALID_HOOKS,
4911 + RW_LOCK_UNLOCKED, check, NULL
4914 +static unsigned int
4915 +ebt_nat_dst(unsigned int hook, struct sk_buff **pskb, const struct net_device *in
4916 + , const struct net_device *out, int (*okfn)(struct sk_buff *))
4918 + return ebt_do_table(hook, pskb, in, out, &frame_nat);
4921 +static unsigned int
4922 +ebt_nat_src(unsigned int hook, struct sk_buff **pskb, const struct net_device *in
4923 + , const struct net_device *out, int (*okfn)(struct sk_buff *))
4925 + return ebt_do_table(hook, pskb, in, out, &frame_nat);
4928 +static struct nf_hook_ops ebt_ops_nat[] = {
4929 + { { NULL, NULL }, ebt_nat_dst, PF_BRIDGE, NF_BR_LOCAL_OUT,
4930 + NF_BR_PRI_NAT_DST_OTHER},
4931 + { { NULL, NULL }, ebt_nat_src, PF_BRIDGE, NF_BR_POST_ROUTING,
4932 + NF_BR_PRI_NAT_SRC},
4933 + { { NULL, NULL }, ebt_nat_dst, PF_BRIDGE, NF_BR_PRE_ROUTING,
4934 + NF_BR_PRI_NAT_DST_BRIDGED},
4937 +static int __init init(void)
4941 + ret = ebt_register_table(&frame_nat);
4944 + for (i = 0; i < sizeof(ebt_ops_nat) / sizeof(ebt_ops_nat[0]); i++)
4945 + if ((ret = nf_register_hook(&ebt_ops_nat[i])) < 0)
4949 + for (j = 0; j < i; j++)
4950 + nf_unregister_hook(&ebt_ops_nat[j]);
4951 + ebt_unregister_table(&frame_nat);
4955 +static void __exit fini(void)
4959 + for (i = 0; i < sizeof(ebt_ops_nat) / sizeof(ebt_ops_nat[0]); i++)
4960 + nf_unregister_hook(&ebt_ops_nat[i]);
4961 + ebt_unregister_table(&frame_nat);
4967 +MODULE_LICENSE("GPL");
4968 diff -Nur linux.old/net/bridge/netfilter/ebtables.c linux.dev/net/bridge/netfilter/ebtables.c
4969 --- linux.old/net/bridge/netfilter/ebtables.c 1970-01-01 01:00:00.000000000 +0100
4970 +++ linux.dev/net/bridge/netfilter/ebtables.c 2005-10-10 10:40:05.146309500 +0200
4976 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
4978 + * ebtables.c,v 2.0, July, 2002
4980 + * This code is stongly inspired on the iptables code which is
4981 + * Copyright (C) 1999 Paul `Rusty' Russell & Michael J. Neuling
4983 + * This program is free software; you can redistribute it and/or
4984 + * modify it under the terms of the GNU General Public License
4985 + * as published by the Free Software Foundation; either version
4986 + * 2 of the License, or (at your option) any later version.
4989 +// used for print_string
4990 +#include <linux/sched.h>
4991 +#include <linux/tty.h>
4993 +#include <linux/kmod.h>
4994 +#include <linux/module.h>
4995 +#include <linux/vmalloc.h>
4996 +#include <linux/netfilter_bridge/ebtables.h>
4997 +#include <linux/spinlock.h>
4998 +#include <asm/uaccess.h>
4999 +#include <linux/smp.h>
5000 +#include <net/sock.h>
5001 +// needed for logical [in,out]-dev filtering
5002 +#include "../br_private.h"
5005 +#define ASSERT_READ_LOCK(x)
5006 +#define ASSERT_WRITE_LOCK(x)
5007 +#include <linux/netfilter_ipv4/listhelp.h>
5009 +#if 0 // use this for remote debugging
5010 +// Copyright (C) 1998 by Ori Pomerantz
5011 +// Print the string to the appropriate tty, the one
5012 +// the current task uses
5013 +static void print_string(char *str)
5015 + struct tty_struct *my_tty;
5017 + /* The tty for the current task */
5018 + my_tty = current->tty;
5019 + if (my_tty != NULL) {
5020 + (*(my_tty->driver).write)(my_tty, 0, str, strlen(str));
5021 + (*(my_tty->driver).write)(my_tty, 0, "\015\012", 2);
5025 +#define BUGPRINT(args) print_string(args);
5027 +#define BUGPRINT(format, args...) printk("kernel msg: ebtables bug: please "\
5028 + "report to author: "format, ## args)
5029 +// #define BUGPRINT(format, args...)
5031 +#define MEMPRINT(format, args...) printk("kernel msg: ebtables "\
5032 + ": out of memory: "format, ## args)
5033 +// #define MEMPRINT(format, args...)
5037 +// Each cpu has its own set of counters, so there is no need for write_lock in
5039 +// For reading or updating the counters, the user context needs to
5040 +// get a write_lock
5042 +// The size of each set of counters is altered to get cache alignment
5043 +#define SMP_ALIGN(x) (((x) + SMP_CACHE_BYTES-1) & ~(SMP_CACHE_BYTES-1))
5044 +#define COUNTER_OFFSET(n) (SMP_ALIGN(n * sizeof(struct ebt_counter)))
5045 +#define COUNTER_BASE(c, n, cpu) ((struct ebt_counter *)(((char *)c) + \
5046 + COUNTER_OFFSET(n) * cpu))
5050 +static DECLARE_MUTEX(ebt_mutex);
5051 +static LIST_HEAD(ebt_tables);
5052 +static LIST_HEAD(ebt_targets);
5053 +static LIST_HEAD(ebt_matches);
5054 +static LIST_HEAD(ebt_watchers);
5056 +static struct ebt_target ebt_standard_target =
5057 +{ {NULL, NULL}, EBT_STANDARD_TARGET, NULL, NULL, NULL, NULL};
5059 +static inline int ebt_do_watcher (struct ebt_entry_watcher *w,
5060 + const struct sk_buff *skb, unsigned int hooknr, const struct net_device *in,
5061 + const struct net_device *out)
5063 + w->u.watcher->watcher(skb, hooknr, in, out, w->data,
5065 + // watchers don't give a verdict
5069 +static inline int ebt_do_match (struct ebt_entry_match *m,
5070 + const struct sk_buff *skb, const struct net_device *in,
5071 + const struct net_device *out)
5073 + return m->u.match->match(skb, in, out, m->data,
5077 +static inline int ebt_dev_check(char *entry, const struct net_device *device)
5080 + char *devname = device->name;
5082 + if (*entry == '\0')
5086 + /* 1 is the wildcard token */
5087 + while (entry[i] != '\0' && entry[i] != 1 && entry[i] == devname[i])
5089 + return (devname[i] != entry[i] && entry[i] != 1);
5092 +#define FWINV2(bool,invflg) ((bool) ^ !!(e->invflags & invflg))
5093 +// process standard matches
5094 +static inline int ebt_basic_match(struct ebt_entry *e, struct ethhdr *h,
5095 + const struct net_device *in, const struct net_device *out)
5099 + if (e->bitmask & EBT_802_3) {
5100 + if (FWINV2(ntohs(h->h_proto) >= 1536, EBT_IPROTO))
5102 + } else if (!(e->bitmask & EBT_NOPROTO) &&
5103 + FWINV2(e->ethproto != h->h_proto, EBT_IPROTO))
5106 + if (FWINV2(ebt_dev_check(e->in, in), EBT_IIN))
5108 + if (FWINV2(ebt_dev_check(e->out, out), EBT_IOUT))
5110 + if ((!in || !in->br_port) ? 0 : FWINV2(ebt_dev_check(
5111 + e->logical_in, &in->br_port->br->dev), EBT_ILOGICALIN))
5113 + if ((!out || !out->br_port) ? 0 : FWINV2(ebt_dev_check(
5114 + e->logical_out, &out->br_port->br->dev), EBT_ILOGICALOUT))
5117 + if (e->bitmask & EBT_SOURCEMAC) {
5119 + for (i = 0; i < 6; i++)
5120 + verdict |= (h->h_source[i] ^ e->sourcemac[i]) &
5122 + if (FWINV2(verdict != 0, EBT_ISOURCE) )
5125 + if (e->bitmask & EBT_DESTMAC) {
5127 + for (i = 0; i < 6; i++)
5128 + verdict |= (h->h_dest[i] ^ e->destmac[i]) &
5130 + if (FWINV2(verdict != 0, EBT_IDEST) )
5136 +// Do some firewalling
5137 +unsigned int ebt_do_table (unsigned int hook, struct sk_buff **pskb,
5138 + const struct net_device *in, const struct net_device *out,
5139 + struct ebt_table *table)
5142 + struct ebt_entry *point;
5143 + struct ebt_counter *counter_base, *cb_base;
5144 + struct ebt_entry_target *t;
5145 + int verdict, sp = 0;
5146 + struct ebt_chainstack *cs;
5147 + struct ebt_entries *chaininfo;
5149 + struct ebt_table_info *private;
5151 + read_lock_bh(&table->lock);
5152 + private = table->private;
5153 + cb_base = COUNTER_BASE(private->counters, private->nentries,
5154 + cpu_number_map(smp_processor_id()));
5155 + if (private->chainstack)
5156 + cs = private->chainstack[cpu_number_map(smp_processor_id())];
5159 + chaininfo = private->hook_entry[hook];
5160 + nentries = private->hook_entry[hook]->nentries;
5161 + point = (struct ebt_entry *)(private->hook_entry[hook]->data);
5162 + counter_base = cb_base + private->hook_entry[hook]->counter_offset;
5163 + // base for chain jumps
5164 + base = private->entries;
5166 + while (i < nentries) {
5167 + if (ebt_basic_match(point, (**pskb).mac.ethernet, in, out))
5168 + goto letscontinue;
5170 + if (EBT_MATCH_ITERATE(point, ebt_do_match, *pskb, in, out) != 0)
5171 + goto letscontinue;
5173 + // increase counter
5174 + (*(counter_base + i)).pcnt++;
5175 + (*(counter_base + i)).bcnt+=(**pskb).len;
5177 + // these should only watch: not modify, nor tell us
5178 + // what to do with the packet
5179 + EBT_WATCHER_ITERATE(point, ebt_do_watcher, *pskb, hook, in,
5182 + t = (struct ebt_entry_target *)
5183 + (((char *)point) + point->target_offset);
5184 + // standard target
5185 + if (!t->u.target->target)
5186 + verdict = ((struct ebt_standard_target *)t)->verdict;
5188 + verdict = t->u.target->target(pskb, hook,
5189 + in, out, t->data, t->target_size);
5190 + if (verdict == EBT_ACCEPT) {
5191 + read_unlock_bh(&table->lock);
5194 + if (verdict == EBT_DROP) {
5195 + read_unlock_bh(&table->lock);
5198 + if (verdict == EBT_RETURN) {
5200 +#ifdef CONFIG_NETFILTER_DEBUG
5202 + BUGPRINT("RETURN on base chain");
5203 + // act like this is EBT_CONTINUE
5204 + goto letscontinue;
5208 + // put all the local variables right
5210 + chaininfo = cs[sp].chaininfo;
5211 + nentries = chaininfo->nentries;
5213 + counter_base = cb_base +
5214 + chaininfo->counter_offset;
5217 + if (verdict == EBT_CONTINUE)
5218 + goto letscontinue;
5219 +#ifdef CONFIG_NETFILTER_DEBUG
5220 + if (verdict < 0) {
5221 + BUGPRINT("bogus standard verdict\n");
5222 + read_unlock_bh(&table->lock);
5228 + cs[sp].chaininfo = chaininfo;
5229 + cs[sp].e = (struct ebt_entry *)
5230 + (((char *)point) + point->next_offset);
5232 + chaininfo = (struct ebt_entries *) (base + verdict);
5233 +#ifdef CONFIG_NETFILTER_DEBUG
5234 + if (chaininfo->distinguisher) {
5235 + BUGPRINT("jump to non-chain\n");
5236 + read_unlock_bh(&table->lock);
5240 + nentries = chaininfo->nentries;
5241 + point = (struct ebt_entry *)chaininfo->data;
5242 + counter_base = cb_base + chaininfo->counter_offset;
5246 + point = (struct ebt_entry *)
5247 + (((char *)point) + point->next_offset);
5251 + // I actually like this :)
5252 + if (chaininfo->policy == EBT_RETURN)
5254 + if (chaininfo->policy == EBT_ACCEPT) {
5255 + read_unlock_bh(&table->lock);
5258 + read_unlock_bh(&table->lock);
5262 +// If it succeeds, returns element and locks mutex
5263 +static inline void *
5264 +find_inlist_lock_noload(struct list_head *head, const char *name, int *error,
5265 + struct semaphore *mutex)
5269 + *error = down_interruptible(mutex);
5273 + ret = list_named_find(head, name);
5281 +#ifndef CONFIG_KMOD
5282 +#define find_inlist_lock(h,n,p,e,m) find_inlist_lock_noload((h),(n),(e),(m))
5285 +find_inlist_lock(struct list_head *head, const char *name, const char *prefix,
5286 + int *error, struct semaphore *mutex)
5290 + ret = find_inlist_lock_noload(head, name, error, mutex);
5292 + char modulename[EBT_FUNCTION_MAXNAMELEN + strlen(prefix) + 1];
5293 + strcpy(modulename, prefix);
5294 + strcat(modulename, name);
5295 + request_module(modulename);
5296 + ret = find_inlist_lock_noload(head, name, error, mutex);
5302 +static inline struct ebt_table *
5303 +find_table_lock(const char *name, int *error, struct semaphore *mutex)
5305 + return find_inlist_lock(&ebt_tables, name, "ebtable_", error, mutex);
5308 +static inline struct ebt_match *
5309 +find_match_lock(const char *name, int *error, struct semaphore *mutex)
5311 + return find_inlist_lock(&ebt_matches, name, "ebt_", error, mutex);
5314 +static inline struct ebt_watcher *
5315 +find_watcher_lock(const char *name, int *error, struct semaphore *mutex)
5317 + return find_inlist_lock(&ebt_watchers, name, "ebt_", error, mutex);
5320 +static inline struct ebt_target *
5321 +find_target_lock(const char *name, int *error, struct semaphore *mutex)
5323 + return find_inlist_lock(&ebt_targets, name, "ebt_", error, mutex);
5327 +ebt_check_match(struct ebt_entry_match *m, struct ebt_entry *e,
5328 + const char *name, unsigned int hookmask, unsigned int *cnt)
5330 + struct ebt_match *match;
5333 + if (((char *)m) + m->match_size + sizeof(struct ebt_entry_match) >
5334 + ((char *)e) + e->watchers_offset)
5336 + match = find_match_lock(m->u.name, &ret, &ebt_mutex);
5339 + m->u.match = match;
5341 + __MOD_INC_USE_COUNT(match->me);
5343 + if (match->check &&
5344 + match->check(name, hookmask, e, m->data, m->match_size) != 0) {
5345 + BUGPRINT("match->check failed\n");
5347 + __MOD_DEC_USE_COUNT(match->me);
5355 +ebt_check_watcher(struct ebt_entry_watcher *w, struct ebt_entry *e,
5356 + const char *name, unsigned int hookmask, unsigned int *cnt)
5358 + struct ebt_watcher *watcher;
5361 + if (((char *)w) + w->watcher_size + sizeof(struct ebt_entry_watcher) >
5362 + ((char *)e) + e->target_offset)
5364 + watcher = find_watcher_lock(w->u.name, &ret, &ebt_mutex);
5367 + w->u.watcher = watcher;
5369 + __MOD_INC_USE_COUNT(watcher->me);
5371 + if (watcher->check &&
5372 + watcher->check(name, hookmask, e, w->data, w->watcher_size) != 0) {
5373 + BUGPRINT("watcher->check failed\n");
5375 + __MOD_DEC_USE_COUNT(watcher->me);
5382 +// this one is very careful, as it is the first function
5383 +// to parse the userspace data
5385 +ebt_check_entry_size_and_hooks(struct ebt_entry *e,
5386 + struct ebt_table_info *newinfo, char *base, char *limit,
5387 + struct ebt_entries **hook_entries, unsigned int *n, unsigned int *cnt,
5388 + unsigned int *totalcnt, unsigned int *udc_cnt, unsigned int valid_hooks)
5392 + for (i = 0; i < NF_BR_NUMHOOKS; i++) {
5393 + if ((valid_hooks & (1 << i)) == 0)
5395 + if ( (char *)hook_entries[i] - base ==
5396 + (char *)e - newinfo->entries)
5399 + // beginning of a new chain
5400 + // if i == NF_BR_NUMHOOKS it must be a user defined chain
5401 + if (i != NF_BR_NUMHOOKS || !(e->bitmask & EBT_ENTRY_OR_ENTRIES)) {
5402 + if ((e->bitmask & EBT_ENTRY_OR_ENTRIES) != 0) {
5403 + // we make userspace set this right,
5404 + // so there is no misunderstanding
5405 + BUGPRINT("EBT_ENTRY_OR_ENTRIES shouldn't be set "
5406 + "in distinguisher\n");
5409 + // this checks if the previous chain has as many entries
5410 + // as it said it has
5412 + BUGPRINT("nentries does not equal the nr of entries "
5413 + "in the chain\n");
5416 + // before we look at the struct, be sure it is not too big
5417 + if ((char *)hook_entries[i] + sizeof(struct ebt_entries)
5419 + BUGPRINT("entries_size too small\n");
5422 + if (((struct ebt_entries *)e)->policy != EBT_DROP &&
5423 + ((struct ebt_entries *)e)->policy != EBT_ACCEPT) {
5424 + // only RETURN from udc
5425 + if (i != NF_BR_NUMHOOKS ||
5426 + ((struct ebt_entries *)e)->policy != EBT_RETURN) {
5427 + BUGPRINT("bad policy\n");
5431 + if (i == NF_BR_NUMHOOKS) // it's a user defined chain
5434 + newinfo->hook_entry[i] = (struct ebt_entries *)e;
5435 + if (((struct ebt_entries *)e)->counter_offset != *totalcnt) {
5436 + BUGPRINT("counter_offset != totalcnt");
5439 + *n = ((struct ebt_entries *)e)->nentries;
5443 + // a plain old entry, heh
5444 + if (sizeof(struct ebt_entry) > e->watchers_offset ||
5445 + e->watchers_offset > e->target_offset ||
5446 + e->target_offset >= e->next_offset) {
5447 + BUGPRINT("entry offsets not in right order\n");
5450 + // this is not checked anywhere else
5451 + if (e->next_offset - e->target_offset < sizeof(struct ebt_entry_target)) {
5452 + BUGPRINT("target size too small\n");
5461 +struct ebt_cl_stack
5463 + struct ebt_chainstack cs;
5465 + unsigned int hookmask;
5468 +// we need these positions to check that the jumps to a different part of the
5469 +// entries is a jump to the beginning of a new chain.
5471 +ebt_get_udc_positions(struct ebt_entry *e, struct ebt_table_info *newinfo,
5472 + struct ebt_entries **hook_entries, unsigned int *n, unsigned int valid_hooks,
5473 + struct ebt_cl_stack *udc)
5477 + // we're only interested in chain starts
5478 + if (e->bitmask & EBT_ENTRY_OR_ENTRIES)
5480 + for (i = 0; i < NF_BR_NUMHOOKS; i++) {
5481 + if ((valid_hooks & (1 << i)) == 0)
5483 + if (newinfo->hook_entry[i] == (struct ebt_entries *)e)
5486 + // only care about udc
5487 + if (i != NF_BR_NUMHOOKS)
5490 + udc[*n].cs.chaininfo = (struct ebt_entries *)e;
5491 + // these initialisations are depended on later in check_chainloops()
5493 + udc[*n].hookmask = 0;
5500 +ebt_cleanup_match(struct ebt_entry_match *m, unsigned int *i)
5502 + if (i && (*i)-- == 0)
5504 + if (m->u.match->destroy)
5505 + m->u.match->destroy(m->data, m->match_size);
5506 + if (m->u.match->me)
5507 + __MOD_DEC_USE_COUNT(m->u.match->me);
5513 +ebt_cleanup_watcher(struct ebt_entry_watcher *w, unsigned int *i)
5515 + if (i && (*i)-- == 0)
5517 + if (w->u.watcher->destroy)
5518 + w->u.watcher->destroy(w->data, w->watcher_size);
5519 + if (w->u.watcher->me)
5520 + __MOD_DEC_USE_COUNT(w->u.watcher->me);
5526 +ebt_cleanup_entry(struct ebt_entry *e, unsigned int *cnt)
5528 + struct ebt_entry_target *t;
5530 + if ((e->bitmask & EBT_ENTRY_OR_ENTRIES) == 0)
5533 + if (cnt && (*cnt)-- == 0)
5535 + EBT_WATCHER_ITERATE(e, ebt_cleanup_watcher, NULL);
5536 + EBT_MATCH_ITERATE(e, ebt_cleanup_match, NULL);
5537 + t = (struct ebt_entry_target *)(((char *)e) + e->target_offset);
5538 + if (t->u.target->destroy)
5539 + t->u.target->destroy(t->data, t->target_size);
5540 + if (t->u.target->me)
5541 + __MOD_DEC_USE_COUNT(t->u.target->me);
5547 +ebt_check_entry(struct ebt_entry *e, struct ebt_table_info *newinfo,
5548 + const char *name, unsigned int *cnt, unsigned int valid_hooks,
5549 + struct ebt_cl_stack *cl_s, unsigned int udc_cnt)
5551 + struct ebt_entry_target *t;
5552 + struct ebt_target *target;
5553 + unsigned int i, j, hook = 0, hookmask = 0;
5556 + // Don't mess with the struct ebt_entries
5557 + if ((e->bitmask & EBT_ENTRY_OR_ENTRIES) == 0)
5560 + if (e->bitmask & ~EBT_F_MASK) {
5561 + BUGPRINT("Unknown flag for bitmask\n");
5564 + if (e->invflags & ~EBT_INV_MASK) {
5565 + BUGPRINT("Unknown flag for inv bitmask\n");
5568 + if ( (e->bitmask & EBT_NOPROTO) && (e->bitmask & EBT_802_3) ) {
5569 + BUGPRINT("NOPROTO & 802_3 not allowed\n");
5572 + // what hook do we belong to?
5573 + for (i = 0; i < NF_BR_NUMHOOKS; i++) {
5574 + if ((valid_hooks & (1 << i)) == 0)
5576 + if ((char *)newinfo->hook_entry[i] < (char *)e)
5581 + // (1 << NF_BR_NUMHOOKS) tells the check functions the rule is on
5583 + if (i < NF_BR_NUMHOOKS)
5584 + hookmask = (1 << hook) | (1 << NF_BR_NUMHOOKS);
5586 + for (i = 0; i < udc_cnt; i++)
5587 + if ((char *)(cl_s[i].cs.chaininfo) > (char *)e)
5590 + hookmask = (1 << hook) | (1 << NF_BR_NUMHOOKS);
5592 + hookmask = cl_s[i - 1].hookmask;
5595 + ret = EBT_MATCH_ITERATE(e, ebt_check_match, e, name, hookmask, &i);
5597 + goto cleanup_matches;
5599 + ret = EBT_WATCHER_ITERATE(e, ebt_check_watcher, e, name, hookmask, &j);
5601 + goto cleanup_watchers;
5602 + t = (struct ebt_entry_target *)(((char *)e) + e->target_offset);
5603 + target = find_target_lock(t->u.name, &ret, &ebt_mutex);
5605 + goto cleanup_watchers;
5607 + __MOD_INC_USE_COUNT(target->me);
5610 + t->u.target = target;
5611 + if (t->u.target == &ebt_standard_target) {
5612 + if (e->target_offset + sizeof(struct ebt_standard_target) >
5614 + BUGPRINT("Standard target size too big\n");
5616 + goto cleanup_watchers;
5618 + if (((struct ebt_standard_target *)t)->verdict <
5619 + -NUM_STANDARD_TARGETS) {
5620 + BUGPRINT("Invalid standard target\n");
5622 + goto cleanup_watchers;
5624 + } else if ((e->target_offset + t->target_size +
5625 + sizeof(struct ebt_entry_target) > e->next_offset) ||
5626 + (t->u.target->check &&
5627 + t->u.target->check(name, hookmask, e, t->data, t->target_size) != 0)){
5628 + if (t->u.target->me)
5629 + __MOD_DEC_USE_COUNT(t->u.target->me);
5631 + goto cleanup_watchers;
5636 + EBT_WATCHER_ITERATE(e, ebt_cleanup_watcher, &j);
5638 + EBT_MATCH_ITERATE(e, ebt_cleanup_match, &i);
5642 +// checks for loops and sets the hook mask for udc
5643 +// the hook mask for udc tells us from which base chains the udc can be
5644 +// accessed. This mask is a parameter to the check() functions of the extensions
5645 +static int check_chainloops(struct ebt_entries *chain,
5646 + struct ebt_cl_stack *cl_s, unsigned int udc_cnt,
5647 + unsigned int hooknr, char *base)
5649 + int i, chain_nr = -1, pos = 0, nentries = chain->nentries, verdict;
5650 + struct ebt_entry *e = (struct ebt_entry *)chain->data;
5651 + struct ebt_entry_target *t;
5653 + while (pos < nentries || chain_nr != -1) {
5654 + // end of udc, go back one 'recursion' step
5655 + if (pos == nentries) {
5656 + // put back values of the time when this chain was called
5657 + e = cl_s[chain_nr].cs.e;
5658 + if (cl_s[chain_nr].from != -1)
5660 + cl_s[cl_s[chain_nr].from].cs.chaininfo->nentries;
5662 + nentries = chain->nentries;
5663 + pos = cl_s[chain_nr].cs.n;
5664 + // make sure we won't see a loop that isn't one
5665 + cl_s[chain_nr].cs.n = 0;
5666 + chain_nr = cl_s[chain_nr].from;
5667 + if (pos == nentries)
5670 + t = (struct ebt_entry_target *)
5671 + (((char *)e) + e->target_offset);
5672 + if (strcmp(t->u.name, EBT_STANDARD_TARGET))
5673 + goto letscontinue;
5674 + if (e->target_offset + sizeof(struct ebt_standard_target) >
5676 + BUGPRINT("Standard target size too big\n");
5679 + verdict = ((struct ebt_standard_target *)t)->verdict;
5680 + if (verdict >= 0) { // jump to another chain
5681 + struct ebt_entries *hlp2 =
5682 + (struct ebt_entries *)(base + verdict);
5683 + for (i = 0; i < udc_cnt; i++)
5684 + if (hlp2 == cl_s[i].cs.chaininfo)
5686 + // bad destination or loop
5687 + if (i == udc_cnt) {
5688 + BUGPRINT("bad destination\n");
5691 + if (cl_s[i].cs.n) {
5692 + BUGPRINT("loop\n");
5695 + // this can't be 0, so the above test is correct
5696 + cl_s[i].cs.n = pos + 1;
5698 + cl_s[i].cs.e = ((void *)e + e->next_offset);
5699 + e = (struct ebt_entry *)(hlp2->data);
5700 + nentries = hlp2->nentries;
5701 + cl_s[i].from = chain_nr;
5703 + // this udc is accessible from the base chain for hooknr
5704 + cl_s[i].hookmask |= (1 << hooknr);
5708 + e = (void *)e + e->next_offset;
5714 +// do the parsing of the table/chains/entries/matches/watchers/targets, heh
5715 +static int translate_table(struct ebt_replace *repl,
5716 + struct ebt_table_info *newinfo)
5718 + unsigned int i, j, k, udc_cnt;
5720 + struct ebt_cl_stack *cl_s = NULL; // used in the checking for chain loops
5723 + while (i < NF_BR_NUMHOOKS && !(repl->valid_hooks & (1 << i)))
5725 + if (i == NF_BR_NUMHOOKS) {
5726 + BUGPRINT("No valid hooks specified\n");
5729 + if (repl->hook_entry[i] != (struct ebt_entries *)repl->entries) {
5730 + BUGPRINT("Chains don't start at beginning\n");
5733 + // make sure chains are ordered after each other in same order
5734 + // as their corresponding hooks
5735 + for (j = i + 1; j < NF_BR_NUMHOOKS; j++) {
5736 + if (!(repl->valid_hooks & (1 << j)))
5738 + if ( repl->hook_entry[j] <= repl->hook_entry[i] ) {
5739 + BUGPRINT("Hook order must be followed\n");
5745 + for (i = 0; i < NF_BR_NUMHOOKS; i++)
5746 + newinfo->hook_entry[i] = NULL;
5748 + newinfo->entries_size = repl->entries_size;
5749 + newinfo->nentries = repl->nentries;
5751 + // do some early checkings and initialize some things
5752 + i = 0; // holds the expected nr. of entries for the chain
5753 + j = 0; // holds the up to now counted entries for the chain
5754 + k = 0; // holds the total nr. of entries, should equal
5755 + // newinfo->nentries afterwards
5756 + udc_cnt = 0; // will hold the nr. of user defined chains (udc)
5757 + ret = EBT_ENTRY_ITERATE(newinfo->entries, newinfo->entries_size,
5758 + ebt_check_entry_size_and_hooks, newinfo, repl->entries,
5759 + repl->entries + repl->entries_size, repl->hook_entry, &i, &j, &k,
5760 + &udc_cnt, repl->valid_hooks);
5766 + BUGPRINT("nentries does not equal the nr of entries in the "
5767 + "(last) chain\n");
5770 + if (k != newinfo->nentries) {
5771 + BUGPRINT("Total nentries is wrong\n");
5775 + // check if all valid hooks have a chain
5776 + for (i = 0; i < NF_BR_NUMHOOKS; i++) {
5777 + if (newinfo->hook_entry[i] == NULL &&
5778 + (repl->valid_hooks & (1 << i))) {
5779 + BUGPRINT("Valid hook without chain\n");
5784 + // Get the location of the udc, put them in an array
5785 + // While we're at it, allocate the chainstack
5787 + // this will get free'd in do_replace()/ebt_register_table()
5788 + // if an error occurs
5789 + newinfo->chainstack = (struct ebt_chainstack **)
5790 + vmalloc(smp_num_cpus * sizeof(struct ebt_chainstack));
5791 + if (!newinfo->chainstack)
5793 + for (i = 0; i < smp_num_cpus; i++) {
5794 + newinfo->chainstack[i] =
5795 + vmalloc(udc_cnt * sizeof(struct ebt_chainstack));
5796 + if (!newinfo->chainstack[i]) {
5798 + vfree(newinfo->chainstack[--i]);
5799 + vfree(newinfo->chainstack);
5800 + newinfo->chainstack = NULL;
5805 + cl_s = (struct ebt_cl_stack *)
5806 + vmalloc(udc_cnt * sizeof(struct ebt_cl_stack));
5809 + i = 0; // the i'th udc
5810 + EBT_ENTRY_ITERATE(newinfo->entries, newinfo->entries_size,
5811 + ebt_get_udc_positions, newinfo, repl->hook_entry, &i,
5812 + repl->valid_hooks, cl_s);
5814 + if (i != udc_cnt) {
5815 + BUGPRINT("i != udc_cnt\n");
5821 + // Check for loops
5822 + for (i = 0; i < NF_BR_NUMHOOKS; i++)
5823 + if (repl->valid_hooks & (1 << i))
5824 + if (check_chainloops(newinfo->hook_entry[i],
5825 + cl_s, udc_cnt, i, newinfo->entries)) {
5831 + // we now know the following (along with E=mc):
5832 + // - the nr of entries in each chain is right
5833 + // - the size of the allocated space is right
5834 + // - all valid hooks have a corresponding chain
5835 + // - there are no loops
5836 + // - wrong data can still be on the level of a single entry
5837 + // - could be there are jumps to places that are not the
5838 + // beginning of a chain. This can only occur in chains that
5839 + // are not accessible from any base chains, so we don't care.
5841 + // used to know what we need to clean up if something goes wrong
5843 + ret = EBT_ENTRY_ITERATE(newinfo->entries, newinfo->entries_size,
5844 + ebt_check_entry, newinfo, repl->name, &i, repl->valid_hooks,
5847 + EBT_ENTRY_ITERATE(newinfo->entries, newinfo->entries_size,
5848 + ebt_cleanup_entry, &i);
5855 +// called under write_lock
5856 +static void get_counters(struct ebt_counter *oldcounters,
5857 + struct ebt_counter *counters, unsigned int nentries)
5860 + struct ebt_counter *counter_base;
5862 + // counters of cpu 0
5863 + memcpy(counters, oldcounters,
5864 + sizeof(struct ebt_counter) * nentries);
5865 + // add other counters to those of cpu 0
5866 + for (cpu = 1; cpu < smp_num_cpus; cpu++) {
5867 + counter_base = COUNTER_BASE(oldcounters, nentries, cpu);
5868 + for (i = 0; i < nentries; i++) {
5869 + counters[i].pcnt += counter_base[i].pcnt;
5870 + counters[i].bcnt += counter_base[i].bcnt;
5875 +// replace the table
5876 +static int do_replace(void *user, unsigned int len)
5878 + int ret, i, countersize;
5879 + struct ebt_table_info *newinfo;
5880 + struct ebt_replace tmp;
5881 + struct ebt_table *t;
5882 + struct ebt_counter *counterstmp = NULL;
5883 + // used to be able to unlock earlier
5884 + struct ebt_table_info *table;
5886 + if (copy_from_user(&tmp, user, sizeof(tmp)) != 0)
5889 + if (len != sizeof(tmp) + tmp.entries_size) {
5890 + BUGPRINT("Wrong len argument\n");
5894 + if (tmp.entries_size == 0) {
5895 + BUGPRINT("Entries_size never zero\n");
5898 + countersize = COUNTER_OFFSET(tmp.nentries) * smp_num_cpus;
5899 + newinfo = (struct ebt_table_info *)
5900 + vmalloc(sizeof(struct ebt_table_info) + countersize);
5905 + memset(newinfo->counters, 0, countersize);
5907 + newinfo->entries = (char *)vmalloc(tmp.entries_size);
5908 + if (!newinfo->entries) {
5910 + goto free_newinfo;
5912 + if (copy_from_user(
5913 + newinfo->entries, tmp.entries, tmp.entries_size) != 0) {
5914 + BUGPRINT("Couldn't copy entries from userspace\n");
5916 + goto free_entries;
5919 + // the user wants counters back
5920 + // the check on the size is done later, when we have the lock
5921 + if (tmp.num_counters) {
5922 + counterstmp = (struct ebt_counter *)
5923 + vmalloc(tmp.num_counters * sizeof(struct ebt_counter));
5924 + if (!counterstmp) {
5926 + goto free_entries;
5930 + counterstmp = NULL;
5932 + // this can get initialized by translate_table()
5933 + newinfo->chainstack = NULL;
5934 + ret = translate_table(&tmp, newinfo);
5937 + goto free_counterstmp;
5939 + t = find_table_lock(tmp.name, &ret, &ebt_mutex);
5941 + goto free_iterate;
5943 + // the table doesn't like it
5944 + if (t->check && (ret = t->check(newinfo, tmp.valid_hooks)))
5947 + if (tmp.num_counters && tmp.num_counters != t->private->nentries) {
5948 + BUGPRINT("Wrong nr. of counters requested\n");
5953 + // we have the mutex lock, so no danger in reading this pointer
5954 + table = t->private;
5955 + // we need an atomic snapshot of the counters
5956 + write_lock_bh(&t->lock);
5957 + if (tmp.num_counters)
5958 + get_counters(t->private->counters, counterstmp,
5959 + t->private->nentries);
5961 + t->private = newinfo;
5962 + write_unlock_bh(&t->lock);
5964 + // So, a user can change the chains while having messed up her counter
5965 + // allocation. Only reason why this is done is because this way the lock
5966 + // is held only once, while this doesn't bring the kernel into a
5967 + // dangerous state.
5968 + if (tmp.num_counters &&
5969 + copy_to_user(tmp.counters, counterstmp,
5970 + tmp.num_counters * sizeof(struct ebt_counter))) {
5971 + BUGPRINT("Couldn't copy counters to userspace\n");
5977 + // decrease module count and free resources
5978 + EBT_ENTRY_ITERATE(table->entries, table->entries_size,
5979 + ebt_cleanup_entry, NULL);
5981 + vfree(table->entries);
5982 + if (table->chainstack) {
5983 + for (i = 0; i < smp_num_cpus; i++)
5984 + vfree(table->chainstack[i]);
5985 + vfree(table->chainstack);
5990 + vfree(counterstmp);
5996 + EBT_ENTRY_ITERATE(newinfo->entries, newinfo->entries_size,
5997 + ebt_cleanup_entry, NULL);
6000 + vfree(counterstmp);
6001 + // can be initialized in translate_table()
6002 + if (newinfo->chainstack) {
6003 + for (i = 0; i < smp_num_cpus; i++)
6004 + vfree(newinfo->chainstack[i]);
6005 + vfree(newinfo->chainstack);
6008 + if (newinfo->entries)
6009 + vfree(newinfo->entries);
6016 +int ebt_register_target(struct ebt_target *target)
6020 + ret = down_interruptible(&ebt_mutex);
6023 + if (!list_named_insert(&ebt_targets, target)) {
6028 + MOD_INC_USE_COUNT;
6033 +void ebt_unregister_target(struct ebt_target *target)
6036 + LIST_DELETE(&ebt_targets, target);
6038 + MOD_DEC_USE_COUNT;
6041 +int ebt_register_match(struct ebt_match *match)
6045 + ret = down_interruptible(&ebt_mutex);
6048 + if (!list_named_insert(&ebt_matches, match)) {
6053 + MOD_INC_USE_COUNT;
6058 +void ebt_unregister_match(struct ebt_match *match)
6061 + LIST_DELETE(&ebt_matches, match);
6063 + MOD_DEC_USE_COUNT;
6066 +int ebt_register_watcher(struct ebt_watcher *watcher)
6070 + ret = down_interruptible(&ebt_mutex);
6073 + if (!list_named_insert(&ebt_watchers, watcher)) {
6078 + MOD_INC_USE_COUNT;
6083 +void ebt_unregister_watcher(struct ebt_watcher *watcher)
6086 + LIST_DELETE(&ebt_watchers, watcher);
6088 + MOD_DEC_USE_COUNT;
6091 +int ebt_register_table(struct ebt_table *table)
6093 + struct ebt_table_info *newinfo;
6094 + int ret, i, countersize;
6096 + if (!table || !table->table ||!table->table->entries ||
6097 + table->table->entries_size == 0 ||
6098 + table->table->counters || table->private) {
6099 + BUGPRINT("Bad table data for ebt_register_table!!!\n");
6103 + countersize = COUNTER_OFFSET(table->table->nentries) * smp_num_cpus;
6104 + newinfo = (struct ebt_table_info *)
6105 + vmalloc(sizeof(struct ebt_table_info) + countersize);
6110 + newinfo->entries = (char *)vmalloc(table->table->entries_size);
6111 + if (!(newinfo->entries))
6112 + goto free_newinfo;
6114 + memcpy(newinfo->entries, table->table->entries,
6115 + table->table->entries_size);
6118 + memset(newinfo->counters, 0, countersize);
6120 + // fill in newinfo and parse the entries
6121 + newinfo->chainstack = NULL;
6122 + ret = translate_table(table->table, newinfo);
6124 + BUGPRINT("Translate_table failed\n");
6125 + goto free_chainstack;
6128 + if (table->check && table->check(newinfo, table->valid_hooks)) {
6129 + BUGPRINT("The table doesn't like its own initial data, lol\n");
6133 + table->private = newinfo;
6134 + table->lock = RW_LOCK_UNLOCKED;
6135 + ret = down_interruptible(&ebt_mutex);
6137 + goto free_chainstack;
6139 + if (list_named_find(&ebt_tables, table->name)) {
6141 + BUGPRINT("Table name already exists\n");
6145 + list_prepend(&ebt_tables, table);
6147 + MOD_INC_USE_COUNT;
6152 + if (newinfo->chainstack) {
6153 + for (i = 0; i < smp_num_cpus; i++)
6154 + vfree(newinfo->chainstack[i]);
6155 + vfree(newinfo->chainstack);
6157 + vfree(newinfo->entries);
6163 +void ebt_unregister_table(struct ebt_table *table)
6168 + BUGPRINT("Request to unregister NULL table!!!\n");
6172 + LIST_DELETE(&ebt_tables, table);
6174 + EBT_ENTRY_ITERATE(table->private->entries,
6175 + table->private->entries_size, ebt_cleanup_entry, NULL);
6176 + if (table->private->entries)
6177 + vfree(table->private->entries);
6178 + if (table->private->chainstack) {
6179 + for (i = 0; i < smp_num_cpus; i++)
6180 + vfree(table->private->chainstack[i]);
6181 + vfree(table->private->chainstack);
6183 + vfree(table->private);
6184 + MOD_DEC_USE_COUNT;
6187 +// userspace just supplied us with counters
6188 +static int update_counters(void *user, unsigned int len)
6191 + struct ebt_counter *tmp;
6192 + struct ebt_replace hlp;
6193 + struct ebt_table *t;
6195 + if (copy_from_user(&hlp, user, sizeof(hlp)))
6198 + if (len != sizeof(hlp) + hlp.num_counters * sizeof(struct ebt_counter))
6200 + if (hlp.num_counters == 0)
6203 + if ( !(tmp = (struct ebt_counter *)
6204 + vmalloc(hlp.num_counters * sizeof(struct ebt_counter))) ){
6205 + MEMPRINT("Update_counters && nomemory\n");
6209 + t = find_table_lock(hlp.name, &ret, &ebt_mutex);
6213 + if (hlp.num_counters != t->private->nentries) {
6214 + BUGPRINT("Wrong nr of counters\n");
6216 + goto unlock_mutex;
6219 + if ( copy_from_user(tmp, hlp.counters,
6220 + hlp.num_counters * sizeof(struct ebt_counter)) ) {
6221 + BUGPRINT("Updata_counters && !cfu\n");
6223 + goto unlock_mutex;
6226 + // we want an atomic add of the counters
6227 + write_lock_bh(&t->lock);
6229 + // we add to the counters of the first cpu
6230 + for (i = 0; i < hlp.num_counters; i++) {
6231 + t->private->counters[i].pcnt += tmp[i].pcnt;
6232 + t->private->counters[i].bcnt += tmp[i].bcnt;
6235 + write_unlock_bh(&t->lock);
6244 +static inline int ebt_make_matchname(struct ebt_entry_match *m,
6245 + char *base, char *ubase)
6247 + char *hlp = ubase - base + (char *)m;
6248 + if (copy_to_user(hlp, m->u.match->name, EBT_FUNCTION_MAXNAMELEN))
6253 +static inline int ebt_make_watchername(struct ebt_entry_watcher *w,
6254 + char *base, char *ubase)
6256 + char *hlp = ubase - base + (char *)w;
6257 + if (copy_to_user(hlp , w->u.watcher->name, EBT_FUNCTION_MAXNAMELEN))
6262 +static inline int ebt_make_names(struct ebt_entry *e, char *base, char *ubase)
6266 + struct ebt_entry_target *t;
6268 + if ((e->bitmask & EBT_ENTRY_OR_ENTRIES) == 0)
6271 + hlp = ubase - base + (char *)e + e->target_offset;
6272 + t = (struct ebt_entry_target *)(((char *)e) + e->target_offset);
6274 + ret = EBT_MATCH_ITERATE(e, ebt_make_matchname, base, ubase);
6277 + ret = EBT_WATCHER_ITERATE(e, ebt_make_watchername, base, ubase);
6280 + if (copy_to_user(hlp, t->u.target->name, EBT_FUNCTION_MAXNAMELEN))
6285 +// called with ebt_mutex down
6286 +static int copy_everything_to_user(struct ebt_table *t, void *user,
6287 + int *len, int cmd)
6289 + struct ebt_replace tmp;
6290 + struct ebt_counter *counterstmp, *oldcounters;
6291 + unsigned int entries_size, nentries;
6294 + if (cmd == EBT_SO_GET_ENTRIES) {
6295 + entries_size = t->private->entries_size;
6296 + nentries = t->private->nentries;
6297 + entries = t->private->entries;
6298 + oldcounters = t->private->counters;
6300 + entries_size = t->table->entries_size;
6301 + nentries = t->table->nentries;
6302 + entries = t->table->entries;
6303 + oldcounters = t->table->counters;
6306 + if (copy_from_user(&tmp, user, sizeof(tmp))) {
6307 + BUGPRINT("Cfu didn't work\n");
6311 + if (*len != sizeof(struct ebt_replace) + entries_size +
6312 + (tmp.num_counters? nentries * sizeof(struct ebt_counter): 0)) {
6313 + BUGPRINT("Wrong size\n");
6317 + if (tmp.nentries != nentries) {
6318 + BUGPRINT("Nentries wrong\n");
6322 + if (tmp.entries_size != entries_size) {
6323 + BUGPRINT("Wrong size\n");
6327 + // userspace might not need the counters
6328 + if (tmp.num_counters) {
6329 + if (tmp.num_counters != nentries) {
6330 + BUGPRINT("Num_counters wrong\n");
6333 + counterstmp = (struct ebt_counter *)
6334 + vmalloc(nentries * sizeof(struct ebt_counter));
6335 + if (!counterstmp) {
6336 + MEMPRINT("Couldn't copy counters, out of memory\n");
6339 + write_lock_bh(&t->lock);
6340 + get_counters(oldcounters, counterstmp, nentries);
6341 + write_unlock_bh(&t->lock);
6343 + if (copy_to_user(tmp.counters, counterstmp,
6344 + nentries * sizeof(struct ebt_counter))) {
6345 + BUGPRINT("Couldn't copy counters to userspace\n");
6346 + vfree(counterstmp);
6349 + vfree(counterstmp);
6352 + if (copy_to_user(tmp.entries, entries, entries_size)) {
6353 + BUGPRINT("Couldn't copy entries to userspace\n");
6356 + // set the match/watcher/target names right
6357 + return EBT_ENTRY_ITERATE(entries, entries_size,
6358 + ebt_make_names, entries, tmp.entries);
6361 +static int do_ebt_set_ctl(struct sock *sk,
6362 + int cmd, void *user, unsigned int len)
6367 + case EBT_SO_SET_ENTRIES:
6368 + ret = do_replace(user, len);
6370 + case EBT_SO_SET_COUNTERS:
6371 + ret = update_counters(user, len);
6379 +static int do_ebt_get_ctl(struct sock *sk, int cmd, void *user, int *len)
6382 + struct ebt_replace tmp;
6383 + struct ebt_table *t;
6385 + if (copy_from_user(&tmp, user, sizeof(tmp)))
6388 + t = find_table_lock(tmp.name, &ret, &ebt_mutex);
6393 + case EBT_SO_GET_INFO:
6394 + case EBT_SO_GET_INIT_INFO:
6395 + if (*len != sizeof(struct ebt_replace)){
6400 + if (cmd == EBT_SO_GET_INFO) {
6401 + tmp.nentries = t->private->nentries;
6402 + tmp.entries_size = t->private->entries_size;
6403 + tmp.valid_hooks = t->valid_hooks;
6405 + tmp.nentries = t->table->nentries;
6406 + tmp.entries_size = t->table->entries_size;
6407 + tmp.valid_hooks = t->table->valid_hooks;
6410 + if (copy_to_user(user, &tmp, *len) != 0){
6411 + BUGPRINT("c2u Didn't work\n");
6418 + case EBT_SO_GET_ENTRIES:
6419 + case EBT_SO_GET_INIT_ENTRIES:
6420 + ret = copy_everything_to_user(t, user, len, cmd);
6432 +static struct nf_sockopt_ops ebt_sockopts =
6433 +{ { NULL, NULL }, PF_INET, EBT_BASE_CTL, EBT_SO_SET_MAX + 1, do_ebt_set_ctl,
6434 + EBT_BASE_CTL, EBT_SO_GET_MAX + 1, do_ebt_get_ctl, 0, NULL
6437 +static int __init init(void)
6441 + if (br_netfilter_init())
6445 + list_named_insert(&ebt_targets, &ebt_standard_target);
6447 + if ((ret = nf_register_sockopt(&ebt_sockopts)) < 0)
6450 + printk(KERN_NOTICE "Ebtables v2.0 registered\n");
6454 +static void __exit fini(void)
6456 + nf_unregister_sockopt(&ebt_sockopts);
6457 + printk(KERN_NOTICE "Ebtables v2.0 unregistered\n");
6459 + br_netfilter_fini();
6462 +EXPORT_SYMBOL(ebt_register_table);
6463 +EXPORT_SYMBOL(ebt_unregister_table);
6464 +EXPORT_SYMBOL(ebt_register_match);
6465 +EXPORT_SYMBOL(ebt_unregister_match);
6466 +EXPORT_SYMBOL(ebt_register_watcher);
6467 +EXPORT_SYMBOL(ebt_unregister_watcher);
6468 +EXPORT_SYMBOL(ebt_register_target);
6469 +EXPORT_SYMBOL(ebt_unregister_target);
6470 +EXPORT_SYMBOL(ebt_do_table);
6473 +MODULE_LICENSE("GPL");
6474 diff -Nur linux.old/net/core/dev.c linux.dev/net/core/dev.c
6475 --- linux.old/net/core/dev.c 2005-10-10 10:33:06.872169000 +0200
6476 +++ linux.dev/net/core/dev.c 2005-10-10 10:36:45.969861750 +0200
6477 @@ -1439,7 +1439,7 @@
6480 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6481 -void (*br_handle_frame_hook)(struct sk_buff *skb) = NULL;
6482 +int (*br_handle_frame_hook)(struct sk_buff *skb) = NULL;
6485 static __inline__ int handle_bridge(struct sk_buff *skb,
6486 @@ -1456,7 +1456,6 @@
6490 - br_handle_frame_hook(skb);
6494 @@ -1516,7 +1515,12 @@
6495 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6496 if (skb->dev->br_port != NULL && br_handle_frame_hook != NULL &&
6497 skb->pkt_type != PACKET_LOOPBACK) {
6498 - return handle_bridge(skb, pt_prev);
6501 + ret = handle_bridge(skb, pt_prev);
6502 + if (br_handle_frame_hook(skb) == 0)
6508 diff -Nur linux.old/net/core/netfilter.c linux.dev/net/core/netfilter.c
6509 --- linux.old/net/core/netfilter.c 2005-01-19 15:10:13.000000000 +0100
6510 +++ linux.dev/net/core/netfilter.c 2005-10-10 10:36:46.197876000 +0200
6511 @@ -342,32 +342,29 @@
6512 const struct net_device *indev,
6513 const struct net_device *outdev,
6514 struct list_head **i,
6515 - int (*okfn)(struct sk_buff *))
6516 + int (*okfn)(struct sk_buff *),
6519 + unsigned int verdict;
6521 for (*i = (*i)->next; *i != head; *i = (*i)->next) {
6522 struct nf_hook_ops *elem = (struct nf_hook_ops *)*i;
6523 - switch (elem->hook(hook, skb, indev, outdev, okfn)) {
6536 + if (hook_thresh > elem->priority)
6539 + verdict = elem->hook(hook, skb, indev, outdev, okfn);
6540 + if (verdict != NF_ACCEPT) {
6541 #ifdef CONFIG_NETFILTER_DEBUG
6546 - NFDEBUG("Evil return from %p(%u).\n",
6547 - elem->hook, hook);
6548 + if (unlikely(verdict > NF_MAX_VERDICT)) {
6549 + NFDEBUG("Evil return from %p(%u).\n",
6550 + elem->hook, hook);
6554 + if (verdict != NF_REPEAT)
6560 @@ -413,6 +410,10 @@
6563 struct nf_info *info;
6564 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6565 + struct net_device *physindev = NULL;
6566 + struct net_device *physoutdev = NULL;
6569 if (!queue_handler[pf].outfn) {
6571 @@ -435,36 +436,52 @@
6572 if (indev) dev_hold(indev);
6573 if (outdev) dev_hold(outdev);
6575 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6576 + if (skb->nf_bridge) {
6577 + physindev = skb->nf_bridge->physindev;
6578 + if (physindev) dev_hold(physindev);
6579 + physoutdev = skb->nf_bridge->physoutdev;
6580 + if (physoutdev) dev_hold(physoutdev);
6584 status = queue_handler[pf].outfn(skb, info, queue_handler[pf].data);
6586 /* James M doesn't say fuck enough. */
6587 if (indev) dev_put(indev);
6588 if (outdev) dev_put(outdev);
6589 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6590 + if (physindev) dev_put(physindev);
6591 + if (physoutdev) dev_put(physoutdev);
6599 -int nf_hook_slow(int pf, unsigned int hook, struct sk_buff *skb,
6600 +/* Returns 1 if okfn() needs to be executed by the caller,
6601 + * -EPERM for NF_DROP, 0 otherwise. */
6602 +int nf_hook_slow(int pf, unsigned int hook, struct sk_buff **pskb,
6603 struct net_device *indev,
6604 struct net_device *outdev,
6605 - int (*okfn)(struct sk_buff *))
6606 + int (*okfn)(struct sk_buff *),
6609 struct list_head *elem;
6610 unsigned int verdict;
6613 /* This stopgap cannot be removed until all the hooks are audited. */
6614 - if (skb_is_nonlinear(skb) && skb_linearize(skb, GFP_ATOMIC) != 0) {
6616 + if (skb_is_nonlinear(*pskb) && skb_linearize(*pskb, GFP_ATOMIC) != 0) {
6620 - if (skb->ip_summed == CHECKSUM_HW) {
6621 + if ((*pskb)->ip_summed == CHECKSUM_HW) {
6622 if (outdev == NULL) {
6623 - skb->ip_summed = CHECKSUM_NONE;
6624 + (*pskb)->ip_summed = CHECKSUM_NONE;
6626 - skb_checksum_help(skb);
6627 + skb_checksum_help(*pskb);
6631 @@ -472,30 +489,24 @@
6632 br_read_lock_bh(BR_NETPROTO_LOCK);
6634 #ifdef CONFIG_NETFILTER_DEBUG
6635 - if (skb->nf_debug & (1 << hook)) {
6636 + if (unlikely((*pskb)->nf_debug & (1 << hook))) {
6637 printk("nf_hook: hook %i already set.\n", hook);
6638 - nf_dump_skb(pf, skb);
6639 + nf_dump_skb(pf, *pskb);
6641 - skb->nf_debug |= (1 << hook);
6642 + (*pskb)->nf_debug |= (1 << hook);
6645 elem = &nf_hooks[pf][hook];
6646 - verdict = nf_iterate(&nf_hooks[pf][hook], &skb, hook, indev,
6647 - outdev, &elem, okfn);
6648 - if (verdict == NF_QUEUE) {
6649 - NFDEBUG("nf_hook: Verdict = QUEUE.\n");
6650 - nf_queue(skb, elem, pf, hook, indev, outdev, okfn);
6653 - switch (verdict) {
6660 + verdict = nf_iterate(&nf_hooks[pf][hook], pskb, hook, indev,
6661 + outdev, &elem, okfn, hook_thresh);
6662 + if (verdict == NF_ACCEPT || verdict == NF_STOP)
6664 + else if (verdict == NF_DROP) {
6668 + } else if (verdict == NF_QUEUE) {
6669 + NFDEBUG("nf_hook: Verdict = QUEUE.\n");
6670 + nf_queue(*pskb, elem, pf, hook, indev, outdev, okfn);
6673 br_read_unlock_bh(BR_NETPROTO_LOCK);
6674 @@ -510,6 +521,14 @@
6676 /* We don't have BR_NETPROTO_LOCK here */
6677 br_read_lock_bh(BR_NETPROTO_LOCK);
6678 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6679 + if (skb->nf_bridge) {
6680 + if (skb->nf_bridge->physindev)
6681 + dev_put(skb->nf_bridge->physindev);
6682 + if (skb->nf_bridge->physoutdev)
6683 + dev_put(skb->nf_bridge->physoutdev);
6686 for (i = nf_hooks[info->pf][info->hook].next; i != elem; i = i->next) {
6687 if (i == &nf_hooks[info->pf][info->hook]) {
6688 /* The module which sent it to userspace is gone. */
6690 verdict = nf_iterate(&nf_hooks[info->pf][info->hook],
6692 info->indev, info->outdev, &elem,
6694 + info->okfn, INT_MIN);
6698 diff -Nur linux.old/net/core/skbuff.c linux.dev/net/core/skbuff.c
6699 --- linux.old/net/core/skbuff.c 2005-10-10 10:33:00.891795250 +0200
6700 +++ linux.dev/net/core/skbuff.c 2005-10-10 10:36:46.205876500 +0200
6702 #ifdef CONFIG_NETFILTER_DEBUG
6705 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6706 + skb->nf_bridge = NULL;
6709 #ifdef CONFIG_NET_SCHED
6713 #ifdef CONFIG_NETFILTER
6714 nf_conntrack_put(skb->nfct);
6715 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6716 + nf_bridge_put(skb->nf_bridge);
6719 skb_headerinit(skb, NULL, 0); /* clean state */
6722 #ifdef CONFIG_NETFILTER_DEBUG
6725 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6728 #endif /*CONFIG_NETFILTER*/
6729 #if defined(CONFIG_HIPPI)
6733 #ifdef CONFIG_NETFILTER
6734 nf_conntrack_get(skb->nfct);
6735 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6736 + nf_bridge_get(skb->nf_bridge);
6741 @@ -452,6 +464,10 @@
6742 #ifdef CONFIG_NETFILTER_DEBUG
6743 new->nf_debug=old->nf_debug;
6745 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6746 + new->nf_bridge=old->nf_bridge;
6747 + nf_bridge_get(new->nf_bridge);
6750 #ifdef CONFIG_NET_SCHED
6751 new->tc_index = old->tc_index;
6753 /* Set the tail pointer and length */
6754 skb_put(n,skb->len);
6756 - /* Copy the data only. */
6757 - if (skb_copy_bits(skb, 0, n->data, skb->len))
6759 + /* Copy the linear data and header. */
6760 + if (skb_copy_bits(skb, -newheadroom, n->head, newheadroom + skb->len))
6763 copy_skb_header(n, skb);
6765 diff -Nur linux.old/net/ipv4/ip_output.c linux.dev/net/ipv4/ip_output.c
6766 --- linux.old/net/ipv4/ip_output.c 2005-01-19 15:10:13.000000000 +0100
6767 +++ linux.dev/net/ipv4/ip_output.c 2005-10-10 10:36:46.265880250 +0200
6769 #include <linux/netfilter_ipv4.h>
6770 #include <linux/mroute.h>
6771 #include <linux/netlink.h>
6772 +#include <linux/netfilter_bridge.h>
6775 * Shall we try to damage output packets if routing dev changes?
6778 struct rtable *rt = (struct rtable*)skb->dst;
6781 + unsigned int ll_rs = 0;
6783 dev = rt->u.dst.dev;
6786 @@ -785,6 +787,10 @@
6787 hlen = iph->ihl * 4;
6788 left = skb->len - hlen; /* Space per frame */
6789 mtu = rt->u.dst.pmtu - hlen; /* Size of data space */
6790 +#ifdef CONFIG_NETFILTER
6791 + ll_rs = nf_bridge_pad(skb);
6794 ptr = raw + hlen; /* Where to start from */
6801 - if ((skb2 = alloc_skb(len+hlen+dev->hard_header_len+15,GFP_ATOMIC)) == NULL) {
6802 + if ((skb2 = alloc_skb(len+hlen+dev->hard_header_len+15+ll_rs,GFP_ATOMIC)) == NULL) {
6803 NETDEBUG(printk(KERN_INFO "IP: frag: no memory for new fragment!\n"));
6808 skb2->pkt_type = skb->pkt_type;
6809 skb2->priority = skb->priority;
6810 - skb_reserve(skb2, (dev->hard_header_len+15)&~15);
6811 + skb_reserve(skb2, (dev->hard_header_len+15+ll_rs)&~15);
6812 skb_put(skb2, len + hlen);
6813 skb2->nh.raw = skb2->data;
6814 skb2->h.raw = skb2->data + hlen;
6815 @@ -890,6 +896,10 @@
6816 /* Connection association is same as pre-frag packet */
6817 skb2->nfct = skb->nfct;
6818 nf_conntrack_get(skb2->nfct);
6819 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6820 + skb2->nf_bridge = skb->nf_bridge;
6821 + nf_bridge_get(skb2->nf_bridge);
6823 #ifdef CONFIG_NETFILTER_DEBUG
6824 skb2->nf_debug = skb->nf_debug;
6826 diff -Nur linux.old/net/ipv4/netfilter/Config.in linux.dev/net/ipv4/netfilter/Config.in
6827 --- linux.old/net/ipv4/netfilter/Config.in 2005-10-10 10:33:00.891795250 +0200
6828 +++ linux.dev/net/ipv4/netfilter/Config.in 2005-10-10 10:36:46.293882000 +0200
6830 int ' Buffer size for application layer data (256-65536)' CONFIG_IP_NF_MATCH_LAYER7_MAXDATALEN 2048
6833 + if [ "$CONFIG_BRIDGE" != "n" ]; then
6834 + dep_tristate ' Physdev match support' CONFIG_IP_NF_MATCH_PHYSDEV $CONFIG_IP_NF_IPTABLES
6837 dep_tristate ' Packet filtering' CONFIG_IP_NF_FILTER $CONFIG_IP_NF_IPTABLES
6838 if [ "$CONFIG_IP_NF_FILTER" != "n" ]; then
6839 diff -Nur linux.old/net/ipv4/netfilter/Makefile linux.dev/net/ipv4/netfilter/Makefile
6840 --- linux.old/net/ipv4/netfilter/Makefile 2005-10-10 10:33:00.895795500 +0200
6841 +++ linux.dev/net/ipv4/netfilter/Makefile 2005-10-10 10:36:46.289881750 +0200
6844 obj-$(CONFIG_IP_NF_MATCH_LAYER7) += ipt_layer7.o
6846 +obj-$(CONFIG_IP_NF_MATCH_PHYSDEV) += ipt_physdev.o
6849 obj-$(CONFIG_IP_NF_TARGET_REJECT) += ipt_REJECT.o
6850 obj-$(CONFIG_IP_NF_TARGET_MIRROR) += ipt_MIRROR.o
6851 diff -Nur linux.old/net/ipv4/netfilter/ip_tables.c linux.dev/net/ipv4/netfilter/ip_tables.c
6852 --- linux.old/net/ipv4/netfilter/ip_tables.c 2005-04-04 03:42:20.000000000 +0200
6853 +++ linux.dev/net/ipv4/netfilter/ip_tables.c 2005-10-10 10:36:46.233878250 +0200
6854 @@ -120,12 +120,19 @@
6856 ip_packet_match(const struct iphdr *ip,
6858 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6859 + const char *physindev,
6862 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6863 + const char *physoutdev,
6865 const struct ipt_ip *ipinfo,
6870 + unsigned long ret2 = 1;
6872 #define FWINV(bool,invflg) ((bool) ^ !!(ipinfo->invflags & invflg))
6874 @@ -155,7 +162,15 @@
6875 & ((const unsigned long *)ipinfo->iniface_mask)[i];
6878 - if (FWINV(ret != 0, IPT_INV_VIA_IN)) {
6879 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6880 + for (i = 0, ret2 = 0; i < IFNAMSIZ/sizeof(unsigned long); i++) {
6881 + ret2 |= (((const unsigned long *)physindev)[i]
6882 + ^ ((const unsigned long *)ipinfo->iniface)[i])
6883 + & ((const unsigned long *)ipinfo->iniface_mask)[i];
6887 + if (FWINV(ret != 0 && ret2 != 0, IPT_INV_VIA_IN)) {
6888 dprintf("VIA in mismatch (%s vs %s).%s\n",
6889 indev, ipinfo->iniface,
6890 ipinfo->invflags&IPT_INV_VIA_IN ?" (INV)":"");
6891 @@ -168,7 +183,15 @@
6892 & ((const unsigned long *)ipinfo->outiface_mask)[i];
6895 - if (FWINV(ret != 0, IPT_INV_VIA_OUT)) {
6896 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6897 + for (i = 0, ret2 = 0; i < IFNAMSIZ/sizeof(unsigned long); i++) {
6898 + ret2 |= (((const unsigned long *)physoutdev)[i]
6899 + ^ ((const unsigned long *)ipinfo->outiface)[i])
6900 + & ((const unsigned long *)ipinfo->outiface_mask)[i];
6904 + if (FWINV(ret != 0 && ret2 != 0, IPT_INV_VIA_OUT)) {
6905 dprintf("VIA out mismatch (%s vs %s).%s\n",
6906 outdev, ipinfo->outiface,
6907 ipinfo->invflags&IPT_INV_VIA_OUT ?" (INV)":"");
6909 /* Initializing verdict to NF_DROP keeps gcc happy. */
6910 unsigned int verdict = NF_DROP;
6911 const char *indev, *outdev;
6912 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6913 + const char *physindev, *physoutdev;
6916 struct ipt_entry *e, *back;
6918 @@ -276,6 +302,13 @@
6919 datalen = (*pskb)->len - ip->ihl * 4;
6920 indev = in ? in->name : nulldevname;
6921 outdev = out ? out->name : nulldevname;
6922 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6923 + physindev = ((*pskb)->nf_bridge && (*pskb)->nf_bridge->physindev) ?
6924 + (*pskb)->nf_bridge->physindev->name : nulldevname;
6925 + physoutdev = ((*pskb)->nf_bridge && (*pskb)->nf_bridge->physoutdev) ?
6926 + (*pskb)->nf_bridge->physoutdev->name : nulldevname;
6929 /* We handle fragments by dealing with the first fragment as
6930 * if it was a normal packet. All other fragments are treated
6931 * normally, except that they will NEVER match rules that ask
6932 @@ -311,7 +344,15 @@
6935 (*pskb)->nfcache |= e->nfcache;
6936 - if (ip_packet_match(ip, indev, outdev, &e->ip, offset)) {
6937 + if (ip_packet_match(ip, indev,
6938 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6942 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6945 + &e->ip, offset)) {
6946 struct ipt_entry_target *t;
6948 if (IPT_MATCH_ITERATE(e, do_match,
6949 diff -Nur linux.old/net/ipv4/netfilter/ipt_LOG.c linux.dev/net/ipv4/netfilter/ipt_LOG.c
6950 --- linux.old/net/ipv4/netfilter/ipt_LOG.c 2005-04-04 03:42:20.000000000 +0200
6951 +++ linux.dev/net/ipv4/netfilter/ipt_LOG.c 2005-10-10 10:36:46.265880250 +0200
6952 @@ -317,6 +317,18 @@
6955 out ? out->name : "");
6956 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
6957 + if ((*pskb)->nf_bridge) {
6958 + struct net_device *physindev = (*pskb)->nf_bridge->physindev;
6959 + struct net_device *physoutdev = (*pskb)->nf_bridge->physoutdev;
6961 + if (physindev && in != physindev)
6962 + printk("PHYSIN=%s ", physindev->name);
6963 + if (physoutdev && out != physoutdev)
6964 + printk("PHYSOUT=%s ", physoutdev->name);
6969 /* MAC logging for input chain only. */
6971 diff -Nur linux.old/net/ipv4/netfilter/ipt_REJECT.c linux.dev/net/ipv4/netfilter/ipt_REJECT.c
6972 --- linux.old/net/ipv4/netfilter/ipt_REJECT.c 2005-01-19 15:10:13.000000000 +0100
6973 +++ linux.dev/net/ipv4/netfilter/ipt_REJECT.c 2005-10-10 10:36:46.353885750 +0200
6975 #include <net/route.h>
6976 #include <linux/netfilter_ipv4/ip_tables.h>
6977 #include <linux/netfilter_ipv4/ipt_REJECT.h>
6978 +#ifdef CONFIG_BRIDGE_NETFILTER
6979 +#include <linux/netfilter_bridge.h>
6983 #define DEBUGP printk
6985 struct rt_key key = {};
6988 - if (hook != NF_IP_FORWARD) {
6989 + /* We don't require ip forwarding to be enabled to be able to
6990 + * send a RST reply for bridged traffic. */
6991 + if (hook != NF_IP_FORWARD
6992 +#ifdef CONFIG_BRIDGE_NETFILTER
6993 + || (skb->nf_bridge && skb->nf_bridge->mask & BRNF_BRIDGED)
6996 key.dst = iph->saddr;
6997 if (hook == NF_IP_LOCAL_IN)
6998 key.src = iph->daddr;
6999 diff -Nur linux.old/net/ipv4/netfilter/ipt_physdev.c linux.dev/net/ipv4/netfilter/ipt_physdev.c
7000 --- linux.old/net/ipv4/netfilter/ipt_physdev.c 1970-01-01 01:00:00.000000000 +0100
7001 +++ linux.dev/net/ipv4/netfilter/ipt_physdev.c 2005-10-10 10:36:46.293882000 +0200
7003 +/* Kernel module to match the bridge port in and
7004 + * out device for IP packets coming into contact with a bridge. */
7005 +#include <linux/module.h>
7006 +#include <linux/skbuff.h>
7007 +#include <linux/netfilter_ipv4/ipt_physdev.h>
7008 +#include <linux/netfilter_ipv4/ip_tables.h>
7009 +#include <linux/netfilter_bridge.h>
7010 +#include <linux/netdevice.h>
7015 +match(const struct sk_buff *skb,
7016 + const struct net_device *in,
7017 + const struct net_device *out,
7018 + const void *matchinfo,
7021 + u_int16_t datalen,
7025 + static const char nulldevname[IFNAMSIZ] = { 0 };
7026 + const struct ipt_physdev_info *info = matchinfo;
7027 + unsigned long ret;
7028 + const char *indev, *outdev;
7029 + struct nf_bridge_info *nf_bridge;
7031 + /* Not a bridged IP packet or no info available yet:
7032 + * LOCAL_OUT/mangle and LOCAL_OUT/nat don't know if
7033 + * the destination device will be a bridge. */
7034 + if (!(nf_bridge = skb->nf_bridge)) {
7035 + /* Return MATCH if the invert flags of the used options are on */
7036 + if ((info->bitmask & IPT_PHYSDEV_OP_BRIDGED) &&
7037 + !(info->invert & IPT_PHYSDEV_OP_BRIDGED))
7039 + if ((info->bitmask & IPT_PHYSDEV_OP_ISIN) &&
7040 + !(info->invert & IPT_PHYSDEV_OP_ISIN))
7042 + if ((info->bitmask & IPT_PHYSDEV_OP_ISOUT) &&
7043 + !(info->invert & IPT_PHYSDEV_OP_ISOUT))
7045 + if ((info->bitmask & IPT_PHYSDEV_OP_IN) &&
7046 + !(info->invert & IPT_PHYSDEV_OP_IN))
7048 + if ((info->bitmask & IPT_PHYSDEV_OP_OUT) &&
7049 + !(info->invert & IPT_PHYSDEV_OP_OUT))
7054 + /* This only makes sense in the FORWARD and POSTROUTING chains */
7055 + if ((info->bitmask & IPT_PHYSDEV_OP_BRIDGED) &&
7056 + (!!(nf_bridge->mask & BRNF_BRIDGED) ^
7057 + !(info->invert & IPT_PHYSDEV_OP_BRIDGED)))
7060 + if ((info->bitmask & IPT_PHYSDEV_OP_ISIN &&
7061 + (!nf_bridge->physindev ^ !!(info->invert & IPT_PHYSDEV_OP_ISIN))) ||
7062 + (info->bitmask & IPT_PHYSDEV_OP_ISOUT &&
7063 + (!nf_bridge->physoutdev ^ !!(info->invert & IPT_PHYSDEV_OP_ISOUT))))
7066 + if (!(info->bitmask & IPT_PHYSDEV_OP_IN))
7067 + goto match_outdev;
7068 + indev = nf_bridge->physindev ? nf_bridge->physindev->name : nulldevname;
7069 + for (i = 0, ret = 0; i < IFNAMSIZ/sizeof(unsigned long); i++) {
7070 + ret |= (((const unsigned long *)indev)[i]
7071 + ^ ((const unsigned long *)info->physindev)[i])
7072 + & ((const unsigned long *)info->in_mask)[i];
7075 + if ((ret == 0) ^ !(info->invert & IPT_PHYSDEV_OP_IN))
7079 + if (!(info->bitmask & IPT_PHYSDEV_OP_OUT))
7081 + outdev = nf_bridge->physoutdev ?
7082 + nf_bridge->physoutdev->name : nulldevname;
7083 + for (i = 0, ret = 0; i < IFNAMSIZ/sizeof(unsigned long); i++) {
7084 + ret |= (((const unsigned long *)outdev)[i]
7085 + ^ ((const unsigned long *)info->physoutdev)[i])
7086 + & ((const unsigned long *)info->out_mask)[i];
7089 + return (ret != 0) ^ !(info->invert & IPT_PHYSDEV_OP_OUT);
7093 +checkentry(const char *tablename,
7094 + const struct ipt_ip *ip,
7096 + unsigned int matchsize,
7097 + unsigned int hook_mask)
7099 + const struct ipt_physdev_info *info = matchinfo;
7101 + if (matchsize != IPT_ALIGN(sizeof(struct ipt_physdev_info)))
7103 + if (!(info->bitmask & IPT_PHYSDEV_OP_MASK) ||
7104 + info->bitmask & ~IPT_PHYSDEV_OP_MASK)
7109 +static struct ipt_match physdev_match = {
7110 + .name = "physdev",
7112 + .checkentry = &checkentry,
7113 + .me = THIS_MODULE,
7116 +static int __init init(void)
7118 + return ipt_register_match(&physdev_match);
7121 +static void __exit fini(void)
7123 + ipt_unregister_match(&physdev_match);
7128 +MODULE_LICENSE("GPL");