All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Elise Lennion <elise.lennion@gmail.com>
Cc: netfilter-devel@vger.kernel.org
Subject: Re: [PATCH nft v2] datatype: Display pre-defined inet_service values in host byte order
Date: Wed, 7 Dec 2016 20:25:10 +0100	[thread overview]
Message-ID: <20161207192510.GA3314@salvia> (raw)
In-Reply-To: <20161207190331.GA7206@lennorien.com>

Hi Elise,

On Wed, Dec 07, 2016 at 05:03:31PM -0200, Elise Lennion wrote:
> nft describe displays, to the user, which values are available for a selector,
> then the values should be in host byte order.
> 
> Reported-by: Pablo Neira Ayuso <pablo@netfilter.org>
> Fixes: ccc5da470e76 ("datatype: Replace getnameinfo() by internal lookup table")
> Signed-off-by: Elise Lennion <elise.lennion@gmail.com>
> ---
> 
>  v2: Created a function to convert different types and number of bytes
> 
>  include/datatype.h |  3 ++-
>  src/datatype.c     | 27 ++++++++++++++++++++++++---
>  src/expression.c   |  3 ++-
>  3 files changed, 28 insertions(+), 5 deletions(-)
> 
> diff --git a/include/datatype.h b/include/datatype.h
> index d4fe817..a7db1df 100644
> --- a/include/datatype.h
> +++ b/include/datatype.h
> @@ -191,7 +191,8 @@ extern struct error_record *symbolic_constant_parse(const struct expr *sym,
>  extern void symbolic_constant_print(const struct symbol_table *tbl,
>  				    const struct expr *expr, bool quotes);
>  extern void symbol_table_print(const struct symbol_table *tbl,
> -			       const struct datatype *dtype);
> +			       const struct datatype *dtype,
> +			       enum byteorder byteorder);
>  
>  extern struct symbol_table *rt_symbol_table_init(const char *filename);
>  extern void rt_symbol_table_free(struct symbol_table *tbl);
> diff --git a/src/datatype.c b/src/datatype.c
> index b5d73bc..c884171 100644
> --- a/src/datatype.c
> +++ b/src/datatype.c
> @@ -180,15 +180,36 @@ void symbolic_constant_print(const struct symbol_table *tbl,
>  		printf("%s", s->identifier);
>  }
>  
> +static void big_to_host_byteorder(void *value, const unsigned int nbytes)
> +{
> +	unsigned char *p = value;
> +	unsigned int i;
> +
> +	for (i = 0; i < nbytes / 2; i++) {
> +		p[i] ^= p[nbytes - 1 - i];
> +		p[nbytes - 1 - i] ^= p[i];
> +		p[i] ^= p[nbytes - 1 - i];
> +	}

Sorry, probably I should have specified a bit more.

I suggest you use libgmp for this, that allows any arbitrary word
size. See mpz_init() to initialize the variable, then
mpz_switch_byteorder() to change byteorder. Then, export it via
mpz_export_data() back to fixed standard datatypes.

libgmp is well documented, please have a look at it.

Thanks.

  reply	other threads:[~2016-12-07 19:25 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-07 19:03 [PATCH nft v2] datatype: Display pre-defined inet_service values in host byte order Elise Lennion
2016-12-07 19:25 ` Pablo Neira Ayuso [this message]
2016-12-08 17:16   ` Elise Lennion
2016-12-08 18:47     ` 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=20161207192510.GA3314@salvia \
    --to=pablo@netfilter.org \
    --cc=elise.lennion@gmail.com \
    --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.