From owner-svn-src-all@freebsd.org Thu Sep 3 22:24:53 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 722D33CD01D; Thu, 3 Sep 2020 22:24:53 +0000 (UTC) (envelope-from melifaro@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 "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4BjFjd2RN5z467k; Thu, 3 Sep 2020 22:24:53 +0000 (UTC) (envelope-from melifaro@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 36BA322B73; Thu, 3 Sep 2020 22:24:53 +0000 (UTC) (envelope-from melifaro@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 083MOrmh057043; Thu, 3 Sep 2020 22:24:53 GMT (envelope-from melifaro@FreeBSD.org) Received: (from melifaro@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 083MOr1W057042; Thu, 3 Sep 2020 22:24:53 GMT (envelope-from melifaro@FreeBSD.org) Message-Id: <202009032224.083MOr1W057042@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: melifaro set sender to melifaro@FreeBSD.org using -f From: "Alexander V. Chernikov" Date: Thu, 3 Sep 2020 22:24:53 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r365315 - head/sys/net/route X-SVN-Group: head X-SVN-Commit-Author: melifaro X-SVN-Commit-Paths: head/sys/net/route X-SVN-Commit-Revision: 365315 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 Sep 2020 22:24:53 -0000 Author: melifaro Date: Thu Sep 3 22:24:52 2020 New Revision: 365315 URL: https://svnweb.freebsd.org/changeset/base/365315 Log: Fix regression for IPv6 loopback routes. After nexthop introduction, loopback routes for the interface addresses were created without embedding actual interface index in the gateway. The latter is needed to pass the IPv6 scope during transmission via loopback.. Fix the regression by actually using passed gateway data with interface index. Differential Revision: https://reviews.freebsd.org/D26306 Modified: head/sys/net/route/nhop_ctl.c Modified: head/sys/net/route/nhop_ctl.c ============================================================================== --- head/sys/net/route/nhop_ctl.c Thu Sep 3 22:20:27 2020 (r365314) +++ head/sys/net/route/nhop_ctl.c Thu Sep 3 22:24:52 2020 (r365315) @@ -225,6 +225,7 @@ set_nhop_gw_from_info(struct nhop_object *nh, struct r } memcpy(&nh->gw_sa, gw, gw->sa_len); } else { + /* * Interface route. Currently the route.c code adds * sa of type AF_LINK, which is 56 bytes long. The only @@ -235,7 +236,21 @@ set_nhop_gw_from_info(struct nhop_object *nh, struct r * in the separate field (nh_aifp, see below), write AF_LINK * compatible sa with shorter total length. */ - fill_sdl_from_ifp(&nh->gwl_sa, nh->nh_ifp); + struct sockaddr_dl *sdl; + struct ifnet *ifp; + + /* Fetch and validate interface index */ + sdl = (struct sockaddr_dl *)gw; + if (sdl->sdl_family != AF_LINK) { + DPRINTF("unsupported AF: %d", sdl->sdl_family); + return (ENOTSUP); + } + ifp = ifnet_byindex(sdl->sdl_index); + if (ifp == NULL) { + DPRINTF("invalid ifindex %d", sdl->sdl_index); + return (EINVAL); + } + fill_sdl_from_ifp(&nh->gwl_sa, ifp); } return (0); @@ -272,12 +287,13 @@ fill_nhop_from_info(struct nhop_priv *nh_priv, struct nh->nh_flags = convert_rt_to_nh_flags(rt_flags); set_nhop_mtu_from_info(nh, info); + if ((error = set_nhop_gw_from_info(nh, info)) != 0) + return (error); + nh->nh_ifp = info->rti_ifa->ifa_ifp; nh->nh_ifa = info->rti_ifa; + /* depends on the gateway */ nh->nh_aifp = get_aifp(nh, 0); - - if ((error = set_nhop_gw_from_info(nh, info)) != 0) - return (error); /* * Note some of the remaining data is set by the