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=ifUtCCKE; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTPS id C4E335A0265 for ; Wed, 01 Jul 2026 09:51:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1782892295; 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; bh=eypHV+4PYQ0Vk8nYF1NHI577EuDgYDT3zzFNXFkQYJ4=; b=ifUtCCKET3MJ11ltgcLqEAfg1tfkxYyrBZzNefdg+KThygtN9O/Y9tHeJeT3F53MJUrDBm IIMMQEfv2PHsjGlaDNIiINiWDbL/zzS5yOnQY7Dh2HAYKV4OxiTdRmPOqJVcsIfvM7Cj/i 5Ru6TJ5jJhsnjqc5onkWZIa+4QyMVsA= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-325-D3sQ9uN7Opu5Vj33P9BnrQ-1; Wed, 01 Jul 2026 03:51:32 -0400 X-MC-Unique: D3sQ9uN7Opu5Vj33P9BnrQ-1 X-Mimecast-MFC-AGG-ID: D3sQ9uN7Opu5Vj33P9BnrQ_1782892291 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-46fd6d94a8dso136821f8f.2 for ; Wed, 01 Jul 2026 00:51:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782892291; x=1783497091; h=date:content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=UdN+/reUW2xWkhqau8TkhYtAlQCniG3SxI1ag+NbUT8=; b=RCy9DToWWGLTXYfvcjTKoll+oR3M6gSpJSdcSuVGqmp+Z3TiaNLfuH7Y/aEj3PuFfD ByF1Hrh8ewnMRocoO8eiuDf2KUwy2HE+bAkqWqa9aBZZRD3Yl3jAVKhp0u2EOTDfcQ0T j6ql3TRl/W73bcJ+gsVHlLau637RX2QeAl5JBMaA3/6eFRSHBr/nlS6glYTsxTiN9cmj 0zoQppNnvkmLMOI/NHwM72UAf1QncSw43mRfeZpVZGxHABIxSWtsGxINxLXOqtLCSl20 O1abbS7Mbe089e7kSX/1UKKXEDp42YM3+OgX2qaHkUQ2nMrZ8tHr3sq7h+uOVhl61nSQ ZRPg== X-Gm-Message-State: AOJu0YylDMvmFwvsPYVKtuhlzpHpP1Qq5Qe2tUJCzyUbY7Ky9e4R/5GG 31qhH7VGGr8FFgtSy6zlzIkyyzwQfgZKmDKMu3wxUhXNlQvUsULPCg2ebzeHNSPsHMx+hQgiD8k ++ZjhmjS0xGEM1WgUUsLN+HMtP1R+xk29F+fpyStCTI4knK48++2AfQ== X-Gm-Gg: AfdE7cm0ELpB8SWERk1vnq7SxLnG6JG8G6M82wwIPXSCWQUcXYmvNCY1/Nt1Q5txe4S aL3e/t5ExVm8SvQhEvvDAas/cghhxQZw/FOGJeccLhvAYOqoMT4oo/V9eUFqHUXeszBh0FfytcE S7OoFug4PREyYybc5KWK+iOuyzsEc/hgPb8URBiraJiZvipZh7MMj4l45AfKUTXli0iHksXuYw9 SOwvAiPzKxrAULAx/XCzV4dluQp+lqs+qx6+LTZBoB54odObyNfaPU/2yZWt3cmGP239exm5zbY zCTou3m++tJGXJ6Ulo+1KlkU0Ff6bsF+acdET/EactKeH3n3dxDQZtbUnES7Cd9ciJTKueHptlQ zMioJ2FsJNUT3xhn0BDmcyA== X-Received: by 2002:a05:6000:2407:b0:46f:8cc5:454b with SMTP id ffacd0b85a97d-47759568450mr786048f8f.43.1782892291047; Wed, 01 Jul 2026 00:51:31 -0700 (PDT) X-Received: by 2002:a05:6000:2407:b0:46f:8cc5:454b with SMTP id ffacd0b85a97d-47759568450mr785989f8f.43.1782892290338; Wed, 01 Jul 2026 00:51:30 -0700 (PDT) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [2a10:fc81:a806:d6a9::1]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4756636cf98sm11271755f8f.22.2026.07.01.00.51.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jul 2026 00:51:29 -0700 (PDT) From: Stefano Brivio To: Anshu Kumari Subject: Re: [PATCH v4 1/4] dhcp: Refactor fill_one() to operate on a generic buffer Message-ID: <20260701095128.4640ca6f@elisabeth> In-Reply-To: <20260617132243.1499556-2-anskuma@redhat.com> References: <20260617132243.1499556-1-anskuma@redhat.com> <20260617132243.1499556-2-anskuma@redhat.com> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.49; x86_64-pc-linux-gnu) MIME-Version: 1.0 Date: Wed, 01 Jul 2026 09:51:29 +0200 (CEST) X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 8fNKLwNhphfPcJiQaPaEhA53xQXHW3rFFubtBM5D-yk_1782892291 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: MBVQCB7NJQ6A7VGTXCUAMZU6NRVHAAFO X-Message-ID-Hash: MBVQCB7NJQ6A7VGTXCUAMZU6NRVHAAFO X-MailFrom: sbrivio@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: passt-dev@passt.top, jmaloy@redhat.com, david@gibson.dropbear.id.au, lvivier@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 Wed, 17 Jun 2026 18:52:35 +0530 Anshu Kumari wrote: > Change fill_one() to accept a buffer pointer and capacity instead of > a struct msg pointer. This is a pure refactor with no behavior change, > preparing for option overload support where fill_one() will also write > into the file and sname fields. >=20 > Link: https://bugs.passt.top/show_bug.cgi?id=3D192 > Signed-off-by: Anshu Kumari > --- > v4: > - Unchanged from v3. >=20 > v3: > - Restored removed comments: "If we don't have space to write the > option, then just skip" and "Move to option". >=20 > v2: > - Renamed parameter cap =E2=86=92 size. > --- > dhcp.c | 28 +++++++++++++--------------- > 1 file changed, 13 insertions(+), 15 deletions(-) >=20 > diff --git a/dhcp.c b/dhcp.c > index 1ff8cba..8e3ffd6 100644 > --- a/dhcp.c > +++ b/dhcp.c > @@ -131,28 +131,29 @@ struct msg { > } __attribute__((__packed__)); > =20 > /** > - * fill_one() - Fill a single option in message > - * @m:=09=09Message to fill > + * fill_one() - Fill a single option into a buffer > + * @buf:=09Buffer to write option > + * @size:=09Usable size of @buf (excluding end marker) > * @o:=09=09Option number > - * @offset:=09Current offset within options field, updated on insertion > + * @offset:=09Current offset within @buf, updated on insertion > * > - * Return: false if m has space to write the option, true otherwise > + * Return: false if @buf has space to write the option, true otherwise > */ > -static bool fill_one(struct msg *m, int o, int *offset) > +static bool fill_one(uint8_t *buf, size_t size, int o, int *offset) > { > =09size_t slen =3D opts[o].slen; > =20 > =09/* If we don't have space to write the option, then just skip */ > -=09if (*offset + 2 /* code and length of option */ + slen > OPT_MAX) > +=09if (*offset + 2 + slen > size) This looks like an automatic linter dropping comments, but I think the original comment is quite useful. See also Laurent's review of v2: https://archives.passt.top/passt-dev/3b36426b-798c-489c-aad2-abcde13d2e93= @redhat.com/ > =09=09return true; > =20 > -=09m->o[*offset] =3D o; > -=09m->o[*offset + 1] =3D slen; > +=09buf[*offset] =3D o; > +=09buf[*offset + 1] =3D slen; > =20 > =09/* Move to option */ > =09*offset +=3D 2; > =20 > -=09memcpy(&m->o[*offset], opts[o].s, slen); > +=09memcpy(&buf[*offset], opts[o].s, slen); I think slightly more idiomatic: buf + *offset. Otherwise you have a pointer, dereference it, and then take its address. It looks a bit convoluted. Conversely, using buf[*offset] above makes sense because you need to dereference buf anyway. > =20 > =09opts[o].sent =3D 1; > =09*offset +=3D slen; > @@ -177,20 +178,17 @@ static int fill(struct msg *m) > =09 * Put it there explicitly, unless requested via option 55. > =09 */ > =09if (opts[55].clen > 0 && !memchr(opts[55].c, 53, opts[55].clen)) > -=09=09if (fill_one(m, 53, &offset)) > -=09=09=09 debug("DHCP: skipping option 53"); > +=09=09fill_one(m->o, OPT_MAX, 53, &offset); > =20 > =09for (i =3D 0; i < opts[55].clen; i++) { > =09=09o =3D opts[55].c[i]; > =09=09if (opts[o].slen !=3D -1) > -=09=09=09if (fill_one(m, o, &offset)) > -=09=09=09=09debug("DHCP: skipping option %i", o); > +=09=09=09fill_one(m->o, OPT_MAX, o, &offset); > =09} > =20 > =09for (o =3D 0; o < 255; o++) { > =09=09if (opts[o].slen !=3D -1 && !opts[o].sent) > -=09=09=09if (fill_one(m, o, &offset)) > -=09=09=09=09debug("DHCP: skipping option %i", o); > +=09=09=09fill_one(m->o, OPT_MAX, o, &offset); > =09} > =20 > =09m->o[offset++] =3D 255; I also had the same comment as David's about dropping debug() messages... until I reached 2/4, which is a good indication that they should go away later. --=20 Stefano