Page MenuHomeVyOS Platform

Error when re-configuring an interface from DHCP to static IP
Closed, ResolvedPublicBUG

Description

I found a non-critical (mostly cosmetic) bug in VyOS 1.2.0 RC9, which occurs when an interface is configure to use DHCP and then is re-configured with a static IP.

Steps to reproduce:

Clear old config:

delete interfaces ethernet eth0 address

Enable DHCP on interface:

set interfaces ethernet eth0 address dhcp
commit

Reconfigure to static IP:

set interfaces ethernet eth0 address 192.168.139.5/24
delete interfaces ethernet eth0 address dhcp
commit

Resulting error message:

Traceback (most recent call last):
  File "/usr/libexec/vyos/system/normalize-ip", line 32, in <module>
    address_string, prefix_length = re.match(r'(.+)/(.+)', sys.argv[1]).groups()
AttributeError: 'NoneType' object has no attribute 'groups'

The problem here is that the regular expression is applied to the "dhcp" string, which fails for obvious reasons.

Details

Difficulty level
Unknown (require assessment)
Version
VyOS 1.2.0 RC9
Why the issue appeared?
Will be filled on close

Event Timeline

syncer triaged this task as Normal priority.
syncer edited projects, added VyOS 1.2 Crux (VyOS 1.2.0-rc10); removed VyOS 1.2 Crux.
hagbard changed the task status from Open to In progress.Nov 29 2018, 8:36 PM

Actually it returns the IP allocated via DHCP, however the ip-normalize script needs a prefix for the regex, which is not set when dhcp was set.

I did some further investigation on this topic, and it turned out that this is a more general problem, which does not just happen in the specific case I wrote above.
It basically happens anytime when an interface is first configured via DHCPv4 and then DHCPv4 is disabled later.

Easier way to reproduce:

Activate DHCP for a given interface

delete interfaces ethernet eth0 address
set interfaces ethernet eth0 address dhcp
commit

De-activate DHCP

delete interfaces ethernet eth0 address
set interfaces ethernet eth0 address dhcp
commit

Resulting error message:

Traceback (most recent call last):
  File "/usr/libexec/vyos/system/normalize-ip", line 32, in <module>
    address_string, prefix_length = re.match(r'(.+)/(.+)', sys.argv[1]).groups()
AttributeError: 'NoneType' object has no attribute 'groups'

The problem is:
The file "/opt/vyatta/sbin/vyatta-address" calls "/usr/libexec/vyos/system/normalize-ip" with the IP address.
In case of a DHCPv4 configured interface, the IPv4 address is parsed from the dhclient lease file and then passed to the "normalize-ip" script.
That script expects an address with network prefix in CIDR notation, which is not provided here (only the pure IPv4 address is passed).

This may also apply to DHCPv6.

Ooops X-fire. I grab the IP and prefix from the interface, that way I know it exists and can be removed and won't have to many test cycles. The subsystem needs to be rewritten at one point, but as you can imagine that is quite a task. DHCPv6 won't be affected since it uses always IP/prefix, but I haven't tested it yet.