Date: Fri, 12 Feb 2016 02:53:44 +0000 (UTC) From: Devin Teske <dteske@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r295556 - head/share/examples/jails Message-ID: <201602120253.u1C2ridG013452@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: dteske Date: Fri Feb 12 02:53:44 2016 New Revision: 295556 URL: https://svnweb.freebsd.org/changeset/base/295556 Log: Comments and fix small bug Reduce differences between jib/jng and fix a bug that would prevent additional interfaces from being created if the first of many already existed (counter wasn't incremented before calling only continue). Modified: head/share/examples/jails/jib head/share/examples/jails/jng Modified: head/share/examples/jails/jib ============================================================================== --- head/share/examples/jails/jib Fri Feb 12 02:50:36 2016 (r295555) +++ head/share/examples/jails/jib Fri Feb 12 02:53:44 2016 (r295556) @@ -286,13 +286,16 @@ jib_addm() !*) iface=${iface#!} no_derive=1 ;; esac - # 1. Make sure the interface doesn't exist already - ifconfig "e${i}a_$name" > /dev/null 2>&1 && continue + # Make sure the interface doesn't exist already + if ifconfig "e${i}a_$name" > /dev/null 2>&1; then + i=$(( $i + 1 )) + continue + fi - # 2. Bring the interface up + # Bring the interface up ifconfig $iface up || return - # 3. Make sure the interface has been bridged + # Make sure the interface has been bridged if ! ifconfig "$iface$bridge" > /dev/null 2>&1; then new=$( ifconfig bridge create ) || return ifconfig $new addm $iface || return @@ -300,18 +303,18 @@ jib_addm() ifconfig "$iface$bridge" up || return fi - # 4. Create a new interface to the bridge + # Create a new interface to the bridge new=$( ifconfig epair create ) || return ifconfig "$iface$bridge" addm $new || return - # 5. Rename the new interface + # Rename the new interface ifconfig $new name "e${i}a_$name" || return ifconfig ${new%a}b name "e${i}b_$name" || return ifconfig "e${i}a_$name" up || return ifconfig "e${i}b_$name" up || return # - # 6. Set the MAC address of the new interface using a sensible + # Set the MAC address of the new interface using a sensible # algorithm to prevent conflicts on the network. # eiface_devid_a= eiface_devid_b= @@ -322,7 +325,7 @@ jib_addm() ifconfig "e${i}b_$name" ether $eiface_devid_b fi > /dev/null 2>&1 - i=$(( $i + 1 )) # on to next e{i}b_name + i=$(( $i + 1 )) done # for iface } Modified: head/share/examples/jails/jng ============================================================================== --- head/share/examples/jails/jng Fri Feb 12 02:50:36 2016 (r295555) +++ head/share/examples/jails/jng Fri Feb 12 02:53:44 2016 (r295556) @@ -291,18 +291,21 @@ jng_bridge() !*) iface=${iface#!} no_derive=1 ;; esac - # 0. Make sure the interface doesn't exist already + # Make sure the interface doesn't exist already eiface=ng${i}_$name - ngctl msg "$eiface:" getifname > /dev/null 2>&1 && continue + if ngctl msg "$eiface:" getifname > /dev/null 2>&1; then + i=$(( $i + 1 )) + continue + fi - # 1. Bring the interface up + # Bring the interface up ifconfig $iface up || return - # 2. Set promiscuous mode and don't overwrite src addr + # Set promiscuous mode and don't overwrite src addr ngctl msg $iface: setpromisc 1 || return ngctl msg $iface: setautosrc 0 || return - # 3. Make sure the interface has been bridged + # Make sure the interface has been bridged if ! ngctl info ${iface}bridge: > /dev/null 2>&1; then ngctl mkpeer $iface: bridge lower link0 || return ngctl connect $iface: $iface:lower upper link1 || @@ -310,7 +313,7 @@ jng_bridge() ngctl name $iface:lower ${iface}bridge || return fi - # 3.5. Optionally create a secondary bridge + # Optionally create a secondary bridge if [ "$bridge" != "bridge" ] && ! ngctl info "$iface$bridge:" > /dev/null 2>&1 then @@ -326,7 +329,7 @@ jng_bridge() return fi - # 4. Create a new interface to the bridge + # Create a new interface to the bridge num=2 while ngctl msg "$iface$bridge:" getstats $num > /dev/null 2>&1 do @@ -334,7 +337,7 @@ jng_bridge() done ngctl mkpeer "$iface$bridge:" eiface link$num ether || return - # 5. Rename the new interface + # Rename the new interface while [ ${#eiface} -gt 15 ]; do # OS limitation eiface=${eiface%?} done @@ -345,7 +348,7 @@ jng_bridge() ifconfig $eiface up || return # - # 6. Set the MAC address of the new interface using a sensible + # Set the MAC address of the new interface using a sensible # algorithm to prevent conflicts on the network. # eiface_devid= @@ -358,7 +361,7 @@ jng_bridge() [ "$eiface_devid" ] && ifconfig $eiface ether $eiface_devid > /dev/null 2>&1 - i=$(( $i + 1 )) # on to next ng{i}_name + i=$(( $i + 1 )) done # for iface }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201602120253.u1C2ridG013452>