[IPV6]: annotate inet6_csk_search_req()
[safe/jmp/linux-2.6] / net / netfilter / nfnetlink.c
index 34d6719..52fdfa2 100644 (file)
@@ -14,7 +14,6 @@
  * 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>
@@ -128,18 +127,16 @@ 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);
 
        while (NFA_OK(nfa, len)) {
-               unsigned flavor = nfa->nfa_type;
+               unsigned flavor = NFA_TYPE(nfa);
                if (flavor && flavor <= maxattr)
                        tb[flavor-1] = nfa;
                nfa = NFA_NEXT(nfa, len);
        }
-
-       return 0;
 }
 
 /**
@@ -164,7 +161,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;
 
@@ -177,7 +174,7 @@ nfnetlink_check_attributes(struct nfnetlink_subsystem *subsys,
                int attrlen = nlh->nlmsg_len - NLMSG_ALIGN(min_len);
 
                while (NFA_OK(attr, attrlen)) {
-                       unsigned flavor = attr->nfa_type;
+                       unsigned flavor = NFA_TYPE(attr);
                        if (flavor) {
                                if (flavor > attr_count)
                                        return -EINVAL;
@@ -193,10 +190,15 @@ nfnetlink_check_attributes(struct nfnetlink_subsystem *subsys,
         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)
 {
-       unsigned int __nocast allocation =
-                       in_interrupt() ? GFP_ATOMIC : GFP_KERNEL;
+       gfp_t allocation = in_interrupt() ? GFP_ATOMIC : GFP_KERNEL;
        int err = 0;
 
        NETLINK_CB(skb).dst_group = group;
@@ -215,7 +217,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;
@@ -226,6 +228,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");
@@ -233,8 +241,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;
        }
@@ -251,7 +258,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);
@@ -260,13 +267,6 @@ 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 = 
                        ss->cb[NFNL_MSG_TYPE(nlh->nlmsg_type)].attr_count;