From nobody Thu Nov 09 14:39:21 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 4SR4N93kGKz4yvl2; Thu, 9 Nov 2023 14:39:21 +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 4SR4N937wXz3Q5K; Thu, 9 Nov 2023 14:39:21 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1699540761; 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=5cHDtvtmoAGfoseK8SJFja+8z9MbQp5NzH6UmvMMmnI=; b=VGLVUinTCAMSKCTazX9gWrubQPCYwYMXxADvhYg7RXl7zZL9Ufzl67naMmWI0/JCrYyIoU 2FG3hHowZSRT05np5T4u/3suw0BVQc2U7faRgUuE3dMrkPyCX1yiekhQWFnO6En2JVEyMQ Qrm72JF+RcG/UMQYpUuJwInimmf1zYeu+YeHrxtAjWfwWoCOnMWKgHTqFwEEbc8EfQEf5W qz5PiGiSSUtReJU4tI+4/q24rkqGuX1R9zg8KL6OL7wihXMQHpm4TZHeihh15AeRunsSv7 okWGLrvCuiL7GSjtoChPA5H8DwgeV3S5Hgc9M1e4/6IyWdryKp6/TN1g45kK9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1699540761; 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=5cHDtvtmoAGfoseK8SJFja+8z9MbQp5NzH6UmvMMmnI=; b=WAA5ENbxruJ+MCN7W8JaOSi/Xc6Le5vm/9tOSmIvanrN8t15QlJXi+g79ZDK2vD3E2LaoR ToRNnSf2e5HY4KRLrXLQ7rjuGdoviy1oB672Bi/UOisGuVBXUTa0NNHbGKlQZM6KQoGmLH t/KLe3kDC3d4wjCg9FKvMdGuJ1Rnr+kvotT9aFCVpNu4jkp4xo4IYTFH8qNrjPXtW39fR8 V9E0UX82/KCP11N33DVPBp3fyS6iGbldlZxa1qMoAM3+pzN3hHA3SUtyu+9Fs+Tyb5wjG8 rT9sVtYORq6bGm1lCb7dcX3E7s98RIxp/g/nXvo/zcXHDpQpeOPLYU1LpvTHyw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1699540761; a=rsa-sha256; cv=none; b=PfT4ZxPoGlOrXicQ9wdoZ8BQpMLxys74mXytlf0TVN9zOFUEvn/Eh5RJYJxKPCyvwc4k6O EWKdn9MC7E+DZhuJCpz1E7OoY9gxKGtCDJrwAYcuG2OGEtBd0vMC1xpnZlzYB6dWRdt/K1 9LUJuKIqzXsZKmqkwR3gkYb25EUWkTJ4zqOvBQugyJ4VwoZKvoin5k6N4G+uOcQWXd0XQU S8cE9bOR3oAmttHwjPtnOs3ovXPau3hjTzEBRhgX77jLeehuXsNxEMrHRyvU8IWCVCr0Kt nAlwvixGMZt39ExRtBJ1UV1VR0oPYFsTkeehYeSdpZE1PtRl0IPH81U+ko3b3Q== 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 4SR4N91xPYz4cK; Thu, 9 Nov 2023 14:39:21 +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 3A9EdLRX064483; Thu, 9 Nov 2023 14:39:21 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3A9EdLp4064479; Thu, 9 Nov 2023 14:39:21 GMT (envelope-from git) Date: Thu, 9 Nov 2023 14:39:21 GMT Message-Id: <202311091439.3A9EdLp4064479@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: 3903a749c8bf - stable/14 - 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/stable/14 X-Git-Reftype: branch X-Git-Commit: 3903a749c8bfcb50f85711ec95eecb8ce50644d9 Auto-Submitted: auto-generated The branch stable/14 has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=3903a749c8bfcb50f85711ec95eecb8ce50644d9 commit 3903a749c8bfcb50f85711ec95eecb8ce50644d9 Author: Kristof Provost AuthorDate: 2023-10-20 07:13:56 +0000 Commit: Kristof Provost CommitDate: 2023-11-09 09:56:20 +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 (cherry picked from commit c1146e6ad67fb866c2472a1cbe5609fd939fd5ef) --- 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 eb2e09b2e6f2..4990dce653b1 100644 --- a/sys/netpfil/pf/pf.c +++ b/sys/netpfil/pf/pf.c @@ -8249,7 +8249,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 :