Merge branch 'vendor/GCC47'
[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         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 #
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
51 fi
52
53 interface=$1
54 shift
55 startstop=$1
56 shift
57
58 case ${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         ;;
66 esac
67
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
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                 # Add default route into $static_routes
105                 case ${defaultrouter} in
106                 [Nn][Oo] | '')
107                         ;;
108                 *)
109                         static_routes="default ${static_routes}"
110                         route_default="default ${defaultrouter}"
111                         ;;
112                 esac
113
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}"
118                 fi
119
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
126                 fi
127                 ;;
128         esac
129
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}
136                 fi
137                 ;;
138         esac
139         ;;
140 # Stop the interface
141 *)
142         if [ -r /etc/stop_if.${interface} ]; then
143                 . /etc/stop_if.${interface}
144         fi
145
146         eval ifconfig_args=\$ifconfig_${interface}
147         case ${ifconfig_args} in
148         [Nn][Oo] | '')
149                 ;;
150         [Dd][Hh][Cc][Pp])
151                 # Stop the DHCP client for this interface
152                 stop_dhcp
153                 ;;
154         *)
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
162                 fi
163
164                 # Delete aliases if exist
165                 alias=0
166                 while :
167                 do
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;
174                         fi
175                 done
176                 ;;
177         esac
178
179         # Remove the network interface and clean the ARP table
180         ifconfig ${interface} delete
181         arp -d -a
182         
183         # Clean the routing table
184         case ${removable_route_flush} in
185         [Nn][Oo])
186                 ;;
187         *)      
188                 # flush beforehand, just in case....
189                 route -n flush -inet
190                 ;;
191         esac
192         ;;
193 esac