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