From owner-dev-commits-src-all@freebsd.org Fri Feb 12 19:45:48 2021 Return-Path: Delivered-To: dev-commits-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 2DC5652E940; Fri, 12 Feb 2021 19:45:48 +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 4DckWJ0t6Wz3qFK; Fri, 12 Feb 2021 19:45:48 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 0C6DE1A91; Fri, 12 Feb 2021 19:45:48 +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 11CJjlfj037180; Fri, 12 Feb 2021 19:45:47 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 11CJjl5f037179; Fri, 12 Feb 2021 19:45:47 GMT (envelope-from git) Date: Fri, 12 Feb 2021 19:45:47 GMT Message-Id: <202102121945.11CJjl5f037179@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: "Alexander V. Chernikov" Subject: git: 8170a7d43835 - main - Fix interface route addition with net/bird. 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/main X-Git-Reftype: branch X-Git-Commit: 8170a7d43835047f9c1548a081eea45116473995 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 12 Feb 2021 19:45:48 -0000 The branch main has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=8170a7d43835047f9c1548a081eea45116473995 commit 8170a7d43835047f9c1548a081eea45116473995 Author: Alexander V. Chernikov AuthorDate: 2021-02-11 23:24:27 +0000 Commit: Alexander V. Chernikov CommitDate: 2021-02-12 19:45:35 +0000 Fix interface route addition with net/bird. The case of adding interface route by specifying interface address as the gateway was missed during code refactoring. Re-add it back by copying non-AF_LINK gateway data when RTF_GATEWAY is not set. Reviewed by: donner MFC after: 3 days --- sys/net/route/nhop_ctl.c | 50 +++++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/sys/net/route/nhop_ctl.c b/sys/net/route/nhop_ctl.c index 542380afd64b..7de553799fab 100644 --- a/sys/net/route/nhop_ctl.c +++ b/sys/net/route/nhop_ctl.c @@ -219,42 +219,44 @@ set_nhop_gw_from_info(struct nhop_object *nh, struct rt_addrinfo *info) gw = info->rti_info[RTAX_GATEWAY]; KASSERT(gw != NULL, ("gw is NULL")); - if (info->rti_flags & RTF_GATEWAY) { - if (gw->sa_len > sizeof(struct sockaddr_in6)) { - DPRINTF("nhop SA size too big: AF %d len %u", - gw->sa_family, gw->sa_len); - return (ENOMEM); - } - memcpy(&nh->gw_sa, gw, gw->sa_len); - } else { + if ((gw->sa_family == AF_LINK) && !(info->rti_flags & RTF_GATEWAY)) { /* - * Interface route. Currently the route.c code adds - * sa of type AF_LINK, which is 56 bytes long. The only - * meaningful data there is the interface index. It is used - * used is the IPv6 loopback output, where we need to preserve - * the original interface to maintain proper scoping. + * Interface route with interface specified by the interface + * index in sockadd_dl structure. It is used in the IPv6 loopback + * output code, where we need to preserve the original interface + * to maintain proper scoping. * Despite the fact that nexthop code stores original interface * in the separate field (nh_aifp, see below), write AF_LINK * compatible sa with shorter total length. */ - 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); + struct sockaddr_dl *sdl = (struct sockaddr_dl *)gw; + struct ifnet *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); - } + } else { + /* + * Multiple options here: + * + * 1) RTF_GATEWAY with IPv4/IPv6 gateway data + * 2) Interface route with IPv4/IPv6 address of the + * matching interface. Some routing daemons do that + * instead of specifying ifindex in AF_LINK. + * + * In both cases, save the original nexthop to make the callers + * happy. + */ + if (gw->sa_len > sizeof(struct sockaddr_in6)) { + DPRINTF("nhop SA size too big: AF %d len %u", + gw->sa_family, gw->sa_len); + return (ENOMEM); + } + memcpy(&nh->gw_sa, gw, gw->sa_len); + } return (0); }