summaryrefslogtreecommitdiffstats
path: root/etc/pccard_ether
diff options
context:
space:
mode:
authorbrooks <brooks@FreeBSD.org>2005-06-07 04:49:12 +0000
committerbrooks <brooks@FreeBSD.org>2005-06-07 04:49:12 +0000
commit5a3d620fb15161572eed8cb406ccb6672fd2f93c (patch)
tree5b737af62b38f4124fab3c80ff903dbb7a8a0a1d /etc/pccard_ether
parent9a851b1b815c8f75342aef3c3bdd9d7943045a0d (diff)
downloadFreeBSD-src-5a3d620fb15161572eed8cb406ccb6672fd2f93c.zip
FreeBSD-src-5a3d620fb15161572eed8cb406ccb6672fd2f93c.tar.gz
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.
Diffstat (limited to 'etc/pccard_ether')
-rwxr-xr-xetc/pccard_ether296
1 files changed, 70 insertions, 226 deletions
diff --git a/etc/pccard_ether b/etc/pccard_ether
index 8c7b671..99c3204 100755
--- a/etc/pccard_ether
+++ b/etc/pccard_ether
@@ -2,271 +2,115 @@
#
# $FreeBSD$
#
-# pccard_ether interfacename [start|stop] [ifconfig option]
+# pccard_ether interfacename [start|stop]
#
-# example: pccard_ether fxp0 start link0
+# example: pccard_ether fxp0 start
#
+. /etc/rc.subr
. /etc/network.subr
-stop_dhcp() {
- # If dhclient is already running, record
- # its interfaces.
- if [ -x /usr/bin/grep ]; then
- eval _active_list=\"`/bin/ps -axwww | \
- /usr/bin/grep dhclient | \
- /usr/bin/grep -v grep | \
- /usr/bin/sed -e 's|^.*dhclient||' | \
- /usr/bin/awk '{for (i=1;i<=NF;i++) \
- { if ($i~/[a-zA-Z].[0-9]$/) \
- { printf(" %s",$i) } }}'` \
- \"
- fi
+usage()
+{
+ err 3 'USAGE: $0 interface (start|stop)'
+}
- # Get the rc.conf list of dhcp configured interfaces
- static_dhcp_list="`list_net_interfaces dhcp`"
+ifn=$1
+shift
+startstop=$1
+shift
- # Get the current ifconfig list of interfaces
- _aprefix=
- _nlist=
- for _if in ${_active_list} ; do
- _test_if=`ifconfig ${_if} 2>&1`
- case "$_test_if" in
- "ifconfig: interface $_if does not exist")
- ;;
- ${interface})
- # Don't record the same device twice.
- ;;
- *)
- #
- # Catch devices which were specified before,
- # but have not been part of the rc. We need
- # them again for the restart.
- #
- for _cif in ${static_dhcp_list} ; do
- case "$_cif" in
- ${_if})
- # Nothing to add
- ;;
- *)
- # Found interface beside rc.conf
- _nlist="${_nlist}${_aprefix}${_if}"
- ;;
- esac
- done
- _dhcplist="${_dhcplist}${_aprefix}${_if}"
- [ -z "$_aprefix" ] && _aprefix=' '
- ;;
- esac
- done
+# Ignore interfaces not in removable_interfaces
+expr "${removable_interfaces}" : ".*${ifn}" > /dev/null || exit 0
- if [ -s /var/run/dhclient.pid ]; then
- pidfile="/var/run/dhclient.pid"
- else
- return
- fi
- /sbin/dhclient -r ${interface}
- rm -f ${pidfile}
- case ${startstop} in
- [Ss][Tt][Oo][Pp])
- if [ -z "${_nlist}" ]; then
- sh /etc/rc.d/dhclient start
- else
- start_dhcp_keep_current
- fi
+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
-}
-start_dhcp() {
- stop_dhcp
- case ${pccard_ether_delay} in
- [Nn][Oo])
- ;;
- [0-9]*)
- sleep ${pccard_ether_delay}
- ;;
- esac
- [ -n "$dhcp_program" ] && dhclient_program="$dhcp_program"
- [ -n "$dhcp_flags" ] && dhclient_flags="$dhcp_flags"
- if [ -x "${dhclient_program}" ]; then
- interfaces=`echo $_dhcplist ${interface} | xargs -n 1 echo | sort -u`
- ${dhclient_program} ${dhclient_flags} ${interfaces}
- else
- echo "${dhclient_program}: DHCP client software not available"
+ # 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
-}
-# Called after detaching a card, if dhclient has been
-# used for more than one interface.
-start_dhcp_keep_current() {
- [ -n "$dhcp_program" ] && dhclient_program="$dhcp_program"
- [ -n "$dhcp_flags" ] && dhclient_flags="$dhcp_flags"
- if [ -x "${dhclient_program}" ]; then
- ${dhclient_program} ${dhclient_flags} \
- ${_dhcplist}
- else
- echo "${dhclient_program}: DHCP client software not available"
+ # 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
}
-# Suck in the configuration variables
-#
-if [ -r /etc/defaults/rc.conf ]; then
- . /etc/defaults/rc.conf
- source_rc_confs
-elif [ -r /etc/rc.conf ]; then
- . /etc/rc.conf
-fi
-
-interface=$1
-shift
-startstop=$1
-shift
+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
+}
-case ${pccard_ifconfig} in
-[Nn][Oo] | '')
- expr "${removable_interfaces}" : ".*${interface}" > /dev/null || exit 0
- ;;
-*)
- # Backward compatible
- eval ifconfig_${interface}=\${pccard_ifconfig}
- ;;
-esac
+load_rc_config pccard_ether
case ${startstop} in
[Ss][Tt][Aa][Rr][Tt] | '')
if [ -x /usr/bin/grep ]; then
- if ifconfig ${interface} | grep -s netmask > /dev/null 2>&1; then
+ if ifconfig $ifn | grep -s netmask > /dev/null 2>&1; then
# Interface is already up, so ignore it.
exit 0
fi
fi
- if [ -r /etc/start_if.${interface} ]; then
- . /etc/start_if.${interface}
- fi
+ /etc/rc.d/netif start $ifn
- eval ifconfig_args=\$ifconfig_${interface}
- case ${ifconfig_args} in
- [Nn][Oo] | '')
- ;;
- [Dd][Hh][Cc][Pp])
- # Start up the DHCP client program
- start_dhcp
- ;;
- *)
- # Do the primary ifconfig if specified
- ifconfig ${interface} ${ifconfig_args} $*
-
- # Check to see if aliases need to be added
- alias=0
- while :
- do
- eval ifx_args=\$ifconfig_${interface}_alias${alias}
- if [ -n "${ifx_args}" ]; then
- ifconfig ${interface} ${ifx_args} alias
- alias=`expr ${alias} + 1`
- else
- break;
- fi
- done
-
- # Do ipx address if specified
- eval ifx_args=\$ifconfig_${interface}_ipx
- if [ -n "${ifx_args}" ]; then
- ifconfig ${interface} ${ifx_args}
- fi
-
- # 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_${interface}
- 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
+ # 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
- ;;
- esac
+ fi
# IPv6 setup
- case ${ipv6_enable} in
- [Yy][Ee][Ss])
- if [ -r /etc/network.subr ]; then
- . /etc/network.subr
- network6_interface_setup ${interface}
- fi
- ;;
- esac
- ;;
-# Stop the interface
-*)
- if [ -r /etc/stop_if.${interface} ]; then
- . /etc/stop_if.${interface}
+ if checkyesno ipv6_enable; then
+ network6_interface_setup $ifn
fi
+ ;;
- eval ifconfig_args=\$ifconfig_${interface}
- case ${ifconfig_args} in
- [Nn][Oo] | '')
- ;;
- [Dd][Hh][Cc][Pp])
- # Stop the DHCP client for this interface
- stop_dhcp
- ;;
- *)
- # Delete static route if specified
- eval ifx_routes=\$static_routes_${interface}
- if [ -n "${ifx_routes}" ]; then
- for i in ${ifx_routes}; do
- eval route_args=\$route_${i}
- route delete ${route_args}
- done
+# Stop the interface
+[Ss][Tt][Oo][Pp])
+ if [ -n "`ifconfig_getargs $ifn`" ]; then
+ if ! dhcpif $ifn; then
+ remove_routes
fi
+ fi
- # Delete aliases if exist
- alias=0
- while :
- do
- eval ifx_args=\$ifconfig_${interface}_alias${alias}
- if [ -n "${ifx_args}" ]; then
- ifconfig ${interface} ${ifx_args} alias delete
- alias=`expr ${alias} + 1`
- else
- break;
- fi
- done
- ;;
- esac
+ /etc/rc.d/netif stop $ifn
- # Remove the network interface and cleaning ARP table
- ifconfig ${interface} delete
+ # clean ARP table
arp -d -a
# Clean the routing table
- case ${removable_route_flush} in
- [Nn][Oo])
- ;;
- *)
- # flush beforehand, just in case....
- route -n flush -inet
- ;;
- esac
+ if checkyesno removable_route_flush; then
+ route -n flush -inet > /dev/null
+ fi
;;
+*)
+ usage
esac
OpenPOWER on IntegriCloud