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