3 # Send data between two processes across namespaces
4 # Run twice: once without and once with zerocopy
10 readonly BIN
="./msg_zerocopy"
12 readonly RAND
="$(mktemp -u XXXXXX)"
13 readonly NSPREFIX
="ns-${RAND}"
14 readonly NS1
="${NSPREFIX}1"
15 readonly NS2
="${NSPREFIX}2"
17 readonly SADDR4
='192.168.1.1'
18 readonly DADDR4
='192.168.1.2'
19 readonly SADDR6
='fd::1'
20 readonly DADDR6
='fd::2'
22 readonly path_sysctl_mem
="net.core.optmem_max"
24 # No arguments: automated test
25 if [[ "$#" -eq "0" ]]; then
30 echo "OK. All tests passed"
35 if [[ "$#" -lt "2" ]]; then
36 echo "Usage: $0 [4|6] [tcp|udp|raw|raw_hdrincl|packet|packet_dgram] <args>"
44 readonly EXTRA_ARGS
="$@"
46 # Argument parsing: configure addresses
47 if [[ "${IP}" == "4" ]]; then
48 readonly SADDR
="${SADDR4}"
49 readonly DADDR
="${DADDR4}"
50 elif [[ "${IP}" == "6" ]]; then
51 readonly SADDR
="${SADDR6}"
52 readonly DADDR
="${DADDR6}"
54 echo "Invalid IP version ${IP}"
58 # Argument parsing: select receive mode
60 # This differs from send mode for
61 # - packet: use raw recv, because packet receives skb clones
62 # - raw_hdrinc: use raw recv, because hdrincl is a tx-only option
64 'packet' |
'packet_dgram' |
'raw_hdrincl')
72 # Start of state changes: install cleanup handler
81 # Create virtual ethernet pair between network namespaces
85 # Configure system settings
86 ip netns
exec "${NS1}" sysctl
-w -q "${path_sysctl_mem}=1000000"
87 ip netns
exec "${NS2}" sysctl
-w -q "${path_sysctl_mem}=1000000"
89 ip link add
"${DEV}" mtu "${DEV_MTU}" netns "${NS1}" type veth \
90 peer name
"${DEV}" mtu "${DEV_MTU}" netns "${NS2}"
92 # Bring the devices up
93 ip
-netns "${NS1}" link
set "${DEV}" up
94 ip
-netns "${NS2}" link
set "${DEV}" up
96 # Set fixed MAC addresses on the devices
97 ip
-netns "${NS1}" link
set dev
"${DEV}" address
02:02:02:02:02:02
98 ip
-netns "${NS2}" link
set dev
"${DEV}" address
06:06:06:06:06:06
100 # Add fixed IP addresses to the devices
101 ip
-netns "${NS1}" addr add
192.168.1.1/24 dev
"${DEV}"
102 ip
-netns "${NS2}" addr add
192.168.1.2/24 dev
"${DEV}"
103 ip
-netns "${NS1}" addr add fd
::1/64 dev
"${DEV}" nodad
104 ip
-netns "${NS2}" addr add fd
::2/64 dev
"${DEV}" nodad
106 # Optionally disable sg or csum offload to test edge cases
107 # ip netns exec "${NS1}" ethtool -K "${DEV}" sg off
110 local readonly ARGS
="$1"
112 echo "ipv${IP} ${TXMODE} ${ARGS}"
113 ip netns
exec "${NS2}" "${BIN}" "-${IP}" -i "${DEV}" -t 2 -C 2 -S "${SADDR}" -D "${DADDR}" ${ARGS} -r "${RXMODE}" &
115 ip netns
exec "${NS1}" "${BIN}" "-${IP}" -i "${DEV}" -t 1 -C 3 -S "${SADDR}" -D "${DADDR}" ${ARGS} "${TXMODE}"
119 do_test
"${EXTRA_ARGS}"
120 do_test
"-z ${EXTRA_ARGS}"