tcp, tcp_splice: Parse listening socket epoll ref in tcp_listen_handler()
tcp_listen_handler() uses the epoll reference for the listening socket it handles, and also passes on one variant of it to tcp_tap_conn_from_sock() and tcp_splice_conn_from_sock(). The latter two functions only need a couple of specific fields from the reference. Pass those specific values instead of the whole reference, which localises the handling of the listening (as opposed to accepted) socket and its reference entirely within tcp_listen_handler(). Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
parent
ee677e0a42
commit
dc9a5d71e9
3 changed files with 16 additions and 13 deletions
12
tcp.c
12
tcp.c
|
@ -2679,14 +2679,13 @@ static void tcp_snat_inbound(const struct ctx *c, union inany_addr *addr)
|
||||||
/**
|
/**
|
||||||
* tcp_tap_conn_from_sock() - Initialize state for non-spliced connection
|
* tcp_tap_conn_from_sock() - Initialize state for non-spliced connection
|
||||||
* @c: Execution context
|
* @c: Execution context
|
||||||
* @ref: epoll reference of listening socket
|
* @dstport: Destination port for connection (host side)
|
||||||
* @flow: flow to initialise
|
* @flow: flow to initialise
|
||||||
* @s: Accepted socket
|
* @s: Accepted socket
|
||||||
* @sa: Peer socket address (from accept())
|
* @sa: Peer socket address (from accept())
|
||||||
* @now: Current timestamp
|
* @now: Current timestamp
|
||||||
*/
|
*/
|
||||||
static void tcp_tap_conn_from_sock(struct ctx *c,
|
static void tcp_tap_conn_from_sock(struct ctx *c, in_port_t dstport,
|
||||||
union tcp_listen_epoll_ref ref,
|
|
||||||
union flow *flow, int s,
|
union flow *flow, int s,
|
||||||
const union sockaddr_inany *sa,
|
const union sockaddr_inany *sa,
|
||||||
const struct timespec *now)
|
const struct timespec *now)
|
||||||
|
@ -2699,7 +2698,7 @@ static void tcp_tap_conn_from_sock(struct ctx *c,
|
||||||
conn_event(c, conn, SOCK_ACCEPTED);
|
conn_event(c, conn, SOCK_ACCEPTED);
|
||||||
|
|
||||||
inany_from_sockaddr(&conn->faddr, &conn->fport, sa);
|
inany_from_sockaddr(&conn->faddr, &conn->fport, sa);
|
||||||
conn->eport = ref.port + c->tcp.fwd_in.delta[ref.port];
|
conn->eport = dstport + c->tcp.fwd_in.delta[dstport];
|
||||||
|
|
||||||
tcp_snat_inbound(c, &conn->faddr);
|
tcp_snat_inbound(c, &conn->faddr);
|
||||||
|
|
||||||
|
@ -2737,10 +2736,11 @@ void tcp_listen_handler(struct ctx *c, union epoll_ref ref,
|
||||||
if (s < 0)
|
if (s < 0)
|
||||||
goto cancel;
|
goto cancel;
|
||||||
|
|
||||||
if (tcp_splice_conn_from_sock(c, ref.tcp_listen, flow, s, &sa))
|
if (tcp_splice_conn_from_sock(c, ref.tcp_listen.pif,
|
||||||
|
ref.tcp_listen.port, flow, s, &sa))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
tcp_tap_conn_from_sock(c, ref.tcp_listen, flow, s, &sa, now);
|
tcp_tap_conn_from_sock(c, ref.tcp_listen.port, flow, s, &sa, now);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
cancel:
|
cancel:
|
||||||
|
|
12
tcp_splice.c
12
tcp_splice.c
|
@ -413,7 +413,8 @@ static int tcp_conn_sock_ns(const struct ctx *c, sa_family_t af)
|
||||||
/**
|
/**
|
||||||
* tcp_splice_conn_from_sock() - Attempt to init state for a spliced connection
|
* tcp_splice_conn_from_sock() - Attempt to init state for a spliced connection
|
||||||
* @c: Execution context
|
* @c: Execution context
|
||||||
* @ref: epoll reference of listening socket
|
* @pif0: pif id of side 0
|
||||||
|
* @dstport: Side 0 destination port of connection
|
||||||
* @flow: flow to initialise
|
* @flow: flow to initialise
|
||||||
* @s0: Accepted (side 0) socket
|
* @s0: Accepted (side 0) socket
|
||||||
* @sa: Peer address of connection
|
* @sa: Peer address of connection
|
||||||
|
@ -422,12 +423,13 @@ static int tcp_conn_sock_ns(const struct ctx *c, sa_family_t af)
|
||||||
* #syscalls:pasta setsockopt
|
* #syscalls:pasta setsockopt
|
||||||
*/
|
*/
|
||||||
bool tcp_splice_conn_from_sock(const struct ctx *c,
|
bool tcp_splice_conn_from_sock(const struct ctx *c,
|
||||||
union tcp_listen_epoll_ref ref, union flow *flow,
|
uint8_t pif0, in_port_t dstport,
|
||||||
int s0, const union sockaddr_inany *sa)
|
union flow *flow, int s0,
|
||||||
|
const union sockaddr_inany *sa)
|
||||||
{
|
{
|
||||||
in_port_t srcport, dstport = ref.port;
|
|
||||||
struct tcp_splice_conn *conn;
|
struct tcp_splice_conn *conn;
|
||||||
union inany_addr src;
|
union inany_addr src;
|
||||||
|
in_port_t srcport;
|
||||||
sa_family_t af;
|
sa_family_t af;
|
||||||
uint8_t pif1;
|
uint8_t pif1;
|
||||||
|
|
||||||
|
@ -437,7 +439,7 @@ bool tcp_splice_conn_from_sock(const struct ctx *c,
|
||||||
inany_from_sockaddr(&src, &srcport, sa);
|
inany_from_sockaddr(&src, &srcport, sa);
|
||||||
af = inany_v4(&src) ? AF_INET : AF_INET6;
|
af = inany_v4(&src) ? AF_INET : AF_INET6;
|
||||||
|
|
||||||
switch (ref.pif) {
|
switch (pif0) {
|
||||||
case PIF_SPLICE:
|
case PIF_SPLICE:
|
||||||
if (!inany_is_loopback(&src)) {
|
if (!inany_is_loopback(&src)) {
|
||||||
char str[INANY_ADDRSTRLEN];
|
char str[INANY_ADDRSTRLEN];
|
||||||
|
|
|
@ -12,8 +12,9 @@ union sockaddr_inany;
|
||||||
void tcp_splice_sock_handler(struct ctx *c, union epoll_ref ref,
|
void tcp_splice_sock_handler(struct ctx *c, union epoll_ref ref,
|
||||||
uint32_t events);
|
uint32_t events);
|
||||||
bool tcp_splice_conn_from_sock(const struct ctx *c,
|
bool tcp_splice_conn_from_sock(const struct ctx *c,
|
||||||
union tcp_listen_epoll_ref ref, union flow *flow,
|
uint8_t pif0, in_port_t dstport,
|
||||||
int s0, const union sockaddr_inany *sa);
|
union flow *flow, int s0,
|
||||||
|
const union sockaddr_inany *sa);
|
||||||
void tcp_splice_init(struct ctx *c);
|
void tcp_splice_init(struct ctx *c);
|
||||||
|
|
||||||
#endif /* TCP_SPLICE_H */
|
#endif /* TCP_SPLICE_H */
|
||||||
|
|
Loading…
Reference in a new issue