From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 0CF6F5A026F for ; Mon, 24 Jul 2023 08:09:43 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1690178979; bh=1ALdChTW8GBtjDnrCrX7KbSaT+x9+iD1h2afi/uHiYE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DBejtJYFlSZSN9fk1YGmATP0CY81fu6efH1bfRAKu0v/Wl3EPTmb2ni5grrzkDUQS BPfy3lll332xPi5ed69sdcuIuhhz9m0ZCVT/PjSgDdwayldrnAMKVnNzoFr4keCot9 DD+RHa5fa1jxsjfoS8g1h0ZHItBSl/v/mpJDgCHQ= Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4R8V9v4NrTz4wyh; Mon, 24 Jul 2023 16:09:39 +1000 (AEST) From: David Gibson To: Stefano Brivio , passt-dev@passt.top Subject: [PATCH 04/17] netlink: Use struct in_addr for IPv4 addresses, not bare uint32_t Date: Mon, 24 Jul 2023 16:09:23 +1000 Message-ID: <20230724060936.952659-5-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230724060936.952659-1-david@gibson.dropbear.id.au> References: <20230724060936.952659-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: UOLMJGFM7BRF67V2HVDI6PZXYQXFQBDT X-Message-ID-Hash: UOLMJGFM7BRF67V2HVDI6PZXYQXFQBDT 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: 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: This improves consistency with IPv6 and makes it harder to misuse these as some other sort of value. Signed-off-by: David Gibson --- netlink.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/netlink.c b/netlink.c index 346eb3a..75d5988 100644 --- a/netlink.c +++ b/netlink.c @@ -265,9 +265,9 @@ void nl_route_set_def(unsigned int ifi, sa_family_t af, void *gw) } r6; struct { struct rtattr rta_dst; - uint32_t d; + struct in_addr d; struct rtattr rta_gw; - uint32_t a; + struct in_addr a; } r4; } set; } req = { @@ -309,7 +309,7 @@ void nl_route_set_def(unsigned int ifi, sa_family_t af, void *gw) req.set.r4.rta_dst.rta_type = RTA_DST; req.set.r4.rta_dst.rta_len = rta_len; - req.set.r4.a = *(uint32_t *)gw; + memcpy(&req.set.r4.a, gw, sizeof(req.set.r4.a)); req.set.r4.rta_gw.rta_type = RTA_GATEWAY; req.set.r4.rta_gw.rta_len = rta_len; } @@ -471,9 +471,9 @@ void nl_addr_set(unsigned int ifi, sa_family_t af, void *addr, int prefix_len) union { struct { struct rtattr rta_l; - uint32_t l; + struct in_addr l; struct rtattr rta_a; - uint32_t a; + struct in_addr a; } a4; struct { struct rtattr rta_l; @@ -517,7 +517,7 @@ void nl_addr_set(unsigned int ifi, sa_family_t af, void *addr, int prefix_len) req.nlh.nlmsg_len = offsetof(struct req_t, set.a4) + sizeof(req.set.a4); - req.set.a4.l = req.set.a4.a = *(uint32_t *)addr; + memcpy(&req.set.a4.l, addr, sizeof(req.set.a4.l)); req.set.a4.rta_l.rta_len = rta_len; req.set.a4.rta_l.rta_type = IFA_LOCAL; req.set.a4.rta_a.rta_len = rta_len; -- 2.41.0