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=202504 header.b=T5VlfNxk; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 0FCCE5A0008 for ; Mon, 14 Apr 2025 06:07:57 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202504; t=1744603675; bh=1plDi0RpbQYjdRp8Qol5aseci98Sz4hQD+0RJBLIlnU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=T5VlfNxktQyjUcMvxDAGF52w72+HtUaQLE4eB72hsNydAa6JUGYXTmjCAjJEET0kW ZG4Uu+EWLYlzx/rRUygYeuwiudYnZBR7QflpPRbBPPDbhrS8H3cFbuUNjm0LKOsXBB 4+6fZWsKwgx2aKnV7dkt2PbamG0f+2hRLxq3NhaEx1G1vHSYy+P4jJoFXFWlCDYnbh UVA3SjyKc2E55WFbgLSjl9aPeDn5PykmJzIRUZAjt+tqjnJfZHmWbuR2r1K7NKlPkT Dp5K3xT0F6MMTMlwLO0mgFJUYrtW1wpNzMRGAU3jJlG41ssuT2E+0KknBPmVIfQax4 kr00tuHZc5/eQ== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4ZbYfg045Wz4x3p; Mon, 14 Apr 2025 14:07:54 +1000 (AEST) Date: Mon, 14 Apr 2025 14:07:48 +1000 From: David Gibson To: Laurent Vivier Subject: Re: [PATCH v2 13/20] dhcpv6: move offset initialization out of dhcpv6_opt() Message-ID: References: <20250411131031.1398006-1-lvivier@redhat.com> <20250411131031.1398006-14-lvivier@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="l/o0pmQnAe4IXid4" Content-Disposition: inline In-Reply-To: <20250411131031.1398006-14-lvivier@redhat.com> Message-ID-Hash: C5UFXA6VQTHR46VRFH6T2HNPPBVD4JEY X-Message-ID-Hash: C5UFXA6VQTHR46VRFH6T2HNPPBVD4JEY 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: --l/o0pmQnAe4IXid4 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Apr 11, 2025 at 03:10:23PM +0200, Laurent Vivier wrote: > No functional change. >=20 > Currently, if dhcpv6_opt() is called with offset set to 0, it will set the > offset to point to DHCPv6 options offset. >=20 > To simplify the use of iovec_tail in a later patch, move the initializati= on > out of the function. Replace all the call using 0 by a call using > the offset of the DHCPv6 options. >=20 > Signed-off-by: Laurent Vivier Reviewed-by: David Gibson As a rule, I dislike automagical special cases like this one in any case. > --- > dhcpv6.c | 22 +++++++++++----------- > 1 file changed, 11 insertions(+), 11 deletions(-) >=20 > diff --git a/dhcpv6.c b/dhcpv6.c > index 373a98869f9b..be51c278af7a 100644 > --- a/dhcpv6.c > +++ b/dhcpv6.c > @@ -54,14 +54,14 @@ struct opt_hdr { > uint16_t l; > } __attribute__((packed)); > =20 > +#define UDP_MSG_HDR_SIZE (sizeof(struct udphdr) + sizeof(struct msg_hdr)) > # define OPT_SIZE_CONV(x) (htons_constant(x)) > #define OPT_SIZE(x) OPT_SIZE_CONV(sizeof(struct opt_##x) - \ > sizeof(struct opt_hdr)) > #define OPT_VSIZE(x) (sizeof(struct opt_##x) - \ > sizeof(struct opt_hdr)) > #define OPT_MAX_SIZE IPV6_MIN_MTU - (sizeof(struct ipv6hdr) + \ > - sizeof(struct udphdr) + \ > - sizeof(struct msg_hdr)) > + UDP_MSG_HDR_SIZE) > =20 > /** > * struct opt_client_id - DHCPv6 Client Identifier option > @@ -290,8 +290,7 @@ static struct opt_hdr *dhcpv6_opt(const struct pool *= p, size_t *offset, > struct opt_hdr *o; > size_t left; > =20 > - if (!*offset) > - *offset =3D sizeof(struct udphdr) + sizeof(struct msg_hdr); > + ASSERT(*offset >=3D UDP_MSG_HDR_SIZE); > =20 > while ((o =3D packet_get_try(p, 0, *offset, sizeof(*o), &left))) { > unsigned int opt_len =3D ntohs(o->l) + sizeof(*o); > @@ -327,7 +326,7 @@ static struct opt_hdr *dhcpv6_ia_notonlink(const stru= ct pool *p, > size_t offset; > =20 > foreach(ia_type, ia_types) { > - offset =3D 0; > + offset =3D UDP_MSG_HDR_SIZE; > while ((ia =3D dhcpv6_opt(p, &offset, *ia_type))) { > if (ntohs(ia->l) < OPT_VSIZE(ia_na)) > return NULL; > @@ -464,8 +463,9 @@ static size_t dhcpv6_client_fqdn_fill(const struct po= ol *p, const struct ctx *c, > =20 > o =3D (struct opt_client_fqdn *)(buf + offset); > encode_domain_name(o->domain_name, c->fqdn); > - req_opt =3D (struct opt_client_fqdn *)dhcpv6_opt(p, &(size_t){ 0 }, > - OPT_CLIENT_FQDN); > + req_opt =3D (struct opt_client_fqdn *)dhcpv6_opt(p, > + &(size_t){ UDP_MSG_HDR_SIZE }, > + OPT_CLIENT_FQDN); > if (req_opt && req_opt->flags & 0x01 /* S flag */) > o->flags =3D 0x02 /* O flag */; > else > @@ -522,15 +522,15 @@ int dhcpv6(struct ctx *c, const struct pool *p, > if (!mh) > return -1; > =20 > - client_id =3D dhcpv6_opt(p, &(size_t){ 0 }, OPT_CLIENTID); > + client_id =3D dhcpv6_opt(p, &(size_t){ UDP_MSG_HDR_SIZE }, OPT_CLIENTID= ); > if (!client_id || ntohs(client_id->l) > OPT_VSIZE(client_id)) > return -1; > =20 > - server_id =3D dhcpv6_opt(p, &(size_t){ 0 }, OPT_SERVERID); > + server_id =3D dhcpv6_opt(p, &(size_t){ UDP_MSG_HDR_SIZE }, OPT_SERVERID= ); > if (server_id && ntohs(server_id->l) !=3D OPT_VSIZE(server_id)) > return -1; > =20 > - ia =3D dhcpv6_opt(p, &(size_t){ 0 }, OPT_IA_NA); > + ia =3D dhcpv6_opt(p, &(size_t){ UDP_MSG_HDR_SIZE }, OPT_IA_NA); > if (ia && ntohs(ia->l) < MIN(OPT_VSIZE(ia_na), OPT_VSIZE(ia_ta))) > return -1; > =20 > @@ -580,7 +580,7 @@ int dhcpv6(struct ctx *c, const struct pool *p, > memcmp(&resp.server_id, server_id, sizeof(resp.server_id))) > return -1; > =20 > - if (ia || dhcpv6_opt(p, &(size_t){ 0 }, OPT_IA_TA)) > + if (ia || dhcpv6_opt(p, &(size_t){ UDP_MSG_HDR_SIZE }, OPT_IA_TA)) > return -1; > =20 > info("DHCPv6: received INFORMATION_REQUEST, sending REPLY"); --=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 --l/o0pmQnAe4IXid4 Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmf8ihMACgkQzQJF27ox 2GeskBAAm7Q9URny/b06FDdo+S40+4lFRKq0/osmc2L9g2KtoYqLS/7DEWHzlY0u IHhSyOR1mPc8FxcIMGYdxmw5Mx7wQ9rMsbi1Dgbu4/WalWrB7EQxIIPsAU3hut9Z oDZKsRLpJ5qPP2awZKCScMNCTanxsQiHQCqzH2u0EMr0POg8Nc88obN73nwy4nya ot8t1mFqAzq3NVLKa+ec9Ax0wkvzoVQYPPVy/eeCFc5Z73CPTLjva75evP1TgBBO eG4O8K3a6R741rz6IJeIkwp0KlXuQy52gYd32viHkGudnzoTsHnT8KgeBsxLwUQ0 hzZ7f0pL0tGCc83XYAoqms7mKrtq5sNCLL7PlGfTsOoRgeP+lk1bdcjudgOKxhN6 mwi4Uhf8bD4x+Xc3Y0Wy9sKHN4WQBr5/Zo/qxexI+9oGeIzI/qGvVUonKTQhbhwn Cywp6T+lrgqAYdBL3/qHXPMFW+vxtKbPRgnPKeY+1RXz6Bnk6Uu0mWurV2utyDo/ tu3Ljs2k8YLi7VaL0pnhLrIWO7d6yKoVW7sj5z92d+95mmRKfy/y/VsrJ/kqWv/3 j/GNl50sGsO7CIpbu9FoemrTedztrVpiNRNx7B4yd3cHD67SGzrjbAf4wSrWC+nq ODd5UalURnVGEJ3+w+hOivCTQc8j5nj3jYLH/nSEaERUsv4H0tM= =4t0z -----END PGP SIGNATURE----- --l/o0pmQnAe4IXid4--