-#!/bin/bash
+#!/bin/sh
#
-# network Bring up/down networking
+# network Bring up/down networking
#
-# chkconfig: 345 10 97
-# description: Activates/Deactivates all network interfaces configured to \
-# start at boot time.
-# probe: true
+# chkconfig: 2345 10 90
+# description: Activates/Deactivates all network interfaces configured to \
+# start at boot time.
+#
+# probe: true
+
+# $Id: network,v 1.58 2002/12/17 14:01:10 baggins Exp $
+
+PATH=/sbin:/usr/sbin:/bin:/usr/bin
+
+# NLS
+NLS_DOMAIN="rc-scripts"
# Source function library.
. /etc/rc.d/init.d/functions
+. /etc/sysconfig/network-scripts/functions.network
if [ ! -f /etc/sysconfig/network ]; then
- exit 0
+ nls "%s is missing. Can't continue." "/etc/sysconfig/network"
+ exit 1
fi
. /etc/sysconfig/network
-if [ -f /etc/sysconfig/pcmcia ]; then
- . /etc/sysconfig/pcmcia
-fi
-
-if [ -f /etc/sysconfig/network-ip6 ]; then
- . /etc/sysconfig/network-ip6
-fi
-
# Check that networking is up.
-[ ${NETWORKING} = "no" ] && exit 0
-
-[ -x /sbin/ifconfig ] || exit 0
-
-# Load IPv6 module
-
-if [ ${IP6NETWORKING} = "yes" ]; then
- if [ -r /lib/modules/`uname -r`/ipv6/ipv6.o ]; then
- /sbin/modprobe net-pf-10
+is_no "${NETWORKING}" && exit 0
+
+# Will be removed in the future
+if is_yes "$NETWORKING" ; then
+ if [ -z "$IPV4_NETWORKING" ] ; then
+ echo "NETWORKING is set to YES, but IPV4_NETWORKING is empty!"
+ echo "Please upgrade your config"
+ echo "Assuming you want IPv4 networking"
+ IPV4_NETWORKING=yes
fi
fi
-# Even if IPX is configured, without the utilities we can't do much
-[ ! -x /usr/bin/ipx_internal_net -o ! -x /usr/bin/ipx_configure ] && IPX=
-
-cd /etc/sysconfig/network-scripts
-
-# find all the interfaces besides loopback.
-# ignore aliases, alternative configurations, and editor backup files
-interfaces=`ls ifcfg* | egrep -v '(ifcfg-lo|:)' | egrep 'ifcfg-[a-z0-9]+$' | \
- sed 's/^ifcfg-//g'`
+if [ ! -x /sbin/ip ]; then
+ nls "%s is missing. Can't continue." "/sbin/ip"
+ exit 1
+fi
-ipv4_forward_set ()
+######
+# initialize networking:
+# - check IPv4, IPv6, IPX can be handled by system
+# - setup default IPv{4,6} interfaces policy like:
+# - spoofig protection,
+# - icmp echo ignore broadcasts,
+# - setup lo interface
+network_init()
{
- # Turn IP forwarding on or off. We do this before bringing up the
- # interfaces to make sure we don't forward when we shouldn't, and
- # we do it even if networking isn't configured (why not?).
- if [ -d /proc/sys/net/ipv4 ]; then
- # people could have left this out of their kernel, which isn't
- # exactly an error
- if [ ! -f /proc/sys/net/ipv4/ip_forward ] ; then
- echo "/proc/sys/net/ipv4/ip_forward is missing --" \
- "cannot control IP forwarding" >&2
- else
- if [ "$FORWARD_IPV4" = "no" -o "$FORWARD_IPV4" = "false" ]; then
- value=0
- message="Disabling IPv4 packet forwarding."
+# Modprobe needed devices
+modprobe_net
+
+# Kernel network parameters
+run_cmd "Setting network parameters" sysctl -p /etc/sysctl.conf
+
+# Set UP loopback interface
+set_up_loopback
+
+# Setup configuration
+setup_nat on
+setup_routes on
+setup_ip_rules on
+# Setup IPX
+if is_yes "$IPX"; then
+ if [ -n $IPXAUTOPRIMARY ] ; then
+ if is_yes "$IPXAUTOPRIMARY"; then
+ IPXAUTOPRIMARY="on"
else
- value=1
- message="Enabling IPv4 packet forwarding."
+ IPXAUTOPRIMARY="off"
fi
-
- if [ $value != `cat /proc/sys/net/ipv4/ip_forward` ]; then
- show $message
- busy
- echo "$value" > /proc/sys/net/ipv4/ip_forward
- deltext
- ok
+ /sbin/ipx_configure --auto_primary=$IPXAUTOPRIMARY
+ fi
+ if [ -n $IPXAUTOFRAME ] ; then
+ if is_yes "$IPXAUTOFRAME"; then
+ IPXAUTOFRAME="on"
+ else
+ IPXAUTOFRAME="off"
fi
- fi
+ /sbin/ipx_configure --auto_interface=$IPXAUTOFRAME
+ fi
+ if [ -n "$IPXINTERNALNETNUM" -a "$IPXINTERNALNETNUM" != "0" ]; then
+ /sbin/ipx_internal_net add $IPXINTERNALNETNUM $IPXINTERNALNODENUM
fi
+fi
}
-ipv4_spoof_protection ()
+network_postinit()
{
-# This is the best method: turn on Source Address Verification and get
-# spoof protection on all current and future interfaces.
-if [ -e /proc/sys/net/ipv4/conf/all/rp_filter ]; then
- show Setting up IP spoofing protection
- busy
- for f in /proc/sys/net/ipv4/conf/*/rp_filter; do
- echo 1 > $f
- done
- deltext
- ok
- else
- deltext
- fail
- echo "PROBLEMS SETTING UP IP SPOOFING PROTECTION. BE WORRIED!"
-fi
+# Set static RARP table
+static_rarp
+
+# Set static ARP table
+static_arp
+}
+
+######
+# deinitialize networking
+# - down lo interface.
+network_deinit()
+{
+setup_routes off
+setup_ip_rules off
+
+# Set down NAT rules
+setup_nat off
+# Set DOWN loopback interface
+set_down_loopback
}
+# find all the interfaces besides loopback.
+# ignore aliases, alternative configurations, and editor backup files
+interfaces_boot=$((
+ . /etc/rc.d/init.d/functions; \
+ cd /etc/sysconfig/interfaces && ls -1 ifcfg* | \
+ egrep -v '(ifcfg-lo|ifcfg-sit|ifcfg-atm|ifcfg-lec|ifcfg-nas|:)' | \
+ egrep 'ifcfg-[a-z0-9\.]+$' | \
+ for i in `cat`; do \
+ ONBOOT=""; . /etc/sysconfig/interfaces/"$i"; is_yes "$ONBOOT" && echo "$i"; \
+ done | \
+ awk ' { gsub(/ifcfg-/,NIL); print $0 } ') 2> /dev/null)
+interfaces_sit_boot=$((
+ . /etc/rc.d/init.d/functions; \
+ cd /etc/sysconfig/interfaces && ls -1 ifcfg-sit* | \
+ egrep 'ifcfg-[a-z0-9]+$' | \
+ for i in `cat`; do \
+ ONBOOT=""; . /etc/sysconfig/interfaces/"$i"; is_yes "$ONBOOT" && echo "$i"; \
+ done | \
+ awk ' { gsub(/ifcfg-/,NIL); print $0 } ') 2> /dev/null)
+tunnels=$((cd /etc/sysconfig/interfaces && ls -1 tnlcfg-* | \
+ xargs egrep -l "ONBOOT=[^n][^o]" | \
+ awk ' { gsub(/tnlcfg-/,NIL); print $0 } ') 2> /dev/null)
+
# See how we were called.
case "$1" in
start)
- ipv4_forward_set
+ network_init
- ./ifup ifcfg-lo
-
- case "$IPX" in
- yes|true)
- /usr/bin/ipx_configure --auto_primary=$IPXAUTOPRIMARY \
- --auto_interface=$IPXAUTOFRAME
- /usr/bin/ipx_internal_net add $IPXINTERNALNETNUM $IPXINTERNALNODENUM
- ;;
- esac
-
- for i in $interfaces; do
- ./ifup $i boot
+ for i in $interfaces_boot $interfaces_sit_boot ; do
+ run_cmd -a "$(nls 'Bringing up interface') $i" /sbin/ifup $i boot
done
- ipv4_spoof_protection
+ for i in $tunnels; do
+ run_cmd -a "$(nls 'Setting tunnel') $i" /sbin/tnlup $i boot
+ run_cmd -a "$(nls 'Bringing up tunnel interface') $i" /sbin/ifup tnlcfg-$i boot
+ done
+
+ network_postinit
touch /var/lock/subsys/network
;;
stop)
- for i in $interfaces; do
- ./ifdown $i boot
+ # If we go to runlevel 0, 1 or 6 then umount all network fs
+ if [ "$RUNLEVEL" = "6" -o "$RUNLEVEL" = "0" -o "$RUNLEVEL" = "1" ]; then
+ if [ -x /etc/rc.d/init.d/netfs -a -f /var/lock/subsys/netfs ];
+ then
+ /etc/rc.d/init.d/netfs stop
+ else
+ netmtab=$(awk '{ if ($3 ~ /^(nfs|smbfs|ncpfs)$/ ) print $3}' /proc/mounts)
+ if (echo "$netmtab" | grep -q nfs); then
+ run_cmd "Unmounting NFS filesystems" umount -fat nfs
+ fi
+ if (echo "$netmtab" | grep -q smbfs); then
+ run_cmd "Unmounting SMB filesystems" umount -at smbfs
+ fi
+ if (echo "$netmtab" | grep -q ncpfs); then
+ run_cmd "Unmounting NCP filesystems" umount -at ncpfs
+ fi
+ fi
+ fi
+
+ for i in $tunnels; do
+ run_cmd -a "$(nls 'Shutting down tunnel interface') $i" /sbin/ifdown tnlcfg-$i boot
+ run_cmd -a "$(nls 'Removing tunnel') $i" /sbin/tnldown $i boot
+ done
+
+ for i in $interfaces_sit_boot $interfaces_boot ; do
+ run_cmd -a "$(nls 'Shutting down interface') $i" /sbin/ifdown $i boot
done
- case "$IPX" in
- yes|true)
- /usr/bin/ipx_internal_net del
- ;;
- esac
- ./ifdown ifcfg-lo
- echo "Disabling IPv4 packet forwarding."
- echo 0 > /proc/sys/net/ipv4/ip_forward
+
+ network_deinit
+
rm -f /var/lock/subsys/network
;;
status)
- echo "Configured devices:"
- echo lo $interfaces
-
- if [ -x /bin/linuxconf ] ; then
- eval `/bin/linuxconf --hint netdev`
- echo "Devices that are down:"
- echo $DEV_UP
- echo "Devices with modified configuration:"
- echo $DEV_RECONF
- else
- echo "Currently active devices:"
- echo `/sbin/ifconfig | grep ^[a-z] | awk '{print $1}'`
- fi
+ nls "Configured devices:"
+ echo "lo $interfaces"
+ nls "Configured tunnels:"
+ echo "$tunnels"
+ echo
+ nls "Currently inactive devices and tunnels:"
+ /sbin/ip link show | awk -F":" '(/^[0-90-90-9]:/) && ! (/UP/) { print $2 }' | xargs
+ nls "Currently active devices and tunnels:"
+ /sbin/ip link show | awk -F":" ' (/UP/) { print $2 }' | xargs
;;
restart)
$0 stop
$0 start
;;
- reload)
- if [ -x /bin/linuxconf ] ; then
- eval `/bin/linuxconf --hint netdev`
- if [ "$RECONF_IPV4ROUTING" = "yes" ] ; then
- ipv4_forward_set
- fi
- for device in $DEV_UP ; do
- ./ifup $device
- done
- for device in $DEV_DOWN ; do
- ./ifdown $device
- done
- for device in $DEV_RECONF ; do
- ./ifdown $device
- ./ifup $device
- done
- for device in $DEV_RECONF_ALIASES ; do
- /etc/sysconfig/network-scripts/ifup-aliases $device
- done
- for device in $DEV_RECONF_ROUTES ; do
- /etc/sysconfig/network-scripts/ifup-routes $device
- done
- case $IPX in yes|true)
- case $IPXINTERNALNET in
- reconf)
- /usr/bin/ipx_internal_net del
- /usr/bin/ipx_internal_net add $IPXINTERNALNETNUM \
- $IPXINTERNALNODENUM
- ;;
- add)
- /usr/bin/ipx_internal_net add $IPXINTERNALNETNUM \
- $IPXINTERNALNODENUM
- ;;
- del)
- /usr/bin/ipx_internal_net del
- ;;
- esac
- ;;
- esac
- else
- $0 restart
- fi
- ;;
- probe)
- if [ -x /bin/linuxconf ] ; then
- eval `/bin/linuxconf --hint netdev`
- [ -n "$DEV_UP$DEV_DOWN$DEV_RECONF$DEV_RECONF_ALIASES" -o \
- -n "$DEV_RECONF_ROUTES$IPXINTERNALNET" -o \
- "$RECONF_IPV4ROUTING" = yes ] && \
- echo reload
- exit 0
- else
- # if linuxconf isn't around to figure stuff out for us,
- # we punt. Probably better than completely reloading
- # networking if user isn't sure which to do. If user
- # is sure, they would run restart or reload, not probe.
- exit 0
- fi
- ;;
*)
- echo "Usage: network {start|stop|restart|reload|status|probe}"
+ echo "Usage: $0 {start|stop|restart|status}"
exit 1
esac
exit 0
+
+# This must be last line !
+# vi:syntax=sh:tw=78:ts=8:sw=4