1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Intel Corporation
7 * Accepts pointer to first segment packet data as an input parameter.
8 * analog of tcpdump -s 1 -d 'dst 1.2.3.4 && udp && dst port 5000'
10 * (001) jeq #0x800 jt 2 jf 12
12 * (003) jeq #0x1020304 jt 4 jf 12
14 * (005) jeq #0x11 jt 6 jf 12
16 * (007) jset #0x1fff jt 12 jf 8
17 * (008) ldxb 4*([14]&0xf)
19 * (010) jeq #0x1388 jt 11 jf 12
24 * clang -O2 -target bpf -c t1.c
28 #include <net/ethernet.h>
29 #include <netinet/ip.h>
30 #include <netinet/udp.h>
35 struct ether_header *ether_header = (void *)pkt;
37 if (ether_header->ether_type != __builtin_bswap16(0x0800))
40 struct iphdr *iphdr = (void *)(ether_header + 1);
41 if (iphdr->protocol != 17 || (iphdr->frag_off & 0x1ffff) != 0 ||
42 iphdr->daddr != __builtin_bswap32(0x1020304))
45 int hlen = iphdr->ihl * 4;
46 struct udphdr *udphdr = (void *)iphdr + hlen;
48 if (udphdr->dest != __builtin_bswap16(5000))