xref: /linux/tools/testing/selftests/bpf/bpf_sockopt_helpers.h (revision e3b2949e3fa2fd8c19cd5fbb0424d38f70a70e9c)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 
3 #include <sys/socket.h>
4 #include <bpf/bpf_helpers.h>
5 
6 int get_set_sk_priority(void *ctx)
7 {
8 	int prio;
9 
10 	/* Verify that context allows calling bpf_getsockopt and
11 	 * bpf_setsockopt by reading and writing back socket
12 	 * priority.
13 	 */
14 
15 	if (bpf_getsockopt(ctx, SOL_SOCKET, SO_PRIORITY, &prio, sizeof(prio)))
16 		return 0;
17 	if (bpf_setsockopt(ctx, SOL_SOCKET, SO_PRIORITY, &prio, sizeof(prio)))
18 		return 0;
19 
20 	return 1;
21 }
22