xref: /freebsd/libexec/rc/rc.d/bridge (revision f99f0ee14e3af81c23150a6a340259ca8a33d01a)
10696600cSBjoern A. Zeeb#!/bin/sh
20696600cSBjoern A. Zeeb#
30696600cSBjoern A. Zeeb# Copyright (c) 2006 The FreeBSD Project. All rights reserved.
40696600cSBjoern A. Zeeb#
50696600cSBjoern A. Zeeb# Redistribution and use in source and binary forms, with or without
60696600cSBjoern A. Zeeb# modification, are permitted provided that the following conditions
70696600cSBjoern A. Zeeb# are met:
80696600cSBjoern A. Zeeb# 1. Redistributions of source code must retain the above copyright
90696600cSBjoern A. Zeeb#    notice, this list of conditions and the following disclaimer.
100696600cSBjoern A. Zeeb# 2. Redistributions in binary form must reproduce the above copyright
110696600cSBjoern A. Zeeb#    notice, this list of conditions and the following disclaimer in the
120696600cSBjoern A. Zeeb#    documentation and/or other materials provided with the distribution.
130696600cSBjoern A. Zeeb#
140696600cSBjoern A. Zeeb# THIS SOFTWARE IS PROVIDED BY THE PROJECT ``AS IS'' AND ANY EXPRESS OR
150696600cSBjoern A. Zeeb# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
160696600cSBjoern A. Zeeb# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
170696600cSBjoern A. Zeeb# IN NO EVENT SHALL THE PROJECT BE LIABLE FOR ANY DIRECT, INDIRECT,
180696600cSBjoern A. Zeeb# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
190696600cSBjoern A. Zeeb# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
200696600cSBjoern A. Zeeb# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
210696600cSBjoern A. Zeeb# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
220696600cSBjoern A. Zeeb# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
230696600cSBjoern A. Zeeb# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
240696600cSBjoern A. Zeeb#
250696600cSBjoern A. Zeeb#
260696600cSBjoern A. Zeeb
270696600cSBjoern A. Zeeb# PROVIDE: bridge
280696600cSBjoern A. Zeeb# REQUIRE: netif ppp stf
291809089aSMark Johnston# KEYWORD: nojailvnet
300696600cSBjoern A. Zeeb
310696600cSBjoern A. Zeeb. /etc/rc.subr
320696600cSBjoern A. Zeeb. /etc/network.subr
330696600cSBjoern A. Zeeb
340696600cSBjoern A. Zeebname="bridge"
350696600cSBjoern A. Zeebdesc="Network bridge setup"
360696600cSBjoern A. Zeebstart_cmd="bridge_start"
370696600cSBjoern A. Zeebstop_cmd="bridge_stop"
380696600cSBjoern A. Zeebcmd=""
390696600cSBjoern A. Zeeb
400696600cSBjoern A. Zeebglob_int() {
410696600cSBjoern A. Zeeb	case "$1" in
420696600cSBjoern A. Zeeb		$2 ) true ;;
430696600cSBjoern A. Zeeb		* ) false ;;
440696600cSBjoern A. Zeeb	esac
450696600cSBjoern A. Zeeb}
460696600cSBjoern A. Zeeb
470696600cSBjoern A. Zeebbridge_test() {
480696600cSBjoern A. Zeeb	bridge=$1
490696600cSBjoern A. Zeeb	iface=$2
500696600cSBjoern A. Zeeb
510696600cSBjoern A. Zeeb	eval interfaces=\$autobridge_${bridge}
520696600cSBjoern A. Zeeb	if [ -n "${interfaces}" ]; then
530696600cSBjoern A. Zeeb		for i in ${interfaces}; do
540696600cSBjoern A. Zeeb			if glob_int $iface $i ; then
550696600cSBjoern A. Zeeb				ifconfig $bridge $cmd $iface > /dev/null 2>&1
560696600cSBjoern A. Zeeb				return
570696600cSBjoern A. Zeeb			fi
580696600cSBjoern A. Zeeb		done
590696600cSBjoern A. Zeeb	fi
600696600cSBjoern A. Zeeb}
610696600cSBjoern A. Zeeb
620696600cSBjoern A. Zeebautobridge()
630696600cSBjoern A. Zeeb{
640696600cSBjoern A. Zeeb	if [ -n "${autobridge_interfaces}" ]; then
650696600cSBjoern A. Zeeb		if [ -z "$iflist" ]; then
660696600cSBjoern A. Zeeb			# We're operating as a general network start routine.
670696600cSBjoern A. Zeeb			iflist="`list_net_interfaces`"
680696600cSBjoern A. Zeeb		fi
690696600cSBjoern A. Zeeb
700696600cSBjoern A. Zeeb		for br in ${autobridge_interfaces}; do
710696600cSBjoern A. Zeeb			for i in $iflist; do
720696600cSBjoern A. Zeeb				bridge_test $br $i
730696600cSBjoern A. Zeeb			done
740696600cSBjoern A. Zeeb		done
750696600cSBjoern A. Zeeb	fi
760696600cSBjoern A. Zeeb}
770696600cSBjoern A. Zeeb
780696600cSBjoern A. Zeebbridge_start()
790696600cSBjoern A. Zeeb{
800696600cSBjoern A. Zeeb	cmd="addm"
810696600cSBjoern A. Zeeb	autobridge
820696600cSBjoern A. Zeeb}
830696600cSBjoern A. Zeeb
840696600cSBjoern A. Zeebbridge_stop()
850696600cSBjoern A. Zeeb{
860696600cSBjoern A. Zeeb	cmd="deletem"
870696600cSBjoern A. Zeeb	autobridge
880696600cSBjoern A. Zeeb}
890696600cSBjoern A. Zeeb
900696600cSBjoern A. Zeebiflist=$2
910696600cSBjoern A. Zeeb
920696600cSBjoern A. Zeebload_rc_config $name
93*f99f0ee1SAlexander Leidinger
94*f99f0ee1SAlexander Leidinger# doesn't make sense to run in a svcj: config setting
95*f99f0ee1SAlexander Leidingerbridge_svcj="NO"
96*f99f0ee1SAlexander Leidinger
970696600cSBjoern A. Zeebrun_rc_command "$1"
98