Skip to content

Commit b47fb94

Browse files
committed
dhcp6: Compute the minimum lifetimes for T1 and T2
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.
1 parent 103b81e commit b47fb94

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,7 @@ static int client_parse_message(
772772
bool clientid = false;
773773
uint8_t *id = NULL;
774774
size_t id_len;
775+
uint32_t lt_t1 = ~0, lt_t2 = ~0;
775776

776777
assert(client);
777778
assert(message);
@@ -872,6 +873,11 @@ static int client_parse_message(
872873
return -EINVAL;
873874
}
874875

876+
if (lease->ia.addresses) {
877+
lt_t1 = MIN(lt_t1, be32toh(lease->ia.ia_na.lifetime_t1));
878+
lt_t2 = MIN(lt_t2, be32toh(lease->ia.ia_na.lifetime_t1));
879+
}
880+
875881
break;
876882

877883
case SD_DHCP6_OPTION_IA_PD:
@@ -895,6 +901,11 @@ static int client_parse_message(
895901
return -EINVAL;
896902
}
897903

904+
if (lease->pd.addresses) {
905+
lt_t1 = MIN(lt_t1, be32toh(lease->pd.ia_pd.lifetime_t1));
906+
lt_t2 = MIN(lt_t2, be32toh(lease->pd.ia_pd.lifetime_t2));
907+
}
908+
898909
break;
899910

900911
case SD_DHCP6_OPTION_RAPID_COMMIT:
@@ -947,6 +958,17 @@ static int client_parse_message(
947958
if (r < 0)
948959
log_dhcp6_client(client, "%s has no server id",
949960
dhcp6_message_type_to_string(message->type));
961+
return r;
962+
}
963+
964+
if (lease->ia.addresses) {
965+
lease->ia.ia_na.lifetime_t1 = htobe32(lt_t1);
966+
lease->ia.ia_na.lifetime_t2 = htobe32(lt_t2);
967+
}
968+
969+
if (lease->pd.addresses) {
970+
lease->pd.ia_pd.lifetime_t1 = htobe32(lt_t1);
971+
lease->pd.ia_pd.lifetime_t2 = htobe32(lt_t2);
950972
}
951973

952974
return r;

0 commit comments

Comments
 (0)