net: convert bridge_nf to use skb extension infrastructure
[linux-2.6-block.git] / include / linux / netfilter_bridge.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
1da177e4
LT
2#ifndef __LINUX_BRIDGE_NETFILTER_H
3#define __LINUX_BRIDGE_NETFILTER_H
4
607ca46e 5#include <uapi/linux/netfilter_bridge.h>
c737b7c4 6#include <linux/skbuff.h>
1da177e4 7
34666d46 8#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
1da177e4 9
0c4b51f0 10int br_handle_frame_finish(struct net *net, struct sock *sk, struct sk_buff *skb);
ea2d9b41 11
a881e963
PHP
12static inline void br_drop_fake_rtable(struct sk_buff *skb)
13{
14 struct dst_entry *dst = skb_dst(skb);
15
16 if (dst && (dst->flags & DST_FAKE_RTABLE))
17 skb_dst_drop(skb);
18}
19
c4b0e771
FW
20static inline struct nf_bridge_info *
21nf_bridge_info_get(const struct sk_buff *skb)
22{
de8bda1d 23 return skb_ext_find(skb, SKB_EXT_BRIDGE_NF);
c4b0e771
FW
24}
25
26static inline bool nf_bridge_info_exists(const struct sk_buff *skb)
27{
de8bda1d 28 return skb_ext_exist(skb, SKB_EXT_BRIDGE_NF);
c4b0e771
FW
29}
30
c737b7c4
FW
31static inline int nf_bridge_get_physinif(const struct sk_buff *skb)
32{
c4b0e771 33 const struct nf_bridge_info *nf_bridge = nf_bridge_info_get(skb);
547c4b54 34
c4b0e771 35 if (!nf_bridge)
547c4b54
FW
36 return 0;
37
547c4b54 38 return nf_bridge->physindev ? nf_bridge->physindev->ifindex : 0;
c737b7c4
FW
39}
40
41static inline int nf_bridge_get_physoutif(const struct sk_buff *skb)
42{
c4b0e771 43 const struct nf_bridge_info *nf_bridge = nf_bridge_info_get(skb);
547c4b54 44
c4b0e771 45 if (!nf_bridge)
547c4b54
FW
46 return 0;
47
547c4b54 48 return nf_bridge->physoutdev ? nf_bridge->physoutdev->ifindex : 0;
c737b7c4
FW
49}
50
51static inline struct net_device *
52nf_bridge_get_physindev(const struct sk_buff *skb)
53{
c4b0e771
FW
54 const struct nf_bridge_info *nf_bridge = nf_bridge_info_get(skb);
55
56 return nf_bridge ? nf_bridge->physindev : NULL;
c737b7c4
FW
57}
58
59static inline struct net_device *
60nf_bridge_get_physoutdev(const struct sk_buff *skb)
61{
c4b0e771
FW
62 const struct nf_bridge_info *nf_bridge = nf_bridge_info_get(skb);
63
64 return nf_bridge ? nf_bridge->physoutdev : NULL;
c737b7c4 65}
72b1e5e4
FW
66
67static inline bool nf_bridge_in_prerouting(const struct sk_buff *skb)
68{
c4b0e771
FW
69 const struct nf_bridge_info *nf_bridge = nf_bridge_info_get(skb);
70
71 return nf_bridge && nf_bridge->in_prerouting;
72b1e5e4 72}
07317621 73#else
a881e963 74#define br_drop_fake_rtable(skb) do { } while (0)
72b1e5e4
FW
75static inline bool nf_bridge_in_prerouting(const struct sk_buff *skb)
76{
77 return false;
78}
1da177e4
LT
79#endif /* CONFIG_BRIDGE_NETFILTER */
80
1da177e4 81#endif