1#!/bin/sh - 2# 3# 4# pccard_ether interfacename [start|stop|restart] 5# 6# example: pccard_ether fxp0 start 7# 8 9. /etc/rc.subr 10. /etc/network.subr 11 12name="pccard_ether" 13start_precmd="checkauto" 14start_cmd="pccard_ether_start" 15stop_precmd="checkauto" 16stop_cmd="pccard_ether_stop" 17restart_precmd="checkauto" 18restart_cmd="pccard_ether_restart" 19startchildren_cmd="pccard_ether_startchildren" 20stopchildren_cmd="pccard_ether_stopchildren" 21extra_commands="startchildren stopchildren" 22 23setup_routes() 24{ 25 # Add default route into $static_routes 26 case ${defaultrouter} in 27 [Nn][Oo] | '') 28 ;; 29 *) 30 static_routes="default ${static_routes}" 31 route_default="default ${defaultrouter}" 32 ;; 33 esac 34 35 # Add private route for this interface into $static_routes 36 eval ifx_routes=\$static_routes_${ifn} 37 if [ -n "${ifx_routes}" ]; then 38 static_routes="${ifx_routes} ${static_routes}" 39 fi 40 41 # Set up any static routes if specified 42 if [ -n "${static_routes}" ]; then 43 for i in ${static_routes}; do 44 eval route_args=\$route_${i} 45 route add ${route_args} 46 done 47 fi 48} 49 50remove_routes() 51{ 52 # Delete static route if specified 53 eval ifx_routes=\$static_routes_${ifn} 54 if [ -n "${ifx_routes}" ]; then 55 for i in ${ifx_routes}; do 56 eval route_args=\$route_${i} 57 route delete ${route_args} 58 done 59 fi 60} 61 62checkauto() 63{ 64 if [ -z "$rc_force" ]; then 65 # Ignore interfaces with the NOAUTO keyword 66 autoif $ifn || exit 0 67 fi 68} 69 70pccard_ether_start() 71{ 72 ifisup $ifn 73 case $? in 74 0) # Interface is already up, so ignore it. 75 if [ -z "$rc_force"]; then 76 exit 0 77 fi 78 ;; 79 2) # Interface does not exist. 80 exit 1 81 ;; 82 esac 83 84 /etc/rc.d/netif quietstart $ifn 85 86 # Do route configuration if needed. 87 # XXX: should probably do this by calling rc.d/routing. 88 if [ -n "`ifconfig_getargs $ifn`" ]; then 89 if ! dhcpif $ifn; then 90 setup_routes 91 fi 92 fi 93 94 # XXX: IPv6 setup should be done in some way. 95} 96 97pccard_ether_stop() 98{ 99 if [ -n "`ifconfig_getargs $ifn`" ]; then 100 if ! dhcpif $ifn; then 101 remove_routes 102 fi 103 fi 104 105 /etc/rc.d/netif quietstop $ifn 106 107 # clean ARP table 108 ifexists $ifn && arp -d -i $ifn -a 109} 110 111pccard_ether_restart() 112{ 113 # Hand implemented because the default implementation runs 114 # the equivalent of "$0 start; $0 stop" and this script 115 # doesn't support that syntax 116 pccard_ether_stop 117 pccard_ether_start 118} 119 120pccard_ether_startchildren() 121{ 122 for child in `get_if_var $ifn wlans_IF`; do 123 if ifexists $child; then 124 continue 125 fi 126 /etc/rc.d/netif quietstart $child 127 done 128} 129 130pccard_ether_stopchildren() 131{ 132 for child in `get_if_var $ifn wlans_IF`; do 133 /etc/rc.d/netif quietstop $child 134 done 135} 136 137ifn=$1 138shift 139if [ -z "$*" ]; then 140 args="start" 141else 142 args=$* 143fi 144 145load_rc_config pccard_ether 146load_rc_config network 147run_rc_command $args 148