1#!/bin/sh 2# SPDX-License-Identifier: GPL-2.0-or-later 3# Copyright (c) 2019-2020 Petr Vorel <pvorel@suse.cz> 4 5TST_NEEDS_ROOT=1 6TST_NEEDS_CMDS="ip" 7. tst_net.sh 8 9ROUTE_RHOST_PORT=${ROUTE_RHOST_PORT:-65535} 10ROUTE_MAX_IP=${ROUTE_MAX_IP:-5} 11 12IP_ADDR_DELIM=',' 13 14add_macvlan() 15{ 16 local action="add" 17 local OPTIND 18 while getopts d opt; do 19 case "$opt" in 20 d) action="del";; 21 esac 22 done 23 shift $((OPTIND - 1)) 24 25 local iface="$1" 26 local type="${2:-lhost}" 27 28 cmd="ip link $action $iface link $(tst_iface $type) type macvlan mode bridge" 29 if [ $type = "lhost" ]; then 30 ROD $cmd 31 [ "$action" = "add" ] || return 32 LHOST_IFACES="$LHOST_IFACES $iface" 33 else 34 tst_rhost_run -s -c "$cmd" 35 [ "$action" = "add" ] || return 36 RHOST_IFACES="$RHOST_IFACES $iface" 37 fi 38 tst_init_iface $type 1 39} 40 41check_max_ip() 42{ 43 local max_ip_limit=254 44 [ "$TST_IPV6" ] && max_ip_limit=65534 45 46 tst_is_int "$ROUTE_MAX_IP" || tst_brk TBROK "\$ROUTE_MAX_IP not int ($ROUTE_MAX_IP)" 47 [ $ROUTE_MAX_IP -gt $max_ip_limit ] && ROUTE_MAX_IP=$max_ip_limit 48 [ $ROUTE_MAX_IP -gt $ROUTE_CHANGE_NETLINK ] && ROUTE_MAX_IP=$ROUTE_CHANGE_NETLINK 49} 50 51cleanup_if() 52{ 53 [ "$new_liface" ] && add_macvlan -d $new_liface 54 [ "$new_riface" ] && add_macvlan -d $new_riface rhost 55 route_cleanup 56} 57 58route_cleanup() 59{ 60 tst_restore_ipaddr 61 tst_restore_ipaddr rhost 62} 63 64setup_gw() 65{ 66 rt="$(tst_ipaddr_un -p 0 0)" 67 lhost="$(tst_ipaddr_un 1 1)" 68 rhost="$(tst_ipaddr_un 0 1)" 69 tst_add_ipaddr -s -q -a $lhost 70 tst_add_ipaddr -s -q -a $rhost rhost 71} 72 73setup_if() 74{ 75 rt="$(tst_ipaddr_un -p 0)" 76 rhost="$(tst_ipaddr_un 0 1)" 77 tst_add_ipaddr -s -q -a $rhost rhost 78 79 if [ $(tst_get_ifaces_cnt) -lt 2 ]; then 80 new_liface="ltp_mv2" 81 tst_res TINFO "2 or more local ifaces required, adding '$new_liface'" 82 add_macvlan $new_liface 83 fi 84 85 if [ $(tst_get_ifaces_cnt rhost) -lt 2 ]; then 86 new_riface="ltp_mv1" 87 tst_res TINFO "2 or more remote ifaces required, adding '$new_riface'" 88 add_macvlan $new_riface rhost 89 fi 90} 91 92test_netlink() 93{ 94 local opt="-c $ROUTE_CHANGE_NETLINK $TST_IPV6_FLAG -p $ROUTE_RHOST_PORT $ROUTE_CHANGE_NETLINK_PARAMS" 95 local cmd="route-change-netlink" 96 local ret=0 97 98 tst_res TINFO "running $cmd $opt" 99 $cmd $opt || ret=$? 100 if [ "$ret" -ne 0 ]; then 101 [ $((ret & 3)) -ne 0 ] && \ 102 tst_brk TFAIL "$cmd failed" 103 [ $((ret & 32)) -ne 0 ] && \ 104 tst_brk TCONF "not supported configuration" 105 [ $((ret & 4)) -ne 0 ] && \ 106 tst_res TWARN "$cmd has warnings" 107 fi 108 tst_res TPASS "$cmd passed" 109} 110