mirror of
https://passt.top/passt
synced 2025-06-16 12:25:34 +02:00
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 <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
parent
a45a7e9798
commit
e0647ad80c
9 changed files with 226 additions and 264 deletions
20
flow.c
20
flow.c
|
@ -237,6 +237,26 @@ int flowside_sock_l4(const struct ctx *c, enum epoll_type type, uint8_t pif,
|
|||
}
|
||||
}
|
||||
|
||||
/** flowside_connect() - Connect a socket based on flowside
|
||||
* @c: Execution context
|
||||
* @s: Socket to connect
|
||||
* @pif: Target pif
|
||||
* @tgt: Target flowside
|
||||
*
|
||||
* Connect @s to the endpoint address and port from @tgt.
|
||||
*
|
||||
* Return: 0 on success, negative on error
|
||||
*/
|
||||
int flowside_connect(const struct ctx *c, int s,
|
||||
uint8_t pif, const struct flowside *tgt)
|
||||
{
|
||||
union sockaddr_inany sa;
|
||||
socklen_t sl;
|
||||
|
||||
pif_sockaddr(c, &sa, &sl, pif, &tgt->eaddr, tgt->eport);
|
||||
return connect(s, &sa.sa, sl);
|
||||
}
|
||||
|
||||
/** flow_log_ - Log flow-related message
|
||||
* @f: flow the message is related to
|
||||
* @pri: Log priority
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue