]> err.no Git - linux-2.6/blobdiff - net/netfilter/nfnetlink.c
Merge branch 'for-linus' of master.kernel.org:/pub/scm/linux/kernel/git/roland/infiniband
[linux-2.6] / net / netfilter / nfnetlink.c
index 4bc27a6334c169690650dd900031fde729b35b73..bf23e489e4cdc88eec4a81a8c3461ac2cd5008ee 100644 (file)
  * of the GNU General Public License, incorporated herein by reference.
  */
 
-#include <linux/config.h>
 #include <linux/module.h>
 #include <linux/types.h>
 #include <linux/socket.h>
 #include <linux/kernel.h>
 #include <linux/major.h>
-#include <linux/sched.h>
 #include <linux/timer.h>
 #include <linux/string.h>
 #include <linux/sockios.h>
@@ -106,7 +104,7 @@ static inline struct nfnl_callback *
 nfnetlink_find_client(u_int16_t type, struct nfnetlink_subsystem *ss)
 {
        u_int8_t cb_id = NFNL_MSG_TYPE(type);
-       
+
        if (cb_id >= ss->cb_count) {
                DEBUGP("msgtype %u >= %u, returning\n", type, ss->cb_count);
                return NULL;
@@ -128,7 +126,7 @@ void __nfa_fill(struct sk_buff *skb, int attrtype, int attrlen,
        memset(NFA_DATA(nfa) + attrlen, 0, NFA_ALIGN(size) - size);
 }
 
-int nfattr_parse(struct nfattr *tb[], int maxattr, struct nfattr *nfa, int len)
+void nfattr_parse(struct nfattr *tb[], int maxattr, struct nfattr *nfa, int len)
 {
        memset(tb, 0, sizeof(struct nfattr *) * maxattr);
 
@@ -138,8 +136,6 @@ int nfattr_parse(struct nfattr *tb[], int maxattr, struct nfattr *nfa, int len)
                        tb[flavor-1] = nfa;
                nfa = NFA_NEXT(nfa, len);
        }
-
-       return 0;
 }
 
 /**
@@ -164,7 +160,7 @@ nfnetlink_check_attributes(struct nfnetlink_subsystem *subsys,
                return -EINVAL;
        }
 
-       min_len = NLMSG_ALIGN(sizeof(struct nfgenmsg));
+       min_len = NLMSG_SPACE(sizeof(struct nfgenmsg));
        if (unlikely(nlh->nlmsg_len < min_len))
                return -EINVAL;
 
@@ -190,18 +186,23 @@ nfnetlink_check_attributes(struct nfnetlink_subsystem *subsys,
        /* implicit: if nlmsg_len == min_len, we return 0, and an empty
         * (zeroed) cda[] array. The message is valid, but empty. */
 
-        return 0;
+       return 0;
 }
 
+int nfnetlink_has_listeners(unsigned int group)
+{
+       return netlink_has_listeners(nfnl, group);
+}
+EXPORT_SYMBOL_GPL(nfnetlink_has_listeners);
+
 int nfnetlink_send(struct sk_buff *skb, u32 pid, unsigned group, int echo)
 {
-       gfp_t allocation = in_interrupt() ? GFP_ATOMIC : GFP_KERNEL;
        int err = 0;
 
        NETLINK_CB(skb).dst_group = group;
        if (echo)
                atomic_inc(&skb->users);
-       netlink_broadcast(nfnl, skb, pid, group, allocation);
+       netlink_broadcast(nfnl, skb, pid, group, gfp_any());
        if (echo)
                err = netlink_unicast(nfnl, skb, pid, MSG_DONTWAIT);
 
@@ -214,7 +215,7 @@ int nfnetlink_unicast(struct sk_buff *skb, u_int32_t pid, int flags)
 }
 
 /* Process one complete nfnetlink message. */
-static inline int nfnetlink_rcv_msg(struct sk_buff *skb,
+static int nfnetlink_rcv_msg(struct sk_buff *skb,
                                    struct nlmsghdr *nlh, int *errp)
 {
        struct nfnl_callback *nc;
@@ -225,6 +226,12 @@ static inline int nfnetlink_rcv_msg(struct sk_buff *skb,
                 NFNL_SUBSYS_ID(nlh->nlmsg_type),
                 NFNL_MSG_TYPE(nlh->nlmsg_type));
 
+       if (security_netlink_recv(skb, CAP_NET_ADMIN)) {
+               DEBUGP("missing CAP_NET_ADMIN\n");
+               *errp = -EPERM;
+               return -1;
+       }
+
        /* Only requests are handled by kernel now. */
        if (!(nlh->nlmsg_flags & NLM_F_REQUEST)) {
                DEBUGP("received non-request message\n");
@@ -232,8 +239,7 @@ static inline int nfnetlink_rcv_msg(struct sk_buff *skb,
        }
 
        /* All the messages must at least contain nfgenmsg */
-       if (nlh->nlmsg_len < 
-                       NLMSG_LENGTH(NLMSG_ALIGN(sizeof(struct nfgenmsg)))) {
+       if (nlh->nlmsg_len < NLMSG_SPACE(sizeof(struct nfgenmsg))) {
                DEBUGP("received message was too short\n");
                return 0;
        }
@@ -250,7 +256,7 @@ static inline int nfnetlink_rcv_msg(struct sk_buff *skb,
                ss = nfnetlink_get_subsys(type);
                if (!ss)
 #endif
-               goto err_inval;
+                       goto err_inval;
        }
 
        nc = nfnetlink_find_client(type, ss);
@@ -259,20 +265,13 @@ static inline int nfnetlink_rcv_msg(struct sk_buff *skb,
                goto err_inval;
        }
 
-       if (nc->cap_required && 
-           !cap_raised(NETLINK_CB(skb).eff_cap, nc->cap_required)) {
-               DEBUGP("permission denied for type %d\n", type);
-               *errp = -EPERM;
-               return -1;
-       }
-
        {
-               u_int16_t attr_count = 
+               u_int16_t attr_count =
                        ss->cb[NFNL_MSG_TYPE(nlh->nlmsg_type)].attr_count;
                struct nfattr *cda[attr_count];
 
                memset(cda, 0, sizeof(struct nfattr *) * attr_count);
-               
+
                err = nfnetlink_check_attributes(ss, nlh, cda);
                if (err < 0)
                        goto err_inval;
@@ -356,7 +355,7 @@ static int __init nfnetlink_init(void)
        printk("Netfilter messages via NETLINK v%s.\n", nfversion);
 
        nfnl = netlink_kernel_create(NETLINK_NETFILTER, NFNLGRP_MAX,
-                                    nfnetlink_rcv, THIS_MODULE);
+                                    nfnetlink_rcv, THIS_MODULE);
        if (!nfnl) {
                printk(KERN_ERR "cannot initialize nfnetlink!\n");
                return -1;