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