From nobody Sat Feb 19 14:22:34 2022 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 F227619CD004; Sat, 19 Feb 2022 14:22:34 +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 4K19kf618Zz4f6x; Sat, 19 Feb 2022 14:22:34 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1645280554; 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=FKTcjnzPaazYfx52yBNxXu0f1PoTBHomOtExTiJEdXA=; b=WSFZJm1w9WVrH8z5D2BReB2aB2WrebGQOlUYBK6tOwlPa9xV7NHJq362WI3Iw9jAW0rk45 aDakNwrYDQTU0KjKI1Zhai2RI4yDkkHSYhm2wn+MopvePKZfgKLpxu29gVAtLXIWxqQbKT mC+VrZyKXoJNUdV/fZsL//SGWBzX+jNaRT+Ku8yIoPfYYD9zooSD5l2PhpnRsckZ+aZ+8f ofYffF3IPaKvewaQ8OyXEy8e3GdevJwSKjn97/jGTxUetLLiBvo5OFaU35AMigsquwJQZf kAtRph3QxS/2CoEIcjDgCniMzqBnhtuqt+qUWjBNb+UiU9HlISbkan5AFE0aZA== 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 96B042894; Sat, 19 Feb 2022 14:22:34 +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 21JEMYwp071811; Sat, 19 Feb 2022 14:22:34 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 21JEMYvd071810; Sat, 19 Feb 2022 14:22:34 GMT (envelope-from git) Date: Sat, 19 Feb 2022 14:22:34 GMT Message-Id: <202202191422.21JEMYvd071810@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kristof Provost Subject: git: cb6af6551c76 - stable/13 - pf: deal with tables gaining or losing counters 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: kp X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: cb6af6551c76c8fda914c3c18003f293b60b06d8 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1645280554; 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=FKTcjnzPaazYfx52yBNxXu0f1PoTBHomOtExTiJEdXA=; b=yIO36sP1GBZWvHlrFZyQ/IEgimWmacoGTyQP4qR9bR40plsq+3YBeXZzSi7fSq08jQMFB9 l4y71ZnVMkdxs+mYzo6AACEq1Bk3lHn7/393GvpWU27PFzB6t3ZYVf/8RXRaQHIA2PPjjc pqV8KpEJ4QIxwnuG6cLQupAv84EzXvKK1Zff5SCh+kbujNZ31nlrpqZxcoBCa1+pJScGVx IebnE2Iz45P11K4qixoWw/RZ//fKiQ6AECZPQlDJoAY3S1a3HgaLZXQu3L8neHjGOOw4l+ FQluvjIh8Q3eFZTzqYBC1Z82R5O+3eeI7/4RIW+xr5t0UZ1ZYYB6onJ+I8cNPA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1645280554; a=rsa-sha256; cv=none; b=yuzRBr0v8uGrwwfHU3emDTal6ysTJhporDpyhaADncmzCdpRu5gC/ycvyPIjxO/W/7b4CW 2X6wK5rKjkR+67fH+SNf80/mvACax1E8Cwl6ZEUNB2V80rktsX0aL1r39d7NceqITONczC rB0wvh35nRmwnRRKI2XdsBmD2u2bOV2MD8hOd+JZGxHZzzU6Mae8bbNvubmPFj4h4MtySL /dVKId2yqvJwXqn1fLJAUdEZ9dYpcI2QI/OGgD+vDVdeTHl9kM2txpP9kysYEHwfkiUf24 +5fA2yLa6WLjiR46Y8fXYiHzR4FX90DQHVpfCsCWkJY/Tt6NIp2p0I8px9iyjA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=cb6af6551c76c8fda914c3c18003f293b60b06d8 commit cb6af6551c76c8fda914c3c18003f293b60b06d8 Author: Kristof Provost AuthorDate: 2022-02-01 17:25:57 +0000 Commit: Kristof Provost CommitDate: 2022-02-19 08:43:23 +0000 pf: deal with tables gaining or losing counters When we create a table without counters, add an entry and later re-define the table to have counters we wound up trying to read non-existent counters. We now cope with this by attempting to add them if needed, removing them when they're no longer needed and not trying to read from counters that are not present. MFC after: 2 weeks Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D34131 (cherry picked from commit b21826bf15f7ec1e206fa3cfdf40691f84fb1d8e) --- sys/netpfil/pf/pf_table.c | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/sys/netpfil/pf/pf_table.c b/sys/netpfil/pf/pf_table.c index 4cfe5d61e83e..2352e43cb342 100644 --- a/sys/netpfil/pf/pf_table.c +++ b/sys/netpfil/pf/pf_table.c @@ -103,7 +103,8 @@ struct pfr_walktree { PFRW_GET_ADDRS, PFRW_GET_ASTATS, PFRW_POOL_GET, - PFRW_DYNADDR_UPDATE + PFRW_DYNADDR_UPDATE, + PFRW_COUNTERS } pfrw_op; union { struct pfr_addr *pfrw1_addr; @@ -1032,7 +1033,8 @@ pfr_copyout_astats(struct pfr_astats *as, const struct pfr_kentry *ke, pfr_copyout_addr(&as->pfras_a, ke); as->pfras_tzero = kc->pfrkc_tzero; - if (! (w->pfrw_flags & PFR_TFLAG_COUNTERS)) { + if (! (w->pfrw_flags & PFR_TFLAG_COUNTERS) || + kc->pfrkc_counters == NULL) { bzero(as->pfras_packets, sizeof(as->pfras_packets)); bzero(as->pfras_bytes, sizeof(as->pfras_bytes)); as->pfras_a.pfra_fback = PFR_FB_NOCOUNT; @@ -1114,6 +1116,21 @@ pfr_walktree(struct radix_node *rn, void *arg) } break; } + case PFRW_COUNTERS: + { + if (w->pfrw_flags & PFR_TFLAG_COUNTERS) { + if (ke->pfrke_counters.pfrkc_counters != NULL) + break; + ke->pfrke_counters.pfrkc_counters = + uma_zalloc_pcpu(V_pfr_kentry_counter_z, + M_NOWAIT | M_ZERO); + } else { + uma_zfree_pcpu(V_pfr_kentry_counter_z, + ke->pfrke_counters.pfrkc_counters); + ke->pfrke_counters.pfrkc_counters = NULL; + } + break; + } } return (0); } @@ -1818,6 +1835,7 @@ static void pfr_setflags_ktable(struct pfr_ktable *kt, int newf) { struct pfr_kentryworkq addrq; + struct pfr_walktree w; PF_RULES_WASSERT(); @@ -1838,6 +1856,20 @@ pfr_setflags_ktable(struct pfr_ktable *kt, int newf) V_pfr_ktable_cnt--; return; } + if (newf & PFR_TFLAG_COUNTERS && ! (kt->pfrkt_flags & PFR_TFLAG_COUNTERS)) { + bzero(&w, sizeof(w)); + w.pfrw_op = PFRW_COUNTERS; + w.pfrw_flags |= PFR_TFLAG_COUNTERS; + kt->pfrkt_ip4->rnh_walktree(&kt->pfrkt_ip4->rh, pfr_walktree, &w); + kt->pfrkt_ip6->rnh_walktree(&kt->pfrkt_ip6->rh, pfr_walktree, &w); + } + if (! (newf & PFR_TFLAG_COUNTERS) && (kt->pfrkt_flags & PFR_TFLAG_COUNTERS)) { + bzero(&w, sizeof(w)); + w.pfrw_op = PFRW_COUNTERS; + w.pfrw_flags |= 0; + kt->pfrkt_ip4->rnh_walktree(&kt->pfrkt_ip4->rh, pfr_walktree, &w); + kt->pfrkt_ip6->rnh_walktree(&kt->pfrkt_ip6->rh, pfr_walktree, &w); + } if (!(newf & PFR_TFLAG_ACTIVE) && kt->pfrkt_cnt) { pfr_enqueue_addrs(kt, &addrq, NULL, 0); pfr_remove_kentries(kt, &addrq);