2024-06-13 12:36:49 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
* Copyright (c) 2021 Red Hat GmbH
|
|
|
|
* Author: Stefano Brivio <sbrivio@redhat.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef TCP_INTERNAL_H
|
|
|
|
#define TCP_INTERNAL_H
|
|
|
|
|
|
|
|
#define MAX_WS 8
|
|
|
|
#define MAX_WINDOW (1 << (16 + (MAX_WS)))
|
|
|
|
|
|
|
|
#define MSS4 ROUND_DOWN(IP_MAX_MTU - \
|
|
|
|
sizeof(struct tcphdr) - \
|
|
|
|
sizeof(struct iphdr), \
|
|
|
|
sizeof(uint32_t))
|
|
|
|
#define MSS6 ROUND_DOWN(IP_MAX_MTU - \
|
|
|
|
sizeof(struct tcphdr) - \
|
|
|
|
sizeof(struct ipv6hdr), \
|
|
|
|
sizeof(uint32_t))
|
|
|
|
|
|
|
|
#define SEQ_LE(a, b) ((b) - (a) < MAX_WINDOW)
|
|
|
|
#define SEQ_LT(a, b) ((b) - (a) - 1 < MAX_WINDOW)
|
|
|
|
#define SEQ_GE(a, b) ((a) - (b) < MAX_WINDOW)
|
|
|
|
#define SEQ_GT(a, b) ((a) - (b) - 1 < MAX_WINDOW)
|
|
|
|
|
|
|
|
#define FIN (1 << 0)
|
|
|
|
#define SYN (1 << 1)
|
|
|
|
#define RST (1 << 2)
|
|
|
|
#define ACK (1 << 4)
|
|
|
|
|
|
|
|
/* Flags for internal usage */
|
|
|
|
#define DUP_ACK (1 << 5)
|
|
|
|
#define OPT_EOL 0
|
|
|
|
#define OPT_NOP 1
|
|
|
|
#define OPT_MSS 2
|
|
|
|
#define OPT_MSS_LEN 4
|
|
|
|
#define OPT_WS 3
|
|
|
|
#define OPT_WS_LEN 3
|
|
|
|
#define OPT_SACKP 4
|
|
|
|
#define OPT_SACK 5
|
|
|
|
#define OPT_TS 8
|
2024-07-18 05:26:29 +00:00
|
|
|
|
|
|
|
#define TAPSIDE(conn_) ((conn_)->f.pif[1] == PIF_TAP)
|
|
|
|
#define TAPFLOW(conn_) (&((conn_)->f.side[TAPSIDE(conn_)]))
|
2024-07-18 05:26:35 +00:00
|
|
|
#define TAP_SIDX(conn_) (FLOW_SIDX((conn_), TAPSIDE(conn_)))
|
2024-07-18 05:26:29 +00:00
|
|
|
|
2024-08-21 04:19:57 +00:00
|
|
|
#define CONN_V4(conn) (!!inany_v4(&TAPFLOW(conn)->oaddr))
|
2024-06-13 12:36:49 +00:00
|
|
|
#define CONN_V6(conn) (!CONN_V4(conn))
|
|
|
|
|
|
|
|
/*
|
|
|
|
* enum tcp_iov_parts - I/O vector parts for one TCP frame
|
|
|
|
* @TCP_IOV_TAP tap backend specific header
|
|
|
|
* @TCP_IOV_ETH Ethernet header
|
|
|
|
* @TCP_IOV_IP IP (v4/v6) header
|
|
|
|
* @TCP_IOV_PAYLOAD IP payload (TCP header + data)
|
|
|
|
* @TCP_NUM_IOVS the number of entries in the iovec array
|
|
|
|
*/
|
|
|
|
enum tcp_iov_parts {
|
|
|
|
TCP_IOV_TAP = 0,
|
|
|
|
TCP_IOV_ETH = 1,
|
|
|
|
TCP_IOV_IP = 2,
|
|
|
|
TCP_IOV_PAYLOAD = 3,
|
|
|
|
TCP_NUM_IOVS
|
|
|
|
};
|
|
|
|
|
2024-10-03 14:51:04 +00:00
|
|
|
/**
|
|
|
|
* struct tcp_payload_t - TCP header and data to send segments with payload
|
|
|
|
* @th: TCP header
|
|
|
|
* @data: TCP data
|
|
|
|
*/
|
|
|
|
struct tcp_payload_t {
|
|
|
|
struct tcphdr th;
|
|
|
|
uint8_t data[IP_MAX_MTU - sizeof(struct tcphdr)];
|
|
|
|
#ifdef __AVX2__
|
|
|
|
} __attribute__ ((packed, aligned(32))); /* For AVX2 checksum routines */
|
|
|
|
#else
|
|
|
|
} __attribute__ ((packed, aligned(__alignof__(unsigned int))));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct tcp_flags_t - TCP header and data to send zero-length
|
|
|
|
* segments (flags)
|
|
|
|
* @th: TCP header
|
|
|
|
* @opts TCP options
|
|
|
|
*/
|
|
|
|
struct tcp_flags_t {
|
|
|
|
struct tcphdr th;
|
|
|
|
char opts[OPT_MSS_LEN + OPT_WS_LEN + 1];
|
|
|
|
#ifdef __AVX2__
|
|
|
|
} __attribute__ ((packed, aligned(32)));
|
|
|
|
#else
|
|
|
|
} __attribute__ ((packed, aligned(__alignof__(unsigned int))));
|
|
|
|
#endif
|
|
|
|
|
2024-06-13 12:36:49 +00:00
|
|
|
extern char tcp_buf_discard [MAX_WINDOW];
|
|
|
|
|
|
|
|
void conn_flag_do(const struct ctx *c, struct tcp_tap_conn *conn,
|
|
|
|
unsigned long flag);
|
|
|
|
#define conn_flag(c, conn, flag) \
|
|
|
|
do { \
|
|
|
|
flow_trace(conn, "flag at %s:%i", __func__, __LINE__); \
|
|
|
|
conn_flag_do(c, conn, flag); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
|
|
|
|
void conn_event_do(const struct ctx *c, struct tcp_tap_conn *conn,
|
|
|
|
unsigned long event);
|
|
|
|
#define conn_event(c, conn, event) \
|
|
|
|
do { \
|
|
|
|
flow_trace(conn, "event at %s:%i", __func__, __LINE__); \
|
|
|
|
conn_event_do(c, conn, event); \
|
|
|
|
} while (0)
|
|
|
|
|
2024-09-18 01:53:05 +00:00
|
|
|
void tcp_rst_do(const struct ctx *c, struct tcp_tap_conn *conn);
|
2024-06-13 12:36:49 +00:00
|
|
|
#define tcp_rst(c, conn) \
|
|
|
|
do { \
|
|
|
|
flow_dbg((conn), "TCP reset at %s:%i", __func__, __LINE__); \
|
|
|
|
tcp_rst_do(c, conn); \
|
|
|
|
} while (0)
|
|
|
|
|
2024-07-18 05:26:30 +00:00
|
|
|
size_t tcp_l2_buf_fill_headers(const struct tcp_tap_conn *conn,
|
2024-06-13 12:36:49 +00:00
|
|
|
struct iovec *iov, size_t dlen,
|
2024-09-18 13:13:28 +00:00
|
|
|
const uint16_t *check, uint32_t seq,
|
|
|
|
bool no_tcp_csum);
|
2024-06-13 12:36:49 +00:00
|
|
|
int tcp_update_seqack_wnd(const struct ctx *c, struct tcp_tap_conn *conn,
|
2024-09-18 01:53:07 +00:00
|
|
|
bool force_seq, struct tcp_info *tinfo);
|
2024-09-18 01:53:05 +00:00
|
|
|
int tcp_prepare_flags(const struct ctx *c, struct tcp_tap_conn *conn, int flags,
|
2024-06-13 12:36:49 +00:00
|
|
|
struct tcphdr *th, char *data, size_t *optlen);
|
|
|
|
|
|
|
|
#endif /* TCP_INTERNAL_H */
|