From nobody Mon Feb 27 16:33:43 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4PQQzq4tRlz3vKXn; Mon, 27 Feb 2023 16:33:43 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4PQQzq3cj6z3lSr; Mon, 27 Feb 2023 16:33:43 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1677515623; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=e0idSiLFArk5JQEyA8Dsfu5PNVTF6eYID5OLxME+T+U=; b=glg58RLmIE53nOA8uRxqbeKyDj0FS5gJ9CVjUHq6NJSZ+PcM/VqNf5H6Z4FwvDho2vRo1G vHrjRS+/m4FpOCbIy4wN9iTgCs8KHHBUVE+vN+YMg8fOd2kJaTOOt0r2bMAU/YxVk+3sct NsGBqIZwQZw872KmQ/ct5+TGoUc8E1JU16w9NHSoLbHZIIwqvKLfQu/jvKCX2B9P+OswvX I7g2c76Aiv5E/ows8JD/Lqi+agdD6XvJT5WJP23dPB1DBG50jWwrFejrzFb5VAmc7lWNgF JJtN9N/7dvuPYnBxLcRvo0Zd1tTwPGUtg5Qyc1cowFPdB46Q+AZNxQATinDZWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1677515623; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=e0idSiLFArk5JQEyA8Dsfu5PNVTF6eYID5OLxME+T+U=; b=QxXfbXDabwJdhq82mnd8rQyi5ZYsj6aYJj/WnNInVVv8XAcAUxKhaBs1XadU+MEQiOGu+6 9bFkxwZqFo4VI4ZG1HwwMc+7FY3K6mll6X5kGnSPRWhiTEAfiRMssgGxFHoWWeEZ6zqyEM 2ggWBIwlk6ZDEemDkrTAd52pWuqQYiDRbM0/sUPwwNbzf2b5fYtuBoJM+lDxxbau9j++sX QXxV6W4C0BeNbjBA00jPBcEiGu9Yk3hjUWep+dOiYEg3PB6GYKOOWimhbW1bHLqUW+6X+/ bFH6i2Ud2g1liahk4rs6DaJgl2VOZNMcGOeeNbAWflTq+t3NZ2UHZuFKqNdK5w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1677515623; a=rsa-sha256; cv=none; b=e0x4ghGOTZKJlnbnf6VQGRaLwkadk+aif1aGppFf7JNcjEFZlnYnvWrM4h4hwdF6klNYK2 RcSd7IU8E9VDrAZpMUW2L3ElifdCVFZHyQijExdcMdA93fmgcfhI7FtOsHyO5NIhSL1gKy +BgG/bCZcOgcPaPrhJIx688zf3KPCAFNX5HfsBaAKTHRg0DDXhKI4g0yyHLSE9EbPmVN2R b6yktF8pkrjMG0aA2eNy+R74rN4eQB5tHRu8Jbh7FmakPT6eVJ1YrBYCU8kBi0DRKu08l1 UFXtdPqsIjsfZ1FzxV1kbNqzmvvOkNyY63sqJleO5/7axNpvL/6hwBCXPjTKCg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4PQQzq2jGszYPc; Mon, 27 Feb 2023 16:33:43 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 31RGXhk9068018; Mon, 27 Feb 2023 16:33:43 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 31RGXhpr068017; Mon, 27 Feb 2023 16:33:43 GMT (envelope-from git) Date: Mon, 27 Feb 2023 16:33:43 GMT Message-Id: <202302271633.31RGXhpr068017@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: "Alexander V. Chernikov" Subject: git: 6899e0be9433 - releng/13.2 - netlink: fix IPv6 route addition with link-local gateway List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: melifaro X-Git-Repository: src X-Git-Refname: refs/heads/releng/13.2 X-Git-Reftype: branch X-Git-Commit: 6899e0be9433a2b2e3190e8642fb43910839982a Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch releng/13.2 has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=6899e0be9433a2b2e3190e8642fb43910839982a commit 6899e0be9433a2b2e3190e8642fb43910839982a Author: Alexander V. Chernikov AuthorDate: 2023-02-20 14:24:01 +0000 Commit: Alexander V. Chernikov CommitDate: 2023-02-27 16:27:16 +0000 netlink: fix IPv6 route addition with link-local gateway Currently kernel assumes that IPv6 gateway address is in "embedded" form - that is, for the link-local IPv6 addresses, interface index is embedded in bytes 2 and 3 of the address. Fix address embedding in netlink by wrapping nhop_set_gw() in the netlink-specific nl_set_nexthop_gw(), which does such embedding automatically. Reported by: Marek Zarychta MFC after: 3 days Approved by: re(cperciva) (cherry picked from commit c7c348162101a70b1f99299578dabe1d3b100e48) (cherry picked from commit 240ee0183fa190502a5e1f163c49f336f8f10cd4) --- sys/netlink/route/nexthop.c | 42 ++++++++++++++++++++++++++++++++++++------ sys/netlink/route/route_var.h | 2 ++ sys/netlink/route/rt.c | 15 ++++++++++++--- 3 files changed, 50 insertions(+), 9 deletions(-) diff --git a/sys/netlink/route/nexthop.c b/sys/netlink/route/nexthop.c index e9f008842644..63e491687249 100644 --- a/sys/netlink/route/nexthop.c +++ b/sys/netlink/route/nexthop.c @@ -741,8 +741,34 @@ newnhg(struct unhop_ctl *ctl, struct nl_parsed_nhop *attrs, struct user_nhop *un return (0); } +/* + * Sets nexthop @nh gateway specified by @gw. + * If gateway is IPv6 link-local, alters @gw to include scopeid equal to + * @ifp ifindex. + * Returns 0 on success or errno. + */ +int +nl_set_nexthop_gw(struct nhop_object *nh, struct sockaddr *gw, struct ifnet *ifp, + struct nl_pstate *npt) +{ +#ifdef INET6 + if (gw->sa_family == AF_INET6) { + struct sockaddr_in6 *gw6 = (struct sockaddr_in6 *)gw; + if (IN6_IS_ADDR_LINKLOCAL(&gw6->sin6_addr)) { + if (ifp == NULL) { + NLMSG_REPORT_ERR_MSG(npt, "interface not set"); + return (EINVAL); + } + in6_set_unicast_scopeid(&gw6->sin6_addr, ifp->if_index); + } + } +#endif + nhop_set_gw(nh, gw, true); + return (0); +} + static int -newnhop(struct nl_parsed_nhop *attrs, struct user_nhop *unhop) +newnhop(struct nl_parsed_nhop *attrs, struct user_nhop *unhop, struct nl_pstate *npt) { struct ifaddr *ifa = NULL; struct nhop_object *nh; @@ -750,17 +776,17 @@ newnhop(struct nl_parsed_nhop *attrs, struct user_nhop *unhop) if (!attrs->nha_blackhole) { if (attrs->nha_gw == NULL) { - NL_LOG(LOG_DEBUG, "missing NHA_GATEWAY"); + NLMSG_REPORT_ERR_MSG(npt, "missing NHA_GATEWAY"); return (EINVAL); } if (attrs->nha_oif == NULL) { - NL_LOG(LOG_DEBUG, "missing NHA_OIF"); + NLMSG_REPORT_ERR_MSG(npt, "missing NHA_OIF"); return (EINVAL); } if (ifa == NULL) ifa = ifaof_ifpforaddr(attrs->nha_gw, attrs->nha_oif); if (ifa == NULL) { - NL_LOG(LOG_DEBUG, "Unable to determine default source IP"); + NLMSG_REPORT_ERR_MSG(npt, "Unable to determine default source IP"); return (EINVAL); } } @@ -777,7 +803,11 @@ newnhop(struct nl_parsed_nhop *attrs, struct user_nhop *unhop) if (attrs->nha_blackhole) nhop_set_blackhole(nh, NHF_BLACKHOLE); else { - nhop_set_gw(nh, attrs->nha_gw, true); + error = nl_set_nexthop_gw(nh, attrs->nha_gw, attrs->nha_oif, npt); + if (error != 0) { + nhop_free(nh); + return (error); + } nhop_set_transmit_ifp(nh, attrs->nha_oif); nhop_set_src(nh, ifa); } @@ -839,7 +869,7 @@ rtnl_handle_newnhop(struct nlmsghdr *hdr, struct nlpcb *nlp, if (attrs.nha_group) error = newnhg(ctl, &attrs, unhop); else - error = newnhop(&attrs, unhop); + error = newnhop(&attrs, unhop, npt); if (error != 0) { free(unhop, M_NETLINK); diff --git a/sys/netlink/route/route_var.h b/sys/netlink/route/route_var.h index f1e522c7ae05..f3b1d7d929a5 100644 --- a/sys/netlink/route/route_var.h +++ b/sys/netlink/route/route_var.h @@ -104,6 +104,8 @@ void rtnl_iface_drivers_register(void); void rtnl_nexthops_init(void); struct nhop_object *nl_find_nhop(uint32_t fibnum, int family, uint32_t uidx, int nh_flags, int *perror); +int nl_set_nexthop_gw(struct nhop_object *nh, struct sockaddr *gw, + struct ifnet *ifp, struct nl_pstate *npt); #endif diff --git a/sys/netlink/route/rt.c b/sys/netlink/route/rt.c index aca69e75fea8..534186447b4d 100644 --- a/sys/netlink/route/rt.c +++ b/sys/netlink/route/rt.c @@ -736,7 +736,11 @@ create_nexthop_one(struct nl_parsed_route *attrs, struct rta_mpath_nh *mpnh, if (nh == NULL) return (ENOMEM); - nhop_set_gw(nh, mpnh->gw, true); + error = nl_set_nexthop_gw(nh, mpnh->gw, mpnh->ifp, npt); + if (error != 0) { + nhop_free(nh); + return (error); + } if (mpnh->ifp != NULL) nhop_set_transmit_ifp(nh, mpnh->ifp); nhop_set_rtflags(nh, attrs->rta_rtflags); @@ -800,8 +804,13 @@ create_nexthop_from_attrs(struct nl_parsed_route *attrs, *perror = ENOMEM; return (NULL); } - if (attrs->rta_gw != NULL) - nhop_set_gw(nh, attrs->rta_gw, true); + if (attrs->rta_gw != NULL) { + *perror = nl_set_nexthop_gw(nh, attrs->rta_gw, attrs->rta_oif, npt); + if (*perror != 0) { + nhop_free(nh); + return (NULL); + } + } if (attrs->rta_oif != NULL) nhop_set_transmit_ifp(nh, attrs->rta_oif); if (attrs->rtax_mtu != 0)