| 1 |
#!/bin/sh |
| 2 |
# |
| 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. |
| 6 |
|
| 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 |
| 12 |
|
| 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 |
| 16 |
|
| 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 $$" |
| 21 |
|
| 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) |
| 26 |
|
| 27 |
echo "To communicate with this testenv, use: $helper_script" |
| 28 |
echo "-------------------------------------------------------------" |
| 29 |
|
| 30 |
# the rest of the args are the samba command to run |
| 31 |
shift 3 |
| 32 |
SAMBA_CMD=$@ |
| 33 |
|
| 34 |
# make sure namespace loopback is up (it's needed for ping, etc) |
| 35 |
ip link set dev lo up |
| 36 |
|
| 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 |
| 49 |
|
| 50 |
# move the bridge end of the link back into the parent namespace. |
| 51 |
ip link set $interface-br netns $parent_pid |
| 52 |
|
| 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 |
| 59 |
|
| 60 |
# start samba |
| 61 |
$SAMBA_CMD |