mirror of
https://github.com/CumulusNetworks/ifupdown2.git
synced 2024-05-06 15:54:50 +00:00
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 <julien@cumulusnetworks.com>
This commit is contained in:
@@ -573,34 +573,31 @@ class addressvirtual(moduleBase):
|
|||||||
macvlan_ip4_ifname = "%s%s" % (self.get_vrrp_prefix(ifname, "4"), vrrp_id)
|
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)
|
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:
|
if ip4 or ifquery:
|
||||||
# config_ip4
|
merged_with_existing_obj = False
|
||||||
macvlan_ip4_mac = "00:00:5e:00:01:%s" % hex_id
|
macvlan_ip4_mac = "00:00:5e:00:01:%s" % hex_id
|
||||||
user_config_list.append({
|
macvlan_ip4_mac_int = self.mac_str_to_int(macvlan_ip4_mac)
|
||||||
"ifname": macvlan_ip4_ifname,
|
# if the vrr config is defined in different lines for the same ID
|
||||||
"hwaddress": macvlan_ip4_mac,
|
# we need to save the ip4 and ip6 in the objects we previously
|
||||||
"hwaddress_int": self.mac_str_to_int(macvlan_ip4_mac),
|
# created, example:
|
||||||
"mode": "bridge",
|
# vrrp 255 10.0.0.15/24 10.0.0.2/15
|
||||||
"ips": ip4,
|
# vrrp 255 fe80::a00:27ff:fe04:42/64
|
||||||
"id": vrrp_id
|
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:
|
elif not ip4 and not ifquery:
|
||||||
# special check to see if all ipv4 were removed from the vrrp
|
# special check to see if all ipv4 were removed from the vrrp
|
||||||
# configuration, if so we need to remove the associated macvlan
|
# configuration, if so we need to remove the associated macvlan
|
||||||
@@ -608,16 +605,31 @@ class addressvirtual(moduleBase):
|
|||||||
netlink.link_del(macvlan_ip4_ifname)
|
netlink.link_del(macvlan_ip4_ifname)
|
||||||
|
|
||||||
if ip6 or ifquery:
|
if ip6 or ifquery:
|
||||||
# config_ip6
|
merged_with_existing_obj = False
|
||||||
macvlan_ip6_mac = "00:00:5e:00:02:%s" % hex_id
|
macvlan_ip6_mac = "00:00:5e:00:02:%s" % hex_id
|
||||||
user_config_list.append({
|
macvlan_ip6_mac_int = self.mac_str_to_int(macvlan_ip6_mac)
|
||||||
"ifname": macvlan_ip6_ifname,
|
# if the vrr config is defined in different lines for the same ID
|
||||||
"hwaddress": macvlan_ip6_mac,
|
# we need to save the ip4 and ip6 in the objects we previously
|
||||||
"hwaddress_int": self.mac_str_to_int(macvlan_ip6_mac),
|
# created, example:
|
||||||
"mode": "bridge",
|
# vrrp 255 10.0.0.15/24 10.0.0.2/15
|
||||||
"ips": ip6,
|
# vrrp 255 fe80::a00:27ff:fe04:42/64
|
||||||
"id": vrrp_id
|
|
||||||
})
|
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:
|
elif not ip6 and not ifquery:
|
||||||
# special check to see if all ipv6 were removed from the vrrp
|
# special check to see if all ipv6 were removed from the vrrp
|
||||||
# configuration, if so we need to remove the associated macvlan
|
# configuration, if so we need to remove the associated macvlan
|
||||||
|
|||||||
@@ -3576,6 +3576,19 @@ class Link(NetlinkPacket):
|
|||||||
IFLA_INET6_ADDR_GEN_MODE : 'IFLA_INET6_ADDR_GEN_MODE',
|
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
|
# Subtype attrbutes AF_INET
|
||||||
IFLA_INET_UNSPEC = 0
|
IFLA_INET_UNSPEC = 0
|
||||||
IFLA_INET_CONF = 1
|
IFLA_INET_CONF = 1
|
||||||
|
|||||||
Reference in New Issue
Block a user