From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from imap.gmail.com [173.194.76.109] by localhost with POP3 (fetchmail-6.3.26) for (single-drop); Tue, 21 May 2024 07:57:40 +0200 (CEST) Received: by 2002:a05:6a10:9148:b0:55f:c3c0:ed08 with SMTP id n8csp851879pxb; Mon, 20 May 2024 22:57:21 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUbgIKNMWcelkFLlwhSHDMpYCUq41ooIdjkdscdz2oN4Yns9AL/bENbghmj7STuGOIdHjqP4Cx2GEf4B+FzUZidAix+EPxGaBo= X-Google-Smtp-Source: AGHT+IGM8nwdPJ1RyJkZYxJR+coyRXg3mo/JcPzDUIM93Tz1bDn7DGKW1JybXDyANkrQTzOv/I+P X-Received: by 2002:a05:620a:2609:b0:793:19d6:7b57 with SMTP id af79cd13be357-79319d67e16mr1312701285a.65.1716271041271; Mon, 20 May 2024 22:57:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1716271041; cv=none; d=google.com; s=arc-20160816; b=oSXaqQ3UA4qAsQyRdhnQiR3s81ZpZ0gBaLStMYrTatXX+2Jz5Mf+PeGm1y0UKi5p8L XNUPjvYqkKVGaCmQv4UlCSa8PBr2i981Ti2N6zslGwq+mizwvQI7ec/yPSFyhdhHTBee QHymDCfuT7tOF18BbFYNs2Q5VuxTyzF++D9+bQe2J5rAFsQ9RGEaBom7w0f7LsYRbGjU 9uq95NaERlnbQB9Od6PSXv7VAdDwThr7UqjDbhtfGpwjgKK3UHfHEjoFZzogLxPIBXTU DEXkPTrkqCShpGxhSkFnoZ0FzoKwH3Fln+c25fVKawbMljBnyulwjWD6P24eRUBd76bG sqkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:delivered-to; bh=tKVBtTYqhFY4fV6mg0dNe1bfCmn2RexIAxUrTLrgoxk=; fh=OvZxoe0l5OQEr5hiks2YsWDyoZfSCuw/Wl/AnSjLRjU=; b=btNonsRnQHHzt2RQ+r9Nslk3cwirAS4NSsYPcDaGF+ppsSc9Mmc+eL6fbKiuKosQs7 YZHdRi1Kwp+UOtrz3JrBqWcXKzI8HZ/2vFUbXItKn4ElQVKOMHv+KiQM35tB5WDAm9+B v2afb7iSAcyrGnoyRn9vHkBeFw14j6Zcmpw0HDQIhc3EjT45ZnnHnSeLHH6zA5nVpaSf Yhg/GAkiOoig/tOM/YnSH5+uHz/xmNInzjcdlmBjy0fN80PaUAsOM1YsEXBslxQ7fEjl VoN7FXdpzJ4247ZiHT9g3FmuQXm2BAyV1FdEHTm4/WzNGZuifNAk7qd17HV9O32pgKkn GQAw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of dgibson@gandalf.ozlabs.org designates 150.107.74.76 as permitted sender) smtp.mailfrom=dgibson@gandalf.ozlabs.org Return-Path: Received: from us-smtp-inbound-delivery-1.mimecast.com (us-smtp-delivery-1.mimecast.com. [170.10.128.131]) by mx.google.com with ESMTPS id af79cd13be357-792bf361fc3si29419285a.565.2024.05.20.22.57.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 May 2024 22:57:21 -0700 (PDT) Received-SPF: pass (google.com: domain of dgibson@gandalf.ozlabs.org designates 150.107.74.76 as permitted sender) client-ip=150.107.74.76; Authentication-Results: mx.google.com; spf=pass (google.com: domain of dgibson@gandalf.ozlabs.org designates 150.107.74.76 as permitted sender) smtp.mailfrom=dgibson@gandalf.ozlabs.org Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-177-l4G0EUgwOVGj-9cZdMPKQA-1; Tue, 21 May 2024 01:57:19 -0400 X-MC-Unique: l4G0EUgwOVGj-9cZdMPKQA-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8B1611955F29 for ; Tue, 21 May 2024 05:57:18 +0000 (UTC) Received: by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) id 7AE1F1954AFE; Tue, 21 May 2024 05:57:18 +0000 (UTC) Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.46]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 7839B1954B06 for ; Tue, 21 May 2024 05:57:18 +0000 (UTC) Received: from us-smtp-inbound-delivery-1.mimecast.com (us-smtp-delivery-1.mimecast.com [170.10.128.131]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 24E991956088 for ; Tue, 21 May 2024 05:57:18 +0000 (UTC) Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-185-u2jVJUN1Nt-AV4_QRe5HAw-1; Tue, 21 May 2024 01:57:14 -0400 X-MC-Unique: u2jVJUN1Nt-AV4_QRe5HAw-1 Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4Vk3c56YFrz4x1Q; Tue, 21 May 2024 15:57:09 +1000 (AEST) From: David Gibson To: Stefano Brivio , passt-dev@passt.top Cc: David Gibson Subject: [PATCH 4/6] flow: Make side 0 always be the initiating side Date: Tue, 21 May 2024 15:57:06 +1000 Message-ID: <20240521055708.1150050-5-david@gibson.dropbear.id.au> In-Reply-To: <20240521055708.1150050-1-david@gibson.dropbear.id.au> References: <20240521055708.1150050-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition;Similar Internal Domain=false;Similar Monitored External Domain=false;Custom External Domain=false;Mimecast External Domain=false;Newly Observed Domain=false;Internal User Name=false;Custom Display Name List=false;Reply-to Address Mismatch=false;Targeted Threat Dictionary=false;Mimecast Threat Dictionary=false;Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: gibson.dropbear.id.au Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="US-ASCII"; x-default=true List-Id: Each flow in the flow table has two sides, 0 and 1, representing the two interfaces between which passt/pasta will forward data for that flow. Which side is which is currently up to the protocol specific code: TCP uses side 0 for the host/"sock" side and 1 for the guest/"tap" side, except for spliced connections where it uses 0 for the initiating side and 1 for the target side. ICMP also uses 0 for the host/"sock" side and 1 for the guest/"tap" side, but in its case the latter is always also the initiating side. Make this generically consistent by always using side 0 for the initiating side and 1 for the target side. This doesn't simplify a lot for now, and arguably makes TCP slightly more complex, since we add an extra field to the connection structure to record which is the guest facing side. This is an interim change, which we'll be able to remove later. Signed-off-by: David Gibson q --- flow.c | 5 +---- flow.h | 5 +++++ flow_table.h | 6 ++---- icmp.c | 8 ++------ tcp.c | 19 ++++++++----------- tcp_conn.h | 3 ++- tcp_splice.c | 2 +- 7 files changed, 21 insertions(+), 27 deletions(-) diff --git a/flow.c b/flow.c index da71fe10..91c00465 100644 --- a/flow.c +++ b/flow.c @@ -152,12 +152,10 @@ static void flow_set_state(struct flow_common *f, enu= m flow_state state) * flow_set_type() - Set type and move to TYPED * @flow:=09Flow to change state * @type:=09Type for new flow - * @iniside:=09Which side initiated the new flow * * Return: @flow */ -union flow *flow_set_type(union flow *flow, enum flow_type type, -=09=09=09 unsigned iniside) +union flow *flow_set_type(union flow *flow, enum flow_type type) { =09struct flow_common *f =3D &flow->f; =20 @@ -165,7 +163,6 @@ union flow *flow_set_type(union flow *flow, enum flow_t= ype type, =09ASSERT(flow_new_entry =3D=3D flow && f->state =3D=3D FLOW_STATE_NEW); =09ASSERT(f->type =3D=3D FLOW_TYPE_NONE); =20 -=09(void)iniside; =09f->type =3D type; =09flow_set_state(f, FLOW_STATE_TYPED); =09return flow; diff --git a/flow.h b/flow.h index e61d35e8..95309389 100644 --- a/flow.h +++ b/flow.h @@ -100,6 +100,11 @@ extern const uint8_t flow_proto[]; #define FLOW_PROTO(f)=09=09=09=09\ =09((f)->type < FLOW_NUM_TYPES ? flow_proto[(f)->type] : 0) =20 +#define SIDES=09=09=092 + +#define INISIDE=09=09=090=09/* Initiating side */ +#define TGTSIDE=09=09=091=09/* Target side */ + /** * struct flow_common - Common fields for packet flows * @state:=09State of the flow table entry diff --git a/flow_table.h b/flow_table.h index 17b9ea70..28e36b9a 100644 --- a/flow_table.h +++ b/flow_table.h @@ -107,10 +107,8 @@ static inline flow_sidx_t flow_sidx(const struct flow_= common *f, union flow *flow_alloc(void); void flow_alloc_cancel(union flow *flow); =20 -union flow *flow_set_type(union flow *flow, enum flow_type type, -=09=09=09 unsigned iniside); -#define FLOW_SET_TYPE(flow_, t_, var_, i_)=09\ -=09(&flow_set_type((flow_), (t_), (i_))->var_) +union flow *flow_set_type(union flow *flow, enum flow_type type); +#define FLOW_SET_TYPE(flow_, t_, var_)=09(&flow_set_type((flow_), (t_))->v= ar_) =20 void flow_activate(struct flow_common *f); #define FLOW_ACTIVATE(flow_)=09=09=09\ diff --git a/icmp.c b/icmp.c index fc729557..3567ad7e 100644 --- a/icmp.c +++ b/icmp.c @@ -45,10 +45,6 @@ #define ICMP_ECHO_TIMEOUT=0960 /* s, timeout for ICMP socket activity */ #define ICMP_NUM_IDS=09=09(1U << 16) =20 -/* Sides of a flow as we use them for ping streams */ -#define=09SOCKSIDE=090 -#define=09TAPSIDE=09=091 - #define PINGF(idx)=09=09(&(FLOW(idx)->ping)) =20 /* Indexed by ICMP echo identifier */ @@ -167,7 +163,7 @@ static struct icmp_ping_flow *icmp_ping_new(const struc= t ctx *c, =09if (!flow) =09=09return NULL; =20 -=09pingf =3D FLOW_SET_TYPE(flow, flowtype, ping, TAPSIDE); +=09pingf =3D FLOW_SET_TYPE(flow, flowtype, ping); =20 =09pingf->seq =3D -1; =09pingf->id =3D id; @@ -180,7 +176,7 @@ static struct icmp_ping_flow *icmp_ping_new(const struc= t ctx *c, =09=09bind_if =3D c->ip6.ifname_out; =09} =20 -=09ref.flowside =3D FLOW_SIDX(flow, SOCKSIDE); +=09ref.flowside =3D FLOW_SIDX(flow, TGTSIDE); =09pingf->sock =3D sock_l4(c, af, flow_proto[flowtype], bind_addr, bind_if= , =09=09=09 0, ref.data); =20 diff --git a/tcp.c b/tcp.c index 64fe46e0..0313dcb9 100644 --- a/tcp.c +++ b/tcp.c @@ -303,10 +303,6 @@ =20 #include "flow_table.h" =20 -/* Sides of a flow as we use them in "tap" connections */ -#define=09SOCKSIDE=090 -#define=09TAPSIDE=09=091 - #define TCP_FRAMES_MEM=09=09=09128 #define TCP_FRAMES=09=09=09=09=09=09=09\ =09(c->mode =3D=3D MODE_PASST ? TCP_FRAMES_MEM : 1) @@ -581,7 +577,7 @@ static int tcp_epoll_ctl(const struct ctx *c, struct tc= p_tap_conn *conn) { =09int m =3D conn->in_epoll ? EPOLL_CTL_MOD : EPOLL_CTL_ADD; =09union epoll_ref ref =3D { .type =3D EPOLL_TYPE_TCP, .fd =3D conn->sock, -=09=09=09=09.flowside =3D FLOW_SIDX(conn, SOCKSIDE) }; +=09=09=09=09.flowside =3D FLOW_SIDX(conn, !conn->tapside), }; =09struct epoll_event ev =3D { .data.u64 =3D ref.u64 }; =20 =09if (conn->events =3D=3D CLOSED) { @@ -1134,7 +1130,7 @@ static uint64_t tcp_conn_hash(const struct ctx *c, static inline unsigned tcp_hash_probe(const struct ctx *c, =09=09=09=09 const struct tcp_tap_conn *conn) { -=09flow_sidx_t sidx =3D FLOW_SIDX(conn, TAPSIDE); +=09flow_sidx_t sidx =3D FLOW_SIDX(conn, conn->tapside); =09unsigned b =3D tcp_conn_hash(c, conn) % TCP_HASH_TABLE_SIZE; =20 =09/* Linear probing */ @@ -1154,7 +1150,7 @@ static void tcp_hash_insert(const struct ctx *c, stru= ct tcp_tap_conn *conn) { =09unsigned b =3D tcp_hash_probe(c, conn); =20 -=09tc_hash[b] =3D FLOW_SIDX(conn, TAPSIDE); +=09tc_hash[b] =3D FLOW_SIDX(conn, conn->tapside); =09flow_dbg(conn, "hash table insert: sock %i, bucket: %u", conn->sock, b)= ; } =20 @@ -2004,7 +2000,8 @@ static void tcp_conn_from_tap(struct ctx *c, sa_famil= y_t af, =09=09=09goto cancel; =09} =20 -=09conn =3D FLOW_SET_TYPE(flow, FLOW_TCP, tcp, TAPSIDE); +=09conn =3D FLOW_SET_TYPE(flow, FLOW_TCP, tcp); +=09conn->tapside =3D INISIDE; =09conn->sock =3D s; =09conn->timer =3D -1; =09conn_event(c, conn, TAP_SYN_RCVD); @@ -2716,9 +2713,9 @@ static void tcp_tap_conn_from_sock(struct ctx *c, in_= port_t dstport, =09=09=09=09 const union sockaddr_inany *sa, =09=09=09=09 const struct timespec *now) { -=09struct tcp_tap_conn *conn =3D FLOW_SET_TYPE(flow, FLOW_TCP, tcp, -=09=09=09=09=09=09 SOCKSIDE); +=09struct tcp_tap_conn *conn =3D FLOW_SET_TYPE(flow, FLOW_TCP, tcp); =20 +=09conn->tapside =3D TGTSIDE; =09conn->sock =3D s; =09conn->timer =3D -1; =09conn->ws_to_tap =3D conn->ws_from_tap =3D 0; @@ -2875,7 +2872,7 @@ void tcp_sock_handler(struct ctx *c, union epoll_ref = ref, uint32_t events) =09struct tcp_tap_conn *conn =3D CONN(ref.flowside.flow); =20 =09ASSERT(conn->f.type =3D=3D FLOW_TCP); -=09ASSERT(ref.flowside.side =3D=3D SOCKSIDE); +=09ASSERT(ref.flowside.side =3D=3D !conn->tapside); =20 =09if (conn->events =3D=3D CLOSED) =09=09return; diff --git a/tcp_conn.h b/tcp_conn.h index 52bd8156..e8c51c34 100644 --- a/tcp_conn.h +++ b/tcp_conn.h @@ -13,6 +13,7 @@ * struct tcp_tap_conn - Descriptor for a TCP connection (not spliced) * @f:=09=09=09Generic flow information * @in_epoll:=09=09Is the connection in the epoll set? + * @tapside:=09=09Which side of the flow faces the tap/guest interface * @tap_mss:=09=09MSS advertised by tap/guest, rounded to 2 ^ TCP_MSS_BITS * @sock:=09=09Socket descriptor number * @events:=09=09Connection events, implying connection states @@ -39,6 +40,7 @@ struct tcp_tap_conn { =09struct flow_common f; =20 =09bool=09=09in_epoll=09:1; +=09unsigned=09tapside=09=09:1; =20 #define TCP_RETRANS_BITS=09=093 =09unsigned int=09retrans=09=09:TCP_RETRANS_BITS; @@ -106,7 +108,6 @@ struct tcp_tap_conn { =09uint32_t=09seq_init_from_tap; }; =20 -#define SIDES=09=09=092 /** * struct tcp_splice_conn - Descriptor for a spliced TCP connection * @f:=09=09=09Generic flow information diff --git a/tcp_splice.c b/tcp_splice.c index 852a93b4..31e21732 100644 --- a/tcp_splice.c +++ b/tcp_splice.c @@ -471,7 +471,7 @@ bool tcp_splice_conn_from_sock(const struct ctx *c, =09=09return false; =09} =20 -=09conn =3D FLOW_SET_TYPE(flow, FLOW_TCP_SPLICE, tcp_splice, 0); +=09conn =3D FLOW_SET_TYPE(flow, FLOW_TCP_SPLICE, tcp_splice); =20 =09conn->flags =3D af =3D=3D AF_INET ? 0 : SPLICE_V6; =09conn->s[0] =3D s0; --=20 2.45.1