__uint(value_size, sizeof(int));
} xsk SEC(".maps");
+static unsigned int idx;
+
SEC("xdp") int xsk_def_prog(struct xdp_md *xdp)
{
return bpf_redirect_map(&xsk, 0, XDP_DROP);
}
+SEC("xdp") int xsk_xdp_drop(struct xdp_md *xdp)
+{
+ /* Drop every other packet */
+ if (idx++ % 2)
+ return XDP_DROP;
+
+ return bpf_redirect_map(&xsk, 0, XDP_DROP);
+}
+
char _license[] SEC("license") = "GPL";
pkt_stream_restore_default(test);
}
+static void testapp_xdp_drop(struct test_spec *test)
+{
+ struct ifobject *ifobj = test->ifobj_rx;
+ int err;
+
+ test_spec_set_name(test, "XDP_DROP_HALF");
+ xsk_detach_xdp_program(ifobj->ifindex, ifobj->xdp_flags);
+ err = xsk_attach_xdp_program(ifobj->xdp_progs->progs.xsk_xdp_drop, ifobj->ifindex,
+ ifobj->xdp_flags);
+ if (err) {
+ printf("Error attaching XDP_DROP program\n");
+ test->fail = true;
+ return;
+ }
+
+ pkt_stream_receive_half(test);
+ testapp_validate_traffic(test);
+
+ pkt_stream_restore_default(test);
+ xsk_detach_xdp_program(ifobj->ifindex, ifobj->xdp_flags);
+ err = xsk_attach_xdp_program(ifobj->xdp_progs->progs.xsk_def_prog, ifobj->ifindex,
+ ifobj->xdp_flags);
+ if (err) {
+ printf("Error restoring default XDP program\n");
+ exit_with_error(-err);
+ }
+}
+
static int xsk_load_xdp_programs(struct ifobject *ifobj)
{
ifobj->xdp_progs = xsk_xdp_progs__open_and_load();
case TEST_TYPE_HEADROOM:
testapp_headroom(test);
break;
+ case TEST_TYPE_XDP_DROP_HALF:
+ testapp_xdp_drop(test);
+ break;
default:
break;
}