]> git.pld-linux.org Git - projects/rc-scripts.git/blob - lib/ifdown
- move network scripts to /lib, as none of them are config files
[projects/rc-scripts.git] / lib / ifdown
1 #!/bin/sh
2 #
3 #       $Id$
4 #
5 PATH=/sbin:/usr/sbin:/bin:/usr/bin
6
7 . /etc/sysconfig/network
8 . /etc/rc.d/init.d/functions
9 . /lib/rc-scripts/functions.network
10
11 # Will be removed in the future
12 if is_yes "$NETWORKING" ; then
13         if [ -z "$IPV4_NETWORKING" ] ; then
14                 echo "NETWORKING is set to YES, but IPV4_NETWORKING is empty!"
15                 echo "Please upgrade your config"
16                 echo "Assuming you want IPv4 networking"
17                 IPV4_NETWORKING=yes
18         fi
19 fi
20
21 DEV=$1
22
23 [ -z "$DEV" ] && {
24         nls "Usage: %s <device name>" "ifdown" >&2
25         exit 1
26 }
27
28 if [ -f "/etc/sysconfig/interfaces/ifcfg-$DEV" ] ; then
29         CONFIG="/etc/sysconfig/interfaces/ifcfg-$DEV"
30 else
31         CONFIG="$DEV"
32 fi
33
34 if [ "$(id -u)" != "0" ]; then
35         if [ -x /sbin/usernetctl ]; then
36                 exec /sbin/usernetctl $CONFIG down
37         fi
38         echo "Users cannot control this device." >&2
39         exit 1
40 fi
41
42 source_config
43
44 # set all major variables
45 setup_ip_param
46
47 OTHERSCRIPT="/lib/rc-scripts/ifdown-${DEVICETYPE}"
48
49 # shutdown tleds software
50 if [ "$TLEDS_DEV" = "$DEVICE" -a -x /usr/bin/tleds ]; then
51         /usr/bin/tleds -qk "$DEVICE"
52 fi
53
54 if [ -x $OTHERSCRIPT ]; then
55         if [ "$HANDLING" = "0" ]; then
56                 exec $OTHERSCRIPT $CONFIG $2
57         elif [ "$HANDLING" = "1" ]; then
58                 $OTHERSCRIPT $CONFIG $2
59         fi
60 fi
61
62 if is_yes "$ENABLE_6TO4"; then
63         tun6to4=tun6to4_$DEVICE 
64         /sbin/ip -6 route flush dev $tun6to4 2>/dev/null
65         if [ $? = 0 ]; then   # the tunnel has been set up in ifup
66                 /sbin/ip link set dev $tun6to4 down
67                 /sbin/ip tunnel del $tun6to4
68         fi
69 fi
70
71 if [ -n "$BOOTPROTO" -a "$BOOTPROTO" != "none" -a "$BOOTPROTO" != "static" ]; then
72         if is_yes "$IPV4_NETWORKING"; then
73                 set_dhcpclient
74
75                 case ${DHCP_CLIENT##*/} in
76                   pump)
77                         $DHCP_CLIENT -r -i ${DEVICE}
78                         RESULT=$?
79                         ;;
80                   dhcpcd)
81                         $DHCP_CLIENT -k ${DEVICE}
82                         RESULT=$?
83                         sleep 1
84                         ;;
85                   dhcpxd)
86                         $DHCP_CLIENT -k ${DEVICE}
87                         RESULT=$?
88                         ;;
89                   dhclient)
90                         if [ -f "/var/run/dhclient.$DEVICE.pid" ] ; then
91                                 $DHCP_CLIENT -r -pf /var/run/dhclient.$DEVICE.pid -lf /var/lib/dhclient/dhclient.$DEVICE.leases 2>/dev/null
92                                 RESULT=$?
93                         elif [ -f /var/run/dhclient.pid ]; then
94                                 # may be left by older rc-scripts
95                                 PID=$(cat /var/run/dhclient.pid)
96                                 if kill -0 $PID 2>/dev/null; then
97                                         kill $PID
98                                         RESULT=$?
99                                 fi
100                         fi
101                         ;;
102                   avahi-autoipd)
103                         $DHCP_CLIENT -k ${DEVICE}
104                         RESULT=$?
105                         ;;
106                 esac
107         fi
108 fi
109
110 if is_yes "${WLAN_WPA}"; then
111         killproc --pidfile "wpa_supplicant-${DEVICE}.pid" wpa_supplicant > /dev/null 2>&1
112         rm -f "/var/run/wpa_supplicant-${DEVICE}.pid"
113 fi
114
115 # Check to make sure the device is actually up
116 check_device_down && exit 0
117
118 if [ -n "${SUBDEVICE}" ]; then
119         ip addr del ${IP4ADDR} label ${SUBDEVICE} dev ${DEVICE}
120 else
121         LC_ALL=C ip addr flush dev ${DEVICE} 2>&1 | grep -v "Nothing to flush"
122
123         if [ ${DEVICETYPE} = "bond" ]; then
124                 if [ ! -x /sbin/ifenslave ]; then
125                         nls "%s is missing. Can't continue." "/sbin/ifenslave"
126                         exit 1
127                 fi
128
129                 # get up the bonding device before enslaving
130                 if ! check_device_down "${DEVICE}"; then
131                         ip link set ${DEVICE} up
132                 fi
133
134                 for BSVAR in $(awk '/Slave Interface:/{ print $3}' /proc/net/bonding/${DEVICE}); do
135                         if [ "${BSVAR}" ]; then
136                                 ifenslave -d ${DEVICE} $BSVAR
137                         fi
138                 done
139         fi
140
141         ip link set ${DEVICE} down
142 fi
143
144 if [ "$HANDLING" = "4" ]; then
145         exit 0
146 fi
147
148 if [ -n "$RESULT" ] ; then
149         if [ "$RESULT" -ne "0" ]; then
150                 exit $RESULT
151         fi
152 fi
153
154 exec /lib/rc-scripts/ifdown-post $CONFIG
This page took 0.069608 seconds and 4 git commands to generate.