From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 6246C5A032A for ; Thu, 18 Jul 2024 07:27:11 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1721280419; bh=eyLxaD2fKBPv1+GN0EADGFjDK2MoacURQZpmpmMPzrA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PO+Hz9B9wf2xMtniIo3/J2nhECWEPUf/e+Dr+Hv/4NwZIJB0W8UHSa2CLT/WvAlRX Uosok61Qmtg78tOakufyFsNzuf8oHb28XdK0yMC3I4i87my4rQ+qWKnGCW6cFO5sbL 99hN4qWq8alPEdLgiL8tssVtgS7H+Sm+X4LZ8ITP+Am9yneI8RFZLJ+uIdWE5XVVls RrzuJEXny6Uqxm7glXSVhlRPB+bF1eBCOszvqF1PQfXbsx7EnrPYZ3bsYOlm7hu8sy 9vNVJA8cdpnycG2vyv+P1rOVQnVbA52IMIxTNTCxPpDcdk5MnpslDRhTctY4G+cBcj gAAHWmu9O+7/A== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4WPhBW0vCYz4x7D; Thu, 18 Jul 2024 15:26:59 +1000 (AEST) From: David Gibson To: Stefano Brivio , passt-dev@passt.top Subject: [PATCH v8 22/27] udp: Remove obsolete splice tracking Date: Thu, 18 Jul 2024 15:26:48 +1000 Message-ID: <20240718052653.3241585-23-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240718052653.3241585-1-david@gibson.dropbear.id.au> References: <20240718052653.3241585-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: D735HYTRLDZAUYC4CD45YJ5BBECHQBRJ X-Message-ID-Hash: D735HYTRLDZAUYC4CD45YJ5BBECHQBRJ X-MailFrom: dgibson@gandalf.ozlabs.org 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: jmaloy@redhat.com, David Gibson 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: Now that spliced datagrams are managed via the flow table, remove UDP_ACT_SPLICE_NS and UDP_ACT_SPLICE_INIT which are no longer used. With those removed, the 'ts' field in udp_splice_port is also no longer used. struct udp_splice_port now contains just a socket fd, so replace it with a plain int in udp_splice_ns[] and udp_splice_init[]. The latter are still used for tracking of automatic port forwarding. Finally, the 'splice' field of union udp_epoll_ref is no longer used so remove it as well. Signed-off-by: David Gibson --- udp.c | 65 +++++++++++++++++------------------------------------------ udp.h | 5 +---- 2 files changed, 19 insertions(+), 51 deletions(-) diff --git a/udp.c b/udp.c index 5543e614..b459b109 100644 --- a/udp.c +++ b/udp.c @@ -150,27 +150,15 @@ struct udp_tap_port { time_t ts; }; -/** - * struct udp_splice_port - Bound socket for spliced communication - * @sock: Socket bound to index port - * @ts: Activity timestamp - */ -struct udp_splice_port { - int sock; - time_t ts; -}; - /* Port tracking, arrays indexed by packet source port (host order) */ static struct udp_tap_port udp_tap_map [IP_VERSIONS][NUM_PORTS]; /* "Spliced" sockets indexed by bound port (host order) */ -static struct udp_splice_port udp_splice_ns [IP_VERSIONS][NUM_PORTS]; -static struct udp_splice_port udp_splice_init[IP_VERSIONS][NUM_PORTS]; +static int udp_splice_ns [IP_VERSIONS][NUM_PORTS]; +static int udp_splice_init[IP_VERSIONS][NUM_PORTS]; enum udp_act_type { UDP_ACT_TAP, - UDP_ACT_SPLICE_NS, - UDP_ACT_SPLICE_INIT, UDP_ACT_TYPE_MAX, }; @@ -260,8 +248,8 @@ void udp_portmap_clear(void) for (i = 0; i < NUM_PORTS; i++) { udp_tap_map[V4][i].sock = udp_tap_map[V6][i].sock = -1; - udp_splice_ns[V4][i].sock = udp_splice_ns[V6][i].sock = -1; - udp_splice_init[V4][i].sock = udp_splice_init[V6][i].sock = -1; + udp_splice_ns[V4][i] = udp_splice_ns[V6][i] = -1; + udp_splice_init[V4][i] = udp_splice_init[V6][i] = -1; } } @@ -1142,8 +1130,7 @@ int udp_tap_handler(struct ctx *c, uint8_t pif, int udp_sock_init(const struct ctx *c, int ns, sa_family_t af, const void *addr, const char *ifname, in_port_t port) { - union udp_epoll_ref uref = { .splice = (c->mode == MODE_PASTA), - .orig = true, .port = port }; + union udp_epoll_ref uref = { .orig = true, .port = port }; int s, r4 = FD_REF_MAX + 1, r6 = FD_REF_MAX + 1; ASSERT(!c->no_udp); @@ -1161,12 +1148,12 @@ int udp_sock_init(const struct ctx *c, int ns, sa_family_t af, ifname, port, uref.u32); udp_tap_map[V4][port].sock = s < 0 ? -1 : s; - udp_splice_init[V4][port].sock = s < 0 ? -1 : s; + udp_splice_init[V4][port] = s < 0 ? -1 : s; } else { r4 = s = sock_l4(c, AF_INET, EPOLL_TYPE_UDP, &in4addr_loopback, ifname, port, uref.u32); - udp_splice_ns[V4][port].sock = s < 0 ? -1 : s; + udp_splice_ns[V4][port] = s < 0 ? -1 : s; } } @@ -1178,12 +1165,12 @@ int udp_sock_init(const struct ctx *c, int ns, sa_family_t af, ifname, port, uref.u32); udp_tap_map[V6][port].sock = s < 0 ? -1 : s; - udp_splice_init[V6][port].sock = s < 0 ? -1 : s; + udp_splice_init[V6][port] = s < 0 ? -1 : s; } else { r6 = s = sock_l4(c, AF_INET6, EPOLL_TYPE_UDP, &in6addr_loopback, ifname, port, uref.u32); - udp_splice_ns[V6][port].sock = s < 0 ? -1 : s; + udp_splice_ns[V6][port] = s < 0 ? -1 : s; } } @@ -1224,7 +1211,6 @@ static void udp_splice_iov_init(void) static void udp_timer_one(struct ctx *c, int v6, enum udp_act_type type, in_port_t port, const struct timespec *now) { - struct udp_splice_port *sp; struct udp_tap_port *tp; int *sockp = NULL; @@ -1237,20 +1223,6 @@ static void udp_timer_one(struct ctx *c, int v6, enum udp_act_type type, tp->flags = 0; } - break; - case UDP_ACT_SPLICE_INIT: - sp = &udp_splice_init[v6 ? V6 : V4][port]; - - if (now->tv_sec - sp->ts > UDP_CONN_TIMEOUT) - sockp = &sp->sock; - - break; - case UDP_ACT_SPLICE_NS: - sp = &udp_splice_ns[v6 ? V6 : V4][port]; - - if (now->tv_sec - sp->ts > UDP_CONN_TIMEOUT) - sockp = &sp->sock; - break; default: return; @@ -1274,24 +1246,23 @@ static void udp_timer_one(struct ctx *c, int v6, enum udp_act_type type, */ static void udp_port_rebind(struct ctx *c, bool outbound) { + int (*socks)[NUM_PORTS] = outbound ? udp_splice_ns : udp_splice_init; const uint8_t *fmap = outbound ? c->udp.fwd_out.f.map : c->udp.fwd_in.f.map; const uint8_t *rmap = outbound ? c->udp.fwd_in.f.map : c->udp.fwd_out.f.map; - struct udp_splice_port (*socks)[NUM_PORTS] - = outbound ? udp_splice_ns : udp_splice_init; unsigned port; for (port = 0; port < NUM_PORTS; port++) { if (!bitmap_isset(fmap, port)) { - if (socks[V4][port].sock >= 0) { - close(socks[V4][port].sock); - socks[V4][port].sock = -1; + if (socks[V4][port] >= 0) { + close(socks[V4][port]); + socks[V4][port] = -1; } - if (socks[V6][port].sock >= 0) { - close(socks[V6][port].sock); - socks[V6][port].sock = -1; + if (socks[V6][port] >= 0) { + close(socks[V6][port]); + socks[V6][port] = -1; } continue; @@ -1301,8 +1272,8 @@ static void udp_port_rebind(struct ctx *c, bool outbound) if (bitmap_isset(rmap, port)) continue; - if ((c->ifi4 && socks[V4][port].sock == -1) || - (c->ifi6 && socks[V6][port].sock == -1)) + if ((c->ifi4 && socks[V4][port] == -1) || + (c->ifi6 && socks[V6][port] == -1)) udp_sock_init(c, outbound, AF_UNSPEC, NULL, NULL, port); } } diff --git a/udp.h b/udp.h index db5e546e..e133f1e7 100644 --- a/udp.h +++ b/udp.h @@ -26,8 +26,6 @@ void udp_update_l2_buf(const unsigned char *eth_d, const unsigned char *eth_s); * union udp_epoll_ref - epoll reference portion for TCP connections * @port: Source port for connected sockets, bound port otherwise * @pif: pif for this socket - * @bound: Set if this file descriptor is a bound socket - * @splice: Set if descriptor packets to be "spliced" * @orig: Set if a spliced socket which can originate "connections" * @v6: Set for IPv6 sockets or connections * @u32: Opaque u32 value of reference @@ -36,8 +34,7 @@ union udp_epoll_ref { struct { in_port_t port; uint8_t pif; - bool splice:1, - orig:1, + bool orig:1, v6:1; }; uint32_t u32; -- 2.45.2