Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
1da177e4 LT |
2 | #ifndef __LINUX_RTNETLINK_H |
3 | #define __LINUX_RTNETLINK_H | |
4 | ||
1da177e4 | 5 | |
6756ae4b | 6 | #include <linux/mutex.h> |
3b42a96d | 7 | #include <linux/netdevice.h> |
200b916f | 8 | #include <linux/wait.h> |
607ca46e | 9 | #include <uapi/linux/rtnetlink.h> |
1da177e4 | 10 | |
97c53cac DL |
11 | extern int rtnetlink_send(struct sk_buff *skb, struct net *net, u32 pid, u32 group, int echo); |
12 | extern int rtnl_unicast(struct sk_buff *skb, struct net *net, u32 pid); | |
1ce85fe4 PNA |
13 | extern void rtnl_notify(struct sk_buff *skb, struct net *net, u32 pid, |
14 | u32 group, struct nlmsghdr *nlh, gfp_t flags); | |
97c53cac | 15 | extern void rtnl_set_sk_err(struct net *net, u32 group, int error); |
1da177e4 | 16 | extern int rtnetlink_put_metrics(struct sk_buff *skb, u32 *metrics); |
e3703b3d | 17 | extern int rtnl_put_cacheinfo(struct sk_buff *skb, struct dst_entry *dst, |
87a50699 | 18 | u32 id, long expires, u32 error); |
1da177e4 | 19 | |
7f294054 | 20 | void rtmsg_ifinfo(int type, struct net_device *dev, unsigned change, gfp_t flags); |
395eea6c | 21 | struct sk_buff *rtmsg_ifinfo_build_skb(int type, struct net_device *dev, |
3d3ea5af VY |
22 | unsigned change, u32 event, |
23 | gfp_t flags); | |
395eea6c MB |
24 | void rtmsg_ifinfo_send(struct sk_buff *skb, struct net_device *dev, |
25 | gfp_t flags); | |
26 | ||
1da177e4 | 27 | |
6756ae4b | 28 | /* RTNL is used as a global lock for all changes to network configuration */ |
1da177e4 | 29 | extern void rtnl_lock(void); |
1da177e4 | 30 | extern void rtnl_unlock(void); |
6756ae4b | 31 | extern int rtnl_trylock(void); |
c9c1014b | 32 | extern int rtnl_is_locked(void); |
200b916f CW |
33 | |
34 | extern wait_queue_head_t netdev_unregistering_wq; | |
35 | extern struct mutex net_mutex; | |
36 | ||
a898def2 | 37 | #ifdef CONFIG_PROVE_LOCKING |
0cbf3343 | 38 | extern bool lockdep_rtnl_is_held(void); |
85328240 | 39 | #else |
0cbf3343 | 40 | static inline bool lockdep_rtnl_is_held(void) |
85328240 | 41 | { |
0cbf3343 | 42 | return true; |
85328240 | 43 | } |
a898def2 | 44 | #endif /* #ifdef CONFIG_PROVE_LOCKING */ |
6756ae4b | 45 | |
a6e0fc85 ED |
46 | /** |
47 | * rcu_dereference_rtnl - rcu_dereference with debug checking | |
48 | * @p: The pointer to read, prior to dereferencing | |
49 | * | |
50 | * Do an rcu_dereference(p), but check caller either holds rcu_read_lock() | |
29fa060e | 51 | * or RTNL. Note : Please prefer rtnl_dereference() or rcu_dereference() |
a6e0fc85 ED |
52 | */ |
53 | #define rcu_dereference_rtnl(p) \ | |
d8bf4ca9 | 54 | rcu_dereference_check(p, lockdep_rtnl_is_held()) |
a6e0fc85 | 55 | |
331b7292 JF |
56 | /** |
57 | * rcu_dereference_bh_rtnl - rcu_dereference_bh with debug checking | |
58 | * @p: The pointer to read, prior to dereference | |
59 | * | |
60 | * Do an rcu_dereference_bh(p), but check caller either holds rcu_read_lock_bh() | |
61 | * or RTNL. Note : Please prefer rtnl_dereference() or rcu_dereference_bh() | |
62 | */ | |
63 | #define rcu_dereference_bh_rtnl(p) \ | |
64 | rcu_dereference_bh_check(p, lockdep_rtnl_is_held()) | |
65 | ||
7dff59ef | 66 | /** |
29fa060e | 67 | * rtnl_dereference - fetch RCU pointer when updates are prevented by RTNL |
7dff59ef ED |
68 | * @p: The pointer to read, prior to dereferencing |
69 | * | |
29fa060e DM |
70 | * Return the value of the specified RCU-protected pointer, but omit |
71 | * both the smp_read_barrier_depends() and the ACCESS_ONCE(), because | |
72 | * caller holds RTNL. | |
7dff59ef ED |
73 | */ |
74 | #define rtnl_dereference(p) \ | |
29fa060e | 75 | rcu_dereference_protected(p, lockdep_rtnl_is_held()) |
7dff59ef | 76 | |
24824a09 ED |
77 | static inline struct netdev_queue *dev_ingress_queue(struct net_device *dev) |
78 | { | |
79 | return rtnl_dereference(dev->ingress_queue); | |
80 | } | |
81 | ||
4577139b DB |
82 | struct netdev_queue *dev_ingress_queue_create(struct net_device *dev); |
83 | ||
1cf51900 | 84 | #ifdef CONFIG_NET_INGRESS |
4577139b DB |
85 | void net_inc_ingress_queue(void); |
86 | void net_dec_ingress_queue(void); | |
4577139b | 87 | #endif |
24824a09 | 88 | |
1f211a1b DB |
89 | #ifdef CONFIG_NET_EGRESS |
90 | void net_inc_egress_queue(void); | |
91 | void net_dec_egress_queue(void); | |
92 | #endif | |
93 | ||
1b5c5493 ED |
94 | void rtnetlink_init(void); |
95 | void __rtnl_unlock(void); | |
96 | void rtnl_kfree_skbs(struct sk_buff *head, struct sk_buff *tail); | |
1da177e4 LT |
97 | |
98 | #define ASSERT_RTNL() do { \ | |
c9c1014b | 99 | if (unlikely(!rtnl_is_locked())) { \ |
1da177e4 LT |
100 | printk(KERN_ERR "RTNL: assertion failed at %s (%d)\n", \ |
101 | __FILE__, __LINE__); \ | |
102 | dump_stack(); \ | |
103 | } \ | |
104 | } while(0) | |
105 | ||
77162022 JF |
106 | extern int ndo_dflt_fdb_dump(struct sk_buff *skb, |
107 | struct netlink_callback *cb, | |
108 | struct net_device *dev, | |
5d5eacb3 | 109 | struct net_device *filter_dev, |
d297653d | 110 | int *idx); |
090096bf VY |
111 | extern int ndo_dflt_fdb_add(struct ndmsg *ndm, |
112 | struct nlattr *tb[], | |
113 | struct net_device *dev, | |
114 | const unsigned char *addr, | |
f6f6424b JP |
115 | u16 vid, |
116 | u16 flags); | |
090096bf VY |
117 | extern int ndo_dflt_fdb_del(struct ndmsg *ndm, |
118 | struct nlattr *tb[], | |
119 | struct net_device *dev, | |
f6f6424b JP |
120 | const unsigned char *addr, |
121 | u16 vid); | |
815cccbf JF |
122 | |
123 | extern int ndo_dflt_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq, | |
2c3c031c | 124 | struct net_device *dev, u16 mode, |
7d4f8d87 SF |
125 | u32 flags, u32 mask, int nlflags, |
126 | u32 filter_mask, | |
127 | int (*vlan_fill)(struct sk_buff *skb, | |
128 | struct net_device *dev, | |
129 | u32 filter_mask)); | |
1da177e4 | 130 | #endif /* __LINUX_RTNETLINK_H */ |