From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Subject: [PATCH libnftnl 1/2] flowtable: device array dynamic allocation
Date: Fri, 18 Oct 2019 11:49:46 +0200 [thread overview]
Message-ID: <20191018094947.9531-1-pablo@netfilter.org> (raw)
Remove artificial upper limit of 8 devices per flowtable.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
src/flowtable.c | 29 +++++++++++++++--------------
1 file changed, 15 insertions(+), 14 deletions(-)
diff --git a/src/flowtable.c b/src/flowtable.c
index 1f7ba3052d4f..54e1bea25775 100644
--- a/src/flowtable.c
+++ b/src/flowtable.c
@@ -358,30 +358,31 @@ static int nftnl_flowtable_parse_hook_cb(const struct nlattr *attr, void *data)
static int nftnl_flowtable_parse_devs(struct nlattr *nest,
struct nftnl_flowtable *c)
{
+ const char **dev_array;
+ int len = 0, size = 8;
struct nlattr *attr;
- char *dev_array[8];
- int len = 0, i;
+
+ dev_array = calloc(8, sizeof(char *));
+ if (!dev_array)
+ return -1;
mnl_attr_for_each_nested(attr, nest) {
if (mnl_attr_get_type(attr) != NFTA_DEVICE_NAME)
goto err;
dev_array[len++] = strdup(mnl_attr_get_str(attr));
- if (len >= 8)
- break;
- }
+ if (len >= size) {
+ dev_array = realloc(dev_array, size * 2);
+ if (!dev_array)
+ goto err;
- if (!len)
- return -1;
-
- c->dev_array = calloc(len + 1, sizeof(char *));
- if (!c->dev_array)
- goto err;
+ size *= 2;
+ memset(&dev_array[len], 0, size - len);
+ }
+ }
+ c->dev_array = dev_array;
c->dev_array_len = len;
- for (i = 0; i < len; i++)
- c->dev_array[i] = dev_array[i];
-
return 0;
err:
while (len--)
--
2.11.0
next reply other threads:[~2019-10-18 9:49 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-18 9:49 Pablo Neira Ayuso [this message]
2019-10-18 9:49 ` [PATCH libnftnl 2/2] chain: multi-device support Pablo Neira Ayuso
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=20191018094947.9531-1-pablo@netfilter.org \
--to=pablo@netfilter.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.