From: Holger Eitzenberger <holger@eitzenberger.org>
To: Patrick McHardy <kaber@trash.net>, David Miller <davem@davemloft.net>
Cc: netfilter-devel@vger.kernel.org, netdev@vger.kernel.org
Subject: [patch 2/6] netlink: add nla_policy_len()
Date: Mon, 16 Mar 2009 23:07:01 +0100 [thread overview]
Message-ID: <20090316221137.034320718@jonathan.eitzenberger.org> (raw)
In-Reply-To: 20090316220659.756862181@jonathan.eitzenberger.org
[-- Attachment #1: netlink-add-nla_policy_len.diff --]
[-- Type: text/plain, Size: 2023 bytes --]
It calculates the max. length of a Netlink policy, which is usefull
for allocating Netlink buffers roughly the size of the actual
message.
Signed-off-by: Holger Eitzenberger <holger@eitzenberger.org>
Index: net-next-2.6/include/net/netlink.h
===================================================================
--- net-next-2.6.orig/include/net/netlink.h
+++ net-next-2.6/include/net/netlink.h
@@ -230,6 +230,7 @@ extern int nla_validate(struct nlattr *
extern int nla_parse(struct nlattr *tb[], int maxtype,
struct nlattr *head, int len,
const struct nla_policy *policy);
+extern int nla_policy_len(const struct nla_policy *, int);
extern struct nlattr * nla_find(struct nlattr *head, int len, int attrtype);
extern size_t nla_strlcpy(char *dst, const struct nlattr *nla,
size_t dstsize);
Index: net-next-2.6/net/netlink/attr.c
===================================================================
--- net-next-2.6.orig/net/netlink/attr.c
+++ net-next-2.6/net/netlink/attr.c
@@ -133,6 +133,32 @@ errout:
}
/**
+ * nla_policy_len - Determin the max. length of a policy
+ * @policy: policy to use
+ * @n: number of policies
+ *
+ * Determines the max. length of the policy. It is currently used
+ * to allocated Netlink buffers roughly the size of the actual
+ * message.
+ *
+ * Returns 0 on success or a negative error code.
+ */
+int
+nla_policy_len(const struct nla_policy *p, int n)
+{
+ int i, len = 0;
+
+ for (i = 0; i < n; i++) {
+ if (p->len)
+ len += nla_total_size(p->len);
+ else if (nla_attr_minlen[p->type])
+ len += nla_total_size(nla_attr_minlen[p->type]);
+ }
+
+ return len;
+}
+
+/**
* nla_parse - Parse a stream of attributes into a tb buffer
* @tb: destination array with maxtype+1 elements
* @maxtype: maximum attribute type to be expected
@@ -456,6 +482,7 @@ int nla_append(struct sk_buff *skb, int
}
EXPORT_SYMBOL(nla_validate);
+EXPORT_SYMBOL(nla_policy_len);
EXPORT_SYMBOL(nla_parse);
EXPORT_SYMBOL(nla_find);
EXPORT_SYMBOL(nla_strlcpy);
--
next prev parent reply other threads:[~2009-03-16 22:11 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-16 22:06 [patch 0/6] netfilter: ctnetlink allocation improvement Holger Eitzenberger
2009-03-16 22:07 ` [patch 1/6] ctnetlink: add callbacks to the per-proto nlattrs Holger Eitzenberger
2009-03-25 17:25 ` Patrick McHardy
2009-03-16 22:07 ` Holger Eitzenberger [this message]
2009-03-25 17:27 ` [patch 2/6] netlink: add nla_policy_len() Patrick McHardy
2009-03-16 22:07 ` [patch 3/6] netfilter: limit the length of the helper name Holger Eitzenberger
2009-03-25 17:32 ` Patrick McHardy
2009-03-25 17:41 ` Holger Eitzenberger
2009-03-25 17:44 ` Patrick McHardy
2009-03-16 22:07 ` [patch 4/6] ctnetlink: allocate right-sized ctnetlink skb Holger Eitzenberger
2009-03-25 17:46 ` Patrick McHardy
2009-03-16 22:07 ` [patch 5/6] netfilter: add generic function to get len of generic policy Holger Eitzenberger
2009-03-16 22:07 ` [patch 6/6] netfilter: calculate per-protocol nlattr size Holger Eitzenberger
2009-03-17 4:35 ` [patch 0/6] netfilter: ctnetlink allocation improvement Patrick McHardy
2009-03-17 7:39 ` Holger Eitzenberger
2009-03-17 9:07 ` Florian Westphal
2009-03-17 10:24 ` Pablo Neira Ayuso
2009-03-17 9:49 ` Pablo Neira Ayuso
2009-03-17 10:03 ` Holger Eitzenberger
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=20090316221137.034320718@jonathan.eitzenberger.org \
--to=holger@eitzenberger.org \
--cc=davem@davemloft.net \
--cc=kaber@trash.net \
--cc=netdev@vger.kernel.org \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.