From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=none 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=J1wMFAPG; 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 ESMTP id 859F05A004E for ; Tue, 26 Nov 2024 07:43:05 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1732603384; 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=gGuEO9tDxqSq/JMGYL1wn5KbjEi5dOdQoMYO140xvjc=; b=J1wMFAPG5IfYnyKuk1EVK1ewXIqnA1p0fJLIkbsK+RiJAW9kPq1UbowUhIa95YsW1shnub TKqrs9ftIRqCV0c4E3ADCl9395FveicCBHcYmg7ApDr8+d51adAKfsGESMPBOQ17imYGtI j74HBNkV60VVcIsHfUTEs1qAu0smxzY= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-83-rTXIEtVUOcGp7dtxYyVM6A-1; Tue, 26 Nov 2024 01:43:03 -0500 X-MC-Unique: rTXIEtVUOcGp7dtxYyVM6A-1 X-Mimecast-MFC-AGG-ID: rTXIEtVUOcGp7dtxYyVM6A Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4349cda1899so16571215e9.0 for ; Mon, 25 Nov 2024 22:43:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732603380; x=1733208180; h=content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=gGuEO9tDxqSq/JMGYL1wn5KbjEi5dOdQoMYO140xvjc=; b=dLH/d4b9bloAcjybDpaCbykan5S5WjOFzmGc3FJYkhnD6yGupMeNqWCT3GS/+p3T5t t0C7kQfivDjfbBCD82aRxQpMFJ8wRq2PcuSUq1iFqAx4C5jCmV1aeBnaiy5UJDaDHETp 4jrDBE0DB96dH9RlrmRbJLHPrCFfaDK/4qGWoNBNlVlGViGuhDumDzH0h/ORkT8asYgB BDcy9n0+t4Cp40nNCZGcGf1qZYOyQ+WAKrQyaH8pl15rTQqEJ4JvxTiyNaK0T4DMIx7E tOv9Hn58Dp9lmcOmVYYiUIaSyrBZoMNoD492XxkHgqdWsCVChkdsum/LvnBPd8Zu+0nb qGQQ== X-Gm-Message-State: AOJu0Yxt06LRCD8Tgeau9SffUQe6UmTmCtkbPjAt+P/z2QDCtAk+eo+X OkYHDv5tNIpnOObOi0qeD4xlf/ZduikLe+P4N75ky24UIN++1dlqPq+3lF8tMYObhAU8Mf/pyBI qPdsiHxlsj1VravgicgDWKHRA8wv3T8DBBHr9v871QLKzn2mS5c072gluhA== X-Gm-Gg: ASbGnct1gczk6FVM4XEYO4iivgA2K16E60iR9rKU5L/8J5XUfUYHmrBhlmXphwIb7pw +bJucP4kK3XKmaJMhgRcim4/ynSCejC7ZYVccu1cy4DflFkOOfnceNaHiQT4HkFv57JzJjucThu VjhMlGq1+qFjQ0fIrCB3ZxMYZFcRxpNDYv0y/jCVl/iYqj/4YMLn7szMBGT1Gd38VG8OJR4+AiC BM3yIkQzJUxaC5F9e48tXQy97HEyM9y4yc8sC8/vdXOEMztZhJjI1wadzXpIA== X-Received: by 2002:a05:6000:23c5:b0:37d:50e1:b3d3 with SMTP id ffacd0b85a97d-38260b5e4e2mr9833717f8f.20.1732603380672; Mon, 25 Nov 2024 22:43:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IGGxk0MESUXf24IxyQCBrFhsBuXv8ldd1K39jfn21if29QfxBo7ky+sTCyl5ocGwf3gwbGfdg== X-Received: by 2002:a05:6000:23c5:b0:37d:50e1:b3d3 with SMTP id ffacd0b85a97d-38260b5e4e2mr9833708f8f.20.1732603380262; Mon, 25 Nov 2024 22:43:00 -0800 (PST) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [2a10:fc81:a806:d6a9::1]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3825fb27196sm12410564f8f.55.2024.11.25.22.42.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Nov 2024 22:42:59 -0800 (PST) Date: Tue, 26 Nov 2024 07:42:58 +0100 From: Stefano Brivio To: passt-dev@passt.top Subject: Re: [PATCH v4 1/3] dhcp: Use -1 as "missing option" length instead of 0 Message-ID: <20241126074258.221abd08@elisabeth> In-Reply-To: <20241126063410.1950820-2-sbrivio@redhat.com> References: <20241126063410.1950820-1-sbrivio@redhat.com> <20241126063410.1950820-2-sbrivio@redhat.com> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.41; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 8WumSRDzGpvcCA0HceLjYF7RTzOBaae7JFpazmRndzE_1732603382 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: SE5AVO3G7DSYHFKSD2P4E2XX5H4NIWED X-Message-ID-Hash: SE5AVO3G7DSYHFKSD2P4E2XX5H4NIWED 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: David Gibson 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 Tue, 26 Nov 2024 07:34:08 +0100 Stefano Brivio wrote: > We want to add support for option 80 (Rapid Commit, RFC 4039), whose > length is 0. > > Signed-off-by: Stefano Brivio > --- > dhcp.c | 30 ++++++++++++++++++++++-------- > 1 file changed, 22 insertions(+), 8 deletions(-) > > diff --git a/dhcp.c b/dhcp.c > index a06f143..387aee3 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 = 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, > @@ -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); > > for (i = 0; i < opts[55].clen; i++) { > o = opts[55].c[i]; > - if (opts[o].slen) > + if (opts[o].slen != -1) > fill_one(m, o, &offset); > } > > for (o = 0; o < 255; o++) { > - if (opts[o].slen && !opts[o].sent) > + if (opts[o].slen != -1 && !opts[o].sent) > fill_one(m, o, &offset); > } > > @@ -264,6 +269,9 @@ static void opt_set_dns_search(const struct ctx *c, size_t max_len) > ".\xc0"); > } > } > + > + if (!opts[119].slen) > + opts[119].slen = -1; > } > > /** > @@ -313,6 +321,9 @@ int dhcp(const struct ctx *c, const struct pool *p) > > offset += offsetof(struct msg, o); > > + for (i = 0; i < ARRAY_SIZE(opts); i++) > + opts[i].clen = -1; > + > while (opt_off + 2 < opt_len) { > const uint8_t *olen, *val; > uint8_t *type; > @@ -331,11 +342,12 @@ int dhcp(const struct ctx *c, const struct pool *p) > opt_off += *olen + 2; > } > > - if (opts[53].c[0] == DHCPDISCOVER) { > + if (opts[53].clen > 0 && opts[53].c[0] == DHCPDISCOVER) { > info("DHCP: offer to discover"); > opts[53].s[0] = DHCPOFFER; > - } else if (opts[53].c[0] == DHCPREQUEST || !opts[53].clen) { > - info("%s: ack to request", opts[53].clen ? "DHCP" : "BOOTP"); > + } else if (opts[53].clen <= 0 || opts[53].c[0] == DHCPREQUEST) { > + info("%s: ack to request", /* DHCP needs a valid message type */ > + (opts[53].clen <= 0) ? "BOOTP" : "DHCP"); Oops, posted before tests completed, this is broken again... -- Stefano