net: Move all of the network sysctls without a namespace into init_net.
[firefly-linux-kernel-4.4.55.git] / net / ipv4 / route.c
index 4dc1c104c942204882acadcf73e709683ebaafd6..86866a4b537f318ec9c22b7709045fee2bba4b7b 100644 (file)
 #include <net/rtnetlink.h>
 #ifdef CONFIG_SYSCTL
 #include <linux/sysctl.h>
+#include <linux/kmemleak.h>
 #endif
 #include <net/secure_seq.h>
 
@@ -229,7 +230,7 @@ const __u8 ip_tos2prio[16] = {
        TC_PRIO_INTERACTIVE_BULK,
        ECN_OR_COST(INTERACTIVE_BULK)
 };
-
+EXPORT_SYMBOL(ip_tos2prio);
 
 /*
  * Route cache.
@@ -296,7 +297,7 @@ static inline void rt_hash_lock_init(void)
 #endif
 
 static struct rt_hash_bucket   *rt_hash_table __read_mostly;
-static unsigned                        rt_hash_mask __read_mostly;
+static unsigned int            rt_hash_mask __read_mostly;
 static unsigned int            rt_hash_log  __read_mostly;
 
 static DEFINE_PER_CPU(struct rt_cache_stat, rt_cache_stat);
@@ -1143,7 +1144,7 @@ static int rt_bind_neighbour(struct rtable *rt)
        return 0;
 }
 
-static struct rtable *rt_intern_hash(unsigned hash, struct rtable *rt,
+static struct rtable *rt_intern_hash(unsigned int hash, struct rtable *rt,
                                     struct sk_buff *skb, int ifindex)
 {
        struct rtable   *rth, *cand;
@@ -1384,7 +1385,7 @@ void __ip_select_ident(struct iphdr *iph, struct dst_entry *dst, int more)
 }
 EXPORT_SYMBOL(__ip_select_ident);
 
-static void rt_del(unsigned hash, struct rtable *rt)
+static void rt_del(unsigned int hash, struct rtable *rt)
 {
        struct rtable __rcu **rthp;
        struct rtable *aux;
@@ -1538,7 +1539,7 @@ static struct dst_entry *ipv4_negative_advice(struct dst_entry *dst)
                        ip_rt_put(rt);
                        ret = NULL;
                } else if (rt->rt_flags & RTCF_REDIRECTED) {
-                       unsigned hash = rt_hash(rt->rt_key_dst, rt->rt_key_src,
+                       unsigned int hash = rt_hash(rt->rt_key_dst, rt->rt_key_src,
                                                rt->rt_oif,
                                                rt_genid(dev_net(dst->dev)));
                        rt_del(hash, rt);
@@ -2041,7 +2042,7 @@ static int ip_route_input_mc(struct sk_buff *skb, __be32 daddr, __be32 saddr,
                if (err < 0)
                        goto e_err;
        }
-       rth = rt_dst_alloc(init_net.loopback_dev,
+       rth = rt_dst_alloc(dev_net(dev)->loopback_dev,
                           IN_DEV_CONF_GET(in_dev, NOPOLICY), false);
        if (!rth)
                goto e_nobufs;
@@ -2215,9 +2216,9 @@ static int ip_mkroute_input(struct sk_buff *skb,
                            struct in_device *in_dev,
                            __be32 daddr, __be32 saddr, u32 tos)
 {
-       struct rtablerth = NULL;
+       struct rtable *rth = NULL;
        int err;
-       unsigned hash;
+       unsigned int hash;
 
 #ifdef CONFIG_IP_ROUTE_MULTIPATH
        if (res->fi && res->fi->fib_nhs > 1)
@@ -2255,13 +2256,13 @@ static int ip_route_input_slow(struct sk_buff *skb, __be32 daddr, __be32 saddr,
        struct fib_result res;
        struct in_device *in_dev = __in_dev_get_rcu(dev);
        struct flowi4   fl4;
-       unsigned        flags = 0;
+       unsigned int    flags = 0;
        u32             itag = 0;
-       struct rtable rth;
-       unsigned        hash;
+       struct rtable   *rth;
+       unsigned int    hash;
        __be32          spec_dst;
        int             err = -EINVAL;
-       struct net    * net = dev_net(dev);
+       struct net    *net = dev_net(dev);
 
        /* IP on this device is disabled. */
 
