From e0647ad80c63fcad6a9dc31541881fa02aeaac98 Mon Sep 17 00:00:00 2001 From: David Gibson Date: Thu, 18 Jul 2024 15:26:47 +1000 Subject: udp: Handle "spliced" datagrams with per-flow sockets When forwarding a datagram to a socket, we need to find a socket with a suitable local address to send it. Currently we keep track of such sockets in an array indexed by local port, but this can't properly handle cases where we have multiple local addresses in active use. For "spliced" (socket to socket) cases, improve this by instead opening a socket specifically for the target side of the flow. We connect() as well as bind()ing that socket, so that it will only receive the flow's reply packets, not anything else. We direct datagrams sent via that socket using the addresses from the flow table, effectively replacing bespoke addressing logic with the unified logic in fwd.c When we create the flow, we also take a duplicate of the originating socket, and use that to deliver reply datagrams back to the origin, again using addresses from the flow table entry. Signed-off-by: David Gibson Signed-off-by: Stefano Brivio --- flow_table.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'flow_table.h') diff --git a/flow_table.h b/flow_table.h index df253be..a499e7b 100644 --- a/flow_table.h +++ b/flow_table.h @@ -100,6 +100,21 @@ static inline uint8_t pif_at_sidx(flow_sidx_t sidx) return flow->f.pif[sidx.sidei]; } +/** flowside_at_sidx() - Retrieve a specific flowside + * @sidx: Flow & side index + * + * Return: Flowside for the flow & side given by @sidx + */ +static inline const struct flowside *flowside_at_sidx(flow_sidx_t sidx) +{ + const union flow *flow = flow_at_sidx(sidx); + + if (!flow) + return PIF_NONE; + + return &flow->f.side[sidx.sidei]; +} + /** flow_sidx_opposite() - Get the other side of the same flow * @sidx: Flow & side index * -- cgit v1.2.3