From 418822cd51c76cdb088960604db53c7be73fbf78 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Tue, 1 Oct 2013 20:43:24 +0200 Subject: vserver.netns: interface has to be down to change mac --- vserver.netns | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vserver.netns b/vserver.netns index 8e55c02..8d9e244 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 ;; -- cgit v1.2.3-1-g7c22 From 7875e0f5d6f1939ab87c5b98a20b55bd06f2dada Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Tue, 1 Oct 2013 20:50:04 +0200 Subject: vserver.functions: add magically localhost for netns --- vserver.functions | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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 } -- cgit v1.2.3-1-g7c22 From 3ed5f40df866fe48b7f634e353e40b699899c1f8 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Wed, 2 Oct 2013 18:15:07 +0200 Subject: vserver.netns: only delete the netns, if nothing is active in it --- vserver.netns | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/vserver.netns b/vserver.netns index 8d9e244..c507621 100755 --- a/vserver.netns +++ b/vserver.netns @@ -143,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 -- cgit v1.2.3-1-g7c22