mirror of
https://github.com/raspberrypi/linux.git
synced 2025-12-15 22:41:38 +00:00
Extend the netkit selftests to specify and validate the {head,tail}room
on the netdevice:
# ./vmtest.sh -- ./test_progs -t netkit
[...]
./test_progs -t netkit
[ 1.174147] bpf_testmod: loading out-of-tree module taints kernel.
[ 1.174585] bpf_testmod: module verification failed: signature and/or required key missing - tainting kernel
[ 1.422307] tsc: Refined TSC clocksource calibration: 3407.983 MHz
[ 1.424511] clocksource: tsc: mask: 0xffffffffffffffff max_cycles: 0x311fc3e5084, max_idle_ns: 440795359833 ns
[ 1.428092] clocksource: Switched to clocksource tsc
#363 tc_netkit_basic:OK
#364 tc_netkit_device:OK
#365 tc_netkit_multi_links:OK
#366 tc_netkit_multi_opts:OK
#367 tc_netkit_neigh_links:OK
#368 tc_netkit_pkt_type:OK
#369 tc_netkit_scrub:OK
Summary: 7/0 PASSED, 0 SKIPPED, 0 FAILED
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Nikolay Aleksandrov <razor@blackwall.org>
Link: https://lore.kernel.org/bpf/20241220234658.490686-3-daniel@iogearbox.net
130 lines
2.3 KiB
C
130 lines
2.3 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/* Copyright (c) 2023 Isovalent */
|
|
#include <stdbool.h>
|
|
|
|
#include <linux/bpf.h>
|
|
#include <linux/if_ether.h>
|
|
#include <linux/stddef.h>
|
|
#include <linux/if_packet.h>
|
|
#include <bpf/bpf_endian.h>
|
|
#include <bpf/bpf_helpers.h>
|
|
#include <bpf/bpf_core_read.h>
|
|
|
|
char LICENSE[] SEC("license") = "GPL";
|
|
|
|
bool seen_tc1;
|
|
bool seen_tc2;
|
|
bool seen_tc3;
|
|
bool seen_tc4;
|
|
bool seen_tc5;
|
|
bool seen_tc6;
|
|
bool seen_tc7;
|
|
bool seen_tc8;
|
|
|
|
bool set_type;
|
|
|
|
bool seen_eth;
|
|
bool seen_host;
|
|
bool seen_mcast;
|
|
|
|
int mark, prio;
|
|
unsigned short headroom, tailroom;
|
|
|
|
SEC("tc/ingress")
|
|
int tc1(struct __sk_buff *skb)
|
|
{
|
|
struct ethhdr eth = {};
|
|
|
|
if (skb->protocol != __bpf_constant_htons(ETH_P_IP))
|
|
goto out;
|
|
if (bpf_skb_load_bytes(skb, 0, ð, sizeof(eth)))
|
|
goto out;
|
|
seen_eth = eth.h_proto == bpf_htons(ETH_P_IP);
|
|
seen_host = skb->pkt_type == PACKET_HOST;
|
|
if (seen_host && set_type) {
|
|
eth.h_dest[0] = 4;
|
|
if (bpf_skb_store_bytes(skb, 0, ð, sizeof(eth), 0))
|
|
goto fail;
|
|
bpf_skb_change_type(skb, PACKET_MULTICAST);
|
|
}
|
|
out:
|
|
seen_tc1 = true;
|
|
fail:
|
|
return TCX_NEXT;
|
|
}
|
|
|
|
SEC("tc/egress")
|
|
int tc2(struct __sk_buff *skb)
|
|
{
|
|
seen_tc2 = true;
|
|
return TCX_NEXT;
|
|
}
|
|
|
|
SEC("tc/egress")
|
|
int tc3(struct __sk_buff *skb)
|
|
{
|
|
seen_tc3 = true;
|
|
return TCX_NEXT;
|
|
}
|
|
|
|
SEC("tc/egress")
|
|
int tc4(struct __sk_buff *skb)
|
|
{
|
|
seen_tc4 = true;
|
|
return TCX_NEXT;
|
|
}
|
|
|
|
SEC("tc/egress")
|
|
int tc5(struct __sk_buff *skb)
|
|
{
|
|
seen_tc5 = true;
|
|
return TCX_PASS;
|
|
}
|
|
|
|
SEC("tc/egress")
|
|
int tc6(struct __sk_buff *skb)
|
|
{
|
|
seen_tc6 = true;
|
|
return TCX_PASS;
|
|
}
|
|
|
|
SEC("tc/ingress")
|
|
int tc7(struct __sk_buff *skb)
|
|
{
|
|
struct ethhdr eth = {};
|
|
|
|
if (skb->protocol != __bpf_constant_htons(ETH_P_IP))
|
|
goto out;
|
|
if (bpf_skb_load_bytes(skb, 0, ð, sizeof(eth)))
|
|
goto out;
|
|
if (eth.h_dest[0] == 4 && set_type) {
|
|
seen_mcast = skb->pkt_type == PACKET_MULTICAST;
|
|
bpf_skb_change_type(skb, PACKET_HOST);
|
|
}
|
|
out:
|
|
seen_tc7 = true;
|
|
return TCX_PASS;
|
|
}
|
|
|
|
struct sk_buff {
|
|
struct net_device *dev;
|
|
};
|
|
|
|
struct net_device {
|
|
unsigned short needed_headroom;
|
|
unsigned short needed_tailroom;
|
|
};
|
|
|
|
SEC("tc/egress")
|
|
int tc8(struct __sk_buff *skb)
|
|
{
|
|
struct net_device *dev = BPF_CORE_READ((struct sk_buff *)skb, dev);
|
|
|
|
seen_tc8 = true;
|
|
mark = skb->mark;
|
|
prio = skb->priority;
|
|
headroom = BPF_CORE_READ(dev, needed_headroom);
|
|
tailroom = BPF_CORE_READ(dev, needed_tailroom);
|
|
return TCX_PASS;
|
|
}
|