Date: Mon, 5 May 2003 22:29:35 -0700 From: "Sean Hamilton" <sh@planetquake.com> To: <hackers@freebsd.org> Subject: Bridge config in /etc/rc (patch) Message-ID: <011901c31390$7aef5730$0300000a@antalus>
index | next in thread | raw e-mail
[-- Attachment #1 --]
Greetings,
As I manage three FreeBSD bridges, I found it somewhat irritating that there
was no convenient way of doing so. Thus, this patch. Should it get approved,
I'll write diffs for the man pages, /etc/defaults/rc.conf, and anything else
which needs it.
I've updated both the old /etc/rc.network and the new rcng stuff, though
only the latter is tested.
Configuration goes like this:
bridge_enable="YES"
bridge_ifaces="fxp0,fxp1,fxp2"
or, for multiple bridges
bridge_enable="YES"
bridge0_ifaces="fxp3,fxp4,fxp5"
bridge1_ifaces="rl0,rl1,dc0"
Both comma-separated and space-separated lists are accepted.
Also allowed:
bridge_ipfw="YES"
bridge_ipfilter="YES"
I've also added an option, "ip_any_interface=YES" which sets
net.inet.ip.check_interface to 0. This felt more natural than having the
option, "ip_check_interface=NO".
This is a first for me on several counts, so hopefully I've got everything
right. Or should I be submitting this as a PR? It's not really a problem,
so...
sh
[-- Attachment #2 --]
diff -Nru etcorig/rc.d/bridge etc/rc.d/bridge
--- etcorig/rc.d/bridge Wed Dec 31 16:00:00 1969
+++ etc/rc.d/bridge Mon May 5 22:08:11 2003
@@ -0,0 +1,85 @@
+#!/bin/sh -x
+
+# PROVIDE: bridge
+# REQUIRE: ipfw ip6fw ipfilter
+# KEYWORD: FreeBSD
+
+. /etc/rc.subr
+
+name="bridge"
+start_cmd="bridge_start"
+stop_cmd="bridge_stop"
+
+bridge_start()
+{
+ case ${bridge_enable} in
+ [Yy][Ee][Ss])
+
+ bridge_in_kernel=1
+
+ if ! sysctl net.link.ether.bridge >/dev/null 2>&1; then
+ if kldload bridge; then
+ echo 'Bridge module loaded'
+ else
+ echo 'Warning: Bridge module failed to load.'
+ bridge_in_kernel=0
+ fi
+ fi
+
+ if [ "${bridge_in_kernel}" -eq 1 ]; then
+
+ bridgenum=
+ bridgecfg=
+
+ while : ; do
+ eval bridge_args=\$bridge${bridgenum}_ifaces
+ if [ -n "${bridge_args}" ]; then
+ bridge_args=`echo -n "${bridge_args}" | sed 's/,/ /'`
+ for iface in ${bridge_args}; do
+ if [ -n "${bridgecfg}" ]; then
+ bridgecfg=${bridgecfg},
+ fi
+ bridgecfg=${bridgecfg}${iface}:$((${bridgenum:--1} + 1))
+ done
+ else
+ if [ -n "${bridgenum}" ]; then
+ break;
+ fi
+ fi
+ bridgenum=$((${bridgenum:--1} + 1))
+ done
+
+ case ${bridge_ipfw} in
+ [Yy][Ee][Ss])
+ sysctl net.link.ether.bridge_ipfw=1 >/dev/null
+ ;;
+ esac
+
+ case ${bridge_ipfilter} in
+ [Yy][Ee][Ss])
+ sysctl net.link.ether.bridge_ipf=1 >/dev/null
+ ;;
+ esac
+
+ sysctl net.link.ether.bridge_cfg="${bridgecfg}" >/dev/null
+ sysctl net.link.ether.bridge=1 >/dev/null
+ fi
+ ;;
+ esac
+}
+
+bridge_stop()
+{
+ sysctl net.link.ether.bridge=0 >/dev/null
+ sysctl net.link.ether.bridge_cfg= >/dev/null
+ sysctl net.link.ether.bridge_ipfw=0 >/dev/null
+ sysctl net.link.ether.bridge_ipf=0 >/dev/null
+
+ if kldstat -n bridge >/dev/null 2>&1; then
+ kldunload bridge
+ fi
+}
+
+load_rc_config $name
+run_rc_command "$1"
+
diff -Nru etcorig/rc.d/network2 etc/rc.d/network2
--- etcorig/rc.d/network2 Mon May 5 22:05:19 2003
+++ etc/rc.d/network2 Mon May 5 22:05:42 2003
@@ -115,6 +115,13 @@
;;
esac
+ case ${ip_any_interface} in
+ [Yy][Ee][Ss])
+ echo -n ' any interface=YES'
+ sysctl net.inet.ip.check_interface=0 >/dev/null
+ ;;
+ esac
+
case ${ip_portrange_first} in
[Nn][Oo] | '')
;;
diff -Nru etcorig/rc.network etc/rc.network
--- etcorig/rc.network Mon May 5 21:58:12 2003
+++ etc/rc.network Mon May 5 21:59:50 2003
@@ -393,6 +393,66 @@
;;
esac
+ # Bridge
+ #
+ case ${bridge_enable} in
+ [Yy][Ee][Ss])
+
+ bridge_in_kernel=1
+ if ! sysctl net.link.ether.bridge >/dev/null 2>&1; then
+ if kldload bridge; then
+ echo 'Bridge module loaded'
+ else
+ echo 'Warning: Bridge module failed to load.'
+ bridge_in_kernel=0
+ fi
+ fi
+
+ if [ "${bridge_in_kernel}" -eq 1 ]; then
+ bridgenum=
+ bridgecfg=
+ while : ; do
+ eval bridge_args=\$bridge${bridgenum}_ifaces
+ if [ -n "${bridge_args}" ]; then
+ bridge_args=`echo -n "${bridge_args}" | sed 's/,/ /'`
+ for iface in ${bridge_args}; do
+ if [ -n "${bridgecfg}" ]; then
+ bridgecfg=${bridgecfg},
+ fi
+ bridgecfg=${bridgecfg}${iface}:$((${bridgenum:--1} + 1))
+ done
+ else
+ if [ -n "${bridgenum}" ]; then
+ break;
+ fi
+ fi
+ bridgenum=$((${bridgenum:--1} + 1))
+ done
+
+ case ${bridge_ipfw} in
+ [Yy][Ee][Ss])
+ sysctl net.link.ether.bridge_ipfw=1 >/dev/null
+ ;;
+ esac
+
+ case ${bridge_ipfilter} in
+ [Yy][Ee][Ss])
+ sysctl net.link.ether.bridge_ipf=1 >/dev/null
+ ;;
+ esac
+
+ sysctl net.link.ether.bridge_cfg="${bridgecfg}" >/dev/null
+ sysctl net.link.ether.bridge=1 >/dev/null
+ fi
+ ;;
+ esac
+
+ case ${ip_any_interface} in
+ [Yy][Ee][Ss])
+ sysctl net.inet.ip.check_interface=0 >/dev/null
+ ;;
+ esac
+
# Additional ATM interface configuration
#
if [ -n "${atm_pass1_done}" ]; then
help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?011901c31390$7aef5730$0300000a>
