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