rtnetlink: add support for protodown reason
Subsystems (2)
PATCH v2 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
---
v2 - remove unnecessary helper dev_get_proto_down_reason
- move dev->proto_down_reason to use an existing hole in struct net_device
include/linux/netdevice.h | 4 ++ include/uapi/linux/if_link.h | 10 ++++ net/core/dev.c | 25 ++++++++++ net/core/rtnetlink.c | 113 +++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 147 insertions(+), 5 deletions(-)
include/linux/netdevice.h +4 -0
@@ -2058,6 +2058,8 @@ struct net_device {struct timer_list watchdog_timer;int watchdog_timeo; +u32 proto_down_reason; +struct list_head todo_list;int __percpu *pcpu_refcnt;
@@ -3810,6 +3812,8 @@ 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); +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 +25 -0
@@ -8716,6 +8716,31 @@ int dev_change_proto_down_generic(struct net_device *dev, bool proto_down) }EXPORT_SYMBOL (dev_change_proto_down_generic); +/** +* 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
From: Roopa Prabhu <[email protected]>
Date: Fri, 31 Jul 2020 17:34:01 -0700
Quoted 59 lines
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-EBUSYif there are active protodown reason bits
- reason is not included in link dumps if not usedexample 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_reasonvrrp on $ip link set dev vxlan0protodown_reasonmlag on
$ip link show
14: vxlan0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000link/ether f6:06:be:17:91:e7 brd ff:ff:ff:ff:ff:ff protodown on <mlag,vrrp>
Quoted 7 lines
$ip link set dev vxlan0
protodown_reasonmlag off
$ip link set dev vxlan0 protodown offprotodown_reasonvrrp offSigned-off-by Roopa Prabhu <[email protected]>---
v2 - remove unnecessary helperdev_get_proto_down_reason
- movedev->proto_down_reasonto use an existing hole in structnet_device
Applied, thank you.