#! /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" LOCATION=/data/cisco export PATH="${PATH:+$PATH:}/bin:/usr/bin:/usr/sbin:/sbin" if [ -f $DYNADIR/config ]; then . $DYNADIR/config HOST_IP=${HOST_IPADDR%\/*} 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 ifconfig $HOST_IF 0.0.0.0 promisc brctl addif br0 $HOST_IF # Bring up br0 ip l s dev eth1 up 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 brctl delif br0 $TAP tunctl -d $TAP done } ################################################################################ # RUN case "$1" in start) enable_bridge enable_taps chown $DYNA_USER.wheel /dev/net/tun chmod 0666 /dev/net/tun $LOCATION/dynamips-0.2.8-RC2-x86.bin -H 7210 & su -c "screen -d -S termserv -m $LOCATION/dynagen/dynagen $LOCATION/ts.net" $DYNA_USER ;; stop) disable_taps disable_bridge kill -9 `ps -ef | grep dyna | grep 7210 | tr -s [:space:] " " | cut -d\ -f2` ;; 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