From owner-dev-commits-src-branches@freebsd.org Tue Sep 7 21:12:54 2021 Return-Path: Delivered-To: dev-commits-src-branches@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 32BDF66BF71; Tue, 7 Sep 2021 21:12:54 +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 4H3yfC136wz4Vfh; Tue, 7 Sep 2021 21:12:50 +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 0C7D2198C9; Tue, 7 Sep 2021 21:12:50 +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 187LCnHQ023955; Tue, 7 Sep 2021 21:12:49 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 187LCnee023954; Tue, 7 Sep 2021 21:12:49 GMT (envelope-from git) Date: Tue, 7 Sep 2021 21:12:49 GMT Message-Id: <202109072112.187LCnee023954@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: 10e097610309 - stable/13 - Simplify nhop operations in ip_output(). 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/stable/13 X-Git-Reftype: branch X-Git-Commit: 10e09761030960a435c075e2b1dfd3bff2db7c4c Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 07 Sep 2021 21:12:54 -0000 The branch stable/13 has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=10e09761030960a435c075e2b1dfd3bff2db7c4c commit 10e09761030960a435c075e2b1dfd3bff2db7c4c Author: Alexander V. Chernikov AuthorDate: 2021-08-07 11:18:02 +0000 Commit: Alexander V. Chernikov CommitDate: 2021-09-07 21:02:58 +0000 Simplify nhop operations in ip_output(). Consistently use `nh` instead of always dereferencing ro->ro_nh inside the if block. Always use nexthop mtu, as it provides guarantee that mtu is accurate. Pass `nh` pointer to rt_update_ro_flags() to allow upcoming uses of updating ro flags based on different nexthop. Differential Revision: https://reviews.freebsd.org/D31451 Reviewed by: kp (cherry picked from commit 9748eb742791dcfbb6496dc5c7c72c9283759baf) --- sys/net/route/route_ctl.c | 21 +++++++++++++++++++-- sys/netinet/ip_output.c | 27 +++++++++++++-------------- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/sys/net/route/route_ctl.c b/sys/net/route/route_ctl.c index 582901d67a8d..a686d1623053 100644 --- a/sys/net/route/route_ctl.c +++ b/sys/net/route/route_ctl.c @@ -567,6 +567,24 @@ rib_add_route(uint32_t fibnum, struct rt_addrinfo *info, return (error); } +/* + * Checks if @dst and @gateway is valid combination. + * + * Returns true if is valid, false otherwise. + */ +static bool +check_gateway(struct rib_head *rnh, struct sockaddr *dst, + struct sockaddr *gateway) +{ + if (dst->sa_family == gateway->sa_family) + return (true); + else if (gateway->sa_family == AF_UNSPEC) + return (true); + else if (gateway->sa_family == AF_LINK) + return (true); + return (false); +} + /* * Creates rtentry and nexthop based on @info data. * Return 0 and fills in rtentry into @prt on success, @@ -589,8 +607,7 @@ create_rtentry(struct rib_head *rnh, struct rt_addrinfo *info, if ((flags & RTF_GATEWAY) && !gateway) return (EINVAL); - if (dst && gateway && (dst->sa_family != gateway->sa_family) && - (gateway->sa_family != AF_UNSPEC) && (gateway->sa_family != AF_LINK)) + if (dst && gateway && !check_gateway(rnh, dst, gateway)) return (EINVAL); if (dst->sa_len > sizeof(((struct rtentry *)NULL)->rt_dstb)) diff --git a/sys/netinet/ip_output.c b/sys/netinet/ip_output.c index 405490e890c0..13b5cecbfe82 100644 --- a/sys/netinet/ip_output.c +++ b/sys/netinet/ip_output.c @@ -292,9 +292,9 @@ done: /* rte<>ro_flags translation */ static inline void -rt_update_ro_flags(struct route *ro) +rt_update_ro_flags(struct route *ro, const struct nhop_object *nh) { - int nh_flags = ro->ro_nh->nh_flags; + int nh_flags = nh->nh_flags; ro->ro_flags &= ~ (RT_REJECT|RT_BLACKHOLE|RT_HAS_GW); @@ -493,22 +493,21 @@ again: goto bad; } } - ia = ifatoia(ro->ro_nh->nh_ifa); - ifp = ro->ro_nh->nh_ifp; - counter_u64_add(ro->ro_nh->nh_pksent, 1); - rt_update_ro_flags(ro); - if (ro->ro_nh->nh_flags & NHF_GATEWAY) - gw = &ro->ro_nh->gw4_sa; - if (ro->ro_nh->nh_flags & NHF_HOST) - isbroadcast = (ro->ro_nh->nh_flags & NHF_BROADCAST); + struct nhop_object *nh = ro->ro_nh; + + ia = ifatoia(nh->nh_ifa); + ifp = nh->nh_ifp; + counter_u64_add(nh->nh_pksent, 1); + rt_update_ro_flags(ro, nh); + if (nh->nh_flags & NHF_GATEWAY) + gw = &nh->gw4_sa; + if (nh->nh_flags & NHF_HOST) + isbroadcast = (nh->nh_flags & NHF_BROADCAST); else if (ifp->if_flags & IFF_BROADCAST) isbroadcast = in_ifaddr_broadcast(gw->sin_addr, ia); else isbroadcast = 0; - if (ro->ro_nh->nh_flags & NHF_HOST) - mtu = ro->ro_nh->nh_mtu; - else - mtu = ifp->if_mtu; + mtu = nh->nh_mtu; src = IA_SIN(ia)->sin_addr; } else { struct nhop_object *nh;