From: Julien Fortin Date: Thu, 7 Mar 2019 17:43:10 +0000 (+0100) Subject: addons: addressvirtual: vrrp: fix multiline-merge attribute detection X-Git-Tag: 1.2.8-1~29 X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=b994bd3977915e243c08e05c65fcebe6b18d0aa7;p=mirror_ifupdown2.git addons: addressvirtual: vrrp: fix multiline-merge attribute detection 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 --- diff --git a/ifupdown2/addons/addressvirtual.py b/ifupdown2/addons/addressvirtual.py index 8d0ffd0..b112b35 100644 --- a/ifupdown2/addons/addressvirtual.py +++ b/ifupdown2/addons/addressvirtual.py @@ -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 diff --git a/ifupdown2/nlmanager/nlpacket.py b/ifupdown2/nlmanager/nlpacket.py index 4e57321..2fc0b51 100644 --- a/ifupdown2/nlmanager/nlpacket.py +++ b/ifupdown2/nlmanager/nlpacket.py @@ -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