From: David Gibson <david@gibson.dropbear.id.au>
To: passt-dev@passt.top, Stefano Brivio <sbrivio@redhat.com>
Cc: David Gibson <david@gibson.dropbear.id.au>
Subject: [PATCH v18 5/9] tcp: Get bound address for connected inbound sockets too
Date: Wed, 12 Feb 2025 18:07:17 +1100 [thread overview]
Message-ID: <20250212070721.1746128-6-david@gibson.dropbear.id.au> (raw)
In-Reply-To: <20250212070721.1746128-1-david@gibson.dropbear.id.au>
From: Stefano Brivio <sbrivio@redhat.com>
So that we can bind inbound sockets to specific addresses, like we
already do for outbound sockets.
While at it, change the error message in tcp_conn_from_tap() to match
this one.
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
flow.c | 6 +++---
flow_table.h | 6 +++---
tcp.c | 22 ++++++++++++++--------
3 files changed, 20 insertions(+), 14 deletions(-)
diff --git a/flow.c b/flow.c
index a6fe6d1f..3ac551bd 100644
--- a/flow.c
+++ b/flow.c
@@ -390,9 +390,9 @@ const struct flowside *flow_initiate_af(union flow *flow, uint8_t pif,
*
* Return: pointer to the initiating flowside information
*/
-const struct flowside *flow_initiate_sa(union flow *flow, uint8_t pif,
- const union sockaddr_inany *ssa,
- in_port_t dport)
+struct flowside *flow_initiate_sa(union flow *flow, uint8_t pif,
+ const union sockaddr_inany *ssa,
+ in_port_t dport)
{
struct flowside *ini = &flow->f.side[INISIDE];
diff --git a/flow_table.h b/flow_table.h
index eeb6f411..9a2ff24a 100644
--- a/flow_table.h
+++ b/flow_table.h
@@ -161,9 +161,9 @@ const struct flowside *flow_initiate_af(union flow *flow, uint8_t pif,
sa_family_t af,
const void *saddr, in_port_t sport,
const void *daddr, in_port_t dport);
-const struct flowside *flow_initiate_sa(union flow *flow, uint8_t pif,
- const union sockaddr_inany *ssa,
- in_port_t dport);
+struct flowside *flow_initiate_sa(union flow *flow, uint8_t pif,
+ const union sockaddr_inany *ssa,
+ in_port_t dport);
const struct flowside *flow_target_af(union flow *flow, uint8_t pif,
sa_family_t af,
const void *saddr, in_port_t sport,
diff --git a/tcp.c b/tcp.c
index b87478f3..a1d6c53b 100644
--- a/tcp.c
+++ b/tcp.c
@@ -1536,12 +1536,10 @@ static void tcp_conn_from_tap(const struct ctx *c, sa_family_t af,
if (c->mode == MODE_VU) { /* To rebind to same oport after migration */
sl = sizeof(sa);
- if (!getsockname(s, &sa.sa, &sl)) {
+ if (!getsockname(s, &sa.sa, &sl))
inany_from_sockaddr(&tgt->oaddr, &tgt->oport, &sa);
- } else {
- err("Failed to get local address for socket: %s",
- strerror_(errno));
- }
+ else
+ err_perror("Can't get local address for socket %i", s);
}
FLOW_ACTIVATE(conn);
@@ -2075,9 +2073,9 @@ static void tcp_tap_conn_from_sock(const struct ctx *c, union flow *flow,
void tcp_listen_handler(const struct ctx *c, union epoll_ref ref,
const struct timespec *now)
{
- const struct flowside *ini;
union sockaddr_inany sa;
socklen_t sl = sizeof(sa);
+ struct flowside *ini;
union flow *flow;
int s;
@@ -2093,12 +2091,20 @@ void tcp_listen_handler(const struct ctx *c, union epoll_ref ref,
tcp_sock_set_bufsize(c, s);
tcp_sock_set_nodelay(s);
- /* FIXME: When listening port has a specific bound address, record that
- * as our address
+ /* FIXME: If useful: when the listening port has a specific bound
+ * address, record that as our address, as implemented for vhost-user
+ * mode only, below.
*/
ini = flow_initiate_sa(flow, ref.tcp_listen.pif, &sa,
ref.tcp_listen.port);
+ if (c->mode == MODE_VU) { /* Rebind to same address after migration */
+ if (!getsockname(s, &sa.sa, &sl))
+ inany_from_sockaddr(&ini->oaddr, &ini->oport, &sa);
+ else
+ err_perror("Can't get local address for socket %i", s);
+ }
+
if (!inany_is_unicast(&ini->eaddr) || ini->eport == 0) {
char sastr[SOCKADDR_STRLEN];
--
@@ -1536,12 +1536,10 @@ static void tcp_conn_from_tap(const struct ctx *c, sa_family_t af,
if (c->mode == MODE_VU) { /* To rebind to same oport after migration */
sl = sizeof(sa);
- if (!getsockname(s, &sa.sa, &sl)) {
+ if (!getsockname(s, &sa.sa, &sl))
inany_from_sockaddr(&tgt->oaddr, &tgt->oport, &sa);
- } else {
- err("Failed to get local address for socket: %s",
- strerror_(errno));
- }
+ else
+ err_perror("Can't get local address for socket %i", s);
}
FLOW_ACTIVATE(conn);
@@ -2075,9 +2073,9 @@ static void tcp_tap_conn_from_sock(const struct ctx *c, union flow *flow,
void tcp_listen_handler(const struct ctx *c, union epoll_ref ref,
const struct timespec *now)
{
- const struct flowside *ini;
union sockaddr_inany sa;
socklen_t sl = sizeof(sa);
+ struct flowside *ini;
union flow *flow;
int s;
@@ -2093,12 +2091,20 @@ void tcp_listen_handler(const struct ctx *c, union epoll_ref ref,
tcp_sock_set_bufsize(c, s);
tcp_sock_set_nodelay(s);
- /* FIXME: When listening port has a specific bound address, record that
- * as our address
+ /* FIXME: If useful: when the listening port has a specific bound
+ * address, record that as our address, as implemented for vhost-user
+ * mode only, below.
*/
ini = flow_initiate_sa(flow, ref.tcp_listen.pif, &sa,
ref.tcp_listen.port);
+ if (c->mode == MODE_VU) { /* Rebind to same address after migration */
+ if (!getsockname(s, &sa.sa, &sl))
+ inany_from_sockaddr(&ini->oaddr, &ini->oport, &sa);
+ else
+ err_perror("Can't get local address for socket %i", s);
+ }
+
if (!inany_is_unicast(&ini->eaddr) || ini->eport == 0) {
char sastr[SOCKADDR_STRLEN];
--
2.48.1
next prev parent reply other threads:[~2025-02-12 7:07 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-12 7:07 [PATCH v18 0/9] State migration (kinda draft again) David Gibson
2025-02-12 7:07 ` [PATCH v18 1/9] migrate: Skeleton of live migration logic David Gibson
2025-02-12 7:07 ` [PATCH v18 2/9] migrate: Migrate guest observed addresses David Gibson
2025-02-12 7:07 ` [PATCH v18 3/9] Add interfaces and configuration bits for passt-repair David Gibson
2025-02-12 7:07 ` [PATCH v18 4/9] vhost_user: Make source quit after reporting migration state David Gibson
2025-02-12 7:07 ` David Gibson [this message]
2025-02-12 7:07 ` [PATCH v18 6/9] migrate: Migrate TCP flows David Gibson
2025-02-12 7:07 ` [PATCH v18 7/9] rampstream: Add utility to test for corruption of data streams David Gibson
2025-02-12 19:44 ` Stefano Brivio
2025-02-12 7:07 ` [PATCH v18 8/9] test: Add migration tests David Gibson
2025-02-12 7:07 ` [PATCH v18 9/9] debug David Gibson
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=20250212070721.1746128-6-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).