tcp: Move connection state structures into a shared header

Currently spliced and non-spliced connections use completely independent
tracking structures.  We want to unify these, so as a preliminary step move
the definitions for both variants into a new tcp_conn.h header, shared by
tcp.c and tcp_splice.c.

This requires renaming some #defines with the same name but different
meanings between the two cases.  In the process we correct some places that
are slightly out of sync between the comments and the code for various
event bit names.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
David Gibson 2022-11-17 16:58:43 +11:00 committed by Stefano Brivio
parent c6b822428a
commit 3cf027bd59
4 changed files with 245 additions and 225 deletions

View file

@ -47,7 +47,8 @@ MANPAGES = passt.1 pasta.1 qrap.1
PASST_HEADERS = arch.h arp.h checksum.h conf.h dhcp.h dhcpv6.h icmp.h \ PASST_HEADERS = arch.h arp.h checksum.h conf.h dhcp.h dhcpv6.h icmp.h \
isolation.h lineread.h log.h ndp.h netlink.h packet.h passt.h pasta.h \ isolation.h lineread.h log.h ndp.h netlink.h packet.h passt.h pasta.h \
pcap.h port_fwd.h siphash.h tap.h tcp.h tcp_splice.h udp.h util.h pcap.h port_fwd.h siphash.h tap.h tcp.h tcp_conn.h tcp_splice.h udp.h \
util.h
HEADERS = $(PASST_HEADERS) seccomp.h HEADERS = $(PASST_HEADERS) seccomp.h
# On gcc 11 and 12, with -O2 and -flto, tcp_hash() and siphash_20b(), if # On gcc 11 and 12, with -O2 and -flto, tcp_hash() and siphash_20b(), if

206
tcp.c
View file

