PERFORCE change 66271 for review
Sam Leffler
sam at FreeBSD.org
Thu Dec 2 12:34:39 PST 2004
http://perforce.freebsd.org/chv.cgi?CH=66271
Change 66271 by sam at sam_ebb on 2004/12/02 20:34:13
overhaul for new world order; needs more cleanup and testing
Affected files ...
.. //depot/projects/wifi/etc/pccard_ether#2 edit
Differences ...
==== //depot/projects/wifi/etc/pccard_ether#2 (text+ko) ====
@@ -9,79 +9,17 @@
. /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
+# 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
- # Get the rc.conf list of dhcp configured interfaces
- static_dhcp_list="`list_net_interfaces dhcp`"
-
- # 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
-
- 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
- ;;
- *)
- ;;
- esac
-}
-
-start_dhcp() {
- stop_dhcp
+start_dhcp()
+{
case ${pccard_ether_delay} in
[Nn][Oo])
;;
@@ -89,37 +27,60 @@
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}
+ ${dhclient_program} ${dhclient_flags} ${interface}
else
echo "${dhclient_program}: DHCP client software not available"
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}
+ifn_isup()
+{
+ if [ -x /usr/bin/grep ]; then
+ ifconfig ${interface} | grep -s netmask > /dev/null 2>&1
+ return # returns grep exit status
else
- echo "${dhclient_program}: DHCP client software not available"
+ return 0 # cannot tell
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
+# XXX these come from rc.d/netif; if they get moved to network.subr
+# XXX we can delete our private copies
+
+ifn_start()
+{
+ local ifn cfg
+ ifn="$1"
+ cfg=1
+
+ [ -z "$ifn" ] && return 1
+
+ ifscript_up ${ifn} && cfg=0
+ ifconfig_up ${ifn} && cfg=0
+ ifalias_up ${ifn} && cfg=0
+ ipx_up ${ifn} && cfg=0
+
+ return $cfg
+}
+
+ifn_stop()
+{
+ local ifn cfg
+ ifn="$1"
+ cfg=1
+
+ [ -z "$ifn" ] && return 1
+
+ ipx_down ${ifn} && cfg=0
+ ifalias_down ${ifn} && cfg=0
+ ifconfig_down ${ifn} && cfg=0
+ ifscript_down ${ifn} && cfg=0
+
+ return $cfg
+}
interface=$1
shift
@@ -138,47 +99,21 @@
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
- # Interface is already up, so ignore it.
- exit 0
- fi
- fi
+ ifn_isup ${interface} && exit 0 # already configured
- if [ -r /etc/start_if.${interface} ]; then
- . /etc/start_if.${interface}
- fi
-
eval ifconfig_args=\$ifconfig_${interface}
case ${ifconfig_args} in
[Nn][Oo] | '')
;;
[Dd][Hh][Cc][Pp])
- # Start up the DHCP client program
- start_dhcp
+ ifscript_up ${interface} # run any script
+ start_dhcp # start DHCP client program
;;
*)
- # Do the primary ifconfig if specified
- ifconfig ${interface} ${ifconfig_args} $*
+ ifn_start ${interface} # static configuration
- # 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
+ # XXX this mimics what's in rc.d/routing and should
+ # XXX probably pulled up into network.subr
# Add default route into $static_routes
case ${defaultrouter} in
@@ -209,26 +144,22 @@
# IPv6 setup
case ${ipv6_enable} in
[Yy][Ee][Ss])
- if [ -r /etc/network.subr ]; then
- . /etc/network.subr
- network6_interface_setup ${interface}
- fi
+ network6_interface_setup ${interface}
;;
esac
;;
# Stop the interface
*)
- if [ -r /etc/stop_if.${interface} ]; then
- . /etc/stop_if.${interface}
- fi
-
eval ifconfig_args=\$ifconfig_${interface}
case ${ifconfig_args} in
[Nn][Oo] | '')
;;
[Dd][Hh][Cc][Pp])
+ ifscript_down ${interface} # run any script
+
# Stop the DHCP client for this interface
- stop_dhcp
+ # nothing to do; any dhclient will note the interface
+ # go down and terminate
;;
*)
# Delete static route if specified
@@ -240,33 +171,14 @@
done
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
+ ifn_down ${interface}
;;
esac
- # Remove the network interface and cleaning ARP table
- ifconfig ${interface} delete
+ #
+ # Remove the network interface and cleanup ARP table
+ # XXX no way to limit arp flush to one interface
+ #
+ ifconfig ${interface} delete down
arp -d -a
-
- # Clean the routing table
- case ${removable_route_flush} in
- [Nn][Oo])
- ;;
- *)
- # flush beforehand, just in case....
- route -n flush -inet
- ;;
- esac
- ;;
esac
More information about the p4-projects
mailing list