1 /* SPDX-License-Identifier: GPL-2.0 */
2 // Copyright (c) 2018 Politecnico di Torino
6 #include <linux/if_ether.h>
8 #include <linux/pkt_cls.h>
9 #include <bpf/bpf_helpers.h>
12 __uint(type, MAP_TYPE);
13 __uint(max_entries, 32);
16 __uint(value_size, sizeof(__u32));
17 } map_in SEC(".maps");
20 __uint(type, MAP_TYPE);
21 __uint(max_entries, 32);
24 __uint(value_size, sizeof(__u32));
25 } map_out SEC(".maps");
28 int _test(struct __sk_buff *skb)
30 void *data_end = (void *)(long)skb->data_end;
31 void *data = (void *)(long)skb->data;
32 struct ethhdr *eth = (struct ethhdr *)(data);
36 if (eth + 1 > data_end)
39 struct iphdr *iph = (struct iphdr *)(eth + 1);
41 if (iph + 1 > data_end)
44 err = bpf_map_pop_elem(&map_in, &value);
50 err = bpf_map_push_elem(&map_out, &iph->saddr, 0);
57 char _license[] SEC("license") = "GPL";