Debian Codegraph @

examples/cgroup_skb/cgroup_skb.c

raw symbols SCIP
1 //go:build ignore
2
3 #include "common.h"
4
5 char __license[] SEC("license") = "Dual MIT/GPL";
6
7 struct {
8 __uint(type, BPF_MAP_TYPE_ARRAY);
9 __type(key, u32);
10 __type(value, u64);
11 __uint(max_entries, 1);
12 } pkt_count SEC(".maps");
13
14 SEC("cgroup_skb/egress")
15 int count_egress_packets(struct __sk_buff *skb) {
16 u32 key = 0;
17 u64 init_val = 1;
18
19 u64 *count = bpf_map_lookup_elem(&pkt_count, &key);
20 if (!count) {
21 bpf_map_update_elem(&pkt_count, &key, &init_val, BPF_ANY);
22 return 1;
23 }
24 __sync_fetch_and_add(count, 1);
25
26 return 1;
27 }