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 835DC5A026D for ; Thu, 7 Dec 2023 15:31:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1701959502; bh=Y/mPcY0GD9eZ4xpHrT7Iskgy9vRXz35BjU1U551Nfps=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fSlhLIQLL09ZBZ32Av8w5kAUURL5NFeV/N4PVpAgoexSKz/78VBEIZR/2eeyImEUm QCh8KwI4Ma5AVrvedye88TQlUv9GnYp2BGGJEFe8sOhAfGXTsKyMTmt2ozlRrhzzql QTyJEWFDQ+jVXMyG1FpMmIL7i386pfc7yZ2Igaxj76sVWOAbBn2vwt2bs+inYM4Xf+ VCG9VRlC51rdbyFwdSPAAPSWQb9ayTBS/VlQuejAJrdcKFDS/8JKyw6gvnEBk+5Rmv cPKpD+QsOGk/citAy/z66RWlcLvLRokYDdqV2asmK7QMGiJ3YQM1njFfKAJlz8Nj08 OPPwRlcbChGWg== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4SmGtQ1Lmlz4xNG; Fri, 8 Dec 2023 01:31:42 +1100 (AEDT) From: David Gibson To: Stefano Brivio , passt-dev@passt.top Subject: [PATCH 2/8] treewide: Use IN4ADDR_LOOPBACK_INIT more widely Date: Fri, 8 Dec 2023 01:31:34 +1100 Message-ID: <20231207143140.1851378-3-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: D4IOSAD7JUWU5E2SAPW4LV2FU2L4DCDY X-Message-ID-Hash: D4IOSAD7JUWU5E2SAPW4LV2FU2L4DCDY 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: We already define IN4ADDR_LOOPBACK_INIT to initialise a struct in_addr to the loopback address without delving into its internals. However there are some places we don't use it, and explicitly look at the internal structure of struct in_addr, which we generally want to avoid. Use the define more widely to avoid that. Signed-off-by: David Gibson --- tcp.c | 2 +- tcp_splice.c | 2 +- udp.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tcp.c b/tcp.c index bda95b2..466b0ca 100644 --- a/tcp.c +++ b/tcp.c @@ -2973,7 +2973,7 @@ static void tcp_ns_sock_init4(const struct ctx *c, in_port_t port) .port = port + c->tcp.fwd_out.delta[port], .pif = PIF_SPLICE, }; - struct in_addr loopback = { htonl(INADDR_LOOPBACK) }; + struct in_addr loopback = IN4ADDR_LOOPBACK_INIT; int s; ASSERT(c->mode == MODE_PASTA); diff --git a/tcp_splice.c b/tcp_splice.c index 69ea79d..1655f8e 100644 --- a/tcp_splice.c +++ b/tcp_splice.c @@ -347,7 +347,7 @@ static int tcp_splice_connect(const struct ctx *c, struct tcp_splice_conn *conn, struct sockaddr_in addr4 = { .sin_family = AF_INET, .sin_port = htons(port), - .sin_addr = { .s_addr = htonl(INADDR_LOOPBACK) }, + .sin_addr = IN4ADDR_LOOPBACK_INIT, }; const struct sockaddr *sa; socklen_t sl; diff --git a/udp.c b/udp.c index 1f8c306..489a843 100644 --- a/udp.c +++ b/udp.c @@ -429,7 +429,7 @@ int udp_splice_new(const struct ctx *c, int v6, in_port_t src, bool ns) struct sockaddr_in addr4 = { .sin_family = AF_INET, .sin_port = htons(src), - .sin_addr = { .s_addr = htonl(INADDR_LOOPBACK) }, + .sin_addr = IN4ADDR_LOOPBACK_INIT, }; if (bind(s, (struct sockaddr *)&addr4, sizeof(addr4))) goto fail; @@ -1012,7 +1012,7 @@ int udp_sock_init(const struct ctx *c, int ns, sa_family_t af, udp_tap_map[V4][uref.port].sock = s < 0 ? -1 : s; udp_splice_init[V4][port].sock = s < 0 ? -1 : s; } else { - struct in_addr loopback = { htonl(INADDR_LOOPBACK) }; + struct in_addr loopback = IN4ADDR_LOOPBACK_INIT; r4 = s = sock_l4(c, AF_INET, IPPROTO_UDP, &loopback, ifname, port, uref.u32); -- 2.43.0