eval echo "$1=\$$1"
}
-# Unless the subhost already has a private /etc/network/interfaces,
-# install an "empty" one
+# Install a default $1/etc/network/interfaces on the subhost root $1
setup_networking() {
- [ -r $UPPER/etc/network/interfaces ] && return 0
- [ "$UPPER/etc/network" = "/etc/network" ] && exit 1
- mkdir -p $UPPER/etc/network
- cat <<EOF > $UPPER/etc/network/interfaces
+ [ -r $1/etc/network/interfaces ] && return 0
+ mkdir -p $1/etc/network
+ cat <<EOF >> $1/etc/network/interfaces
# Generated for $NAME subhost
auto lo
iface lo inet loopback
EOF
- return 1
+ for IF in $(ip netns exec $NAME ip link show | grep "^eth") ; do
+ cat <<EOF >> $1/etc/network/interfaces
+
+auto eth$i
+iface eth$i inet manual
+EOF
+ done
}
# Setup the network namespace for the given $CABLES
NETNS="$1"
shift 1
i=0
- ADD=false
- setup_networking || ADD=true
for C in "$@" ; do
IF=$NETNS$i
MAC="${C#*=}"
[ -z "$MAC" ] || MAC="address $MAC"
ip link add $IF type veth peer name eth$i $MAC netns $NETNS
ip link set $IF up
- $ADD && cat <<EOF >> $UPPER/etc/network/interfaces
-
-auto eth$i
-iface eth$i inet manual
-EOF
BR="${C%=*}"
if [ -z "$BR" ] ; then
ip link set $IF
mkdir "$UPPER/dev/pts"
chmod 1777 "$UPPER/dev/shm"
+ # all good so far ; now avoid using the host's networking setup
+ setup_networking "$UPPER"
+
OLY="-olowerdir=$3,upperdir=$UPPER,workdir=$5"
- if mount -t overlay "$OLY" $1 $2 ; then
- : # all good
- else
+ if ! mount -t overlay "$OLY" $1 $2 ; then
umount -R "$UPPER/dev"
umount "$UPPER/run"
die "Cannot set up the overlay mount $2"
config START "networking ssh"
config SUBSHELL /bin/sh
-# Setup virtual cabling and subhost's /etc/network/interfaces
+# Setup virtual cabling
setup_veth_cables $NAME $CABLES
# Set up the mount for this subhost, including a new tmpfs on its /run
+# and a default $UPPER/etc/network/interfaces if needed
echo setup_overlay "$NAME" "$LIVE" "$LOWER" "$UPPER" "$WORK"
setup_overlay "$NAME" "$LIVE" "$LOWER" "$UPPER" "$WORK"