]> git.proxmox.com Git - mirror_ifupdown2.git/commitdiff
addons: addressvirtual: vrrp: fix multiline-merge attribute detection
authorJulien Fortin <julien@cumulusnetworks.com>
Thu, 7 Mar 2019 17:43:10 +0000 (18:43 +0100)
committerJulien Fortin <julien@cumulusnetworks.com>
Mon, 22 Apr 2019 02:53:01 +0000 (10:53 +0800)
Now we support the following config:
auto swp1
iface swp1
      vrrp 3 50.0.1.1/24
      vrrp 3 2001:50:0:1::1/64
      vrrp 3 2001:50:0:42::1/64

Signed-off-by: Julien Fortin <julien@cumulusnetworks.com>
ifupdown2/addons/addressvirtual.py
ifupdown2/nlmanager/nlpacket.py

index 8d0ffd0fe11977d19a3782e7601617e8c7c786e5..b112b35a226d1ec3c5b1358ebd69ceb249da956a 100644 (file)
@@ -573,34 +573,31 @@ class addressvirtual(moduleBase):
             macvlan_ip4_ifname = "%s%s" % (self.get_vrrp_prefix(ifname, "4"), vrrp_id)
             macvlan_ip6_ifname = "%s%s" % (self.get_vrrp_prefix(ifname, "6"), vrrp_id)
 
-            merged_with_existing_obj = False
-            # if the vrr config is defined in different lines for the same ID
-            # we need to save the ip4 and ip6 in the objects we previously
-            # created, example:
-            #       vrrp 255 10.0.0.15/24 10.0.0.2/15
-            #       vrrp 255 fe80::a00:27ff:fe04:42/64
-            for obj in user_config_list:
-                if obj.get("ifname") == macvlan_ip4_ifname:
-                    obj["ips"] += ip4
-                    merged_with_existing_obj = True
-                elif obj.get("ifname") == macvlan_ip6_ifname:
-                    obj["ips"] += ip6
-                    merged_with_existing_obj = True
-
-            if merged_with_existing_obj:
-                continue
-
             if ip4 or ifquery:
-                # config_ip4
+                merged_with_existing_obj = False
                 macvlan_ip4_mac = "00:00:5e:00:01:%s" % hex_id
-                user_config_list.append({
-                    "ifname": macvlan_ip4_ifname,
-                    "hwaddress": macvlan_ip4_mac,
-                    "hwaddress_int": self.mac_str_to_int(macvlan_ip4_mac),
-                    "mode": "bridge",
-                    "ips": ip4,
-                    "id": vrrp_id
-                })
+                macvlan_ip4_mac_int = self.mac_str_to_int(macvlan_ip4_mac)
+                # if the vrr config is defined in different lines for the same ID
+                # we need to save the ip4 and ip6 in the objects we previously
+                # created, example:
+                # vrrp 255 10.0.0.15/24 10.0.0.2/15
+                # vrrp 255 fe80::a00:27ff:fe04:42/64
+                for obj in user_config_list:
+                    if obj.get("hwaddress_int") == macvlan_ip4_mac_int:
+                        obj["ips"] += ip4
+                        merged_with_existing_obj = True
+
+                if not merged_with_existing_obj:
+                    # if ip4 config wasn't merge with an existing object
+                    # we need to insert it in our list
+                    user_config_list.append({
+                        "ifname": macvlan_ip4_ifname,
+                        "hwaddress": macvlan_ip4_mac,
+                        "hwaddress_int": macvlan_ip4_mac_int,
+                        "mode": "bridge",
+                        "ips": ip4,
+                        "id": vrrp_id
+                    })
             elif not ip4 and not ifquery:
                 # special check to see if all ipv4 were removed from the vrrp
                 # configuration, if so we need to remove the associated macvlan
@@ -608,16 +605,31 @@ class addressvirtual(moduleBase):
                     netlink.link_del(macvlan_ip4_ifname)
 
             if ip6 or ifquery:
-                # config_ip6
+                merged_with_existing_obj = False
                 macvlan_ip6_mac = "00:00:5e:00:02:%s" % hex_id
-                user_config_list.append({
-                    "ifname": macvlan_ip6_ifname,
-                    "hwaddress": macvlan_ip6_mac,
-                    "hwaddress_int": self.mac_str_to_int(macvlan_ip6_mac),
-                    "mode": "bridge",
-                    "ips": ip6,
-                    "id": vrrp_id
-                })
+                macvlan_ip6_mac_int = self.mac_str_to_int(macvlan_ip6_mac)
+                # if the vrr config is defined in different lines for the same ID
+                # we need to save the ip4 and ip6 in the objects we previously
+                # created, example:
+                # vrrp 255 10.0.0.15/24 10.0.0.2/15
+                # vrrp 255 fe80::a00:27ff:fe04:42/64
+
+                for obj in user_config_list:
+                    if obj.get("hwaddress_int") == macvlan_ip6_mac_int:
+                        obj["ips"] += ip6
+                        merged_with_existing_obj = True
+
+                if not merged_with_existing_obj:
+                    # if ip6 config wasn't merge with an existing object
+                    # we need to insert it in our list
+                    user_config_list.append({
+                        "ifname": macvlan_ip6_ifname,
+                        "hwaddress": macvlan_ip6_mac,
+                        "hwaddress_int": macvlan_ip6_mac_int,
+                        "mode": "bridge",
+                        "ips": ip6,
+                        "id": vrrp_id
+                    })
             elif not ip6 and not ifquery:
                 # special check to see if all ipv6 were removed from the vrrp
                 # configuration, if so we need to remove the associated macvlan
index 4e57321187e537d61842282438932e81cf40b57a..2fc0b5133fb7982fcd24bbb59f24456f8b058809 100644 (file)
@@ -3576,6 +3576,19 @@ class Link(NetlinkPacket):
         IFLA_INET6_ADDR_GEN_MODE    : 'IFLA_INET6_ADDR_GEN_MODE',
     }
 
+    # IFLA_INET6_ADDR_GEN_MODE values
+    IN6_ADDR_GEN_MODE_EUI64 = 0
+    IN6_ADDR_GEN_MODE_NONE = 1
+    IN6_ADDR_GEN_MODE_STABLE_PRIVACY = 2
+    IN6_ADDR_GEN_MODE_RANDOM = 3
+
+    ifla_inet6_addr_gen_mode_dict = {
+        IN6_ADDR_GEN_MODE_EUI64: "eui64",
+        IN6_ADDR_GEN_MODE_NONE: "none",
+        IN6_ADDR_GEN_MODE_STABLE_PRIVACY: "stable_secret",
+        IN6_ADDR_GEN_MODE_RANDOM: "random"
+    }
+
     # Subtype attrbutes AF_INET
     IFLA_INET_UNSPEC    = 0
     IFLA_INET_CONF      = 1