16 #ifndef included_tcp_packet_h 17 #define included_tcp_packet_h 22 #define foreach_tcp_flag \ 34 #define _(f) TCP_FLAG_BIT_##f, 42 #define _(f) TCP_FLAG_##f = 1 << TCP_FLAG_BIT_##f, 47 typedef struct _tcp_header
69 u8 data_offset_and_reserved;
78 #define tcp_doff(_th) ((_th)->data_offset_and_reserved >> 4) 79 #define tcp_fin(_th) ((_th)->flags & TCP_FLAG_FIN) 80 #define tcp_syn(_th) ((_th)->flags & TCP_FLAG_SYN) 81 #define tcp_rst(_th) ((_th)->flags & TCP_FLAG_RST) 82 #define tcp_psh(_th) ((_th)->flags & TCP_FLAG_PSH) 83 #define tcp_ack(_th) ((_th)->flags & TCP_FLAG_ACK) 84 #define tcp_urg(_th) ((_th)->flags & TCP_FLAG_URG) 85 #define tcp_ece(_th) ((_th)->flags & TCP_FLAG_ECE) 86 #define tcp_cwr(_th) ((_th)->flags & TCP_FLAG_CWR) 89 #define tcp_is_syn(_th) !!((_th)->flags & TCP_FLAG_SYN) 90 #define tcp_is_fin(_th) !!((_th)->flags & TCP_FLAG_FIN) 115 #define foreach_tcp_options_flag \ 124 #define _(f) TCP_OPTS_FLAG_BIT_##f, 132 #define _(f) TCP_OPTS_FLAG_##f = 1 << TCP_OPTS_FLAG_BIT_##f, 137 typedef struct _sack_block
155 #define tcp_opts_mss(_to) ((_to)->flags & TCP_OPTS_FLAG_MSS) 156 #define tcp_opts_tstamp(_to) ((_to)->flags & TCP_OPTS_FLAG_TSTAMP) 157 #define tcp_opts_wscale(_to) ((_to)->flags & TCP_OPTS_FLAG_WSCALE) 158 #define tcp_opts_sack(_to) ((_to)->flags & TCP_OPTS_FLAG_SACK) 159 #define tcp_opts_sack_permitted(_to) ((_to)->flags & TCP_OPTS_FLAG_SACK_PERMITTED) 162 #define TCP_OPTION_LEN_EOL 1 163 #define TCP_OPTION_LEN_NOOP 1 164 #define TCP_OPTION_LEN_MSS 4 165 #define TCP_OPTION_LEN_WINDOW_SCALE 3 166 #define TCP_OPTION_LEN_SACK_PERMITTED 2 167 #define TCP_OPTION_LEN_TIMESTAMP 10 168 #define TCP_OPTION_LEN_SACK_BLOCK 8 170 #define TCP_HDR_LEN_MAX 60 171 #define TCP_WND_MAX 65535U 172 #define TCP_MAX_WND_SCALE 14 173 #define TCP_OPTS_ALIGN 4 174 #define TCP_OPTS_MAX_SACK_BLOCKS 3 175 #define TCP_MAX_GSO_SZ 65536 178 #define seq_lt(_s1, _s2) ((i32)((_s1)-(_s2)) < 0) 179 #define seq_leq(_s1, _s2) ((i32)((_s1)-(_s2)) <= 0) 180 #define seq_gt(_s1, _s2) ((i32)((_s1)-(_s2)) > 0) 181 #define seq_geq(_s1, _s2) ((i32)((_s1)-(_s2)) >= 0) 182 #define seq_max(_s1, _s2) (seq_gt((_s1), (_s2)) ? (_s1) : (_s2)) 185 #define timestamp_lt(_t1, _t2) ((i32)((_t1)-(_t2)) < 0) 186 #define timestamp_leq(_t1, _t2) ((i32)((_t1)-(_t2)) <= 0) 200 u8 opt_len, opts_len, kind;
205 data = (
const u8 *) (th + 1);
208 to->
flags &= (TCP_OPTS_FLAG_SACK_PERMITTED | TCP_OPTS_FLAG_WSCALE
209 | TCP_OPTS_FLAG_TSTAMP | TCP_OPTS_FLAG_MSS);
211 for (; opts_len > 0; opts_len -= opt_len, data += opt_len)
231 if (opt_len < 2 || opt_len > opts_len)
243 to->
flags |= TCP_OPTS_FLAG_MSS;
244 to->
mss = clib_net_to_host_u16 (*(
u16 *) (data + 2));
252 to->
flags |= TCP_OPTS_FLAG_WSCALE;
260 to->
flags |= TCP_OPTS_FLAG_TSTAMP;
261 if ((to->
flags & TCP_OPTS_FLAG_TSTAMP)
264 to->
tsval = clib_net_to_host_u32 (*(
u32 *) (data + 2));
265 to->
tsecr = clib_net_to_host_u32 (*(
u32 *) (data + 6));
272 to->
flags |= TCP_OPTS_FLAG_SACK_PERMITTED;
276 if ((to->
flags & TCP_OPTS_FLAG_SACK_PERMITTED) == 0 ||
tcp_syn (th))
283 to->
flags |= TCP_OPTS_FLAG_SACK;
288 b.start = clib_net_to_host_u32 (*(
u32 *) (data + 2 + 8 * j));
289 b.end = clib_net_to_host_u32 (*(
u32 *) (data + 6 + 8 * j));
312 u32 buf, seq_len = 4;
318 buf = clib_host_to_net_u16 (opts->
mss);
320 data +=
sizeof (opts->
mss);
343 buf = clib_host_to_net_u32 (opts->
tsval);
345 data +=
sizeof (opts->
tsval);
346 buf = clib_host_to_net_u32 (opts->
tsecr);
348 data +=
sizeof (opts->
tsecr);
362 buf = clib_host_to_net_u32 (opts->
sacks[i].start);
365 buf = clib_host_to_net_u32 (opts->
sacks[i].end);
#define TCP_OPTION_LEN_EOL
#define TCP_OPTION_LEN_SACK_PERMITTED
struct _sack_block sack_block_t
vl_api_wireguard_peer_flags_t flags
#define tcp_opts_tstamp(_to)
vl_api_ip_port_and_mask_t dst_port
#define clib_memcpy_fast(a, b, c)
static u32 tcp_options_write(u8 *data, tcp_options_t *opts)
Write TCP options to segment.
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
#define tcp_opts_sack(_to)
u8 n_sack_blocks
Number of SACKs blocks.
struct _tcp_header tcp_header_t
u8 wscale
Option flags, see above.
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
static int tcp_options_parse(tcp_header_t *th, tcp_options_t *to, u8 is_syn)
Parse TCP header options.
#define TCP_OPTION_LEN_SACK_BLOCK
enum tcp_option_type tcp_option_type_t
sack_block_t * sacks
SACK blocks.
#define foreach_tcp_options_flag
SACK present.
#define TCP_OPTION_LEN_WINDOW_SCALE
#define tcp_opts_mss(_to)
#define TCP_OPTION_LEN_TIMESTAMP
#define TCP_MAX_WND_SCALE
vl_api_ip_port_and_mask_t src_port
sll srl srl sll sra u16x4 i
u16 mss
Maximum segment size advertised.
#define foreach_tcp_flag
Sender reduced congestion window.
#define tcp_opts_wscale(_to)
u32 tsval
Timestamp value.
u32 tsecr
Echoed/reflected time stamp.
#define TCP_OPTION_LEN_MSS
static int tcp_header_bytes(tcp_header_t *t)
#define TCP_OPTION_LEN_NOOP
f64 end
end of the time range
#define tcp_opts_sack_permitted(_to)