pccard_ether revision 118840
1#!/bin/sh - 2# 3# $FreeBSD: head/etc/pccard_ether 118840 2003-08-12 20:22:44Z mbr $ 4# 5# pccard_ether interfacename [start|stop] [ifconfig option] 6# 7# example: pccard_ether fxp0 start link0 8# 9 10. /etc/network.subr 11 12stop_dhcp() { 13 # If dhclient is already running, record 14 # its interfaces. 15 if [ -x /usr/bin/grep ]; then 16 eval _active_list=\"`/bin/ps -axwww | \ 17 /usr/bin/grep dhclient | \ 18 /usr/bin/grep -v grep | \ 19 /usr/bin/sed -e 's|^.*dhclient||' | \ 20 /usr/bin/awk '{for (i=1;i<=NF;i++) \ 21 { if ($i~/[a-zA-Z].[0-9]$/) \ 22 { printf(" %s",$i) } }}'` \ 23 \" 24 fi 25 26 # Get the rc.conf list of dhcp configured interfaces 27 static_dhcp_list="`list_net_interfaces dhcp`" 28 29 # Get the current ifconfig list of interfaces 30 _aprefix= 31 _nlist= 32 for _if in ${_active_list} ; do 33 _test_if=`ifconfig ${_if} 2>&1` 34 case "$_test_if" in 35 "ifconfig: interface $_if does not exist") 36 ;; 37 ${interface}) 38 # Don't record the same device twice. 39 ;; 40 *) 41 # 42 # Catch devices which were specified before, 43 # but have not been part of the rc. We need 44 # them again for the restart. 45 # 46 for _cif in ${static_dhcp_list} ; do 47 case "$_cif" in 48 ${_if}) 49 # Nothing to add 50 ;; 51 *) 52 # Found interface beside rc.conf 53 _nlist="${_nlist}${_aprefix}${_if}" 54 ;; 55 esac 56 done 57 _dhcplist="${_dhcplist}${_aprefix}${_if}" 58 [ -z "$_aprefix" ] && _aprefix=' ' 59 ;; 60 esac 61 done 62 63 if [ -s /var/run/dhclient.${interface}.pid ]; then 64 pidfile="/var/run/dhclient.${interface}.pid" 65 elif [ -s /var/run/dhcpc.${interface}.pid ]; then 66 pidfile="/var/run/dhcpc.${interface}.pid" 67 elif [ -s /var/run/dhclient.pid ]; then 68 pidfile="/var/run/dhclient.pid" 69 else 70 return 71 fi 72 kill `cat ${pidfile}` 73 rm -f ${pidfile} 74 case ${startstop} in 75 [Ss][Tt][Oo][Pp]) 76 if [ -z "${_nlist}" ]; then 77 sh `/etc/rc.d/dhclient start` 78 else 79 start_dhcp_keep_current 80 fi 81 ;; 82 *) 83 ;; 84 esac 85} 86 87start_dhcp() { 88 case ${pccard_ether_delay} in 89 [Nn][Oo]) 90 ;; 91 [0-9]) 92 sleep ${pccard_ether_delay} 93 ;; 94 esac 95 stop_dhcp 96 [ -n "$dhcp_program" ] && dhclient_program="$dhcp_program" 97 [ -n "$dhcp_flags" ] && dhclient_flags="$dhcp_flags" 98 if [ -x "${dhclient_program}" ]; then 99 if [ `basename ${dhclient_program}` = "dhclient" ]; then 100 pidfile="/var/run/dhclient.${interface}.pid" 101 dhclient_flags="${dhclient_flags} -pf ${pidfile}" 102 fi 103 ${dhclient_program} ${dhclient_flags} $_dhcplist ${interface} 104 else 105 echo "${dhclient_program}: DHCP client software not available" 106 fi 107} 108 109# Called after detaching a card, if dhclient has been 110# used for more than one interface. 111start_dhcp_keep_current() { 112 [ -n "$dhcp_program" ] && dhclient_program="$dhcp_program" 113 [ -n "$dhcp_flags" ] && dhclient_flags="$dhcp_flags" 114 if [ -x "${dhclient_program}" ]; then 115 ${dhclient_program} ${dhclient_flags} \ 116 ${_dhcplist} 117 else 118 echo "${dhclient_program}: DHCP client software not available" 119 fi 120} 121 122# Suck in the configuration variables 123# 124if [ -r /etc/defaults/rc.conf ]; then 125 . /etc/defaults/rc.conf 126 source_rc_confs 127elif [ -r /etc/rc.conf ]; then 128 . /etc/rc.conf 129fi 130 131interface=$1 132shift 133startstop=$1 134shift 135 136case ${pccard_ifconfig} in 137[Nn][Oo] | '') 138 expr "${removable_interfaces}" : ".*${interface}" > /dev/null || exit 0 139 ;; 140*) 141 # Backward compatible 142 eval ifconfig_${interface}=\${pccard_ifconfig} 143 ;; 144esac 145 146case ${startstop} in 147[Ss][Tt][Aa][Rr][Tt] | '') 148 if [ -x /usr/bin/grep ]; then 149 if ifconfig ${interface} | grep -s UP, > /dev/null 2>&1; then 150 # Interface is already up, so ignore it. 151 exit 0 152 fi 153 fi 154 155 if [ -r /etc/start_if.${interface} ]; then 156 . /etc/start_if.${interface} 157 fi 158 159 eval ifconfig_args=\$ifconfig_${interface} 160 case ${ifconfig_args} in 161 [Nn][Oo] | '') 162 ;; 163 [Dd][Hh][Cc][Pp]) 164 # Start up the DHCP client program 165 start_dhcp 166 ;; 167 *) 168 # Do the primary ifconfig if specified 169 ifconfig ${interface} ${ifconfig_args} $* 170 171 # Check to see if aliases need to be added 172 alias=0 173 while : 174 do 175 eval ifx_args=\$ifconfig_${interface}_alias${alias} 176 if [ -n "${ifx_args}" ]; then 177 ifconfig ${interface} ${ifx_args} alias 178 alias=`expr ${alias} + 1` 179 else 180 break; 181 fi 182 done 183 184 # Do ipx address if specified 185 eval ifx_args=\$ifconfig_${interface}_ipx 186 if [ -n "${ifx_args}" ]; then 187 ifconfig ${interface} ${ifx_args} 188 fi 189 190 # Add default route into $static_routes 191 case ${defaultrouter} in 192 [Nn][Oo] | '') 193 ;; 194 *) 195 static_routes="default ${static_routes}" 196 route_default="default ${defaultrouter}" 197 ;; 198 esac 199 200 # Add private route for this interface into $static_routes 201 eval ifx_routes=\$static_routes_${interface} 202 if [ -n "${ifx_routes}" ]; then 203 static_routes="${ifx_routes} ${static_routes}" 204 fi 205 206 # Set up any static routes if specified 207 if [ -n "${static_routes}" ]; then 208 for i in ${static_routes}; do 209 eval route_args=\$route_${i} 210 route add ${route_args} 211 done 212 fi 213 ;; 214 esac 215 216 # IPv6 setup 217 case ${ipv6_enable} in 218 [Yy][Ee][Ss]) 219 if [ -r /etc/network.subr ]; then 220 . /etc/network.subr 221 network6_interface_setup ${interface} 222 fi 223 ;; 224 esac 225 ;; 226# Stop the interface 227*) 228 if [ -r /etc/stop_if.${interface} ]; then 229 . /etc/stop_if.${interface} 230 fi 231 232 eval ifconfig_args=\$ifconfig_${interface} 233 case ${ifconfig_args} in 234 [Nn][Oo] | '') 235 ;; 236 [Dd][Hh][Cc][Pp]) 237 # Stop the DHCP client for this interface 238 stop_dhcp 239 ;; 240 *) 241 # Delete static route if specified 242 eval ifx_routes=\$static_routes_${interface} 243 if [ -n "${ifx_routes}" ]; then 244 for i in ${ifx_routes}; do 245 eval route_args=\$route_${i} 246 route delete ${route_args} 247 done 248 fi 249 250 # Delete aliases if exist 251 alias=0 252 while : 253 do 254 eval ifx_args=\$ifconfig_${interface}_alias${alias} 255 if [ -n "${ifx_args}" ]; then 256 ifconfig ${interface} ${ifx_args} alias delete 257 alias=`expr ${alias} + 1` 258 else 259 break; 260 fi 261 done 262 ;; 263 esac 264 265 # Remove the network interface and cleaning ARP table 266 ifconfig ${interface} delete 267 arp -d -a 268 269 # Clean the routing table 270 case ${removable_route_flush} in 271 [Nn][Oo]) 272 ;; 273 *) 274 # flush beforehand, just in case.... 275 route -n flush -inet 276 ;; 277 esac 278 ;; 279esac 280