From nobody Thu Oct 19 16:19:30 2023 X-Original-To: dev-commits-src-main@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 4SBCbS3x5pz4xcXX; Thu, 19 Oct 2023 16:19:32 +0000 (UTC) (envelope-from mjguzik@gmail.com) Received: from mail-oo1-xc35.google.com (mail-oo1-xc35.google.com [IPv6:2607:f8b0:4864:20::c35]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1D4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4SBCbS0Cnfz3Fly; Thu, 19 Oct 2023 16:19:32 +0000 (UTC) (envelope-from mjguzik@gmail.com) Authentication-Results: mx1.freebsd.org; none Received: by mail-oo1-xc35.google.com with SMTP id 006d021491bc7-57b9231e91dso4813101eaf.2; Thu, 19 Oct 2023 09:19:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697732371; x=1698337171; darn=freebsd.org; h=cc:to:subject:message-id:date:from:references:in-reply-to :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=LjYT0TyRQFnr+Iv2YO80LBeR9NdSzi4ViPU89rFSTto=; b=PgjREPkpsO8Ri7snEI3Iw+sFNrBu1aFPW2OA5YS1dTn0k8JSV9QbTANB0nG7QkX6Gr fcc6HXnPutVq8OgOsNuBiiHzw/PeKojkCYnPfqTUNSd1ASQ+lBi1hBnt5MQCl1RG57+f P2dKJD7ond8XC6mJE1aAedVI8Mug0kbHepCkyLDULU2d1kv/9ifozBm9j59LPm17Rw35 2mkMUApQoaGXN4e16ehM04iuwtZwWKNVviXKE9HtvjxuCPuRPdN5UmycRWBLMTue6Kry +JNo//FW301ucWJWghfb9NoOEDtZQ8v/zWjqHHfTmULQAKtBmLIKC02uX+Y6+4Igu28A ULYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697732371; x=1698337171; h=cc:to:subject:message-id:date:from:references:in-reply-to :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=LjYT0TyRQFnr+Iv2YO80LBeR9NdSzi4ViPU89rFSTto=; b=nxE/HHgJLocELqIPCG0RUEqV9xwu6Ml+OwmdXm+Wf/eiyWYWXAc6i/V+NDb7Y68+30 fCCp2CANjik1mvy+yieKBQ6015WtYs4DaGZeLWXsWPkDkyf2/PpiXbPuYBK8fCy7kg9M f5x3Shb7UivuZoDSCiBXuuFzhf5HRUf4XDUdK3ujxEwhGWtR0VXRTKG1Hxh1KIAfYyhD vNuxZ7lEol/ylGx+cY9dECX30jUinxehleGnuCHJcefAd3pMfCco+7uLxC0GJ3P3o6hV QSQaoMScoTwvW1i22IJ3SIGn2SAffycdu7W6v1V3G4LkbmUgmVZQwinKVNPrxsdw51nw zitw== X-Gm-Message-State: AOJu0Yx7OvQUceCTDhBGhlKtvfMZCZov5jTNw4QuPHGkp9G//ekKpenh Jp44iPQyM/GnulslciSix/Nadm55WhdxdulDcl7s9664 X-Google-Smtp-Source: AGHT+IEk4lfo8erQpI+QZz6cz8uZYzPktXRV2ro5klksx5nvRmUv/9/jwNL1IQlAyH1vUKVUndeeziNsdylGteuLUTE= X-Received: by 2002:a4a:a708:0:b0:571:28d5:2c71 with SMTP id g8-20020a4aa708000000b0057128d52c71mr2869841oom.2.1697732370911; Thu, 19 Oct 2023 09:19:30 -0700 (PDT) List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Received: by 2002:ac9:7b90:0:b0:4f0:1250:dd51 with HTTP; Thu, 19 Oct 2023 09:19:30 -0700 (PDT) In-Reply-To: References: <202310191237.39JCbdXp094554@gitrepo.freebsd.org> From: Mateusz Guzik Date: Thu, 19 Oct 2023 18:19:30 +0200 Message-ID: Subject: Re: git: fabf705f4b5a - main - pf: fix pf divert-to loop To: Gleb Smirnoff Cc: Kristof Provost , Igor Ostapenko , src-committers@freebsd.org, dev-commits-src-all@freebsd.org, dev-commits-src-main@freebsd.org Content-Type: text/plain; charset="UTF-8" X-Spamd-Bar: ---- X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US] X-Rspamd-Queue-Id: 4SBCbS0Cnfz3Fly On 10/19/23, Gleb Smirnoff wrote: > 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=1, PF_DIVERT_MTAG_DIR_OUT=2 }; > 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> +}; > > This can be written as: > > typedef enum { > PF_DIVERT_MTAG_DIR_IN = 1, > PF_DIVERT_MTAG_DIR_OUT = 2, > } pf_mtag_dir; > 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. */ > }; > }; > > 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. > > 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. > > Sorry for not messaing that in the phabricator. > I don't have an opinion on employing an enum, but if going that route one can shrink it by using smaller enums -- grep for __enum_uint8 for an example. -- Mateusz Guzik