From nobody Fri Oct 30 12:21:38 2026 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 4jGKw33hVzz6wm1t for ; Fri, 30 Oct 2026 12:21:39 +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) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4jGKw303RJz4V2X for ; Fri, 30 Oct 2026 12:21:38 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1793362899; 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=ZkcOAMMHCoCd+KyfrMvEjqxRcdPF+RMCdDtq7Af2Z4I=; b=w/TnzgZ9dCB7rOXhR8v5QbjkrNMmbpjynBXzCQy+/MWXN1okkKB3sFCkNU+rBbtOo8A+Wx WREJrrtvJaOE6M6wulOMzGQ2eCJ4adu6XmncfCvAwgjSZISpSgZ6ImkG/cDYNAYvAQIm7r aBEmLh+Rbayh+d6iwTFu/Qv67m5gj0zSavOE8ZPjbbV/3IWnRacjmiYgH6uOEHSREU/YoL QEV8r/u+jP8KjbsuaPeeHtKEVNZ6Ah8m1waptRa7pxrBZ1idyADJD5k9SELeaaQ2Es/ThF c5gIh19pag5YM8/faA1qUBOyRm2ImR563T7EIGnJJXstBLTpKnT2rMxlf7vQqw== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1793362899; b=xEHHD2aJGHunJSejZTW/JjUaF8EclGqYgA3BKdWnt9p611kAT9fnIadHcSDl2xinesRmUK CoFR2WDeOVYDExO0lQpLVr8SBOv3c7kBjH3csMTUGF+Vbf9lu2ssF9kY7vVZpvGAhjuKiM tVahBayHuXUGzRcKnqUgVG5KRYYyUcZGeALm7sGvD6fUUTzlvepmPPSQYkDqWXvBNIhe31 16gCYH1rF1VNEIvDkd+/tP6fGSEnTRa61vFPp2GbnIJ9SOm3mTBwfblJTD1VFJ3wKQ4gu6 43NkVzTYE8BQBaeVbTlXt/JHF16ZiOKhvLq3dZnl3npufU7Ng36ysU9O4EAyng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1793362899; 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=ZkcOAMMHCoCd+KyfrMvEjqxRcdPF+RMCdDtq7Af2Z4I=; b=YlkEdTOjXz7AFkv2Q7j4qzs8ETx4FBMbBxEr0vaA/jotQ8Jwk9tXczpC28PWK7H+D9UbXs lgnavzn33hwXnsFn5Lh/vqUwIPuLNTkkIuIc20I0RaVt5zbWdW9SNXiy/LMOwedBi98m55 P06yRSj4FaUeW4Iv8RNkOiPQP/CQrakqE6nOClhvp5lzHK3sfpJdOk7h/DsX+Tj7rf/LRr 8pU2CrbmD+gzvQy0tq6k3HzUN92xPF+pxIws7ImAnULnDwlCLk8Ag+elVroXVIFWNDii2B DYF+HlNLkOMZul8ikp4W2K5zFy1Q/GOBUmAMq4H5BIqT/lHwod9jYsQT9rM7NQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4jGKw25tntzR1s for ; Fri, 30 Oct 2026 12:21:38 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 4436b by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Fri, 30 Oct 2026 12:21:38 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kristof Provost Subject: git: 2636cc0414fd - main - pf: have DIOCXBEGIN/DIOCXROLLBACK/DIOCXCOMMIT use the new functions List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org List-Id: Commit messages for all branches of the src repository List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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/main X-Git-Reftype: branch X-Git-Commit: 2636cc0414fdd2cf69759d8c56e1e82782aef7b0 Auto-Submitted: auto-generated Date: Fri, 30 Oct 2026 12:21:38 +0000 Message-Id: <6ae48bd2.4436b.134dbda5@gitrepo.freebsd.org> The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=2636cc0414fdd2cf69759d8c56e1e82782aef7b0 commit 2636cc0414fdd2cf69759d8c56e1e82782aef7b0 Author: Kristof Provost AuthorDate: 2026-10-27 13:37:45 +0000 Commit: Kristof Provost CommitDate: 2026-10-30 12:21:10 +0000 pf: have DIOCXBEGIN/DIOCXROLLBACK/DIOCXCOMMIT use the new functions The netlink begin/rollback/commit code has separate functions for this. Deduplicate the code and just use those functions. Sponsored by: Rubicon Communications, LLC ("Netgate") --- sys/netpfil/pf/pf_ioctl.c | 316 +++++----------------------------------------- 1 file changed, 35 insertions(+), 281 deletions(-) diff --git a/sys/netpfil/pf/pf_ioctl.c b/sys/netpfil/pf/pf_ioctl.c index 464a89a40b9a..27a6528d7e91 100644 --- a/sys/netpfil/pf/pf_ioctl.c +++ b/sys/netpfil/pf/pf_ioctl.c @@ -6399,10 +6399,13 @@ DIOCCHANGEADDR_error: break; } - case DIOCXBEGIN: { + case DIOCXBEGIN: + case DIOCXROLLBACK: + case DIOCXCOMMIT: { struct pfioc_trans *io = (struct pfioc_trans *)addr; - struct pfioc_trans_e *ioes, *ioe; - size_t totlen; + struct pfioc_trans_e *ioe; + struct pf_trans trans; + struct pf_trans_e *e; int i; if (io->esize != sizeof(*ioe)) { @@ -6415,296 +6418,47 @@ DIOCCHANGEADDR_error: error = EINVAL; goto fail; } - totlen = sizeof(struct pfioc_trans_e) * io->size; - ioes = mallocarray(io->size, sizeof(struct pfioc_trans_e), - M_PF, M_WAITOK); - error = copyin(io->array, ioes, totlen); - if (error) { - free(ioes, M_PF); - goto fail; - } - PF_RULES_WLOCK(); - for (i = 0, ioe = ioes; i < io->size; i++, ioe++) { - ioe->anchor[sizeof(ioe->anchor) - 1] = '\0'; - switch (ioe->rs_num) { - case PF_RULESET_ETH: - if ((error = pf_begin_eth(&ioe->ticket, ioe->anchor))) { - PF_RULES_WUNLOCK(); - free(ioes, M_PF); - goto fail; - } - break; -#ifdef ALTQ - case PF_RULESET_ALTQ: - if (ioe->anchor[0]) { - PF_RULES_WUNLOCK(); - free(ioes, M_PF); - error = EINVAL; - goto fail; - } - if ((error = pf_begin_altq(&ioe->ticket))) { - PF_RULES_WUNLOCK(); - free(ioes, M_PF); - goto fail; - } - break; -#endif /* ALTQ */ - case PF_RULESET_TABLE: - { - struct pfr_table table; - - bzero(&table, sizeof(table)); - strlcpy(table.pfrt_anchor, ioe->anchor, - sizeof(table.pfrt_anchor)); - if ((error = pfr_ina_begin(&table, - &ioe->ticket, NULL, 0))) { - PF_RULES_WUNLOCK(); - free(ioes, M_PF); - goto fail; - } - break; - } - default: - if ((error = pf_begin_rules(&ioe->ticket, - ioe->rs_num, ioe->anchor))) { - PF_RULES_WUNLOCK(); - free(ioes, M_PF); - goto fail; - } - break; - } - } - PF_RULES_WUNLOCK(); - error = copyout(ioes, io->array, totlen); - free(ioes, M_PF); - break; - } - case DIOCXROLLBACK: { - struct pfioc_trans *io = (struct pfioc_trans *)addr; - struct pfioc_trans_e *ioe, *ioes; - size_t totlen; - int i; + TAILQ_INIT(&trans.elms); + trans.count = 0; + for (int i = 0; i < io->size; i++) { + struct pfioc_trans_e ie; - if (io->esize != sizeof(*ioe)) { - error = ENODEV; - goto fail; - } - if (io->size < 0 || - io->size > pf_ioctl_maxcount || - WOULD_OVERFLOW(io->size, sizeof(struct pfioc_trans_e))) { - error = EINVAL; - goto fail; - } - totlen = sizeof(struct pfioc_trans_e) * io->size; - ioes = mallocarray(io->size, sizeof(struct pfioc_trans_e), - M_PF, M_WAITOK); - error = copyin(io->array, ioes, totlen); - if (error) { - free(ioes, M_PF); - goto fail; - } - PF_RULES_WLOCK(); - for (i = 0, ioe = ioes; i < io->size; i++, ioe++) { - ioe->anchor[sizeof(ioe->anchor) - 1] = '\0'; - switch (ioe->rs_num) { - case PF_RULESET_ETH: - if ((error = pf_rollback_eth(ioe->ticket, - ioe->anchor))) { - PF_RULES_WUNLOCK(); - free(ioes, M_PF); - goto fail; /* really bad */ - } - break; -#ifdef ALTQ - case PF_RULESET_ALTQ: - if (ioe->anchor[0]) { - PF_RULES_WUNLOCK(); - free(ioes, M_PF); - error = EINVAL; - goto fail; - } - if ((error = pf_rollback_altq(ioe->ticket))) { - PF_RULES_WUNLOCK(); - free(ioes, M_PF); - goto fail; /* really bad */ - } - break; -#endif /* ALTQ */ - case PF_RULESET_TABLE: - { - struct pfr_table table; - - bzero(&table, sizeof(table)); - strlcpy(table.pfrt_anchor, ioe->anchor, - sizeof(table.pfrt_anchor)); - if ((error = pfr_ina_rollback(&table, - ioe->ticket, NULL, 0))) { - PF_RULES_WUNLOCK(); - free(ioes, M_PF); - goto fail; /* really bad */ - } - break; - } - default: - if ((error = pf_rollback_rules(ioe->ticket, - ioe->rs_num, ioe->anchor))) { - PF_RULES_WUNLOCK(); - free(ioes, M_PF); - goto fail; /* really bad */ - } - break; + error = copyin(&io->array[i], &ie, sizeof(ie)); + if (error != 0) { + pf_trans_free(&trans); + goto fail; } - } - PF_RULES_WUNLOCK(); - free(ioes, M_PF); - break; - } - case DIOCXCOMMIT: { - struct pfioc_trans *io = (struct pfioc_trans *)addr; - struct pfioc_trans_e *ioe, *ioes; - struct pf_kruleset *rs; - struct pf_keth_ruleset *ers; - size_t totlen; - int i; + e = malloc(sizeof(*e), M_PF, M_WAITOK); - if (io->esize != sizeof(*ioe)) { - error = ENODEV; - goto fail; - } + e->rs_num = ie.rs_num; + strlcpy(e->anchor, ie.anchor, sizeof(e->anchor)); + e->ticket = ie.ticket; - if (io->size < 0 || - io->size > pf_ioctl_maxcount || - WOULD_OVERFLOW(io->size, sizeof(struct pfioc_trans_e))) { - error = EINVAL; - goto fail; + TAILQ_INSERT_TAIL(&trans.elms, e, entry); } - totlen = sizeof(struct pfioc_trans_e) * io->size; - ioes = mallocarray(io->size, sizeof(struct pfioc_trans_e), - M_PF, M_WAITOK); - error = copyin(io->array, ioes, totlen); - if (error) { - free(ioes, M_PF); - goto fail; - } - PF_RULES_WLOCK(); - /* First makes sure everything will succeed. */ - for (i = 0, ioe = ioes; i < io->size; i++, ioe++) { - ioe->anchor[sizeof(ioe->anchor) - 1] = '\0'; - switch (ioe->rs_num) { - case PF_RULESET_ETH: - ers = pf_find_keth_ruleset(ioe->anchor); - if (ers == NULL || ioe->ticket == 0 || - ioe->ticket != ers->inactive.ticket) { - PF_RULES_WUNLOCK(); - free(ioes, M_PF); - error = EINVAL; - goto fail; - } - break; -#ifdef ALTQ - case PF_RULESET_ALTQ: - if (ioe->anchor[0]) { - PF_RULES_WUNLOCK(); - free(ioes, M_PF); - error = EINVAL; - goto fail; - } - if (!V_altqs_inactive_open || ioe->ticket != - V_ticket_altqs_inactive) { - PF_RULES_WUNLOCK(); - free(ioes, M_PF); - error = EBUSY; - goto fail; - } - break; -#endif /* ALTQ */ - case PF_RULESET_TABLE: - rs = pf_find_kruleset(ioe->anchor); - if (rs == NULL || !rs->topen || ioe->ticket != - rs->tticket) { - PF_RULES_WUNLOCK(); - free(ioes, M_PF); - error = EBUSY; - goto fail; - } - break; - default: - if (ioe->rs_num < 0 || ioe->rs_num >= - PF_RULESET_MAX) { - PF_RULES_WUNLOCK(); - free(ioes, M_PF); - error = EINVAL; - goto fail; - } - rs = pf_find_kruleset(ioe->anchor); - if (rs == NULL || - !rs->rules[ioe->rs_num].inactive.open || - rs->rules[ioe->rs_num].inactive.ticket != - ioe->ticket) { - PF_RULES_WUNLOCK(); - free(ioes, M_PF); - error = EBUSY; - goto fail; - } - break; - } + switch (cmd) { + case DIOCXBEGIN: + error = pf_begin(&trans); + break; + case DIOCXROLLBACK: + error = pf_rollback(&trans); + break; + case DIOCXCOMMIT: + error = pf_commit(&trans); + break; } - /* Now do the commit - no errors should happen here. */ - for (i = 0, ioe = ioes; i < io->size; i++, ioe++) { - switch (ioe->rs_num) { - case PF_RULESET_ETH: - if ((error = pf_commit_eth(ioe->ticket, ioe->anchor))) { - PF_RULES_WUNLOCK(); - free(ioes, M_PF); - goto fail; /* really bad */ - } - break; -#ifdef ALTQ - case PF_RULESET_ALTQ: - if ((error = pf_commit_altq(ioe->ticket))) { - PF_RULES_WUNLOCK(); - free(ioes, M_PF); - goto fail; /* really bad */ - } - break; -#endif /* ALTQ */ - case PF_RULESET_TABLE: - { - struct pfr_table table; - - bzero(&table, sizeof(table)); - (void)strlcpy(table.pfrt_anchor, ioe->anchor, - sizeof(table.pfrt_anchor)); - if ((error = pfr_ina_commit(&table, - ioe->ticket, NULL, NULL, 0))) { - PF_RULES_WUNLOCK(); - free(ioes, M_PF); - goto fail; /* really bad */ - } - break; - } - default: - if ((error = pf_commit_rules(ioe->ticket, - ioe->rs_num, ioe->anchor))) { - PF_RULES_WUNLOCK(); - free(ioes, M_PF); - goto fail; /* really bad */ - } - break; - } + + i = 0; + TAILQ_FOREACH(e, &trans.elms, entry) { + error = copyout(&e->ticket, &io->array[i].ticket, sizeof(e->ticket)); + i++; } - PF_RULES_WUNLOCK(); - /* Only hook into EtherNet taffic if we've got rules for it. */ - if (! TAILQ_EMPTY(V_pf_keth->active.rules)) - hook_pf_eth(); - else - dehook_pf_eth(); + pf_trans_free(&trans); - free(ioes, M_PF); break; }