1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Copyright (c) 2020 Facebook */
4 #ifndef _TEST_TCP_HDR_OPTIONS_H
5 #define _TEST_TCP_HDR_OPTIONS_H
7 struct bpf_test_option
{
11 } __attribute__((packed
));
20 #define OPTION_F_RESEND (1 << OPTION_RESEND)
21 #define OPTION_F_MAX_DELACK_MS (1 << OPTION_MAX_DELACK_MS)
22 #define OPTION_F_RAND (1 << OPTION_RAND)
23 #define OPTION_MASK ((1 << __NR_OPTION_FLAGS) - 1)
25 #define TEST_OPTION_FLAGS(flags, option) (1 & ((flags) >> (option)))
26 #define SET_OPTION_FLAGS(flags, option) ((flags) |= (1 << (option)))
28 /* Store in bpf_sk_storage */
31 bool resend_syn
; /* active side only */
32 bool syncookie
; /* passive side only */
33 bool fastopen
; /* passive side only */
41 #define TCPHDR_FIN 0x01
42 #define TCPHDR_SYN 0x02
43 #define TCPHDR_RST 0x04
44 #define TCPHDR_PSH 0x08
45 #define TCPHDR_ACK 0x10
46 #define TCPHDR_URG 0x20
47 #define TCPHDR_ECE 0x40
48 #define TCPHDR_CWR 0x80
49 #define TCPHDR_SYNACK (TCPHDR_SYN | TCPHDR_ACK)
53 #define TCPOPT_WINDOW 3
54 #define TCPOPT_EXP 254
56 #define TCP_BPF_EXPOPT_BASE_LEN 4
57 #define MAX_TCP_HDR_LEN 60
58 #define MAX_TCP_OPTION_SPACE 40
60 #ifdef BPF_PROG_TEST_TCP_HDR_OPTIONS
69 struct tcp_exprm_opt
{
77 } __attribute__((packed
));
86 } __attribute__((packed
));
89 __uint(type
, BPF_MAP_TYPE_HASH
);
90 __uint(max_entries
, 2);
92 __type(value
, struct linum_err
);
93 } lport_linum_map
SEC(".maps");
95 static inline unsigned int tcp_hdrlen(const struct tcphdr
*th
)
100 static inline __u8
skops_tcp_flags(const struct bpf_sock_ops
*skops
)
102 return skops
->skb_tcp_flags
;
105 static inline void clear_hdr_cb_flags(struct bpf_sock_ops
*skops
)
107 bpf_sock_ops_cb_flags_set(skops
,
108 skops
->bpf_sock_ops_cb_flags
&
109 ~(BPF_SOCK_OPS_PARSE_UNKNOWN_HDR_OPT_CB_FLAG
|
110 BPF_SOCK_OPS_WRITE_HDR_OPT_CB_FLAG
));
113 static inline void set_hdr_cb_flags(struct bpf_sock_ops
*skops
, __u32 extra
)
115 bpf_sock_ops_cb_flags_set(skops
,
116 skops
->bpf_sock_ops_cb_flags
|
117 BPF_SOCK_OPS_PARSE_UNKNOWN_HDR_OPT_CB_FLAG
|
118 BPF_SOCK_OPS_WRITE_HDR_OPT_CB_FLAG
|
122 clear_parse_all_hdr_cb_flags(struct bpf_sock_ops
*skops
)
124 bpf_sock_ops_cb_flags_set(skops
,
125 skops
->bpf_sock_ops_cb_flags
&
126 ~BPF_SOCK_OPS_PARSE_ALL_HDR_OPT_CB_FLAG
);
130 set_parse_all_hdr_cb_flags(struct bpf_sock_ops
*skops
)
132 bpf_sock_ops_cb_flags_set(skops
,
133 skops
->bpf_sock_ops_cb_flags
|
134 BPF_SOCK_OPS_PARSE_ALL_HDR_OPT_CB_FLAG
);
137 #define RET_CG_ERR(__err) ({ \
138 struct linum_err __linum_err; \
141 __linum_err.linum = __LINE__; \
142 __linum_err.err = __err; \
143 __lport = skops->local_port; \
144 bpf_map_update_elem(&lport_linum_map, &__lport, &__linum_err, BPF_NOEXIST); \
145 clear_hdr_cb_flags(skops); \
146 clear_parse_all_hdr_cb_flags(skops); \
150 #endif /* BPF_PROG_TEST_TCP_HDR_OPTIONS */
152 #endif /* _TEST_TCP_HDR_OPTIONS_H */