pccard_ether revision 147424
114596Snate#!/bin/sh - 214596Snate# 350472Speter# $FreeBSD: head/etc/pccard_ether 147424 2005-06-16 18:08:04Z brooks $ 438738Sbrian# 5147088Sbrooks# pccard_ether interfacename [start|stop] 614596Snate# 7147088Sbrooks# example: pccard_ether fxp0 start 814596Snate# 914596Snate 10147088Sbrooks. /etc/rc.subr 11118840Smbr. /etc/network.subr 12118840Smbr 13147088Sbrooksusage() 14147088Sbrooks{ 15147088Sbrooks err 3 'USAGE: $0 interface (start|stop)' 16147088Sbrooks} 17118840Smbr 18147088Sbrookssetup_routes() 19147088Sbrooks{ 20147088Sbrooks # Add default route into $static_routes 21147088Sbrooks case ${defaultrouter} in 22147088Sbrooks [Nn][Oo] | '') 23118840Smbr ;; 24118840Smbr *) 25147088Sbrooks static_routes="default ${static_routes}" 26147088Sbrooks route_default="default ${defaultrouter}" 27118840Smbr ;; 28118840Smbr esac 2967221Sjoe 30147088Sbrooks # Add private route for this interface into $static_routes 31147088Sbrooks eval ifx_routes=\$static_routes_${ifn} 32147088Sbrooks if [ -n "${ifx_routes}" ]; then 33147088Sbrooks static_routes="${ifx_routes} ${static_routes}" 3467221Sjoe fi 35147088Sbrooks 36147088Sbrooks # Set up any static routes if specified 37147088Sbrooks if [ -n "${static_routes}" ]; then 38147088Sbrooks for i in ${static_routes}; do 39147088Sbrooks eval route_args=\$route_${i} 40147088Sbrooks route add ${route_args} 41147088Sbrooks done 42147088Sbrooks fi 4367221Sjoe} 4467221Sjoe 45147088Sbrooksremove_routes() 46147088Sbrooks{ 47147088Sbrooks # Delete static route if specified 48147088Sbrooks eval ifx_routes=\$static_routes_${ifn} 49147088Sbrooks if [ -n "${ifx_routes}" ]; then 50147088Sbrooks for i in ${ifx_routes}; do 51147088Sbrooks eval route_args=\$route_${i} 52147088Sbrooks route delete ${route_args} 53147088Sbrooks done 54118840Smbr fi 55118840Smbr} 56118840Smbr 57147424Sbrooksifn=$1 58147424Sbrooksshift 59147424Sbrooksstartstop=$1 60147424Sbrooksshift 61147424Sbrooks 62147088Sbrooksload_rc_config pccard_ether 6314596Snate 64147424Sbrooks# Ignore interfaces not in removable_interfaces 65147424Sbrooksexpr "${removable_interfaces}" : ".*${ifn}" > /dev/null || exit 0 66147424Sbrooks 67147424Sbrooksif [ -n "$1" ]; then 68147424Sbrooks usage 69147424Sbrooksfi 70147424Sbrooks 7167221Sjoecase ${startstop} in 7267221Sjoe[Ss][Tt][Aa][Rr][Tt] | '') 73118840Smbr if [ -x /usr/bin/grep ]; then 74147088Sbrooks if ifconfig $ifn | grep -s netmask > /dev/null 2>&1; then 75118840Smbr # Interface is already up, so ignore it. 76118840Smbr exit 0 77118840Smbr fi 78107761Simp fi 79107761Simp 80147088Sbrooks /etc/rc.d/netif start $ifn 8170349Stoshi 82147088Sbrooks # Do route configuration if needed. 83147088Sbrooks # XXX: should probably do this by calling rc.d/routing. 84147088Sbrooks if [ -n "`ifconfig_getargs $ifn`" ]; then 85147088Sbrooks if ! dhcpif $ifn; then 86147088Sbrooks setup_routes 8770349Stoshi fi 88147088Sbrooks fi 8970349Stoshi 9067221Sjoe # IPv6 setup 91147088Sbrooks if checkyesno ipv6_enable; then 92147088Sbrooks network6_interface_setup $ifn 93147088Sbrooks fi 9463308Sume ;; 95147088Sbrooks 9667221Sjoe# Stop the interface 97147088Sbrooks[Ss][Tt][Oo][Pp]) 98147088Sbrooks if [ -n "`ifconfig_getargs $ifn`" ]; then 99147088Sbrooks if ! dhcpif $ifn; then 100147088Sbrooks remove_routes 101147088Sbrooks fi 10270349Stoshi fi 10370349Stoshi 104147088Sbrooks /etc/rc.d/netif stop $ifn 10570349Stoshi 106147088Sbrooks # clean ARP table 10770349Stoshi arp -d -a 10870349Stoshi 10970349Stoshi # Clean the routing table 110147088Sbrooks if checkyesno removable_route_flush; then 111147088Sbrooks route -n flush -inet > /dev/null 112147088Sbrooks fi 11367221Sjoe ;; 114147088Sbrooks*) 115147088Sbrooks usage 11663308Sumeesac 117