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 | |
David Howells | 607ca46 | 2012-10-13 10:46:48 +0100 | [diff] [blame] | 4 | #include <uapi/linux/netfilter_bridge.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | |
| 7 | enum nf_br_hook_priorities { |
| 8 | NF_BR_PRI_FIRST = INT_MIN, |
| 9 | NF_BR_PRI_NAT_DST_BRIDGED = -300, |
| 10 | NF_BR_PRI_FILTER_BRIDGED = -200, |
| 11 | NF_BR_PRI_BRNF = 0, |
| 12 | NF_BR_PRI_NAT_DST_OTHER = 100, |
| 13 | NF_BR_PRI_FILTER_OTHER = 200, |
| 14 | NF_BR_PRI_NAT_SRC = 300, |
| 15 | NF_BR_PRI_LAST = INT_MAX, |
| 16 | }; |
| 17 | |
Pablo Neira Ayuso | 34666d4 | 2014-09-18 11:29:03 +0200 | [diff] [blame^] | 18 | #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | |
| 20 | #define BRNF_PKT_TYPE 0x01 |
| 21 | #define BRNF_BRIDGED_DNAT 0x02 |
Bart De Schuymer | ea2d9b4 | 2010-04-15 12:14:51 +0200 | [diff] [blame] | 22 | #define BRNF_BRIDGED 0x04 |
| 23 | #define BRNF_NF_BRIDGE_PREROUTING 0x08 |
Bart De Schuymer | e179e63 | 2010-04-15 12:26:39 +0200 | [diff] [blame] | 24 | #define BRNF_8021Q 0x10 |
| 25 | #define BRNF_PPPoE 0x20 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
Patrick McHardy | fc38582 | 2007-05-03 03:36:16 -0700 | [diff] [blame] | 27 | static inline unsigned int nf_bridge_encap_header_len(const struct sk_buff *skb) |
| 28 | { |
| 29 | switch (skb->protocol) { |
Harvey Harrison | f3a7c66 | 2009-02-14 22:58:35 -0800 | [diff] [blame] | 30 | case __cpu_to_be16(ETH_P_8021Q): |
Patrick McHardy | fc38582 | 2007-05-03 03:36:16 -0700 | [diff] [blame] | 31 | return VLAN_HLEN; |
Harvey Harrison | f3a7c66 | 2009-02-14 22:58:35 -0800 | [diff] [blame] | 32 | case __cpu_to_be16(ETH_P_PPP_SES): |
Patrick McHardy | fc38582 | 2007-05-03 03:36:16 -0700 | [diff] [blame] | 33 | return PPPOE_SES_HLEN; |
| 34 | default: |
| 35 | return 0; |
| 36 | } |
| 37 | } |
| 38 | |
Pablo Neira Ayuso | 7276ca3 | 2014-09-22 13:28:16 +0200 | [diff] [blame] | 39 | static inline void nf_bridge_update_protocol(struct sk_buff *skb) |
| 40 | { |
| 41 | if (skb->nf_bridge->mask & BRNF_8021Q) |
| 42 | skb->protocol = htons(ETH_P_8021Q); |
| 43 | else if (skb->nf_bridge->mask & BRNF_PPPoE) |
| 44 | skb->protocol = htons(ETH_P_PPP_SES); |
| 45 | } |
| 46 | |
| 47 | /* Fill in the header for fragmented IP packets handled by |
| 48 | * the IPv4 connection tracking code. |
| 49 | * |
| 50 | * Only used in br_forward.c |
| 51 | */ |
| 52 | static inline int nf_bridge_copy_header(struct sk_buff *skb) |
| 53 | { |
| 54 | int err; |
| 55 | unsigned int header_size; |
| 56 | |
| 57 | nf_bridge_update_protocol(skb); |
| 58 | header_size = ETH_HLEN + nf_bridge_encap_header_len(skb); |
| 59 | err = skb_cow_head(skb, header_size); |
| 60 | if (err) |
| 61 | return err; |
| 62 | |
| 63 | skb_copy_to_linear_data_offset(skb, -header_size, |
| 64 | skb->nf_bridge->data, header_size); |
| 65 | __skb_push(skb, nf_bridge_encap_header_len(skb)); |
| 66 | return 0; |
| 67 | } |
| 68 | |
| 69 | static inline int nf_bridge_maybe_copy_header(struct sk_buff *skb) |
| 70 | { |
| 71 | if (skb->nf_bridge && |
| 72 | skb->nf_bridge->mask & (BRNF_BRIDGED | BRNF_BRIDGED_DNAT)) |
| 73 | return nf_bridge_copy_header(skb); |
| 74 | return 0; |
| 75 | } |
| 76 | |
Bart De Schuymer | 6c79bf0 | 2010-04-20 16:22:01 +0200 | [diff] [blame] | 77 | static inline unsigned int nf_bridge_mtu_reduction(const struct sk_buff *skb) |
| 78 | { |
| 79 | if (unlikely(skb->nf_bridge->mask & BRNF_PPPoE)) |
| 80 | return PPPOE_SES_HLEN; |
| 81 | return 0; |
| 82 | } |
| 83 | |
Joe Perches | a0f4ecf | 2013-09-26 14:48:15 -0700 | [diff] [blame] | 84 | int br_handle_frame_finish(struct sk_buff *skb); |
Bart De Schuymer | ea2d9b4 | 2010-04-15 12:14:51 +0200 | [diff] [blame] | 85 | /* Only used in br_device.c */ |
| 86 | static inline int br_nf_pre_routing_finish_bridge_slow(struct sk_buff *skb) |
| 87 | { |
| 88 | struct nf_bridge_info *nf_bridge = skb->nf_bridge; |
| 89 | |
| 90 | skb_pull(skb, ETH_HLEN); |
| 91 | nf_bridge->mask ^= BRNF_BRIDGED_DNAT; |
Bart De Schuymer | e179e63 | 2010-04-15 12:26:39 +0200 | [diff] [blame] | 92 | skb_copy_to_linear_data_offset(skb, -(ETH_HLEN-ETH_ALEN), |
| 93 | skb->nf_bridge->data, ETH_HLEN-ETH_ALEN); |
Bart De Schuymer | ea2d9b4 | 2010-04-15 12:14:51 +0200 | [diff] [blame] | 94 | skb->dev = nf_bridge->physindev; |
| 95 | return br_handle_frame_finish(skb); |
| 96 | } |
| 97 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | /* This is called by the IP fragmenting code and it ensures there is |
| 99 | * enough room for the encapsulating header (if there is one). */ |
Patrick McHardy | fc38582 | 2007-05-03 03:36:16 -0700 | [diff] [blame] | 100 | static inline unsigned int nf_bridge_pad(const struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | { |
Patrick McHardy | fc38582 | 2007-05-03 03:36:16 -0700 | [diff] [blame] | 102 | if (skb->nf_bridge) |
| 103 | return nf_bridge_encap_header_len(skb); |
| 104 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | struct bridge_skb_cb { |
| 108 | union { |
Al Viro | 47c183fa | 2006-11-14 21:11:51 -0800 | [diff] [blame] | 109 | __be32 ipv4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | } daddr; |
| 111 | }; |
Patrick McHardy | 10ea6ac | 2006-07-24 22:54:55 -0700 | [diff] [blame] | 112 | |
Peter Huang (Peng) | a881e96 | 2012-04-19 20:12:51 +0000 | [diff] [blame] | 113 | static inline void br_drop_fake_rtable(struct sk_buff *skb) |
| 114 | { |
| 115 | struct dst_entry *dst = skb_dst(skb); |
| 116 | |
| 117 | if (dst && (dst->flags & DST_FAKE_RTABLE)) |
| 118 | skb_dst_drop(skb); |
| 119 | } |
| 120 | |
Stephen Hemminger | 07317621 | 2006-08-29 17:48:17 -0700 | [diff] [blame] | 121 | #else |
| 122 | #define nf_bridge_maybe_copy_header(skb) (0) |
Stephen Hemminger | 9bcfcaf | 2006-08-29 17:48:57 -0700 | [diff] [blame] | 123 | #define nf_bridge_pad(skb) (0) |
Peter Huang (Peng) | a881e96 | 2012-04-19 20:12:51 +0000 | [diff] [blame] | 124 | #define br_drop_fake_rtable(skb) do { } while (0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | #endif /* CONFIG_BRIDGE_NETFILTER */ |
| 126 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | #endif |