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=EPJxJfIR; 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 40C295A004C for ; Mon, 25 Nov 2024 09:30:19 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1732523418; 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=WR52LN132Tg/pYvngWT5fn4BJa78ca0fmf8rxsyDOss=; b=EPJxJfIRcIkR3yDiqplUpAcUywAOT1xVt4ai0X0v2zgRj1F4bXLjlVqdFACe5CrbyskeqM YnVYApRa4/+jzVR6rwtwfkV6RgMeBjcjtKIAg9snsV7RX5tK0KtUvePRQvYXJ8oEhk1IuB RSQl0niMF4j0xWzW994sDoWns0+yL2I= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-689-D9ElJSudPoimYSO_GPDqQg-1; Mon, 25 Nov 2024 03:30:16 -0500 X-MC-Unique: D9ElJSudPoimYSO_GPDqQg-1 X-Mimecast-MFC-AGG-ID: D9ElJSudPoimYSO_GPDqQg Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-3822ebe9321so2629385f8f.2 for ; Mon, 25 Nov 2024 00:30:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732523414; x=1733128214; 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=WR52LN132Tg/pYvngWT5fn4BJa78ca0fmf8rxsyDOss=; b=wd4OqfUNJwPUOaXCg2Ud2SU0hAuoZ2AnOg7FVr2mAdAsr9SnDaI6V6UQuUDrxzmPMF +3xFPrlte0KQDatN56PKWqialImqjBiv58d4zxatyGc9plppvVX9RtgkdV2PWLJo4ZQT ehVkzYGCNx+uggXRL9LECkWErIwHNh8XMK4yeyr9nNRNm9B7nrCOOObMDo5rPUFqtEf/ lCF0ssaaS6pvElxDqGFZ5rsXYFq/sZycxHaIxAiSVgU60BaUPypUpWsam6O8iZZb17HA KbhBsxtK+Kgb11Tw+S3VvXGkx/Wz3M2mHKzx5R41UcW3RxN2mG40nNfIvIDJgPacBoyM TCPw== X-Gm-Message-State: AOJu0YxvLG0/bBDjYX/x6L4vZNI5uHJtNFI8fCLCcf9QY3l1OrRiWmNv Cb+IP0HOYSMYWRFvfxKKzHLcaXLMyKduof+dvPU4ynxXUyMY3ab/wFzCc2nL5tB7weV51OAWsJ1 2ApKkY+RzWBJO76wZAKPBS2YgpdC3W4hTSSm+m00PqsOYgh+aVZiORuMOnQ== X-Gm-Gg: ASbGnctREzOtU5slivV+o76Okl9wW/9JRP+5/CF5X9ef/XbRr3A/RkR+doCINA6Dp0U 88uityxPQ7Lnrp3U1Uc680uYIWf1aqcM9lO21HOnE3fMgu9LoHhnrIUOVNcOe8Fx+b0Nx8on4M/ ZRlICJtu5lqxLT2picpIssyJmrWa8iIX9m6Qusl1GU2t4tGJlp5nTjER7KW9OzjPHQC9CdvEb9n 9f2YO628q1IQwurXhsdCaAvgisezmlqJKO74+s2BQwGjfNlmp12XbqJSRDOmg== X-Received: by 2002:a05:6000:410e:b0:382:503f:a323 with SMTP id ffacd0b85a97d-38260b58dd7mr6480312f8f.19.1732523414262; Mon, 25 Nov 2024 00:30:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IF0KDmz7Rq2iR8PCRPLC168WK/Ty8/VZhO7VdiM2DEcXdTey01x35b6jh8DMYuJufxNiKIDSA== X-Received: by 2002:a05:6000:410e:b0:382:503f:a323 with SMTP id ffacd0b85a97d-38260b58dd7mr6480283f8f.19.1732523413577; Mon, 25 Nov 2024 00:30:13 -0800 (PST) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [2a10:fc81:a806:d6a9::1]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-433b463ab5fsm187164005e9.27.2024.11.25.00.30.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Nov 2024 00:30:12 -0800 (PST) Date: Mon, 25 Nov 2024 09:30:10 +0100 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH 1/3] dhcp: Use -1 as "missing option" length instead of 0 Message-ID: <20241125093010.362f1aa8@elisabeth> In-Reply-To: References: <20241125000423.4131458-1-sbrivio@redhat.com> <20241125000423.4131458-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: NDJoMhEtTEP0qlhF5fbackxm-fDFDbQihv7VoKw5QkQ_1732523415 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: 3ZQ6DLCLUIAGBVWU6XFMCNOEFAKT2DXT X-Message-ID-Hash: 3ZQ6DLCLUIAGBVWU6XFMCNOEFAKT2DXT 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 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 Mon, 25 Nov 2024 12:08:35 +1100 David Gibson wrote: > On Mon, Nov 25, 2024 at 01:04:21AM +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 | 27 ++++++++++++++++++++------- > > 1 file changed, 20 insertions(+), 7 deletions(-) > > > > diff --git a/dhcp.c b/dhcp.c > > index a06f143..2fe4a4d 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 { > > @@ -154,17 +154,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 +264,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 +316,13 @@ int dhcp(const struct ctx *c, const struct pool *p) > > > > offset += offsetof(struct msg, o); > > > > + for (i = 0; i < ARRAY_SIZE(opts); i++) { > > + if (!opts[i].slen) > > + opts[i].slen = -1; > > + > > + opts[i].clen = -1; > > + } > > Could this move to dhcp_init()? I think there you wouldn't need test > and could unconditionally initialize all the lengths to -1 before > initializing the options we actually use. No, because dhcp_init() is run only once, and 'opts' at this point represents the status from the previous run, so: - we need to unconditionally reset all the 'clen' attributes which were set in the previous run - we need to reset the 'slen' attributes for zero-length options (it's just option 80 at the moment) because we need to re-evaluate their inclusion. Sure, I could also clean things up at the end of any run, but this is more practical and robust > > while (opt_off + 2 < opt_len) { > > const uint8_t *olen, *val; > > uint8_t *type; > > @@ -334,8 +344,9 @@ int dhcp(const struct ctx *c, const struct pool *p) > > if (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].c[0] == DHCPREQUEST || opts[53].clen <= 0) { > > + info("%s: ack to request", > > + (opts[53].clen <= 0) ? "DHCP" : "BOOTP"); > > Should this be <= 0, or < 0? i.e. Wouldn't even an empty option 53 > indicate we're dealing with DHCP rather than BOOTP? It should really be <= 0, preserving the existing behaviour, because if option 53 is empty, we don't know what kind of DHCP message that is. We know for sure that it's not a valid DHCP message, but it probably is a valid BOOTP message (with a vendor extension). This might look like speculation, but there are some half-DHCP implementations from the 1990s which we can happily handle as BOOTP clients, but not really as DHCP. After all the fun we had with wattcp32 and mTCP I would say it's not unlikely. > > opts[53].s[0] = DHCPACK; > > } else { > > return -1; > > @@ -374,6 +385,8 @@ int dhcp(const struct ctx *c, const struct pool *p) > > ((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 (!c->no_dhcp_dns_search) > > opt_set_dns_search(c, sizeof(m->o)); -- Stefano