Commit 6f704992 authored by YOSHIFUJI Hideaki's avatar YOSHIFUJI Hideaki Committed by David S. Miller

ipv6 addrconf: Allow infinite prefix lifetime.

We need to handle infinite prefix lifetime specially.
With help from original reporter "Bonitch, Joseph"
<Joseph.Bonitch@xerox.com>.
Signed-off-by: default avatarYOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 69cdf8f9
...@@ -1764,14 +1764,16 @@ void addrconf_prefix_rcv(struct net_device *dev, u8 *opt, int len) ...@@ -1764,14 +1764,16 @@ void addrconf_prefix_rcv(struct net_device *dev, u8 *opt, int len)
* 2) Configure prefixes with the auto flag set * 2) Configure prefixes with the auto flag set
*/ */
/* Avoid arithmetic overflow. Really, we could if (valid_lft == INFINITY_LIFE_TIME)
save rt_expires in seconds, likely valid_lft, rt_expires = ~0UL;
but it would require division in fib gc, that it else if (valid_lft >= 0x7FFFFFFF/HZ) {
not good. /* Avoid arithmetic overflow. Really, we could
*/ * save rt_expires in seconds, likely valid_lft,
if (valid_lft >= 0x7FFFFFFF/HZ) * but it would require division in fib gc, that it
* not good.
*/
rt_expires = 0x7FFFFFFF - (0x7FFFFFFF % HZ); rt_expires = 0x7FFFFFFF - (0x7FFFFFFF % HZ);
else } else
rt_expires = valid_lft * HZ; rt_expires = valid_lft * HZ;
/* /*
...@@ -1779,7 +1781,7 @@ void addrconf_prefix_rcv(struct net_device *dev, u8 *opt, int len) ...@@ -1779,7 +1781,7 @@ void addrconf_prefix_rcv(struct net_device *dev, u8 *opt, int len)
* Avoid arithmetic overflow there as well. * Avoid arithmetic overflow there as well.
* Overflow can happen only if HZ < USER_HZ. * Overflow can happen only if HZ < USER_HZ.
*/ */
if (HZ < USER_HZ && rt_expires > 0x7FFFFFFF / USER_HZ) if (HZ < USER_HZ && ~rt_expires && rt_expires > 0x7FFFFFFF / USER_HZ)
rt_expires = 0x7FFFFFFF / USER_HZ; rt_expires = 0x7FFFFFFF / USER_HZ;
if (pinfo->onlink) { if (pinfo->onlink) {
...@@ -1788,17 +1790,28 @@ void addrconf_prefix_rcv(struct net_device *dev, u8 *opt, int len) ...@@ -1788,17 +1790,28 @@ void addrconf_prefix_rcv(struct net_device *dev, u8 *opt, int len)
dev->ifindex, 1); dev->ifindex, 1);
if (rt && ((rt->rt6i_flags & (RTF_GATEWAY | RTF_DEFAULT)) == 0)) { if (rt && ((rt->rt6i_flags & (RTF_GATEWAY | RTF_DEFAULT)) == 0)) {
if (rt->rt6i_flags&RTF_EXPIRES) { /* Autoconf prefix route */
if (valid_lft == 0) { if (valid_lft == 0) {
ip6_del_rt(rt); ip6_del_rt(rt);
rt = NULL; rt = NULL;
} else { } else if (~rt_expires) {
rt->rt6i_expires = jiffies + rt_expires; /* not infinity */
} rt->rt6i_expires = jiffies + rt_expires;
rt->rt6i_flags |= RTF_EXPIRES;
} else {
rt->rt6i_flags &= ~RTF_EXPIRES;
rt->rt6i_expires = 0;
} }
} else if (valid_lft) { } else if (valid_lft) {
int flags = RTF_ADDRCONF | RTF_PREFIX_RT;
clock_t expires = 0;
if (~rt_expires) {
/* not infinity */
flags |= RTF_EXPIRES;
expires = jiffies_to_clock_t(rt_expires);
}
addrconf_prefix_route(&pinfo->prefix, pinfo->prefix_len, addrconf_prefix_route(&pinfo->prefix, pinfo->prefix_len,
dev, jiffies_to_clock_t(rt_expires), RTF_ADDRCONF|RTF_EXPIRES|RTF_PREFIX_RT); dev, expires, flags);
} }
if (rt) if (rt)
dst_release(&rt->u.dst); dst_release(&rt->u.dst);
...@@ -2021,7 +2034,8 @@ static int inet6_addr_add(struct net *net, int ifindex, struct in6_addr *pfx, ...@@ -2021,7 +2034,8 @@ static int inet6_addr_add(struct net *net, int ifindex, struct in6_addr *pfx,
struct inet6_dev *idev; struct inet6_dev *idev;
struct net_device *dev; struct net_device *dev;
int scope; int scope;
u32 flags = RTF_EXPIRES; u32 flags;
clock_t expires;
ASSERT_RTNL(); ASSERT_RTNL();
...@@ -2041,8 +2055,13 @@ static int inet6_addr_add(struct net *net, int ifindex, struct in6_addr *pfx, ...@@ -2041,8 +2055,13 @@ static int inet6_addr_add(struct net *net, int ifindex, struct in6_addr *pfx,
if (valid_lft == INFINITY_LIFE_TIME) { if (valid_lft == INFINITY_LIFE_TIME) {
ifa_flags |= IFA_F_PERMANENT; ifa_flags |= IFA_F_PERMANENT;
flags = 0; flags = 0;
} else if (valid_lft >= 0x7FFFFFFF/HZ) expires = 0;
valid_lft = 0x7FFFFFFF/HZ; } else {
if (valid_lft >= 0x7FFFFFFF/HZ)
valid_lft = 0x7FFFFFFF/HZ;
flags = RTF_EXPIRES;
expires = jiffies_to_clock_t(valid_lft * HZ);
}
if (prefered_lft == 0) if (prefered_lft == 0)
ifa_flags |= IFA_F_DEPRECATED; ifa_flags |= IFA_F_DEPRECATED;
...@@ -2060,7 +2079,7 @@ static int inet6_addr_add(struct net *net, int ifindex, struct in6_addr *pfx, ...@@ -2060,7 +2079,7 @@ static int inet6_addr_add(struct net *net, int ifindex, struct in6_addr *pfx,
spin_unlock_bh(&ifp->lock); spin_unlock_bh(&ifp->lock);
addrconf_prefix_route(&ifp->addr, ifp->prefix_len, dev, addrconf_prefix_route(&ifp->addr, ifp->prefix_len, dev,
jiffies_to_clock_t(valid_lft * HZ), flags); expires, flags);
/* /*
* Note that section 3.1 of RFC 4429 indicates * Note that section 3.1 of RFC 4429 indicates
* that the Optimistic flag should not be set for * that the Optimistic flag should not be set for
...@@ -3148,7 +3167,8 @@ inet6_rtm_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) ...@@ -3148,7 +3167,8 @@ inet6_rtm_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
static int inet6_addr_modify(struct inet6_ifaddr *ifp, u8 ifa_flags, static int inet6_addr_modify(struct inet6_ifaddr *ifp, u8 ifa_flags,
u32 prefered_lft, u32 valid_lft) u32 prefered_lft, u32 valid_lft)
{ {
u32 flags = RTF_EXPIRES; u32 flags;
clock_t expires;
if (!valid_lft || (prefered_lft > valid_lft)) if (!valid_lft || (prefered_lft > valid_lft))
return -EINVAL; return -EINVAL;
...@@ -3156,8 +3176,13 @@ static int inet6_addr_modify(struct inet6_ifaddr *ifp, u8 ifa_flags, ...@@ -3156,8 +3176,13 @@ static int inet6_addr_modify(struct inet6_ifaddr *ifp, u8 ifa_flags,
if (valid_lft == INFINITY_LIFE_TIME) { if (valid_lft == INFINITY_LIFE_TIME) {
ifa_flags |= IFA_F_PERMANENT; ifa_flags |= IFA_F_PERMANENT;
flags = 0; flags = 0;
} else if (valid_lft >= 0x7FFFFFFF/HZ) expires = 0;
valid_lft = 0x7FFFFFFF/HZ; } else {
if (valid_lft >= 0x7FFFFFFF/HZ)
valid_lft = 0x7FFFFFFF/HZ;
flags = RTF_EXPIRES;
expires = jiffies_to_clock_t(valid_lft * HZ);
}
if (prefered_lft == 0) if (prefered_lft == 0)
ifa_flags |= IFA_F_DEPRECATED; ifa_flags |= IFA_F_DEPRECATED;
...@@ -3176,7 +3201,7 @@ static int inet6_addr_modify(struct inet6_ifaddr *ifp, u8 ifa_flags, ...@@ -3176,7 +3201,7 @@ static int inet6_addr_modify(struct inet6_ifaddr *ifp, u8 ifa_flags,
ipv6_ifa_notify(0, ifp); ipv6_ifa_notify(0, ifp);
addrconf_prefix_route(&ifp->addr, ifp->prefix_len, ifp->idev->dev, addrconf_prefix_route(&ifp->addr, ifp->prefix_len, ifp->idev->dev,
jiffies_to_clock_t(valid_lft * HZ), flags); expires, flags);
addrconf_verify(0); addrconf_verify(0);
return 0; return 0;
......
...@@ -1106,7 +1106,9 @@ int ip6_route_add(struct fib6_config *cfg) ...@@ -1106,7 +1106,9 @@ int ip6_route_add(struct fib6_config *cfg)
} }
rt->u.dst.obsolete = -1; rt->u.dst.obsolete = -1;
rt->rt6i_expires = jiffies + clock_t_to_jiffies(cfg->fc_expires); rt->rt6i_expires = (cfg->fc_flags & RTF_EXPIRES) ?
jiffies + clock_t_to_jiffies(cfg->fc_expires) :
0;
if (cfg->fc_protocol == RTPROT_UNSPEC) if (cfg->fc_protocol == RTPROT_UNSPEC)
cfg->fc_protocol = RTPROT_BOOT; cfg->fc_protocol = RTPROT_BOOT;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment