How can I release my IP on suspend and request a new one on resume?

Hi,

in my workplace IPs are a scarce ressource, this is why we are supposed to release them when we don’t need them. I tried to accomplish this in openSUSE 11.4 by placing this file in /etc/pm/sleep.d (this version already with debug code):

#!/bin/bashcase $1 in
     hibernate)
    dhcpcd --release eth0
    echo dhcpcd --release eth0: $?
    ifconfig
    ;;
     suspend)
    dhcpcd --release eth0
    echo dhcpcd --release eth0: $?
    ifconfig
    ;;
     thaw)
    dhcpcd eth0
    echo dhcpcd eth0: $?
    ifconfig
    ;;
     resume)
    dhcpcd eth0 2> /tmp/dhcpcd.err
    echo dhcpcd eth0: $?
    cat /tmp/dhcpcd.err
    ifconfig
esac



I named it 42ip since I wanted it to be called after the general NetworkManager script on resume.
However, it didn’t work. /var/log/pm-suspend.log:

Initial commandline parameters: Tue Aug 14 07:45:41 EDT 2012: Running hooks for suspend.
Running hook /usr/lib/pm-utils/sleep.d/00logging suspend suspend:
suspend initiated: Tue Aug 14 07:45:41 EDT 2012


Linux linux-0wui 2.6.37.1-1.2-desktop #1 SMP PREEMPT 2011-02-21 10:34:10 +0100 i686 i686 i386 GNU/Linux
kernel command line: 'root=/dev/sda2 resume=/dev/sda1 splash=silent quiet'
Module                  Size  Used by
autofs4                24519  1 
nls_utf8                1197  1 
udf                    90065  1 
crc_itu_t               1451  1 udf
fuse                   71688  2 
vmsync                  3234  0 
vmblock                11346  1 
af_packet              20330  0 
mperf                   1271  0 
snd_pcm_oss            48271  0 
snd_mixer_oss          17521  1 snd_pcm_oss
snd_seq_midi            5996  0 
snd_seq_midi_event      6691  1 snd_seq_midi
snd_seq                57777  2 snd_seq_midi,snd_seq_midi_event
edd                     8752  0 
dm_mod                 76266  0 
snd_ens1371            20450  4 
gameport               10001  1 snd_ens1371
snd_rawmidi            22487  2 snd_seq_midi,snd_ens1371
snd_seq_device          6678  3 snd_seq_midi,snd_seq,snd_rawmidi
snd_ac97_codec        106769  1 snd_ens1371
ac97_bus                1082  1 snd_ac97_codec
snd_pcm                88841  4 snd_pcm_oss,snd_ens1371,snd_ac97_codec
pcnet32                32959  0 
vmci                   42071  0 
vmxnet                 18175  0 
snd_timer              22055  3 snd_seq,snd_pcm
snd                    67246  16 snd_pcm_oss,snd_mixer_oss,snd_seq_midi,snd_seq,snd_ens1371,snd_rawmidi,snd_seq_device,snd_ac97_codec,snd_pcm,snd_timer
vmw_balloon             6216  0 
sg                     28446  0 
sr_mod                 15048  1 
ppdev                   7883  0 
parport_pc             33763  0 
mptctl                 26418  0 
parport                34550  2 ppdev,parport_pc
pcspkr                  1662  0 
floppy                 58277  0 
cdrom                  38437  1 sr_mod
soundcore               7270  1 snd
snd_page_alloc          8121  1 snd_pcm
i2c_piix4              10342  0 
shpchp                 27427  0 
pci_hotplug            28814  1 shpchp
button                  5497  0 
container               2583  0 
ac                      3227  0 
ext4                  373729  1 
jbd2                   78939  1 ext4
crc16                   1419  1 ext4
fan                     2575  0 
thermal                13154  0 
processor              36507  0 
thermal_sys            14790  3 fan,thermal,processor
ata_generic             3015  0 
mptspi                 14415  2 
mptscsih               25036  1 mptspi
mptbase                70667  3 mptctl,mptspi,mptscsih
scsi_transport_spi     24056  1 mptspi
vmw_pvscsi             15590  0 
vmxnet3                32982  0 


             total       used       free     shared    buffers     cached
Mem:       2039316     873420    1165896          0      49672     500256
-/+ buffers/cache:     323492    1715824
Swap:      1156092          0    1156092




/usr/lib/pm-utils/sleep.d/00logging suspend suspend: success.
Running hook /usr/lib/pm-utils/sleep.d/00powersave suspend suspend:


