1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef __LINUX_BRIDGE_NETFILTER_H 3 #define __LINUX_BRIDGE_NETFILTER_H 4 5 #include <uapi/linux/netfilter_bridge.h> 6 #include <linux/skbuff.h> 7 8 struct nf_bridge_frag_data { 9 char mac[ETH_HLEN]; 10 bool vlan_present; 11 u16 vlan_tci; 12 __be16 vlan_proto; 13 }; 14 15 #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER) 16 17 int br_handle_frame_finish(struct net *net, struct sock *sk, struct sk_buff *skb); 18 br_drop_fake_rtable(struct sk_buff * skb)19static inline void br_drop_fake_rtable(struct sk_buff *skb) 20 { 21 struct dst_entry *dst = skb_dst(skb); 22 23 if (dst && (dst->flags & DST_FAKE_RTABLE)) 24 skb_dst_drop(skb); 25 } 26 27 static inline struct nf_bridge_info * nf_bridge_info_get(const struct sk_buff * skb)28nf_bridge_info_get(const struct sk_buff *skb) 29 { 30 return skb_ext_find(skb, SKB_EXT_BRIDGE_NF); 31 } 32 nf_bridge_info_exists(const struct sk_buff * skb)33static inline bool nf_bridge_info_exists(const struct sk_buff *skb) 34 { 35 return skb_ext_exist(skb, SKB_EXT_BRIDGE_NF); 36 } 37 nf_bridge_get_physinif(const struct sk_buff * skb)38static inline int nf_bridge_get_physinif(const struct sk_buff *skb) 39 { 40 const struct nf_bridge_info *nf_bridge = nf_bridge_info_get(skb); 41 42 if (!nf_bridge) 43 return 0; 44 45 return nf_bridge->physinif; 46 } 47 nf_bridge_get_physoutif(const struct sk_buff * skb)48static inline int nf_bridge_get_physoutif(const struct sk_buff *skb) 49 { 50 const struct nf_bridge_info *nf_bridge = nf_bridge_info_get(skb); 51 52 if (!nf_bridge) 53 return 0; 54 55 return nf_bridge->physoutdev ? nf_bridge->physoutdev->ifindex : 0; 56 } 57 58 static inline struct net_device * nf_bridge_get_physindev(const struct sk_buff * skb,struct net * net)59nf_bridge_get_physindev(const struct sk_buff *skb, struct net *net) 60 { 61 const struct nf_bridge_info *nf_bridge = nf_bridge_info_get(skb); 62 63 return nf_bridge ? dev_get_by_index_rcu(net, nf_bridge->physinif) : NULL; 64 } 65 66 static inline struct net_device * nf_bridge_get_physoutdev(const struct sk_buff * skb)67nf_bridge_get_physoutdev(const struct sk_buff *skb) 68 { 69 const struct nf_bridge_info *nf_bridge = nf_bridge_info_get(skb); 70 71 return nf_bridge ? nf_bridge->physoutdev : NULL; 72 } 73 nf_bridge_in_prerouting(const struct sk_buff * skb)74static inline bool nf_bridge_in_prerouting(const struct sk_buff *skb) 75 { 76 const struct nf_bridge_info *nf_bridge = nf_bridge_info_get(skb); 77 78 return nf_bridge && nf_bridge->in_prerouting; 79 } 80 #else 81 #define br_drop_fake_rtable(skb) do { } while (0) nf_bridge_in_prerouting(const struct sk_buff * skb)82static inline bool nf_bridge_in_prerouting(const struct sk_buff *skb) 83 { 84 return false; 85 } 86 #endif /* CONFIG_BRIDGE_NETFILTER */ 87 88 #endif 89