Blob Blame History Raw
From fad810f8c3b1b9135f9b8a89d6e6e5472fb2b3b4 Mon Sep 17 00:00:00 2001
From: Phil Sutter <psutter@redhat.com>
Date: Fri, 12 May 2017 18:29:28 +0200
Subject: [PATCH] datatype: time_type should send milliseconds to userspace

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1427114
Upstream Status: nftables commit 82dfc87c85f00
Conflicts: Adjusted one test case for previously backported commit
	   3ed932917cc74 ("src: use new range expression for != [a,b]
	   intervals").

commit 82dfc87c85f00acfa0d46369ae3f66c26a93f502
Author: Pablo Neira Ayuso <pablo@netfilter.org>
Date:   Fri Jul 8 15:12:31 2016 +0200

    datatype: time_type should send milliseconds to userspace

    Kernel expects milliseconds, so fix this datatype to use
    milliseconds instead of seconds.

    Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 include/utils.h           |  1 +
 src/datatype.c            |  3 ++-
 tests/py/any/ct.t.payload | 16 ++++++++--------
 3 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/include/utils.h b/include/utils.h
index 8a1dc5e..d886764 100644
--- a/include/utils.h
+++ b/include/utils.h
@@ -83,6 +83,7 @@
 	(void) (&_max1 == &_max2);		\
 	_max1 > _max2 ? _max1 : _max2; })
 
+#define MSEC_PER_SEC	1000L
 
 /**
  * fls - find last (most-significant) bit set
diff --git a/src/datatype.c b/src/datatype.c
index 40e14c9..002c4c6 100644
--- a/src/datatype.c
+++ b/src/datatype.c
@@ -883,7 +883,7 @@ struct error_record *time_parse(const struct location *loc, const char *str,
 
 static void time_type_print(const struct expr *expr)
 {
-	time_print(mpz_get_uint64(expr->value));
+	time_print(mpz_get_uint64(expr->value) / MSEC_PER_SEC);
 }
 
 static struct error_record *time_type_parse(const struct expr *sym,
@@ -896,6 +896,7 @@ static struct error_record *time_type_parse(const struct expr *sym,
 	if (erec != NULL)
 		return erec;
 
+	s *= MSEC_PER_SEC;
 	if (s > UINT32_MAX)
 		return error(&sym->location, "value too large");
 
diff --git a/tests/py/any/ct.t.payload b/tests/py/any/ct.t.payload
index 26bcf26..0598fdf 100644
--- a/tests/py/any/ct.t.payload
+++ b/tests/py/any/ct.t.payload
@@ -197,35 +197,35 @@ ip test-ip4 output
 # ct expiration 30
 ip test-ip4 output
   [ ct load expiration => reg 1 ]
-  [ cmp eq reg 1 0x0000001e ]
+  [ cmp eq reg 1 0x00007530 ]
 
 # ct expiration 22
 ip test-ip4 output
   [ ct load expiration => reg 1 ]
-  [ cmp eq reg 1 0x00000016 ]
+  [ cmp eq reg 1 0x000055f0 ]
 
 # ct expiration != 233
 ip test-ip4 output
   [ ct load expiration => reg 1 ]
-  [ cmp neq reg 1 0x000000e9 ]
+  [ cmp neq reg 1 0x00038e28 ]
 
 # ct expiration 33-45
 ip test-ip4 output
   [ ct load expiration => reg 1 ]
   [ byteorder reg 1 = hton(reg 1, 4, 4) ]
-  [ cmp gte reg 1 0x21000000 ]
-  [ cmp lte reg 1 0x2d000000 ]
+  [ cmp gte reg 1 0xe8800000 ]
+  [ cmp lte reg 1 0xc8af0000 ]
 
 # ct expiration != 33-45
 ip test-ip4 output
   [ ct load expiration => reg 1 ]
   [ byteorder reg 1 = hton(reg 1, 4, 4) ]
-  [ range neq reg 1 0x21000000 0x2d000000 ]
+  [ range neq reg 1 0xe8800000 0xc8af0000 ]
 
 # ct expiration {33, 55, 67, 88}
 __set%d test-ip4 3
 __set%d test-ip4 0
-	element 00000021  : 0 [end]	element 00000037  : 0 [end]	element 00000043  : 0 [end]	element 00000058  : 0 [end]
+	element 000080e8  : 0 [end]	element 0000d6d8  : 0 [end]	element 000105b8  : 0 [end]	element 000157c0  : 0 [end]
 ip test-ip4 output
   [ ct load expiration => reg 1 ]
   [ lookup reg 1 set __set%d ]
@@ -233,7 +233,7 @@ ip test-ip4 output
 # ct expiration {33-55}
 __set%d test-ip4 7
 __set%d test-ip4 0
-	element 00000000  : 1 [end]	element 21000000  : 0 [end]	element 38000000  : 1 [end]
+	element 00000000  : 1 [end]	element e8800000  : 0 [end]	element d9d60000  : 1 [end]
 ip test-ip4 output
   [ ct load expiration => reg 1 ]
   [ byteorder reg 1 = hton(reg 1, 4, 4) ]
-- 
1.8.3.1