freebsd-skq/etc/pccard_ether
brooks 5fea548711 MFC 1.47 and 1.48:
1.47:	Be less IPv4 centric.  When checking if the interface is
	already configured, check if the UP flag is set instead of
	checking for the netmask keyword.

1.48:	Use more rc.subr bits to clean up pccard_ether and implement
	new features.  Both the presence of a NOAUTO keyword and an
	interface being up can be ignored is the forcestart option
	is used.  Additionally, a restart option has been added.
2005-12-10 02:11:07 +00:00

131 lines
2.3 KiB
Bash
Executable File

#!/bin/sh -
#
# $FreeBSD$
#
# pccard_ether interfacename [start|stop|restart]
#
# example: pccard_ether fxp0 start
#
. /etc/rc.subr
. /etc/network.subr
name="pccard_ether"
start_precmd="checkauto"
start_cmd="pccard_ether_start"
stop_precmd="checkauto"
stop_cmd="pccard_ether_stop"
restart_precmd="checkauto"
restart_cmd="pccard_ether_restart"
setup_routes()
{
# Add default route into $static_routes
case ${defaultrouter} in
[Nn][Oo] | '')
;;
*)
static_routes="default ${static_routes}"
route_default="default ${defaultrouter}"
;;
esac
# Add private route for this interface into $static_routes
eval ifx_routes=\$static_routes_${ifn}
if [ -n "${ifx_routes}" ]; then
static_routes="${ifx_routes} ${static_routes}"
fi
# Set up any static routes if specified
if [ -n "${static_routes}" ]; then
for i in ${static_routes}; do
eval route_args=\$route_${i}
route add ${route_args}
done
fi
}
remove_routes()
{
# Delete static route if specified
eval ifx_routes=\$static_routes_${ifn}
if [ -n "${ifx_routes}" ]; then
for i in ${ifx_routes}; do
eval route_args=\$route_${i}
route delete ${route_args}
done
fi
}
checkauto()
{
if [ -z "$rc_force" ]; then
# Ignore interfaces with the NOAUTO keyword
autoif $ifn || exit 0
fi
}
pccard_ether_start()
{
if [ -z "$rc_force" -a -x /usr/bin/grep ]; then
if ifconfig $ifn | grep -s '[<,]UP[,>]' > /dev/null 2>&1; then
# Interface is already up, so ignore it.
exit 0
fi
fi
/etc/rc.d/netif start $ifn
# Do route configuration if needed.
# XXX: should probably do this by calling rc.d/routing.
if [ -n "`ifconfig_getargs $ifn`" ]; then
if ! dhcpif $ifn; then
setup_routes
fi
fi
# IPv6 setup
if checkyesno ipv6_enable; then
network6_interface_setup $ifn
fi
}
pccard_ether_stop()
{
if [ -n "`ifconfig_getargs $ifn`" ]; then
if ! dhcpif $ifn; then
remove_routes
fi
fi
/etc/rc.d/netif stop $ifn
# clean ARP table
arp -d -a
# Clean the routing table
if checkyesno removable_route_flush; then
route -n flush -inet > /dev/null
fi
}
pccard_ether_restart()
{
# Hand implemented because the default implementation runs
# the equivalent of "$0 start; $0 stop" and this script
# doesn't support that syntax
pccard_ether_stop
pccard_ether_start
}
ifn=$1
shift
if [ -z "$*" ]; then
args="start"
else
args=$*
fi
load_rc_config pccard_ether
run_rc_command $args