From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202410 header.b=bnIP31U/; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id E40C15A004C for ; Tue, 26 Nov 2024 02:16:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202410; t=1732583774; bh=aFrOWohd1JjNS6F7MFRLPQD92nXcXwgMqPhcvXL/M1w=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=bnIP31U/AFGBnlaGL1MgfiypfRu1asWwXzpPhDz7Q0kzQy6thvO995DI5d1hz3Qsl wgl6fLGTrkm2/dTR6wu0xGkcpwDbHlbK8lhXSw/SR/2CDOWI4hyQlQ7SYs0+A735OI M4Q1fIMqMLIu7F5u7nv7JerzK1su9ylkzVy2Lc+BU4Gil9t6H9wFmc3fb72B9rVpuL yAaIFAH51qa1aU2A2tJIsdXSRxTjOowOrLT2dgJa2sBsDIjSCyb99A0SU5OrGzMn17 B40B9illxBe2xEDwOPrHaVr1nzg6Gj6oHlT558B9dtyGq5aVxdjw8fjFb51NxozFfd repJugNzMtvEQ== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4Xy4Qk6tGPz4xdl; Tue, 26 Nov 2024 12:16:14 +1100 (AEDT) Date: Tue, 26 Nov 2024 12:12:03 +1100 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH v3 1/3] dhcp: Use -1 as "missing option" length instead of 0 Message-ID: References: <20241125152812.369553-1-sbrivio@redhat.com> <20241125152812.369553-2-sbrivio@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="Isr5Q9ULHINUY1h6" Content-Disposition: inline In-Reply-To: <20241125152812.369553-2-sbrivio@redhat.com> Message-ID-Hash: GTBLU3FKDA4STJGGZ67NZFZCSCFBOXZW X-Message-ID-Hash: GTBLU3FKDA4STJGGZ67NZFZCSCFBOXZW X-MailFrom: dgibson@gandalf.ozlabs.org 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: passt-dev@passt.top 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: --Isr5Q9ULHINUY1h6 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Nov 25, 2024 at 04:28:10PM +0100, Stefano Brivio wrote: > We want to add support for option 80 (Rapid Commit, RFC 4039), whose > length is 0. >=20 > Signed-off-by: Stefano Brivio Reviewed-by: David Gibson > --- > dhcp.c | 28 +++++++++++++++++++++------- > 1 file changed, 21 insertions(+), 7 deletions(-) >=20 > diff --git a/dhcp.c b/dhcp.c > index a06f143..57f69a5 100644 > --- a/dhcp.c > +++ b/dhcp.c > @@ -36,9 +36,9 @@ > /** > * struct opt - DHCP option > * @sent: Convenience flag, set while filling replies > - * @slen: Length of option defined for server > + * @slen: Length of option defined for server, -1 if not going to be sent > * @s: Option payload from server > - * @clen: Length of option received from client > + * @clen: Length of option received from client, -1 if not received > * @c: Option payload from client > */ > struct opt { > @@ -68,6 +68,11 @@ static struct opt opts[255]; > */ > void dhcp_init(void) > { > + int i; > + > + for (i =3D 0; i < ARRAY_SIZE(opts); i++) > + opts[i].slen =3D -1; > + > opts[1] =3D (struct opt) { 0, 4, { 0 }, 0, { 0 }, }; /* Mask */ > opts[3] =3D (struct opt) { 0, 4, { 0 }, 0, { 0 }, }; /* Router */ > opts[51] =3D (struct opt) { 0, 4, { 0xff, > @@ -154,17 +159,17 @@ static int fill(struct msg *m) > * option 53 at the beginning of the list. > * Put it there explicitly, unless requested via option 55. > */ > - if (!memchr(opts[55].c, 53, opts[55].clen)) > + if (opts[55].clen > 0 && !memchr(opts[55].c, 53, opts[55].clen)) > fill_one(m, 53, &offset); > =20 > for (i =3D 0; i < opts[55].clen; i++) { > o =3D opts[55].c[i]; > - if (opts[o].slen) > + if (opts[o].slen !=3D -1) > fill_one(m, o, &offset); > } > =20 > for (o =3D 0; o < 255; o++) { > - if (opts[o].slen && !opts[o].sent) > + if (opts[o].slen !=3D -1 && !opts[o].sent) > fill_one(m, o, &offset); > } > =20 > @@ -264,6 +269,9 @@ static void opt_set_dns_search(const struct ctx *c, s= ize_t max_len) > ".\xc0"); > } > } > + > + if (!opts[119].slen) > + opts[119].slen =3D -1; > } > =20 > /** > @@ -313,6 +321,9 @@ int dhcp(const struct ctx *c, const struct pool *p) > =20 > offset +=3D offsetof(struct msg, o); > =20 > + for (i =3D 0; i < ARRAY_SIZE(opts); i++) > + opts[i].clen =3D -1; > + > while (opt_off + 2 < opt_len) { > const uint8_t *olen, *val; > uint8_t *type; > @@ -334,8 +345,9 @@ int dhcp(const struct ctx *c, const struct pool *p) > if (opts[53].c[0] =3D=3D DHCPDISCOVER) { > info("DHCP: offer to discover"); > opts[53].s[0] =3D DHCPOFFER; > - } else if (opts[53].c[0] =3D=3D DHCPREQUEST || !opts[53].clen) { > - info("%s: ack to request", opts[53].clen ? "DHCP" : "BOOTP"); > + } else if (opts[53].c[0] =3D=3D DHCPREQUEST || opts[53].clen <=3D 0) { > + info("%s: ack to request", /* DHCP needs a valid message type */ > + (opts[53].clen <=3D 0) ? "DHCP" : "BOOTP"); > opts[53].s[0] =3D DHCPACK; > } else { > return -1; > @@ -374,6 +386,8 @@ int dhcp(const struct ctx *c, const struct pool *p) > ((struct in_addr *)opts[6].s)[i] =3D c->ip4.dns[i]; > opts[6].slen +=3D sizeof(uint32_t); > } > + if (!opts[6].slen) > + opts[6].slen =3D -1; > =20 > if (!c->no_dhcp_dns_search) > opt_set_dns_search(c, sizeof(m->o)); --=20 David Gibson (he or they) | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you, not the other way | around. http://www.ozlabs.org/~dgibson --Isr5Q9ULHINUY1h6 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmdFIGIACgkQzQJF27ox 2GcuUBAAlhAGP/j5seoKk5OJ+92nyK0x2ImZs+RmlhQGHGI0L+8upSMneUieSFzh Hrv+x/xRzz3UD/IgODL505yUihTP/aUm1ITd80JubMf+kW/oYF6g8t5FQSaotWbb 90tdQW4GBaFK6eLkDOp6jK4sCYbti7AxJzukp9DnYewPfFtNl76eao7PDBtODpWr gR59raZ2BFZGJ5Z6p4odzuE3h/c0U4cM2hUdd90Ch4vIMlodTVTs0dNgg80WBUmL R65o9lu9nKN9RKfKLAwsKVtq4s/1csB7f1aH+83J58amS1PdHL5QZwR24uKWQ4JY uKb2GtJUSo5vp2o+65ler+Kzi/9oz2M8sg2nLcMixl1HEUAhKFn4fBlg5AXx9l1b ZpWGZalAqqGQhmLQv29FDH5tEjEVlSwSOZUKQu864pm4AatdBD277f6Q67t/AwiW +d02mkWhACdBwdkROYnqvBj9iZWThuVhTDXf3iSsNvQU8g89BVTOs3TLRk1y+JCT jPNQEGw9583NTLYvC1nJ1YfnXf3+hhUS88oLyYyJYsdghCjoQ3zARrxMoplA9P6z Lpe+KvHWBVm19zcKuFTW8OQSwKELwbhUn9xXBsAgQL9hcWWtKtxqhNKmLqZm8VwC brIxCkfazsFsLXvxguS7QCR1BqqKRNOTNh2d0ukTRiZeLPjJZRA= =gjG6 -----END PGP SIGNATURE----- --Isr5Q9ULHINUY1h6--