netif revision 212579
174462Salfred#!/bin/sh 274462Salfred# 3261057Smav# Copyright (c) 2003 The FreeBSD Project. All rights reserved. 4261057Smav# 5261057Smav# Redistribution and use in source and binary forms, with or without 6261057Smav# modification, are permitted provided that the following conditions 7261057Smav# are met: 8261057Smav# 1. Redistributions of source code must retain the above copyright 9261057Smav# notice, this list of conditions and the following disclaimer. 10261057Smav# 2. Redistributions in binary form must reproduce the above copyright 11261057Smav# notice, this list of conditions and the following disclaimer in the 12261057Smav# documentation and/or other materials provided with the distribution. 13261057Smav# 14261057Smav# THIS SOFTWARE IS PROVIDED BY THE PROJECT ``AS IS'' AND ANY EXPRESS OR 15261057Smav# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16261057Smav# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 1774462Salfred# IN NO EVENT SHALL THE PROJECT BE LIABLE FOR ANY DIRECT, INDIRECT, 18261057Smav# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19261057Smav# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20261057Smav# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21261057Smav# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22261057Smav# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23261057Smav# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24261057Smav# 25261057Smav# $FreeBSD: head/etc/rc.d/netif 212579 2010-09-13 19:55:40Z hrs $ 26261057Smav# 27261057Smav 28261057Smav# PROVIDE: netif 2974462Salfred# REQUIRE: atm1 cleanvar FILESYSTEMS serial sppp sysctl 3074462Salfred# REQUIRE: ipfilter ipfs 3174462Salfred# KEYWORD: nojail 3274462Salfred 3374462Salfred. /etc/rc.subr 3474462Salfred. /etc/network.subr 35136581Sobrien 36136581Sobrienname="network" 3774462Salfredstart_cmd="network_start" 3874462Salfredstop_cmd="network_stop" 3992990Sobriencloneup_cmd="clone_up" 4092990Sobrienclonedown_cmd="clone_down" 4174462Salfredextra_commands="cloneup clonedown" 4274462Salfredcmdifn= 4374462Salfred 4474462Salfredset_rcvar_obsolete ipv6_enable ipv6_activate_all_interfaces 4574462Salfredset_rcvar_obsolete ipv6_prefer 4674462Salfred 4775094Siedowsenetwork_start() 4874462Salfred{ 4974462Salfred # Set the list of interfaces to work on. 5074462Salfred # 5174462Salfred cmdifn=$* 5274462Salfred 5374462Salfred if [ -z "$cmdifn" ]; then 5474462Salfred # 5574462Salfred # We're operating as a general network start routine. 5674462Salfred # 5774462Salfred 5874462Salfred # disable SIGINT (Ctrl-c) when running at startup 5974462Salfred trap : 2 6074462Salfred 6174462Salfred # Create cloned interfaces 6274462Salfred clone_up 63156090Sdeischen 6474462Salfred # Create Fast EtherChannel interfaces 6592905Sobrien fec_up 6674462Salfred 6774462Salfred # Create IPv6<-->IPv4 tunnels 6874462Salfred gif_up 6974462Salfred 7074462Salfred # Rename interfaces. 7174462Salfred ifnet_rename 7274462Salfred fi 7374462Salfred 7474462Salfred # Configure the interface(s). 7574462Salfred network_common ifn_start 7674462Salfred 7774462Salfred if [ -f /etc/rc.d/ipfilter ] ; then 7892905Sobrien # Resync ipfilter 7974462Salfred /etc/rc.d/ipfilter quietresync 8074462Salfred fi 8174462Salfred if [ -f /etc/rc.d/bridge -a -n "$cmdifn" ] ; then 8274462Salfred /etc/rc.d/bridge start $cmdifn 8374462Salfred fi 8474462Salfred} 8574462Salfred 8674462Salfrednetwork_stop() 8774462Salfred{ 8874462Salfred # Set the list of interfaces to work on. 8974462Salfred # 9074462Salfred cmdifn=$* 9174462Salfred 9274462Salfred # Deconfigure the interface(s) 9374462Salfred network_common ifn_stop 9474462Salfred} 9574462Salfred 9674462Salfred# network_common routine 9774462Salfred# Common configuration subroutine for network interfaces. This 9874462Salfred# routine takes all the preparatory steps needed for configuriing 9974462Salfred# an interface and then calls $routine. 10074462Salfrednetwork_common() 10174462Salfred{ 10274462Salfred local _cooked_list _fail _func _ok _str 10374462Salfred 10474462Salfred _func= 10574462Salfred 10674462Salfred if [ -z "$1" ]; then 10774462Salfred err 1 "network_common(): No function name specified." 10874462Salfred else 10974462Salfred _func="$1" 11074462Salfred fi 11174462Salfred 11274462Salfred # Set the scope of the command (all interfaces or just one). 11374462Salfred # 11474462Salfred _cooked_list= 11574462Salfred if [ -n "$cmdifn" ]; then 11674462Salfred # Don't check that the interface(s) exist. We need to run 11774462Salfred # the down code even when the interface doesn't exist to 11874462Salfred # kill off wpa_supplicant. 11974462Salfred # XXXBED: is this really true or does wpa_supplicant die? 12074462Salfred # if so, we should get rid of the devd entry 12174462Salfred _cooked_list="$cmdifn" 12274462Salfred else 12374462Salfred _cooked_list="`list_net_interfaces`" 12474462Salfred fi 12574462Salfred 12674462Salfred _fail= 12774462Salfred _ok= 12874462Salfred for ifn in ${_cooked_list}; do 12974462Salfred if ${_func} ${ifn} $2; then 13074462Salfred _ok="${_ok} ${ifn}" 13174462Salfred else 13274462Salfred _fail="${_fail} ${ifn}" 13374462Salfred fi 13474462Salfred done 13574462Salfred 13674462Salfred _str= 13774462Salfred if [ -n "${_ok}" ]; then 13874462Salfred case ${_func} in 13974462Salfred ifn_start) 14074462Salfred _str='Starting' 14174462Salfred ;; 14274462Salfred ifn_stop) 14374462Salfred _str='Stopping' 14474462Salfred ;; 14574462Salfred esac 14674462Salfred echo "${_str} Network:${_ok}." 14774462Salfred if check_startmsgs; then 14874462Salfred for ifn in ${_ok}; do 14992905Sobrien /sbin/ifconfig ${ifn} 15074462Salfred done 15174462Salfred fi 15274462Salfred fi 15374462Salfred 15474462Salfred debug "The following interfaces were not configured: $_fail" 15574462Salfred} 15674462Salfred 15774462Salfredload_rc_config $name 15874462Salfredrun_rc_command $* 15974462Salfred