#! /bin/bash . /usr/lib/network/network tunnel_up() { load_profile "$1" if [ -e /sys/class/net/$INTERFACE ]; then report_fail "Interface $INTERFACE already exists." exit 1 else ip tunnel add "$INTERFACE" mode "$MODE" \ remote "$REMOTE" local "$LOCAL" ttl "$TTL" &>/dev/null fi bring_interface up "$INTERFACE" case "$IP" in static) if [[ -n "$ADDR" ]]; then [[ -z $NETMASK ]] && NETMASK=24 report_debug tunnel_up ip addr add "$ADDR/$NETMASK" brd + dev "$INTERFACE" if ! ip addr add "$ADDR/$NETMASK" brd + dev "$INTERFACE"; then report_iproute "Could not configure interface" fi fi if [[ -n "$IFOPTS" ]]; then if ! ifconfig "$INTERFACE" $IFOPTS up; then report_iproute "Bringing interface up failed." return 1 fi fi if [[ -n "$ROUTES" ]]; then for route in "${ROUTES[@]}"; do report_debug tunnel_up ip route add $route dev "$INTERFACE" if ! ip route add $route dev "$INTERFACE" ; then report_iproute "Adding route '$route' failed" fi done fi if [[ -n "$GATEWAY" ]]; then report_debug tunnel_up ip route add default via "$GATEWAY" dev "$INTERFACE" if ! ip route add default via "$GATEWAY" dev "$INTERFACE"; then report_iproute "Adding gateway $GATEWAY failed" fi fi ;; ""|no) ;; *) report_iproute "IP must be either 'static' or 'no'" ;; esac if [[ -n "$IPCFG" ]]; then for line in "${IPCFG[@]}"; do report_debug tunnel_up ip "$line" if ! ip $line; then report_iproute "Could not configure interface ($line)." fi done fi # Load ipv6 module if necessary (FS#25530) case "$IP6" in stateless|static) [ -d "/proc/sys/net/ipv6" ] || modprobe ipv6 ;; ""|no) [ -d /proc/sys/net/ipv6 ] && sysctl -q -w net.ipv6.conf.$INTERFACE.accept_ra=0 ;; *) report_iproute "IP6 must be 'stateless', 'static' or 'no'" ;; esac case "$IP6" in stateless) sysctl -q -w net.ipv6.conf.$INTERFACE.accept_ra=1 ;; static) sysctl -q -w net.ipv6.conf.$INTERFACE.accept_ra=0 if [[ -n "$ADDR6" ]]; then for addr in "${ADDR6[@]}"; do report_debug tunnel_up ip -6 addr add "$addr" dev "$INTERFACE" if ! ip -6 addr add "$addr" dev "$INTERFACE"; then report_iproute "Could not add address $addr to interface" fi done fi if [[ -n "$GATEWAY6" ]]; then report_debug tunnel_up ip -6 route add default via "$GATEWAY6" dev "$INTERFACE" if ! ip -6 route add default via "$GATEWAY6" dev "$INTERFACE"; then report_iproute "Adding gateway $GATEWAY6 failed" fi fi # Add static IPv6 routes if [[ -n "$ROUTES6" ]]; then for route in "${ROUTES6[@]}"; do report_debug tunnel_up ip -6 route add $route dev $INTERFACE if ! ip -6 route add $route dev $INTERFACE ; then report_iproute "Adding route '$route' failed" fi done fi ;; esac return 0 } tunnel_down() { load_profile "$1" bring_interface down "$INTERFACE" ip tunnel del "$INTERFACE" mode "$MODE" \ remote "$REMOTE" local "$LOCAL" ttl "$TTL" &>/dev/null return 0 } tunnel_status() { if [ -e /sys/class/net/$INTERFACE ]; then return 0 else return 1 fi } tunnel_$1 "$2" exit $? # vim: set ts=4 et sw=4 tw=0: