aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv4/devinet.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/ipv4/devinet.c')
-rw-r--r--net/ipv4/devinet.c37
1 files changed, 17 insertions, 20 deletions
diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
index 21f71bf912d5..f282b26f63eb 100644
--- a/net/ipv4/devinet.c
+++ b/net/ipv4/devinet.c
@@ -64,7 +64,7 @@
64#include <net/rtnetlink.h> 64#include <net/rtnetlink.h>
65#include <net/net_namespace.h> 65#include <net/net_namespace.h>
66 66
67struct ipv4_devconf ipv4_devconf = { 67static struct ipv4_devconf ipv4_devconf = {
68 .data = { 68 .data = {
69 [NET_IPV4_CONF_ACCEPT_REDIRECTS - 1] = 1, 69 [NET_IPV4_CONF_ACCEPT_REDIRECTS - 1] = 1,
70 [NET_IPV4_CONF_SEND_REDIRECTS - 1] = 1, 70 [NET_IPV4_CONF_SEND_REDIRECTS - 1] = 1,
@@ -485,46 +485,41 @@ errout:
485 return err; 485 return err;
486} 486}
487 487
488static struct in_ifaddr *rtm_to_ifaddr(struct nlmsghdr *nlh) 488static struct in_ifaddr *rtm_to_ifaddr(struct net *net, struct nlmsghdr *nlh)
489{ 489{
490 struct nlattr *tb[IFA_MAX+1]; 490 struct nlattr *tb[IFA_MAX+1];
491 struct in_ifaddr *ifa; 491 struct in_ifaddr *ifa;
492 struct ifaddrmsg *ifm; 492 struct ifaddrmsg *ifm;
493 struct net_device *dev; 493 struct net_device *dev;
494 struct in_device *in_dev; 494 struct in_device *in_dev;
495 int err = -EINVAL; 495 int err;
496 496
497 err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, ifa_ipv4_policy); 497 err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, ifa_ipv4_policy);
498 if (err < 0) 498 if (err < 0)
499 goto errout; 499 goto errout;
500 500
501 ifm = nlmsg_data(nlh); 501 ifm = nlmsg_data(nlh);
502 if (ifm->ifa_prefixlen > 32 || tb[IFA_LOCAL] == NULL) { 502 err = -EINVAL;
503 err = -EINVAL; 503 if (ifm->ifa_prefixlen > 32 || tb[IFA_LOCAL] == NULL)
504 goto errout; 504 goto errout;
505 }
506 505
507 dev = __dev_get_by_index(&init_net, ifm->ifa_index); 506 dev = __dev_get_by_index(net, ifm->ifa_index);
508 if (dev == NULL) { 507 err = -ENODEV;
509 err = -ENODEV; 508 if (dev == NULL)
510 goto errout; 509 goto errout;
511 }
512 510
513 in_dev = __in_dev_get_rtnl(dev); 511 in_dev = __in_dev_get_rtnl(dev);
514 if (in_dev == NULL) { 512 err = -ENOBUFS;
515 err = -ENOBUFS; 513 if (in_dev == NULL)
516 goto errout; 514 goto errout;
517 }
518 515
519 ifa = inet_alloc_ifa(); 516 ifa = inet_alloc_ifa();
520 if (ifa == NULL) { 517 if (ifa == NULL)
521 /* 518 /*
522 * A potential indev allocation can be left alive, it stays 519 * A potential indev allocation can be left alive, it stays
523 * assigned to its device and is destroy with it. 520 * assigned to its device and is destroy with it.
524 */ 521 */
525 err = -ENOBUFS;
526 goto errout; 522 goto errout;
527 }
528 523
529 ipv4_devconf_setall(in_dev); 524 ipv4_devconf_setall(in_dev);
530 in_dev_hold(in_dev); 525 in_dev_hold(in_dev);
@@ -568,7 +563,7 @@ static int inet_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg
568 if (net != &init_net) 563 if (net != &init_net)
569 return -EINVAL; 564 return -EINVAL;
570 565
571 ifa = rtm_to_ifaddr(nlh); 566 ifa = rtm_to_ifaddr(net, nlh);
572 if (IS_ERR(ifa)) 567 if (IS_ERR(ifa))
573 return PTR_ERR(ifa); 568 return PTR_ERR(ifa);
574 569
@@ -1182,7 +1177,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
1182 1177
1183 s_ip_idx = ip_idx = cb->args[1]; 1178 s_ip_idx = ip_idx = cb->args[1];
1184 idx = 0; 1179 idx = 0;
1185 for_each_netdev(&init_net, dev) { 1180 for_each_netdev(net, dev) {
1186 if (idx < s_idx) 1181 if (idx < s_idx)
1187 goto cont; 1182 goto cont;
1188 if (idx > s_idx) 1183 if (idx > s_idx)
@@ -1216,7 +1211,9 @@ static void rtmsg_ifa(int event, struct in_ifaddr* ifa, struct nlmsghdr *nlh,
1216 struct sk_buff *skb; 1211 struct sk_buff *skb;
1217 u32 seq = nlh ? nlh->nlmsg_seq : 0; 1212 u32 seq = nlh ? nlh->nlmsg_seq : 0;
1218 int err = -ENOBUFS; 1213 int err = -ENOBUFS;
1214 struct net *net;
1219 1215
1216 net = ifa->ifa_dev->dev->nd_net;
1220 skb = nlmsg_new(inet_nlmsg_size(), GFP_KERNEL); 1217 skb = nlmsg_new(inet_nlmsg_size(), GFP_KERNEL);
1221 if (skb == NULL) 1218 if (skb == NULL)
1222 goto errout; 1219 goto errout;
@@ -1228,10 +1225,10 @@ static void rtmsg_ifa(int event, struct in_ifaddr* ifa, struct nlmsghdr *nlh,
1228 kfree_skb(skb); 1225 kfree_skb(skb);
1229 goto errout; 1226 goto errout;
1230 } 1227 }
1231 err = rtnl_notify(skb, &init_net, pid, RTNLGRP_IPV4_IFADDR, nlh, GFP_KERNEL); 1228 err = rtnl_notify(skb, net, pid, RTNLGRP_IPV4_IFADDR, nlh, GFP_KERNEL);
1232errout: 1229errout:
1233 if (err < 0) 1230 if (err < 0)
1234 rtnl_set_sk_err(&init_net, RTNLGRP_IPV4_IFADDR, err); 1231 rtnl_set_sk_err(net, RTNLGRP_IPV4_IFADDR, err);
1235} 1232}
1236 1233
1237#ifdef CONFIG_SYSCTL 1234#ifdef CONFIG_SYSCTL