From nobody Sun Sep 29 19:25:41 2024 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 4XGvLY4R99z5X5kY; Sun, 29 Sep 2024 19:25:41 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XGvLY3rrGz4LB6; Sun, 29 Sep 2024 19:25:41 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1727637941; 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=dbC+Xs9Z8V46ygccKzZX3Q0+hJ7VkaS7uTqxCfE2ECY=; b=xnpD5Qg4d4qmxxjmgnOObI91UpSTIr8BnCu/HBAqbcIjkqUNcTzgQ3GKxO5Y2kEC8A7sKw A9b5dJ2aSXcSOvTZLOqeiFqyit6iY3QHPFopPYiInkSB3eiaK6cjfmzgFkuj7fKU2WFXQw gjX/FlxXdh/QOyApNZgqYN7XS4y3Q+sQtwi+d1P3nIqim+hKHSc1ZHJZO9atjlv9p50/zn gW4Q+KORobRdYodKWmpQf8ew9Hy9o0GfKPq3gzFo9kgDu6f5zA4B6GpqCJN/5UyKtZKon0 FHyB9V3awWkdQ/fk2trIUnsqaHweukvXDNuZexvpZQcXGYZFODDlzp5ritGF9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1727637941; 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=dbC+Xs9Z8V46ygccKzZX3Q0+hJ7VkaS7uTqxCfE2ECY=; b=iSCu4DK8IrCPBp1Ek+j8as77Euz9+PORKvOlxFAqqHUXE5+Gh7gWStcXRLD0675S5zhfDB FOrKtr9lFEJQuFx+g8eYqAORUi222KzHDPDu1d6kRFV0I7Nm9QA914cI0lXO3wccBaj3A5 LDN39a3lmYqH+FJA+0FE+lhmZOQQ1o8qYUIknsHqazGAWKXc5gmKseN6zXqoPBSZwTTnTx NgxD/P8+I1/joZw51cjgrL21ZlRTPPGFjyUN3XbTP3/Vx0+U3r8Lt4XBIyRneE/T7CZZQM i8HZgPzBfbKEmzh5N9upam0g9DLTWMRWNeeCKGYETXmjAN2vfBDTLKpNGX5sEw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1727637941; a=rsa-sha256; cv=none; b=Qw5s3dJFFyP5Mv6naa3NdZv0sEbxJf/YjN/Xsb/0I8ypx55TpGE0XBN96FcCh/GCXMdrUx B2sND+U2tHsNFueKpWybBCPbd9dUd4G6IpVBnBUT78hPbDSPqKA9Uu6sHMIr1JqiVVVobu lzVv1TmniGE4TPZxsaXATAjrdIlwJ1viEdXtiMUZkPkjVlTZEyEkdYO2Wfwh+OlgFFsLVU Vi515w+N/1A84sueLBMAHAPyhVGv7YzEVJiFRGuC/3y6BRZoWnOGlwg5DtNZZhX/HnJr0U Ugy7YO9qsg+QjiT71deABNWfeFdQW0yETrxMnSPVuSgJHpU2ptgwFdzdvJXepA== 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 4XGvLY3SFSzMHD; Sun, 29 Sep 2024 19:25:41 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 48TJPfBp037956; Sun, 29 Sep 2024 19:25:41 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 48TJPfWG037953; Sun, 29 Sep 2024 19:25:41 GMT (envelope-from git) Date: Sun, 29 Sep 2024 19:25:41 GMT Message-Id: <202409291925.48TJPfWG037953@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: e3a9f4123f76 - stable/14 - libpfctl: ensure we return useful error codes 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: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-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/14 X-Git-Reftype: branch X-Git-Commit: e3a9f4123f76205d0b85715f3f60aa1d9dc02887 Auto-Submitted: auto-generated The branch stable/14 has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=e3a9f4123f76205d0b85715f3f60aa1d9dc02887 commit e3a9f4123f76205d0b85715f3f60aa1d9dc02887 Author: Kristof Provost AuthorDate: 2024-09-20 09:36:22 +0000 Commit: Kristof Provost CommitDate: 2024-09-29 18:29:50 +0000 libpfctl: ensure we return useful error codes Return errno rather than -1 on error. This allows pfctl to report much more useful errors. Reported by: Alexander Leidinger MFC after: 1 week (cherry picked from commit 93e96359c980ccf318fe089b30b863f7c910b622) --- lib/libpfctl/libpfctl.c | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/lib/libpfctl/libpfctl.c b/lib/libpfctl/libpfctl.c index 7dc375717acc..d2e23ea2496e 100644 --- a/lib/libpfctl/libpfctl.c +++ b/lib/libpfctl/libpfctl.c @@ -1337,8 +1337,12 @@ pfctl_clear_rules(int dev, const char *anchorname) ret = ioctl(dev, DIOCXBEGIN, &trans); if (ret != 0) - return (ret); - return ioctl(dev, DIOCXCOMMIT, &trans); + return (errno); + ret = ioctl(dev, DIOCXCOMMIT, &trans); + if (ret != 0) + return (errno); + + return (0); } int @@ -1372,9 +1376,14 @@ pfctl_clear_nat(int dev, const char *anchorname) ret = ioctl(dev, DIOCXBEGIN, &trans); if (ret != 0) - return (ret); - return ioctl(dev, DIOCXCOMMIT, &trans); + return (errno); + ret = ioctl(dev, DIOCXCOMMIT, &trans); + if (ret != 0) + return (errno); + + return (0); } + int pfctl_clear_eth_rules(int dev, const char *anchorname) { @@ -1396,8 +1405,12 @@ pfctl_clear_eth_rules(int dev, const char *anchorname) ret = ioctl(dev, DIOCXBEGIN, &trans); if (ret != 0) - return (ret); - return ioctl(dev, DIOCXCOMMIT, &trans); + return (errno); + ret = ioctl(dev, DIOCXCOMMIT, &trans); + if (ret != 0) + return (errno); + + return (0); } static int @@ -1451,7 +1464,10 @@ pfctl_set_syncookies(int dev, const struct pfctl_syncookies *s) ret = ioctl(dev, DIOCSETSYNCOOKIES, &nv); free(nv.data); - return (ret); + if (ret != 0) + return (errno); + + return (0); } int @@ -1559,7 +1575,7 @@ pfctl_table_set_addrs(int dev, struct pfr_table *tbl, struct pfr_addr io.pfrio_size = size; io.pfrio_size2 = (size2 != NULL) ? *size2 : 0; if (ioctl(dev, DIOCRSETADDRS, &io)) - return (-1); + return (errno); if (nadd != NULL) *nadd = io.pfrio_nadd; if (ndel != NULL) @@ -1587,7 +1603,7 @@ int pfctl_table_get_addrs(int dev, struct pfr_table *tbl, struct pfr_addr *addr, io.pfrio_esize = sizeof(*addr); io.pfrio_size = *size; if (ioctl(dev, DIOCRGETADDRS, &io)) - return (-1); + return (errno); *size = io.pfrio_size; return (0); }