Date: Sun, 9 Apr 2023 13:34:16 GMT From: "Alexander V. Chernikov" <melifaro@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: git: cc3793b1c548 - main - netlink: improve source ifa selection algorithm when adding routes. Message-ID: <202304091334.339DYGRC077249@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch main has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=cc3793b1c54847e26001f42026778703970fa570 commit cc3793b1c54847e26001f42026778703970fa570 Author: Alexander V. Chernikov <melifaro@FreeBSD.org> AuthorDate: 2023-04-09 13:30:45 +0000 Commit: Alexander V. Chernikov <melifaro@FreeBSD.org> CommitDate: 2023-04-09 13:33:22 +0000 netlink: improve source ifa selection algorithm when adding routes. Use route destination sockaddr when the gateway is eiter AF_LINK or has the different family (IPv4 over IPv6). This change ensures the nexthop IFA has the same family as the destination. Reported by: Dmitriy Smirnov <fox@sage.su> Tested by: Dmitriy Smirnov <fox@sage.su> MFC after: 3 days --- sys/netlink/route/rt.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/sys/netlink/route/rt.c b/sys/netlink/route/rt.c index 7e81d59d696b..db535cb676e4 100644 --- a/sys/netlink/route/rt.c +++ b/sys/netlink/route/rt.c @@ -708,7 +708,19 @@ finalize_nhop(struct nhop_object *nh, const struct sockaddr *dst, int *perror) } /* Both nh_ifp and gateway are set */ if (nh->nh_ifa == NULL) { - struct ifaddr *ifa = ifaof_ifpforaddr(&nh->gw_sa, nh->nh_ifp); + const struct sockaddr *gw_sa = &nh->gw_sa; + + if (gw_sa->sa_family != dst->sa_family) { + /* + * Use dst as the target for determining the default + * preferred ifa IF + * 1) the gateway is link-level (e.g. direct route) + * 2) the gateway family is different (e.g. IPv4 over IPv6). + */ + gw_sa = dst; + } + + struct ifaddr *ifa = ifaof_ifpforaddr(gw_sa, nh->nh_ifp); if (ifa == NULL) { NL_LOG(LOG_DEBUG, "Unable to determine ifa, skipping"); *perror = EINVAL;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202304091334.339DYGRC077249>