]> git.karo-electronics.de Git - linux-beck.git/commitdiff
ipv6: expose RFC4191 route preference via rtnetlink
authorLubomir Rintel <lkundrak@v3.sk>
Wed, 11 Mar 2015 14:39:21 +0000 (15:39 +0100)
committerDavid S. Miller <davem@davemloft.net>
Thu, 12 Mar 2015 03:28:09 +0000 (23:28 -0400)
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>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/uapi/linux/rtnetlink.h
net/ipv6/route.c

index c3722b024e73afb6459ce3f1528bdef92cc18971..bea910f924dde6b125568e83e737801e721778c0 100644 (file)
@@ -305,6 +305,7 @@ enum rtattr_type_t {
        RTA_MFC_STATS,
        RTA_VIA,
        RTA_NEWDST,
+       RTA_PREF,
        __RTA_MAX
 };
 
index 06fa819c43c931ce3be664d78b735530a4ce588b..58c0e6a4d15de6789fb6214d6bc56f4721cf4127 100644 (file)
@@ -2398,6 +2398,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,
@@ -2405,6 +2406,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);
@@ -2480,6 +2482,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;
@@ -2583,7 +2593,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,
@@ -2724,6 +2735,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;