From nobody Fri Jan 13 21:24:48 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 4NtvZT1tj6z2qkqm; Fri, 13 Jan 2023 21:24:49 +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 4NtvZT0V5tz40cl; Fri, 13 Jan 2023 21:24:49 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1673645089; 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=jPtzuzs94aL/8WPa0ARC60wn+VUWSc5JjXmpUcxVGMA=; b=Ca3RtS10pccAggB+1DA766ReN3R1cS6Q2495CHBcYlUBQfxFzSrBSrOD4Y1ErmJcwuHhol eRd8yjH14B8FfkLts/6HXmV27o4pRpUyq68QKR7s3fwUvyMzD4+DYW8BenGGvK+KTdoFdX Q/Id9Ny6OSZTXXrBELYaEBwjARSfSMvdLUCvP7hQceHdodsg6Fld+xmop+TDh7rlY8PYXw mNXq0Xl8FVjSGStV0hM5cmjJLT2Y5qfjwU/HFNm7WBzH6bASn23W4jBFd7dGyLD/nnQ9Vl URPo2ga1fuRTK370J0NcuWVplQ7UJ0NeCaeX0OI0tc6BUpz2YpulV4sPFmLoEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1673645089; 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=jPtzuzs94aL/8WPa0ARC60wn+VUWSc5JjXmpUcxVGMA=; b=VH2W7bK4GrqdpCJKFcMARSWEBk4/w6kV9PSs/ZmARR1aC+LdCluo2hLNN0lDTEludlDiJN zHEqbJx3ZZPN2Ec7+ab3Zz3oYT2MmK/wv17Oj0zrFvNiYscaFew52Rj0WwQj3m+kvNqbI8 N5+nuixXupF7UAbfhMnxp522ts7KNIeZYWkkYTdywbiJ49C471Ugr0FkJz16aJAmmzYhlG vG0/4mV+ZmkIi8tQE6/TWj0ob1kzfiXbXY1D/3f5XzLBxp9QvQJyfGFPkrC5LscSXb349a ve4+ILo9QMJcQL31KQXutDq+0x4PJb+dgEGtFzXz0vnfaTbhys82BRcVKD7LiQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1673645089; a=rsa-sha256; cv=none; b=Yhde9dfR3Yr3I/rDMJ7skSNf8kVkD1k+uffZ5KC/TutvehjVUWFR1KWjJg6vTOL4m7hte+ +m+uzhO+my7rlBQhj+3Qe2Wh2+/nHTNAON21iNxke/0jCNQbaYXLJ+MR6nlspvn3FWcRyY ozQdS8nIvoU6RustKRuPn7mJpUC2yFUOfFO1IqF5saIMTpsj3TmEM+/WAaATqV1RZhT69W J6ii72ipLiC7r0xZL4oRBj0jQzqBFknD3+8sPA428WopoudqVcPB4er4bss50uAMuR1jGq IRIlU2j4e+7I5me6+C04391TkigMcLUt09mA7tcxXlJ0Ga4SqKNIVSY/rufWjQ== 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 4NtvZS5dBbzNGT; Fri, 13 Jan 2023 21:24:48 +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 30DLOmma040754; Fri, 13 Jan 2023 21:24:48 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30DLOm8s040753; Fri, 13 Jan 2023 21:24:48 GMT (envelope-from git) Date: Fri, 13 Jan 2023 21:24:48 GMT Message-Id: <202301132124.30DLOm8s040753@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: 884b1fa66bc1 - stable/13 - routing: simplify decompose_change_notification(). 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: 884b1fa66bc16e7667efe492a7e1cc18c53c23e0 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=884b1fa66bc16e7667efe492a7e1cc18c53c23e0 commit 884b1fa66bc16e7667efe492a7e1cc18c53c23e0 Author: Alexander V. Chernikov AuthorDate: 2022-06-27 17:29:03 +0000 Commit: Alexander V. Chernikov CommitDate: 2023-01-13 21:18:25 +0000 routing: simplify decompose_change_notification(). The function's goal is to compare old/new nhop/nexthop group for the route and decompose it into the series of RTM_ADD/RTM_DELETE single-nhop events, calling specified callback for each event. Simplify it by properly leveraging the fact that both old/new groups are sorted nhop-# ascending. Tested by: Claudio Jeker Differential Revision: https://reviews.freebsd.org/D35598 MFC after: 2 weeks (cherry picked from commit 8010b7a78a3af66dda1c74373499794af9ffd35f) --- sys/net/route/route_helpers.c | 128 ++++++++++++++++++++---------------------- 1 file changed, 61 insertions(+), 67 deletions(-) diff --git a/sys/net/route/route_helpers.c b/sys/net/route/route_helpers.c index 0696eec416b1..1577df5513d3 100644 --- a/sys/net/route/route_helpers.c +++ b/sys/net/route/route_helpers.c @@ -64,6 +64,11 @@ __FBSDID("$FreeBSD$"); #endif #include +#define DEBUG_MOD_NAME rt_helpers +#define DEBUG_MAX_LEVEL LOG_DEBUG2 +#include +_DECLARE_DEBUG(LOG_INFO); + /* * RIB helper functions. */ @@ -253,13 +258,38 @@ rib_lookup(uint32_t fibnum, const struct sockaddr *dst, uint32_t flags, return (nh); } +static void +notify_add(struct rib_cmd_info *rc, const struct weightened_nhop *wn_src, + route_notification_t *cb, void *cbdata) { + rc->rc_nh_new = wn_src->nh; + rc->rc_nh_weight = wn_src->weight; +#if DEBUG_MAX_LEVEL >= LOG_DEBUG2 + char nhbuf[NHOP_PRINT_BUFSIZE]; + FIB_NH_LOG(LOG_DEBUG2, wn_src->nh, "RTM_ADD for %s @ w=%u", + nhop_print_buf(wn_src->nh, nhbuf, sizeof(nhbuf)), wn_src->weight); +#endif + cb(rc, cbdata); +} + +static void +notify_del(struct rib_cmd_info *rc, const struct weightened_nhop *wn_src, + route_notification_t *cb, void *cbdata) { + rc->rc_nh_old = wn_src->nh; + rc->rc_nh_weight = wn_src->weight; +#if DEBUG_MAX_LEVEL >= LOG_DEBUG2 + char nhbuf[NHOP_PRINT_BUFSIZE]; + FIB_NH_LOG(LOG_DEBUG2, wn_src->nh, "RTM_DEL for %s @ w=%u", + nhop_print_buf(wn_src->nh, nhbuf, sizeof(nhbuf)), wn_src->weight); +#endif + cb(rc, cbdata); +} + #ifdef ROUTE_MPATH static void decompose_change_notification(struct rib_cmd_info *rc, route_notification_t *cb, void *cbdata) { uint32_t num_old, num_new; - uint32_t nh_idx_old, nh_idx_new; struct weightened_nhop *wn_old, *wn_new; struct weightened_nhop tmp = { NULL, 0 }; uint32_t idx_old = 0, idx_new = 0; @@ -283,90 +313,58 @@ decompose_change_notification(struct rib_cmd_info *rc, route_notification_t *cb, wn_new = &tmp; num_new = 1; } +#if DEBUG_MAX_LEVEL >= LOG_DEBUG + { + char buf_old[NHOP_PRINT_BUFSIZE], buf_new[NHOP_PRINT_BUFSIZE]; + nhop_print_buf_any(rc->rc_nh_old, buf_old, NHOP_PRINT_BUFSIZE); + nhop_print_buf_any(rc->rc_nh_new, buf_new, NHOP_PRINT_BUFSIZE); + FIB_NH_LOG(LOG_DEBUG, wn_old[0].nh, "change %s -> %s", buf_old, buf_new); + } +#endif /* Use the fact that each @wn array is sorted */ /* - * Want to convert into set of add and delete operations - * [1] -> [1, 2] = A{2} - * [2] -> [1, 2] = A{1} - * [1, 2, 4]->[1, 3, 4] = A{2}, D{3} - * [1, 2, 4]->[1, 4] = D{2} - * [1, 2, 4] -> [3, 4] = D{1}, C{2,3} OR C{1,3}, D{2} OR D{1},D{2},A{3} - * [1, 2] -> [3, 4] = + * Here we have one (or two) multipath groups and transition + * between them needs to be reported to the caller, using series + * of primitive (RTM_DEL, RTM_ADD) operations. * + * Leverage the fact that each nexthop group has its nexthops sorted + * by their indices. + * [1] -> [1, 2] = A{2} + * [1, 2] -> [1] = D{2} + * [1, 2, 4] -> [1, 3, 4] = D{2}, A{3} + * [1, 2] -> [3, 4] = D{1}, D{2}, A{3}, A{4] */ - idx_old = 0; while ((idx_old < num_old) && (idx_new < num_new)) { - nh_idx_old = wn_old[idx_old].nh->nh_priv->nh_idx; - nh_idx_new = wn_new[idx_new].nh->nh_priv->nh_idx; + uint32_t nh_idx_old = wn_old[idx_old].nh->nh_priv->nh_idx; + uint32_t nh_idx_new = wn_new[idx_new].nh->nh_priv->nh_idx; if (nh_idx_old == nh_idx_new) { if (wn_old[idx_old].weight != wn_new[idx_new].weight) { /* Update weight by providing del/add notifications */ - rc_del.rc_nh_old = wn_old[idx_old].nh; - rc_del.rc_nh_weight = wn_old[idx_old].weight; - cb(&rc_del, cbdata); - - rc_add.rc_nh_new = wn_new[idx_new].nh; - rc_add.rc_nh_weight = wn_new[idx_new].weight; - cb(&rc_add, cbdata); + notify_del(&rc_del, &wn_old[idx_old], cb, cbdata); + notify_add(&rc_add, &wn_new[idx_new], cb, cbdata); } idx_old++; idx_new++; } else if (nh_idx_old < nh_idx_new) { - /* - * [1, ~2~, 4], [1, ~3~, 4] - * [1, ~2~, 5], [1, ~3~, 4] - * [1, ~2~], [1, ~3~, 4] - */ - if ((idx_old + 1 >= num_old) || - (wn_old[idx_old + 1].nh->nh_priv->nh_idx > nh_idx_new)) { - /* Add new unless the next old item is still <= new */ - rc_add.rc_nh_new = wn_new[idx_new].nh; - rc_add.rc_nh_weight = wn_new[idx_new].weight; - cb(&rc_add, cbdata); - idx_new++; - } - /* In any case, delete current old */ - rc_del.rc_nh_old = wn_old[idx_old].nh; - rc_del.rc_nh_weight = wn_old[idx_old].weight; - cb(&rc_del, cbdata); + /* [1, ~2~, 4], [1, ~3~, 4] */ + notify_del(&rc_del, &wn_old[idx_old], cb, cbdata); idx_old++; } else { - /* - * nh_idx_old > nh_idx_new - * - * [1, ~3~, 4], [1, ~2~, 4] - * [1, ~3~, 5], [1, ~2~, 4] - * [1, ~3~, 4], [1, ~2~] - */ - if ((idx_new + 1 >= num_new) || - (wn_new[idx_new + 1].nh->nh_priv->nh_idx > nh_idx_old)) { - /* No next item or next item is > current one */ - rc_add.rc_nh_new = wn_new[idx_new].nh; - rc_add.rc_nh_weight = wn_new[idx_new].weight; - cb(&rc_add, cbdata); - idx_new++; - } - /* In any case, delete current old */ - rc_del.rc_nh_old = wn_old[idx_old].nh; - rc_del.rc_nh_weight = wn_old[idx_old].weight; - cb(&rc_del, cbdata); - idx_old++; + /* nh_idx_old > nh_idx_new. */ + notify_add(&rc_add, &wn_new[idx_new], cb, cbdata); + idx_new++; } } while (idx_old < num_old) { - rc_del.rc_nh_old = wn_old[idx_old].nh; - rc_del.rc_nh_weight = wn_old[idx_old].weight; - cb(&rc_del, cbdata); + notify_del(&rc_del, &wn_old[idx_old], cb, cbdata); idx_old++; } while (idx_new < num_new) { - rc_add.rc_nh_new = wn_new[idx_new].nh; - rc_add.rc_nh_weight = wn_new[idx_new].weight; - cb(&rc_add, cbdata); + notify_add(&rc_add, &wn_new[idx_new], cb, cbdata); idx_new++; } } @@ -393,9 +391,7 @@ rib_decompose_notification(struct rib_cmd_info *rc, route_notification_t *cb, return; wn = nhgrp_get_nhops((struct nhgrp_object *)rc->rc_nh_new, &num_nhops); for (uint32_t i = 0; i < num_nhops; i++) { - rc_new.rc_nh_new = wn[i].nh; - rc_new.rc_nh_weight = wn[i].weight; - cb(&rc_new, cbdata); + notify_add(&rc_new, &wn[i], cb, cbdata); } break; case RTM_DELETE: @@ -403,9 +399,7 @@ rib_decompose_notification(struct rib_cmd_info *rc, route_notification_t *cb, return; wn = nhgrp_get_nhops((struct nhgrp_object *)rc->rc_nh_old, &num_nhops); for (uint32_t i = 0; i < num_nhops; i++) { - rc_new.rc_nh_old = wn[i].nh; - rc_new.rc_nh_weight = wn[i].weight; - cb(&rc_new, cbdata); + notify_del(&rc_new, &wn[i], cb, cbdata); } break; case RTM_CHANGE: