1#!/bin/sh - 2# 3# $FreeBSD$ 4# 5# pccard_ether interfacename [start|stop|restart] 6# 7# example: pccard_ether fxp0 start 8# 9 10. /etc/rc.subr 11. /etc/network.subr 12 13name="pccard_ether" 14start_precmd="checkauto" 15start_cmd="pccard_ether_start" 16stop_precmd="checkauto" 17stop_cmd="pccard_ether_stop" 18restart_precmd="checkauto" 19restart_cmd="pccard_ether_restart" 20startchildren_cmd="pccard_ether_startchildren" 21stopchildren_cmd="pccard_ether_stopchildren" 22extra_commands="startchildren stopchildren" 23 24setup_routes() 25{ 26 # Add default route into $static_routes 27 case ${defaultrouter} in 28 [Nn][Oo] | '') 29 ;; 30 *) 31 static_routes="default ${static_routes}" 32 route_default="default ${defaultrouter}" 33 ;; 34 esac 35 36 # Add private route for this interface into $static_routes 37 eval ifx_routes=\$static_routes_${ifn} 38 if [ -n "${ifx_routes}" ]; then 39 static_routes="${ifx_routes} ${static_routes}" 40 fi 41 42 # Set up any static routes if specified 43 if [ -n "${static_routes}" ]; then 44 for i in ${static_routes}; do 45 eval route_args=\$route_${i} 46 route add ${route_args} 47 done 48 fi 49} 50 51remove_routes() 52{ 53 # Delete static route if specified 54 eval ifx_routes=\$static_routes_${ifn} 55 if [ -n "${ifx_routes}" ]; then 56 for i in ${ifx_routes}; do 57 eval route_args=\$route_${i} 58 route delete ${route_args} 59 done 60 fi 61} 62 63checkauto() 64{ 65 if [ -z "$rc_force" ]; then 66 # Ignore interfaces with the NOAUTO keyword 67 autoif $ifn || exit 0 68 fi 69} 70 71pccard_ether_start() 72{ 73 ifexists $ifn || exit 1 74 75 if [ -z "$rc_force" ]; then 76 for uif in `ifconfig -ul`; do 77 if [ "${uif}" = "${ifn}" ]; then 78 # Interface is already up, so ignore it. 79 exit 0 80 fi 81 done 82 fi 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