git: b755f1a009b0 - main - netlink: Fix adding routes with nexthops on p2p interfaces.
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 30 Mar 2023 09:57:23 UTC
The branch main has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=b755f1a009b05cec45108e2ae83ae72c6e264c29 commit b755f1a009b05cec45108e2ae83ae72c6e264c29 Author: Alexander V. Chernikov <melifaro@FreeBSD.org> AuthorDate: 2023-03-29 14:13:44 +0000 Commit: Alexander V. Chernikov <melifaro@FreeBSD.org> CommitDate: 2023-03-30 09:53:50 +0000 netlink: Fix adding routes with nexthops on p2p interfaces. Use full-featured ifa_ifwithroute() to guess route ifa/ifp instead of ifa_ifwithnet(). This change makes the route addition logic closer to the rt_getifa_fib() used by rtsock. Reported by: glebius Tested by: glebius Differential Revision: https://reviews.freebsd.org/D39335 MFC after: 2 weeks --- sys/netlink/route/rt.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/sys/netlink/route/rt.c b/sys/netlink/route/rt.c index 7785dd42dc65..6d76390016dd 100644 --- a/sys/netlink/route/rt.c +++ b/sys/netlink/route/rt.c @@ -661,7 +661,7 @@ handle_rtm_dump(struct nlpcb *nlp, uint32_t fibnum, int family, } static struct nhop_object * -finalize_nhop(struct nhop_object *nh, int *perror) +finalize_nhop(struct nhop_object *nh, const struct sockaddr *dst, int *perror) { /* * The following MUST be filled: @@ -682,7 +682,15 @@ finalize_nhop(struct nhop_object *nh, int *perror) } else { /* Gateway is set up, we can derive ifp if not set */ if (nh->nh_ifp == NULL) { - struct ifaddr *ifa = ifa_ifwithnet(&nh->gw_sa, 1, nhop_get_fibnum(nh)); + uint32_t fibnum = nhop_get_fibnum(nh); + uint32_t flags = 0; + + if (nh->nh_flags & NHF_GATEWAY) + flags = RTF_GATEWAY; + else if (nh->nh_flags & NHF_HOST) + flags = RTF_HOST; + + struct ifaddr *ifa = ifa_ifwithroute(flags, dst, &nh->gw_sa, fibnum); if (ifa == NULL) { NL_LOG(LOG_DEBUG, "Unable to determine ifp, skipping"); *perror = EINVAL; @@ -765,7 +773,7 @@ create_nexthop_one(struct nl_parsed_route *attrs, struct rta_mpath_nh *mpnh, if (attrs->rtm_protocol > RTPROT_STATIC) nhop_set_origin(nh, attrs->rtm_protocol); - *pnh = finalize_nhop(nh, &error); + *pnh = finalize_nhop(nh, attrs->rta_dst, &error); return (error); } @@ -852,7 +860,7 @@ create_nexthop_from_attrs(struct nl_parsed_route *attrs, /* TODO: return ENOTSUP for other types if strict option is set */ } - nh = finalize_nhop(nh, perror); + nh = finalize_nhop(nh, attrs->rta_dst, perror); } return (nh);