From nobody Mon Jun 27 17:32:54 2022 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 509248A3422; Mon, 27 Jun 2022 17:32: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 4LWvvB67CMz3DHN; Mon, 27 Jun 2022 17:32:54 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1656351174; 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=X8a9WeBqwe4XWsdTHJBUkM9y5NYZ6gGDCmt5xphcgss=; b=ZUMvIojcCuSHL8RemLlFX1uH2jywnMr0oAQPioSwaJ+Ig+MD1Lv1Qd7Kn9Hw5t2v57SCrV Aw2vTh6nMHPEDS0XC7HJ4QXFqoQ4ql/pEhcnE48R3qg2yRqG3BhO9bl2hCOjMr5roLSstl p0blwqeP0zXW/J5WEblXAspEUTLtbjyPrX4cdELReV5E4yaqGVZiU5KA1xJ4HkU5hqQKZS k4mXkDlQ4Eg/TmnKtj3TGoGk5HOouESYvESIKTOOlwSHlL+ZChz0RBhELjZM/xFsUi38jE K6G5w6/xpTY6f7I2skiKG73OItpoWBLbd+tMsCsgLEvNm7DLUD6iAuRaNW1zDA== 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 A0D054ABA; Mon, 27 Jun 2022 17:32:54 +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 25RHWsoX055335; Mon, 27 Jun 2022 17:32:54 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 25RHWs3s055334; Mon, 27 Jun 2022 17:32:54 GMT (envelope-from git) Date: Mon, 27 Jun 2022 17:32:54 GMT Message-Id: <202206271732.25RHWs3s055334@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: 8010b7a78a3a - main - routing: simplify decompose_change_notification(). 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/main X-Git-Reftype: branch X-Git-Commit: 8010b7a78a3af66dda1c74373499794af9ffd35f Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1656351174; 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=X8a9WeBqwe4XWsdTHJBUkM9y5NYZ6gGDCmt5xphcgss=; b=BK49rJJEP7JvA0Fmmi5nk2lDdc2xl+uBQOqMx+87w4jVII0ZwlS5VW4nTEHJlmcz9nj+d2 1O4s+rSLR+oDy5woNqdgNxZ0e1Hrgn1S5mS/fRCq4lOen9Qujv10w5AmHVJ1Rlhvu3VDdV Ua1XhGgodkTeQqGVxAjGH/DwufLhPC2CR62MHCMWQh72xV7GYfUPMRP0iyUxCz365wkXfb IRnR0si7vnqq/FquFvQQRd8teCRxPpz0rpgef9YZvqGdWsTiJYDq0KNyPspEX32cecWqjt +cKClKVCuGVUt4Y8mlxhjfv071/NEDNZKM+ZUC8DtiYBSlv2wJcqt3C75Qh8BA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1656351174; a=rsa-sha256; cv=none; b=LwrFiO72eBA6vJOIKrpub2AxJP2tmWwK4Hje44GpCAR/ADWx2WxtHg3mmWyE23MLbUt2ci 1GSaFb/9yUj8mjnSNBTKZBezKpEnGXeQ2vTt4IQYJLe+yiXqUd+6A8yYdEUBqjHowq0x5V k4Zt+BAX0NrE0d6PHmbUaK5hAS/o6+WsxopvTrjquX7nk9ZuiOm1EhoGBpUwKF7mZuPFoT pz+xi7IVosEdrJhdU/Pn014IE/u/BqioKpaX37VbvGEfRwvrenl/Vl2qrfEhNpiXADHGPi kfKs+yzV8n/BQv/Ag1K4w3GnYkhAshhRwfGNfFwbwjWKpJJSMfZVhCE8qSQvLg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=8010b7a78a3af66dda1c74373499794af9ffd35f commit 8010b7a78a3af66dda1c74373499794af9ffd35f Author: Alexander V. Chernikov AuthorDate: 2022-06-27 17:29:03 +0000 Commit: Alexander V. Chernikov CommitDate: 2022-06-27 17:30:52 +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 --- 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: