pccard_ether revision 162490
1#!/bin/sh -
2#
3# $FreeBSD: head/etc/pccard_ether 162490 2006-09-21 01:44:52Z brooks $
4#
5# pccard_ether interfacename [start|stop|restart]
6#
7# example: pccard_ether fxp0 start
8#
9
10. /etc/rc.subr
11. /etc/network.subr
12
13name="pccard_ether"
14start_precmd="checkauto"
15start_cmd="pccard_ether_start"
16stop_precmd="checkauto"
17stop_cmd="pccard_ether_stop"
18restart_precmd="checkauto"
19restart_cmd="pccard_ether_restart"
20
21setup_routes()
22{
23	# Add default route into $static_routes
24	case ${defaultrouter} in
25	[Nn][Oo] | '')
26		;;
27	*)
28		static_routes="default ${static_routes}"
29		route_default="default ${defaultrouter}"
30		;;
31	esac
32
33	# Add private route for this interface into $static_routes
34	eval ifx_routes=\$static_routes_${ifn}
35	if [ -n "${ifx_routes}" ]; then
36		static_routes="${ifx_routes} ${static_routes}"
37	fi
38
39	# Set up any static routes if specified
40	if [ -n "${static_routes}" ]; then
41		for i in ${static_routes}; do
42			eval route_args=\$route_${i}
43			route add ${route_args}
44		done
45	fi
46}
47
48remove_routes()
49{
50	# Delete static route if specified
51	eval ifx_routes=\$static_routes_${ifn}
52	if [ -n "${ifx_routes}" ]; then
53		for i in ${ifx_routes}; do
54			eval route_args=\$route_${i}
55			route delete ${route_args}
56		done
57	fi
58}
59
60checkauto()
61{
62	if [ -z "$rc_force" ]; then
63		# Ignore interfaces with the NOAUTO keyword
64		autoif $ifn || exit 0
65	fi
66}
67
68pccard_ether_start()
69{
70	ifexists $ifn || exit 1
71
72	if [ -z "$rc_force" ]; then
73		for uif in `ifconfig -ul`; do
74			if [ "${uif}" = "${ifn}" ]; then
75				# Interface is already up, so ignore it.
76				exit 0
77			fi
78		done
79	fi
80
81	/etc/rc.d/netif start $ifn
82
83	# Do route configuration if needed.
84	# XXX: should probably do this by calling rc.d/routing.
85	if [ -n "`ifconfig_getargs $ifn`" ]; then
86		if ! dhcpif $ifn; then
87			setup_routes
88		fi
89	fi
90
91	# IPv6 setup
92	if ipv6if $ifn; then
93		# XXX: network6_interface_setup assumes you're calling
94		# it with ALL the IPv6 interfaces at once and thus isn't
95		# really appropraite for this job, but it's the best we've
96		# got for now.
97		network6_interface_setup $ifn
98	fi
99}
100
101pccard_ether_stop()
102{
103	if [ -n "`ifconfig_getargs $ifn`" ]; then
104		if ! dhcpif $ifn; then
105			remove_routes
106		fi
107	fi
108
109	/etc/rc.d/netif stop $ifn
110
111	# clean ARP table
112	ifexists $ifn && arp -d -i $ifn -a
113}
114
115pccard_ether_restart()
116{
117	# Hand implemented because the default implementation runs
118	# the equivalent of "$0 start; $0 stop" and this script
119	# doesn't support that syntax
120	pccard_ether_stop
121	pccard_ether_start
122}
123
124ifn=$1
125shift
126if [ -z "$*" ]; then
127	args="start"
128else
129	args=$*
130fi
131
132load_rc_config pccard_ether
133run_rc_command $args
134