From 0183822505181eb08b6077b147a504a12f34899e Mon Sep 17 00:00:00 2001 From: Pim van Pelt Date: Thu, 25 May 2023 18:24:46 +0200 Subject: [PATCH] Add address.get_canonical() and is_canonical() These functions will take either an IPv4/IPv6 address, or an IPv4/IPv6 prefix, and cast them to their canonical form. Notably for IPv6 addresses, this means lower case and with the 0-tuples correctly formatted: 2001:DB8::1 becomes 2001:db8::1 2001:db8:0:0::1 becomes 2001:db8::1 This avoids spurious diffs in vppcfg when comparing to the output of the VPP dataplane. --- vppcfg/config/loopback.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/vppcfg/config/loopback.py b/vppcfg/config/loopback.py index 5db307f..a5f1d2d 100644 --- a/vppcfg/config/loopback.py +++ b/vppcfg/config/loopback.py @@ -83,6 +83,12 @@ def validate_loopbacks(yaml): f"loopback {ifname} IP address {addr} conflicts with another" ) result = False + if not address.is_canonical(addr): + canonical = address.get_canonical(addr) + msgs.append( + f"loopback {ifname} IP address {addr} is not canonical, use {canonical}" + ) + result = False if "mac" in iface and mac.is_multicast(iface["mac"]): msgs.append( f"loopback {ifname} MAC address {iface['mac']} cannot be multicast"