diff options
author | David Gibson <david@gibson.dropbear.id.au> | 2025-02-04 16:42:15 +1100 |
---|---|---|
committer | Stefano Brivio <sbrivio@redhat.com> | 2025-02-04 09:02:54 +0100 |
commit | 745c163e60b0e5da7bf6013645d79b4bdbf3e848 (patch) | |
tree | 5f883e1d96cdf0e1ab3ad5f3760b4ec186a6e914 | |
parent | b4a7b5d4a66db5f419cb5de87da3403cfba3847d (diff) | |
download | passt-745c163e60b0e5da7bf6013645d79b4bdbf3e848.tar passt-745c163e60b0e5da7bf6013645d79b4bdbf3e848.tar.gz passt-745c163e60b0e5da7bf6013645d79b4bdbf3e848.tar.bz2 passt-745c163e60b0e5da7bf6013645d79b4bdbf3e848.tar.lz passt-745c163e60b0e5da7bf6013645d79b4bdbf3e848.tar.xz passt-745c163e60b0e5da7bf6013645d79b4bdbf3e848.tar.zst passt-745c163e60b0e5da7bf6013645d79b4bdbf3e848.zip |
tcp: Simplify handling of getsockname()
For migration we need to get the specific local address and port for
connected sockets with getsockname(). We currently open code marshalling
the results into the flow entry.
However, we already have inany_from_sockaddr() which handles the fiddly
parts of this, so use it. Also report failures, which may make debugging
problems easier.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
[sbrivio: Drop re-declarations of 'sa' and 'sl']
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
-rw-r--r-- | tcp.c | 22 |
1 files changed, 5 insertions, 17 deletions
@@ -1535,24 +1535,12 @@ static void tcp_conn_from_tap(const struct ctx *c, sa_family_t af, tcp_epoll_ctl(c, conn); if (c->mode == MODE_VU) { /* To rebind to same oport after migration */ - if (af == AF_INET) { - struct sockaddr_in s_in; - - sl = sizeof(s_in); - if (!getsockname(s, (struct sockaddr *)&s_in, &sl)) { - /* NOLINTNEXTLINE(clang-analyzer-core.CallAndMessage) */ - tgt->oport = ntohs(s_in.sin_port); - tgt->oaddr = inany_from_v4(s_in.sin_addr); - } + sl = sizeof(sa); + if (!getsockname(s, &sa.sa, &sl)) { + inany_from_sockaddr(&tgt->oaddr, &tgt->oport, &sa); } else { - struct sockaddr_in6 s_in6; - - sl = sizeof(s_in6); - if (!getsockname(s, (struct sockaddr *)&s_in6, &sl)) { - /* NOLINTNEXTLINE(clang-analyzer-core.CallAndMessage) */ - tgt->oport = ntohs(s_in6.sin6_port); - tgt->oaddr.a6 = s_in6.sin6_addr; - } + err("Failed to get local address for socket: %s", + strerror_(errno)); } } |