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