From nobody Fri Jan 13 21:25:55 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 4Ntvbl6PfJz2qlSh; Fri, 13 Jan 2023 21:25:55 +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 4Ntvbl3XKGz44M7; Fri, 13 Jan 2023 21:25:55 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1673645155; 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=DfwlNjR6xKmRU7hNJrRd7XLHI9HHCef2HBjptheCDlI=; b=Wx9YDpJN3NGPpLcpQzIpFiNZKrznxamLFcxU+kA5kJaXefukyRlT/wkdZDeKZYX4Hn8NjW 1/rRWWTSGNYr6ZQdirf7MwZhHp5NLwKUNZoEZr4WKIQv8uyKTrZgcx6U6g9kdpRVperV2i 0FgJ+yr/Z0jk3mD5JeK1VdvwrPQmhil3ff9V6VvYXwUt16r5TaRT3Zu+yBqyrGBTmERkz0 q4m41AAP4uYTIAzbGUHx42RQdySXlfd/nAu5ytNObPKlpkqxQ+HwyIdKO6HUH0oLWB78+2 HLtKQW+1hV+A4DFCuS1lfsqAxYeqCRgohQvHFAZ1T2tIC06VccaOZwcKToMu2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1673645155; 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=DfwlNjR6xKmRU7hNJrRd7XLHI9HHCef2HBjptheCDlI=; b=VhcEgMpBAFZr1NrjbYTjPI9zu0nAXJqWM+PcvPCFTQ43NhQJ4UQuCFh81i0gBYsDpUtQFL +Z/M20ZD3RpZTSxt+sFe1pMFPyVac33ceXjzHxCigxKn+LTtbkWPN8Zj4InLCbILqjnbXo hyAMvsqoahRmnD+yclZWrRMhd8tXtkuk7ZAuiRvGPm6eIycD8dSykhunF1Xrmx9kQD+ZKe EaSr6UR8JelAFkuQ8hGyzmmq9lOTrioGDidEfPl1SSPXm30QKsAwdaYGPKlyiC6uHjbhQj 34u/ouAk2x32Qq5Mgt4LMZYWT/fRdmF24o7EaQhFk01G3RNzPYZyfOq70+SIPg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1673645155; a=rsa-sha256; cv=none; b=IQZ5yAwolKmx3OGoQY7WuJ0izfNbHZ+eHZoXHKokoFDjxPsl2pBgEWfifwZCsOJ6ulxo0G WrtX859g8biCcxKfUO2EL427x0wWhp0ianPEgS2fkVE5bKFE6nU6cb9RIQ79UO9tqlnnno AillsCFtWM2d1+N+7Yj01eY9wguMqehoFgFVDvXMEuHnyjuHEGrNcJ8R1NHpB8YSuYHfwx Y7jjjYG3pVo+JpXxFCmVk4kE0MzKld4AdKz/jfBPq1eYi9FSLeYnObwkfRxIPKEM5BXinW CdPPnV9XmcxSSS/aqBC3WptldXNpUSiXfrbW/UJL4UTfdCiASP5BYZdGBhoXng== 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 4Ntvbl2WhtzNGf; Fri, 13 Jan 2023 21:25:55 +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 30DLPtkt042523; Fri, 13 Jan 2023 21:25:55 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30DLPtHT042520; Fri, 13 Jan 2023 21:25:55 GMT (envelope-from git) Date: Fri, 13 Jan 2023 21:25:55 GMT Message-Id: <202301132125.30DLPtHT042520@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: 0bab3df58f66 - stable/13 - routing: add abitity to set the protocol that installed route/nexthop. 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: 0bab3df58f66336ee6decac1a8c5a1ad9ae61f73 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=0bab3df58f66336ee6decac1a8c5a1ad9ae61f73 commit 0bab3df58f66336ee6decac1a8c5a1ad9ae61f73 Author: Alexander V. Chernikov AuthorDate: 2022-09-08 09:05:53 +0000 Commit: Alexander V. Chernikov CommitDate: 2023-01-13 21:24:12 +0000 routing: add abitity to set the protocol that installed route/nexthop. Routing daemons such as bird need to know if they install certain route so they can clean it up on startup, as a form of achieving consistent state during the crash recovery. Currently they use combination of routing flags (RTF_PROTO1) to detect these routes when interacting via route(4) rtsock protocol. Netlink protocol has a special "rtm_protocol" field that is filled and checked by the route originator. To prepare for the upcoming netlink introduction, add ability to record origing to both nexthops and nexthop groups via __origin() KPI. The actual calls will be used in the followup commits. MFC after: 1 month (cherry picked from commit 000250be0d2dc7a241f1c9b9c27d941af781ca46) --- sys/net/route.c | 1 + sys/net/route/nhgrp_ctl.c | 12 ++++++++++++ sys/net/route/nhgrp_var.h | 3 ++- sys/net/route/nhop.h | 10 ++++++++++ sys/net/route/nhop_ctl.c | 12 ++++++++++++ sys/net/route/nhop_var.h | 1 + sys/net/route/route_ctl.c | 1 + 7 files changed, 39 insertions(+), 1 deletion(-) diff --git a/sys/net/route.c b/sys/net/route.c index 7190d93d787d..b74256207e4a 100644 --- a/sys/net/route.c +++ b/sys/net/route.c @@ -217,6 +217,7 @@ rib_add_redirect(u_int fibnum, struct sockaddr *dst, struct sockaddr *gateway, nhop_set_pxtype_flag(nh, NHF_HOST); nhop_set_expire(nh, lifetime_sec + time_uptime); nhop_set_redirect(nh, true); + nhop_set_origin(nh, NH_ORIGIN_REDIRECT); rnd.rnd_nhop = nhop_get_nhop(nh, &error); if (error == 0) { error = rib_add_route_px(fibnum, dst, -1, diff --git a/sys/net/route/nhgrp_ctl.c b/sys/net/route/nhgrp_ctl.c index ca9e01ed0077..06f46746be4b 100644 --- a/sys/net/route/nhgrp_ctl.c +++ b/sys/net/route/nhgrp_ctl.c @@ -852,6 +852,18 @@ nhgrp_get_idx(const struct nhgrp_object *nhg) return (nhg_priv->nhg_idx); } +uint8_t +nhgrp_get_origin(struct nhgrp_object *nhg) +{ + return (NHGRP_PRIV(nhg)->nhg_origin); +} + +void +nhgrp_set_origin(struct nhgrp_object *nhg, uint8_t origin) +{ + NHGRP_PRIV(nhg)->nhg_origin = origin; +} + uint32_t nhgrp_get_count(struct rib_head *rh) { diff --git a/sys/net/route/nhgrp_var.h b/sys/net/route/nhgrp_var.h index 3d894857558d..c1540fbb33cf 100644 --- a/sys/net/route/nhgrp_var.h +++ b/sys/net/route/nhgrp_var.h @@ -49,7 +49,8 @@ struct nhgrp_priv { uint32_t nhg_idx; uint32_t nhg_uidx; uint8_t nhg_nh_count; /* number of items in nh_weights */ - uint8_t nhg_spare[3]; + uint8_t nhg_origin; /* protocol which created the group */ + uint8_t nhg_spare[2]; u_int nhg_refcount; /* use refcount */ u_int nhg_linked; /* refcount(9), == 2 if linked to the list */ struct nh_control *nh_control; /* parent control structure */ diff --git a/sys/net/route/nhop.h b/sys/net/route/nhop.h index 24ddb692efb8..669284e0ac62 100644 --- a/sys/net/route/nhop.h +++ b/sys/net/route/nhop.h @@ -199,6 +199,14 @@ void nhop_set_type(struct nhop_object *nh, enum nhop_type nh_type); void nhop_set_src(struct nhop_object *nh, struct ifaddr *ifa); void nhop_set_transmit_ifp(struct nhop_object *nh, struct ifnet *ifp); +#define NH_ORIGIN_UNSPEC 0 /* not set */ +#define NH_ORIGIN_REDIRECT 1 /* kernel-originated redirect */ +#define NH_ORIGIN_KERNEL 2 /* kernel (interface) routes */ +#define NH_ORIGIN_BOOT 3 /* kernel-originated routes at boot */ +#define NH_ORIGIN_STATIC 4 /* route(8) routes */ +void nhop_set_origin(struct nhop_object *nh, uint8_t origin); +uint8_t nhop_get_origin(struct nhop_object *nh); + uint32_t nhop_get_idx(const struct nhop_object *nh); uint32_t nhop_get_uidx(const struct nhop_object *nh); void nhop_set_uidx(struct nhop_object *nh, uint32_t uidx); @@ -217,6 +225,8 @@ struct rib_head *nhop_get_rh(const struct nhop_object *nh); struct nhgrp_object; uint32_t nhgrp_get_uidx(const struct nhgrp_object *nhg); +uint8_t nhgrp_get_origin(struct nhgrp_object *nhg); +void nhgrp_set_origin(struct nhgrp_object *nhg, uint8_t origin); #endif /* _KERNEL */ /* Kernel <> userland structures */ diff --git a/sys/net/route/nhop_ctl.c b/sys/net/route/nhop_ctl.c index e4195d106d01..033a99acab1b 100644 --- a/sys/net/route/nhop_ctl.c +++ b/sys/net/route/nhop_ctl.c @@ -1012,6 +1012,18 @@ nhop_get_rh(const struct nhop_object *nh) return (rt_tables_get_rnh(fibnum, family)); } +uint8_t +nhop_get_origin(struct nhop_object *nh) +{ + return (nh->nh_priv->nh_origin); +} + +void +nhop_set_origin(struct nhop_object *nh, uint8_t origin) +{ + nh->nh_priv->nh_origin = origin; +} + void nhops_update_ifmtu(struct rib_head *rh, struct ifnet *ifp, uint32_t mtu) { diff --git a/sys/net/route/nhop_var.h b/sys/net/route/nhop_var.h index c3c442a4bfa3..ace14556a14c 100644 --- a/sys/net/route/nhop_var.h +++ b/sys/net/route/nhop_var.h @@ -87,6 +87,7 @@ struct nhop_priv { u_int nh_refcnt; /* number of references, refcount(9) */ u_int nh_linked; /* refcount(9), == 2 if linked to the list */ int nh_finalized; /* non-zero if finalized() was called */ + uint8_t nh_origin; /* protocol that originated the nexthop */ struct nhop_object *nh; /* backreference to the dataplane nhop */ struct nh_control *nh_control; /* backreference to the rnh */ struct nhop_priv *nh_next; /* hash table membership */ diff --git a/sys/net/route/route_ctl.c b/sys/net/route/route_ctl.c index a9ea2ad49103..d6c382735902 100644 --- a/sys/net/route/route_ctl.c +++ b/sys/net/route/route_ctl.c @@ -622,6 +622,7 @@ rib_copy_route(struct rtentry *rt, const struct route_nhop_data *rnd_src, return (ENOMEM); } nhop_copy(nh, rnd_src->rnd_nhop); + nhop_set_origin(nh, nhop_get_origin(rnd_src->rnd_nhop)); nhop_set_fibnum(nh, rh_dst->rib_fibnum); nh = nhop_get_nhop_internal(rh_dst, nh, &error); if (error != 0) {