pccard_ether revision 147088
114596Snate#!/bin/sh -
214596Snate#
350472Speter# $FreeBSD: head/etc/pccard_ether 147088 2005-06-07 04:49:12Z brooks $
438738Sbrian#
5147088Sbrooks# pccard_ether interfacename [start|stop]
614596Snate#
7147088Sbrooks# example: pccard_ether fxp0 start
814596Snate#
914596Snate
10147088Sbrooks. /etc/rc.subr
11118840Smbr. /etc/network.subr
12118840Smbr
13147088Sbrooksusage()
14147088Sbrooks{
15147088Sbrooks	err 3 'USAGE: $0 interface (start|stop)'
16147088Sbrooks}
17118840Smbr
18147088Sbrooksifn=$1
19147088Sbrooksshift
20147088Sbrooksstartstop=$1
21147088Sbrooksshift
22118840Smbr
23147088Sbrooks# Ignore interfaces not in removable_interfaces
24147088Sbrooksexpr "${removable_interfaces}" : ".*${ifn}" > /dev/null || exit 0
25118840Smbr
26147088Sbrooksif [ -n "$1" ]; then
27147088Sbrooks	usage
28147088Sbrooksfi
29147088Sbrooks
30147088Sbrookssetup_routes()
31147088Sbrooks{
32147088Sbrooks	# Add default route into $static_routes
33147088Sbrooks	case ${defaultrouter} in
34147088Sbrooks	[Nn][Oo] | '')
35118840Smbr		;;
36118840Smbr	*)
37147088Sbrooks		static_routes="default ${static_routes}"
38147088Sbrooks		route_default="default ${defaultrouter}"
39118840Smbr		;;
40118840Smbr	esac
4167221Sjoe
42147088Sbrooks	# Add private route for this interface into $static_routes
43147088Sbrooks	eval ifx_routes=\$static_routes_${ifn}
44147088Sbrooks	if [ -n "${ifx_routes}" ]; then
45147088Sbrooks		static_routes="${ifx_routes} ${static_routes}"
4667221Sjoe	fi
47147088Sbrooks
48147088Sbrooks	# Set up any static routes if specified
49147088Sbrooks	if [ -n "${static_routes}" ]; then
50147088Sbrooks		for i in ${static_routes}; do
51147088Sbrooks			eval route_args=\$route_${i}
52147088Sbrooks			route add ${route_args}
53147088Sbrooks		done
54147088Sbrooks	fi
5567221Sjoe}
5667221Sjoe
57147088Sbrooksremove_routes()
58147088Sbrooks{
59147088Sbrooks	# Delete static route if specified
60147088Sbrooks	eval ifx_routes=\$static_routes_${ifn}
61147088Sbrooks	if [ -n "${ifx_routes}" ]; then
62147088Sbrooks		for i in ${ifx_routes}; do
63147088Sbrooks			eval route_args=\$route_${i}
64147088Sbrooks			route delete ${route_args}
65147088Sbrooks		done
66118840Smbr	fi
67118840Smbr}
68118840Smbr
69147088Sbrooksload_rc_config pccard_ether
7014596Snate
7167221Sjoecase ${startstop} in
7267221Sjoe[Ss][Tt][Aa][Rr][Tt] | '')
73118840Smbr	if [ -x /usr/bin/grep ]; then
74147088Sbrooks		if ifconfig $ifn | grep -s netmask > /dev/null 2>&1; then
75118840Smbr		    # Interface is already up, so ignore it.
76118840Smbr		    exit 0
77118840Smbr		fi
78107761Simp	fi
79107761Simp
80147088Sbrooks	/etc/rc.d/netif start $ifn
8170349Stoshi
82147088Sbrooks	# Do route configuration if needed.
83147088Sbrooks	# XXX: should probably do this by calling rc.d/routing.
84147088Sbrooks	if [ -n "`ifconfig_getargs $ifn`" ]; then
85147088Sbrooks		if ! dhcpif $ifn; then
86147088Sbrooks			setup_routes
8770349Stoshi		fi
88147088Sbrooks	fi
8970349Stoshi
9067221Sjoe	# IPv6 setup
91147088Sbrooks	if checkyesno ipv6_enable; then
92147088Sbrooks		network6_interface_setup $ifn
93147088Sbrooks	fi
9463308Sume	;;
95147088Sbrooks
9667221Sjoe# Stop the interface
97147088Sbrooks[Ss][Tt][Oo][Pp])
98147088Sbrooks	if [ -n "`ifconfig_getargs $ifn`" ]; then
99147088Sbrooks		if ! dhcpif $ifn; then
100147088Sbrooks			remove_routes
101147088Sbrooks		fi
10270349Stoshi	fi
10370349Stoshi
104147088Sbrooks	/etc/rc.d/netif stop $ifn
10570349Stoshi
106147088Sbrooks	# clean ARP table
10770349Stoshi	arp -d -a
10870349Stoshi
10970349Stoshi	# Clean the routing table
110147088Sbrooks	if checkyesno removable_route_flush; then
111147088Sbrooks		route -n flush -inet > /dev/null
112147088Sbrooks	fi
11367221Sjoe	;;
114147088Sbrooks*)
115147088Sbrooks	usage
11663308Sumeesac
117