Date: Thu, 19 Oct 2023 17:19:27 +0100 From: Jessica Clarke <jrtc27@freebsd.org> To: Gleb Smirnoff <glebius@freebsd.org> Cc: Kristof Provost <kp@freebsd.org>, Igor Ostapenko <pm@igoro.pro>, src-committers <src-committers@freebsd.org>, dev-commits-src-all@freebsd.org, dev-commits-src-main@freebsd.org Subject: Re: git: fabf705f4b5a - main - pf: fix pf divert-to loop Message-ID: <6BB48213-2480-40B5-8698-058B4ED71304@freebsd.org> In-Reply-To: <ZTFV74-C4amIm0ru@FreeBSD.org> References: <202310191237.39JCbdXp094554@gitrepo.freebsd.org> <ZTFV74-C4amIm0ru@FreeBSD.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On 19 Oct 2023, at 17:14, Gleb Smirnoff <glebius@freebsd.org> wrote: >=20 > On Thu, Oct 19, 2023 at 12:37:39PM +0000, Kristof Provost wrote: > K> +++ b/sys/netinet/ip_var.h > ... > K> +/* pf specific mtag for divert(4) support */ > K> +enum { PF_DIVERT_MTAG_DIR_IN=3D1, PF_DIVERT_MTAG_DIR_OUT=3D2 }; > K> +struct pf_divert_mtag { > K> + uint16_t idir; // initial pkt direction > K> + uint16_t ndir; // a) divert(4) port upon initial diversion > K> + // b) new direction upon pkt re-enter > K> +}; >=20 > This can be written as: >=20 > typedef enum { > PF_DIVERT_MTAG_DIR_IN =3D 1, > PF_DIVERT_MTAG_DIR_OUT =3D 2, > } pf_mtag_dir; You don=E2=80=99t need the typedef, whether you use it or not is a = matter of taste. > struct pf_divert_mtag { > pf_mtag_dir idir; /* Initial packet direction. */ > union { > pf_mtag_dir ndir; /* New direction after re-enter. = */ > uint16_t port; /* Initial divert(4) port. */ > }; > }; >=20 > 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. >=20 > This will grow structure from 4 bytes to 8, as enum is always an int. = However, > uma allocator backing m_tag_alloc() will allocate same amount of = memory. We have __enum_uint8(_decl) these days, one could easily add a 16-bit = variant. Jess
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?6BB48213-2480-40B5-8698-058B4ED71304>