xref: /dragonfly/etc/pccard_ether (revision 75a74ed8)
1#!/bin/sh -
2#
3# $FreeBSD: head/libexec/rc/pccard_ether 339413 2018-10-17 16:49:11Z bz $
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_cmd="pccard_ether_start"
15stop_cmd="pccard_ether_stop"
16restart_cmd="pccard_ether_restart"
17startchildren_cmd="pccard_ether_startchildren"
18stopchildren_cmd="pccard_ether_stopchildren"
19extra_commands="startchildren stopchildren"
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
60pccard_ether_start()
61{
62	ifexists $ifn || exit 1
63
64	if [ -z "$rc_force" ]; then
65		for uif in `ifconfig -ul`; do
66			if [ "${uif}" = "${ifn}" ]; then
67				# Interface is already up, so ignore it.
68				exit 0
69			fi
70		done
71	fi
72
73	/etc/rc.d/netif start $ifn
74
75	# Do route configuration if needed.
76	# XXX: should probably do this by calling rc.d/routing.
77	if [ -n "`ifconfig_getargs $ifn`" ]; then
78		if ! dhcpif $ifn; then
79			setup_routes
80		fi
81	fi
82
83	# XXX: IPv6 setup should be done in some way.
84}
85
86pccard_ether_stop()
87{
88	if [ -n "`ifconfig_getargs $ifn`" ]; then
89		if ! dhcpif $ifn; then
90			remove_routes
91		fi
92	fi
93
94	/etc/rc.d/netif stop $ifn
95
96	# clean ARP table
97	ifexists $ifn && arp -d -i $ifn -a
98}
99
100pccard_ether_restart()
101{
102	# Hand implemented because the default implementation runs
103	# the equivalent of "$0 start; $0 stop" and this script
104	# doesn't support that syntax
105	pccard_ether_stop
106	pccard_ether_start
107}
108
109pccard_ether_startchildren()
110{
111	for child in `get_if_var $ifn wlans_IF`; do
112		if ifexists $child; then
113			continue
114		fi
115		/etc/rc.d/netif start $child
116	done
117}
118
119pccard_ether_stopchildren()
120{
121	for child in `get_if_var $ifn wlans_IF`; do
122		/etc/rc.d/netif stop $child
123	done
124}
125
126ifn=$1
127shift
128if [ -z "$*" ]; then
129	args="start"
130else
131	args=$*
132fi
133
134load_rc_config pccard_ether
135load_rc_config network
136run_rc_command $args
137