Merge pull request #13662 from benpicco/tapsetup-uplink
tapsetup: add --uplink option
This commit is contained in:
commit
e9fdee073c
42
dist/tools/tapsetup/tapsetup
vendored
42
dist/tools/tapsetup/tapsetup
vendored
@ -6,6 +6,7 @@ COMMAND=""
|
|||||||
BRNAME="tapbr0"
|
BRNAME="tapbr0"
|
||||||
TAPNAME="tap"
|
TAPNAME="tap"
|
||||||
DEACTIVATE_IPV6=""
|
DEACTIVATE_IPV6=""
|
||||||
|
UPLINK=""
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
echo "usage: ${PROGRAM} [arguments]" >&2
|
echo "usage: ${PROGRAM} [arguments]" >&2
|
||||||
@ -22,6 +23,8 @@ usage() {
|
|||||||
echo " (default: tap; ignored on OSX and FreeBSD)" >&2
|
echo " (default: tap; ignored on OSX and FreeBSD)" >&2
|
||||||
echo " -6, --deactivate-ipv6: Deactivate IPv6 for the interfaces and bridge" >&2
|
echo " -6, --deactivate-ipv6: Deactivate IPv6 for the interfaces and bridge" >&2
|
||||||
echo " (ignored on OSX and FreeBSD)" >&2
|
echo " (ignored on OSX and FreeBSD)" >&2
|
||||||
|
echo " -u, --uplink: Optional uplink interface" >&2
|
||||||
|
echo " (ignored on OSX and FreeBSD)" >&2
|
||||||
echo " -h, --help: Prints this text" >&2
|
echo " -h, --help: Prints this text" >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,6 +33,16 @@ unsupported_plattform() {
|
|||||||
echo "(currently supported \`uname -s\` 'Darvin', 'FreeBSD', and 'Linux')" >&2
|
echo "(currently supported \`uname -s\` 'Darvin', 'FreeBSD', and 'Linux')" >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
update_uplink() {
|
||||||
|
if command -v dhclient > /dev/null; then
|
||||||
|
dhclient $1
|
||||||
|
else
|
||||||
|
echo "DHCP client \`dhclient\` not found." >&2
|
||||||
|
echo "Please reconfigure your DHCP client for interface $1" >&2
|
||||||
|
echo "to keep up-link's IPv4 connection." >&2
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
create_bridge() {
|
create_bridge() {
|
||||||
echo "creating ${BRNAME}"
|
echo "creating ${BRNAME}"
|
||||||
|
|
||||||
@ -39,6 +52,10 @@ create_bridge() {
|
|||||||
ifconfig ${BRNAME} create || exit 1 ;;
|
ifconfig ${BRNAME} create || exit 1 ;;
|
||||||
Linux)
|
Linux)
|
||||||
ip link add name ${BRNAME} type bridge || exit 1
|
ip link add name ${BRNAME} type bridge || exit 1
|
||||||
|
if [ -n "${UPLINK}" ]; then
|
||||||
|
echo "using uplink ${UPLINK}"
|
||||||
|
ip link set dev ${UPLINK} master ${BRNAME} || exit 1
|
||||||
|
fi
|
||||||
if [ -n "${DEACTIVATE_IPV6}" ]; then
|
if [ -n "${DEACTIVATE_IPV6}" ]; then
|
||||||
echo 1 > /proc/sys/net/ipv6/conf/${BRNAME}/disable_ipv6 || exit 1
|
echo 1 > /proc/sys/net/ipv6/conf/${BRNAME}/disable_ipv6 || exit 1
|
||||||
fi ;;
|
fi ;;
|
||||||
@ -54,7 +71,12 @@ up_bridge() {
|
|||||||
FreeBSD|OSX)
|
FreeBSD|OSX)
|
||||||
ifconfig ${BRNAME} up || exit 1 ;;
|
ifconfig ${BRNAME} up || exit 1 ;;
|
||||||
Linux)
|
Linux)
|
||||||
ip link set ${BRNAME} up || exit 1 ;;
|
ip link set ${BRNAME} up || exit 1
|
||||||
|
|
||||||
|
# The bridge is now the new uplink
|
||||||
|
if [ -n "${UPLINK}" ]; then
|
||||||
|
update_uplink ${BRNAME}
|
||||||
|
fi ;;
|
||||||
*)
|
*)
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
@ -70,10 +92,17 @@ delete_bridge() {
|
|||||||
kldunload if_bridge || exit 1 ;;
|
kldunload if_bridge || exit 1 ;;
|
||||||
Linux)
|
Linux)
|
||||||
for IF in $(ls /sys/class/net/${BRNAME}/brif); do
|
for IF in $(ls /sys/class/net/${BRNAME}/brif); do
|
||||||
|
if [ ${IF} != ${UPLINK} ]; then
|
||||||
ip link delete "${IF}"
|
ip link delete "${IF}"
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
ip link delete ${BRNAME} || exit 1 ;;
|
ip link delete ${BRNAME} || exit 1
|
||||||
|
|
||||||
|
# restore the old uplink
|
||||||
|
if [ -n "${UPLINK}" ]; then
|
||||||
|
update_uplink ${UPLINK}
|
||||||
|
fi ;;
|
||||||
OSX)
|
OSX)
|
||||||
ifconfig ${BRNAME} destroy || exit 1 ;;
|
ifconfig ${BRNAME} destroy || exit 1 ;;
|
||||||
*)
|
*)
|
||||||
@ -158,6 +187,15 @@ while true ; do
|
|||||||
-h|--help)
|
-h|--help)
|
||||||
usage
|
usage
|
||||||
exit ;;
|
exit ;;
|
||||||
|
-u|--uplink)
|
||||||
|
case "$2" in
|
||||||
|
"")
|
||||||
|
usage
|
||||||
|
exit 2 ;;
|
||||||
|
*)
|
||||||
|
UPLINK="$2"
|
||||||
|
shift 2 ;;
|
||||||
|
esac ;;
|
||||||
-t|--tap)
|
-t|--tap)
|
||||||
case "$2" in
|
case "$2" in
|
||||||
"")
|
"")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user