* [patch net-next] ipv6: addrconf: implement address generation modes
@ 2014-07-11 8:19 Jiri Pirko
2014-07-11 8:30 ` [patch iproute2] iproute2: allow to ipv6 set address generation mode Jiri Pirko
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Jiri Pirko @ 2014-07-11 8:19 UTC (permalink / raw)
To: netdev
Cc: davem, kuznet, jmorris, yoshfuji, kaber, sfeldma, arvid.brodin,
sucheta.chakraborty, hannes
This patch introduces a possibility for userspace to set various (so far
two) modes of generating addresses. This is useful for example for
NetworkManager because it can set the mode to NONE and take care of link
local addresses itself. That allow it to have the interface up,
monitoring carrier but still don't have any addresses on it.
Signed-off-by: Jiri Pirko <jiri@resnulli.us>
---
include/net/if_inet6.h | 1 +
include/uapi/linux/if_link.h | 6 +++++
net/ipv6/addrconf.c | 56 ++++++++++++++++++++++++++++++--------------
3 files changed, 45 insertions(+), 18 deletions(-)
diff --git a/include/net/if_inet6.h b/include/net/if_inet6.h
index b4956a5..f82b281 100644
--- a/include/net/if_inet6.h
+++ b/include/net/if_inet6.h
@@ -206,6 +206,7 @@ struct inet6_dev {
__u8 rs_probes;
unsigned long tstamp; /* ipv6InterfaceTable update timestamp */
+ enum in6_addr_gen_mode addr_gen_mode;
struct rcu_head rcu;
};
diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h
index b385348..ff95760 100644
--- a/include/uapi/linux/if_link.h
+++ b/include/uapi/linux/if_link.h
@@ -204,11 +204,17 @@ enum {
IFLA_INET6_CACHEINFO, /* time values and max reasm size */
IFLA_INET6_ICMP6STATS, /* statistics (icmpv6) */
IFLA_INET6_TOKEN, /* device token */
+ IFLA_INET6_ADDR_GEN_MODE, /* implicit address generator mode */
__IFLA_INET6_MAX
};
#define IFLA_INET6_MAX (__IFLA_INET6_MAX - 1)
+enum in6_addr_gen_mode {
+ IN6_ADDR_GEN_MODE_EUI64,
+ IN6_ADDR_GEN_MODE_NONE,
+};
+
enum {
BRIDGE_MODE_UNSPEC,
BRIDGE_MODE_HAIRPIN,
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index 358edd2..2c75ec1 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -2730,9 +2730,25 @@ static void addrconf_add_linklocal(struct inet6_dev *idev, const struct in6_addr
}
}
+static void addr_conf_addr_gen(struct inet6_dev *idev, bool prefix_route)
+{
+ if (idev->addr_gen_mode == IN6_ADDR_GEN_MODE_EUI64) {
+ struct in6_addr addr;
+
+ ipv6_addr_set(&addr, htonl(0xFE800000), 0, 0, 0);
+ /* addrconf_add_linklocal also adds a prefix_route and we
+ * only need to care about prefix routes if ipv6_generate_eui64
+ * couldn't generate one.
+ */
+ if (ipv6_generate_eui64(addr.s6_addr + 8, idev->dev) == 0)
+ addrconf_add_linklocal(idev, &addr);
+ else if (prefix_route)
+ addrconf_prefix_route(&addr, 64, idev->dev, 0, 0);
+ }
+}
+
static void addrconf_dev_config(struct net_device *dev)
{
- struct in6_addr addr;
struct inet6_dev *idev;
ASSERT_RTNL();
@@ -2753,11 +2769,7 @@ static void addrconf_dev_config(struct net_device *dev)
if (IS_ERR(idev))
return;
- memset(&addr, 0, sizeof(struct in6_addr));
- addr.s6_addr32[0] = htonl(0xFE800000);
-
- if (ipv6_generate_eui64(addr.s6_addr + 8, dev) == 0)
- addrconf_add_linklocal(idev, &addr);
+ addr_conf_addr_gen(idev, false);
}
#if IS_ENABLED(CONFIG_IPV6_SIT)
@@ -2779,11 +2791,7 @@ static void addrconf_sit_config(struct net_device *dev)
}
if (dev->priv_flags & IFF_ISATAP) {
- struct in6_addr addr;
-
- ipv6_addr_set(&addr, htonl(0xFE800000), 0, 0, 0);
- if (!ipv6_generate_eui64(addr.s6_addr + 8, dev))
- addrconf_add_linklocal(idev, &addr);
+ addr_conf_addr_gen(idev, false);
return;
}
@@ -2798,7 +2806,6 @@ static void addrconf_sit_config(struct net_device *dev)
static void addrconf_gre_config(struct net_device *dev)
{
struct inet6_dev *idev;
- struct in6_addr addr;
ASSERT_RTNL();
@@ -2807,11 +2814,7 @@ static void addrconf_gre_config(struct net_device *dev)
return;
}
- ipv6_addr_set(&addr, htonl(0xFE800000), 0, 0, 0);
- if (!ipv6_generate_eui64(addr.s6_addr + 8, dev))
- addrconf_add_linklocal(idev, &addr);
- else
- addrconf_prefix_route(&addr, 64, dev, 0, 0);
+ addr_conf_addr_gen(idev, true);
}
#endif
@@ -4423,6 +4426,10 @@ static int inet6_fill_ifla6_attrs(struct sk_buff *skb, struct inet6_dev *idev)
nla = nla_reserve(skb, IFLA_INET6_TOKEN, sizeof(struct in6_addr));
if (nla == NULL)
goto nla_put_failure;
+
+ if (nla_put_u8(skb, IFLA_INET6_ADDR_GEN_MODE, idev->addr_gen_mode))
+ goto nla_put_failure;
+
read_lock_bh(&idev->lock);
memcpy(nla_data(nla), idev->token.s6_addr, nla_len(nla));
read_unlock_bh(&idev->lock);
@@ -4527,8 +4534,21 @@ static int inet6_set_link_af(struct net_device *dev, const struct nlattr *nla)
if (nla_parse_nested(tb, IFLA_INET6_MAX, nla, NULL) < 0)
BUG();
- if (tb[IFLA_INET6_TOKEN])
+ if (tb[IFLA_INET6_TOKEN]) {
err = inet6_set_iftoken(idev, nla_data(tb[IFLA_INET6_TOKEN]));
+ if (err)
+ return err;
+ }
+
+ if (tb[IFLA_INET6_ADDR_GEN_MODE]) {
+ u8 mode = nla_get_u8(tb[IFLA_INET6_ADDR_GEN_MODE]);
+
+ if (mode != IN6_ADDR_GEN_MODE_EUI64 &&
+ mode != IN6_ADDR_GEN_MODE_NONE)
+ return -EINVAL;
+ idev->addr_gen_mode = mode;
+ err = 0;
+ }
return err;
}
--
1.9.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [patch iproute2] iproute2: allow to ipv6 set address generation mode
2014-07-11 8:19 [patch net-next] ipv6: addrconf: implement address generation modes Jiri Pirko
@ 2014-07-11 8:30 ` Jiri Pirko
2014-07-11 9:16 ` [patch net-next] ipv6: addrconf: implement address generation modes YOSHIFUJI Hideaki
2014-07-11 15:40 ` Dan Williams
2 siblings, 0 replies; 5+ messages in thread
From: Jiri Pirko @ 2014-07-11 8:30 UTC (permalink / raw)
To: netdev
Cc: davem, kuznet, jmorris, yoshfuji, kaber, sfeldma, arvid.brodin,
sucheta.chakraborty, hannes, stephen
Signed-off-by: Jiri Pirko <jiri@resnulli.us>
---
include/linux/if_link.h | 6 ++++++
ip/iplink.c | 22 ++++++++++++++++++++++
2 files changed, 28 insertions(+)
diff --git a/include/linux/if_link.h b/include/linux/if_link.h
index fadef0f..39cb62c 100644
--- a/include/linux/if_link.h
+++ b/include/linux/if_link.h
@@ -202,11 +202,17 @@ enum {
IFLA_INET6_CACHEINFO, /* time values and max reasm size */
IFLA_INET6_ICMP6STATS, /* statistics (icmpv6) */
IFLA_INET6_TOKEN, /* device token */
+ IFLA_INET6_ADDR_GEN_MODE, /* implicit address generator mode */
__IFLA_INET6_MAX
};
#define IFLA_INET6_MAX (__IFLA_INET6_MAX - 1)
+enum in6_addr_gen_mode {
+ IN6_ADDR_GEN_MODE_EUI64,
+ IN6_ADDR_GEN_MODE_NONE,
+};
+
enum {
BRIDGE_MODE_UNSPEC,
BRIDGE_MODE_HAIRPIN,
diff --git a/ip/iplink.c b/ip/iplink.c
index 0d020ef..ecb05d6 100644
--- a/ip/iplink.c
+++ b/ip/iplink.c
@@ -81,6 +81,7 @@ void iplink_usage(void)
fprintf(stderr, " [ state { auto | enable | disable} ] ]\n");
fprintf(stderr, " [ master DEVICE ]\n");
fprintf(stderr, " [ nomaster ]\n");
+ fprintf(stderr, " [ addrgenmode { eui64 | none } ]\n");
fprintf(stderr, " ip link show [ DEVICE | group GROUP ] [up]\n");
if (iplink_have_newlink()) {
@@ -161,6 +162,15 @@ static int get_link_mode(const char *mode)
return -1;
}
+static int get_addr_gen_mode(const char *mode)
+{
+ if (strcasecmp(mode, "eui64") == 0)
+ return IN6_ADDR_GEN_MODE_EUI64;
+ if (strcasecmp(mode, "none") == 0)
+ return IN6_ADDR_GEN_MODE_NONE;
+ return -1;
+}
+
#if IPLINK_IOCTL_COMPAT
static int have_rtnl_newlink = -1;
@@ -557,6 +567,18 @@ int iplink_parse(int argc, char **argv, struct iplink_req *req,
invarg("Invalid \"numrxqueues\" value\n", *argv);
addattr_l(&req->n, sizeof(*req), IFLA_NUM_RX_QUEUES,
&numrxqueues, 4);
+ } else if (matches(*argv, "addrgenmode") == 0) {
+ struct rtattr *afs, *afs6;
+ int mode;
+ NEXT_ARG();
+ mode = get_addr_gen_mode(*argv);
+ if (mode < 0)
+ invarg("Invalid address generation mode\n", *argv);
+ afs = addattr_nest(&req->n, sizeof(*req), IFLA_AF_SPEC);
+ afs6 = addattr_nest(&req->n, sizeof(*req), AF_INET6);
+ addattr8(&req->n, sizeof(*req), IFLA_INET6_ADDR_GEN_MODE, mode);
+ addattr_nest_end(&req->n, afs6);
+ addattr_nest_end(&req->n, afs);
} else {
if (strcmp(*argv, "dev") == 0) {
NEXT_ARG();
--
1.9.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [patch net-next] ipv6: addrconf: implement address generation modes
2014-07-11 8:19 [patch net-next] ipv6: addrconf: implement address generation modes Jiri Pirko
2014-07-11 8:30 ` [patch iproute2] iproute2: allow to ipv6 set address generation mode Jiri Pirko
@ 2014-07-11 9:16 ` YOSHIFUJI Hideaki
2014-07-11 15:40 ` Dan Williams
2 siblings, 0 replies; 5+ messages in thread
From: YOSHIFUJI Hideaki @ 2014-07-11 9:16 UTC (permalink / raw)
To: Jiri Pirko, netdev
Cc: hideaki.yoshifuji, davem, kuznet, jmorris, yoshfuji, kaber,
sfeldma, arvid.brodin, sucheta.chakraborty, hannes
Hi,
Jiri Pirko wrote:
> This patch introduces a possibility for userspace to set various (so far
> two) modes of generating addresses. This is useful for example for
> NetworkManager because it can set the mode to NONE and take care of link
> local addresses itself. That allow it to have the interface up,
> monitoring carrier but still don't have any addresses on it.
>
> Signed-off-by: Jiri Pirko <jiri@resnulli.us>
> ---
> include/net/if_inet6.h | 1 +
> include/uapi/linux/if_link.h | 6 +++++
> net/ipv6/addrconf.c | 56 ++++++++++++++++++++++++++++++--------------
> 3 files changed, 45 insertions(+), 18 deletions(-)
>
> diff --git a/include/net/if_inet6.h b/include/net/if_inet6.h
> index b4956a5..f82b281 100644
> --- a/include/net/if_inet6.h
> +++ b/include/net/if_inet6.h
> @@ -206,6 +206,7 @@ struct inet6_dev {
> __u8 rs_probes;
>
> unsigned long tstamp; /* ipv6InterfaceTable update timestamp */
> + enum in6_addr_gen_mode addr_gen_mode;
How about putting this as __u8 after dad_probes?
> diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
> index 358edd2..2c75ec1 100644
> --- a/net/ipv6/addrconf.c
> +++ b/net/ipv6/addrconf.c
> @@ -2730,9 +2730,25 @@ static void addrconf_add_linklocal(struct inet6_dev *idev, const struct in6_addr
> }
> }
>
> +static void addr_conf_addr_gen(struct inet6_dev *idev, bool prefix_route)
s/addr_conf/addrconf/
--
Hideaki Yoshifuji <hideaki.yoshifuji@miraclelinux.com>
Technical Division, MIRACLE LINUX CORPORATION
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [patch net-next] ipv6: addrconf: implement address generation modes
2014-07-11 8:19 [patch net-next] ipv6: addrconf: implement address generation modes Jiri Pirko
2014-07-11 8:30 ` [patch iproute2] iproute2: allow to ipv6 set address generation mode Jiri Pirko
2014-07-11 9:16 ` [patch net-next] ipv6: addrconf: implement address generation modes YOSHIFUJI Hideaki
@ 2014-07-11 15:40 ` Dan Williams
2 siblings, 0 replies; 5+ messages in thread
From: Dan Williams @ 2014-07-11 15:40 UTC (permalink / raw)
To: Jiri Pirko
Cc: netdev, davem, kuznet, jmorris, yoshfuji, kaber, sfeldma,
arvid.brodin, sucheta.chakraborty, hannes
On Fri, 2014-07-11 at 10:19 +0200, Jiri Pirko wrote:
> This patch introduces a possibility for userspace to set various (so far
> two) modes of generating addresses. This is useful for example for
> NetworkManager because it can set the mode to NONE and take care of link
> local addresses itself. That allow it to have the interface up,
> monitoring carrier but still don't have any addresses on it.
One more use-case:
WWAN devices often have their LL address provided by the firmware of the
device, which sometimes refuses to respond to incorrect LL addresses
when doing DHCPv6 or IPv6 ND. The kernel cannot generate the correct LL
address for two reasons:
1) WWAN pseudo-ethernet interfaces often construct a fake MAC address,
or read a meaningless MAC address from the firmware. Thus the EUI64 and
the IPv6LL address the kernel assigns will be wrong. The real LL
address is often retrieved from the firmware with AT or proprietary
commands.
2) WWAN PPP interfaces receive their LL address from IPV6CP, not from
kernel assignments. Only after IPV6CP has completed do we know the LL
address of the PPP interface and its peer. But the kernel has already
assigned an incorrect LL address to the interface.
So being able to suppress the kernel LL address generation and assign
the one retrieved from the firmware is less complicated and more robust.
Dan
> Signed-off-by: Jiri Pirko <jiri@resnulli.us>
> ---
> include/net/if_inet6.h | 1 +
> include/uapi/linux/if_link.h | 6 +++++
> net/ipv6/addrconf.c | 56 ++++++++++++++++++++++++++++++--------------
> 3 files changed, 45 insertions(+), 18 deletions(-)
>
> diff --git a/include/net/if_inet6.h b/include/net/if_inet6.h
> index b4956a5..f82b281 100644
> --- a/include/net/if_inet6.h
> +++ b/include/net/if_inet6.h
> @@ -206,6 +206,7 @@ struct inet6_dev {
> __u8 rs_probes;
>
> unsigned long tstamp; /* ipv6InterfaceTable update timestamp */
> + enum in6_addr_gen_mode addr_gen_mode;
> struct rcu_head rcu;
> };
>
> diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h
> index b385348..ff95760 100644
> --- a/include/uapi/linux/if_link.h
> +++ b/include/uapi/linux/if_link.h
> @@ -204,11 +204,17 @@ enum {
> IFLA_INET6_CACHEINFO, /* time values and max reasm size */
> IFLA_INET6_ICMP6STATS, /* statistics (icmpv6) */
> IFLA_INET6_TOKEN, /* device token */
> + IFLA_INET6_ADDR_GEN_MODE, /* implicit address generator mode */
> __IFLA_INET6_MAX
> };
>
> #define IFLA_INET6_MAX (__IFLA_INET6_MAX - 1)
>
> +enum in6_addr_gen_mode {
> + IN6_ADDR_GEN_MODE_EUI64,
> + IN6_ADDR_GEN_MODE_NONE,
> +};
> +
> enum {
> BRIDGE_MODE_UNSPEC,
> BRIDGE_MODE_HAIRPIN,
> diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
> index 358edd2..2c75ec1 100644
> --- a/net/ipv6/addrconf.c
> +++ b/net/ipv6/addrconf.c
> @@ -2730,9 +2730,25 @@ static void addrconf_add_linklocal(struct inet6_dev *idev, const struct in6_addr
> }
> }
>
> +static void addr_conf_addr_gen(struct inet6_dev *idev, bool prefix_route)
> +{
> + if (idev->addr_gen_mode == IN6_ADDR_GEN_MODE_EUI64) {
> + struct in6_addr addr;
> +
> + ipv6_addr_set(&addr, htonl(0xFE800000), 0, 0, 0);
> + /* addrconf_add_linklocal also adds a prefix_route and we
> + * only need to care about prefix routes if ipv6_generate_eui64
> + * couldn't generate one.
> + */
> + if (ipv6_generate_eui64(addr.s6_addr + 8, idev->dev) == 0)
> + addrconf_add_linklocal(idev, &addr);
> + else if (prefix_route)
> + addrconf_prefix_route(&addr, 64, idev->dev, 0, 0);
> + }
> +}
> +
> static void addrconf_dev_config(struct net_device *dev)
> {
> - struct in6_addr addr;
> struct inet6_dev *idev;
>
> ASSERT_RTNL();
> @@ -2753,11 +2769,7 @@ static void addrconf_dev_config(struct net_device *dev)
> if (IS_ERR(idev))
> return;
>
> - memset(&addr, 0, sizeof(struct in6_addr));
> - addr.s6_addr32[0] = htonl(0xFE800000);
> -
> - if (ipv6_generate_eui64(addr.s6_addr + 8, dev) == 0)
> - addrconf_add_linklocal(idev, &addr);
> + addr_conf_addr_gen(idev, false);
> }
>
> #if IS_ENABLED(CONFIG_IPV6_SIT)
> @@ -2779,11 +2791,7 @@ static void addrconf_sit_config(struct net_device *dev)
> }
>
> if (dev->priv_flags & IFF_ISATAP) {
> - struct in6_addr addr;
> -
> - ipv6_addr_set(&addr, htonl(0xFE800000), 0, 0, 0);
> - if (!ipv6_generate_eui64(addr.s6_addr + 8, dev))
> - addrconf_add_linklocal(idev, &addr);
> + addr_conf_addr_gen(idev, false);
> return;
> }
>
> @@ -2798,7 +2806,6 @@ static void addrconf_sit_config(struct net_device *dev)
> static void addrconf_gre_config(struct net_device *dev)
> {
> struct inet6_dev *idev;
> - struct in6_addr addr;
>
> ASSERT_RTNL();
>
> @@ -2807,11 +2814,7 @@ static void addrconf_gre_config(struct net_device *dev)
> return;
> }
>
> - ipv6_addr_set(&addr, htonl(0xFE800000), 0, 0, 0);
> - if (!ipv6_generate_eui64(addr.s6_addr + 8, dev))
> - addrconf_add_linklocal(idev, &addr);
> - else
> - addrconf_prefix_route(&addr, 64, dev, 0, 0);
> + addr_conf_addr_gen(idev, true);
> }
> #endif
>
> @@ -4423,6 +4426,10 @@ static int inet6_fill_ifla6_attrs(struct sk_buff *skb, struct inet6_dev *idev)
> nla = nla_reserve(skb, IFLA_INET6_TOKEN, sizeof(struct in6_addr));
> if (nla == NULL)
> goto nla_put_failure;
> +
> + if (nla_put_u8(skb, IFLA_INET6_ADDR_GEN_MODE, idev->addr_gen_mode))
> + goto nla_put_failure;
> +
> read_lock_bh(&idev->lock);
> memcpy(nla_data(nla), idev->token.s6_addr, nla_len(nla));
> read_unlock_bh(&idev->lock);
> @@ -4527,8 +4534,21 @@ static int inet6_set_link_af(struct net_device *dev, const struct nlattr *nla)
> if (nla_parse_nested(tb, IFLA_INET6_MAX, nla, NULL) < 0)
> BUG();
>
> - if (tb[IFLA_INET6_TOKEN])
> + if (tb[IFLA_INET6_TOKEN]) {
> err = inet6_set_iftoken(idev, nla_data(tb[IFLA_INET6_TOKEN]));
> + if (err)
> + return err;
> + }
> +
> + if (tb[IFLA_INET6_ADDR_GEN_MODE]) {
> + u8 mode = nla_get_u8(tb[IFLA_INET6_ADDR_GEN_MODE]);
> +
> + if (mode != IN6_ADDR_GEN_MODE_EUI64 &&
> + mode != IN6_ADDR_GEN_MODE_NONE)
> + return -EINVAL;
> + idev->addr_gen_mode = mode;
> + err = 0;
> + }
>
> return err;
> }
^ permalink raw reply [flat|nested] 5+ messages in thread
* [patch net-next v2] ipv6: addrconf: implement address generation modes
@ 2014-07-11 19:10 Jiri Pirko
2014-07-11 19:11 ` [patch iproute2] iproute2: allow to ipv6 set address generation mode Jiri Pirko
0 siblings, 1 reply; 5+ messages in thread
From: Jiri Pirko @ 2014-07-11 19:10 UTC (permalink / raw)
To: netdev
Cc: davem, kuznet, jmorris, yoshfuji, kaber, sfeldma, arvid.brodin,
sucheta.chakraborty, hannes, stephen, dcbw
This patch introduces a possibility for userspace to set various (so far
two) modes of generating addresses. This is useful for example for
NetworkManager because it can set the mode to NONE and take care of link
local addresses itself. That allow it to have the interface up,
monitoring carrier but still don't have any addresses on it.
One more use-case by Dan Williams:
<quote>
WWAN devices often have their LL address provided by the firmware of the
device, which sometimes refuses to respond to incorrect LL addresses
when doing DHCPv6 or IPv6 ND. The kernel cannot generate the correct LL
address for two reasons:
1) WWAN pseudo-ethernet interfaces often construct a fake MAC address,
or read a meaningless MAC address from the firmware. Thus the EUI64 and
the IPv6LL address the kernel assigns will be wrong. The real LL
address is often retrieved from the firmware with AT or proprietary
commands.
2) WWAN PPP interfaces receive their LL address from IPV6CP, not from
kernel assignments. Only after IPV6CP has completed do we know the LL
address of the PPP interface and its peer. But the kernel has already
assigned an incorrect LL address to the interface.
So being able to suppress the kernel LL address generation and assign
the one retrieved from the firmware is less complicated and more robust.
</quote>
Signed-off-by: Jiri Pirko <jiri@resnulli.us>
---
v1->v2:
- changed addr_gen_mode to u8 and moved after rs_probes as suggested by YOSHIFUJI
- s/addr_conf/addrconf/ as suggested by YOSHIFUJI
- added use-case by Dan Williams to patch description
include/net/if_inet6.h | 1 +
include/uapi/linux/if_link.h | 6 +++++
net/ipv6/addrconf.c | 56 ++++++++++++++++++++++++++++++--------------
3 files changed, 45 insertions(+), 18 deletions(-)
diff --git a/include/net/if_inet6.h b/include/net/if_inet6.h
index b4956a5..d07b1a6 100644
--- a/include/net/if_inet6.h
+++ b/include/net/if_inet6.h
@@ -205,6 +205,7 @@ struct inet6_dev {
struct timer_list rs_timer;
__u8 rs_probes;
+ __u8 addr_gen_mode;
unsigned long tstamp; /* ipv6InterfaceTable update timestamp */
struct rcu_head rcu;
};
diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h
index 8f81085..e7e122b 100644
--- a/include/uapi/linux/if_link.h
+++ b/include/uapi/linux/if_link.h
@@ -205,11 +205,17 @@ enum {
IFLA_INET6_CACHEINFO, /* time values and max reasm size */
IFLA_INET6_ICMP6STATS, /* statistics (icmpv6) */
IFLA_INET6_TOKEN, /* device token */
+ IFLA_INET6_ADDR_GEN_MODE, /* implicit address generator mode */
__IFLA_INET6_MAX
};
#define IFLA_INET6_MAX (__IFLA_INET6_MAX - 1)
+enum in6_addr_gen_mode {
+ IN6_ADDR_GEN_MODE_EUI64,
+ IN6_ADDR_GEN_MODE_NONE,
+};
+
enum {
BRIDGE_MODE_UNSPEC,
BRIDGE_MODE_HAIRPIN,
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index 358edd2..4c03c28 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -2730,9 +2730,25 @@ static void addrconf_add_linklocal(struct inet6_dev *idev, const struct in6_addr
}
}
+static void addrconf_addr_gen(struct inet6_dev *idev, bool prefix_route)
+{
+ if (idev->addr_gen_mode == IN6_ADDR_GEN_MODE_EUI64) {
+ struct in6_addr addr;
+
+ ipv6_addr_set(&addr, htonl(0xFE800000), 0, 0, 0);
+ /* addrconf_add_linklocal also adds a prefix_route and we
+ * only need to care about prefix routes if ipv6_generate_eui64
+ * couldn't generate one.
+ */
+ if (ipv6_generate_eui64(addr.s6_addr + 8, idev->dev) == 0)
+ addrconf_add_linklocal(idev, &addr);
+ else if (prefix_route)
+ addrconf_prefix_route(&addr, 64, idev->dev, 0, 0);
+ }
+}
+
static void addrconf_dev_config(struct net_device *dev)
{
- struct in6_addr addr;
struct inet6_dev *idev;
ASSERT_RTNL();
@@ -2753,11 +2769,7 @@ static void addrconf_dev_config(struct net_device *dev)
if (IS_ERR(idev))
return;
- memset(&addr, 0, sizeof(struct in6_addr));
- addr.s6_addr32[0] = htonl(0xFE800000);
-
- if (ipv6_generate_eui64(addr.s6_addr + 8, dev) == 0)
- addrconf_add_linklocal(idev, &addr);
+ addrconf_addr_gen(idev, false);
}
#if IS_ENABLED(CONFIG_IPV6_SIT)
@@ -2779,11 +2791,7 @@ static void addrconf_sit_config(struct net_device *dev)
}
if (dev->priv_flags & IFF_ISATAP) {
- struct in6_addr addr;
-
- ipv6_addr_set(&addr, htonl(0xFE800000), 0, 0, 0);
- if (!ipv6_generate_eui64(addr.s6_addr + 8, dev))
- addrconf_add_linklocal(idev, &addr);
+ addrconf_addr_gen(idev, false);
return;
}
@@ -2798,7 +2806,6 @@ static void addrconf_sit_config(struct net_device *dev)
static void addrconf_gre_config(struct net_device *dev)
{
struct inet6_dev *idev;
- struct in6_addr addr;
ASSERT_RTNL();
@@ -2807,11 +2814,7 @@ static void addrconf_gre_config(struct net_device *dev)
return;
}
- ipv6_addr_set(&addr, htonl(0xFE800000), 0, 0, 0);
- if (!ipv6_generate_eui64(addr.s6_addr + 8, dev))
- addrconf_add_linklocal(idev, &addr);
- else
- addrconf_prefix_route(&addr, 64, dev, 0, 0);
+ addrconf_addr_gen(idev, true);
}
#endif
@@ -4423,6 +4426,10 @@ static int inet6_fill_ifla6_attrs(struct sk_buff *skb, struct inet6_dev *idev)
nla = nla_reserve(skb, IFLA_INET6_TOKEN, sizeof(struct in6_addr));
if (nla == NULL)
goto nla_put_failure;
+
+ if (nla_put_u8(skb, IFLA_INET6_ADDR_GEN_MODE, idev->addr_gen_mode))
+ goto nla_put_failure;
+
read_lock_bh(&idev->lock);
memcpy(nla_data(nla), idev->token.s6_addr, nla_len(nla));
read_unlock_bh(&idev->lock);
@@ -4527,8 +4534,21 @@ static int inet6_set_link_af(struct net_device *dev, const struct nlattr *nla)
if (nla_parse_nested(tb, IFLA_INET6_MAX, nla, NULL) < 0)
BUG();
- if (tb[IFLA_INET6_TOKEN])
+ if (tb[IFLA_INET6_TOKEN]) {
err = inet6_set_iftoken(idev, nla_data(tb[IFLA_INET6_TOKEN]));
+ if (err)
+ return err;
+ }
+
+ if (tb[IFLA_INET6_ADDR_GEN_MODE]) {
+ u8 mode = nla_get_u8(tb[IFLA_INET6_ADDR_GEN_MODE]);
+
+ if (mode != IN6_ADDR_GEN_MODE_EUI64 &&
+ mode != IN6_ADDR_GEN_MODE_NONE)
+ return -EINVAL;
+ idev->addr_gen_mode = mode;
+ err = 0;
+ }
return err;
}
--
1.9.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [patch iproute2] iproute2: allow to ipv6 set address generation mode
2014-07-11 19:10 [patch net-next v2] " Jiri Pirko
@ 2014-07-11 19:11 ` Jiri Pirko
0 siblings, 0 replies; 5+ messages in thread
From: Jiri Pirko @ 2014-07-11 19:11 UTC (permalink / raw)
To: netdev
Cc: davem, kuznet, jmorris, yoshfuji, kaber, sfeldma, arvid.brodin,
sucheta.chakraborty, hannes, stephen, dcbw
Signed-off-by: Jiri Pirko <jiri@resnulli.us>
---
include/linux/if_link.h | 6 ++++++
ip/iplink.c | 22 ++++++++++++++++++++++
2 files changed, 28 insertions(+)
diff --git a/include/linux/if_link.h b/include/linux/if_link.h
index fadef0f..39cb62c 100644
--- a/include/linux/if_link.h
+++ b/include/linux/if_link.h
@@ -202,11 +202,17 @@ enum {
IFLA_INET6_CACHEINFO, /* time values and max reasm size */
IFLA_INET6_ICMP6STATS, /* statistics (icmpv6) */
IFLA_INET6_TOKEN, /* device token */
+ IFLA_INET6_ADDR_GEN_MODE, /* implicit address generator mode */
__IFLA_INET6_MAX
};
#define IFLA_INET6_MAX (__IFLA_INET6_MAX - 1)
+enum in6_addr_gen_mode {
+ IN6_ADDR_GEN_MODE_EUI64,
+ IN6_ADDR_GEN_MODE_NONE,
+};
+
enum {
BRIDGE_MODE_UNSPEC,
BRIDGE_MODE_HAIRPIN,
diff --git a/ip/iplink.c b/ip/iplink.c
index 0d020ef..ecb05d6 100644
--- a/ip/iplink.c
+++ b/ip/iplink.c
@@ -81,6 +81,7 @@ void iplink_usage(void)
fprintf(stderr, " [ state { auto | enable | disable} ] ]\n");
fprintf(stderr, " [ master DEVICE ]\n");
fprintf(stderr, " [ nomaster ]\n");
+ fprintf(stderr, " [ addrgenmode { eui64 | none } ]\n");
fprintf(stderr, " ip link show [ DEVICE | group GROUP ] [up]\n");
if (iplink_have_newlink()) {
@@ -161,6 +162,15 @@ static int get_link_mode(const char *mode)
return -1;
}
+static int get_addr_gen_mode(const char *mode)
+{
+ if (strcasecmp(mode, "eui64") == 0)
+ return IN6_ADDR_GEN_MODE_EUI64;
+ if (strcasecmp(mode, "none") == 0)
+ return IN6_ADDR_GEN_MODE_NONE;
+ return -1;
+}
+
#if IPLINK_IOCTL_COMPAT
static int have_rtnl_newlink = -1;
@@ -557,6 +567,18 @@ int iplink_parse(int argc, char **argv, struct iplink_req *req,
invarg("Invalid \"numrxqueues\" value\n", *argv);
addattr_l(&req->n, sizeof(*req), IFLA_NUM_RX_QUEUES,
&numrxqueues, 4);
+ } else if (matches(*argv, "addrgenmode") == 0) {
+ struct rtattr *afs, *afs6;
+ int mode;
+ NEXT_ARG();
+ mode = get_addr_gen_mode(*argv);
+ if (mode < 0)
+ invarg("Invalid address generation mode\n", *argv);
+ afs = addattr_nest(&req->n, sizeof(*req), IFLA_AF_SPEC);
+ afs6 = addattr_nest(&req->n, sizeof(*req), AF_INET6);
+ addattr8(&req->n, sizeof(*req), IFLA_INET6_ADDR_GEN_MODE, mode);
+ addattr_nest_end(&req->n, afs6);
+ addattr_nest_end(&req->n, afs);
} else {
if (strcmp(*argv, "dev") == 0) {
NEXT_ARG();
--
1.9.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-07-11 19:11 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-11 8:19 [patch net-next] ipv6: addrconf: implement address generation modes Jiri Pirko
2014-07-11 8:30 ` [patch iproute2] iproute2: allow to ipv6 set address generation mode Jiri Pirko
2014-07-11 9:16 ` [patch net-next] ipv6: addrconf: implement address generation modes YOSHIFUJI Hideaki
2014-07-11 15:40 ` Dan Williams
-- strict thread matches above, loose matches on Subject: below --
2014-07-11 19:10 [patch net-next v2] " Jiri Pirko
2014-07-11 19:11 ` [patch iproute2] iproute2: allow to ipv6 set address generation mode Jiri Pirko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).