1#!/bin/sh
2#==============================================================================
3# Copyright (c) 2015 Red Hat, Inc.
4#
5# This program is free software: you can redistribute it and/or modify
6# it under the terms of version 2 the GNU General Public License as
7# published by the Free Software Foundation.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16#
17# Written by Matus Marhefka <mmarhefk@redhat.com>
18#
19#==============================================================================
20#
21# SYNOPSIS:
22# netns_comm.sh <NS_EXEC_PROGRAM> <IP_VERSION> <COMM_TYPE>
23#
24# OPTIONS:
25#       * NS_EXEC_PROGRAM (ns_exec|ip)
26#               Program which will be used to enter and run other commands
27#               inside a network namespace.
28#       * IP_VERSION (ipv4|ipv6)
29#               Version of IP. (ipv4|ipv6)
30#	* COMM_TYPE (netlink|ioctl)
31#		Communication type between kernel and user space
32#		for basic setup: enabling and assigning IP addresses
33#		to the virtual ethernet devices. (Uses 'ip' command for netlink
34#		and 'ifconfig' for ioctl.)
35#
36# Tests that a separate network namespace can configure and communicate
37# over the devices it sees. Tests are done using netlink(7) ('ip' command)
38# or ioctl(2) ('ifconfig' command) for controlling devices.
39#
40# There are three test cases:
41# 1,2. communication over paired veth (virtual ethernet) devices
42#      from two different network namespaces (each namespace has
43#      one device)
44#   3. communication over the lo (localhost) device in a separate
45#      network namespace
46#==============================================================================
47
48TCID="netns_comm_$1_$2_$3"
49TST_TOTAL=3
50. netns_helper.sh
51
52# SETUP
53netns_setup $1 $2 $3 "192.168.0.2" "192.168.0.3" "fd00::2" "fd00::3"
54tst_resm TINFO "NS interaction: $1 | devices setup: $3"
55
56
57# TEST CASE #1
58$NS_EXEC $NS_HANDLE0 $NS_TYPE $tping -q -c2 -I veth0 $IP1 1>/dev/null
59if [ $? -eq 0 ]; then
60	tst_resm TPASS "configuration and communication over veth0"
61else
62	tst_resm TFAIL "configuration and communication over veth0"
63fi
64
65
66# TEST CASE #2
67$NS_EXEC $NS_HANDLE1 $NS_TYPE $tping -q -c2 -I veth1 $IP0 1>/dev/null
68if [ $? -eq 0 ]; then
69	tst_resm TPASS "configuration and communication over veth1"
70else
71	tst_resm TFAIL "configuration and communication over veth1"
72fi
73
74
75# TEST CASE #3
76case "$2" in
77ipv4) IP_LO="127.0.0.1" ;;
78ipv6) IP_LO="::1" ;;
79esac
80case "$3" in
81netlink)
82	$NS_EXEC $NS_HANDLE0 $NS_TYPE ip link set dev lo up || \
83		tst_brkm TBROK "enabling lo device failed"
84	;;
85ioctl)
86	$NS_EXEC $NS_HANDLE0 $NS_TYPE ifconfig lo up || \
87		tst_brkm TBROK "enabling lo device failed"
88	;;
89esac
90$NS_EXEC $NS_HANDLE0 $NS_TYPE $tping -q -c2 -I lo $IP_LO 1>/dev/null
91if [ $? -eq 0 ]; then
92	tst_resm TPASS "configuration and communication over localhost"
93else
94	tst_resm TFAIL "configuration and communication over localhost"
95fi
96
97
98tst_exit
99