linux 2.6.16.38 w/ vs2.0.3-rc1
[linux-2.6.git] / include / linux / netfilter_bridge.h
1 #ifndef __LINUX_BRIDGE_NETFILTER_H
2 #define __LINUX_BRIDGE_NETFILTER_H
3
4 /* bridge-specific defines for netfilter. 
5  */
6
7 #include <linux/config.h>
8 #include <linux/netfilter.h>
9 #if defined(__KERNEL__) && defined(CONFIG_BRIDGE_NETFILTER)
10 #include <asm/atomic.h>
11 #include <linux/if_ether.h>
12 #endif
13
14 /* Bridge Hooks */
15 /* After promisc drops, checksum checks. */
16 #define NF_BR_PRE_ROUTING       0
17 /* If the packet is destined for this box. */
18 #define NF_BR_LOCAL_IN          1
19 /* If the packet is destined for another interface. */
20 #define NF_BR_FORWARD           2
21 /* Packets coming from a local process. */
22 #define NF_BR_LOCAL_OUT         3
23 /* Packets about to hit the wire. */
24 #define NF_BR_POST_ROUTING      4
25 /* Not really a hook, but used for the ebtables broute table */
26 #define NF_BR_BROUTING          5
27 #define NF_BR_NUMHOOKS          6
28
29 #ifdef __KERNEL__
30
31 enum nf_br_hook_priorities {
32         NF_BR_PRI_FIRST = INT_MIN,
33         NF_BR_PRI_NAT_DST_BRIDGED = -300,
34         NF_BR_PRI_FILTER_BRIDGED = -200,
35         NF_BR_PRI_BRNF = 0,
36         NF_BR_PRI_NAT_DST_OTHER = 100,
37         NF_BR_PRI_FILTER_OTHER = 200,
38         NF_BR_PRI_NAT_SRC = 300,
39         NF_BR_PRI_LAST = INT_MAX,
40 };
41
42 #ifdef CONFIG_BRIDGE_NETFILTER
43
44 #define BRNF_PKT_TYPE                   0x01
45 #define BRNF_BRIDGED_DNAT               0x02
46 #define BRNF_DONT_TAKE_PARENT           0x04
47 #define BRNF_BRIDGED                    0x08
48 #define BRNF_NF_BRIDGE_PREROUTING       0x10
49
50 static inline
51 struct nf_bridge_info *nf_bridge_alloc(struct sk_buff *skb)
52 {
53         struct nf_bridge_info **nf_bridge = &(skb->nf_bridge);
54
55         if ((*nf_bridge = kmalloc(sizeof(**nf_bridge), GFP_ATOMIC)) != NULL) {
56                 atomic_set(&(*nf_bridge)->use, 1);
57                 (*nf_bridge)->mask = 0;
58                 (*nf_bridge)->physindev = (*nf_bridge)->physoutdev = NULL;
59 #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
60                 (*nf_bridge)->netoutdev = NULL;
61 #endif
62         }
63
64         return *nf_bridge;
65 }
66
67 /* Only used in br_forward.c */
68 static inline int nf_bridge_maybe_copy_header(struct sk_buff *skb)
69 {
70         int err;
71
72         if (skb->nf_bridge) {
73                 if (skb->protocol == __constant_htons(ETH_P_8021Q)) {
74                         err = skb_cow(skb, 18);
75                         if (err)
76                                 return err;
77                         memcpy(skb->data - 18, skb->nf_bridge->data, 18);
78                         skb_push(skb, 4);
79                 } else {
80                         err = skb_cow(skb, 16);
81                         if (err)
82                                 return err;
83                         memcpy(skb->data - 16, skb->nf_bridge->data, 16);
84                 }
85         }
86         return 0;
87 }
88
89 static inline
90 void nf_bridge_save_header(struct sk_buff *skb)
91 {
92         int header_size = 16;
93
94         if (skb->protocol == __constant_htons(ETH_P_8021Q))
95                 header_size = 18;
96
97         memcpy(skb->nf_bridge->data, skb->data - header_size, header_size);
98 }
99
100 /* This is called by the IP fragmenting code and it ensures there is
101  * enough room for the encapsulating header (if there is one). */
102 static inline
103 int nf_bridge_pad(struct sk_buff *skb)
104 {
105         if (skb->protocol == __constant_htons(ETH_P_IP))
106                 return 0;
107         if (skb->nf_bridge) {
108                 if (skb->protocol == __constant_htons(ETH_P_8021Q))
109                         return 4;
110         }
111         return 0;
112 }
113
114 struct bridge_skb_cb {
115         union {
116                 __u32 ipv4;
117         } daddr;
118 };
119 #endif /* CONFIG_BRIDGE_NETFILTER */
120
121 #endif /* __KERNEL__ */
122 #endif