2017-11-01 15:07:57 +01:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
2005-04-16 15:20:36 -07:00
|
|
|
#ifndef __LINUX_RTNETLINK_H
|
|
|
|
|
#define __LINUX_RTNETLINK_H
|
|
|
|
|
|
|
|
|
|
|
2006-03-20 22:23:58 -08:00
|
|
|
#include <linux/mutex.h>
|
2010-11-15 06:01:59 +00:00
|
|
|
#include <linux/netdevice.h>
|
2014-05-12 15:11:20 -07:00
|
|
|
#include <linux/wait.h>
|
2018-09-24 19:22:49 +03:00
|
|
|
#include <linux/refcount.h>
|
2012-10-13 10:46:48 +01:00
|
|
|
#include <uapi/linux/rtnetlink.h>
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2007-11-19 22:26:51 -08:00
|
|
|
extern int rtnetlink_send(struct sk_buff *skb, struct net *net, u32 pid, u32 group, int echo);
|
2023-12-08 16:28:43 -03:00
|
|
|
|
|
|
|
|
static inline int rtnetlink_maybe_send(struct sk_buff *skb, struct net *net,
|
|
|
|
|
u32 pid, u32 group, int echo)
|
|
|
|
|
{
|
|
|
|
|
return !skb ? 0 : rtnetlink_send(skb, net, pid, group, echo);
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-19 22:26:51 -08:00
|
|
|
extern int rtnl_unicast(struct sk_buff *skb, struct net *net, u32 pid);
|
2009-02-24 23:18:28 -08:00
|
|
|
extern void rtnl_notify(struct sk_buff *skb, struct net *net, u32 pid,
|
2022-10-28 04:42:21 -04:00
|
|
|
u32 group, const struct nlmsghdr *nlh, gfp_t flags);
|
2007-11-19 22:26:51 -08:00
|
|
|
extern void rtnl_set_sk_err(struct net *net, u32 group, int error);
|
2005-04-16 15:20:36 -07:00
|
|
|
extern int rtnetlink_put_metrics(struct sk_buff *skb, u32 *metrics);
|
2006-11-27 09:27:07 -08:00
|
|
|
extern int rtnl_put_cacheinfo(struct sk_buff *skb, struct dst_entry *dst,
|
2012-07-10 05:06:14 -07:00
|
|
|
u32 id, long expires, u32 error);
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2022-10-28 04:42:21 -04:00
|
|
|
void rtmsg_ifinfo(int type, struct net_device *dev, unsigned int change, gfp_t flags,
|
|
|
|
|
u32 portid, const struct nlmsghdr *nlh);
|
2017-10-03 13:53:23 +02:00
|
|
|
void rtmsg_ifinfo_newnet(int type, struct net_device *dev, unsigned int change,
|
2018-01-25 15:01:39 +01:00
|
|
|
gfp_t flags, int *new_nsid, int new_ifindex);
|
2014-12-03 13:46:24 -08:00
|
|
|
struct sk_buff *rtmsg_ifinfo_build_skb(int type, struct net_device *dev,
|
2017-05-27 10:14:34 -04:00
|
|
|
unsigned change, u32 event,
|
2018-01-25 15:01:39 +01:00
|
|
|
gfp_t flags, int *new_nsid,
|
2023-04-11 09:43:19 +02:00
|
|
|
int new_ifindex, u32 portid,
|
|
|
|
|
const struct nlmsghdr *nlh);
|
2014-12-03 13:46:24 -08:00
|
|
|
void rtmsg_ifinfo_send(struct sk_buff *skb, struct net_device *dev,
|
2022-10-28 04:42:21 -04:00
|
|
|
gfp_t flags, u32 portid, const struct nlmsghdr *nlh);
|
2014-12-03 13:46:24 -08:00
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2006-03-20 22:23:58 -08:00
|
|
|
/* RTNL is used as a global lock for all changes to network configuration */
|
2005-04-16 15:20:36 -07:00
|
|
|
extern void rtnl_lock(void);
|
|
|
|
|
extern void rtnl_unlock(void);
|
2006-03-20 22:23:58 -08:00
|
|
|
extern int rtnl_trylock(void);
|
2008-04-23 22:10:48 -07:00
|
|
|
extern int rtnl_is_locked(void);
|
2025-02-04 18:03:10 +01:00
|
|
|
extern int rtnl_lock_interruptible(void);
|
2018-03-14 22:17:20 +03:00
|
|
|
extern int rtnl_lock_killable(void);
|
2018-09-24 19:22:49 +03:00
|
|
|
extern bool refcount_dec_and_rtnl_lock(refcount_t *r);
|
2014-05-12 15:11:20 -07:00
|
|
|
|
|
|
|
|
extern wait_queue_head_t netdev_unregistering_wq;
|
2024-02-02 10:11:06 +00:00
|
|
|
extern atomic_t dev_unreg_count;
|
2018-03-27 18:02:23 +03:00
|
|
|
extern struct rw_semaphore pernet_ops_rwsem;
|
2018-03-29 19:20:32 +03:00
|
|
|
extern struct rw_semaphore net_rwsem;
|
2014-05-12 15:11:20 -07:00
|
|
|
|
2024-10-04 15:10:30 -07:00
|
|
|
#define ASSERT_RTNL() \
|
|
|
|
|
WARN_ONCE(!rtnl_is_locked(), \
|
|
|
|
|
"RTNL: assertion failed at %s (%d)\n", __FILE__, __LINE__)
|
|
|
|
|
|
2010-02-22 17:04:49 -08:00
|
|
|
#ifdef CONFIG_PROVE_LOCKING
|
2015-10-08 21:29:02 +08:00
|
|
|
extern bool lockdep_rtnl_is_held(void);
|
2013-11-26 06:33:52 +00:00
|
|
|
#else
|
2015-10-08 21:29:02 +08:00
|
|
|
static inline bool lockdep_rtnl_is_held(void)
|
2013-11-26 06:33:52 +00:00
|
|
|
{
|
2015-10-08 21:29:02 +08:00
|
|
|
return true;
|
2013-11-26 06:33:52 +00:00
|
|
|
}
|
2010-02-22 17:04:49 -08:00
|
|
|
#endif /* #ifdef CONFIG_PROVE_LOCKING */
|
2006-03-20 22:23:58 -08:00
|
|
|
|
2010-09-08 14:15:32 -07:00
|
|
|
/**
|
|
|
|
|
* rcu_dereference_rtnl - rcu_dereference with debug checking
|
|
|
|
|
* @p: The pointer to read, prior to dereferencing
|
|
|
|
|
*
|
|
|
|
|
* Do an rcu_dereference(p), but check caller either holds rcu_read_lock()
|
2010-10-05 00:29:48 -07:00
|
|
|
* or RTNL. Note : Please prefer rtnl_dereference() or rcu_dereference()
|
2010-09-08 14:15:32 -07:00
|
|
|
*/
|
|
|
|
|
#define rcu_dereference_rtnl(p) \
|
2011-07-08 14:39:41 +02:00
|
|
|
rcu_dereference_check(p, lockdep_rtnl_is_held())
|
2010-09-08 14:15:32 -07:00
|
|
|
|
2010-09-15 11:07:15 +00:00
|
|
|
/**
|
2010-10-05 00:29:48 -07:00
|
|
|
* rtnl_dereference - fetch RCU pointer when updates are prevented by RTNL
|
2010-09-15 11:07:15 +00:00
|
|
|
* @p: The pointer to read, prior to dereferencing
|
|
|
|
|
*
|
2024-12-05 08:59:14 -08:00
|
|
|
* Return: the value of the specified RCU-protected pointer, but omit
|
2017-10-09 10:37:22 -07:00
|
|
|
* the READ_ONCE(), because caller holds RTNL.
|
2010-09-15 11:07:15 +00:00
|
|
|
*/
|
|
|
|
|
#define rtnl_dereference(p) \
|
2010-10-05 00:29:48 -07:00
|
|
|
rcu_dereference_protected(p, lockdep_rtnl_is_held())
|
2010-09-15 11:07:15 +00:00
|
|
|
|
2023-12-15 14:57:10 -03:00
|
|
|
/**
|
|
|
|
|
* rcu_replace_pointer_rtnl - replace an RCU pointer under rtnl_lock, returning
|
|
|
|
|
* its old value
|
|
|
|
|
* @rp: RCU pointer, whose value is returned
|
|
|
|
|
* @p: regular pointer
|
|
|
|
|
*
|
|
|
|
|
* Perform a replacement under rtnl_lock, where @rp is an RCU-annotated
|
|
|
|
|
* pointer. The old value of @rp is returned, and @rp is set to @p
|
|
|
|
|
*/
|
|
|
|
|
#define rcu_replace_pointer_rtnl(rp, p) \
|
|
|
|
|
rcu_replace_pointer(rp, p, lockdep_rtnl_is_held())
|
|
|
|
|
|
2024-10-04 15:10:29 -07:00
|
|
|
#ifdef CONFIG_DEBUG_NET_SMALL_RTNL
|
|
|
|
|
void __rtnl_net_lock(struct net *net);
|
|
|
|
|
void __rtnl_net_unlock(struct net *net);
|
|
|
|
|
void rtnl_net_lock(struct net *net);
|
|
|
|
|
void rtnl_net_unlock(struct net *net);
|
2024-10-21 11:32:36 -07:00
|
|
|
int rtnl_net_trylock(struct net *net);
|
2025-01-04 17:21:48 +09:00
|
|
|
int rtnl_net_lock_killable(struct net *net);
|
2024-10-04 15:10:29 -07:00
|
|
|
int rtnl_net_lock_cmp_fn(const struct lockdep_map *a, const struct lockdep_map *b);
|
2024-10-04 15:10:30 -07:00
|
|
|
|
|
|
|
|
bool rtnl_net_is_locked(struct net *net);
|
|
|
|
|
|
|
|
|
|
#define ASSERT_RTNL_NET(net) \
|
|
|
|
|
WARN_ONCE(!rtnl_net_is_locked(net), \
|
|
|
|
|
"RTNL_NET: assertion failed at %s (%d)\n", \
|
|
|
|
|
__FILE__, __LINE__)
|
|
|
|
|
|
|
|
|
|
bool lockdep_rtnl_net_is_held(struct net *net);
|
|
|
|
|
|
|
|
|
|
#define rcu_dereference_rtnl_net(net, p) \
|
|
|
|
|
rcu_dereference_check(p, lockdep_rtnl_net_is_held(net))
|
|
|
|
|
#define rtnl_net_dereference(net, p) \
|
|
|
|
|
rcu_dereference_protected(p, lockdep_rtnl_net_is_held(net))
|
|
|
|
|
#define rcu_replace_pointer_rtnl_net(net, rp, p) \
|
|
|
|
|
rcu_replace_pointer(rp, p, lockdep_rtnl_net_is_held(net))
|
2024-10-04 15:10:29 -07:00
|
|
|
#else
|
|
|
|
|
static inline void __rtnl_net_lock(struct net *net) {}
|
|
|
|
|
static inline void __rtnl_net_unlock(struct net *net) {}
|
|
|
|
|
|
|
|
|
|
static inline void rtnl_net_lock(struct net *net)
|
|
|
|
|
{
|
|
|
|
|
rtnl_lock();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void rtnl_net_unlock(struct net *net)
|
|
|
|
|
{
|
|
|
|
|
rtnl_unlock();
|
|
|
|
|
}
|
2024-10-04 15:10:30 -07:00
|
|
|
|
2024-10-21 11:32:36 -07:00
|
|
|
static inline int rtnl_net_trylock(struct net *net)
|
|
|
|
|
{
|
|
|
|
|
return rtnl_trylock();
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-04 17:21:48 +09:00
|
|
|
static inline int rtnl_net_lock_killable(struct net *net)
|
|
|
|
|
{
|
|
|
|
|
return rtnl_lock_killable();
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-04 15:10:30 -07:00
|
|
|
static inline void ASSERT_RTNL_NET(struct net *net)
|
|
|
|
|
{
|
|
|
|
|
ASSERT_RTNL();
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-21 11:32:28 -07:00
|
|
|
#define rcu_dereference_rtnl_net(net, p) \
|
|
|
|
|
rcu_dereference_rtnl(p)
|
|
|
|
|
#define rtnl_net_dereference(net, p) \
|
|
|
|
|
rtnl_dereference(p)
|
|
|
|
|
#define rcu_replace_pointer_rtnl_net(net, rp, p) \
|
|
|
|
|
rcu_replace_pointer_rtnl(rp, p)
|
2024-10-04 15:10:29 -07:00
|
|
|
#endif
|
|
|
|
|
|
2010-10-02 06:11:55 +00:00
|
|
|
static inline struct netdev_queue *dev_ingress_queue(struct net_device *dev)
|
|
|
|
|
{
|
|
|
|
|
return rtnl_dereference(dev->ingress_queue);
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-24 19:22:51 +03:00
|
|
|
static inline struct netdev_queue *dev_ingress_queue_rcu(struct net_device *dev)
|
|
|
|
|
{
|
|
|
|
|
return rcu_dereference(dev->ingress_queue);
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-10 23:07:54 +02:00
|
|
|
struct netdev_queue *dev_ingress_queue_create(struct net_device *dev);
|
|
|
|
|
|
2015-05-13 18:19:37 +02:00
|
|
|
#ifdef CONFIG_NET_INGRESS
|
2015-04-10 23:07:54 +02:00
|
|
|
void net_inc_ingress_queue(void);
|
|
|
|
|
void net_dec_ingress_queue(void);
|
|
|
|
|
#endif
|
2010-10-02 06:11:55 +00:00
|
|
|
|
2016-01-07 22:29:47 +01:00
|
|
|
#ifdef CONFIG_NET_EGRESS
|
|
|
|
|
void net_inc_egress_queue(void);
|
|
|
|
|
void net_dec_egress_queue(void);
|
2022-04-16 00:40:45 +08:00
|
|
|
void netdev_xmit_skip_txqueue(bool skip);
|
2016-01-07 22:29:47 +01:00
|
|
|
#endif
|
|
|
|
|
|
2016-06-13 20:21:50 -07:00
|
|
|
void rtnetlink_init(void);
|
|
|
|
|
void __rtnl_unlock(void);
|
|
|
|
|
void rtnl_kfree_skbs(struct sk_buff *head, struct sk_buff *tail);
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2024-12-09 10:07:45 +00:00
|
|
|
/* Shared by rtnl_fdb_dump() and various ndo_fdb_dump() helpers. */
|
|
|
|
|
struct ndo_fdb_dump_context {
|
2024-12-09 10:07:46 +00:00
|
|
|
unsigned long ifindex;
|
2024-12-09 10:07:45 +00:00
|
|
|
unsigned long fdb_idx;
|
|
|
|
|
};
|
|
|
|
|
|
2012-04-15 06:43:56 +00:00
|
|
|
extern int ndo_dflt_fdb_dump(struct sk_buff *skb,
|
|
|
|
|
struct netlink_callback *cb,
|
|
|
|
|
struct net_device *dev,
|
2014-07-10 07:01:58 -04:00
|
|
|
struct net_device *filter_dev,
|
2016-08-30 21:56:45 -07:00
|
|
|
int *idx);
|
2013-03-06 15:39:42 +00:00
|
|
|
extern int ndo_dflt_fdb_add(struct ndmsg *ndm,
|
|
|
|
|
struct nlattr *tb[],
|
|
|
|
|
struct net_device *dev,
|
|
|
|
|
const unsigned char *addr,
|
2014-11-28 14:34:15 +01:00
|
|
|
u16 vid,
|
|
|
|
|
u16 flags);
|
2013-03-06 15:39:42 +00:00
|
|
|
extern int ndo_dflt_fdb_del(struct ndmsg *ndm,
|
|
|
|
|
struct nlattr *tb[],
|
|
|
|
|
struct net_device *dev,
|
2014-11-28 14:34:15 +01:00
|
|
|
const unsigned char *addr,
|
|
|
|
|
u16 vid);
|
2012-10-24 08:13:09 +00:00
|
|
|
|
|
|
|
|
extern int ndo_dflt_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq,
|
2014-11-28 14:34:25 +01:00
|
|
|
struct net_device *dev, u16 mode,
|
2015-06-22 00:27:17 -07:00
|
|
|
u32 flags, u32 mask, int nlflags,
|
|
|
|
|
u32 filter_mask,
|
|
|
|
|
int (*vlan_fill)(struct sk_buff *skb,
|
|
|
|
|
struct net_device *dev,
|
|
|
|
|
u32 filter_mask));
|
2022-03-02 18:31:23 +02:00
|
|
|
|
|
|
|
|
extern void rtnl_offload_xstats_notify(struct net_device *dev);
|
|
|
|
|
|
2023-12-08 16:28:41 -03:00
|
|
|
static inline int rtnl_has_listeners(const struct net *net, u32 group)
|
|
|
|
|
{
|
|
|
|
|
struct sock *rtnl = net->rtnl;
|
|
|
|
|
|
|
|
|
|
return netlink_has_listeners(rtnl, group);
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-08 16:28:42 -03:00
|
|
|
/**
|
|
|
|
|
* rtnl_notify_needed - check if notification is needed
|
|
|
|
|
* @net: Pointer to the net namespace
|
|
|
|
|
* @nlflags: netlink ingress message flags
|
|
|
|
|
* @group: rtnl group
|
|
|
|
|
*
|
|
|
|
|
* Based on the ingress message flags and rtnl group, returns true
|
|
|
|
|
* if a notification is needed, false otherwise.
|
|
|
|
|
*/
|
|
|
|
|
static inline bool
|
|
|
|
|
rtnl_notify_needed(const struct net *net, u16 nlflags, u32 group)
|
|
|
|
|
{
|
|
|
|
|
return (nlflags & NLM_F_ECHO) || rtnl_has_listeners(net, group);
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-04 09:11:22 -07:00
|
|
|
void netif_set_operstate(struct net_device *dev, int newstate);
|
2024-02-13 06:32:42 +00:00
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
#endif /* __LINUX_RTNETLINK_H */
|