From: David Gibson <david@gibson.dropbear.id.au>
To: Stefano Brivio <sbrivio@redhat.com>, passt-dev@passt.top
Cc: David Gibson <david@gibson.dropbear.id.au>
Subject: [PATCH 2/8] treewide: Use IN4ADDR_LOOPBACK_INIT more widely
Date: Fri, 8 Dec 2023 01:31:34 +1100 [thread overview]
Message-ID: <20231207143140.1851378-3-david@gibson.dropbear.id.au> (raw)
In-Reply-To: <20231207143140.1851378-1-david@gibson.dropbear.id.au>
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 <david@gibson.dropbear.id.au>
---
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);
--
@@ -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
next prev parent reply other threads:[~2023-12-07 14:31 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-07 14:31 [PATCH 0/8] Small cleanups related to addresses and binding David Gibson
2023-12-07 14:31 ` [PATCH 1/8] tcp: Fix address type for tcp_sock_init_af() David Gibson
2023-12-27 20:25 ` Stefano Brivio
2023-12-28 2:42 ` David Gibson
2023-12-28 10:11 ` Stefano Brivio
2024-01-07 5:35 ` David Gibson
2024-01-13 22:50 ` Stefano Brivio
2023-12-07 14:31 ` David Gibson [this message]
2023-12-07 14:31 ` [PATCH 3/8] treewide: Add IN4ADDR_ANY_INIT macro David Gibson
2023-12-07 14:31 ` [PATCH 4/8] util: Use htonl_constant() in more places David Gibson
2023-12-07 14:31 ` [PATCH 5/8] util: Improve sockaddr initialisation in sock_l4() David Gibson
2023-12-27 20:25 ` Stefano Brivio
2024-01-07 5:34 ` David Gibson
2023-12-07 14:31 ` [PATCH 6/8] icmp: Avoid unnecessary handling of unspecified bind address David Gibson
2023-12-07 14:31 ` [PATCH 7/8] treewide: Avoid in_addr_t David Gibson
2023-12-07 14:31 ` [PATCH 8/8] util: Make sock_l4() treat empty string ifname like NULL David Gibson
2023-12-27 20:25 ` [PATCH 0/8] Small cleanups related to addresses and binding Stefano Brivio
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231207143140.1851378-3-david@gibson.dropbear.id.au \
--to=david@gibson.dropbear.id.au \
--cc=passt-dev@passt.top \
--cc=sbrivio@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://passt.top/passt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).