• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0-or-later
3# Copyright (c) Köry Maincent <kory.maincent@bootlin.com> 2020
4# Copyright (c) 2015 Red Hat, Inc.
5#
6# SYNOPSIS:
7# netns_comm.sh <NS_EXEC_PROGRAM> <IP_VERSION> <COMM_TYPE>
8#
9# OPTIONS:
10#       * NS_EXEC_PROGRAM (ns_exec|ip)
11#               Program which will be used to enter and run other commands
12#               inside a network namespace.
13#       * IP_VERSION (ipv4|ipv6)
14#               Version of IP. (ipv4|ipv6)
15#	* COMM_TYPE (netlink|ioctl)
16#		Communication type between kernel and user space
17#		for basic setup: enabling and assigning IP addresses
18#		to the virtual ethernet devices. (Uses 'ip' command for netlink
19#		and 'ifconfig' for ioctl.)
20#
21# Tests that a separate network namespace can configure and communicate
22# over the devices it sees. Tests are done using netlink(7) ('ip' command)
23# or ioctl(2) ('ifconfig' command) for controlling devices.
24#
25# There are three test cases:
26# 1,2. communication over paired veth (virtual ethernet) devices
27#      from two different network namespaces (each namespace has
28#      one device)
29#   3. communication over the lo (localhost) device in a separate
30#      network namespace
31
32TST_POS_ARGS=3
33TST_SETUP=do_setup
34TST_TESTFUNC=do_test
35. netns_helper.sh
36
37PROG=$1
38IP_VER=$2
39COM_TYPE=$3
40
41do_setup()
42{
43	netns_setup $PROG $IP_VER $COM_TYPE "192.168.0.2" "192.168.0.3" "fd00::2" "fd00::3"
44	tst_res TINFO "NS interaction: $PROG | devices setup: $COM_TYPE"
45}
46
47do_test()
48{
49	EXPECT_PASS $NS_EXEC $NS_HANDLE0 $NS_TYPE $tping -q -c2 -I veth0 $IP1 1>/dev/null
50
51	EXPECT_PASS $NS_EXEC $NS_HANDLE1 $NS_TYPE $tping -q -c2 -I veth1 $IP0 1>/dev/null
52
53	case "$IP_VER" in
54	ipv4) ip_lo="127.0.0.1" ;;
55	ipv6) ip_lo="::1" ;;
56	esac
57	case "$COM_TYPE" in
58	netlink)
59		$NS_EXEC $NS_HANDLE0 $NS_TYPE ip link set dev lo up || \
60			tst_brk TBROK "enabling lo device failed"
61		;;
62	ioctl)
63		$NS_EXEC $NS_HANDLE0 $NS_TYPE ifconfig lo up || \
64			tst_brk TBROK "enabling lo device failed"
65		;;
66	esac
67	EXPECT_PASS $NS_EXEC $NS_HANDLE0 $NS_TYPE $tping -q -c2 -I lo $ip_lo 1>/dev/null
68}
69
70tst_run
71