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=fail reason="key not found in DNS" header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202312 header.b=Y1r6S6Zn; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 7BC665A0276 for ; Mon, 19 Aug 2024 03:39:57 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1724031595; bh=YXxext/HSgLpeKnHQSHZXmAjXp4WxxkAkwMnbvi+M6g=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Y1r6S6ZncWzJOEjm7g+uXrfDDBt3JSfZiPXsJ//QmWjwlFawABtoamPV5LCB4IShM EuUnGFibbJkotdDeVTpN3K2+IzknCB/5ncOzJBSdArcQnd9u6nW0n+VJGQggFGmmWe 8z4Vt+1ER4/7CRAm+vApEQxg2nQl+Fw2vZ6/V3JT6KbwzVUuFWjIISDRSLgAceeT04 +J5wIh4Y55DSyzQehkCjU/GlmK98M0tKi/4Mo/18pxyUaMnsksC4hTaKz0/Z7RrVaz p6AsvGgXX5z5X8lt7WjYKq/YxNvLwduKOtfaeH9X1N94STmxRbvozeGy9nWQHU/5H3 GNaYl0Ju3e3mA== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4WnFdl2BG1z4w2F; Mon, 19 Aug 2024 11:39:55 +1000 (AEST) Date: Mon, 19 Aug 2024 11:38:25 +1000 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH 04/22] treewide: Use struct assignment instead of memcpy() for IP addresses Message-ID: References: <20240816054004.1335006-1-david@gibson.dropbear.id.au> <20240816054004.1335006-5-david@gibson.dropbear.id.au> <20240818174503.2530d030@elisabeth> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="mLPr9k72xnsvjuG8" Content-Disposition: inline In-Reply-To: <20240818174503.2530d030@elisabeth> Message-ID-Hash: ITM5TK5LIOHA5OPQCFP5ZWQOKZDVLKIW X-Message-ID-Hash: ITM5TK5LIOHA5OPQCFP5ZWQOKZDVLKIW 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, Paul Holzinger 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: --mLPr9k72xnsvjuG8 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Aug 18, 2024 at 05:45:03PM +0200, Stefano Brivio wrote: > On Fri, 16 Aug 2024 15:39:45 +1000 > David Gibson wrote: >=20 > > We rely on C11 already, so we can use clearer and more type-checkable > > struct assignment instead of mempcy() for copying IP addresses around. > >=20 > > This exposes some "pointer could be const" warnings from cppcheck, so > > address those too. > >=20 > > Signed-off-by: David Gibson > > --- > > conf.c | 12 ++++++------ > > dhcpv6.c | 10 ++++++---- > > 2 files changed, 12 insertions(+), 10 deletions(-) > >=20 > > diff --git a/conf.c b/conf.c > > index 750fdc86..9b05afeb 100644 > > --- a/conf.c > > +++ b/conf.c > > @@ -389,14 +389,14 @@ static void add_dns6(struct ctx *c, > > /* Guest or container can only access local addresses via redirect */ > > if (IN6_IS_ADDR_LOOPBACK(addr)) { > > if (!c->no_map_gw) { > > - memcpy(*conf, &c->ip6.gw, sizeof(**conf)); > > + **conf =3D c->ip6.gw; > > (*conf)++; > > =20 > > if (IN6_IS_ADDR_UNSPECIFIED(&c->ip6.dns_match)) > > - memcpy(&c->ip6.dns_match, addr, sizeof(*addr)); > > + c->ip6.dns_match =3D *addr; > > } > > } else { > > - memcpy(*conf, addr, sizeof(**conf)); > > + **conf =3D *addr; > > (*conf)++; > > } > > =20 > > @@ -632,7 +632,7 @@ static unsigned int conf_ip4(unsigned int ifi, > > ip4->prefix_len =3D 32; > > } > > =20 > > - memcpy(&ip4->addr_seen, &ip4->addr, sizeof(ip4->addr_seen)); > > + ip4->addr_seen =3D ip4->addr; > > =20 > > if (MAC_IS_ZERO(mac)) { > > int rc =3D nl_link_get_mac(nl_sock, ifi, mac); > > @@ -693,8 +693,8 @@ static unsigned int conf_ip6(unsigned int ifi, > > return 0; > > } > > =20 > > - memcpy(&ip6->addr_seen, &ip6->addr, sizeof(ip6->addr)); > > - memcpy(&ip6->addr_ll_seen, &ip6->addr_ll, sizeof(ip6->addr_ll)); > > + ip6->addr_seen =3D ip6->addr; > > + ip6->addr_ll_seen =3D ip6->addr_ll; > > =20 > > if (MAC_IS_ZERO(mac)) { > > rc =3D nl_link_get_mac(nl_sock, ifi, mac); > > diff --git a/dhcpv6.c b/dhcpv6.c > > index bbed41dc..87b3c3eb 100644 > > --- a/dhcpv6.c > > +++ b/dhcpv6.c > > @@ -298,7 +298,8 @@ static struct opt_hdr *dhcpv6_ia_notonlink(const st= ruct pool *p, > > { > > char buf[INET6_ADDRSTRLEN]; > > struct in6_addr req_addr; > > - struct opt_hdr *ia, *h; > > + const struct opt_hdr *h; > > + struct opt_hdr *ia; > > size_t offset; > > int ia_type; > > =20 > > @@ -312,12 +313,13 @@ ia_ta: > > offset +=3D sizeof(struct opt_ia_na); > > =20 > > while ((h =3D dhcpv6_opt(p, &offset, OPT_IAAADR))) { > > - struct opt_ia_addr *opt_addr =3D (struct opt_ia_addr *)h; > > + const struct opt_ia_addr *opt_addr > > + =3D (const struct opt_ia_addr *)h; >=20 > Nit: the assignment could go on its own line, then? Good point, done. > > if (ntohs(h->l) !=3D OPT_VSIZE(ia_addr)) > > return NULL; > > =20 > > - memcpy(&req_addr, &opt_addr->addr, sizeof(req_addr)); > > + req_addr =3D opt_addr->addr; > > if (!IN6_ARE_ADDR_EQUAL(la, &req_addr)) { > > info("DHCPv6: requested address %s not on link", > > inet_ntop(AF_INET6, &req_addr, > > @@ -363,7 +365,7 @@ static size_t dhcpv6_dns_fill(const struct ctx *c, = char *buf, int offset) > > srv->hdr.l =3D 0; > > } > > =20 > > - memcpy(&srv->addr[i], &c->ip6.dns[i], sizeof(srv->addr[i])); > > + srv->addr[i] =3D c->ip6.dns[i]; > > srv->hdr.l +=3D sizeof(srv->addr[i]); > > offset +=3D sizeof(srv->addr[i]); > > } >=20 > I only reviewed up to this patch so far. >=20 --=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 --mLPr9k72xnsvjuG8 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmbCohAACgkQzQJF27ox 2Ge9Zg//W1cxBmZhAopkcvWBt1Rkg/DxsDzy0n7+iJAUyZ5VK3I7/C8vDFpdb2S9 zzgpf1Gs1Me4NTCQ/VIk5mkJ76hAVtlMZbIfYIbbFltWItdEZ2OrNBXaOqXLs94a MlJsEcgtsOzTD/KJIg+2Xfu5Z+BIg1Sd85KMtZEFWa4uKcK+lD+87UUD9m4gr57Q R5v7faW2RnKTSNgCm7finFvf/P1O0TMF6g0tBcDsnXAXe4E9aMBBztpG7ycj4dKb WscwfR5KksfDB+AztASQ1bHoYdz85H6Lon7hAmsCILdvifyA90sYDHiiHeAKiJVN MOn1rbQ/sA8anlg88iyBxE6BHMcQdZY/WQW7euiewmJocj3Wg8VtMcupkSjmZJTF 00q6AYw6spPvme5Uu8jR0G2Xdh65tU7CbAB1ZhWpslUFtVvaZG+J6WcSbKdrTl+i CsZM4Z6GtF6Ya1MyVS88wJnX3ut+5GHS9QLqVKdqJd6JLNnfAIH0I2TiDdcXhDHk wTWPO6izb8liEo1ommk70nEgXyZDfDpu8+s4iM77Yv5oDDpySPOcal3/m/Zf4HAo etMY0ly9waaxBPE+lVwV+nSsMyUbSjKzML6Vm5S7mlRICjQzMTWpXdI3UOgGGDlE 4apV2lpJDDLVd+dIJ6kVNv3e6ztJyuO3VCBBco7eV2aYKGgpzUk= =dhwZ -----END PGP SIGNATURE----- --mLPr9k72xnsvjuG8--