ether.bridge (79035) | ether.bridge (94477) |
---|---|
1#!/bin/sh | 1#!/bin/sh |
2# $FreeBSD: head/share/examples/netgraph/ether.bridge 79035 2001-06-30 21:39:31Z dd $ 3 | 2# $FreeBSD: head/share/examples/netgraph/ether.bridge 94477 2002-04-12 04:44:53Z julian $ |
4# This script sets up an Ethernet bridging network across multiple 5# Ethernet interfaces using the ng_bridge(4) and ng_ether(4) netgraph 6# node types. 7# 8# To use this script: 9# 10# 0. Make your own copy of this example script 11# 12# 1. Give your bridging network a name by editing the definition of 13# ${BRIDGE_NAME} below. It must be a valid netgraph node name. 14# | 3# This script sets up an Ethernet bridging network across multiple 4# Ethernet interfaces using the ng_bridge(4) and ng_ether(4) netgraph 5# node types. 6# 7# To use this script: 8# 9# 0. Make your own copy of this example script 10# 11# 1. Give your bridging network a name by editing the definition of 12# ${BRIDGE_NAME} below. It must be a valid netgraph node name. 13# |
15# 2. Edit the definitions of ${BRIDGE_IFACES} and ${LOCAL_IFACE} | 14# 2. Edit the definitions of ${BRIDGE_IFACES} and ${LOCAL_IFACES} |
16# as described below to define your bridging interfaces. 17# 18# 3. Run this script with "start" as the command line argument. 19# 20# 4. Examine bridging statistics by running this script with "stats" 21# as the command line argument. 22# 23# 5. Stop bridging by running this script with "stop" as the 24# command line argument. 25# 26# To run multiple independent bridging networks, create multiple 27# copies of this script with different variable definitions. | 15# as described below to define your bridging interfaces. 16# 17# 3. Run this script with "start" as the command line argument. 18# 19# 4. Examine bridging statistics by running this script with "stats" 20# as the command line argument. 21# 22# 5. Stop bridging by running this script with "stop" as the 23# command line argument. 24# 25# To run multiple independent bridging networks, create multiple 26# copies of this script with different variable definitions. |
27# 28# To make a "brouted" network, with IP being routed and other protocols being 29# bridged, add all the interface in the BRIDGE_IFACES to the LOCAL_IFACES. 30# I you just want a normal bridge, just one will surfice. 31# in some cases you may want some mixture. |
|
28# 29 30# Give each bridging network a unique name here 31 32BRIDGE_NAME="bnet0" 33 34# List the names of the interfaces that you want to bridge across 35# here in ${BRIDGE_IFACES}. If you want to include the local host | 32# 33 34# Give each bridging network a unique name here 35 36BRIDGE_NAME="bnet0" 37 38# List the names of the interfaces that you want to bridge across 39# here in ${BRIDGE_IFACES}. If you want to include the local host |
36# machine as well then set ${LOCAL_IFACE} as well (it may also be | 40# machine as well then set ${LOCAL_IFACES} as well (they may also be |
37# listed in ${BRIDGE_IFACES}). Of course, any ${LOCAL_IFACE} must 38# be ifconfig(8)ured separately. If you don't want a ${LOCAL_IFACE} 39# then leave it defined as the emtpy string. 40 | 41# listed in ${BRIDGE_IFACES}). Of course, any ${LOCAL_IFACE} must 42# be ifconfig(8)ured separately. If you don't want a ${LOCAL_IFACE} 43# then leave it defined as the emtpy string. 44 |
41BRIDGE_IFACES="ed0 fxp0 fxp1" 42LOCAL_IFACE="fxp0" | 45BRIDGE_IFACES="de0 fxp0 fxp1" 46LOCAL_IFACES="fxp0 fxp1" |
43 44#################################################################### 45#### Everything below this point should not need to be modified #### 46#################################################################### 47 48# Routine to verify node's existence 49bridge_verify() { 50 ngctl info ${BRIDGE_NAME}: >/dev/null 2>&1 --- 25 unchanged lines hidden (view full) --- 76 echo "done" 77 fi 78 done 79 80 # Reset all interfaces 81 bridge_stop 82 83 # Verify all interfaces exist | 47 48#################################################################### 49#### Everything below this point should not need to be modified #### 50#################################################################### 51 52# Routine to verify node's existence 53bridge_verify() { 54 ngctl info ${BRIDGE_NAME}: >/dev/null 2>&1 --- 25 unchanged lines hidden (view full) --- 80 echo "done" 81 fi 82 done 83 84 # Reset all interfaces 85 bridge_stop 86 87 # Verify all interfaces exist |
84 for ETHER in ${BRIDGE_IFACES} ${LOCAL_IFACE}; do | 88 for ETHER in ${BRIDGE_IFACES} ${LOCAL_IFACES}; do |
85 if ngctl info ${ETHER}: >/dev/null 2>&1; then 86 else 87 echo "Error: interface ${ETHER} does not exist" 88 exit 1 89 fi 90 ifconfig ${ETHER} up || exit 1 91 done 92 --- 8 unchanged lines hidden (view full) --- 101 if [ ${LINKNUM} != 0 ]; then 102 ngctl connect ${ETHER}: ${BRIDGE_NAME}: \ 103 lower link${LINKNUM} || exit 1 104 fi 105 LINKNUM=`expr ${LINKNUM} + 1` 106 done 107 108 # Hook up local interface, if any | 89 if ngctl info ${ETHER}: >/dev/null 2>&1; then 90 else 91 echo "Error: interface ${ETHER} does not exist" 92 exit 1 93 fi 94 ifconfig ${ETHER} up || exit 1 95 done 96 --- 8 unchanged lines hidden (view full) --- 105 if [ ${LINKNUM} != 0 ]; then 106 ngctl connect ${ETHER}: ${BRIDGE_NAME}: \ 107 lower link${LINKNUM} || exit 1 108 fi 109 LINKNUM=`expr ${LINKNUM} + 1` 110 done 111 112 # Hook up local interface, if any |
109 if [ "${LOCAL_IFACE}" != "" ]; then | 113 for LOCAL_IFACE in ${LOCAL_IFACES}; do |
110 ngctl connect ${LOCAL_IFACE}: ${BRIDGE_NAME}: \ 111 upper link${LINKNUM} || exit 1 | 114 ngctl connect ${LOCAL_IFACE}: ${BRIDGE_NAME}: \ 115 upper link${LINKNUM} || exit 1 |
112 fi | 116 LINKNUM=`expr ${LINKNUM} + 1` 117 done |
113 114 # Set all interfaces in promiscuous mode and don't overwrite src addr 115 for ETHER in ${BRIDGE_IFACES}; do 116 ngctl msg ${ETHER}: setpromisc 1 || exit 1 117 ngctl msg ${ETHER}: setautosrc 0 || exit 1 118 done 119} 120 121# Stop routine 122bridge_stop() { 123 ngctl kill ${BRIDGE_NAME}: >/dev/null 2>&1 | 118 119 # Set all interfaces in promiscuous mode and don't overwrite src addr 120 for ETHER in ${BRIDGE_IFACES}; do 121 ngctl msg ${ETHER}: setpromisc 1 || exit 1 122 ngctl msg ${ETHER}: setautosrc 0 || exit 1 123 done 124} 125 126# Stop routine 127bridge_stop() { 128 ngctl kill ${BRIDGE_NAME}: >/dev/null 2>&1 |
124 for ETHER in ${BRIDGE_IFACES} ${LOCAL_IFACE}; do | 129 for ETHER in ${BRIDGE_IFACES} ${LOCAL_IFACES}; do |
125 ngctl kill ${ETHER}: >/dev/null 2>&1 126 done 127} 128 129# Stats routine 130bridge_stats() { 131 132 # Make sure node exists 133 bridge_verify 134 135 echo "" 136 echo "Statistics for bridging network ${BRIDGE_NAME}:" 137 echo "" 138 LINKNUM=0 139 for ETHER in ${BRIDGE_IFACES}; do 140 echo "Network interface ${ETHER}:" 141 bridge_linkstats ${LINKNUM} 142 LINKNUM=`expr ${LINKNUM} + 1` 143 done | 130 ngctl kill ${ETHER}: >/dev/null 2>&1 131 done 132} 133 134# Stats routine 135bridge_stats() { 136 137 # Make sure node exists 138 bridge_verify 139 140 echo "" 141 echo "Statistics for bridging network ${BRIDGE_NAME}:" 142 echo "" 143 LINKNUM=0 144 for ETHER in ${BRIDGE_IFACES}; do 145 echo "Network interface ${ETHER}:" 146 bridge_linkstats ${LINKNUM} 147 LINKNUM=`expr ${LINKNUM} + 1` 148 done |
144 if [ "${LOCAL_IFACE}" != "" ]; then | 149 for LOCAL_IFACE in ${LOCAL_IFACES}; do |
145 echo "Local host interface ${LOCAL_IFACE}:" 146 bridge_linkstats ${LINKNUM} | 150 echo "Local host interface ${LOCAL_IFACE}:" 151 bridge_linkstats ${LINKNUM} |
147 fi | 152 LINKNUM=`expr ${LINKNUM} + 1` 153 done |
148} 149 150# Main entry point 151case $1 in 152 start) 153 bridge_start 154 ;; 155 stats) --- 12 unchanged lines hidden --- | 154} 155 156# Main entry point 157case $1 in 158 start) 159 bridge_start 160 ;; 161 stats) --- 12 unchanged lines hidden --- |