Merge branch 'x86-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[cris-mirror.git] / tools / testing / selftests / net / msg_zerocopy.sh
blobd571d213418d56048f8edd1da798fe0005a3e4ef
1 #!/bin/bash
3 # Send data between two processes across namespaces
4 # Run twice: once without and once with zerocopy
6 set -e
8 readonly DEV="veth0"
9 readonly DEV_MTU=65535
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 # Argument parsing
25 if [[ "$#" -lt "2" ]]; then
26 echo "Usage: $0 [4|6] [tcp|udp|raw|raw_hdrincl|packet|packet_dgram] <args>"
27 exit 1
30 readonly IP="$1"
31 shift
32 readonly TXMODE="$1"
33 shift
34 readonly EXTRA_ARGS="$@"
36 # Argument parsing: configure addresses
37 if [[ "${IP}" == "4" ]]; then
38 readonly SADDR="${SADDR4}"
39 readonly DADDR="${DADDR4}"
40 elif [[ "${IP}" == "6" ]]; then
41 readonly SADDR="${SADDR6}"
42 readonly DADDR="${DADDR6}"
43 else
44 echo "Invalid IP version ${IP}"
45 exit 1
48 # Argument parsing: select receive mode
50 # This differs from send mode for
51 # - packet: use raw recv, because packet receives skb clones
52 # - raw_hdrinc: use raw recv, because hdrincl is a tx-only option
53 case "${TXMODE}" in
54 'packet' | 'packet_dgram' | 'raw_hdrincl')
55 RXMODE='raw'
58 RXMODE="${TXMODE}"
60 esac
62 # Start of state changes: install cleanup handler
63 save_sysctl_mem="$(sysctl -n ${path_sysctl_mem})"
65 cleanup() {
66 ip netns del "${NS2}"
67 ip netns del "${NS1}"
68 sysctl -w -q "${path_sysctl_mem}=${save_sysctl_mem}"
71 trap cleanup EXIT
73 # Configure system settings
74 sysctl -w -q "${path_sysctl_mem}=1000000"
76 # Create virtual ethernet pair between network namespaces
77 ip netns add "${NS1}"
78 ip netns add "${NS2}"
80 ip link add "${DEV}" mtu "${DEV_MTU}" netns "${NS1}" type veth \
81 peer name "${DEV}" mtu "${DEV_MTU}" netns "${NS2}"
83 # Bring the devices up
84 ip -netns "${NS1}" link set "${DEV}" up
85 ip -netns "${NS2}" link set "${DEV}" up
87 # Set fixed MAC addresses on the devices
88 ip -netns "${NS1}" link set dev "${DEV}" address 02:02:02:02:02:02
89 ip -netns "${NS2}" link set dev "${DEV}" address 06:06:06:06:06:06
91 # Add fixed IP addresses to the devices
92 ip -netns "${NS1}" addr add 192.168.1.1/24 dev "${DEV}"
93 ip -netns "${NS2}" addr add 192.168.1.2/24 dev "${DEV}"
94 ip -netns "${NS1}" addr add fd::1/64 dev "${DEV}" nodad
95 ip -netns "${NS2}" addr add fd::2/64 dev "${DEV}" nodad
97 # Optionally disable sg or csum offload to test edge cases
98 # ip netns exec "${NS1}" ethtool -K "${DEV}" sg off
100 do_test() {
101 local readonly ARGS="$1"
103 echo "ipv${IP} ${TXMODE} ${ARGS}"
104 ip netns exec "${NS2}" "${BIN}" "-${IP}" -i "${DEV}" -t 2 -C 2 -S "${SADDR}" -D "${DADDR}" ${ARGS} -r "${RXMODE}" &
105 sleep 0.2
106 ip netns exec "${NS1}" "${BIN}" "-${IP}" -i "${DEV}" -t 1 -C 3 -S "${SADDR}" -D "${DADDR}" ${ARGS} "${TXMODE}"
107 wait
110 do_test "${EXTRA_ARGS}"
111 do_test "-z ${EXTRA_ARGS}"
112 echo ok