[PATCH 10/10] nss: handle leases with infinite expiry time

Michal Privoznik mprivozn at redhat.com
Fri Dec 18 15:09:16 UTC 2020


After v6.3.0-rc1~64 a lease can have infinite expiry time. This
means that the expiration time will appear as a value of zero.
Do the expiration check only if the expiration time is not zero.

Fixes: 97a0aa246799c97d0a9ca9ecd6b4fd932ae4756c
Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
---
 tests/nssdata/virbr0.status    | 7 +++++++
 tests/nsstest.c                | 2 +-
 tools/nss/libvirt_nss_leases.c | 4 +++-
 3 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/tests/nssdata/virbr0.status b/tests/nssdata/virbr0.status
index 78afaf6200..354715bb1c 100644
--- a/tests/nssdata/virbr0.status
+++ b/tests/nssdata/virbr0.status
@@ -21,5 +21,12 @@
         "ip-address": "192.168.122.2",
         "mac-address": "52:54:00:11:22:33",
         "expiry-time": 2000000000
+    },
+    {
+        "ip-address": "192.168.122.3",
+        "mac-address": "52:54:00:a4:6f:91",
+        "hostname": "fedora",
+        "client-id": "01:52:54:00:a4:6f:91",
+        "expiry-time": 0
     }
 ]
diff --git a/tests/nsstest.c b/tests/nsstest.c
index 135f6b6c93..a4e8a4a37f 100644
--- a/tests/nsstest.c
+++ b/tests/nsstest.c
@@ -173,7 +173,7 @@ mymain(void)
     } while (0)
 
 # if !defined(LIBVIRT_NSS_GUEST)
-    DO_TEST("fedora", AF_INET, "192.168.122.197", "192.168.122.198", "192.168.122.199");
+    DO_TEST("fedora", AF_INET, "192.168.122.197", "192.168.122.198", "192.168.122.199", "192.168.122.3");
     DO_TEST("gentoo", AF_INET, "192.168.122.254");
     DO_TEST("gentoo", AF_INET6, "2001:1234:dead:beef::2");
     DO_TEST("gentoo", AF_UNSPEC, "192.168.122.254");
diff --git a/tools/nss/libvirt_nss_leases.c b/tools/nss/libvirt_nss_leases.c
index 015bbc4ab6..536fcf8608 100644
--- a/tools/nss/libvirt_nss_leases.c
+++ b/tools/nss/libvirt_nss_leases.c
@@ -276,7 +276,8 @@ findLeasesParserEndMap(void *ctx)
             found = true;
     }
     DEBUG("Found %d", found);
-    if (parser->entry.expiry < parser->now) {
+    if (parser->entry.expiry != 0 &&
+        parser->entry.expiry < parser->now) {
         DEBUG("Entry expired at %llu vs now %llu",
               parser->entry.expiry, parser->now);
         found = false;
@@ -298,6 +299,7 @@ findLeasesParserEndMap(void *ctx)
     free(parser->entry.macaddr);
     free(parser->entry.ipaddr);
     free(parser->entry.hostname);
+    parser->entry.expiry = 0;
     parser->entry.macaddr = NULL;
     parser->entry.ipaddr = NULL;
     parser->entry.hostname = NULL;
-- 
2.26.2




More information about the libvir-list mailing list