1 // SPDX-License-Identifier: GPL-2.0 2 /* fails to load without expected_attach_type = BPF_XDP_DEVMAP 3 * because of access to egress_ifindex 4 */ 5 #include <linux/bpf.h> 6 #include <bpf/bpf_helpers.h> 7 8 SEC("xdp_dm_log") 9 int xdpdm_devlog(struct xdp_md *ctx) 10 { 11 char fmt[] = "devmap redirect: dev %u -> dev %u len %u\n"; 12 void *data_end = (void *)(long)ctx->data_end; 13 void *data = (void *)(long)ctx->data; 14 unsigned int len = data_end - data; 15 16 bpf_trace_printk(fmt, sizeof(fmt), 17 ctx->ingress_ifindex, ctx->egress_ifindex, len); 18 19 return XDP_PASS; 20 } 21 22 char _license[] SEC("license") = "GPL"; 23