Blame SOURCES/0004-nispor-fix-show-of-empty-next_hop_address-and-destin.patch

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