]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - include/linux/netfilter_bridge.h
bridge: move mac header copying into br_netfilter
[karo-tx-linux.git] / include / linux / netfilter_bridge.h
1 #ifndef __LINUX_BRIDGE_NETFILTER_H
2 #define __LINUX_BRIDGE_NETFILTER_H
3
4 #include <uapi/linux/netfilter_bridge.h>
5
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
18 #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
19
20 #define BRNF_PKT_TYPE                   0x01
21 #define BRNF_BRIDGED_DNAT               0x02
22 #define BRNF_BRIDGED                    0x04
23 #define BRNF_NF_BRIDGE_PREROUTING       0x08
24 #define BRNF_8021Q                      0x10
25 #define BRNF_PPPoE                      0x20
26
27 static inline unsigned int nf_bridge_encap_header_len(const struct sk_buff *skb)
28 {
29         switch (skb->protocol) {
30         case __cpu_to_be16(ETH_P_8021Q):
31                 return VLAN_HLEN;
32         case __cpu_to_be16(ETH_P_PPP_SES):
33                 return PPPOE_SES_HLEN;
34         default:
35                 return 0;
36         }
37 }
38
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 static inline unsigned int nf_bridge_mtu_reduction(const struct sk_buff *skb)
48 {
49         if (unlikely(skb->nf_bridge->mask & BRNF_PPPoE))
50                 return PPPOE_SES_HLEN;
51         return 0;
52 }
53
54 int br_handle_frame_finish(struct sk_buff *skb);
55 /* Only used in br_device.c */
56 static inline int br_nf_pre_routing_finish_bridge_slow(struct sk_buff *skb)
57 {
58         struct nf_bridge_info *nf_bridge = skb->nf_bridge;
59
60         skb_pull(skb, ETH_HLEN);
61         nf_bridge->mask ^= BRNF_BRIDGED_DNAT;
62         skb_copy_to_linear_data_offset(skb, -(ETH_HLEN-ETH_ALEN),
63                                        skb->nf_bridge->data, ETH_HLEN-ETH_ALEN);
64         skb->dev = nf_bridge->physindev;
65         return br_handle_frame_finish(skb);
66 }
67
68 /* This is called by the IP fragmenting code and it ensures there is
69  * enough room for the encapsulating header (if there is one). */
70 static inline unsigned int nf_bridge_pad(const struct sk_buff *skb)
71 {
72         if (skb->nf_bridge)
73                 return nf_bridge_encap_header_len(skb);
74         return 0;
75 }
76
77 struct bridge_skb_cb {
78         union {
79                 __be32 ipv4;
80         } daddr;
81 };
82
83 static inline void br_drop_fake_rtable(struct sk_buff *skb)
84 {
85         struct dst_entry *dst = skb_dst(skb);
86
87         if (dst && (dst->flags & DST_FAKE_RTABLE))
88                 skb_dst_drop(skb);
89 }
90
91 #else
92 #define nf_bridge_pad(skb)                      (0)
93 #define br_drop_fake_rtable(skb)                do { } while (0)
94 #endif /* CONFIG_BRIDGE_NETFILTER */
95
96 #endif