ipv6: report why a route was deleted in RTM_DELROUTE
Subsystems (5)
v3 cover ipv6: report why a route was deleted in RTM_DELROUTE
When the kernel deletes an IPv6 route on its own, the RTM_DELROUTE notification does not say why. User space cannot tell a route that expired from one the router explicitly withdrew, yet the two call for different reactions: an expired RA route means the router failed to refresh it in time, which points at a misconfigured or unreliable router and may warrant action such as disabling IPv6 on that network, while a zero-lifetime withdrawal is normal, RFC-compliant operation.
This is a general problem for any consumer device running Linux, especially on Wi-Fi networks, where multicast delivery is not guaranteed (e.g. frames can be lost around DTIM for clients in power save mode). The motivating case is Android: the userspace NetworkStack process listens on RTMGRP_IPV6_ROUTE and today treats any loss of the IPv6 default route as "router lost". To avoid the device repeatedly gaining and losing IPv6 connectivity on a badly configured network, when it detects the device is on a dual-stack network with working IPv4 connectivity, it defensively clears accept_ra_defrtr and restarts IPv6, so user space apps stop using broken global IPv6 connectivity while link-local IPv6 keeps working. That reaction is wrong if the route was withdrawn by a zero-lifetime RA (some ISPs do this intentionally for reconfiguration) - with accept_ra_defrtr off, IPv6 never recovers once the router advertises again. It is the right reaction if the route genuinely expired, since the router failed to refresh it in time.
Fixing this in user space is not practical: RTM_NEWROUTE carries the initial route lifetime (in rta_cacheinfo), but the kernel does not resend it when a later RA refreshes the lifetime. So distinguishing the cause of an RTM_DELROUTE from user space would mean opening a raw socket, listening to RAs, and tracking lifetimes independently, duplicating logic the kernel already has. Sending RTM_NEWROUTE on every RA lifetime refresh was also considered, but that would be spammy and is technically wrong, since a lifetime update does not add a new route.
This series proposes RTA_DEL_REASON instead: it tells user space why the route was deleted so it can react accordingly. In the Android case, NetworkStack would defensively disable global IPv6 only on RTA_DEL_REASON_EXPIRED, and take no action on RTA_DEL_REASON_RA_WITHDRAWN, since that is RFC-compliant behavior.
Patch 1 adds RTA_DEL_REASON (u32) to RTM_DELROUTE notifications and records the cause in the kernel-initiated IPv6 deletion paths:RTA_DEL_REASON_EXPIRED for routes garbage collected after their RTF_EXPIRES lifetime ran out, and RTA_DEL_REASON_RA_WITHDRAWN for default routes, prefix routes and RFC 4191 route information routes withdrawn by Router Advertisements. The rt-route Netlink spec is extended with the attribute, the route notifications and their multicast groups.
Only kernel-initiated deletions that user space cannot otherwise explain are attributed. User-requested deletions are self-explanatory to the requester, so they carry no reason; the UAPI documents that absence and RTA_DEL_REASON_UNSPEC must be treated identically, which keeps the door open for attributing more paths (nexthop removal cascades, device removal) later.
Patch 2 adds selftests covering all three producer paths: a GC-expired route, and a default route + PIO prefix route + RIO route advertised and then withdrawn by hand-crafted RAs over a raw ICMPv6 socket (no external RA tool needed), plus a check that user-requested deletions carry no attribute. The notifications are decoded with YNL, which also exercises the rt-route spec additions.
Changes since v2:
- Fix the patch 1 commit message, which still said u8.
- Keep del-reason out of the newroute and delroute request attribute lists in the rt-route spec, since the kernel rejects it in requests.
Changes since v1:
- Expand the motivation with the Android use case, per review request.
- Widen RTA_DEL_REASON from u8 to u32, per Netlink uAPI convention.
- Convert dict_keys to a set before the set difference in the selftest, for clarity.
Yuyang Huang (2):
ipv6: report why a route was deleted in RTM_DELROUTE
selftests: net: verify RTA_DEL_REASON on route deletion
Documentation/netlink/specs/rt-route.yaml | 67 ++++++- include/net/ip6_fib.h | 4 +- include/net/ip6_route.h | 2 + include/uapi/linux/rtnetlink.h | 17 ++ net/ipv6/addrconf.c | 3 +- net/ipv6/ip6_fib.c | 19 +- net/ipv6/ndisc.c | 7 +- net/ipv6/route.c | 66 ++++--- .../testing/selftests/net/lib/py/__init__.py | 4 +- tools/testing/selftests/net/lib/py/ynl.py | 7 +- tools/testing/selftests/net/rtnetlink.py | 181 +++++++++++++++++- 11 files changed, 335 insertions(+), 42 deletions(-)
--
2.43.0
PATCH v3 1/2 ipv6: report why a route was deleted in RTM_DELROUTE
Add RTA_DEL_REASON (u32) to RTM_DELROUTE notifications to report the cause of kernel-initiated IPv6 route deletions, so user space can tell routes that expired from routes explicitly withdrawn by Router Advertisements.
The two causes call for different treatment in user space. An expired RA route means the router failed to refresh it before its lifetime ran out, which points at a misconfigured or unreliable router; user space may want to react, for example by disabling IPv6 on that network entirely. An RA withdrawal (zero lifetime) is valid, RFC-compliant operation and needs no such recovery. Today both surface as an identical RTM_DELROUTE.
Plumb the deletion reason through the IPv6 FIB and notification paths:
- Update fib6_del, fib6_del_route, and inet6_rt_notify signatures to explicitly pass the del_reason down the call chain.
- Update rt6_fill_node() to emit RTA_DEL_REASON attribute when the reason is not UNSPEC.
- Record the cause in the kernel-initiated IPv6 deletion paths:
- RTA_DEL_REASON_EXPIRED: for routes cleaned up by the FIB6 garbage collector.
- RTA_DEL_REASON_RA_WITHDRAWN: for default routes, prefix routes, or route information option routes withdrawn by Router Advertisements.
- Update the rt-route Netlink YAML spec to define the new attribute, notifications, and multicast groups.
--- Documentation/netlink/specs/rt-route.yaml | 67 ++++++++++++++++++++++- include/net/ip6_fib.h | 4 +- include/net/ip6_route.h | 2 + include/uapi/linux/rtnetlink.h | 17 ++++++ net/ipv6/addrconf.c | 3 +- net/ipv6/ip6_fib.c | 19 ++++--- net/ipv6/ndisc.c | 7 ++- net/ipv6/route.c | 66 ++++++++++++++-------- 8 files changed, 148 insertions(+), 37 deletions(-)
Documentation/netlink/specs/rt-route.yaml +65 -2
@@ -78,6 +78,15 @@ definitions: - name: rta-used type: u32 + - + name: del-reason + type: enum + name-prefix: rta-del-reason- + enum-name: rta-del-reason + entries: + - unspec + - expired + - ra-withdrawn attribute-sets: -
@@ -185,6 +194,10 @@ attribute-sets: type: u32 byte-order: big-endian display-hint: hex + - + name: del-reason + type: u32 + enum: del-reason - name: metrics name-prefix: rtax-
@@ -299,6 +312,7 @@ operations: - dport - nh-id - flowlabel + - del-reason dump: request: value: 26
@@ -313,7 +327,37 @@ operations: do: request: value: 24 - attributes: *all-route-attrs + # del-reason is notification-only, the kernel rejects it in + # requests, so it is deliberately absent from this list. + attributes: &route-req-attrs + - dst + - src + - iif + - oif + - gateway + - priority + - prefsrc + - metrics + - multipath + - flow + - cacheinfo + - table + - mark + - mfc-stats + - via + - newdst + - pref + - encap-type + - encap + - expires + - pad + - uid + - ttl-propagate + - ip-proto + - sport + - dport + - nh-id + - flowlabel - name: delroute doc: Delete an existing route
@@ -321,4 +365,23 @@ operations: do: request: value: 25 - attributes: *all-route-attrs + attributes: *route-req-attrs + - + name: newroute-ntf + doc: Notification about a created route. + value: 24 + notify: getroute + - + name: delroute-ntf + doc: Notification about a deleted route. + value: 25 + notify: getroute + +mcast-groups: + list: + - + name: rtnlgrp-ipv4-route + value: 7 + - + name: rtnlgrp-ipv6-route + value: 11
include/net/ip6_fib.h +2 -2
@@ -468,7 +468,7 @@ void fib6_clean_all_skip_notify(struct net *net,int fib6_add (struct fib6_node *root,struct fib6_info *rt,struct nl_info *info,struct netlink_ext_ack *extack); -int fib6_del (struct fib6_info *rt,struct nl_info *info); +int fib6_del (struct fib6_info *rt,struct nl_info *info,u32 del_reason);static inline void rt6_get_prefsrc (const struct rt6_info *rt,struct in6_addr *addr)
@@ -531,7 +531,7 @@ static inline void fib6_rt_update(struct net *net, struct fib6_info *rt, }#endif void inet6_rt_notify (int event,struct fib6_info *rt,struct nl_info *info, -unsigned int flags); +unsigned int flags,u32 del_reason);void fib6_age_exceptions (struct fib6_info *rt,struct fib6_gc_args *gc_args,unsigned long now);
include/net/ip6_route.h +2 -0
@@ -128,6 +128,8 @@ int ip6_route_add(struct fib6_config *cfg, gfp_t gfp_flags,int ip6_ins_rt (struct net *net,struct fib6_info *f6i);#if IS_ENABLED (CONFIG_IPV6 )int ip6_del_rt (struct net *net,struct fib6_info *f6i,bool skip_notify); +int ip6_del_rt_reason (struct net *net,struct fib6_info *f6i,bool skip_notify, +u32 del_reason);#else static inline int ip6_del_rt (struct net *net,struct fib6_info *f6i,bool skip_notify)
include/uapi/linux/rtnetlink.h +17 -0
@@ -399,6 +399,7 @@ enum rtattr_type_t {RTA_DPORT ,RTA_NH_ID ,RTA_FLOWLABEL , +RTA_DEL_REASON , __RTA_MAX };
@@ -407,6 +408,22 @@ enum rtattr_type_t {#define RTM_RTA (r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct rtmsg))))#define RTM_PAYLOAD (n) NLMSG_PAYLOAD(n,sizeof(struct rtmsg)) +/* RTA_DEL_REASON: why the kernel deleted the route. u32. +* Emitted only on RTM_DELROUTE notifications, and only when the deletion +* path records a cause. Absence means either an older kernel or a +* deletion path that does not (yet) record its cause - consumers must +* treat "absent" and "unspec" identically. New causes may be appended. +* Currently only IPv6 deletion paths record a cause. +*/ +enum rta_del_reason { +RTA_DEL_REASON_UNSPEC ,/* cause not recorded */ +RTA_DEL_REASON_EXPIRED ,/* RTF_EXPIRES lifetime ran out (GC) */ +RTA_DEL_REASON_RA_WITHDRAWN ,/* zero-lifetime RA / PIO / RIO */ + __RTA_DEL_REASON_MAX +}; + +#define RTA_DEL_REASON_MAX (__RTA_DEL_REASON_MAX - 1) +/* RTM_MULTIPATH --- array of struct rtnexthop. * * "struct rtnexthop" describes all necessary nexthop information,
net/ipv6/addrconf.c +2 -1
@@ -2874,7 +2874,8 @@ void addrconf_prefix_rcv(struct net_device *dev, u8 *opt, int len, bool sllao)if (rt) {/* Autoconf prefix route */ if (valid_lft ==0 ) { -ip6_del_rt (net, rt, false); +ip6_del_rt_reason (net, rt, false, +RTA_DEL_REASON_RA_WITHDRAWN ); rt =NULL ; }else { table = rt->fib6_table;
net/ipv6/ip6_fib.c +11 -8
@@ -1286,7 +1286,8 @@ static int fib6_add_rt2node(struct fib6_node *fn, struct fib6_info *rt,rcu_assign_pointer (rt->fib6_node, fn);rcu_assign_pointer (*ins, rt);if (!info->skip_notify) -inet6_rt_notify (RTM_NEWROUTE , rt, info, nlflags); +inet6_rt_notify (RTM_NEWROUTE , rt, info, nlflags, +RTA_DEL_REASON_UNSPEC ); info->nl_net->ipv6.rt6_stats->fib_rt_entries++;if (!(fn->fn_flags &RTN_RTINFO )) {
@@ -1317,7 +1318,8 @@ static int fib6_add_rt2node(struct fib6_node *fn, struct fib6_info *rt, rt->fib6_next = iter->fib6_next;rcu_assign_pointer (*ins, rt);if (!info->skip_notify) -inet6_rt_notify (RTM_NEWROUTE , rt, info,NLM_F_REPLACE ); +inet6_rt_notify (RTM_NEWROUTE , rt, info,NLM_F_REPLACE , +RTA_DEL_REASON_UNSPEC );if (!(fn->fn_flags &RTN_RTINFO )) { info->nl_net->ipv6.rt6_stats->fib_route_nodes++; fn->fn_flags |=RTN_RTINFO ;
@@ -1966,7 +1968,8 @@ static struct fib6_node *fib6_repair_tree(struct net *net, }static void fib6_del_route (struct fib6_table *table,struct fib6_node *fn, -struct fib6_info __rcu **rtp,struct nl_info *info) +struct fib6_info __rcu **rtp,struct nl_info *info, +u32 del_reason) {struct fib6_info *leaf, *replace_rt =NULL ;struct fib6_walker *w;
@@ -2055,13 +2058,13 @@ static void fib6_del_route(struct fib6_table *table, struct fib6_node *fn,call_fib6_entry_notifiers_replace (net, replace_rt); }if (!info->skip_notify) -inet6_rt_notify (RTM_DELROUTE , rt, info,0 ); +inet6_rt_notify (RTM_DELROUTE , rt, info,0 , del_reason);fib6_info_release (rt); }/* Need to own table->tb6_lock */ -int fib6_del (struct fib6_info *rt,struct nl_info *info) +int fib6_del (struct fib6_info *rt,struct nl_info *info,u32 del_reason) {struct net *net = info->nl_net;struct fib6_info __rcu **rtp;
@@ -2090,7 +2093,7 @@ int fib6_del(struct fib6_info *rt, struct nl_info *info)if (rt == cur) {if (fib6_requires_src (cur))fib6_routes_require_src_dec (info->nl_net); -fib6_del_route (table, fn, rtp, info); +fib6_del_route (table, fn, rtp, info, del_reason);return 0 ; } rtp_next = &cur->fib6_next;
@@ -2252,7 +2255,7 @@ static int fib6_clean_node(struct fib6_walker *w) res = c->func (rt, c->arg);if (res ==-1 ) { w->leaf = rt; - res =fib6_del (rt, &info); + res =fib6_del (rt, &info,RTA_DEL_REASON_UNSPEC );if (res) {#if RT6_DEBUG >=2 pr_debug("%s: del failed: rt=%p@%p err=%d\n",
@@ -2400,7 +2403,7 @@ static void fib6_gc_table(struct net *net,hlist_for_each_entry_safe (rt, n, &tb6->tb6_gc_hlist, gc_link)if (fib6_age (rt, gc_args) ==-1 ) -fib6_del (rt, &info); +fib6_del (rt, &info,RTA_DEL_REASON_EXPIRED ); }static void fib6_gc_all (struct net *net,struct fib6_gc_args *gc_args)
net/ipv6/ndisc.c +5 -2
@@ -1361,7 +1361,9 @@ static enum skb_drop_reason ndisc_router_discovery(struct sk_buff *skb) defrtr_usr_metric = in6_dev->cnf.ra_defrtr_metric;/* delete the route if lifetime is 0 or if metric needs change */ if (rt && (lifetime ==0 || rt->fib6_metric != defrtr_usr_metric)) { -ip6_del_rt (net, rt, false); +ip6_del_rt_reason (net, rt, false, + lifetime ==0 ?RTA_DEL_REASON_RA_WITHDRAWN : +RTA_DEL_REASON_UNSPEC ); rt =NULL ; }
@@ -1396,7 +1398,8 @@ static enum skb_drop_reason ndisc_router_discovery(struct sk_buff *skb) .nl_net = net, }; rt->fib6_flags = (rt->fib6_flags & ~RTF_PREF_MASK ) |RTF_PREF (pref); -inet6_rt_notify (RTM_NEWROUTE , rt, &nlinfo,NLM_F_REPLACE ); +inet6_rt_notify (RTM_NEWROUTE , rt, &nlinfo,NLM_F_REPLACE , +RTA_DEL_REASON_UNSPEC ); }if (rt) {
net/ipv6/route.c +44 -22
200 lines not on this page · raw message
Signature · 1 line
2.43.0
Ido Schimmel
maintainerQuoted 27 lines · Yuyang Huang
Add
RTA_DEL_REASON(u32) toRTM_DELROUTEnotifications to report the cause of kernel-initiated IPv6 route deletions, so user space can tell routes that expired from routes explicitly withdrawn by Router Advertisements.The two causes call for different treatment in user space. An expired RA route means the router failed to refresh it before its lifetime ran out, which points at a misconfigured or unreliable router; user space may want to react, for example by disabling IPv6 on that network entirely. An RA withdrawal (zero lifetime) is valid, RFC-compliant operation and needs no such recovery. Today both surface as an identical
RTM_DELROUTE.Plumb the deletion reason through the IPv6 FIB and notification paths:
- Updatefib6_del,fib6_del_route, andinet6_rt_notifysignatures to explicitly pass thedel_reasondown the call chain.
- Updatert6_fill_node()to emitRTA_DEL_REASONattribute when the reason is not UNSPEC.
- Record the cause in the kernel-initiated IPv6 deletion paths:
-RTA_DEL_REASON_EXPIRED: for routes cleaned up by the FIB6 garbage collector.
-RTA_DEL_REASON_RA_WITHDRAWN: for default routes, prefix routes, or route information option routes withdrawn by Router Advertisements.
- Update thert-routeNetlink YAML spec to define the new attribute, notifications, and multicast groups.Signed-off-by Yuyang Huang <[email protected]>
Quoted 10 lines
--- Documentation/netlink/specs/rt-route.yaml | 67 ++++++++++++++++++++++- include/net/ip6_fib.h | 4 +- include/net/ip6_route.h | 2 + include/uapi/linux/rtnetlink.h | 17 ++++++ net/ipv6/addrconf.c | 3 +- net/ipv6/ip6_fib.c | 19 ++++--- net/ipv6/ndisc.c | 7 ++- net/ipv6/route.c | 66 ++++++++++++++-------- 8 files changed, 148 insertions(+), 37 deletions(-)
There are too many changes in this patch. The meaningful changes are mixed in with a lot of churn. I suggest splitting it as follows:
1. Add the rta_del_reason enum and ip6_del_rt_reason(). Call it from ip6_del_rt() with RTA_DEL_REASON_UNSPEC. No functional changes.
2. Propagate the deletion reason argument from ip6_del_rt_reason() all the way to fib6_del_route(). Purely a mechanical change with a lot of churn.
3. Change the relevant callers to specify the deletion reason instead of RTA_DEL_REASON_UNSPEC. This is the meaningful change.
Now the only thing that is left is to expose the deletion reason to user space.
4. Add a deletion reason argument to rt6_fill_node() and pass UNSPEC. Purely a mechanical change with a lot of churn.
5. Change rt6_fill_node() (and rt6_nlmsg_size()) to expose the reason to user space assuming it is not UNSPEC. At this point it is still not visible to user space since all the callers pass UNSPEC.
6. Add inet6_rt_del_notify() (see more below) and call it from fib6_del_route() with the deletion reason. The inet6_rt_notify() callers do not need to change.
7. Add the multicast groups and the notifications to rt-route.yaml (see more below).
8. Add the deletion reason to rt-route.yaml.
9. Add the selftest.
Quoted 64 lines
Documentation/netlink/specs/rt-route.yaml +33
-1@@ -78,6 +78,15 @@ definitions: - name: rta-used type: u32 + - + name: del-reason + type: enum + name-prefix: rta-del-reason- + enum-name: rta-del-reason + entries: + - unspec + - expired + - ra-withdrawn attribute-sets: -@@ -185,6 +194,10 @@ attribute-sets: type: u32 byte-order: big-endian display-hint: hex + - + name: del-reason + type: u32 + enum: del-reason - name: metrics name-prefix: rtax-@@ -299,6 +312,7 @@ operations: - dport - nh-id - flowlabel + - del-reason dump: request: value: 26@@ -313,7 +327,37 @@ operations: do: request: value: 24 - attributes: *all-route-attrs + # del-reason is notification-only, the kernel rejects it in + # requests, so it is deliberately absent from this list. + attributes: &route-req-attrs + - dst + - src + - iif + - oif + - gateway + - priority + - prefsrc + - metrics + - multipath + - flow + - cacheinfo + - table + - mark + - mfc-stats + - via + - newdst
Documentation/netlink/specs/rt-route.yaml operations: · line 358
Quoted 10 lines
Documentation/netlink/specs/rt-route.yaml +10
-0+ - pref + - encap-type + - encap + - expires + - pad + - uid + - ttl-propagate + - ip-proto + - sport + - dport
At least sport and dport are only used in RTM_GETROUTE, but it does seem like they won't be rejected if encoded in an RTM_NEWROUTE request, so I guess it's OK to put them here.
Quoted 20 lines
Documentation/netlink/specs/rt-route.yaml +12
-1+ - nh-id + - flowlabel - name: delroute doc: Delete an existing route@@ -321,4 +365,23 @@ operations: do: request: value: 25 - attributes: *all-route-attrs + attributes: *route-req-attrs + - + name: newroute-ntf + doc: Notification about a created route. + value: 24 + notify: getroute + - + name: delroute-ntf + doc: Notification about a deleted route. + value: 25
Documentation/netlink/specs/rt-route.yaml operations: · line 387
Quoted 10 lines
Documentation/netlink/specs/rt-route.yaml +10
-0+ notify: getroute + +mcast-groups: + list: + - + name: rtnlgrp-ipv4-route + value: 7 + - + name: rtnlgrp-ipv6-route + value: 11
This hunk (adding the mcast groups and notifications) is not related to the deletion reason. Please split it to a separate patch. There are too many changes in this patch as-is.
Quoted 14 lines
include/net/ip6_fib.h +1
-1@@ -468,7 +468,7 @@ void fib6_clean_all_skip_notify(struct net *net,int fib6_add (struct fib6_node *root,struct fib6_info *rt,struct nl_info *info,struct netlink_ext_ack *extack); -int fib6_del (struct fib6_info *rt,struct nl_info *info); +int fib6_del (struct fib6_info *rt,struct nl_info *info,u32 del_reason);static inline void rt6_get_prefsrc (const struct rt6_info *rt,struct in6_addr *addr)
include/net/ip6_fib.h static inline void fib6_rt_update(struct net *net, struct fib6_info *rt, · line 534
Quoted 5 lines
include/net/ip6_fib.h +1
-1@@ -531,7 +531,7 @@ static inline void fib6_rt_update(struct net *net, struct fib6_info *rt, }#endif void inet6_rt_notify (int event,struct fib6_info *rt,struct nl_info *info, -unsigned int flags); +unsigned int flags,u32 del_reason);
Why not use enum rta_del_reason like we do with kfree_skb_reason()?
Also, only one caller calls it from the deletion path, the rest pass RTM_NEWROUTE and it's weird to see something like:
inet6_rt_notify(RTM_NEWROUTE, rt, info, nlflags, RTA_DEL_REASON_UNSPEC);
Maybe create inet6_rt_del_notify(rt, info, del_reason) and have it call __inet6_rt_notify()? Then we don't need any changes in the addition path.
include/net/ip6_route.h int ip6_route_add(struct fib6_config *cfg, gfp_t gfp_flags, · line 132
Quoted 13 lines
include/net/ip6_fib.h +0
-0void fib6_age_exceptions (struct fib6_info *rt,struct fib6_gc_args *gc_args,unsigned long now);include/net/ip6_route.h +2
-0@@ -128,6 +128,8 @@ int ip6_route_add(struct fib6_config *cfg, gfp_t gfp_flags,int ip6_ins_rt (struct net *net,struct fib6_info *f6i);#if IS_ENABLED (CONFIG_IPV6 )int ip6_del_rt (struct net *net,struct fib6_info *f6i,bool skip_notify); +int ip6_del_rt_reason (struct net *net,struct fib6_info *f6i,bool skip_notify, +u32 del_reason);
Please use the enum throughout the patch instead of a plain u32.
Quoted 47 lines · Ido Schimmel
There are too many changes in this patch. The meaningful changes are mixed in with a lot of churn. I suggest splitting it as follows:
1. Add the
rta_del_reasonenum andip6_del_rt_reason(). Call it fromip6_del_rt()withRTA_DEL_REASON_UNSPEC. No functional changes.2. Propagate the deletion reason argument from
ip6_del_rt_reason()all the way tofib6_del_route(). Purely a mechanical change with a lot of churn.3. Change the relevant callers to specify the deletion reason instead of
RTA_DEL_REASON_UNSPEC. This is the meaningful change.Now the only thing that is left is to expose the deletion reason to user space.
4. Add a deletion reason argument to
rt6_fill_node()and pass UNSPEC. Purely a mechanical change with a lot of churn.5. Change
rt6_fill_node()(andrt6_nlmsg_size()) to expose the reason to user space assuming it is not UNSPEC. At this point it is still not visible to user space since all the callers pass UNSPEC.6. Add
inet6_rt_del_notify()(see more below) and call it fromfib6_del_route()with the deletion reason. Theinet6_rt_notify()callers do not need to change.7. Add the multicast groups and the notifications to
rt-route.yaml(see more below).8. Add the deletion reason to
rt-route.yaml.9. Add the selftest.
At least sport and dport are only used in
RTM_GETROUTE, but it does seem like they won't be rejected if encoded in anRTM_NEWROUTErequest, so I guess it's OK to put them here.This hunk (adding the mcast groups and notifications) is not related to the deletion reason. Please split it to a separate patch. There are too many changes in this patch as-is.
Why not use enum
rta_del_reasonlike we do withkfree_skb_reason()?Also, only one caller calls it from the deletion path, the rest pass
RTM_NEWROUTEand it's weird to see something like:
Quoted 7 lines
inet6_rt_notify(RTM_NEWROUTE, rt, info, nlflags, RTA_DEL_REASON_UNSPEC);Maybe create
inet6_rt_del_notify(rt, info, del_reason)and have it call__inet6_rt_notify()? Then we don't need any changes in the addition path.Please use the enum throughout the patch instead of a plain u32.
Thank you very much for all the detailed reviews!
Will adjust all the items properly in patchset v4.
Yuyang
PATCH v3 2/2 selftests: net: verify RTA_DEL_REASON on route deletion
In reply to Yuyang HuangExtend rtnetlink.py to check the reason reported in RTM_DELROUTE:
- expired: route with a 2s lifetime collected by the fib6 GC (gc_interval lowered like fib_tests.sh fib6_gc_test does);
- ra-withdrawn: a single RA advertises a default route (router lifetime), an on-link prefix route (RFC 4861 prefix information option) and a route information option route (RFC 4191), then a second RA withdraws all three with zero lifetimes; the RAs are crafted over a raw ICMPv6 socket so the test does not depend on an external RA tool;
- absence: a userspace deletion request records no cause and must not carry the attribute at all.
--- .../testing/selftests/net/lib/py/__init__.py | 4 +- tools/testing/selftests/net/lib/py/ynl.py | 7 +- tools/testing/selftests/net/rtnetlink.py | 181 +++++++++++++++++- 3 files changed, 187 insertions(+), 5 deletions(-)
tools/testing/selftests/net/lib/py/__init__.py +2 -2
@@ -17,7 +17,7 @@ from .utils import CmdExitFailure, fd_read_timeout, cmd, bkg, defer, \ wait_file, tool, tc from .bpf import bpf_map_set, bpf_map_dump, bpf_prog_map_ids from .ynl import NlError, NlctrlFamily, YnlFamily, \ - EthtoolFamily, NetdevFamily, RtnlFamily, RtnlAddrFamily + EthtoolFamily, NetdevFamily, RtnlFamily, RtnlAddrFamily, RtnlRouteFamily from .ynl import NetshaperFamily, DevlinkFamily, PSPFamily, Netlink __all__ = ["KSRC",
@@ -34,4 +34,4 @@ __all__ = ["KSRC", "NetdevSim", "NetdevSimDev", "NetshaperFamily", "DevlinkFamily", "PSPFamily", "NlError", "YnlFamily", "EthtoolFamily", "NetdevFamily", "RtnlFamily", - "NlctrlFamily", "RtnlAddrFamily", "Netlink"] + "NlctrlFamily", "RtnlAddrFamily", "RtnlRouteFamily", "Netlink"]
tools/testing/selftests/net/lib/py/ynl.py +6 -1
@@ -29,7 +29,7 @@ except ModuleNotFoundError as e: __all__ = [ "NlError", "NlPolicy", "Netlink", "YnlFamily", "SPEC_PATH", - "EthtoolFamily", "RtnlFamily", "RtnlAddrFamily", + "EthtoolFamily", "RtnlFamily", "RtnlAddrFamily", "RtnlRouteFamily", "NetdevFamily", "NetshaperFamily", "NlctrlFamily", "DevlinkFamily", "PSPFamily", ]
@@ -54,6 +54,11 @@ class RtnlAddrFamily(YnlFamily): super().__init__((SPEC_PATH / Path('rt-addr.yaml')).as_posix(), schema='', recv_size=recv_size) +class RtnlRouteFamily(YnlFamily): + def __init__(self, recv_size=0): + super().__init__((SPEC_PATH / Path('rt-route.yaml')).as_posix(), + schema='', recv_size=recv_size) + class NetdevFamily(YnlFamily): def __init__(self, recv_size=0): super().__init__((SPEC_PATH / Path('netdev.yaml')).as_posix(),
tools/testing/selftests/net/rtnetlink.py +179 -2
194 lines not on this page · raw message
Signature · 1 line
2.43.0