xref: /freebsd/tools/regression/net/if_tap/test-tap.sh (revision d0b2dbfa0ecf2bbc9709efc5e20baf8e4b44bbbf)
1*8fa4106eSEd Maste#!/bin/sh
2*8fa4106eSEd Maste
3*8fa4106eSEd Maste# Copyright (C) 2012 ADARA Networks.  All rights reserved.
4*8fa4106eSEd Maste#
5*8fa4106eSEd Maste# Redistribution and use in source and binary forms, with or without
6*8fa4106eSEd Maste# modification, are permitted provided that the following conditions
7*8fa4106eSEd Maste# are met:
8*8fa4106eSEd Maste# 1. Redistributions of source code must retain the above copyright
9*8fa4106eSEd Maste#    notice, this list of conditions and the following disclaimer.
10*8fa4106eSEd Maste# 2. Redistributions in binary form must reproduce the above copyright
11*8fa4106eSEd Maste#    notice, this list of conditions and the following disclaimer in the
12*8fa4106eSEd Maste#    documentation and/or other materials provided with the distribution.
13*8fa4106eSEd Maste#
14*8fa4106eSEd Maste# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15*8fa4106eSEd Maste# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16*8fa4106eSEd Maste# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17*8fa4106eSEd Maste# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18*8fa4106eSEd Maste# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19*8fa4106eSEd Maste# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20*8fa4106eSEd Maste# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21*8fa4106eSEd Maste# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22*8fa4106eSEd Maste# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23*8fa4106eSEd Maste# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24*8fa4106eSEd Maste# SUCH DAMAGE.
25*8fa4106eSEd Maste#
26*8fa4106eSEd Maste
27*8fa4106eSEd Mastetap_exists()
28*8fa4106eSEd Maste{
29*8fa4106eSEd Maste	ls -1 /dev | grep -q "$1"
30*8fa4106eSEd Maste}
31*8fa4106eSEd Maste
32*8fa4106eSEd Masteif [ $(id -u) -ne 0 ]; then
33*8fa4106eSEd Maste	echo "Must be root" >&2
34*8fa4106eSEd Maste	exit 1
35*8fa4106eSEd Mastefi
36*8fa4106eSEd Maste
37*8fa4106eSEd Masteset -e
38*8fa4106eSEd Maste
39*8fa4106eSEd Maste# Base case create & destroy
40*8fa4106eSEd Mastetap=$(ifconfig tap create)
41*8fa4106eSEd Mastetap_exists $tap
42*8fa4106eSEd Masteifconfig $tap destroy
43*8fa4106eSEd Maste! tap_exists $tap
44*8fa4106eSEd Maste
45*8fa4106eSEd Maste# kern/172075: INVARIANTS kernel panicked when destroying an in-use tap(4)
46*8fa4106eSEd Maste# Fixed in HEAD r240938.
47*8fa4106eSEd Mastetap=$(ifconfig tap create)
48*8fa4106eSEd Mastetap_exists $tap
49*8fa4106eSEd Mastecat /dev/$tap > /dev/null &
50*8fa4106eSEd Mastecatpid=$!
51*8fa4106eSEd Mastesleep 0.1
52*8fa4106eSEd Masteifconfig $tap destroy &
53*8fa4106eSEd Mastesleep 0.1
54*8fa4106eSEd Mastekill $catpid
55*8fa4106eSEd Maste! tap_exists $tap
56*8fa4106eSEd Maste
57*8fa4106eSEd Masteecho PASS
58*8fa4106eSEd Masteexit 0
59