15ecd8c22SAndrey Ignatov#!/bin/sh 25ecd8c22SAndrey Ignatov# SPDX-License-Identifier: GPL-2.0 35ecd8c22SAndrey Ignatov# Copyright (c) 2018 Facebook 45ecd8c22SAndrey Ignatov 55ecd8c22SAndrey Ignatovset -eu 65ecd8c22SAndrey Ignatov 75ecd8c22SAndrey Ignatovwait_for_ip() 85ecd8c22SAndrey Ignatov{ 95ecd8c22SAndrey Ignatov local _i 105ecd8c22SAndrey Ignatov echo -n "Wait for testing link-local IP to become available " 115ecd8c22SAndrey Ignatov for _i in $(seq ${MAX_PING_TRIES}); do 125ecd8c22SAndrey Ignatov echo -n "." 13deee2caeSLi Zhijian if $PING6 -c 1 -W 1 ff02::1%${TEST_IF} >/dev/null 2>&1; then 145ecd8c22SAndrey Ignatov echo " OK" 155ecd8c22SAndrey Ignatov return 165ecd8c22SAndrey Ignatov fi 175ecd8c22SAndrey Ignatov sleep 1 185ecd8c22SAndrey Ignatov done 195ecd8c22SAndrey Ignatov echo 1>&2 "ERROR: Timeout waiting for test IP to become available." 205ecd8c22SAndrey Ignatov exit 1 215ecd8c22SAndrey Ignatov} 225ecd8c22SAndrey Ignatov 235ecd8c22SAndrey Ignatovsetup() 245ecd8c22SAndrey Ignatov{ 255ecd8c22SAndrey Ignatov # Create testing interfaces not to interfere with current environment. 265ecd8c22SAndrey Ignatov ip link add dev ${TEST_IF} type veth peer name ${TEST_IF_PEER} 275ecd8c22SAndrey Ignatov ip link set ${TEST_IF} up 285ecd8c22SAndrey Ignatov ip link set ${TEST_IF_PEER} up 295ecd8c22SAndrey Ignatov 305ecd8c22SAndrey Ignatov wait_for_ip 315ecd8c22SAndrey Ignatov 325ecd8c22SAndrey Ignatov tc qdisc add dev ${TEST_IF} clsact 335ecd8c22SAndrey Ignatov tc filter add dev ${TEST_IF} egress bpf obj ${BPF_PROG_OBJ} \ 345ecd8c22SAndrey Ignatov sec ${BPF_PROG_SECTION} da 355ecd8c22SAndrey Ignatov 365ecd8c22SAndrey Ignatov BPF_PROG_ID=$(tc filter show dev ${TEST_IF} egress | \ 375ecd8c22SAndrey Ignatov awk '/ id / {sub(/.* id /, "", $0); print($1)}') 385ecd8c22SAndrey Ignatov} 395ecd8c22SAndrey Ignatov 405ecd8c22SAndrey Ignatovcleanup() 415ecd8c22SAndrey Ignatov{ 425ecd8c22SAndrey Ignatov ip link del ${TEST_IF} 2>/dev/null || : 435ecd8c22SAndrey Ignatov ip link del ${TEST_IF_PEER} 2>/dev/null || : 445ecd8c22SAndrey Ignatov} 455ecd8c22SAndrey Ignatov 465ecd8c22SAndrey Ignatovmain() 475ecd8c22SAndrey Ignatov{ 485ecd8c22SAndrey Ignatov trap cleanup EXIT 2 3 6 15 495ecd8c22SAndrey Ignatov setup 505ecd8c22SAndrey Ignatov ${PROG} ${TEST_IF} ${BPF_PROG_ID} 515ecd8c22SAndrey Ignatov} 525ecd8c22SAndrey Ignatov 535ecd8c22SAndrey IgnatovDIR=$(dirname $0) 545ecd8c22SAndrey IgnatovTEST_IF="test_cgid_1" 555ecd8c22SAndrey IgnatovTEST_IF_PEER="test_cgid_2" 565ecd8c22SAndrey IgnatovMAX_PING_TRIES=5 57*afef88e6SDaniel MüllerBPF_PROG_OBJ="${DIR}/test_skb_cgroup_id_kern.bpf.o" 585ecd8c22SAndrey IgnatovBPF_PROG_SECTION="cgroup_id_logger" 595ecd8c22SAndrey IgnatovBPF_PROG_ID=0 605ecd8c22SAndrey IgnatovPROG="${DIR}/test_skb_cgroup_id_user" 61deee2caeSLi Zhijiantype ping6 >/dev/null 2>&1 && PING6="ping6" || PING6="ping -6" 625ecd8c22SAndrey Ignatov 635ecd8c22SAndrey Ignatovmain 64