FILE
mptcp_sockmap.c
File preview with syntax highlighting.
linux-6.19.14/tools/testing/selftests/bpf/progs/mptcp_sockmap.c
1// SPDX-License-Identifier: GPL-2.0 2 3#include "bpf_tracing_net.h" 4 5char _license[] SEC("license") = "GPL"; 6 7int sk_index; 8int redirect_idx; 9int trace_port; 10int helper_ret; 11struct { 12 __uint(type, BPF_MAP_TYPE_SOCKMAP); 13 __uint(key_size, sizeof(__u32)); 14 __uint(value_size, sizeof(__u32)); 15 __uint(max_entries, 100); 16} sock_map SEC(".maps"); 17 18SEC("sockops") 19int mptcp_sockmap_inject(struct bpf_sock_ops *skops) 20{ 21 struct bpf_sock *sk; 22 23 /* only accept specified connection */ 24 if (skops->local_port != trace_port || 25 skops->op != BPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB) 26 return 1; 27 28 sk = skops->sk; 29 if (!sk) 30 return 1; 31 32 /* update sk handler */ 33 helper_ret = bpf_sock_map_update(skops, &sock_map, &sk_index, BPF_NOEXIST); 34 35 return 1; 36} 37 38SEC("sk_skb/stream_verdict") 39int mptcp_sockmap_redirect(struct __sk_buff *skb) 40{ 41 /* redirect skb to the sk under sock_map[redirect_idx] */ 42 return bpf_sk_redirect_map(skb, &sock_map, redirect_idx, 0); 43}
~/
Read-only file preview.