Discussion:
Adding IP(v6) address with scope link creates global address
Andreas Henriksson
2009-11-25 13:59:45 UTC
Permalink
Hello!

"Jedasothi" reported problems setting scope with iproute on newly added
ipv6 addresses in:
https://bugs.launchpad.net/ubuntu/+source/iproute/+bug/487745
To reproduce bug run
ip addr add '::4/64' scope link dev eth0
This results in a line seen with
ip addr show eth0
inet6 ::4/64 scope global tentative
The label "global" is seen instead of "link".
This works for me on ipv4 and seems to be only a problem with ipv6.

I think this is a kernel bug. The scope seems to be passed into the
kernel via netlink as specified on the command line.

Looking at the kernel, inet6_rtm_newaddr [1] calls inet6_addr_add [2]
without passing the ifa_scope struct member and then the scope is
generated from the address within the inet6_addr_add function.

It would be nice if someone could verify this and while at it
also whip up a patch and forward to the right person. ;)

[1]: http://lxr.linux.no/#linux+v2.6.31/net/ipv6/addrconf.c#L3263
[2]: http://lxr.linux.no/#linux+v2.6.31/net/ipv6/addrconf.c#L2081
--
Andreas Henriksson
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to ***@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Andreas Henriksson
2009-12-07 13:41:08 UTC
Permalink
Hello again!

Replying to myself (see http://www.spinics.net/lists/netdev/msg113943.html)
and attaching an untested patch to see if this sparks more interest.
Post by Andreas Henriksson
"Jedasothi" reported problems setting scope with iproute on newly added
https://bugs.launchpad.net/ubuntu/+source/iproute/+bug/487745
To reproduce bug run
ip addr add '::4/64' scope link dev eth0
This results in a line seen with
ip addr show eth0
inet6 ::4/64 scope global tentative
The label "global" is seen instead of "link".
I'd appreciate if someone could review and test this:


diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index 1fd0a3d..64d6d35 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -2083,13 +2083,12 @@ err_exit:
* Manual configuration of address on an interface
*/
static int inet6_addr_add(struct net *net, int ifindex, struct in6_addr *pfx,
- unsigned int plen, __u8 ifa_flags, __u32 prefered_lft,
- __u32 valid_lft)
+ unsigned int plen, __u8 ifa_flags, int scope,
+ __u32 prefered_lft, __u32 valid_lft)
{
struct inet6_ifaddr *ifp;
struct inet6_dev *idev;
struct net_device *dev;
- int scope;
u32 flags;
clock_t expires;
unsigned long timeout;
@@ -2110,7 +2109,8 @@ static int inet6_addr_add(struct net *net, int ifindex, struct in6_addr *pfx,
if ((idev = addrconf_add_dev(dev)) == NULL)
return -ENOBUFS;

- scope = ipv6_addr_scope(pfx);
+ if (scope == 0)
+ scope = ipv6_addr_scope(pfx);

timeout = addrconf_timeout_fixup(valid_lft, HZ);
if (addrconf_finite_timeout(timeout)) {
@@ -2207,7 +2207,7 @@ int addrconf_add_ifaddr(struct net *net, void __user *arg)

rtnl_lock();
err = inet6_addr_add(net, ireq.ifr6_ifindex, &ireq.ifr6_addr,
- ireq.ifr6_prefixlen, IFA_F_PERMANENT,
+ ireq.ifr6_prefixlen, IFA_F_PERMANENT, 0,
INFINITY_LIFE_TIME, INFINITY_LIFE_TIME);
rtnl_unlock();
return err;
@@ -3328,6 +3328,7 @@ inet6_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
*/
return inet6_addr_add(net, ifm->ifa_index, pfx,
ifm->ifa_prefixlen, ifa_flags,
+ ifm->ifa_scope,
preferred_lft, valid_lft);
}

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to ***@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Brian Haley
2009-12-07 17:18:06 UTC
Permalink
Hi Andreas,
Post by Andreas Henriksson
Hello again!
Replying to myself (see http://www.spinics.net/lists/netdev/msg113943.html)
and attaching an untested patch to see if this sparks more interest.
Post by Andreas Henriksson
"Jedasothi" reported problems setting scope with iproute on newly added
https://bugs.launchpad.net/ubuntu/+source/iproute/+bug/487745
To reproduce bug run
ip addr add '::4/64' scope link dev eth0
This results in a line seen with
ip addr show eth0
inet6 ::4/64 scope global tentative
The label "global" is seen instead of "link".
I tried the patch quickly since I was curious why this is a problem, but
it didn't work exactly right. I could post an update, but I'm not sure
this is the right thing to do - ::4 isn't a link-local address, and other
parts of the network stack (and other systems) aren't going to treat it as
such.

Maybe the submitter can explain exactly how this is breaking something?

Thanks,

-Brian
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to ***@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Andreas Henriksson
2009-12-07 19:30:05 UTC
Permalink
Adding submitter and launchpad bug to CC.
Post by Brian Haley
Hi Andreas,
=20
Post by Andreas Henriksson
Hello again!
=20
Replying to myself (see http://www.spinics.net/lists/netdev/msg1139=
43.html)
Post by Brian Haley
Post by Andreas Henriksson
and attaching an untested patch to see if this sparks more interest=
=2E
Post by Brian Haley
Post by Andreas Henriksson
=20
"Jedasothi" reported problems setting scope with iproute on newly =
added
Post by Brian Haley
Post by Andreas Henriksson
https://bugs.launchpad.net/ubuntu/+source/iproute/+bug/487745
To reproduce bug run
ip addr add '::4/64' scope link dev eth0
This results in a line seen with
ip addr show eth0
inet6 ::4/64 scope global tentative
The label "global" is seen instead of "link".
=20
=20
I tried the patch quickly since I was curious why this is a problem, =
but
Post by Brian Haley
it didn't work exactly right. I could post an update, but I'm not su=
re
Post by Brian Haley
this is the right thing to do - ::4 isn't a link-local address, and o=
ther
Post by Brian Haley
parts of the network stack (and other systems) aren't going to treat =
it as
Post by Brian Haley
such.
=20
Maybe the submitter can explain exactly how this is breaking somethin=
g?
Post by Brian Haley
=20
Thanks,
=20
-Brian
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to ***@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Loading...