1 /* Copyright (c) 2016 Facebook
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of version 2 of the GNU General Public
5 * License as published by the Free Software Foundation.
8 #include <linux/ipv6.h>
10 #include <linux/tcp.h>
11 #include <linux/udp.h>
12 #include <uapi/linux/bpf.h>
14 #include "bpf_helpers.h"
16 #define DEFAULT_PKTGEN_UDP_PORT 9
18 /* copy of 'struct ethhdr' without __packed */
20 unsigned char h_dest
[ETH_ALEN
];
21 unsigned char h_source
[ETH_ALEN
];
22 unsigned short h_proto
;
26 int handle_ingress(struct __sk_buff
*skb
)
28 void *data
= (void *)(long)skb
->data
;
29 struct eth_hdr
*eth
= data
;
30 struct iphdr
*iph
= data
+ sizeof(*eth
);
31 struct udphdr
*udp
= data
+ sizeof(*eth
) + sizeof(*iph
);
32 void *data_end
= (void *)(long)skb
->data_end
;
34 /* single length check */
35 if (data
+ sizeof(*eth
) + sizeof(*iph
) + sizeof(*udp
) > data_end
)
38 if (eth
->h_proto
!= htons(ETH_P_IP
))
40 if (iph
->protocol
!= IPPROTO_UDP
|| iph
->ihl
!= 5)
42 if (ip_is_fragment(iph
))
44 if (udp
->dest
== htons(DEFAULT_PKTGEN_UDP_PORT
))
48 char _license
[] SEC("license") = "GPL";