From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id C36895A027C for ; Thu, 7 Dec 2023 15:31:50 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1701959502; bh=KLDndQX+Or34xbj1WeypOdmVHrHRpaY7OpzQRj0NHiY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qnZjvf5pyu9+xycqd4gA+ck3OzkahZ5Fd1FNDBcqO7UQWzqx9EYvrmUfXJn7T0w2+ SxOUt23EKOdCxJZCVB1rxcmWjtU8MbRA4IlkgvolD2GQMef9lPiM9gsUNE4DI6xq5y eJ0sGxEhdhJhOB+phLG0s4qzbUQMGmukBT5cWa3FAeMS7lFfrFiPGrKvoeYbM10rm7 4Qdu/rWTbyxG8b+fJOLknyHWQVbfykoEf5G0Rnqja2rEKmQJSQExN+3BJ3jswwTyf4 6eojo9COySi/owTnCcX5Z4xyCtmObfNo+m2plAN3aFLi8OLiNJln7BmgyTEk+O3viA D7NSplOi62jZw== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4SmGtQ24pkz4xPc; Fri, 8 Dec 2023 01:31:42 +1100 (AEDT) From: David Gibson To: Stefano Brivio , passt-dev@passt.top Subject: [PATCH 7/8] treewide: Avoid in_addr_t Date: Fri, 8 Dec 2023 01:31:39 +1100 Message-ID: <20231207143140.1851378-8-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231207143140.1851378-1-david@gibson.dropbear.id.au> References: <20231207143140.1851378-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: RZQVXMS43L4XLOPPFO2AOMJYNQ3TNJ3W X-Message-ID-Hash: RZQVXMS43L4XLOPPFO2AOMJYNQ3TNJ3W 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: IPv4 addresses can be stored in an in_addr_t or a struct in_addr. The former is just a type alias to a 32-bit integer, so doesn't really give us any type checking. Therefore we generally prefer the structure, since we mostly want to treat IP address as opaque objects. Fix a few places where we still use in_addr_t, but can just as easily use struct in_addr. Note there are still some uses of in_addr_t in conf.c, but those are justified: since they're doing prefix calculations, they actually need to look at the internals of the address as an integer. Signed-off-by: David Gibson --- udp.c | 4 ++-- util.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/udp.c b/udp.c index 489a843..f6e8b37 100644 --- a/udp.c +++ b/udp.c @@ -866,8 +866,8 @@ int udp_tap_handler(struct ctx *c, uint8_t pif, debug("UDP from tap src=%hu dst=%hu, s=%d", src, dst, udp_tap_map[V4][src].sock); if ((s = udp_tap_map[V4][src].sock) < 0) { + struct in_addr bind_addr = IN4ADDR_ANY_INIT; union udp_epoll_ref uref = { .port = src }; - in_addr_t bind_addr = { 0 }; const char *bind_if = NULL; if (!IN6_IS_ADDR_LOOPBACK(&s_in.sin_addr) && @@ -876,7 +876,7 @@ int udp_tap_handler(struct ctx *c, uint8_t pif, if (!IN4_IS_ADDR_UNSPECIFIED(&c->ip4.addr_out) && !IN4_IS_ADDR_LOOPBACK(&s_in.sin_addr)) - bind_addr = c->ip4.addr_out.s_addr; + bind_addr = c->ip4.addr_out; s = sock_l4(c, AF_INET, IPPROTO_UDP, &bind_addr, bind_if, src, uref.u32); diff --git a/util.c b/util.c index 0152ae6..4de7b96 100644 --- a/util.c +++ b/util.c @@ -161,7 +161,7 @@ int sock_l4(const struct ctx *c, int af, uint8_t proto, if (af == AF_INET) { if (bind_addr) - addr4.sin_addr.s_addr = *(in_addr_t *)bind_addr; + addr4.sin_addr = *(struct in_addr *)bind_addr; sa = (const struct sockaddr *)&addr4; sl = sizeof(addr4); -- 2.43.0