summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2014-02-28 21:09:25 +0100
committerAlexander Sulfrian <alexander@sulfrian.net>2014-02-28 21:09:25 +0100
commita97473c54a958d14cf083a19134767345b42be81 (patch)
treeeb6759574194e601b935046dee98fde249e92830
parentd9d60af781079936010f8fe700ad4e5f1deb1e5a (diff)
parent3ed5f40df866fe48b7f634e353e40b699899c1f8 (diff)
downloadutil-vserver-netns-a97473c54a958d14cf083a19134767345b42be81.tar.gz
util-vserver-netns-a97473c54a958d14cf083a19134767345b42be81.tar.bz2
util-vserver-netns-a97473c54a958d14cf083a19134767345b42be81.zip
Merge commit '1.4' into debian
* commit '1.4': vserver.netns: only delete the netns, if nothing is active in it vserver.functions: add magically localhost for netns vserver.netns: interface has to be down to change mac
-rw-r--r--vserver.functions13
-rwxr-xr-xvserver.netns17
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