LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] ipv6: expose RFC4191 route preference via rtnetlink
@ 2015-03-03 10:01 Lubomir Rintel
  2015-03-03 15:17 ` Jiri Pirko
  0 siblings, 1 reply; 7+ messages in thread
From: Lubomir Rintel @ 2015-03-03 10:01 UTC (permalink / raw)
  To: netdev
  Cc: linux-kernel, linux-api, David S. Miller, Alexey Kuznetsov,
	Lubomir Rintel

This makes it possible to retain the route preference when RAs are handled in
userspace.

Signed-off-by: Lubomir Rintel <lkundrak@v3.sk>
---
 include/uapi/linux/rtnetlink.h |  1 +
 net/ipv6/route.c               | 16 +++++++++++++++-
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/include/uapi/linux/rtnetlink.h b/include/uapi/linux/rtnetlink.h
index 5cc5d66..0671524 100644
--- a/include/uapi/linux/rtnetlink.h
+++ b/include/uapi/linux/rtnetlink.h
@@ -303,6 +303,7 @@ enum rtattr_type_t {
 	RTA_TABLE,
 	RTA_MARK,
 	RTA_MFC_STATS,
+	RTA_PREF,
 	__RTA_MAX
 };
 
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 47b5109..08f689e 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -2401,6 +2401,7 @@ static const struct nla_policy rtm_ipv6_policy[RTA_MAX+1] = {
 	[RTA_PRIORITY]          = { .type = NLA_U32 },
 	[RTA_METRICS]           = { .type = NLA_NESTED },
 	[RTA_MULTIPATH]		= { .len = sizeof(struct rtnexthop) },
+	[RTA_PREF]              = { .type = NLA_U8 },
 };
 
 static int rtm_to_fib6_config(struct sk_buff *skb, struct nlmsghdr *nlh,
@@ -2408,6 +2409,7 @@ static int rtm_to_fib6_config(struct sk_buff *skb, struct nlmsghdr *nlh,
 {
 	struct rtmsg *rtm;
 	struct nlattr *tb[RTA_MAX+1];
+	unsigned int pref;
 	int err;
 
 	err = nlmsg_parse(nlh, sizeof(*rtm), tb, RTA_MAX, rtm_ipv6_policy);
@@ -2483,6 +2485,14 @@ static int rtm_to_fib6_config(struct sk_buff *skb, struct nlmsghdr *nlh,
 		cfg->fc_mp_len = nla_len(tb[RTA_MULTIPATH]);
 	}
 
+	if (tb[RTA_PREF]) {
+		pref = nla_get_u8(tb[RTA_PREF]);
+		if (pref == ICMPV6_ROUTER_PREF_LOW ||
+		    pref == ICMPV6_ROUTER_PREF_MEDIUM ||
+		    pref == ICMPV6_ROUTER_PREF_HIGH)
+			cfg->fc_flags |= RTF_PREF(pref);
+	}
+
 	err = 0;
 errout:
 	return err;
@@ -2586,7 +2596,8 @@ static inline size_t rt6_nlmsg_size(void)
 	       + nla_total_size(4) /* RTA_PRIORITY */
 	       + RTAX_MAX * nla_total_size(4) /* RTA_METRICS */
 	       + nla_total_size(sizeof(struct rta_cacheinfo))
-	       + nla_total_size(TCP_CA_NAME_MAX); /* RTAX_CC_ALGO */
+	       + nla_total_size(TCP_CA_NAME_MAX) /* RTAX_CC_ALGO */
+	       + nla_total_size(1); /* RTA_PREF */
 }
 
 static int rt6_fill_node(struct net *net,
@@ -2727,6 +2738,9 @@ static int rt6_fill_node(struct net *net,
 	if (rtnl_put_cacheinfo(skb, &rt->dst, 0, expires, rt->dst.error) < 0)
 		goto nla_put_failure;
 
+	if (nla_put_u8(skb, RTA_PREF, IPV6_EXTRACT_PREF(rt->rt6i_flags)))
+		goto nla_put_failure;
+
 	nlmsg_end(skb, nlh);
 	return 0;
 
-- 
2.1.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] ipv6: expose RFC4191 route preference via rtnetlink
  2015-03-03 10:01 [PATCH] ipv6: expose RFC4191 route preference via rtnetlink Lubomir Rintel
@ 2015-03-03 15:17 ` Jiri Pirko
  2015-03-10 15:56   ` Lubomir Rintel
  0 siblings, 1 reply; 7+ messages in thread
From: Jiri Pirko @ 2015-03-03 15:17 UTC (permalink / raw)
  To: Lubomir Rintel
  Cc: netdev, linux-kernel, linux-api, David S. Miller, Alexey Kuznetsov

Tue, Mar 03, 2015 at 11:01:52AM CET, lkundrak@v3.sk wrote:
>This makes it possible to retain the route preference when RAs are handled in
>userspace.
>
>Signed-off-by: Lubomir Rintel <lkundrak@v3.sk>
>---
> include/uapi/linux/rtnetlink.h |  1 +
> net/ipv6/route.c               | 16 +++++++++++++++-
> 2 files changed, 16 insertions(+), 1 deletion(-)
>
>diff --git a/include/uapi/linux/rtnetlink.h b/include/uapi/linux/rtnetlink.h
>index 5cc5d66..0671524 100644
>--- a/include/uapi/linux/rtnetlink.h
>+++ b/include/uapi/linux/rtnetlink.h
>@@ -303,6 +303,7 @@ enum rtattr_type_t {
> 	RTA_TABLE,
> 	RTA_MARK,
> 	RTA_MFC_STATS,
>+	RTA_PREF,
> 	__RTA_MAX
> };
> 
>diff --git a/net/ipv6/route.c b/net/ipv6/route.c
>index 47b5109..08f689e 100644
>--- a/net/ipv6/route.c
>+++ b/net/ipv6/route.c
>@@ -2401,6 +2401,7 @@ static const struct nla_policy rtm_ipv6_policy[RTA_MAX+1] = {
> 	[RTA_PRIORITY]          = { .type = NLA_U32 },
> 	[RTA_METRICS]           = { .type = NLA_NESTED },
> 	[RTA_MULTIPATH]		= { .len = sizeof(struct rtnexthop) },
>+	[RTA_PREF]              = { .type = NLA_U8 },
> };
> 
> static int rtm_to_fib6_config(struct sk_buff *skb, struct nlmsghdr *nlh,
>@@ -2408,6 +2409,7 @@ static int rtm_to_fib6_config(struct sk_buff *skb, struct nlmsghdr *nlh,
> {
> 	struct rtmsg *rtm;
> 	struct nlattr *tb[RTA_MAX+1];
>+	unsigned int pref;
> 	int err;
> 
> 	err = nlmsg_parse(nlh, sizeof(*rtm), tb, RTA_MAX, rtm_ipv6_policy);
>@@ -2483,6 +2485,14 @@ static int rtm_to_fib6_config(struct sk_buff *skb, struct nlmsghdr *nlh,
> 		cfg->fc_mp_len = nla_len(tb[RTA_MULTIPATH]);
> 	}
> 
>+	if (tb[RTA_PREF]) {
>+		pref = nla_get_u8(tb[RTA_PREF]);
>+		if (pref == ICMPV6_ROUTER_PREF_LOW ||
>+		    pref == ICMPV6_ROUTER_PREF_MEDIUM ||
>+		    pref == ICMPV6_ROUTER_PREF_HIGH)
>+			cfg->fc_flags |= RTF_PREF(pref);

Don't we want to do "goto errout;" in case pref is invalid ?


>+	}
>+
> 	err = 0;
> errout:
> 	return err;
>@@ -2586,7 +2596,8 @@ static inline size_t rt6_nlmsg_size(void)
> 	       + nla_total_size(4) /* RTA_PRIORITY */
> 	       + RTAX_MAX * nla_total_size(4) /* RTA_METRICS */
> 	       + nla_total_size(sizeof(struct rta_cacheinfo))
>-	       + nla_total_size(TCP_CA_NAME_MAX); /* RTAX_CC_ALGO */
>+	       + nla_total_size(TCP_CA_NAME_MAX) /* RTAX_CC_ALGO */
>+	       + nla_total_size(1); /* RTA_PREF */
> }
> 
> static int rt6_fill_node(struct net *net,
>@@ -2727,6 +2738,9 @@ static int rt6_fill_node(struct net *net,
> 	if (rtnl_put_cacheinfo(skb, &rt->dst, 0, expires, rt->dst.error) < 0)
> 		goto nla_put_failure;
> 
>+	if (nla_put_u8(skb, RTA_PREF, IPV6_EXTRACT_PREF(rt->rt6i_flags)))
>+		goto nla_put_failure;
>+
> 	nlmsg_end(skb, nlh);
> 	return 0;
> 
>-- 
>2.1.0
>
>--
>To unsubscribe from this list: send the line "unsubscribe netdev" in
>the body of a message to majordomo@vger.kernel.org
>More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] ipv6: expose RFC4191 route preference via rtnetlink
  2015-03-03 15:17 ` Jiri Pirko
@ 2015-03-10 15:56   ` Lubomir Rintel
  2015-03-10 16:04     ` Jiri Pirko
  0 siblings, 1 reply; 7+ messages in thread
From: Lubomir Rintel @ 2015-03-10 15:56 UTC (permalink / raw)
  To: Jiri Pirko
  Cc: netdev, linux-kernel, linux-api, David S. Miller, Alexey Kuznetsov

On Tue, 2015-03-03 at 16:17 +0100, Jiri Pirko wrote:
> Tue, Mar 03, 2015 at 11:01:52AM CET, lkundrak@v3.sk wrote:
> >This makes it possible to retain the route preference when RAs are handled in
> >userspace.
> >
> >Signed-off-by: Lubomir Rintel <lkundrak@v3.sk>
> >---
> > include/uapi/linux/rtnetlink.h |  1 +
> > net/ipv6/route.c               | 16 +++++++++++++++-
> > 2 files changed, 16 insertions(+), 1 deletion(-)
> >
> >diff --git a/include/uapi/linux/rtnetlink.h b/include/uapi/linux/rtnetlink.h
> >index 5cc5d66..0671524 100644
> >--- a/include/uapi/linux/rtnetlink.h
> >+++ b/include/uapi/linux/rtnetlink.h
> >@@ -303,6 +303,7 @@ enum rtattr_type_t {
> > 	RTA_TABLE,
> > 	RTA_MARK,
> > 	RTA_MFC_STATS,
> >+	RTA_PREF,
> > 	__RTA_MAX
> > };
> > 
> >diff --git a/net/ipv6/route.c b/net/ipv6/route.c
> >index 47b5109..08f689e 100644
> >--- a/net/ipv6/route.c
> >+++ b/net/ipv6/route.c
> >@@ -2401,6 +2401,7 @@ static const struct nla_policy rtm_ipv6_policy[RTA_MAX+1] = {
> > 	[RTA_PRIORITY]          = { .type = NLA_U32 },
> > 	[RTA_METRICS]           = { .type = NLA_NESTED },
> > 	[RTA_MULTIPATH]		= { .len = sizeof(struct rtnexthop) },
> >+	[RTA_PREF]              = { .type = NLA_U8 },
> > };
> > 
> > static int rtm_to_fib6_config(struct sk_buff *skb, struct nlmsghdr *nlh,
> >@@ -2408,6 +2409,7 @@ static int rtm_to_fib6_config(struct sk_buff *skb, struct nlmsghdr *nlh,
> > {
> > 	struct rtmsg *rtm;
> > 	struct nlattr *tb[RTA_MAX+1];
> >+	unsigned int pref;
> > 	int err;
> > 
> > 	err = nlmsg_parse(nlh, sizeof(*rtm), tb, RTA_MAX, rtm_ipv6_policy);
> >@@ -2483,6 +2485,14 @@ static int rtm_to_fib6_config(struct sk_buff *skb, struct nlmsghdr *nlh,
> > 		cfg->fc_mp_len = nla_len(tb[RTA_MULTIPATH]);
> > 	}
> > 
> >+	if (tb[RTA_PREF]) {
> >+		pref = nla_get_u8(tb[RTA_PREF]);
> >+		if (pref == ICMPV6_ROUTER_PREF_LOW ||
> >+		    pref == ICMPV6_ROUTER_PREF_MEDIUM ||
> >+		    pref == ICMPV6_ROUTER_PREF_HIGH)
> >+			cfg->fc_flags |= RTF_PREF(pref);
> 
> Don't we want to do "goto errout;" in case pref is invalid ?

I'm not sure. If RFC 4191 suggests that the invalid value ought to be
ignored (treated as medium). It could be done in the userspace or the
userspace could just relay whatever it got in the NDP message to the
kernel.

What is your opinion on this?

Thank you,
Lubo


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] ipv6: expose RFC4191 route preference via rtnetlink
  2015-03-10 15:56   ` Lubomir Rintel
@ 2015-03-10 16:04     ` Jiri Pirko
  2015-03-11 14:39       ` [PATCH v2] " Lubomir Rintel
  0 siblings, 1 reply; 7+ messages in thread
From: Jiri Pirko @ 2015-03-10 16:04 UTC (permalink / raw)
  To: Lubomir Rintel
  Cc: netdev, linux-kernel, linux-api, David S. Miller, Alexey Kuznetsov

Tue, Mar 10, 2015 at 04:56:53PM CET, lkundrak@v3.sk wrote:
>On Tue, 2015-03-03 at 16:17 +0100, Jiri Pirko wrote:
>> Tue, Mar 03, 2015 at 11:01:52AM CET, lkundrak@v3.sk wrote:
>> >This makes it possible to retain the route preference when RAs are handled in
>> >userspace.
>> >
>> >Signed-off-by: Lubomir Rintel <lkundrak@v3.sk>
>> >---
>> > include/uapi/linux/rtnetlink.h |  1 +
>> > net/ipv6/route.c               | 16 +++++++++++++++-
>> > 2 files changed, 16 insertions(+), 1 deletion(-)
>> >
>> >diff --git a/include/uapi/linux/rtnetlink.h b/include/uapi/linux/rtnetlink.h
>> >index 5cc5d66..0671524 100644
>> >--- a/include/uapi/linux/rtnetlink.h
>> >+++ b/include/uapi/linux/rtnetlink.h
>> >@@ -303,6 +303,7 @@ enum rtattr_type_t {
>> > 	RTA_TABLE,
>> > 	RTA_MARK,
>> > 	RTA_MFC_STATS,
>> >+	RTA_PREF,
>> > 	__RTA_MAX
>> > };
>> > 
>> >diff --git a/net/ipv6/route.c b/net/ipv6/route.c
>> >index 47b5109..08f689e 100644
>> >--- a/net/ipv6/route.c
>> >+++ b/net/ipv6/route.c
>> >@@ -2401,6 +2401,7 @@ static const struct nla_policy rtm_ipv6_policy[RTA_MAX+1] = {
>> > 	[RTA_PRIORITY]          = { .type = NLA_U32 },
>> > 	[RTA_METRICS]           = { .type = NLA_NESTED },
>> > 	[RTA_MULTIPATH]		= { .len = sizeof(struct rtnexthop) },
>> >+	[RTA_PREF]              = { .type = NLA_U8 },
>> > };
>> > 
>> > static int rtm_to_fib6_config(struct sk_buff *skb, struct nlmsghdr *nlh,
>> >@@ -2408,6 +2409,7 @@ static int rtm_to_fib6_config(struct sk_buff *skb, struct nlmsghdr *nlh,
>> > {
>> > 	struct rtmsg *rtm;
>> > 	struct nlattr *tb[RTA_MAX+1];
>> >+	unsigned int pref;
>> > 	int err;
>> > 
>> > 	err = nlmsg_parse(nlh, sizeof(*rtm), tb, RTA_MAX, rtm_ipv6_policy);
>> >@@ -2483,6 +2485,14 @@ static int rtm_to_fib6_config(struct sk_buff *skb, struct nlmsghdr *nlh,
>> > 		cfg->fc_mp_len = nla_len(tb[RTA_MULTIPATH]);
>> > 	}
>> > 
>> >+	if (tb[RTA_PREF]) {
>> >+		pref = nla_get_u8(tb[RTA_PREF]);
>> >+		if (pref == ICMPV6_ROUTER_PREF_LOW ||
>> >+		    pref == ICMPV6_ROUTER_PREF_MEDIUM ||
>> >+		    pref == ICMPV6_ROUTER_PREF_HIGH)
>> >+			cfg->fc_flags |= RTF_PREF(pref);
>> 
>> Don't we want to do "goto errout;" in case pref is invalid ?
>
>I'm not sure. If RFC 4191 suggests that the invalid value ought to be
>ignored (treated as medium). It could be done in the userspace or the
>userspace could just relay whatever it got in the NDP message to the
>kernel.

In that case I would suggest in case of invalid value to set pref to
ICMPV6_ROUTER_PREF_MEDIUM.

>
>What is your opinion on this?
>
>Thank you,
>Lubo
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2] ipv6: expose RFC4191 route preference via rtnetlink
  2015-03-10 16:04     ` Jiri Pirko
@ 2015-03-11 14:39       ` Lubomir Rintel
  2015-03-11 15:01         ` Jiri Pirko
  2015-03-12  3:28         ` David Miller
  0 siblings, 2 replies; 7+ messages in thread
From: Lubomir Rintel @ 2015-03-11 14:39 UTC (permalink / raw)
  To: netdev
  Cc: linux-kernel, linux-api, David S. Miller, Alexey Kuznetsov,
	Jiri Pirko, Lubomir Rintel

This makes it possible to retain the route preference when RAs are handled in
userspace.

Signed-off-by: Lubomir Rintel <lkundrak@v3.sk>
---
Changes since v1:
  - In case an invalid value is specified treat it as ICMPV6_ROUTER_PREF_MEDIUM

 include/uapi/linux/rtnetlink.h |  1 +
 net/ipv6/route.c               | 16 +++++++++++++++-
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/include/uapi/linux/rtnetlink.h b/include/uapi/linux/rtnetlink.h
index 5cc5d66..0671524 100644
--- a/include/uapi/linux/rtnetlink.h
+++ b/include/uapi/linux/rtnetlink.h
@@ -303,6 +303,7 @@ enum rtattr_type_t {
 	RTA_TABLE,
 	RTA_MARK,
 	RTA_MFC_STATS,
+	RTA_PREF,
 	__RTA_MAX
 };
 
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 47b5109..8b01d16 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -2401,6 +2401,7 @@ static const struct nla_policy rtm_ipv6_policy[RTA_MAX+1] = {
 	[RTA_PRIORITY]          = { .type = NLA_U32 },
 	[RTA_METRICS]           = { .type = NLA_NESTED },
 	[RTA_MULTIPATH]		= { .len = sizeof(struct rtnexthop) },
+	[RTA_PREF]              = { .type = NLA_U8 },
 };
 
 static int rtm_to_fib6_config(struct sk_buff *skb, struct nlmsghdr *nlh,
@@ -2408,6 +2409,7 @@ static int rtm_to_fib6_config(struct sk_buff *skb, struct nlmsghdr *nlh,
 {
 	struct rtmsg *rtm;
 	struct nlattr *tb[RTA_MAX+1];
+	unsigned int pref;
 	int err;
 
 	err = nlmsg_parse(nlh, sizeof(*rtm), tb, RTA_MAX, rtm_ipv6_policy);
@@ -2483,6 +2485,14 @@ static int rtm_to_fib6_config(struct sk_buff *skb, struct nlmsghdr *nlh,
 		cfg->fc_mp_len = nla_len(tb[RTA_MULTIPATH]);
 	}
 
+	if (tb[RTA_PREF]) {
+		pref = nla_get_u8(tb[RTA_PREF]);
+		if (pref != ICMPV6_ROUTER_PREF_LOW &&
+		    pref != ICMPV6_ROUTER_PREF_HIGH)
+			pref = ICMPV6_ROUTER_PREF_MEDIUM;
+		cfg->fc_flags |= RTF_PREF(pref);
+	}
+
 	err = 0;
 errout:
 	return err;
@@ -2586,7 +2596,8 @@ static inline size_t rt6_nlmsg_size(void)
 	       + nla_total_size(4) /* RTA_PRIORITY */
 	       + RTAX_MAX * nla_total_size(4) /* RTA_METRICS */
 	       + nla_total_size(sizeof(struct rta_cacheinfo))
-	       + nla_total_size(TCP_CA_NAME_MAX); /* RTAX_CC_ALGO */
+	       + nla_total_size(TCP_CA_NAME_MAX) /* RTAX_CC_ALGO */
+	       + nla_total_size(1); /* RTA_PREF */
 }
 
 static int rt6_fill_node(struct net *net,
@@ -2727,6 +2738,9 @@ static int rt6_fill_node(struct net *net,
 	if (rtnl_put_cacheinfo(skb, &rt->dst, 0, expires, rt->dst.error) < 0)
 		goto nla_put_failure;
 
+	if (nla_put_u8(skb, RTA_PREF, IPV6_EXTRACT_PREF(rt->rt6i_flags)))
+		goto nla_put_failure;
+
 	nlmsg_end(skb, nlh);
 	return 0;
 
-- 
2.1.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] ipv6: expose RFC4191 route preference via rtnetlink
  2015-03-11 14:39       ` [PATCH v2] " Lubomir Rintel
@ 2015-03-11 15:01         ` Jiri Pirko
  2015-03-12  3:28         ` David Miller
  1 sibling, 0 replies; 7+ messages in thread
From: Jiri Pirko @ 2015-03-11 15:01 UTC (permalink / raw)
  To: Lubomir Rintel
  Cc: netdev, linux-kernel, linux-api, David S. Miller, Alexey Kuznetsov

Wed, Mar 11, 2015 at 03:39:21PM CET, lkundrak@v3.sk wrote:
>This makes it possible to retain the route preference when RAs are handled in
>userspace.
>
>Signed-off-by: Lubomir Rintel <lkundrak@v3.sk>

Reviewed-by: Jiri Pirko <jiri@resnulli.us>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] ipv6: expose RFC4191 route preference via rtnetlink
  2015-03-11 14:39       ` [PATCH v2] " Lubomir Rintel
  2015-03-11 15:01         ` Jiri Pirko
@ 2015-03-12  3:28         ` David Miller
  1 sibling, 0 replies; 7+ messages in thread
From: David Miller @ 2015-03-12  3:28 UTC (permalink / raw)
  To: lkundrak; +Cc: netdev, linux-kernel, linux-api, kuznet, jiri

From: Lubomir Rintel <lkundrak@v3.sk>
Date: Wed, 11 Mar 2015 15:39:21 +0100

> This makes it possible to retain the route preference when RAs are handled in
> userspace.
> 
> Signed-off-by: Lubomir Rintel <lkundrak@v3.sk>
> ---
> Changes since v1:
>   - In case an invalid value is specified treat it as ICMPV6_ROUTER_PREF_MEDIUM

Applied, thanks.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-03-12  3:28 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-03 10:01 [PATCH] ipv6: expose RFC4191 route preference via rtnetlink Lubomir Rintel
2015-03-03 15:17 ` Jiri Pirko
2015-03-10 15:56   ` Lubomir Rintel
2015-03-10 16:04     ` Jiri Pirko
2015-03-11 14:39       ` [PATCH v2] " Lubomir Rintel
2015-03-11 15:01         ` Jiri Pirko
2015-03-12  3:28         ` David Miller

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).