xref: /linux/tools/testing/selftests/bpf/progs/mptcp_bpf.h (revision 7f71507851fc7764b36a3221839607d3a45c2025)
1 /* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */
2 #ifndef __MPTCP_BPF_H__
3 #define __MPTCP_BPF_H__
4 
5 #include "bpf_experimental.h"
6 
7 /* list helpers from include/linux/list.h */
8 static inline int list_is_head(const struct list_head *list,
9 			       const struct list_head *head)
10 {
11 	return list == head;
12 }
13 
14 #define list_entry(ptr, type, member)					\
15 	container_of(ptr, type, member)
16 
17 #define list_first_entry(ptr, type, member)				\
18 	list_entry((ptr)->next, type, member)
19 
20 #define list_next_entry(pos, member)					\
21 	list_entry((pos)->member.next, typeof(*(pos)), member)
22 
23 #define list_entry_is_head(pos, head, member)				\
24 	list_is_head(&pos->member, (head))
25 
26 /* small difference: 'can_loop' has been added in the conditions */
27 #define list_for_each_entry(pos, head, member)				\
28 	for (pos = list_first_entry(head, typeof(*pos), member);	\
29 	     !list_entry_is_head(pos, head, member) && can_loop;	\
30 	     pos = list_next_entry(pos, member))
31 
32 /* mptcp helpers from protocol.h */
33 #define mptcp_for_each_subflow(__msk, __subflow)			\
34 	list_for_each_entry(__subflow, &((__msk)->conn_list), node)
35 
36 static __always_inline struct sock *
37 mptcp_subflow_tcp_sock(const struct mptcp_subflow_context *subflow)
38 {
39 	return subflow->tcp_sock;
40 }
41 
42 #endif
43