pccard_ether revision 114942
1#!/bin/sh - 2# 3# $FreeBSD: head/etc/pccard_ether 114942 2003-05-12 11:36:50Z ume $ 4# 5# pccard_ether interfacename [start|stop] [ifconfig option] 6# 7# example: pccard_ether ep0 start -link0 8# 9 10stop_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 22start_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 if [ -x "${dhcp_program}" ]; then 32 if [ `basename ${dhcp_program}` = "dhclient" ]; then 33 pidfile="/var/run/dhclient.${interface}.pid" 34 dhcp_flags="${dhcp_flags} -pf ${pidfile}" 35 fi 36 ${dhcp_program} ${dhcp_flags} ${interface} 37 else 38 echo "${dhcp_program}: DHCP client software not available" 39 fi 40} 41 42# Suck in the configuration variables 43# 44if [ -r /etc/defaults/rc.conf ]; then 45 . /etc/defaults/rc.conf 46 source_rc_confs 47elif [ -r /etc/rc.conf ]; then 48 . /etc/rc.conf 49fi 50 51interface=$1 52shift 53startstop=$1 54shift 55 56case ${pccard_ifconfig} in 57[Nn][Oo] | '') 58 expr "${removable_interfaces}" : ".*${interface}" > /dev/null || exit 0 59 ;; 60*) 61 # Backward compatible 62 eval ifconfig_${interface}=\${pccard_ifconfig} 63 ;; 64esac 65 66case ${startstop} in 67[Ss][Tt][Aa][Rr][Tt] | '') 68 if ifconfig ${interface} | grep -s UP, > /dev/null 2>&1; then 69 # Interface is already up, so ignore it. 70 exit 0 71 fi 72 73 if [ -r /etc/start_if.${interface} ]; then 74 . /etc/start_if.${interface} 75 fi 76 77 eval ifconfig_args=\$ifconfig_${interface} 78 case ${ifconfig_args} in 79 [Nn][Oo] | '') 80 ;; 81 [Dd][Hh][Cc][Pp]) 82 # Start up the DHCP client program 83 start_dhcp 84 ;; 85 *) 86 # Do the primary ifconfig if specified 87 ifconfig ${interface} ${ifconfig_args} $* 88 89 # Check to see if aliases need to be added 90 alias=0 91 while : 92 do 93 eval ifx_args=\$ifconfig_${interface}_alias${alias} 94 if [ -n "${ifx_args}" ]; then 95 ifconfig ${interface} ${ifx_args} alias 96 alias=`expr ${alias} + 1` 97 else 98 break; 99 fi 100 done 101 102 # Do ipx address if specified 103 eval ifx_args=\$ifconfig_${interface}_ipx 104 if [ -n "${ifx_args}" ]; then 105 ifconfig ${interface} ${ifx_args} 106 fi 107 108 # Add default route into $static_routes 109 case ${defaultrouter} in 110 [Nn][Oo] | '') 111 ;; 112 *) 113 static_routes="default ${static_routes}" 114 route_default="default ${defaultrouter}" 115 ;; 116 esac 117 118 # Add private route for this interface into $static_routes 119 eval ifx_routes=\$static_routes_${interface} 120 if [ -n "${ifx_routes}" ]; then 121 static_routes="${ifx_routes} ${static_routes}" 122 fi 123 124 # Set up any static routes if specified 125 if [ -n "${static_routes}" ]; then 126 for i in ${static_routes}; do 127 eval route_args=\$route_${i} 128 route add ${route_args} 129 done 130 fi 131 ;; 132 esac 133 134 # IPv6 setup 135 case ${ipv6_enable} in 136 [Yy][Ee][Ss]) 137 if [ -r /etc/network.subr ]; then 138 . /etc/network.subr 139 network6_interface_setup ${interface} 140 fi 141 ;; 142 esac 143 ;; 144# Stop the interface 145*) 146 if [ -r /etc/stop_if.${interface} ]; then 147 . /etc/stop_if.${interface} 148 fi 149 150 eval ifconfig_args=\$ifconfig_${interface} 151 case ${ifconfig_args} in 152 [Nn][Oo] | '') 153 ;; 154 [Dd][Hh][Cc][Pp]) 155 # Stop the DHCP client for this interface 156 stop_dhcp 157 ;; 158 *) 159 # Delelte static route if specified 160 eval ifx_routes=\$static_routes_${interface} 161 if [ -n "${ifx_routes}" ]; then 162 for i in ${ifx_routes}; do 163 eval route_args=\$route_${i} 164 route delete ${route_args} 165 done 166 fi 167 168 # Delete aliases if exist 169 alias=0 170 while : 171 do 172 eval ifx_args=\$ifconfig_${interface}_alias${alias} 173 if [ -n "${ifx_args}" ]; then 174 ifconfig ${interface} ${ifx_args} alias delete 175 alias=`expr ${alias} + 1` 176 else 177 break; 178 fi 179 done 180 ;; 181 esac 182 183 # Remove the network interface and cleaning ARP table 184 ifconfig ${interface} delete 185 arp -d -a 186 187 # Clean the routing table 188 case ${removable_route_flush} in 189 [Nn][Oo]) 190 ;; 191 *) 192 # flush beforehand, just in case.... 193 route -n flush -inet 194 ;; 195 esac 196 ;; 197esac 198