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