netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Patrick McHardy <kaber@trash.net>
To: davem@davemloft.net
Cc: Patrick McHardy <kaber@trash.net>, netfilter-devel@vger.kernel.org
Subject: [NETFILTER 05/19]: nfnetlink: support attribute policies
Date: Fri, 28 Sep 2007 18:30:44 +0200 (MEST)	[thread overview]
Message-ID: <20070928163044.8394.90702.sendpatchset@localhost.localdomain> (raw)
In-Reply-To: <20070928163036.8394.36374.sendpatchset@localhost.localdomain>

[NETFILTER]: nfnetlink: support attribute policies

Add support for automatic checking of per-callback attribute policies.

Signed-off-by: Patrick McHardy <kaber@trash.net>

---
commit 77f03e3cfbe5b876031f757f2af2b55c568b0d34
tree 2347ecf9e7a9f8a64f9c8692f5fc3fcda00a7367
parent 6e4c97ee8ad0d54a48057f7fd1ec4e7cd2571556
author Patrick McHardy <kaber@trash.net> Fri, 28 Sep 2007 18:09:13 +0200
committer Patrick McHardy <kaber@trash.net> Fri, 28 Sep 2007 18:09:13 +0200

 include/linux/netfilter/nfnetlink.h |    3 +-
 net/netfilter/nfnetlink.c           |   48 +++++++++--------------------------
 2 files changed, 15 insertions(+), 36 deletions(-)

diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
index 0bd6086..3ee136a 100644
--- a/include/linux/netfilter/nfnetlink.h
+++ b/include/linux/netfilter/nfnetlink.h
@@ -58,7 +58,8 @@ struct nfnl_callback
 {
 	int (*call)(struct sock *nl, struct sk_buff *skb, 
 		struct nlmsghdr *nlh, struct nlattr *cda[]);
-	u_int16_t attr_count;	/* number of nlattr's */
+	const struct nla_policy *policy;	/* netlink attribute policy */
+	const u_int16_t attr_count;		/* number of nlattr's */
 };
 
 struct nfnetlink_subsystem
diff --git a/net/netfilter/nfnetlink.c b/net/netfilter/nfnetlink.c
index e212102..cb41990 100644
--- a/net/netfilter/nfnetlink.c
+++ b/net/netfilter/nfnetlink.c
@@ -111,35 +111,6 @@ nfnetlink_find_client(u_int16_t type, const struct nfnetlink_subsystem *ss)
 	return &ss->cb[cb_id];
 }
 
