diff options
author | hrs <hrs@FreeBSD.org> | 2013-10-10 07:41:11 +0000 |
---|---|---|
committer | hrs <hrs@FreeBSD.org> | 2013-10-10 07:41:11 +0000 |
commit | 028a23e8a8be61d8c8bf8e10c9853997db1eec58 (patch) | |
tree | 3b31c1b3747bc17ad87137a9082fa32a9ba9ecd7 /etc/network.subr | |
parent | 981609eebab29132c522028ba3265970ad0bfac0 (diff) | |
download | FreeBSD-src-028a23e8a8be61d8c8bf8e10c9853997db1eec58.zip FreeBSD-src-028a23e8a8be61d8c8bf8e10c9853997db1eec58.tar.gz |
Add support for "vnet jname" argument in ifconfig_IF. The vnet keyword
is ignored except for "rc.d/netif vnet{up,down} ifn" because a jail is
usually created after interface initialization on boot time.
"rc.d/netif vnetup ifn" moves ifn into the specified jail. It is
designed to be used in other scripts like rc.d/jail, not automatically
invoked during the interface initialization.
Approved by: re (kib)
Diffstat (limited to 'etc/network.subr')
-rw-r--r-- | etc/network.subr | 77 |
1 files changed, 67 insertions, 10 deletions
diff --git a/etc/network.subr b/etc/network.subr index 36e0140..f92cab1 100644 --- a/etc/network.subr +++ b/etc/network.subr @@ -82,6 +82,41 @@ ifn_stop() return $cfg } +# ifn_vnetup ifn +# Move ifn to the specified vnet jail. +# +ifn_vnetup() +{ + + ifn_vnet0 $1 vnet +} + +# ifn_vnetdown ifn +# Reclaim ifn from the specified vnet jail. +# +ifn_vnetdown() +{ + + ifn_vnet0 $1 -vnet +} + +# ifn_vnet0 ifn action +# Helper function for ifn_vnetup and ifn_vnetdown. +# +ifn_vnet0() +{ + local _ifn _cfg _action _vnet + _ifn="$1" + _action="$2" + _cfg=1 + + if _vnet=$(vnetif $_ifn); then + ${IFCONFIG_CMD} $_ifn $_action $_vnet && _cfg=0 + fi + + return $_cfg +} + # ifconfig_up if # Evaluate ifconfig(8) arguments for interface $if and # run ifconfig(8) with those arguments. It returns 0 if @@ -284,24 +319,27 @@ _ifconfig_getargs() # args such as DHCP and WPA. ifconfig_getargs() { - local _tmpargs _arg _args + local _tmpargs _arg _args _vnet _tmpargs=`_ifconfig_getargs $1 $2` if [ $? -eq 1 ]; then return 1 fi _args= + _vnet=0 for _arg in $_tmpargs; do - case $_arg in - [Dd][Hh][Cc][Pp]) ;; - [Nn][Oo][Aa][Uu][Tt][Oo]) ;; - [Nn][Oo][Ss][Yy][Nn][Cc][Dd][Hh][Cc][Pp]) ;; - [Ss][Yy][Nn][Cc][Dd][Hh][Cc][Pp]) ;; - [Ww][Pp][Aa]) ;; - [Hh][Oo][Ss][Tt][Aa][Pp]) ;; - *) + case $_arg:$_vnet in + [Dd][Hh][Cc][Pp]:0) ;; + [Nn][Oo][Aa][Uu][Tt][Oo]:0) ;; + [Nn][Oo][Ss][Yy][Nn][Cc][Dd][Hh][Cc][Pp]:0) ;; + [Ss][Yy][Nn][Cc][Dd][Hh][Cc][Pp]:0) ;; + [Ww][Pp][Aa]:0) ;; + [Hh][Oo][Ss][Tt][Aa][Pp]:0) ;; + vnet:0) _vnet=1 ;; + *:1) _vnet=0 ;; + *:0) _args="$_args $_arg" - ;; + ;; esac done @@ -426,6 +464,25 @@ hostapif() return 1 } +# vnetif if +# Returns 0 and echo jail if "vnet" keyword is specified on the +# interface, and 1 otherwise. +vnetif() +{ + local _tmpargs _arg _vnet + _tmpargs=`_ifconfig_getargs $1` + + _vnet=0 + for _arg in $_tmpargs; do + case $_arg:$_vnet in + vnet:0) _vnet=1 ;; + *:1) echo $_arg; return 0 ;; + esac + done + + return 1 +} + # afexists af # Returns 0 if the address family is enabled in the kernel # 1 otherwise. |