From: Ian Kelling Date: Thu, 19 Jan 2017 10:30:46 +0000 (-0800) Subject: even better documentation X-Git-Url: https://iankelling.org/git/?a=commitdiff_plain;h=11818aeee42717a9ce5ca1b4ac7bde4a646f1306;p=newns even better documentation --- diff --git a/newns b/newns index 31f1b52..d6a1b08 100755 --- a/newns +++ b/newns @@ -37,7 +37,7 @@ fi usage() { cat </dev/null; then echo "please install the iproute2 package" @@ -116,8 +115,7 @@ fi if $install_error; then exit 1 fi - -## end sanity checking ## +#### end sanity checking #### v0=veth0-$nn @@ -128,10 +126,10 @@ if ! $create && [[ $(readlink /proc/self/ns/net) == "$(readlink /proc/1/ns/net)" create=true fi +# make the default network namespace be named target=/run/netns/default if [[ ! -e $target && ! -L $target ]]; then mkdir -p /run/netns - # make the default network namespace be named ln -s /proc/1/ns/net $target fi @@ -146,7 +144,7 @@ fi dexec() { ip netns exec default "$@"; } -# head -n1 is defensive. Not sure if there is some weird feature +# background: head -n1 is defensive. Not sure if there is some weird feature # for 2 routes to be 0/0. gateway_if=$(ipd route list exact 0/0 | head -n1| sed -r 's/.*\s(\S+)\s*$/\1/') nat() { dexec iptables -t nat $1 POSTROUTING -o $gateway_if -j MASQUERADE \ @@ -168,13 +166,13 @@ find_network() { } start() { - find_network if ! $found; then echo "$0: error: no open network found" exit 1 fi + #### begin mount namespace setup #### mkdir -p /root/mount_namespaces if ! mountpoint /root/mount_namespaces >/dev/null; then mount --bind /root/mount_namespaces /root/mount_namespaces @@ -186,6 +184,7 @@ start() { if ! mountpoint /root/mount_namespaces/$nn >/dev/null; then unshare --mount=/root/mount_namespaces/$nn fi + #### end mount namespace setup #### if $create; then @@ -193,8 +192,6 @@ start() { ip -n $nn link set dev lo up fi - - echo 1 | dexec dd of=/proc/sys/net/ipv4/ip_forward 2>/dev/null _errcatch_cleanup=stop