pccard_ether revision 147088
1#!/bin/sh -
2#
3# $FreeBSD: head/etc/pccard_ether 147088 2005-06-07 04:49:12Z brooks $
4#
5# pccard_ether interfacename [start|stop]
6#
7# example: pccard_ether fxp0 start
8#
9
10. /etc/rc.subr
11. /etc/network.subr
12
13usage()
14{
15	err 3 'USAGE: $0 interface (start|stop)'
16}
17
18ifn=$1
19shift
20startstop=$1
21shift
22
23# Ignore interfaces not in removable_interfaces
24expr "${removable_interfaces}" : ".*${ifn}" > /dev/null || exit 0
25
26if [ -n "$1" ]; then
27	usage
28fi
29
30setup_routes()
31{
32	# Add default route into $static_routes
33	case ${defaultrouter} in
34	[Nn][Oo] | '')
35		;;
36	*)
37		static_routes="default ${static_routes}"
38		route_default="default ${defaultrouter}"
39		;;
40	esac
41
42	# Add private route for this interface into $static_routes
43	eval ifx_routes=\$static_routes_${ifn}
44	if [ -n "${ifx_routes}" ]; then
45		static_routes="${ifx_routes} ${static_routes}"
46	fi
47
48	# Set up any static routes if specified
49	if [ -n "${static_routes}" ]; then
50		for i in ${static_routes}; do
51			eval route_args=\$route_${i}
52			route add ${route_args}
53		done
54	fi
55}
56
57remove_routes()
58{
59	# Delete static route if specified
60	eval ifx_routes=\$static_routes_${ifn}
61	if [ -n "${ifx_routes}" ]; then
62		for i in ${ifx_routes}; do
63			eval route_args=\$route_${i}
64			route delete ${route_args}
65		done
66	fi
67}
68
69load_rc_config pccard_ether
70
71case ${startstop} in
72[Ss][Tt][Aa][Rr][Tt] | '')
73	if [ -x /usr/bin/grep ]; then
74		if ifconfig $ifn | grep -s netmask > /dev/null 2>&1; then
75		    # Interface is already up, so ignore it.
76		    exit 0
77		fi
78	fi
79
80	/etc/rc.d/netif start $ifn
81
82	# Do route configuration if needed.
83	# XXX: should probably do this by calling rc.d/routing.
84	if [ -n "`ifconfig_getargs $ifn`" ]; then
85		if ! dhcpif $ifn; then
86			setup_routes
87		fi
88	fi
89
90	# IPv6 setup
91	if checkyesno ipv6_enable; then
92		network6_interface_setup $ifn
93	fi
94	;;
95
96# Stop the interface
97[Ss][Tt][Oo][Pp])
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 stop $ifn
105
106	# clean ARP table
107	arp -d -a
108
109	# Clean the routing table
110	if checkyesno removable_route_flush; then
111		route -n flush -inet > /dev/null
112	fi
113	;;
114*)
115	usage
116esac
117