From nobody Sat Sep 21 22:56:14 2024 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 4XB4PB68Yxz5XS75; Sat, 21 Sep 2024 22:56:14 +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 4XB4PB2N5jz539k; Sat, 21 Sep 2024 22:56:14 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1726959374; 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=K4euioem/t++rkWqtUlX6FvCNwh/boaJclsWQ9vDu1Q=; b=IfGYgF1kaRpMJmDVD+cwQscl5DqY7RSQ+GvogOpyjE1PcbXhidwB5fpkk+giCjN3AK67+f Ymmq2WhR+usDRB6mKm9HqUzYsicrN+oJh+DCmhnld39OdqN56K7EUJQXxyeJhngNH6czYy OLqFpErkDUFVpGCeBvejjgvdCqQ29GzXTcM9RpVwu1pJ92Ap4S+iK5WYyXhjLzrUj9ywPd 5MlOBcTA5mAUJO8yB7ccTIXwfXIAduxRKaRfdENWP87bYdFMXtRQgForDhWf4ej7NloRlr mWQypJeU13RcoSprt6qW3UOnBVBlnKCjRn/GR3O9nCtCK5oO41wQpEFVW7lcfQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1726959374; a=rsa-sha256; cv=none; b=BFFneJuxaf3P8lUnvYICvcyfnQX+B2HYYikv06Il6DEVzEcs+P+lw7FE0rlxEszlgt+Igi Ka/h+jrF+58c3UF5qVQMzLCAGZdlqXyuw9aHiLSJ4bSSTICBUJc2Gwk8mPS85CjWdrwQGz Q5v3zZ0UfwYv3jzOOw9oWx0Y7ngiDtnpZiymLwp25g2JlfENJ+u/8aROS90LQaRYgz6/7R 9CiHyD43lfjY/SOy+2I5PY6kZh5q08SqOzgeyFhIb2tshHh+9BOjFSmM+6wYVw5atSiQU2 ekFekfzoqIK+XrJH4ZEVk4+XuT00tEVWfQ7qW4dArZD7j9rs3FhOezaRB3Hm2A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1726959374; 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=K4euioem/t++rkWqtUlX6FvCNwh/boaJclsWQ9vDu1Q=; b=K5UWalrgLzDb18oMluuo6NKjYSmRrZvkeQ8KtZvN/R2ybysCeOeF+YxL0zcUFGNd17pzxJ 4JAtffIWUewdBqm4KcN/Wf61nOIkXyuXKSyfTTS91j8oRks4ad/WbertHQyWu3MvCmVs6K Q+8FpWobLdZ1mrRQoky5QfaJD6tKKcVLYrJEZSaRTYtdHd8qBPumkOiu+Y+2+vaeLaei9t 2O4vWvRUWPPo20gBKVtE36OhvyT1neslFn/2x6psbcfcOknX1PRXpXRg+kZDtK+Qk5chy2 FSAbOHxcK8t6KLHwkem76OC5MmT+gF6ximozkyJD343c3kIMFZ4XOn9tNIpeKg== 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 4XB4PB1yP1zsNb; Sat, 21 Sep 2024 22:56:14 +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 48LMuE07012201; Sat, 21 Sep 2024 22:56:14 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 48LMuE1d012198; Sat, 21 Sep 2024 22:56:14 GMT (envelope-from git) Date: Sat, 21 Sep 2024 22:56:14 GMT Message-Id: <202409212256.48LMuE1d012198@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kristof Provost Subject: git: 93e96359c980 - main - libpfctl: ensure we return useful error codes 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@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/main X-Git-Reftype: branch X-Git-Commit: 93e96359c980ccf318fe089b30b863f7c910b622 Auto-Submitted: auto-generated The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=93e96359c980ccf318fe089b30b863f7c910b622 commit 93e96359c980ccf318fe089b30b863f7c910b622 Author: Kristof Provost AuthorDate: 2024-09-20 09:36:22 +0000 Commit: Kristof Provost CommitDate: 2024-09-21 22:55:46 +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 --- 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 11984a301336..c8eeb913e912 100644 --- a/lib/libpfctl/libpfctl.c +++ b/lib/libpfctl/libpfctl.c @@ -2164,8 +2164,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 @@ -2199,9 +2203,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) { @@ -2223,8 +2232,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 @@ -2278,7 +2291,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 @@ -2386,7 +2402,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) @@ -2414,7 +2430,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); }