1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2018 Intel Corporation 3 */ 4 5 /* 6 * eBPF program sample. 7 * Accepts pointer to struct rte_mbuf as an input parameter. 8 * Dump the mbuf into stdout if it is an ARP packet (aka tcpdump 'arp'). 9 * 10 * To compile on x86: 11 * clang -O2 -U __GNUC__ -target bpf -Wno-int-to-void-pointer-cast -c t3.c 12 * 13 * To compile on ARM: 14 * clang -O2 -I/usr/include/aarch64-linux-gnu -target bpf \ 15 * -Wno-int-to-void-pointer-cast -c t3.c 16 * 17 * NOTE: if DPDK is not installed system-wide, add compiler flag with path 18 * to DPDK rte_mbuf.h file to above commands, 19 * e.g. "clang -I/path/to/dpdk/headers -O2 ..." 20 */ 21 22 #include <stdint.h> 23 #include <stddef.h> 24 #include <stdio.h> 25 #include <net/ethernet.h> 26 #include <rte_config.h> 27 #include <rte_mbuf_core.h> 28 #include <arpa/inet.h> 29 30 extern void rte_pktmbuf_dump(FILE *, const struct rte_mbuf *, unsigned int); 31 32 uint64_t entry(const void * pkt)33entry(const void *pkt) 34 { 35 const struct rte_mbuf *mb; 36 const struct ether_header *eth; 37 38 mb = pkt; 39 eth = rte_pktmbuf_mtod(mb, const struct ether_header *); 40 41 if (eth->ether_type == htons(ETHERTYPE_ARP)) 42 rte_pktmbuf_dump(stdout, mb, 64); 43 44 return 1; 45 } 46