1 // SPDX-License-Identifier: GPL-2.0
4 #include <bpf/bpf_endian.h>
5 #include <bpf/bpf_helpers.h>
6 #include <linux/if_ether.h>
9 /* This function extracts the last byte of the daddr, and uses it
10 * as output dev index.
13 int test_lwt_reroute(struct __sk_buff *skb)
15 struct iphdr *iph = NULL;
16 void *start = (void *)(long)skb->data;
17 void *end = (void *)(long)skb->data_end;
19 /* set mark at most once */
23 if (start + sizeof(*iph) > end)
26 iph = (struct iphdr *)start;
27 skb->mark = bpf_ntohl(iph->daddr) & 0xff;
29 /* do not reroute x.x.x.0 packets */
33 return BPF_LWT_REROUTE;
36 char _license[] SEC("license") = "GPL";