]> git.proxmox.com Git - mirror_ifupdown2.git/commitdiff
addons: address: Fix handling of 'pointopoint' attr. (#23)
authorMaximilian Wilhelm <max+gh@rfc2324.org>
Wed, 23 Aug 2017 21:11:57 +0000 (23:11 +0200)
committerJulien Fortin <julien@cumulusnetworks.com>
Tue, 13 Mar 2018 03:54:05 +0000 (14:54 +1100)
Due to a simple logic bug the 'pointopoint' attribute was ignored when
  specifying and address as <ip/mask> and only considered when IP and mask
  where given seperately. This commit fixes this behaviour.

  When configured in ptp mode »ip addr« will show the IP address without a
  netmask which will make »ifquery -c« mark the IP as failed. The check has
  been fixed, too.

Signed-off-by: Maximilian Wilhelm <max@rfc2324.org>
addons/address.py

index 29e2bfad140f8dbf6b5e5fba338e605351c10ed7..b5628f3f82cea54f56885f7f5d4d744278cb4b1c 100644 (file)
@@ -202,21 +202,21 @@ class address(moduleBase):
             # If user address is not in CIDR notation, convert them to CIDR
             for addr_index in range(0, len(addrs)):
                 addr = addrs[addr_index]
+                newaddr = addr
                 if '/' in addr:
                     newaddrs.append(addr)
-                    continue
-                newaddr = addr
-                netmask = ifaceobj.get_attr_value_n('netmask', addr_index)
-                if netmask:
-                    prefixlen = IPNetwork('%s' %addr +
-                                '/%s' %netmask).prefixlen
-                    newaddr = addr + '/%s' %prefixlen
                 else:
-                    # we are here because there is no slash (/xx) and no netmask
-                    # just let IPNetwork handle the ipv4 or ipv6 address mask
-                    prefixlen = IPNetwork(addr).prefixlen
-                    newaddr = addr + '/%s' %prefixlen
-                newaddrs.append(newaddr)
+                    netmask = ifaceobj.get_attr_value_n('netmask', addr_index)
+                    if netmask:
+                        prefixlen = IPNetwork('%s' %addr +
+                                    '/%s' %netmask).prefixlen
+                        newaddr = addr + '/%s' %prefixlen
+                    else:
+                        # we are here because there is no slash (/xx) and no netmask
+                        # just let IPNetwork handle the ipv4 or ipv6 address mask
+                        prefixlen = IPNetwork(addr).prefixlen
+                        newaddr = addr + '/%s' %prefixlen
+                    newaddrs.append(newaddr)
 
                 attrs = {}
                 for a in ['broadcast', 'pointopoint', 'scope',
@@ -631,6 +631,9 @@ class address(moduleBase):
         if not runningaddrsdict and not addrs:
             return
         runningaddrs = runningaddrsdict.keys() if runningaddrsdict else []
+        # Add /32 netmask to configured address without netmask.
+        # This may happen on interfaces where pointopoint is used.
+        runningaddrs = [ addr if '/' in addr else addr + '/32' for addr in runningaddrs]
         if runningaddrs != addrs:
             runningaddrsset = set(runningaddrs) if runningaddrs else set([])
             addrsset = set(addrs) if addrs else set([])