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=JX/LqjfI; 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 D46BC5A0275 for ; Mon, 18 May 2026 15:20:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1779110425; 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=HS4GUFutKiEGTs+PHQmakVk4bba2H3qiLfR6kd1nVGM=; b=JX/LqjfIZNB9f9gft+uyYPfTU6OVZgQtwcTrH4719R8uRWIfpwEMiAxACKfUysm+kCE60X xyweXwS1+KtPLRX9J7YFaa+Ub8nBjuA26bqvQL3gO+enrlQ+HaS7zj5Ov7uJHRQqI2+v3Y LrbxgT1/XWhvBcNuhcVTabri5oOclJk= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-297-zChfT71sPYW3o55kqHfFDA-1; Mon, 18 May 2026 09:20:24 -0400 X-MC-Unique: zChfT71sPYW3o55kqHfFDA-1 X-Mimecast-MFC-AGG-ID: zChfT71sPYW3o55kqHfFDA_1779110423 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6927E180060F; Mon, 18 May 2026 13:20:23 +0000 (UTC) Received: from anskuma-thinkpadp1gen7.bengluru.csb (unknown [10.74.80.120]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8459F18004A3; Mon, 18 May 2026 13:20:20 +0000 (UTC) From: Anshu Kumari To: anskuma@redhat.com, sbrivio@redhat.com, passt-dev@passt.top Subject: [PATCH 4/6] dhcp: Refactor fill_one() to operate on a generic buffer Date: Mon, 18 May 2026 18:50:00 +0530 Message-ID: <20260518132002.418296-5-anskuma@redhat.com> In-Reply-To: <20260518132002.418296-4-anskuma@redhat.com> References: <20260518132002.418296-1-anskuma@redhat.com> <20260518132002.418296-2-anskuma@redhat.com> <20260518132002.418296-3-anskuma@redhat.com> <20260518132002.418296-4-anskuma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: g57-t0i341anfkaUatPN8XvhIVN3WoQLjOZeROa5dCY_1779110423 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: SEQOF5XF4EXZESCOBRZKAWBCFUTUDSP7 X-Message-ID-Hash: SEQOF5XF4EXZESCOBRZKAWBCFUTUDSP7 X-MailFrom: anskuma@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: lvivier@redhat.com, jmaloy@redhat.com, david@gibson.dropbear.id.au 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: 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. Link: https://bugs.passt.top/show_bug.cgi?id=192 Signed-off-by: Anshu Kumari --- dhcp.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/dhcp.c b/dhcp.c index 9220516..a966c34 100644 --- a/dhcp.c +++ b/dhcp.c @@ -358,28 +358,27 @@ struct msg { } __attribute__((__packed__)); /** - * fill_one() - Fill a single option in message - * @m: Message to fill + * fill_one() - Fill a single option into a buffer + * @buf: Buffer to write option + * @cap: Usable capacity of @buf (excluding end marker) * @o: Option number - * @offset: Current offset within options field, updated on insertion + * @offset: Current 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 cap, int o, int *offset) { size_t slen = opts[o].slen; - /* If we don't have space to write the option, then just skip */ - if (*offset + 2 /* code and length of option */ + slen > OPT_MAX) + if (*offset + 2 + slen > cap) return true; - m->o[*offset] = o; - m->o[*offset + 1] = slen; + buf[*offset] = o; + buf[*offset + 1] = slen; - /* Move to option */ *offset += 2; - memcpy(&m->o[*offset], opts[o].s, slen); + memcpy(&buf[*offset], opts[o].s, slen); opts[o].sent = 1; *offset += slen; @@ -404,19 +403,19 @@ static int fill(struct msg *m) * Put it there explicitly, unless requested via option 55. */ if (opts[55].clen > 0 && !memchr(opts[55].c, 53, opts[55].clen)) - if (fill_one(m, 53, &offset)) + if (fill_one(m->o, OPT_MAX, 53, &offset)) debug("DHCP: skipping option 53"); for (i = 0; i < opts[55].clen; i++) { o = opts[55].c[i]; if (opts[o].slen != -1) - if (fill_one(m, o, &offset)) + 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 (fill_one(m, o, &offset)) + if (fill_one(m->o, OPT_MAX, o, &offset)) debug("DHCP: skipping option %i", o); } -- 2.54.0