@@ -2433,8 +2434,8 @@ martian_source_keep_err:
 int ip_route_input_common(struct sk_buff *skb, __be32 daddr, __be32 saddr,
                           u8 tos, struct net_device *dev, bool noref)
 {
-       struct rtable rth;
-       unsigned        hash;
+       struct rtable   *rth;
+       unsigned int    hash;
        int iif = dev->ifindex;
        struct net *net;
        int res;
@@ -2972,7 +2973,8 @@ static int rt_fill_info(struct net *net,
        r->rtm_src_len  = 0;
        r->rtm_tos      = rt->rt_key_tos;
        r->rtm_table    = RT_TABLE_MAIN;
-       NLA_PUT_U32(skb, RTA_TABLE, RT_TABLE_MAIN);
+       if (nla_put_u32(skb, RTA_TABLE, RT_TABLE_MAIN))
+               goto nla_put_failure;
        r->rtm_type     = rt->rt_type;
        r->rtm_scope    = RT_SCOPE_UNIVERSE;
        r->rtm_protocol = RTPROT_UNSPEC;
@@ -2980,31 +2982,38 @@ static int rt_fill_info(struct net *net,
        if (rt->rt_flags & RTCF_NOTIFY)
                r->rtm_flags |= RTM_F_NOTIFY;
 
-       NLA_PUT_BE32(skb, RTA_DST, rt->rt_dst);
-
+       if (nla_put_be32(skb, RTA_DST, rt->rt_dst))
+               goto nla_put_failure;
        if (rt->rt_key_src) {
                r->rtm_src_len = 32;
-               NLA_PUT_BE32(skb, RTA_SRC, rt->rt_key_src);
+               if (nla_put_be32(skb, RTA_SRC, rt->rt_key_src))
+                       goto nla_put_failure;
        }
-       if (rt->dst.dev)
-               NLA_PUT_U32(skb, RTA_OIF, rt->dst.dev->ifindex);
+       if (rt->dst.dev &&
+           nla_put_u32(skb, RTA_OIF, rt->dst.dev->ifindex))
+               goto nla_put_failure;
 #ifdef CONFIG_IP_ROUTE_CLASSID
-       if (rt->dst.tclassid)
-               NLA_PUT_U32(skb, RTA_FLOW, rt->dst.tclassid);
+       if (rt->dst.tclassid &&
+           nla_put_u32(skb, RTA_FLOW, rt->dst.tclassid))
+               goto nla_put_failure;
 #endif
-       if (rt_is_input_route(rt))
-               NLA_PUT_BE32(skb, RTA_PREFSRC, rt->rt_spec_dst);
-       else if (rt->rt_src != rt->rt_key_src)
-               NLA_PUT_BE32(skb, RTA_PREFSRC, rt->rt_src);
-
-       if (rt->rt_dst != rt->rt_gateway)
-               NLA_PUT_BE32(skb, RTA_GATEWAY, rt->rt_gateway);
+       if (rt_is_input_route(rt)) {
+               if (nla_put_be32(skb, RTA_PREFSRC, rt->rt_spec_dst))
+                       goto nla_put_failure;
+       } else if (rt->rt_src != rt->rt_key_src) {
+               if (nla_put_be32(skb, RTA_PREFSRC, rt->rt_src))
+                       goto nla_put_failure;
+       }
+       if (rt->rt_dst != rt->rt_gateway &&
+           nla_put_be32(skb, RTA_GATEWAY, rt->rt_gateway))
+               goto nla_put_failure;
 
        if (rtnetlink_put_metrics(skb, dst_metrics_ptr(&rt->dst)) < 0)
                goto nla_put_failure;
 
-       if (rt->rt_mark)
-               NLA_PUT_BE32(skb, RTA_MARK, rt->rt_mark);
+       if (rt->rt_mark &&
+           nla_put_be32(skb, RTA_MARK, rt->rt_mark))
+               goto nla_put_failure;
 
        error = rt->dst.error;
        if (peer) {
@@ -3045,7 +3054,8 @@ static int rt_fill_info(struct net *net,
                        }
                } else
 #endif
-                       NLA_PUT_U32(skb, RTA_IIF, rt->rt_iif);
+                       if (nla_put_u32(skb, RTA_IIF, rt->rt_iif))
+                               goto nla_put_failure;
        }
 
        if (rtnl_put_cacheinfo(skb, &rt->dst, id, ts, tsage,
@@ -3059,7 +3069,7 @@ nla_put_failure:
        return -EMSGSIZE;
 }
 
-static int inet_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdrnlh, void *arg)
+static int inet_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh, void *arg)
 {
        struct net *net = sock_net(in_skb->sk);
        struct rtmsg *rtm;
@@ -3505,6 +3515,6 @@ int __init ip_rt_init(void)
  */
 void __init ip_static_sysctl_init(void)
 {
-       register_sysctl_paths(ipv4_path, ipv4_skeleton);
+       kmemleak_not_leak(register_net_sysctl_table(&init_net, ipv4_path, ipv4_skeleton));
 }
 #endif