#!/bin/sh # ################################################################################ # # # /etc/rc.d/rc.bridge_tuntap R00-00.00 # # # # ============================================================================ # # # # Purpose: # # # # Set-up a bridge environment for Virtual Machines # # # # ============================================================================ # # # # Arguments: # # # # Arg 1 - The specific function or operation to invoke for processing. The # # - valid values are : # # - # # - start # # - stop # # - _start (interface is tapN) # # - _stop # # - status # # - show # # # # ============================================================================ # # # # Programming Notes: # # # # Interfaces using the notation ethN:M appear to be stopped whe the bridge # # environment is set-up. These interfaces can be re-actived by doing : # # # # /etc/rc.d/rc.inet1 ethN:M_start # # # # where N and M are substituted with the appropriate values such as : # # # # /etc/rc.d/rc.inet1 eth0:0_start # # # # The ":" will need to be escaped as "eth0\:0_start" as it causes the script # # to do some unwanted substitutions. The script would be used as follows: # # # # /etc/rc.d/rc.bridge_tuntap start # # /etc/rc.d/rc.inet1 eth0\:0_start # # /etc/rc.d/rc.bridge_tuntap tap0_start # # # # Much appreciation to http://sfxpt.wordpress.com/2011/02/08/manually-... # # for the useful information on the kvm/tun/bridge information. And the other # # sites which had useful information as well. # # # # ============================================================================ # # # # Revision: # # # # Revision Who When Why # # ========= =========== =========== ======================================= # # R00-00.00 DRLJr/I-AS 19/Oct/2012 Script created # # # ################################################################################ # #==============================================================================# # Get the existing IP address configurations # #==============================================================================# # . /etc/rc.d/rc.inet1.conf # #==============================================================================# # # # Set up the bridge interface device # # # # Arg 1 : Bridge Device Name # # Arg 2 : Ethernet Device Name # # Arg 3 : Bridge IPv4 address # # Arg 4 : Bridge IPv4 netmask # # # #==============================================================================# # set_up_bridge() { echo "Activating bridge $1 for Ethernet interface $2 at IPv4 $3 with Netmask $4" /usr/sbin/brctl addbr $1 /usr/sbin/brctl addif $1 $2 /usr/sbin/brctl stp $1 on /usr/sbin/ip addr flush $2 /sbin/ifconfig $2 0.0.0.0 /sbin/ifconfig $1 $3 netmask $4 up return } # #==============================================================================# # # # Take down the bridge interface device # # # # Arg 1 : Bridge Device Name # # Arg 2 : Ethernet Device Name # # # #==============================================================================# # take_down_bridge() { echo "Deactivating bridge $1 Ethernet interface $2" /usr/sbin/brctl delif $1 $2 /sbin/ifconfig $1 down /usr/sbin/brctl delbr $1 /etc/rc.d/rc.inet1 $2_start return } # #==============================================================================# # # # Set up the tun/tap interface device # # # # Arg 1 : Bridge Device Name # # Arg 2 : Tunnel Device Name # # # #==============================================================================# # set_up_tuntap() { echo "Activating tun/tap $2 on Bridge $1" # # Insure the module is loaded and kvm group exists # echo "modprobe" /sbin/modprobe tun KVMGRP="`grep '^kvm:' /etc/group 2> /dev/null`" if [ "${KVMGRP}" = "" ] ; then echo " " echo "/etc/rc.d/rc.bridge_tuntap : Group kvm does not exist." echo " " KVMOPT="" else KVMOPT="-g kvm" fi # # echo "tunctl" /usr/sbin/tunctl -t $2 ${KVMOPT} # echo "brctl" /usr/sbin/brctl addif $1 $2 # echo "ifconfig" /sbin/ifconfig $2 0.0.0.0 return } # #==============================================================================# # # # Take down the tun/tap interface device # # # # Arg 1 : Bridge Device Name # # Arg 2 : Tunnel Device Name # # # #==============================================================================# # take_down_tuntap() { echo "Deactivating Tunnel $2 on Bridge $1" /usr/sbin/brctl delif $1 $2 /usr/sbin/tunctl -d $2 return } # #==============================================================================# # # # start function # # # #==============================================================================# # start() { # indx=0 # if [ "${BRIDGE[${indx}]}" = "" ] ; then BRIDGE="br0" else BRIDGE="${BRIDGE[${indx}]}" fi # if [ "${IFNAME[${indx}]}" = "" ] ; then INTF="eth0" else INTF="${IFNAME[${indx}]}" fi # IPV4="${IPADDR[${indx}]}" NMSK="${NETMASK[${indx}]}" # set_up_bridge ${BRIDGE} ${INTF} ${IPV4} ${NMSK} # return } # #==============================================================================# # # # start_tuntap # # # #==============================================================================# # start_tuntap() { # indx=0 # if [ "${BRIDGE[${indx}]}" = "" ] ; then BRIDGE="br0" else BRIDGE="${BRIDGE[${indx}]}" fi # INTF="$1" # set_up_tuntap ${BRIDGE} ${INTF} # return } # # #==============================================================================# # # # stop function # # # #==============================================================================# # stop() { # indx=0 # if [ "${BRIDGE[${indx}]}" = "" ] ; then BRIDGE="br0" else BRIDGE="${BRIDGE[${indx}]}" fi # if [ "${IFNAME[${indx}]}" = "" ] ; then INTF="eth0" else INTF="${IFNAME[${indx}]}" fi # IPV4="${IPADDR[${indx}]}" NMSK="${NETMASK[${indx}]}" # take_down_bridge ${BRIDGE} ${INTF} # return } # #==============================================================================# # # # stop_tuntap # # # #==============================================================================# # stop_tuntap() { # indx=0 # if [ "${BRIDGE[${indx}]}" = "" ] ; then BRIDGE="br0" else BRIDGE="${BRIDGE[${indx}]}" fi # INTF="$1" # take_down_tuntap ${BRIDGE} ${INTF} # return } # #==============================================================================# # Main Processing # #==============================================================================# echo " " echo "$0 : $1" echo " " case "$1" in #============================================================================# # # #============================================================================# 'start') start ;; #============================================================================# # # #============================================================================# 'stop') stop ;; #============================================================================# # # #============================================================================# *_start) INTERFACE=`echo $1 | /bin/cut -d '_' -f 1` start_tuntap ${INTERFACE} ;; #============================================================================# # # #============================================================================# *_stop) INTERFACE=`echo $1 | /bin/cut -d '_' -f 1` stop_tuntap ${INTERFACE} ;; #============================================================================# # # #============================================================================# 'status') /usr/sbin/brctl show ;; #============================================================================# # # #============================================================================# 'show') /usr/sbin/brctl show ;; #============================================================================# # # #============================================================================# *) echo " " echo "/etc/rc.d/rc.bridge_tuntap : Argument \"$1\" is not supported/known" echo " " ;; #============================================================================# # # #============================================================================# esac ################################################################################ # # ################################################################################