boot: Use snprintf() when filling command_errbuf[] w/ dynamic content.
[dragonfly.git] / etc / pccard_ether
blob03db4c34613efe2573ec9bfc9c6f2c53555a46b6
1 #!/bin/sh -
3 # $FreeBSD: src/etc/pccard_ether,v 1.15.2.10 2001/09/14 17:28:11 imp Exp $
5 # pccard_ether interfacename [start|stop] [ifconfig option]
7 # example: pccard_ether ep0 start -link0
10 stop_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
18 kill `cat ${pidfile}`
19 rm -f ${pidfile}
22 start_dhcp() {
23 stop_dhcp
24 case ${pccard_ether_delay} in
25 [Nn][Oo])
27 [0-9])
28 sleep ${pccard_ether_delay}
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}"
38 ${dhclient_program} ${dhclient_flags} ${interface}
39 else
40 echo "${dhclient_program}: DHCP client software not available"
44 # Suck in the configuration variables
46 if [ -r /etc/defaults/rc.conf ]; then
47 . /etc/defaults/rc.conf
48 source_rc_confs
49 elif [ -r /etc/rc.conf ]; then
50 . /etc/rc.conf
53 interface=$1
54 shift
55 startstop=$1
56 shift
58 case ${pccard_ifconfig} in
59 [Nn][Oo] | '')
60 expr "${removable_interfaces}" : ".*${interface}" > /dev/null || exit 0
63 # Backward compatible
64 eval ifconfig_${interface}=\${pccard_ifconfig}
66 esac
68 case ${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
75 if [ -r /etc/start_if.${interface} ]; then
76 . /etc/start_if.${interface}
79 eval ifconfig_args=\$ifconfig_${interface}
80 case ${ifconfig_args} in
81 [Nn][Oo] | '')
83 [Dd][Hh][Cc][Pp])
84 # Start up the DHCP client program
85 start_dhcp
88 # Do the primary ifconfig if specified
89 ifconfig ${interface} ${ifconfig_args} $*
91 # Check to see if aliases need to be added
92 alias=0
93 while :
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;
102 done
104 # Add default route into $static_routes
105 case ${defaultrouter} in
106 [Nn][Oo] | '')
109 static_routes="default ${static_routes}"
110 route_default="default ${defaultrouter}"
112 esac
114 # Add private route for this interface into $static_routes
115 eval ifx_routes=\$static_routes_${interface}
116 if [ -n "${ifx_routes}" ]; then
117 static_routes="${ifx_routes} ${static_routes}"
120 # Set up any static routes if specified
121 if [ -n "${static_routes}" ]; then
122 for i in ${static_routes}; do
123 eval route_args=\$route_${i}
124 route add ${route_args}
125 done
128 esac
130 # IPv6 setup
131 case ${ipv6_enable} in
132 [Yy][Ee][Ss])
133 if [ -r /etc/network.subr ]; then
134 . /etc/network.subr
135 network6_interface_setup ${interface}
138 esac
140 # Stop the interface
142 if [ -r /etc/stop_if.${interface} ]; then
143 . /etc/stop_if.${interface}
146 eval ifconfig_args=\$ifconfig_${interface}
147 case ${ifconfig_args} in
148 [Nn][Oo] | '')
150 [Dd][Hh][Cc][Pp])
151 # Stop the DHCP client for this interface
152 stop_dhcp
155 # Delete static route if specified
156 eval ifx_routes=\$static_routes_${interface}
157 if [ -n "${ifx_routes}" ]; then
158 for i in ${ifx_routes}; do
159 eval route_args=\$route_${i}
160 route delete ${route_args}
161 done
164 # Delete aliases if exist
165 alias=0
166 while :
168 eval ifx_args=\$ifconfig_${interface}_alias${alias}
169 if [ -n "${ifx_args}" ]; then
170 ifconfig ${interface} ${ifx_args} alias delete
171 alias=`expr ${alias} + 1`
172 else
173 break;
175 done
177 esac
179 # Remove the network interface and clean the ARP table
180 ifconfig ${interface} delete
181 arp -d -a
183 # Clean the routing table
184 case ${removable_route_flush} in
185 [Nn][Oo])
188 # flush beforehand, just in case....
189 route -n flush -inet
191 esac
193 esac