staging: rtl8192u: remove redundant assignment to pointer crypt
[linux/fpc-iii.git] / tools / testing / selftests / bpf / progs / socket_cookie_prog.c
blobe4440fdd94cbe7729b4e050c19a7ade8f34e9d74
1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (c) 2018 Facebook
4 #include <linux/bpf.h>
5 #include <sys/socket.h>
7 #include "bpf_helpers.h"
8 #include "bpf_endian.h"
10 struct socket_cookie {
11 __u64 cookie_key;
12 __u32 cookie_value;
15 struct {
16 __uint(type, BPF_MAP_TYPE_SK_STORAGE);
17 __uint(map_flags, BPF_F_NO_PREALLOC);
18 __type(key, int);
19 __type(value, struct socket_cookie);
20 } socket_cookies SEC(".maps");
22 SEC("cgroup/connect6")
23 int set_cookie(struct bpf_sock_addr *ctx)
25 struct socket_cookie *p;
27 if (ctx->family != AF_INET6 || ctx->user_family != AF_INET6)
28 return 1;
30 p = bpf_sk_storage_get(&socket_cookies, ctx->sk, 0,
31 BPF_SK_STORAGE_GET_F_CREATE);
32 if (!p)
33 return 1;
35 p->cookie_value = 0xFF;
36 p->cookie_key = bpf_get_socket_cookie(ctx);
38 return 1;
41 SEC("sockops")
42 int update_cookie(struct bpf_sock_ops *ctx)
44 struct bpf_sock *sk;
45 struct socket_cookie *p;
47 if (ctx->family != AF_INET6)
48 return 1;
50 if (ctx->op != BPF_SOCK_OPS_TCP_CONNECT_CB)
51 return 1;
53 if (!ctx->sk)
54 return 1;
56 p = bpf_sk_storage_get(&socket_cookies, ctx->sk, 0, 0);
57 if (!p)
58 return 1;
60 if (p->cookie_key != bpf_get_socket_cookie(ctx))
61 return 1;
63 p->cookie_value = (ctx->local_port << 8) | p->cookie_value;
65 return 1;
68 int _version SEC("version") = 1;
70 char _license[] SEC("license") = "GPL";