freebsd-skq/etc/pccard_ether
brooks 5a3d620fb1 Support code for the OpenBSD dhclient. This significantly changes the
way interfaces are configured.  Some key points:

  - At startup, all interfaces are configured through /etc/rc.d/netif.
  - ifconfig_<if> variables my now mix real ifconfig commands the with
    DHCP and WPA directives.  For example, this allows media
    configuration prior to running dhclient.
  - /etc/rc.d/dhclient is not run at startup except by netif to start
    dhclient on specific interfaces.
  - /etc/pccard_ether calls "/etc/rc.d/netif start <if>" to do most of
    it's work.
  - /etc/pccard_ether no longer takes additional arguments to pass to
    ifconfig.  Instead, ifconfig_<if> variables are now honored in favor
    of pccard_ifconfig when available.
  - /etc/pccard_ether will only run on interfaces specified in
    removable_interfaces, even if pccard_ifconfig is set.
2005-06-07 04:49:12 +00:00

117 lines
2.0 KiB
Bash
Executable File

#!/bin/sh -
#
# $FreeBSD$
#
# pccard_ether interfacename [start|stop]
#
# example: pccard_ether fxp0 start
#
. /etc/rc.subr
. /etc/network.subr
usage()
{
err 3 'USAGE: $0 interface (start|stop)'
}
ifn=$1
shift
startstop=$1
shift
# Ignore interfaces not in removable_interfaces
expr "${removable_interfaces}" : ".*${ifn}" > /dev/null || exit 0
if [ -n "$1" ]; then
usage
fi
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
}
load_rc_config pccard_ether
case ${startstop} in
[Ss][Tt][Aa][Rr][Tt] | '')
if [ -x /usr/bin/grep ]; then
if ifconfig $ifn | grep -s netmask > /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
;;
# Stop the interface
[Ss][Tt][Oo][Pp])
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
;;
*)
usage
esac