From nobody Wed Oct 06 08:47:29 2021 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 1E9AB17E716C; Wed, 6 Oct 2021 08:47:31 +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 4HPSkn6wGwz4VxY; Wed, 6 Oct 2021 08:47:29 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 3818E1CC57; Wed, 6 Oct 2021 08:47:29 +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 1968lT5P060780; Wed, 6 Oct 2021 08:47:29 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1968lT2w060779; Wed, 6 Oct 2021 08:47:29 GMT (envelope-from git) Date: Wed, 6 Oct 2021 08:47:29 GMT Message-Id: <202110060847.1968lT2w060779@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: 8a443f829e10 - stable/12 - pf: hook up adaptive mode configuration 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/12 X-Git-Reftype: branch X-Git-Commit: 8a443f829e10c7094c4180aceca18aa3f7ca9bde Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/12 has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=8a443f829e10c7094c4180aceca18aa3f7ca9bde commit 8a443f829e10c7094c4180aceca18aa3f7ca9bde Author: Kristof Provost AuthorDate: 2021-07-24 12:23:59 +0000 Commit: Kristof Provost CommitDate: 2021-10-06 08:46:58 +0000 pf: hook up adaptive mode configuration The kernel side of pf syncookie adaptive mode configuration. MFC after: 1 week Sponsored by: Modirum MDPay Differential Revision: https://reviews.freebsd.org/D32135 (cherry picked from commit 955460d41e99031906841870e02063ffdf227f09) --- sys/netpfil/pf/pf_syncookies.c | 56 ++++++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 21 deletions(-) diff --git a/sys/netpfil/pf/pf_syncookies.c b/sys/netpfil/pf/pf_syncookies.c index d054b6823e74..8fdc96e31e98 100644 --- a/sys/netpfil/pf/pf_syncookies.c +++ b/sys/netpfil/pf/pf_syncookies.c @@ -85,6 +85,7 @@ #include #include +#include #define DPFPRINTF(n, x) if (V_pf_status.debug >= (n)) printf x @@ -147,7 +148,10 @@ pf_get_syncookies(struct pfioc_nv *nv) nvlist_add_bool(nvl, "enabled", V_pf_status.syncookies_mode != PF_SYNCOOKIES_NEVER); - nvlist_add_bool(nvl, "adaptive", false); + nvlist_add_bool(nvl, "adaptive", + V_pf_status.syncookies_mode == PF_SYNCOOKIES_ADAPTIVE); + nvlist_add_number(nvl, "highwater", V_pf_syncookie_status.hiwat); + nvlist_add_number(nvl, "lowwater", V_pf_syncookie_status.lowat); nvlpacked = nvlist_pack(nvl, &nv->len); if (nvlpacked == NULL) { @@ -174,6 +178,10 @@ pf_set_syncookies(struct pfioc_nv *nv) void *nvlpacked = NULL; int error; bool enabled, adaptive; + uint32_t hiwat, lowat; + uint8_t newmode; + +#define ERROUT(x) ERROUT_FUNCTION(errout, x) if (nv->len > pf_ioctl_maxcount) return (ENOMEM); @@ -183,38 +191,44 @@ pf_set_syncookies(struct pfioc_nv *nv) return (ENOMEM); error = copyin(nv->data, nvlpacked, nv->len); - if (error) { - free(nvlpacked, M_TEMP); - return (error); - } + if (error) + ERROUT(error); nvl = nvlist_unpack(nvlpacked, nv->len, 0); - if (nvl == NULL) { - free(nvlpacked, M_TEMP); - return (EBADMSG); - } + if (nvl == NULL) + ERROUT(EBADMSG); if (! nvlist_exists_bool(nvl, "enabled") - || ! nvlist_exists_bool(nvl, "adaptive")) { - nvlist_destroy(nvl); - free(nvlpacked, M_TEMP); - return (EBADMSG); - } + || ! nvlist_exists_bool(nvl, "adaptive")) + ERROUT(EBADMSG); enabled = nvlist_get_bool(nvl, "enabled"); adaptive = nvlist_get_bool(nvl, "adaptive"); + PFNV_CHK(pf_nvuint32_opt(nvl, "highwater", &hiwat, + V_pf_syncookie_status.hiwat)); + PFNV_CHK(pf_nvuint32_opt(nvl, "lowwater", &lowat, + V_pf_syncookie_status.lowat)); - if (adaptive) { - nvlist_destroy(nvl); - free(nvlpacked, M_TEMP); - return (ENOTSUP); - } + if (lowat >= hiwat) + ERROUT(EINVAL); + + newmode = PF_SYNCOOKIES_NEVER; + if (enabled) + newmode = adaptive ? PF_SYNCOOKIES_ADAPTIVE : PF_SYNCOOKIES_ALWAYS; PF_RULES_WLOCK(); - error = pf_syncookies_setmode(enabled ? - PF_SYNCOOKIES_ALWAYS : PF_SYNCOOKIES_NEVER); + error = pf_syncookies_setmode(newmode); + + V_pf_syncookie_status.lowat = lowat; + V_pf_syncookie_status.hiwat = hiwat; + PF_RULES_WUNLOCK(); +#undef ERROUT +errout: + nvlist_destroy(nvl); + free(nvlpacked, M_TEMP); + return (error); }