125d11a86SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause 225d11a86SBruce Richardson * Copyright(c) 2018 Intel Corporation 325d11a86SBruce Richardson */ 425d11a86SBruce Richardson 525d11a86SBruce Richardson /* 625d11a86SBruce Richardson * eBPF program sample. 725d11a86SBruce Richardson * Accepts pointer to struct rte_mbuf as an input parameter. 825d11a86SBruce Richardson * Dump the mbuf into stdout if it is an ARP packet (aka tcpdump 'arp'). 925d11a86SBruce Richardson * 1025d11a86SBruce Richardson * To compile on x86: 11*f399b017SCiara Power * clang -O2 -U __GNUC__ -target bpf -Wno-int-to-void-pointer-cast -c t3.c 1225d11a86SBruce Richardson * 1325d11a86SBruce Richardson * To compile on ARM: 14*f399b017SCiara Power * clang -O2 -I/usr/include/aarch64-linux-gnu -target bpf \ 1525d11a86SBruce Richardson * -Wno-int-to-void-pointer-cast -c t3.c 16*f399b017SCiara Power * 17*f399b017SCiara Power * NOTE: if DPDK is not installed system-wide, add compiler flag with path 18*f399b017SCiara Power * to DPDK rte_mbuf.h file to above commands, 19*f399b017SCiara Power * e.g. "clang -I/path/to/dpdk/headers -O2 ..." 2025d11a86SBruce Richardson */ 2125d11a86SBruce Richardson 2225d11a86SBruce Richardson #include <stdint.h> 2325d11a86SBruce Richardson #include <stddef.h> 2425d11a86SBruce Richardson #include <stdio.h> 2525d11a86SBruce Richardson #include <net/ethernet.h> 2625d11a86SBruce Richardson #include <rte_config.h> 27b50bcefdSKonstantin Ananyev #include <rte_mbuf_core.h> 2825d11a86SBruce Richardson #include <arpa/inet.h> 2925d11a86SBruce Richardson 3025d11a86SBruce Richardson extern void rte_pktmbuf_dump(FILE *, const struct rte_mbuf *, unsigned int); 3125d11a86SBruce Richardson 3225d11a86SBruce Richardson uint64_t entry(const void * pkt)3325d11a86SBruce Richardsonentry(const void *pkt) 3425d11a86SBruce Richardson { 3525d11a86SBruce Richardson const struct rte_mbuf *mb; 3625d11a86SBruce Richardson const struct ether_header *eth; 3725d11a86SBruce Richardson 3825d11a86SBruce Richardson mb = pkt; 3925d11a86SBruce Richardson eth = rte_pktmbuf_mtod(mb, const struct ether_header *); 4025d11a86SBruce Richardson 4125d11a86SBruce Richardson if (eth->ether_type == htons(ETHERTYPE_ARP)) 4225d11a86SBruce Richardson rte_pktmbuf_dump(stdout, mb, 64); 4325d11a86SBruce Richardson 4425d11a86SBruce Richardson return 1; 4525d11a86SBruce Richardson } 46