]> err.no Git - linux-2.6/blobdiff - net/netlink/af_netlink.c
Merge master.kernel.org:/pub/scm/linux/kernel/git/davem/sparc-2.6
[linux-2.6] / net / netlink / af_netlink.c
index 0f36ddc0b72d7bfdeab851573404f851b5469266..383dd4e82ee150fc33a3a8b726c0d5e02ff7f4b8 100644 (file)
@@ -472,8 +472,7 @@ static int netlink_release(struct socket *sock)
                                NETLINK_URELEASE, &n);
        }       
 
-       if (nlk->module)
-               module_put(nlk->module);
+       module_put(nlk->module);
 
        netlink_table_grab();
        if (nlk->flags & NETLINK_KERNEL_SOCKET) {
@@ -699,7 +698,7 @@ static struct sock *netlink_getsockbypid(struct sock *ssk, u32 pid)
 
 struct sock *netlink_getsockbyfilp(struct file *filp)
 {
-       struct inode *inode = filp->f_dentry->d_inode;
+       struct inode *inode = filp->f_path.dentry->d_inode;
        struct sock *sock;
 
        if (!S_ISSOCK(inode->i_mode))
@@ -1075,8 +1074,9 @@ static int netlink_getsockopt(struct socket *sock, int level, int optname,
                        return -EINVAL;
                len = sizeof(int);
                val = nlk->flags & NETLINK_RECV_PKTINFO ? 1 : 0;
-               put_user(len, optlen);
-               put_user(val, optval);
+               if (put_user(len, optlen) ||
+                   put_user(val, optval))
+                       return -EFAULT;
                err = 0;
                break;
        default:
@@ -1147,12 +1147,11 @@ static int netlink_sendmsg(struct kiocb *kiocb, struct socket *sock,
        if (len > sk->sk_sndbuf - 32)
                goto out;
        err = -ENOBUFS;
-       skb = nlmsg_new(len, GFP_KERNEL);
+       skb = alloc_skb(len, GFP_KERNEL);
        if (skb==NULL)
                goto out;
 
        NETLINK_CB(skb).pid     = nlk->pid;
-       NETLINK_CB(skb).dst_pid = dst_pid;
        NETLINK_CB(skb).dst_group = dst_group;
        NETLINK_CB(skb).loginuid = audit_get_loginuid(current->audit_context);
        selinux_get_task_sid(current, &(NETLINK_CB(skb).sid));
@@ -1434,14 +1433,13 @@ void netlink_ack(struct sk_buff *in_skb, struct nlmsghdr *nlh, int err)
        struct sk_buff *skb;
        struct nlmsghdr *rep;
        struct nlmsgerr *errmsg;
-       int size;
+       size_t payload = sizeof(*errmsg);
 
-       if (err == 0)
-               size = nlmsg_total_size(sizeof(*errmsg));
-       else
-               size = nlmsg_total_size(sizeof(*errmsg) + nlmsg_len(nlh));
+       /* error messages get the original request appened */
+       if (err)
+               payload += nlmsg_len(nlh);
 
-       skb = nlmsg_new(size, GFP_KERNEL);
+       skb = nlmsg_new(payload, GFP_KERNEL);
        if (!skb) {
                struct sock *sk;
 
@@ -1549,6 +1547,38 @@ void netlink_queue_skip(struct nlmsghdr *nlh, struct sk_buff *skb)
        skb_pull(skb, msglen);
 }
 
+/**
+ * nlmsg_notify - send a notification netlink message
+ * @sk: netlink socket to use
+ * @skb: notification message
+ * @pid: destination netlink pid for reports or 0
+ * @group: destination multicast group or 0
+ * @report: 1 to report back, 0 to disable
+ * @flags: allocation flags
+ */
+int nlmsg_notify(struct sock *sk, struct sk_buff *skb, u32 pid,
+                unsigned int group, int report, gfp_t flags)
+{
+       int err = 0;
+
+       if (group) {
+               int exclude_pid = 0;
+
+               if (report) {
+                       atomic_inc(&skb->users);
+                       exclude_pid = pid;
+               }
+
+               /* errors reported via destination sk->sk_err */
+               nlmsg_multicast(sk, skb, exclude_pid, group, flags);
+       }
+
+       if (report)
+               err = nlmsg_unicast(sk, skb, pid);
+
+       return err;
+}
+
 #ifdef CONFIG_PROC_FS
 struct nl_seq_iter {
        int link;
@@ -1730,8 +1760,6 @@ static struct net_proto_family netlink_family_ops = {
        .owner  = THIS_MODULE,  /* for consistency 8) */
 };
 
-extern void netlink_skb_parms_too_large(void);
-
 static int __init netlink_proto_init(void)
 {
        struct sk_buff *dummy_skb;
@@ -1743,8 +1771,7 @@ static int __init netlink_proto_init(void)
        if (err != 0)
                goto out;
 
-       if (sizeof(struct netlink_skb_parms) > sizeof(dummy_skb->cb))
-               netlink_skb_parms_too_large();
+       BUILD_BUG_ON(sizeof(struct netlink_skb_parms) > sizeof(dummy_skb->cb));
 
        nl_table = kcalloc(MAX_LINKS, sizeof(*nl_table), GFP_KERNEL);
        if (!nl_table)
@@ -1802,4 +1829,4 @@ EXPORT_SYMBOL(netlink_set_err);
 EXPORT_SYMBOL(netlink_set_nonroot);
 EXPORT_SYMBOL(netlink_unicast);
 EXPORT_SYMBOL(netlink_unregister_notifier);
-
+EXPORT_SYMBOL(nlmsg_notify);