From nobody Thu Feb 23 17:43:22 2023 X-Original-To: dev-commits-src-main@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 4PN0k30Knsz3sH94; Thu, 23 Feb 2023 17:43:23 +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 4PN0k26vnNz3pCq; Thu, 23 Feb 2023 17:43:22 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1677174203; 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=pmU2H+oodvshqkDj+RMe+C8UGKQHil5jEvT8g7U3D9g=; b=mkybSQteoO6qqJqdUYNYVcHyk7PEKyI11dlEkmmRZQ9/jsnfPpgw1jlsXxElBUXadUjKjB inb3uRQqjgPlNS65Ih0QC1fiEaDi6hXPcudxqmNezkxrfh04b6AN1XvRIv+fGC6U2C7zoU sArYyGHE6K/yp1yKed7fSjLBIpxMv5Pk9nRgEm8bJgzdMYmZv4AKXUsazrP57ssAPXF707 3GuBx4/yN/j5B2jiLh2eRQv2e+rDcdXebRvtXvrztpXa+o+8YLWwtv1w8eCVKgjZ1Ul4YR cPALRhRJKa6SO9FzmmLNI801lOFP8xMMPbH2gpXVQAJfDTe+QPI+ORBholEVxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1677174203; 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=pmU2H+oodvshqkDj+RMe+C8UGKQHil5jEvT8g7U3D9g=; b=j/VUT7kkxZ52M5IQHBsIFfWCt2GH5gESph5ZG6asLYWAvMSoseLnN3qDd2KM4AbR638hhT RQ4vgP6o/V4kqJe5Y53GPFKC5uGt/rGdQieJE/vzdCQOG4SBKvzeWF0QQo//0qV0hCJM3f ykapVBjlP8eVysLam5ZmK3Tv9n3lD26qXhyTyBUmm7n95F9XnGgU0Si/MNApeK5JWaNJPv pkAvKj/NNsoYSJnvanJaKrgTjEvDw3Z01cWjCLm8jbb8LPqucQYvT6HpQwV9S6XH+mIWA+ gKEr5xSDakIEoWj5Or38WABJL4U6GBr9oBjd/Mv59xHQBRoUEDjDV5EF9nWUIg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1677174203; a=rsa-sha256; cv=none; b=yiXzez5UWrIusr4t0t34VwAiGC7BbfHTRcotxkV8mtMGEjt5B6R1mQ/PrL8/HzXOWP7Y2q Sz7kbB3Ch4LN1mz0ORq8kRcWfuSoX399bmd0+ygwcfAXb9cufx3vGRHwQrqNu2+e2QYbbu 4h5RjgADzEPCxu07v54Mv0jWOJj+ZfVjAOQwZBl7t4BDUXMlyEtGF1KntlL4S16oPsJWhw U5WR+3sNOp5pTVoUr/04Ci1XusvrbS5DJdEq/kYMHu8pYJkfHVUYuhkPQ1a8Rb8d5u5bj7 Bpr0tjU5CMFdWdXCEW0wNWGEGAPMJlKW0M2orM8AFX5tb0O475iSLFj9rS1a9w== 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 4PN0k25y2Tzrg8; Thu, 23 Feb 2023 17:43:22 +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 31NHhMJa061849; Thu, 23 Feb 2023 17:43:22 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 31NHhMZE061848; Thu, 23 Feb 2023 17:43:22 GMT (envelope-from git) Date: Thu, 23 Feb 2023 17:43:22 GMT Message-Id: <202302231743.31NHhMZE061848@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: d2deebe21b59 - main - netlink: fix addition of blackhole/reject routes. List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: d2deebe21b591336fbd8915b37d409b25da54d4d Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=d2deebe21b591336fbd8915b37d409b25da54d4d commit d2deebe21b591336fbd8915b37d409b25da54d4d Author: Alexander V. Chernikov AuthorDate: 2023-02-23 17:38:18 +0000 Commit: Alexander V. Chernikov CommitDate: 2023-02-23 17:43:18 +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 --- 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 15d4ec394187..73c34f675a04 100644 --- a/sys/net/route/nhop_ctl.c +++ b/sys/net/route/nhop_ctl.c @@ -823,6 +823,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); }