1// SPDX-License-Identifier: GPL-2.0
2/* Copyright (c) 2020 Facebook */
3#include "bpf_iter.h"
4#include "bpf_tracing_net.h"
5#include <bpf/bpf_helpers.h>
6#include <bpf/bpf_tracing.h>
7
8char _license[] SEC("license") = "GPL";
9
10struct {
11	__uint(type, BPF_MAP_TYPE_SK_STORAGE);
12	__uint(map_flags, BPF_F_NO_PREALLOC);
13	__type(key, int);
14	__type(value, int);
15} sk_stg_map SEC(".maps");
16
17__u32 val_sum = 0;
18__u32 ipv6_sk_count = 0;
19__u32 to_add_val = 0;
20
21SEC("iter/bpf_sk_storage_map")
22int rw_bpf_sk_storage_map(struct bpf_iter__bpf_sk_storage_map *ctx)
23{
24	struct sock *sk = ctx->sk;
25	__u32 *val = ctx->value;
26
27	if (sk == NULL || val == NULL)
28		return 0;
29
30	if (sk->sk_family == AF_INET6)
31		ipv6_sk_count++;
32
33	val_sum += *val;
34
35	*val += to_add_val;
36
37	return 0;
38}
39
40SEC("iter/bpf_sk_storage_map")
41int oob_write_bpf_sk_storage_map(struct bpf_iter__bpf_sk_storage_map *ctx)
42{
43	struct sock *sk = ctx->sk;
44	__u32 *val = ctx->value;
45
46	if (sk == NULL || val == NULL)
47		return 0;
48
49	*(val + 1) = 0xdeadbeef;
50
51	return 0;
52}
53