Home | History | Annotate | Line # | Download | only in net
net_common.sh revision 1.3
      1  1.3  ozaki #	$NetBSD: net_common.sh,v 1.3 2016/11/24 09:05:16 ozaki-r Exp $
      2  1.1  ozaki #
      3  1.1  ozaki # Copyright (c) 2016 Internet Initiative Japan Inc.
      4  1.1  ozaki # All rights reserved.
      5  1.1  ozaki #
      6  1.1  ozaki # Redistribution and use in source and binary forms, with or without
      7  1.1  ozaki # modification, are permitted provided that the following conditions
      8  1.1  ozaki # are met:
      9  1.1  ozaki # 1. Redistributions of source code must retain the above copyright
     10  1.1  ozaki #    notice, this list of conditions and the following disclaimer.
     11  1.1  ozaki # 2. Redistributions in binary form must reproduce the above copyright
     12  1.1  ozaki #    notice, this list of conditions and the following disclaimer in the
     13  1.1  ozaki #    documentation and/or other materials provided with the distribution.
     14  1.1  ozaki #
     15  1.1  ozaki # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     16  1.1  ozaki # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     17  1.1  ozaki # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     18  1.1  ozaki # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     19  1.1  ozaki # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     20  1.1  ozaki # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     21  1.1  ozaki # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     22  1.1  ozaki # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     23  1.1  ozaki # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     24  1.1  ozaki # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     25  1.1  ozaki # POSSIBILITY OF SUCH DAMAGE.
     26  1.1  ozaki #
     27  1.1  ozaki 
     28  1.1  ozaki #
     29  1.1  ozaki # Common utility functions for tests/net
     30  1.1  ozaki #
     31  1.1  ozaki 
     32  1.2  ozaki HIJACKING="env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=sysctl=yes"
     33  1.2  ozaki 
     34  1.1  ozaki extract_new_packets()
     35  1.1  ozaki {
     36  1.1  ozaki 	local bus=$1
     37  1.1  ozaki 	local old=./.__old
     38  1.1  ozaki 
     39  1.1  ozaki 	if [ ! -f $old ]; then
     40  1.1  ozaki 		old=/dev/null
     41  1.1  ozaki 	fi
     42  1.1  ozaki 
     43  1.1  ozaki 	shmif_dumpbus -p - $bus 2>/dev/null| \
     44  1.1  ozaki 	    tcpdump -n -e -r - 2>/dev/null > ./.__new
     45  1.1  ozaki 	diff -u $old ./.__new |grep '^+' |cut -d '+' -f 2 > ./.__diff
     46  1.1  ozaki 	mv -f ./.__new ./.__old
     47  1.1  ozaki 	cat ./.__diff
     48  1.1  ozaki }
     49  1.1  ozaki 
     50  1.3  ozaki check_route()
     51  1.3  ozaki {
     52  1.3  ozaki 	local target=$1
     53  1.3  ozaki 	local gw=$2
     54  1.3  ozaki 	local flags=${3:-\.\+}
     55  1.3  ozaki 	local ifname=${4:-\.\+}
     56  1.3  ozaki 
     57  1.3  ozaki 	target=$(echo $target |sed 's/\./\\./g')
     58  1.3  ozaki 	if [ "$gw" = "" ]; then
     59  1.3  ozaki 		gw=".+"
     60  1.3  ozaki 	else
     61  1.3  ozaki 		gw=$(echo $gw |sed 's/\./\\./g')
     62  1.3  ozaki 	fi
     63  1.3  ozaki 
     64  1.3  ozaki 	atf_check -s exit:0 -e ignore \
     65  1.3  ozaki 	    -o match:"^$target +$gw +$flags +- +- +.+ +$ifname" \
     66  1.3  ozaki 	    rump.netstat -rn
     67  1.3  ozaki }
     68  1.3  ozaki 
     69  1.3  ozaki check_route_flags()
     70  1.3  ozaki {
     71  1.3  ozaki 
     72  1.3  ozaki 	check_route "$1" "" "$2" ""
     73  1.3  ozaki }
     74  1.3  ozaki 
     75  1.3  ozaki check_route_gw()
     76  1.3  ozaki {
     77  1.3  ozaki 
     78  1.3  ozaki 	check_route "$1" "$2" "" ""
     79  1.3  ozaki }
     80  1.3  ozaki 
     81  1.3  ozaki check_route_no_entry()
     82  1.3  ozaki {
     83  1.3  ozaki 	local target=$(echo $1 |sed 's/\./\\./g')
     84  1.3  ozaki 
     85  1.3  ozaki 	atf_check -s exit:0 -e ignore -o not-match:"^$target" \
     86  1.3  ozaki 	    rump.netstat -rn
     87  1.3  ozaki }
     88