From nobody Fri Oct 20 08:42:26 2023 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 4SBdPZ3jMtz4xW5b; Fri, 20 Oct 2023 08:42:26 +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 4SBdPZ392Qz4Gt4; Fri, 20 Oct 2023 08:42:26 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1697791346; 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=4w1W1bxX+1g0SKQ0LKHh9KIaCk9+GOVPzakruDIqCO0=; b=NwcudPRkwoImAt2eqYLO2/7VvnjHCjukiAq2RDDnFitm+vlxV39nTMZLlc/aFlhKSrTA8F fD8kuLQzY2zpHYVTXpjsZLXpSMlbsItOu3fT7/vMD3XcNEDF78H5qMLHvYUyRN0wCxbiaZ npFq8QDcqVLbMS+QBaURcBCP/tWMaaErvtiPY/GZtsSbDmUigMELS6rqOkPLNNjAkuVSEV gzIFHWYUK9/Qp48V8ew0KSasY/gpzv5p1t2lrI5gB0ejd/xkjsdXVb+7YMSNwtFCvGx6tv zog1JpujIo1aahp6ehODeuyD2ryrj1/IqsQqhg3qG0xbZv60mh3I7R8jL+SihA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1697791346; a=rsa-sha256; cv=none; b=TN9UjgYOVx7BVGb20e2lugqj9Cs1tRJFg9KwH2JtFZemfwQ5Ex7LJ8m6od7PudXAWAAnz4 KpwLu2kpIaNmXLWdpibhAOC7xDZdV7RmFbR+d+IYL7XNot9nyu5EcfcazbJCyRpqnyIKhz +XKryWe7E41lC+X72GF/2cHbWJHE/hVB9KLX2RoVuE8h541ANwi5A3KRI8EPnFZR+RdG6z rxdskPfFD2UVCjpiQBZAnNzXXzp6ruvJNlK+l7Kv/wdAEjccy/i9I1L45RjQ8NOhw50Ajw qKD+JSO7OnZ9jdCVFKV8JSWFaqCfOGExKxMD9QecsK0sgrBcbWUFsy9MhjLT4Q== 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=1697791346; 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=4w1W1bxX+1g0SKQ0LKHh9KIaCk9+GOVPzakruDIqCO0=; b=oP7TELW6BUkg1oULg2lj5XkaethyeWG9cjSmT08Phxe1E50hr5pA0D219G+CYXiqIyIOsu 7Mdh5/OjLjh1yX1uVcaPOQxI0Z+D6JRIMjWD0Dmliq25DjinDOALt0OoCsGpRA0DGwS43o xDMamhIFex7dJ5DUsQf5bdAlxIFO3VSFBZA1WbDBjujZXv6NanB9V0nDw3ffo2+eblZ9sY AJyIun1LtOqMvfMWTInbBE3ONrc2VrnypFEB70T9yAhgKtDJohNuByV6G79Dbt/Qqr7XzS wgd6UbSDSjKhC2lT3L5o+X92zUOUJ1gmKTu+7B9FSiV6xr/oFc4zIMLJwJWQzA== 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 4SBdPZ1x88zBTP; Fri, 20 Oct 2023 08:42:26 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 39K8gQTL005802; Fri, 20 Oct 2023 08:42:26 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 39K8gQfS005799; Fri, 20 Oct 2023 08:42:26 GMT (envelope-from git) Date: Fri, 20 Oct 2023 08:42:26 GMT Message-Id: <202310200842.39K8gQfS005799@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: c1146e6ad67f - main - pf: use an enum for packet direction in divert tag 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: 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: c1146e6ad67fb866c2472a1cbe5609fd939fd5ef Auto-Submitted: auto-generated The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=c1146e6ad67fb866c2472a1cbe5609fd939fd5ef commit c1146e6ad67fb866c2472a1cbe5609fd939fd5ef Author: Kristof Provost AuthorDate: 2023-10-20 07:13:56 +0000 Commit: Kristof Provost CommitDate: 2023-10-20 07:16:08 +0000 pf: use an enum for packet direction in divert tag The benefit is that in the debugger you will see PF_DIVERT_MTAG_DIR_IN instead of 1 when looking at a structure. And compilation time failure if anybody sets it to a wrong value. Using "port" instead of "ndir" when assigning a port improves readability of code. Suggested by: glebius MFC after: 3 weeks X-MFC-With: fabf705f4b --- sys/netinet/ip_divert.c | 2 +- sys/netinet/ip_var.h | 14 ++++++++++---- sys/netpfil/pf/pf.c | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/sys/netinet/ip_divert.c b/sys/netinet/ip_divert.c index ad95a1ce0d76..78ca36fc2a0f 100644 --- a/sys/netinet/ip_divert.c +++ b/sys/netinet/ip_divert.c @@ -182,7 +182,7 @@ divert_packet(struct mbuf *m, bool incoming) (((struct ipfw_rule_ref *)(mtag+1))->info)); } else if ((mtag = m_tag_locate(m, MTAG_PF_DIVERT, 0, NULL)) != NULL) { cookie = ((struct pf_divert_mtag *)(mtag+1))->idir; - nport = htons(((struct pf_divert_mtag *)(mtag+1))->ndir); + nport = htons(((struct pf_divert_mtag *)(mtag+1))->port); } else { m_freem(m); return; diff --git a/sys/netinet/ip_var.h b/sys/netinet/ip_var.h index a8c687682af9..a8a9adc1d4c6 100644 --- a/sys/netinet/ip_var.h +++ b/sys/netinet/ip_var.h @@ -328,11 +328,17 @@ extern int (*ip_dn_ctl_ptr)(struct sockopt *); extern int (*ip_dn_io_ptr)(struct mbuf **, struct ip_fw_args *); /* pf specific mtag for divert(4) support */ -enum { PF_DIVERT_MTAG_DIR_IN=1, PF_DIVERT_MTAG_DIR_OUT=2 }; +__enum_uint8_decl(pf_mtag_dir) { + PF_DIVERT_MTAG_DIR_IN = 1, + PF_DIVERT_MTAG_DIR_OUT = 2 +}; struct pf_divert_mtag { - uint16_t idir; // initial pkt direction - uint16_t ndir; // a) divert(4) port upon initial diversion - // b) new direction upon pkt re-enter + __enum_uint8(pf_mtag_dir) idir; // initial pkt direction + union { + __enum_uint8(pf_mtag_dir) ndir; // a) divert(4) port upon initial diversion + // b) new direction upon pkt re-enter + uint16_t port; /* Initial divert(4) port */ + }; }; #define MTAG_PF_DIVERT 1262273569 diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c index a6c7ee359416..1cd8412193dc 100644 --- a/sys/netpfil/pf/pf.c +++ b/sys/netpfil/pf/pf.c @@ -8022,7 +8022,7 @@ done: mtag = m_tag_alloc(MTAG_PF_DIVERT, 0, sizeof(struct pf_divert_mtag), M_NOWAIT | M_ZERO); if (mtag != NULL) { - ((struct pf_divert_mtag *)(mtag+1))->ndir = + ((struct pf_divert_mtag *)(mtag+1))->port = ntohs(r->divert.port); ((struct pf_divert_mtag *)(mtag+1))->idir = (dir == PF_IN) ? PF_DIVERT_MTAG_DIR_IN :