]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blobdiff - net/ipv6/route.c
netlink: implement nla_put_in_addr and nla_put_in6_addr
[mirror_ubuntu-artful-kernel.git] / net / ipv6 / route.c
index 06fa819c43c931ce3be664d78b735530a4ce588b..385e9bd4f21815382b8045e8621291d33136cc81 100644 (file)
@@ -1476,7 +1476,7 @@ static int ip6_convert_metrics(struct mx6_config *mxc,
        int remaining;
        u32 *mp;
 
-       if (cfg->fc_mx == NULL)
+       if (!cfg->fc_mx)
                return 0;
 
        mp = kzalloc(sizeof(u32) * RTAX_MAX, GFP_KERNEL);
@@ -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,
@@ -2658,19 +2669,19 @@ static int rt6_fill_node(struct net *net,
                rtm->rtm_flags |= RTM_F_CLONED;
 
        if (dst) {
-               if (nla_put(skb, RTA_DST, 16, dst))
+               if (nla_put_in6_addr(skb, RTA_DST, dst))
                        goto nla_put_failure;
                rtm->rtm_dst_len = 128;
        } else if (rtm->rtm_dst_len)
-               if (nla_put(skb, RTA_DST, 16, &rt->rt6i_dst.addr))
+               if (nla_put_in6_addr(skb, RTA_DST, &rt->rt6i_dst.addr))
                        goto nla_put_failure;
 #ifdef CONFIG_IPV6_SUBTREES
        if (src) {
-               if (nla_put(skb, RTA_SRC, 16, src))
+               if (nla_put_in6_addr(skb, RTA_SRC, src))
                        goto nla_put_failure;
                rtm->rtm_src_len = 128;
        } else if (rtm->rtm_src_len &&
-                  nla_put(skb, RTA_SRC, 16, &rt->rt6i_src.addr))
+                  nla_put_in6_addr(skb, RTA_SRC, &rt->rt6i_src.addr))
                goto nla_put_failure;
 #endif
        if (iif) {
@@ -2694,14 +2705,14 @@ static int rt6_fill_node(struct net *net,
        } else if (dst) {
                struct in6_addr saddr_buf;
                if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf) == 0 &&
-                   nla_put(skb, RTA_PREFSRC, 16, &saddr_buf))
+                   nla_put_in6_addr(skb, RTA_PREFSRC, &saddr_buf))
                        goto nla_put_failure;
        }
 
        if (rt->rt6i_prefsrc.plen) {
                struct in6_addr saddr_buf;
                saddr_buf = rt->rt6i_prefsrc.addr;
-               if (nla_put(skb, RTA_PREFSRC, 16, &saddr_buf))
+               if (nla_put_in6_addr(skb, RTA_PREFSRC, &saddr_buf))
                        goto nla_put_failure;
        }
 
@@ -2709,7 +2720,7 @@ static int rt6_fill_node(struct net *net,
                goto nla_put_failure;
 
        if (rt->rt6i_flags & RTF_GATEWAY) {
-               if (nla_put(skb, RTA_GATEWAY, 16, &rt->rt6i_gateway) < 0)
+               if (nla_put_in6_addr(skb, RTA_GATEWAY, &rt->rt6i_gateway) < 0)
                        goto nla_put_failure;
        }
 
@@ -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;