From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=NjrP4upp; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTPS id 9CF2C5A0652 for ; Tue, 25 Aug 2026 17:35:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1787672121; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:autocrypt:autocrypt; bh=Dez9oQQsvXjQCinmWZQR3eQjEeEYqReDFmz+7eBv48I=; b=NjrP4uppKae3ho2DGTiJd6pJ1kGOK23DGHWWKh+Y4UlEmshqeEXJvuuDd6d+po4VYWG7EX isnKFOe+dL2dSjzuRy3QvZDDt5Bv7Szuo0n3ilr8BB3q7Ityjc4TAg43+4MUuKQVfhoE6Y aeyjTBdEwj1rAeuy/r8iKmqC4qGq3Ww= Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-78-587k424QNNC7e9v-1x1oSw-1; Tue, 25 Aug 2026 11:35:20 -0400 X-MC-Unique: 587k424QNNC7e9v-1x1oSw-1 X-Mimecast-MFC-AGG-ID: 587k424QNNC7e9v-1x1oSw_1787672119 Received: by mail-ej1-f69.google.com with SMTP id a640c23a62f3a-c20262b5e10so579918566b.1 for ; Tue, 25 Aug 2026 08:35:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787672119; x=1788276919; h=content-transfer-encoding:content-type:in-reply-to:autocrypt:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Dez9oQQsvXjQCinmWZQR3eQjEeEYqReDFmz+7eBv48I=; b=SNVklz6PKZ5uOH6Z+zytA5LXF6XtjykDN4+EvDCpiLQ83JHeR1aqKm7zHP/RXpZiZS wx4RfcYLoillhT0z9cAbbNzT5iToopO+CcQIAsrQKxtVjXAYhwIsOtgNk/PYpn+I0al8 F6XMW6KumSVhlNXo3dEQX0zlSRJw8FNNGEoqC/RGJyNpporhKM2/3RmX2+rrG+3SAV99 XTDfgdlBgOYkRMpHfBO2WGStqC0Z5oFAyJ3pn/bdjtrvJso7uMiDs2nIpm77yfY4SYN2 Hy5GBGOtSCZZOKslon9rPQLbeeeSs8p5slE2aPDehUCDFr6c6huCcTZ+vgrdnOeFiQUj iUdA== X-Forwarded-Encrypted: i=1; AHgh+RqePNtUGd9pDnBEOQt486fx1+9wBKQByT29RU4cK0XvMlmvq7MXcaUMqBhtPj41OAX/ZTYv+2VFzEE=@passt.top X-Gm-Message-State: AFuF++mlJmLPFSgtCTpS6DiHMZldqJGPPMPqNTkgKrSgJhConB+rN9CE Y5yrNG9JhWPQSXHD76b8AWRegwEcuOVRot/Ran4Bvi4/ngKN8RwnJDZQLgL1FxPQbLygKoQ6BFi MCYsfd4KNA+c+Ws13FLAjmgjOO3z+ihY21Ebuve2E0RY99/h53UkKX004EEPXEQ== X-Gm-Gg: AR+sD13KugrUGwCrtMgYnO5d8nhThVeB2UnaSy6zv+gBYh/5QTtzgO6N3jcolPvqBoo XhBDm4OylvkG85rEA7gsjF1QWlE6+aeYJqFTCCiNtwg4Ww64I7M5seNrvtQNFmZZ/XWUYjfqInj a6WWOkVvI6n+a4RgaPtOIUG+1ocC3LIjfH9wOarS7VMDm7hWK8gzsOcBRVJgYeyn8Mux6R0fv1g N0dfcQjXKTp5knboL9O7Nj/ylYC/nXbEd7J96IUwZBJyk2Ed5vTQTB2AhzOnKhSLmEo3wfF1T1U wZpQ8qIwe8K/ua5zSAne+K2CS0lFBLlCKT3KWpXr/eL6J5jPqLf2O869Dd/kwDTYL6Ti6CZgygr 03C+PEZA5dfoDti45e+MeMyj/jdsJbIMDO/iDYJC3Wzy0 X-Received: by 2002:a17:906:f246:b0:c21:61a6:8821 with SMTP id a640c23a62f3a-c246a6cd384mr3300475766b.23.1787672118680; Tue, 25 Aug 2026 08:35:18 -0700 (PDT) X-Received: by 2002:a17:906:f246:b0:c21:61a6:8821 with SMTP id a640c23a62f3a-c246a6cd384mr3300470366b.23.1787672118228; Tue, 25 Aug 2026 08:35:18 -0700 (PDT) Received: from ?IPV6:2a01:e0a:e10:ef90:d92c:7e4a:47e6:1b23? ([2a01:e0a:e10:ef90:d92c:7e4a:47e6:1b23]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c250a9ef996sm5845666b.62.2026.08.25.08.35.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 25 Aug 2026 08:35:17 -0700 (PDT) Message-ID: <45429e2d-119a-4f68-bc58-538dd6b06cdd@redhat.com> Date: Tue, 25 Aug 2026 17:35:16 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v6 2/6] dhcp: Add option state management with enum opt_state To: Anshu Kumari , sbrivio@redhat.com, passt-dev@passt.top References: <20260824134436.282300-1-anskuma@redhat.com> <20260824134436.282300-3-anskuma@redhat.com> From: Laurent Vivier Autocrypt: addr=lvivier@redhat.com; keydata= xsFNBFYFJhkBEAC2me7w2+RizYOKZM+vZCx69GTewOwqzHrrHSG07MUAxJ6AY29/+HYf6EY2 WoeuLWDmXE7A3oJoIsRecD6BXHTb0OYS20lS608anr3B0xn5g0BX7es9Mw+hV/pL+63EOCVm SUVTEQwbGQN62guOKnJJJfphbbv82glIC/Ei4Ky8BwZkUuXd7d5NFJKC9/GDrbWd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9TTEChq AcNg88eYryKsYpFwegGpwUlaUaaGh1m9OrTzcQy+klVfZWaVJ9Nw0keoGRGb8j4XjVpL8+2x OhXKrM1fzzb8JtAuSbuzZSQPDwQEI5CKKxp7zf76J21YeRrEW4WDznPyVcDTa+tz++q2S/Bp P4W98bXCBIuQgs2m+OflERv5c3Ojldp04/S4NEjXEYRWdiCxN7ca5iPml5gLtuvhJMSy36gl U6IW9kn30IWuSoBpTkgV7rLUEhh9Ms82VWW/h2TxL8enfx40PrfbDtWwqRID3WY8jLrjKfTd R3LW8BnUDNkG+c4FzvvGUs8AvuqxxyHbXAfDx9o/jXfPHVRmJVhSmd+hC3mcQ+4iX5bBPBPM oDqSoLt5w9GoQQ6gDVP2ZjTWqwSRMLzNr37rJjZ1pt0DCMMTbiYIUcrhX8eveCJtY7NGWNyx FCRkhxRuGcpwPmRVDwOl39MB3iTsRighiMnijkbLXiKoJ5CDVvX5yicNqYJPKh5MFXN1bvsB kmYiStMRbrD0HoY1kx5/VozBtc70OU0EB8Wrv9hZD+Ofp0T3KOr1RUHvCZoLURfFhSQ= In-Reply-To: <20260824134436.282300-3-anskuma@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: ZmCoB05M728Og1Vm5akhnxvyMEVjCZrl0N5G4RcSU1s_1787672119 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Message-ID-Hash: DGLOABIRFT24ZOO6SWDO4LX2KLD3SVDV X-Message-ID-Hash: DGLOABIRFT24ZOO6SWDO4LX2KLD3SVDV X-MailFrom: lvivier@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: david@gibson.dropbear.id.au, jmaloy@redhat.com X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On 8/24/26 15:44, Anshu Kumari wrote: > Overloading slen = -1 to mean "not set" conflates the option > length with its lifecycle state, and can't express additional > states such as "set by the user via command-line" which will > be needed for --dhcp-opt support. > > Introduce enum opt_state with OPT_UNSET (option not > configured) and OPT_DEFAULT (derived from host > configuration). Replace all slen = -1 / slen != -1 checks > with state comparisons, and set state = OPT_DEFAULT for > options initialised in dhcp_init() and at reply time in > dhcp(). > > Link: https://bugs.passt.top/show_bug.cgi?id=192 > Signed-off-by: Anshu Kumari > --- > v6: > - Rewrote commit message to explain why slen = -1 overloading > is problematic and how it motivates the enum. > - Dropped explicit OPT_UNSET initialization loop inside dhcp_init(). > - Realigned opts[51] initializer for consistency. > > v5: > - New patch: introduce enum opt_state { OPT_UNSET, OPT_DEFAULT } to replace slen = -1 for tracking option state > - Replace all slen = -1 / slen != -1 checks with state = OPT_UNSET / state != OPT_UNSET > - Set OPT_DEFAULT for options initialised in dhcp_init() and at reply time > --- > dhcp.c | 58 ++++++++++++++++++++++++++++++++++++++-------------------- > 1 file changed, 38 insertions(+), 20 deletions(-) Reviewed-by: Laurent Vivier one comment below > > diff --git a/dhcp.c b/dhcp.c > index bb72b72..321968a 100644 > --- a/dhcp.c > +++ b/dhcp.c > @@ -33,13 +33,24 @@ > #include "log.h" > #include "dhcp.h" > > +/** > + * enum opt_state - DHCP option state > + * @OPT_UNSET: Option not configured > + * @OPT_DEFAULT: Option derived from host configuration > + */ > +enum opt_state { > + OPT_UNSET = 0, > + OPT_DEFAULT, > +}; > + > /** > * struct opt - DHCP option > * @sent: Convenience flag, set while filling replies > - * @slen: Length of option defined for server, -1 if not going to be sent > + * @slen: Length of option defined for server > * @s: Option payload from server > * @clen: Length of option received from client, -1 if not received > * @c: Option payload from client > + * @state: Option state (unset or default) > */ > struct opt { > int sent; > @@ -47,6 +58,7 @@ struct opt { > uint8_t s[255]; > int clen; > uint8_t c[255]; > + enum opt_state state; > }; > > static struct opt opts[256]; > @@ -73,19 +85,17 @@ static struct opt opts[256]; > */ > void dhcp_init(void) > { > - int i; > - > - for (i = 0; i < ARRAY_SIZE(opts); i++) > - opts[i].slen = -1; > - > - opts[1] = (struct opt) { 0, 4, { 0 }, 0, { 0 }, }; /* Mask */ > - opts[3] = (struct opt) { 0, 4, { 0 }, 0, { 0 }, }; /* Router */ > - opts[51] = (struct opt) { 0, 4, { 0xff, > - 0xff, > - 0xff, > - 0xff }, 0, { 0 }, }; /* Lease time */ > - opts[53] = (struct opt) { 0, 1, { 0 }, 0, { 0 }, }; /* Type */ > - opts[54] = (struct opt) { 0, 4, { 0 }, 0, { 0 }, }; /* Server ID */ > + /* Mask */ > + opts[1] = (struct opt) { 0, 4, { 0 }, 0, { 0 }, OPT_DEFAULT, }; > + /* Router */ > + opts[3] = (struct opt) { 0, 4, { 0 }, 0, { 0 }, OPT_DEFAULT, }; > + /* Lease time */ > + opts[51] = (struct opt) { 0, 4, { 0xff, 0xff, 0xff, 0xff }, > + 0, { 0 }, OPT_DEFAULT }; > + /* Type */ > + opts[53] = (struct opt) { 0, 1, { 0 }, 0, { 0 }, OPT_DEFAULT, }; > + /* Server ID */ > + opts[54] = (struct opt) { 0, 4, { 0 }, 0, { 0 }, OPT_DEFAULT, }; unneeded comma after OPT_DEFAULT > } > > /** > @@ -183,13 +193,13 @@ static int fill(struct msg *m) > > for (i = 0; i < opts[55].clen; i++) { > o = opts[55].c[i]; > - if (opts[o].slen != -1) > + if (opts[o].state != OPT_UNSET) > if (fill_one(m->o, OPT_MAX, o, &offset)) > debug("DHCP: skipping option %i", o); > } > > for (o = 0; o < 255; o++) { > - if (opts[o].slen != -1 && !opts[o].sent) > + if (opts[o].state != OPT_UNSET && !opts[o].sent) > if (fill_one(m->o, OPT_MAX, o, &offset)) > debug("DHCP: skipping option %i", o); > } > @@ -243,6 +253,7 @@ static void opt_set_dns_search(const struct ctx *c, size_t max_len) > int i; > > opts[119].slen = 0; > + opts[119].state = OPT_DEFAULT; > > for (i = 0; i < 255; i++) > max_len -= opts[i].slen; > @@ -291,7 +302,7 @@ static void opt_set_dns_search(const struct ctx *c, size_t max_len) > } > > if (!opts[119].slen) > - opts[119].slen = -1; > + opts[119].state = OPT_UNSET; > } > > /** > @@ -389,7 +400,7 @@ int dhcp(const struct ctx *c, struct iov_tail *data) > iov_drop_header(data, *olen); > } > > - opts[80].slen = -1; > + opts[80].state = OPT_UNSET; > if (opts[53].clen > 0 && opts[53].c[0] == DHCPDISCOVER) { > if (opts[80].clen == -1) { > info("DHCP: offer to discover"); > @@ -398,6 +409,7 @@ int dhcp(const struct ctx *c, struct iov_tail *data) > info("DHCP: ack to discover (Rapid Commit)"); > opts[53].s[0] = DHCPACK; > opts[80].slen = 0; > + opts[80].state = OPT_DEFAULT; > } > } else if (opts[53].clen <= 0 || opts[53].c[0] == DHCPREQUEST) { > info("%s: ack to request", /* DHCP needs a valid message type */ > @@ -421,6 +433,7 @@ int dhcp(const struct ctx *c, struct iov_tail *data) > != (c->ip4.guest_gw.s_addr & mask.s_addr)) { > /* a.b.c.d/32:0.0.0.0, 0:a.b.c.d */ > opts[121].slen = 14; > + opts[121].state = OPT_DEFAULT; > opts[121].s[0] = 32; > memcpy(opts[121].s + 1, > &c->ip4.guest_gw, sizeof(c->ip4.guest_gw)); > @@ -430,6 +443,7 @@ int dhcp(const struct ctx *c, struct iov_tail *data) > > if (c->mtu) { > opts[26].slen = 2; > + opts[26].state = OPT_DEFAULT; > opts[26].s[0] = c->mtu / 256; > opts[26].s[1] = c->mtu % 256; > } > @@ -441,12 +455,15 @@ int dhcp(const struct ctx *c, struct iov_tail *data) > ((struct in_addr *)opts[6].s)[i] = c->ip4.dns[i]; > opts[6].slen += sizeof(uint32_t); > } > - if (!opts[6].slen) > - opts[6].slen = -1; > + if (opts[6].slen) > + opts[6].state = OPT_DEFAULT; > + else > + opts[6].state = OPT_UNSET; > > opt_len = strlen(c->hostname); > if (opt_len > 0) { > opts[12].slen = opt_len; > + opts[12].state = OPT_DEFAULT; > memcpy(opts[12].s, &c->hostname, opt_len); > } > > @@ -463,6 +480,7 @@ int dhcp(const struct ctx *c, struct iov_tail *data) > encode_domain_name((char *)opts[81].s + 3, c->fqdn); > > opts[81].slen = opt_len; > + opts[81].state = OPT_DEFAULT; > } else { > debug("DHCP: client FQDN option doesn't fit, skipping"); > }