File Index
Files and directories
Sign in
FILE

sockmap_helpers.h

File preview with syntax highlighting.

linux-6.19.14/tools/testing/selftests/bpf/prog_tests/sockmap_helpers.h C
 1#ifndef __SOCKMAP_HELPERS__
 2#define __SOCKMAP_HELPERS__
 3
 4#include "socket_helpers.h"
 5
 6#define MAX_TEST_NAME 80
 7
 8#define u32(v) ((u32){(v)})
 9#define u64(v) ((u64){(v)})
10
11#define __always_unused	__attribute__((__unused__))
12
13#define xbpf_map_delete_elem(fd, key)                                          \
14	({                                                                     \
15		int __ret = bpf_map_delete_elem((fd), (key));                  \
16		if (__ret < 0)                                                 \
17			FAIL_ERRNO("map_delete");                              \
18		__ret;                                                         \
19	})
20
21#define xbpf_map_lookup_elem(fd, key, val)                                     \
22	({                                                                     \
23		int __ret = bpf_map_lookup_elem((fd), (key), (val));           \
24		if (__ret < 0)                                                 \
25			FAIL_ERRNO("map_lookup");                              \
26		__ret;                                                         \
27	})
28
29#define xbpf_map_update_elem(fd, key, val, flags)                              \
30	({                                                                     \
31		int __ret = bpf_map_update_elem((fd), (key), (val), (flags));  \
32		if (__ret < 0)                                                 \
33			FAIL_ERRNO("map_update");                              \
34		__ret;                                                         \
35	})
36
37#define xbpf_prog_attach(prog, target, type, flags)                            \
38	({                                                                     \
39		int __ret =                                                    \
40			bpf_prog_attach((prog), (target), (type), (flags));    \
41		if (__ret < 0)                                                 \
42			FAIL_ERRNO("prog_attach(" #type ")");                  \
43		__ret;                                                         \
44	})
45
46#define xbpf_prog_detach2(prog, target, type)                                  \
47	({                                                                     \
48		int __ret = bpf_prog_detach2((prog), (target), (type));        \
49		if (__ret < 0)                                                 \
50			FAIL_ERRNO("prog_detach2(" #type ")");                 \
51		__ret;                                                         \
52	})
53
54#define xpthread_create(thread, attr, func, arg)                               \
55	({                                                                     \
56		int __ret = pthread_create((thread), (attr), (func), (arg));   \
57		errno = __ret;                                                 \
58		if (__ret)                                                     \
59			FAIL_ERRNO("pthread_create");                          \
60		__ret;                                                         \
61	})
62
63#define xpthread_join(thread, retval)                                          \
64	({                                                                     \
65		int __ret = pthread_join((thread), (retval));                  \
66		errno = __ret;                                                 \
67		if (__ret)                                                     \
68			FAIL_ERRNO("pthread_join");                            \
69		__ret;                                                         \
70	})
71
72static inline int add_to_sockmap(int mapfd, int fd1, int fd2)
73{
74	int err;
75
76	err = xbpf_map_update_elem(mapfd, &u32(0), &u64(fd1), BPF_NOEXIST);
77	if (err)
78		return err;
79
80	return xbpf_map_update_elem(mapfd, &u32(1), &u64(fd2), BPF_NOEXIST);
81}
82
83#endif // __SOCKMAP_HELPERS__
~/ Read-only file preview.