jib (295553) | jib (295554) |
---|---|
1#!/bin/sh 2#- 3# Copyright (c) 2016 Devin Teske 4# All rights reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions 8# are met: --- 10 unchanged lines hidden (view full) --- 19# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25# SUCH DAMAGE. 26# | 1#!/bin/sh 2#- 3# Copyright (c) 2016 Devin Teske 4# All rights reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions 8# are met: --- 10 unchanged lines hidden (view full) --- 19# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25# SUCH DAMAGE. 26# |
27# $FreeBSD: head/share/examples/jails/jib 295553 2016-02-12 01:12:44Z dteske $ | 27# $FreeBSD: head/share/examples/jails/jib 295554 2016-02-12 01:41:40Z dteske $ |
28# 29############################################################ IDENT(1) 30# 31# $Title: if_bridge(4) management script for vnet jails $ 32# 33############################################################ INFORMATION 34# 35# Use this tool with jail.conf(5) (or rc.conf(5) ``legacy'' configuration) to --- 216 unchanged lines hidden (view full) --- 252mustberoot_to_continue() 253{ 254 if [ "$( id -u )" -ne 0 ]; then 255 echo "Must run as root!" >&2 256 exit $FAILURE 257 fi 258} 259 | 28# 29############################################################ IDENT(1) 30# 31# $Title: if_bridge(4) management script for vnet jails $ 32# 33############################################################ INFORMATION 34# 35# Use this tool with jail.conf(5) (or rc.conf(5) ``legacy'' configuration) to --- 216 unchanged lines hidden (view full) --- 252mustberoot_to_continue() 253{ 254 if [ "$( id -u )" -ne 0 ]; then 255 echo "Must run as root!" >&2 256 exit $FAILURE 257 fi 258} 259 |
260jib_addm_usage="addm [-b BRIDGE_NAME] NAME interface0 [interface1 ...]" | 260jib_addm_usage="addm [-b BRIDGE_NAME] NAME [!]iface0 [[!]iface1 ...]" |
261jib_addm_descr="Creates e0b_NAME [e1b_NAME ...]" 262jib_addm() 263{ 264 local OPTIND=1 OPTARG flag bridge=bridge 265 while getopts b: flag; do 266 case "$flag" in 267 b) bridge="${OPTARG:-bridge}" ;; 268 *) action_usage addm # NOTREACHED --- 4 unchanged lines hidden (view full) --- 273 local name="$1" 274 [ "${name:-x}" = "${name#*[!0-9a-zA-Z_]}" -a $# -gt 1 ] || 275 action_usage addm # NOTREACHED 276 shift 1 # name 277 278 mustberoot_to_continue 279 280 local iface eiface_devid_a eiface_devid_b | 261jib_addm_descr="Creates e0b_NAME [e1b_NAME ...]" 262jib_addm() 263{ 264 local OPTIND=1 OPTARG flag bridge=bridge 265 while getopts b: flag; do 266 case "$flag" in 267 b) bridge="${OPTARG:-bridge}" ;; 268 *) action_usage addm # NOTREACHED --- 4 unchanged lines hidden (view full) --- 273 local name="$1" 274 [ "${name:-x}" = "${name#*[!0-9a-zA-Z_]}" -a $# -gt 1 ] || 275 action_usage addm # NOTREACHED 276 shift 1 # name 277 278 mustberoot_to_continue 279 280 local iface eiface_devid_a eiface_devid_b |
281 local new num quad i=0 | 281 local new no_derive num quad i=0 |
282 for iface in $*; do 283 | 282 for iface in $*; do 283 |
284 no_derive= 285 case "$iface" in 286 !*) iface=${iface#!} no_derive=1 ;; 287 esac 288 |
|
284 # 1. Make sure the interface doesn't exist already 285 ifconfig "e${i}a_$name" > /dev/null 2>&1 && continue 286 287 # 2. Bring the interface up 288 ifconfig $iface up || return 289 290 # 3. Make sure the interface has been bridged 291 if ! ifconfig "$iface$bridge" > /dev/null 2>&1; then --- 12 unchanged lines hidden (view full) --- 304 ifconfig ${new%a}b name "e${i}b_$name" || return 305 ifconfig "e${i}a_$name" up || return 306 ifconfig "e${i}b_$name" up || return 307 308 # 309 # 6. Set the MAC address of the new interface using a sensible 310 # algorithm to prevent conflicts on the network. 311 # | 289 # 1. Make sure the interface doesn't exist already 290 ifconfig "e${i}a_$name" > /dev/null 2>&1 && continue 291 292 # 2. Bring the interface up 293 ifconfig $iface up || return 294 295 # 3. Make sure the interface has been bridged 296 if ! ifconfig "$iface$bridge" > /dev/null 2>&1; then --- 12 unchanged lines hidden (view full) --- 309 ifconfig ${new%a}b name "e${i}b_$name" || return 310 ifconfig "e${i}a_$name" up || return 311 ifconfig "e${i}b_$name" up || return 312 313 # 314 # 6. Set the MAC address of the new interface using a sensible 315 # algorithm to prevent conflicts on the network. 316 # |
312 derive_mac -2 $iface "$name" eiface_devid_a eiface_devid_b 313 ifconfig "e${i}a_$name" ether $eiface_devid_a > /dev/null 2>&1 314 ifconfig "e${i}b_$name" ether $eiface_devid_b > /dev/null 2>&1 | 317 eiface_devid_a= eiface_devid_b= 318 [ "$no_derive" ] || derive_mac -2 $iface "$name" \ 319 eiface_devid_a eiface_devid_b 320 if [ "$eiface_devid_a" -a "$eiface_devid_b" ]; then 321 ifconfig "e${i}a_$name" ether $eiface_devid_a 322 ifconfig "e${i}b_$name" ether $eiface_devid_b 323 fi > /dev/null 2>&1 |
315 316 i=$(( $i + 1 )) # on to next e{i}b_name 317 done # for iface 318} 319 320jib_show_usage="show" 321jib_show_descr="List possible NAME values for \`show NAME'" 322jib_show1_usage="show NAME" --- 82 unchanged lines hidden --- | 324 325 i=$(( $i + 1 )) # on to next e{i}b_name 326 done # for iface 327} 328 329jib_show_usage="show" 330jib_show_descr="List possible NAME values for \`show NAME'" 331jib_show1_usage="show NAME" --- 82 unchanged lines hidden --- |