blob: 2032ce2eb20bff492698a1309aa043470de0991f [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002#ifndef __LINUX_RTNETLINK_H
3#define __LINUX_RTNETLINK_H
4
Linus Torvalds1da177e2005-04-16 15:20:36 -07005
Stephen Hemminger6756ae42006-03-20 22:23:58 -08006#include <linux/mutex.h>
Andy Whitcroft3b42a962010-11-15 06:01:59 +00007#include <linux/netdevice.h>
Cong Wang200b9162014-05-12 15:11:20 -07008#include <linux/wait.h>
David Howells607ca462012-10-13 10:46:48 +01009#include <uapi/linux/rtnetlink.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010
Denis V. Lunev97c53ca2007-11-19 22:26:51 -080011extern int rtnetlink_send(struct sk_buff *skb, struct net *net, u32 pid, u32 group, int echo);
12extern int rtnl_unicast(struct sk_buff *skb, struct net *net, u32 pid);
Pablo Neira Ayuso1ce85fe2009-02-24 23:18:28 -080013extern void rtnl_notify(struct sk_buff *skb, struct net *net, u32 pid,
14 u32 group, struct nlmsghdr *nlh, gfp_t flags);
Denis V. Lunev97c53ca2007-11-19 22:26:51 -080015extern void rtnl_set_sk_err(struct net *net, u32 group, int error);
Linus Torvalds1da177e2005-04-16 15:20:36 -070016extern int rtnetlink_put_metrics(struct sk_buff *skb, u32 *metrics);
Thomas Grafe3703b32006-11-27 09:27:07 -080017extern int rtnl_put_cacheinfo(struct sk_buff *skb, struct dst_entry *dst,
David S. Miller87a50692012-07-10 05:06:14 -070018 u32 id, long expires, u32 error);
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
Alexei Starovoitov7f294052013-10-23 16:02:42 -070020void rtmsg_ifinfo(int type, struct net_device *dev, unsigned change, gfp_t flags);
Nicolas Dichtel6621dd22017-10-03 13:53:23 +020021void rtmsg_ifinfo_newnet(int type, struct net_device *dev, unsigned int change,
22 gfp_t flags, int *new_nsid);
Mahesh Bandewar395eea62014-12-03 13:46:24 -080023struct sk_buff *rtmsg_ifinfo_build_skb(int type, struct net_device *dev,
Vlad Yasevich3d3ea5a2017-05-27 10:14:34 -040024 unsigned change, u32 event,
Nicolas Dichtel6621dd22017-10-03 13:53:23 +020025 gfp_t flags, int *new_nsid);
Mahesh Bandewar395eea62014-12-03 13:46:24 -080026void rtmsg_ifinfo_send(struct sk_buff *skb, struct net_device *dev,
27 gfp_t flags);
28
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
Stephen Hemminger6756ae42006-03-20 22:23:58 -080030/* RTNL is used as a global lock for all changes to network configuration */
Linus Torvalds1da177e2005-04-16 15:20:36 -070031extern void rtnl_lock(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070032extern void rtnl_unlock(void);
Stephen Hemminger6756ae42006-03-20 22:23:58 -080033extern int rtnl_trylock(void);
Patrick McHardyc9c10142008-04-23 22:10:48 -070034extern int rtnl_is_locked(void);
Cong Wang200b9162014-05-12 15:11:20 -070035
36extern wait_queue_head_t netdev_unregistering_wq;
37extern struct mutex net_mutex;
38
Paul E. McKenneya898def2010-02-22 17:04:49 -080039#ifdef CONFIG_PROVE_LOCKING
Yaowei Bai0cbf3342015-10-08 21:29:02 +080040extern bool lockdep_rtnl_is_held(void);
John Fastabend85328242013-11-26 06:33:52 +000041#else
Yaowei Bai0cbf3342015-10-08 21:29:02 +080042static inline bool lockdep_rtnl_is_held(void)
John Fastabend85328242013-11-26 06:33:52 +000043{
Yaowei Bai0cbf3342015-10-08 21:29:02 +080044 return true;
John Fastabend85328242013-11-26 06:33:52 +000045}
Paul E. McKenneya898def2010-02-22 17:04:49 -080046#endif /* #ifdef CONFIG_PROVE_LOCKING */
Stephen Hemminger6756ae42006-03-20 22:23:58 -080047
Eric Dumazeta6e0fc82010-09-08 14:15:32 -070048/**
49 * rcu_dereference_rtnl - rcu_dereference with debug checking
50 * @p: The pointer to read, prior to dereferencing
51 *
52 * Do an rcu_dereference(p), but check caller either holds rcu_read_lock()
David S. Miller29fa0602010-10-05 00:29:48 -070053 * or RTNL. Note : Please prefer rtnl_dereference() or rcu_dereference()
Eric Dumazeta6e0fc82010-09-08 14:15:32 -070054 */
55#define rcu_dereference_rtnl(p) \
Michal Hockod8bf4ca2011-07-08 14:39:41 +020056 rcu_dereference_check(p, lockdep_rtnl_is_held())
Eric Dumazeta6e0fc82010-09-08 14:15:32 -070057
Eric Dumazet7dff59e2010-09-15 11:07:15 +000058/**
John Fastabend331b7292014-09-12 20:08:20 -070059 * rcu_dereference_bh_rtnl - rcu_dereference_bh with debug checking
60 * @p: The pointer to read, prior to dereference
61 *
62 * Do an rcu_dereference_bh(p), but check caller either holds rcu_read_lock_bh()
63 * or RTNL. Note : Please prefer rtnl_dereference() or rcu_dereference_bh()
64 */
65#define rcu_dereference_bh_rtnl(p) \
66 rcu_dereference_bh_check(p, lockdep_rtnl_is_held())
67
68/**
David S. Miller29fa0602010-10-05 00:29:48 -070069 * rtnl_dereference - fetch RCU pointer when updates are prevented by RTNL
Eric Dumazet7dff59e2010-09-15 11:07:15 +000070 * @p: The pointer to read, prior to dereferencing
71 *
David S. Miller29fa0602010-10-05 00:29:48 -070072 * Return the value of the specified RCU-protected pointer, but omit
Mark Rutland14cd5d42017-10-23 14:07:17 -070073 * both the smp_read_barrier_depends() and the READ_ONCE(), because
David S. Miller29fa0602010-10-05 00:29:48 -070074 * caller holds RTNL.
Eric Dumazet7dff59e2010-09-15 11:07:15 +000075 */
76#define rtnl_dereference(p) \
David S. Miller29fa0602010-10-05 00:29:48 -070077 rcu_dereference_protected(p, lockdep_rtnl_is_held())
Eric Dumazet7dff59e2010-09-15 11:07:15 +000078
Eric Dumazet24824a02010-10-02 06:11:55 +000079static inline struct netdev_queue *dev_ingress_queue(struct net_device *dev)
80{
81 return rtnl_dereference(dev->ingress_queue);
82}
83
Daniel Borkmann45771392015-04-10 23:07:54 +020084struct netdev_queue *dev_ingress_queue_create(struct net_device *dev);
85
Pablo Neira1cf519002015-05-13 18:19:37 +020086#ifdef CONFIG_NET_INGRESS
Daniel Borkmann45771392015-04-10 23:07:54 +020087void net_inc_ingress_queue(void);
88void net_dec_ingress_queue(void);
Daniel Borkmann45771392015-04-10 23:07:54 +020089#endif
Eric Dumazet24824a02010-10-02 06:11:55 +000090
Daniel Borkmann1f211a12016-01-07 22:29:47 +010091#ifdef CONFIG_NET_EGRESS
92void net_inc_egress_queue(void);
93void net_dec_egress_queue(void);
94#endif
95
Eric Dumazet1b5c5492016-06-13 20:21:50 -070096void rtnetlink_init(void);
97void __rtnl_unlock(void);
98void rtnl_kfree_skbs(struct sk_buff *head, struct sk_buff *tail);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
100#define ASSERT_RTNL() do { \
Patrick McHardyc9c10142008-04-23 22:10:48 -0700101 if (unlikely(!rtnl_is_locked())) { \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 printk(KERN_ERR "RTNL: assertion failed at %s (%d)\n", \
103 __FILE__, __LINE__); \
104 dump_stack(); \
105 } \
106} while(0)
107
John Fastabend77162022012-04-15 06:43:56 +0000108extern int ndo_dflt_fdb_dump(struct sk_buff *skb,
109 struct netlink_callback *cb,
110 struct net_device *dev,
Jamal Hadi Salim5d5eacb2014-07-10 07:01:58 -0400111 struct net_device *filter_dev,
Roopa Prabhud2976532016-08-30 21:56:45 -0700112 int *idx);
Vlad Yasevich090096b2013-03-06 15:39:42 +0000113extern int ndo_dflt_fdb_add(struct ndmsg *ndm,
114 struct nlattr *tb[],
115 struct net_device *dev,
116 const unsigned char *addr,
Jiri Pirkof6f64242014-11-28 14:34:15 +0100117 u16 vid,
118 u16 flags);
Vlad Yasevich090096b2013-03-06 15:39:42 +0000119extern int ndo_dflt_fdb_del(struct ndmsg *ndm,
120 struct nlattr *tb[],
121 struct net_device *dev,
Jiri Pirkof6f64242014-11-28 14:34:15 +0100122 const unsigned char *addr,
123 u16 vid);
John Fastabend815cccb2012-10-24 08:13:09 +0000124
125extern int ndo_dflt_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
Scott Feldman2c3c0312014-11-28 14:34:25 +0100126 struct net_device *dev, u16 mode,
Scott Feldman7d4f8d82015-06-22 00:27:17 -0700127 u32 flags, u32 mask, int nlflags,
128 u32 filter_mask,
129 int (*vlan_fill)(struct sk_buff *skb,
130 struct net_device *dev,
131 u32 filter_mask));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132#endif /* __LINUX_RTNETLINK_H */