/usr/lib/pm-utils/sleep.d/00powersave suspend suspend: success.
Running hook /usr/lib/pm-utils/sleep.d/02rtcwake suspend suspend:
rtcwake alarm not enabled in /etc/pm/config.d/rtcwake.config, doing nothing...


/usr/lib/pm-utils/sleep.d/02rtcwake suspend suspend: success.
Running hook /usr/lib/pm-utils/sleep.d/06autofs suspend suspend:
Shutting down automount ..done


/usr/lib/pm-utils/sleep.d/06autofs suspend suspend: success.
Running hook /usr/lib/pm-utils/sleep.d/30s2disk-check suspend suspend:


/usr/lib/pm-utils/sleep.d/30s2disk-check suspend suspend: success.
Running hook /etc/pm/sleep.d/42ip suspend suspend:
err, eth0: dhcpcd not running
dhcpcd --release eth0: 1
lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:182 errors:0 dropped:0 overruns:0 frame:0
          TX packets:182 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:26212 (25.5 Kb)  TX bytes:26212 (25.5 Kb)




/etc/pm/sleep.d/42ip suspend suspend: success.
Running hook /usr/lib/pm-utils/sleep.d/45pcmcia suspend suspend:


/usr/lib/pm-utils/sleep.d/45pcmcia suspend suspend: success.
Running hook /usr/lib/pm-utils/sleep.d/49bluetooth suspend suspend:


/usr/lib/pm-utils/sleep.d/49bluetooth suspend suspend: success.
Running hook /usr/lib/pm-utils/sleep.d/50rcnetwork suspend suspend:


/usr/lib/pm-utils/sleep.d/50rcnetwork suspend suspend: success.
Running hook /usr/lib/pm-utils/sleep.d/55NetworkManager suspend suspend:
Having NetworkManager put all interaces to sleep...Failed.


/usr/lib/pm-utils/sleep.d/55NetworkManager suspend suspend: success.
Running hook /usr/lib/pm-utils/sleep.d/75modules suspend suspend:


/usr/lib/pm-utils/sleep.d/75modules suspend suspend: success.
Running hook /usr/lib/pm-utils/sleep.d/80acpi-fan suspend suspend:


/usr/lib/pm-utils/sleep.d/80acpi-fan suspend suspend: success.
Running hook /usr/lib/pm-utils/sleep.d/80videobios suspend suspend:


/usr/lib/pm-utils/sleep.d/80videobios suspend suspend: success.
Running hook /usr/lib/pm-utils/sleep.d/90clock suspend suspend:


/usr/lib/pm-utils/sleep.d/90clock suspend suspend: success.
Running hook /usr/lib/pm-utils/sleep.d/94cpufreq suspend suspend:


/usr/lib/pm-utils/sleep.d/94cpufreq suspend suspend: success.
Running hook /usr/lib/pm-utils/sleep.d/95led suspend suspend:


/usr/lib/pm-utils/sleep.d/95led suspend suspend: success.
Running hook /usr/lib/pm-utils/sleep.d/95packagekit suspend suspend:


/usr/lib/pm-utils/sleep.d/95packagekit suspend suspend: success.
Running hook /usr/lib/pm-utils/sleep.d/98video-quirk-db-handler suspend suspend:
Using last known working set of quirks.


/usr/lib/pm-utils/sleep.d/98video-quirk-db-handler suspend suspend: success.
Running hook /usr/lib/pm-utils/sleep.d/99Zgrub suspend suspend:


/usr/lib/pm-utils/sleep.d/99Zgrub suspend suspend: success.
Running hook /etc/pm/sleep.d/99at suspend suspend:


/etc/pm/sleep.d/99at suspend suspend: success.
Running hook /usr/lib/pm-utils/sleep.d/99info suspend suspend:


/usr/lib/pm-utils/sleep.d/99info suspend suspend: success.
Running hook /usr/lib/pm-utils/sleep.d/99video suspend suspend:
kernel.acpi_video_flags = 0
vbetool not installed!
vbetool not installed!
vbetool not installed!
vbetool not installed!


/usr/lib/pm-utils/sleep.d/99video suspend suspend: success.
Tue Aug 14 07:45:42 EDT 2012: performing suspend
Tue Aug 14 07:46:24 EDT 2012: Awake.
Tue Aug 14 07:46:24 EDT 2012: Running hooks for resume
Running hook /usr/lib/pm-utils/sleep.d/99video resume suspend:
vbetool not installed!
vbetool not installed!
vbetool not installed!
vbetool not installed!


