]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
dhcp6: Compute the minimum lifetimes for T1 and T2
authorPatrik Flykt <patrik.flykt@linux.intel.com>
Thu, 4 Jan 2018 13:11:52 +0000 (15:11 +0200)
committerPatrik Flykt <patrik.flykt@linux.intel.com>
Thu, 4 Jan 2018 13:22:44 +0000 (15:22 +0200)
Compute one set of minimum lifetimes for T1 and T2, i.e. the smaller
ones assigned to IA NA and IA PD. The lifetimes should be the same,
see RFC 7550 for details.

src/libsystemd-network/sd-dhcp6-client.c

index 2c2d062ede5851cc8beec6843e08e5d0acc64af5..0584059fec8c183e4076d89cca2e9694929828c1 100644 (file)
@@ -772,6 +772,7 @@ static int client_parse_message(
         bool clientid = false;
         uint8_t *id = NULL;
         size_t id_len;
+        uint32_t lt_t1 = ~0, lt_t2 = ~0;
 
         assert(client);
         assert(message);
@@ -872,6 +873,11 @@ static int client_parse_message(
                                 return -EINVAL;
                         }
 
+                        if (lease->ia.addresses) {
+                                lt_t1 = MIN(lt_t1, be32toh(lease->ia.ia_na.lifetime_t1));
+                                lt_t2 = MIN(lt_t2, be32toh(lease->ia.ia_na.lifetime_t1));
+                        }
+
                         break;
 
                 case SD_DHCP6_OPTION_IA_PD:
@@ -895,6 +901,11 @@ static int client_parse_message(
                                 return -EINVAL;
                         }
 
+                        if (lease->pd.addresses) {
+                                lt_t1 = MIN(lt_t1, be32toh(lease->pd.ia_pd.lifetime_t1));
+                                lt_t2 = MIN(lt_t2, be32toh(lease->pd.ia_pd.lifetime_t2));
+                        }
+
                         break;
 
                 case SD_DHCP6_OPTION_RAPID_COMMIT:
@@ -947,6 +958,17 @@ static int client_parse_message(
                 if (r < 0)
                         log_dhcp6_client(client, "%s has no server id",
                                          dhcp6_message_type_to_string(message->type));
+                return r;
+        }
+
+        if (lease->ia.addresses) {
+                lease->ia.ia_na.lifetime_t1 = htobe32(lt_t1);
+                lease->ia.ia_na.lifetime_t2 = htobe32(lt_t2);
+        }
+
+        if (lease->pd.addresses) {
+                lease->pd.ia_pd.lifetime_t1 = htobe32(lt_t1);
+                lease->pd.ia_pd.lifetime_t2 = htobe32(lt_t2);
         }
 
         return r;