1 // SPDX-License-Identifier: GPL-2.0
5 #include <linux/if_ether.h>
6 #include <linux/if_packet.h>
8 #include <linux/types.h>
9 #include <linux/socket.h>
10 #include <linux/tcp.h>
11 #include <netinet/in.h>
12 #include "bpf_helpers.h"
13 #include "bpf_endian.h"
14 #include "test_tcpbpf.h"
16 struct bpf_map_def
SEC("maps") global_map
= {
17 .type
= BPF_MAP_TYPE_ARRAY
,
18 .key_size
= sizeof(__u32
),
19 .value_size
= sizeof(struct tcpbpf_globals
),
23 static inline void update_event_map(int event
)
26 struct tcpbpf_globals g
, *gp
;
28 gp
= bpf_map_lookup_elem(&global_map
, &key
);
30 struct tcpbpf_globals g
= {0};
32 g
.event_map
|= (1 << event
);
33 bpf_map_update_elem(&global_map
, &key
, &g
,
37 g
.event_map
|= (1 << event
);
38 bpf_map_update_elem(&global_map
, &key
, &g
,
43 int _version
SEC("version") = 1;
46 int bpf_testcb(struct bpf_sock_ops
*skops
)
59 case BPF_SOCK_OPS_ACTIVE_ESTABLISHED_CB
:
60 /* Test failure to set largest cb flag (assumes not defined) */
61 bad_call_rv
= bpf_sock_ops_cb_flags_set(skops
, 0x80);
63 good_call_rv
= bpf_sock_ops_cb_flags_set(skops
,
64 BPF_SOCK_OPS_STATE_CB_FLAG
);
68 struct tcpbpf_globals g
, *gp
;
70 gp
= bpf_map_lookup_elem(&global_map
, &key
);
74 g
.bad_cb_test_rv
= bad_call_rv
;
75 g
.good_cb_test_rv
= good_call_rv
;
76 bpf_map_update_elem(&global_map
, &key
, &g
,
80 case BPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB
:
81 skops
->sk_txhash
= 0x12345f;
83 rv
= bpf_setsockopt(skops
, SOL_IPV6
, IPV6_TCLASS
, &v
,
86 case BPF_SOCK_OPS_RTO_CB
:
88 case BPF_SOCK_OPS_RETRANS_CB
:
90 case BPF_SOCK_OPS_STATE_CB
:
91 if (skops
->args
[1] == BPF_TCP_CLOSE
) {
93 struct tcpbpf_globals g
, *gp
;
95 gp
= bpf_map_lookup_elem(&global_map
, &key
);
99 if (skops
->args
[0] == BPF_TCP_LISTEN
) {
102 g
.total_retrans
= skops
->total_retrans
;
103 g
.data_segs_in
= skops
->data_segs_in
;
104 g
.data_segs_out
= skops
->data_segs_out
;
105 g
.bytes_received
= skops
->bytes_received
;
106 g
.bytes_acked
= skops
->bytes_acked
;
108 bpf_map_update_elem(&global_map
, &key
, &g
,
112 case BPF_SOCK_OPS_TCP_LISTEN_CB
:
113 bpf_sock_ops_cb_flags_set(skops
, BPF_SOCK_OPS_STATE_CB_FLAG
);
121 char _license
[] SEC("license") = "GPL";