1 // SPDX-License-Identifier: GPL-2.0
5 #include <bpf/bpf_helpers.h>
10 __uint(type, BPF_MAP_TYPE_SK_STORAGE);
11 __uint(map_flags, BPF_F_NO_PREALLOC);
14 } sockops_netns_cookies SEC(".maps");
17 __uint(type, BPF_MAP_TYPE_SK_STORAGE);
18 __uint(map_flags, BPF_F_NO_PREALLOC);
21 } sk_msg_netns_cookies SEC(".maps");
24 __uint(type, BPF_MAP_TYPE_SOCKMAP);
25 __uint(max_entries, 2);
28 } sock_map SEC(".maps");
30 int tcx_init_netns_cookie, tcx_netns_cookie;
33 int get_netns_cookie_sockops(struct bpf_sock_ops *ctx)
35 struct bpf_sock *sk = ctx->sk;
39 if (ctx->family != AF_INET6)
46 case BPF_SOCK_OPS_TCP_CONNECT_CB:
47 cookie = bpf_sk_storage_get(&sockops_netns_cookies, sk, 0,
48 BPF_SK_STORAGE_GET_F_CREATE);
52 *cookie = bpf_get_netns_cookie(ctx);
54 case BPF_SOCK_OPS_ACTIVE_ESTABLISHED_CB:
55 bpf_sock_map_update(ctx, &sock_map, &key, BPF_NOEXIST);
65 int get_netns_cookie_sk_msg(struct sk_msg_md *msg)
67 struct bpf_sock *sk = msg->sk;
70 if (msg->family != AF_INET6)
76 cookie = bpf_sk_storage_get(&sk_msg_netns_cookies, sk, 0,
77 BPF_SK_STORAGE_GET_F_CREATE);
81 *cookie = bpf_get_netns_cookie(msg);
87 int get_netns_cookie_tcx(struct __sk_buff *skb)
89 tcx_init_netns_cookie = bpf_get_netns_cookie(NULL);
90 tcx_netns_cookie = bpf_get_netns_cookie(skb);
94 char _license[] SEC("license") = "GPL";