@@ -502,6 +502,8 @@ impl<'a> Socket<'a> {
502
502
// Times T1 and T2 are configurable by the server through
503
503
// options. T1 defaults to (0.5 * duration_of_lease). T2
504
504
// defaults to (0.875 * duration_of_lease).
505
+ // When receiving T1 and T2, they must be in the order:
506
+ // T1 < T2 < lease_duration
505
507
let ( renew_duration, rebind_duration) = match (
506
508
dhcp_repr
507
509
. renew_duration
@@ -510,26 +512,36 @@ impl<'a> Socket<'a> {
510
512
. rebind_duration
511
513
. map ( |d| Duration :: from_secs ( d as u64 ) ) ,
512
514
) {
513
- ( Some ( renew_duration) , Some ( rebind_duration) ) => ( renew_duration, rebind_duration) ,
514
- ( None , None ) => ( lease_duration / 2 , lease_duration * 7 / 8 ) ,
515
+ ( Some ( renew_duration) , Some ( rebind_duration) )
516
+ if renew_duration < rebind_duration && rebind_duration < lease_duration =>
517
+ {
518
+ ( renew_duration, rebind_duration)
519
+ }
515
520
// RFC 2131 does not say what to do if only one value is
516
521
// provided, so:
517
522
518
523
// If only T1 is provided, set T2 to be 0.75 through the gap
519
524
// between T1 and the duration of the lease. If T1 is set to
520
525
// the default (0.5 * duration_of_lease), then T2 will also
521
526
// be set to the default (0.875 * duration_of_lease).
522
- ( Some ( renew_duration) , None ) => (
527
+ ( Some ( renew_duration) , None ) if renew_duration < lease_duration => (
523
528
renew_duration,
524
529
renew_duration + ( lease_duration - renew_duration) * 3 / 4 ,
525
530
) ,
526
531
527
532
// If only T2 is provided, then T1 will be set to be
528
533
// whichever is smaller of the default (0.5 *
529
534
// duration_of_lease) or T2.
530
- ( None , Some ( rebind_duration) ) => {
535
+ ( None , Some ( rebind_duration) ) if rebind_duration < lease_duration => {
531
536
( ( lease_duration / 2 ) . min ( rebind_duration) , rebind_duration)
532
537
}
538
+
539
+ // Use the defaults if the following order is not met:
540
+ // T1 < T2 < lease_duration
541
+ ( _, _) => {
542
+ net_debug ! ( "using default T1 and T2 values since the provided values are invalid" ) ;
543
+ ( lease_duration / 2 , lease_duration * 7 / 8 )
544
+ }
533
545
} ;
534
546
let renew_at = now + renew_duration;
535
547
let rebind_at = now + rebind_duration;
0 commit comments