From: Benoit Boissinot <benoit.boissinot@ens-lyon.org>
To: "YOSHIFUJI Hideaki / 吉藤英明" <yoshfuji@linux-ipv6.org>
Cc: netdev@vger.kernel.org, pekkas@netcore.fi
Subject: Re: [PATCH 4 of 5] IPv6: fix lifetime calculation on temporary address creation
Date: Wed, 2 Apr 2008 02:17:06 +0200 [thread overview]
Message-ID: <20080402001706.GD32592@pirzuine> (raw)
In-Reply-To: <20080402.084114.60517414.yoshfuji@linux-ipv6.org>
On Wed, Apr 02, 2008 at 08:41:14AM +0900, YOSHIFUJI Hideaki / 吉藤英明 wrote:
> In article <20080401215657.GP475@pirzuine> (at Tue, 1 Apr 2008 23:56:57 +0200), Benoit Boissinot <benoit.boissinot@ens-lyon.org> says:
>
> > On Fri, Mar 28, 2008 at 12:04:01PM +0900, YOSHIFUJI Hideaki / 吉藤英明 wrote:
> > > In article <ec551b4a5bb25cda00ff.1206305172@pirzuine> (at Sun, 23 Mar 2008 21:46:12 +0100), Benoit Boissinot <benoit.boissinot@ens-lyon.org> says:
> > >
> > > > IPv6: fix lifetime calculation on temporary address creation
> > [snip]
> > > > + now = jiffies;
> > > > + elapsed = (now - ifp->tstamp) / HZ;
> > > > + if (elapsed >= ifp->valid_lft)
> > > > + tmp_valid_lft = 0;
> > > > + else
> > > > + tmp_valid_lft = min_t(__u32,
> > > > + ifp->valid_lft - elapsed,
> > > > + idev->cnf.temp_valid_lft);
> > > > + if (elapsed >= ifp->prefered_lft)
> > > > + tmp_prefered_lft = 0;
> > > > + else
> > > > + tmp_prefered_lft = min_t(__u32,
> > > > + ifp->prefered_lft - elapsed,
> > > > + idev->cnf.temp_prefered_lft - desync_factor / HZ);
> > >
> > > Basically I agree, but it is possible to expire the temporary
> > > address AFTER public address, which is not good. Please fix this.
> >
> > do you mean because of the rounding of 'elapsed' ? otherwise I don't see
> > what the problem is, sorry.
>
> Right. Maybe we could substruct "now" by adj = (now - ifp->tstamp) % HZ;
> now = jiffies
> elapsed = (now - ifp->tstamp) / HZ;
> now -= (now - ifp->tstamp) % HZ;
Why not just simply round it above:
elapsed = (now - ifp->tstamp + HZ - 1) / HZ; /* round it up */
and the rest stays the same.
Or do we care about having a lifetime a little bit (<1s) shorter ?
updated patch below:
IPv6: fix lifetime calculation on temporary address creation
The lifetime calculation was buggy since it copied the tstamp
from the associated public address.
If (now - ifp->prefered_lft)/HZ (ie the elapsed time since the
timestamp was set in the public address) was greater than
temp_prefered_lft, you would always get deprecated addresses.
This patch corrects the lifetime calculation by setting the tstamp
to "now" and calculating the remaining time from the public address.
Signed-off-by: Benoit Boissinot <benoit.boissinot@ens-lyon.org>
diff -r 00affc24c178 net/ipv6/addrconf.c
--- a/net/ipv6/addrconf.c Sat Mar 22 00:39:16 2008 +0100
+++ b/net/ipv6/addrconf.c Wed Apr 02 02:14:13 2008 +0200
@@ -775,8 +775,7 @@
{
struct inet6_dev *idev = ifp->idev;
struct in6_addr addr, *tmpaddr;
- unsigned long tmp_prefered_lft, tmp_valid_lft, tmp_cstamp, tmp_tstamp;
- unsigned long regen_advance;
+ unsigned long tmp_prefered_lft, tmp_valid_lft, elapsed, regen_advance;
int tmp_plen;
int ret = 0;
int max_addresses;
@@ -825,16 +824,21 @@
goto out;
}
memcpy(&addr.s6_addr[8], idev->rndid, 8);
- tmp_valid_lft = min_t(__u32,
- ifp->valid_lft,
- idev->cnf.temp_valid_lft);
- tmp_prefered_lft = min_t(__u32,
- ifp->prefered_lft,
- idev->cnf.temp_prefered_lft - desync_factor / HZ);
+ elapsed = (jiffies - ifp->tstamp + HZ - 1) / HZ; /* round above */
+ if (elapsed >= ifp->valid_lft)
+ tmp_valid_lft = 0;
+ else
+ tmp_valid_lft = min_t(__u32,
+ ifp->valid_lft - elapsed,
+ idev->cnf.temp_valid_lft);
+ if (elapsed >= ifp->prefered_lft)
+ tmp_prefered_lft = 0;
+ else
+ tmp_prefered_lft = min_t(__u32,
+ ifp->prefered_lft - elapsed,
+ idev->cnf.temp_prefered_lft - desync_factor / HZ);
tmp_plen = ifp->prefix_len;
max_addresses = idev->cnf.max_addresses;
- tmp_cstamp = ifp->cstamp;
- tmp_tstamp = ifp->tstamp;
spin_unlock_bh(&ifp->lock);
regen_advance = idev->cnf.regen_max_retry *
@@ -878,8 +882,6 @@
ift->ifpub = ifp;
ift->valid_lft = tmp_valid_lft;
ift->prefered_lft = tmp_prefered_lft;
- ift->cstamp = tmp_cstamp;
- ift->tstamp = tmp_tstamp;
spin_unlock_bh(&ift->lock);
addrconf_dad_start(ift, 0);
--
:wq
next prev parent reply other threads:[~2008-04-02 0:17 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-03-23 20:46 [PATCH 0 of 5] IPv6: Fix temporary address support Benoit Boissinot
2008-03-23 20:46 ` [PATCH 1 of 5] IPv6: do not wrap around when the lifetime has expired Benoit Boissinot
2008-03-27 18:25 ` YOSHIFUJI Hideaki / 吉藤英明
2008-03-27 19:38 ` Benoit Boissinot
2008-03-28 3:06 ` YOSHIFUJI Hideaki / 吉藤英明
2008-04-01 22:43 ` Benoit Boissinot
2008-03-23 20:46 ` [PATCH 2 of 5] IPv6: only update the lifetime of the relevant temporary address Benoit Boissinot
2008-03-27 18:31 ` YOSHIFUJI Hideaki / 吉藤英明
2008-03-23 20:46 ` [PATCH 3 of 5] IPv6: do not create temporary adresses with too short preferred lifetime Benoit Boissinot
2008-03-27 18:39 ` YOSHIFUJI Hideaki / 吉藤英明
2008-03-23 20:46 ` [PATCH 4 of 5] IPv6: fix lifetime calculation on temporary address creation Benoit Boissinot
2008-03-28 3:04 ` YOSHIFUJI Hideaki / 吉藤英明
2008-04-01 21:56 ` Benoit Boissinot
2008-04-01 23:41 ` YOSHIFUJI Hideaki / 吉藤英明
2008-04-02 0:17 ` Benoit Boissinot [this message]
2008-04-02 0:25 ` YOSHIFUJI Hideaki / 吉藤英明
2008-04-02 5:56 ` Pekka Savola
2008-03-23 20:46 ` [PATCH 5 of 5] IPv6: temporary address: update the timer for tentative addresses Benoit Boissinot
2008-03-28 3:25 ` YOSHIFUJI Hideaki / 吉藤英明
2008-04-01 21:53 ` Benoit Boissinot
2008-03-27 17:59 ` [PATCH 0 of 5] IPv6: Fix temporary address support Benoit Boissinot
2008-03-27 18:12 ` YOSHIFUJI Hideaki / 吉藤英明
2008-03-28 0:32 ` Benoit Boissinot
2008-03-28 3:15 ` YOSHIFUJI Hideaki / 吉藤英明
2008-04-01 21:55 ` Benoit Boissinot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080402001706.GD32592@pirzuine \
--to=benoit.boissinot@ens-lyon.org \
--cc=netdev@vger.kernel.org \
--cc=pekkas@netcore.fi \
--cc=yoshfuji@linux-ipv6.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.