From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Subject: [PATCH nft] meta: skip -T for hour and date format
Date: Mon, 6 Sep 2021 10:31:19 +0200 [thread overview]
Message-ID: <20210906083119.1628-1-pablo@netfilter.org> (raw)
If -T is used:
- meta hour displays the hours in seconds based on your
- meta time displays the UNIX time since 1970 in nanoseconds.
Better, skip -T for these two datatypes and use the formatted output
instead, ie.
- meta hour "00:00:20"
- meta time "1970-01-01 01:00:01"
Fixes: f8f32deda31d ("meta: Introduce new conditions 'time', 'day' and 'hour'")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
src/meta.c | 33 +++++++++------------------------
1 file changed, 9 insertions(+), 24 deletions(-)
diff --git a/src/meta.c b/src/meta.c
index fdbeba26291a..bdd10269569d 100644
--- a/src/meta.c
+++ b/src/meta.c
@@ -388,27 +388,17 @@ static void date_type_print(const struct expr *expr, struct output_ctx *octx)
/* Convert from nanoseconds to seconds */
tstamp /= 1000000000L;
- if (!nft_output_seconds(octx)) {
- /* Obtain current tm, to add tm_gmtoff to the timestamp */
- cur_tm = localtime((time_t *) &tstamp);
+ /* Obtain current tm, to add tm_gmtoff to the timestamp */
+ cur_tm = localtime((time_t *) &tstamp);
- if (cur_tm)
- tstamp += cur_tm->tm_gmtoff;
-
- if ((tm = gmtime((time_t *) &tstamp)) != NULL &&
- strftime(timestr, sizeof(timestr) - 1, "%F %T", tm))
- nft_print(octx, "\"%s\"", timestr);
- else
- nft_print(octx, "Error converting timestamp to printed time");
-
- return;
- }
+ if (cur_tm)
+ tstamp += cur_tm->tm_gmtoff;
- /*
- * Do our own printing. The default print function will print in
- * nanoseconds, which is ugly.
- */
- nft_print(octx, "%" PRIu64, tstamp);
+ if ((tm = gmtime((time_t *) &tstamp)) != NULL &&
+ strftime(timestr, sizeof(timestr) - 1, "%F %T", tm))
+ nft_print(octx, "\"%s\"", timestr);
+ else
+ nft_print(octx, "Error converting timestamp to printed time");
}
static time_t parse_iso_date(const char *sym)
@@ -498,11 +488,6 @@ static void hour_type_print(const struct expr *expr, struct output_ctx *octx)
struct tm *cur_tm;
time_t ts;
- if (nft_output_seconds(octx)) {
- expr_basetype(expr)->print(expr, octx);
- return;
- }
-
/* Obtain current tm, so that we can add tm_gmtoff */
ts = time(NULL);
cur_tm = localtime(&ts);
--
2.20.1
reply other threads:[~2021-09-06 8:31 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20210906083119.1628-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 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).