/usr/lib/pm-utils/sleep.d/99video resume suspend: success.
Running hook /usr/lib/pm-utils/sleep.d/99info resume suspend:


/usr/lib/pm-utils/sleep.d/99info resume suspend: success.
Running hook /etc/pm/sleep.d/99at resume suspend:


/etc/pm/sleep.d/99at resume suspend: success.
Running hook /usr/lib/pm-utils/sleep.d/99Zgrub resume suspend:


/usr/lib/pm-utils/sleep.d/99Zgrub resume suspend: success.
Running hook /usr/lib/pm-utils/sleep.d/98video-quirk-db-handler resume suspend:


/usr/lib/pm-utils/sleep.d/98video-quirk-db-handler resume suspend: success.
Running hook /usr/lib/pm-utils/sleep.d/95packagekit resume suspend:
method return sender=:1.547 -> dest=:1.552 reply_serial=2


/usr/lib/pm-utils/sleep.d/95packagekit resume suspend: success.
Running hook /usr/lib/pm-utils/sleep.d/95led resume suspend:


/usr/lib/pm-utils/sleep.d/95led resume suspend: success.
Running hook /usr/lib/pm-utils/sleep.d/94cpufreq resume suspend:


/usr/lib/pm-utils/sleep.d/94cpufreq resume suspend: success.
Running hook /usr/lib/pm-utils/sleep.d/90clock resume suspend:


/usr/lib/pm-utils/sleep.d/90clock resume suspend: success.
Running hook /usr/lib/pm-utils/sleep.d/80videobios resume suspend:


/usr/lib/pm-utils/sleep.d/80videobios resume suspend: success.
Running hook /usr/lib/pm-utils/sleep.d/80acpi-fan resume suspend:


/usr/lib/pm-utils/sleep.d/80acpi-fan resume suspend: success.
Running hook /usr/lib/pm-utils/sleep.d/75modules resume suspend:
Reloaded unloaded modules.


/usr/lib/pm-utils/sleep.d/75modules resume suspend: success.
Running hook /usr/lib/pm-utils/sleep.d/55NetworkManager resume suspend:
Having NetworkManager wake interfaces back up...Failed.


/usr/lib/pm-utils/sleep.d/55NetworkManager resume suspend: success.
Running hook /usr/lib/pm-utils/sleep.d/50rcnetwork resume suspend:


/usr/lib/pm-utils/sleep.d/50rcnetwork resume suspend: success.
Running hook /usr/lib/pm-utils/sleep.d/49bluetooth resume suspend:


/usr/lib/pm-utils/sleep.d/49bluetooth resume suspend: success.
Running hook /usr/lib/pm-utils/sleep.d/45pcmcia resume suspend:


/usr/lib/pm-utils/sleep.d/45pcmcia resume suspend: success.
Running hook /etc/pm/sleep.d/42ip resume suspend:
dhcpcd eth0: 1
err, eth0: ioctl SIOCSIFFLAGS: Cannot allocate memory
lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:182 errors:0 dropped:0 overruns:0 frame:0
          TX packets:182 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:26212 (25.5 Kb)  TX bytes:26212 (25.5 Kb)




/etc/pm/sleep.d/42ip resume suspend: success.
Running hook /usr/lib/pm-utils/sleep.d/30s2disk-check resume suspend:


/usr/lib/pm-utils/sleep.d/30s2disk-check resume suspend: success.
Running hook /usr/lib/pm-utils/sleep.d/06autofs resume suspend:
Shutting down automount ..done
Starting automount ..done


/usr/lib/pm-utils/sleep.d/06autofs resume suspend: success.
Running hook /usr/lib/pm-utils/sleep.d/02rtcwake resume suspend:


/usr/lib/pm-utils/sleep.d/02rtcwake resume suspend: success.
Running hook /usr/lib/pm-utils/sleep.d/00powersave resume suspend:


/usr/lib/pm-utils/sleep.d/00powersave resume suspend: success.
Running hook /usr/lib/pm-utils/sleep.d/00logging resume suspend:


/usr/lib/pm-utils/sleep.d/00logging resume suspend: success.
Tue Aug 14 07:46:27 EDT 2012: Finished.



Calling dhcpcd by hand after resuming results in the same error:


err, eth0: dhcpcd not running

Also, eth0 no longer appears in ifconfig’s output, only lo.

After a reboot, eth0 is back.

Calling dhcpcd -k eth0 and dhcpcd eth0 by hand works - first the IP is released, then an another is acquired.

