xref: /linux/tools/testing/selftests/bpf/progs/test_sockmap_invalid_update.c (revision a1c3be890440a1769ed6f822376a3e3ab0d42994)
1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (c) 2020 Cloudflare
3 #include "vmlinux.h"
4 #include <bpf/bpf_helpers.h>
5 
6 struct {
7 	__uint(type, BPF_MAP_TYPE_SOCKMAP);
8 	__uint(max_entries, 1);
9 	__type(key, __u32);
10 	__type(value, __u64);
11 } map SEC(".maps");
12 
13 SEC("sockops")
14 int bpf_sockmap(struct bpf_sock_ops *skops)
15 {
16 	__u32 key = 0;
17 
18 	if (skops->sk)
19 		bpf_map_update_elem(&map, &key, skops->sk, 0);
20 	return 0;
21 }
22 
23 char _license[] SEC("license") = "GPL";
24