This commit is contained in:
committed by
Git OBS Bridge
parent
1b5538862e
commit
1e7aaafcb1
172
network-multinet
172
network-multinet
@@ -1,22 +1,22 @@
|
||||
#!/bin/sh
|
||||
#============================================================================
|
||||
# network-multi_net
|
||||
# network-multinet
|
||||
#
|
||||
# Version = 1.1.2
|
||||
# Date = 2007-07-11
|
||||
# Version = 1.3.1
|
||||
# Date = 2007-08-29
|
||||
#
|
||||
# Maintainer(s) = Ron Terry - ron (at) pronetworkconsulting (dot) com
|
||||
#
|
||||
# The latest version can be found at:
|
||||
#
|
||||
# http://pronetworkconsulting.com/linux/scripts/network-multi_net.html
|
||||
# http://pronetworkconsulting.com/linux/scripts/network-multinet.html
|
||||
#
|
||||
# Description:
|
||||
#
|
||||
# Replacement for the xen network-bridge, network-nat and network-route
|
||||
# scripts. This script allows for the creation of multiple bridges.
|
||||
#
|
||||
# This script can create 3 types of bridges:
|
||||
# This script can create 4 types of bridges:
|
||||
#
|
||||
# traditional bridges: -Bridges that contain both a physical network
|
||||
# device (ethX) and a virtual network device (vethX)
|
||||
@@ -55,6 +55,13 @@
|
||||
# -These can be used to allow VMs in DomUs to
|
||||
# communicate only with other DomUs and not Dom0.
|
||||
#
|
||||
# nohost bridges: -Bridges that contain a physical network device
|
||||
# but not a virtual network device from Dom0.
|
||||
# -These can be used to allow virtual machines to
|
||||
# communicate with the outside world but not with
|
||||
# Dom0. (Usefull if you want to isolate traffic
|
||||
# away from Dom0)
|
||||
#
|
||||
# This script accepts the (start|stop|restart|status) parameters.
|
||||
#
|
||||
# This script depends on an unmodified version of the network-bridge script
|
||||
@@ -96,21 +103,26 @@
|
||||
# is configured as a NAT network and the second host bridge (on veth3)
|
||||
# is configured as a hostonly network.
|
||||
#
|
||||
# Edit the NOHOST_BRIDGE_LIST variable to define which bridges you would
|
||||
# like to be connected to the outside world but not Dom0. These are
|
||||
# usefull if you want to allow VMs to access the outside world but you
|
||||
# want to isolate traffic away from Dom0.
|
||||
#
|
||||
# Edit the EMPTY_BRIDGE_LIST variable to define which empty bridges to
|
||||
# create. This list should contain the numbers of the bridges to
|
||||
# create (4 5 6 7)
|
||||
#
|
||||
# To enable this script edit the network-script field in the
|
||||
# /etc/xen/xen-config.sxp file.
|
||||
# /etc/xen/xend-config.sxp file.
|
||||
#
|
||||
# Example: (network-script network-multi_net)
|
||||
# Example: (network-script network-multinet)
|
||||
#
|
||||
# Depends on: /etc/xen/scripts/xen-network-common.sh
|
||||
# /etc/xen/scripts/network-bridge
|
||||
#
|
||||
# Config file: /etc/sysconfig/xend
|
||||
# Config file: /etc/sysconfig/xendconfig
|
||||
#
|
||||
# Usage: network-multi_net (start|stop|restart|status)
|
||||
# Usage: network-multinet (start|stop|restart|status)
|
||||
#
|
||||
# Vars:
|
||||
#
|
||||
@@ -123,11 +135,20 @@
|
||||
# LOCAL_BRIDGE_LIST -Space delimited list of virtual network devices to
|
||||
# create local bridges on using the following format:
|
||||
#
|
||||
# <virtual network device>,<mac address>,<IP address/CIDR NetMask>,<nat|hostonly|routed>
|
||||
# <virtual network device>,<mac address>,<IP address/CIDR NetMask>,<nat|hostonly|routed>,<dhcp-on|dhcp-off>
|
||||
#
|
||||
# Example with 2 virtual devices:
|
||||
#
|
||||
# "veth2,00:16:3E:01:00:02,172.22.0.1/16,nat veth3,00:16:3E:01:00:03,172.23.0.1/16,hostonly"
|
||||
# "veth2,00:16:3E:01:00:02,172.22.0.1/16,nat,dhcp-on veth3,00:16:3E:01:00:03,172.23.0.1/16,hostonly,dhcp-off"
|
||||
#
|
||||
# NOHOST_BRIDGE_LIST -Space delimited list of bridge numbers/NICs to create
|
||||
# "no-host" bridges on.
|
||||
#
|
||||
# <bridge number>,<physical network device>
|
||||
#
|
||||
# Example with 2 devices:
|
||||
#
|
||||
# "4,eth1 5.eth2"
|
||||
#
|
||||
# EMPTY_BRIDGE_LIST -Space delimited list of bridge numbers to create as
|
||||
# empty bridges.
|
||||
@@ -148,8 +169,10 @@
|
||||
. /etc/sysconfig/xend
|
||||
|
||||
SCRIPT_PATH="/etc/xen/scripts"
|
||||
CONF_FILE_PATH="/etc/xen/conf"
|
||||
NETWORK_SAVE_PATH="/var/lib/xend/network_save"
|
||||
IPTABLES_SAVE_FILE="$NETWORK_SAVE_PATH/iptables-save"
|
||||
XEN_DHCP_SCRIPT="$SCRIPT_PATH/xen-dhcpd"
|
||||
|
||||
#### Script Functions #####################################################
|
||||
|
||||
@@ -171,12 +194,17 @@ get_option() {
|
||||
esac
|
||||
}
|
||||
|
||||
make_save_dir() {
|
||||
make_config_dirs() {
|
||||
# Create temporary storage directory if needed.
|
||||
if ! [ -d "$NETWORK_SAVE_PATH" ]
|
||||
then
|
||||
mkdir $NETWORK_SAVE_PATH
|
||||
fi
|
||||
|
||||
if ! [ -d $CONF_FILE_PATH ]
|
||||
then
|
||||
mkdir $CONF_FILE_PATH
|
||||
fi
|
||||
}
|
||||
|
||||
manage_routing() {
|
||||
@@ -385,6 +413,7 @@ setup_host_interface() {
|
||||
|
||||
# bring it back up
|
||||
ip link set $DEV up
|
||||
ip link set $DEV arp on
|
||||
;;
|
||||
stop)
|
||||
# take the interface down
|
||||
@@ -580,6 +609,89 @@ create_local_bridges() {
|
||||
done
|
||||
}
|
||||
|
||||
create_nohost_bridges() {
|
||||
# Creates bridges attached to an external interface but no devices in Dom0.
|
||||
#
|
||||
# This function reads the start,stop,status parameter from the $CMD_OPT
|
||||
# variable and responds respectively.
|
||||
|
||||
echo ""
|
||||
echo "============================================================"
|
||||
for BRIDGE in $NOHOST_BRIDGE_LIST
|
||||
do
|
||||
|
||||
local DEV=`echo $BRIDGE|cut -d "," -f 1`
|
||||
local PDEV=p$DEV
|
||||
local MAC=`ip link show ${i} | grep 'link\/ether' | sed -e 's/.*ether \(..:..:..:..:..:..\).*/\1/'`
|
||||
local BRIDGE_NUM=`echo $BRIDGE|cut -d "," -f 2`
|
||||
local BR_NAME=$BRIDGE_NAME$BRIDGE_NUM
|
||||
|
||||
case $CMD_OPT in
|
||||
start)
|
||||
if ! brctl show | grep -qw "^$BR_NAME"
|
||||
then
|
||||
echo ""
|
||||
echo "============================================================"
|
||||
echo "Configuring Virtual No-Host Bridge: $BR_NAME"
|
||||
echo ""
|
||||
echo " using- Virtual Device: $DEV"
|
||||
|
||||
# create the bridge
|
||||
create_bridge $BR_NAME
|
||||
|
||||
# back up the interface's info (MAC, etc)
|
||||
echo $MAC > $NETWORK_SAVE_PATH/$DEV-info
|
||||
|
||||
# configure the interface as a bridge port
|
||||
setup_bridge_port $DEV
|
||||
|
||||
# rename the physical interface
|
||||
ip link set $DEV name $PDEV
|
||||
|
||||
# add the interface to the bridge
|
||||
add_to_bridge $BR_NAME $PDEV
|
||||
fi
|
||||
;;
|
||||
stop)
|
||||
if brctl show | grep -qw "^$BR_NAME"
|
||||
then
|
||||
echo "============================================================"
|
||||
echo "Removing Virtual No-Host Bridge: $BR_NAME"
|
||||
echo ""
|
||||
|
||||
# bring the bridge down
|
||||
ip link set $BR_NAME down
|
||||
|
||||
# remove the interface from the bridge
|
||||
brctl delif $BR_NAME $PDEV
|
||||
|
||||
# remove the bridge
|
||||
brctl delbr $BR_NAME
|
||||
|
||||
# bring the interface down
|
||||
ip link set down $PDEV
|
||||
|
||||
# reset the interface back to normal
|
||||
ip link set $PDEV arp on
|
||||
ip link set $PDEV multicast on
|
||||
|
||||
# reset the interface back to its original name and MAC
|
||||
ip link set $PDEV name $DEV
|
||||
ip link set $DEV addr `cat $NETWORK_SAVE_PATH/$DEV-info`
|
||||
rm -f `cat $NETWORK_SAVE_PATH/$DEV-info`
|
||||
|
||||
# bring the interface back up
|
||||
ifup $DEV
|
||||
fi
|
||||
;;
|
||||
status)
|
||||
brctl show $BR_NAME | grep -w "^$BR_NAME"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
echo "============================================================"
|
||||
}
|
||||
|
||||
create_empty_bridges() {
|
||||
# Creates bridges attached to no devices in Dom0.
|
||||
#
|
||||
@@ -625,12 +737,13 @@ start_xend_network() {
|
||||
echo "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
|
||||
echo " Starting the xend network environment"
|
||||
echo "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
|
||||
make_save_dir
|
||||
make_config_dirs
|
||||
manage_susefirewall2 || manage_iptables
|
||||
create_traditional_bridges
|
||||
manage_routing
|
||||
create_local_bridges
|
||||
create_empty_bridges
|
||||
create_nohost_bridges
|
||||
}
|
||||
|
||||
stop_xend_network() {
|
||||
@@ -641,6 +754,7 @@ stop_xend_network() {
|
||||
create_traditional_bridges
|
||||
create_local_bridges
|
||||
create_empty_bridges
|
||||
create_nohost_bridges
|
||||
manage_routing
|
||||
manage_susefirewall2 || manage_iptables
|
||||
}
|
||||
@@ -649,28 +763,58 @@ show_xend_network_status() {
|
||||
create_traditional_bridges
|
||||
create_local_bridges
|
||||
create_empty_bridges
|
||||
create_nohost_bridges
|
||||
}
|
||||
|
||||
#### Maid Code Body #######################################################
|
||||
#### Main Code Body #######################################################
|
||||
|
||||
get_option "$1"
|
||||
|
||||
case $CMD_OPT in
|
||||
start)
|
||||
# Start the Xen network
|
||||
start_xend_network
|
||||
|
||||
# Start the DHCP server if it exists
|
||||
if [ -e $XEN_DHCP_SCRIPT ]
|
||||
then
|
||||
$XEN_DHCP_SCRIPT start
|
||||
fi
|
||||
;;
|
||||
stop)
|
||||
# Stop the DHCP server if it exists
|
||||
if [ -e $XEN_DHCP_SCRIPT ]
|
||||
then
|
||||
$XEN_DHCP_SCRIPT stop
|
||||
fi
|
||||
|
||||
# Stop the Xen network
|
||||
stop_xend_network
|
||||
;;
|
||||
restart)
|
||||
# Stop the DHCP server if it exists
|
||||
if [ -e $XEN_DHCP_SCRIPT ]
|
||||
then
|
||||
$XEN_DHCP_SCRIPT stop
|
||||
fi
|
||||
|
||||
# Stop the Xen network
|
||||
CMD_OPT="stop"
|
||||
stop_xend_network
|
||||
|
||||
# Start the Xen network
|
||||
CMD_OPT="start"
|
||||
start_xend_network
|
||||
|
||||
# Start the DHCP server if it exists
|
||||
if [ -e $XEN_DHCP_SCRIPT ]
|
||||
then
|
||||
$XEN_DHCP_SCRIPT start
|
||||
fi
|
||||
;;
|
||||
status)
|
||||
show_xend_network_status
|
||||
$XEN_DHCP_SCRIPT status
|
||||
;;
|
||||
esac
|
||||
|
||||
|
Reference in New Issue
Block a user