1 diff -Nur linux-mips-cvs/include/linux/if_bridge.h linux-ebtables/include/linux/if_bridge.h
2 --- linux-mips-cvs/include/linux/if_bridge.h 2000-02-24 01:13:20.000000000 +0100
3 +++ linux-ebtables/include/linux/if_bridge.h 2005-02-07 05:52:50.000000000 +0100
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-mips-cvs/include/linux/netfilter.h linux-ebtables/include/linux/netfilter.h
15 --- linux-mips-cvs/include/linux/netfilter.h 2005-01-20 03:19:24.000000000 +0100
16 +++ linux-ebtables/include/linux/netfilter.h 2005-02-07 05:52:50.000000000 +0100
18 /* This is gross, but inline doesn't cut it for avoiding the function
19 call in fast path: gcc doesn't inline (needs value tracking?). --RR */
20 #ifdef CONFIG_NETFILTER_DEBUG
21 -#define NF_HOOK nf_hook_slow
22 +#define NF_HOOK(pf, hook, skb, indev, outdev, okfn) \
23 +nf_hook_slow((pf), (hook), (skb), (indev), (outdev), (okfn), INT_MIN)
24 +#define NF_HOOK_THRESH nf_hook_slow
26 #define NF_HOOK(pf, hook, skb, indev, outdev, okfn) \
27 (list_empty(&nf_hooks[(pf)][(hook)]) \
29 - : nf_hook_slow((pf), (hook), (skb), (indev), (outdev), (okfn)))
30 + : nf_hook_slow((pf), (hook), (skb), (indev), (outdev), (okfn), INT_MIN))
31 +#define NF_HOOK_THRESH(pf, hook, skb, indev, outdev, okfn, thresh) \
32 +(list_empty(&nf_hooks[(pf)][(hook)]) \
34 + : nf_hook_slow((pf), (hook), (skb), (indev), (outdev), (okfn), (thresh)))
37 int nf_hook_slow(int pf, unsigned int hook, struct sk_buff *skb,
38 struct net_device *indev, struct net_device *outdev,
39 - int (*okfn)(struct sk_buff *));
40 + int (*okfn)(struct sk_buff *), int thresh);
42 /* Call setsockopt() */
43 int nf_setsockopt(struct sock *sk, int pf, int optval, char *opt,
44 diff -Nur linux-mips-cvs/include/linux/netfilter_bridge/ebt_802_3.h linux-ebtables/include/linux/netfilter_bridge/ebt_802_3.h
45 --- linux-mips-cvs/include/linux/netfilter_bridge/ebt_802_3.h 1970-01-01 01:00:00.000000000 +0100
46 +++ linux-ebtables/include/linux/netfilter_bridge/ebt_802_3.h 2005-02-07 05:52:50.000000000 +0100
48 +#ifndef __LINUX_BRIDGE_EBT_802_3_H
49 +#define __LINUX_BRIDGE_EBT_802_3_H
51 +#define EBT_802_3_SAP 0x01
52 +#define EBT_802_3_TYPE 0x02
54 +#define EBT_802_3_MATCH "802_3"
57 + * If frame has DSAP/SSAP value 0xaa you must check the SNAP type
58 + * to discover what kind of packet we're carrying.
60 +#define CHECK_TYPE 0xaa
63 + * Control field may be one or two bytes. If the first byte has
64 + * the value 0x03 then the entire length is one byte, otherwise it is two.
65 + * One byte controls are used in Unnumbered Information frames.
66 + * Two byte controls are used in Numbered Information frames.
70 +#define EBT_802_3_MASK (EBT_802_3_SAP | EBT_802_3_TYPE | EBT_802_3)
72 +/* ui has one byte ctrl, ni has two */
89 +struct ebt_802_3_hdr {
99 +struct ebt_802_3_info
108 diff -Nur linux-mips-cvs/include/linux/netfilter_bridge/ebt_among.h linux-ebtables/include/linux/netfilter_bridge/ebt_among.h
109 --- linux-mips-cvs/include/linux/netfilter_bridge/ebt_among.h 1970-01-01 01:00:00.000000000 +0100
110 +++ linux-ebtables/include/linux/netfilter_bridge/ebt_among.h 2005-02-07 05:52:50.000000000 +0100
112 +#ifndef __LINUX_BRIDGE_EBT_AMONG_H
113 +#define __LINUX_BRIDGE_EBT_AMONG_H
115 +#define EBT_AMONG_DST 0x01
116 +#define EBT_AMONG_SRC 0x02
118 +/* Grzegorz Borowiak <grzes@gnu.univ.gda.pl> 2003
120 + * Write-once-read-many hash table, used for checking if a given
121 + * MAC address belongs to a set or not and possibly for checking
122 + * if it is related with a given IPv4 address.
124 + * The hash value of an address is its last byte.
126 + * In real-world ethernet addresses, values of the last byte are
127 + * evenly distributed and there is no need to consider other bytes.
128 + * It would only slow the routines down.
130 + * For MAC address comparison speedup reasons, we introduce a trick.
131 + * MAC address is mapped onto an array of two 32-bit integers.
132 + * This pair of integers is compared with MAC addresses in the
133 + * hash table, which are stored also in form of pairs of integers
134 + * (in `cmp' array). This is quick as it requires only two elementary
135 + * number comparisons in worst case. Further, we take advantage of
136 + * fact that entropy of 3 last bytes of address is larger than entropy
137 + * of 3 first bytes. So first we compare 4 last bytes of addresses and
138 + * if they are the same we compare 2 first.
140 + * Yes, it is a memory overhead, but in 2003 AD, who cares?
143 +struct ebt_mac_wormhash_tuple
149 +struct ebt_mac_wormhash
153 + struct ebt_mac_wormhash_tuple pool[0];
156 +#define ebt_mac_wormhash_size(x) ((x) ? sizeof(struct ebt_mac_wormhash) \
157 + + (x)->poolsize * sizeof(struct ebt_mac_wormhash_tuple) : 0)
159 +struct ebt_among_info
166 +#define EBT_AMONG_DST_NEG 0x1
167 +#define EBT_AMONG_SRC_NEG 0x2
169 +#define ebt_among_wh_dst(x) ((x)->wh_dst_ofs ? \
170 + (struct ebt_mac_wormhash*)((char*)(x) + (x)->wh_dst_ofs) : NULL)
171 +#define ebt_among_wh_src(x) ((x)->wh_src_ofs ? \
172 + (struct ebt_mac_wormhash*)((char*)(x) + (x)->wh_src_ofs) : NULL)
174 +#define EBT_AMONG_MATCH "among"
177 diff -Nur linux-mips-cvs/include/linux/netfilter_bridge/ebt_arp.h linux-ebtables/include/linux/netfilter_bridge/ebt_arp.h
178 --- linux-mips-cvs/include/linux/netfilter_bridge/ebt_arp.h 1970-01-01 01:00:00.000000000 +0100
179 +++ linux-ebtables/include/linux/netfilter_bridge/ebt_arp.h 2005-02-07 05:52:50.000000000 +0100
181 +#ifndef __LINUX_BRIDGE_EBT_ARP_H
182 +#define __LINUX_BRIDGE_EBT_ARP_H
184 +#define EBT_ARP_OPCODE 0x01
185 +#define EBT_ARP_HTYPE 0x02
186 +#define EBT_ARP_PTYPE 0x04
187 +#define EBT_ARP_SRC_IP 0x08
188 +#define EBT_ARP_DST_IP 0x10
189 +#define EBT_ARP_SRC_MAC 0x20
190 +#define EBT_ARP_DST_MAC 0x40
191 +#define EBT_ARP_MASK (EBT_ARP_OPCODE | EBT_ARP_HTYPE | EBT_ARP_PTYPE | \
192 + EBT_ARP_SRC_IP | EBT_ARP_DST_IP | EBT_ARP_SRC_MAC | EBT_ARP_DST_MAC)
193 +#define EBT_ARP_MATCH "arp"
204 + unsigned char smaddr[ETH_ALEN];
205 + unsigned char smmsk[ETH_ALEN];
206 + unsigned char dmaddr[ETH_ALEN];
207 + unsigned char dmmsk[ETH_ALEN];
213 diff -Nur linux-mips-cvs/include/linux/netfilter_bridge/ebt_arpreply.h linux-ebtables/include/linux/netfilter_bridge/ebt_arpreply.h
214 --- linux-mips-cvs/include/linux/netfilter_bridge/ebt_arpreply.h 1970-01-01 01:00:00.000000000 +0100
215 +++ linux-ebtables/include/linux/netfilter_bridge/ebt_arpreply.h 2005-02-07 05:52:50.000000000 +0100
217 +#ifndef __LINUX_BRIDGE_EBT_ARPREPLY_H
218 +#define __LINUX_BRIDGE_EBT_ARPREPLY_H
220 +struct ebt_arpreply_info
222 + unsigned char mac[ETH_ALEN];
225 +#define EBT_ARPREPLY_TARGET "arpreply"
228 diff -Nur linux-mips-cvs/include/linux/netfilter_bridge/ebt_ip.h linux-ebtables/include/linux/netfilter_bridge/ebt_ip.h
229 --- linux-mips-cvs/include/linux/netfilter_bridge/ebt_ip.h 1970-01-01 01:00:00.000000000 +0100
230 +++ linux-ebtables/include/linux/netfilter_bridge/ebt_ip.h 2005-02-07 05:52:50.000000000 +0100
236 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
241 + * added ip-sport and ip-dport
242 + * Innominate Security Technologies AG <mhopf@innominate.com>
246 +#ifndef __LINUX_BRIDGE_EBT_IP_H
247 +#define __LINUX_BRIDGE_EBT_IP_H
249 +#define EBT_IP_SOURCE 0x01
250 +#define EBT_IP_DEST 0x02
251 +#define EBT_IP_TOS 0x04
252 +#define EBT_IP_PROTO 0x08
253 +#define EBT_IP_SPORT 0x10
254 +#define EBT_IP_DPORT 0x20
255 +#define EBT_IP_MASK (EBT_IP_SOURCE | EBT_IP_DEST | EBT_IP_TOS | EBT_IP_PROTO |\
256 + EBT_IP_SPORT | EBT_IP_DPORT )
257 +#define EBT_IP_MATCH "ip"
259 +// the same values are used for the invflags
275 diff -Nur linux-mips-cvs/include/linux/netfilter_bridge/ebt_limit.h linux-ebtables/include/linux/netfilter_bridge/ebt_limit.h
276 --- linux-mips-cvs/include/linux/netfilter_bridge/ebt_limit.h 1970-01-01 01:00:00.000000000 +0100
277 +++ linux-ebtables/include/linux/netfilter_bridge/ebt_limit.h 2005-02-07 05:52:50.000000000 +0100
279 +#ifndef __LINUX_BRIDGE_EBT_LIMIT_H
280 +#define __LINUX_BRIDGE_EBT_LIMIT_H
282 +#define EBT_LIMIT_MATCH "limit"
284 +/* timings are in milliseconds. */
285 +#define EBT_LIMIT_SCALE 10000
287 +/* 1/10,000 sec period => max of 10,000/sec. Min rate is then 429490
288 + seconds, or one every 59 hours. */
290 +struct ebt_limit_info
292 + u_int32_t avg; /* Average secs between packets * scale */
293 + u_int32_t burst; /* Period multiplier for upper limit. */
295 + /* Used internally by the kernel */
296 + unsigned long prev;
298 + u_int32_t credit_cap, cost;
302 diff -Nur linux-mips-cvs/include/linux/netfilter_bridge/ebt_log.h linux-ebtables/include/linux/netfilter_bridge/ebt_log.h
303 --- linux-mips-cvs/include/linux/netfilter_bridge/ebt_log.h 1970-01-01 01:00:00.000000000 +0100
304 +++ linux-ebtables/include/linux/netfilter_bridge/ebt_log.h 2005-02-07 05:52:50.000000000 +0100
306 +#ifndef __LINUX_BRIDGE_EBT_LOG_H
307 +#define __LINUX_BRIDGE_EBT_LOG_H
309 +#define EBT_LOG_IP 0x01 // if the frame is made by ip, log the ip information
310 +#define EBT_LOG_ARP 0x02
311 +#define EBT_LOG_MASK (EBT_LOG_IP | EBT_LOG_ARP)
312 +#define EBT_LOG_PREFIX_SIZE 30
313 +#define EBT_LOG_WATCHER "log"
318 + uint8_t prefix[EBT_LOG_PREFIX_SIZE];
323 diff -Nur linux-mips-cvs/include/linux/netfilter_bridge/ebt_mark_m.h linux-ebtables/include/linux/netfilter_bridge/ebt_mark_m.h
324 --- linux-mips-cvs/include/linux/netfilter_bridge/ebt_mark_m.h 1970-01-01 01:00:00.000000000 +0100
325 +++ linux-ebtables/include/linux/netfilter_bridge/ebt_mark_m.h 2005-02-07 05:52:50.000000000 +0100
327 +#ifndef __LINUX_BRIDGE_EBT_MARK_M_H
328 +#define __LINUX_BRIDGE_EBT_MARK_M_H
330 +#define EBT_MARK_AND 0x01
331 +#define EBT_MARK_OR 0x02
332 +#define EBT_MARK_MASK (EBT_MARK_AND | EBT_MARK_OR)
333 +struct ebt_mark_m_info
335 + unsigned long mark, mask;
339 +#define EBT_MARK_MATCH "mark_m"
342 diff -Nur linux-mips-cvs/include/linux/netfilter_bridge/ebt_mark_t.h linux-ebtables/include/linux/netfilter_bridge/ebt_mark_t.h
343 --- linux-mips-cvs/include/linux/netfilter_bridge/ebt_mark_t.h 1970-01-01 01:00:00.000000000 +0100
344 +++ linux-ebtables/include/linux/netfilter_bridge/ebt_mark_t.h 2005-02-07 05:52:50.000000000 +0100
346 +#ifndef __LINUX_BRIDGE_EBT_MARK_T_H
347 +#define __LINUX_BRIDGE_EBT_MARK_T_H
349 +struct ebt_mark_t_info
351 + unsigned long mark;
352 + // EBT_ACCEPT, EBT_DROP or EBT_CONTINUE or EBT_RETURN
355 +#define EBT_MARK_TARGET "mark"
358 diff -Nur linux-mips-cvs/include/linux/netfilter_bridge/ebt_nat.h linux-ebtables/include/linux/netfilter_bridge/ebt_nat.h
359 --- linux-mips-cvs/include/linux/netfilter_bridge/ebt_nat.h 1970-01-01 01:00:00.000000000 +0100
360 +++ linux-ebtables/include/linux/netfilter_bridge/ebt_nat.h 2005-02-07 05:52:50.000000000 +0100
362 +#ifndef __LINUX_BRIDGE_EBT_NAT_H
363 +#define __LINUX_BRIDGE_EBT_NAT_H
367 + unsigned char mac[ETH_ALEN];
368 + // EBT_ACCEPT, EBT_DROP, EBT_CONTINUE or EBT_RETURN
371 +#define EBT_SNAT_TARGET "snat"
372 +#define EBT_DNAT_TARGET "dnat"
375 diff -Nur linux-mips-cvs/include/linux/netfilter_bridge/ebt_pkttype.h linux-ebtables/include/linux/netfilter_bridge/ebt_pkttype.h
376 --- linux-mips-cvs/include/linux/netfilter_bridge/ebt_pkttype.h 1970-01-01 01:00:00.000000000 +0100
377 +++ linux-ebtables/include/linux/netfilter_bridge/ebt_pkttype.h 2005-02-07 05:52:50.000000000 +0100
379 +#ifndef __LINUX_BRIDGE_EBT_PKTTYPE_H
380 +#define __LINUX_BRIDGE_EBT_PKTTYPE_H
382 +struct ebt_pkttype_info
387 +#define EBT_PKTTYPE_MATCH "pkttype"
390 diff -Nur linux-mips-cvs/include/linux/netfilter_bridge/ebt_redirect.h linux-ebtables/include/linux/netfilter_bridge/ebt_redirect.h
391 --- linux-mips-cvs/include/linux/netfilter_bridge/ebt_redirect.h 1970-01-01 01:00:00.000000000 +0100
392 +++ linux-ebtables/include/linux/netfilter_bridge/ebt_redirect.h 2005-02-07 05:52:50.000000000 +0100
394 +#ifndef __LINUX_BRIDGE_EBT_REDIRECT_H
395 +#define __LINUX_BRIDGE_EBT_REDIRECT_H
397 +struct ebt_redirect_info
399 + // EBT_ACCEPT, EBT_DROP or EBT_CONTINUE or EBT_RETURN
402 +#define EBT_REDIRECT_TARGET "redirect"
405 diff -Nur linux-mips-cvs/include/linux/netfilter_bridge/ebt_stp.h linux-ebtables/include/linux/netfilter_bridge/ebt_stp.h
406 --- linux-mips-cvs/include/linux/netfilter_bridge/ebt_stp.h 1970-01-01 01:00:00.000000000 +0100
407 +++ linux-ebtables/include/linux/netfilter_bridge/ebt_stp.h 2005-02-07 05:52:50.000000000 +0100
409 +#ifndef __LINUX_BRIDGE_EBT_STP_H
410 +#define __LINUX_BRIDGE_EBT_STP_H
412 +#define EBT_STP_TYPE 0x0001
414 +#define EBT_STP_FLAGS 0x0002
415 +#define EBT_STP_ROOTPRIO 0x0004
416 +#define EBT_STP_ROOTADDR 0x0008
417 +#define EBT_STP_ROOTCOST 0x0010
418 +#define EBT_STP_SENDERPRIO 0x0020
419 +#define EBT_STP_SENDERADDR 0x0040
420 +#define EBT_STP_PORT 0x0080
421 +#define EBT_STP_MSGAGE 0x0100
422 +#define EBT_STP_MAXAGE 0x0200
423 +#define EBT_STP_HELLOTIME 0x0400
424 +#define EBT_STP_FWDD 0x0800
426 +#define EBT_STP_MASK 0x0fff
427 +#define EBT_STP_CONFIG_MASK 0x0ffe
429 +#define EBT_STP_MATCH "stp"
431 +struct ebt_stp_config_info
434 + uint16_t root_priol, root_priou;
435 + char root_addr[6], root_addrmsk[6];
436 + uint32_t root_costl, root_costu;
437 + uint16_t sender_priol, sender_priou;
438 + char sender_addr[6], sender_addrmsk[6];
439 + uint16_t portl, portu;
440 + uint16_t msg_agel, msg_ageu;
441 + uint16_t max_agel, max_ageu;
442 + uint16_t hello_timel, hello_timeu;
443 + uint16_t forward_delayl, forward_delayu;
449 + struct ebt_stp_config_info config;
455 diff -Nur linux-mips-cvs/include/linux/netfilter_bridge/ebt_ulog.h linux-ebtables/include/linux/netfilter_bridge/ebt_ulog.h
456 --- linux-mips-cvs/include/linux/netfilter_bridge/ebt_ulog.h 1970-01-01 01:00:00.000000000 +0100
457 +++ linux-ebtables/include/linux/netfilter_bridge/ebt_ulog.h 2005-02-07 05:52:50.000000000 +0100
462 +#define EBT_ULOG_DEFAULT_NLGROUP 0
463 +#define EBT_ULOG_DEFAULT_QTHRESHOLD 1
464 +#define EBT_ULOG_MAXNLGROUPS 32 /* hardcoded netlink max */
465 +#define EBT_ULOG_PREFIX_LEN 32
466 +#define EBT_ULOG_MAX_QLEN 50
467 +#define EBT_ULOG_WATCHER "ulog"
469 +struct ebt_ulog_info {
471 + unsigned int cprange;
472 + unsigned int qthreshold;
473 + char prefix[EBT_ULOG_PREFIX_LEN];
476 +typedef struct ebt_ulog_packet_msg {
477 + char indev[IFNAMSIZ];
478 + char outdev[IFNAMSIZ];
479 + char physindev[IFNAMSIZ];
480 + char physoutdev[IFNAMSIZ];
481 + char prefix[EBT_ULOG_PREFIX_LEN];
482 + struct timeval stamp;
483 + unsigned long mark;
486 + /* The complete packet, including Ethernet header and perhaps
487 + * the VLAN header is appended */
488 + unsigned char data[0] __attribute__ ((aligned (__alignof__(int))));
489 +} ebt_ulog_packet_msg_t;
491 +#endif /* _EBT_ULOG_H */
492 diff -Nur linux-mips-cvs/include/linux/netfilter_bridge/ebt_vlan.h linux-ebtables/include/linux/netfilter_bridge/ebt_vlan.h
493 --- linux-mips-cvs/include/linux/netfilter_bridge/ebt_vlan.h 1970-01-01 01:00:00.000000000 +0100
494 +++ linux-ebtables/include/linux/netfilter_bridge/ebt_vlan.h 2005-02-07 05:52:50.000000000 +0100
496 +#ifndef __LINUX_BRIDGE_EBT_VLAN_H
497 +#define __LINUX_BRIDGE_EBT_VLAN_H
499 +#define EBT_VLAN_ID 0x01
500 +#define EBT_VLAN_PRIO 0x02
501 +#define EBT_VLAN_ENCAP 0x04
502 +#define EBT_VLAN_MASK (EBT_VLAN_ID | EBT_VLAN_PRIO | EBT_VLAN_ENCAP)
503 +#define EBT_VLAN_MATCH "vlan"
505 +struct ebt_vlan_info {
506 + uint16_t id; /* VLAN ID {1-4095} */
507 + uint8_t prio; /* VLAN User Priority {0-7} */
508 + uint16_t encap; /* VLAN Encapsulated frame code {0-65535} */
509 + uint8_t bitmask; /* Args bitmask bit 1=1 - ID arg,
510 + bit 2=1 User-Priority arg, bit 3=1 encap*/
511 + uint8_t invflags; /* Inverse bitmask bit 1=1 - inversed ID arg,
512 + bit 2=1 - inversed Pirority arg */
516 diff -Nur linux-mips-cvs/include/linux/netfilter_bridge/ebtables.h linux-ebtables/include/linux/netfilter_bridge/ebtables.h
517 --- linux-mips-cvs/include/linux/netfilter_bridge/ebtables.h 1970-01-01 01:00:00.000000000 +0100
518 +++ linux-ebtables/include/linux/netfilter_bridge/ebtables.h 2005-02-07 05:52:50.000000000 +0100
524 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
526 + * ebtables.c,v 2.0, September, 2002
528 + * This code is stongly inspired on the iptables code which is
529 + * Copyright (C) 1999 Paul `Rusty' Russell & Michael J. Neuling
532 +#ifndef __LINUX_BRIDGE_EFF_H
533 +#define __LINUX_BRIDGE_EFF_H
534 +#include <linux/if.h>
535 +#include <linux/netfilter_bridge.h>
536 +#include <linux/if_ether.h>
538 +#define EBT_TABLE_MAXNAMELEN 32
539 +#define EBT_CHAIN_MAXNAMELEN EBT_TABLE_MAXNAMELEN
540 +#define EBT_FUNCTION_MAXNAMELEN EBT_TABLE_MAXNAMELEN
542 +// verdicts >0 are "branches"
543 +#define EBT_ACCEPT -1
545 +#define EBT_CONTINUE -3
546 +#define EBT_RETURN -4
547 +#define NUM_STANDARD_TARGETS 4
555 +struct ebt_entries {
556 + // this field is always set to zero
557 + // See EBT_ENTRY_OR_ENTRIES.
558 + // Must be same size as ebt_entry.bitmask
559 + unsigned int distinguisher;
561 + char name[EBT_CHAIN_MAXNAMELEN];
562 + // counter offset for this chain
563 + unsigned int counter_offset;
564 + // one standard (accept, drop, return) per hook
567 + unsigned int nentries;
572 +// used for the bitmask of struct ebt_entry
574 +// This is a hack to make a difference between an ebt_entry struct and an
575 +// ebt_entries struct when traversing the entries from start to end.
576 +// Using this simplifies the code alot, while still being able to use
578 +// Contrary, iptables doesn't use something like ebt_entries and therefore uses
579 +// different techniques for naming the policy and such. So, iptables doesn't
580 +// need a hack like this.
581 +#define EBT_ENTRY_OR_ENTRIES 0x01
582 +// these are the normal masks
583 +#define EBT_NOPROTO 0x02
584 +#define EBT_802_3 0x04
585 +#define EBT_SOURCEMAC 0x08
586 +#define EBT_DESTMAC 0x10
587 +#define EBT_F_MASK (EBT_NOPROTO | EBT_802_3 | EBT_SOURCEMAC | EBT_DESTMAC \
588 + | EBT_ENTRY_OR_ENTRIES)
590 +#define EBT_IPROTO 0x01
591 +#define EBT_IIN 0x02
592 +#define EBT_IOUT 0x04
593 +#define EBT_ISOURCE 0x8
594 +#define EBT_IDEST 0x10
595 +#define EBT_ILOGICALIN 0x20
596 +#define EBT_ILOGICALOUT 0x40
597 +#define EBT_INV_MASK (EBT_IPROTO | EBT_IIN | EBT_IOUT | EBT_ILOGICALIN \
598 + | EBT_ILOGICALOUT | EBT_ISOURCE | EBT_IDEST)
600 +struct ebt_entry_match
603 + char name[EBT_FUNCTION_MAXNAMELEN];
604 + struct ebt_match *match;
607 + unsigned int match_size;
608 + unsigned char data[0];
611 +struct ebt_entry_watcher
614 + char name[EBT_FUNCTION_MAXNAMELEN];
615 + struct ebt_watcher *watcher;
618 + unsigned int watcher_size;
619 + unsigned char data[0];
622 +struct ebt_entry_target
625 + char name[EBT_FUNCTION_MAXNAMELEN];
626 + struct ebt_target *target;
629 + unsigned int target_size;
630 + unsigned char data[0];
633 +#define EBT_STANDARD_TARGET "standard"
634 +struct ebt_standard_target
636 + struct ebt_entry_target target;
642 + // this needs to be the first field
643 + unsigned int bitmask;
644 + unsigned int invflags;
646 + // the physical in-dev
648 + // the logical in-dev
649 + char logical_in[IFNAMSIZ];
650 + // the physical out-dev
651 + char out[IFNAMSIZ];
652 + // the logical out-dev
653 + char logical_out[IFNAMSIZ];
654 + unsigned char sourcemac[ETH_ALEN];
655 + unsigned char sourcemsk[ETH_ALEN];
656 + unsigned char destmac[ETH_ALEN];
657 + unsigned char destmsk[ETH_ALEN];
658 + // sizeof ebt_entry + matches
659 + unsigned int watchers_offset;
660 + // sizeof ebt_entry + matches + watchers
661 + unsigned int target_offset;
662 + // sizeof ebt_entry + matches + watchers + target
663 + unsigned int next_offset;
664 + unsigned char elems[0];
669 + char name[EBT_TABLE_MAXNAMELEN];
670 + unsigned int valid_hooks;
671 + // nr of rules in the table
672 + unsigned int nentries;
673 + // total size of the entries
674 + unsigned int entries_size;
675 + // start of the chains
676 + struct ebt_entries *hook_entry[NF_BR_NUMHOOKS];
677 + // nr of counters userspace expects back
678 + unsigned int num_counters;
679 + // where the kernel will put the old counters
680 + struct ebt_counter *counters;
684 +// [gs]etsockopt numbers
685 +#define EBT_BASE_CTL 128
687 +#define EBT_SO_SET_ENTRIES (EBT_BASE_CTL)
688 +#define EBT_SO_SET_COUNTERS (EBT_SO_SET_ENTRIES+1)
689 +#define EBT_SO_SET_MAX (EBT_SO_SET_COUNTERS+1)
691 +#define EBT_SO_GET_INFO (EBT_BASE_CTL)
692 +#define EBT_SO_GET_ENTRIES (EBT_SO_GET_INFO+1)
693 +#define EBT_SO_GET_INIT_INFO (EBT_SO_GET_ENTRIES+1)
694 +#define EBT_SO_GET_INIT_ENTRIES (EBT_SO_GET_INIT_INFO+1)
695 +#define EBT_SO_GET_MAX (EBT_SO_GET_INIT_ENTRIES+1)
699 +// return values for match() functions
701 +#define EBT_NOMATCH 1
705 + struct list_head list;
706 + const char name[EBT_FUNCTION_MAXNAMELEN];
708 + int (*match)(const struct sk_buff *skb, const struct net_device *in,
709 + const struct net_device *out, const void *matchdata,
710 + unsigned int datalen);
712 + int (*check)(const char *tablename, unsigned int hookmask,
713 + const struct ebt_entry *e, void *matchdata, unsigned int datalen);
714 + void (*destroy)(void *matchdata, unsigned int datalen);
720 + struct list_head list;
721 + const char name[EBT_FUNCTION_MAXNAMELEN];
722 + void (*watcher)(const struct sk_buff *skb, unsigned int hooknr,
723 + const struct net_device *in, const struct net_device *out,
724 + const void *watcherdata, unsigned int datalen);
726 + int (*check)(const char *tablename, unsigned int hookmask,
727 + const struct ebt_entry *e, void *watcherdata, unsigned int datalen);
728 + void (*destroy)(void *watcherdata, unsigned int datalen);
734 + struct list_head list;
735 + const char name[EBT_FUNCTION_MAXNAMELEN];
736 + // returns one of the standard verdicts
737 + int (*target)(struct sk_buff **pskb, unsigned int hooknr,
738 + const struct net_device *in, const struct net_device *out,
739 + const void *targetdata, unsigned int datalen);
741 + int (*check)(const char *tablename, unsigned int hookmask,
742 + const struct ebt_entry *e, void *targetdata, unsigned int datalen);
743 + void (*destroy)(void *targetdata, unsigned int datalen);
747 +// used for jumping from and into user defined chains (udc)
748 +struct ebt_chainstack
750 + struct ebt_entries *chaininfo; // pointer to chain data
751 + struct ebt_entry *e; // pointer to entry data
752 + unsigned int n; // n'th entry
755 +struct ebt_table_info
757 + // total size of the entries
758 + unsigned int entries_size;
759 + unsigned int nentries;
760 + // pointers to the start of the chains
761 + struct ebt_entries *hook_entry[NF_BR_NUMHOOKS];
762 + // room to maintain the stack used for jumping from and into udc
763 + struct ebt_chainstack **chainstack;
765 + struct ebt_counter counters[0] ____cacheline_aligned;
770 + struct list_head list;
771 + char name[EBT_TABLE_MAXNAMELEN];
772 + struct ebt_replace *table;
773 + unsigned int valid_hooks;
775 + // e.g. could be the table explicitly only allows certain
776 + // matches, targets, ... 0 == let it in
777 + int (*check)(const struct ebt_table_info *info,
778 + unsigned int valid_hooks);
779 + // the data used by the kernel
780 + struct ebt_table_info *private;
783 +#define EBT_ALIGN(s) (((s) + (__alignof__(struct ebt_entry_target)-1)) & \
784 + ~(__alignof__(struct ebt_entry_target)-1))
785 +extern int ebt_register_table(struct ebt_table *table);
786 +extern void ebt_unregister_table(struct ebt_table *table);
787 +extern int ebt_register_match(struct ebt_match *match);
788 +extern void ebt_unregister_match(struct ebt_match *match);
789 +extern int ebt_register_watcher(struct ebt_watcher *watcher);
790 +extern void ebt_unregister_watcher(struct ebt_watcher *watcher);
791 +extern int ebt_register_target(struct ebt_target *target);
792 +extern void ebt_unregister_target(struct ebt_target *target);
793 +extern unsigned int ebt_do_table(unsigned int hook, struct sk_buff **pskb,
794 + const struct net_device *in, const struct net_device *out,
795 + struct ebt_table *table);
797 + // Used in the kernel match() functions
798 +#define FWINV(bool,invflg) ((bool) ^ !!(info->invflags & invflg))
799 +// True if the hook mask denotes that the rule is in a base chain,
800 +// used in the check() functions
801 +#define BASE_CHAIN (hookmask & (1 << NF_BR_NUMHOOKS))
802 +// Clear the bit in the hook mask that tells if the rule is on a base chain
803 +#define CLEAR_BASE_CHAIN_BIT (hookmask &= ~(1 << NF_BR_NUMHOOKS))
804 +// True if the target is not a standard target
805 +#define INVALID_TARGET (info->target < -NUM_STANDARD_TARGETS || info->target >= 0)
807 +#endif /* __KERNEL__ */
809 +// blatently stolen from ip_tables.h
810 +// fn returns 0 to continue iteration
811 +#define EBT_MATCH_ITERATE(e, fn, args...) \
813 + unsigned int __i; \
815 + struct ebt_entry_match *__match; \
817 + for (__i = sizeof(struct ebt_entry); \
818 + __i < (e)->watchers_offset; \
819 + __i += __match->match_size + \
820 + sizeof(struct ebt_entry_match)) { \
821 + __match = (void *)(e) + __i; \
823 + __ret = fn(__match , ## args); \
827 + if (__ret == 0) { \
828 + if (__i != (e)->watchers_offset) \
834 +#define EBT_WATCHER_ITERATE(e, fn, args...) \
836 + unsigned int __i; \
838 + struct ebt_entry_watcher *__watcher; \
840 + for (__i = e->watchers_offset; \
841 + __i < (e)->target_offset; \
842 + __i += __watcher->watcher_size + \
843 + sizeof(struct ebt_entry_watcher)) { \
844 + __watcher = (void *)(e) + __i; \
846 + __ret = fn(__watcher , ## args); \
850 + if (__ret == 0) { \
851 + if (__i != (e)->target_offset) \
857 +#define EBT_ENTRY_ITERATE(entries, size, fn, args...) \
859 + unsigned int __i; \
861 + struct ebt_entry *__entry; \
863 + for (__i = 0; __i < (size);) { \
864 + __entry = (void *)(entries) + __i; \
865 + __ret = fn(__entry , ## args); \
868 + if (__entry->bitmask != 0) \
869 + __i += __entry->next_offset; \
871 + __i += sizeof(struct ebt_entries); \
873 + if (__ret == 0) { \
874 + if (__i != (size)) \
881 diff -Nur linux-mips-cvs/include/linux/netfilter_bridge.h linux-ebtables/include/linux/netfilter_bridge.h
882 --- linux-mips-cvs/include/linux/netfilter_bridge.h 2001-08-22 05:25:11.000000000 +0200
883 +++ linux-ebtables/include/linux/netfilter_bridge.h 2005-02-07 05:52:50.000000000 +0100
886 #include <linux/config.h>
887 #include <linux/netfilter.h>
888 +#if defined(__KERNEL__) && defined(CONFIG_NETFILTER)
889 +#include <asm/atomic.h>
890 +#include <linux/if_ether.h>
894 /* After promisc drops, checksum checks. */
896 #define NF_BR_LOCAL_OUT 3
897 /* Packets about to hit the wire. */
898 #define NF_BR_POST_ROUTING 4
899 -#define NF_BR_NUMHOOKS 5
900 +/* Not really a hook, but used for the ebtables broute table */
901 +#define NF_BR_BROUTING 5
902 +#define NF_BR_NUMHOOKS 6
906 +#define BRNF_PKT_TYPE 0x01
907 +#define BRNF_BRIDGED_DNAT 0x02
908 +#define BRNF_DONT_TAKE_PARENT 0x04
909 +#define BRNF_BRIDGED 0x08
910 +#define BRNF_NF_BRIDGE_PREROUTING 0x10
912 +enum nf_br_hook_priorities {
913 + NF_BR_PRI_FIRST = INT_MIN,
914 + NF_BR_PRI_NAT_DST_BRIDGED = -300,
915 + NF_BR_PRI_FILTER_BRIDGED = -200,
916 + NF_BR_PRI_BRNF = 0,
917 + NF_BR_PRI_NAT_DST_OTHER = 100,
918 + NF_BR_PRI_FILTER_OTHER = 200,
919 + NF_BR_PRI_NAT_SRC = 300,
920 + NF_BR_PRI_LAST = INT_MAX,
923 +#ifdef CONFIG_NETFILTER
925 +struct nf_bridge_info *nf_bridge_alloc(struct sk_buff *skb)
927 + struct nf_bridge_info **nf_bridge = &(skb->nf_bridge);
929 + if ((*nf_bridge = kmalloc(sizeof(**nf_bridge), GFP_ATOMIC)) != NULL) {
930 + atomic_set(&(*nf_bridge)->use, 1);
931 + (*nf_bridge)->mask = 0;
932 + (*nf_bridge)->physindev = (*nf_bridge)->physoutdev = NULL;
933 +#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
934 + (*nf_bridge)->netoutdev = NULL;
941 +/* Only used in br_forward.c */
943 +void nf_bridge_maybe_copy_header(struct sk_buff *skb)
945 + if (skb->nf_bridge) {
946 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
947 + memcpy(skb->data - 18, skb->nf_bridge->data, 18);
950 + memcpy(skb->data - 16, skb->nf_bridge->data, 16);
955 +void nf_bridge_save_header(struct sk_buff *skb)
957 + int header_size = 16;
959 + if (skb->protocol == __constant_htons(ETH_P_8021Q))
961 + memcpy(skb->nf_bridge->data, skb->data - header_size, header_size);
964 +struct bridge_skb_cb {
969 +#endif /* CONFIG_NETFILTER */
971 +#endif /* __KERNEL__ */
973 diff -Nur linux-mips-cvs/include/linux/netfilter_ipv4/ipt_physdev.h linux-ebtables/include/linux/netfilter_ipv4/ipt_physdev.h
974 --- linux-mips-cvs/include/linux/netfilter_ipv4/ipt_physdev.h 1970-01-01 01:00:00.000000000 +0100
975 +++ linux-ebtables/include/linux/netfilter_ipv4/ipt_physdev.h 2005-02-07 05:52:50.000000000 +0100
977 +#ifndef _IPT_PHYSDEV_H
978 +#define _IPT_PHYSDEV_H
981 +#include <linux/if.h>
984 +#define IPT_PHYSDEV_OP_IN 0x01
985 +#define IPT_PHYSDEV_OP_OUT 0x02
986 +#define IPT_PHYSDEV_OP_BRIDGED 0x04
987 +#define IPT_PHYSDEV_OP_ISIN 0x08
988 +#define IPT_PHYSDEV_OP_ISOUT 0x10
989 +#define IPT_PHYSDEV_OP_MASK (0x20 - 1)
991 +struct ipt_physdev_info {
992 + char physindev[IFNAMSIZ];
993 + char in_mask[IFNAMSIZ];
994 + char physoutdev[IFNAMSIZ];
995 + char out_mask[IFNAMSIZ];
1000 +#endif /*_IPT_PHYSDEV_H*/
1001 diff -Nur linux-mips-cvs/include/linux/netfilter_ipv4.h linux-ebtables/include/linux/netfilter_ipv4.h
1002 --- linux-mips-cvs/include/linux/netfilter_ipv4.h 2002-02-26 07:00:31.000000000 +0100
1003 +++ linux-ebtables/include/linux/netfilter_ipv4.h 2005-02-07 05:52:50.000000000 +0100
1005 enum nf_ip_hook_priorities {
1006 NF_IP_PRI_FIRST = INT_MIN,
1007 NF_IP_PRI_CONNTRACK = -200,
1008 + NF_IP_PRI_BRIDGE_SABOTAGE_FORWARD = -175,
1009 NF_IP_PRI_MANGLE = -150,
1010 NF_IP_PRI_NAT_DST = -100,
1011 + NF_IP_PRI_BRIDGE_SABOTAGE_LOCAL_OUT = -50,
1012 NF_IP_PRI_FILTER = 0,
1013 NF_IP_PRI_NAT_SRC = 100,
1014 NF_IP_PRI_LAST = INT_MAX,
1015 diff -Nur linux-mips-cvs/include/linux/netfilter_ipv6.h linux-ebtables/include/linux/netfilter_ipv6.h
1016 --- linux-mips-cvs/include/linux/netfilter_ipv6.h 2001-01-11 05:02:45.000000000 +0100
1017 +++ linux-ebtables/include/linux/netfilter_ipv6.h 2005-02-07 05:52:50.000000000 +0100
1019 enum nf_ip6_hook_priorities {
1020 NF_IP6_PRI_FIRST = INT_MIN,
1021 NF_IP6_PRI_CONNTRACK = -200,
1022 + NF_IP6_PRI_BRIDGE_SABOTAGE_FORWARD = -175,
1023 NF_IP6_PRI_MANGLE = -150,
1024 NF_IP6_PRI_NAT_DST = -100,
1025 + NF_IP6_PRI_BRIDGE_SABOTAGE_LOCAL_OUT = -50,
1026 NF_IP6_PRI_FILTER = 0,
1027 NF_IP6_PRI_NAT_SRC = 100,
1028 NF_IP6_PRI_LAST = INT_MAX,
1029 diff -Nur linux-mips-cvs/include/linux/skbuff.h linux-ebtables/include/linux/skbuff.h
1030 --- linux-mips-cvs/include/linux/skbuff.h 2005-01-31 12:56:47.000000000 +0100
1031 +++ linux-ebtables/include/linux/skbuff.h 2005-02-07 05:52:50.000000000 +0100
1034 struct nf_conntrack *master;
1037 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
1038 +struct nf_bridge_info {
1040 + struct net_device *physindev;
1041 + struct net_device *physoutdev;
1042 +#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
1043 + struct net_device *netoutdev;
1045 + unsigned int mask;
1046 + unsigned long data[32 / sizeof(unsigned long)];
1052 struct sk_buff_head {
1054 #ifdef CONFIG_NETFILTER_DEBUG
1055 unsigned int nf_debug;
1057 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
1058 + struct nf_bridge_info *nf_bridge; /* Saved data about a bridged frame - see br_netfilter.c */
1060 #endif /*CONFIG_NETFILTER*/
1062 #if defined(CONFIG_HIPPI)
1063 @@ -1175,6 +1192,20 @@
1068 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
1069 +static inline void nf_bridge_put(struct nf_bridge_info *nf_bridge)
1071 + if (nf_bridge && atomic_dec_and_test(&nf_bridge->use))
1074 +static inline void nf_bridge_get(struct nf_bridge_info *nf_bridge)
1077 + atomic_inc(&nf_bridge->use);
1081 #else /* CONFIG_NETFILTER */
1082 static inline void nf_reset(struct sk_buff *skb) {}
1083 #endif /* CONFIG_NETFILTER */
1084 diff -Nur linux-mips-cvs/include/linux/sysctl.h linux-ebtables/include/linux/sysctl.h
1085 --- linux-mips-cvs/include/linux/sysctl.h 2004-11-29 18:47:18.000000000 +0100
1086 +++ linux-ebtables/include/linux/sysctl.h 2005-02-07 05:52:50.000000000 +0100
1087 @@ -608,6 +608,15 @@
1088 NET_DECNET_CONF_DEV_STATE = 7
1091 +/* /proc/sys/net/bridge */
1093 + NET_BRIDGE_NF_CALL_ARPTABLES = 1,
1094 + NET_BRIDGE_NF_CALL_IPTABLES = 2,
1095 + NET_BRIDGE_NF_CALL_IP6TABLES = 3,
1096 + NET_BRIDGE_NF_FILTER_VLAN_TAGGED = 4,
1100 /* CTL_PROC names: */
1103 diff -Nur linux-mips-cvs/include/linux/sysctl.h.orig linux-ebtables/include/linux/sysctl.h.orig
1104 --- linux-mips-cvs/include/linux/sysctl.h.orig 1970-01-01 01:00:00.000000000 +0100
1105 +++ linux-ebtables/include/linux/sysctl.h.orig 2004-11-29 18:47:18.000000000 +0100
1108 + * sysctl.h: General linux system control interface
1110 + * Begun 24 March 1995, Stephen Tweedie
1112 + ****************************************************************
1113 + ****************************************************************
1116 + ** The values in this file are exported to user space via
1117 + ** the sysctl() binary interface. Do *NOT* change the
1118 + ** numbering of any existing values here, and do not change
1119 + ** any numbers within any one set of values. If you have
1120 + ** to redefine an existing interface, use a new number for it.
1121 + ** The kernel will then return ENOTDIR to any application using
1122 + ** the old binary interface.
1126 + ****************************************************************
1127 + ****************************************************************
1130 +#ifndef _LINUX_SYSCTL_H
1131 +#define _LINUX_SYSCTL_H
1133 +#include <linux/kernel.h>
1134 +#include <linux/types.h>
1135 +#include <linux/list.h>
1139 +#define CTL_MAXNAME 10
1141 +struct __sysctl_args {
1148 + unsigned long __unused[4];
1151 +/* Define sysctl names first */
1153 +/* Top-level names: */
1155 +/* For internal pattern-matching use only: */
1157 +#define CTL_ANY -1 /* Matches any name */
1163 + CTL_KERN=1, /* General kernel info and control */
1164 + CTL_VM=2, /* VM management */
1165 + CTL_NET=3, /* Networking */
1166 + CTL_PROC=4, /* Process info */
1167 + CTL_FS=5, /* Filesystems */
1168 + CTL_DEBUG=6, /* Debugging */
1169 + CTL_DEV=7, /* Devices */
1170 + CTL_BUS=8, /* Busses */
1171 + CTL_ABI=9, /* Binary emulation */
1172 + CTL_CPU=10 /* CPU stuff (speed scaling, etc) */
1175 +/* CTL_BUS names: */
1178 + CTL_BUS_ISA=1 /* ISA */
1181 +/* CTL_KERN names: */
1184 + KERN_OSTYPE=1, /* string: system version */
1185 + KERN_OSRELEASE=2, /* string: system release */
1186 + KERN_OSREV=3, /* int: system revision */
1187 + KERN_VERSION=4, /* string: compile time info */
1188 + KERN_SECUREMASK=5, /* struct: maximum rights mask */
1189 + KERN_PROF=6, /* table: profiling information */
1191 + KERN_DOMAINNAME=8,
1193 + KERN_CAP_BSET=14, /* int: capability bounding set */
1194 + KERN_PANIC=15, /* int: panic timeout */
1195 + KERN_REALROOTDEV=16, /* real root device to mount after initrd */
1197 + KERN_SPARC_REBOOT=21, /* reboot command on Sparc */
1198 + KERN_CTLALTDEL=22, /* int: allow ctl-alt-del to reboot */
1199 + KERN_PRINTK=23, /* struct: control printk logging parameters */
1200 + KERN_NAMETRANS=24, /* Name translation */
1201 + KERN_PPC_HTABRECLAIM=25, /* turn htab reclaimation on/off on PPC */
1202 + KERN_PPC_ZEROPAGED=26, /* turn idle page zeroing on/off on PPC */
1203 + KERN_PPC_POWERSAVE_NAP=27, /* use nap mode for power saving */
1205 + KERN_SG_BIG_BUFF=29,
1206 + KERN_ACCT=30, /* BSD process accounting parameters */
1207 + KERN_PPC_L2CR=31, /* l2cr register on PPC */
1209 + KERN_RTSIGNR=32, /* Number of rt sigs queued */
1210 + KERN_RTSIGMAX=33, /* Max queuable */
1212 + KERN_SHMMAX=34, /* long: Maximum shared memory segment */
1213 + KERN_MSGMAX=35, /* int: Maximum size of a messege */
1214 + KERN_MSGMNB=36, /* int: Maximum message queue size */
1215 + KERN_MSGPOOL=37, /* int: Maximum system message pool size */
1216 + KERN_SYSRQ=38, /* int: Sysreq enable */
1217 + KERN_MAX_THREADS=39, /* int: Maximum nr of threads in the system */
1218 + KERN_RANDOM=40, /* Random driver */
1219 + KERN_SHMALL=41, /* int: Maximum size of shared memory */
1220 + KERN_MSGMNI=42, /* int: msg queue identifiers */
1221 + KERN_SEM=43, /* struct: sysv semaphore limits */
1222 + KERN_SPARC_STOP_A=44, /* int: Sparc Stop-A enable */
1223 + KERN_SHMMNI=45, /* int: shm array identifiers */
1224 + KERN_OVERFLOWUID=46, /* int: overflow UID */
1225 + KERN_OVERFLOWGID=47, /* int: overflow GID */
1226 + KERN_SHMPATH=48, /* string: path to shm fs */
1227 + KERN_HOTPLUG=49, /* string: path to hotplug policy agent */
1228 + KERN_IEEE_EMULATION_WARNINGS=50, /* int: unimplemented ieee instructions */
1229 + KERN_S390_USER_DEBUG_LOGGING=51, /* int: dumps of user faults */
1230 + KERN_CORE_USES_PID=52, /* int: use core or core.%pid */
1231 + KERN_TAINTED=53, /* int: various kernel tainted flags */
1232 + KERN_CADPID=54, /* int: PID of the process to notify on CAD */
1233 + KERN_CORE_PATTERN=56, /* string: pattern for core-files */
1234 + KERN_PPC_L3CR=57, /* l3cr register on PPC */
1235 + KERN_EXCEPTION_TRACE=58, /* boolean: exception trace */
1236 + KERN_CORE_SETUID=59, /* int: set to allow core dumps of setuid apps */
1237 + KERN_SPARC_SCONS_PWROFF=64, /* int: serial console power-off halt */
1241 +/* CTL_VM names: */
1244 + VM_SWAPCTL=1, /* struct: Set vm swapping control */
1245 + VM_SWAPOUT=2, /* int: Linear or sqrt() swapout for hogs */
1246 + VM_FREEPG=3, /* struct: Set free page thresholds */
1247 + VM_BDFLUSH=4, /* struct: Control buffer cache flushing */
1248 + VM_OVERCOMMIT_MEMORY=5, /* Turn off the virtual memory safety limit */
1249 + VM_BUFFERMEM=6, /* struct: Set buffer memory thresholds */
1250 + VM_PAGECACHE=7, /* struct: Set cache memory thresholds */
1251 + VM_PAGERDAEMON=8, /* struct: Control kswapd behaviour */
1252 + VM_PGT_CACHE=9, /* struct: Set page table cache parameters */
1253 + VM_PAGE_CLUSTER=10, /* int: set number of pages to swap together */
1254 + VM_MAX_MAP_COUNT=11, /* int: Maximum number of active map areas */
1255 + VM_MIN_READAHEAD=12, /* Min file readahead */
1256 + VM_MAX_READAHEAD=13, /* Max file readahead */
1257 + VM_VFS_SCAN_RATIO=14, /* part of the inactive vfs lists to scan */
1258 + VM_LRU_BALANCE_RATIO=15,/* balance active and inactive caches */
1259 + VM_PASSES=16, /* number of vm passes before failing */
1260 + VM_PAGEBUF=17, /* struct: Control pagebuf parameters */
1261 + VM_GFP_DEBUG=18, /* debug GFP failures */
1262 + VM_CACHE_SCAN_RATIO=19, /* part of the inactive cache list to scan */
1263 + VM_MAPPED_RATIO=20, /* amount of unfreeable pages that triggers swapout */
1264 + VM_LAPTOP_MODE=21, /* kernel in laptop flush mode */
1265 + VM_BLOCK_DUMP=22, /* dump fs activity to log */
1266 + VM_ANON_LRU=23, /* immediatly insert anon pages in the vm page lru */
1270 +/* CTL_NET names: */
1293 +/* /proc/sys/kernel/random */
1296 + RANDOM_POOLSIZE=1,
1297 + RANDOM_ENTROPY_COUNT=2,
1298 + RANDOM_READ_THRESH=3,
1299 + RANDOM_WRITE_THRESH=4,
1304 +/* /proc/sys/bus/isa */
1307 + BUS_ISA_MEM_BASE=1,
1308 + BUS_ISA_PORT_BASE=2,
1309 + BUS_ISA_PORT_SHIFT=3
1312 +/* /proc/sys/net/core */
1315 + NET_CORE_WMEM_MAX=1,
1316 + NET_CORE_RMEM_MAX=2,
1317 + NET_CORE_WMEM_DEFAULT=3,
1318 + NET_CORE_RMEM_DEFAULT=4,
1319 +/* was NET_CORE_DESTROY_DELAY */
1320 + NET_CORE_MAX_BACKLOG=6,
1321 + NET_CORE_FASTROUTE=7,
1322 + NET_CORE_MSG_COST=8,
1323 + NET_CORE_MSG_BURST=9,
1324 + NET_CORE_OPTMEM_MAX=10,
1325 + NET_CORE_HOT_LIST_LENGTH=11,
1326 + NET_CORE_DIVERT_VERSION=12,
1327 + NET_CORE_NO_CONG_THRESH=13,
1328 + NET_CORE_NO_CONG=14,
1329 + NET_CORE_LO_CONG=15,
1330 + NET_CORE_MOD_CONG=16,
1331 + NET_CORE_DEV_WEIGHT=17,
1332 + NET_CORE_SOMAXCONN=18,
1335 +/* /proc/sys/net/ethernet */
1337 +/* /proc/sys/net/802 */
1339 +/* /proc/sys/net/unix */
1343 + NET_UNIX_DESTROY_DELAY=1,
1344 + NET_UNIX_DELETE_DELAY=2,
1345 + NET_UNIX_MAX_DGRAM_QLEN=3,
1348 +/* /proc/sys/net/ipv4 */
1351 + /* v2.0 compatibile variables */
1352 + NET_IPV4_FORWARD=8,
1353 + NET_IPV4_DYNADDR=9,
1356 + NET_IPV4_NEIGH=17,
1357 + NET_IPV4_ROUTE=18,
1358 + NET_IPV4_FIB_HASH=19,
1359 + NET_IPV4_NETFILTER=20,
1361 + NET_IPV4_TCP_TIMESTAMPS=33,
1362 + NET_IPV4_TCP_WINDOW_SCALING=34,
1363 + NET_IPV4_TCP_SACK=35,
1364 + NET_IPV4_TCP_RETRANS_COLLAPSE=36,
1365 + NET_IPV4_DEFAULT_TTL=37,
1366 + NET_IPV4_AUTOCONFIG=38,
1367 + NET_IPV4_NO_PMTU_DISC=39,
1368 + NET_IPV4_TCP_SYN_RETRIES=40,
1369 + NET_IPV4_IPFRAG_HIGH_THRESH=41,
1370 + NET_IPV4_IPFRAG_LOW_THRESH=42,
1371 + NET_IPV4_IPFRAG_TIME=43,
1372 + NET_IPV4_TCP_MAX_KA_PROBES=44,
1373 + NET_IPV4_TCP_KEEPALIVE_TIME=45,
1374 + NET_IPV4_TCP_KEEPALIVE_PROBES=46,
1375 + NET_IPV4_TCP_RETRIES1=47,
1376 + NET_IPV4_TCP_RETRIES2=48,
1377 + NET_IPV4_TCP_FIN_TIMEOUT=49,
1378 + NET_IPV4_IP_MASQ_DEBUG=50,
1379 + NET_TCP_SYNCOOKIES=51,
1380 + NET_TCP_STDURG=52,
1381 + NET_TCP_RFC1337=53,
1382 + NET_TCP_SYN_TAILDROP=54,
1383 + NET_TCP_MAX_SYN_BACKLOG=55,
1384 + NET_IPV4_LOCAL_PORT_RANGE=56,
1385 + NET_IPV4_ICMP_ECHO_IGNORE_ALL=57,
1386 + NET_IPV4_ICMP_ECHO_IGNORE_BROADCASTS=58,
1387 + NET_IPV4_ICMP_SOURCEQUENCH_RATE=59,
1388 + NET_IPV4_ICMP_DESTUNREACH_RATE=60,
1389 + NET_IPV4_ICMP_TIMEEXCEED_RATE=61,
1390 + NET_IPV4_ICMP_PARAMPROB_RATE=62,
1391 + NET_IPV4_ICMP_ECHOREPLY_RATE=63,
1392 + NET_IPV4_ICMP_IGNORE_BOGUS_ERROR_RESPONSES=64,
1393 + NET_IPV4_IGMP_MAX_MEMBERSHIPS=65,
1394 + NET_TCP_TW_RECYCLE=66,
1395 + NET_IPV4_ALWAYS_DEFRAG=67,
1396 + NET_IPV4_TCP_KEEPALIVE_INTVL=68,
1397 + NET_IPV4_INET_PEER_THRESHOLD=69,
1398 + NET_IPV4_INET_PEER_MINTTL=70,
1399 + NET_IPV4_INET_PEER_MAXTTL=71,
1400 + NET_IPV4_INET_PEER_GC_MINTIME=72,
1401 + NET_IPV4_INET_PEER_GC_MAXTIME=73,
1402 + NET_TCP_ORPHAN_RETRIES=74,
1403 + NET_TCP_ABORT_ON_OVERFLOW=75,
1404 + NET_TCP_SYNACK_RETRIES=76,
1405 + NET_TCP_MAX_ORPHANS=77,
1406 + NET_TCP_MAX_TW_BUCKETS=78,
1408 + NET_TCP_REORDERING=80,
1414 + NET_TCP_APP_WIN=86,
1415 + NET_TCP_ADV_WIN_SCALE=87,
1416 + NET_IPV4_NONLOCAL_BIND=88,
1417 + NET_IPV4_ICMP_RATELIMIT=89,
1418 + NET_IPV4_ICMP_RATEMASK=90,
1419 + NET_TCP_TW_REUSE=91,
1421 + NET_TCP_LOW_LATENCY=93,
1422 + NET_IPV4_IPFRAG_SECRET_INTERVAL=94,
1423 + NET_TCP_WESTWOOD=95,
1424 + NET_IPV4_IGMP_MAX_MSF=96,
1425 + NET_TCP_NO_METRICS_SAVE=97,
1427 + NET_TCP_VEGAS_ALPHA=99,
1428 + NET_TCP_VEGAS_BETA=100,
1429 + NET_TCP_VEGAS_GAMMA=101,
1431 + NET_TCP_BIC_FAST_CONVERGENCE=103,
1432 + NET_TCP_BIC_LOW_WINDOW=104,
1433 + NET_TCP_DEFAULT_WIN_SCALE=105,
1434 + NET_TCP_MODERATE_RCVBUF=106,
1438 + NET_IPV4_ROUTE_FLUSH=1,
1439 + NET_IPV4_ROUTE_MIN_DELAY=2,
1440 + NET_IPV4_ROUTE_MAX_DELAY=3,
1441 + NET_IPV4_ROUTE_GC_THRESH=4,
1442 + NET_IPV4_ROUTE_MAX_SIZE=5,
1443 + NET_IPV4_ROUTE_GC_MIN_INTERVAL=6,
1444 + NET_IPV4_ROUTE_GC_TIMEOUT=7,
1445 + NET_IPV4_ROUTE_GC_INTERVAL=8,
1446 + NET_IPV4_ROUTE_REDIRECT_LOAD=9,
1447 + NET_IPV4_ROUTE_REDIRECT_NUMBER=10,
1448 + NET_IPV4_ROUTE_REDIRECT_SILENCE=11,
1449 + NET_IPV4_ROUTE_ERROR_COST=12,
1450 + NET_IPV4_ROUTE_ERROR_BURST=13,
1451 + NET_IPV4_ROUTE_GC_ELASTICITY=14,
1452 + NET_IPV4_ROUTE_MTU_EXPIRES=15,
1453 + NET_IPV4_ROUTE_MIN_PMTU=16,
1454 + NET_IPV4_ROUTE_MIN_ADVMSS=17,
1455 + NET_IPV4_ROUTE_SECRET_INTERVAL=18,
1460 + NET_PROTO_CONF_ALL=-2,
1461 + NET_PROTO_CONF_DEFAULT=-3
1463 + /* And device ifindices ... */
1468 + NET_IPV4_CONF_FORWARDING=1,
1469 + NET_IPV4_CONF_MC_FORWARDING=2,
1470 + NET_IPV4_CONF_PROXY_ARP=3,
1471 + NET_IPV4_CONF_ACCEPT_REDIRECTS=4,
1472 + NET_IPV4_CONF_SECURE_REDIRECTS=5,
1473 + NET_IPV4_CONF_SEND_REDIRECTS=6,
1474 + NET_IPV4_CONF_SHARED_MEDIA=7,
1475 + NET_IPV4_CONF_RP_FILTER=8,
1476 + NET_IPV4_CONF_ACCEPT_SOURCE_ROUTE=9,
1477 + NET_IPV4_CONF_BOOTP_RELAY=10,
1478 + NET_IPV4_CONF_LOG_MARTIANS=11,
1479 + NET_IPV4_CONF_TAG=12,
1480 + NET_IPV4_CONF_ARPFILTER=13,
1481 + NET_IPV4_CONF_MEDIUM_ID=14,
1482 + NET_IPV4_CONF_FORCE_IGMP_VERSION=17,
1483 + NET_IPV4_CONF_ARP_ANNOUNCE=18,
1484 + NET_IPV4_CONF_ARP_IGNORE=19,
1487 +/* /proc/sys/net/ipv4/netfilter */
1490 + NET_IPV4_NF_CONNTRACK_MAX=1,
1491 + NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_SYN_SENT=2,
1492 + NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_SYN_RECV=3,
1493 + NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_ESTABLISHED=4,
1494 + NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_FIN_WAIT=5,
1495 + NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_CLOSE_WAIT=6,
1496 + NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_LAST_ACK=7,
1497 + NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_TIME_WAIT=8,
1498 + NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_CLOSE=9,
1499 + NET_IPV4_NF_CONNTRACK_UDP_TIMEOUT=10,
1500 + NET_IPV4_NF_CONNTRACK_UDP_TIMEOUT_STREAM=11,
1501 + NET_IPV4_NF_CONNTRACK_ICMP_TIMEOUT=12,
1502 + NET_IPV4_NF_CONNTRACK_GENERIC_TIMEOUT=13,
1503 + NET_IPV4_NF_CONNTRACK_BUCKETS=14,
1506 +/* /proc/sys/net/ipv6 */
1509 + NET_IPV6_NEIGH=17,
1510 + NET_IPV6_ROUTE=18,
1512 + NET_IPV6_BINDV6ONLY=20,
1513 + NET_IPV6_MLD_MAX_MSF=25,
1517 + NET_IPV6_ROUTE_FLUSH=1,
1518 + NET_IPV6_ROUTE_GC_THRESH=2,
1519 + NET_IPV6_ROUTE_MAX_SIZE=3,
1520 + NET_IPV6_ROUTE_GC_MIN_INTERVAL=4,
1521 + NET_IPV6_ROUTE_GC_TIMEOUT=5,
1522 + NET_IPV6_ROUTE_GC_INTERVAL=6,
1523 + NET_IPV6_ROUTE_GC_ELASTICITY=7,
1524 + NET_IPV6_ROUTE_MTU_EXPIRES=8,
1525 + NET_IPV6_ROUTE_MIN_ADVMSS=9
1529 + NET_IPV6_FORWARDING=1,
1530 + NET_IPV6_HOP_LIMIT=2,
1532 + NET_IPV6_ACCEPT_RA=4,
1533 + NET_IPV6_ACCEPT_REDIRECTS=5,
1534 + NET_IPV6_AUTOCONF=6,
1535 + NET_IPV6_DAD_TRANSMITS=7,
1536 + NET_IPV6_RTR_SOLICITS=8,
1537 + NET_IPV6_RTR_SOLICIT_INTERVAL=9,
1538 + NET_IPV6_RTR_SOLICIT_DELAY=10
1541 +/* /proc/sys/net/ipv6/icmp */
1543 + NET_IPV6_ICMP_RATELIMIT=1
1546 +/* /proc/sys/net/<protocol>/neigh/<dev> */
1548 + NET_NEIGH_MCAST_SOLICIT=1,
1549 + NET_NEIGH_UCAST_SOLICIT=2,
1550 + NET_NEIGH_APP_SOLICIT=3,
1551 + NET_NEIGH_RETRANS_TIME=4,
1552 + NET_NEIGH_REACHABLE_TIME=5,
1553 + NET_NEIGH_DELAY_PROBE_TIME=6,
1554 + NET_NEIGH_GC_STALE_TIME=7,
1555 + NET_NEIGH_UNRES_QLEN=8,
1556 + NET_NEIGH_PROXY_QLEN=9,
1557 + NET_NEIGH_ANYCAST_DELAY=10,
1558 + NET_NEIGH_PROXY_DELAY=11,
1559 + NET_NEIGH_LOCKTIME=12,
1560 + NET_NEIGH_GC_INTERVAL=13,
1561 + NET_NEIGH_GC_THRESH1=14,
1562 + NET_NEIGH_GC_THRESH2=15,
1563 + NET_NEIGH_GC_THRESH3=16
1566 +/* /proc/sys/net/ipx */
1568 + NET_IPX_PPROP_BROADCASTING=1,
1569 + NET_IPX_FORWARDING=2
1573 +/* /proc/sys/net/appletalk */
1575 + NET_ATALK_AARP_EXPIRY_TIME=1,
1576 + NET_ATALK_AARP_TICK_TIME=2,
1577 + NET_ATALK_AARP_RETRANSMIT_LIMIT=3,
1578 + NET_ATALK_AARP_RESOLVE_TIME=4
1582 +/* /proc/sys/net/netrom */
1584 + NET_NETROM_DEFAULT_PATH_QUALITY=1,
1585 + NET_NETROM_OBSOLESCENCE_COUNT_INITIALISER=2,
1586 + NET_NETROM_NETWORK_TTL_INITIALISER=3,
1587 + NET_NETROM_TRANSPORT_TIMEOUT=4,
1588 + NET_NETROM_TRANSPORT_MAXIMUM_TRIES=5,
1589 + NET_NETROM_TRANSPORT_ACKNOWLEDGE_DELAY=6,
1590 + NET_NETROM_TRANSPORT_BUSY_DELAY=7,
1591 + NET_NETROM_TRANSPORT_REQUESTED_WINDOW_SIZE=8,
1592 + NET_NETROM_TRANSPORT_NO_ACTIVITY_TIMEOUT=9,
1593 + NET_NETROM_ROUTING_CONTROL=10,
1594 + NET_NETROM_LINK_FAILS_COUNT=11
1597 +/* /proc/sys/net/ax25 */
1599 + NET_AX25_IP_DEFAULT_MODE=1,
1600 + NET_AX25_DEFAULT_MODE=2,
1601 + NET_AX25_BACKOFF_TYPE=3,
1602 + NET_AX25_CONNECT_MODE=4,
1603 + NET_AX25_STANDARD_WINDOW=5,
1604 + NET_AX25_EXTENDED_WINDOW=6,
1605 + NET_AX25_T1_TIMEOUT=7,
1606 + NET_AX25_T2_TIMEOUT=8,
1607 + NET_AX25_T3_TIMEOUT=9,
1608 + NET_AX25_IDLE_TIMEOUT=10,
1610 + NET_AX25_PACLEN=12,
1611 + NET_AX25_PROTOCOL=13,
1612 + NET_AX25_DAMA_SLAVE_TIMEOUT=14
1615 +/* /proc/sys/net/rose */
1617 + NET_ROSE_RESTART_REQUEST_TIMEOUT=1,
1618 + NET_ROSE_CALL_REQUEST_TIMEOUT=2,
1619 + NET_ROSE_RESET_REQUEST_TIMEOUT=3,
1620 + NET_ROSE_CLEAR_REQUEST_TIMEOUT=4,
1621 + NET_ROSE_ACK_HOLD_BACK_TIMEOUT=5,
1622 + NET_ROSE_ROUTING_CONTROL=6,
1623 + NET_ROSE_LINK_FAIL_TIMEOUT=7,
1624 + NET_ROSE_MAX_VCS=8,
1625 + NET_ROSE_WINDOW_SIZE=9,
1626 + NET_ROSE_NO_ACTIVITY_TIMEOUT=10
1629 +/* /proc/sys/net/x25 */
1631 + NET_X25_RESTART_REQUEST_TIMEOUT=1,
1632 + NET_X25_CALL_REQUEST_TIMEOUT=2,
1633 + NET_X25_RESET_REQUEST_TIMEOUT=3,
1634 + NET_X25_CLEAR_REQUEST_TIMEOUT=4,
1635 + NET_X25_ACK_HOLD_BACK_TIMEOUT=5
1638 +/* /proc/sys/net/token-ring */
1641 + NET_TR_RIF_TIMEOUT=1
1644 +/* /proc/sys/net/decnet/ */
1646 + NET_DECNET_NODE_TYPE = 1,
1647 + NET_DECNET_NODE_ADDRESS = 2,
1648 + NET_DECNET_NODE_NAME = 3,
1649 + NET_DECNET_DEFAULT_DEVICE = 4,
1650 + NET_DECNET_TIME_WAIT = 5,
1651 + NET_DECNET_DN_COUNT = 6,
1652 + NET_DECNET_DI_COUNT = 7,
1653 + NET_DECNET_DR_COUNT = 8,
1654 + NET_DECNET_DST_GC_INTERVAL = 9,
1655 + NET_DECNET_CONF = 10,
1656 + NET_DECNET_NO_FC_MAX_CWND = 11,
1657 + NET_DECNET_DEBUG_LEVEL = 255
1660 +/* /proc/sys/net/sctp */
1662 + NET_SCTP_RTO_INITIAL = 1,
1663 + NET_SCTP_RTO_MIN = 2,
1664 + NET_SCTP_RTO_MAX = 3,
1665 + NET_SCTP_RTO_ALPHA = 4,
1666 + NET_SCTP_RTO_BETA = 5,
1667 + NET_SCTP_VALID_COOKIE_LIFE = 6,
1668 + NET_SCTP_ASSOCIATION_MAX_RETRANS = 7,
1669 + NET_SCTP_PATH_MAX_RETRANS = 8,
1670 + NET_SCTP_MAX_INIT_RETRANSMITS = 9,
1671 + NET_SCTP_HB_INTERVAL = 10,
1672 + NET_SCTP_PRESERVE_ENABLE = 11,
1673 + NET_SCTP_MAX_BURST = 12,
1674 + NET_SCTP_ADDIP_ENABLE = 13,
1675 + NET_SCTP_PRSCTP_ENABLE = 14,
1677 +/* /proc/sys/net/khttpd/ */
1679 + NET_KHTTPD_DOCROOT = 1,
1680 + NET_KHTTPD_START = 2,
1681 + NET_KHTTPD_STOP = 3,
1682 + NET_KHTTPD_UNLOAD = 4,
1683 + NET_KHTTPD_CLIENTPORT = 5,
1684 + NET_KHTTPD_PERMREQ = 6,
1685 + NET_KHTTPD_PERMFORBID = 7,
1686 + NET_KHTTPD_LOGGING = 8,
1687 + NET_KHTTPD_SERVERPORT = 9,
1688 + NET_KHTTPD_DYNAMICSTRING= 10,
1689 + NET_KHTTPD_SLOPPYMIME = 11,
1690 + NET_KHTTPD_THREADS = 12,
1691 + NET_KHTTPD_MAXCONNECT = 13
1694 +/* /proc/sys/net/decnet/conf/<dev> */
1696 + NET_DECNET_CONF_LOOPBACK = -2,
1697 + NET_DECNET_CONF_DDCMP = -3,
1698 + NET_DECNET_CONF_PPP = -4,
1699 + NET_DECNET_CONF_X25 = -5,
1700 + NET_DECNET_CONF_GRE = -6,
1701 + NET_DECNET_CONF_ETHER = -7
1703 + /* ... and ifindex of devices */
1706 +/* /proc/sys/net/decnet/conf/<dev>/ */
1708 + NET_DECNET_CONF_DEV_PRIORITY = 1,
1709 + NET_DECNET_CONF_DEV_T1 = 2,
1710 + NET_DECNET_CONF_DEV_T2 = 3,
1711 + NET_DECNET_CONF_DEV_T3 = 4,
1712 + NET_DECNET_CONF_DEV_FORWARDING = 5,
1713 + NET_DECNET_CONF_DEV_BLKSIZE = 6,
1714 + NET_DECNET_CONF_DEV_STATE = 7
1717 +/* CTL_PROC names: */
1719 +/* CTL_FS names: */
1722 + FS_NRINODE=1, /* int:current number of allocated inodes */
1724 + FS_MAXINODE=3, /* int:maximum number of inodes that can be allocated */
1725 + FS_NRDQUOT=4, /* int:current number of allocated dquots */
1726 + /* was FS_MAXDQUOT */
1727 + FS_NRFILE=6, /* int:current number of allocated filedescriptors */
1728 + FS_MAXFILE=7, /* int:maximum number of filedescriptors that can be allocated */
1730 + FS_NRSUPER=9, /* int:current number of allocated super_blocks */
1731 + FS_MAXSUPER=10, /* int:maximum number of super_blocks that can be allocated */
1732 + FS_OVERFLOWUID=11, /* int: overflow UID */
1733 + FS_OVERFLOWGID=12, /* int: overflow GID */
1734 + FS_LEASES=13, /* int: leases enabled */
1735 + FS_DIR_NOTIFY=14, /* int: directory notification enabled */
1736 + FS_LEASE_TIME=15, /* int: maximum time to wait for a lease break */
1737 + FS_DQSTATS=16, /* dir: disc quota usage statistics and settings */
1738 + FS_XFS=17, /* struct: control xfs parameters */
1741 +/* /proc/sys/fs/quota/ */
1743 + FS_DQ_LOOKUPS = 1,
1747 + FS_DQ_CACHE_HITS = 5,
1748 + FS_DQ_ALLOCATED = 6,
1751 + FS_DQ_WARNINGS = 9,
1754 +/* CTL_DEBUG names: */
1756 +/* CTL_DEV names: */
1765 +/* /proc/sys/dev/cdrom */
1768 + DEV_CDROM_AUTOCLOSE=2,
1769 + DEV_CDROM_AUTOEJECT=3,
1770 + DEV_CDROM_DEBUG=4,
1772 + DEV_CDROM_CHECK_MEDIA=6
1775 +/* /proc/sys/dev/parport */
1777 + DEV_PARPORT_DEFAULT=-3
1780 +/* /proc/sys/dev/raid */
1782 + DEV_RAID_SPEED_LIMIT_MIN=1,
1783 + DEV_RAID_SPEED_LIMIT_MAX=2
1786 +/* /proc/sys/dev/parport/default */
1788 + DEV_PARPORT_DEFAULT_TIMESLICE=1,
1789 + DEV_PARPORT_DEFAULT_SPINTIME=2
1792 +/* /proc/sys/dev/parport/parport n */
1794 + DEV_PARPORT_SPINTIME=1,
1795 + DEV_PARPORT_BASE_ADDR=2,
1796 + DEV_PARPORT_IRQ=3,
1797 + DEV_PARPORT_DMA=4,
1798 + DEV_PARPORT_MODES=5,
1799 + DEV_PARPORT_DEVICES=6,
1800 + DEV_PARPORT_AUTOPROBE=16
1803 +/* /proc/sys/dev/parport/parport n/devices/ */
1805 + DEV_PARPORT_DEVICES_ACTIVE=-3,
1808 +/* /proc/sys/dev/parport/parport n/devices/device n */
1810 + DEV_PARPORT_DEVICE_TIMESLICE=1,
1813 +/* /proc/sys/dev/mac_hid */
1815 + DEV_MAC_HID_KEYBOARD_SENDS_LINUX_KEYCODES=1,
1816 + DEV_MAC_HID_KEYBOARD_LOCK_KEYCODES=2,
1817 + DEV_MAC_HID_MOUSE_BUTTON_EMULATION=3,
1818 + DEV_MAC_HID_MOUSE_BUTTON2_KEYCODE=4,
1819 + DEV_MAC_HID_MOUSE_BUTTON3_KEYCODE=5,
1820 + DEV_MAC_HID_ADB_MOUSE_SENDS_KEYCODES=6
1823 +/* /proc/sys/abi */
1826 + ABI_DEFHANDLER_COFF=1, /* default handler for coff binaries */
1827 + ABI_DEFHANDLER_ELF=2, /* default handler for ELF binaries */
1828 + ABI_DEFHANDLER_LCALL7=3,/* default handler for procs using lcall7 */
1829 + ABI_DEFHANDLER_LIBCSO=4,/* default handler for an libc.so ELF interp */
1830 + ABI_TRACE=5, /* tracing flags */
1831 + ABI_FAKE_UTSNAME=6, /* fake target utsname information */
1836 +extern asmlinkage long sys_sysctl(struct __sysctl_args *);
1837 +extern void sysctl_init(void);
1839 +typedef struct ctl_table ctl_table;
1841 +typedef int ctl_handler (ctl_table *table, int *name, int nlen,
1842 + void *oldval, size_t *oldlenp,
1843 + void *newval, size_t newlen,
1846 +typedef int proc_handler (ctl_table *ctl, int write, struct file * filp,
1847 + void *buffer, size_t *lenp);
1849 +extern int proc_dostring(ctl_table *, int, struct file *,
1850 + void *, size_t *);
1851 +extern int proc_dointvec(ctl_table *, int, struct file *,
1852 + void *, size_t *);
1853 +extern int proc_dointvec_bset(ctl_table *, int, struct file *,
1854 + void *, size_t *);
1855 +extern int proc_dointvec_minmax(ctl_table *, int, struct file *,
1856 + void *, size_t *);
1857 +extern int proc_dointvec_jiffies(ctl_table *, int, struct file *,
1858 + void *, size_t *);
1859 +extern int proc_doulongvec_minmax(ctl_table *, int, struct file *,
1860 + void *, size_t *);
1861 +extern int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int,
1862 + struct file *, void *, size_t *);
1864 +extern int do_sysctl (int *name, int nlen,
1865 + void *oldval, size_t *oldlenp,
1866 + void *newval, size_t newlen);
1868 +extern int do_sysctl_strategy (ctl_table *table,
1869 + int *name, int nlen,
1870 + void *oldval, size_t *oldlenp,
1871 + void *newval, size_t newlen, void ** context);
1873 +extern ctl_handler sysctl_string;
1874 +extern ctl_handler sysctl_intvec;
1875 +extern ctl_handler sysctl_jiffies;
1879 + * Register a set of sysctl names by calling register_sysctl_table
1880 + * with an initialised array of ctl_table's. An entry with zero
1881 + * ctl_name terminates the table. table->de will be set up by the
1882 + * registration and need not be initialised in advance.
1884 + * sysctl names can be mirrored automatically under /proc/sys. The
1885 + * procname supplied controls /proc naming.
1887 + * The table's mode will be honoured both for sys_sysctl(2) and
1890 + * Leaf nodes in the sysctl tree will be represented by a single file
1891 + * under /proc; non-leaf nodes will be represented by directories. A
1892 + * null procname disables /proc mirroring at this node.
1894 + * sysctl(2) can automatically manage read and write requests through
1895 + * the sysctl table. The data and maxlen fields of the ctl_table
1896 + * struct enable minimal validation of the values being written to be
1897 + * performed, and the mode field allows minimal authentication.
1899 + * More sophisticated management can be enabled by the provision of a
1900 + * strategy routine with the table entry. This will be called before
1901 + * any automatic read or write of the data is performed.
1903 + * The strategy routine may return:
1904 + * <0: Error occurred (error is passed to user process)
1905 + * 0: OK - proceed with automatic read or write.
1906 + * >0: OK - read or write has been done by the strategy routine, so
1907 + * return immediately.
1909 + * There must be a proc_handler routine for any terminal nodes
1910 + * mirrored under /proc/sys (non-terminals are handled by a built-in
1911 + * directory handler). Several default handlers are available to
1912 + * cover common cases.
1915 +/* A sysctl table is an array of struct ctl_table: */
1918 + int ctl_name; /* Binary ID */
1919 + const char *procname; /* Text ID for /proc/sys, or zero */
1924 + proc_handler *proc_handler; /* Callback for text formatting */
1925 + ctl_handler *strategy; /* Callback function for all r/w */
1926 + struct proc_dir_entry *de; /* /proc control block */
1931 +/* struct ctl_table_header is used to maintain dynamic lists of
1932 + ctl_table trees. */
1933 +struct ctl_table_header
1935 + ctl_table *ctl_table;
1936 + struct list_head ctl_entry;
1939 +struct ctl_table_header * register_sysctl_table(ctl_table * table,
1940 + int insert_at_head);
1941 +void unregister_sysctl_table(struct ctl_table_header * table);
1943 +#else /* __KERNEL__ */
1945 +#endif /* __KERNEL__ */
1947 +#endif /* _LINUX_SYSCTL_H */
1948 diff -Nur linux-mips-cvs/net/8021q/vlan_dev.c linux-ebtables/net/8021q/vlan_dev.c
1949 --- linux-mips-cvs/net/8021q/vlan_dev.c 2004-11-29 18:47:19.000000000 +0100
1950 +++ linux-ebtables/net/8021q/vlan_dev.c 2005-02-07 05:52:50.000000000 +0100
1951 @@ -488,6 +488,10 @@
1952 stats->tx_packets++; /* for statics only */
1953 stats->tx_bytes += skb->len;
1955 + skb->protocol = __constant_htons(ETH_P_8021Q);
1956 + skb->mac.raw -= VLAN_HLEN;
1957 + skb->nh.raw -= VLAN_HLEN;
1959 skb->dev = VLAN_DEV_INFO(dev)->real_dev;
1960 dev_queue_xmit(skb);
1962 diff -Nur linux-mips-cvs/net/Config.in linux-ebtables/net/Config.in
1963 --- linux-mips-cvs/net/Config.in 2005-01-09 20:34:04.000000000 +0100
1964 +++ linux-ebtables/net/Config.in 2005-02-07 05:52:50.000000000 +0100
1966 source net/decnet/Config.in
1968 dep_tristate '802.1d Ethernet Bridging' CONFIG_BRIDGE $CONFIG_INET
1969 +if [ "$CONFIG_BRIDGE" != "n" -a "$CONFIG_NETFILTER" != "n" ]; then
1970 + source net/bridge/netfilter/Config.in
1972 if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then
1973 tristate 'CCITT X.25 Packet Layer (EXPERIMENTAL)' CONFIG_X25
1974 tristate 'LAPB Data Link Driver (EXPERIMENTAL)' CONFIG_LAPB
1975 diff -Nur linux-mips-cvs/net/Config.in.orig linux-ebtables/net/Config.in.orig
1976 --- linux-mips-cvs/net/Config.in.orig 1970-01-01 01:00:00.000000000 +0100
1977 +++ linux-ebtables/net/Config.in.orig 2005-01-09 20:34:04.000000000 +0100
1980 +# Network configuration
1982 +mainmenu_option next_comment
1983 +comment 'Networking options'
1984 +tristate 'Packet socket' CONFIG_PACKET
1985 +if [ "$CONFIG_PACKET" != "n" ]; then
1986 + bool ' Packet socket: mmapped IO' CONFIG_PACKET_MMAP
1989 +tristate 'Netlink device emulation' CONFIG_NETLINK_DEV
1991 +bool 'Network packet filtering (replaces ipchains)' CONFIG_NETFILTER
1992 +if [ "$CONFIG_NETFILTER" = "y" ]; then
1993 + bool ' Network packet filtering debugging' CONFIG_NETFILTER_DEBUG
1995 +bool 'Socket Filtering' CONFIG_FILTER
1996 +tristate 'Unix domain sockets' CONFIG_UNIX
1997 +bool 'TCP/IP networking' CONFIG_INET
1998 +if [ "$CONFIG_INET" = "y" ]; then
1999 + source net/ipv4/Config.in
2000 + if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then
2001 +# IPv6 as module will cause a CRASH if you try to unload it
2002 + tristate ' The IPv6 protocol (EXPERIMENTAL)' CONFIG_IPV6
2003 + if [ "$CONFIG_IPV6" != "n" ]; then
2004 + source net/ipv6/Config.in
2007 + if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then
2008 + source net/khttpd/Config.in
2010 + if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then
2011 + source net/sctp/Config.in
2014 +if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then
2015 + tristate 'Asynchronous Transfer Mode (ATM) (EXPERIMENTAL)' CONFIG_ATM
2016 + if [ "$CONFIG_ATM" = "y" -o "$CONFIG_ATM" = "m" ]; then
2017 + if [ "$CONFIG_INET" = "y" ]; then
2018 + dep_tristate ' Classical IP over ATM' CONFIG_ATM_CLIP $CONFIG_ATM
2019 + if [ "$CONFIG_ATM_CLIP" != "n" ]; then
2020 + bool ' Do NOT send ICMP if no neighbour' CONFIG_ATM_CLIP_NO_ICMP
2023 + dep_tristate ' LAN Emulation (LANE) support' CONFIG_ATM_LANE $CONFIG_ATM
2024 + if [ "$CONFIG_INET" = "y" -a "$CONFIG_ATM_LANE" != "n" ]; then
2025 + tristate ' Multi-Protocol Over ATM (MPOA) support' CONFIG_ATM_MPOA
2027 + dep_tristate ' RFC1483/2684 Bridged protocols' CONFIG_ATM_BR2684 $CONFIG_ATM
2028 + if [ "$CONFIG_ATM_BR2684" != "n" ]; then
2029 + bool ' Per-VC IP filter kludge' CONFIG_ATM_BR2684_IPFILTER
2033 +tristate '802.1Q VLAN Support' CONFIG_VLAN_8021Q
2036 +tristate 'The IPX protocol' CONFIG_IPX
2037 +if [ "$CONFIG_IPX" != "n" ]; then
2038 + source net/ipx/Config.in
2041 +tristate 'Appletalk protocol support' CONFIG_ATALK
2042 +if [ "$CONFIG_ATALK" != "n" ]; then
2043 + source drivers/net/appletalk/Config.in
2046 +tristate 'DECnet Support' CONFIG_DECNET
2047 +if [ "$CONFIG_DECNET" != "n" ]; then
2048 + source net/decnet/Config.in
2050 +dep_tristate '802.1d Ethernet Bridging' CONFIG_BRIDGE $CONFIG_INET
2051 +if [ "$CONFIG_EXPERIMENTAL" = "y" ]; then
2052 + tristate 'CCITT X.25 Packet Layer (EXPERIMENTAL)' CONFIG_X25
2053 + tristate 'LAPB Data Link Driver (EXPERIMENTAL)' CONFIG_LAPB
2054 + bool '802.2 LLC (EXPERIMENTAL)' CONFIG_LLC
2055 + bool 'Frame Diverter (EXPERIMENTAL)' CONFIG_NET_DIVERT
2056 +# if [ "$CONFIG_LLC" = "y" ]; then
2057 +# bool ' Netbeui (EXPERIMENTAL)' CONFIG_NETBEUI
2059 + if [ "$CONFIG_INET" = "y" ]; then
2060 + tristate 'Acorn Econet/AUN protocols (EXPERIMENTAL)' CONFIG_ECONET
2061 + if [ "$CONFIG_ECONET" != "n" ]; then
2062 + bool ' AUN over UDP' CONFIG_ECONET_AUNUDP
2063 + bool ' Native Econet' CONFIG_ECONET_NATIVE
2066 + tristate 'WAN router' CONFIG_WAN_ROUTER
2067 + bool 'Fast switching (read help!)' CONFIG_NET_FASTROUTE
2068 + bool 'Forwarding between high speed interfaces' CONFIG_NET_HW_FLOWCONTROL
2071 +mainmenu_option next_comment
2072 +comment 'QoS and/or fair queueing'
2073 +bool 'QoS and/or fair queueing' CONFIG_NET_SCHED
2074 +if [ "$CONFIG_NET_SCHED" = "y" ]; then
2075 + source net/sched/Config.in
2077 +#bool 'Network code profiler' CONFIG_NET_PROFILE
2080 +mainmenu_option next_comment
2081 +comment 'Network testing'
2082 +dep_tristate 'Packet Generator (USE WITH CAUTION)' CONFIG_NET_PKTGEN $CONFIG_PROC_FS
2086 diff -Nur linux-mips-cvs/net/Makefile linux-ebtables/net/Makefile
2087 --- linux-mips-cvs/net/Makefile 2004-08-14 20:39:04.000000000 +0200
2088 +++ linux-ebtables/net/Makefile 2005-02-07 05:52:50.000000000 +0100
2091 O_TARGET := network.o
2093 -mod-subdirs := ipv4/netfilter ipv6/netfilter ipx irda bluetooth atm netlink sched core sctp 802
2094 +mod-subdirs := ipv4/netfilter ipv6/netfilter bridge/netfilter ipx irda \
2095 + bluetooth atm netlink sched core sctp 802
2096 export-objs := netsyms.o
2098 subdir-y := core ethernet
2103 +ifneq ($(CONFIG_BRIDGE),n)
2104 +ifneq ($(CONFIG_BRIDGE),)
2105 +subdir-$(CONFIG_BRIDGE) += bridge/netfilter
2109 subdir-$(CONFIG_KHTTPD) += khttpd
2110 subdir-$(CONFIG_PACKET) += packet
2111 subdir-$(CONFIG_NET_SCHED) += sched
2112 diff -Nur linux-mips-cvs/net/bridge/Makefile linux-ebtables/net/bridge/Makefile
2113 --- linux-mips-cvs/net/bridge/Makefile 2001-01-10 18:18:10.000000000 +0100
2114 +++ linux-ebtables/net/bridge/Makefile 2005-02-07 05:52:50.000000000 +0100
2117 # Note 2! The CFLAGS definition is now in the main makefile...
2119 +export-objs := br.o
2121 O_TARGET := bridge.o
2122 obj-y := br.o br_device.o br_fdb.o br_forward.o br_if.o br_input.o \
2123 br_ioctl.o br_notify.o br_stp.o br_stp_bpdu.o \
2124 br_stp_if.o br_stp_timer.o
2126 +ifeq ($(CONFIG_NETFILTER),y)
2127 +obj-y += br_netfilter.o
2130 obj-m := $(O_TARGET)
2132 include $(TOPDIR)/Rules.make
2133 diff -Nur linux-mips-cvs/net/bridge/br.c linux-ebtables/net/bridge/br.c
2134 --- linux-mips-cvs/net/bridge/br.c 2004-08-14 20:39:04.000000000 +0200
2135 +++ linux-ebtables/net/bridge/br.c 2005-02-07 05:52:50.000000000 +0100
2137 #include "../atm/lec.h"
2140 +int (*br_should_route_hook) (struct sk_buff **pskb) = NULL;
2142 void br_dec_use_count()
2147 printk(KERN_INFO "NET4: Ethernet Bridge 008 for NET4.0\n");
2149 +#ifdef CONFIG_NETFILTER
2150 + if (br_netfilter_init())
2153 br_handle_frame_hook = br_handle_frame;
2154 br_ioctl_hook = br_ioctl_deviceless_stub;
2155 #if defined(CONFIG_ATM_LANE) || defined(CONFIG_ATM_LANE_MODULE)
2158 static void __exit br_deinit(void)
2160 +#ifdef CONFIG_NETFILTER
2161 + br_netfilter_fini();
2163 unregister_netdevice_notifier(&br_device_notifier);
2171 +EXPORT_SYMBOL(br_should_route_hook);
2173 module_init(br_init)
2174 module_exit(br_deinit)
2175 diff -Nur linux-mips-cvs/net/bridge/br_forward.c linux-ebtables/net/bridge/br_forward.c
2176 --- linux-mips-cvs/net/bridge/br_forward.c 2003-11-17 02:07:47.000000000 +0100
2177 +++ linux-ebtables/net/bridge/br_forward.c 2005-02-07 05:52:50.000000000 +0100
2182 -static int __dev_queue_push_xmit(struct sk_buff *skb)
2183 +int br_dev_queue_push_xmit(struct sk_buff *skb)
2185 +#ifdef CONFIG_NETFILTER
2186 + nf_bridge_maybe_copy_header(skb);
2188 skb_push(skb, ETH_HLEN);
2189 dev_queue_xmit(skb);
2194 -static int __br_forward_finish(struct sk_buff *skb)
2195 +int br_forward_finish(struct sk_buff *skb)
2197 NF_HOOK(PF_BRIDGE, NF_BR_POST_ROUTING, skb, NULL, skb->dev,
2198 - __dev_queue_push_xmit);
2199 + br_dev_queue_push_xmit);
2204 static void __br_deliver(struct net_bridge_port *to, struct sk_buff *skb)
2207 +#ifdef CONFIG_NETFILTER_DEBUG
2208 + skb->nf_debug = 0;
2210 NF_HOOK(PF_BRIDGE, NF_BR_LOCAL_OUT, skb, NULL, skb->dev,
2211 - __br_forward_finish);
2212 + br_forward_finish);
2215 static void __br_forward(struct net_bridge_port *to, struct sk_buff *skb)
2217 skb->ip_summed = CHECKSUM_NONE;
2219 NF_HOOK(PF_BRIDGE, NF_BR_FORWARD, skb, indev, skb->dev,
2220 - __br_forward_finish);
2221 + br_forward_finish);
2224 /* called under bridge lock */
2225 diff -Nur linux-mips-cvs/net/bridge/br_input.c linux-ebtables/net/bridge/br_input.c
2226 --- linux-mips-cvs/net/bridge/br_input.c 2003-08-13 19:19:30.000000000 +0200
2227 +++ linux-ebtables/net/bridge/br_input.c 2005-02-07 05:52:50.000000000 +0100
2230 static int br_pass_frame_up_finish(struct sk_buff *skb)
2232 +#ifdef CONFIG_NETFILTER_DEBUG
2233 + skb->nf_debug = 0;
2239 br_pass_frame_up_finish);
2242 -static int br_handle_frame_finish(struct sk_buff *skb)
2243 +int br_handle_frame_finish(struct sk_buff *skb)
2245 struct net_bridge *br;
2246 unsigned char *dest;
2251 -void br_handle_frame(struct sk_buff *skb)
2252 +int br_handle_frame(struct sk_buff *skb)
2254 struct net_bridge *br;
2255 unsigned char *dest;
2256 @@ -146,26 +149,35 @@
2257 goto handle_special_frame;
2259 if (p->state == BR_STATE_FORWARDING) {
2260 + if (br_should_route_hook && br_should_route_hook(&skb)) {
2261 + read_unlock(&br->lock);
2265 + if (!memcmp(p->br->dev.dev_addr, dest, ETH_ALEN))
2266 + skb->pkt_type = PACKET_HOST;
2268 NF_HOOK(PF_BRIDGE, NF_BR_PRE_ROUTING, skb, skb->dev, NULL,
2269 br_handle_frame_finish);
2270 read_unlock(&br->lock);
2276 read_unlock(&br->lock);
2282 handle_special_frame:
2284 NF_HOOK(PF_BRIDGE, NF_BR_LOCAL_IN, skb, skb->dev,NULL,
2285 br_stp_handle_bpdu);
2286 read_unlock(&br->lock);
2291 read_unlock(&br->lock);
2295 diff -Nur linux-mips-cvs/net/bridge/br_netfilter.c linux-ebtables/net/bridge/br_netfilter.c
2296 --- linux-mips-cvs/net/bridge/br_netfilter.c 1970-01-01 01:00:00.000000000 +0100
2297 +++ linux-ebtables/net/bridge/br_netfilter.c 2005-02-07 05:52:50.000000000 +0100
2300 + * Handle firewalling
2301 + * Linux ethernet bridge
2304 + * Lennert Buytenhek <buytenh@gnu.org>
2305 + * Bart De Schuymer (maintainer) <bdschuym@pandora.be>
2308 + * Apr 29 2003: physdev module support (bdschuym)
2309 + * Jun 19 2003: let arptables see bridged ARP traffic (bdschuym)
2310 + * Oct 06 2003: filter encapsulated IP/ARP VLAN traffic on untagged bridge
2312 + * Aug 28 2004: add IPv6 filtering (bdschuym)
2314 + * This program is free software; you can redistribute it and/or
2315 + * modify it under the terms of the GNU General Public License
2316 + * as published by the Free Software Foundation; either version
2317 + * 2 of the License, or (at your option) any later version.
2319 + * Lennert dedicates this file to Kerstin Wurdinger.
2322 +#include <linux/module.h>
2323 +#include <linux/kernel.h>
2324 +#include <linux/ip.h>
2325 +#include <linux/netdevice.h>
2326 +#include <linux/skbuff.h>
2327 +#include <linux/if_ether.h>
2328 +#include <linux/if_vlan.h>
2329 +#include <linux/netfilter_bridge.h>
2330 +#include <linux/netfilter_ipv4.h>
2331 +#include <linux/netfilter_ipv6.h>
2332 +#include <linux/in_route.h>
2333 +#include <net/ip.h>
2334 +#include <net/ipv6.h>
2335 +#include <asm/uaccess.h>
2336 +#include <asm/checksum.h>
2337 +#include "br_private.h"
2338 +#ifdef CONFIG_SYSCTL
2339 +#include <linux/sysctl.h>
2342 +#define skb_origaddr(skb) (((struct bridge_skb_cb *) \
2343 + (skb->nf_bridge->data))->daddr.ipv4)
2344 +#define store_orig_dstaddr(skb) (skb_origaddr(skb) = (skb)->nh.iph->daddr)
2345 +#define dnat_took_place(skb) (skb_origaddr(skb) != (skb)->nh.iph->daddr)
2347 +#define has_bridge_parent(device) ((device)->br_port != NULL)
2348 +#define bridge_parent(device) (&((device)->br_port->br->dev))
2350 +#ifdef CONFIG_SYSCTL
2351 +static struct ctl_table_header *brnf_sysctl_header;
2352 +static int brnf_call_iptables = 1;
2353 +static int brnf_call_ip6tables = 1;
2354 +static int brnf_call_arptables = 1;
2355 +static int brnf_filter_vlan_tagged = 1;
2357 +#define brnf_filter_vlan_tagged 1
2360 +#define IS_VLAN_IP (skb->protocol == __constant_htons(ETH_P_8021Q) && \
2361 + hdr->h_vlan_encapsulated_proto == __constant_htons(ETH_P_IP) && \
2362 + brnf_filter_vlan_tagged)
2363 +#define IS_VLAN_IPV6 (skb->protocol == __constant_htons(ETH_P_8021Q) && \
2364 + hdr->h_vlan_encapsulated_proto == __constant_htons(ETH_P_IPV6) && \
2365 + brnf_filter_vlan_tagged)
2367 +#define IS_VLAN_ARP (skb->protocol == __constant_htons(ETH_P_8021Q) && \
2368 + hdr->h_vlan_encapsulated_proto == __constant_htons(ETH_P_ARP) && \
2369 + brnf_filter_vlan_tagged)
2372 +/* We need these fake structures to make netfilter happy --
2373 + * lots of places assume that skb->dst != NULL, which isn't
2374 + * all that unreasonable.
2376 + * Currently, we fill in the PMTU entry because netfilter
2377 + * refragmentation needs it, and the rt_flags entry because
2378 + * ipt_REJECT needs it. Future netfilter modules might
2379 + * require us to fill additional fields.
2381 +static struct net_device __fake_net_device = {
2382 + .hard_header_len = ETH_HLEN
2385 +static struct rtable __fake_rtable = {
2388 + __refcnt: ATOMIC_INIT(1),
2389 + dev: &__fake_net_device,
2398 +/* PF_BRIDGE/PRE_ROUTING *********************************************/
2399 +/* Undo the changes made for ip6tables PREROUTING and continue the
2400 + * bridge PRE_ROUTING hook. */
2401 +static int br_nf_pre_routing_finish_ipv6(struct sk_buff *skb)
2403 + struct nf_bridge_info *nf_bridge = skb->nf_bridge;
2405 +#ifdef CONFIG_NETFILTER_DEBUG
2406 + skb->nf_debug ^= (1 << NF_BR_PRE_ROUTING);
2409 + if (nf_bridge->mask & BRNF_PKT_TYPE) {
2410 + skb->pkt_type = PACKET_OTHERHOST;
2411 + nf_bridge->mask ^= BRNF_PKT_TYPE;
2413 + nf_bridge->mask ^= BRNF_NF_BRIDGE_PREROUTING;
2415 + skb->dst = (struct dst_entry *)&__fake_rtable;
2416 + dst_hold(skb->dst);
2418 + skb->dev = nf_bridge->physindev;
2419 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
2420 + skb_push(skb, VLAN_HLEN);
2421 + skb->nh.raw -= VLAN_HLEN;
2423 + NF_HOOK_THRESH(PF_BRIDGE, NF_BR_PRE_ROUTING, skb, skb->dev, NULL,
2424 + br_handle_frame_finish, 1);
2429 +static void __br_dnat_complain(void)
2431 + static unsigned long last_complaint;
2433 + if (jiffies - last_complaint >= 5 * HZ) {
2434 + printk(KERN_WARNING "Performing cross-bridge DNAT requires IP "
2435 + "forwarding to be enabled\n");
2436 + last_complaint = jiffies;
2441 +/* This requires some explaining. If DNAT has taken place,
2442 + * we will need to fix up the destination Ethernet address,
2443 + * and this is a tricky process.
2445 + * There are two cases to consider:
2446 + * 1. The packet was DNAT'ed to a device in the same bridge
2447 + * port group as it was received on. We can still bridge
2449 + * 2. The packet was DNAT'ed to a different device, either
2450 + * a non-bridged device or another bridge port group.
2451 + * The packet will need to be routed.
2453 + * The correct way of distinguishing between these two cases is to
2454 + * call ip_route_input() and to look at skb->dst->dev, which is
2455 + * changed to the destination device if ip_route_input() succeeds.
2457 + * Let us first consider the case that ip_route_input() succeeds:
2459 + * If skb->dst->dev equals the logical bridge device the packet
2460 + * came in on, we can consider this bridging. We then call
2461 + * skb->dst->output() which will make the packet enter br_nf_local_out()
2462 + * not much later. In that function it is assured that the iptables
2463 + * FORWARD chain is traversed for the packet.
2465 + * Otherwise, the packet is considered to be routed and we just
2466 + * change the destination MAC address so that the packet will
2467 + * later be passed up to the IP stack to be routed.
2469 + * Let us now consider the case that ip_route_input() fails:
2471 + * After a "echo '0' > /proc/sys/net/ipv4/ip_forward" ip_route_input()
2472 + * will fail, while __ip_route_output_key() will return success. The source
2473 + * address for __ip_route_output_key() is set to zero, so __ip_route_output_key
2474 + * thinks we're handling a locally generated packet and won't care
2475 + * if IP forwarding is allowed. We send a warning message to the users's
2476 + * log telling her to put IP forwarding on.
2478 + * ip_route_input() will also fail if there is no route available.
2479 + * In that case we just drop the packet.
2481 + * --Lennert, 20020411
2482 + * --Bart, 20020416 (updated)
2483 + * --Bart, 20021007 (updated)
2486 +static int br_nf_pre_routing_finish_bridge(struct sk_buff *skb)
2488 +#ifdef CONFIG_NETFILTER_DEBUG
2489 + skb->nf_debug |= (1 << NF_BR_PRE_ROUTING) | (1 << NF_BR_FORWARD);
2492 + if (skb->pkt_type == PACKET_OTHERHOST) {
2493 + skb->pkt_type = PACKET_HOST;
2494 + skb->nf_bridge->mask |= BRNF_PKT_TYPE;
2496 + skb->nf_bridge->mask ^= BRNF_NF_BRIDGE_PREROUTING;
2498 + skb->dev = bridge_parent(skb->dev);
2499 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
2500 + skb_pull(skb, VLAN_HLEN);
2501 + skb->nh.raw += VLAN_HLEN;
2503 + skb->dst->output(skb);
2507 +static int br_nf_pre_routing_finish(struct sk_buff *skb)
2509 + struct net_device *dev = skb->dev;
2510 + struct iphdr *iph = skb->nh.iph;
2511 + struct nf_bridge_info *nf_bridge = skb->nf_bridge;
2513 +#ifdef CONFIG_NETFILTER_DEBUG
2514 + skb->nf_debug ^= (1 << NF_BR_PRE_ROUTING);
2517 + if (nf_bridge->mask & BRNF_PKT_TYPE) {
2518 + skb->pkt_type = PACKET_OTHERHOST;
2519 + nf_bridge->mask ^= BRNF_PKT_TYPE;
2521 + nf_bridge->mask ^= BRNF_NF_BRIDGE_PREROUTING;
2523 + if (dnat_took_place(skb)) {
2524 + if (ip_route_input(skb, iph->daddr, iph->saddr, iph->tos,
2526 + struct rtable *rt;
2528 + if (!ip_route_output(&rt, iph->daddr, 0, iph->tos, 0)) {
2529 + /* Bridged-and-DNAT'ed traffic doesn't
2530 + * require ip_forwarding.
2532 + if (((struct dst_entry *)rt)->dev == dev) {
2533 + skb->dst = (struct dst_entry *)rt;
2534 + goto bridged_dnat;
2536 + __br_dnat_complain();
2537 + dst_release((struct dst_entry *)rt);
2542 + if (skb->dst->dev == dev) {
2544 + /* Tell br_nf_local_out this is a
2547 + nf_bridge->mask |= BRNF_BRIDGED_DNAT;
2548 + skb->dev = nf_bridge->physindev;
2549 + if (skb->protocol ==
2550 + __constant_htons(ETH_P_8021Q)) {
2551 + skb_push(skb, VLAN_HLEN);
2552 + skb->nh.raw -= VLAN_HLEN;
2554 + NF_HOOK_THRESH(PF_BRIDGE, NF_BR_PRE_ROUTING,
2555 + skb, skb->dev, NULL,
2556 + br_nf_pre_routing_finish_bridge,
2560 + memcpy(skb->mac.ethernet->h_dest, dev->dev_addr,
2562 + skb->pkt_type = PACKET_HOST;
2565 + skb->dst = (struct dst_entry *)&__fake_rtable;
2566 + dst_hold(skb->dst);
2569 + skb->dev = nf_bridge->physindev;
2570 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
2571 + skb_push(skb, VLAN_HLEN);
2572 + skb->nh.raw -= VLAN_HLEN;
2574 + NF_HOOK_THRESH(PF_BRIDGE, NF_BR_PRE_ROUTING, skb, skb->dev, NULL,
2575 + br_handle_frame_finish, 1);
2580 +/* Some common code for IPv4/IPv6 */
2581 +static void setup_pre_routing(struct sk_buff *skb)
2583 + struct nf_bridge_info *nf_bridge = skb->nf_bridge;
2585 + if (skb->pkt_type == PACKET_OTHERHOST) {
2586 + skb->pkt_type = PACKET_HOST;
2587 + nf_bridge->mask |= BRNF_PKT_TYPE;
2590 + nf_bridge->mask |= BRNF_NF_BRIDGE_PREROUTING;
2591 + nf_bridge->physindev = skb->dev;
2592 + skb->dev = bridge_parent(skb->dev);
2595 +/* We only check the length. A bridge shouldn't do any hop-by-hop stuff anyway */
2596 +static int check_hbh_len(struct sk_buff *skb)
2598 + unsigned char *raw = (u8*)(skb->nh.ipv6h+1);
2600 + int off = raw - skb->nh.raw;
2601 + int len = (raw[1]+1)<<3;
2603 + if ((raw + len) - skb->data > skb_headlen(skb))
2610 + int optlen = raw[off+1]+2;
2612 + switch (skb->nh.raw[off]) {
2613 + case IPV6_TLV_PAD0:
2617 + case IPV6_TLV_PADN:
2620 + case IPV6_TLV_JUMBO:
2621 + if (skb->nh.raw[off+1] != 4 || (off&3) != 2)
2624 + pkt_len = ntohl(*(u32*)(skb->nh.raw+off+2));
2626 + if (pkt_len > skb->len - sizeof(struct ipv6hdr))
2628 + if (pkt_len + sizeof(struct ipv6hdr) < skb->len) {
2629 + if (__pskb_trim(skb,
2630 + pkt_len + sizeof(struct ipv6hdr)))
2632 + if (skb->ip_summed == CHECKSUM_HW)
2633 + skb->ip_summed = CHECKSUM_NONE;
2651 +/* Replicate the checks that IPv6 does on packet reception and pass the packet
2652 + * to ip6tables, which doesn't support NAT, so things are fairly simple. */
2653 +static unsigned int br_nf_pre_routing_ipv6(unsigned int hook,
2654 + struct sk_buff *skb, const struct net_device *in,
2655 + const struct net_device *out, int (*okfn)(struct sk_buff *))
2657 + struct ipv6hdr *hdr;
2659 + struct nf_bridge_info *nf_bridge;
2661 + if (skb->len < sizeof(struct ipv6hdr))
2664 + if (!pskb_may_pull(skb, sizeof(struct ipv6hdr)))
2667 + hdr = skb->nh.ipv6h;
2669 + if (hdr->version != 6)
2672 + pkt_len = ntohs(hdr->payload_len);
2674 + if (pkt_len || hdr->nexthdr != NEXTHDR_HOP) {
2675 + if (pkt_len + sizeof(struct ipv6hdr) > skb->len)
2677 + if (pkt_len + sizeof(struct ipv6hdr) < skb->len) {
2678 + if (__pskb_trim(skb, pkt_len + sizeof(struct ipv6hdr)))
2680 + if (skb->ip_summed == CHECKSUM_HW)
2681 + skb->ip_summed = CHECKSUM_NONE;
2684 + if (hdr->nexthdr == NEXTHDR_HOP && check_hbh_len(skb))
2687 +#ifdef CONFIG_NETFILTER_DEBUG
2688 + skb->nf_debug ^= (1 << NF_IP6_PRE_ROUTING);
2690 + if ((nf_bridge = nf_bridge_alloc(skb)) == NULL)
2692 + setup_pre_routing(skb);
2694 + NF_HOOK(PF_INET6, NF_IP6_PRE_ROUTING, skb, skb->dev, NULL,
2695 + br_nf_pre_routing_finish_ipv6);
2703 +/* Direct IPv6 traffic to br_nf_pre_routing_ipv6.
2704 + * Replicate the checks that IPv4 does on packet reception.
2705 + * Set skb->dev to the bridge device (i.e. parent of the
2706 + * receiving device) to make netfilter happy, the REDIRECT
2707 + * target in particular. Save the original destination IP
2708 + * address to be able to detect DNAT afterwards.
2710 +static unsigned int br_nf_pre_routing(unsigned int hook, struct sk_buff **pskb,
2711 + const struct net_device *in, const struct net_device *out,
2712 + int (*okfn)(struct sk_buff *))
2714 + struct iphdr *iph;
2716 + struct sk_buff *skb = *pskb;
2717 + struct nf_bridge_info *nf_bridge;
2718 + struct vlan_ethhdr *hdr = (struct vlan_ethhdr *)
2719 + ((*pskb)->mac.ethernet);
2721 + if (skb->protocol == __constant_htons(ETH_P_IPV6) || IS_VLAN_IPV6) {
2722 +#ifdef CONFIG_SYSCTL
2723 + if (!brnf_call_ip6tables)
2726 + if ((skb = skb_share_check(*pskb, GFP_ATOMIC)) == NULL)
2729 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
2730 + skb_pull(skb, VLAN_HLEN);
2731 + (skb)->nh.raw += VLAN_HLEN;
2733 + return br_nf_pre_routing_ipv6(hook, skb, in, out, okfn);
2736 +#ifdef CONFIG_SYSCTL
2737 + if (!brnf_call_iptables)
2741 + if (skb->protocol != __constant_htons(ETH_P_IP) && !IS_VLAN_IP)
2743 + if ((skb = skb_share_check(*pskb, GFP_ATOMIC)) == NULL)
2746 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
2747 + skb_pull(skb, VLAN_HLEN);
2748 + (skb)->nh.raw += VLAN_HLEN;
2751 + if (!pskb_may_pull(skb, sizeof(struct iphdr)))
2754 + iph = skb->nh.iph;
2755 + if (iph->ihl < 5 || iph->version != 4)
2758 + if (!pskb_may_pull(skb, 4*iph->ihl))
2761 + iph = skb->nh.iph;
2762 + if (ip_fast_csum((__u8 *)iph, iph->ihl) != 0)
2765 + len = ntohs(iph->tot_len);
2766 + if (skb->len < len || len < 4*iph->ihl)
2769 + if (skb->len > len) {
2770 + __pskb_trim(skb, len);
2771 + if (skb->ip_summed == CHECKSUM_HW)
2772 + skb->ip_summed = CHECKSUM_NONE;
2775 +#ifdef CONFIG_NETFILTER_DEBUG
2776 + skb->nf_debug ^= (1 << NF_IP_PRE_ROUTING);
2778 + if ((nf_bridge = nf_bridge_alloc(skb)) == NULL)
2781 + setup_pre_routing(skb);
2782 + store_orig_dstaddr(skb);
2784 + NF_HOOK(PF_INET, NF_IP_PRE_ROUTING, skb, skb->dev, NULL,
2785 + br_nf_pre_routing_finish);
2790 +// IP_INC_STATS_BH(IpInHdrErrors);
2796 +/* PF_BRIDGE/LOCAL_IN ************************************************/
2797 +/* The packet is locally destined, which requires a real
2798 + * dst_entry, so detach the fake one. On the way up, the
2799 + * packet would pass through PRE_ROUTING again (which already
2800 + * took place when the packet entered the bridge), but we
2801 + * register an IPv4 PRE_ROUTING 'sabotage' hook that will
2802 + * prevent this from happening.
2804 +static unsigned int br_nf_local_in(unsigned int hook, struct sk_buff **pskb,
2805 + const struct net_device *in, const struct net_device *out,
2806 + int (*okfn)(struct sk_buff *))
2808 + struct sk_buff *skb = *pskb;
2810 + if (skb->dst == (struct dst_entry *)&__fake_rtable) {
2811 + dst_release(skb->dst);
2818 +/* PF_BRIDGE/FORWARD *************************************************/
2819 +static int br_nf_forward_finish(struct sk_buff *skb)
2821 + struct nf_bridge_info *nf_bridge = skb->nf_bridge;
2822 + struct net_device *in;
2823 +/* struct vlan_ethhdr *hdr = (struct vlan_ethhdr *)(skb->mac.ethernet);*/
2825 +#ifdef CONFIG_NETFILTER_DEBUG
2826 + skb->nf_debug ^= (1 << NF_BR_FORWARD);
2829 +/* if (skb->protocol != __constant_htons(ETH_P_ARP) && !IS_VLAN_ARP) {*/
2830 + in = nf_bridge->physindev;
2831 + if (nf_bridge->mask & BRNF_PKT_TYPE) {
2832 + skb->pkt_type = PACKET_OTHERHOST;
2833 + nf_bridge->mask ^= BRNF_PKT_TYPE;
2836 + in = *((struct net_device **)(skb->cb));
2838 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
2839 + skb_push(skb, VLAN_HLEN);
2840 + skb->nh.raw -= VLAN_HLEN;
2842 + NF_HOOK_THRESH(PF_BRIDGE, NF_BR_FORWARD, skb, in,
2843 + skb->dev, br_forward_finish, 1);
2847 +/* This is the 'purely bridged' case. For IP, we pass the packet to
2848 + * netfilter with indev and outdev set to the bridge device,
2849 + * but we are still able to filter on the 'real' indev/outdev
2850 + * because of the ipt_physdev.c module. For ARP, indev and outdev are the
2853 +static unsigned int br_nf_forward_ip(unsigned int hook, struct sk_buff **pskb,
2854 + const struct net_device *in, const struct net_device *out,
2855 + int (*okfn)(struct sk_buff *))
2857 + struct sk_buff *skb = *pskb;
2858 + struct nf_bridge_info *nf_bridge;
2859 + struct vlan_ethhdr *hdr = (struct vlan_ethhdr *)(skb->mac.ethernet);
2862 + if (!skb->nf_bridge)
2865 + if (skb->protocol == __constant_htons(ETH_P_IP) || IS_VLAN_IP)
2870 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
2871 + skb_pull(*pskb, VLAN_HLEN);
2872 + (*pskb)->nh.raw += VLAN_HLEN;
2875 +#ifdef CONFIG_NETFILTER_DEBUG
2876 + skb->nf_debug ^= (1 << NF_BR_FORWARD);
2878 + nf_bridge = skb->nf_bridge;
2879 + if (skb->pkt_type == PACKET_OTHERHOST) {
2880 + skb->pkt_type = PACKET_HOST;
2881 + nf_bridge->mask |= BRNF_PKT_TYPE;
2884 + /* The physdev module checks on this */
2885 + nf_bridge->mask |= BRNF_BRIDGED;
2886 + nf_bridge->physoutdev = skb->dev;
2888 + NF_HOOK(pf, NF_IP_FORWARD, skb, bridge_parent(in),
2889 + bridge_parent(out), br_nf_forward_finish);
2895 +static unsigned int br_nf_forward_arp(unsigned int hook, struct sk_buff **pskb,
2896 + const struct net_device *in, const struct net_device *out,
2897 + int (*okfn)(struct sk_buff *))
2899 + struct sk_buff *skb = *pskb;
2900 + struct vlan_ethhdr *hdr = (struct vlan_ethhdr *)(skb->mac.ethernet);
2901 + struct net_device **d = (struct net_device **)(skb->cb);
2903 + if (!brnf_call_arptables)
2906 + if (skb->protocol != __constant_htons(ETH_P_ARP)) {
2909 + skb_pull(*pskb, VLAN_HLEN);
2910 + (*pskb)->nh.raw += VLAN_HLEN;
2913 +#ifdef CONFIG_NETFILTER_DEBUG
2914 + skb->nf_debug ^= (1 << NF_BR_FORWARD);
2917 + if (skb->nh.arph->ar_pln != 4) {
2918 + if (IS_VLAN_ARP) {
2919 + skb_push(*pskb, VLAN_HLEN);
2920 + (*pskb)->nh.raw -= VLAN_HLEN;
2924 + *d = (struct net_device *)in;
2925 + NF_HOOK(NF_ARP, NF_ARP_FORWARD, skb, (struct net_device *)in,
2926 + (struct net_device *)out, br_nf_forward_finish);
2932 +/* PF_BRIDGE/LOCAL_OUT ***********************************************/
2933 +static int br_nf_local_out_finish(struct sk_buff *skb)
2935 +#ifdef CONFIG_NETFILTER_DEBUG
2936 + skb->nf_debug &= ~(1 << NF_BR_LOCAL_OUT);
2938 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
2939 + skb_push(skb, VLAN_HLEN);
2940 + skb->nh.raw -= VLAN_HLEN;
2943 + NF_HOOK_THRESH(PF_BRIDGE, NF_BR_LOCAL_OUT, skb, NULL, skb->dev,
2944 + br_forward_finish, NF_BR_PRI_FIRST + 1);
2950 +/* This function sees both locally originated IP packets and forwarded
2951 + * IP packets (in both cases the destination device is a bridge
2952 + * device). It also sees bridged-and-DNAT'ed packets.
2953 + * To be able to filter on the physical bridge devices (with the ipt_physdev.c
2954 + * module), we steal packets destined to a bridge device away from the
2955 + * PF_INET/FORWARD and PF_INET/OUTPUT hook functions, and give them back later,
2956 + * when we have determined the real output device. This is done in here.
2958 + * If (nf_bridge->mask & BRNF_BRIDGED_DNAT) then the packet is bridged
2959 + * and we fake the PF_BRIDGE/FORWARD hook. The function br_nf_forward()
2960 + * will then fake the PF_INET/FORWARD hook. br_nf_local_out() has priority
2961 + * NF_BR_PRI_FIRST, so no relevant PF_BRIDGE/INPUT functions have been nor
2962 + * will be executed.
2963 + * Otherwise, if nf_bridge->physindev is NULL, the bridge-nf code never touched
2964 + * this packet before, and so the packet was locally originated. We fake
2965 + * the PF_INET/LOCAL_OUT hook.
2966 + * Finally, if nf_bridge->physindev isn't NULL, then the packet was IP routed,
2967 + * so we fake the PF_INET/FORWARD hook. ipv4_sabotage_out() makes sure
2968 + * even routed packets that didn't arrive on a bridge interface have their
2969 + * nf_bridge->physindev set.
2972 +static unsigned int br_nf_local_out(unsigned int hook, struct sk_buff **pskb,
2973 + const struct net_device *in, const struct net_device *out,
2974 + int (*okfn)(struct sk_buff *))
2976 + struct net_device *realindev, *realoutdev;
2977 + struct sk_buff *skb = *pskb;
2978 + struct nf_bridge_info *nf_bridge;
2979 + struct vlan_ethhdr *hdr = (struct vlan_ethhdr *)(skb->mac.ethernet);
2982 + if (!skb->nf_bridge)
2985 + if (skb->protocol == __constant_htons(ETH_P_IP) || IS_VLAN_IP)
2990 +#ifdef CONFIG_NETFILTER_DEBUG
2991 + /* Sometimes we get packets with NULL ->dst here (for example,
2992 + * running a dhcp client daemon triggers this). This should now
2993 + * be fixed, but let's keep the check around. */
2994 + if (skb->dst == NULL) {
2995 + printk(KERN_CRIT "br_netfilter: skb->dst == NULL.");
3000 + nf_bridge = skb->nf_bridge;
3001 + nf_bridge->physoutdev = skb->dev;
3002 + realindev = nf_bridge->physindev;
3004 + /* Bridged, take PF_BRIDGE/FORWARD.
3005 + * (see big note in front of br_nf_pre_routing_finish)
3007 + if (nf_bridge->mask & BRNF_BRIDGED_DNAT) {
3008 + if (nf_bridge->mask & BRNF_PKT_TYPE) {
3009 + skb->pkt_type = PACKET_OTHERHOST;
3010 + nf_bridge->mask ^= BRNF_PKT_TYPE;
3012 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
3013 + skb_push(skb, VLAN_HLEN);
3014 + skb->nh.raw -= VLAN_HLEN;
3017 + NF_HOOK(PF_BRIDGE, NF_BR_FORWARD, skb, realindev,
3018 + skb->dev, br_forward_finish);
3021 + realoutdev = bridge_parent(skb->dev);
3023 +#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
3024 + /* iptables should match -o br0.x */
3025 + if (nf_bridge->netoutdev)
3026 + realoutdev = nf_bridge->netoutdev;
3028 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
3029 + skb_pull(skb, VLAN_HLEN);
3030 + (*pskb)->nh.raw += VLAN_HLEN;
3032 + /* IP forwarded traffic has a physindev, locally
3033 + * generated traffic hasn't.
3035 + if (realindev != NULL) {
3036 + if (((nf_bridge->mask & BRNF_DONT_TAKE_PARENT) == 0) &&
3037 + has_bridge_parent(realindev))
3038 + realindev = bridge_parent(realindev);
3039 + NF_HOOK_THRESH(pf, NF_IP_FORWARD, skb, realindev,
3041 + NF_IP_PRI_BRIDGE_SABOTAGE_FORWARD + 1);
3043 +#ifdef CONFIG_NETFILTER_DEBUG
3044 + skb->nf_debug ^= (1 << NF_IP_LOCAL_OUT);
3047 + NF_HOOK_THRESH(pf, NF_IP_LOCAL_OUT, skb, realindev,
3049 + NF_IP_PRI_BRIDGE_SABOTAGE_LOCAL_OUT + 1);
3057 +/* PF_BRIDGE/POST_ROUTING ********************************************/
3058 +static unsigned int br_nf_post_routing(unsigned int hook, struct sk_buff **pskb,
3059 + const struct net_device *in, const struct net_device *out,
3060 + int (*okfn)(struct sk_buff *))
3062 + struct sk_buff *skb = *pskb;
3063 + struct nf_bridge_info *nf_bridge = (*pskb)->nf_bridge;
3064 + struct vlan_ethhdr *hdr = (struct vlan_ethhdr *)(skb->mac.ethernet);
3065 + struct net_device *realoutdev = bridge_parent(skb->dev);
3068 +#ifdef CONFIG_NETFILTER_DEBUG
3069 + /* Be very paranoid. This probably won't happen anymore, but let's
3070 + * keep the check just to be sure... */
3071 + if (skb->mac.raw < skb->head || skb->mac.raw + ETH_HLEN > skb->data) {
3072 + printk(KERN_CRIT "br_netfilter: Argh!! br_nf_post_routing: "
3073 + "bad mac.raw pointer.");
3081 + if (skb->protocol == __constant_htons(ETH_P_IP) || IS_VLAN_IP)
3086 + /* Sometimes we get packets with NULL ->dst here (for example,
3087 + * running a dhcp client daemon triggers this).
3089 + if (skb->dst == NULL)
3092 +#ifdef CONFIG_NETFILTER_DEBUG
3093 + /* Sometimes we get packets with NULL ->dst here (for example,
3094 + * running a dhcp client daemon triggers this). This should now
3095 + * be fixed, but let's keep the check around.
3097 + if (skb->dst == NULL) {
3098 + printk(KERN_CRIT "br_netfilter: skb->dst == NULL.");
3102 + skb->nf_debug ^= (1 << NF_IP_POST_ROUTING);
3105 + /* We assume any code from br_dev_queue_push_xmit onwards doesn't care
3106 + * about the value of skb->pkt_type.
3108 + if (skb->pkt_type == PACKET_OTHERHOST) {
3109 + skb->pkt_type = PACKET_HOST;
3110 + nf_bridge->mask |= BRNF_PKT_TYPE;
3113 + if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
3114 + skb_pull(skb, VLAN_HLEN);
3115 + skb->nh.raw += VLAN_HLEN;
3118 + nf_bridge_save_header(skb);
3120 +#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
3121 + if (nf_bridge->netoutdev)
3122 + realoutdev = nf_bridge->netoutdev;
3124 + NF_HOOK(pf, NF_IP_POST_ROUTING, skb, NULL,
3125 + realoutdev, br_dev_queue_push_xmit);
3129 +#ifdef CONFIG_NETFILTER_DEBUG
3131 + if (skb->dev != NULL) {
3132 + printk("[%s]", skb->dev->name);
3133 + if (has_bridge_parent(skb->dev))
3134 + printk("[%s]", bridge_parent(skb->dev)->name);
3136 + printk(" head:%p, raw:%p, data:%p\n", skb->head, skb->mac.raw,
3143 +/* IPv4/SABOTAGE *****************************************************/
3145 +/* Don't hand locally destined packets to PF_INET/PRE_ROUTING
3146 + * for the second time.
3148 +static unsigned int ip_sabotage_in(unsigned int hook, struct sk_buff **pskb,
3149 + const struct net_device *in, const struct net_device *out,
3150 + int (*okfn)(struct sk_buff *))
3152 + if ((*pskb)->nf_bridge &&
3153 + !((*pskb)->nf_bridge->mask & BRNF_NF_BRIDGE_PREROUTING)) {
3161 +/* Postpone execution of PF_INET/FORWARD, PF_INET/LOCAL_OUT
3162 + * and PF_INET/POST_ROUTING until we have done the forwarding
3163 + * decision in the bridge code and have determined skb->physoutdev.
3165 +static unsigned int ip_sabotage_out(unsigned int hook, struct sk_buff **pskb,
3166 + const struct net_device *in, const struct net_device *out,
3167 + int (*okfn)(struct sk_buff *))
3169 + struct sk_buff *skb = *pskb;
3171 + if ((out->hard_start_xmit == br_dev_xmit &&
3172 + okfn != br_nf_forward_finish &&
3173 + okfn != br_nf_local_out_finish &&
3174 + okfn != br_dev_queue_push_xmit)
3175 +#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
3176 + || ((out->priv_flags & IFF_802_1Q_VLAN) &&
3177 + VLAN_DEV_INFO(out)->real_dev->hard_start_xmit == br_dev_xmit)
3180 + struct nf_bridge_info *nf_bridge;
3182 + if (!skb->nf_bridge) {
3183 +#ifdef CONFIG_SYSCTL
3184 + /* This code is executed while in the IP(v6) stack,
3185 + the version should be 4 or 6. We can't use
3186 + skb->protocol because that isn't set on
3187 + PF_INET(6)/LOCAL_OUT. */
3188 + struct iphdr *ip = skb->nh.iph;
3190 + if (ip->version == 4 && !brnf_call_iptables)
3192 + else if (ip->version == 6 && !brnf_call_ip6tables)
3195 + if (hook == NF_IP_POST_ROUTING)
3197 + if (!nf_bridge_alloc(skb))
3201 + nf_bridge = skb->nf_bridge;
3203 + /* This frame will arrive on PF_BRIDGE/LOCAL_OUT and we
3204 + * will need the indev then. For a brouter, the real indev
3205 + * can be a bridge port, so we make sure br_nf_local_out()
3206 + * doesn't use the bridge parent of the indev by using
3207 + * the BRNF_DONT_TAKE_PARENT mask.
3209 + if (hook == NF_IP_FORWARD && nf_bridge->physindev == NULL) {
3210 + nf_bridge->mask &= BRNF_DONT_TAKE_PARENT;
3211 + nf_bridge->physindev = (struct net_device *)in;
3213 +#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
3214 + /* the iptables outdev is br0.x, not br0 */
3215 + if (out->priv_flags & IFF_802_1Q_VLAN)
3216 + nf_bridge->netoutdev = (struct net_device *)out;
3225 +/* For br_nf_local_out we need (prio = NF_BR_PRI_FIRST), to insure that innocent
3226 + * PF_BRIDGE/NF_BR_LOCAL_OUT functions don't get bridged traffic as input.
3227 + * For br_nf_post_routing, we need (prio = NF_BR_PRI_LAST), because
3228 + * ip_refrag() can return NF_STOLEN.
3230 +static struct nf_hook_ops br_nf_ops[] = {
3231 + { .hook = br_nf_pre_routing,
3233 + .hooknum = NF_BR_PRE_ROUTING,
3234 + .priority = NF_BR_PRI_BRNF, },
3235 + { .hook = br_nf_local_in,
3237 + .hooknum = NF_BR_LOCAL_IN,
3238 + .priority = NF_BR_PRI_BRNF, },
3239 + { .hook = br_nf_forward_ip,
3241 + .hooknum = NF_BR_FORWARD,
3242 + .priority = NF_BR_PRI_BRNF /*- 1*/, },
3243 +/* { .hook = br_nf_forward_arp,
3245 + .hooknum = NF_BR_FORWARD,
3246 + .priority = NF_BR_PRI_BRNF, },*/
3247 + { .hook = br_nf_local_out,
3249 + .hooknum = NF_BR_LOCAL_OUT,
3250 + .priority = NF_BR_PRI_FIRST, },
3251 + { .hook = br_nf_post_routing,
3253 + .hooknum = NF_BR_POST_ROUTING,
3254 + .priority = NF_BR_PRI_LAST, },
3255 + { .hook = ip_sabotage_in,
3257 + .hooknum = NF_IP_PRE_ROUTING,
3258 + .priority = NF_IP_PRI_FIRST, },
3259 + { .hook = ip_sabotage_in,
3261 + .hooknum = NF_IP6_PRE_ROUTING,
3262 + .priority = NF_IP6_PRI_FIRST, },
3263 + { .hook = ip_sabotage_out,
3265 + .hooknum = NF_IP_FORWARD,
3266 + .priority = NF_IP_PRI_BRIDGE_SABOTAGE_FORWARD, },
3267 + { .hook = ip_sabotage_out,
3269 + .hooknum = NF_IP6_FORWARD,
3270 + .priority = NF_IP6_PRI_BRIDGE_SABOTAGE_FORWARD, },
3271 + { .hook = ip_sabotage_out,
3273 + .hooknum = NF_IP_LOCAL_OUT,
3274 + .priority = NF_IP_PRI_BRIDGE_SABOTAGE_LOCAL_OUT, },
3275 + { .hook = ip_sabotage_out,
3277 + .hooknum = NF_IP6_LOCAL_OUT,
3278 + .priority = NF_IP6_PRI_BRIDGE_SABOTAGE_LOCAL_OUT, },
3279 + { .hook = ip_sabotage_out,
3281 + .hooknum = NF_IP_POST_ROUTING,
3282 + .priority = NF_IP_PRI_FIRST, },
3283 + { .hook = ip_sabotage_out,
3285 + .hooknum = NF_IP6_POST_ROUTING,
3286 + .priority = NF_IP6_PRI_FIRST, },
3289 +#ifdef CONFIG_SYSCTL
3291 +int brnf_sysctl_call_tables(ctl_table *ctl, int write, struct file * filp,
3292 + void *buffer, size_t *lenp)
3296 + ret = proc_dointvec(ctl, write, filp, buffer, lenp);
3298 + if (write && *(int *)(ctl->data))
3299 + *(int *)(ctl->data) = 1;
3303 +static ctl_table brnf_table[] = {
3305 + .ctl_name = NET_BRIDGE_NF_CALL_ARPTABLES,
3306 + .procname = "bridge-nf-call-arptables",
3307 + .data = &brnf_call_arptables,
3308 + .maxlen = sizeof(int),
3310 + .proc_handler = &brnf_sysctl_call_tables,
3313 + .ctl_name = NET_BRIDGE_NF_CALL_IPTABLES,
3314 + .procname = "bridge-nf-call-iptables",
3315 + .data = &brnf_call_iptables,
3316 + .maxlen = sizeof(int),
3318 + .proc_handler = &brnf_sysctl_call_tables,
3321 + .ctl_name = NET_BRIDGE_NF_CALL_IP6TABLES,
3322 + .procname = "bridge-nf-call-ip6tables",
3323 + .data = &brnf_call_ip6tables,
3324 + .maxlen = sizeof(int),
3326 + .proc_handler = &brnf_sysctl_call_tables,
3329 + .ctl_name = NET_BRIDGE_NF_FILTER_VLAN_TAGGED,
3330 + .procname = "bridge-nf-filter-vlan-tagged",
3331 + .data = &brnf_filter_vlan_tagged,
3332 + .maxlen = sizeof(int),
3334 + .proc_handler = &brnf_sysctl_call_tables,
3339 +static ctl_table brnf_bridge_table[] = {
3341 + .ctl_name = NET_BRIDGE,
3342 + .procname = "bridge",
3344 + .child = brnf_table,
3349 +static ctl_table brnf_net_table[] = {
3351 + .ctl_name = CTL_NET,
3352 + .procname = "net",
3354 + .child = brnf_bridge_table,
3360 +int br_netfilter_init(void)
3364 + for (i = 0; i < ARRAY_SIZE(br_nf_ops); i++) {
3367 + if ((ret = nf_register_hook(&br_nf_ops[i])) >= 0)
3371 + nf_unregister_hook(&br_nf_ops[i]);
3376 +#ifdef CONFIG_SYSCTL
3377 + brnf_sysctl_header = register_sysctl_table(brnf_net_table, 0);
3378 + if (brnf_sysctl_header == NULL) {
3379 + printk(KERN_WARNING "br_netfilter: can't register to sysctl.\n");
3380 + for (i = 0; i < ARRAY_SIZE(br_nf_ops); i++)
3381 + nf_unregister_hook(&br_nf_ops[i]);
3386 + printk(KERN_NOTICE "Bridge firewalling registered\n");
3391 +void br_netfilter_fini(void)
3395 + for (i = ARRAY_SIZE(br_nf_ops) - 1; i >= 0; i--)
3396 + nf_unregister_hook(&br_nf_ops[i]);
3397 +#ifdef CONFIG_SYSCTL
3398 + unregister_sysctl_table(brnf_sysctl_header);
3402 diff -Nur linux-mips-cvs/net/bridge/br_private.h linux-ebtables/net/bridge/br_private.h
3403 --- linux-mips-cvs/net/bridge/br_private.h 2004-08-14 20:39:04.000000000 +0200
3404 +++ linux-ebtables/net/bridge/br_private.h 2005-02-07 05:52:50.000000000 +0100
3405 @@ -143,8 +143,10 @@
3407 extern void br_deliver(struct net_bridge_port *to,
3408 struct sk_buff *skb);
3409 +extern int br_dev_queue_push_xmit(struct sk_buff *skb);
3410 extern void br_forward(struct net_bridge_port *to,
3411 struct sk_buff *skb);
3412 +extern int br_forward_finish(struct sk_buff *skb);
3413 extern void br_flood_deliver(struct net_bridge *br,
3414 struct sk_buff *skb,
3420 -extern void br_handle_frame(struct sk_buff *skb);
3421 +extern int br_handle_frame_finish(struct sk_buff *skb);
3422 +extern int br_handle_frame(struct sk_buff *skb);
3425 extern int br_ioctl(struct net_bridge *br,
3426 @@ -175,6 +178,10 @@
3427 unsigned long arg2);
3428 extern int br_ioctl_deviceless_stub(unsigned long arg);
3430 +/* br_netfilter.c */
3431 +extern int br_netfilter_init(void);
3432 +extern void br_netfilter_fini(void);
3435 extern int br_is_root_bridge(struct net_bridge *br);
3436 extern struct net_bridge_port *br_get_port(struct net_bridge *br,
3437 diff -Nur linux-mips-cvs/net/bridge/netfilter/Config.in linux-ebtables/net/bridge/netfilter/Config.in
3438 --- linux-mips-cvs/net/bridge/netfilter/Config.in 1970-01-01 01:00:00.000000000 +0100
3439 +++ linux-ebtables/net/bridge/netfilter/Config.in 2005-02-07 05:52:50.000000000 +0100
3442 +# Bridge netfilter configuration
3444 +dep_tristate ' Bridge: ebtables' CONFIG_BRIDGE_NF_EBTABLES $CONFIG_BRIDGE
3445 +dep_tristate ' ebt: filter table support' CONFIG_BRIDGE_EBT_T_FILTER $CONFIG_BRIDGE_NF_EBTABLES
3446 +dep_tristate ' ebt: nat table support' CONFIG_BRIDGE_EBT_T_NAT $CONFIG_BRIDGE_NF_EBTABLES
3447 +dep_tristate ' ebt: broute table support' CONFIG_BRIDGE_EBT_BROUTE $CONFIG_BRIDGE_NF_EBTABLES
3448 +dep_tristate ' ebt: log support' CONFIG_BRIDGE_EBT_LOG $CONFIG_BRIDGE_NF_EBTABLES
3449 +dep_tristate ' ebt: ulog support' CONFIG_BRIDGE_EBT_LOG $CONFIG_BRIDGE_NF_EBTABLES
3450 +dep_tristate ' ebt: IP filter support' CONFIG_BRIDGE_EBT_IPF $CONFIG_BRIDGE_NF_EBTABLES
3451 +dep_tristate ' ebt: ARP filter support' CONFIG_BRIDGE_EBT_ARPF $CONFIG_BRIDGE_NF_EBTABLES
3452 +dep_tristate ' ebt: among filter support' CONFIG_BRIDGE_EBT_AMONG $CONFIG_BRIDGE_NF_EBTABLES
3453 +dep_tristate ' ebt: limit filter support' CONFIG_BRIDGE_EBT_LIMIT $CONFIG_BRIDGE_NF_EBTABLES
3454 +dep_tristate ' ebt: 802.1Q VLAN filter support' CONFIG_BRIDGE_EBT_VLANF $CONFIG_BRIDGE_NF_EBTABLES
3455 +dep_tristate ' ebt: 802.3 filter support' CONFIG_BRIDGE_EBT_802_3 $CONFIG_BRIDGE_NF_EBTABLES
3456 +dep_tristate ' ebt: packet type filter support' CONFIG_BRIDGE_EBT_PKTTYPE $CONFIG_BRIDGE_NF_EBTABLES
3457 +dep_tristate ' ebt: STP filter support' CONFIG_BRIDGE_EBT_STP $CONFIG_BRIDGE_NF_EBTABLES
3458 +dep_tristate ' ebt: mark filter support' CONFIG_BRIDGE_EBT_MARKF $CONFIG_BRIDGE_NF_EBTABLES
3459 +dep_tristate ' ebt: arp reply target support' CONFIG_BRIDGE_EBT_ARPREPLY $CONFIG_BRIDGE_NF_EBTABLES
3460 +dep_tristate ' ebt: snat target support' CONFIG_BRIDGE_EBT_SNAT $CONFIG_BRIDGE_NF_EBTABLES
3461 +dep_tristate ' ebt: dnat target support' CONFIG_BRIDGE_EBT_DNAT $CONFIG_BRIDGE_NF_EBTABLES
3462 +dep_tristate ' ebt: redirect target support' CONFIG_BRIDGE_EBT_REDIRECT $CONFIG_BRIDGE_NF_EBTABLES
3463 +dep_tristate ' ebt: mark target support' CONFIG_BRIDGE_EBT_MARK_T $CONFIG_BRIDGE_NF_EBTABLES
3464 diff -Nur linux-mips-cvs/net/bridge/netfilter/Makefile linux-ebtables/net/bridge/netfilter/Makefile
3465 --- linux-mips-cvs/net/bridge/netfilter/Makefile 1970-01-01 01:00:00.000000000 +0100
3466 +++ linux-ebtables/net/bridge/netfilter/Makefile 2005-02-07 05:52:50.000000000 +0100
3469 +# Makefile for the netfilter modules on top of bridging.
3471 +# Note! Dependencies are done automagically by 'make dep', which also
3472 +# removes any old dependencies. DON'T put your own dependencies here
3473 +# unless it's something special (ie not a .c file).
3475 +# Note 2! The CFLAGS definition is now in the main makefile...
3477 +O_TARGET := netfilter.o
3479 +export-objs := ebtables.o
3481 +obj-$(CONFIG_BRIDGE_NF_EBTABLES) += ebtables.o
3482 +obj-$(CONFIG_BRIDGE_EBT_T_FILTER) += ebtable_filter.o
3483 +obj-$(CONFIG_BRIDGE_EBT_T_NAT) += ebtable_nat.o
3484 +obj-$(CONFIG_BRIDGE_EBT_BROUTE) += ebtable_broute.o
3485 +obj-$(CONFIG_BRIDGE_EBT_802_3) += ebt_802_3.o
3486 +obj-$(CONFIG_BRIDGE_EBT_ARPF) += ebt_arp.o
3487 +obj-$(CONFIG_BRIDGE_EBT_AMONG) += ebt_among.o
3488 +obj-$(CONFIG_BRIDGE_EBT_IPF) += ebt_ip.o
3489 +obj-$(CONFIG_BRIDGE_EBT_LIMIT) += ebt_limit.o
3490 +obj-$(CONFIG_BRIDGE_EBT_MARKF) += ebt_mark_m.o
3491 +obj-$(CONFIG_BRIDGE_EBT_PKTTYPE) += ebt_pkttype.o
3492 +obj-$(CONFIG_BRIDGE_EBT_STP) += ebt_stp.o
3493 +obj-$(CONFIG_BRIDGE_EBT_VLANF) += ebt_vlan.o
3494 +obj-$(CONFIG_BRIDGE_EBT_LOG) += ebt_log.o
3495 +obj-$(CONFIG_BRIDGE_EBT_LOG) += ebt_ulog.o
3496 +obj-$(CONFIG_BRIDGE_EBT_ARPREPLY) += ebt_arpreply.o
3497 +obj-$(CONFIG_BRIDGE_EBT_DNAT) += ebt_dnat.o
3498 +obj-$(CONFIG_BRIDGE_EBT_MARK_T) += ebt_mark.o
3499 +obj-$(CONFIG_BRIDGE_EBT_REDIRECT) += ebt_redirect.o
3500 +obj-$(CONFIG_BRIDGE_EBT_SNAT) += ebt_snat.o
3501 +include $(TOPDIR)/Rules.make
3502 diff -Nur linux-mips-cvs/net/bridge/netfilter/ebt_802_3.c linux-ebtables/net/bridge/netfilter/ebt_802_3.c
3503 --- linux-mips-cvs/net/bridge/netfilter/ebt_802_3.c 1970-01-01 01:00:00.000000000 +0100
3504 +++ linux-ebtables/net/bridge/netfilter/ebt_802_3.c 2005-02-07 05:52:50.000000000 +0100
3510 + * Chris Vitale csv@bluetail.com
3516 +#include <linux/netfilter_bridge/ebtables.h>
3517 +#include <linux/netfilter_bridge/ebt_802_3.h>
3518 +#include <linux/module.h>
3520 +static int ebt_filter_802_3(const struct sk_buff *skb, const struct net_device *in,
3521 + const struct net_device *out, const void *data, unsigned int datalen)
3523 + struct ebt_802_3_info *info = (struct ebt_802_3_info *)data;
3524 + struct ebt_802_3_hdr *hdr = (struct ebt_802_3_hdr *)skb->mac.ethernet;
3525 + uint16_t type = hdr->llc.ui.ctrl & IS_UI ? hdr->llc.ui.type : hdr->llc.ni.type;
3527 + if (info->bitmask & EBT_802_3_SAP) {
3528 + if (FWINV(info->sap != hdr->llc.ui.ssap, EBT_802_3_SAP))
3529 + return EBT_NOMATCH;
3530 + if (FWINV(info->sap != hdr->llc.ui.dsap, EBT_802_3_SAP))
3531 + return EBT_NOMATCH;
3534 + if (info->bitmask & EBT_802_3_TYPE) {
3535 + if (!(hdr->llc.ui.dsap == CHECK_TYPE && hdr->llc.ui.ssap == CHECK_TYPE))
3536 + return EBT_NOMATCH;
3537 + if (FWINV(info->type != type, EBT_802_3_TYPE))
3538 + return EBT_NOMATCH;
3544 +static struct ebt_match filter_802_3;
3545 +static int ebt_802_3_check(const char *tablename, unsigned int hookmask,
3546 + const struct ebt_entry *e, void *data, unsigned int datalen)
3548 + struct ebt_802_3_info *info = (struct ebt_802_3_info *)data;
3550 + if (datalen != EBT_ALIGN(sizeof(struct ebt_802_3_info)))
3552 + if (info->bitmask & ~EBT_802_3_MASK || info->invflags & ~EBT_802_3_MASK)
3558 +static struct ebt_match filter_802_3 =
3560 + .name = EBT_802_3_MATCH,
3561 + .match = ebt_filter_802_3,
3562 + .check = ebt_802_3_check,
3563 + .me = THIS_MODULE,
3566 +static int __init init(void)
3568 + return ebt_register_match(&filter_802_3);
3571 +static void __exit fini(void)
3573 + ebt_unregister_match(&filter_802_3);
3579 +MODULE_LICENSE("GPL");
3580 diff -Nur linux-mips-cvs/net/bridge/netfilter/ebt_among.c linux-ebtables/net/bridge/netfilter/ebt_among.c
3581 --- linux-mips-cvs/net/bridge/netfilter/ebt_among.c 1970-01-01 01:00:00.000000000 +0100
3582 +++ linux-ebtables/net/bridge/netfilter/ebt_among.c 2005-02-07 05:52:50.000000000 +0100
3588 + * Grzegorz Borowiak <grzes@gnu.univ.gda.pl>
3594 +#include <linux/netfilter_bridge/ebtables.h>
3595 +#include <linux/netfilter_bridge/ebt_among.h>
3596 +#include <linux/ip.h>
3597 +#include <linux/if_arp.h>
3598 +#include <linux/module.h>
3600 +static int ebt_mac_wormhash_contains(const struct ebt_mac_wormhash *wh,
3601 + const char *mac, uint32_t ip)
3603 + /* You may be puzzled as to how this code works.
3604 + * Some tricks were used, refer to
3605 + * include/linux/netfilter_bridge/ebt_among.h
3606 + * as there you can find a solution of this mystery.
3608 + const struct ebt_mac_wormhash_tuple *p;
3609 + int start, limit, i;
3610 + uint32_t cmp[2] = { 0, 0 };
3611 + int key = (const unsigned char) mac[5];
3613 + memcpy(((char *) cmp) + 2, mac, 6);
3614 + start = wh->table[key];
3615 + limit = wh->table[key + 1];
3617 + for (i = start; i < limit; i++) {
3619 + if (cmp[1] == p->cmp[1] && cmp[0] == p->cmp[0]) {
3620 + if (p->ip == 0 || p->ip == ip) {
3626 + for (i = start; i < limit; i++) {
3628 + if (cmp[1] == p->cmp[1] && cmp[0] == p->cmp[0]) {
3638 +static int ebt_mac_wormhash_check_integrity(const struct ebt_mac_wormhash
3643 + for (i = 0; i < 256; i++) {
3644 + if (wh->table[i] > wh->table[i + 1])
3645 + return -0x100 - i;
3646 + if (wh->table[i] < 0)
3647 + return -0x200 - i;
3648 + if (wh->table[i] > wh->poolsize)
3649 + return -0x300 - i;
3651 + if (wh->table[256] > wh->poolsize)
3656 +static int get_ip_dst(const struct sk_buff *skb, uint32_t * addr)
3658 + if (skb->mac.ethernet->h_proto == __constant_htons(ETH_P_IP))
3659 + *addr = skb->nh.iph->daddr;
3660 + else if (skb->mac.ethernet->h_proto == __constant_htons(ETH_P_ARP)) {
3661 + uint32_t arp_len = sizeof(struct arphdr) +
3662 + (2 * (((*skb).nh.arph)->ar_hln)) +
3663 + (2 * (((*skb).nh.arph)->ar_pln));
3665 + /* Make sure the packet is long enough. */
3666 + if ((((*skb).nh.raw) + arp_len) > (*skb).tail)
3668 + /* IPv4 addresses are always 4 bytes. */
3669 + if (((*skb).nh.arph)->ar_pln != sizeof(uint32_t))
3672 + memcpy(addr, ((*skb).nh.raw) + sizeof(struct arphdr) +
3673 + (2 * (((*skb).nh.arph)->ar_hln)) +
3674 + (((*skb).nh.arph)->ar_pln), sizeof(uint32_t));
3680 +static int get_ip_src(const struct sk_buff *skb, uint32_t * addr)
3682 + if (skb->mac.ethernet->h_proto == __constant_htons(ETH_P_IP))
3683 + *addr = skb->nh.iph->saddr;
3684 + else if (skb->mac.ethernet->h_proto == __constant_htons(ETH_P_ARP)) {
3685 + uint32_t arp_len = sizeof(struct arphdr) +
3686 + (2 * (((*skb).nh.arph)->ar_hln)) +
3687 + (2 * (((*skb).nh.arph)->ar_pln));
3689 + /* Make sure the packet is long enough. */
3690 + if ((((*skb).nh.raw) + arp_len) > (*skb).tail)
3692 + /* IPv4 addresses are always 4 bytes. */
3693 + if (((*skb).nh.arph)->ar_pln != sizeof(uint32_t))
3696 + memcpy(addr, ((*skb).nh.raw) + sizeof(struct arphdr) +
3697 + ((((*skb).nh.arph)->ar_hln)), sizeof(uint32_t));
3703 +static int ebt_filter_among(const struct sk_buff *skb,
3704 + const struct net_device *in,
3705 + const struct net_device *out, const void *data,
3706 + unsigned int datalen)
3708 + struct ebt_among_info *info = (struct ebt_among_info *) data;
3709 + const char *dmac, *smac;
3710 + const struct ebt_mac_wormhash *wh_dst, *wh_src;
3711 + uint32_t dip = 0, sip = 0;
3713 + wh_dst = ebt_among_wh_dst(info);
3714 + wh_src = ebt_among_wh_src(info);
3717 + smac = skb->mac.ethernet->h_source;
3718 + if (get_ip_src(skb, &sip))
3719 + return EBT_NOMATCH;
3720 + if (!(info->bitmask & EBT_AMONG_SRC_NEG)) {
3721 + /* we match only if it contains */
3722 + if (!ebt_mac_wormhash_contains(wh_src, smac, sip))
3723 + return EBT_NOMATCH;
3725 + /* we match only if it DOES NOT contain */
3726 + if (ebt_mac_wormhash_contains(wh_src, smac, sip))
3727 + return EBT_NOMATCH;
3732 + dmac = skb->mac.ethernet->h_dest;
3733 + if (get_ip_dst(skb, &dip))
3734 + return EBT_NOMATCH;
3735 + if (!(info->bitmask & EBT_AMONG_DST_NEG)) {
3736 + /* we match only if it contains */
3737 + if (!ebt_mac_wormhash_contains(wh_dst, dmac, dip))
3738 + return EBT_NOMATCH;
3740 + /* we match only if it DOES NOT contain */
3741 + if (ebt_mac_wormhash_contains(wh_dst, dmac, dip))
3742 + return EBT_NOMATCH;
3749 +static int ebt_among_check(const char *tablename, unsigned int hookmask,
3750 + const struct ebt_entry *e, void *data,
3751 + unsigned int datalen)
3753 + struct ebt_among_info *info = (struct ebt_among_info *) data;
3754 + int expected_length = sizeof(struct ebt_among_info);
3755 + const struct ebt_mac_wormhash *wh_dst, *wh_src;
3758 + wh_dst = ebt_among_wh_dst(info);
3759 + wh_src = ebt_among_wh_src(info);
3760 + expected_length += ebt_mac_wormhash_size(wh_dst);
3761 + expected_length += ebt_mac_wormhash_size(wh_src);
3763 + if (datalen != EBT_ALIGN(expected_length)) {
3764 + printk(KERN_WARNING
3765 + "ebtables: among: wrong size: %d"
3766 + "against expected %d, rounded to %d\n",
3767 + datalen, expected_length,
3768 + EBT_ALIGN(expected_length));
3771 + if (wh_dst && (err = ebt_mac_wormhash_check_integrity(wh_dst))) {
3772 + printk(KERN_WARNING
3773 + "ebtables: among: dst integrity fail: %x\n", -err);
3776 + if (wh_src && (err = ebt_mac_wormhash_check_integrity(wh_src))) {
3777 + printk(KERN_WARNING
3778 + "ebtables: among: src integrity fail: %x\n", -err);
3784 +static struct ebt_match filter_among = {
3793 +static int __init init(void)
3795 + return ebt_register_match(&filter_among);
3798 +static void __exit fini(void)
3800 + ebt_unregister_match(&filter_among);
3806 +MODULE_LICENSE("GPL");
3807 diff -Nur linux-mips-cvs/net/bridge/netfilter/ebt_arp.c linux-ebtables/net/bridge/netfilter/ebt_arp.c
3808 --- linux-mips-cvs/net/bridge/netfilter/ebt_arp.c 1970-01-01 01:00:00.000000000 +0100
3809 +++ linux-ebtables/net/bridge/netfilter/ebt_arp.c 2005-02-07 05:52:50.000000000 +0100
3815 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
3816 + * Tim Gardner <timg@tpi.com>
3822 +#include <linux/netfilter_bridge/ebtables.h>
3823 +#include <linux/netfilter_bridge/ebt_arp.h>
3824 +#include <linux/if_arp.h>
3825 +#include <linux/if_ether.h>
3826 +#include <linux/module.h>
3828 +static int ebt_filter_arp(const struct sk_buff *skb, const struct net_device *in,
3829 + const struct net_device *out, const void *data, unsigned int datalen)
3831 + struct ebt_arp_info *info = (struct ebt_arp_info *)data;
3833 + if (info->bitmask & EBT_ARP_OPCODE && FWINV(info->opcode !=
3834 + ((*skb).nh.arph)->ar_op, EBT_ARP_OPCODE))
3835 + return EBT_NOMATCH;
3836 + if (info->bitmask & EBT_ARP_HTYPE && FWINV(info->htype !=
3837 + ((*skb).nh.arph)->ar_hrd, EBT_ARP_HTYPE))
3838 + return EBT_NOMATCH;
3839 + if (info->bitmask & EBT_ARP_PTYPE && FWINV(info->ptype !=
3840 + ((*skb).nh.arph)->ar_pro, EBT_ARP_PTYPE))
3841 + return EBT_NOMATCH;
3843 + if (info->bitmask & (EBT_ARP_SRC_IP | EBT_ARP_DST_IP))
3845 + uint32_t arp_len = sizeof(struct arphdr) +
3846 + (2 * (((*skb).nh.arph)->ar_hln)) +
3847 + (2 * (((*skb).nh.arph)->ar_pln));
3851 + // Make sure the packet is long enough.
3852 + if ((((*skb).nh.raw) + arp_len) > (*skb).tail)
3853 + return EBT_NOMATCH;
3854 + // IPv4 addresses are always 4 bytes.
3855 + if (((*skb).nh.arph)->ar_pln != sizeof(uint32_t))
3856 + return EBT_NOMATCH;
3858 + if (info->bitmask & EBT_ARP_SRC_IP) {
3859 + memcpy(&src, ((*skb).nh.raw) + sizeof(struct arphdr) +
3860 + ((*skb).nh.arph)->ar_hln, sizeof(uint32_t));
3861 + if (FWINV(info->saddr != (src & info->smsk),
3863 + return EBT_NOMATCH;
3866 + if (info->bitmask & EBT_ARP_DST_IP) {
3867 + memcpy(&dst, ((*skb).nh.raw)+sizeof(struct arphdr) +
3868 + (2*(((*skb).nh.arph)->ar_hln)) +
3869 + (((*skb).nh.arph)->ar_pln), sizeof(uint32_t));
3870 + if (FWINV(info->daddr != (dst & info->dmsk),
3872 + return EBT_NOMATCH;
3876 + if (info->bitmask & (EBT_ARP_SRC_MAC | EBT_ARP_DST_MAC))
3878 + uint32_t arp_len = sizeof(struct arphdr) +
3879 + (2 * (((*skb).nh.arph)->ar_hln)) +
3880 + (2 * (((*skb).nh.arph)->ar_pln));
3881 + unsigned char dst[ETH_ALEN];
3882 + unsigned char src[ETH_ALEN];
3884 + // Make sure the packet is long enough.
3885 + if ((((*skb).nh.raw) + arp_len) > (*skb).tail)
3886 + return EBT_NOMATCH;
3887 + // MAC addresses are 6 bytes.
3888 + if (((*skb).nh.arph)->ar_hln != ETH_ALEN)
3889 + return EBT_NOMATCH;
3890 + if (info->bitmask & EBT_ARP_SRC_MAC) {
3891 + uint8_t verdict, i;
3893 + memcpy(&src, ((*skb).nh.raw) +
3894 + sizeof(struct arphdr),
3897 + for (i = 0; i < 6; i++)
3898 + verdict |= (src[i] ^ info->smaddr[i]) &
3900 + if (FWINV(verdict != 0, EBT_ARP_SRC_MAC))
3901 + return EBT_NOMATCH;
3904 + if (info->bitmask & EBT_ARP_DST_MAC) {
3905 + uint8_t verdict, i;
3907 + memcpy(&dst, ((*skb).nh.raw) +
3908 + sizeof(struct arphdr) +
3909 + (((*skb).nh.arph)->ar_hln) +
3910 + (((*skb).nh.arph)->ar_pln),
3913 + for (i = 0; i < 6; i++)
3914 + verdict |= (dst[i] ^ info->dmaddr[i]) &
3916 + if (FWINV(verdict != 0, EBT_ARP_DST_MAC))
3917 + return EBT_NOMATCH;
3924 +static int ebt_arp_check(const char *tablename, unsigned int hookmask,
3925 + const struct ebt_entry *e, void *data, unsigned int datalen)
3927 + struct ebt_arp_info *info = (struct ebt_arp_info *)data;
3929 + if (datalen != EBT_ALIGN(sizeof(struct ebt_arp_info)))
3931 + if ((e->ethproto != __constant_htons(ETH_P_ARP) &&
3932 + e->ethproto != __constant_htons(ETH_P_RARP)) ||
3933 + e->invflags & EBT_IPROTO)
3935 + if (info->bitmask & ~EBT_ARP_MASK || info->invflags & ~EBT_ARP_MASK)
3940 +static struct ebt_match filter_arp =
3942 + {NULL, NULL}, EBT_ARP_MATCH, ebt_filter_arp, ebt_arp_check, NULL,
3946 +static int __init init(void)
3948 + return ebt_register_match(&filter_arp);
3951 +static void __exit fini(void)
3953 + ebt_unregister_match(&filter_arp);
3959 +MODULE_LICENSE("GPL");
3960 diff -Nur linux-mips-cvs/net/bridge/netfilter/ebt_arpreply.c linux-ebtables/net/bridge/netfilter/ebt_arpreply.c
3961 --- linux-mips-cvs/net/bridge/netfilter/ebt_arpreply.c 1970-01-01 01:00:00.000000000 +0100
3962 +++ linux-ebtables/net/bridge/netfilter/ebt_arpreply.c 2005-02-07 05:52:50.000000000 +0100
3968 + * Grzegorz Borowiak <grzes@gnu.univ.gda.pl>
3969 + * Bart De Schuymer <bdschuym@pandora.be>
3975 +#include <linux/netfilter_bridge/ebtables.h>
3976 +#include <linux/netfilter_bridge/ebt_arpreply.h>
3977 +#include <linux/if_arp.h>
3978 +#include <net/arp.h>
3979 +#include <linux/module.h>
3981 +static int ebt_target_reply(struct sk_buff **pskb, unsigned int hooknr,
3982 + const struct net_device *in, const struct net_device *out,
3983 + const void *data, unsigned int datalen)
3985 + struct ebt_arpreply_info *info = (struct ebt_arpreply_info *)data;
3986 + struct arphdr *ah;
3987 + unsigned char *sha, *arp_ptr;
3990 + ah = (**pskb).nh.arph;
3991 + if (ah->ar_op != __constant_htons(ARPOP_REQUEST) ||
3992 + ah->ar_hln != ETH_ALEN || ah->ar_pro != htons(ETH_P_IP) ||
3994 + return EBT_CONTINUE;
3996 + arp_ptr = (unsigned char *)(ah + 1);
3998 + /* get source and target IP */
4000 + arp_ptr += ETH_ALEN;
4001 + memcpy(&sip, arp_ptr, 4);
4002 + arp_ptr += 4 + ETH_ALEN;
4003 + memcpy(&tip, arp_ptr, 4);
4005 + arp_send(ARPOP_REPLY, ETH_P_ARP, sip, in, tip, sha, info->mac, sha);
4007 + return info->target;
4010 +static int ebt_target_reply_check(const char *tablename, unsigned int hookmask,
4011 + const struct ebt_entry *e, void *data, unsigned int datalen)
4013 + struct ebt_arpreply_info *info = (struct ebt_arpreply_info *)data;
4015 + if (datalen != EBT_ALIGN(sizeof(struct ebt_arpreply_info)))
4017 + if (BASE_CHAIN && info->target == EBT_RETURN)
4019 + if (e->ethproto != __constant_htons(ETH_P_ARP) ||
4020 + e->invflags & EBT_IPROTO)
4022 + CLEAR_BASE_CHAIN_BIT;
4023 + if (strcmp(tablename, "nat") || hookmask & ~(1 << NF_BR_PRE_ROUTING))
4028 +static struct ebt_target reply_target =
4030 + .name = EBT_ARPREPLY_TARGET,
4031 + .target = ebt_target_reply,
4032 + .check = ebt_target_reply_check,
4033 + .me = THIS_MODULE,
4036 +static int __init init(void)
4038 + return ebt_register_target(&reply_target);
4041 +static void __exit fini(void)
4043 + ebt_unregister_target(&reply_target);
4049 +MODULE_LICENSE("GPL");
4050 diff -Nur linux-mips-cvs/net/bridge/netfilter/ebt_dnat.c linux-ebtables/net/bridge/netfilter/ebt_dnat.c
4051 --- linux-mips-cvs/net/bridge/netfilter/ebt_dnat.c 1970-01-01 01:00:00.000000000 +0100
4052 +++ linux-ebtables/net/bridge/netfilter/ebt_dnat.c 2005-02-07 05:52:50.000000000 +0100
4058 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
4064 +#include <linux/netfilter_bridge/ebtables.h>
4065 +#include <linux/netfilter_bridge/ebt_nat.h>
4066 +#include <linux/module.h>
4067 +#include <net/sock.h>
4069 +static int ebt_target_dnat(struct sk_buff **pskb, unsigned int hooknr,
4070 + const struct net_device *in, const struct net_device *out,
4071 + const void *data, unsigned int datalen)
4073 + struct ebt_nat_info *info = (struct ebt_nat_info *)data;
4075 + memcpy(((**pskb).mac.ethernet)->h_dest, info->mac,
4076 + ETH_ALEN * sizeof(unsigned char));
4077 + return info->target;
4080 +static int ebt_target_dnat_check(const char *tablename, unsigned int hookmask,
4081 + const struct ebt_entry *e, void *data, unsigned int datalen)
4083 + struct ebt_nat_info *info = (struct ebt_nat_info *)data;
4085 + if (BASE_CHAIN && info->target == EBT_RETURN)
4087 + CLEAR_BASE_CHAIN_BIT;
4088 + if ( (strcmp(tablename, "nat") ||
4089 + (hookmask & ~((1 << NF_BR_PRE_ROUTING) | (1 << NF_BR_LOCAL_OUT)))) &&
4090 + (strcmp(tablename, "broute") || hookmask & ~(1 << NF_BR_BROUTING)) )
4092 + if (datalen != EBT_ALIGN(sizeof(struct ebt_nat_info)))
4094 + if (INVALID_TARGET)
4099 +static struct ebt_target dnat =
4101 + {NULL, NULL}, EBT_DNAT_TARGET, ebt_target_dnat, ebt_target_dnat_check,
4105 +static int __init init(void)
4107 + return ebt_register_target(&dnat);
4110 +static void __exit fini(void)
4112 + ebt_unregister_target(&dnat);
4118 +MODULE_LICENSE("GPL");
4119 diff -Nur linux-mips-cvs/net/bridge/netfilter/ebt_ip.c linux-ebtables/net/bridge/netfilter/ebt_ip.c
4120 --- linux-mips-cvs/net/bridge/netfilter/ebt_ip.c 1970-01-01 01:00:00.000000000 +0100
4121 +++ linux-ebtables/net/bridge/netfilter/ebt_ip.c 2005-02-07 05:52:50.000000000 +0100
4127 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
4132 + * added ip-sport and ip-dport
4133 + * Innominate Security Technologies AG <mhopf@innominate.com>
4137 +#include <linux/netfilter_bridge/ebtables.h>
4138 +#include <linux/netfilter_bridge/ebt_ip.h>
4139 +#include <linux/ip.h>
4140 +#include <linux/in.h>
4141 +#include <linux/module.h>
4149 + unsigned char *raw;
4150 + struct tcpudphdr *tuh;
4153 +static int ebt_filter_ip(const struct sk_buff *skb, const struct net_device *in,
4154 + const struct net_device *out, const void *data,
4155 + unsigned int datalen)
4157 + struct ebt_ip_info *info = (struct ebt_ip_info *)data;
4159 + if (info->bitmask & EBT_IP_TOS &&
4160 + FWINV(info->tos != ((*skb).nh.iph)->tos, EBT_IP_TOS))
4161 + return EBT_NOMATCH;
4162 + if (info->bitmask & EBT_IP_PROTO) {
4163 + if (FWINV(info->protocol != ((*skb).nh.iph)->protocol,
4165 + return EBT_NOMATCH;
4166 + if ( info->protocol == IPPROTO_TCP ||
4167 + info->protocol == IPPROTO_UDP )
4170 + h.raw = skb->data + skb->nh.iph->ihl*4;
4171 + if (info->bitmask & EBT_IP_DPORT) {
4172 + uint16_t port = ntohs(h.tuh->dst);
4173 + if (FWINV(port < info->dport[0] ||
4174 + port > info->dport[1],
4176 + return EBT_NOMATCH;
4178 + if (info->bitmask & EBT_IP_SPORT) {
4179 + uint16_t port = ntohs(h.tuh->src);
4180 + if (FWINV(port < info->sport[0] ||
4181 + port > info->sport[1],
4183 + return EBT_NOMATCH;
4187 + if (info->bitmask & EBT_IP_SOURCE &&
4188 + FWINV((((*skb).nh.iph)->saddr & info->smsk) !=
4189 + info->saddr, EBT_IP_SOURCE))
4190 + return EBT_NOMATCH;
4191 + if ((info->bitmask & EBT_IP_DEST) &&
4192 + FWINV((((*skb).nh.iph)->daddr & info->dmsk) !=
4193 + info->daddr, EBT_IP_DEST))
4194 + return EBT_NOMATCH;
4198 +static int ebt_ip_check(const char *tablename, unsigned int hookmask,
4199 + const struct ebt_entry *e, void *data, unsigned int datalen)
4201 + struct ebt_ip_info *info = (struct ebt_ip_info *)data;
4203 + if (datalen != EBT_ALIGN(sizeof(struct ebt_ip_info)))
4205 + if (e->ethproto != __constant_htons(ETH_P_IP) ||
4206 + e->invflags & EBT_IPROTO)
4208 + if (info->bitmask & ~EBT_IP_MASK || info->invflags & ~EBT_IP_MASK)
4210 + if (info->bitmask & (EBT_IP_DPORT | EBT_IP_SPORT)) {
4211 + if (!info->bitmask & EBT_IPROTO)
4213 + if (info->protocol != IPPROTO_TCP &&
4214 + info->protocol != IPPROTO_UDP)
4217 + if (info->bitmask & EBT_IP_DPORT && info->dport[0] > info->dport[1])
4219 + if (info->bitmask & EBT_IP_SPORT && info->sport[0] > info->sport[1])
4224 +static struct ebt_match filter_ip =
4226 + {NULL, NULL}, EBT_IP_MATCH, ebt_filter_ip, ebt_ip_check, NULL,
4230 +static int __init init(void)
4232 + return ebt_register_match(&filter_ip);
4235 +static void __exit fini(void)
4237 + ebt_unregister_match(&filter_ip);
4243 +MODULE_LICENSE("GPL");
4244 diff -Nur linux-mips-cvs/net/bridge/netfilter/ebt_limit.c linux-ebtables/net/bridge/netfilter/ebt_limit.c
4245 --- linux-mips-cvs/net/bridge/netfilter/ebt_limit.c 1970-01-01 01:00:00.000000000 +0100
4246 +++ linux-ebtables/net/bridge/netfilter/ebt_limit.c 2005-02-07 05:52:50.000000000 +0100
4252 + * Tom Marshall <tommy@home.tig-grr.com>
4254 + * Mostly copied from netfilter's ipt_limit.c, see that file for explanation
4260 +#include <linux/netfilter_bridge/ebtables.h>
4261 +#include <linux/netfilter_bridge/ebt_limit.h>
4262 +#include <linux/module.h>
4264 +#include <linux/netdevice.h>
4265 +#include <linux/spinlock.h>
4267 +static spinlock_t limit_lock = SPIN_LOCK_UNLOCKED;
4269 +#define CREDITS_PER_JIFFY 128
4271 +static int ebt_limit_match(const struct sk_buff *skb, const struct net_device *in,
4272 + const struct net_device *out, const void *data, unsigned int datalen)
4274 + struct ebt_limit_info *info = (struct ebt_limit_info *)data;
4275 + unsigned long now = jiffies;
4277 + spin_lock_bh(&limit_lock);
4278 + info->credit += (now - xchg(&info->prev, now)) * CREDITS_PER_JIFFY;
4279 + if (info->credit > info->credit_cap)
4280 + info->credit = info->credit_cap;
4282 + if (info->credit >= info->cost) {
4283 + /* We're not limited. */
4284 + info->credit -= info->cost;
4285 + spin_unlock_bh(&limit_lock);
4289 + spin_unlock_bh(&limit_lock);
4290 + return EBT_NOMATCH;
4293 +/* Precision saver. */
4295 +user2credits(u_int32_t user)
4297 + /* If multiplying would overflow... */
4298 + if (user > 0xFFFFFFFF / (HZ*CREDITS_PER_JIFFY))
4299 + /* Divide first. */
4300 + return (user / EBT_LIMIT_SCALE) * HZ * CREDITS_PER_JIFFY;
4302 + return (user * HZ * CREDITS_PER_JIFFY) / EBT_LIMIT_SCALE;
4305 +static int ebt_limit_check(const char *tablename, unsigned int hookmask,
4306 + const struct ebt_entry *e, void *data, unsigned int datalen)
4308 + struct ebt_limit_info *info = (struct ebt_limit_info *)data;
4310 + if (datalen != EBT_ALIGN(sizeof(struct ebt_limit_info)))
4313 + /* Check for overflow. */
4314 + if (info->burst == 0
4315 + || user2credits(info->avg * info->burst) < user2credits(info->avg)) {
4316 + printk("Overflow in ebt_limit: %u/%u\n",
4317 + info->avg, info->burst);
4321 + /* User avg in seconds * EBT_LIMIT_SCALE: convert to jiffies * 128. */
4322 + info->prev = jiffies;
4323 + info->credit = user2credits(info->avg * info->burst);
4324 + info->credit_cap = user2credits(info->avg * info->burst);
4325 + info->cost = user2credits(info->avg);
4329 +static struct ebt_match ebt_limit_reg =
4331 + {NULL, NULL}, EBT_LIMIT_MATCH, ebt_limit_match, ebt_limit_check, NULL,
4335 +static int __init init(void)
4337 + return ebt_register_match(&ebt_limit_reg);
4340 +static void __exit fini(void)
4342 + ebt_unregister_match(&ebt_limit_reg);
4348 +MODULE_LICENSE("GPL");
4349 diff -Nur linux-mips-cvs/net/bridge/netfilter/ebt_log.c linux-ebtables/net/bridge/netfilter/ebt_log.c
4350 --- linux-mips-cvs/net/bridge/netfilter/ebt_log.c 1970-01-01 01:00:00.000000000 +0100
4351 +++ linux-ebtables/net/bridge/netfilter/ebt_log.c 2005-02-07 05:52:50.000000000 +0100
4357 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
4363 +#include <linux/netfilter_bridge/ebtables.h>
4364 +#include <linux/netfilter_bridge/ebt_log.h>
4365 +#include <linux/module.h>
4366 +#include <linux/ip.h>
4367 +#include <linux/in.h>
4368 +#include <linux/if_arp.h>
4369 +#include <linux/spinlock.h>
4371 +static spinlock_t ebt_log_lock = SPIN_LOCK_UNLOCKED;
4373 +static int ebt_log_check(const char *tablename, unsigned int hookmask,
4374 + const struct ebt_entry *e, void *data, unsigned int datalen)
4376 + struct ebt_log_info *info = (struct ebt_log_info *)data;
4378 + if (datalen != EBT_ALIGN(sizeof(struct ebt_log_info)))
4380 + if (info->bitmask & ~EBT_LOG_MASK)
4382 + if (info->loglevel >= 8)
4384 + info->prefix[EBT_LOG_PREFIX_SIZE - 1] = '\0';
4396 + unsigned char mac_src[ETH_ALEN];
4397 + unsigned char ip_src[4];
4398 + unsigned char mac_dst[ETH_ALEN];
4399 + unsigned char ip_dst[4];
4402 +static void print_MAC(unsigned char *p)
4406 + for (i = 0; i < ETH_ALEN; i++, p++)
4407 + printk("%02x%c", *p, i == ETH_ALEN - 1 ? ' ':':');
4410 +#define myNIPQUAD(a) a[0], a[1], a[2], a[3]
4411 +static void ebt_log(const struct sk_buff *skb, unsigned int hooknr,
4412 + const struct net_device *in, const struct net_device *out,
4413 + const void *data, unsigned int datalen)
4415 + struct ebt_log_info *info = (struct ebt_log_info *)data;
4416 + char level_string[4] = "< >";
4417 + level_string[1] = '0' + info->loglevel;
4419 + spin_lock_bh(&ebt_log_lock);
4420 + printk(level_string);
4421 + printk("%s IN=%s OUT=%s ", info->prefix, in ? in->name : "",
4422 + out ? out->name : "");
4424 + printk("MAC source = ");
4425 + print_MAC((skb->mac.ethernet)->h_source);
4426 + printk("MAC dest = ");
4427 + print_MAC((skb->mac.ethernet)->h_dest);
4429 + printk("proto = 0x%04x", ntohs(((*skb).mac.ethernet)->h_proto));
4431 + if ((info->bitmask & EBT_LOG_IP) && skb->mac.ethernet->h_proto ==
4433 + struct iphdr *iph = skb->nh.iph;
4434 + printk(" IP SRC=%u.%u.%u.%u IP DST=%u.%u.%u.%u,",
4435 + NIPQUAD(iph->saddr), NIPQUAD(iph->daddr));
4436 + printk(" IP tos=0x%02X, IP proto=%d", iph->tos, iph->protocol);
4437 + if (iph->protocol == IPPROTO_TCP ||
4438 + iph->protocol == IPPROTO_UDP) {
4439 + struct tcpudphdr *ports = (struct tcpudphdr *)(skb->data + iph->ihl*4);
4441 + if (skb->data + iph->ihl*4 > skb->tail) {
4442 + printk(" INCOMPLETE TCP/UDP header");
4445 + printk(" SPT=%u DPT=%u", ntohs(ports->src),
4446 + ntohs(ports->dst));
4451 + if ((info->bitmask & EBT_LOG_ARP) &&
4452 + ((skb->mac.ethernet->h_proto == __constant_htons(ETH_P_ARP)) ||
4453 + (skb->mac.ethernet->h_proto == __constant_htons(ETH_P_RARP)))) {
4454 + struct arphdr * arph = skb->nh.arph;
4455 + printk(" ARP HTYPE=%d, PTYPE=0x%04x, OPCODE=%d",
4456 + ntohs(arph->ar_hrd), ntohs(arph->ar_pro),
4457 + ntohs(arph->ar_op));
4458 + /* If it's for Ethernet and the lengths are OK,
4459 + * then log the ARP payload */
4460 + if (arph->ar_hrd == __constant_htons(1) &&
4461 + arph->ar_hln == ETH_ALEN &&
4462 + arph->ar_pln == sizeof(uint32_t)) {
4463 + struct arppayload *arpp = (struct arppayload *)(skb->data + sizeof(*arph));
4465 + if (skb->data + sizeof(*arph) > skb->tail) {
4466 + printk(" INCOMPLETE ARP header");
4470 + printk(" ARP MAC SRC=");
4471 + print_MAC(arpp->mac_src);
4472 + printk(" ARP IP SRC=%u.%u.%u.%u",
4473 + myNIPQUAD(arpp->ip_src));
4474 + printk(" ARP MAC DST=");
4475 + print_MAC(arpp->mac_dst);
4476 + printk(" ARP IP DST=%u.%u.%u.%u",
4477 + myNIPQUAD(arpp->ip_dst));
4483 + spin_unlock_bh(&ebt_log_lock);
4486 +static struct ebt_watcher log =
4488 + {NULL, NULL}, EBT_LOG_WATCHER, ebt_log, ebt_log_check, NULL,
4492 +static int __init init(void)
4494 + return ebt_register_watcher(&log);
4497 +static void __exit fini(void)
4499 + ebt_unregister_watcher(&log);
4505 +MODULE_LICENSE("GPL");
4506 diff -Nur linux-mips-cvs/net/bridge/netfilter/ebt_mark.c linux-ebtables/net/bridge/netfilter/ebt_mark.c
4507 --- linux-mips-cvs/net/bridge/netfilter/ebt_mark.c 1970-01-01 01:00:00.000000000 +0100
4508 +++ linux-ebtables/net/bridge/netfilter/ebt_mark.c 2005-02-07 05:52:50.000000000 +0100
4514 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
4520 +// The mark target can be used in any chain
4521 +// I believe adding a mangle table just for marking is total overkill
4522 +// Marking a frame doesn't really change anything in the frame anyway
4524 +#include <linux/netfilter_bridge/ebtables.h>
4525 +#include <linux/netfilter_bridge/ebt_mark_t.h>
4526 +#include <linux/module.h>
4528 +static int ebt_target_mark(struct sk_buff **pskb, unsigned int hooknr,
4529 + const struct net_device *in, const struct net_device *out,
4530 + const void *data, unsigned int datalen)
4532 + struct ebt_mark_t_info *info = (struct ebt_mark_t_info *)data;
4534 + if ((*pskb)->nfmark != info->mark) {
4535 + (*pskb)->nfmark = info->mark;
4536 + (*pskb)->nfcache |= NFC_ALTERED;
4538 + return info->target;
4541 +static int ebt_target_mark_check(const char *tablename, unsigned int hookmask,
4542 + const struct ebt_entry *e, void *data, unsigned int datalen)
4544 + struct ebt_mark_t_info *info = (struct ebt_mark_t_info *)data;
4546 + if (datalen != EBT_ALIGN(sizeof(struct ebt_mark_t_info)))
4548 + if (BASE_CHAIN && info->target == EBT_RETURN)
4550 + CLEAR_BASE_CHAIN_BIT;
4551 + if (INVALID_TARGET)
4556 +static struct ebt_target mark_target =
4558 + {NULL, NULL}, EBT_MARK_TARGET, ebt_target_mark,
4559 + ebt_target_mark_check, NULL, THIS_MODULE
4562 +static int __init init(void)
4564 + return ebt_register_target(&mark_target);
4567 +static void __exit fini(void)
4569 + ebt_unregister_target(&mark_target);
4575 +MODULE_LICENSE("GPL");
4576 diff -Nur linux-mips-cvs/net/bridge/netfilter/ebt_mark_m.c linux-ebtables/net/bridge/netfilter/ebt_mark_m.c
4577 --- linux-mips-cvs/net/bridge/netfilter/ebt_mark_m.c 1970-01-01 01:00:00.000000000 +0100
4578 +++ linux-ebtables/net/bridge/netfilter/ebt_mark_m.c 2005-02-07 05:52:50.000000000 +0100
4584 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
4590 +#include <linux/netfilter_bridge/ebtables.h>
4591 +#include <linux/netfilter_bridge/ebt_mark_m.h>
4592 +#include <linux/module.h>
4594 +static int ebt_filter_mark(const struct sk_buff *skb,
4595 + const struct net_device *in, const struct net_device *out, const void *data,
4596 + unsigned int datalen)
4598 + struct ebt_mark_m_info *info = (struct ebt_mark_m_info *) data;
4600 + if (info->bitmask & EBT_MARK_OR)
4601 + return !(!!(skb->nfmark & info->mask) ^ info->invert);
4602 + return !(((skb->nfmark & info->mask) == info->mark) ^ info->invert);
4605 +static int ebt_mark_check(const char *tablename, unsigned int hookmask,
4606 + const struct ebt_entry *e, void *data, unsigned int datalen)
4608 + struct ebt_mark_m_info *info = (struct ebt_mark_m_info *) data;
4610 + if (datalen != EBT_ALIGN(sizeof(struct ebt_mark_m_info)))
4612 + if (info->bitmask & ~EBT_MARK_MASK)
4614 + if ((info->bitmask & EBT_MARK_OR) && (info->bitmask & EBT_MARK_AND))
4616 + if (!info->bitmask)
4621 +static struct ebt_match filter_mark =
4623 + {NULL, NULL}, EBT_MARK_MATCH, ebt_filter_mark, ebt_mark_check, NULL,
4627 +static int __init init(void)
4629 + return ebt_register_match(&filter_mark);
4632 +static void __exit fini(void)
4634 + ebt_unregister_match(&filter_mark);
4640 +MODULE_LICENSE("GPL");
4641 diff -Nur linux-mips-cvs/net/bridge/netfilter/ebt_pkttype.c linux-ebtables/net/bridge/netfilter/ebt_pkttype.c
4642 --- linux-mips-cvs/net/bridge/netfilter/ebt_pkttype.c 1970-01-01 01:00:00.000000000 +0100
4643 +++ linux-ebtables/net/bridge/netfilter/ebt_pkttype.c 2005-02-07 05:52:50.000000000 +0100
4649 + * Bart De Schuymer <bdschuym@pandora.be>
4655 +#include <linux/netfilter_bridge/ebtables.h>
4656 +#include <linux/netfilter_bridge/ebt_pkttype.h>
4657 +#include <linux/module.h>
4659 +static int ebt_filter_pkttype(const struct sk_buff *skb,
4660 + const struct net_device *in,
4661 + const struct net_device *out,
4663 + unsigned int datalen)
4665 + struct ebt_pkttype_info *info = (struct ebt_pkttype_info *)data;
4667 + return (skb->pkt_type != info->pkt_type) ^ info->invert;
4670 +static int ebt_pkttype_check(const char *tablename, unsigned int hookmask,
4671 + const struct ebt_entry *e, void *data, unsigned int datalen)
4673 + struct ebt_pkttype_info *info = (struct ebt_pkttype_info *)data;
4675 + if (datalen != EBT_ALIGN(sizeof(struct ebt_pkttype_info)))
4677 + if (info->invert != 0 && info->invert != 1)
4679 + /* Allow any pkt_type value */
4683 +static struct ebt_match filter_pkttype =
4685 + .name = EBT_PKTTYPE_MATCH,
4686 + .match = ebt_filter_pkttype,
4687 + .check = ebt_pkttype_check,
4688 + .me = THIS_MODULE,
4691 +static int __init init(void)
4693 + return ebt_register_match(&filter_pkttype);
4696 +static void __exit fini(void)
4698 + ebt_unregister_match(&filter_pkttype);
4704 +MODULE_LICENSE("GPL");
4705 diff -Nur linux-mips-cvs/net/bridge/netfilter/ebt_redirect.c linux-ebtables/net/bridge/netfilter/ebt_redirect.c
4706 --- linux-mips-cvs/net/bridge/netfilter/ebt_redirect.c 1970-01-01 01:00:00.000000000 +0100
4707 +++ linux-ebtables/net/bridge/netfilter/ebt_redirect.c 2005-02-07 05:52:50.000000000 +0100
4713 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
4719 +#include <linux/netfilter_bridge/ebtables.h>
4720 +#include <linux/netfilter_bridge/ebt_redirect.h>
4721 +#include <linux/module.h>
4722 +#include <net/sock.h>
4723 +#include "../br_private.h"
4725 +static int ebt_target_redirect(struct sk_buff **pskb, unsigned int hooknr,
4726 + const struct net_device *in, const struct net_device *out,
4727 + const void *data, unsigned int datalen)
4729 + struct ebt_redirect_info *info = (struct ebt_redirect_info *)data;
4731 + if (hooknr != NF_BR_BROUTING)
4732 + memcpy((**pskb).mac.ethernet->h_dest,
4733 + in->br_port->br->dev.dev_addr, ETH_ALEN);
4735 + memcpy((**pskb).mac.ethernet->h_dest,
4736 + in->dev_addr, ETH_ALEN);
4737 + (*pskb)->pkt_type = PACKET_HOST;
4739 + return info->target;
4742 +static int ebt_target_redirect_check(const char *tablename, unsigned int hookmask,
4743 + const struct ebt_entry *e, void *data, unsigned int datalen)
4745 + struct ebt_redirect_info *info = (struct ebt_redirect_info *)data;
4747 + if (datalen != EBT_ALIGN(sizeof(struct ebt_redirect_info)))
4749 + if (BASE_CHAIN && info->target == EBT_RETURN)
4751 + CLEAR_BASE_CHAIN_BIT;
4752 + if ( (strcmp(tablename, "nat") || hookmask & ~(1 << NF_BR_PRE_ROUTING)) &&
4753 + (strcmp(tablename, "broute") || hookmask & ~(1 << NF_BR_BROUTING)) )
4755 + if (INVALID_TARGET)
4760 +static struct ebt_target redirect_target =
4762 + {NULL, NULL}, EBT_REDIRECT_TARGET, ebt_target_redirect,
4763 + ebt_target_redirect_check, NULL, THIS_MODULE
4766 +static int __init init(void)
4768 + return ebt_register_target(&redirect_target);
4771 +static void __exit fini(void)
4773 + ebt_unregister_target(&redirect_target);
4779 +MODULE_LICENSE("GPL");
4780 diff -Nur linux-mips-cvs/net/bridge/netfilter/ebt_snat.c linux-ebtables/net/bridge/netfilter/ebt_snat.c
4781 --- linux-mips-cvs/net/bridge/netfilter/ebt_snat.c 1970-01-01 01:00:00.000000000 +0100
4782 +++ linux-ebtables/net/bridge/netfilter/ebt_snat.c 2005-02-07 05:52:50.000000000 +0100
4788 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
4794 +#include <linux/netfilter_bridge/ebtables.h>
4795 +#include <linux/netfilter_bridge/ebt_nat.h>
4796 +#include <linux/module.h>
4798 +static int ebt_target_snat(struct sk_buff **pskb, unsigned int hooknr,
4799 + const struct net_device *in, const struct net_device *out,
4800 + const void *data, unsigned int datalen)
4802 + struct ebt_nat_info *info = (struct ebt_nat_info *) data;
4804 + memcpy(((**pskb).mac.ethernet)->h_source, info->mac,
4805 + ETH_ALEN * sizeof(unsigned char));
4806 + return info->target;
4809 +static int ebt_target_snat_check(const char *tablename, unsigned int hookmask,
4810 + const struct ebt_entry *e, void *data, unsigned int datalen)
4812 + struct ebt_nat_info *info = (struct ebt_nat_info *) data;
4814 + if (datalen != EBT_ALIGN(sizeof(struct ebt_nat_info)))
4816 + if (BASE_CHAIN && info->target == EBT_RETURN)
4818 + CLEAR_BASE_CHAIN_BIT;
4819 + if (strcmp(tablename, "nat"))
4821 + if (hookmask & ~(1 << NF_BR_POST_ROUTING))
4823 + if (INVALID_TARGET)
4828 +static struct ebt_target snat =
4830 + {NULL, NULL}, EBT_SNAT_TARGET, ebt_target_snat, ebt_target_snat_check,
4834 +static int __init init(void)
4836 + return ebt_register_target(&snat);
4839 +static void __exit fini(void)
4841 + ebt_unregister_target(&snat);
4847 +MODULE_LICENSE("GPL");
4848 diff -Nur linux-mips-cvs/net/bridge/netfilter/ebt_stp.c linux-ebtables/net/bridge/netfilter/ebt_stp.c
4849 --- linux-mips-cvs/net/bridge/netfilter/ebt_stp.c 1970-01-01 01:00:00.000000000 +0100
4850 +++ linux-ebtables/net/bridge/netfilter/ebt_stp.c 2005-02-07 05:52:50.000000000 +0100
4856 + * Bart De Schuymer <bdschuym@pandora.be>
4857 + * Stephen Hemminger <shemminger@osdl.org>
4862 +#include <linux/netfilter_bridge/ebtables.h>
4863 +#include <linux/netfilter_bridge/ebt_stp.h>
4864 +#include <linux/module.h>
4866 +#define BPDU_TYPE_CONFIG 0
4867 +#define BPDU_TYPE_TCN 0x80
4869 +struct stp_header {
4878 +struct stp_config_pdu {
4881 + uint8_t root_cost[4];
4882 + uint8_t sender[8];
4884 + uint8_t msg_age[2];
4885 + uint8_t max_age[2];
4886 + uint8_t hello_time[2];
4887 + uint8_t forward_delay[2];
4890 +#define NR16(p) (p[0] << 8 | p[1])
4891 +#define NR32(p) ((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3])
4893 +static int ebt_filter_config(struct ebt_stp_info *info,
4894 + struct stp_config_pdu *stpc)
4896 + struct ebt_stp_config_info *c;
4901 + c = &info->config;
4902 + if ((info->bitmask & EBT_STP_FLAGS) &&
4903 + FWINV(c->flags != stpc->flags, EBT_STP_FLAGS))
4904 + return EBT_NOMATCH;
4905 + if (info->bitmask & EBT_STP_ROOTPRIO) {
4906 + v16 = NR16(stpc->root);
4907 + if (FWINV(v16 < c->root_priol ||
4908 + v16 > c->root_priou, EBT_STP_ROOTPRIO))
4909 + return EBT_NOMATCH;
4911 + if (info->bitmask & EBT_STP_ROOTADDR) {
4913 + for (i = 0; i < 6; i++)
4914 + verdict |= (stpc->root[2+i] ^ c->root_addr[i]) &
4915 + c->root_addrmsk[i];
4916 + if (FWINV(verdict != 0, EBT_STP_ROOTADDR))
4917 + return EBT_NOMATCH;
4919 + if (info->bitmask & EBT_STP_ROOTCOST) {
4920 + v32 = NR32(stpc->root_cost);
4921 + if (FWINV(v32 < c->root_costl ||
4922 + v32 > c->root_costu, EBT_STP_ROOTCOST))
4923 + return EBT_NOMATCH;
4925 + if (info->bitmask & EBT_STP_SENDERPRIO) {
4926 + v16 = NR16(stpc->sender);
4927 + if (FWINV(v16 < c->sender_priol ||
4928 + v16 > c->sender_priou, EBT_STP_SENDERPRIO))
4929 + return EBT_NOMATCH;
4931 + if (info->bitmask & EBT_STP_SENDERADDR) {
4933 + for (i = 0; i < 6; i++)
4934 + verdict |= (stpc->sender[2+i] ^ c->sender_addr[i]) &
4935 + c->sender_addrmsk[i];
4936 + if (FWINV(verdict != 0, EBT_STP_SENDERADDR))
4937 + return EBT_NOMATCH;
4939 + if (info->bitmask & EBT_STP_PORT) {
4940 + v16 = NR16(stpc->port);
4941 + if (FWINV(v16 < c->portl ||
4942 + v16 > c->portu, EBT_STP_PORT))
4943 + return EBT_NOMATCH;
4945 + if (info->bitmask & EBT_STP_MSGAGE) {
4946 + v16 = NR16(stpc->msg_age);
4947 + if (FWINV(v16 < c->msg_agel ||
4948 + v16 > c->msg_ageu, EBT_STP_MSGAGE))
4949 + return EBT_NOMATCH;
4951 + if (info->bitmask & EBT_STP_MAXAGE) {
4952 + v16 = NR16(stpc->max_age);
4953 + if (FWINV(v16 < c->max_agel ||
4954 + v16 > c->max_ageu, EBT_STP_MAXAGE))
4955 + return EBT_NOMATCH;
4957 + if (info->bitmask & EBT_STP_HELLOTIME) {
4958 + v16 = NR16(stpc->hello_time);
4959 + if (FWINV(v16 < c->hello_timel ||
4960 + v16 > c->hello_timeu, EBT_STP_HELLOTIME))
4961 + return EBT_NOMATCH;
4963 + if (info->bitmask & EBT_STP_FWDD) {
4964 + v16 = NR16(stpc->forward_delay);
4965 + if (FWINV(v16 < c->forward_delayl ||
4966 + v16 > c->forward_delayu, EBT_STP_FWDD))
4967 + return EBT_NOMATCH;
4972 +static int ebt_filter_stp(const struct sk_buff *skb, const struct net_device *in,
4973 + const struct net_device *out, const void *data, unsigned int datalen)
4975 + struct ebt_stp_info *info = (struct ebt_stp_info *)data;
4976 + struct stp_header stph;
4977 + uint8_t header[6] = {0x42, 0x42, 0x03, 0x00, 0x00, 0x00};
4978 + if (skb_copy_bits(skb, 0, &stph, sizeof(stph)))
4979 + return EBT_NOMATCH;
4981 + /* The stp code only considers these */
4982 + if (memcmp(&stph, header, sizeof(header)))
4983 + return EBT_NOMATCH;
4985 + if (info->bitmask & EBT_STP_TYPE
4986 + && FWINV(info->type != stph.type, EBT_STP_TYPE))
4987 + return EBT_NOMATCH;
4989 + if (stph.type == BPDU_TYPE_CONFIG &&
4990 + info->bitmask & EBT_STP_CONFIG_MASK) {
4991 + struct stp_config_pdu stpc;
4993 + if (skb_copy_bits(skb, sizeof(stph), &stpc, sizeof(stpc)))
4994 + return EBT_NOMATCH;
4995 + return ebt_filter_config(info, &stpc);
5000 +static int ebt_stp_check(const char *tablename, unsigned int hookmask,
5001 + const struct ebt_entry *e, void *data, unsigned int datalen)
5003 + struct ebt_stp_info *info = (struct ebt_stp_info *)data;
5004 + int len = EBT_ALIGN(sizeof(struct ebt_stp_info));
5005 + uint8_t bridge_ula[6] = { 0x01, 0x80, 0xc2, 0x00, 0x00, 0x00 };
5006 + uint8_t msk[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
5008 + if (info->bitmask & ~EBT_STP_MASK || info->invflags & ~EBT_STP_MASK ||
5009 + !(info->bitmask & EBT_STP_MASK))
5011 + if (datalen != len)
5013 + /* Make sure the match only receives stp frames */
5014 + if (memcmp(e->destmac, bridge_ula, ETH_ALEN) ||
5015 + memcmp(e->destmsk, msk, ETH_ALEN) || !(e->bitmask & EBT_DESTMAC))
5021 +static struct ebt_match filter_stp =
5023 + .name = EBT_STP_MATCH,
5024 + .match = ebt_filter_stp,
5025 + .check = ebt_stp_check,
5026 + .me = THIS_MODULE,
5029 +static int __init init(void)
5031 + return ebt_register_match(&filter_stp);
5034 +static void __exit fini(void)
5036 + ebt_unregister_match(&filter_stp);
5042 +MODULE_LICENSE("GPL");
5043 diff -Nur linux-mips-cvs/net/bridge/netfilter/ebt_ulog.c linux-ebtables/net/bridge/netfilter/ebt_ulog.c
5044 --- linux-mips-cvs/net/bridge/netfilter/ebt_ulog.c 1970-01-01 01:00:00.000000000 +0100
5045 +++ linux-ebtables/net/bridge/netfilter/ebt_ulog.c 2005-02-07 05:52:50.000000000 +0100
5048 + * netfilter module for userspace bridged Ethernet frames logging daemons
5051 + * Bart De Schuymer <bdschuym@pandora.be>
5055 + * Based on ipt_ULOG.c, which is
5056 + * (C) 2000-2002 by Harald Welte <laforge@netfilter.org>
5058 + * This module accepts two parameters:
5061 + * The parameter specifies how big the buffer for each netlink multicast
5062 + * group is. e.g. If you say nlbufsiz=8192, up to eight kb of packets will
5063 + * get accumulated in the kernel until they are sent to userspace. It is
5064 + * NOT possible to allocate more than 128kB, and it is strongly discouraged,
5065 + * because atomically allocating 128kB inside the network rx softirq is not
5066 + * reliable. Please also keep in mind that this buffer size is allocated for
5067 + * each nlgroup you are using, so the total kernel memory usage increases
5071 + * Specify, after how many hundredths of a second the queue should be
5072 + * flushed even if it is not full yet.
5076 +#include <linux/module.h>
5077 +#include <linux/config.h>
5078 +#include <linux/spinlock.h>
5079 +#include <linux/socket.h>
5080 +#include <linux/skbuff.h>
5081 +#include <linux/kernel.h>
5082 +#include <linux/timer.h>
5083 +#include <linux/netlink.h>
5084 +#include <linux/netdevice.h>
5085 +#include <linux/module.h>
5086 +#include <linux/netfilter_bridge/ebtables.h>
5087 +#include <linux/netfilter_bridge/ebt_ulog.h>
5088 +#include <net/sock.h>
5089 +#include "../br_private.h"
5091 +#define PRINTR(format, args...) do { if (net_ratelimit()) \
5092 + printk(format , ## args); } while (0)
5094 +static unsigned int nlbufsiz = 4096;
5095 +MODULE_PARM(nlbufsiz, "i");
5096 +MODULE_PARM_DESC(nlbufsiz, "netlink buffer size (number of bytes) "
5097 + "(defaults to 4096)");
5099 +static unsigned int flushtimeout = 10;
5100 +MODULE_PARM(flushtimeout, "i");
5101 +MODULE_PARM_DESC(flushtimeout, "buffer flush timeout (hundredths of a second) "
5102 + "(defaults to 10)");
5105 + unsigned int qlen; /* number of nlmsgs' in the skb */
5106 + struct nlmsghdr *lastnlh; /* netlink header of last msg in skb */
5107 + struct sk_buff *skb; /* the pre-allocated skb */
5108 + struct timer_list timer; /* the timer function */
5109 + spinlock_t lock; /* the per-queue lock */
5112 +static ebt_ulog_buff_t ulog_buffers[EBT_ULOG_MAXNLGROUPS];
5113 +static struct sock *ebtlognl;
5115 +/* send one ulog_buff_t to userspace */
5116 +static void ulog_send(unsigned int nlgroup)
5118 + ebt_ulog_buff_t *ub = &ulog_buffers[nlgroup];
5120 + if (timer_pending(&ub->timer))
5121 + del_timer(&ub->timer);
5123 + /* last nlmsg needs NLMSG_DONE */
5125 + ub->lastnlh->nlmsg_type = NLMSG_DONE;
5127 + NETLINK_CB(ub->skb).dst_groups = 1 << nlgroup;
5128 + netlink_broadcast(ebtlognl, ub->skb, 0, 1 << nlgroup, GFP_ATOMIC);
5134 +/* timer function to flush queue in flushtimeout time */
5135 +static void ulog_timer(unsigned long data)
5137 + spin_lock_bh(&ulog_buffers[data].lock);
5138 + if (ulog_buffers[data].skb)
5140 + spin_unlock_bh(&ulog_buffers[data].lock);
5143 +static struct sk_buff *ulog_alloc_skb(unsigned int size)
5145 + struct sk_buff *skb;
5147 + skb = alloc_skb(nlbufsiz, GFP_ATOMIC);
5149 + PRINTR(KERN_ERR "ebt_ulog: can't alloc whole buffer "
5150 + "of size %ub!\n", nlbufsiz);
5151 + if (size < nlbufsiz) {
5152 + /* try to allocate only as much as we need for
5153 + * current packet */
5154 + skb = alloc_skb(size, GFP_ATOMIC);
5156 + PRINTR(KERN_ERR "ebt_ulog: can't even allocate "
5157 + "buffer of size %ub\n", size);
5164 +static void ebt_ulog(const struct sk_buff *skb, unsigned int hooknr,
5165 + const struct net_device *in, const struct net_device *out,
5166 + const void *data, unsigned int datalen)
5168 + ebt_ulog_packet_msg_t *pm;
5169 + size_t size, copy_len;
5170 + struct nlmsghdr *nlh;
5171 + struct ebt_ulog_info *loginfo = (struct ebt_ulog_info *)data;
5172 + unsigned int group = loginfo->nlgroup;
5173 + ebt_ulog_buff_t *ub = &ulog_buffers[group];
5174 + spinlock_t *lock = &ub->lock;
5176 + if ((loginfo->cprange == 0) ||
5177 + (loginfo->cprange > skb->len + ETH_HLEN))
5178 + copy_len = skb->len + ETH_HLEN;
5180 + copy_len = loginfo->cprange;
5182 + size = NLMSG_SPACE(sizeof(*pm) + copy_len);
5184 + spin_lock_bh(lock);
5187 + if (!(ub->skb = ulog_alloc_skb(size)))
5188 + goto alloc_failure;
5189 + } else if (size > skb_tailroom(ub->skb)) {
5192 + if (!(ub->skb = ulog_alloc_skb(size)))
5193 + goto alloc_failure;
5196 + nlh = NLMSG_PUT(ub->skb, 0, ub->qlen, 0,
5197 + size - NLMSG_ALIGN(sizeof(*nlh)));
5200 + pm = NLMSG_DATA(nlh);
5202 + /* Fill in the ulog data */
5203 + do_gettimeofday(&pm->stamp);
5204 + if (ub->qlen == 1)
5205 + ub->skb->stamp = pm->stamp;
5206 + pm->data_len = copy_len;
5207 + pm->mark = skb->nfmark;
5208 + pm->hook = hooknr;
5209 + if (loginfo->prefix != NULL)
5210 + strcpy(pm->prefix, loginfo->prefix);
5212 + *(pm->prefix) = '\0';
5215 + strcpy(pm->physindev, in->name);
5216 + strcpy(pm->indev, in->br_port->br->dev.name);
5218 + pm->indev[0] = pm->physindev[0] = '\0';
5221 + strcpy(pm->physoutdev, out->name);
5222 + strcpy(pm->outdev, out->br_port->br->dev.name);
5224 + pm->outdev[0] = pm->physoutdev[0] = '\0';
5226 + if (skb_copy_bits(skb, -ETH_HLEN, pm->data, copy_len) < 0)
5230 + ub->lastnlh->nlmsg_flags |= NLM_F_MULTI;
5232 + ub->lastnlh = nlh;
5234 + if (ub->qlen >= loginfo->qthreshold)
5236 + else if (!timer_pending(&ub->timer)) {
5237 + ub->timer.expires = jiffies + flushtimeout * HZ / 100;
5238 + add_timer(&ub->timer);
5242 + spin_unlock_bh(lock);
5247 + PRINTR(KERN_ERR "ebt_ULOG: error during NLMSG_PUT.\n");
5253 +static int ebt_ulog_check(const char *tablename, unsigned int hookmask,
5254 + const struct ebt_entry *e, void *data, unsigned int datalen)
5256 + struct ebt_ulog_info *loginfo = (struct ebt_ulog_info *)data;
5258 + if (datalen != EBT_ALIGN(sizeof(struct ebt_ulog_info)) ||
5259 + loginfo->nlgroup > 31)
5262 + loginfo->prefix[EBT_ULOG_PREFIX_LEN - 1] = '\0';
5264 + if (loginfo->qthreshold > EBT_ULOG_MAX_QLEN)
5265 + loginfo->qthreshold = EBT_ULOG_MAX_QLEN;
5270 +static struct ebt_watcher ulog = {
5271 + {NULL, NULL}, EBT_ULOG_WATCHER, ebt_ulog, ebt_ulog_check, NULL,
5275 +static int __init init(void)
5279 + if (nlbufsiz >= 128*1024) {
5280 + printk(KERN_NOTICE "ebt_ulog: Netlink buffer has to be <= 128kB,"
5281 + " please try a smaller nlbufsiz parameter.\n");
5285 + /* initialize ulog_buffers */
5286 + for (i = 0; i < EBT_ULOG_MAXNLGROUPS; i++) {
5287 + init_timer(&ulog_buffers[i].timer);
5288 + ulog_buffers[i].timer.function = ulog_timer;
5289 + ulog_buffers[i].timer.data = i;
5290 + ulog_buffers[i].lock = SPIN_LOCK_UNLOCKED;
5293 + ebtlognl = netlink_kernel_create(NETLINK_NFLOG, NULL);
5296 + else if ((ret = ebt_register_watcher(&ulog)))
5297 + sock_release(ebtlognl->socket);
5302 +static void __exit fini(void)
5304 + ebt_ulog_buff_t *ub;
5307 + ebt_unregister_watcher(&ulog);
5308 + for (i = 0; i < EBT_ULOG_MAXNLGROUPS; i++) {
5309 + ub = &ulog_buffers[i];
5310 + if (timer_pending(&ub->timer))
5311 + del_timer(&ub->timer);
5312 + spin_lock_bh(&ub->lock);
5314 + kfree_skb(ub->skb);
5317 + spin_unlock_bh(&ub->lock);
5319 + sock_release(ebtlognl->socket);
5324 +MODULE_LICENSE("GPL");
5325 +MODULE_AUTHOR("Bart De Schuymer <bdschuym@pandora.be>");
5326 +MODULE_DESCRIPTION("ebtables userspace logging module for bridged Ethernet"
5328 diff -Nur linux-mips-cvs/net/bridge/netfilter/ebt_vlan.c linux-ebtables/net/bridge/netfilter/ebt_vlan.c
5329 --- linux-mips-cvs/net/bridge/netfilter/ebt_vlan.c 1970-01-01 01:00:00.000000000 +0100
5330 +++ linux-ebtables/net/bridge/netfilter/ebt_vlan.c 2005-02-07 05:52:50.000000000 +0100
5333 + * Description: EBTables 802.1Q match extension kernelspace module.
5334 + * Authors: Nick Fedchik <nick@fedchik.org.ua>
5335 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
5337 + * This program is free software; you can redistribute it and/or modify
5338 + * it under the terms of the GNU General Public License as published by
5339 + * the Free Software Foundation; either version 2 of the License, or
5340 + * (at your option) any later version.
5342 + * This program is distributed in the hope that it will be useful,
5343 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5344 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5345 + * GNU General Public License for more details.
5347 + * You should have received a copy of the GNU General Public License
5348 + * along with this program; if not, write to the Free Software
5349 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
5352 +#include <linux/if_ether.h>
5353 +#include <linux/if_vlan.h>
5354 +#include <linux/module.h>
5355 +#include <linux/netfilter_bridge/ebtables.h>
5356 +#include <linux/netfilter_bridge/ebt_vlan.h>
5358 +static unsigned char debug;
5359 +#define MODULE_VERSION "0.6"
5361 +MODULE_PARM(debug, "0-1b");
5362 +MODULE_PARM_DESC(debug, "debug=1 is turn on debug messages");
5363 +MODULE_AUTHOR("Nick Fedchik <nick@fedchik.org.ua>");
5364 +MODULE_DESCRIPTION("802.1Q match module (ebtables extension), v"
5366 +MODULE_LICENSE("GPL");
5369 +#define DEBUG_MSG(args...) if (debug) printk (KERN_DEBUG "ebt_vlan: " args)
5370 +#define INV_FLAG(_inv_flag_) (info->invflags & _inv_flag_) ? "!" : ""
5371 +#define GET_BITMASK(_BIT_MASK_) info->bitmask & _BIT_MASK_
5372 +#define SET_BITMASK(_BIT_MASK_) info->bitmask |= _BIT_MASK_
5373 +#define EXIT_ON_MISMATCH(_MATCH_,_MASK_) if (!((info->_MATCH_ == _MATCH_)^!!(info->invflags & _MASK_))) return 1;
5376 + * Function description: ebt_filter_vlan() is main engine for
5377 + * checking passed 802.1Q frame according to
5378 + * the passed extension parameters (in the *data buffer)
5379 + * ebt_filter_vlan() is called after successfull check the rule params
5380 + * by ebt_check_vlan() function.
5382 + * const struct sk_buff *skb - pointer to passed ethernet frame buffer
5383 + * const void *data - pointer to passed extension parameters
5384 + * unsigned int datalen - length of passed *data buffer
5385 + * const struct net_device *in -
5386 + * const struct net_device *out -
5387 + * const struct ebt_counter *c -
5388 + * Returned values:
5389 + * 0 - ok (all rule params matched)
5390 + * 1 - miss (rule params not acceptable to the parsed frame)
5393 +ebt_filter_vlan(const struct sk_buff *skb,
5394 + const struct net_device *in,
5395 + const struct net_device *out,
5396 + const void *data, unsigned int datalen)
5398 + struct ebt_vlan_info *info = (struct ebt_vlan_info *) data; /* userspace data */
5399 + struct vlan_ethhdr *frame = (struct vlan_ethhdr *) skb->mac.raw; /* Passed tagged frame */
5401 + unsigned short TCI; /* Whole TCI, given from parsed frame */
5402 + unsigned short id; /* VLAN ID, given from frame TCI */
5403 + unsigned char prio; /* user_priority, given from frame TCI */
5404 + unsigned short encap; /* VLAN encapsulated Type/Length field, given from orig frame */
5407 + * Tag Control Information (TCI) consists of the following elements:
5408 + * - User_priority. The user_priority field is three bits in length,
5409 + * interpreted as a binary number.
5410 + * - Canonical Format Indicator (CFI). The Canonical Format Indicator
5411 + * (CFI) is a single bit flag value. Currently ignored.
5412 + * - VLAN Identifier (VID). The VID is encoded as
5413 + * an unsigned binary number.
5415 + TCI = ntohs(frame->h_vlan_TCI);
5416 + id = TCI & VLAN_VID_MASK;
5417 + prio = (TCI >> 13) & 0x7;
5418 + encap = frame->h_vlan_encapsulated_proto;
5421 + * Checking VLAN Identifier (VID)
5423 + if (GET_BITMASK(EBT_VLAN_ID)) { /* Is VLAN ID parsed? */
5424 + EXIT_ON_MISMATCH(id, EBT_VLAN_ID);
5427 + * Checking user_priority
5429 + if (GET_BITMASK(EBT_VLAN_PRIO)) { /* Is VLAN user_priority parsed? */
5430 + EXIT_ON_MISMATCH(prio, EBT_VLAN_PRIO);
5433 + * Checking Encapsulated Proto (Length/Type) field
5435 + if (GET_BITMASK(EBT_VLAN_ENCAP)) { /* Is VLAN Encap parsed? */
5436 + EXIT_ON_MISMATCH(encap, EBT_VLAN_ENCAP);
5439 + * All possible extension parameters was parsed.
5440 + * If rule never returned by missmatch, then all ok.
5446 + * Function description: ebt_vlan_check() is called when userspace
5447 + * delivers the table entry to the kernel,
5448 + * and to check that userspace doesn't give a bad table.
5450 + * const char *tablename - table name string
5451 + * unsigned int hooknr - hook number
5452 + * const struct ebt_entry *e - ebtables entry basic set
5453 + * const void *data - pointer to passed extension parameters
5454 + * unsigned int datalen - length of passed *data buffer
5455 + * Returned values:
5456 + * 0 - ok (all delivered rule params are correct)
5457 + * 1 - miss (rule params is out of range, invalid, incompatible, etc.)
5460 +ebt_check_vlan(const char *tablename,
5461 + unsigned int hooknr,
5462 + const struct ebt_entry *e, void *data, unsigned int datalen)
5464 + struct ebt_vlan_info *info = (struct ebt_vlan_info *) data;
5467 + * Parameters buffer overflow check
5469 + if (datalen != EBT_ALIGN(sizeof(struct ebt_vlan_info))) {
5471 + ("passed size %d is not eq to ebt_vlan_info (%d)\n",
5472 + datalen, sizeof(struct ebt_vlan_info));
5477 + * Is it 802.1Q frame checked?
5479 + if (e->ethproto != __constant_htons(ETH_P_8021Q)) {
5481 + ("passed entry proto %2.4X is not 802.1Q (8100)\n",
5482 + (unsigned short) ntohs(e->ethproto));
5487 + * Check for bitmask range
5488 + * True if even one bit is out of mask
5490 + if (info->bitmask & ~EBT_VLAN_MASK) {
5491 + DEBUG_MSG("bitmask %2X is out of mask (%2X)\n",
5492 + info->bitmask, EBT_VLAN_MASK);
5497 + * Check for inversion flags range
5499 + if (info->invflags & ~EBT_VLAN_MASK) {
5500 + DEBUG_MSG("inversion flags %2X is out of mask (%2X)\n",
5501 + info->invflags, EBT_VLAN_MASK);
5506 + * Reserved VLAN ID (VID) values
5507 + * -----------------------------
5508 + * 0 - The null VLAN ID.
5509 + * 1 - The default Port VID (PVID)
5510 + * 0x0FFF - Reserved for implementation use.
5511 + * if_vlan.h: VLAN_GROUP_ARRAY_LEN 4096.
5513 + if (GET_BITMASK(EBT_VLAN_ID)) { /* when vlan-id param was spec-ed */
5514 + if (!!info->id) { /* if id!=0 => check vid range */
5515 + if (info->id > VLAN_GROUP_ARRAY_LEN) {
5517 + ("id %d is out of range (1-4096)\n",
5522 + * Note: This is valid VLAN-tagged frame point.
5523 + * Any value of user_priority are acceptable,
5524 + * but should be ignored according to 802.1Q Std.
5525 + * So we just drop the prio flag.
5527 + info->bitmask &= ~EBT_VLAN_PRIO;
5530 + * Else, id=0 (null VLAN ID) => user_priority range (any?)
5534 + if (GET_BITMASK(EBT_VLAN_PRIO)) {
5535 + if ((unsigned char) info->prio > 7) {
5537 + ("prio %d is out of range (0-7)\n",
5543 + * Check for encapsulated proto range - it is possible to be
5544 + * any value for u_short range.
5545 + * if_ether.h: ETH_ZLEN 60 - Min. octets in frame sans FCS
5547 + if (GET_BITMASK(EBT_VLAN_ENCAP)) {
5548 + if ((unsigned short) ntohs(info->encap) < ETH_ZLEN) {
5550 + ("encap frame length %d is less than minimal\n",
5551 + ntohs(info->encap));
5559 +static struct ebt_match filter_vlan = {
5569 + * Module initialization function.
5571 +static int __init init(void)
5573 + DEBUG_MSG("ebtables 802.1Q extension module v"
5574 + MODULE_VERSION "\n");
5575 + DEBUG_MSG("module debug=%d\n", !!debug);
5576 + return ebt_register_match(&filter_vlan);
5580 + * Module "finalization" function
5582 +static void __exit fini(void)
5584 + ebt_unregister_match(&filter_vlan);
5591 diff -Nur linux-mips-cvs/net/bridge/netfilter/ebtable_broute.c linux-ebtables/net/bridge/netfilter/ebtable_broute.c
5592 --- linux-mips-cvs/net/bridge/netfilter/ebtable_broute.c 1970-01-01 01:00:00.000000000 +0100
5593 +++ linux-ebtables/net/bridge/netfilter/ebtable_broute.c 2005-02-07 05:52:50.000000000 +0100
5599 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
5603 + * This table lets you choose between routing and bridging for frames
5604 + * entering on a bridge enslaved nic. This table is traversed before any
5605 + * other ebtables table. See net/bridge/br_input.c.
5608 +#include <linux/netfilter_bridge/ebtables.h>
5609 +#include <linux/module.h>
5610 +#include <linux/if_bridge.h>
5611 +#include <linux/brlock.h>
5613 +// EBT_ACCEPT means the frame will be bridged
5614 +// EBT_DROP means the frame will be routed
5615 +static struct ebt_entries initial_chain =
5616 + {0, "BROUTING", 0, EBT_ACCEPT, 0};
5618 +static struct ebt_replace initial_table =
5620 + "broute", 1 << NF_BR_BROUTING, 0, sizeof(struct ebt_entries),
5621 + { [NF_BR_BROUTING]&initial_chain}, 0, NULL, (char *)&initial_chain
5624 +static int check(const struct ebt_table_info *info, unsigned int valid_hooks)
5626 + if (valid_hooks & ~(1 << NF_BR_BROUTING))
5631 +static struct ebt_table broute_table =
5633 + {NULL, NULL}, "broute", &initial_table, 1 << NF_BR_BROUTING,
5634 + RW_LOCK_UNLOCKED, check, NULL
5637 +static int ebt_broute(struct sk_buff **pskb)
5641 + ret = ebt_do_table(NF_BR_BROUTING, pskb, (*pskb)->dev, NULL,
5643 + if (ret == NF_DROP)
5644 + return 1; // route it
5645 + return 0; // bridge it
5648 +static int __init init(void)
5652 + ret = ebt_register_table(&broute_table);
5655 + br_write_lock_bh(BR_NETPROTO_LOCK);
5657 + br_should_route_hook = ebt_broute;
5658 + br_write_unlock_bh(BR_NETPROTO_LOCK);
5662 +static void __exit fini(void)
5664 + br_write_lock_bh(BR_NETPROTO_LOCK);
5665 + br_should_route_hook = NULL;
5666 + br_write_unlock_bh(BR_NETPROTO_LOCK);
5667 + ebt_unregister_table(&broute_table);
5673 +MODULE_LICENSE("GPL");
5674 diff -Nur linux-mips-cvs/net/bridge/netfilter/ebtable_filter.c linux-ebtables/net/bridge/netfilter/ebtable_filter.c
5675 --- linux-mips-cvs/net/bridge/netfilter/ebtable_filter.c 1970-01-01 01:00:00.000000000 +0100
5676 +++ linux-ebtables/net/bridge/netfilter/ebtable_filter.c 2005-02-07 05:52:50.000000000 +0100
5682 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
5688 +#include <linux/netfilter_bridge/ebtables.h>
5689 +#include <linux/module.h>
5691 +#define FILTER_VALID_HOOKS ((1 << NF_BR_LOCAL_IN) | (1 << NF_BR_FORWARD) | \
5692 + (1 << NF_BR_LOCAL_OUT))
5694 +static struct ebt_entries initial_chains[] =
5696 + {0, "INPUT", 0, EBT_ACCEPT, 0},
5697 + {0, "FORWARD", 0, EBT_ACCEPT, 0},
5698 + {0, "OUTPUT", 0, EBT_ACCEPT, 0}
5701 +static struct ebt_replace initial_table =
5703 + "filter", FILTER_VALID_HOOKS, 0, 3 * sizeof(struct ebt_entries),
5704 + { [NF_BR_LOCAL_IN]&initial_chains[0], [NF_BR_FORWARD]&initial_chains[1],
5705 + [NF_BR_LOCAL_OUT]&initial_chains[2] }, 0, NULL, (char *)initial_chains
5708 +static int check(const struct ebt_table_info *info, unsigned int valid_hooks)
5710 + if (valid_hooks & ~FILTER_VALID_HOOKS)
5715 +static struct ebt_table frame_filter =
5717 + {NULL, NULL}, "filter", &initial_table, FILTER_VALID_HOOKS,
5718 + RW_LOCK_UNLOCKED, check, NULL
5721 +static unsigned int
5722 +ebt_hook (unsigned int hook, struct sk_buff **pskb, const struct net_device *in,
5723 + const struct net_device *out, int (*okfn)(struct sk_buff *))
5725 + return ebt_do_table(hook, pskb, in, out, &frame_filter);
5728 +static struct nf_hook_ops ebt_ops_filter[] = {
5729 + { { NULL, NULL }, ebt_hook, PF_BRIDGE, NF_BR_LOCAL_IN,
5730 + NF_BR_PRI_FILTER_BRIDGED},
5731 + { { NULL, NULL }, ebt_hook, PF_BRIDGE, NF_BR_FORWARD,
5732 + NF_BR_PRI_FILTER_BRIDGED},
5733 + { { NULL, NULL }, ebt_hook, PF_BRIDGE, NF_BR_LOCAL_OUT,
5734 + NF_BR_PRI_FILTER_OTHER}
5737 +static int __init init(void)
5741 + ret = ebt_register_table(&frame_filter);
5744 + for (i = 0; i < sizeof(ebt_ops_filter) / sizeof(ebt_ops_filter[0]); i++)
5745 + if ((ret = nf_register_hook(&ebt_ops_filter[i])) < 0)
5749 + for (j = 0; j < i; j++)
5750 + nf_unregister_hook(&ebt_ops_filter[j]);
5751 + ebt_unregister_table(&frame_filter);
5755 +static void __exit fini(void)
5759 + for (i = 0; i < sizeof(ebt_ops_filter) / sizeof(ebt_ops_filter[0]); i++)
5760 + nf_unregister_hook(&ebt_ops_filter[i]);
5761 + ebt_unregister_table(&frame_filter);
5767 +MODULE_LICENSE("GPL");
5768 diff -Nur linux-mips-cvs/net/bridge/netfilter/ebtable_nat.c linux-ebtables/net/bridge/netfilter/ebtable_nat.c
5769 --- linux-mips-cvs/net/bridge/netfilter/ebtable_nat.c 1970-01-01 01:00:00.000000000 +0100
5770 +++ linux-ebtables/net/bridge/netfilter/ebtable_nat.c 2005-02-07 05:52:50.000000000 +0100
5776 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
5782 +#include <linux/netfilter_bridge/ebtables.h>
5783 +#include <linux/module.h>
5784 +#define NAT_VALID_HOOKS ((1 << NF_BR_PRE_ROUTING) | (1 << NF_BR_LOCAL_OUT) | \
5785 + (1 << NF_BR_POST_ROUTING))
5787 +static struct ebt_entries initial_chains[] =
5789 + {0, "PREROUTING", 0, EBT_ACCEPT, 0},
5790 + {0, "OUTPUT", 0, EBT_ACCEPT, 0},
5791 + {0, "POSTROUTING", 0, EBT_ACCEPT, 0}
5794 +static struct ebt_replace initial_table =
5796 + "nat", NAT_VALID_HOOKS, 0, 3 * sizeof(struct ebt_entries),
5797 + { [NF_BR_PRE_ROUTING]&initial_chains[0], [NF_BR_LOCAL_OUT]&initial_chains[1],
5798 + [NF_BR_POST_ROUTING]&initial_chains[2] }, 0, NULL, (char *)initial_chains
5801 +static int check(const struct ebt_table_info *info, unsigned int valid_hooks)
5803 + if (valid_hooks & ~NAT_VALID_HOOKS)
5808 +static struct ebt_table frame_nat =
5810 + {NULL, NULL}, "nat", &initial_table, NAT_VALID_HOOKS,
5811 + RW_LOCK_UNLOCKED, check, NULL
5814 +static unsigned int
5815 +ebt_nat_dst(unsigned int hook, struct sk_buff **pskb, const struct net_device *in
5816 + , const struct net_device *out, int (*okfn)(struct sk_buff *))
5818 + return ebt_do_table(hook, pskb, in, out, &frame_nat);
5821 +static unsigned int
5822 +ebt_nat_src(unsigned int hook, struct sk_buff **pskb, const struct net_device *in
5823 + , const struct net_device *out, int (*okfn)(struct sk_buff *))
5825 + return ebt_do_table(hook, pskb, in, out, &frame_nat);
5828 +static struct nf_hook_ops ebt_ops_nat[] = {
5829 + { { NULL, NULL }, ebt_nat_dst, PF_BRIDGE, NF_BR_LOCAL_OUT,
5830 + NF_BR_PRI_NAT_DST_OTHER},
5831 + { { NULL, NULL }, ebt_nat_src, PF_BRIDGE, NF_BR_POST_ROUTING,
5832 + NF_BR_PRI_NAT_SRC},
5833 + { { NULL, NULL }, ebt_nat_dst, PF_BRIDGE, NF_BR_PRE_ROUTING,
5834 + NF_BR_PRI_NAT_DST_BRIDGED},
5837 +static int __init init(void)
5841 + ret = ebt_register_table(&frame_nat);
5844 + for (i = 0; i < sizeof(ebt_ops_nat) / sizeof(ebt_ops_nat[0]); i++)
5845 + if ((ret = nf_register_hook(&ebt_ops_nat[i])) < 0)
5849 + for (j = 0; j < i; j++)
5850 + nf_unregister_hook(&ebt_ops_nat[j]);
5851 + ebt_unregister_table(&frame_nat);
5855 +static void __exit fini(void)
5859 + for (i = 0; i < sizeof(ebt_ops_nat) / sizeof(ebt_ops_nat[0]); i++)
5860 + nf_unregister_hook(&ebt_ops_nat[i]);
5861 + ebt_unregister_table(&frame_nat);
5867 +MODULE_LICENSE("GPL");
5868 diff -Nur linux-mips-cvs/net/bridge/netfilter/ebtables.c linux-ebtables/net/bridge/netfilter/ebtables.c
5869 --- linux-mips-cvs/net/bridge/netfilter/ebtables.c 1970-01-01 01:00:00.000000000 +0100
5870 +++ linux-ebtables/net/bridge/netfilter/ebtables.c 2005-02-07 05:52:50.000000000 +0100
5876 + * Bart De Schuymer <bart.de.schuymer@pandora.be>
5878 + * ebtables.c,v 2.0, July, 2002
5880 + * This code is stongly inspired on the iptables code which is
5881 + * Copyright (C) 1999 Paul `Rusty' Russell & Michael J. Neuling
5883 + * This program is free software; you can redistribute it and/or
5884 + * modify it under the terms of the GNU General Public License
5885 + * as published by the Free Software Foundation; either version
5886 + * 2 of the License, or (at your option) any later version.
5889 +// used for print_string
5890 +#include <linux/sched.h>
5891 +#include <linux/tty.h>
5893 +#include <linux/kmod.h>
5894 +#include <linux/module.h>
5895 +#include <linux/vmalloc.h>
5896 +#include <linux/netfilter_bridge/ebtables.h>
5897 +#include <linux/spinlock.h>
5898 +#include <asm/uaccess.h>
5899 +#include <linux/smp.h>
5900 +#include <net/sock.h>
5901 +// needed for logical [in,out]-dev filtering
5902 +#include "../br_private.h"
5905 +#define ASSERT_READ_LOCK(x)
5906 +#define ASSERT_WRITE_LOCK(x)
5907 +#include <linux/netfilter_ipv4/listhelp.h>
5909 +#if 0 // use this for remote debugging
5910 +// Copyright (C) 1998 by Ori Pomerantz
5911 +// Print the string to the appropriate tty, the one
5912 +// the current task uses
5913 +static void print_string(char *str)
5915 + struct tty_struct *my_tty;
5917 + /* The tty for the current task */
5918 + my_tty = current->tty;
5919 + if (my_tty != NULL) {
5920 + (*(my_tty->driver).write)(my_tty, 0, str, strlen(str));
5921 + (*(my_tty->driver).write)(my_tty, 0, "\015\012", 2);
5925 +#define BUGPRINT(args) print_string(args);
5927 +#define BUGPRINT(format, args...) printk("kernel msg: ebtables bug: please "\
5928 + "report to author: "format, ## args)
5929 +// #define BUGPRINT(format, args...)
5931 +#define MEMPRINT(format, args...) printk("kernel msg: ebtables "\
5932 + ": out of memory: "format, ## args)
5933 +// #define MEMPRINT(format, args...)
5937 +// Each cpu has its own set of counters, so there is no need for write_lock in
5939 +// For reading or updating the counters, the user context needs to
5940 +// get a write_lock
5942 +// The size of each set of counters is altered to get cache alignment
5943 +#define SMP_ALIGN(x) (((x) + SMP_CACHE_BYTES-1) & ~(SMP_CACHE_BYTES-1))
5944 +#define COUNTER_OFFSET(n) (SMP_ALIGN(n * sizeof(struct ebt_counter)))
5945 +#define COUNTER_BASE(c, n, cpu) ((struct ebt_counter *)(((char *)c) + \
5946 + COUNTER_OFFSET(n) * cpu))
5950 +static DECLARE_MUTEX(ebt_mutex);
5951 +static LIST_HEAD(ebt_tables);
5952 +static LIST_HEAD(ebt_targets);
5953 +static LIST_HEAD(ebt_matches);
5954 +static LIST_HEAD(ebt_watchers);
5956 +static struct ebt_target ebt_standard_target =
5957 +{ {NULL, NULL}, EBT_STANDARD_TARGET, NULL, NULL, NULL, NULL};
5959 +static inline int ebt_do_watcher (struct ebt_entry_watcher *w,
5960 + const struct sk_buff *skb, unsigned int hooknr, const struct net_device *in,
5961 + const struct net_device *out)
5963 + w->u.watcher->watcher(skb, hooknr, in, out, w->data,
5965 + // watchers don't give a verdict
5969 +static inline int ebt_do_match (struct ebt_entry_match *m,
5970 + const struct sk_buff *skb, const struct net_device *in,
5971 + const struct net_device *out)
5973 + return m->u.match->match(skb, in, out, m->data,
5977 +static inline int ebt_dev_check(char *entry, const struct net_device *device)
5980 + char *devname = device->name;
5982 + if (*entry == '\0')
5986 + /* 1 is the wildcard token */
5987 + while (entry[i] != '\0' && entry[i] != 1 && entry[i] == devname[i])
5989 + return (devname[i] != entry[i] && entry[i] != 1);
5992 +#define FWINV2(bool,invflg) ((bool) ^ !!(e->invflags & invflg))
5993 +// process standard matches
5994 +static inline int ebt_basic_match(struct ebt_entry *e, struct ethhdr *h,
5995 + const struct net_device *in, const struct net_device *out)
5999 + if (e->bitmask & EBT_802_3) {
6000 + if (FWINV2(ntohs(h->h_proto) >= 1536, EBT_IPROTO))
6002 + } else if (!(e->bitmask & EBT_NOPROTO) &&
6003 + FWINV2(e->ethproto != h->h_proto, EBT_IPROTO))
6006 + if (FWINV2(ebt_dev_check(e->in, in), EBT_IIN))
6008 + if (FWINV2(ebt_dev_check(e->out, out), EBT_IOUT))
6010 + if ((!in || !in->br_port) ? 0 : FWINV2(ebt_dev_check(
6011 + e->logical_in, &in->br_port->br->dev), EBT_ILOGICALIN))
6013 + if ((!out || !out->br_port) ? 0 : FWINV2(ebt_dev_check(
6014 + e->logical_out, &out->br_port->br->dev), EBT_ILOGICALOUT))
6017 + if (e->bitmask & EBT_SOURCEMAC) {
6019 + for (i = 0; i < 6; i++)
6020 + verdict |= (h->h_source[i] ^ e->sourcemac[i]) &
6022 + if (FWINV2(verdict != 0, EBT_ISOURCE) )
6025 + if (e->bitmask & EBT_DESTMAC) {
6027 + for (i = 0; i < 6; i++)
6028 + verdict |= (h->h_dest[i] ^ e->destmac[i]) &
6030 + if (FWINV2(verdict != 0, EBT_IDEST) )
6036 +// Do some firewalling
6037 +unsigned int ebt_do_table (unsigned int hook, struct sk_buff **pskb,
6038 + const struct net_device *in, const struct net_device *out,
6039 + struct ebt_table *table)
6042 + struct ebt_entry *point;
6043 + struct ebt_counter *counter_base, *cb_base;
6044 + struct ebt_entry_target *t;
6045 + int verdict, sp = 0;
6046 + struct ebt_chainstack *cs;
6047 + struct ebt_entries *chaininfo;
6049 + struct ebt_table_info *private = table->private;
6051 + read_lock_bh(&table->lock);
6052 + cb_base = COUNTER_BASE(private->counters, private->nentries,
6053 + cpu_number_map(smp_processor_id()));
6054 + if (private->chainstack)
6055 + cs = private->chainstack[cpu_number_map(smp_processor_id())];
6058 + chaininfo = private->hook_entry[hook];
6059 + nentries = private->hook_entry[hook]->nentries;
6060 + point = (struct ebt_entry *)(private->hook_entry[hook]->data);
6061 + counter_base = cb_base + private->hook_entry[hook]->counter_offset;
6062 + // base for chain jumps
6063 + base = private->entries;
6065 + while (i < nentries) {
6066 + if (ebt_basic_match(point, (**pskb).mac.ethernet, in, out))
6067 + goto letscontinue;
6069 + if (EBT_MATCH_ITERATE(point, ebt_do_match, *pskb, in, out) != 0)
6070 + goto letscontinue;
6072 + // increase counter
6073 + (*(counter_base + i)).pcnt++;
6074 + (*(counter_base + i)).bcnt+=(**pskb).len;
6076 + // these should only watch: not modify, nor tell us
6077 + // what to do with the packet
6078 + EBT_WATCHER_ITERATE(point, ebt_do_watcher, *pskb, hook, in,
6081 + t = (struct ebt_entry_target *)
6082 + (((char *)point) + point->target_offset);
6083 + // standard target
6084 + if (!t->u.target->target)
6085 + verdict = ((struct ebt_standard_target *)t)->verdict;
6087 + verdict = t->u.target->target(pskb, hook,
6088 + in, out, t->data, t->target_size);
6089 + if (verdict == EBT_ACCEPT) {
6090 + read_unlock_bh(&table->lock);
6093 + if (verdict == EBT_DROP) {
6094 + read_unlock_bh(&table->lock);
6097 + if (verdict == EBT_RETURN) {
6099 +#ifdef CONFIG_NETFILTER_DEBUG
6101 + BUGPRINT("RETURN on base chain");
6102 + // act like this is EBT_CONTINUE
6103 + goto letscontinue;
6107 + // put all the local variables right
6109 + chaininfo = cs[sp].chaininfo;
6110 + nentries = chaininfo->nentries;
6112 + counter_base = cb_base +
6113 + chaininfo->counter_offset;
6116 + if (verdict == EBT_CONTINUE)
6117 + goto letscontinue;
6118 +#ifdef CONFIG_NETFILTER_DEBUG
6119 + if (verdict < 0) {
6120 + BUGPRINT("bogus standard verdict\n");
6121 + read_unlock_bh(&table->lock);
6127 + cs[sp].chaininfo = chaininfo;
6128 + cs[sp].e = (struct ebt_entry *)
6129 + (((char *)point) + point->next_offset);
6131 + chaininfo = (struct ebt_entries *) (base + verdict);
6132 +#ifdef CONFIG_NETFILTER_DEBUG
6133 + if (chaininfo->distinguisher) {
6134 + BUGPRINT("jump to non-chain\n");
6135 + read_unlock_bh(&table->lock);
6139 + nentries = chaininfo->nentries;
6140 + point = (struct ebt_entry *)chaininfo->data;
6141 + counter_base = cb_base + chaininfo->counter_offset;
6145 + point = (struct ebt_entry *)
6146 + (((char *)point) + point->next_offset);
6150 + // I actually like this :)
6151 + if (chaininfo->policy == EBT_RETURN)
6153 + if (chaininfo->policy == EBT_ACCEPT) {
6154 + read_unlock_bh(&table->lock);
6157 + read_unlock_bh(&table->lock);
6161 +// If it succeeds, returns element and locks mutex
6162 +static inline void *
6163 +find_inlist_lock_noload(struct list_head *head, const char *name, int *error,
6164 + struct semaphore *mutex)
6168 + *error = down_interruptible(mutex);
6172 + ret = list_named_find(head, name);
6180 +#ifndef CONFIG_KMOD
6181 +#define find_inlist_lock(h,n,p,e,m) find_inlist_lock_noload((h),(n),(e),(m))
6184 +find_inlist_lock(struct list_head *head, const char *name, const char *prefix,
6185 + int *error, struct semaphore *mutex)
6189 + ret = find_inlist_lock_noload(head, name, error, mutex);
6191 + char modulename[EBT_FUNCTION_MAXNAMELEN + strlen(prefix) + 1];
6192 + strcpy(modulename, prefix);
6193 + strcat(modulename, name);
6194 + request_module(modulename);
6195 + ret = find_inlist_lock_noload(head, name, error, mutex);
6201 +static inline struct ebt_table *
6202 +find_table_lock(const char *name, int *error, struct semaphore *mutex)
6204 + return find_inlist_lock(&ebt_tables, name, "ebtable_", error, mutex);
6207 +static inline struct ebt_match *
6208 +find_match_lock(const char *name, int *error, struct semaphore *mutex)
6210 + return find_inlist_lock(&ebt_matches, name, "ebt_", error, mutex);
6213 +static inline struct ebt_watcher *
6214 +find_watcher_lock(const char *name, int *error, struct semaphore *mutex)
6216 + return find_inlist_lock(&ebt_watchers, name, "ebt_", error, mutex);
6219 +static inline struct ebt_target *
6220 +find_target_lock(const char *name, int *error, struct semaphore *mutex)
6222 + return find_inlist_lock(&ebt_targets, name, "ebt_", error, mutex);
6226 +ebt_check_match(struct ebt_entry_match *m, struct ebt_entry *e,
6227 + const char *name, unsigned int hookmask, unsigned int *cnt)
6229 + struct ebt_match *match;
6232 + if (((char *)m) + m->match_size + sizeof(struct ebt_entry_match) >
6233 + ((char *)e) + e->watchers_offset)
6235 + match = find_match_lock(m->u.name, &ret, &ebt_mutex);
6238 + m->u.match = match;
6240 + __MOD_INC_USE_COUNT(match->me);
6242 + if (match->check &&
6243 + match->check(name, hookmask, e, m->data, m->match_size) != 0) {
6244 + BUGPRINT("match->check failed\n");
6246 + __MOD_DEC_USE_COUNT(match->me);
6254 +ebt_check_watcher(struct ebt_entry_watcher *w, struct ebt_entry *e,
6255 + const char *name, unsigned int hookmask, unsigned int *cnt)
6257 + struct ebt_watcher *watcher;
6260 + if (((char *)w) + w->watcher_size + sizeof(struct ebt_entry_watcher) >
6261 + ((char *)e) + e->target_offset)
6263 + watcher = find_watcher_lock(w->u.name, &ret, &ebt_mutex);
6266 + w->u.watcher = watcher;
6268 + __MOD_INC_USE_COUNT(watcher->me);
6270 + if (watcher->check &&
6271 + watcher->check(name, hookmask, e, w->data, w->watcher_size) != 0) {
6272 + BUGPRINT("watcher->check failed\n");
6274 + __MOD_DEC_USE_COUNT(watcher->me);
6281 +// this one is very careful, as it is the first function
6282 +// to parse the userspace data
6284 +ebt_check_entry_size_and_hooks(struct ebt_entry *e,
6285 + struct ebt_table_info *newinfo, char *base, char *limit,
6286 + struct ebt_entries **hook_entries, unsigned int *n, unsigned int *cnt,
6287 + unsigned int *totalcnt, unsigned int *udc_cnt, unsigned int valid_hooks)
6291 + for (i = 0; i < NF_BR_NUMHOOKS; i++) {
6292 + if ((valid_hooks & (1 << i)) == 0)
6294 + if ( (char *)hook_entries[i] - base ==
6295 + (char *)e - newinfo->entries)
6298 + // beginning of a new chain
6299 + // if i == NF_BR_NUMHOOKS it must be a user defined chain
6300 + if (i != NF_BR_NUMHOOKS || !(e->bitmask & EBT_ENTRY_OR_ENTRIES)) {
6301 + if ((e->bitmask & EBT_ENTRY_OR_ENTRIES) != 0) {
6302 + // we make userspace set this right,
6303 + // so there is no misunderstanding
6304 + BUGPRINT("EBT_ENTRY_OR_ENTRIES shouldn't be set "
6305 + "in distinguisher\n");
6308 + // this checks if the previous chain has as many entries
6309 + // as it said it has
6311 + BUGPRINT("nentries does not equal the nr of entries "
6312 + "in the chain\n");
6315 + // before we look at the struct, be sure it is not too big
6316 + if ((char *)hook_entries[i] + sizeof(struct ebt_entries)
6318 + BUGPRINT("entries_size too small\n");
6321 + if (((struct ebt_entries *)e)->policy != EBT_DROP &&
6322 + ((struct ebt_entries *)e)->policy != EBT_ACCEPT) {
6323 + // only RETURN from udc
6324 + if (i != NF_BR_NUMHOOKS ||
6325 + ((struct ebt_entries *)e)->policy != EBT_RETURN) {
6326 + BUGPRINT("bad policy\n");
6330 + if (i == NF_BR_NUMHOOKS) // it's a user defined chain
6333 + newinfo->hook_entry[i] = (struct ebt_entries *)e;
6334 + if (((struct ebt_entries *)e)->counter_offset != *totalcnt) {
6335 + BUGPRINT("counter_offset != totalcnt");
6338 + *n = ((struct ebt_entries *)e)->nentries;
6342 + // a plain old entry, heh
6343 + if (sizeof(struct ebt_entry) > e->watchers_offset ||
6344 + e->watchers_offset > e->target_offset ||
6345 + e->target_offset >= e->next_offset) {
6346 + BUGPRINT("entry offsets not in right order\n");
6349 + // this is not checked anywhere else
6350 + if (e->next_offset - e->target_offset < sizeof(struct ebt_entry_target)) {
6351 + BUGPRINT("target size too small\n");
6360 +struct ebt_cl_stack
6362 + struct ebt_chainstack cs;
6364 + unsigned int hookmask;
6367 +// we need these positions to check that the jumps to a different part of the
6368 +// entries is a jump to the beginning of a new chain.
6370 +ebt_get_udc_positions(struct ebt_entry *e, struct ebt_table_info *newinfo,
6371 + struct ebt_entries **hook_entries, unsigned int *n, unsigned int valid_hooks,
6372 + struct ebt_cl_stack *udc)
6376 + // we're only interested in chain starts
6377 + if (e->bitmask & EBT_ENTRY_OR_ENTRIES)
6379 + for (i = 0; i < NF_BR_NUMHOOKS; i++) {
6380 + if ((valid_hooks & (1 << i)) == 0)
6382 + if (newinfo->hook_entry[i] == (struct ebt_entries *)e)
6385 + // only care about udc
6386 + if (i != NF_BR_NUMHOOKS)
6389 + udc[*n].cs.chaininfo = (struct ebt_entries *)e;
6390 + // these initialisations are depended on later in check_chainloops()
6392 + udc[*n].hookmask = 0;
6399 +ebt_cleanup_match(struct ebt_entry_match *m, unsigned int *i)
6401 + if (i && (*i)-- == 0)
6403 + if (m->u.match->destroy)
6404 + m->u.match->destroy(m->data, m->match_size);
6405 + if (m->u.match->me)
6406 + __MOD_DEC_USE_COUNT(m->u.match->me);
6412 +ebt_cleanup_watcher(struct ebt_entry_watcher *w, unsigned int *i)
6414 + if (i && (*i)-- == 0)
6416 + if (w->u.watcher->destroy)
6417 + w->u.watcher->destroy(w->data, w->watcher_size);
6418 + if (w->u.watcher->me)
6419 + __MOD_DEC_USE_COUNT(w->u.watcher->me);
6425 +ebt_cleanup_entry(struct ebt_entry *e, unsigned int *cnt)
6427 + struct ebt_entry_target *t;
6429 + if ((e->bitmask & EBT_ENTRY_OR_ENTRIES) == 0)
6432 + if (cnt && (*cnt)-- == 0)
6434 + EBT_WATCHER_ITERATE(e, ebt_cleanup_watcher, NULL);
6435 + EBT_MATCH_ITERATE(e, ebt_cleanup_match, NULL);
6436 + t = (struct ebt_entry_target *)(((char *)e) + e->target_offset);
6437 + if (t->u.target->destroy)
6438 + t->u.target->destroy(t->data, t->target_size);
6439 + if (t->u.target->me)
6440 + __MOD_DEC_USE_COUNT(t->u.target->me);
6446 +ebt_check_entry(struct ebt_entry *e, struct ebt_table_info *newinfo,
6447 + const char *name, unsigned int *cnt, unsigned int valid_hooks,
6448 + struct ebt_cl_stack *cl_s, unsigned int udc_cnt)
6450 + struct ebt_entry_target *t;
6451 + struct ebt_target *target;
6452 + unsigned int i, j, hook = 0, hookmask = 0;
6455 + // Don't mess with the struct ebt_entries
6456 + if ((e->bitmask & EBT_ENTRY_OR_ENTRIES) == 0)
6459 + if (e->bitmask & ~EBT_F_MASK) {
6460 + BUGPRINT("Unknown flag for bitmask\n");
6463 + if (e->invflags & ~EBT_INV_MASK) {
6464 + BUGPRINT("Unknown flag for inv bitmask\n");
6467 + if ( (e->bitmask & EBT_NOPROTO) && (e->bitmask & EBT_802_3) ) {
6468 + BUGPRINT("NOPROTO & 802_3 not allowed\n");
6471 + // what hook do we belong to?
6472 + for (i = 0; i < NF_BR_NUMHOOKS; i++) {
6473 + if ((valid_hooks & (1 << i)) == 0)
6475 + if ((char *)newinfo->hook_entry[i] < (char *)e)
6480 + // (1 << NF_BR_NUMHOOKS) tells the check functions the rule is on
6482 + if (i < NF_BR_NUMHOOKS)
6483 + hookmask = (1 << hook) | (1 << NF_BR_NUMHOOKS);
6485 + for (i = 0; i < udc_cnt; i++)
6486 + if ((char *)(cl_s[i].cs.chaininfo) > (char *)e)
6489 + hookmask = (1 << hook) | (1 << NF_BR_NUMHOOKS);
6491 + hookmask = cl_s[i - 1].hookmask;
6494 + ret = EBT_MATCH_ITERATE(e, ebt_check_match, e, name, hookmask, &i);
6496 + goto cleanup_matches;
6498 + ret = EBT_WATCHER_ITERATE(e, ebt_check_watcher, e, name, hookmask, &j);
6500 + goto cleanup_watchers;
6501 + t = (struct ebt_entry_target *)(((char *)e) + e->target_offset);
6502 + target = find_target_lock(t->u.name, &ret, &ebt_mutex);
6504 + goto cleanup_watchers;
6506 + __MOD_INC_USE_COUNT(target->me);
6509 + t->u.target = target;
6510 + if (t->u.target == &ebt_standard_target) {
6511 + if (e->target_offset + sizeof(struct ebt_standard_target) >
6513 + BUGPRINT("Standard target size too big\n");
6515 + goto cleanup_watchers;
6517 + if (((struct ebt_standard_target *)t)->verdict <
6518 + -NUM_STANDARD_TARGETS) {
6519 + BUGPRINT("Invalid standard target\n");
6521 + goto cleanup_watchers;
6523 + } else if ((e->target_offset + t->target_size +
6524 + sizeof(struct ebt_entry_target) > e->next_offset) ||
6525 + (t->u.target->check &&
6526 + t->u.target->check(name, hookmask, e, t->data, t->target_size) != 0)){
6527 + if (t->u.target->me)
6528 + __MOD_DEC_USE_COUNT(t->u.target->me);
6530 + goto cleanup_watchers;
6535 + EBT_WATCHER_ITERATE(e, ebt_cleanup_watcher, &j);
6537 + EBT_MATCH_ITERATE(e, ebt_cleanup_match, &i);
6541 +// checks for loops and sets the hook mask for udc
6542 +// the hook mask for udc tells us from which base chains the udc can be
6543 +// accessed. This mask is a parameter to the check() functions of the extensions
6544 +static int check_chainloops(struct ebt_entries *chain,
6545 + struct ebt_cl_stack *cl_s, unsigned int udc_cnt,
6546 + unsigned int hooknr, char *base)
6548 + int i, chain_nr = -1, pos = 0, nentries = chain->nentries, verdict;
6549 + struct ebt_entry *e = (struct ebt_entry *)chain->data;
6550 + struct ebt_entry_target *t;
6552 + while (pos < nentries || chain_nr != -1) {
6553 + // end of udc, go back one 'recursion' step
6554 + if (pos == nentries) {
6555 + // put back values of the time when this chain was called
6556 + e = cl_s[chain_nr].cs.e;
6557 + if (cl_s[chain_nr].from != -1)
6559 + cl_s[cl_s[chain_nr].from].cs.chaininfo->nentries;
6561 + nentries = chain->nentries;
6562 + pos = cl_s[chain_nr].cs.n;
6563 + // make sure we won't see a loop that isn't one
6564 + cl_s[chain_nr].cs.n = 0;
6565 + chain_nr = cl_s[chain_nr].from;
6566 + if (pos == nentries)
6569 + t = (struct ebt_entry_target *)
6570 + (((char *)e) + e->target_offset);
6571 + if (strcmp(t->u.name, EBT_STANDARD_TARGET))
6572 + goto letscontinue;
6573 + if (e->target_offset + sizeof(struct ebt_standard_target) >
6575 + BUGPRINT("Standard target size too big\n");
6578 + verdict = ((struct ebt_standard_target *)t)->verdict;
6579 + if (verdict >= 0) { // jump to another chain
6580 + struct ebt_entries *hlp2 =
6581 + (struct ebt_entries *)(base + verdict);
6582 + for (i = 0; i < udc_cnt; i++)
6583 + if (hlp2 == cl_s[i].cs.chaininfo)
6585 + // bad destination or loop
6586 + if (i == udc_cnt) {
6587 + BUGPRINT("bad destination\n");
6590 + if (cl_s[i].cs.n) {
6591 + BUGPRINT("loop\n");
6594 + // this can't be 0, so the above test is correct
6595 + cl_s[i].cs.n = pos + 1;
6597 + cl_s[i].cs.e = ((void *)e + e->next_offset);
6598 + e = (struct ebt_entry *)(hlp2->data);
6599 + nentries = hlp2->nentries;
6600 + cl_s[i].from = chain_nr;
6602 + // this udc is accessible from the base chain for hooknr
6603 + cl_s[i].hookmask |= (1 << hooknr);
6607 + e = (void *)e + e->next_offset;
6613 +// do the parsing of the table/chains/entries/matches/watchers/targets, heh
6614 +static int translate_table(struct ebt_replace *repl,
6615 + struct ebt_table_info *newinfo)
6617 + unsigned int i, j, k, udc_cnt;
6619 + struct ebt_cl_stack *cl_s = NULL; // used in the checking for chain loops
6622 + while (i < NF_BR_NUMHOOKS && !(repl->valid_hooks & (1 << i)))
6624 + if (i == NF_BR_NUMHOOKS) {
6625 + BUGPRINT("No valid hooks specified\n");
6628 + if (repl->hook_entry[i] != (struct ebt_entries *)repl->entries) {
6629 + BUGPRINT("Chains don't start at beginning\n");
6632 + // make sure chains are ordered after each other in same order
6633 + // as their corresponding hooks
6634 + for (j = i + 1; j < NF_BR_NUMHOOKS; j++) {
6635 + if (!(repl->valid_hooks & (1 << j)))
6637 + if ( repl->hook_entry[j] <= repl->hook_entry[i] ) {
6638 + BUGPRINT("Hook order must be followed\n");
6644 + for (i = 0; i < NF_BR_NUMHOOKS; i++)
6645 + newinfo->hook_entry[i] = NULL;
6647 + newinfo->entries_size = repl->entries_size;
6648 + newinfo->nentries = repl->nentries;
6650 + // do some early checkings and initialize some things
6651 + i = 0; // holds the expected nr. of entries for the chain
6652 + j = 0; // holds the up to now counted entries for the chain
6653 + k = 0; // holds the total nr. of entries, should equal
6654 + // newinfo->nentries afterwards
6655 + udc_cnt = 0; // will hold the nr. of user defined chains (udc)
6656 + ret = EBT_ENTRY_ITERATE(newinfo->entries, newinfo->entries_size,
6657 + ebt_check_entry_size_and_hooks, newinfo, repl->entries,
6658 + repl->entries + repl->entries_size, repl->hook_entry, &i, &j, &k,
6659 + &udc_cnt, repl->valid_hooks);
6665 + BUGPRINT("nentries does not equal the nr of entries in the "
6666 + "(last) chain\n");
6669 + if (k != newinfo->nentries) {
6670 + BUGPRINT("Total nentries is wrong\n");
6674 + // check if all valid hooks have a chain
6675 + for (i = 0; i < NF_BR_NUMHOOKS; i++) {
6676 + if (newinfo->hook_entry[i] == NULL &&
6677 + (repl->valid_hooks & (1 << i))) {
6678 + BUGPRINT("Valid hook without chain\n");
6683 + // Get the location of the udc, put them in an array
6684 + // While we're at it, allocate the chainstack
6686 + // this will get free'd in do_replace()/ebt_register_table()
6687 + // if an error occurs
6688 + newinfo->chainstack = (struct ebt_chainstack **)
6689 + vmalloc(smp_num_cpus * sizeof(struct ebt_chainstack));
6690 + if (!newinfo->chainstack)
6692 + for (i = 0; i < smp_num_cpus; i++) {
6693 + newinfo->chainstack[i] =
6694 + vmalloc(udc_cnt * sizeof(struct ebt_chainstack));
6695 + if (!newinfo->chainstack[i]) {
6697 + vfree(newinfo->chainstack[--i]);
6698 + vfree(newinfo->chainstack);
6699 + newinfo->chainstack = NULL;
6704 + cl_s = (struct ebt_cl_stack *)
6705 + vmalloc(udc_cnt * sizeof(struct ebt_cl_stack));
6708 + i = 0; // the i'th udc
6709 + EBT_ENTRY_ITERATE(newinfo->entries, newinfo->entries_size,
6710 + ebt_get_udc_positions, newinfo, repl->hook_entry, &i,
6711 + repl->valid_hooks, cl_s);
6713 + if (i != udc_cnt) {
6714 + BUGPRINT("i != udc_cnt\n");
6720 + // Check for loops
6721 + for (i = 0; i < NF_BR_NUMHOOKS; i++)
6722 + if (repl->valid_hooks & (1 << i))
6723 + if (check_chainloops(newinfo->hook_entry[i],
6724 + cl_s, udc_cnt, i, newinfo->entries)) {
6730 + // we now know the following (along with E=mc²):
6731 + // - the nr of entries in each chain is right
6732 + // - the size of the allocated space is right
6733 + // - all valid hooks have a corresponding chain
6734 + // - there are no loops
6735 + // - wrong data can still be on the level of a single entry
6736 + // - could be there are jumps to places that are not the
6737 + // beginning of a chain. This can only occur in chains that
6738 + // are not accessible from any base chains, so we don't care.
6740 + // used to know what we need to clean up if something goes wrong
6742 + ret = EBT_ENTRY_ITERATE(newinfo->entries, newinfo->entries_size,
6743 + ebt_check_entry, newinfo, repl->name, &i, repl->valid_hooks,
6746 + EBT_ENTRY_ITERATE(newinfo->entries, newinfo->entries_size,
6747 + ebt_cleanup_entry, &i);
6754 +// called under write_lock
6755 +static void get_counters(struct ebt_counter *oldcounters,
6756 + struct ebt_counter *counters, unsigned int nentries)
6759 + struct ebt_counter *counter_base;
6761 + // counters of cpu 0
6762 + memcpy(counters, oldcounters,
6763 + sizeof(struct ebt_counter) * nentries);
6764 + // add other counters to those of cpu 0
6765 + for (cpu = 1; cpu < smp_num_cpus; cpu++) {
6766 + counter_base = COUNTER_BASE(oldcounters, nentries, cpu);
6767 + for (i = 0; i < nentries; i++) {
6768 + counters[i].pcnt += counter_base[i].pcnt;
6769 + counters[i].bcnt += counter_base[i].bcnt;
6774 +// replace the table
6775 +static int do_replace(void *user, unsigned int len)
6777 + int ret, i, countersize;
6778 + struct ebt_table_info *newinfo;
6779 + struct ebt_replace tmp;
6780 + struct ebt_table *t;
6781 + struct ebt_counter *counterstmp = NULL;
6782 + // used to be able to unlock earlier
6783 + struct ebt_table_info *table;
6785 + if (copy_from_user(&tmp, user, sizeof(tmp)) != 0)
6788 + if (len != sizeof(tmp) + tmp.entries_size) {
6789 + BUGPRINT("Wrong len argument\n");
6793 + if (tmp.entries_size == 0) {
6794 + BUGPRINT("Entries_size never zero\n");
6797 + countersize = COUNTER_OFFSET(tmp.nentries) * smp_num_cpus;
6798 + newinfo = (struct ebt_table_info *)
6799 + vmalloc(sizeof(struct ebt_table_info) + countersize);
6804 + memset(newinfo->counters, 0, countersize);
6806 + newinfo->entries = (char *)vmalloc(tmp.entries_size);
6807 + if (!newinfo->entries) {
6809 + goto free_newinfo;
6811 + if (copy_from_user(
6812 + newinfo->entries, tmp.entries, tmp.entries_size) != 0) {
6813 + BUGPRINT("Couldn't copy entries from userspace\n");
6815 + goto free_entries;
6818 + // the user wants counters back
6819 + // the check on the size is done later, when we have the lock
6820 + if (tmp.num_counters) {
6821 + counterstmp = (struct ebt_counter *)
6822 + vmalloc(tmp.num_counters * sizeof(struct ebt_counter));
6823 + if (!counterstmp) {
6825 + goto free_entries;
6829 + counterstmp = NULL;
6831 + // this can get initialized by translate_table()
6832 + newinfo->chainstack = NULL;
6833 + ret = translate_table(&tmp, newinfo);
6836 + goto free_counterstmp;
6838 + t = find_table_lock(tmp.name, &ret, &ebt_mutex);
6840 + goto free_iterate;
6842 + // the table doesn't like it
6843 + if (t->check && (ret = t->check(newinfo, tmp.valid_hooks)))
6846 + if (tmp.num_counters && tmp.num_counters != t->private->nentries) {
6847 + BUGPRINT("Wrong nr. of counters requested\n");
6852 + // we have the mutex lock, so no danger in reading this pointer
6853 + table = t->private;
6854 + // we need an atomic snapshot of the counters
6855 + write_lock_bh(&t->lock);
6856 + if (tmp.num_counters)
6857 + get_counters(t->private->counters, counterstmp,
6858 + t->private->nentries);
6860 + t->private = newinfo;
6861 + write_unlock_bh(&t->lock);
6863 + // So, a user can change the chains while having messed up her counter
6864 + // allocation. Only reason why this is done is because this way the lock
6865 + // is held only once, while this doesn't bring the kernel into a
6866 + // dangerous state.
6867 + if (tmp.num_counters &&
6868 + copy_to_user(tmp.counters, counterstmp,
6869 + tmp.num_counters * sizeof(struct ebt_counter))) {
6870 + BUGPRINT("Couldn't copy counters to userspace\n");
6876 + // decrease module count and free resources
6877 + EBT_ENTRY_ITERATE(table->entries, table->entries_size,
6878 + ebt_cleanup_entry, NULL);
6880 + vfree(table->entries);
6881 + if (table->chainstack) {
6882 + for (i = 0; i < smp_num_cpus; i++)
6883 + vfree(table->chainstack[i]);
6884 + vfree(table->chainstack);
6889 + vfree(counterstmp);
6895 + EBT_ENTRY_ITERATE(newinfo->entries, newinfo->entries_size,
6896 + ebt_cleanup_entry, NULL);
6899 + vfree(counterstmp);
6900 + // can be initialized in translate_table()
6901 + if (newinfo->chainstack) {
6902 + for (i = 0; i < smp_num_cpus; i++)
6903 + vfree(newinfo->chainstack[i]);
6904 + vfree(newinfo->chainstack);
6907 + if (newinfo->entries)
6908 + vfree(newinfo->entries);
6915 +int ebt_register_target(struct ebt_target *target)
6919 + ret = down_interruptible(&ebt_mutex);
6922 + if (!list_named_insert(&ebt_targets, target)) {
6927 + MOD_INC_USE_COUNT;
6932 +void ebt_unregister_target(struct ebt_target *target)
6935 + LIST_DELETE(&ebt_targets, target);
6937 + MOD_DEC_USE_COUNT;
6940 +int ebt_register_match(struct ebt_match *match)
6944 + ret = down_interruptible(&ebt_mutex);
6947 + if (!list_named_insert(&ebt_matches, match)) {
6952 + MOD_INC_USE_COUNT;
6957 +void ebt_unregister_match(struct ebt_match *match)
6960 + LIST_DELETE(&ebt_matches, match);
6962 + MOD_DEC_USE_COUNT;
6965 +int ebt_register_watcher(struct ebt_watcher *watcher)
6969 + ret = down_interruptible(&ebt_mutex);
6972 + if (!list_named_insert(&ebt_watchers, watcher)) {
6977 + MOD_INC_USE_COUNT;
6982 +void ebt_unregister_watcher(struct ebt_watcher *watcher)
6985 + LIST_DELETE(&ebt_watchers, watcher);
6987 + MOD_DEC_USE_COUNT;
6990 +int ebt_register_table(struct ebt_table *table)
6992 + struct ebt_table_info *newinfo;
6993 + int ret, i, countersize;
6995 + if (!table || !table->table ||!table->table->entries ||
6996 + table->table->entries_size == 0 ||
6997 + table->table->counters || table->private) {
6998 + BUGPRINT("Bad table data for ebt_register_table!!!\n");
7002 + countersize = COUNTER_OFFSET(table->table->nentries) * smp_num_cpus;
7003 + newinfo = (struct ebt_table_info *)
7004 + vmalloc(sizeof(struct ebt_table_info) + countersize);
7009 + newinfo->entries = (char *)vmalloc(table->table->entries_size);
7010 + if (!(newinfo->entries))
7011 + goto free_newinfo;
7013 + memcpy(newinfo->entries, table->table->entries,
7014 + table->table->entries_size);
7017 + memset(newinfo->counters, 0, countersize);
7019 + // fill in newinfo and parse the entries
7020 + newinfo->chainstack = NULL;
7021 + ret = translate_table(table->table, newinfo);
7023 + BUGPRINT("Translate_table failed\n");
7024 + goto free_chainstack;
7027 + if (table->check && table->check(newinfo, table->valid_hooks)) {
7028 + BUGPRINT("The table doesn't like its own initial data, lol\n");
7032 + table->private = newinfo;
7033 + table->lock = RW_LOCK_UNLOCKED;
7034 + ret = down_interruptible(&ebt_mutex);
7036 + goto free_chainstack;
7038 + if (list_named_find(&ebt_tables, table->name)) {
7040 + BUGPRINT("Table name already exists\n");
7044 + list_prepend(&ebt_tables, table);
7046 + MOD_INC_USE_COUNT;
7051 + if (newinfo->chainstack) {
7052 + for (i = 0; i < smp_num_cpus; i++)
7053 + vfree(newinfo->chainstack[i]);
7054 + vfree(newinfo->chainstack);
7056 + vfree(newinfo->entries);
7062 +void ebt_unregister_table(struct ebt_table *table)
7067 + BUGPRINT("Request to unregister NULL table!!!\n");
7071 + LIST_DELETE(&ebt_tables, table);
7073 + EBT_ENTRY_ITERATE(table->private->entries,
7074 + table->private->entries_size, ebt_cleanup_entry, NULL);
7075 + if (table->private->entries)
7076 + vfree(table->private->entries);
7077 + if (table->private->chainstack) {
7078 + for (i = 0; i < smp_num_cpus; i++)
7079 + vfree(table->private->chainstack[i]);
7080 + vfree(table->private->chainstack);
7082 + vfree(table->private);
7083 + MOD_DEC_USE_COUNT;
7086 +// userspace just supplied us with counters
7087 +static int update_counters(void *user, unsigned int len)
7090 + struct ebt_counter *tmp;
7091 + struct ebt_replace hlp;
7092 + struct ebt_table *t;
7094 + if (copy_from_user(&hlp, user, sizeof(hlp)))
7097 + if (len != sizeof(hlp) + hlp.num_counters * sizeof(struct ebt_counter))
7099 + if (hlp.num_counters == 0)
7102 + if ( !(tmp = (struct ebt_counter *)
7103 + vmalloc(hlp.num_counters * sizeof(struct ebt_counter))) ){
7104 + MEMPRINT("Update_counters && nomemory\n");
7108 + t = find_table_lock(hlp.name, &ret, &ebt_mutex);
7112 + if (hlp.num_counters != t->private->nentries) {
7113 + BUGPRINT("Wrong nr of counters\n");
7115 + goto unlock_mutex;
7118 + if ( copy_from_user(tmp, hlp.counters,
7119 + hlp.num_counters * sizeof(struct ebt_counter)) ) {
7120 + BUGPRINT("Updata_counters && !cfu\n");
7122 + goto unlock_mutex;
7125 + // we want an atomic add of the counters
7126 + write_lock_bh(&t->lock);
7128 + // we add to the counters of the first cpu
7129 + for (i = 0; i < hlp.num_counters; i++) {
7130 + t->private->counters[i].pcnt += tmp[i].pcnt;
7131 + t->private->counters[i].bcnt += tmp[i].bcnt;
7134 + write_unlock_bh(&t->lock);
7143 +static inline int ebt_make_matchname(struct ebt_entry_match *m,
7144 + char *base, char *ubase)
7146 + char *hlp = ubase - base + (char *)m;
7147 + if (copy_to_user(hlp, m->u.match->name, EBT_FUNCTION_MAXNAMELEN))
7152 +static inline int ebt_make_watchername(struct ebt_entry_watcher *w,
7153 + char *base, char *ubase)
7155 + char *hlp = ubase - base + (char *)w;
7156 + if (copy_to_user(hlp , w->u.watcher->name, EBT_FUNCTION_MAXNAMELEN))
7161 +static inline int ebt_make_names(struct ebt_entry *e, char *base, char *ubase)
7165 + struct ebt_entry_target *t;
7167 + if ((e->bitmask & EBT_ENTRY_OR_ENTRIES) == 0)
7170 + hlp = ubase - base + (char *)e + e->target_offset;
7171 + t = (struct ebt_entry_target *)(((char *)e) + e->target_offset);
7173 + ret = EBT_MATCH_ITERATE(e, ebt_make_matchname, base, ubase);
7176 + ret = EBT_WATCHER_ITERATE(e, ebt_make_watchername, base, ubase);
7179 + if (copy_to_user(hlp, t->u.target->name, EBT_FUNCTION_MAXNAMELEN))
7184 +// called with ebt_mutex down
7185 +static int copy_everything_to_user(struct ebt_table *t, void *user,
7186 + int *len, int cmd)
7188 + struct ebt_replace tmp;
7189 + struct ebt_counter *counterstmp, *oldcounters;
7190 + unsigned int entries_size, nentries;
7193 + if (cmd == EBT_SO_GET_ENTRIES) {
7194 + entries_size = t->private->entries_size;
7195 + nentries = t->private->nentries;
7196 + entries = t->private->entries;
7197 + oldcounters = t->private->counters;
7199 + entries_size = t->table->entries_size;
7200 + nentries = t->table->nentries;
7201 + entries = t->table->entries;
7202 + oldcounters = t->table->counters;
7205 + if (copy_from_user(&tmp, user, sizeof(tmp))) {
7206 + BUGPRINT("Cfu didn't work\n");
7210 + if (*len != sizeof(struct ebt_replace) + entries_size +
7211 + (tmp.num_counters? nentries * sizeof(struct ebt_counter): 0)) {
7212 + BUGPRINT("Wrong size\n");
7216 + if (tmp.nentries != nentries) {
7217 + BUGPRINT("Nentries wrong\n");
7221 + if (tmp.entries_size != entries_size) {
7222 + BUGPRINT("Wrong size\n");
7226 + // userspace might not need the counters
7227 + if (tmp.num_counters) {
7228 + if (tmp.num_counters != nentries) {
7229 + BUGPRINT("Num_counters wrong\n");
7232 + counterstmp = (struct ebt_counter *)
7233 + vmalloc(nentries * sizeof(struct ebt_counter));
7234 + if (!counterstmp) {
7235 + MEMPRINT("Couldn't copy counters, out of memory\n");
7238 + write_lock_bh(&t->lock);
7239 + get_counters(oldcounters, counterstmp, nentries);
7240 + write_unlock_bh(&t->lock);
7242 + if (copy_to_user(tmp.counters, counterstmp,
7243 + nentries * sizeof(struct ebt_counter))) {
7244 + BUGPRINT("Couldn't copy counters to userspace\n");
7245 + vfree(counterstmp);
7248 + vfree(counterstmp);
7251 + if (copy_to_user(tmp.entries, entries, entries_size)) {
7252 + BUGPRINT("Couldn't copy entries to userspace\n");
7255 + // set the match/watcher/target names right
7256 + return EBT_ENTRY_ITERATE(entries, entries_size,
7257 + ebt_make_names, entries, tmp.entries);
7260 +static int do_ebt_set_ctl(struct sock *sk,
7261 + int cmd, void *user, unsigned int len)
7266 + case EBT_SO_SET_ENTRIES:
7267 + ret = do_replace(user, len);
7269 + case EBT_SO_SET_COUNTERS:
7270 + ret = update_counters(user, len);
7278 +static int do_ebt_get_ctl(struct sock *sk, int cmd, void *user, int *len)
7281 + struct ebt_replace tmp;
7282 + struct ebt_table *t;
7284 + if (copy_from_user(&tmp, user, sizeof(tmp)))
7287 + t = find_table_lock(tmp.name, &ret, &ebt_mutex);
7292 + case EBT_SO_GET_INFO:
7293 + case EBT_SO_GET_INIT_INFO:
7294 + if (*len != sizeof(struct ebt_replace)){
7299 + if (cmd == EBT_SO_GET_INFO) {
7300 + tmp.nentries = t->private->nentries;
7301 + tmp.entries_size = t->private->entries_size;
7302 + tmp.valid_hooks = t->valid_hooks;
7304 + tmp.nentries = t->table->nentries;
7305 + tmp.entries_size = t->table->entries_size;
7306 + tmp.valid_hooks = t->table->valid_hooks;
7309 + if (copy_to_user(user, &tmp, *len) != 0){
7310 + BUGPRINT("c2u Didn't work\n");
7317 + case EBT_SO_GET_ENTRIES:
7318 + case EBT_SO_GET_INIT_ENTRIES:
7319 + ret = copy_everything_to_user(t, user, len, cmd);
7331 +static struct nf_sockopt_ops ebt_sockopts =
7332 +{ { NULL, NULL }, PF_INET, EBT_BASE_CTL, EBT_SO_SET_MAX + 1, do_ebt_set_ctl,
7333 + EBT_BASE_CTL, EBT_SO_GET_MAX + 1, do_ebt_get_ctl, 0, NULL
7336 +static int __init init(void)
7341 + list_named_insert(&ebt_targets, &ebt_standard_target);
7343 + if ((ret = nf_register_sockopt(&ebt_sockopts)) < 0)
7346 + printk(KERN_NOTICE "Ebtables v2.0 registered\n");
7350 +static void __exit fini(void)
7352 + nf_unregister_sockopt(&ebt_sockopts);
7353 + printk(KERN_NOTICE "Ebtables v2.0 unregistered\n");
7356 +EXPORT_SYMBOL(ebt_register_table);
7357 +EXPORT_SYMBOL(ebt_unregister_table);
7358 +EXPORT_SYMBOL(ebt_register_match);
7359 +EXPORT_SYMBOL(ebt_unregister_match);
7360 +EXPORT_SYMBOL(ebt_register_watcher);
7361 +EXPORT_SYMBOL(ebt_unregister_watcher);
7362 +EXPORT_SYMBOL(ebt_register_target);
7363 +EXPORT_SYMBOL(ebt_unregister_target);
7364 +EXPORT_SYMBOL(ebt_do_table);
7367 +MODULE_LICENSE("GPL");
7368 diff -Nur linux-mips-cvs/net/core/dev.c linux-ebtables/net/core/dev.c
7369 --- linux-mips-cvs/net/core/dev.c 2004-04-16 05:14:21.000000000 +0200
7370 +++ linux-ebtables/net/core/dev.c 2005-02-07 05:52:50.000000000 +0100
7371 @@ -1426,7 +1426,7 @@
7374 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
7375 -void (*br_handle_frame_hook)(struct sk_buff *skb) = NULL;
7376 +int (*br_handle_frame_hook)(struct sk_buff *skb) = NULL;
7379 static __inline__ int handle_bridge(struct sk_buff *skb,
7380 @@ -1443,7 +1443,6 @@
7384 - br_handle_frame_hook(skb);
7388 @@ -1503,7 +1502,12 @@
7389 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
7390 if (skb->dev->br_port != NULL && br_handle_frame_hook != NULL &&
7391 skb->pkt_type != PACKET_LOOPBACK) {
7392 - return handle_bridge(skb, pt_prev);
7395 + ret = handle_bridge(skb, pt_prev);
7396 + if (br_handle_frame_hook(skb) == 0)
7402 diff -Nur linux-mips-cvs/net/core/netfilter.c linux-ebtables/net/core/netfilter.c
7403 --- linux-mips-cvs/net/core/netfilter.c 2005-01-20 03:19:25.000000000 +0100
7404 +++ linux-ebtables/net/core/netfilter.c 2005-02-07 05:52:50.000000000 +0100
7405 @@ -342,10 +342,15 @@
7406 const struct net_device *indev,
7407 const struct net_device *outdev,
7408 struct list_head **i,
7409 - int (*okfn)(struct sk_buff *))
7410 + int (*okfn)(struct sk_buff *),
7413 for (*i = (*i)->next; *i != head; *i = (*i)->next) {
7414 struct nf_hook_ops *elem = (struct nf_hook_ops *)*i;
7416 + if (hook_thresh > elem->priority)
7419 switch (elem->hook(hook, skb, indev, outdev, okfn)) {
7422 @@ -413,6 +418,10 @@
7425 struct nf_info *info;
7426 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
7427 + struct net_device *physindev = NULL;
7428 + struct net_device *physoutdev = NULL;
7431 if (!queue_handler[pf].outfn) {
7433 @@ -435,11 +444,24 @@
7434 if (indev) dev_hold(indev);
7435 if (outdev) dev_hold(outdev);
7437 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
7438 + if (skb->nf_bridge) {
7439 + physindev = skb->nf_bridge->physindev;
7440 + if (physindev) dev_hold(physindev);
7441 + physoutdev = skb->nf_bridge->physoutdev;
7442 + if (physoutdev) dev_hold(physoutdev);
7446 status = queue_handler[pf].outfn(skb, info, queue_handler[pf].data);
7448 /* James M doesn't say fuck enough. */
7449 if (indev) dev_put(indev);
7450 if (outdev) dev_put(outdev);
7451 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
7452 + if (physindev) dev_put(physindev);
7453 + if (physoutdev) dev_put(physoutdev);
7459 int nf_hook_slow(int pf, unsigned int hook, struct sk_buff *skb,
7460 struct net_device *indev,
7461 struct net_device *outdev,
7462 - int (*okfn)(struct sk_buff *))
7463 + int (*okfn)(struct sk_buff *),
7466 struct list_head *elem;
7467 unsigned int verdict;
7470 elem = &nf_hooks[pf][hook];
7471 verdict = nf_iterate(&nf_hooks[pf][hook], &skb, hook, indev,
7472 - outdev, &elem, okfn);
7473 + outdev, &elem, okfn, hook_thresh);
7474 if (verdict == NF_QUEUE) {
7475 NFDEBUG("nf_hook: Verdict = QUEUE.\n");
7476 nf_queue(skb, elem, pf, hook, indev, outdev, okfn);
7477 @@ -510,6 +533,14 @@
7479 /* We don't have BR_NETPROTO_LOCK here */
7480 br_read_lock_bh(BR_NETPROTO_LOCK);
7481 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
7482 + if (skb->nf_bridge) {
7483 + if (skb->nf_bridge->physindev)
7484 + dev_put(skb->nf_bridge->physindev);
7485 + if (skb->nf_bridge->physoutdev)
7486 + dev_put(skb->nf_bridge->physoutdev);
7489 for (i = nf_hooks[info->pf][info->hook].next; i != elem; i = i->next) {
7490 if (i == &nf_hooks[info->pf][info->hook]) {
7491 /* The module which sent it to userspace is gone. */
7493 verdict = nf_iterate(&nf_hooks[info->pf][info->hook],
7495 info->indev, info->outdev, &elem,
7497 + info->okfn, INT_MIN);
7501 diff -Nur linux-mips-cvs/net/core/skbuff.c linux-ebtables/net/core/skbuff.c
7502 --- linux-mips-cvs/net/core/skbuff.c 2003-08-13 19:19:30.000000000 +0200
7503 +++ linux-ebtables/net/core/skbuff.c 2005-02-07 05:52:50.000000000 +0100
7505 #ifdef CONFIG_NETFILTER_DEBUG
7508 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
7509 + skb->nf_bridge = NULL;
7512 #ifdef CONFIG_NET_SCHED
7516 #ifdef CONFIG_NETFILTER
7517 nf_conntrack_put(skb->nfct);
7518 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
7519 + nf_bridge_put(skb->nf_bridge);
7522 skb_headerinit(skb, NULL, 0); /* clean state */
7525 #ifdef CONFIG_NETFILTER_DEBUG
7528 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
7531 #endif /*CONFIG_NETFILTER*/
7532 #if defined(CONFIG_HIPPI)
7536 #ifdef CONFIG_NETFILTER
7537 nf_conntrack_get(skb->nfct);
7538 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
7539 + nf_bridge_get(skb->nf_bridge);
7544 @@ -440,6 +452,10 @@
7545 #ifdef CONFIG_NETFILTER_DEBUG
7546 new->nf_debug=old->nf_debug;
7548 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
7549 + new->nf_bridge=old->nf_bridge;
7550 + nf_bridge_get(new->nf_bridge);
7553 #ifdef CONFIG_NET_SCHED
7554 new->tc_index = old->tc_index;
7556 /* Set the tail pointer and length */
7557 skb_put(n,skb->len);
7559 - /* Copy the data only. */
7560 - if (skb_copy_bits(skb, 0, n->data, skb->len))
7562 + /* Copy the linear data and header. */
7563 + if (skb_copy_bits(skb, -newheadroom, n->head, newheadroom + skb->len))
7566 copy_skb_header(n, skb);
7568 diff -Nur linux-mips-cvs/net/ipv4/ip_output.c linux-ebtables/net/ipv4/ip_output.c
7569 --- linux-mips-cvs/net/ipv4/ip_output.c 2005-01-20 03:19:25.000000000 +0100
7570 +++ linux-ebtables/net/ipv4/ip_output.c 2005-02-07 05:52:50.000000000 +0100
7571 @@ -890,6 +890,10 @@
7572 /* Connection association is same as pre-frag packet */
7573 skb2->nfct = skb->nfct;
7574 nf_conntrack_get(skb2->nfct);
7575 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
7576 + skb2->nf_bridge = skb->nf_bridge;
7577 + nf_bridge_get(skb2->nf_bridge);
7579 #ifdef CONFIG_NETFILTER_DEBUG
7580 skb2->nf_debug = skb->nf_debug;
7582 diff -Nur linux-mips-cvs/net/ipv4/ip_output.c.orig linux-ebtables/net/ipv4/ip_output.c.orig
7583 --- linux-mips-cvs/net/ipv4/ip_output.c.orig 1970-01-01 01:00:00.000000000 +0100
7584 +++ linux-ebtables/net/ipv4/ip_output.c.orig 2005-01-20 03:19:25.000000000 +0100
7587 + * INET An implementation of the TCP/IP protocol suite for the LINUX
7588 + * operating system. INET is implemented using the BSD Socket
7589 + * interface as the means of communication with the user level.
7591 + * The Internet Protocol (IP) output module.
7595 + * Authors: Ross Biro, <bir7@leland.Stanford.Edu>
7596 + * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
7597 + * Donald Becker, <becker@super.org>
7598 + * Alan Cox, <Alan.Cox@linux.org>
7599 + * Richard Underwood
7600 + * Stefan Becker, <stefanb@yello.ping.de>
7601 + * Jorge Cwik, <jorge@laser.satlink.net>
7602 + * Arnt Gulbrandsen, <agulbra@nvg.unit.no>
7604 + * See ip_input.c for original log
7607 + * Alan Cox : Missing nonblock feature in ip_build_xmit.
7608 + * Mike Kilburn : htons() missing in ip_build_xmit.
7609 + * Bradford Johnson: Fix faulty handling of some frames when
7610 + * no route is found.
7611 + * Alexander Demenshin: Missing sk/skb free in ip_queue_xmit
7612 + * (in case if packet not accepted by
7613 + * output firewall rules)
7614 + * Mike McLagan : Routing by source
7615 + * Alexey Kuznetsov: use new route cache
7616 + * Andi Kleen: Fix broken PMTU recovery and remove
7617 + * some redundant tests.
7618 + * Vitaly E. Lavrov : Transparent proxy revived after year coma.
7619 + * Andi Kleen : Replace ip_reply with ip_send_reply.
7620 + * Andi Kleen : Split fast and slow ip_build_xmit path
7621 + * for decreased register pressure on x86
7622 + * and more readibility.
7623 + * Marc Boucher : When call_out_firewall returns FW_QUEUE,
7624 + * silently drop skb instead of failing with -EPERM.
7625 + * Detlev Wengorz : Copy protocol for fragments.
7628 +#include <asm/uaccess.h>
7629 +#include <asm/system.h>
7630 +#include <linux/types.h>
7631 +#include <linux/kernel.h>
7632 +#include <linux/sched.h>
7633 +#include <linux/mm.h>
7634 +#include <linux/string.h>
7635 +#include <linux/errno.h>
7636 +#include <linux/config.h>
7638 +#include <linux/socket.h>
7639 +#include <linux/sockios.h>
7640 +#include <linux/in.h>
7641 +#include <linux/inet.h>
7642 +#include <linux/netdevice.h>
7643 +#include <linux/etherdevice.h>
7644 +#include <linux/proc_fs.h>
7645 +#include <linux/stat.h>
7646 +#include <linux/init.h>
7648 +#include <net/snmp.h>
7649 +#include <net/ip.h>
7650 +#include <net/protocol.h>
7651 +#include <net/route.h>
7652 +#include <net/tcp.h>
7653 +#include <net/udp.h>
7654 +#include <linux/skbuff.h>
7655 +#include <net/sock.h>
7656 +#include <net/arp.h>
7657 +#include <net/icmp.h>
7658 +#include <net/raw.h>
7659 +#include <net/checksum.h>
7660 +#include <net/inetpeer.h>
7661 +#include <linux/igmp.h>
7662 +#include <linux/netfilter_ipv4.h>
7663 +#include <linux/mroute.h>
7664 +#include <linux/netlink.h>
7667 + * Shall we try to damage output packets if routing dev changes?
7670 +int sysctl_ip_dynaddr = 0;
7671 +int sysctl_ip_default_ttl = IPDEFTTL;
7673 +/* Generate a checksum for an outgoing IP datagram. */
7674 +__inline__ void ip_send_check(struct iphdr *iph)
7677 + iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);
7680 +/* dev_loopback_xmit for use with netfilter. */
7681 +static int ip_dev_loopback_xmit(struct sk_buff *newskb)
7683 + newskb->mac.raw = newskb->data;
7684 + __skb_pull(newskb, newskb->nh.raw - newskb->data);
7685 + newskb->pkt_type = PACKET_LOOPBACK;
7686 + newskb->ip_summed = CHECKSUM_UNNECESSARY;
7687 + BUG_TRAP(newskb->dst);
7689 +#ifdef CONFIG_NETFILTER_DEBUG
7690 + nf_debug_ip_loopback_xmit(newskb);
7696 +/* Don't just hand NF_HOOK skb->dst->output, in case netfilter hook
7699 +output_maybe_reroute(struct sk_buff *skb)
7701 + return skb->dst->output(skb);
7705 + * Add an ip header to a skbuff and send it out.
7707 +int ip_build_and_send_pkt(struct sk_buff *skb, struct sock *sk,
7708 + u32 saddr, u32 daddr, struct ip_options *opt)
7710 + struct rtable *rt = (struct rtable *)skb->dst;
7711 + struct iphdr *iph;
7713 + /* Build the IP header. */
7715 + iph=(struct iphdr *)skb_push(skb,sizeof(struct iphdr) + opt->optlen);
7717 + iph=(struct iphdr *)skb_push(skb,sizeof(struct iphdr));
7721 + iph->tos = sk->protinfo.af_inet.tos;
7722 + if (ip_dont_fragment(sk, &rt->u.dst))
7723 + iph->frag_off = htons(IP_DF);
7725 + iph->frag_off = 0;
7726 + iph->ttl = sk->protinfo.af_inet.ttl;
7727 + iph->daddr = rt->rt_dst;
7728 + iph->saddr = rt->rt_src;
7729 + iph->protocol = sk->protocol;
7730 + iph->tot_len = htons(skb->len);
7731 + ip_select_ident(iph, &rt->u.dst, sk);
7732 + skb->nh.iph = iph;
7734 + if (opt && opt->optlen) {
7735 + iph->ihl += opt->optlen>>2;
7736 + ip_options_build(skb, opt, daddr, rt, 0);
7738 + ip_send_check(iph);
7740 + /* Send it out. */
7741 + return NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, skb, NULL, rt->u.dst.dev,
7742 + output_maybe_reroute);
7745 +static inline int ip_finish_output2(struct sk_buff *skb)
7747 + struct dst_entry *dst = skb->dst;
7748 + struct hh_cache *hh = dst->hh;
7750 +#ifdef CONFIG_NETFILTER_DEBUG
7751 + nf_debug_ip_finish_output2(skb);
7752 +#endif /*CONFIG_NETFILTER_DEBUG*/
7757 + read_lock_bh(&hh->hh_lock);
7758 + hh_alen = HH_DATA_ALIGN(hh->hh_len);
7759 + memcpy(skb->data - hh_alen, hh->hh_data, hh_alen);
7760 + read_unlock_bh(&hh->hh_lock);
7761 + skb_push(skb, hh->hh_len);
7762 + return hh->hh_output(skb);
7763 + } else if (dst->neighbour)
7764 + return dst->neighbour->output(skb);
7766 + if (net_ratelimit())
7767 + printk(KERN_DEBUG "ip_finish_output2: No header cache and no neighbour!\n");
7772 +static __inline__ int __ip_finish_output(struct sk_buff *skb)
7774 + struct net_device *dev = skb->dst->dev;
7777 + skb->protocol = htons(ETH_P_IP);
7779 + return NF_HOOK(PF_INET, NF_IP_POST_ROUTING, skb, NULL, dev,
7780 + ip_finish_output2);
7783 +int ip_finish_output(struct sk_buff *skb)
7785 + return __ip_finish_output(skb);
7788 +int ip_mc_output(struct sk_buff *skb)
7790 + struct sock *sk = skb->sk;
7791 + struct rtable *rt = (struct rtable*)skb->dst;
7792 + struct net_device *dev = rt->u.dst.dev;
7795 + * If the indicated interface is up and running, send the packet.
7797 + IP_INC_STATS(IpOutRequests);
7798 +#ifdef CONFIG_IP_ROUTE_NAT
7799 + if (rt->rt_flags & RTCF_NAT)
7804 + skb->protocol = htons(ETH_P_IP);
7807 + * Multicasts are looped back for other local users
7810 + if (rt->rt_flags&RTCF_MULTICAST) {
7811 + if ((!sk || sk->protinfo.af_inet.mc_loop)
7812 +#ifdef CONFIG_IP_MROUTE
7813 + /* Small optimization: do not loopback not local frames,
7814 + which returned after forwarding; they will be dropped
7815 + by ip_mr_input in any case.
7816 + Note, that local frames are looped back to be delivered
7817 + to local recipients.
7819 + This check is duplicated in ip_mr_input at the moment.
7821 + && ((rt->rt_flags&RTCF_LOCAL) || !(IPCB(skb)->flags&IPSKB_FORWARDED))
7824 + struct sk_buff *newskb = skb_clone(skb, GFP_ATOMIC);
7826 + NF_HOOK(PF_INET, NF_IP_POST_ROUTING, newskb, NULL,
7828 + ip_dev_loopback_xmit);
7831 + /* Multicasts with ttl 0 must not go beyond the host */
7833 + if (skb->nh.iph->ttl == 0) {
7839 + if (rt->rt_flags&RTCF_BROADCAST) {
7840 + struct sk_buff *newskb = skb_clone(skb, GFP_ATOMIC);
7842 + NF_HOOK(PF_INET, NF_IP_POST_ROUTING, newskb, NULL,
7843 + newskb->dev, ip_dev_loopback_xmit);
7846 + return __ip_finish_output(skb);
7849 +int ip_output(struct sk_buff *skb)
7851 +#ifdef CONFIG_IP_ROUTE_NAT
7852 + struct rtable *rt = (struct rtable*)skb->dst;
7855 + IP_INC_STATS(IpOutRequests);
7857 +#ifdef CONFIG_IP_ROUTE_NAT
7858 + if (rt->rt_flags&RTCF_NAT)
7862 + return __ip_finish_output(skb);
7865 +/* Queues a packet to be sent, and starts the transmitter if necessary.
7866 + * This routine also needs to put in the total length and compute the
7867 + * checksum. We use to do this in two stages, ip_build_header() then
7868 + * this, but that scheme created a mess when routes disappeared etc.
7869 + * So we do it all here, and the TCP send engine has been changed to
7870 + * match. (No more unroutable FIN disasters, etc. wheee...) This will
7871 + * most likely make other reliable transport layers above IP easier
7872 + * to implement under Linux.
7874 +static inline int ip_queue_xmit2(struct sk_buff *skb)
7876 + struct sock *sk = skb->sk;
7877 + struct rtable *rt = (struct rtable *)skb->dst;
7878 + struct net_device *dev;
7879 + struct iphdr *iph = skb->nh.iph;
7881 + dev = rt->u.dst.dev;
7883 + /* This can happen when the transport layer has segments queued
7884 + * with a cached route, and by the time we get here things are
7885 + * re-routed to a device with a different MTU than the original
7886 + * device. Sick, but we must cover it.
7888 + if (skb_headroom(skb) < dev->hard_header_len && dev->hard_header) {
7889 + struct sk_buff *skb2;
7891 + skb2 = skb_realloc_headroom(skb, (dev->hard_header_len + 15) & ~15);
7896 + skb_set_owner_w(skb2, sk);
7898 + iph = skb->nh.iph;
7901 + if (skb->len > rt->u.dst.pmtu)
7904 + ip_select_ident(iph, &rt->u.dst, sk);
7906 + /* Add an IP checksum. */
7907 + ip_send_check(iph);
7909 + skb->priority = sk->priority;
7910 + return skb->dst->output(skb);
7913 + if (ip_dont_fragment(sk, &rt->u.dst)) {
7914 + /* Reject packet ONLY if TCP might fragment
7915 + * it itself, if were careful enough.
7917 + NETDEBUG(printk(KERN_DEBUG "sending pkt_too_big (len[%u] pmtu[%u]) to self\n",
7918 + skb->len, rt->u.dst.pmtu));
7920 + icmp_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED,
7921 + htonl(rt->u.dst.pmtu));
7925 + ip_select_ident(iph, &rt->u.dst, sk);
7926 + if (skb->ip_summed == CHECKSUM_HW &&
7927 + (skb = skb_checksum_help(skb)) == NULL)
7929 + return ip_fragment(skb, skb->dst->output);
7932 +int ip_queue_xmit(struct sk_buff *skb, int ipfragok)
7934 + struct sock *sk = skb->sk;
7935 + struct ip_options *opt = sk->protinfo.af_inet.opt;
7936 + struct rtable *rt;
7937 + struct iphdr *iph;
7939 + /* Skip all of this if the packet is already routed,
7940 + * f.e. by something like SCTP.
7942 + rt = (struct rtable *) skb->dst;
7944 + goto packet_routed;
7946 + /* Make sure we can route this packet. */
7947 + rt = (struct rtable *)__sk_dst_check(sk, 0);
7951 + /* Use correct destination address if we have options. */
7952 + daddr = sk->daddr;
7953 + if(opt && opt->srr)
7954 + daddr = opt->faddr;
7956 + /* If this fails, retransmit mechanism of transport layer will
7957 + * keep trying until route appears or the connection times itself
7960 + if (ip_route_output(&rt, daddr, sk->saddr,
7961 + RT_CONN_FLAGS(sk),
7962 + sk->bound_dev_if))
7964 + __sk_dst_set(sk, &rt->u.dst);
7965 + sk->route_caps = rt->u.dst.dev->features;
7967 + skb->dst = dst_clone(&rt->u.dst);
7970 + if (opt && opt->is_strictroute && rt->rt_dst != rt->rt_gateway)
7973 + /* OK, we know where to send it, allocate and build IP header. */
7974 + iph = (struct iphdr *) skb_push(skb, sizeof(struct iphdr) + (opt ? opt->optlen : 0));
7975 + *((__u16 *)iph) = htons((4 << 12) | (5 << 8) | (sk->protinfo.af_inet.tos & 0xff));
7976 + iph->tot_len = htons(skb->len);
7977 + if (ip_dont_fragment(sk, &rt->u.dst) && !ipfragok)
7978 + iph->frag_off = htons(IP_DF);
7980 + iph->frag_off = 0;
7981 + iph->ttl = sk->protinfo.af_inet.ttl;
7982 + iph->protocol = sk->protocol;
7983 + iph->saddr = rt->rt_src;
7984 + iph->daddr = rt->rt_dst;
7985 + skb->nh.iph = iph;
7986 + /* Transport layer set skb->h.foo itself. */
7988 + if(opt && opt->optlen) {
7989 + iph->ihl += opt->optlen >> 2;
7990 + ip_options_build(skb, opt, sk->daddr, rt, 0);
7993 + return NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, skb, NULL, rt->u.dst.dev,
7997 + IP_INC_STATS(IpOutNoRoutes);
7999 + return -EHOSTUNREACH;
8003 + * Build and send a packet, with as little as one copy
8005 + * Doesn't care much about ip options... option length can be
8006 + * different for fragment at 0 and other fragments.
8008 + * Note that the fragment at the highest offset is sent first,
8009 + * so the getfrag routine can fill in the TCP/UDP checksum header
8010 + * field in the last fragment it sends... actually it also helps
8011 + * the reassemblers, they can put most packets in at the head of
8012 + * the fragment queue, and they know the total size in advance. This
8013 + * last feature will measurably improve the Linux fragment handler one
8016 + * The callback has five args, an arbitrary pointer (copy of frag),
8017 + * the source IP address (may depend on the routing table), the
8018 + * destination address (char *), the offset to copy from, and the
8019 + * length to be copied.
8022 +static int ip_build_xmit_slow(struct sock *sk,
8023 + int getfrag (const void *,
8027 + struct sk_buff *),
8030 + struct ipcm_cookie *ipc,
8031 + struct rtable *rt,
8034 + unsigned int fraglen, maxfraglen, fragheaderlen;
8040 + int hh_len = (rt->u.dst.dev->hard_header_len + 15)&~15;
8042 + struct ip_options *opt = ipc->opt;
8045 + mtu = rt->u.dst.pmtu;
8046 + if (ip_dont_fragment(sk, &rt->u.dst))
8047 + df = htons(IP_DF);
8049 + length -= sizeof(struct iphdr);
8052 + fragheaderlen = sizeof(struct iphdr) + opt->optlen;
8053 + maxfraglen = ((mtu-sizeof(struct iphdr)-opt->optlen) & ~7) + fragheaderlen;
8055 + fragheaderlen = sizeof(struct iphdr);
8058 + * Fragheaderlen is the size of 'overhead' on each buffer. Now work
8059 + * out the size of the frames to send.
8062 + maxfraglen = ((mtu-sizeof(struct iphdr)) & ~7) + fragheaderlen;
8065 + if (length + fragheaderlen > 0xFFFF) {
8066 + ip_local_error(sk, EMSGSIZE, rt->rt_dst, sk->dport, mtu);
8071 + * Start at the end of the frame by handling the remainder.
8074 + offset = length - (length % (maxfraglen - fragheaderlen));
8077 + * Amount of memory to allocate for final fragment.
8080 + fraglen = length - offset + fragheaderlen;
8082 + if (length-offset==0) {
8083 + fraglen = maxfraglen;
8084 + offset -= maxfraglen-fragheaderlen;
8088 + * The last fragment will not have MF (more fragments) set.
8094 + * Don't fragment packets for path mtu discovery.
8097 + if (offset > 0 && sk->protinfo.af_inet.pmtudisc==IP_PMTUDISC_DO) {
8098 + ip_local_error(sk, EMSGSIZE, rt->rt_dst, sk->dport, mtu);
8101 + if (flags&MSG_PROBE)
8105 + * Begin outputting the bytes.
8108 + id = sk->protinfo.af_inet.id++;
8112 + struct sk_buff * skb;
8115 + * Get the memory we require with some space left for alignment.
8117 + if (!(flags & MSG_DONTWAIT) || nfrags == 0) {
8118 + skb = sock_alloc_send_skb(sk, fraglen + hh_len + 15,
8119 + (flags & MSG_DONTWAIT), &err);
8121 + /* On a non-blocking write, we check for send buffer
8122 + * usage on the first fragment only.
8124 + skb = sock_wmalloc(sk, fraglen + hh_len + 15, 1,
8133 + * Fill in the control structures
8136 + skb->priority = sk->priority;
8137 + skb->dst = dst_clone(&rt->u.dst);
8138 + skb_reserve(skb, hh_len);
8141 + * Find where to start putting bytes.
8144 + data = skb_put(skb, fraglen);
8145 + skb->nh.iph = (struct iphdr *)data;
8148 + * Only write IP header onto non-raw packets
8152 + struct iphdr *iph = (struct iphdr *)data;
8157 + iph->ihl += opt->optlen>>2;
8158 + ip_options_build(skb, opt,
8159 + ipc->addr, rt, offset);
8161 + iph->tos = sk->protinfo.af_inet.tos;
8162 + iph->tot_len = htons(fraglen - fragheaderlen + iph->ihl*4);
8163 + iph->frag_off = htons(offset>>3)|mf|df;
8166 + if (offset || !df) {
8167 + /* Select an unpredictable ident only
8168 + * for packets without DF or having
8169 + * been fragmented.
8171 + __ip_select_ident(iph, &rt->u.dst);
8176 + * Any further fragments will have MF set.
8178 + mf = htons(IP_MF);
8180 + if (rt->rt_type == RTN_MULTICAST)
8181 + iph->ttl = sk->protinfo.af_inet.mc_ttl;
8183 + iph->ttl = sk->protinfo.af_inet.ttl;
8184 + iph->protocol = sk->protocol;
8186 + iph->saddr = rt->rt_src;
8187 + iph->daddr = rt->rt_dst;
8188 + iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);
8189 + data += iph->ihl*4;
8193 + * User data callback
8196 + if (getfrag(frag, data, offset, fraglen-fragheaderlen, skb)) {
8202 + offset -= (maxfraglen-fragheaderlen);
8203 + fraglen = maxfraglen;
8207 + err = NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, skb, NULL,
8208 + skb->dst->dev, output_maybe_reroute);
8211 + err = sk->protinfo.af_inet.recverr ? net_xmit_errno(err) : 0;
8215 + } while (offset >= 0);
8218 + ip_statistics[smp_processor_id()*2 + !in_softirq()].IpFragCreates += nfrags;
8223 + IP_INC_STATS(IpOutDiscards);
8225 + ip_statistics[smp_processor_id()*2 + !in_softirq()].IpFragCreates += nfrags;
8230 + * Fast path for unfragmented packets.
8232 +int ip_build_xmit(struct sock *sk,
8233 + int getfrag (const void *,
8237 + struct sk_buff *),
8240 + struct ipcm_cookie *ipc,
8241 + struct rtable *rt,
8245 + struct sk_buff *skb;
8247 + struct iphdr *iph;
8250 + * Try the simple case first. This leaves fragmented frames, and by
8251 + * choice RAW frames within 20 bytes of maximum size(rare) to the long path
8254 + if (!sk->protinfo.af_inet.hdrincl) {
8255 + length += sizeof(struct iphdr);
8258 + * Check for slow path.
8260 + if (length > rt->u.dst.pmtu || ipc->opt != NULL)
8261 + return ip_build_xmit_slow(sk,getfrag,frag,length,ipc,rt,flags);
8263 + if (length > rt->u.dst.dev->mtu) {
8264 + ip_local_error(sk, EMSGSIZE, rt->rt_dst, sk->dport, rt->u.dst.dev->mtu);
8268 + if (flags&MSG_PROBE)
8272 + * Do path mtu discovery if needed.
8275 + if (ip_dont_fragment(sk, &rt->u.dst))
8276 + df = htons(IP_DF);
8279 + * Fast path for unfragmented frames without options.
8282 + int hh_len = (rt->u.dst.dev->hard_header_len + 15)&~15;
8284 + skb = sock_alloc_send_skb(sk, length+hh_len+15,
8285 + flags&MSG_DONTWAIT, &err);
8288 + skb_reserve(skb, hh_len);
8291 + skb->priority = sk->priority;
8292 + skb->dst = dst_clone(&rt->u.dst);
8294 + skb->nh.iph = iph = (struct iphdr *)skb_put(skb, length);
8296 + if(!sk->protinfo.af_inet.hdrincl) {
8299 + iph->tos=sk->protinfo.af_inet.tos;
8300 + iph->tot_len = htons(length);
8301 + iph->frag_off = df;
8302 + iph->ttl=sk->protinfo.af_inet.mc_ttl;
8303 + ip_select_ident(iph, &rt->u.dst, sk);
8304 + if (rt->rt_type != RTN_MULTICAST)
8305 + iph->ttl=sk->protinfo.af_inet.ttl;
8306 + iph->protocol=sk->protocol;
8307 + iph->saddr=rt->rt_src;
8308 + iph->daddr=rt->rt_dst;
8310 + iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);
8311 + err = getfrag(frag, ((char *)iph)+iph->ihl*4,0, length-iph->ihl*4, skb);
8314 + err = getfrag(frag, (void *)iph, 0, length, skb);
8319 + err = NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, skb, NULL, rt->u.dst.dev,
8320 + output_maybe_reroute);
8322 + err = sk->protinfo.af_inet.recverr ? net_xmit_errno(err) : 0;
8332 + IP_INC_STATS(IpOutDiscards);
8337 + * This IP datagram is too large to be sent in one piece. Break it up into
8338 + * smaller pieces (each of size equal to IP header plus
8339 + * a block of the data of the original IP data part) that will yet fit in a
8340 + * single device frame, and queue such a frame for sending.
8342 + * Yes this is inefficient, feel free to submit a quicker one.
8345 +int ip_fragment(struct sk_buff *skb, int (*output)(struct sk_buff*))
8347 + struct iphdr *iph;
8350 + struct net_device *dev;
8351 + struct sk_buff *skb2;
8352 + unsigned int mtu, hlen, left, len;
8354 + int not_last_frag;
8355 + struct rtable *rt = (struct rtable*)skb->dst;
8358 + dev = rt->u.dst.dev;
8361 + * Point into the IP datagram header.
8364 + iph = skb->nh.iph;
8367 + * Setup starting values.
8370 + hlen = iph->ihl * 4;
8371 + left = skb->len - hlen; /* Space per frame */
8372 + mtu = rt->u.dst.pmtu - hlen; /* Size of data space */
8373 + ptr = raw + hlen; /* Where to start from */
8376 + * Fragment the datagram.
8379 + offset = (ntohs(iph->frag_off) & IP_OFFSET) << 3;
8380 + not_last_frag = iph->frag_off & htons(IP_MF);
8383 + * Keep copying data until we run out.
8388 + /* IF: it doesn't fit, use 'mtu' - the data space left */
8391 + /* IF: we are not sending upto and including the packet end
8392 + then align the next start on an eight byte boundary */
8397 + * Allocate buffer.
8400 + if ((skb2 = alloc_skb(len+hlen+dev->hard_header_len+15,GFP_ATOMIC)) == NULL) {
8401 + NETDEBUG(printk(KERN_INFO "IP: frag: no memory for new fragment!\n"));
8407 + * Set up data on packet
8410 + skb2->pkt_type = skb->pkt_type;
8411 + skb2->priority = skb->priority;
8412 + skb_reserve(skb2, (dev->hard_header_len+15)&~15);
8413 + skb_put(skb2, len + hlen);
8414 + skb2->nh.raw = skb2->data;
8415 + skb2->h.raw = skb2->data + hlen;
8416 + skb2->protocol = skb->protocol;
8417 + skb2->security = skb->security;
8420 + * Charge the memory for the fragment to any owner
8421 + * it might possess
8425 + skb_set_owner_w(skb2, skb->sk);
8426 + skb2->dst = dst_clone(skb->dst);
8427 + skb2->dev = skb->dev;
8430 + * Copy the packet header into the new buffer.
8433 + memcpy(skb2->nh.raw, skb->data, hlen);
8436 + * Copy a block of the IP datagram.
8438 + if (skb_copy_bits(skb, ptr, skb2->h.raw, len))
8443 + * Fill in the new header fields.
8445 + iph = skb2->nh.iph;
8446 + iph->frag_off = htons((offset >> 3));
8448 + /* ANK: dirty, but effective trick. Upgrade options only if
8449 + * the segment to be fragmented was THE FIRST (otherwise,
8450 + * options are already fixed) and make it ONCE
8451 + * on the initial skb, so that all the following fragments
8452 + * will inherit fixed options.
8455 + ip_options_fragment(skb);
8457 + /* Copy the flags to each fragment. */
8458 + IPCB(skb2)->flags = IPCB(skb)->flags;
8461 + * Added AC : If we are fragmenting a fragment that's not the
8462 + * last fragment then keep MF on each bit
8464 + if (left > 0 || not_last_frag)
8465 + iph->frag_off |= htons(IP_MF);
8469 +#ifdef CONFIG_NET_SCHED
8470 + skb2->tc_index = skb->tc_index;
8472 +#ifdef CONFIG_NETFILTER
8473 + skb2->nfmark = skb->nfmark;
8474 + skb2->nfcache = skb->nfcache;
8475 + /* Connection association is same as pre-frag packet */
8476 + skb2->nfct = skb->nfct;
8477 + nf_conntrack_get(skb2->nfct);
8478 +#ifdef CONFIG_NETFILTER_DEBUG
8479 + skb2->nf_debug = skb->nf_debug;
8484 + * Put this fragment into the sending queue.
8487 + IP_INC_STATS(IpFragCreates);
8489 + iph->tot_len = htons(len + hlen);
8491 + ip_send_check(iph);
8493 + err = output(skb2);
8498 + IP_INC_STATS(IpFragOKs);
8503 + IP_INC_STATS(IpFragFails);
8508 + * Fetch data from kernel space and fill in checksum if needed.
8510 +static int ip_reply_glue_bits(const void *dptr, char *to, unsigned int offset,
8511 + unsigned int fraglen, struct sk_buff *skb)
8513 + struct ip_reply_arg *dp = (struct ip_reply_arg*)dptr;
8514 + u16 *pktp = (u16 *)to;
8515 + struct iovec *iov;
8519 + iov = &dp->iov[0];
8520 + if (offset >= iov->iov_len) {
8521 + offset -= iov->iov_len;
8525 + len = iov->iov_len - offset;
8526 + if (fraglen > len) { /* overlapping. */
8527 + dp->csum = csum_partial_copy_nocheck(iov->iov_base+offset, to, len,
8535 + dp->csum = csum_partial_copy_nocheck(iov->iov_base+offset, to, fraglen,
8538 + if (hdrflag && dp->csumoffset)
8539 + *(pktp + dp->csumoffset) = csum_fold(dp->csum); /* fill in checksum */
8544 + * Generic function to send a packet as reply to another packet.
8545 + * Used to send TCP resets so far. ICMP should use this function too.
8547 + * Should run single threaded per socket because it uses the sock
8548 + * structure to pass arguments.
8550 +void ip_send_reply(struct sock *sk, struct sk_buff *skb, struct ip_reply_arg *arg,
8554 + struct ip_options opt;
8557 + struct ipcm_cookie ipc;
8559 + struct rtable *rt = (struct rtable*)skb->dst;
8561 + if (ip_options_echo(&replyopts.opt, skb))
8564 + daddr = ipc.addr = rt->rt_src;
8567 + if (replyopts.opt.optlen) {
8568 + ipc.opt = &replyopts.opt;
8571 + daddr = replyopts.opt.faddr;
8574 + if (ip_route_output(&rt, daddr, rt->rt_spec_dst, RT_TOS(skb->nh.iph->tos), 0))
8577 + /* And let IP do all the hard work.
8579 + This chunk is not reenterable, hence spinlock.
8580 + Note that it uses the fact, that this function is called
8581 + with locally disabled BH and that sk cannot be already spinlocked.
8584 + sk->protinfo.af_inet.tos = skb->nh.iph->tos;
8585 + sk->priority = skb->priority;
8586 + sk->protocol = skb->nh.iph->protocol;
8587 + ip_build_xmit(sk, ip_reply_glue_bits, arg, len, &ipc, rt, MSG_DONTWAIT);
8588 + bh_unlock_sock(sk);
8594 + * IP protocol layer initialiser
8597 +static struct packet_type ip_packet_type =
8599 + __constant_htons(ETH_P_IP),
8600 + NULL, /* All devices */
8607 + * IP registers the packet type and then calls the subprotocol initialisers
8610 +void __init ip_init(void)
8612 + dev_add_pack(&ip_packet_type);
8617 +#ifdef CONFIG_IP_MULTICAST
8618 + proc_net_create("igmp", 0, ip_mc_procinfo);
8620 + proc_net_create("mcfilter", 0, ip_mcf_procinfo);
8622 diff -Nur linux-mips-cvs/net/ipv4/netfilter/Config.in linux-ebtables/net/ipv4/netfilter/Config.in
8623 --- linux-mips-cvs/net/ipv4/netfilter/Config.in 2005-01-20 03:19:25.000000000 +0100
8624 +++ linux-ebtables/net/ipv4/netfilter/Config.in 2005-02-07 05:52:50.000000000 +0100
8626 dep_tristate ' Unclean match support (EXPERIMENTAL)' CONFIG_IP_NF_MATCH_UNCLEAN $CONFIG_IP_NF_IPTABLES
8627 dep_tristate ' Owner match support (EXPERIMENTAL)' CONFIG_IP_NF_MATCH_OWNER $CONFIG_IP_NF_IPTABLES
8629 + if [ "$CONFIG_BRIDGE" != "n" ]; then
8630 + dep_tristate ' Physdev match support' CONFIG_IP_NF_MATCH_PHYSDEV $CONFIG_IP_NF_IPTABLES
8633 dep_tristate ' Packet filtering' CONFIG_IP_NF_FILTER $CONFIG_IP_NF_IPTABLES
8634 if [ "$CONFIG_IP_NF_FILTER" != "n" ]; then
8635 diff -Nur linux-mips-cvs/net/ipv4/netfilter/Makefile linux-ebtables/net/ipv4/netfilter/Makefile
8636 --- linux-mips-cvs/net/ipv4/netfilter/Makefile 2003-08-13 19:19:30.000000000 +0200
8637 +++ linux-ebtables/net/ipv4/netfilter/Makefile 2005-02-07 05:52:50.000000000 +0100
8639 obj-$(CONFIG_IP_NF_MATCH_UNCLEAN) += ipt_unclean.o
8640 obj-$(CONFIG_IP_NF_MATCH_TCPMSS) += ipt_tcpmss.o
8642 +obj-$(CONFIG_IP_NF_MATCH_PHYSDEV) += ipt_physdev.o
8645 obj-$(CONFIG_IP_NF_TARGET_REJECT) += ipt_REJECT.o
8646 obj-$(CONFIG_IP_NF_TARGET_MIRROR) += ipt_MIRROR.o
8647 diff -Nur linux-mips-cvs/net/ipv4/netfilter/ip_tables.c linux-ebtables/net/ipv4/netfilter/ip_tables.c
8648 --- linux-mips-cvs/net/ipv4/netfilter/ip_tables.c 2005-01-20 03:19:25.000000000 +0100
8649 +++ linux-ebtables/net/ipv4/netfilter/ip_tables.c 2005-02-07 05:52:50.000000000 +0100
8650 @@ -118,12 +118,19 @@
8652 ip_packet_match(const struct iphdr *ip,
8654 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
8655 + const char *physindev,
8658 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
8659 + const char *physoutdev,
8661 const struct ipt_ip *ipinfo,
8666 + unsigned long ret2 = 1;
8668 #define FWINV(bool,invflg) ((bool) ^ !!(ipinfo->invflags & invflg))
8670 @@ -153,7 +160,15 @@
8671 & ((const unsigned long *)ipinfo->iniface_mask)[i];
8674 - if (FWINV(ret != 0, IPT_INV_VIA_IN)) {
8675 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
8676 + for (i = 0, ret2 = 0; i < IFNAMSIZ/sizeof(unsigned long); i++) {
8677 + ret2 |= (((const unsigned long *)physindev)[i]
8678 + ^ ((const unsigned long *)ipinfo->iniface)[i])
8679 + & ((const unsigned long *)ipinfo->iniface_mask)[i];
8683 + if (FWINV(ret != 0 && ret2 != 0, IPT_INV_VIA_IN)) {
8684 dprintf("VIA in mismatch (%s vs %s).%s\n",
8685 indev, ipinfo->iniface,
8686 ipinfo->invflags&IPT_INV_VIA_IN ?" (INV)":"");
8687 @@ -166,7 +181,15 @@
8688 & ((const unsigned long *)ipinfo->outiface_mask)[i];
8691 - if (FWINV(ret != 0, IPT_INV_VIA_OUT)) {
8692 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
8693 + for (i = 0, ret2 = 0; i < IFNAMSIZ/sizeof(unsigned long); i++) {
8694 + ret2 |= (((const unsigned long *)physoutdev)[i]
8695 + ^ ((const unsigned long *)ipinfo->outiface)[i])
8696 + & ((const unsigned long *)ipinfo->outiface_mask)[i];
8700 + if (FWINV(ret != 0 && ret2 != 0, IPT_INV_VIA_OUT)) {
8701 dprintf("VIA out mismatch (%s vs %s).%s\n",
8702 outdev, ipinfo->outiface,
8703 ipinfo->invflags&IPT_INV_VIA_OUT ?" (INV)":"");
8705 /* Initializing verdict to NF_DROP keeps gcc happy. */
8706 unsigned int verdict = NF_DROP;
8707 const char *indev, *outdev;
8708 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
8709 + const char *physindev, *physoutdev;
8712 struct ipt_entry *e, *back;
8714 @@ -274,6 +300,13 @@
8715 datalen = (*pskb)->len - ip->ihl * 4;
8716 indev = in ? in->name : nulldevname;
8717 outdev = out ? out->name : nulldevname;
8718 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
8719 + physindev = ((*pskb)->nf_bridge && (*pskb)->nf_bridge->physindev) ?
8720 + (*pskb)->nf_bridge->physindev->name : nulldevname;
8721 + physoutdev = ((*pskb)->nf_bridge && (*pskb)->nf_bridge->physoutdev) ?
8722 + (*pskb)->nf_bridge->physoutdev->name : nulldevname;
8725 /* We handle fragments by dealing with the first fragment as
8726 * if it was a normal packet. All other fragments are treated
8727 * normally, except that they will NEVER match rules that ask
8728 @@ -309,7 +342,15 @@
8731 (*pskb)->nfcache |= e->nfcache;
8732 - if (ip_packet_match(ip, indev, outdev, &e->ip, offset)) {
8733 + if (ip_packet_match(ip, indev,
8734 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
8738 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
8741 + &e->ip, offset)) {
8742 struct ipt_entry_target *t;
8744 if (IPT_MATCH_ITERATE(e, do_match,
8745 diff -Nur linux-mips-cvs/net/ipv4/netfilter/ipt_LOG.c linux-ebtables/net/ipv4/netfilter/ipt_LOG.c
8746 --- linux-mips-cvs/net/ipv4/netfilter/ipt_LOG.c 2003-11-17 02:07:48.000000000 +0100
8747 +++ linux-ebtables/net/ipv4/netfilter/ipt_LOG.c 2005-02-07 05:52:50.000000000 +0100
8748 @@ -316,6 +316,18 @@
8751 out ? out->name : "");
8752 +#if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
8753 + if ((*pskb)->nf_bridge) {
8754 + struct net_device *physindev = (*pskb)->nf_bridge->physindev;
8755 + struct net_device *physoutdev = (*pskb)->nf_bridge->physoutdev;
8757 + if (physindev && in != physindev)
8758 + printk("PHYSIN=%s ", physindev->name);
8759 + if (physoutdev && out != physoutdev)
8760 + printk("PHYSOUT=%s ", physoutdev->name);
8765 /* MAC logging for input chain only. */
8767 diff -Nur linux-mips-cvs/net/ipv4/netfilter/ipt_REJECT.c linux-ebtables/net/ipv4/netfilter/ipt_REJECT.c
8768 --- linux-mips-cvs/net/ipv4/netfilter/ipt_REJECT.c 2005-01-20 03:19:25.000000000 +0100
8769 +++ linux-ebtables/net/ipv4/netfilter/ipt_REJECT.c 2005-02-07 05:52:50.000000000 +0100
8771 #include <net/route.h>
8772 #include <linux/netfilter_ipv4/ip_tables.h>
8773 #include <linux/netfilter_ipv4/ipt_REJECT.h>
8774 +#ifdef CONFIG_BRIDGE_NETFILTER
8775 +#include <linux/netfilter_bridge.h>
8779 #define DEBUGP printk
8781 struct rt_key key = {};
8784 - if (hook != NF_IP_FORWARD) {
8785 + /* We don't require ip forwarding to be enabled to be able to
8786 + * send a RST reply for bridged traffic. */
8787 + if (hook != NF_IP_FORWARD
8788 +#ifdef CONFIG_BRIDGE_NETFILTER
8789 + || (skb->nf_bridge && skb->nf_bridge->mask & BRNF_BRIDGED)
8792 key.dst = iph->saddr;
8793 if (hook == NF_IP_LOCAL_IN)
8794 key.src = iph->daddr;
8795 diff -Nur linux-mips-cvs/net/ipv4/netfilter/ipt_REJECT.c.orig linux-ebtables/net/ipv4/netfilter/ipt_REJECT.c.orig
8796 --- linux-mips-cvs/net/ipv4/netfilter/ipt_REJECT.c.orig 1970-01-01 01:00:00.000000000 +0100
8797 +++ linux-ebtables/net/ipv4/netfilter/ipt_REJECT.c.orig 2005-01-20 03:19:25.000000000 +0100
8800 + * This is a module which is used for rejecting packets.
8801 + * Added support for customized reject packets (Jozsef Kadlecsik).
8802 + * Added support for ICMP type-3-code-13 (Maciej Soltysiak). [RFC 1812]
8804 +#include <linux/config.h>
8805 +#include <linux/module.h>
8806 +#include <linux/skbuff.h>
8807 +#include <linux/ip.h>
8808 +#include <linux/udp.h>
8809 +#include <linux/icmp.h>
8810 +#include <net/icmp.h>
8811 +#include <net/ip.h>
8812 +#include <net/tcp.h>
8813 +#include <net/route.h>
8814 +#include <linux/netfilter_ipv4/ip_tables.h>
8815 +#include <linux/netfilter_ipv4/ipt_REJECT.h>
8818 +#define DEBUGP printk
8820 +#define DEBUGP(format, args...)
8823 +static inline struct rtable *route_reverse(struct sk_buff *skb, int hook)
8825 + struct iphdr *iph = skb->nh.iph;
8826 + struct dst_entry *odst;
8827 + struct rt_key key = {};
8828 + struct rtable *rt;
8830 + if (hook != NF_IP_FORWARD) {
8831 + key.dst = iph->saddr;
8832 + if (hook == NF_IP_LOCAL_IN)
8833 + key.src = iph->daddr;
8834 + key.tos = RT_TOS(iph->tos);
8836 + if (ip_route_output_key(&rt, &key) != 0)
8839 + /* non-local src, find valid iif to satisfy
8840 + * rp-filter when calling ip_route_input. */
8841 + key.dst = iph->daddr;
8842 + if (ip_route_output_key(&rt, &key) != 0)
8846 + if (ip_route_input(skb, iph->saddr, iph->daddr,
8847 + RT_TOS(iph->tos), rt->u.dst.dev) != 0) {
8848 + dst_release(&rt->u.dst);
8851 + dst_release(&rt->u.dst);
8852 + rt = (struct rtable *)skb->dst;
8856 + if (rt->u.dst.error) {
8857 + dst_release(&rt->u.dst);
8864 +/* Send RST reply */
8865 +static void send_reset(struct sk_buff *oldskb, int hook)
8867 + struct sk_buff *nskb;
8868 + struct tcphdr *otcph, *tcph;
8869 + struct rtable *rt;
8870 + unsigned int otcplen;
8871 + u_int16_t tmp_port;
8872 + u_int32_t tmp_addr;
8876 + /* IP header checks: fragment, too short. */
8877 + if (oldskb->nh.iph->frag_off & htons(IP_OFFSET)
8878 + || oldskb->len < (oldskb->nh.iph->ihl<<2) + sizeof(struct tcphdr))
8881 + otcph = (struct tcphdr *)((u_int32_t*)oldskb->nh.iph + oldskb->nh.iph->ihl);
8882 + otcplen = oldskb->len - oldskb->nh.iph->ihl*4;
8884 + /* No RST for RST. */
8888 + /* Check checksum. */
8889 + if (tcp_v4_check(otcph, otcplen, oldskb->nh.iph->saddr,
8890 + oldskb->nh.iph->daddr,
8891 + csum_partial((char *)otcph, otcplen, 0)) != 0)
8894 + if ((rt = route_reverse(oldskb, hook)) == NULL)
8897 + hh_len = (rt->u.dst.dev->hard_header_len + 15)&~15;
8900 + /* Copy skb (even if skb is about to be dropped, we can't just
8901 + clone it because there may be other things, such as tcpdump,
8902 + interested in it). We also need to expand headroom in case
8903 + hh_len of incoming interface < hh_len of outgoing interface */
8904 + nskb = skb_copy_expand(oldskb, hh_len, skb_tailroom(oldskb),
8907 + dst_release(&rt->u.dst);
8911 + dst_release(nskb->dst);
8912 + nskb->dst = &rt->u.dst;
8914 + /* This packet will not be the same as the other: clear nf fields */
8916 + nskb->nfcache = 0;
8919 + tcph = (struct tcphdr *)((u_int32_t*)nskb->nh.iph + nskb->nh.iph->ihl);
8921 + /* Swap source and dest */
8922 + tmp_addr = nskb->nh.iph->saddr;
8923 + nskb->nh.iph->saddr = nskb->nh.iph->daddr;
8924 + nskb->nh.iph->daddr = tmp_addr;
8925 + tmp_port = tcph->source;
8926 + tcph->source = tcph->dest;
8927 + tcph->dest = tmp_port;
8929 + /* Truncate to length (no data) */
8930 + tcph->doff = sizeof(struct tcphdr)/4;
8931 + skb_trim(nskb, nskb->nh.iph->ihl*4 + sizeof(struct tcphdr));
8932 + nskb->nh.iph->tot_len = htons(nskb->len);
8936 + tcph->seq = otcph->ack_seq;
8937 + tcph->ack_seq = 0;
8940 + tcph->ack_seq = htonl(ntohl(otcph->seq) + otcph->syn + otcph->fin
8941 + + otcplen - (otcph->doff<<2));
8946 + ((u_int8_t *)tcph)[13] = 0;
8948 + tcph->ack = needs_ack;
8951 + tcph->urg_ptr = 0;
8953 + /* Adjust TCP checksum */
8955 + tcph->check = tcp_v4_check(tcph, sizeof(struct tcphdr),
8956 + nskb->nh.iph->saddr,
8957 + nskb->nh.iph->daddr,
8958 + csum_partial((char *)tcph,
8959 + sizeof(struct tcphdr), 0));
8961 + /* Adjust IP TTL, DF */
8962 + nskb->nh.iph->ttl = MAXTTL;
8963 + /* Set DF, id = 0 */
8964 + nskb->nh.iph->frag_off = htons(IP_DF);
8965 + nskb->nh.iph->id = 0;
8967 + /* Adjust IP checksum */
8968 + nskb->nh.iph->check = 0;
8969 + nskb->nh.iph->check = ip_fast_csum((unsigned char *)nskb->nh.iph,
8970 + nskb->nh.iph->ihl);
8972 + /* "Never happens" */
8973 + if (nskb->len > nskb->dst->pmtu)
8976 + nf_ct_attach(nskb, oldskb);
8978 + NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, nskb, NULL, nskb->dst->dev,
8979 + ip_finish_output);
8986 +static void send_unreach(struct sk_buff *skb_in, int code)
8988 + struct iphdr *iph;
8989 + struct udphdr *udph;
8990 + struct icmphdr *icmph;
8991 + struct sk_buff *nskb;
8994 + int hh_len, length;
8995 + struct rtable *rt = (struct rtable*)skb_in->dst;
8996 + unsigned char *data;
9001 + /* FIXME: Use sysctl number. --RR */
9002 + if (!xrlim_allow(&rt->u.dst, 1*HZ))
9005 + iph = skb_in->nh.iph;
9007 + /* No replies to physical multicast/broadcast */
9008 + if (skb_in->pkt_type!=PACKET_HOST)
9011 + /* Now check at the protocol level */
9012 + if (rt->rt_flags&(RTCF_BROADCAST|RTCF_MULTICAST))
9015 + /* Only reply to fragment 0. */
9016 + if (iph->frag_off&htons(IP_OFFSET))
9019 + /* if UDP checksum is set, verify it's correct */
9020 + if (iph->protocol == IPPROTO_UDP
9021 + && skb_in->tail-(u8*)iph >= sizeof(struct udphdr)) {
9022 + int datalen = skb_in->len - (iph->ihl<<2);
9023 + udph = (struct udphdr *)((char *)iph + (iph->ihl<<2));
9025 + && csum_tcpudp_magic(iph->saddr, iph->daddr,
9026 + datalen, IPPROTO_UDP,
9027 + csum_partial((char *)udph, datalen,
9032 + /* If we send an ICMP error to an ICMP error a mess would result.. */
9033 + if (iph->protocol == IPPROTO_ICMP
9034 + && skb_in->tail-(u8*)iph >= sizeof(struct icmphdr)) {
9035 + icmph = (struct icmphdr *)((char *)iph + (iph->ihl<<2));
9036 + /* Between echo-reply (0) and timestamp (13),
9037 + everything except echo-request (8) is an error.
9038 + Also, anything greater than NR_ICMP_TYPES is
9039 + unknown, and hence should be treated as an error... */
9040 + if ((icmph->type < ICMP_TIMESTAMP
9041 + && icmph->type != ICMP_ECHOREPLY
9042 + && icmph->type != ICMP_ECHO)
9043 + || icmph->type > NR_ICMP_TYPES)
9047 + saddr = iph->daddr;
9048 + if (!(rt->rt_flags & RTCF_LOCAL))
9051 + tos = (iph->tos & IPTOS_TOS_MASK) | IPTOS_PREC_INTERNETCONTROL;
9053 + if (ip_route_output(&rt, iph->saddr, saddr, RT_TOS(tos), 0))
9056 + /* RFC says return as much as we can without exceeding 576 bytes. */
9057 + length = skb_in->len + sizeof(struct iphdr) + sizeof(struct icmphdr);
9059 + if (length > rt->u.dst.pmtu)
9060 + length = rt->u.dst.pmtu;
9064 + hh_len = (rt->u.dst.dev->hard_header_len + 15)&~15;
9066 + nskb = alloc_skb(hh_len+15+length, GFP_ATOMIC);
9072 + nskb->priority = 0;
9073 + nskb->dst = &rt->u.dst;
9074 + skb_reserve(nskb, hh_len);
9076 + /* Set up IP header */
9077 + iph = nskb->nh.iph
9078 + = (struct iphdr *)skb_put(nskb, sizeof(struct iphdr));
9082 + iph->tot_len = htons(length);
9084 + /* PMTU discovery never applies to ICMP packets. */
9085 + iph->frag_off = 0;
9087 + iph->ttl = MAXTTL;
9088 + ip_select_ident(iph, &rt->u.dst, NULL);
9089 + iph->protocol=IPPROTO_ICMP;
9090 + iph->saddr=rt->rt_src;
9091 + iph->daddr=rt->rt_dst;
9093 + iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);
9095 + /* Set up ICMP header. */
9096 + icmph = nskb->h.icmph
9097 + = (struct icmphdr *)skb_put(nskb, sizeof(struct icmphdr));
9098 + icmph->type = ICMP_DEST_UNREACH;
9099 + icmph->code = code;
9100 + icmph->un.gateway = 0;
9101 + icmph->checksum = 0;
9103 + /* Copy as much of original packet as will fit */
9104 + data = skb_put(nskb,
9105 + length - sizeof(struct iphdr) - sizeof(struct icmphdr));
9106 + /* FIXME: won't work with nonlinear skbs --RR */
9107 + memcpy(data, skb_in->nh.iph,
9108 + length - sizeof(struct iphdr) - sizeof(struct icmphdr));
9109 + icmph->checksum = ip_compute_csum((unsigned char *)icmph,
9110 + length - sizeof(struct iphdr));
9112 + nf_ct_attach(nskb, skb_in);
9114 + NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, nskb, NULL, nskb->dst->dev,
9115 + ip_finish_output);
9118 +static unsigned int reject(struct sk_buff **pskb,
9119 + unsigned int hooknum,
9120 + const struct net_device *in,
9121 + const struct net_device *out,
9122 + const void *targinfo,
9125 + const struct ipt_reject_info *reject = targinfo;
9127 + /* Our naive response construction doesn't deal with IP
9128 + options, and probably shouldn't try. */
9129 + if ((*pskb)->nh.iph->ihl<<2 != sizeof(struct iphdr))
9132 + /* WARNING: This code causes reentry within iptables.
9133 + This means that the iptables jump stack is now crap. We
9134 + must return an absolute verdict. --RR */
9135 + switch (reject->with) {
9136 + case IPT_ICMP_NET_UNREACHABLE:
9137 + send_unreach(*pskb, ICMP_NET_UNREACH);
9139 + case IPT_ICMP_HOST_UNREACHABLE:
9140 + send_unreach(*pskb, ICMP_HOST_UNREACH);
9142 + case IPT_ICMP_PROT_UNREACHABLE:
9143 + send_unreach(*pskb, ICMP_PROT_UNREACH);
9145 + case IPT_ICMP_PORT_UNREACHABLE:
9146 + send_unreach(*pskb, ICMP_PORT_UNREACH);
9148 + case IPT_ICMP_NET_PROHIBITED:
9149 + send_unreach(*pskb, ICMP_NET_ANO);
9151 + case IPT_ICMP_HOST_PROHIBITED:
9152 + send_unreach(*pskb, ICMP_HOST_ANO);
9154 + case IPT_ICMP_ADMIN_PROHIBITED:
9155 + send_unreach(*pskb, ICMP_PKT_FILTERED);
9157 + case IPT_TCP_RESET:
9158 + send_reset(*pskb, hooknum);
9159 + case IPT_ICMP_ECHOREPLY:
9160 + /* Doesn't happen. */
9167 +static int check(const char *tablename,
9168 + const struct ipt_entry *e,
9170 + unsigned int targinfosize,
9171 + unsigned int hook_mask)
9173 + const struct ipt_reject_info *rejinfo = targinfo;
9175 + if (targinfosize != IPT_ALIGN(sizeof(struct ipt_reject_info))) {
9176 + DEBUGP("REJECT: targinfosize %u != 0\n", targinfosize);
9180 + /* Only allow these for packet filtering. */
9181 + if (strcmp(tablename, "filter") != 0) {
9182 + DEBUGP("REJECT: bad table `%s'.\n", tablename);
9185 + if ((hook_mask & ~((1 << NF_IP_LOCAL_IN)
9186 + | (1 << NF_IP_FORWARD)
9187 + | (1 << NF_IP_LOCAL_OUT))) != 0) {
9188 + DEBUGP("REJECT: bad hook mask %X\n", hook_mask);
9192 + if (rejinfo->with == IPT_ICMP_ECHOREPLY) {
9193 + printk("REJECT: ECHOREPLY no longer supported.\n");
9195 + } else if (rejinfo->with == IPT_TCP_RESET) {
9196 + /* Must specify that it's a TCP packet */
9197 + if (e->ip.proto != IPPROTO_TCP
9198 + || (e->ip.invflags & IPT_INV_PROTO)) {
9199 + DEBUGP("REJECT: TCP_RESET illegal for non-tcp\n");
9207 +static struct ipt_target ipt_reject_reg
9208 += { { NULL, NULL }, "REJECT", reject, check, NULL, THIS_MODULE };
9210 +static int __init init(void)
9212 + if (ipt_register_target(&ipt_reject_reg))
9217 +static void __exit fini(void)
9219 + ipt_unregister_target(&ipt_reject_reg);
9224 +MODULE_LICENSE("GPL");
9225 diff -Nur linux-mips-cvs/net/ipv4/netfilter/ipt_physdev.c linux-ebtables/net/ipv4/netfilter/ipt_physdev.c
9226 --- linux-mips-cvs/net/ipv4/netfilter/ipt_physdev.c 1970-01-01 01:00:00.000000000 +0100
9227 +++ linux-ebtables/net/ipv4/netfilter/ipt_physdev.c 2005-02-07 05:52:50.000000000 +0100
9229 +/* Kernel module to match the bridge port in and
9230 + * out device for IP packets coming into contact with a bridge. */
9231 +#include <linux/module.h>
9232 +#include <linux/skbuff.h>
9233 +#include <linux/netfilter_ipv4/ipt_physdev.h>
9234 +#include <linux/netfilter_ipv4/ip_tables.h>
9235 +#include <linux/netfilter_bridge.h>
9236 +#include <linux/netdevice.h>
9241 +match(const struct sk_buff *skb,
9242 + const struct net_device *in,
9243 + const struct net_device *out,
9244 + const void *matchinfo,
9247 + u_int16_t datalen,
9251 + static const char nulldevname[IFNAMSIZ] = { 0 };
9252 + const struct ipt_physdev_info *info = matchinfo;
9253 + unsigned long ret;
9254 + const char *indev, *outdev;
9255 + struct nf_bridge_info *nf_bridge;
9257 + /* Not a bridged IP packet or no info available yet:
9258 + * LOCAL_OUT/mangle and LOCAL_OUT/nat don't know if
9259 + * the destination device will be a bridge. */
9260 + if (!(nf_bridge = skb->nf_bridge)) {
9261 + /* Return MATCH if the invert flags of the used options are on */
9262 + if ((info->bitmask & IPT_PHYSDEV_OP_BRIDGED) &&
9263 + !(info->invert & IPT_PHYSDEV_OP_BRIDGED))
9265 + if ((info->bitmask & IPT_PHYSDEV_OP_ISIN) &&
9266 + !(info->invert & IPT_PHYSDEV_OP_ISIN))
9268 + if ((info->bitmask & IPT_PHYSDEV_OP_ISOUT) &&
9269 + !(info->invert & IPT_PHYSDEV_OP_ISOUT))
9271 + if ((info->bitmask & IPT_PHYSDEV_OP_IN) &&
9272 + !(info->invert & IPT_PHYSDEV_OP_IN))
9274 + if ((info->bitmask & IPT_PHYSDEV_OP_OUT) &&
9275 + !(info->invert & IPT_PHYSDEV_OP_OUT))
9280 + /* This only makes sense in the FORWARD and POSTROUTING chains */
9281 + if ((info->bitmask & IPT_PHYSDEV_OP_BRIDGED) &&
9282 + (!!(nf_bridge->mask & BRNF_BRIDGED) ^
9283 + !(info->invert & IPT_PHYSDEV_OP_BRIDGED)))
9286 + if ((info->bitmask & IPT_PHYSDEV_OP_ISIN &&
9287 + (!nf_bridge->physindev ^ !!(info->invert & IPT_PHYSDEV_OP_ISIN))) ||
9288 + (info->bitmask & IPT_PHYSDEV_OP_ISOUT &&
9289 + (!nf_bridge->physoutdev ^ !!(info->invert & IPT_PHYSDEV_OP_ISOUT))))
9292 + if (!(info->bitmask & IPT_PHYSDEV_OP_IN))
9293 + goto match_outdev;
9294 + indev = nf_bridge->physindev ? nf_bridge->physindev->name : nulldevname;
9295 + for (i = 0, ret = 0; i < IFNAMSIZ/sizeof(unsigned long); i++) {
9296 + ret |= (((const unsigned long *)indev)[i]
9297 + ^ ((const unsigned long *)info->physindev)[i])
9298 + & ((const unsigned long *)info->in_mask)[i];
9301 + if ((ret == 0) ^ !(info->invert & IPT_PHYSDEV_OP_IN))
9305 + if (!(info->bitmask & IPT_PHYSDEV_OP_OUT))
9307 + outdev = nf_bridge->physoutdev ?
9308 + nf_bridge->physoutdev->name : nulldevname;
9309 + for (i = 0, ret = 0; i < IFNAMSIZ/sizeof(unsigned long); i++) {
9310 + ret |= (((const unsigned long *)outdev)[i]
9311 + ^ ((const unsigned long *)info->physoutdev)[i])
9312 + & ((const unsigned long *)info->out_mask)[i];
9315 + return (ret != 0) ^ !(info->invert & IPT_PHYSDEV_OP_OUT);
9319 +checkentry(const char *tablename,
9320 + const struct ipt_ip *ip,
9322 + unsigned int matchsize,
9323 + unsigned int hook_mask)
9325 + const struct ipt_physdev_info *info = matchinfo;
9327 + if (matchsize != IPT_ALIGN(sizeof(struct ipt_physdev_info)))
9329 + if (!(info->bitmask & IPT_PHYSDEV_OP_MASK) ||
9330 + info->bitmask & ~IPT_PHYSDEV_OP_MASK)
9335 +static struct ipt_match physdev_match = {
9336 + .name = "physdev",
9338 + .checkentry = &checkentry,
9339 + .me = THIS_MODULE,
9342 +static int __init init(void)
9344 + return ipt_register_match(&physdev_match);
9347 +static void __exit fini(void)
9349 + ipt_unregister_match(&physdev_match);
9354 +MODULE_LICENSE("GPL");