xref: /dragonfly/etc/pccard_ether (revision 36a3d1d6)
1#!/bin/sh -
2#
3# $FreeBSD: src/etc/pccard_ether,v 1.15.2.10 2001/09/14 17:28:11 imp Exp $
4# $DragonFly: src/etc/pccard_ether,v 1.4 2003/10/09 15:39:36 dillon Exp $
5#
6# pccard_ether interfacename [start|stop] [ifconfig option]
7#
8# example: pccard_ether ep0 start -link0
9#
10
11stop_dhcp() {
12	if [ -s /var/run/dhclient.${interface}.pid ]; then
13		pidfile="/var/run/dhclient.${interface}.pid"
14	elif [ -s /var/run/dhcpc.${interface}.pid ]; then
15		pidfile="/var/run/dhcpc.${interface}.pid"
16	else
17		return
18	fi
19	kill `cat ${pidfile}`
20	rm -f ${pidfile}
21}
22
23start_dhcp() {
24	stop_dhcp
25	case ${pccard_ether_delay} in
26	[Nn][Oo])
27		;;
28	[0-9])
29		sleep ${pccard_ether_delay}
30		;;
31	esac
32	[ -n "$dhcp_program" ] && dhclient_program="$dhcp_program"
33	[ -n "$dhcp_flags" ] && dhclient_flags="$dhcp_flags"
34	if [ -x "${dhclient_program}" ]; then
35		if [ `basename ${dhclient_program}` = "dhclient" ]; then
36			pidfile="/var/run/dhclient.${interface}.pid"
37			dhclient_flags="${dhclient_flags} -pf ${pidfile}"
38		fi
39		${dhclient_program} ${dhclient_flags} ${interface}
40	else
41		echo "${dhclient_program}: DHCP client software not available"
42	fi
43}
44
45# Suck in the configuration variables
46#
47if [ -r /etc/defaults/rc.conf ]; then
48	. /etc/defaults/rc.conf
49	source_rc_confs
50elif [ -r /etc/rc.conf ]; then
51	. /etc/rc.conf
52fi
53
54interface=$1
55shift
56startstop=$1
57shift
58
59case ${pccard_ifconfig} in
60[Nn][Oo] | '')
61	expr "${removable_interfaces}" : ".*${interface}" > /dev/null || exit 0
62	;;
63*)
64	# Backward compatible
65	eval ifconfig_${interface}=\${pccard_ifconfig}
66	;;
67esac
68
69case ${startstop} in
70[Ss][Tt][Aa][Rr][Tt] | '')
71	if ifconfig ${interface} | grep -s UP, > /dev/null 2>&1; then
72		# Interface is already up, so ignore it.
73		exit 0
74	fi
75
76	if [ -r /etc/start_if.${interface} ]; then
77		. /etc/start_if.${interface}
78	fi
79
80	eval ifconfig_args=\$ifconfig_${interface}
81	case ${ifconfig_args} in
82	[Nn][Oo] | '')
83		;;
84	[Dd][Hh][Cc][Pp])
85		# Start up the DHCP client program
86		start_dhcp
87		;;
88	*)
89		# Do the primary ifconfig if specified
90		ifconfig ${interface} ${ifconfig_args} $*
91
92		# Check to see if aliases need to be added
93		alias=0
94		while :
95		do
96			eval ifx_args=\$ifconfig_${interface}_alias${alias}
97			if [ -n "${ifx_args}" ]; then
98				ifconfig ${interface} ${ifx_args} alias
99				alias=`expr ${alias} + 1`
100			else
101				break;
102			fi
103		done
104
105		# Do ipx address if specified
106		eval ifx_args=\$ifconfig_${interface}_ipx
107		if [ -n "${ifx_args}" ]; then
108			ifconfig ${interface} ${ifx_args}
109		fi
110
111		# Add default route into $static_routes
112		case ${defaultrouter} in
113		[Nn][Oo] | '')
114		        ;;
115		*)
116			static_routes="default ${static_routes}"
117			route_default="default ${defaultrouter}"
118			;;
119		esac
120
121		# Add private route for this interface into $static_routes
122		eval ifx_routes=\$static_routes_${interface}
123		if [ -n "${ifx_routes}" ]; then
124			static_routes="${ifx_routes} ${static_routes}"
125		fi
126
127		# Set up any static routes if specified
128		if [ -n "${static_routes}" ]; then
129			for i in ${static_routes}; do
130				eval route_args=\$route_${i}
131				route add ${route_args}
132			done
133		fi
134		;;
135	esac
136
137	# IPv6 setup
138	case ${ipv6_enable} in
139	[Yy][Ee][Ss])
140		if [ -r /etc/network.subr ]; then
141			. /etc/network.subr
142			network6_interface_setup ${interface}
143		fi
144		;;
145	esac
146	;;
147# Stop the interface
148*)
149	if [ -r /etc/stop_if.${interface} ]; then
150		. /etc/stop_if.${interface}
151	fi
152
153	eval ifconfig_args=\$ifconfig_${interface}
154	case ${ifconfig_args} in
155	[Nn][Oo] | '')
156	        ;;
157	[Dd][Hh][Cc][Pp])
158		# Stop the DHCP client for this interface
159		stop_dhcp
160		;;
161	*)
162		# Delete static route if specified
163		eval ifx_routes=\$static_routes_${interface}
164		if [ -n "${ifx_routes}" ]; then
165			for i in ${ifx_routes}; do
166				eval route_args=\$route_${i}
167				route delete ${route_args}
168			done
169		fi
170
171		# Delete aliases if exist
172		alias=0
173		while :
174		do
175			eval ifx_args=\$ifconfig_${interface}_alias${alias}
176			if [ -n "${ifx_args}" ]; then
177				ifconfig ${interface} ${ifx_args} alias delete
178				alias=`expr ${alias} + 1`
179			else
180				break;
181			fi
182		done
183		;;
184	esac
185
186	# Remove the network interface and clean the ARP table
187	ifconfig ${interface} delete
188	arp -d -a
189
190	# Clean the routing table
191	case ${removable_route_flush} in
192	[Nn][Oo])
193		;;
194	*)
195		# flush beforehand, just in case....
196		route -n flush -inet
197		;;
198	esac
199	;;
200esac
201