]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: fix json generation
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 8 Nov 2023 16:23:12 +0000 (01:23 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 8 Nov 2023 16:30:03 +0000 (01:30 +0900)
When the DHCPv6 client is running in the information requesting mode,
then T1 and T2 are not set.

src/network/networkd-json.c

index 6e53d368d293048d80bbafa561160b0f008359ae..a72eb4ca3a948180d71b6096b3e01a19eefbbdf2 100644 (file)
@@ -1057,7 +1057,7 @@ static int dhcp6_client_vendor_options_append_json(Link *link, JsonVariant **v)
                                                             JSON_BUILD_PAIR_UNSIGNED("SubOptionCode", (*option)->option),
                                                             JSON_BUILD_PAIR_HEX("SubOptionData", (*option)->data, (*option)->length)));
                 if (r < 0)
-                        return 0;
+                        return r;
         }
 
         return json_variant_set_field_non_null(v, "VendorSpecificOptions", array);
@@ -1065,7 +1065,7 @@ static int dhcp6_client_vendor_options_append_json(Link *link, JsonVariant **v)
 
 static int dhcp6_client_lease_append_json(Link *link, JsonVariant **v) {
         _cleanup_(json_variant_unrefp) JsonVariant *w = NULL;
-        usec_t ts, t1, t2;
+        usec_t ts = USEC_INFINITY, t1 = USEC_INFINITY, t2 = USEC_INFINITY;
         int r;
 
         assert(link);
@@ -1075,15 +1075,15 @@ static int dhcp6_client_lease_append_json(Link *link, JsonVariant **v) {
                 return 0;
 
         r = sd_dhcp6_lease_get_timestamp(link->dhcp6_lease, CLOCK_BOOTTIME, &ts);
-        if (r < 0)
+        if (r < 0 && r != -ENODATA)
                 return r;
 
         r = sd_dhcp6_lease_get_t1_timestamp(link->dhcp6_lease, CLOCK_BOOTTIME, &t1);
-        if (r < 0)
+        if (r < 0 && r != -ENODATA)
                 return r;
 
         r = sd_dhcp6_lease_get_t2_timestamp(link->dhcp6_lease, CLOCK_BOOTTIME, &t2);
-        if (r < 0)
+        if (r < 0 && r != -ENODATA)
                 return r;
 
         r = json_build(&w, JSON_BUILD_OBJECT(
@@ -1161,7 +1161,7 @@ static int dhcp6_client_append_json(Link *link, JsonVariant **v) {
 
 static int dhcp_client_lease_append_json(Link *link, JsonVariant **v) {
         _cleanup_(json_variant_unrefp) JsonVariant *w = NULL;
-        usec_t lease_timestamp_usec, t1, t2;
+        usec_t lease_timestamp_usec = USEC_INFINITY, t1 = USEC_INFINITY, t2 = USEC_INFINITY;
         int r;
 
         assert(link);
@@ -1171,16 +1171,16 @@ static int dhcp_client_lease_append_json(Link *link, JsonVariant **v) {
                 return 0;
 
         r = sd_dhcp_lease_get_timestamp(link->dhcp_lease, CLOCK_BOOTTIME, &lease_timestamp_usec);
-        if (r < 0)
-                return 0;
+        if (r < 0 && r != -ENODATA)
+                return r;
 
         r = sd_dhcp_lease_get_t1_timestamp(link->dhcp_lease, CLOCK_BOOTTIME, &t1);
-        if (r < 0)
-                return 0;
+        if (r < 0 && r != -ENODATA)
+                return r;
 
         r = sd_dhcp_lease_get_t2_timestamp(link->dhcp_lease, CLOCK_BOOTTIME, &t2);
-        if (r < 0)
-                return 0;
+        if (r < 0 && r != -ENODATA)
+                return r;
 
         r = json_build(&w, JSON_BUILD_OBJECT(
                                 JSON_BUILD_PAIR_FINITE_USEC("LeaseTimestampUSec", lease_timestamp_usec),