-/**
- * nfnetlink_check_attributes - check and parse nfnetlink attributes
- *
- * subsys: nfnl subsystem for which this message is to be parsed
- * nlmsghdr: netlink message to be checked/parsed
- * cda: array of pointers, needs to be at least subsys->attr_count+1 big
- *
- */
-static int
-nfnetlink_check_attributes(const struct nfnetlink_subsystem *subsys,
-			   struct nlmsghdr *nlh, struct nlattr *cda[])
-{
-	int min_len = NLMSG_SPACE(sizeof(struct nfgenmsg));
-	u_int8_t cb_id = NFNL_MSG_TYPE(nlh->nlmsg_type);
-	u_int16_t attr_count = subsys->cb[cb_id].attr_count;
-
-	/* check attribute lengths. */
-	if (likely(nlh->nlmsg_len > min_len)) {
-		struct nlattr *attr = (void *)nlh + NLMSG_ALIGN(min_len);
-		int attrlen = nlh->nlmsg_len - NLMSG_ALIGN(min_len);
-		nla_parse(cda, attr_count, attr, attrlen, NULL);
-	}
-
-	/* implicit: if nlmsg_len == min_len, we return 0, and an empty
-	 * (zeroed) cda[] array. The message is valid, but empty. */
-
-	return 0;
-}
-
 int nfnetlink_has_listeners(unsigned int group)
 {
 	return netlink_has_listeners(nfnl, group);
@@ -192,15 +163,22 @@ static int nfnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
 		return -EINVAL;
 
 	{
-		u_int16_t attr_count =
-			ss->cb[NFNL_MSG_TYPE(nlh->nlmsg_type)].attr_count;
+		int min_len = NLMSG_SPACE(sizeof(struct nfgenmsg));
+		u_int8_t cb_id = NFNL_MSG_TYPE(nlh->nlmsg_type);
+		u_int16_t attr_count = ss->cb[cb_id].attr_count;
 		struct nlattr *cda[attr_count+1];
 
-		memset(cda, 0, sizeof(struct nlattr *) * attr_count);
+		if (likely(nlh->nlmsg_len >= min_len)) {
+			struct nlattr *attr = (void *)nlh + NLMSG_ALIGN(min_len);
+			int attrlen = nlh->nlmsg_len - NLMSG_ALIGN(min_len);
+
+			err = nla_parse(cda, attr_count, attr, attrlen,
+					ss->cb[cb_id].policy);
+			if (err < 0)
+				return err;
+		} else
+			return -EINVAL;
 
-		err = nfnetlink_check_attributes(ss, nlh, cda);
-		if (err < 0)
-			return err;
 		return nc->call(nfnl, skb, nlh, cda);
 	}
 }

  parent reply	other threads:[~2007-09-28 16:30 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-28 16:30 [NETFILTER 00/19]: Netfilter update Patrick McHardy
2007-09-28 16:30 ` [NETFILTER 01/19]: nfnetlink: make subsystem and callbacks const Patrick McHardy
2007-09-28 16:30 ` [NETFILTER 02/19]: nfnetlink: convert to generic netlink attribute functions Patrick McHardy
2007-09-28 16:30 ` [NETFILTER 03/19]: nfnetlink: rename functions containing 'nfattr' Patrick McHardy
2007-09-28 16:30 ` [NETFILTER 04/19]: nfnetlink: use nlmsg_notify() Patrick McHardy
2007-09-28 16:30 ` Patrick McHardy [this message]
2007-09-28 16:30 ` [NETFILTER 06/19]: nfnetlink_log: use netlink policy Patrick McHardy
2007-09-28 16:30 ` [NETFILTER 07/19]: nfnetlink_queue: " Patrick McHardy
2007-09-28 16:30 ` [NETFILTER 08/19]: ctnetlink: " Patrick McHardy
2007-09-28 16:30 ` [NETFILTER 09/19]: nfnetlink: kill nlattr_bad_size Patrick McHardy
2007-09-28 16:30 ` [NETFILTER 10/19]: nf_conntrack: kill unique ID Patrick McHardy
2007-09-28 16:30 ` [NETFILTER 11/19]: nf_conntrack_expect: " Patrick McHardy
2007-09-28 16:30 ` [NETFILTER 12/19]: nf_conntrack_netlink: add support to related connections Patrick McHardy
2007-09-28 16:30 ` [NETFILTER 13/19]: nfnetlink_log: kill duplicate code Patrick McHardy
2007-09-28 16:30 ` [NETFILTER 14/19]: nfnetlink_log: flush queue early Patrick McHardy
2007-09-28 16:30 ` [NETFILTER 15/19]: nfnetlink_log: fix style Patrick McHardy
2007-09-28 16:30 ` [NETFILTER 16/19]: nfnetlink_log: fix instance_create() failure path Patrick McHardy
2007-09-28 16:31 ` [NETFILTER 17/19]: nfnetlink_log: fix some constants Patrick McHardy
2007-09-28 16:31 ` [NETFILTER 18/19]: x_tables: add xt_time match Patrick McHardy
2007-09-28 16:31 ` [NETFILTER 19/19]: bridge: remove broken netfilter binary sysctls Patrick McHardy
2007-09-28 21:52 ` [NETFILTER 00/19]: Netfilter update David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070928163044.8394.90702.sendpatchset@localhost.localdomain \
    --to=kaber@trash.net \
    --cc=davem@davemloft.net \
    --cc=netfilter-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).