From 369ed3210ecedfa1deda88a6eb7cacc19a47f89d Mon Sep 17 00:00:00 2001 From: Fernando Fernandez Mancera Date: Mon, 26 Jul 2021 16:13:15 +0200 Subject: [PATCH 4/4] nispor: fix show of empty next_hop_address and destination The correct way of representing an empty next_hop_address is using "0.0.0.0" for IPv4 and "::" for IPv6. This configuration is valid because an user should be able to specify the following routes: ``` --- routes: config: - destination: 0.0.0.0/0 next-hop-address: 0.0.0.0 next-hop-interface: dummy - destination: ::/0 next-hop-address: "::" next-hop-interface: dummy ``` That means each of the hosts within the range of the route are considered to be directly connected through that interface. For example, using iproute2 the user should introduce the following command: `ip route 0.0.0.0 0.0.0.0 dummy` Integration test case added. Ref: https://bugzilla.redhat.com/1985879 Signed-off-by: Fernando Fernandez Mancera Signed-off-by: Gris Ge --- libnmstate/nispor/route.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/libnmstate/nispor/route.py b/libnmstate/nispor/route.py index 510ddc3..9852ba5 100644 --- a/libnmstate/nispor/route.py +++ b/libnmstate/nispor/route.py @@ -23,6 +23,9 @@ from libnmstate.schema import Route IPV4_DEFAULT_GATEWAY_DESTINATION = "0.0.0.0/0" IPV6_DEFAULT_GATEWAY_DESTINATION = "::/0" +IPV4_EMPTY_NEXT_HOP_ADDRESS = "0.0.0.0" +IPV6_EMPTY_NEXT_HOP_ADDRESS = "::" + LOCAL_ROUTE_TABLE = 255 @@ -50,21 +53,23 @@ def nispor_route_state_to_nmstate_static(np_routes): def _nispor_route_to_nmstate(np_rt): if np_rt.dst: destination = np_rt.dst - elif np_rt.gateway: + else: destination = ( IPV6_DEFAULT_GATEWAY_DESTINATION if np_rt.address_family == "ipv6" else IPV4_DEFAULT_GATEWAY_DESTINATION ) - else: - destination = "" if np_rt.via: next_hop = np_rt.via elif np_rt.gateway: next_hop = np_rt.gateway else: - next_hop = "" + next_hop = ( + IPV6_EMPTY_NEXT_HOP_ADDRESS + if np_rt.address_family == "ipv6" + else IPV4_EMPTY_NEXT_HOP_ADDRESS + ) return { Route.TABLE_ID: np_rt.table, -- 2.32.0