Skip to content

Commit

Permalink
Python/ifconfig: T1712: always start DHCP when configured
Browse files Browse the repository at this point in the history
DHCP was only started when the interface operstate was set to up but this is
wrong. An interface can be configured as DHCP interface and DHCP client must
be launched even when the physical interface becomes available n-minutes
later. DHCP client then can ask for an IP assignemnt by DHCP.

Tested by starting DHCP client on a not connected ethernet interface. Address
was assigned later on after link became ready.
  • Loading branch information
c-po committed Oct 18, 2019
1 parent ca4f0dc commit 04c02bc
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions python/vyos/ifconfig.py
Expand Up @@ -521,14 +521,13 @@ def _set_dhcp(self):
with open(self._dhcp_cfg_file, 'w') as f:
f.write(dhcp_text)

if self.get_state() == 'up':
cmd = 'start-stop-daemon --start --quiet --pidfile ' + \
self._dhcp_pid_file
cmd += ' --exec /sbin/dhclient --'
# now pass arguments to dhclient binary
cmd += ' -4 -nw -cf {} -pf {} -lf {} {}'.format(
self._dhcp_cfg_file, self._dhcp_pid_file, self._dhcp_lease_file, self._ifname)
return self._cmd(cmd)
cmd = 'start-stop-daemon --start --quiet --pidfile ' + \
self._dhcp_pid_file
cmd += ' --exec /sbin/dhclient --'
# now pass arguments to dhclient binary
cmd += ' -4 -nw -cf {} -pf {} -lf {} {}'.format(
self._dhcp_cfg_file, self._dhcp_pid_file, self._dhcp_lease_file, self._ifname)
return self._cmd(cmd)


def _del_dhcp(self):
Expand Down

0 comments on commit 04c02bc

Please sign in to comment.