fuzzing: fix fuzz_stable_sort_r_unstable comparison
[Samba.git] / selftest / ns / start_in_ns.sh
blobf16767d545be14da96b2bfed0d1da1bdc66bed8e
1 #!/bin/sh
3 # Starts samba in a separate namespace. This gets passed the interface/IP
4 # to use, as well as the Samba command to run. The whole script gets run
5 # (via unshare) in a separate namespace.
7 # the first 3 args are our interface-name, parent-PID, and a exports file
8 # containing environment variables ($SERVER, $SERVER_IP, etc)
9 interface=$1
10 exports_file=$2
11 parent_pid=$3
13 # we write the testenv environment variables to file, which makes it easier
14 # to work out the $SERVER, $SERVER_IP, etc
15 . $exports_file
17 # The namespaces we use are anonymous, which means other processes would need
18 # to use our PID to access the new namespace
19 echo "-------------------------------------------------------------"
20 echo "Created namespace for $NETBIOSNAME ($ENVNAME) PID $$"
22 # generate a helper script if the developer wants to talk to this namespace
23 # in another shell
24 mk_nsenter_script="$(dirname $0)/mk_nsenter.sh"
25 helper_script=$($mk_nsenter_script $$ $exports_file)
27 echo "To communicate with this testenv, use: $helper_script"
28 echo "-------------------------------------------------------------"
30 # the rest of the args are the samba command to run
31 shift 3
32 SAMBA_CMD=$@
34 # make sure namespace loopback is up (it's needed for ping, etc)
35 ip link set dev lo up
37 # Create the interfaces needed for communication between namespaces.
38 # We use a veth pair, which acts as a tunnel between the namespaces.
39 # One end of the veth link is added to a common bridge in the top-level (i.e.
40 # selftest) namespace, and the other end is added to the testenv's namespace.
41 # This means each testenv DC is in its own namespace, but they can talk to
42 # each other via the common bridge interface.
43 # The new veth interfaces are named "vethX" and "vethX-br", where
44 # X = the testenv IP (i.e. Samba::get_interface()). E.g. ad_dc = veth30,
45 # and veth30-br.
46 # The "vethX" interface will live in the new testenv's namespace.
47 # The "vethX-br" end is added to the bridge in the main selftest namespace.
48 ip link add dev $interface-br type veth peer name $interface
50 # move the bridge end of the link back into the parent namespace.
51 ip link set $interface-br netns $parent_pid
53 # configure our IP address and bring the interface up
54 ip addr add $SERVER_IP/24 dev $interface
55 # Note that samba can't bind to the IPv6 address while DAD is in progress,
56 # so we use 'nodad' when configuring the address
57 ip addr add $SERVER_IPV6/112 dev $interface nodad
58 ip link set dev $interface up
60 # start samba
61 $SAMBA_CMD