From nobody Mon Feb 27 10:36:08 2023 X-Original-To: dev-commits-src-branches@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 4PQH3D5CKvz3twW0; Mon, 27 Feb 2023 10:36:08 +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 4PQH3D4mVrz4Ddc; Mon, 27 Feb 2023 10:36:08 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1677494168; 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=IcHJscc1EtsG0tAjNj0wlzMqQ4jnyeMphyc9UGdoQ1U=; b=y22tmo160tYOOX4AH3KgfuHLTgJc5Oq2Wsit8XEQVMubmF3+emEA3H/pSdIn8h+yqbrFY+ 5t4E7IzwzC5jXy1e2qSVQ8+OTgjuxSgFc7oOoeGc8tt9POMbADynwV5nC0tIITBldULNpG +BiTLwhoops1UQQvPpE5NYykfoZE3qtca72wBaQn7XjnSitOkQnw2yYsYXFRgqgeBmi1Gw g6+17PVdnCTiIWEORr9azAnoFGKYYCSiyh65YncDkLXLv8DOXSk/WhEc0VUIZ+J8qNXaUH e9lWhkyKcAOEGE4VWxXmWydi8rLJoZSvRbhqNvDOLxdj+TO5T8RtL//+eW067Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1677494168; 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=IcHJscc1EtsG0tAjNj0wlzMqQ4jnyeMphyc9UGdoQ1U=; b=H6CHM6mBVdQsyQFtc6uQ8s0b8AVQUM/+tzsSTlz7xWHQ9ETqo8TOeMp8NirlwjSDFddnT8 tP2vtQUsRx+Go73vLIWgx8lUkuAQ/S318w5bx5qzmcQVbVVTBxiFtq76guafE0EaUBla/B tWCPctM6WRPsWA0E7eSWUJ/uF8nhYiVRstCw3aZno7levN+4gmUpfZAaJhWBalS+B822TQ jpsIwX+Rui6wL/QREBscnYRgxg2PH5sAgnxjW4fzgVARrZfv41eiUXAYZtFYzZdRWapUJr ntJc/86z6zAUbfghuNL0majK5nNajcVGG1kQpFe4K1pEusec8AFvZ2Eq7nVV5A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1677494168; a=rsa-sha256; cv=none; b=ThVbHWLGmIDWOmWxu+vCcg7jQ7IVS0HxDoenBUuZaVOzT7hd6CGPf5y00opN7xrkLbgic/ rIH/qSYw0yE5mL23D21bcM63CmDwKScXAsMocLGIyBslCiMBPsprHzRobR0j+fAwtmbF6p jZ0u9IKm7CEAd1PXbjJKQGnwrHNPjTDnb2sHnlbWRUukQFpef3KU8VV8qMQqvDtRlkQ43/ 8YtXRmI5TauX2m3y8ZFk1XcZS0Q55/EKtPAXLedqDIF59bsI6FpvhbtAwyMH7mDzKuIRjJ JKQoCIjWKm6k9vIo+c58uVV/4i/B1JFrgTItCrUcsoj6J6NzJobSzdlsU6RPig== 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 4PQH3D3scBzNBk; Mon, 27 Feb 2023 10:36:08 +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 31RAa8Bx075575; Mon, 27 Feb 2023 10:36:08 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 31RAa84w075574; Mon, 27 Feb 2023 10:36:08 GMT (envelope-from git) Date: Mon, 27 Feb 2023 10:36:08 GMT Message-Id: <202302271036.31RAa84w075574@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: f054a56ef3e8 - stable/13 - netlink: fix addition of blackhole/reject routes. List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@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/stable/13 X-Git-Reftype: branch X-Git-Commit: f054a56ef3e8dc30ba0904d43cf7ec7b3e6e0ed4 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=f054a56ef3e8dc30ba0904d43cf7ec7b3e6e0ed4 commit f054a56ef3e8dc30ba0904d43cf7ec7b3e6e0ed4 Author: Alexander V. Chernikov AuthorDate: 2023-02-23 17:38:18 +0000 Commit: Alexander V. Chernikov CommitDate: 2023-02-27 10:29:53 +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 (cherry picked from commit d2deebe21b591336fbd8915b37d409b25da54d4d) --- sys/net/route/nhop_ctl.c | 23 +++++++++++++++++++++++ sys/netlink/route/rt.c | 28 ++++++++++++++++++++-------- 2 files changed, 43 insertions(+), 8 deletions(-) diff --git a/sys/net/route/nhop_ctl.c b/sys/net/route/nhop_ctl.c index d042d9519f6b..390e5eddd496 100644 --- a/sys/net/route/nhop_ctl.c +++ b/sys/net/route/nhop_ctl.c @@ -822,6 +822,29 @@ 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) { + 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; + 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; } } 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); }