From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=cSlKNAQi; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTPS id 1151A5A0271 for ; Mon, 03 Feb 2025 07:09:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1738562986; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cIDYhPlT+zzFwaZVGB2bFVfiGS66YMKVI+Os590Bjpw=; b=cSlKNAQijSuJ0z4nQnSwxa37SCwGCpScxSQQHYGDULPyOX1i4QEzIBxFav1wjDKH3Igtlg HGp86zMZk+sGAWjAXlVqIrqN6O9rgxNqRuQueFPKCIRdvhCvQyxFuESNhygFbDM8Ge1dha zPUiBz50vn7MVGDmGuU/cQLFWuj338o= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-214-X18dOyyUPxq4z-eIS3R0cw-1; Mon, 03 Feb 2025 01:09:44 -0500 X-MC-Unique: X18dOyyUPxq4z-eIS3R0cw-1 X-Mimecast-MFC-AGG-ID: X18dOyyUPxq4z-eIS3R0cw Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-436723db6c4so28352875e9.3 for ; Sun, 02 Feb 2025 22:09:44 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738562982; x=1739167782; h=content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=cIDYhPlT+zzFwaZVGB2bFVfiGS66YMKVI+Os590Bjpw=; b=HH2wy/F4NscE5fWFdHpwmXvexRAhb/a4fouVEHuqBYlylPg+5U+6Q4iJdgIKhQT7m5 uyBBiTwO71gc/NqxGjXbcYJvl1CD2rIufRuWjdXCxZzTzM5CCKsihR2q8/MYGoCKQuPP s1mV8B/TRKXwULVXV+JywJROcyDk7oixOOb+olb3o5y30mzAkIe7bcv0ahik0gdiqPIa c3E9kW+G/2q2AVtba/JwAsIwXUQKgTBpPrPm/yGN1PNbHFh0th9rV62T5jweIGGO+67M jjAai8KcpML/FMz3qyU+oUYne3VZ+N7pr8t5PkkZV9Fl1Srt0JferT7N4pOM776EB8dk sY3Q== X-Gm-Message-State: AOJu0YwMy4i1fiLqR3dTh4cfotRRPY0cgliDQf+ozIuaAh+0KrpoxfoK Tn/KZibn+PS9acQiUbmNaxIkiNC7NWeYEc1O2t8EliqaDXUqxKFqKqPfheVlPTaLuqdGbdl1qff Mq5KrBQ6LgdEw1IgNH2iuMjNQDNGxkZ6zsF2811DYwhNul8VLCBf3aBCJEQ== X-Gm-Gg: ASbGncurq665NkfqLymUpdiHnMgL0NW2W38qCyhQIlWnXqTUPZWAV5Qaf/2WbfJwTMx 9vFrZwzwNtN9gpvQB85pdceLkwq8o9FSOErAY9/WYZXfPFMocFXROB8ZofTiboiVO0PrHHBbsjq JUg6dl2yryo52nS0r7+FYl9RdjcSm2MOSs8uDQUOV9P9fVLxwYZX8btGVAzSVT9hlmem7JBCq4c w8GywTTS8ad8Qf7uIJP4XxlUho75oSPlJBFBupg/E2KmZPRRb0DnSbYxfrD9RUsFSJd/KN/D4wW 7DglBOvW0xmQUECr+n+mJS4tgI3nzK08JA== X-Received: by 2002:a05:600c:3488:b0:436:ed38:5c85 with SMTP id 5b1f17b1804b1-438dc3cbc24mr190065025e9.14.1738562982492; Sun, 02 Feb 2025 22:09:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IGcak5dwkV45ZYqXC5ZS6VcscvEpqZLD76Zg+0CbXBs8YFn5SfTUn3R7A2AeclGhUlLXmLrRA== X-Received: by 2002:a05:600c:3488:b0:436:ed38:5c85 with SMTP id 5b1f17b1804b1-438dc3cbc24mr190064885e9.14.1738562982095; Sun, 02 Feb 2025 22:09:42 -0800 (PST) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [176.103.220.4]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-438e23dea58sm141274935e9.15.2025.02.02.22.09.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Feb 2025 22:09:40 -0800 (PST) Date: Mon, 3 Feb 2025 07:09:37 +0100 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH v3 18/20] tcp: Get our socket port using getsockname() when connecting from guest Message-ID: <20250203070937.61c30df9@elisabeth> In-Reply-To: References: <20250131193953.3034031-1-sbrivio@redhat.com> <20250131193953.3034031-19-sbrivio@redhat.com> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.41; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 9Pt4PUswD6ZMiCLWobeQGbR0K7vi3YszNt_cgDLfagI_1738562983 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: W3WOGL4C5BRY6IQCFBBGGNSKUMV4OWB7 X-Message-ID-Hash: W3WOGL4C5BRY6IQCFBBGGNSKUMV4OWB7 X-MailFrom: sbrivio@redhat.com 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: passt-dev@passt.top, Laurent Vivier 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: On Mon, 3 Feb 2025 13:05:33 +1100 David Gibson wrote: > On Fri, Jan 31, 2025 at 08:39:51PM +0100, Stefano Brivio wrote: > > For migration only: we need to store 'oport', our socket-side port, > > as we establish a connection from the guest, so that we can bind the > > same oport as source port in the migration target. > > > > Use getsockname() to fetch that. > > > > Signed-off-by: Stefano Brivio > > --- > > flow.c | 4 ++-- > > flow_table.h | 4 ++-- > > tcp.c | 24 +++++++++++++++++++++++- > > 3 files changed, 27 insertions(+), 5 deletions(-) > > > > diff --git a/flow.c b/flow.c > > index 5638ff1..506cbac 100644 > > --- a/flow.c > > +++ b/flow.c > > @@ -411,8 +411,8 @@ const struct flowside *flow_initiate_sa(union flow *flow, uint8_t pif, > > * > > * Return: pointer to the target flowside information > > */ > > -const struct flowside *flow_target(const struct ctx *c, union flow *flow, > > - uint8_t proto) > > +struct flowside *flow_target(const struct ctx *c, union flow *flow, > > + uint8_t proto) > > { > > char estr[INANY_ADDRSTRLEN], fstr[INANY_ADDRSTRLEN]; > > struct flow_common *f = &flow->f; > > diff --git a/flow_table.h b/flow_table.h > > index 633805d..b107107 100644 > > --- a/flow_table.h > > +++ b/flow_table.h > > @@ -178,8 +178,8 @@ const struct flowside *flow_target_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_target(const struct ctx *c, union flow *flow, > > - uint8_t proto); > > +struct flowside *flow_target(const struct ctx *c, union flow *flow, > > + uint8_t proto); > > > > union flow *flow_set_type(union flow *flow, enum flow_type type); > > #define FLOW_SET_TYPE(flow_, t_, var_) (&flow_set_type((flow_), (t_))->var_) > > diff --git a/tcp.c b/tcp.c > > index 0bd2a02..4fd405b 100644 > > --- a/tcp.c > > +++ b/tcp.c > > @@ -1471,6 +1471,8 @@ static void tcp_bind_outbound(const struct ctx *c, > > * @opts: Pointer to start of options > > * @optlen: Bytes in options: caller MUST ensure available length > > * @now: Current timestamp > > + * > > + * #syscalls:vu getsockname > > */ > > static void tcp_conn_from_tap(const struct ctx *c, sa_family_t af, > > const void *saddr, const void *daddr, > > @@ -1479,9 +1481,10 @@ static void tcp_conn_from_tap(const struct ctx *c, sa_family_t af, > > { > > in_port_t srcport = ntohs(th->source); > > in_port_t dstport = ntohs(th->dest); > > - const struct flowside *ini, *tgt; > > + const struct flowside *ini; > > struct tcp_tap_conn *conn; > > union sockaddr_inany sa; > > + struct flowside *tgt; > > union flow *flow; > > int s = -1, mss; > > uint64_t hash; > > @@ -1586,6 +1589,25 @@ 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 */ > > I suspect we'll want this local side information in more places in > future, but this is fine for now. > > > + if (af == AF_INET) { > > + struct sockaddr_in s_in; > > + socklen_t sl; > > + > > + sl = sizeof(s_in); > > + getsockname(s, (struct sockaddr *)&s_in, &sl); > > + tgt->oport = ntohs(s_in.sin_port); > > Since we're already doing the getsockname() we should also update > tgt->oaddr, and that might matter in cases where the host has multiple > local addresses. I had that in a previous version, because I was actually restoring it as I thought it was needed, then I dropped it. We expect the configuration of the target to be the same as the source, so the same connect() should yield to the same source address being used (minus the fact that we don't set socket options yet (point 9. of the to-do list from cover letter). So should we really bind() to a specific source address just because we happen to know it? I'm not quite sure. > > + } else { > > + struct sockaddr_in6 s_in6; > > + socklen_t sl; > > + > > + sl = sizeof(s_in6); > > + getsockname(s, (struct sockaddr *)&s_in6, &sl); > > + tgt->oport = ntohs(s_in6.sin6_port); > > + } > > We should add an inany_getsockname() or something helper for this. In > fact I'm pretty sure I wrote one at some point, but it was lost in the > shuffles of various flow table iterations. I guess it can be a follow-up. Noted, anyway. -- Stefano