From: Eric Leblond <eric@regit.org>
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: netfilter-devel@vger.kernel.org
Subject: Re: [nft PATCH 2/2] src: get rid of printf
Date: Mon, 04 Sep 2017 09:45:25 +0200 [thread overview]
Message-ID: <1504511125.15611.18.camel@regit.org> (raw)
In-Reply-To: <20170903223441.GB12383@salvia>
Hi,
On Mon, 2017-09-04 at 00:34 +0200, Pablo Neira Ayuso wrote:
> On Mon, Sep 04, 2017 at 12:03:56AM +0200, Eric Leblond wrote:
> > This patch introduces the nft_print_to_output_ctx function that has
> > to be used instead of printf to output information that where
> > previously send to stdout. This function accumulate the output in
> > a buffer that can be fetched by the user with the
> > nft_ctx_get_output()
> > function.
> >
> > This modification will allow the libnftables library to provide an
> > easy way to the users to get the output data and display them like
> > they want.
> >
> > Signed-off-by: Eric Leblond <eric@regit.org>
> > ---
> > include/datatype.h | 5 +-
> > include/expression.h | 2 +-
> > include/nftables.h | 5 ++
> > src/cli.c | 1 +
> > src/ct.c | 21 ++---
> > src/datatype.c | 66 ++++++++-------
> > src/expression.c | 79 ++++++++++--------
> > src/exthdr.c | 16 ++--
> > src/fib.c | 23 +++---
> > src/hash.c | 10 +--
> > src/main.c | 45 ++++++++++
> > src/meta.c | 32 +++++---
> > src/numgen.c | 8 +-
> > src/payload.c | 9 +-
> > src/rule.c | 228 +++++++++++++++++++++++++++++--------
> > --------------
> > src/statement.c | 145 +++++++++++++++++---------------
> > 16 files changed, 408 insertions(+), 287 deletions(-)
> >
> > diff --git a/include/datatype.h b/include/datatype.h
> > index 2e34591..e9f6079 100644
> > --- a/include/datatype.h
> > +++ b/include/datatype.h
> > @@ -209,7 +209,8 @@ extern void symbolic_constant_print(const
> > struct symbol_table *tbl,
> > struct output_ctx *octx);
> > extern void symbol_table_print(const struct symbol_table *tbl,
> > const struct datatype *dtype,
> > - enum byteorder byteorder);
> > + enum byteorder byteorder,
> > + struct output_ctx *octx);
> >
> > extern struct symbol_table *rt_symbol_table_init(const char
> > *filename);
> > extern void rt_symbol_table_free(struct symbol_table *tbl);
> > @@ -261,7 +262,7 @@ extern const struct datatype *
> > set_datatype_alloc(const struct datatype *orig_dtype, unsigned int
> > byteorder);
> > extern void set_datatype_destroy(const struct datatype *dtype);
> >
> > -extern void time_print(uint64_t seconds);
> > +extern void time_print(uint64_t seconds, struct output_ctx *octx);
> > extern struct error_record *time_parse(const struct location *loc,
> > const char *c, uint64_t
> > *res);
> >
> > diff --git a/include/expression.h b/include/expression.h
> > index 32d4423..ce6b702 100644
> > --- a/include/expression.h
> > +++ b/include/expression.h
> > @@ -334,7 +334,7 @@ extern struct expr *expr_get(struct expr
> > *expr);
> > extern void expr_free(struct expr *expr);
> > extern void expr_print(const struct expr *expr, struct output_ctx
> > *octx);
> > extern bool expr_cmp(const struct expr *e1, const struct expr
> > *e2);
> > -extern void expr_describe(const struct expr *expr);
> > +extern void expr_describe(const struct expr *expr, struct
> > output_ctx *octx);
> >
> > extern const struct datatype *expr_basetype(const struct expr
> > *expr);
> > extern void expr_set_type(struct expr *expr, const struct datatype
> > *dtype,
> > diff --git a/include/nftables.h b/include/nftables.h
> > index 7c4e93f..f4d5ce1 100644
> > --- a/include/nftables.h
> > +++ b/include/nftables.h
> > @@ -30,6 +30,8 @@ struct output_ctx {
> > unsigned int ip2name;
> > unsigned int handle;
> > unsigned int echo;
> > + char *output_buf;
> > + size_t output_buf_len;
> > };
> >
> > struct nft_cache {
> > @@ -149,4 +151,7 @@ void realm_table_meta_exit(void);
> > void devgroup_table_exit(void);
> > void realm_table_rt_exit(void);
> >
> > +int nft_print_to_output_ctx(struct output_ctx *octx, const char
> > *fmt, ...);
> > +char *nft_ctx_get_output(struct nft_ctx *ctx);
> > +
> > #endif /* NFTABLES_NFTABLES_H */
> > diff --git a/src/cli.c b/src/cli.c
> > index d923ff7..ca4418c 100644
> > --- a/src/cli.c
> > +++ b/src/cli.c
> > @@ -138,6 +138,7 @@ static void cli_complete(char *line)
> > cli_nft->debug_mask);
> > scanner_push_buffer(scanner, &indesc_cli, line);
> > nft_run(cli_nft, cli_nf_sock, scanner, state, &msgs);
> > + printf("%s", nft_ctx_get_output(cli_nft));
> > erec_print_list(stdout, &msgs, cli_nft->debug_mask);
> > xfree(line);
> > cache_release(&cli_nft->cache);
> > diff --git a/src/ct.c b/src/ct.c
> > index d64f467..f19608a 100644
> > --- a/src/ct.c
> > +++ b/src/ct.c
> > @@ -141,11 +141,12 @@ static void ct_label_type_print(const struct
> > expr *expr,
> > for (s = ct_label_tbl->symbols; s->identifier != NULL;
> > s++) {
> > if (bit != s->value)
> > continue;
> > - printf("\"%s\"", s->identifier);
> > + nft_print_to_output_ctx(octx, "\"%s\"", s-
> > >identifier);
> > return;
> > }
> > /* can happen when connlabel.conf is altered after rules
> > were added */
> > - printf("%ld\n", (long)mpz_scan1(expr->value, 0));
> > + nft_print_to_output_ctx(octx, "%ld\n",
>
> Let's call this nft_print(), ok?
Yes, that's really better.
>
> I can make the rename here before applying.
No need, I'm gonna resubmit the patchset.
BR,
--
Eric Leblond <eric@regit.org>
next prev parent reply other threads:[~2017-09-04 7:45 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-03 22:03 [nft PATCH 0/2] libnftables preparation work Eric Leblond
2017-09-03 22:03 ` [nft PATCH 1/2] src: add flags fo nft_ctx_new Eric Leblond
2017-09-03 22:33 ` Pablo Neira Ayuso
2017-09-03 22:45 ` Pablo Neira Ayuso
2017-09-04 7:21 ` Eric Leblond
2017-09-03 22:03 ` [nft PATCH 2/2] src: get rid of printf Eric Leblond
2017-09-03 22:34 ` Pablo Neira Ayuso
2017-09-04 7:45 ` Eric Leblond [this message]
2017-09-04 7:55 ` [nft PATCH v2] libnftables preparation work Eric Leblond
2017-09-04 7:55 ` [nft PATCH v2 1/2] src: add flags fo nft_ctx_new Eric Leblond
2017-09-04 20:43 ` Pablo Neira Ayuso
2017-09-04 7:55 ` [nft PATCH v2 2/2] src: get rid of printf Eric Leblond
2017-09-04 20:43 ` Pablo Neira Ayuso
2017-09-04 20:53 ` Pablo Neira Ayuso
2017-09-04 21:23 ` Eric Leblond
2017-09-05 17:33 ` Pablo Neira Ayuso
2017-09-21 15:37 ` Phil Sutter
2017-09-21 15:43 ` Florian Westphal
2017-09-21 15:51 ` Pablo Neira Ayuso
2017-09-21 16:21 ` Phil Sutter
2017-09-21 17:05 ` Florian Westphal
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=1504511125.15611.18.camel@regit.org \
--to=eric@regit.org \
--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).