45d60a
#!/bin/sh
45d60a
# If we are running dhclient, shutdown running instances cleanly and
45d60a
# bring them back up on resume.
45d60a
45d60a
. "${PM_FUNCTIONS}"
45d60a
45d60a
PM_DHCLIENT_RUNDIR="${PM_UTILS_RUNDIR}/network"
45d60a
PM_DHCLIENT_SUSPEND="${PM_DHCLIENT_RUNDIR}/dhclient.suspend"
45d60a
45d60a
suspend_dhclient() {
45d60a
    [ ! -d /etc/sysconfig/network-scripts ] && return
45d60a
    [ ! -x /sbin/ifdown ] && return
45d60a
45d60a
    [ ! -d ${PM_DHCLIENT_RUNDIR} ] && /bin/mkdir -p ${PM_DHCLIENT_RUNDIR}
45d60a
    [ -f ${PM_DHCLIENT_SUSPEND} ] && /bin/rm -f ${PM_DHCLIENT_SUSPEND}
45d60a
45d60a
    cd /etc/sysconfig/network-scripts
45d60a
    for ifcfg in ifcfg-* ; do
45d60a
        # Clear relevant parameters set by previous interface
45d60a
        # (lo doesn't set them)
45d60a
        NM_CONTROLLED=
45d60a
        BOOTPROTO=
45d60a
45d60a
        . ./"${ifcfg}"
45d60a
45d60a
        if [ "${NM_CONTROLLED}" = "no" ] || [ "${NM_CONTROLLED}" = "n" ] || [ "${NM_CONTROLLED}" = "false" ]; then
45d60a
            if [ "${BOOTPROTO}" = "bootp" ] || [ "${BOOTPROTO}" = "dhcp" ] || [ -z "${BOOTPROTO}" ]; then
45d60a
                # device is not NetworkManager controlled and uses dhcp,
45d60a
                # now see if it's actually up at the moment
45d60a
                /sbin/ip link show ${DEVICE} | /bin/grep -qE "state (UP|UNKNOWN)" >/dev/null 2>&1
45d60a
                if [ $? -eq 0 ]; then
45d60a
                    echo "${DEVICE}" >> ${PM_DHCLIENT_SUSPEND}
45d60a
                    /sbin/ifdown ${DEVICE}
45d60a
                fi
45d60a
            fi
45d60a
        fi
45d60a
    done
45d60a
}
45d60a
45d60a
resume_dhclient() {
45d60a
    [ ! -f ${PM_DHCLIENT_SUSPEND} ] && return
45d60a
    [ ! -x /sbin/ifup ] && return
45d60a
45d60a
    cd /etc/sysconfig/network-scripts
45d60a
    while read device ; do
45d60a
        /sbin/ifup ${device}
45d60a
    done < ${PM_DHCLIENT_SUSPEND}
45d60a
45d60a
    /bin/rm -f ${PM_DHCLIENT_SUSPEND}
45d60a
}
45d60a
45d60a
case "$1" in
45d60a
    hibernate|suspend)
45d60a
        suspend_dhclient
45d60a
        ;;
45d60a
    thaw|resume)
45d60a
        resume_dhclient
45d60a
        ;;
45d60a
    *) exit $NA
45d60a
        ;;
45d60a
esac