brintos

brintos / linux-shallow public Read only

0
0
Text · 1.9 KiB · 82acff9 Raw
104 lines · bash
1#!/bin/bash2# SPDX-License-Identifier: GPL-2.03 4BPFFS=/sys/fs/bpf5MY_DIR=$(dirname $0)6TEST=$MY_DIR/test_cgrp2_sock27LINK_PIN=$BPFFS/test_cgrp2_sock28BPF_PROG=$MY_DIR/sock_flags.bpf.o9 10function config_device {11	ip netns add at_ns012	ip link add veth0 type veth peer name veth0b13	ip link set veth0 netns at_ns014	ip netns exec at_ns0 sysctl -q net.ipv6.conf.veth0.disable_ipv6=015	ip netns exec at_ns0 ip addr add 172.16.1.100/24 dev veth016	ip netns exec at_ns0 ip addr add 2401:db00::1/64 dev veth0 nodad17	ip netns exec at_ns0 ip link set dev veth0 up18	sysctl -q net.ipv6.conf.veth0b.disable_ipv6=019	ip addr add 172.16.1.101/24 dev veth0b20	ip addr add 2401:db00::2/64 dev veth0b nodad21	ip link set veth0b up22}23 24function config_cgroup {25	rm -rf /tmp/cgroupv226	mkdir -p /tmp/cgroupv227	mount -t cgroup2 none /tmp/cgroupv228	mkdir -p /tmp/cgroupv2/foo29	echo $$ >> /tmp/cgroupv2/foo/cgroup.procs30}31 32function config_bpffs {33	if mount | grep $BPFFS > /dev/null; then34		echo "bpffs already mounted"35	else36		echo "bpffs not mounted. Mounting..."37		mount -t bpf none $BPFFS38	fi39}40 41function attach_bpf {42	$TEST /tmp/cgroupv2/foo $BPF_PROG $143	[ $? -ne 0 ] && exit 144}45 46function cleanup {47	rm -rf $LINK_PIN48	ip link del veth0b49	ip netns delete at_ns050	umount /tmp/cgroupv251	rm -rf /tmp/cgroupv252}53 54cleanup 2>/dev/null55 56set -e57config_device58config_cgroup59config_bpffs60set +e61 62#63# Test 1 - fail ping664#65attach_bpf 066ping -c1 -w1 172.16.1.10067if [ $? -ne 0 ]; then68	echo "ping failed when it should succeed"69	cleanup70	exit 171fi72 73ping6 -c1 -w1 2401:db00::174if [ $? -eq 0 ]; then75	echo "ping6 succeeded when it should not"76	cleanup77	exit 178fi79 80rm -rf $LINK_PIN81sleep 1                 # Wait for link detach82 83#84# Test 2 - fail ping85#86attach_bpf 187ping6 -c1 -w1 2401:db00::188if [ $? -ne 0 ]; then89	echo "ping6 failed when it should succeed"90	cleanup91	exit 192fi93 94ping -c1 -w1 172.16.1.10095if [ $? -eq 0 ]; then96	echo "ping succeeded when it should not"97	cleanup98	exit 199fi100 101cleanup102echo103echo "*** PASS ***"104