diff options
-rw-r--r-- | vserver.functions | 13 | ||||
-rwxr-xr-x | vserver.netns | 17 |
2 files changed, 28 insertions, 2 deletions
diff --git a/vserver.functions b/vserver.functions index a75d717..8c25f74 100644 --- a/vserver.functions +++ b/vserver.functions @@ -47,6 +47,14 @@ function _netnsProcessSingleGateway() { _addInterfaceCmd IP_ROUTE default via "$gw" dev "$iface" } +function _netnsAddLocalhost() { + if [ -r "${1}/nflags" ]; then + if grep -q '^~LBACK_REMAP$' "${1}/nflags"; then + INTERFACES=( "${INTERFACES[@]}" "127.0.0.1/8" "::1/128" ) + fi + fi +} + function _netnsFilterNetnsUmount() { local args=( "$@" ) @@ -93,13 +101,18 @@ function _generateInterfaceOptions() { ret=$? # add commands for default route + local netns=0 for net in "$VSERVER_DIR/netns/"*; do test -d "$net" || continue test ! -e "${net}/disabled" || continue _netnsProcessSingleGateway "$net" + netns=1 done + # if using netns, automatically add localhost + [ "$netns" != "0" ] && _netnsAddLocalhost "$VSERVER_DIR" + return $ret } diff --git a/vserver.netns b/vserver.netns index 8e55c02..c507621 100755 --- a/vserver.netns +++ b/vserver.netns @@ -38,7 +38,8 @@ function _processSingleNetwork() { [ -n "$mav" ] || mac="$(netnsCreateMac "$2")" $_IP link set dev "$iface" netns "$VSERVER_NAME" - $_IP netns exec "$VSERVER_NAME" $_IP link set dev "$iface" address "$mac" + $_IP netns exec "$VSERVER_NAME" $_IP link set "$iface" down + $_IP netns exec "$VSERVER_NAME" $_IP link set "$iface" address "$mac" $_IP netns exec "$VSERVER_NAME" $_VPROCUNHIDE ;; @@ -142,7 +143,19 @@ if [ -n "${_USE_NETNS}" ]; then _processSingleNetwork remove "$net" done - $_IP netns delete "$VSERVER_NAME" + procs="$($_IP netns exec "$VSERVER_NAME" netstat -tulpenW | sed '1d;2d')" + if [ -n "$procs" ]; then + echo "There are still processes active in the network namespace:" + echo "$procs" + echo + echo "Deleting of the network namespace would produce a bad state." + echo "So we DO NOT delete the network namespace. You maybe want + echo "to kill the processes and execute the following commands:" + echo " $_IP netns exec \"$VSERVER_NAME\" netstat -tulpen" + echo " $_IP netns delete \"$VSERVER_NAME\"" + else + $_IP netns delete "$VSERVER_NAME" + fi fi exit $ret |