]> bbs.cooldavid.org Git - net-next-2.6.git/blobdiff - net/decnet/dn_dev.c
[DECNET] address: Calculate accurate message size for netlink notifications
[net-next-2.6.git] / net / decnet / dn_dev.c
index a26ff9f44576fffb0c20dd7725a463c291db989e..2459a8d236a0509dcd17d2b689d040f736a5edec 100644 (file)
@@ -24,7 +24,6 @@
  *                             devices. All mtu based now.
  */
 
-#include <linux/config.h>
 #include <linux/capability.h>
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/seq_file.h>
 #include <linux/timer.h>
 #include <linux/string.h>
+#include <linux/if_addr.h>
 #include <linux/if_arp.h>
 #include <linux/if_ether.h>
 #include <linux/skbuff.h>
-#include <linux/rtnetlink.h>
 #include <linux/sysctl.h>
 #include <linux/notifier.h>
 #include <asm/uaccess.h>
@@ -46,6 +45,8 @@
 #include <net/neighbour.h>
 #include <net/dst.h>
 #include <net/flow.h>
+#include <net/fib_rules.h>
+#include <net/netlink.h>
 #include <net/dn.h>
 #include <net/dn_dev.h>
 #include <net/dn_route.h>
@@ -254,12 +255,10 @@ static void dn_dev_sysctl_register(struct net_device *dev, struct dn_dev_parms *
        struct dn_dev_sysctl_table *t;
        int i;
 
-       t = kmalloc(sizeof(*t), GFP_KERNEL);
+       t = kmemdup(&dn_dev_sysctl, sizeof(*t), GFP_KERNEL);
        if (t == NULL)
                return;
 
-       memcpy(t, &dn_dev_sysctl, sizeof(*t));
-
        for(i = 0; i < ARRAY_SIZE(t->dn_dev_vars) - 1; i++) {
                long offset = (long)t->dn_dev_vars[i].data;
                t->dn_dev_vars[i].data = ((char *)parms) + offset;
@@ -414,11 +413,7 @@ static struct dn_ifaddr *dn_dev_alloc_ifa(void)
 {
        struct dn_ifaddr *ifa;
 
-       ifa = kmalloc(sizeof(*ifa), GFP_KERNEL);
-
-       if (ifa) {
-               memset(ifa, 0, sizeof(*ifa));
-       }
+       ifa = kzalloc(sizeof(*ifa), GFP_KERNEL);
 
        return ifa;
 }
@@ -716,6 +711,14 @@ static int dn_dev_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh, void *a
        return rv;
 }
 
+static inline size_t dn_ifaddr_nlmsg_size(void)
+{
+       return NLMSG_ALIGN(sizeof(struct ifaddrmsg))
+              + nla_total_size(IFNAMSIZ) /* IFA_LABEL */
+              + nla_total_size(2) /* IFA_ADDRESS */
+              + nla_total_size(2); /* IFA_LOCAL */
+}
+
 static int dn_dev_fill_ifaddr(struct sk_buff *skb, struct dn_ifaddr *ifa,
                                u32 pid, u32 seq, int event, unsigned int flags)
 {
@@ -749,20 +752,20 @@ rtattr_failure:
 static void rtmsg_ifa(int event, struct dn_ifaddr *ifa)
 {
        struct sk_buff *skb;
-       int size = NLMSG_SPACE(sizeof(struct ifaddrmsg)+128);
+       int err = -ENOBUFS;
 
-       skb = alloc_skb(size, GFP_KERNEL);
-       if (!skb) {
-               netlink_set_err(rtnl, 0, RTNLGRP_DECnet_IFADDR, ENOBUFS);
-               return;
-       }
-       if (dn_dev_fill_ifaddr(skb, ifa, 0, 0, event, 0) < 0) {
-               kfree_skb(skb);
-               netlink_set_err(rtnl, 0, RTNLGRP_DECnet_IFADDR, EINVAL);
-               return;
-       }
-       NETLINK_CB(skb).dst_group = RTNLGRP_DECnet_IFADDR;
-       netlink_broadcast(rtnl, skb, 0, RTNLGRP_DECnet_IFADDR, GFP_KERNEL);
+       skb = alloc_skb(dn_ifaddr_nlmsg_size(), GFP_KERNEL);
+       if (skb == NULL)
+               goto errout;
+
+       err = dn_dev_fill_ifaddr(skb, ifa, 0, 0, event, 0);
+       /* failure implies BUG in dn_ifaddr_nlmsg_size() */
+       BUG_ON(err < 0);
+
+       err = rtnl_notify(skb, 0, RTNLGRP_DECnet_IFADDR, NULL, GFP_KERNEL);
+errout:
+       if (err < 0)
+               rtnl_set_sk_err(RTNLGRP_DECnet_IFADDR, err);
 }
 
 static int dn_dev_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
@@ -1106,10 +1109,9 @@ struct dn_dev *dn_dev_create(struct net_device *dev, int *err)
                return NULL;
 
        *err = -ENOBUFS;
-       if ((dn_db = kmalloc(sizeof(struct dn_dev), GFP_ATOMIC)) == NULL)
+       if ((dn_db = kzalloc(sizeof(struct dn_dev), GFP_ATOMIC)) == NULL)
                return NULL;
 
-       memset(dn_db, 0, sizeof(struct dn_dev));
        memcpy(&dn_db->parms, p, sizeof(struct dn_dev_parms));
        smp_wmb();
        dev->dn_ptr = dn_db;
@@ -1423,8 +1425,6 @@ static struct rtnetlink_link dnet_rtnetlink_table[RTM_NR_MSGTYPES] =
        [RTM_DELROUTE - RTM_BASE] = { .doit     = dn_fib_rtm_delroute,  },
        [RTM_GETROUTE - RTM_BASE] = { .doit     = dn_cache_getroute,
                                      .dumpit   = dn_fib_dump,          },
-       [RTM_NEWRULE  - RTM_BASE] = { .doit     = dn_fib_rtm_newrule,   },
-       [RTM_DELRULE  - RTM_BASE] = { .doit     = dn_fib_rtm_delrule,   },
        [RTM_GETRULE  - RTM_BASE] = { .dumpit   = dn_fib_dump_rules,    },
 #else
        [RTM_GETROUTE - RTM_BASE] = { .doit     = dn_cache_getroute,