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