Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /* fails to load without expected_attach_type = BPF_XDP_DEVMAP
0003  * because of access to egress_ifindex
0004  */
0005 #include <linux/bpf.h>
0006 #include <bpf/bpf_helpers.h>
0007 
0008 SEC("xdp")
0009 int xdpdm_devlog(struct xdp_md *ctx)
0010 {
0011     char fmt[] = "devmap redirect: dev %u -> dev %u len %u\n";
0012     void *data_end = (void *)(long)ctx->data_end;
0013     void *data = (void *)(long)ctx->data;
0014     unsigned int len = data_end - data;
0015 
0016     bpf_trace_printk(fmt, sizeof(fmt),
0017              ctx->ingress_ifindex, ctx->egress_ifindex, len);
0018 
0019     return XDP_PASS;
0020 }
0021 
0022 char _license[] SEC("license") = "GPL";