return len + nla_total_size(4);
 }
 
-static int rtentry_to_fib_config(int cmd, struct rtentry *rt,
+static int rtentry_to_fib_config(struct net *net, int cmd, struct rtentry *rt,
                                 struct fib_config *cfg)
 {
        __be32 addr;
        int plen;
 
        memset(cfg, 0, sizeof(*cfg));
-       cfg->fc_nlinfo.nl_net = &init_net;
+       cfg->fc_nlinfo.nl_net = net;
 
        if (rt->rt_dst.sa_family != AF_INET)
                return -EAFNOSUPPORT;
                colon = strchr(devname, ':');
                if (colon)
                        *colon = 0;
-               dev = __dev_get_by_name(&init_net, devname);
+               dev = __dev_get_by_name(net, devname);
                if (!dev)
                        return -ENODEV;
                cfg->fc_oif = dev->ifindex;
        if (rt->rt_gateway.sa_family == AF_INET && addr) {
                cfg->fc_gw = addr;
                if (rt->rt_flags & RTF_GATEWAY &&
-                   inet_addr_type(&init_net, addr) == RTN_UNICAST)
+                   inet_addr_type(net, addr) == RTN_UNICAST)
                        cfg->fc_scope = RT_SCOPE_UNIVERSE;
        }
 
                        return -EFAULT;
 
                rtnl_lock();
-               err = rtentry_to_fib_config(cmd, &rt, &cfg);
+               err = rtentry_to_fib_config(&init_net, cmd, &rt, &cfg);
                if (err == 0) {
                        struct fib_table *tb;
 
        [RTA_FLOW]              = { .type = NLA_U32 },
 };
 
-static int rtm_to_fib_config(struct sk_buff *skb, struct nlmsghdr *nlh,
-                            struct fib_config *cfg)
+static int rtm_to_fib_config(struct net *net, struct sk_buff *skb,
+                           struct nlmsghdr *nlh, struct fib_config *cfg)
 {
        struct nlattr *attr;
        int err, remaining;
 
        cfg->fc_nlinfo.pid = NETLINK_CB(skb).pid;
        cfg->fc_nlinfo.nlh = nlh;
-       cfg->fc_nlinfo.nl_net = &init_net;
+       cfg->fc_nlinfo.nl_net = net;
 
        if (cfg->fc_type > RTN_MAX) {
                err = -EINVAL;
        if (net != &init_net)
                return -EINVAL;
 
-       err = rtm_to_fib_config(skb, nlh, &cfg);
+       err = rtm_to_fib_config(net, skb, nlh, &cfg);
        if (err < 0)
                goto errout;
 
        if (net != &init_net)
                return -EINVAL;
 
-       err = rtm_to_fib_config(skb, nlh, &cfg);
+       err = rtm_to_fib_config(net, skb, nlh, &cfg);
        if (err < 0)
                goto errout;
 
 
 static void fib_magic(int cmd, int type, __be32 dst, int dst_len, struct in_ifaddr *ifa)
 {
+       struct net *net = ifa->ifa_dev->dev->nd_net;
        struct fib_table *tb;
        struct fib_config cfg = {
                .fc_protocol = RTPROT_KERNEL,
                .fc_oif = ifa->ifa_dev->dev->ifindex,
                .fc_nlflags = NLM_F_CREATE | NLM_F_APPEND,
                .fc_nlinfo = {
-                       .nl_net = &init_net,
+                       .nl_net = net,
                },
        };
 
        if (type == RTN_UNICAST)
-               tb = fib_new_table(&init_net, RT_TABLE_MAIN);
+               tb = fib_new_table(net, RT_TABLE_MAIN);
        else
-               tb = fib_new_table(&init_net, RT_TABLE_LOCAL);
+               tb = fib_new_table(net, RT_TABLE_LOCAL);
 
        if (tb == NULL)
                return;