Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef __LINUX_BRIDGE_NETFILTER_H |
| 2 | #define __LINUX_BRIDGE_NETFILTER_H |
| 3 | |
| 4 | /* bridge-specific defines for netfilter. |
| 5 | */ |
| 6 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | #include <linux/netfilter.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | #include <linux/if_ether.h> |
Stephen Hemminger | 9bcfcaf | 2006-08-29 17:48:57 -0700 | [diff] [blame] | 9 | #include <linux/if_vlan.h> |
Michael Milner | 516299d | 2007-04-12 22:14:23 -0700 | [diff] [blame] | 10 | #include <linux/if_pppox.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | |
| 12 | /* Bridge Hooks */ |
| 13 | /* After promisc drops, checksum checks. */ |
| 14 | #define NF_BR_PRE_ROUTING 0 |
| 15 | /* If the packet is destined for this box. */ |
| 16 | #define NF_BR_LOCAL_IN 1 |
| 17 | /* If the packet is destined for another interface. */ |
| 18 | #define NF_BR_FORWARD 2 |
| 19 | /* Packets coming from a local process. */ |
| 20 | #define NF_BR_LOCAL_OUT 3 |
| 21 | /* Packets about to hit the wire. */ |
| 22 | #define NF_BR_POST_ROUTING 4 |
| 23 | /* Not really a hook, but used for the ebtables broute table */ |
| 24 | #define NF_BR_BROUTING 5 |
| 25 | #define NF_BR_NUMHOOKS 6 |
| 26 | |
| 27 | #ifdef __KERNEL__ |
| 28 | |
| 29 | enum nf_br_hook_priorities { |
| 30 | NF_BR_PRI_FIRST = INT_MIN, |
| 31 | NF_BR_PRI_NAT_DST_BRIDGED = -300, |
| 32 | NF_BR_PRI_FILTER_BRIDGED = -200, |
| 33 | NF_BR_PRI_BRNF = 0, |
| 34 | NF_BR_PRI_NAT_DST_OTHER = 100, |
| 35 | NF_BR_PRI_FILTER_OTHER = 200, |
| 36 | NF_BR_PRI_NAT_SRC = 300, |
| 37 | NF_BR_PRI_LAST = INT_MAX, |
| 38 | }; |
| 39 | |
| 40 | #ifdef CONFIG_BRIDGE_NETFILTER |
| 41 | |
| 42 | #define BRNF_PKT_TYPE 0x01 |
| 43 | #define BRNF_BRIDGED_DNAT 0x02 |
Bart De Schuymer | ea2d9b4 | 2010-04-15 12:14:51 +0200 | [diff] [blame^] | 44 | #define BRNF_BRIDGED 0x04 |
| 45 | #define BRNF_NF_BRIDGE_PREROUTING 0x08 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | |
| 48 | /* Only used in br_forward.c */ |
Stephen Hemminger | 07317621 | 2006-08-29 17:48:17 -0700 | [diff] [blame] | 49 | extern int nf_bridge_copy_header(struct sk_buff *skb); |
| 50 | static inline int nf_bridge_maybe_copy_header(struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | { |
Patrick McHardy | 4a9ecd5 | 2007-12-13 09:32:04 -0800 | [diff] [blame] | 52 | if (skb->nf_bridge && |
| 53 | skb->nf_bridge->mask & (BRNF_BRIDGED | BRNF_BRIDGED_DNAT)) |
Stephen Hemminger | 07317621 | 2006-08-29 17:48:17 -0700 | [diff] [blame] | 54 | return nf_bridge_copy_header(skb); |
| 55 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | } |
| 57 | |
Patrick McHardy | fc38582 | 2007-05-03 03:36:16 -0700 | [diff] [blame] | 58 | static inline unsigned int nf_bridge_encap_header_len(const struct sk_buff *skb) |
| 59 | { |
| 60 | switch (skb->protocol) { |
Harvey Harrison | f3a7c66 | 2009-02-14 22:58:35 -0800 | [diff] [blame] | 61 | case __cpu_to_be16(ETH_P_8021Q): |
Patrick McHardy | fc38582 | 2007-05-03 03:36:16 -0700 | [diff] [blame] | 62 | return VLAN_HLEN; |
Harvey Harrison | f3a7c66 | 2009-02-14 22:58:35 -0800 | [diff] [blame] | 63 | case __cpu_to_be16(ETH_P_PPP_SES): |
Patrick McHardy | fc38582 | 2007-05-03 03:36:16 -0700 | [diff] [blame] | 64 | return PPPOE_SES_HLEN; |
| 65 | default: |
| 66 | return 0; |
| 67 | } |
| 68 | } |
| 69 | |
Bart De Schuymer | ea2d9b4 | 2010-04-15 12:14:51 +0200 | [diff] [blame^] | 70 | extern int br_handle_frame_finish(struct sk_buff *skb); |
| 71 | /* Only used in br_device.c */ |
| 72 | static inline int br_nf_pre_routing_finish_bridge_slow(struct sk_buff *skb) |
| 73 | { |
| 74 | struct nf_bridge_info *nf_bridge = skb->nf_bridge; |
| 75 | |
| 76 | skb_pull(skb, ETH_HLEN); |
| 77 | nf_bridge->mask ^= BRNF_BRIDGED_DNAT; |
| 78 | skb->dev = nf_bridge->physindev; |
| 79 | return br_handle_frame_finish(skb); |
| 80 | } |
| 81 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | /* This is called by the IP fragmenting code and it ensures there is |
| 83 | * enough room for the encapsulating header (if there is one). */ |
Patrick McHardy | fc38582 | 2007-05-03 03:36:16 -0700 | [diff] [blame] | 84 | static inline unsigned int nf_bridge_pad(const struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | { |
Patrick McHardy | fc38582 | 2007-05-03 03:36:16 -0700 | [diff] [blame] | 86 | if (skb->nf_bridge) |
| 87 | return nf_bridge_encap_header_len(skb); |
| 88 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | struct bridge_skb_cb { |
| 92 | union { |
Al Viro | 47c183fa | 2006-11-14 21:11:51 -0800 | [diff] [blame] | 93 | __be32 ipv4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | } daddr; |
| 95 | }; |
Patrick McHardy | 10ea6ac | 2006-07-24 22:54:55 -0700 | [diff] [blame] | 96 | |
Stephen Hemminger | 07317621 | 2006-08-29 17:48:17 -0700 | [diff] [blame] | 97 | #else |
| 98 | #define nf_bridge_maybe_copy_header(skb) (0) |
Stephen Hemminger | 9bcfcaf | 2006-08-29 17:48:57 -0700 | [diff] [blame] | 99 | #define nf_bridge_pad(skb) (0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | #endif /* CONFIG_BRIDGE_NETFILTER */ |
| 101 | |
| 102 | #endif /* __KERNEL__ */ |
| 103 | #endif |