netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Carlos Falgueras García" <carlosfg@riseup.net>
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: netfilter-devel@vger.kernel.org, kaber@trash.net
Subject: Re: [PATCH 1/4 v4] libnftnl: Implement new buffer of TLV objects
Date: Tue, 15 Mar 2016 21:29:13 +0100	[thread overview]
Message-ID: <56E87099.2070003@riseup.net> (raw)
In-Reply-To: <20160312110947.GA1764@salvia>

Thank you Pablo for the feedback. I will send now the version 5 with all 
changes you have asked me.

On 12/03/16 12:09, Pablo Neira Ayuso wrote:
>> diff --git a/src/libnftnl.map b/src/libnftnl.map
>> index 2e193b7..d6cd2a7 100644
>> --- a/src/libnftnl.map
>> +++ b/src/libnftnl.map
>> @@ -336,6 +336,22 @@ global:
>>     nftnl_set_snprintf;
>>     nftnl_set_fprintf;
>>
>> +  nftnl_udata_alloc;
>> +  nftnl_udata_free;
>> +  nftnl_udata_len;
>> +  nftnl_udata_size;
>> +  nftnl_udata_data;
>> +  nftnl_udata_copy_data;
>> +  nftnl_udata_start;
>> +  nftnl_udata_end;
>> +  nftnl_udata_put;
>> +  nftnl_udata_put_strz;
>> +  nftnl_udata_attr_type;
>> +  nftnl_udata_attr_len;
>> +  nftnl_udata_attr_value;
>> +  nftnl_udata_attr_next;
>> +  nftnl_udata_parse;
>
> Please, add these new symbols to LIBNFTNL_4.1.
Done

>> diff --git a/src/udata.c b/src/udata.c
>> new file mode 100644
>> index 0000000..0503ca3
>> --- /dev/null
>> +++ b/src/udata.c
>> @@ -0,0 +1,134 @@
>> +#include <libnftnl/udata.h>
>> +#include <udata.h>
>> +#include <utils.h>
>> +
>> +#include <stdlib.h>
>> +#include <stdint.h>
>> +#include <string.h>
>> +
>> +struct nftnl_udata_buf *nftnl_udata_alloc(size_t data_size)
>> +{
>> +	struct nftnl_udata_buf *buf;
>> +
>> +	buf = (struct nftnl_udata_buf *)
>> +		malloc(sizeof(struct nftnl_udata_buf) + data_size);
>
> No need for casting, ie.
>
> 	buf = malloc(sizeof(struct nftnl_udata_buf) + data_size);
>
>> +	if (!buf)
>> +		return NULL;
>> +	buf->size = data_size;
>> +	buf->end = buf->data;
>> +
>> +	return buf;
>> +}
>> +EXPORT_SYMBOL(nftnl_udata_alloc);
>> +
>> +void nftnl_udata_free(struct nftnl_udata_buf *buf)
>> +{
>> +	buf->size = 0;
>> +	buf->end = NULL;
>> +	free((void *)buf);
>               ^^^^^^^^
> No need for cast this either here.
>

I have changed this everywere.

>> +}
>> +EXPORT_SYMBOL(nftnl_udata_free);
>> +
>> +size_t nftnl_udata_len(const struct nftnl_udata_buf *buf)
>
> Better use uint32_t instead of size_t. This type depends on the arch
> so in 32 bit will be u32 and in 64 bit will be u64.
>
> And uint32_t should be sufficient for this, same thing here and
> everywhere else.
>
>> +{
>> +	return (size_t)(buf->end - buf->data);
>> +}
>> +EXPORT_SYMBOL(nftnl_udata_len);
>> +
>> +size_t nftnl_udata_size(const struct nftnl_udata_buf *buf)
>
> Same thing here.

Done.

>
>> +{
>> +	return buf->size;
>> +}
>> +EXPORT_SYMBOL(nftnl_udata_size);
>> +
>> +void *nftnl_udata_data(const struct nftnl_udata_buf *buf)
>> +{
>> +	return (void *)buf->data;
>> +}
>> +EXPORT_SYMBOL(nftnl_udata_data);
>> +
>> +void nftnl_udata_copy_data(struct nftnl_udata_buf *buf,
>> +			   const void *data, size_t len)
>> +{
>> +	memcpy(buf->data, data, len <= buf->size ? len : buf->size);
>> +	buf->end = buf->data + len;
>> +}
>> +EXPORT_SYMBOL(nftnl_udata_copy_data);
>> +
>> +struct nftnl_udata *nftnl_udata_start(const struct nftnl_udata_buf *buf)
>> +{
>> +	return (struct nftnl_udata *)buf->data;
>> +}
>> +EXPORT_SYMBOL(nftnl_udata_start);
>> +
>> +struct nftnl_udata *nftnl_udata_end(const struct nftnl_udata_buf *buf)
>> +{
>> +	return (struct nftnl_udata *)buf->end;
>> +}
>> +EXPORT_SYMBOL(nftnl_udata_end);
>> +
>> +struct nftnl_udata *nftnl_udata_put(struct nftnl_udata_buf *buf,
>> +				    uint8_t type, size_t len, const void *value)
>> +{
>> +	struct nftnl_udata *attr = NULL;
>> +
>> +	/* Check if there is enough space */
>
> Remove this comment.

Done.

>
>> +	if (buf->size >= len + sizeof(struct nftnl_udata)) {
>> +		attr = (struct nftnl_udata *)buf->end;
>> +		attr->len  = len;
>> +		attr->type = type;
>> +		memcpy(attr->value, value, len);
>> +
>> +		buf->end = (char *)nftnl_udata_attr_next(attr);
>> +	}
>> +
>> +	return attr;
>
> Why return the nftnl_udata? You can just return a boolean instead.
> Same thing in nftnl_udata_put_strz().

I thought it would be useful, actually it is not. I deleted it.

      reply	other threads:[~2016-03-15 20:29 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-10 21:37 [PATCH 1/4 v4] libnftnl: Implement new buffer of TLV objects Carlos Falgueras García
2016-03-10 21:37 ` [PATCH 2/4 v4] libnftnl: rule: Change the "userdata" attribute to use new TLV buffer Carlos Falgueras García
2016-03-10 21:37 ` [PATCH 3/4 v4] libnftnl: test: Actualize test to check new nftnl_udata features of nftnl_rule Carlos Falgueras García
2016-03-10 21:37 ` [PATCH 4/4 v4] nftables: rule: Change the field "rule->comment" for an nftnl_udata_buf Carlos Falgueras García
2016-03-12 11:29   ` Pablo Neira Ayuso
2016-03-15 20:29     ` Carlos Falgueras García
2016-03-12 11:09 ` [PATCH 1/4 v4] libnftnl: Implement new buffer of TLV objects Pablo Neira Ayuso
2016-03-15 20:29   ` Carlos Falgueras García [this message]

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=56E87099.2070003@riseup.net \
    --to=carlosfg@riseup.net \
    --cc=kaber@trash.net \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pablo@netfilter.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).