xref: /illumos-gate/usr/src/test/util-tests/tests/dladm/show-overlay-exit.ksh (revision 763f1f5f97e4c16840af2ced98915f0ed0f46616)
1#!/bin/ksh
2#
3# This file and its contents are supplied under the terms of the
4# Common Development and Distribution License ("CDDL"), version 1.0.
5# You may only use this file in accordance with the terms of version
6# 1.0 of the CDDL.
7#
8# A full copy of the text of the CDDL should have accompanied this
9# source.  A copy of the CDDL is also available via the Internet at
10# http://www.illumos.org/license/CDDL.
11#
12
13#
14# Copyright (c) 2017, Joyent, Inc.
15# Copyright 2022 OmniOS Community Edition (OmniOSce) Association.
16#
17
18soe_arg0="$(basename $0)"
19
20soe_overlay="soe_overlay$$"
21soe_dummy_ip="169.254.0.0"
22
23soe_port="2000"
24soe_vnetid=20
25soe_encap="vxlan"
26soe_search="direct"
27
28soe_etherstub="soe_teststub$$"
29
30function fatal
31{
32	typeset msg="$*"
33	[[ -z "$msg" ]] && msg="failed"
34	echo "TEST_FAIL: $vt_arg0: $msg" >&2
35	dladm delete-overlay $soe_overlay
36	dladm delete-etherstub $soe_etherstub
37	exit 1
38}
39
40function setup
41{
42	dladm create-overlay -t -v $soe_vnetid -e $soe_encap -s $soe_search \
43	    -p vxlan/listen_ip=$soe_dummy_ip -p direct/dest_ip=$soe_dummy_ip \
44	    -p direct/dest_port=$soe_port $soe_overlay || \
45	    fatal "failed to create overlay"
46
47	dladm create-etherstub $soe_etherstub || \
48	    fatal "failed to create etherstub"
49}
50
51function cleanup
52{
53	dladm delete-overlay $soe_overlay || \
54	    fatal "failed to remove overlay"
55	dladm delete-etherstub $soe_etherstub || \
56	    fatal "failed to remove etherstub"
57}
58
59function runtest
60{
61	dladm show-overlay $* > /dev/null 2>&1
62}
63
64function epass
65{
66	runtest $* || fatal "show-overlay=$* failed, expected success\n"
67}
68
69function efail
70{
71	runtest $* && fatal "show-overlay=$* succeeded, expected failure\n"
72}
73
74setup
75
76epass $soe_overlay
77efail $soe_etherstub
78efail $soe_etherstub $soe_overlay
79efail $soe_overlay $soe_etherstub
80
81cleanup
82
83print "TEST PASS: $soe_arg0"
84