@ -98,7 +98,7 @@
* Connection tracking and storage * Connection tracking and storage
* ------------------------------- * -------------------------------
* *
* Connections are tracked by the @tc array of struct tcp_conn, containing * Connections are tracked by the @tc array of struct tcp_tap_conn, containing
* addresses, ports, TCP states and parameters. This is statically allocated and * addresses, ports, TCP states and parameters. This is statically allocated and
* indexed by an arbitrary connection number. The array is compacted whenever a * indexed by an arbitrary connection number. The array is compacted whenever a
* connection is closed, by remapping the highest connection index in use to the * connection is closed, by remapping the highest connection index in use to the
@ -301,6 +301,8 @@
#include "tcp_splice.h" #include "tcp_splice.h"
#include "log.h" #include "log.h"
#include "tcp_conn.h"
#define TCP_FRAMES_MEM 128 #define TCP_FRAMES_MEM 128
#define TCP_FRAMES \ #define TCP_FRAMES \
(c->mode == MODE_PASST ? TCP_FRAMES_MEM : 1) (c->mode == MODE_PASST ? TCP_FRAMES_MEM : 1)
@ -308,7 +310,6 @@
#define TCP_FILE_PRESSURE 30 /* % of c->nofile */ #define TCP_FILE_PRESSURE 30 /* % of c->nofile */
#define TCP_CONN_PRESSURE 30 /* % of c->tcp.conn_count */ #define TCP_CONN_PRESSURE 30 /* % of c->tcp.conn_count */
#define TCP_HASH_BUCKET_BITS (TCP_CONN_INDEX_BITS + 1)
#define TCP_HASH_TABLE_LOAD 70 /* % */ #define TCP_HASH_TABLE_LOAD 70 /* % */
#define TCP_HASH_TABLE_SIZE (TCP_MAX_CONNS * 100 / \ #define TCP_HASH_TABLE_SIZE (TCP_MAX_CONNS * 100 / \
TCP_HASH_TABLE_LOAD) TCP_HASH_TABLE_LOAD)
@ -402,117 +403,8 @@ struct tcp6_l2_head { /* For MSS6 macro: keep in sync with tcp6_l2_buf_t */
#define OPT_SACK 5 #define OPT_SACK 5
#define OPT_TS 8 #define OPT_TS 8
/**
* struct tcp_conn - Descriptor for a TCP connection (not spliced)
* @next_index: Connection index of next item in hash chain, -1 for none
* @tap_mss: MSS advertised by tap/guest, rounded to 2 ^ TCP_MSS_BITS
* @sock: Socket descriptor number
* @events: Connection events, implying connection states
* @timer: timerfd descriptor for timeout events
* @flags: Connection flags representing internal attributes
* @hash_bucket: Bucket index in connection lookup hash table
* @retrans: Number of retransmissions occurred due to ACK_TIMEOUT
* @ws_from_tap: Window scaling factor advertised from tap/guest
* @ws_to_tap: Window scaling factor advertised to tap/guest
* @sndbuf: Sending buffer in kernel, rounded to 2 ^ SNDBUF_BITS
* @seq_dup_ack_approx: Last duplicate ACK number sent to tap
* @a.a6: IPv6 remote address, can be IPv4-mapped
* @a.a4.zero: Zero prefix for IPv4-mapped, see RFC 6890, Table 20
* @a.a4.one: Ones prefix for IPv4-mapped
* @a.a4.a: IPv4 address
* @tap_port: Guest-facing tap port
* @sock_port: Remote, socket-facing port
* @wnd_from_tap: Last window size from tap, unscaled (as received)
* @wnd_to_tap: Sending window advertised to tap, unscaled (as sent)
* @seq_to_tap: Next sequence for packets to tap
* @seq_ack_from_tap: Last ACK number received from tap
* @seq_from_tap: Next sequence for packets from tap (not actually sent)
* @seq_ack_to_tap: Last ACK number sent to tap
* @seq_init_from_tap: Initial sequence number from tap
*/
struct tcp_conn {
int next_index :TCP_CONN_INDEX_BITS + 2;
#define TCP_RETRANS_BITS 3
unsigned int retrans :TCP_RETRANS_BITS;
#define TCP_MAX_RETRANS ((1U << TCP_RETRANS_BITS) - 1)
#define TCP_WS_BITS 4 /* RFC 7323 */
#define TCP_WS_MAX 14
unsigned int ws_from_tap :TCP_WS_BITS;
unsigned int ws_to_tap :TCP_WS_BITS;
int sock :SOCKET_REF_BITS;
uint8_t events;
#define CLOSED 0
#define SOCK_ACCEPTED BIT(0) /* implies SYN sent to tap */
#define TAP_SYN_RCVD BIT(1) /* implies socket connecting */
#define TAP_SYN_ACK_SENT BIT( 3) /* implies socket connected */
#define ESTABLISHED BIT(2)
#define SOCK_FIN_RCVD BIT( 3)
#define SOCK_FIN_SENT BIT( 4)
#define TAP_FIN_RCVD BIT( 5)
#define TAP_FIN_SENT BIT( 6)
#define TAP_FIN_ACKED BIT( 7)
#define CONN_STATE_BITS /* Setting these clears other flags */ \
(SOCK_ACCEPTED | TAP_SYN_RCVD | ESTABLISHED)
int timer :SOCKET_REF_BITS;
uint8_t flags;
#define STALLED BIT(0)
#define LOCAL BIT(1)
#define WND_CLAMPED BIT(2)
#define IN_EPOLL BIT(3)
#define ACTIVE_CLOSE BIT(4)
#define ACK_TO_TAP_DUE BIT(5)
#define ACK_FROM_TAP_DUE BIT(6)
unsigned int hash_bucket :TCP_HASH_BUCKET_BITS;
#define TCP_MSS_BITS 14
unsigned int tap_mss :TCP_MSS_BITS;
#define MSS_SET(conn, mss) (conn->tap_mss = (mss >> (16 - TCP_MSS_BITS)))
#define MSS_GET(conn) (conn->tap_mss << (16 - TCP_MSS_BITS))
#define SNDBUF_BITS 24
unsigned int sndbuf :SNDBUF_BITS;
#define SNDBUF_SET(conn, bytes) (conn->sndbuf = ((bytes) >> (32 - SNDBUF_BITS)))
#define SNDBUF_GET(conn) (conn->sndbuf << (32 - SNDBUF_BITS))
uint8_t seq_dup_ack_approx;
union {
struct in6_addr a6;
struct {
uint8_t zero[10];
uint8_t one[2];
struct in_addr a;
} a4;
} a;
#define CONN_V4(conn) IN6_IS_ADDR_V4MAPPED(&conn->a.a6) #define CONN_V4(conn) IN6_IS_ADDR_V4MAPPED(&conn->a.a6)
#define CONN_V6(conn) (!CONN_V4(conn)) #define CONN_V6(conn) (!CONN_V4(conn))
in_port_t tap_port;
in_port_t sock_port;
uint16_t wnd_from_tap;
uint16_t wnd_to_tap;
uint32_t seq_to_tap;
uint32_t seq_ack_from_tap;
uint32_t seq_from_tap;
uint32_t seq_ack_to_tap;
uint32_t seq_init_from_tap;
};
#define CONN_IS_CLOSING(conn) \ #define CONN_IS_CLOSING(conn) \
((conn->events & ESTABLISHED) && \ ((conn->events & ESTABLISHED) && \
(conn->events & (SOCK_FIN_RCVD | TAP_FIN_RCVD))) (conn->events & (SOCK_FIN_RCVD | TAP_FIN_RCVD)))
@ -695,7 +587,7 @@ static unsigned int tcp6_l2_flags_buf_used;
static size_t tcp6_l2_flags_buf_bytes; static size_t tcp6_l2_flags_buf_bytes;
/* TCP connections */ /* TCP connections */
static struct tcp_conn tc[TCP_MAX_CONNS]; static struct tcp_tap_conn tc[TCP_MAX_CONNS];
#define CONN(index) (tc + (index)) #define CONN(index) (tc + (index))
#define CONN_IDX(conn) ((conn) - tc) #define CONN_IDX(conn) ((conn) - tc)
@ -705,7 +597,7 @@ static struct tcp_conn tc[TCP_MAX_CONNS];
* *
* Return: pointer to connection, or NULL if @index is out of bounds * Return: pointer to connection, or NULL if @index is out of bounds
*/ */
static inline struct tcp_conn *conn_at_idx(int index) static inline struct tcp_tap_conn *conn_at_idx(int index)
{ {
if ((index < 0) || (index >= TCP_MAX_CONNS)) if ((index < 0) || (index >= TCP_MAX_CONNS))
return NULL; return NULL;
@ -713,7 +605,7 @@ static inline struct tcp_conn *conn_at_idx(int index)
} }
/* Table for lookup from remote address, local port, remote port */ /* Table for lookup from remote address, local port, remote port */
static struct tcp_conn *tc_hash[TCP_HASH_TABLE_SIZE]; static struct tcp_tap_conn *tc_hash[TCP_HASH_TABLE_SIZE];
/* Pools for pre-opened sockets */ /* Pools for pre-opened sockets */
int init_sock_pool4 [TCP_SOCK_POOL_SIZE]; int init_sock_pool4 [TCP_SOCK_POOL_SIZE];
@ -749,7 +641,7 @@ static uint32_t tcp_conn_epoll_events(uint8_t events, uint8_t conn_flags)
return EPOLLRDHUP; return EPOLLRDHUP;
} }
static void conn_flag_do(const struct ctx *c, struct tcp_conn *conn, static void conn_flag_do(const struct ctx *c, struct tcp_tap_conn *conn,
unsigned long flag); unsigned long flag);
#define conn_flag(c, conn, flag) \ #define conn_flag(c, conn, flag) \
do { \ do { \
@ -764,7 +656,7 @@ static void conn_flag_do(const struct ctx *c, struct tcp_conn *conn,
* *
* Return: 0 on success, negative error code on failure (not on deletion) * Return: 0 on success, negative error code on failure (not on deletion)
*/ */
static int tcp_epoll_ctl(const struct ctx *c, struct tcp_conn *conn) static int tcp_epoll_ctl(const struct ctx *c, struct tcp_tap_conn *conn)
{ {
int m = (conn->flags & IN_EPOLL) ? EPOLL_CTL_MOD : EPOLL_CTL_ADD; int m = (conn->flags & IN_EPOLL) ? EPOLL_CTL_MOD : EPOLL_CTL_ADD;
union epoll_ref ref = { .r.proto = IPPROTO_TCP, .r.s = conn->sock, union epoll_ref ref = { .r.proto = IPPROTO_TCP, .r.s = conn->sock,
@ -809,7 +701,7 @@ static int tcp_epoll_ctl(const struct ctx *c, struct tcp_conn *conn)
* *
* #syscalls timerfd_create timerfd_settime * #syscalls timerfd_create timerfd_settime
*/ */
static void tcp_timer_ctl(const struct ctx *c, struct tcp_conn *conn) static void tcp_timer_ctl(const struct ctx *c, struct tcp_tap_conn *conn)
{ {
struct itimerspec it = { { 0 }, { 0 } }; struct itimerspec it = { { 0 }, { 0 } };
@ -865,7 +757,7 @@ static void tcp_timer_ctl(const struct ctx *c, struct tcp_conn *conn)
* @conn: Connection pointer * @conn: Connection pointer
* @flag: Flag to set, or ~flag to unset * @flag: Flag to set, or ~flag to unset
*/ */
static void conn_flag_do(const struct ctx *c, struct tcp_conn *conn, static void conn_flag_do(const struct ctx *c, struct tcp_tap_conn *conn,
unsigned long flag) unsigned long flag)
{ {
if (flag & (flag - 1)) { if (flag & (flag - 1)) {
@ -903,7 +795,7 @@ static void conn_flag_do(const struct ctx *c, struct tcp_conn *conn,
* @conn: Connection pointer * @conn: Connection pointer
* @event: Connection event * @event: Connection event
*/ */
static void conn_event_do(const struct ctx *c, struct tcp_conn *conn, static void conn_event_do(const struct ctx *c, struct tcp_tap_conn *conn,
unsigned long event) unsigned long event)
{ {
int prev, new, num = fls(event); int prev, new, num = fls(event);
@ -963,7 +855,7 @@ static void conn_event_do(const struct ctx *c, struct tcp_conn *conn,
* *
* Return: 1 if destination is in low RTT table, 0 otherwise * Return: 1 if destination is in low RTT table, 0 otherwise
*/ */
static int tcp_rtt_dst_low(const struct tcp_conn *conn) static int tcp_rtt_dst_low(const struct tcp_tap_conn *conn)
{ {
int i; int i;
@ -979,7 +871,7 @@ static int tcp_rtt_dst_low(const struct tcp_conn *conn)
* @conn: Connection pointer * @conn: Connection pointer
* @tinfo: Pointer to struct tcp_info for socket * @tinfo: Pointer to struct tcp_info for socket
*/ */
static void tcp_rtt_dst_check(const struct tcp_conn *conn, static void tcp_rtt_dst_check(const struct tcp_tap_conn *conn,
const struct tcp_info *tinfo) const struct tcp_info *tinfo)
{ {
#ifdef HAS_MIN_RTT #ifdef HAS_MIN_RTT
@ -1016,7 +908,7 @@ static void tcp_rtt_dst_check(const struct tcp_conn *conn,
* tcp_get_sndbuf() - Get, scale SO_SNDBUF between thresholds (1 to 0.5 usage) * tcp_get_sndbuf() - Get, scale SO_SNDBUF between thresholds (1 to 0.5 usage)
* @conn: Connection pointer * @conn: Connection pointer
*/ */
static void tcp_get_sndbuf(struct tcp_conn *conn) static void tcp_get_sndbuf(struct tcp_tap_conn *conn)
{ {
int s = conn->sock, sndbuf; int s = conn->sock, sndbuf;
socklen_t sl; socklen_t sl;
@ -1290,7 +1182,8 @@ static int tcp_opt_get(const char *opts, size_t len, uint8_t type_find,
* *
* Return: 1 on match, 0 otherwise * Return: 1 on match, 0 otherwise
*/ */
static int tcp_hash_match(const struct tcp_conn *conn, int af, const void *addr, static int tcp_hash_match(const struct tcp_tap_conn *conn,
int af, const void *addr,
in_port_t tap_port, in_port_t sock_port) in_port_t tap_port, in_port_t sock_port)
{ {
if (af == AF_INET && CONN_V4(conn) && if (af == AF_INET && CONN_V4(conn) &&
@ -1356,7 +1249,7 @@ static unsigned int tcp_hash(const struct ctx *c, int af, const void *addr,
* @af: Address family, AF_INET or AF_INET6 * @af: Address family, AF_INET or AF_INET6
* @addr: Remote address, pointer to in_addr or in6_addr * @addr: Remote address, pointer to in_addr or in6_addr
*/ */
static void tcp_hash_insert(const struct ctx *c, struct tcp_conn *conn, static void tcp_hash_insert(const struct ctx *c, struct tcp_tap_conn *conn,
int af, const void *addr) int af, const void *addr)
{ {
int b; int b;
@ -1374,9 +1267,9 @@ static void tcp_hash_insert(const struct ctx *c, struct tcp_conn *conn,
* tcp_hash_remove() - Drop connection from hash table, chain unlink * tcp_hash_remove() - Drop connection from hash table, chain unlink
* @conn: Connection pointer * @conn: Connection pointer
*/ */
static void tcp_hash_remove(const struct tcp_conn *conn) static void tcp_hash_remove(const struct tcp_tap_conn *conn)
{ {
struct tcp_conn *entry, *prev = NULL; struct tcp_tap_conn *entry, *prev = NULL;
int b = conn->hash_bucket; int b = conn->hash_bucket;
for (entry = tc_hash[b]; entry; for (entry = tc_hash[b]; entry;
@ -1400,9 +1293,9 @@ static void tcp_hash_remove(const struct tcp_conn *conn)
* @old: Old connection pointer * @old: Old connection pointer
* @new: New connection pointer * @new: New connection pointer
*/ */
static void tcp_hash_update(struct tcp_conn *old, struct tcp_conn *new) static void tcp_hash_update(struct tcp_tap_conn *old, struct tcp_tap_conn *new)
{ {
struct tcp_conn *entry, *prev = NULL; struct tcp_tap_conn *entry, *prev = NULL;
int b = old->hash_bucket; int b = old->hash_bucket;
for (entry = tc_hash[b]; entry; for (entry = tc_hash[b]; entry;
@ -1431,12 +1324,13 @@ static void tcp_hash_update(struct tcp_conn *old, struct tcp_conn *new)
* *
* Return: connection pointer, if found, -ENOENT otherwise * Return: connection pointer, if found, -ENOENT otherwise
*/ */
static struct tcp_conn *tcp_hash_lookup(const struct ctx *c, int af, static struct tcp_tap_conn *tcp_hash_lookup(const struct ctx *c,
const void *addr, int af, const void *addr,
in_port_t tap_port, in_port_t sock_port) in_port_t tap_port,
in_port_t sock_port)
{ {
int b = tcp_hash(c, af, addr, tap_port, sock_port); int b = tcp_hash(c, af, addr, tap_port, sock_port);
struct tcp_conn *conn; struct tcp_tap_conn *conn;
for (conn = tc_hash[b]; conn; conn = conn_at_idx(conn->next_index)) { for (conn = tc_hash[b]; conn; conn = conn_at_idx(conn->next_index)) {
if (tcp_hash_match(conn, af, addr, tap_port, sock_port)) if (tcp_hash_match(conn, af, addr, tap_port, sock_port))
@ -1451,9 +1345,9 @@ static struct tcp_conn *tcp_hash_lookup(const struct ctx *c, int af,
* @c: Execution context * @c: Execution context
* @hole: Pointer to recently closed connection * @hole: Pointer to recently closed connection
*/ */
static void tcp_table_compact(struct ctx *c, struct tcp_conn *hole) static void tcp_table_compact(struct ctx *c, struct tcp_tap_conn *hole)
{ {
struct tcp_conn *from, *to; struct tcp_tap_conn *from, *to;
if (CONN_IDX(hole) == --c->tcp.conn_count) { if (CONN_IDX(hole) == --c->tcp.conn_count) {
debug("TCP: hash table compaction: maximum index was %li (%p)", debug("TCP: hash table compaction: maximum index was %li (%p)",
@ -1482,7 +1376,7 @@ static void tcp_table_compact(struct ctx *c, struct tcp_conn *hole)
* @c: Execution context * @c: Execution context
* @conn: Connection pointer * @conn: Connection pointer
*/ */
static void tcp_conn_destroy(struct ctx *c, struct tcp_conn *conn) static void tcp_conn_destroy(struct ctx *c, struct tcp_tap_conn *conn)
{ {
close(conn->sock); close(conn->sock);
if (conn->timer != -1) if (conn->timer != -1)
@ -1492,7 +1386,7 @@ static void tcp_conn_destroy(struct ctx *c, struct tcp_conn *conn)
tcp_table_compact(c, conn); tcp_table_compact(c, conn);
} }
static void tcp_rst_do(struct ctx *c, struct tcp_conn *conn); static void tcp_rst_do(struct ctx *c, struct tcp_tap_conn *conn);
#define tcp_rst(c, conn) \ #define tcp_rst(c, conn) \
do { \ do { \
debug("TCP: index %li, reset at %s:%i", CONN_IDX(conn), \ debug("TCP: index %li, reset at %s:%i", CONN_IDX(conn), \
@ -1627,7 +1521,7 @@ void tcp_defer_handler(struct ctx *c)
{ {
int max_conns = c->tcp.conn_count / 100 * TCP_CONN_PRESSURE; int max_conns = c->tcp.conn_count / 100 * TCP_CONN_PRESSURE;
int max_files = c->nofile / 100 * TCP_FILE_PRESSURE; int max_files = c->nofile / 100 * TCP_FILE_PRESSURE;
struct tcp_conn *conn; struct tcp_tap_conn *conn;
tcp_l2_flags_buf_flush(c); tcp_l2_flags_buf_flush(c);
tcp_l2_data_buf_flush(c); tcp_l2_data_buf_flush(c);
@ -1656,7 +1550,7 @@ void tcp_defer_handler(struct ctx *c)
* Return: 802.3 length, host order * Return: 802.3 length, host order
*/ */
static size_t tcp_l2_buf_fill_headers(const struct ctx *c, static size_t tcp_l2_buf_fill_headers(const struct ctx *c,
const struct tcp_conn *conn, const struct tcp_tap_conn *conn,
void *p, size_t plen, void *p, size_t plen,
const uint16_t *check, uint32_t seq) const uint16_t *check, uint32_t seq)
{ {
@ -1738,7 +1632,7 @@ do { \
* *
* Return: 1 if sequence or window were updated, 0 otherwise * Return: 1 if sequence or window were updated, 0 otherwise
*/ */
static int tcp_update_seqack_wnd(const struct ctx *c, struct tcp_conn *conn, static int tcp_update_seqack_wnd(const struct ctx *c, struct tcp_tap_conn *conn,
int force_seq, struct tcp_info *tinfo) int force_seq, struct tcp_info *tinfo)
{ {
uint32_t prev_wnd_to_tap = conn->wnd_to_tap << conn->ws_to_tap; uint32_t prev_wnd_to_tap = conn->wnd_to_tap << conn->ws_to_tap;
@ -1824,7 +1718,7 @@ out:
* *
* Return: negative error code on connection reset, 0 otherwise * Return: negative error code on connection reset, 0 otherwise
*/ */
static int tcp_send_flag(struct ctx *c, struct tcp_conn *conn, int flags) static int tcp_send_flag(struct ctx *c, struct tcp_tap_conn *conn, int flags)
{ {
uint32_t prev_ack_to_tap = conn->seq_ack_to_tap; uint32_t prev_ack_to_tap = conn->seq_ack_to_tap;
uint32_t prev_wnd_to_tap = conn->wnd_to_tap; uint32_t prev_wnd_to_tap = conn->wnd_to_tap;
@ -1971,7 +1865,7 @@ static int tcp_send_flag(struct ctx *c, struct tcp_conn *conn, int flags)
* @c: Execution context * @c: Execution context
* @conn: Connection pointer * @conn: Connection pointer
*/ */
static void tcp_rst_do(struct ctx *c, struct tcp_conn *conn) static void tcp_rst_do(struct ctx *c, struct tcp_tap_conn *conn)
{ {
if (conn->events == CLOSED) if (conn->events == CLOSED)
return; return;
@ -1986,7 +1880,7 @@ static void tcp_rst_do(struct ctx *c, struct tcp_conn *conn)
* @opts: Pointer to start of TCP options * @opts: Pointer to start of TCP options
* @optlen: Bytes in options: caller MUST ensure available length * @optlen: Bytes in options: caller MUST ensure available length
*/ */
static void tcp_get_tap_ws(struct tcp_conn *conn, static void tcp_get_tap_ws(struct tcp_tap_conn *conn,
const char *opts, size_t optlen) const char *opts, size_t optlen)
{ {
int ws = tcp_opt_get(opts, optlen, OPT_WS, NULL, NULL); int ws = tcp_opt_get(opts, optlen, OPT_WS, NULL, NULL);
@ -2003,7 +1897,7 @@ static void tcp_get_tap_ws(struct tcp_conn *conn,
* @conn: Connection pointer * @conn: Connection pointer
* @window: Window value, host order, unscaled * @window: Window value, host order, unscaled
*/ */
static void tcp_clamp_window(const struct ctx *c, struct tcp_conn *conn, static void tcp_clamp_window(const struct ctx *c, struct tcp_tap_conn *conn,
unsigned wnd) unsigned wnd)
{ {
uint32_t prev_scaled = conn->wnd_from_tap << conn->ws_from_tap; uint32_t prev_scaled = conn->wnd_from_tap << conn->ws_from_tap;
@ -2125,7 +2019,7 @@ static int tcp_conn_new_sock(const struct ctx *c, sa_family_t af)
* Return: clamped MSS value * Return: clamped MSS value
*/ */
static uint16_t tcp_conn_tap_mss(const struct ctx *c, static uint16_t tcp_conn_tap_mss(const struct ctx *c,
const struct tcp_conn *conn, const struct tcp_tap_conn *conn,
const char *opts, size_t optlen) const char *opts, size_t optlen)
{ {
unsigned int mss; unsigned int mss;
@ -2172,7 +2066,7 @@ static void tcp_conn_from_tap(struct ctx *c, int af, const void *addr,
.sin6_addr = *(struct in6_addr *)addr, .sin6_addr = *(struct in6_addr *)addr,
}; };
const struct sockaddr *sa; const struct sockaddr *sa;
struct tcp_conn *conn; struct tcp_tap_conn *conn;
socklen_t sl; socklen_t sl;
int s, mss; int s, mss;
@ -2280,7 +2174,7 @@ static void tcp_conn_from_tap(struct ctx *c, int af, const void *addr,
* *
* Return: 0 on success, negative error code from recv() on failure * Return: 0 on success, negative error code from recv() on failure
*/ */
static int tcp_sock_consume(struct tcp_conn *conn, uint32_t ack_seq) static int tcp_sock_consume(struct tcp_tap_conn *conn, uint32_t ack_seq)
{ {
/* Simply ignore out-of-order ACKs: we already consumed the data we /* Simply ignore out-of-order ACKs: we already consumed the data we
* needed from the buffer, and we won't rewind back to a lower ACK * needed from the buffer, and we won't rewind back to a lower ACK
@ -2307,7 +2201,7 @@ static int tcp_sock_consume(struct tcp_conn *conn, uint32_t ack_seq)
* @seq: Sequence number to be sent * @seq: Sequence number to be sent
* @now: Current timestamp * @now: Current timestamp
*/ */
static void tcp_data_to_tap(struct ctx *c, struct tcp_conn *conn, static void tcp_data_to_tap(struct ctx *c, struct tcp_tap_conn *conn,
ssize_t plen, int no_csum, uint32_t seq) ssize_t plen, int no_csum, uint32_t seq)
{ {
struct iovec *iov; struct iovec *iov;
@ -2344,7 +2238,7 @@ static void tcp_data_to_tap(struct ctx *c, struct tcp_conn *conn,
* *
* #syscalls recvmsg * #syscalls recvmsg
*/ */
static int tcp_data_from_sock(struct ctx *c, struct tcp_conn *conn) static int tcp_data_from_sock(struct ctx *c, struct tcp_tap_conn *conn)
{ {
uint32_t wnd_scaled = conn->wnd_from_tap << conn->ws_from_tap; uint32_t wnd_scaled = conn->wnd_from_tap << conn->ws_from_tap;
int fill_bufs, send_bufs = 0, last_len, iov_rem = 0; int fill_bufs, send_bufs = 0, last_len, iov_rem = 0;
@ -2475,7 +2369,7 @@ zero_len:
* *
* #syscalls sendmsg * #syscalls sendmsg
*/ */
static void tcp_data_from_tap(struct ctx *c, struct tcp_conn *conn, static void tcp_data_from_tap(struct ctx *c, struct tcp_tap_conn *conn,
const struct pool *p) const struct pool *p)
{ {
int i, iov_i, ack = 0, fin = 0, retr = 0, keep = -1, partial_send = 0; int i, iov_i, ack = 0, fin = 0, retr = 0, keep = -1, partial_send = 0;
@ -2675,7 +2569,7 @@ out:
* @opts: Pointer to start of options * @opts: Pointer to start of options
* @optlen: Bytes in options: caller MUST ensure available length * @optlen: Bytes in options: caller MUST ensure available length
*/ */
static void tcp_conn_from_sock_finish(struct ctx *c, struct tcp_conn *conn, static void tcp_conn_from_sock_finish(struct ctx *c, struct tcp_tap_conn *conn,
const struct tcphdr *th, const struct tcphdr *th,
const char *opts, size_t optlen) const char *opts, size_t optlen)
{ {
@ -2714,7 +2608,7 @@ static void tcp_conn_from_sock_finish(struct ctx *c, struct tcp_conn *conn,
int tcp_tap_handler(struct ctx *c, int af, const void *addr, int tcp_tap_handler(struct ctx *c, int af, const void *addr,
const struct pool *p, const struct timespec *now) const struct pool *p, const struct timespec *now)
{ {
struct tcp_conn *conn; struct tcp_tap_conn *conn;
size_t optlen, len; size_t optlen, len;
struct tcphdr *th; struct tcphdr *th;
int ack_due = 0; int ack_due = 0;
@ -2829,7 +2723,7 @@ int tcp_tap_handler(struct ctx *c, int af, const void *addr,
* @c: Execution context * @c: Execution context
* @conn: Connection pointer * @conn: Connection pointer
*/ */
static void tcp_connect_finish(struct ctx *c, struct tcp_conn *conn) static void tcp_connect_finish(struct ctx *c, struct tcp_tap_conn *conn)
{ {
socklen_t sl; socklen_t sl;
int so; int so;
@ -2857,7 +2751,7 @@ static void tcp_conn_from_sock(struct ctx *c, union epoll_ref ref,
const struct timespec *now) const struct timespec *now)
{ {
struct sockaddr_storage sa; struct sockaddr_storage sa;
struct tcp_conn *conn; struct tcp_tap_conn *conn;
socklen_t sl; socklen_t sl;
int s; int s;
@ -2949,7 +2843,7 @@ static void tcp_conn_from_sock(struct ctx *c, union epoll_ref ref,
*/ */
static void tcp_timer_handler(struct ctx *c, union epoll_ref ref) static void tcp_timer_handler(struct ctx *c, union epoll_ref ref)
{ {
struct tcp_conn *conn = conn_at_idx(ref.r.p.tcp.tcp.index); struct tcp_tap_conn *conn = conn_at_idx(ref.r.p.tcp.tcp.index);
struct itimerspec check_armed = { { 0 }, { 0 } }; struct itimerspec check_armed = { { 0 }, { 0 } };
if (!conn) if (!conn)
@ -3012,7 +2906,7 @@ static void tcp_timer_handler(struct ctx *c, union epoll_ref ref)
void tcp_sock_handler(struct ctx *c, union epoll_ref ref, uint32_t events, void tcp_sock_handler(struct ctx *c, union epoll_ref ref, uint32_t events,
const struct timespec *now) const struct timespec *now)
{ {
struct tcp_conn *conn; struct tcp_tap_conn *conn;
if (ref.r.p.tcp.tcp.timer) { if (ref.r.p.tcp.tcp.timer) {
tcp_timer_handler(c, ref); tcp_timer_handler(c, ref);
@ -3510,7 +3404,7 @@ static int tcp_port_rebind(void *arg)
void tcp_timer(struct ctx *c, const struct timespec *ts) void tcp_timer(struct ctx *c, const struct timespec *ts)
{ {
struct tcp_sock_refill_arg refill_arg = { c, 0 }; struct tcp_sock_refill_arg refill_arg = { c, 0 };
struct tcp_conn *conn; struct tcp_tap_conn *conn;
(void)ts; (void)ts;

168
tcp_conn.h Normal file
View file

@ -0,0 +1,168 @@
/* SPDX-License-Identifier: AGPL-3.0-or-later
* Copyright Red Hat
* Author: Stefano Brivio <sbrivio@redhat.com>
* Author: David Gibson <david@gibson.dropbear.id.au>
*
* TCP connection tracking data structures, used by tcp.c and
* tcp_splice.c. Shouldn't be included in non-TCP code.
*/
#ifndef TCP_CONN_H
#define TCP_CONN_H
#define TCP_HASH_BUCKET_BITS (TCP_CONN_INDEX_BITS + 1)
/**
* struct tcp_tap_conn - Descriptor for a TCP connection (not spliced)
* @next_index: Connection index of next item in hash chain, -1 for none
* @tap_mss: MSS advertised by tap/guest, rounded to 2 ^ TCP_MSS_BITS
* @sock: Socket descriptor number
* @events: Connection events, implying connection states
* @timer: timerfd descriptor for timeout events
* @flags: Connection flags representing internal attributes
* @hash_bucket: Bucket index in connection lookup hash table
* @retrans: Number of retransmissions occurred due to ACK_TIMEOUT
* @ws_from_tap: Window scaling factor advertised from tap/guest
* @ws_to_tap: Window scaling factor advertised to tap/guest
* @sndbuf: Sending buffer in kernel, rounded to 2 ^ SNDBUF_BITS
* @seq_dup_ack_approx: Last duplicate ACK number sent to tap
* @a.a6: IPv6 remote address, can be IPv4-mapped
* @a.a4.zero: Zero prefix for IPv4-mapped, see RFC 6890, Table 20
* @a.a4.one: Ones prefix for IPv4-mapped
* @a.a4.a: IPv4 address
* @tap_port: Guest-facing tap port
* @sock_port: Remote, socket-facing port
* @wnd_from_tap: Last window size from tap, unscaled (as received)
* @wnd_to_tap: Sending window advertised to tap, unscaled (as sent)
* @seq_to_tap: Next sequence for packets to tap
* @seq_ack_from_tap: Last ACK number received from tap
* @seq_from_tap: Next sequence for packets from tap (not actually sent)
* @seq_ack_to_tap: Last ACK number sent to tap
* @seq_init_from_tap: Initial sequence number from tap
*/
struct tcp_tap_conn {
int next_index :TCP_CONN_INDEX_BITS + 2;
#define TCP_RETRANS_BITS 3
unsigned int retrans :TCP_RETRANS_BITS;
#define TCP_MAX_RETRANS ((1U << TCP_RETRANS_BITS) - 1)
#define TCP_WS_BITS 4 /* RFC 7323 */
#define TCP_WS_MAX 14
unsigned int ws_from_tap :TCP_WS_BITS;
unsigned int ws_to_tap :TCP_WS_BITS;
int sock :SOCKET_REF_BITS;
uint8_t events;
#define CLOSED 0
#define SOCK_ACCEPTED BIT(0) /* implies SYN sent to tap */
#define TAP_SYN_RCVD BIT(1) /* implies socket connecting */
#define TAP_SYN_ACK_SENT BIT( 3) /* implies socket connected */
#define ESTABLISHED BIT(2)
#define SOCK_FIN_RCVD BIT( 3)
#define SOCK_FIN_SENT BIT( 4)
#define TAP_FIN_RCVD BIT( 5)
#define TAP_FIN_SENT BIT( 6)
#define TAP_FIN_ACKED BIT( 7)
#define CONN_STATE_BITS /* Setting these clears other flags */ \
(SOCK_ACCEPTED | TAP_SYN_RCVD | ESTABLISHED)
int timer :SOCKET_REF_BITS;
uint8_t flags;
#define STALLED BIT(0)
#define LOCAL BIT(1)
#define WND_CLAMPED BIT(2)
#define IN_EPOLL BIT(3)
#define ACTIVE_CLOSE BIT(4)
#define ACK_TO_TAP_DUE BIT(5)
#define ACK_FROM_TAP_DUE BIT(6)
unsigned int hash_bucket :TCP_HASH_BUCKET_BITS;
#define TCP_MSS_BITS 14
unsigned int tap_mss :TCP_MSS_BITS;
#define MSS_SET(conn, mss) (conn->tap_mss = (mss >> (16 - TCP_MSS_BITS)))
#define MSS_GET(conn) (conn->tap_mss << (16 - TCP_MSS_BITS))
#define SNDBUF_BITS 24
unsigned int sndbuf :SNDBUF_BITS;
#define SNDBUF_SET(conn, bytes) (conn->sndbuf = ((bytes) >> (32 - SNDBUF_BITS)))
#define SNDBUF_GET(conn) (conn->sndbuf << (32 - SNDBUF_BITS))
uint8_t seq_dup_ack_approx;
union {
struct in6_addr a6;
struct {
uint8_t zero[10];
uint8_t one[2];
struct in_addr a;
} a4;
} a;
in_port_t tap_port;
in_port_t sock_port;
uint16_t wnd_from_tap;
uint16_t wnd_to_tap;
uint32_t seq_to_tap;
uint32_t seq_ack_from_tap;
uint32_t seq_from_tap;
uint32_t seq_ack_to_tap;
uint32_t seq_init_from_tap;
};
/**
* struct tcp_splice_conn - Descriptor for a spliced TCP connection
* @a: File descriptor number of socket for accepted connection
* @pipe_a_b: Pipe ends for splice() from @a to @b
* @b: File descriptor number of peer connected socket
* @pipe_b_a: Pipe ends for splice() from @b to @a
* @events: Events observed/actions performed on connection
* @flags: Connection flags (attributes, not events)
* @a_read: Bytes read from @a (not fully written to @b in one shot)
* @a_written: Bytes written to @a (not fully written from one @b read)
* @b_read: Bytes read from @b (not fully written to @a in one shot)
* @b_written: Bytes written to @b (not fully written from one @a read)
*/
struct tcp_splice_conn {
int a;
int pipe_a_b[2];
int b;
int pipe_b_a[2];
uint8_t events;
#define SPLICE_CLOSED 0
#define SPLICE_CONNECT BIT(0)
#define SPLICE_ESTABLISHED BIT(1)
#define A_OUT_WAIT BIT(2)
#define B_OUT_WAIT BIT(3)
#define A_FIN_RCVD BIT(4)
#define B_FIN_RCVD BIT(5)
#define A_FIN_SENT BIT(6)
#define B_FIN_SENT BIT(7)
uint8_t flags;
#define SPLICE_V6 BIT(0)
#define SPLICE_IN_EPOLL BIT(1)
#define RCVLOWAT_SET_A BIT(2)
#define RCVLOWAT_SET_B BIT(3)
#define RCVLOWAT_ACT_A BIT(4)
#define RCVLOWAT_ACT_B BIT(5)
#define CLOSING BIT(6)
uint32_t a_read;
uint32_t a_written;
uint32_t b_read;
uint32_t b_written;
};
#endif /* TCP_CONN_H */

View file

@ -21,12 +21,12 @@
* *
* - SPLICE_CONNECT: connection accepted, connecting to target * - SPLICE_CONNECT: connection accepted, connecting to target
* - SPLICE_ESTABLISHED: connection to target established * - SPLICE_ESTABLISHED: connection to target established
* - SPLICE_A_OUT_WAIT: pipe to accepted socket full, wait for EPOLLOUT * - A_OUT_WAIT: pipe to accepted socket full, wait for EPOLLOUT
* - SPLICE_B_OUT_WAIT: pipe to target socket full, wait for EPOLLOUT * - B_OUT_WAIT: pipe to target socket full, wait for EPOLLOUT
* - SPLICE_A_FIN_RCVD: FIN (EPOLLRDHUP) seen from accepted socket * - A_FIN_RCVD: FIN (EPOLLRDHUP) seen from accepted socket
* - SPLICE_B_FIN_RCVD: FIN (EPOLLRDHUP) seen from target socket * - B_FIN_RCVD: FIN (EPOLLRDHUP) seen from target socket
* - SPLICE_A_FIN_RCVD: FIN (write shutdown) sent to accepted socket * - A_FIN_RCVD: FIN (write shutdown) sent to accepted socket
* - SPLICE_B_FIN_RCVD: FIN (write shutdown) sent to target socket * - B_FIN_RCVD: FIN (write shutdown) sent to target socket
* *
* #syscalls:pasta pipe2|pipe fcntl armv6l:fcntl64 armv7l:fcntl64 ppc64:fcntl64 * #syscalls:pasta pipe2|pipe fcntl armv6l:fcntl64 armv7l:fcntl64 ppc64:fcntl64
*/ */
@ -52,6 +52,8 @@
#include "log.h" #include "log.h"
#include "tcp_splice.h" #include "tcp_splice.h"
#include "tcp_conn.h"
#define MAX_PIPE_SIZE (8UL * 1024 * 1024) #define MAX_PIPE_SIZE (8UL * 1024 * 1024)
#define TCP_SPLICE_PIPE_POOL_SIZE 16 #define TCP_SPLICE_PIPE_POOL_SIZE 16
#define TCP_SPLICE_CONN_PRESSURE 30 /* % of splice_conn_count */ #define TCP_SPLICE_CONN_PRESSURE 30 /* % of splice_conn_count */
@ -66,52 +68,7 @@ extern int ns_sock_pool6 [TCP_SOCK_POOL_SIZE];
/* Pool of pre-opened pipes */ /* Pool of pre-opened pipes */
static int splice_pipe_pool [TCP_SPLICE_PIPE_POOL_SIZE][2][2]; static int splice_pipe_pool [TCP_SPLICE_PIPE_POOL_SIZE][2][2];
/** #define CONN_V6(x) (x->flags & SPLICE_V6)
* struct tcp_splice_conn - Descriptor for a spliced TCP connection
* @a: File descriptor number of socket for accepted connection
* @pipe_a_b: Pipe ends for splice() from @a to @b
* @b: File descriptor number of peer connected socket
* @pipe_b_a: Pipe ends for splice() from @b to @a
* @events: Events observed/actions performed on connection
* @flags: Connection flags (attributes, not events)
* @a_read: Bytes read from @a (not fully written to @b in one shot)
* @a_written: Bytes written to @a (not fully written from one @b read)
* @b_read: Bytes read from @b (not fully written to @a in one shot)
* @b_written: Bytes written to @b (not fully written from one @a read)
*/
struct tcp_splice_conn {
int a;
int pipe_a_b[2];
int b;
int pipe_b_a[2];
uint8_t events;
#define CLOSED 0
#define CONNECT BIT(0)
#define ESTABLISHED BIT(1)
#define A_OUT_WAIT BIT(2)
#define B_OUT_WAIT BIT(3)
#define A_FIN_RCVD BIT(4)
#define B_FIN_RCVD BIT(5)
#define A_FIN_SENT BIT(6)
#define B_FIN_SENT BIT(7)
uint8_t flags;
#define SOCK_V6 BIT(0)
#define IN_EPOLL BIT(1)
#define RCVLOWAT_SET_A BIT(2)
#define RCVLOWAT_SET_B BIT(3)
#define RCVLOWAT_ACT_A BIT(4)
#define RCVLOWAT_ACT_B BIT(5)
#define CLOSING BIT(6)
uint32_t a_read;
uint32_t a_written;
uint32_t b_read;
uint32_t b_written;
};
#define CONN_V6(x) (x->flags & SOCK_V6)
#define CONN_V4(x) (!CONN_V6(x)) #define CONN_V4(x) (!CONN_V6(x))
#define CONN_HAS(conn, set) ((conn->events & (set)) == (set)) #define CONN_HAS(conn, set) ((conn->events & (set)) == (set))
#define CONN(index) (tc_splice + (index)) #define CONN(index) (tc_splice + (index))
@ -122,13 +79,13 @@ static struct tcp_splice_conn tc_splice[TCP_SPLICE_MAX_CONNS];
/* Display strings for connection events */ /* Display strings for connection events */
static const char *tcp_splice_event_str[] __attribute((__unused__)) = { static const char *tcp_splice_event_str[] __attribute((__unused__)) = {
"CONNECT", "ESTABLISHED", "A_OUT_WAIT", "B_OUT_WAIT", "SPLICE_CONNECT", "SPLICE_ESTABLISHED", "A_OUT_WAIT", "B_OUT_WAIT",
"A_FIN_RCVD", "B_FIN_RCVD", "A_FIN_SENT", "B_FIN_SENT", "A_FIN_RCVD", "B_FIN_RCVD", "A_FIN_SENT", "B_FIN_SENT",
}; };
/* Display strings for connection flags */ /* Display strings for connection flags */
static const char *tcp_splice_flag_str[] __attribute((__unused__)) = { static const char *tcp_splice_flag_str[] __attribute((__unused__)) = {
"SOCK_V6", "IN_EPOLL", "RCVLOWAT_SET_A", "RCVLOWAT_SET_B", "SPLICE_V6", "SPLICE_IN_EPOLL", "RCVLOWAT_SET_A", "RCVLOWAT_SET_B",
"RCVLOWAT_ACT_A", "RCVLOWAT_ACT_B", "CLOSING", "RCVLOWAT_ACT_A", "RCVLOWAT_ACT_B", "CLOSING",
}; };
@ -143,12 +100,12 @@ static void tcp_splice_conn_epoll_events(uint16_t events,
{ {
*a = *b = 0; *a = *b = 0;
if (events & ESTABLISHED) { if (events & SPLICE_ESTABLISHED) {
if (!(events & B_FIN_SENT)) if (!(events & B_FIN_SENT))
*a = EPOLLIN | EPOLLRDHUP; *a = EPOLLIN | EPOLLRDHUP;
if (!(events & A_FIN_SENT)) if (!(events & A_FIN_SENT))
*b = EPOLLIN | EPOLLRDHUP; *b = EPOLLIN | EPOLLRDHUP;
} else if (events & CONNECT) { } else if (events & SPLICE_CONNECT) {
*b = EPOLLOUT; *b = EPOLLOUT;
} }
@ -210,7 +167,7 @@ static void conn_flag_do(const struct ctx *c, struct tcp_splice_conn *conn,
static int tcp_splice_epoll_ctl(const struct ctx *c, static int tcp_splice_epoll_ctl(const struct ctx *c,
struct tcp_splice_conn *conn) struct tcp_splice_conn *conn)
{ {
int m = (conn->flags & IN_EPOLL) ? EPOLL_CTL_MOD : EPOLL_CTL_ADD; int m = (conn->flags & SPLICE_IN_EPOLL) ? EPOLL_CTL_MOD : EPOLL_CTL_ADD;
union epoll_ref ref_a = { .r.proto = IPPROTO_TCP, .r.s = conn->a, union epoll_ref ref_a = { .r.proto = IPPROTO_TCP, .r.s = conn->a,
.r.p.tcp.tcp.splice = 1, .r.p.tcp.tcp.splice = 1,
.r.p.tcp.tcp.index = CONN_IDX(conn), .r.p.tcp.tcp.index = CONN_IDX(conn),
@ -234,7 +191,7 @@ static int tcp_splice_epoll_ctl(const struct ctx *c,
epoll_ctl(c->epollfd, m, conn->b, &ev_b)) epoll_ctl(c->epollfd, m, conn->b, &ev_b))
goto delete; goto delete;
conn->flags |= IN_EPOLL; /* No need to log this */ conn->flags |= SPLICE_IN_EPOLL; /* No need to log this */
return 0; return 0;
@ -323,7 +280,7 @@ static void tcp_table_splice_compact(struct ctx *c,
*/ */
static void tcp_splice_destroy(struct ctx *c, struct tcp_splice_conn *conn) static void tcp_splice_destroy(struct ctx *c, struct tcp_splice_conn *conn)
{ {
if (conn->events & ESTABLISHED) { if (conn->events & SPLICE_ESTABLISHED) {
/* Flushing might need to block: don't recycle them. */ /* Flushing might need to block: don't recycle them. */
if (conn->pipe_a_b[0] != -1) { if (conn->pipe_a_b[0] != -1) {
close(conn->pipe_a_b[0]); close(conn->pipe_a_b[0]);
@ -337,7 +294,7 @@ static void tcp_splice_destroy(struct ctx *c, struct tcp_splice_conn *conn)
} }
} }
if (conn->events & CONNECT) { if (conn->events & SPLICE_CONNECT) {
close(conn->b); close(conn->b);
conn->b = -1; conn->b = -1;
} }
@ -346,7 +303,7 @@ static void tcp_splice_destroy(struct ctx *c, struct tcp_splice_conn *conn)
conn->a = -1; conn->a = -1;
conn->a_read = conn->a_written = conn->b_read = conn->b_written = 0; conn->a_read = conn->a_written = conn->b_read = conn->b_written = 0;
conn->events = CLOSED; conn->events = SPLICE_CLOSED;
conn->flags = 0; conn->flags = 0;
debug("TCP (spliced): index %li, CLOSED", CONN_IDX(conn)); debug("TCP (spliced): index %li, CLOSED", CONN_IDX(conn));
@ -397,8 +354,8 @@ static int tcp_splice_connect_finish(const struct ctx *c,
} }
} }
if (!(conn->events & ESTABLISHED)) if (!(conn->events & SPLICE_ESTABLISHED))
conn_event(c, conn, ESTABLISHED); conn_event(c, conn, SPLICE_ESTABLISHED);
return 0; return 0;
} }
@ -466,9 +423,9 @@ static int tcp_splice_connect(const struct ctx *c, struct tcp_splice_conn *conn,
close(sock_conn); close(sock_conn);
return ret; return ret;
} }
conn_event(c, conn, CONNECT); conn_event(c, conn, SPLICE_CONNECT);
} else { } else {
conn_event(c, conn, ESTABLISHED); conn_event(c, conn, SPLICE_ESTABLISHED);
return tcp_splice_connect_finish(c, conn); return tcp_splice_connect_finish(c, conn);
} }
@ -598,7 +555,7 @@ void tcp_sock_handler_splice(struct ctx *c, union epoll_ref ref,
conn = CONN(c->tcp.splice_conn_count++); conn = CONN(c->tcp.splice_conn_count++);
conn->a = s; conn->a = s;
conn->flags = ref.r.p.tcp.tcp.v6 ? SOCK_V6 : 0; conn->flags = ref.r.p.tcp.tcp.v6 ? SPLICE_V6 : 0;
if (tcp_splice_new(c, conn, ref.r.p.tcp.tcp.index, if (tcp_splice_new(c, conn, ref.r.p.tcp.tcp.index,
ref.r.p.tcp.tcp.outbound)) ref.r.p.tcp.tcp.outbound))
@ -609,13 +566,13 @@ void tcp_sock_handler_splice(struct ctx *c, union epoll_ref ref,
conn = CONN(ref.r.p.tcp.tcp.index); conn = CONN(ref.r.p.tcp.tcp.index);
if (conn->events == CLOSED) if (conn->events == SPLICE_CLOSED)
return; return;
if (events & EPOLLERR) if (events & EPOLLERR)
goto close; goto close;
if (conn->events == CONNECT) { if (conn->events == SPLICE_CONNECT) {
if (!(events & EPOLLOUT)) if (!(events & EPOLLOUT))
goto close; goto close;
if (tcp_splice_connect_finish(c, conn)) if (tcp_splice_connect_finish(c, conn))