summaryrefslogtreecommitdiffstats
path: root/etc/pccard_ether
blob: fcea104dca0e3e259bd681d4888d3b621e10c39c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
#!/bin/sh -
#
# $FreeBSD$
#
# pccard_ether interfacename [start|stop] [ifconfig option]
#
# example: pccard_ether fxp0 start link0
#

. /etc/network.subr

stop_dhcp() {
	# If dhclient is already running, record
	# its interfaces.
	if [ -x /usr/bin/grep ]; then
		eval _active_list=\"`/bin/ps -axwww | \
			/usr/bin/grep dhclient | \
			/usr/bin/grep -v grep | \
			/usr/bin/sed -e 's|^.*dhclient||' | \
			/usr/bin/awk '{for (i=1;i<=NF;i++) \
				{ if ($i~/[a-zA-Z].[0-9]$/) \
				{ printf(" %s",$i) } }}'` \
			\"
	fi

	# Get the rc.conf list of dhcp configured interfaces
	static_dhcp_list="`list_net_interfaces dhcp`"

	# Get the current ifconfig list of interfaces
	_aprefix=
	_nlist=
	for _if in ${_active_list} ; do
		_test_if=`ifconfig ${_if} 2>&1`
		case "$_test_if" in
		"ifconfig: interface $_if does not exist")
			;;
		${interface})
			# Don't record the same device twice.
			;;
		*)
			#
			# Catch devices which were specified before,
			# but have not been part of the rc. We need
			# them again for the restart.
			#
			for _cif in ${static_dhcp_list} ; do
				case "$_cif" in
				${_if})
					# Nothing to add
					;;
				*)
					# Found interface beside rc.conf
					_nlist="${_nlist}${_aprefix}${_if}"
					;;
				esac
			done
			_dhcplist="${_dhcplist}${_aprefix}${_if}"
			[ -z "$_aprefix" ] && _aprefix=' '
			;;
		esac
	done

	if [ -s /var/run/dhclient.pid ]; then
		pidfile="/var/run/dhclient.pid"
	else
		return
	fi
	kill `cat ${pidfile}`
	rm -f ${pidfile}
	case ${startstop} in
	[Ss][Tt][Oo][Pp])
		if [ -z "${_nlist}" ]; then
			sh `/etc/rc.d/dhclient start`
		else
			start_dhcp_keep_current
		fi
		;;
	*)
		;;
	esac
}

start_dhcp() {
	stop_dhcp
	case ${pccard_ether_delay} in
	[Nn][Oo])
		;;
	[0-9])
		sleep ${pccard_ether_delay}
		;;
        esac
	[ -n "$dhcp_program" ] && dhclient_program="$dhcp_program"
	[ -n "$dhcp_flags" ] && dhclient_flags="$dhcp_flags"
	if [ -x "${dhclient_program}" ]; then
		${dhclient_program} ${dhclient_flags}  $_dhcplist ${interface}
	else
		echo "${dhclient_program}: DHCP client software not available"
	fi
}

# Called after detaching a card, if dhclient has been
# used for more than one interface.
start_dhcp_keep_current() {
	[ -n "$dhcp_program" ] && dhclient_program="$dhcp_program"
	[ -n "$dhcp_flags" ] && dhclient_flags="$dhcp_flags"
	if [ -x "${dhclient_program}" ]; then
		${dhclient_program} ${dhclient_flags} \
			${_dhcplist}
	else
		echo "${dhclient_program}: DHCP client software not available"
	fi
}

# Suck in the configuration variables
#
if [ -r /etc/defaults/rc.conf ]; then
	. /etc/defaults/rc.conf
	source_rc_confs
elif [ -r /etc/rc.conf ]; then
	. /etc/rc.conf
fi

interface=$1
shift
startstop=$1
shift

case ${pccard_ifconfig} in
[Nn][Oo] | '')
	expr "${removable_interfaces}" : ".*${interface}" > /dev/null || exit 0
	;;
*)
	# Backward compatible
	eval ifconfig_${interface}=\${pccard_ifconfig}
	;;
esac

case ${startstop} in
[Ss][Tt][Aa][Rr][Tt] | '')
	if [ -x /usr/bin/grep ]; then
		if ifconfig ${interface} | grep -s UP, > /dev/null 2>&1; then
		    # Interface is already up, so ignore it.
		    exit 0
		fi
	fi

	if [ -r /etc/start_if.${interface} ]; then
		. /etc/start_if.${interface}
	fi

	eval ifconfig_args=\$ifconfig_${interface}
	case ${ifconfig_args} in
	[Nn][Oo] | '')
		;;
	[Dd][Hh][Cc][Pp])
		# Start up the DHCP client program
		start_dhcp
		;;
	*)
		# Do the primary ifconfig if specified
		ifconfig ${interface} ${ifconfig_args} $*

		# Check to see if aliases need to be added
		alias=0
		while :
		do
			eval ifx_args=\$ifconfig_${interface}_alias${alias}
			if [ -n "${ifx_args}" ]; then
				ifconfig ${interface} ${ifx_args} alias
				alias=`expr ${alias} + 1`
			else
				break;
			fi
		done

		# Do ipx address if specified
		eval ifx_args=\$ifconfig_${interface}_ipx
		if [ -n "${ifx_args}" ]; then
			ifconfig ${interface} ${ifx_args}
		fi

		# Add default route into $static_routes
		case ${defaultrouter} in
		[Nn][Oo] | '')
		        ;;
		*)
			static_routes="default ${static_routes}"
			route_default="default ${defaultrouter}"
			;;
		esac

		# Add private route for this interface into $static_routes
		eval ifx_routes=\$static_routes_${interface}
		if [ -n "${ifx_routes}" ]; then
			static_routes="${ifx_routes} ${static_routes}"
		fi

		# Set up any static routes if specified
		if [ -n "${static_routes}" ]; then
			for i in ${static_routes}; do
				eval route_args=\$route_${i}
				route add ${route_args}
			done
		fi
		;;
	esac

	# IPv6 setup
	case ${ipv6_enable} in
	[Yy][Ee][Ss])
		if [ -r /etc/network.subr ]; then
			. /etc/network.subr
			network6_interface_setup ${interface}
		fi
		;;
	esac
	;;
# Stop the interface
*)
	if [ -r /etc/stop_if.${interface} ]; then
		. /etc/stop_if.${interface}
	fi

	eval ifconfig_args=\$ifconfig_${interface}
	case ${ifconfig_args} in
	[Nn][Oo] | '')
	        ;;
	[Dd][Hh][Cc][Pp])
		# Stop the DHCP client for this interface
		stop_dhcp
		;;
	*)
		# Delete static route if specified
		eval ifx_routes=\$static_routes_${interface}
		if [ -n "${ifx_routes}" ]; then
			for i in ${ifx_routes}; do
				eval route_args=\$route_${i}
				route delete ${route_args}
			done
		fi

		# Delete aliases if exist
		alias=0
		while :
		do
			eval ifx_args=\$ifconfig_${interface}_alias${alias}
			if [ -n "${ifx_args}" ]; then
				ifconfig ${interface} ${ifx_args} alias delete
				alias=`expr ${alias} + 1`
			else
				break;
			fi
		done
		;;
	esac

	# Remove the network interface and cleaning ARP table
	ifconfig ${interface} delete
	arp -d -a

	# Clean the routing table
	case ${removable_route_flush} in
	[Nn][Oo])
	        ;;
	*)	
		# flush beforehand, just in case....
		route -n flush -inet
		;;
	esac
	;;
esac
OpenPOWER on IntegriCloud