Subject: PATCH: ipv6: avoid wraparound for expired lifetimes

From: Jens Rosenboom <[email-masked]>
Date: Thu, 25 Jun 2009 09:39:43 +0200

If the valid or preferred lifetime for an address expires, the kernel
shows huge values for these due to a counter wrap, the following patch
should fix this, at least it did in the test I ran.

--- linux-2.6.30.orig/net/ipv6/addrconf.c	2009-06-10 05:05:27.000000000 +0200
+++ linux-2.6.30/net/ipv6/addrconf.c	2009-06-25 09:33:38.000000000 +0200
@@ -3361,9 +3361,17 @@
 		valid = ifa->valid_lft;
 		if (preferred != INFINITY_LIFE_TIME) {
 			long tval = (jiffies - ifa->tstamp)/HZ;
-			preferred -= tval;
-			if (valid != INFINITY_LIFE_TIME)
-				valid -= tval;
+			if (preferred > tval) {
+				preferred -= tval;
+			} else {
+				preferred = 0;
+			}
+			if (valid != INFINITY_LIFE_TIME) {
+				if (valid > tval) {
+					valid -= tval;
+				} else {
+					valid = 0;
+				}
 		}
 	} else {
 		preferred = INFINITY_LIFE_TIME;