On 2012-08-15 10:06, jpobos wrote:
>
> Hi,
>
> in my workplace IPs are a scarce ressource, this is why we are supposed
> to release them when we don’t need them. I tried to accomplish this in
> openSUSE 11.4 by placing this file in /etc/pm/sleep.d (this version
> already with debug code):

Did you look first at “/usr/lib/pm-utils/sleep.d/50rcnetwork”? Line 37.


Cheers / Saludos,

Carlos E. R.
(from 11.4 x86_64 “Celadon” at Telcontar)

Muchas gracias robin_listas por su tip. My doesn’t run /usr/lib/pm-utils/sleep.d/50rcnetwork successfully. I get this in /var/log/pm-suspend.log


Running hook /usr/lib/pm-utils/sleep.d/50rcnetwork suspend suspend:
point 100
point 200


/usr/lib/pm-utils/sleep.d/50rcnetwork suspend suspend: success.

when I modify /usr/lib/pm-utils/sleep.d/50rcnetwork like this:


#!/bin/bash
#
# Prevent lease timing out for networks controlled by ifup/ifdown
# bnc#603291
#
# needs bash, because /etc/sysconfig/network/scripts/functions uses stuff
# only bash provides
# otherwise, you'll get this in the log:
# /usr/lib/pm-utils/sleep.d/50rcnetwork suspend suspend:/etc/sysconfig/network/scripts/functions: line 287: syntax error near unexpected token `<'
# /etc/sysconfig/network/scripts/functions: line 287: `   done < <(LC_ALL=POSIX ip -4 address list "$1" 2>/dev/null)'


. "${PM_FUNCTIONS}"


echo "point 100"


# Sanity checks
 -x /etc/init.d/network ] || exit $NA
 -r /etc/sysconfig/network/config ] && . /etc/sysconfig/network/config
 -r /etc/sysconfig/network/scripts/functions ] && . /etc/sysconfig/network/scripts/functions


echo "point 200"
command_exists dhcp_clients || exit $NA
echo "point 300"


# NetworkManager is handled by 55NetworkManager, so skip this script if
# nm is enabled in sysconfig ...
 x"${NETWORKMANAGER}" -eq x"yes" ] && exit $NA
# ... or if is running
command_exists nm_running && nm_running && exit $NA


echo "point 400"


case "$1" in
    hibernate|suspend)
        save_state "dhcp_clients" "`dhcp_clients`"
        echo "save_state \"dhcp_clients\" \"\`dhcp_clients\`\": $?"
        service network stop-all-dhcp-clients
        echo "service network stop-all-dhcp-clients: $?"
        ;;
    thaw|resume)
        for interface in `restore_state "dhcp_clients"`; do
            service network restart ${interface}
        done
        ;;
    *) exit $NA
        ;;
esac

Next I will install dhcp_clients, try again and report back.

On 2012-08-23 15:46, jpobos wrote:
>
> Muchas gracias robin_listas por su tip. My doesn’t run
> /usr/lib/pm-utils/sleep.d/50rcnetwork successfully. I get this in
> /var/log/pm-suspend.log

It is exiting in the sanity checks, because you are not using ifup method of networking. You
are probably using network manager from the desktop.


Cheers / Saludos,

Carlos E. R.
(from 12.1 x86_64 “Asparagus” at Telcontar)

Thanks for your reply, but no: it is exiting after the sanity checks - it prints “point 200”.

The problem is that ‘command_exists dhcp_clients’ fails. Which is strange, because there is no package named or containing ‘dhcp_clients’. It is used though, a bit stealthily via dhcp_clientsin the suspend|sleep case.
I also found this patch to /usr/lib/pm-utils/sleep.d/50rcnetwork , which removes the call to ‘command_exists’ with ‘dhcp_clients’: https://build.opensuse.org/package/view_file?file=pm-utils-dhcp-interfaces.patch&package=pm-utils&project=home%3ABinLi%3Abranches%3AopenSUSE%3A12.1%3AUpdate&rev=8060d14395a8d3cfd3e28d1708992e22

However, since it is for openSUSE 12.1 and I’m on 11.4, I’m hesitant to apply it. The first change discussed above does not make sense to me. The second corrects the operator: ‘-eq’ is used for numerical comparison, ‘=’ for string comparison, which is fine. The last change doesn’t seem relevant to 11.4. But it does point to a problem in my version of the file: A function ‘save_state’ is called, though /usr/lib/pm-utils/functions only defines ‘savestate’. Also, it does not tackle my main problem:

Where do I get ‘dhcp_clients’?