From nobody Mon Feb 27 16:33:45 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 4PQQzs6hnZz3vKPm; Mon, 27 Feb 2023 16:33:45 +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 4PQQzs5jjbz3lLm; Mon, 27 Feb 2023 16:33:45 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1677515625; 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=IQlUYPaXgbB0inhOIWPTwsHEujdPKR4shoGwWN12wnA=; b=o7bx53hZkWE26oD0WOXIsJc3OMSGzWN36wlAVT2IdSknbcjZSyHDJMW00JMvf0YvDtMkHR AQiFX/lXMI7gzUu7yc4BXFPIHXVqjH6Q+0gM/JWBJcMObAhhxK1VKbCY5y/7/OzvzTSwHJ KKAHVE7e8PPkIGtVF8GKGY1CFgHWi47TTnaja55x+Gwn8DQlq/9m2F+IriOBBByNDIs8LK 4udmkhkJIWMyz4xDpTDmV9zdMl6xSCEO2DHc3D3XvqYmmhTtLsxw5FhT83fBRSipshavMO E23xjT6Vo56dxK/BxHaOfd/fr20TC/kllkLkr4MakFRUErlds3PEKqC176rSDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1677515625; 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=IQlUYPaXgbB0inhOIWPTwsHEujdPKR4shoGwWN12wnA=; b=xRdaQdrpjEVxzoyLXQbrcDRrsows0DcsZdqpdcx8t0IOApeMHH/gATb8XC1BrpTJOCy08T VpNCk/tdNhUsWHvNRC7N0eOr04BUDIouOtXTZx2xFRg7hMLFrnqnMohmbdQ9tHWSTeTLaZ mfsJHoBT1YivhBDWXl3X0B8vPMO03QLYITsELL2FfUrg6GsmhtW31bm77MPFfqr4AVYqPL 7NiRuc3emFXobWeaMRMvtWqDIlTkuCsX7l6dXM1LN2DlxfaJ77m6x7EOuUp4QrtHiZWvOi dKI8w99IqQKh2Mncre2KtWJ3Y4Fk1nbu/7WPVu0fGeFmJM2nxYGdnC9VUkJMyQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1677515625; a=rsa-sha256; cv=none; b=Azv30YTZfsSPNiWY2YhzwWD84IXTjivySsRXGWZSOoyUBcMRJYwUKs3ophSyYWGhqVltWP 4ceSfG9USvBU7Qe7QVCx0tP3mNdjv9B4QOCDFgnrZXx2rJGLnuGzNltWmY791fAc6tCcFd Ypu8xtH7WUk08nmTfBURbZVOFDJ9JwMuGP9k1j42p1In/KhVf8/ZXKH2iWZcIL0/JoAKKk dUJtK/79S4Jcrv0PFCWk7Ucw8T05EmJH7Xynx3R/m8wybe+nS5zKndj/w93jFaL39cUj1x EfC3vWPVRYEb/1WLL+BZbZg0trrhFT8rrY/v9ZVCclc7mCaaHBUBt6RcPSE9Rw== 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 4PQQzs4XjHzXxF; Mon, 27 Feb 2023 16:33:45 +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 31RGXjBM068056; Mon, 27 Feb 2023 16:33:45 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 31RGXjwL068055; Mon, 27 Feb 2023 16:33:45 GMT (envelope-from git) Date: Mon, 27 Feb 2023 16:33:45 GMT Message-Id: <202302271633.31RGXjwL068055@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: 7dea81a4ed19 - releng/13.2 - netlink: fix addition of blackhole/reject routes. 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: 7dea81a4ed19e18a6f1104f14cd3e0ce57c8f5f5 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=7dea81a4ed19e18a6f1104f14cd3e0ce57c8f5f5 commit 7dea81a4ed19e18a6f1104f14cd3e0ce57c8f5f5 Author: Alexander V. Chernikov AuthorDate: 2023-02-23 17:38:18 +0000 Commit: Alexander V. Chernikov CommitDate: 2023-02-27 16:27:16 +0000 netlink: fix addition of blackhole/reject routes. * Make nhop_set_blackhole() set all necessary properties for the nexthop * Make nexthops blackhole/reject based on the rtm_type netlink property instead of using rtflags. Reported by: Marek Zarychta MFC after: 3 days Approved by: re(cperciva) (cherry picked from commit d2deebe21b591336fbd8915b37d409b25da54d4d) (cherry picked from commit f054a56ef3e8dc30ba0904d43cf7ec7b3e6e0ed4) --- sys/net/route/nhop_ctl.c | 27 +++++++++++++++++++++++++++ sys/netlink/route/rt.c | 28 ++++++++++++++++++++-------- 2 files changed, 47 insertions(+), 8 deletions(-) diff --git a/sys/net/route/nhop_ctl.c b/sys/net/route/nhop_ctl.c index d042d9519f6b..b92977ca42b0 100644 --- a/sys/net/route/nhop_ctl.c +++ b/sys/net/route/nhop_ctl.c @@ -822,6 +822,33 @@ nhop_set_blackhole(struct nhop_object *nh, int blackhole_rt_flag) nh->nh_flags |= NHF_REJECT; nh->nh_priv->rt_flags |= RTF_REJECT; break; + default: + /* Not a blackhole nexthop */ + return; + } + + nh->nh_ifp = V_loif; + nh->nh_flags &= ~NHF_GATEWAY; + nh->nh_priv->rt_flags &= ~RTF_GATEWAY; + nh->nh_priv->nh_neigh_family = nh->nh_priv->nh_upper_family; + + bzero(&nh->gw_sa, sizeof(nh->gw_sa)); + + switch (nh->nh_priv->nh_upper_family) { +#ifdef INET + case AF_INET: + nh->gw4_sa.sin_family = AF_INET; + nh->gw4_sa.sin_len = sizeof(struct sockaddr_in); + nh->gw4_sa.sin_addr.s_addr = htonl(INADDR_LOOPBACK); + break; +#endif +#ifdef INET6 + case AF_INET6: + nh->gw6_sa.sin6_family = AF_INET6; + nh->gw6_sa.sin6_len = sizeof(struct sockaddr_in6); + nh->gw6_sa.sin6_addr = in6addr_loopback; + break; +#endif } } diff --git a/sys/netlink/route/rt.c b/sys/netlink/route/rt.c index dabdaea3e03b..badd8d937be2 100644 --- a/sys/netlink/route/rt.c +++ b/sys/netlink/route/rt.c @@ -458,6 +458,7 @@ struct nl_parsed_route { uint8_t rtm_family; uint8_t rtm_dst_len; uint8_t rtm_protocol; + uint8_t rtm_type; }; #define _IN(_field) offsetof(struct rtmsg, _field) @@ -481,9 +482,10 @@ static const struct nlattr_parser nla_p_rtmsg[] = { }; static const struct nlfield_parser nlf_p_rtmsg[] = { - {.off_in = _IN(rtm_family), .off_out = _OUT(rtm_family), .cb = nlf_get_u8 }, - {.off_in = _IN(rtm_dst_len), .off_out = _OUT(rtm_dst_len), .cb = nlf_get_u8 }, - {.off_in = _IN(rtm_protocol), .off_out = _OUT(rtm_protocol), .cb = nlf_get_u8 }, + { .off_in = _IN(rtm_family), .off_out = _OUT(rtm_family), .cb = nlf_get_u8 }, + { .off_in = _IN(rtm_dst_len), .off_out = _OUT(rtm_dst_len), .cb = nlf_get_u8 }, + { .off_in = _IN(rtm_protocol), .off_out = _OUT(rtm_protocol), .cb = nlf_get_u8 }, + { .off_in = _IN(rtm_type), .off_out = _OUT(rtm_type), .cb = nlf_get_u8 }, }; #undef _IN #undef _OUT @@ -828,13 +830,23 @@ create_nexthop_from_attrs(struct nl_parsed_route *attrs, nhop_set_mtu(nh, attrs->rtax_mtu, true); if (attrs->rta_rtflags & RTF_BROADCAST) nhop_set_broadcast(nh, true); - if (attrs->rta_rtflags & RTF_BLACKHOLE) - nhop_set_blackhole(nh, NHF_BLACKHOLE); - if (attrs->rta_rtflags & RTF_REJECT) - nhop_set_blackhole(nh, NHF_REJECT); - nhop_set_rtflags(nh, attrs->rta_rtflags); if (attrs->rtm_protocol > RTPROT_STATIC) nhop_set_origin(nh, attrs->rtm_protocol); + nhop_set_rtflags(nh, attrs->rta_rtflags); + + switch (attrs->rtm_type) { + case RTN_UNICAST: + break; + case RTN_BLACKHOLE: + nhop_set_blackhole(nh, RTF_BLACKHOLE); + break; + case RTN_PROHIBIT: + case RTN_UNREACHABLE: + nhop_set_blackhole(nh, RTF_REJECT); + break; + /* TODO: return ENOTSUP for other types if strict option is set */ + } + nh = finalize_nhop(nh, perror); }