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