bpf-guardian-rl / dev.jsonl
rvindra's picture
Initial release: Certified eBPF/XDP RLVR benchmark (264 stratified tasks)
a0bc758 verified
Raw History Blame Contribute Delete
112 kB
{"task_id": "rl_n3_dev_nrf_l1_01", "title": "", "description": "", "category": "", "difficulty": "level_1", "level": 1, "requirements": ["Verify Ethernet and IPv4 header bounds against data_end", "Confirm eth->h_proto == ETH_P_IP", "Drop packet with XDP_DROP if ip->ttl <= 1", "Decrement ip->ttl and recalculate IPv4 header checksum ip->check", "Return XDP_TX for forwarded packets, XDP_PASS for non-IP traffic", "SEC(\"xdp\") entry point and GPL license declaration"], "prompt": "", "expected_fixture_count": 0, "test_cases": {"task_id": "rl_n3_dev_nrf_l1_01", "tests": [{"name": "tx_forwarded", "description": "TTL 64 forwarded with XDP_TX", "packet_hex": "525400123456525400654321080045000028123400004006e52dc0a8010ac0a8011430390050000003e8000000005002fffff8020000", "expected_action": "XDP_TX", "weight": 1.0}, {"name": "drop_expired", "description": "TTL 1 dropped", "packet_hex": "525400123456525400654321080045000028123400000106242ec0a8010ac0a8011430390050000003e8000000005002fffff8020000", "expected_action": "XDP_DROP", "weight": 1.0}, {"name": "pass_arp", "description": "ARP passes", "packet_hex": "52540012345652540065432108060001080006040001525400123456c0a8010a000000000000c0a80114", "expected_action": "XDP_PASS", "weight": 1.0}]}, "reference_solution": "#include <linux/bpf.h>\n#include <bpf/bpf_helpers.h>\n#include <bpf/bpf_endian.h>\n#include <linux/if_ether.h>\n#include <linux/ip.h>\n\nSEC(\"xdp\")\nint xdp_fwd_ttl_1(struct xdp_md *ctx) {\n void *data_end = (void *)(long)ctx->data_end;\n void *data = (void *)(long)ctx->data;\n\n struct ethhdr *eth = data;\n if ((void *)(eth + 1) > data_end)\n return XDP_PASS;\n if (eth->h_proto != bpf_htons(ETH_P_IP))\n return XDP_PASS;\n\n struct iphdr *ip = (void *)(eth + 1);\n if ((void *)(ip + 1) > data_end)\n return XDP_PASS;\n\n if (ip->ttl <= 1)\n return XDP_DROP;\n\n ip->ttl -= 1;\n ip->check = 0;\n\n __u16 *words = (void *)ip;\n __u32 csum = 0;\n #pragma unroll\n for (int i = 0; i < 10; i++) {\n if ((void *)(words + i + 1) > data_end)\n return XDP_PASS;\n csum += bpf_ntohs(words[i]);\n }\n while (csum >> 16)\n csum = (csum & 0xFFFF) + (csum >> 16);\n ip->check = bpf_htons((~csum) & 0xFFFF);\n\n return XDP_TX;\n}\n\nchar _license[] SEC(\"license\") = \"GPL\";\n"}
{"task_id": "rl_n3_dev_nrf_l1_02", "title": "", "description": "", "category": "", "difficulty": "level_1", "level": 1, "requirements": ["Verify Ethernet and IPv4 header bounds against data_end", "Confirm eth->h_proto == ETH_P_IP", "Drop packet with XDP_DROP if ip->ttl <= 1", "Decrement ip->ttl and recalculate IPv4 header checksum ip->check", "Return XDP_TX for forwarded packets, XDP_PASS for non-IP traffic", "SEC(\"xdp\") entry point and GPL license declaration"], "prompt": "", "expected_fixture_count": 0, "test_cases": {"task_id": "rl_n3_dev_nrf_l1_02", "tests": [{"name": "tx_forwarded", "description": "TTL 64 forwarded with XDP_TX", "packet_hex": "525400123456525400654321080045000028123400004006e52dc0a8010ac0a8011430390050000003e8000000005002fffff8020000", "expected_action": "XDP_TX", "weight": 1.0}, {"name": "drop_expired", "description": "TTL 1 dropped", "packet_hex": "525400123456525400654321080045000028123400000106242ec0a8010ac0a8011430390050000003e8000000005002fffff8020000", "expected_action": "XDP_DROP", "weight": 1.0}, {"name": "pass_arp", "description": "ARP passes", "packet_hex": "52540012345652540065432108060001080006040001525400123456c0a8010a000000000000c0a80114", "expected_action": "XDP_PASS", "weight": 1.0}]}, "reference_solution": "#include <linux/bpf.h>\n#include <bpf/bpf_helpers.h>\n#include <bpf/bpf_endian.h>\n#include <linux/if_ether.h>\n#include <linux/ip.h>\n\nSEC(\"xdp\")\nint xdp_fwd_ttl_2(struct xdp_md *ctx) {\n void *data_end = (void *)(long)ctx->data_end;\n void *data = (void *)(long)ctx->data;\n\n struct ethhdr *eth = data;\n if ((void *)(eth + 1) > data_end)\n return XDP_PASS;\n if (eth->h_proto != bpf_htons(ETH_P_IP))\n return XDP_PASS;\n\n struct iphdr *ip = (void *)(eth + 1);\n if ((void *)(ip + 1) > data_end)\n return XDP_PASS;\n\n if (ip->ttl <= 1)\n return XDP_DROP;\n\n ip->ttl -= 1;\n ip->check = 0;\n\n __u16 *words = (void *)ip;\n __u32 csum = 0;\n #pragma unroll\n for (int i = 0; i < 10; i++) {\n if ((void *)(words + i + 1) > data_end)\n return XDP_PASS;\n csum += bpf_ntohs(words[i]);\n }\n while (csum >> 16)\n csum = (csum & 0xFFFF) + (csum >> 16);\n ip->check = bpf_htons((~csum) & 0xFFFF);\n\n return XDP_TX;\n}\n\nchar _license[] SEC(\"license\") = \"GPL\";\n"}
{"task_id": "rl_n3_dev_nrf_l1_03", "title": "", "description": "", "category": "", "difficulty": "level_1", "level": 1, "requirements": ["Verify Ethernet and IPv4 header bounds against data_end", "Confirm eth->h_proto == ETH_P_IP", "Drop packet with XDP_DROP if ip->ttl <= 1", "Decrement ip->ttl and recalculate IPv4 header checksum ip->check", "Return XDP_TX for forwarded packets, XDP_PASS for non-IP traffic", "SEC(\"xdp\") entry point and GPL license declaration"], "prompt": "", "expected_fixture_count": 0, "test_cases": {"task_id": "rl_n3_dev_nrf_l1_03", "tests": [{"name": "tx_forwarded", "description": "TTL 64 forwarded with XDP_TX", "packet_hex": "525400123456525400654321080045000028123400004006e52dc0a8010ac0a8011430390050000003e8000000005002fffff8020000", "expected_action": "XDP_TX", "weight": 1.0}, {"name": "drop_expired", "description": "TTL 1 dropped", "packet_hex": "525400123456525400654321080045000028123400000106242ec0a8010ac0a8011430390050000003e8000000005002fffff8020000", "expected_action": "XDP_DROP", "weight": 1.0}, {"name": "pass_arp", "description": "ARP passes", "packet_hex": "52540012345652540065432108060001080006040001525400123456c0a8010a000000000000c0a80114", "expected_action": "XDP_PASS", "weight": 1.0}]}, "reference_solution": "#include <linux/bpf.h>\n#include <bpf/bpf_helpers.h>\n#include <bpf/bpf_endian.h>\n#include <linux/if_ether.h>\n#include <linux/ip.h>\n\nSEC(\"xdp\")\nint xdp_fwd_ttl_3(struct xdp_md *ctx) {\n void *data_end = (void *)(long)ctx->data_end;\n void *data = (void *)(long)ctx->data;\n\n struct ethhdr *eth = data;\n if ((void *)(eth + 1) > data_end)\n return XDP_PASS;\n if (eth->h_proto != bpf_htons(ETH_P_IP))\n return XDP_PASS;\n\n struct iphdr *ip = (void *)(eth + 1);\n if ((void *)(ip + 1) > data_end)\n return XDP_PASS;\n\n if (ip->ttl <= 1)\n return XDP_DROP;\n\n ip->ttl -= 1;\n ip->check = 0;\n\n __u16 *words = (void *)ip;\n __u32 csum = 0;\n #pragma unroll\n for (int i = 0; i < 10; i++) {\n if ((void *)(words + i + 1) > data_end)\n return XDP_PASS;\n csum += bpf_ntohs(words[i]);\n }\n while (csum >> 16)\n csum = (csum & 0xFFFF) + (csum >> 16);\n ip->check = bpf_htons((~csum) & 0xFFFF);\n\n return XDP_TX;\n}\n\nchar _license[] SEC(\"license\") = \"GPL\";\n"}
{"task_id": "rl_n3_dev_nrf_l1_04", "title": "", "description": "", "category": "", "difficulty": "level_1", "level": 1, "requirements": ["Verify Ethernet and IPv4 header bounds against data_end", "Confirm eth->h_proto == ETH_P_IP", "Drop packet with XDP_DROP if ip->ttl <= 1", "Decrement ip->ttl and recalculate IPv4 header checksum ip->check", "Return XDP_TX for forwarded packets, XDP_PASS for non-IP traffic", "SEC(\"xdp\") entry point and GPL license declaration"], "prompt": "", "expected_fixture_count": 0, "test_cases": {"task_id": "rl_n3_dev_nrf_l1_04", "tests": [{"name": "tx_forwarded", "description": "TTL 64 forwarded with XDP_TX", "packet_hex": "525400123456525400654321080045000028123400004006e52dc0a8010ac0a8011430390050000003e8000000005002fffff8020000", "expected_action": "XDP_TX", "weight": 1.0}, {"name": "drop_expired", "description": "TTL 1 dropped", "packet_hex": "525400123456525400654321080045000028123400000106242ec0a8010ac0a8011430390050000003e8000000005002fffff8020000", "expected_action": "XDP_DROP", "weight": 1.0}, {"name": "pass_arp", "description": "ARP passes", "packet_hex": "52540012345652540065432108060001080006040001525400123456c0a8010a000000000000c0a80114", "expected_action": "XDP_PASS", "weight": 1.0}]}, "reference_solution": "#include <linux/bpf.h>\n#include <bpf/bpf_helpers.h>\n#include <bpf/bpf_endian.h>\n#include <linux/if_ether.h>\n#include <linux/ip.h>\n\nSEC(\"xdp\")\nint xdp_fwd_ttl_4(struct xdp_md *ctx) {\n void *data_end = (void *)(long)ctx->data_end;\n void *data = (void *)(long)ctx->data;\n\n struct ethhdr *eth = data;\n if ((void *)(eth + 1) > data_end)\n return XDP_PASS;\n if (eth->h_proto != bpf_htons(ETH_P_IP))\n return XDP_PASS;\n\n struct iphdr *ip = (void *)(eth + 1);\n if ((void *)(ip + 1) > data_end)\n return XDP_PASS;\n\n if (ip->ttl <= 1)\n return XDP_DROP;\n\n ip->ttl -= 1;\n ip->check = 0;\n\n __u16 *words = (void *)ip;\n __u32 csum = 0;\n #pragma unroll\n for (int i = 0; i < 10; i++) {\n if ((void *)(words + i + 1) > data_end)\n return XDP_PASS;\n csum += bpf_ntohs(words[i]);\n }\n while (csum >> 16)\n csum = (csum & 0xFFFF) + (csum >> 16);\n ip->check = bpf_htons((~csum) & 0xFFFF);\n\n return XDP_TX;\n}\n\nchar _license[] SEC(\"license\") = \"GPL\";\n"}
{"task_id": "rl_n3_dev_nrf_l2_01", "title": "", "description": "", "category": "", "difficulty": "level_2", "level": 1, "requirements": ["Verify Ethernet and 802.1Q header bounds against data_end", "Check if eth->h_proto == ETH_P_8021Q and vlan_id == 10", "Return XDP_TX on matching VLAN ID", "Return XDP_PASS for other VLAN IDs, untagged packets, and non-IP traffic", "SEC(\"xdp\") entry point and GPL license declaration"], "prompt": "", "expected_fixture_count": 0, "test_cases": {"task_id": "rl_n3_dev_nrf_l2_01", "tests": [{"name": "tx_vlan_10", "description": "VLAN 10 transmitted", "packet_hex": "5254001234565254006543218100000a080045000028123400004006e52dc0a8010ac0a8011430390050000003e8000000005002fffff8020000", "expected_action": "XDP_TX", "weight": 1.0}, {"name": "pass_other_vlan", "description": "VLAN 999 passed", "packet_hex": "525400123456525400654321810003e7080045000028123400004006e52dc0a8010ac0a8011430390050000003e8000000005002fffff8020000", "expected_action": "XDP_PASS", "weight": 1.0}, {"name": "pass_untagged", "description": "Untagged passed", "packet_hex": "525400123456525400654321080045000028123400004006e52dc0a8010ac0a8011430390050000003e8000000005002fffff8020000", "expected_action": "XDP_PASS", "weight": 1.0}, {"name": "pass_arp", "description": "ARP passed", "packet_hex": "52540012345652540065432108060001080006040001525400123456c0a8010a000000000000c0a80114", "expected_action": "XDP_PASS", "weight": 1.0}]}, "reference_solution": "#include <linux/bpf.h>\n#include <bpf/bpf_helpers.h>\n#include <bpf/bpf_endian.h>\n#include <linux/if_ether.h>\n#include <linux/if_vlan.h>\n\nstruct vlan_hdr {\n __be16 h_vlan_TCI;\n __be16 h_vlan_encapsulated_proto;\n};\n\nSEC(\"xdp\")\nint xdp_vlan_demux_1(struct xdp_md *ctx) {\n void *data_end = (void *)(long)ctx->data_end;\n void *data = (void *)(long)ctx->data;\n\n struct ethhdr *eth = data;\n if ((void *)(eth + 1) > data_end)\n return XDP_PASS;\n\n if (eth->h_proto == bpf_htons(ETH_P_8021Q)) {\n struct vlan_hdr *vlan = (void *)(eth + 1);\n if ((void *)(vlan + 1) > data_end)\n return XDP_PASS;\n\n __u16 vlan_id = bpf_ntohs(vlan->h_vlan_TCI) & 0x0FFF;\n if (vlan_id == 10)\n return XDP_TX;\n }\n\n return XDP_PASS;\n}\n\nchar _license[] SEC(\"license\") = \"GPL\";\n"}
{"task_id": "rl_n3_dev_nrf_l2_02", "title": "", "description": "", "category": "", "difficulty": "level_2", "level": 1, "requirements": ["Verify Ethernet and 802.1Q header bounds against data_end", "Check if eth->h_proto == ETH_P_8021Q and vlan_id == 20", "Return XDP_TX on matching VLAN ID", "Return XDP_PASS for other VLAN IDs, untagged packets, and non-IP traffic", "SEC(\"xdp\") entry point and GPL license declaration"], "prompt": "", "expected_fixture_count": 0, "test_cases": {"task_id": "rl_n3_dev_nrf_l2_02", "tests": [{"name": "tx_vlan_20", "description": "VLAN 20 transmitted", "packet_hex": "52540012345652540065432181000014080045000028123400004006e52dc0a8010ac0a8011430390050000003e8000000005002fffff8020000", "expected_action": "XDP_TX", "weight": 1.0}, {"name": "pass_other_vlan", "description": "VLAN 999 passed", "packet_hex": "525400123456525400654321810003e7080045000028123400004006e52dc0a8010ac0a8011430390050000003e8000000005002fffff8020000", "expected_action": "XDP_PASS", "weight": 1.0}, {"name": "pass_untagged", "description": "Untagged passed", "packet_hex": "525400123456525400654321080045000028123400004006e52dc0a8010ac0a8011430390050000003e8000000005002fffff8020000", "expected_action": "XDP_PASS", "weight": 1.0}, {"name": "pass_arp", "description": "ARP passed", "packet_hex": "52540012345652540065432108060001080006040001525400123456c0a8010a000000000000c0a80114", "expected_action": "XDP_PASS", "weight": 1.0}]}, "reference_solution": "#include <linux/bpf.h>\n#include <bpf/bpf_helpers.h>\n#include <bpf/bpf_endian.h>\n#include <linux/if_ether.h>\n#include <linux/if_vlan.h>\n\nstruct vlan_hdr {\n __be16 h_vlan_TCI;\n __be16 h_vlan_encapsulated_proto;\n};\n\nSEC(\"xdp\")\nint xdp_vlan_demux_2(struct xdp_md *ctx) {\n void *data_end = (void *)(long)ctx->data_end;\n void *data = (void *)(long)ctx->data;\n\n struct ethhdr *eth = data;\n if ((void *)(eth + 1) > data_end)\n return XDP_PASS;\n\n if (eth->h_proto == bpf_htons(ETH_P_8021Q)) {\n struct vlan_hdr *vlan = (void *)(eth + 1);\n if ((void *)(vlan + 1) > data_end)\n return XDP_PASS;\n\n __u16 vlan_id = bpf_ntohs(vlan->h_vlan_TCI) & 0x0FFF;\n if (vlan_id == 20)\n return XDP_TX;\n }\n\n return XDP_PASS;\n}\n\nchar _license[] SEC(\"license\") = \"GPL\";\n"}
{"task_id": "rl_n3_dev_nrf_l2_03", "title": "", "description": "", "category": "", "difficulty": "level_2", "level": 1, "requirements": ["Verify Ethernet and 802.1Q header bounds against data_end", "Check if eth->h_proto == ETH_P_8021Q and vlan_id == 30", "Return XDP_TX on matching VLAN ID", "Return XDP_PASS for other VLAN IDs, untagged packets, and non-IP traffic", "SEC(\"xdp\") entry point and GPL license declaration"], "prompt": "", "expected_fixture_count": 0, "test_cases": {"task_id": "rl_n3_dev_nrf_l2_03", "tests": [{"name": "tx_vlan_30", "description": "VLAN 30 transmitted", "packet_hex": "5254001234565254006543218100001e080045000028123400004006e52dc0a8010ac0a8011430390050000003e8000000005002fffff8020000", "expected_action": "XDP_TX", "weight": 1.0}, {"name": "pass_other_vlan", "description": "VLAN 999 passed", "packet_hex": "525400123456525400654321810003e7080045000028123400004006e52dc0a8010ac0a8011430390050000003e8000000005002fffff8020000", "expected_action": "XDP_PASS", "weight": 1.0}, {"name": "pass_untagged", "description": "Untagged passed", "packet_hex": "525400123456525400654321080045000028123400004006e52dc0a8010ac0a8011430390050000003e8000000005002fffff8020000", "expected_action": "XDP_PASS", "weight": 1.0}, {"name": "pass_arp", "description": "ARP passed", "packet_hex": "52540012345652540065432108060001080006040001525400123456c0a8010a000000000000c0a80114", "expected_action": "XDP_PASS", "weight": 1.0}]}, "reference_solution": "#include <linux/bpf.h>\n#include <bpf/bpf_helpers.h>\n#include <bpf/bpf_endian.h>\n#include <linux/if_ether.h>\n#include <linux/if_vlan.h>\n\nstruct vlan_hdr {\n __be16 h_vlan_TCI;\n __be16 h_vlan_encapsulated_proto;\n};\n\nSEC(\"xdp\")\nint xdp_vlan_demux_3(struct xdp_md *ctx) {\n void *data_end = (void *)(long)ctx->data_end;\n void *data = (void *)(long)ctx->data;\n\n struct ethhdr *eth = data;\n if ((void *)(eth + 1) > data_end)\n return XDP_PASS;\n\n if (eth->h_proto == bpf_htons(ETH_P_8021Q)) {\n struct vlan_hdr *vlan = (void *)(eth + 1);\n if ((void *)(vlan + 1) > data_end)\n return XDP_PASS;\n\n __u16 vlan_id = bpf_ntohs(vlan->h_vlan_TCI) & 0x0FFF;\n if (vlan_id == 30)\n return XDP_TX;\n }\n\n return XDP_PASS;\n}\n\nchar _license[] SEC(\"license\") = \"GPL\";\n"}
{"task_id": "rl_n3_dev_nrf_l2_04", "title": "", "description": "", "category": "", "difficulty": "level_2", "level": 1, "requirements": ["Verify Ethernet and 802.1Q header bounds against data_end", "Check if eth->h_proto == ETH_P_8021Q and vlan_id == 40", "Return XDP_TX on matching VLAN ID", "Return XDP_PASS for other VLAN IDs, untagged packets, and non-IP traffic", "SEC(\"xdp\") entry point and GPL license declaration"], "prompt": "", "expected_fixture_count": 0, "test_cases": {"task_id": "rl_n3_dev_nrf_l2_04", "tests": [{"name": "tx_vlan_40", "description": "VLAN 40 transmitted", "packet_hex": "52540012345652540065432181000028080045000028123400004006e52dc0a8010ac0a8011430390050000003e8000000005002fffff8020000", "expected_action": "XDP_TX", "weight": 1.0}, {"name": "pass_other_vlan", "description": "VLAN 999 passed", "packet_hex": "525400123456525400654321810003e7080045000028123400004006e52dc0a8010ac0a8011430390050000003e8000000005002fffff8020000", "expected_action": "XDP_PASS", "weight": 1.0}, {"name": "pass_untagged", "description": "Untagged passed", "packet_hex": "525400123456525400654321080045000028123400004006e52dc0a8010ac0a8011430390050000003e8000000005002fffff8020000", "expected_action": "XDP_PASS", "weight": 1.0}, {"name": "pass_arp", "description": "ARP passed", "packet_hex": "52540012345652540065432108060001080006040001525400123456c0a8010a000000000000c0a80114", "expected_action": "XDP_PASS", "weight": 1.0}]}, "reference_solution": "#include <linux/bpf.h>\n#include <bpf/bpf_helpers.h>\n#include <bpf/bpf_endian.h>\n#include <linux/if_ether.h>\n#include <linux/if_vlan.h>\n\nstruct vlan_hdr {\n __be16 h_vlan_TCI;\n __be16 h_vlan_encapsulated_proto;\n};\n\nSEC(\"xdp\")\nint xdp_vlan_demux_4(struct xdp_md *ctx) {\n void *data_end = (void *)(long)ctx->data_end;\n void *data = (void *)(long)ctx->data;\n\n struct ethhdr *eth = data;\n if ((void *)(eth + 1) > data_end)\n return XDP_PASS;\n\n if (eth->h_proto == bpf_htons(ETH_P_8021Q)) {\n struct vlan_hdr *vlan = (void *)(eth + 1);\n if ((void *)(vlan + 1) > data_end)\n return XDP_PASS;\n\n __u16 vlan_id = bpf_ntohs(vlan->h_vlan_TCI) & 0x0FFF;\n if (vlan_id == 40)\n return XDP_TX;\n }\n\n return XDP_PASS;\n}\n\nchar _license[] SEC(\"license\") = \"GPL\";\n"}
{"task_id": "rl_n3_dev_nrf_l3_01", "title": "", "description": "", "category": "", "difficulty": "level_3", "level": 1, "requirements": ["Define BPF_MAP_TYPE_LPM_TRIE map 'dev_route_table_1' with BPF_F_NO_PREALLOC", "Define LPM key struct with __u32 prefixlen and __u32 data members", "Verify Ethernet and IPv4 header bounds against data_end", "Lookup ip->daddr in dev_route_table_1", "On hit rewrite destination MAC to route MAC; on miss rewrite to default gateway 52:54:00:00:00:fe", "Return XDP_TX for all routed IPv4 packets, XDP_PASS for non-IP", "SEC(\"xdp\") entry point and GPL license declaration"], "prompt": "", "expected_fixture_count": 0, "test_cases": {"task_id": "rl_n3_dev_nrf_l3_01", "tests": [{"name": "tx_default_gw", "description": "Unmatched routed to default gateway", "packet_hex": "5254001234565254006543210800450000281234000040068340c0a8010ac0a8630130390050000003e8000000005002fffff8020000", "expected_action": "XDP_TX", "weight": 1.0}, {"name": "pass_arp", "description": "ARP passes unmodified", "packet_hex": "52540012345652540065432108060001080006040001525400123456c0a8010a000000000000c0a80114", "expected_action": "XDP_PASS", "weight": 1.0}]}, "reference_solution": "#include <linux/bpf.h>\n#include <bpf/bpf_helpers.h>\n#include <bpf/bpf_endian.h>\n#include <linux/if_ether.h>\n#include <linux/ip.h>\n\nstruct lpm_key_1 {\n __u32 prefixlen;\n __u32 data;\n};\n\nstruct {\n __uint(type, BPF_MAP_TYPE_LPM_TRIE);\n __type(key, struct lpm_key_1);\n __type(value, unsigned char[6]);\n __uint(max_entries, 256);\n __uint(map_flags, BPF_F_NO_PREALLOC);\n} dev_route_table_1 SEC(\".maps\");\n\nSEC(\"xdp\")\nint xdp_route_fallback_1(struct xdp_md *ctx) {\n void *data_end = (void *)(long)ctx->data_end;\n void *data = (void *)(long)ctx->data;\n\n struct ethhdr *eth = data;\n if ((void *)(eth + 1) > data_end)\n return XDP_PASS;\n if (eth->h_proto != bpf_htons(ETH_P_IP))\n return XDP_PASS;\n\n struct iphdr *ip = (void *)(eth + 1);\n if ((void *)(ip + 1) > data_end)\n return XDP_PASS;\n\n struct lpm_key_1 key;\n key.prefixlen = 32;\n key.data = ip->daddr;\n\n unsigned char (*mac)[6] = bpf_map_lookup_elem(&dev_route_table_1, &key);\n if (mac) {\n for (int i = 0; i < 6; i++)\n eth->h_dest[i] = (*mac)[i];\n } else {\n eth->h_dest[0] = 0x52;\n eth->h_dest[1] = 0x54;\n eth->h_dest[2] = 0x00;\n eth->h_dest[3] = 0x00;\n eth->h_dest[4] = 0x00;\n eth->h_dest[5] = 0xfe;\n }\n\n return XDP_TX;\n}\n\nchar _license[] SEC(\"license\") = \"GPL\";\n"}
{"task_id": "rl_n3_dev_nrf_l3_02", "title": "", "description": "", "category": "", "difficulty": "level_3", "level": 1, "requirements": ["Define BPF_MAP_TYPE_LPM_TRIE map 'dev_route_table_2' with BPF_F_NO_PREALLOC", "Define LPM key struct with __u32 prefixlen and __u32 data members", "Verify Ethernet and IPv4 header bounds against data_end", "Lookup ip->daddr in dev_route_table_2", "On hit rewrite destination MAC to route MAC; on miss rewrite to default gateway 52:54:00:00:00:fe", "Return XDP_TX for all routed IPv4 packets, XDP_PASS for non-IP", "SEC(\"xdp\") entry point and GPL license declaration"], "prompt": "", "expected_fixture_count": 0, "test_cases": {"task_id": "rl_n3_dev_nrf_l3_02", "tests": [{"name": "tx_default_gw", "description": "Unmatched routed to default gateway", "packet_hex": "5254001234565254006543210800450000281234000040068340c0a8010ac0a8630130390050000003e8000000005002fffff8020000", "expected_action": "XDP_TX", "weight": 1.0}, {"name": "pass_arp", "description": "ARP passes unmodified", "packet_hex": "52540012345652540065432108060001080006040001525400123456c0a8010a000000000000c0a80114", "expected_action": "XDP_PASS", "weight": 1.0}]}, "reference_solution": "#include <linux/bpf.h>\n#include <bpf/bpf_helpers.h>\n#include <bpf/bpf_endian.h>\n#include <linux/if_ether.h>\n#include <linux/ip.h>\n\nstruct lpm_key_2 {\n __u32 prefixlen;\n __u32 data;\n};\n\nstruct {\n __uint(type, BPF_MAP_TYPE_LPM_TRIE);\n __type(key, struct lpm_key_2);\n __type(value, unsigned char[6]);\n __uint(max_entries, 256);\n __uint(map_flags, BPF_F_NO_PREALLOC);\n} dev_route_table_2 SEC(\".maps\");\n\nSEC(\"xdp\")\nint xdp_route_fallback_2(struct xdp_md *ctx) {\n void *data_end = (void *)(long)ctx->data_end;\n void *data = (void *)(long)ctx->data;\n\n struct ethhdr *eth = data;\n if ((void *)(eth + 1) > data_end)\n return XDP_PASS;\n if (eth->h_proto != bpf_htons(ETH_P_IP))\n return XDP_PASS;\n\n struct iphdr *ip = (void *)(eth + 1);\n if ((void *)(ip + 1) > data_end)\n return XDP_PASS;\n\n struct lpm_key_2 key;\n key.prefixlen = 32;\n key.data = ip->daddr;\n\n unsigned char (*mac)[6] = bpf_map_lookup_elem(&dev_route_table_2, &key);\n if (mac) {\n for (int i = 0; i < 6; i++)\n eth->h_dest[i] = (*mac)[i];\n } else {\n eth->h_dest[0] = 0x52;\n eth->h_dest[1] = 0x54;\n eth->h_dest[2] = 0x00;\n eth->h_dest[3] = 0x00;\n eth->h_dest[4] = 0x00;\n eth->h_dest[5] = 0xfe;\n }\n\n return XDP_TX;\n}\n\nchar _license[] SEC(\"license\") = \"GPL\";\n"}
{"task_id": "rl_n3_dev_nrf_l3_03", "title": "", "description": "", "category": "", "difficulty": "level_3", "level": 1, "requirements": ["Define BPF_MAP_TYPE_LPM_TRIE map 'dev_route_table_3' with BPF_F_NO_PREALLOC", "Define LPM key struct with __u32 prefixlen and __u32 data members", "Verify Ethernet and IPv4 header bounds against data_end", "Lookup ip->daddr in dev_route_table_3", "On hit rewrite destination MAC to route MAC; on miss rewrite to default gateway 52:54:00:00:00:fe", "Return XDP_TX for all routed IPv4 packets, XDP_PASS for non-IP", "SEC(\"xdp\") entry point and GPL license declaration"], "prompt": "", "expected_fixture_count": 0, "test_cases": {"task_id": "rl_n3_dev_nrf_l3_03", "tests": [{"name": "tx_default_gw", "description": "Unmatched routed to default gateway", "packet_hex": "5254001234565254006543210800450000281234000040068340c0a8010ac0a8630130390050000003e8000000005002fffff8020000", "expected_action": "XDP_TX", "weight": 1.0}, {"name": "pass_arp", "description": "ARP passes unmodified", "packet_hex": "52540012345652540065432108060001080006040001525400123456c0a8010a000000000000c0a80114", "expected_action": "XDP_PASS", "weight": 1.0}]}, "reference_solution": "#include <linux/bpf.h>\n#include <bpf/bpf_helpers.h>\n#include <bpf/bpf_endian.h>\n#include <linux/if_ether.h>\n#include <linux/ip.h>\n\nstruct lpm_key_3 {\n __u32 prefixlen;\n __u32 data;\n};\n\nstruct {\n __uint(type, BPF_MAP_TYPE_LPM_TRIE);\n __type(key, struct lpm_key_3);\n __type(value, unsigned char[6]);\n __uint(max_entries, 256);\n __uint(map_flags, BPF_F_NO_PREALLOC);\n} dev_route_table_3 SEC(\".maps\");\n\nSEC(\"xdp\")\nint xdp_route_fallback_3(struct xdp_md *ctx) {\n void *data_end = (void *)(long)ctx->data_end;\n void *data = (void *)(long)ctx->data;\n\n struct ethhdr *eth = data;\n if ((void *)(eth + 1) > data_end)\n return XDP_PASS;\n if (eth->h_proto != bpf_htons(ETH_P_IP))\n return XDP_PASS;\n\n struct iphdr *ip = (void *)(eth + 1);\n if ((void *)(ip + 1) > data_end)\n return XDP_PASS;\n\n struct lpm_key_3 key;\n key.prefixlen = 32;\n key.data = ip->daddr;\n\n unsigned char (*mac)[6] = bpf_map_lookup_elem(&dev_route_table_3, &key);\n if (mac) {\n for (int i = 0; i < 6; i++)\n eth->h_dest[i] = (*mac)[i];\n } else {\n eth->h_dest[0] = 0x52;\n eth->h_dest[1] = 0x54;\n eth->h_dest[2] = 0x00;\n eth->h_dest[3] = 0x00;\n eth->h_dest[4] = 0x00;\n eth->h_dest[5] = 0xfe;\n }\n\n return XDP_TX;\n}\n\nchar _license[] SEC(\"license\") = \"GPL\";\n"}
{"task_id": "rl_n3_dev_nrf_l3_04", "title": "", "description": "", "category": "", "difficulty": "level_3", "level": 1, "requirements": ["Define BPF_MAP_TYPE_LPM_TRIE map 'dev_route_table_4' with BPF_F_NO_PREALLOC", "Define LPM key struct with __u32 prefixlen and __u32 data members", "Verify Ethernet and IPv4 header bounds against data_end", "Lookup ip->daddr in dev_route_table_4", "On hit rewrite destination MAC to route MAC; on miss rewrite to default gateway 52:54:00:00:00:fe", "Return XDP_TX for all routed IPv4 packets, XDP_PASS for non-IP", "SEC(\"xdp\") entry point and GPL license declaration"], "prompt": "", "expected_fixture_count": 0, "test_cases": {"task_id": "rl_n3_dev_nrf_l3_04", "tests": [{"name": "tx_default_gw", "description": "Unmatched routed to default gateway", "packet_hex": "5254001234565254006543210800450000281234000040068340c0a8010ac0a8630130390050000003e8000000005002fffff8020000", "expected_action": "XDP_TX", "weight": 1.0}, {"name": "pass_arp", "description": "ARP passes unmodified", "packet_hex": "52540012345652540065432108060001080006040001525400123456c0a8010a000000000000c0a80114", "expected_action": "XDP_PASS", "weight": 1.0}]}, "reference_solution": "#include <linux/bpf.h>\n#include <bpf/bpf_helpers.h>\n#include <bpf/bpf_endian.h>\n#include <linux/if_ether.h>\n#include <linux/ip.h>\n\nstruct lpm_key_4 {\n __u32 prefixlen;\n __u32 data;\n};\n\nstruct {\n __uint(type, BPF_MAP_TYPE_LPM_TRIE);\n __type(key, struct lpm_key_4);\n __type(value, unsigned char[6]);\n __uint(max_entries, 256);\n __uint(map_flags, BPF_F_NO_PREALLOC);\n} dev_route_table_4 SEC(\".maps\");\n\nSEC(\"xdp\")\nint xdp_route_fallback_4(struct xdp_md *ctx) {\n void *data_end = (void *)(long)ctx->data_end;\n void *data = (void *)(long)ctx->data;\n\n struct ethhdr *eth = data;\n if ((void *)(eth + 1) > data_end)\n return XDP_PASS;\n if (eth->h_proto != bpf_htons(ETH_P_IP))\n return XDP_PASS;\n\n struct iphdr *ip = (void *)(eth + 1);\n if ((void *)(ip + 1) > data_end)\n return XDP_PASS;\n\n struct lpm_key_4 key;\n key.prefixlen = 32;\n key.data = ip->daddr;\n\n unsigned char (*mac)[6] = bpf_map_lookup_elem(&dev_route_table_4, &key);\n if (mac) {\n for (int i = 0; i < 6; i++)\n eth->h_dest[i] = (*mac)[i];\n } else {\n eth->h_dest[0] = 0x52;\n eth->h_dest[1] = 0x54;\n eth->h_dest[2] = 0x00;\n eth->h_dest[3] = 0x00;\n eth->h_dest[4] = 0x00;\n eth->h_dest[5] = 0xfe;\n }\n\n return XDP_TX;\n}\n\nchar _license[] SEC(\"license\") = \"GPL\";\n"}
{"task_id": "rl_n3_dev_pfs_l1_01", "title": "", "description": "", "category": "", "difficulty": "level_1", "level": 1, "requirements": ["Verify Ethernet header bounds against data_end", "Verify IPv4 header bounds and confirm protocol is IPPROTO_UDP", "Safely validate variable IPv4 header length (ip->ihl * 4)", "Verify UDP header bounds against data_end", "Drop packet with XDP_DROP if UDP destination port equals 69", "Return XDP_PASS for non-matching or malformed traffic", "SEC(\"xdp\") entry point and GPL license declaration"], "prompt": "", "expected_fixture_count": 0, "test_cases": {"task_id": "rl_n3_dev_pfs_l1_01", "tests": [{"name": "drop_tftp", "description": "UDP port 69 dropped", "packet_hex": "52540012345652540065432108004500001c123400004011e52ec0a8010ac0a801143039004500080000", "expected_action": "XDP_DROP", "weight": 1.0}, {"name": "pass_unrelated_udp", "description": "Other UDP port passes", "packet_hex": "52540012345652540065432108004500001c123400004011e52ec0a8010ac0a801143039270f00080000", "expected_action": "XDP_PASS", "weight": 1.0}, {"name": "pass_tcp", "description": "TCP traffic passes", "packet_hex": "525400123456525400654321080045000028123400004006e52dc0a8010ac0a8011430390045000003e8000000005002fffff80d0000", "expected_action": "XDP_PASS", "weight": 1.0}, {"name": "pass_arp", "description": "ARP frame passes", "packet_hex": "52540012345652540065432108060001080006040001525400123456c0a8010a000000000000c0a80114", "expected_action": "XDP_PASS", "weight": 1.0}, {"name": "pass_truncated", "description": "Truncated header passes", "packet_hex": "525400123456525400654321080045000010", "expected_action": "XDP_PASS", "weight": 1.0}]}, "reference_solution": "#include <linux/bpf.h>\n#include <bpf/bpf_helpers.h>\n#include <bpf/bpf_endian.h>\n#include <linux/if_ether.h>\n#include <linux/ip.h>\n#include <linux/in.h>\n#include <linux/udp.h>\n\nSEC(\"xdp\")\nint xdp_filter_tftp(struct xdp_md *ctx) {\n void *data_end = (void *)(long)ctx->data_end;\n void *data = (void *)(long)ctx->data;\n\n struct ethhdr *eth = data;\n if ((void *)(eth + 1) > data_end)\n return XDP_PASS;\n if (eth->h_proto != bpf_htons(ETH_P_IP))\n return XDP_PASS;\n\n struct iphdr *ip = (void *)(eth + 1);\n if ((void *)(ip + 1) > data_end)\n return XDP_PASS;\n if (ip->protocol != IPPROTO_UDP)\n return XDP_PASS;\n\n int ip_len = ip->ihl * 4;\n if (ip_len < sizeof(struct iphdr) || (void *)ip + ip_len > data_end)\n return XDP_PASS;\n\n struct udphdr *udp = (void *)ip + ip_len;\n if ((void *)(udp + 1) > data_end)\n return XDP_PASS;\n\n if (udp->dest == bpf_htons(69))\n return XDP_DROP;\n\n return XDP_PASS;\n}\n\nchar _license[] SEC(\"license\") = \"GPL\";\n"}
{"task_id": "rl_n3_dev_pfs_l1_02", "title": "", "description": "", "category": "", "difficulty": "level_1", "level": 1, "requirements": ["Verify Ethernet header bounds against data_end", "Verify IPv4 header bounds and confirm protocol is IPPROTO_UDP", "Safely validate variable IPv4 header length (ip->ihl * 4)", "Verify UDP header bounds against data_end", "Drop packet with XDP_DROP if UDP destination port equals 123", "Return XDP_PASS for non-matching or malformed traffic", "SEC(\"xdp\") entry point and GPL license declaration"], "prompt": "", "expected_fixture_count": 0, "test_cases": {"task_id": "rl_n3_dev_pfs_l1_02", "tests": [{"name": "drop_ntp", "description": "UDP port 123 dropped", "packet_hex": "52540012345652540065432108004500001c123400004011e52ec0a8010ac0a801143039007b00080000", "expected_action": "XDP_DROP", "weight": 1.0}, {"name": "pass_unrelated_udp", "description": "Other UDP port passes", "packet_hex": "52540012345652540065432108004500001c123400004011e52ec0a8010ac0a801143039270f00080000", "expected_action": "XDP_PASS", "weight": 1.0}, {"name": "pass_tcp", "description": "TCP traffic passes", "packet_hex": "525400123456525400654321080045000028123400004006e52dc0a8010ac0a801143039007b000003e8000000005002fffff7d70000", "expected_action": "XDP_PASS", "weight": 1.0}, {"name": "pass_arp", "description": "ARP frame passes", "packet_hex": "52540012345652540065432108060001080006040001525400123456c0a8010a000000000000c0a80114", "expected_action": "XDP_PASS", "weight": 1.0}, {"name": "pass_truncated", "description": "Truncated header passes", "packet_hex": "525400123456525400654321080045000010", "expected_action": "XDP_PASS", "weight": 1.0}]}, "reference_solution": "#include <linux/bpf.h>\n#include <bpf/bpf_helpers.h>\n#include <bpf/bpf_endian.h>\n#include <linux/if_ether.h>\n#include <linux/ip.h>\n#include <linux/in.h>\n#include <linux/udp.h>\n\nSEC(\"xdp\")\nint xdp_filter_ntp(struct xdp_md *ctx) {\n void *data_end = (void *)(long)ctx->data_end;\n void *data = (void *)(long)ctx->data;\n\n struct ethhdr *eth = data;\n if ((void *)(eth + 1) > data_end)\n return XDP_PASS;\n if (eth->h_proto != bpf_htons(ETH_P_IP))\n return XDP_PASS;\n\n struct iphdr *ip = (void *)(eth + 1);\n if ((void *)(ip + 1) > data_end)\n return XDP_PASS;\n if (ip->protocol != IPPROTO_UDP)\n return XDP_PASS;\n\n int ip_len = ip->ihl * 4;\n if (ip_len < sizeof(struct iphdr) || (void *)ip + ip_len > data_end)\n return XDP_PASS;\n\n struct udphdr *udp = (void *)ip + ip_len;\n if ((void *)(udp + 1) > data_end)\n return XDP_PASS;\n\n if (udp->dest == bpf_htons(123))\n return XDP_DROP;\n\n return XDP_PASS;\n}\n\nchar _license[] SEC(\"license\") = \"GPL\";\n"}
{"task_id": "rl_n3_dev_pfs_l1_03", "title": "", "description": "", "category": "", "difficulty": "level_1", "level": 1, "requirements": ["Verify Ethernet header bounds against data_end", "Verify IPv4 header bounds and confirm protocol is IPPROTO_UDP", "Safely validate variable IPv4 header length (ip->ihl * 4)", "Verify UDP header bounds against data_end", "Drop packet with XDP_DROP if UDP destination port equals 161", "Return XDP_PASS for non-matching or malformed traffic", "SEC(\"xdp\") entry point and GPL license declaration"], "prompt": "", "expected_fixture_count": 0, "test_cases": {"task_id": "rl_n3_dev_pfs_l1_03", "tests": [{"name": "drop_snmp", "description": "UDP port 161 dropped", "packet_hex": "52540012345652540065432108004500001c123400004011e52ec0a8010ac0a80114303900a100080000", "expected_action": "XDP_DROP", "weight": 1.0}, {"name": "pass_unrelated_udp", "description": "Other UDP port passes", "packet_hex": "52540012345652540065432108004500001c123400004011e52ec0a8010ac0a801143039270f00080000", "expected_action": "XDP_PASS", "weight": 1.0}, {"name": "pass_tcp", "description": "TCP traffic passes", "packet_hex": "525400123456525400654321080045000028123400004006e52dc0a8010ac0a80114303900a1000003e8000000005002fffff7b10000", "expected_action": "XDP_PASS", "weight": 1.0}, {"name": "pass_arp", "description": "ARP frame passes", "packet_hex": "52540012345652540065432108060001080006040001525400123456c0a8010a000000000000c0a80114", "expected_action": "XDP_PASS", "weight": 1.0}, {"name": "pass_truncated", "description": "Truncated header passes", "packet_hex": "525400123456525400654321080045000010", "expected_action": "XDP_PASS", "weight": 1.0}]}, "reference_solution": "#include <linux/bpf.h>\n#include <bpf/bpf_helpers.h>\n#include <bpf/bpf_endian.h>\n#include <linux/if_ether.h>\n#include <linux/ip.h>\n#include <linux/in.h>\n#include <linux/udp.h>\n\nSEC(\"xdp\")\nint xdp_filter_snmp(struct xdp_md *ctx) {\n void *data_end = (void *)(long)ctx->data_end;\n void *data = (void *)(long)ctx->data;\n\n struct ethhdr *eth = data;\n if ((void *)(eth + 1) > data_end)\n return XDP_PASS;\n if (eth->h_proto != bpf_htons(ETH_P_IP))\n return XDP_PASS;\n\n struct iphdr *ip = (void *)(eth + 1);\n if ((void *)(ip + 1) > data_end)\n return XDP_PASS;\n if (ip->protocol != IPPROTO_UDP)\n return XDP_PASS;\n\n int ip_len = ip->ihl * 4;\n if (ip_len < sizeof(struct iphdr) || (void *)ip + ip_len > data_end)\n return XDP_PASS;\n\n struct udphdr *udp = (void *)ip + ip_len;\n if ((void *)(udp + 1) > data_end)\n return XDP_PASS;\n\n if (udp->dest == bpf_htons(161))\n return XDP_DROP;\n\n return XDP_PASS;\n}\n\nchar _license[] SEC(\"license\") = \"GPL\";\n"}
{"task_id": "rl_n3_dev_pfs_l1_04", "title": "", "description": "", "category": "", "difficulty": "level_1", "level": 1, "requirements": ["Verify Ethernet header bounds against data_end", "Verify IPv4 header bounds and confirm protocol is IPPROTO_UDP", "Safely validate variable IPv4 header length (ip->ihl * 4)", "Verify UDP header bounds against data_end", "Drop packet with XDP_DROP if UDP destination port equals 514", "Return XDP_PASS for non-matching or malformed traffic", "SEC(\"xdp\") entry point and GPL license declaration"], "prompt": "", "expected_fixture_count": 0, "test_cases": {"task_id": "rl_n3_dev_pfs_l1_04", "tests": [{"name": "drop_syslog", "description": "UDP port 514 dropped", "packet_hex": "52540012345652540065432108004500001c123400004011e52ec0a8010ac0a801143039020200080000", "expected_action": "XDP_DROP", "weight": 1.0}, {"name": "pass_unrelated_udp", "description": "Other UDP port passes", "packet_hex": "52540012345652540065432108004500001c123400004011e52ec0a8010ac0a801143039270f00080000", "expected_action": "XDP_PASS", "weight": 1.0}, {"name": "pass_tcp", "description": "TCP traffic passes", "packet_hex": "525400123456525400654321080045000028123400004006e52dc0a8010ac0a8011430390202000003e8000000005002fffff6500000", "expected_action": "XDP_PASS", "weight": 1.0}, {"name": "pass_arp", "description": "ARP frame passes", "packet_hex": "52540012345652540065432108060001080006040001525400123456c0a8010a000000000000c0a80114", "expected_action": "XDP_PASS", "weight": 1.0}, {"name": "pass_truncated", "description": "Truncated header passes", "packet_hex": "525400123456525400654321080045000010", "expected_action": "XDP_PASS", "weight": 1.0}]}, "reference_solution": "#include <linux/bpf.h>\n#include <bpf/bpf_helpers.h>\n#include <bpf/bpf_endian.h>\n#include <linux/if_ether.h>\n#include <linux/ip.h>\n#include <linux/in.h>\n#include <linux/udp.h>\n\nSEC(\"xdp\")\nint xdp_filter_syslog(struct xdp_md *ctx) {\n void *data_end = (void *)(long)ctx->data_end;\n void *data = (void *)(long)ctx->data;\n\n struct ethhdr *eth = data;\n if ((void *)(eth + 1) > data_end)\n return XDP_PASS;\n if (eth->h_proto != bpf_htons(ETH_P_IP))\n return XDP_PASS;\n\n struct iphdr *ip = (void *)(eth + 1);\n if ((void *)(ip + 1) > data_end)\n return XDP_PASS;\n if (ip->protocol != IPPROTO_UDP)\n return XDP_PASS;\n\n int ip_len = ip->ihl * 4;\n if (ip_len < sizeof(struct iphdr) || (void *)ip + ip_len > data_end)\n return XDP_PASS;\n\n struct udphdr *udp = (void *)ip + ip_len;\n if ((void *)(udp + 1) > data_end)\n return XDP_PASS;\n\n if (udp->dest == bpf_htons(514))\n return XDP_DROP;\n\n return XDP_PASS;\n}\n\nchar _license[] SEC(\"license\") = \"GPL\";\n"}
{"task_id": "rl_n3_dev_pfs_l2_01", "title": "", "description": "", "category": "", "difficulty": "level_2", "level": 1, "requirements": ["Verify Ethernet header bounds against data_end", "Verify IPv4 header bounds against data_end", "Drop packet with XDP_DROP if ip->ttl <= 5", "Return XDP_PASS for TTL > 5 or non-IP frames", "SEC(\"xdp\") entry point and GPL license declaration"], "prompt": "", "expected_fixture_count": 0, "test_cases": {"task_id": "rl_n3_dev_pfs_l2_01", "tests": [{"name": "drop_ttl_5", "description": "TTL 5 dropped", "packet_hex": "5254001234565254006543210800450000241234000005012037c0a8010ac0a8011408009fa0123400015445535450494e47", "expected_action": "XDP_DROP", "weight": 1.0}, {"name": "pass_ttl_64", "description": "TTL 64 passes", "packet_hex": "525400123456525400654321080045000024123400004001e536c0a8010ac0a8011408009fa0123400015445535450494e47", "expected_action": "XDP_PASS", "weight": 1.0}, {"name": "pass_arp", "description": "ARP passes", "packet_hex": "52540012345652540065432108060001080006040001525400123456c0a8010a000000000000c0a80114", "expected_action": "XDP_PASS", "weight": 1.0}]}, "reference_solution": "#include <linux/bpf.h>\n#include <bpf/bpf_helpers.h>\n#include <bpf/bpf_endian.h>\n#include <linux/if_ether.h>\n#include <linux/ip.h>\n\nSEC(\"xdp\")\nint xdp_filter_ttl(struct xdp_md *ctx) {\n void *data_end = (void *)(long)ctx->data_end;\n void *data = (void *)(long)ctx->data;\n\n struct ethhdr *eth = data;\n if ((void *)(eth + 1) > data_end)\n return XDP_PASS;\n if (eth->h_proto != bpf_htons(ETH_P_IP))\n return XDP_PASS;\n\n struct iphdr *ip = (void *)(eth + 1);\n if ((void *)(ip + 1) > data_end)\n return XDP_PASS;\n\n if (ip->ttl <= 5)\n return XDP_DROP;\n\n return XDP_PASS;\n}\n\nchar _license[] SEC(\"license\") = \"GPL\";\n"}
{"task_id": "rl_n3_dev_pfs_l2_02", "title": "", "description": "", "category": "", "difficulty": "level_2", "level": 1, "requirements": ["Verify Ethernet header bounds against data_end", "Verify IPv4 header bounds against data_end", "Drop packet with XDP_DROP if ip->ihl > 5", "Return XDP_PASS for standard IHL 5 or non-IP traffic", "SEC(\"xdp\") entry point and GPL license declaration"], "prompt": "", "expected_fixture_count": 0, "test_cases": {"task_id": "rl_n3_dev_pfs_l2_02", "tests": [{"name": "drop_ihl_6", "description": "IHL 6 with options dropped", "packet_hex": "52540012345652540065432108004600002c123400004006e429c0a8010ac0a801140000000030390050000003e8000000005002fffff8020000", "expected_action": "XDP_DROP", "weight": 1.0}, {"name": "pass_ihl_5", "description": "Standard IHL 5 passes", "packet_hex": "525400123456525400654321080045000028123400004006e52dc0a8010ac0a8011430390050000003e8000000005002fffff8020000", "expected_action": "XDP_PASS", "weight": 1.0}, {"name": "pass_arp", "description": "ARP passes", "packet_hex": "52540012345652540065432108060001080006040001525400123456c0a8010a000000000000c0a80114", "expected_action": "XDP_PASS", "weight": 1.0}]}, "reference_solution": "#include <linux/bpf.h>\n#include <bpf/bpf_helpers.h>\n#include <bpf/bpf_endian.h>\n#include <linux/if_ether.h>\n#include <linux/ip.h>\n\nSEC(\"xdp\")\nint xdp_filter_ip_options(struct xdp_md *ctx) {\n void *data_end = (void *)(long)ctx->data_end;\n void *data = (void *)(long)ctx->data;\n\n struct ethhdr *eth = data;\n if ((void *)(eth + 1) > data_end)\n return XDP_PASS;\n if (eth->h_proto != bpf_htons(ETH_P_IP))\n return XDP_PASS;\n\n struct iphdr *ip = (void *)(eth + 1);\n if ((void *)(ip + 1) > data_end)\n return XDP_PASS;\n\n if (ip->ihl > 5)\n return XDP_DROP;\n\n return XDP_PASS;\n}\n\nchar _license[] SEC(\"license\") = \"GPL\";\n"}
{"task_id": "rl_n3_dev_pfs_l2_03", "title": "", "description": "", "category": "", "difficulty": "level_2", "level": 1, "requirements": ["Calculate total packet length from ctx->data and ctx->data_end", "Drop packet with XDP_DROP if length is strictly less than 40 bytes", "Return XDP_PASS for frames with length >= 40 bytes", "SEC(\"xdp\") entry point and GPL license declaration"], "prompt": "", "expected_fixture_count": 0, "test_cases": {"task_id": "rl_n3_dev_pfs_l2_03", "tests": [{"name": "drop_runt_28", "description": "28 byte runt dropped", "packet_hex": "52540012345652540065432108004500000e000000004000", "expected_action": "XDP_DROP", "weight": 1.0}, {"name": "pass_normal_54", "description": "54 byte frame passes", "packet_hex": "525400123456525400654321080045000028123400004006e52dc0a8010ac0a8011430390050000003e8000000005002fffff8020000", "expected_action": "XDP_PASS", "weight": 1.0}]}, "reference_solution": "#include <linux/bpf.h>\n#include <bpf/bpf_helpers.h>\n\nSEC(\"xdp\")\nint xdp_filter_runt(struct xdp_md *ctx) {\n void *data_end = (void *)(long)ctx->data_end;\n void *data = (void *)(long)ctx->data;\n\n long len = (long)data_end - (long)data;\n if (len < 40)\n return XDP_DROP;\n\n return XDP_PASS;\n}\n\nchar _license[] SEC(\"license\") = \"GPL\";\n"}
{"task_id": "rl_n3_dev_pfs_l2_04", "title": "", "description": "", "category": "", "difficulty": "level_2", "level": 1, "requirements": ["Verify Ethernet header bounds against data_end", "Verify IPv4 header bounds against data_end", "Check frag_off field for IP_MF flag (0x2000) or offset bits (0x1FFF)", "Drop packet with XDP_DROP if (bpf_ntohs(ip->frag_off) & 0x3FFF) != 0", "Return XDP_PASS for non-fragmented packets and non-IP traffic", "SEC(\"xdp\") entry point and GPL license declaration"], "prompt": "", "expected_fixture_count": 0, "test_cases": {"task_id": "rl_n3_dev_pfs_l2_04", "tests": [{"name": "drop_mf_set", "description": "MF fragment dropped", "packet_hex": "525400123456525400654321080045000028123420004006c52dc0a8010ac0a8011430390050000003e8000000005002fffff8020000", "expected_action": "XDP_DROP", "weight": 1.0}, {"name": "pass_unfragmented", "description": "Unfragmented passes", "packet_hex": "525400123456525400654321080045000028123400004006e52dc0a8010ac0a8011430390050000003e8000000005002fffff8020000", "expected_action": "XDP_PASS", "weight": 1.0}, {"name": "pass_arp", "description": "ARP passes", "packet_hex": "52540012345652540065432108060001080006040001525400123456c0a8010a000000000000c0a80114", "expected_action": "XDP_PASS", "weight": 1.0}]}, "reference_solution": "#include <linux/bpf.h>\n#include <bpf/bpf_helpers.h>\n#include <bpf/bpf_endian.h>\n#include <linux/if_ether.h>\n#include <linux/ip.h>\n\nSEC(\"xdp\")\nint xdp_filter_frag(struct xdp_md *ctx) {\n void *data_end = (void *)(long)ctx->data_end;\n void *data = (void *)(long)ctx->data;\n\n struct ethhdr *eth = data;\n if ((void *)(eth + 1) > data_end)\n return XDP_PASS;\n if (eth->h_proto != bpf_htons(ETH_P_IP))\n return XDP_PASS;\n\n struct iphdr *ip = (void *)(eth + 1);\n if ((void *)(ip + 1) > data_end)\n return XDP_PASS;\n\n __u16 frag = bpf_ntohs(ip->frag_off);\n if (frag & 0x3FFF)\n return XDP_DROP;\n\n return XDP_PASS;\n}\n\nchar _license[] SEC(\"license\") = \"GPL\";\n"}
{"task_id": "rl_n3_dev_pfs_l3_01", "title": "", "description": "", "category": "", "difficulty": "level_3", "level": 1, "requirements": ["Define BPF_MAP_TYPE_LRU_HASH map 'quarantine_map' with key __u32 and max_entries 1024", "Verify Ethernet and IPv4 header bounds against data_end", "Lookup ip->saddr in quarantine_map", "Drop packet with XDP_DROP if lookup succeeds", "Return XDP_PASS otherwise", "SEC(\"xdp\") entry point and GPL license declaration"], "prompt": "", "expected_fixture_count": 0, "test_cases": {"task_id": "rl_n3_dev_pfs_l3_01", "tests": [{"name": "pass_untracked", "description": "Untracked client passes", "packet_hex": "5254001234565254006543210800450000281234000040069bad0a010132c0a8011430390050000003e8000000005002fffff8020000", "expected_action": "XDP_PASS", "weight": 1.0}, {"name": "pass_arp", "description": "ARP passes", "packet_hex": "52540012345652540065432108060001080006040001525400123456c0a8010a000000000000c0a80114", "expected_action": "XDP_PASS", "weight": 1.0}]}, "reference_solution": "#include <linux/bpf.h>\n#include <bpf/bpf_helpers.h>\n#include <bpf/bpf_endian.h>\n#include <linux/if_ether.h>\n#include <linux/ip.h>\n\nstruct {\n __uint(type, BPF_MAP_TYPE_LRU_HASH);\n __type(key, __u32);\n __type(value, __u8);\n __uint(max_entries, 1024);\n} quarantine_map SEC(\".maps\");\n\nSEC(\"xdp\")\nint xdp_filter_quarantine(struct xdp_md *ctx) {\n void *data_end = (void *)(long)ctx->data_end;\n void *data = (void *)(long)ctx->data;\n\n struct ethhdr *eth = data;\n if ((void *)(eth + 1) > data_end)\n return XDP_PASS;\n if (eth->h_proto != bpf_htons(ETH_P_IP))\n return XDP_PASS;\n\n struct iphdr *ip = (void *)(eth + 1);\n if ((void *)(ip + 1) > data_end)\n return XDP_PASS;\n\n __u32 src = ip->saddr;\n __u8 *val = bpf_map_lookup_elem(&quarantine_map, &src);\n if (val)\n return XDP_DROP;\n\n return XDP_PASS;\n}\n\nchar _license[] SEC(\"license\") = \"GPL\";\n"}
{"task_id": "rl_n3_dev_pfs_l3_02", "title": "", "description": "", "category": "", "difficulty": "level_3", "level": 1, "requirements": ["Define BPF_MAP_TYPE_LRU_HASH map 'client_quota_map' with key __u32 and value __u64", "Verify Ethernet and IPv4 header bounds against data_end", "Lookup ip->saddr in client_quota_map and atomically increment count", "Drop packet with XDP_DROP if packet count exceeds 100", "Return XDP_PASS otherwise", "SEC(\"xdp\") entry point and GPL license declaration"], "prompt": "", "expected_fixture_count": 0, "test_cases": {"task_id": "rl_n3_dev_pfs_l3_02", "tests": [{"name": "pass_untracked", "description": "Untracked client passes", "packet_hex": "5254001234565254006543210800450000281234000040069bad0a010132c0a8011430390050000003e8000000005002fffff8020000", "expected_action": "XDP_PASS", "weight": 1.0}, {"name": "pass_arp", "description": "ARP passes", "packet_hex": "52540012345652540065432108060001080006040001525400123456c0a8010a000000000000c0a80114", "expected_action": "XDP_PASS", "weight": 1.0}]}, "reference_solution": "#include <linux/bpf.h>\n#include <bpf/bpf_helpers.h>\n#include <bpf/bpf_endian.h>\n#include <linux/if_ether.h>\n#include <linux/ip.h>\n\nstruct {\n __uint(type, BPF_MAP_TYPE_LRU_HASH);\n __type(key, __u32);\n __type(value, __u64);\n __uint(max_entries, 1024);\n} client_quota_map SEC(\".maps\");\n\nSEC(\"xdp\")\nint xdp_filter_quota(struct xdp_md *ctx) {\n void *data_end = (void *)(long)ctx->data_end;\n void *data = (void *)(long)ctx->data;\n\n struct ethhdr *eth = data;\n if ((void *)(eth + 1) > data_end)\n return XDP_PASS;\n if (eth->h_proto != bpf_htons(ETH_P_IP))\n return XDP_PASS;\n\n struct iphdr *ip = (void *)(eth + 1);\n if ((void *)(ip + 1) > data_end)\n return XDP_PASS;\n\n __u32 src = ip->saddr;\n __u64 *val = bpf_map_lookup_elem(&client_quota_map, &src);\n if (val) {\n __sync_fetch_and_add(val, 1);\n if (*val > 100)\n return XDP_DROP;\n } else {\n __u64 init_val = 1;\n bpf_map_update_elem(&client_quota_map, &src, &init_val, BPF_NOEXIST);\n }\n\n return XDP_PASS;\n}\n\nchar _license[] SEC(\"license\") = \"GPL\";\n"}
{"task_id": "rl_n3_dev_pfs_l3_03", "title": "", "description": "", "category": "", "difficulty": "level_3", "level": 1, "requirements": ["Define BPF_MAP_TYPE_HASH map 'blocked_knock_map' with key __u32 and max_entries 512", "Verify Ethernet and IPv4 header bounds against data_end", "Lookup ip->saddr in blocked_knock_map", "Drop packet with XDP_DROP if lookup succeeds (host is blocked)", "Return XDP_PASS otherwise", "SEC(\"xdp\") entry point and GPL license declaration"], "prompt": "", "expected_fixture_count": 0, "test_cases": {"task_id": "rl_n3_dev_pfs_l3_03", "tests": [{"name": "pass_untracked", "description": "Untracked client passes", "packet_hex": "5254001234565254006543210800450000281234000040069bad0a010132c0a8011430390050000003e8000000005002fffff8020000", "expected_action": "XDP_PASS", "weight": 1.0}, {"name": "pass_arp", "description": "ARP passes", "packet_hex": "52540012345652540065432108060001080006040001525400123456c0a8010a000000000000c0a80114", "expected_action": "XDP_PASS", "weight": 1.0}]}, "reference_solution": "#include <linux/bpf.h>\n#include <bpf/bpf_helpers.h>\n#include <bpf/bpf_endian.h>\n#include <linux/if_ether.h>\n#include <linux/ip.h>\n\nstruct {\n __uint(type, BPF_MAP_TYPE_HASH);\n __type(key, __u32);\n __type(value, __u32);\n __uint(max_entries, 512);\n} blocked_knock_map SEC(\".maps\");\n\nSEC(\"xdp\")\nint xdp_filter_knock(struct xdp_md *ctx) {\n void *data_end = (void *)(long)ctx->data_end;\n void *data = (void *)(long)ctx->data;\n\n struct ethhdr *eth = data;\n if ((void *)(eth + 1) > data_end)\n return XDP_PASS;\n if (eth->h_proto != bpf_htons(ETH_P_IP))\n return XDP_PASS;\n\n struct iphdr *ip = (void *)(eth + 1);\n if ((void *)(ip + 1) > data_end)\n return XDP_PASS;\n\n __u32 src = ip->saddr;\n __u32 *blocked = bpf_map_lookup_elem(&blocked_knock_map, &src);\n if (blocked)\n return XDP_DROP;\n\n return XDP_PASS;\n}\n\nchar _license[] SEC(\"license\") = \"GPL\";\n"}
{"task_id": "rl_n3_dev_pfs_l3_04", "title": "", "description": "", "category": "", "difficulty": "level_3", "level": 1, "requirements": ["Define BPF_MAP_TYPE_HASH map 'burst_timestamp_map' with key __u32 and value __u64", "Verify Ethernet and IPv4 header bounds against data_end", "Query current timestamp with bpf_ktime_get_ns() and lookup ip->saddr", "Drop packet with XDP_DROP if (now - last_time) < 1000000ULL", "Update timestamp in map and return XDP_PASS", "SEC(\"xdp\") entry point and GPL license declaration"], "prompt": "", "expected_fixture_count": 0, "test_cases": {"task_id": "rl_n3_dev_pfs_l3_04", "tests": [{"name": "pass_untracked", "description": "Untracked client passes", "packet_hex": "5254001234565254006543210800450000281234000040069bad0a010132c0a8011430390050000003e8000000005002fffff8020000", "expected_action": "XDP_PASS", "weight": 1.0}, {"name": "pass_arp", "description": "ARP passes", "packet_hex": "52540012345652540065432108060001080006040001525400123456c0a8010a000000000000c0a80114", "expected_action": "XDP_PASS", "weight": 1.0}]}, "reference_solution": "#include <linux/bpf.h>\n#include <bpf/bpf_helpers.h>\n#include <bpf/bpf_endian.h>\n#include <linux/if_ether.h>\n#include <linux/ip.h>\n\nstruct {\n __uint(type, BPF_MAP_TYPE_HASH);\n __type(key, __u32);\n __type(value, __u64);\n __uint(max_entries, 1024);\n} burst_timestamp_map SEC(\".maps\");\n\nSEC(\"xdp\")\nint xdp_filter_burst(struct xdp_md *ctx) {\n void *data_end = (void *)(long)ctx->data_end;\n void *data = (void *)(long)ctx->data;\n\n struct ethhdr *eth = data;\n if ((void *)(eth + 1) > data_end)\n return XDP_PASS;\n if (eth->h_proto != bpf_htons(ETH_P_IP))\n return XDP_PASS;\n\n struct iphdr *ip = (void *)(eth + 1);\n if ((void *)(ip + 1) > data_end)\n return XDP_PASS;\n\n __u32 src = ip->saddr;\n __u64 now = bpf_ktime_get_ns();\n __u64 *last = bpf_map_lookup_elem(&burst_timestamp_map, &src);\n if (last) {\n if (now - *last < 1000000ULL)\n return XDP_DROP;\n *last = now;\n } else {\n bpf_map_update_elem(&burst_timestamp_map, &src, &now, BPF_ANY);\n }\n\n return XDP_PASS;\n}\n\nchar _license[] SEC(\"license\") = \"GPL\";\n"}
{"task_id": "rl_n3_dev_pit_l1_01", "title": "", "description": "", "category": "", "difficulty": "level_1", "level": 1, "requirements": ["Define BPF_MAP_TYPE_ARRAY map 'size_hist_1' with 4 entries and __u64 values", "Calculate total wire frame length as (ctx->data_end - ctx->data)", "Assign bin: <128 -> 0, <512 -> 1, <1024 -> 2, >=1024 -> 3", "Atomically increment bin counter using __sync_fetch_and_add", "Return XDP_PASS unconditionally", "SEC(\"xdp\") entry point and GPL license declaration"], "prompt": "", "expected_fixture_count": 0, "test_cases": {"task_id": "rl_n3_dev_pit_l1_01", "tests": [{"name": "pass_small", "description": "Small 54 byte frame in bin 0", "packet_hex": "525400123456525400654321080045000028123400004006e52dc0a8010ac0a8011430390050000003e8000000005002fffff8020000", "expected_action": "XDP_PASS", "weight": 1.0}, {"name": "pass_medium", "description": "Medium 200 byte frame in bin 1", "packet_hex": "5254001234565254006543210800450000bc123400004011e48ec0a8010ac0a801143039003500a8000041414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141", "expected_action": "XDP_PASS", "weight": 1.0}]}, "reference_solution": "#include <linux/bpf.h>\n#include <bpf/bpf_helpers.h>\n\nstruct {\n __uint(type, BPF_MAP_TYPE_ARRAY);\n __type(key, __u32);\n __type(value, __u64);\n __uint(max_entries, 4);\n} size_hist_1 SEC(\".maps\");\n\nSEC(\"xdp\")\nint xdp_hist_1(struct xdp_md *ctx) {\n void *data_end = (void *)(long)ctx->data_end;\n void *data = (void *)(long)ctx->data;\n\n long len = (long)data_end - (long)data;\n __u32 bin = 0;\n if (len < 128)\n bin = 0;\n else if (len < 512)\n bin = 1;\n else if (len < 1024)\n bin = 2;\n else\n bin = 3;\n\n __u64 *val = bpf_map_lookup_elem(&size_hist_1, &bin);\n if (val)\n __sync_fetch_and_add(val, 1);\n\n return XDP_PASS;\n}\n\nchar _license[] SEC(\"license\") = \"GPL\";\n"}
{"task_id": "rl_n3_dev_pit_l1_02", "title": "", "description": "", "category": "", "difficulty": "level_1", "level": 1, "requirements": ["Define BPF_MAP_TYPE_ARRAY map 'size_hist_2' with 4 entries and __u64 values", "Calculate total wire frame length as (ctx->data_end - ctx->data)", "Assign bin: <128 -> 0, <512 -> 1, <1024 -> 2, >=1024 -> 3", "Atomically increment bin counter using __sync_fetch_and_add", "Return XDP_PASS unconditionally", "SEC(\"xdp\") entry point and GPL license declaration"], "prompt": "", "expected_fixture_count": 0, "test_cases": {"task_id": "rl_n3_dev_pit_l1_02", "tests": [{"name": "pass_small", "description": "Small 54 byte frame in bin 0", "packet_hex": "525400123456525400654321080045000028123400004006e52dc0a8010ac0a8011430390050000003e8000000005002fffff8020000", "expected_action": "XDP_PASS", "weight": 1.0}, {"name": "pass_medium", "description": "Medium 200 byte frame in bin 1", "packet_hex": "5254001234565254006543210800450000bc123400004011e48ec0a8010ac0a801143039003500a8000041414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141", "expected_action": "XDP_PASS", "weight": 1.0}]}, "reference_solution": "#include <linux/bpf.h>\n#include <bpf/bpf_helpers.h>\n\nstruct {\n __uint(type, BPF_MAP_TYPE_ARRAY);\n __type(key, __u32);\n __type(value, __u64);\n __uint(max_entries, 4);\n} size_hist_2 SEC(\".maps\");\n\nSEC(\"xdp\")\nint xdp_hist_2(struct xdp_md *ctx) {\n void *data_end = (void *)(long)ctx->data_end;\n void *data = (void *)(long)ctx->data;\n\n long len = (long)data_end - (long)data;\n __u32 bin = 0;\n if (len < 128)\n bin = 0;\n else if (len < 512)\n bin = 1;\n else if (len < 1024)\n bin = 2;\n else\n bin = 3;\n\n __u64 *val = bpf_map_lookup_elem(&size_hist_2, &bin);\n if (val)\n __sync_fetch_and_add(val, 1);\n\n return XDP_PASS;\n}\n\nchar _license[] SEC(\"license\") = \"GPL\";\n"}
{"task_id": "rl_n3_dev_pit_l1_03", "title": "", "description": "", "category": "", "difficulty": "level_1", "level": 1, "requirements": ["Define BPF_MAP_TYPE_ARRAY map 'size_hist_3' with 4 entries and __u64 values", "Calculate total wire frame length as (ctx->data_end - ctx->data)", "Assign bin: <128 -> 0, <512 -> 1, <1024 -> 2, >=1024 -> 3", "Atomically increment bin counter using __sync_fetch_and_add", "Return XDP_PASS unconditionally", "SEC(\"xdp\") entry point and GPL license declaration"], "prompt": "", "expected_fixture_count": 0, "test_cases": {"task_id": "rl_n3_dev_pit_l1_03", "tests": [{"name": "pass_small", "description": "Small 54 byte frame in bin 0", "packet_hex": "525400123456525400654321080045000028123400004006e52dc0a8010ac0a8011430390050000003e8000000005002fffff8020000", "expected_action": "XDP_PASS", "weight": 1.0}, {"name": "pass_medium", "description": "Medium 200 byte frame in bin 1", "packet_hex": "5254001234565254006543210800450000bc123400004011e48ec0a8010ac0a801143039003500a8000041414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141", "expected_action": "XDP_PASS", "weight": 1.0}]}, "reference_solution": "#include <linux/bpf.h>\n#include <bpf/bpf_helpers.h>\n\nstruct {\n __uint(type, BPF_MAP_TYPE_ARRAY);\n __type(key, __u32);\n __type(value, __u64);\n __uint(max_entries, 4);\n} size_hist_3 SEC(\".maps\");\n\nSEC(\"xdp\")\nint xdp_hist_3(struct xdp_md *ctx) {\n void *data_end = (void *)(long)ctx->data_end;\n void *data = (void *)(long)ctx->data;\n\n long len = (long)data_end - (long)data;\n __u32 bin = 0;\n if (len < 128)\n bin = 0;\n else if (len < 512)\n bin = 1;\n else if (len < 1024)\n bin = 2;\n else\n bin = 3;\n\n __u64 *val = bpf_map_lookup_elem(&size_hist_3, &bin);\n if (val)\n __sync_fetch_and_add(val, 1);\n\n return XDP_PASS;\n}\n\nchar _license[] SEC(\"license\") = \"GPL\";\n"}
{"task_id": "rl_n3_dev_pit_l1_04", "title": "", "description": "", "category": "", "difficulty": "level_1", "level": 1, "requirements": ["Define BPF_MAP_TYPE_ARRAY map 'size_hist_4' with 4 entries and __u64 values", "Calculate total wire frame length as (ctx->data_end - ctx->data)", "Assign bin: <128 -> 0, <512 -> 1, <1024 -> 2, >=1024 -> 3", "Atomically increment bin counter using __sync_fetch_and_add", "Return XDP_PASS unconditionally", "SEC(\"xdp\") entry point and GPL license declaration"], "prompt": "", "expected_fixture_count": 0, "test_cases": {"task_id": "rl_n3_dev_pit_l1_04", "tests": [{"name": "pass_small", "description": "Small 54 byte frame in bin 0", "packet_hex": "525400123456525400654321080045000028123400004006e52dc0a8010ac0a8011430390050000003e8000000005002fffff8020000", "expected_action": "XDP_PASS", "weight": 1.0}, {"name": "pass_medium", "description": "Medium 200 byte frame in bin 1", "packet_hex": "5254001234565254006543210800450000bc123400004011e48ec0a8010ac0a801143039003500a8000041414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141414141", "expected_action": "XDP_PASS", "weight": 1.0}]}, "reference_solution": "#include <linux/bpf.h>\n#include <bpf/bpf_helpers.h>\n\nstruct {\n __uint(type, BPF_MAP_TYPE_ARRAY);\n __type(key, __u32);\n __type(value, __u64);\n __uint(max_entries, 4);\n} size_hist_4 SEC(\".maps\");\n\nSEC(\"xdp\")\nint xdp_hist_4(struct xdp_md *ctx) {\n void *data_end = (void *)(long)ctx->data_end;\n void *data = (void *)(long)ctx->data;\n\n long len = (long)data_end - (long)data;\n __u32 bin = 0;\n if (len < 128)\n bin = 0;\n else if (len < 512)\n bin = 1;\n else if (len < 1024)\n bin = 2;\n else\n bin = 3;\n\n __u64 *val = bpf_map_lookup_elem(&size_hist_4, &bin);\n if (val)\n __sync_fetch_and_add(val, 1);\n\n return XDP_PASS;\n}\n\nchar _license[] SEC(\"license\") = \"GPL\";\n"}
{"task_id": "rl_n3_dev_pit_l2_01", "title": "", "description": "", "category": "", "difficulty": "level_2", "level": 1, "requirements": ["Define BPF_MAP_TYPE_LRU_HASH map 'dst_bytes_01' with key __u32 and value __u64", "Verify Ethernet and IPv4 header bounds against data_end", "Extract bpf_ntohs(ip->tot_len) and lookup ip->daddr in map", "Atomically add byte count to existing entry or initialize with packet length", "Return XDP_PASS unconditionally", "SEC(\"xdp\") entry point and GPL license declaration"], "prompt": "", "expected_fixture_count": 0, "test_cases": {"task_id": "rl_n3_dev_pit_l2_01", "tests": [{"name": "pass_ip", "description": "IPv4 bytes accumulated and passed", "packet_hex": "525400123456525400654321080045000028123400004006e50fc0a8010ac0a8013230390050000003e8000000005002fffff8020000", "expected_action": "XDP_PASS", "weight": 1.0}, {"name": "pass_arp", "description": "ARP passed unmodified", "packet_hex": "52540012345652540065432108060001080006040001525400123456c0a8010a000000000000c0a80114", "expected_action": "XDP_PASS", "weight": 1.0}]}, "reference_solution": "#include <linux/bpf.h>\n#include <bpf/bpf_helpers.h>\n#include <bpf/bpf_endian.h>\n#include <linux/if_ether.h>\n#include <linux/ip.h>\n\nstruct {\n __uint(type, BPF_MAP_TYPE_LRU_HASH);\n __type(key, __u32);\n __type(value, __u64);\n __uint(max_entries, 1024);\n} dst_bytes_01 SEC(\".maps\");\n\nSEC(\"xdp\")\nint xdp_bytes_dst_1(struct xdp_md *ctx) {\n void *data_end = (void *)(long)ctx->data_end;\n void *data = (void *)(long)ctx->data;\n\n struct ethhdr *eth = data;\n if ((void *)(eth + 1) > data_end)\n return XDP_PASS;\n if (eth->h_proto != bpf_htons(ETH_P_IP))\n return XDP_PASS;\n\n struct iphdr *ip = (void *)(eth + 1);\n if ((void *)(ip + 1) > data_end)\n return XDP_PASS;\n\n __u32 dst = ip->daddr;\n __u64 pkt_bytes = bpf_ntohs(ip->tot_len);\n\n __u64 *val = bpf_map_lookup_elem(&dst_bytes_01, &dst);\n if (val) {\n __sync_fetch_and_add(val, pkt_bytes);\n } else {\n bpf_map_update_elem(&dst_bytes_01, &dst, &pkt_bytes, BPF_NOEXIST);\n }\n\n return XDP_PASS;\n}\n\nchar _license[] SEC(\"license\") = \"GPL\";\n"}
{"task_id": "rl_n3_dev_pit_l2_02", "title": "", "description": "", "category": "", "difficulty": "level_2", "level": 1, "requirements": ["Define BPF_MAP_TYPE_LRU_HASH map 'dst_bytes_02' with key __u32 and value __u64", "Verify Ethernet and IPv4 header bounds against data_end", "Extract bpf_ntohs(ip->tot_len) and lookup ip->daddr in map", "Atomically add byte count to existing entry or initialize with packet length", "Return XDP_PASS unconditionally", "SEC(\"xdp\") entry point and GPL license declaration"], "prompt": "", "expected_fixture_count": 0, "test_cases": {"task_id": "rl_n3_dev_pit_l2_02", "tests": [{"name": "pass_ip", "description": "IPv4 bytes accumulated and passed", "packet_hex": "525400123456525400654321080045000028123400004006e50fc0a8010ac0a8013230390050000003e8000000005002fffff8020000", "expected_action": "XDP_PASS", "weight": 1.0}, {"name": "pass_arp", "description": "ARP passed unmodified", "packet_hex": "52540012345652540065432108060001080006040001525400123456c0a8010a000000000000c0a80114", "expected_action": "XDP_PASS", "weight": 1.0}]}, "reference_solution": "#include <linux/bpf.h>\n#include <bpf/bpf_helpers.h>\n#include <bpf/bpf_endian.h>\n#include <linux/if_ether.h>\n#include <linux/ip.h>\n\nstruct {\n __uint(type, BPF_MAP_TYPE_LRU_HASH);\n __type(key, __u32);\n __type(value, __u64);\n __uint(max_entries, 1024);\n} dst_bytes_02 SEC(\".maps\");\n\nSEC(\"xdp\")\nint xdp_bytes_dst_2(struct xdp_md *ctx) {\n void *data_end = (void *)(long)ctx->data_end;\n void *data = (void *)(long)ctx->data;\n\n struct ethhdr *eth = data;\n if ((void *)(eth + 1) > data_end)\n return XDP_PASS;\n if (eth->h_proto != bpf_htons(ETH_P_IP))\n return XDP_PASS;\n\n struct iphdr *ip = (void *)(eth + 1);\n if ((void *)(ip + 1) > data_end)\n return XDP_PASS;\n\n __u32 dst = ip->daddr;\n __u64 pkt_bytes = bpf_ntohs(ip->tot_len);\n\n __u64 *val = bpf_map_lookup_elem(&dst_bytes_02, &dst);\n if (val) {\n __sync_fetch_and_add(val, pkt_bytes);\n } else {\n bpf_map_update_elem(&dst_bytes_02, &dst, &pkt_bytes, BPF_NOEXIST);\n }\n\n return XDP_PASS;\n}\n\nchar _license[] SEC(\"license\") = \"GPL\";\n"}
{"task_id": "rl_n3_dev_pit_l2_03", "title": "", "description": "", "category": "", "difficulty": "level_2", "level": 1, "requirements": ["Define BPF_MAP_TYPE_LRU_HASH map 'dst_bytes_03' with key __u32 and value __u64", "Verify Ethernet and IPv4 header bounds against data_end", "Extract bpf_ntohs(ip->tot_len) and lookup ip->daddr in map", "Atomically add byte count to existing entry or initialize with packet length", "Return XDP_PASS unconditionally", "SEC(\"xdp\") entry point and GPL license declaration"], "prompt": "", "expected_fixture_count": 0, "test_cases": {"task_id": "rl_n3_dev_pit_l2_03", "tests": [{"name": "pass_ip", "description": "IPv4 bytes accumulated and passed", "packet_hex": "525400123456525400654321080045000028123400004006e50fc0a8010ac0a8013230390050000003e8000000005002fffff8020000", "expected_action": "XDP_PASS", "weight": 1.0}, {"name": "pass_arp", "description": "ARP passed unmodified", "packet_hex": "52540012345652540065432108060001080006040001525400123456c0a8010a000000000000c0a80114", "expected_action": "XDP_PASS", "weight": 1.0}]}, "reference_solution": "#include <linux/bpf.h>\n#include <bpf/bpf_helpers.h>\n#include <bpf/bpf_endian.h>\n#include <linux/if_ether.h>\n#include <linux/ip.h>\n\nstruct {\n __uint(type, BPF_MAP_TYPE_LRU_HASH);\n __type(key, __u32);\n __type(value, __u64);\n __uint(max_entries, 1024);\n} dst_bytes_03 SEC(\".maps\");\n\nSEC(\"xdp\")\nint xdp_bytes_dst_3(struct xdp_md *ctx) {\n void *data_end = (void *)(long)ctx->data_end;\n void *data = (void *)(long)ctx->data;\n\n struct ethhdr *eth = data;\n if ((void *)(eth + 1) > data_end)\n return XDP_PASS;\n if (eth->h_proto != bpf_htons(ETH_P_IP))\n return XDP_PASS;\n\n struct iphdr *ip = (void *)(eth + 1);\n if ((void *)(ip + 1) > data_end)\n return XDP_PASS;\n\n __u32 dst = ip->daddr;\n __u64 pkt_bytes = bpf_ntohs(ip->tot_len);\n\n __u64 *val = bpf_map_lookup_elem(&dst_bytes_03, &dst);\n if (val) {\n __sync_fetch_and_add(val, pkt_bytes);\n } else {\n bpf_map_update_elem(&dst_bytes_03, &dst, &pkt_bytes, BPF_NOEXIST);\n }\n\n return XDP_PASS;\n}\n\nchar _license[] SEC(\"license\") = \"GPL\";\n"}
{"task_id": "rl_n3_dev_pit_l2_04", "title": "", "description": "", "category": "", "difficulty": "level_2", "level": 1, "requirements": ["Define BPF_MAP_TYPE_LRU_HASH map 'dst_bytes_04' with key __u32 and value __u64", "Verify Ethernet and IPv4 header bounds against data_end", "Extract bpf_ntohs(ip->tot_len) and lookup ip->daddr in map", "Atomically add byte count to existing entry or initialize with packet length", "Return XDP_PASS unconditionally", "SEC(\"xdp\") entry point and GPL license declaration"], "prompt": "", "expected_fixture_count": 0, "test_cases": {"task_id": "rl_n3_dev_pit_l2_04", "tests": [{"name": "pass_ip", "description": "IPv4 bytes accumulated and passed", "packet_hex": "525400123456525400654321080045000028123400004006e50fc0a8010ac0a8013230390050000003e8000000005002fffff8020000", "expected_action": "XDP_PASS", "weight": 1.0}, {"name": "pass_arp", "description": "ARP passed unmodified", "packet_hex": "52540012345652540065432108060001080006040001525400123456c0a8010a000000000000c0a80114", "expected_action": "XDP_PASS", "weight": 1.0}]}, "reference_solution": "#include <linux/bpf.h>\n#include <bpf/bpf_helpers.h>\n#include <bpf/bpf_endian.h>\n#include <linux/if_ether.h>\n#include <linux/ip.h>\n\nstruct {\n __uint(type, BPF_MAP_TYPE_LRU_HASH);\n __type(key, __u32);\n __type(value, __u64);\n __uint(max_entries, 1024);\n} dst_bytes_04 SEC(\".maps\");\n\nSEC(\"xdp\")\nint xdp_bytes_dst_4(struct xdp_md *ctx) {\n void *data_end = (void *)(long)ctx->data_end;\n void *data = (void *)(long)ctx->data;\n\n struct ethhdr *eth = data;\n if ((void *)(eth + 1) > data_end)\n return XDP_PASS;\n if (eth->h_proto != bpf_htons(ETH_P_IP))\n return XDP_PASS;\n\n struct iphdr *ip = (void *)(eth + 1);\n if ((void *)(ip + 1) > data_end)\n return XDP_PASS;\n\n __u32 dst = ip->daddr;\n __u64 pkt_bytes = bpf_ntohs(ip->tot_len);\n\n __u64 *val = bpf_map_lookup_elem(&dst_bytes_04, &dst);\n if (val) {\n __sync_fetch_and_add(val, pkt_bytes);\n } else {\n bpf_map_update_elem(&dst_bytes_04, &dst, &pkt_bytes, BPF_NOEXIST);\n }\n\n return XDP_PASS;\n}\n\nchar _license[] SEC(\"license\") = \"GPL\";\n"}
{"task_id": "rl_n3_dev_pit_l3_01", "title": "", "description": "", "category": "", "difficulty": "level_3", "level": 1, "requirements": ["Define BPF_MAP_TYPE_ARRAY map 'win_dist_01' with 4 entries and __u64 values", "Verify Ethernet, IPv4, and TCP header bounds against data_end", "Inspect bpf_ntohs(tcp->window) and select bucket: <4k -> 0, <16k -> 1, <65535 -> 2, >=65535 -> 3", "Atomically increment window bucket counter using __sync_fetch_and_add", "Return XDP_PASS unconditionally", "SEC(\"xdp\") entry point and GPL license declaration"], "prompt": "", "expected_fixture_count": 0, "test_cases": {"task_id": "rl_n3_dev_pit_l3_01", "tests": [{"name": "pass_small_win", "description": "Small window in bin 0 passed", "packet_hex": "525400123456525400654321080045000028123400004006e52dc0a8010ac0a8011430390050000003e800000000500203e8f41a0000", "expected_action": "XDP_PASS", "weight": 1.0}, {"name": "pass_large_win", "description": "Large window in bin 3 passed", "packet_hex": "525400123456525400654321080045000028123400004006e52dc0a8010ac0a8011430390050000003e8000000005002fffff8020000", "expected_action": "XDP_PASS", "weight": 1.0}, {"name": "pass_arp", "description": "ARP passed unmodified", "packet_hex": "52540012345652540065432108060001080006040001525400123456c0a8010a000000000000c0a80114", "expected_action": "XDP_PASS", "weight": 1.0}]}, "reference_solution": "#include <linux/bpf.h>\n#include <bpf/bpf_helpers.h>\n#include <bpf/bpf_endian.h>\n#include <linux/if_ether.h>\n#include <linux/ip.h>\n#include <linux/in.h>\n#include <linux/tcp.h>\n\nstruct {\n __uint(type, BPF_MAP_TYPE_ARRAY);\n __type(key, __u32);\n __type(value, __u64);\n __uint(max_entries, 4);\n} win_dist_01 SEC(\".maps\");\n\nSEC(\"xdp\")\nint xdp_win_1(struct xdp_md *ctx) {\n void *data_end = (void *)(long)ctx->data_end;\n void *data = (void *)(long)ctx->data;\n\n struct ethhdr *eth = data;\n if ((void *)(eth + 1) > data_end)\n return XDP_PASS;\n if (eth->h_proto != bpf_htons(ETH_P_IP))\n return XDP_PASS;\n\n struct iphdr *ip = (void *)(eth + 1);\n if ((void *)(ip + 1) > data_end)\n return XDP_PASS;\n if (ip->protocol != IPPROTO_TCP)\n return XDP_PASS;\n\n int ip_len = ip->ihl * 4;\n if (ip_len < sizeof(struct iphdr) || (void *)ip + ip_len > data_end)\n return XDP_PASS;\n\n struct tcphdr *tcp = (void *)ip + ip_len;\n if ((void *)(tcp + 1) > data_end)\n return XDP_PASS;\n\n __u16 win = bpf_ntohs(tcp->window);\n __u32 bin = 0;\n if (win < 4096)\n bin = 0;\n else if (win < 16384)\n bin = 1;\n else if (win < 65535)\n bin = 2;\n else\n bin = 3;\n\n __u64 *val = bpf_map_lookup_elem(&win_dist_01, &bin);\n if (val)\n __sync_fetch_and_add(val, 1);\n\n return XDP_PASS;\n}\n\nchar _license[] SEC(\"license\") = \"GPL\";\n"}
{"task_id": "rl_n3_dev_pit_l3_02", "title": "", "description": "", "category": "", "difficulty": "level_3", "level": 1, "requirements": ["Define BPF_MAP_TYPE_ARRAY map 'win_dist_02' with 4 entries and __u64 values", "Verify Ethernet, IPv4, and TCP header bounds against data_end", "Inspect bpf_ntohs(tcp->window) and select bucket: <4k -> 0, <16k -> 1, <65535 -> 2, >=65535 -> 3", "Atomically increment window bucket counter using __sync_fetch_and_add", "Return XDP_PASS unconditionally", "SEC(\"xdp\") entry point and GPL license declaration"], "prompt": "", "expected_fixture_count": 0, "test_cases": {"task_id": "rl_n3_dev_pit_l3_02", "tests": [{"name": "pass_small_win", "description": "Small window in bin 0 passed", "packet_hex": "525400123456525400654321080045000028123400004006e52dc0a8010ac0a8011430390050000003e800000000500203e8f41a0000", "expected_action": "XDP_PASS", "weight": 1.0}, {"name": "pass_large_win", "description": "Large window in bin 3 passed", "packet_hex": "525400123456525400654321080045000028123400004006e52dc0a8010ac0a8011430390050000003e8000000005002fffff8020000", "expected_action": "XDP_PASS", "weight": 1.0}, {"name": "pass_arp", "description": "ARP passed unmodified", "packet_hex": "52540012345652540065432108060001080006040001525400123456c0a8010a000000000000c0a80114", "expected_action": "XDP_PASS", "weight": 1.0}]}, "reference_solution": "#include <linux/bpf.h>\n#include <bpf/bpf_helpers.h>\n#include <bpf/bpf_endian.h>\n#include <linux/if_ether.h>\n#include <linux/ip.h>\n#include <linux/in.h>\n#include <linux/tcp.h>\n\nstruct {\n __uint(type, BPF_MAP_TYPE_ARRAY);\n __type(key, __u32);\n __type(value, __u64);\n __uint(max_entries, 4);\n} win_dist_02 SEC(\".maps\");\n\nSEC(\"xdp\")\nint xdp_win_2(struct xdp_md *ctx) {\n void *data_end = (void *)(long)ctx->data_end;\n void *data = (void *)(long)ctx->data;\n\n struct ethhdr *eth = data;\n if ((void *)(eth + 1) > data_end)\n return XDP_PASS;\n if (eth->h_proto != bpf_htons(ETH_P_IP))\n return XDP_PASS;\n\n struct iphdr *ip = (void *)(eth + 1);\n if ((void *)(ip + 1) > data_end)\n return XDP_PASS;\n if (ip->protocol != IPPROTO_TCP)\n return XDP_PASS;\n\n int ip_len = ip->ihl * 4;\n if (ip_len < sizeof(struct iphdr) || (void *)ip + ip_len > data_end)\n return XDP_PASS;\n\n struct tcphdr *tcp = (void *)ip + ip_len;\n if ((void *)(tcp + 1) > data_end)\n return XDP_PASS;\n\n __u16 win = bpf_ntohs(tcp->window);\n __u32 bin = 0;\n if (win < 4096)\n bin = 0;\n else if (win < 16384)\n bin = 1;\n else if (win < 65535)\n bin = 2;\n else\n bin = 3;\n\n __u64 *val = bpf_map_lookup_elem(&win_dist_02, &bin);\n if (val)\n __sync_fetch_and_add(val, 1);\n\n return XDP_PASS;\n}\n\nchar _license[] SEC(\"license\") = \"GPL\";\n"}
{"task_id": "rl_n3_dev_pit_l3_03", "title": "", "description": "", "category": "", "difficulty": "level_3", "level": 1, "requirements": ["Define BPF_MAP_TYPE_ARRAY map 'win_dist_03' with 4 entries and __u64 values", "Verify Ethernet, IPv4, and TCP header bounds against data_end", "Inspect bpf_ntohs(tcp->window) and select bucket: <4k -> 0, <16k -> 1, <65535 -> 2, >=65535 -> 3", "Atomically increment window bucket counter using __sync_fetch_and_add", "Return XDP_PASS unconditionally", "SEC(\"xdp\") entry point and GPL license declaration"], "prompt": "", "expected_fixture_count": 0, "test_cases": {"task_id": "rl_n3_dev_pit_l3_03", "tests": [{"name": "pass_small_win", "description": "Small window in bin 0 passed", "packet_hex": "525400123456525400654321080045000028123400004006e52dc0a8010ac0a8011430390050000003e800000000500203e8f41a0000", "expected_action": "XDP_PASS", "weight": 1.0}, {"name": "pass_large_win", "description": "Large window in bin 3 passed", "packet_hex": "525400123456525400654321080045000028123400004006e52dc0a8010ac0a8011430390050000003e8000000005002fffff8020000", "expected_action": "XDP_PASS", "weight": 1.0}, {"name": "pass_arp", "description": "ARP passed unmodified", "packet_hex": "52540012345652540065432108060001080006040001525400123456c0a8010a000000000000c0a80114", "expected_action": "XDP_PASS", "weight": 1.0}]}, "reference_solution": "#include <linux/bpf.h>\n#include <bpf/bpf_helpers.h>\n#include <bpf/bpf_endian.h>\n#include <linux/if_ether.h>\n#include <linux/ip.h>\n#include <linux/in.h>\n#include <linux/tcp.h>\n\nstruct {\n __uint(type, BPF_MAP_TYPE_ARRAY);\n __type(key, __u32);\n __type(value, __u64);\n __uint(max_entries, 4);\n} win_dist_03 SEC(\".maps\");\n\nSEC(\"xdp\")\nint xdp_win_3(struct xdp_md *ctx) {\n void *data_end = (void *)(long)ctx->data_end;\n void *data = (void *)(long)ctx->data;\n\n struct ethhdr *eth = data;\n if ((void *)(eth + 1) > data_end)\n return XDP_PASS;\n if (eth->h_proto != bpf_htons(ETH_P_IP))\n return XDP_PASS;\n\n struct iphdr *ip = (void *)(eth + 1);\n if ((void *)(ip + 1) > data_end)\n return XDP_PASS;\n if (ip->protocol != IPPROTO_TCP)\n return XDP_PASS;\n\n int ip_len = ip->ihl * 4;\n if (ip_len < sizeof(struct iphdr) || (void *)ip + ip_len > data_end)\n return XDP_PASS;\n\n struct tcphdr *tcp = (void *)ip + ip_len;\n if ((void *)(tcp + 1) > data_end)\n return XDP_PASS;\n\n __u16 win = bpf_ntohs(tcp->window);\n __u32 bin = 0;\n if (win < 4096)\n bin = 0;\n else if (win < 16384)\n bin = 1;\n else if (win < 65535)\n bin = 2;\n else\n bin = 3;\n\n __u64 *val = bpf_map_lookup_elem(&win_dist_03, &bin);\n if (val)\n __sync_fetch_and_add(val, 1);\n\n return XDP_PASS;\n}\n\nchar _license[] SEC(\"license\") = \"GPL\";\n"}
{"task_id": "rl_n3_dev_pit_l3_04", "title": "", "description": "", "category": "", "difficulty": "level_3", "level": 1, "requirements": ["Define BPF_MAP_TYPE_ARRAY map 'win_dist_04' with 4 entries and __u64 values", "Verify Ethernet, IPv4, and TCP header bounds against data_end", "Inspect bpf_ntohs(tcp->window) and select bucket: <4k -> 0, <16k -> 1, <65535 -> 2, >=65535 -> 3", "Atomically increment window bucket counter using __sync_fetch_and_add", "Return XDP_PASS unconditionally", "SEC(\"xdp\") entry point and GPL license declaration"], "prompt": "", "expected_fixture_count": 0, "test_cases": {"task_id": "rl_n3_dev_pit_l3_04", "tests": [{"name": "pass_small_win", "description": "Small window in bin 0 passed", "packet_hex": "525400123456525400654321080045000028123400004006e52dc0a8010ac0a8011430390050000003e800000000500203e8f41a0000", "expected_action": "XDP_PASS", "weight": 1.0}, {"name": "pass_large_win", "description": "Large window in bin 3 passed", "packet_hex": "525400123456525400654321080045000028123400004006e52dc0a8010ac0a8011430390050000003e8000000005002fffff8020000", "expected_action": "XDP_PASS", "weight": 1.0}, {"name": "pass_arp", "description": "ARP passed unmodified", "packet_hex": "52540012345652540065432108060001080006040001525400123456c0a8010a000000000000c0a80114", "expected_action": "XDP_PASS", "weight": 1.0}]}, "reference_solution": "#include <linux/bpf.h>\n#include <bpf/bpf_helpers.h>\n#include <bpf/bpf_endian.h>\n#include <linux/if_ether.h>\n#include <linux/ip.h>\n#include <linux/in.h>\n#include <linux/tcp.h>\n\nstruct {\n __uint(type, BPF_MAP_TYPE_ARRAY);\n __type(key, __u32);\n __type(value, __u64);\n __uint(max_entries, 4);\n} win_dist_04 SEC(\".maps\");\n\nSEC(\"xdp\")\nint xdp_win_4(struct xdp_md *ctx) {\n void *data_end = (void *)(long)ctx->data_end;\n void *data = (void *)(long)ctx->data;\n\n struct ethhdr *eth = data;\n if ((void *)(eth + 1) > data_end)\n return XDP_PASS;\n if (eth->h_proto != bpf_htons(ETH_P_IP))\n return XDP_PASS;\n\n struct iphdr *ip = (void *)(eth + 1);\n if ((void *)(ip + 1) > data_end)\n return XDP_PASS;\n if (ip->protocol != IPPROTO_TCP)\n return XDP_PASS;\n\n int ip_len = ip->ihl * 4;\n if (ip_len < sizeof(struct iphdr) || (void *)ip + ip_len > data_end)\n return XDP_PASS;\n\n struct tcphdr *tcp = (void *)ip + ip_len;\n if ((void *)(tcp + 1) > data_end)\n return XDP_PASS;\n\n __u16 win = bpf_ntohs(tcp->window);\n __u32 bin = 0;\n if (win < 4096)\n bin = 0;\n else if (win < 16384)\n bin = 1;\n else if (win < 65535)\n bin = 2;\n else\n bin = 3;\n\n __u64 *val = bpf_map_lookup_elem(&win_dist_04, &bin);\n if (val)\n __sync_fetch_and_add(val, 1);\n\n return XDP_PASS;\n}\n\nchar _license[] SEC(\"license\") = \"GPL\";\n"}
{"task_id": "rl_n3_dev_ptr_l1_01", "title": "", "description": "", "category": "", "difficulty": "level_1", "level": 1, "requirements": ["Verify Ethernet and IPv4 header bounds against data_end", "Decrement ip->ttl by 1 if ip->ttl > 1", "Recalculate IPv4 header checksum ip->check over all 20 bytes", "Unconditionally return XDP_PASS", "SEC(\"xdp\") entry point and GPL license declaration"], "prompt": "", "expected_fixture_count": 0, "test_cases": {"task_id": "rl_n3_dev_ptr_l1_01", "tests": [{"name": "pass_decremented", "description": "TTL 64 decremented to 63 and passed", "packet_hex": "525400123456525400654321080045000028123400004006e52dc0a8010ac0a8011430390050000003e8000000005002fffff8020000", "expected_action": "XDP_PASS", "weight": 1.0}, {"name": "pass_arp", "description": "Non-IP ARP frame passed without alteration", "packet_hex": "52540012345652540065432108060001080006040001525400123456c0a8010a000000000000c0a80114", "expected_action": "XDP_PASS", "weight": 1.0}]}, "reference_solution": "#include <linux/bpf.h>\n#include <bpf/bpf_helpers.h>\n#include <bpf/bpf_endian.h>\n#include <linux/if_ether.h>\n#include <linux/ip.h>\n\nSEC(\"xdp\")\nint xdp_dec_ttl_1(struct xdp_md *ctx) {\n void *data_end = (void *)(long)ctx->data_end;\n void *data = (void *)(long)ctx->data;\n\n struct ethhdr *eth = data;\n if ((void *)(eth + 1) > data_end)\n return XDP_PASS;\n if (eth->h_proto != bpf_htons(ETH_P_IP))\n return XDP_PASS;\n\n struct iphdr *ip = (void *)(eth + 1);\n if ((void *)(ip + 1) > data_end)\n return XDP_PASS;\n\n if (ip->ttl > 1) {\n ip->ttl -= 1;\n ip->check = 0;\n\n __u16 *words = (void *)ip;\n __u32 csum = 0;\n #pragma unroll\n for (int i = 0; i < 10; i++) {\n if ((void *)(words + i + 1) > data_end)\n return XDP_PASS;\n csum += bpf_ntohs(words[i]);\n }\n while (csum >> 16)\n csum = (csum & 0xFFFF) + (csum >> 16);\n ip->check = bpf_htons((~csum) & 0xFFFF);\n }\n\n return XDP_PASS;\n}\n\nchar _license[] SEC(\"license\") = \"GPL\";\n"}
{"task_id": "rl_n3_dev_ptr_l1_02", "title": "", "description": "", "category": "", "difficulty": "level_1", "level": 1, "requirements": ["Verify Ethernet and IPv4 header bounds against data_end", "Decrement ip->ttl by 1 if ip->ttl > 1", "Recalculate IPv4 header checksum ip->check over all 20 bytes", "Unconditionally return XDP_PASS", "SEC(\"xdp\") entry point and GPL license declaration"], "prompt": "", "expected_fixture_count": 0, "test_cases": {"task_id": "rl_n3_dev_ptr_l1_02", "tests": [{"name": "pass_decremented", "description": "TTL 64 decremented to 63 and passed", "packet_hex": "525400123456525400654321080045000028123400004006e52dc0a8010ac0a8011430390050000003e8000000005002fffff8020000", "expected_action": "XDP_PASS", "weight": 1.0}, {"name": "pass_arp", "description": "Non-IP ARP frame passed without alteration", "packet_hex": "52540012345652540065432108060001080006040001525400123456c0a8010a000000000000c0a80114", "expected_action": "XDP_PASS", "weight": 1.0}]}, "reference_solution": "#include <linux/bpf.h>\n#include <bpf/bpf_helpers.h>\n#include <bpf/bpf_endian.h>\n#include <linux/if_ether.h>\n#include <linux/ip.h>\n\nSEC(\"xdp\")\nint xdp_dec_ttl_2(struct xdp_md *ctx) {\n void *data_end = (void *)(long)ctx->data_end;\n void *data = (void *)(long)ctx->data;\n\n struct ethhdr *eth = data;\n if ((void *)(eth + 1) > data_end)\n return XDP_PASS;\n if (eth->h_proto != bpf_htons(ETH_P_IP))\n return XDP_PASS;\n\n struct iphdr *ip = (void *)(eth + 1);\n if ((void *)(ip + 1) > data_end)\n return XDP_PASS;\n\n if (ip->ttl > 1) {\n ip->ttl -= 1;\n ip->check = 0;\n\n __u16 *words = (void *)ip;\n __u32 csum = 0;\n #pragma unroll\n for (int i = 0; i < 10; i++) {\n if ((void *)(words + i + 1) > data_end)\n return XDP_PASS;\n csum += bpf_ntohs(words[i]);\n }\n while (csum >> 16)\n csum = (csum & 0xFFFF) + (csum >> 16);\n ip->check = bpf_htons((~csum) & 0xFFFF);\n }\n\n return XDP_PASS;\n}\n\nchar _license[] SEC(\"license\") = \"GPL\";\n"}
{"task_id": "rl_n3_dev_ptr_l1_03", "title": "", "description": "", "category": "", "difficulty": "level_1", "level": 1, "requirements": ["Verify Ethernet and IPv4 header bounds against data_end", "Decrement ip->ttl by 1 if ip->ttl > 1", "Recalculate IPv4 header checksum ip->check over all 20 bytes", "Unconditionally return XDP_PASS", "SEC(\"xdp\") entry point and GPL license declaration"], "prompt": "", "expected_fixture_count": 0, "test_cases": {"task_id": "rl_n3_dev_ptr_l1_03", "tests": [{"name": "pass_decremented", "description": "TTL 64 decremented to 63 and passed", "packet_hex": "525400123456525400654321080045000028123400004006e52dc0a8010ac0a8011430390050000003e8000000005002fffff8020000", "expected_action": "XDP_PASS", "weight": 1.0}, {"name": "pass_arp", "description": "Non-IP ARP frame passed without alteration", "packet_hex": "52540012345652540065432108060001080006040001525400123456c0a8010a000000000000c0a80114", "expected_action": "XDP_PASS", "weight": 1.0}]}, "reference_solution": "#include <linux/bpf.h>\n#include <bpf/bpf_helpers.h>\n#include <bpf/bpf_endian.h>\n#include <linux/if_ether.h>\n#include <linux/ip.h>\n\nSEC(\"xdp\")\nint xdp_dec_ttl_3(struct xdp_md *ctx) {\n void *data_end = (void *)(long)ctx->data_end;\n void *data = (void *)(long)ctx->data;\n\n struct ethhdr *eth = data;\n if ((void *)(eth + 1) > data_end)\n return XDP_PASS;\n if (eth->h_proto != bpf_htons(ETH_P_IP))\n return XDP_PASS;\n\n struct iphdr *ip = (void *)(eth + 1);\n if ((void *)(ip + 1) > data_end)\n return XDP_PASS;\n\n if (ip->ttl > 1) {\n ip->ttl -= 1;\n ip->check = 0;\n\n __u16 *words = (void *)ip;\n __u32 csum = 0;\n #pragma unroll\n for (int i = 0; i < 10; i++) {\n if ((void *)(words + i + 1) > data_end)\n return XDP_PASS;\n csum += bpf_ntohs(words[i]);\n }\n while (csum >> 16)\n csum = (csum & 0xFFFF) + (csum >> 16);\n ip->check = bpf_htons((~csum) & 0xFFFF);\n }\n\n return XDP_PASS;\n}\n\nchar _license[] SEC(\"license\") = \"GPL\";\n"}
{"task_id": "rl_n3_dev_ptr_l1_04", "title": "", "description": "", "category": "", "difficulty": "level_1", "level": 1, "requirements": ["Verify Ethernet and IPv4 header bounds against data_end", "Decrement ip->ttl by 1 if ip->ttl > 1", "Recalculate IPv4 header checksum ip->check over all 20 bytes", "Unconditionally return XDP_PASS", "SEC(\"xdp\") entry point and GPL license declaration"], "prompt": "", "expected_fixture_count": 0, "test_cases": {"task_id": "rl_n3_dev_ptr_l1_04", "tests": [{"name": "pass_decremented", "description": "TTL 64 decremented to 63 and passed", "packet_hex": "525400123456525400654321080045000028123400004006e52dc0a8010ac0a8011430390050000003e8000000005002fffff8020000", "expected_action": "XDP_PASS", "weight": 1.0}, {"name": "pass_arp", "description": "Non-IP ARP frame passed without alteration", "packet_hex": "52540012345652540065432108060001080006040001525400123456c0a8010a000000000000c0a80114", "expected_action": "XDP_PASS", "weight": 1.0}]}, "reference_solution": "#include <linux/bpf.h>\n#include <bpf/bpf_helpers.h>\n#include <bpf/bpf_endian.h>\n#include <linux/if_ether.h>\n#include <linux/ip.h>\n\nSEC(\"xdp\")\nint xdp_dec_ttl_4(struct xdp_md *ctx) {\n void *data_end = (void *)(long)ctx->data_end;\n void *data = (void *)(long)ctx->data;\n\n struct ethhdr *eth = data;\n if ((void *)(eth + 1) > data_end)\n return XDP_PASS;\n if (eth->h_proto != bpf_htons(ETH_P_IP))\n return XDP_PASS;\n\n struct iphdr *ip = (void *)(eth + 1);\n if ((void *)(ip + 1) > data_end)\n return XDP_PASS;\n\n if (ip->ttl > 1) {\n ip->ttl -= 1;\n ip->check = 0;\n\n __u16 *words = (void *)ip;\n __u32 csum = 0;\n #pragma unroll\n for (int i = 0; i < 10; i++) {\n if ((void *)(words + i + 1) > data_end)\n return XDP_PASS;\n csum += bpf_ntohs(words[i]);\n }\n while (csum >> 16)\n csum = (csum & 0xFFFF) + (csum >> 16);\n ip->check = bpf_htons((~csum) & 0xFFFF);\n }\n\n return XDP_PASS;\n}\n\nchar _license[] SEC(\"license\") = \"GPL\";\n"}
{"task_id": "rl_n3_dev_ptr_l2_01", "title": "", "description": "", "category": "", "difficulty": "level_2", "level": 1, "requirements": ["Verify Ethernet and 802.1Q header bounds against data_end", "Check if eth->h_proto == ETH_P_8021Q and vlan_id == 100", "Overwrite vlan->h_vlan_TCI in-place preserving priority bits and setting VID to 200", "Return XDP_PASS unconditionally", "SEC(\"xdp\") entry point and GPL license declaration"], "prompt": "", "expected_fixture_count": 0, "test_cases": {"task_id": "rl_n3_dev_ptr_l2_01", "tests": [{"name": "pass_retagged", "description": "VLAN 100 retagged to 200 and passed", "packet_hex": "52540012345652540065432181000064080045000028123400004006e52dc0a8010ac0a8011430390050000003e8000000005002fffff8020000", "expected_action": "XDP_PASS", "weight": 1.0}, {"name": "pass_untagged", "description": "Untagged passed unmodified", "packet_hex": "525400123456525400654321080045000028123400004006e52dc0a8010ac0a8011430390050000003e8000000005002fffff8020000", "expected_action": "XDP_PASS", "weight": 1.0}]}, "reference_solution": "#include <linux/bpf.h>\n#include <bpf/bpf_helpers.h>\n#include <bpf/bpf_endian.h>\n#include <linux/if_ether.h>\n#include <linux/if_vlan.h>\n\nstruct vlan_hdr {\n __be16 h_vlan_TCI;\n __be16 h_vlan_encapsulated_proto;\n};\n\nSEC(\"xdp\")\nint xdp_retag_1(struct xdp_md *ctx) {\n void *data_end = (void *)(long)ctx->data_end;\n void *data = (void *)(long)ctx->data;\n\n struct ethhdr *eth = data;\n if ((void *)(eth + 1) > data_end)\n return XDP_PASS;\n\n if (eth->h_proto == bpf_htons(ETH_P_8021Q)) {\n struct vlan_hdr *vlan = (void *)(eth + 1);\n if ((void *)(vlan + 1) > data_end)\n return XDP_PASS;\n\n __u16 tci = bpf_ntohs(vlan->h_vlan_TCI);\n __u16 vlan_id = tci & 0x0FFF;\n if (vlan_id == 100) {\n __u16 new_tci = (tci & 0xF000) | (200 & 0x0FFF);\n vlan->h_vlan_TCI = bpf_htons(new_tci);\n }\n }\n\n return XDP_PASS;\n}\n\nchar _license[] SEC(\"license\") = \"GPL\";\n"}
{"task_id": "rl_n3_dev_ptr_l2_02", "title": "", "description": "", "category": "", "difficulty": "level_2", "level": 1, "requirements": ["Verify Ethernet and 802.1Q header bounds against data_end", "Check if eth->h_proto == ETH_P_8021Q and vlan_id == 110", "Overwrite vlan->h_vlan_TCI in-place preserving priority bits and setting VID to 210", "Return XDP_PASS unconditionally", "SEC(\"xdp\") entry point and GPL license declaration"], "prompt": "", "expected_fixture_count": 0, "test_cases": {"task_id": "rl_n3_dev_ptr_l2_02", "tests": [{"name": "pass_retagged", "description": "VLAN 110 retagged to 210 and passed", "packet_hex": "5254001234565254006543218100006e080045000028123400004006e52dc0a8010ac0a8011430390050000003e8000000005002fffff8020000", "expected_action": "XDP_PASS", "weight": 1.0}, {"name": "pass_untagged", "description": "Untagged passed unmodified", "packet_hex": "525400123456525400654321080045000028123400004006e52dc0a8010ac0a8011430390050000003e8000000005002fffff8020000", "expected_action": "XDP_PASS", "weight": 1.0}]}, "reference_solution": "#include <linux/bpf.h>\n#include <bpf/bpf_helpers.h>\n#include <bpf/bpf_endian.h>\n#include <linux/if_ether.h>\n#include <linux/if_vlan.h>\n\nstruct vlan_hdr {\n __be16 h_vlan_TCI;\n __be16 h_vlan_encapsulated_proto;\n};\n\nSEC(\"xdp\")\nint xdp_retag_2(struct xdp_md *ctx) {\n void *data_end = (void *)(long)ctx->data_end;\n void *data = (void *)(long)ctx->data;\n\n struct ethhdr *eth = data;\n if ((void *)(eth + 1) > data_end)\n return XDP_PASS;\n\n if (eth->h_proto == bpf_htons(ETH_P_8021Q)) {\n struct vlan_hdr *vlan = (void *)(eth + 1);\n if ((void *)(vlan + 1) > data_end)\n return XDP_PASS;\n\n __u16 tci = bpf_ntohs(vlan->h_vlan_TCI);\n __u16 vlan_id = tci & 0x0FFF;\n if (vlan_id == 110) {\n __u16 new_tci = (tci & 0xF000) | (210 & 0x0FFF);\n vlan->h_vlan_TCI = bpf_htons(new_tci);\n }\n }\n\n return XDP_PASS;\n}\n\nchar _license[] SEC(\"license\") = \"GPL\";\n"}
{"task_id": "rl_n3_dev_ptr_l2_03", "title": "", "description": "", "category": "", "difficulty": "level_2", "level": 1, "requirements": ["Verify Ethernet and 802.1Q header bounds against data_end", "Check if eth->h_proto == ETH_P_8021Q and vlan_id == 120", "Overwrite vlan->h_vlan_TCI in-place preserving priority bits and setting VID to 220", "Return XDP_PASS unconditionally", "SEC(\"xdp\") entry point and GPL license declaration"], "prompt": "", "expected_fixture_count": 0, "test_cases": {"task_id": "rl_n3_dev_ptr_l2_03", "tests": [{"name": "pass_retagged", "description": "VLAN 120 retagged to 220 and passed", "packet_hex": "52540012345652540065432181000078080045000028123400004006e52dc0a8010ac0a8011430390050000003e8000000005002fffff8020000", "expected_action": "XDP_PASS", "weight": 1.0}, {"name": "pass_untagged", "description": "Untagged passed unmodified", "packet_hex": "525400123456525400654321080045000028123400004006e52dc0a8010ac0a8011430390050000003e8000000005002fffff8020000", "expected_action": "XDP_PASS", "weight": 1.0}]}, "reference_solution": "#include <linux/bpf.h>\n#include <bpf/bpf_helpers.h>\n#include <bpf/bpf_endian.h>\n#include <linux/if_ether.h>\n#include <linux/if_vlan.h>\n\nstruct vlan_hdr {\n __be16 h_vlan_TCI;\n __be16 h_vlan_encapsulated_proto;\n};\n\nSEC(\"xdp\")\nint xdp_retag_3(struct xdp_md *ctx) {\n void *data_end = (void *)(long)ctx->data_end;\n void *data = (void *)(long)ctx->data;\n\n struct ethhdr *eth = data;\n if ((void *)(eth + 1) > data_end)\n return XDP_PASS;\n\n if (eth->h_proto == bpf_htons(ETH_P_8021Q)) {\n struct vlan_hdr *vlan = (void *)(eth + 1);\n if ((void *)(vlan + 1) > data_end)\n return XDP_PASS;\n\n __u16 tci = bpf_ntohs(vlan->h_vlan_TCI);\n __u16 vlan_id = tci & 0x0FFF;\n if (vlan_id == 120) {\n __u16 new_tci = (tci & 0xF000) | (220 & 0x0FFF);\n vlan->h_vlan_TCI = bpf_htons(new_tci);\n }\n }\n\n return XDP_PASS;\n}\n\nchar _license[] SEC(\"license\") = \"GPL\";\n"}
{"task_id": "rl_n3_dev_ptr_l2_04", "title": "", "description": "", "category": "", "difficulty": "level_2", "level": 1, "requirements": ["Verify Ethernet and 802.1Q header bounds against data_end", "Check if eth->h_proto == ETH_P_8021Q and vlan_id == 130", "Overwrite vlan->h_vlan_TCI in-place preserving priority bits and setting VID to 230", "Return XDP_PASS unconditionally", "SEC(\"xdp\") entry point and GPL license declaration"], "prompt": "", "expected_fixture_count": 0, "test_cases": {"task_id": "rl_n3_dev_ptr_l2_04", "tests": [{"name": "pass_retagged", "description": "VLAN 130 retagged to 230 and passed", "packet_hex": "52540012345652540065432181000082080045000028123400004006e52dc0a8010ac0a8011430390050000003e8000000005002fffff8020000", "expected_action": "XDP_PASS", "weight": 1.0}, {"name": "pass_untagged", "description": "Untagged passed unmodified", "packet_hex": "525400123456525400654321080045000028123400004006e52dc0a8010ac0a8011430390050000003e8000000005002fffff8020000", "expected_action": "XDP_PASS", "weight": 1.0}]}, "reference_solution": "#include <linux/bpf.h>\n#include <bpf/bpf_helpers.h>\n#include <bpf/bpf_endian.h>\n#include <linux/if_ether.h>\n#include <linux/if_vlan.h>\n\nstruct vlan_hdr {\n __be16 h_vlan_TCI;\n __be16 h_vlan_encapsulated_proto;\n};\n\nSEC(\"xdp\")\nint xdp_retag_4(struct xdp_md *ctx) {\n void *data_end = (void *)(long)ctx->data_end;\n void *data = (void *)(long)ctx->data;\n\n struct ethhdr *eth = data;\n if ((void *)(eth + 1) > data_end)\n return XDP_PASS;\n\n if (eth->h_proto == bpf_htons(ETH_P_8021Q)) {\n struct vlan_hdr *vlan = (void *)(eth + 1);\n if ((void *)(vlan + 1) > data_end)\n return XDP_PASS;\n\n __u16 tci = bpf_ntohs(vlan->h_vlan_TCI);\n __u16 vlan_id = tci & 0x0FFF;\n if (vlan_id == 130) {\n __u16 new_tci = (tci & 0xF000) | (230 & 0x0FFF);\n vlan->h_vlan_TCI = bpf_htons(new_tci);\n }\n }\n\n return XDP_PASS;\n}\n\nchar _license[] SEC(\"license\") = \"GPL\";\n"}
{"task_id": "rl_n3_dev_ptr_l3_01", "title": "", "description": "", "category": "", "difficulty": "level_3", "level": 1, "requirements": ["Verify Ethernet and outer IPv4 header bounds against data_end", "Check if outer_ip->protocol == 41 (IPPROTO_IPV6)", "Calculate variable outer IPv4 header length (outer_ip->ihl * 4)", "Back up Ethernet header and update h_proto to ETH_P_IPV6 (0x86DD)", "Invoke bpf_xdp_adjust_head(ctx, outer_len) and restore updated Ethernet header", "Return XDP_PASS unconditionally", "SEC(\"xdp\") entry point and GPL license declaration"], "prompt": "", "expected_fixture_count": 0, "test_cases": {"task_id": "rl_n3_dev_ptr_l3_01", "tests": [{"name": "pass_decap_6in4", "description": "6in4 tunnel packet decapsulated and passed", "packet_hex": "52540012345652540065432108004500005012340000402951b90a4d01010a4d00fe600000000014064020010db800000000000000000000000120010db800000000000000000000000230390050000003e8000000005002fffff8020000", "expected_action": "XDP_PASS", "weight": 1.0}, {"name": "pass_normal_tcp", "description": "Normal non-tunneled TCP passed unmodified", "packet_hex": "525400123456525400654321080045000028123400004006e52dc0a8010ac0a8011430390050000003e8000000005002fffff8020000", "expected_action": "XDP_PASS", "weight": 1.0}]}, "reference_solution": "#include <linux/bpf.h>\n#include <bpf/bpf_helpers.h>\n#include <bpf/bpf_endian.h>\n#include <linux/if_ether.h>\n#include <linux/ip.h>\n\nSEC(\"xdp\")\nint xdp_decap_6in4_1(struct xdp_md *ctx) {\n void *data_end = (void *)(long)ctx->data_end;\n void *data = (void *)(long)ctx->data;\n\n struct ethhdr *eth = data;\n if ((void *)(eth + 1) > data_end)\n return XDP_PASS;\n if (eth->h_proto != bpf_htons(ETH_P_IP))\n return XDP_PASS;\n\n struct iphdr *outer_ip = (void *)(eth + 1);\n if ((void *)(outer_ip + 1) > data_end)\n return XDP_PASS;\n\n if (outer_ip->protocol == 41) {\n int outer_len = outer_ip->ihl * 4;\n if (outer_len < sizeof(struct iphdr) || (void *)outer_ip + outer_len > data_end)\n return XDP_PASS;\n\n struct ethhdr eth_backup;\n __builtin_memcpy(&eth_backup, eth, sizeof(struct ethhdr));\n eth_backup.h_proto = bpf_htons(ETH_P_IPV6);\n\n if (bpf_xdp_adjust_head(ctx, outer_len))\n return XDP_DROP;\n\n data = (void *)(long)ctx->data;\n data_end = (void *)(long)ctx->data_end;\n eth = data;\n if ((void *)(eth + 1) > data_end)\n return XDP_DROP;\n\n __builtin_memcpy(eth, &eth_backup, sizeof(struct ethhdr));\n }\n\n return XDP_PASS;\n}\n\nchar _license[] SEC(\"license\") = \"GPL\";\n"}
{"task_id": "rl_n3_dev_ptr_l3_02", "title": "", "description": "", "category": "", "difficulty": "level_3", "level": 1, "requirements": ["Verify Ethernet and outer IPv4 header bounds against data_end", "Check if outer_ip->protocol == 41 (IPPROTO_IPV6)", "Calculate variable outer IPv4 header length (outer_ip->ihl * 4)", "Back up Ethernet header and update h_proto to ETH_P_IPV6 (0x86DD)", "Invoke bpf_xdp_adjust_head(ctx, outer_len) and restore updated Ethernet header", "Return XDP_PASS unconditionally", "SEC(\"xdp\") entry point and GPL license declaration"], "prompt": "", "expected_fixture_count": 0, "test_cases": {"task_id": "rl_n3_dev_ptr_l3_02", "tests": [{"name": "pass_decap_6in4", "description": "6in4 tunnel packet decapsulated and passed", "packet_hex": "52540012345652540065432108004500005012340000402950b90a4d02010a4d00fe600000000014064020010db800000000000000000000000120010db800000000000000000000000230390050000003e8000000005002fffff8020000", "expected_action": "XDP_PASS", "weight": 1.0}, {"name": "pass_normal_tcp", "description": "Normal non-tunneled TCP passed unmodified", "packet_hex": "525400123456525400654321080045000028123400004006e52dc0a8010ac0a8011430390050000003e8000000005002fffff8020000", "expected_action": "XDP_PASS", "weight": 1.0}]}, "reference_solution": "#include <linux/bpf.h>\n#include <bpf/bpf_helpers.h>\n#include <bpf/bpf_endian.h>\n#include <linux/if_ether.h>\n#include <linux/ip.h>\n\nSEC(\"xdp\")\nint xdp_decap_6in4_2(struct xdp_md *ctx) {\n void *data_end = (void *)(long)ctx->data_end;\n void *data = (void *)(long)ctx->data;\n\n struct ethhdr *eth = data;\n if ((void *)(eth + 1) > data_end)\n return XDP_PASS;\n if (eth->h_proto != bpf_htons(ETH_P_IP))\n return XDP_PASS;\n\n struct iphdr *outer_ip = (void *)(eth + 1);\n if ((void *)(outer_ip + 1) > data_end)\n return XDP_PASS;\n\n if (outer_ip->protocol == 41) {\n int outer_len = outer_ip->ihl * 4;\n if (outer_len < sizeof(struct iphdr) || (void *)outer_ip + outer_len > data_end)\n return XDP_PASS;\n\n struct ethhdr eth_backup;\n __builtin_memcpy(&eth_backup, eth, sizeof(struct ethhdr));\n eth_backup.h_proto = bpf_htons(ETH_P_IPV6);\n\n if (bpf_xdp_adjust_head(ctx, outer_len))\n return XDP_DROP;\n\n data = (void *)(long)ctx->data;\n data_end = (void *)(long)ctx->data_end;\n eth = data;\n if ((void *)(eth + 1) > data_end)\n return XDP_DROP;\n\n __builtin_memcpy(eth, &eth_backup, sizeof(struct ethhdr));\n }\n\n return XDP_PASS;\n}\n\nchar _license[] SEC(\"license\") = \"GPL\";\n"}
{"task_id": "rl_n3_dev_ptr_l3_03", "title": "", "description": "", "category": "", "difficulty": "level_3", "level": 1, "requirements": ["Verify Ethernet and outer IPv4 header bounds against data_end", "Check if outer_ip->protocol == 41 (IPPROTO_IPV6)", "Calculate variable outer IPv4 header length (outer_ip->ihl * 4)", "Back up Ethernet header and update h_proto to ETH_P_IPV6 (0x86DD)", "Invoke bpf_xdp_adjust_head(ctx, outer_len) and restore updated Ethernet header", "Return XDP_PASS unconditionally", "SEC(\"xdp\") entry point and GPL license declaration"], "prompt": "", "expected_fixture_count": 0, "test_cases": {"task_id": "rl_n3_dev_ptr_l3_03", "tests": [{"name": "pass_decap_6in4", "description": "6in4 tunnel packet decapsulated and passed", "packet_hex": "5254001234565254006543210800450000501234000040294fb90a4d03010a4d00fe600000000014064020010db800000000000000000000000120010db800000000000000000000000230390050000003e8000000005002fffff8020000", "expected_action": "XDP_PASS", "weight": 1.0}, {"name": "pass_normal_tcp", "description": "Normal non-tunneled TCP passed unmodified", "packet_hex": "525400123456525400654321080045000028123400004006e52dc0a8010ac0a8011430390050000003e8000000005002fffff8020000", "expected_action": "XDP_PASS", "weight": 1.0}]}, "reference_solution": "#include <linux/bpf.h>\n#include <bpf/bpf_helpers.h>\n#include <bpf/bpf_endian.h>\n#include <linux/if_ether.h>\n#include <linux/ip.h>\n\nSEC(\"xdp\")\nint xdp_decap_6in4_3(struct xdp_md *ctx) {\n void *data_end = (void *)(long)ctx->data_end;\n void *data = (void *)(long)ctx->data;\n\n struct ethhdr *eth = data;\n if ((void *)(eth + 1) > data_end)\n return XDP_PASS;\n if (eth->h_proto != bpf_htons(ETH_P_IP))\n return XDP_PASS;\n\n struct iphdr *outer_ip = (void *)(eth + 1);\n if ((void *)(outer_ip + 1) > data_end)\n return XDP_PASS;\n\n if (outer_ip->protocol == 41) {\n int outer_len = outer_ip->ihl * 4;\n if (outer_len < sizeof(struct iphdr) || (void *)outer_ip + outer_len > data_end)\n return XDP_PASS;\n\n struct ethhdr eth_backup;\n __builtin_memcpy(&eth_backup, eth, sizeof(struct ethhdr));\n eth_backup.h_proto = bpf_htons(ETH_P_IPV6);\n\n if (bpf_xdp_adjust_head(ctx, outer_len))\n return XDP_DROP;\n\n data = (void *)(long)ctx->data;\n data_end = (void *)(long)ctx->data_end;\n eth = data;\n if ((void *)(eth + 1) > data_end)\n return XDP_DROP;\n\n __builtin_memcpy(eth, &eth_backup, sizeof(struct ethhdr));\n }\n\n return XDP_PASS;\n}\n\nchar _license[] SEC(\"license\") = \"GPL\";\n"}
{"task_id": "rl_n3_dev_ptr_l3_04", "title": "", "description": "", "category": "", "difficulty": "level_3", "level": 1, "requirements": ["Verify Ethernet and outer IPv4 header bounds against data_end", "Check if outer_ip->protocol == 41 (IPPROTO_IPV6)", "Calculate variable outer IPv4 header length (outer_ip->ihl * 4)", "Back up Ethernet header and update h_proto to ETH_P_IPV6 (0x86DD)", "Invoke bpf_xdp_adjust_head(ctx, outer_len) and restore updated Ethernet header", "Return XDP_PASS unconditionally", "SEC(\"xdp\") entry point and GPL license declaration"], "prompt": "", "expected_fixture_count": 0, "test_cases": {"task_id": "rl_n3_dev_ptr_l3_04", "tests": [{"name": "pass_decap_6in4", "description": "6in4 tunnel packet decapsulated and passed", "packet_hex": "5254001234565254006543210800450000501234000040294eb90a4d04010a4d00fe600000000014064020010db800000000000000000000000120010db800000000000000000000000230390050000003e8000000005002fffff8020000", "expected_action": "XDP_PASS", "weight": 1.0}, {"name": "pass_normal_tcp", "description": "Normal non-tunneled TCP passed unmodified", "packet_hex": "525400123456525400654321080045000028123400004006e52dc0a8010ac0a8011430390050000003e8000000005002fffff8020000", "expected_action": "XDP_PASS", "weight": 1.0}]}, "reference_solution": "#include <linux/bpf.h>\n#include <bpf/bpf_helpers.h>\n#include <bpf/bpf_endian.h>\n#include <linux/if_ether.h>\n#include <linux/ip.h>\n\nSEC(\"xdp\")\nint xdp_decap_6in4_4(struct xdp_md *ctx) {\n void *data_end = (void *)(long)ctx->data_end;\n void *data = (void *)(long)ctx->data;\n\n struct ethhdr *eth = data;\n if ((void *)(eth + 1) > data_end)\n return XDP_PASS;\n if (eth->h_proto != bpf_htons(ETH_P_IP))\n return XDP_PASS;\n\n struct iphdr *outer_ip = (void *)(eth + 1);\n if ((void *)(outer_ip + 1) > data_end)\n return XDP_PASS;\n\n if (outer_ip->protocol == 41) {\n int outer_len = outer_ip->ihl * 4;\n if (outer_len < sizeof(struct iphdr) || (void *)outer_ip + outer_len > data_end)\n return XDP_PASS;\n\n struct ethhdr eth_backup;\n __builtin_memcpy(&eth_backup, eth, sizeof(struct ethhdr));\n eth_backup.h_proto = bpf_htons(ETH_P_IPV6);\n\n if (bpf_xdp_adjust_head(ctx, outer_len))\n return XDP_DROP;\n\n data = (void *)(long)ctx->data;\n data_end = (void *)(long)ctx->data_end;\n eth = data;\n if ((void *)(eth + 1) > data_end)\n return XDP_DROP;\n\n __builtin_memcpy(eth, &eth_backup, sizeof(struct ethhdr));\n }\n\n return XDP_PASS;\n}\n\nchar _license[] SEC(\"license\") = \"GPL\";\n"}