rtnetlink: add support for protodown reason
Subsystems (2)
PATCH 1/1 rtnetlink: add support for protodown reason
From: Roopa Prabhu <[email protected]>
netdev protodown is a mechanism that allows protocols to hold an interface down. It was initially introduced in the kernel to hold links down by a multihoming protocol. There was also an attempt to introduce protodown
reason at the time but was rejected. protodown and protodown reason is supported by almost every switching and routing platform. It was ok for a while to live without a protodown reason. But, its become more critical now given more than
one protocol may need to keep a link down on a system
at the same time. eg: vrrp peer node, port security, multihoming protocol. Its common for Network operators and protocol developers to look for such a reason on a networking box (Its also known as errDisable by most networking operators)
This patch adds support for link protodown reason attribute. There are two ways to maintain protodown reasons.
(a) enumerate every possible reason code in kernel
- A protocol developer has to make a request and
have that appear in a certain kernel version
(b) provide the bits in the kernel, and allow user-space (sysadmin or NOS distributions) to manage the bit-to-reasonname map.
- This makes extending reason codes easier (kind of like
the iproute2 table to vrf-name map /etc/iproute2/rt_tables.d/)
This patch takes approach (b).
a few things about the patch:
- It treats the protodown reason bits as counter to indicate active protodown users
- Since protodown attribute is already an exposed UAPI, the reason is not enforced on a protodown set. Its a no-op if not used.
the patch follows the below algorithm:
- presence of reason bits set indicates protodown is in use
- user can set protodown and protodown reason in a single or multiple setlink operations
- setlink operation to clear protodown, will return -EBUSY if there are active protodown reason bits
- reason is not included in link dumps if not used
example with patched iproute2:
$cat /etc/iproute2/protodown_reasons.d/r.conf
0 mlag
1 evpn
2 vrrp
3 psecurity
$ip link set dev vxlan0 protodown on protodown_reason vrrp on $ip link set dev vxlan0 protodown_reason mlag on
$ip link show
14: vxlan0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
link/ether f6:06:be:17:91:e7 brd ff:ff:ff:ff:ff:ff protodown on <mlag,vrrp>
$ip link set dev vxlan0 protodown_reason mlag off
$ip link set dev vxlan0 protodown off protodown_reason vrrp off
--- include/linux/netdevice.h | 4 ++ include/uapi/linux/if_link.h | 10 ++++ net/core/dev.c | 36 ++++++++++++++ net/core/rtnetlink.c | 113 +++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 158 insertions(+), 5 deletions(-)
include/linux/netdevice.h +4 -0
@@ -2126,6 +2126,7 @@ struct net_device {struct lock_class_key *qdisc_tx_busylock;struct lock_class_key *qdisc_running_key;bool proto_down; +u32 proto_down_reason; unsigned wol_enabled:1;struct list_head net_notifier_list;
@@ -3802,6 +3803,9 @@ int dev_get_port_parent_id(struct net_device *dev,bool netdev_port_same_parent_id (struct net_device *a,struct net_device *b);int dev_change_proto_down (struct net_device *dev,bool proto_down);int dev_change_proto_down_generic (struct net_device *dev,bool proto_down); +u32 dev_get_proto_down_reason (const struct net_device *dev); +void dev_change_proto_down_reason (struct net_device *dev,unsigned long mask, +u32 value);struct sk_buff *validate_xmit_skb_list (struct sk_buff *skb,struct net_device *dev,bool *again);struct sk_buff *dev_hard_start_xmit (struct sk_buff *skb,struct net_device *dev,struct netdev_queue *txq,int *ret);
include/uapi/linux/if_link.h +10 -0
@@ -170,12 +170,22 @@ enum {IFLA_PROP_LIST ,IFLA_ALT_IFNAME ,/* Alternative ifname */ IFLA_PERM_ADDRESS , +IFLA_PROTO_DOWN_REASON , __IFLA_MAX };#define IFLA_MAX (__IFLA_MAX - 1) +enum { +IFLA_PROTO_DOWN_REASON_UNSPEC , +IFLA_PROTO_DOWN_REASON_MASK ,/* u32, mask for reason bits */ +IFLA_PROTO_DOWN_REASON_VALUE ,/* u32, reason bit value */ + + __IFLA_PROTO_DOWN_REASON_CNT, +IFLA_PROTO_DOWN_REASON_MAX = __IFLA_PROTO_DOWN_REASON_CNT -1 +}; +/* backwards compatibility for userspace */ #ifndef __KERNEL__#define IFLA_RTA (r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ifinfomsg))))
net/core/dev.c +36 -0
@@ -8703,6 +8703,42 @@ int dev_change_proto_down_generic(struct net_device *dev, bool proto_down) }EXPORT_SYMBOL (dev_change_proto_down_generic); +/** +* dev_get_proto_down_reason - returns protodown reason +* +* @dev: device +*/ +u32 dev_get_proto_down_reason (const struct net_device *dev) +{ +return dev->proto_down_reason; +} +EXPORT_SYMBOL (dev_get_proto_down_reason); + +/** +* dev_change_proto_down_reason - proto down reason +* +* @dev: device +* @mask: proto down mask +* @value: proto down value +*/ +void dev_change_proto_down_reason (struct net_device *dev,unsigned long mask, +u32 value) +{ +int b; + +if (!mask) { + dev->proto_down_reason = value; + }else { +for_each_set_bit (b, &mask,32 ) { +if (value & (1 << b)) + dev->proto_down_reason |=BIT (b); +else + dev->proto_down_reason &= ~BIT (b); + } + } +} +EXPORT_SYMBOL (dev_change_proto_down_reason); +u32 __dev_xdp_query (struct net_device *dev,bpf_op_t bpf_op,enum bpf_netdev_command cmd) {
net/core/rtnetlink.c +108 -5
161 lines not on this page · raw message
Signature · 1 line
2.1.4
net/core/rtnetlink.c static noinline size_t if_nlmsg_size(const struct net_device *dev, · line 1054
Quoted 2 lines · On Mon, 27 Jul 2020 12:21:17 -0700 Roopa Prabhu <[email protected]>…
net/core/rtnetlink.c +1
-1- +nla_total_size (1 )/* IFLA_PROTO_DOWN */ + +rtnl_proto_down_size (dev)/* proto down */
Changing the size of a netlink field is an ABI change in the kernel. This has the potential to break existing programs.
Wouldn't it be safer to add a new link attribute for the reason rather than overloading the existing attribute?
Quoted 6 lines · Stephen Hemminger
External email: Use caution opening links or attachments
On Mon, 27 Jul 2020 12:21:17 -0700
Roopa Prabhu <[email protected]> wrote:
Quoted 7 lines
net/core/rtnetlink.c static noinline size_t if_nlmsg_size(const struct net_device *dev, · line 1054
Quoted 2 lines
net/core/rtnetlink.c +1
-1- +nla_total_size (1 )/* IFLA_PROTO_DOWN */ + +rtnl_proto_down_size (dev)/* proto down */ Changing the size of a netlink field is an ABI change in the kernel. This has the potential to break existing programs.
Wouldn't it be safer to add a new link attribute for the reason rather than overloading the existing attribute?
yes, It does add a new attribute. Its just that I moved all protodown attribute handling to a separate function
David Miller
maintainerFrom: Roopa Prabhu <[email protected]>
Date: Mon, 27 Jul 2020 12:21:17 -0700
net/core/dev.c int dev_change_proto_down_generic(struct net_device *dev, bool proto_down) · line 8715
Quoted 10 lines
net/core/dev.c +10
-0+/** +* dev_get_proto_down_reason - returns protodown reason +* +* @dev: device +*/ +u32 dev_get_proto_down_reason (const struct net_device *dev) +{ +return dev->proto_down_reason; +} +EXPORT_SYMBOL (dev_get_proto_down_reason);
This helper is excessive, please remove it and just dereference the netdev member directly.
Thank you.
Quoted 16 lines · David Miller
From: Roopa Prabhu <[email protected]>
Date: Mon, 27 Jul 2020 12:21:17 -0700net/core/dev.c int dev_change_proto_down_generic(struct net_device *dev, bool proto_down) · line 8715
Quoted 10 lines
net/core/dev.c +10
-0+/** +* dev_get_proto_down_reason - returns protodown reason +* +* @dev: device +*/ +u32 dev_get_proto_down_reason (const struct net_device *dev) +{ +return dev->proto_down_reason; +} +EXPORT_SYMBOL (dev_get_proto_down_reason);This helper is excessive, please remove it and just dereference the netdev member directly.
Quoted 1 line
Thank you.
agree, will send v2. (it was meant to do more than just that initially)