Tuntap: add iproute2 support

This patch was modified by William Hubbs <williamh@gentoo.org> to
document the new usage in net.example.

X-Gentoo-Bug: 394281
X-Gentoo-Bug-URL: http://bugs.gentoo.org/show_bug.cgi?id=394281
This commit is contained in:
Salah Coronya 2011-12-11 22:06:30 -06:00 committed by William Hubbs
parent 2569eb644e
commit a38a5071f3
2 changed files with 21 additions and 8 deletions

View File

@ -790,7 +790,7 @@
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
# TUN/TAP # TUN/TAP
# For TUN/TAP support emerge net-misc/openvpn or sys-apps/usermode-utilities # For TUN/TAP support install iproute2, openvpn or usermode-utilities
# #
# You must specify if we're a tun or tap device. Then you can give it any # You must specify if we're a tun or tap device. Then you can give it any
# name you like - such as vpn # name you like - such as vpn
@ -801,6 +801,9 @@
#tuntap_tap0="tap" #tuntap_tap0="tap"
#config_tap0="192.168.0.1/24" #config_tap0="192.168.0.1/24"
# Use something like this to pass custom options to iproute2 during
# tunnel creation. This sets the user and group ownership of the node.
#iproute2_tun1="user foo group bar"
# For passing custom options to tunctl use something like the following. This # For passing custom options to tunctl use something like the following. This
# example sets the owner to adm # example sets the owner to adm
#tunctl_tun1="-u adm" #tunctl_tun1="-u adm"

View File

@ -6,7 +6,7 @@ tuntap_depend()
before bridge interface macchanger before bridge interface macchanger
} }
_config_vars="$_config_vars tunctl" _config_vars="$_config_vars iproute2 openvpn tunctl"
_is_tuntap() _is_tuntap()
{ {
@ -44,28 +44,36 @@ tuntap_pre_start()
# Set the base metric to 1000 # Set the base metric to 1000
metric=1000 metric=1000
local o_opts= t_opts= do_openvpn=false do_tunctl=false local i_opts= o_opts= t_opts=
local do_iproute2=false do_openvpn=false do_tunctl=false
eval i_opts=\$iproute2_${IFVAR}
eval o_opts=\$openvpn_${IFVAR} eval o_opts=\$openvpn_${IFVAR}
eval t_opts=\$tunctl_${IFVAR} eval t_opts=\$tunctl_${IFVAR}
if [ -n "${o_opts}" ] && type openvpn >/dev/null 2>&1; then if [ -n "${i_opts}" ] && type ip >/dev/null 2>&1; then
do_iproute2=true
elif [ -n "${o_opts}" ] && type openvpn >/dev/null 2>&1; then
do_openvpn=true do_openvpn=true
elif [ -n "${t_opts}" ] && type tunctl >/dev/null 2>&1; then elif [ -n "${t_opts}" ] && type tunctl >/dev/null 2>&1; then
do_tunctl=true do_tunctl=true
elif type ip >/dev/null 2>&1; then
do_iproute2=true
elif type openvpn >/dev/null 2>&1; then elif type openvpn >/dev/null 2>&1; then
do_openvpn=true do_openvpn=true
elif type tunctl >/dev/null 2>&1; then elif type tunctl >/dev/null 2>&1; then
do_tunctl=true do_tunctl=true
fi fi
if ${do_openvpn}; then if ${do_iproute2}; then
ip tuntap add dev "${IFACE}" mode "${tuntap}" ${i_opts}
elif ${do_openvpn}; then
openvpn --mktun --dev-type "${tuntap}" --dev "${IFACE}" \ openvpn --mktun --dev-type "${tuntap}" --dev "${IFACE}" \
${o_opts} >/dev/null ${o_opts} >/dev/null
elif ${do_tunctl}; then elif ${do_tunctl}; then
tunctl ${t_opts} -t "${IFACE}" >/dev/null tunctl ${t_opts} -t "${IFACE}" >/dev/null
else else
eerror "Neither openvpn nor tunctl has been found, please install" eerror "Neither iproute2, openvpn nor tunctl has been found, please install"
eerror "either \"openvpn\" or \"usermode-utilities\"." eerror "either \"iproute2\" \"openvpn\" or \"usermode-utilities\"."
fi fi
eend $? && _up && service_set_value tuntap "${tuntap}" eend $? && _up && service_set_value tuntap "${tuntap}"
} }
@ -75,7 +83,9 @@ tuntap_post_stop()
_is_tuntap || return 0 _is_tuntap || return 0
ebegin "Destroying Tun/Tap interface ${IFACE}" ebegin "Destroying Tun/Tap interface ${IFACE}"
if type tunctl >/dev/null 2>&1; then if type ip > /dev/null 2>&1; then
ip tuntap del dev ${IFACE} mode $(service_get_value tuntap)
elif type tunctl >/dev/null 2>&1; then
tunctl -d "${IFACE}" >/dev/null tunctl -d "${IFACE}" >/dev/null
else else
openvpn --rmtun \ openvpn --rmtun \