#! /bin/sh ### BEGIN INIT INFO # Provides: dyna # Required-Start: $local_fs $syslog $remote_fs # Required-Stop: $local_fs $syslog $remote_fs # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Enable Tap and Bridge interfaces. ### END INIT INFO # #This script configure the machine to use br0 and specified tap interfaces #original credits go to http://farfewertoes.com/. # . /lib/lsb/init-functions # Are we running from init? run_by_init() { ([ "$previous" ] && [ "$runlevel" ]) || [ "$runlevel" = S ] } ################################################################################ # INITIAL CONFIGURATION DYNADIR="/etc/dynamips" export PATH="${PATH:+$PATH:}/bin:/usr/bin:/usr/sbin:/sbin" if [ -f $DYNADIR/config ]; then . $DYNADIR/config else echo "ERROR: $DYNADIR/config does not exist. Exiting." exit 1 fi ################################################################################ # FUNCTIONS # Bring up the bridge interface enable_bridge() { # Load the tun module if [ ! -e /dev/net/tun ]; then modprobe tun fi brctl addbr br0 || /bin/true # Disable $HOST_IF; host will use br0 instead #ip l s dev $HOST_IF down ip l s dev $HOST_IF up ifconfig $HOST_IF 0.0.0.0 promisc brctl addif br0 $HOST_IF # Bring up br0 ip l s dev br0 up if [ $HOST_SETUP = dhcp ] then dhclient br0 else ip a a $HOST_IPADDR dev br0 ip r a default via $HOST_GW fi } # Bring down the bridge interface disable_bridge() { ifdown br0 brctl delbr br0 ifup $HOST_IF } # Activate tap interfaces enable_taps() { for TAP in $TAPS; do # Check if $TAP is configured already ifconfig $TAP > /dev/null 2>&1 if [ $? != 0 ]; then tunctl -t $TAP -u $DYNA_USER brctl addif br0 $TAP # Disable tap interfaces for host; guest will activate them for themselves ip l s dev $TAP up # Enable proxy_arp so that ARP requests can be answered correctly # by the host echo 1 > /proc/sys/net/ipv4/conf/$TAP/proxy_arp else log_failure_msg "Interface $TAP already configured" fi done } # Disable/deconfigure tap interfaces disable_taps() { for TAP in $TAPS; do route del -host $HOST_IP dev $TAP brctl delif br0 $TAP tunctl -d $TAP done } ################################################################################ # RUN case "$1" in start) enable_bridge enable_taps chown $DYNA_USER.users /dev/net/tun chmod 0666 /dev/net/tun ;; stop) disable_taps disable_bridge ;; bridge-up) enable_bridge ;; bridge-down) disable_bridge ;; taps-up) enable_taps ;; taps-down) disable_taps ;; *) log_failure_msg "Usage: $0 {start|stop|bridge-up|bridge-down|taps-up|taps-down}" exit 3 esac exit 0