summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2021-07-17 07:11:16 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2021-07-17 07:11:16 +0000
commita68848db159cc1cafa82f9d383432fda459c8745 (patch)
tree5fd1cd2cd6f298bebbbb0ce5db29fa6de68a2acc /src/core
parentAdding debian version 1.1.0+debian-1. (diff)
downloaddnsjit-a68848db159cc1cafa82f9d383432fda459c8745.tar.xz
dnsjit-a68848db159cc1cafa82f9d383432fda459c8745.zip
Merging upstream version 1.2.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/core')
-rw-r--r--src/core/assert.h2
-rw-r--r--src/core/channel.h6
-rw-r--r--src/core/file.c37
-rw-r--r--src/core/file.h26
-rw-r--r--src/core/file.hh21
-rw-r--r--src/core/file.lua37
-rw-r--r--src/core/loader.lua68
-rw-r--r--src/core/log.h2
-rw-r--r--src/core/object.h2
-rw-r--r--src/core/object/dns.h6
-rw-r--r--src/core/object/ether.h6
-rw-r--r--src/core/object/gre.h6
-rw-r--r--src/core/object/icmp.h6
-rw-r--r--src/core/object/icmp6.h6
-rw-r--r--src/core/object/ieee802.h6
-rw-r--r--src/core/object/ip.h6
-rw-r--r--src/core/object/ip6.h6
-rw-r--r--src/core/object/linuxsll.h6
-rw-r--r--src/core/object/loop.h6
-rw-r--r--src/core/object/null.h6
-rw-r--r--src/core/object/payload.h6
-rw-r--r--src/core/object/pcap.h6
-rw-r--r--src/core/object/tcp.h6
-rw-r--r--src/core/object/udp.h6
-rw-r--r--src/core/producer.h4
-rw-r--r--src/core/receiver.h4
-rw-r--r--src/core/thread.h4
-rw-r--r--src/core/timespec.h2
-rw-r--r--src/core/timespec.lua26
29 files changed, 271 insertions, 60 deletions
diff --git a/src/core/assert.h b/src/core/assert.h
index 3f2f503..1cdc6e6 100644
--- a/src/core/assert.h
+++ b/src/core/assert.h
@@ -21,7 +21,7 @@
#ifndef __dnsjit_core_assert_h
#define __dnsjit_core_assert_h
-#include "core/log.h"
+#include <dnsjit/core/log.h>
#define mlassert_self() \
if (!self) \
diff --git a/src/core/channel.h b/src/core/channel.h
index 75e84ac..b0e90ae 100644
--- a/src/core/channel.h
+++ b/src/core/channel.h
@@ -18,8 +18,8 @@
* along with dnsjit. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "core/log.h"
-#include "core/receiver.h"
+#include <dnsjit/core/log.h>
+#include <dnsjit/core/receiver.h>
#ifndef __dnsjit_core_channel_h
#define __dnsjit_core_channel_h
@@ -36,6 +36,6 @@
#include <ck_pr.h>
#include <stdbool.h>
-#include "core/channel.hh"
+#include <dnsjit/core/channel.hh>
#endif
diff --git a/src/core/file.c b/src/core/file.c
new file mode 100644
index 0000000..d632a73
--- /dev/null
+++ b/src/core/file.c
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2018-2021, OARC, Inc.
+ * All rights reserved.
+ *
+ * This file is part of dnsjit.
+ *
+ * dnsjit is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * dnsjit is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with dnsjit. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include "core/file.h"
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+int core_file_exists(const char* filename)
+{
+ struct stat s;
+
+ if (stat(filename, &s)) {
+ return 1;
+ }
+ return 0;
+}
diff --git a/src/core/file.h b/src/core/file.h
new file mode 100644
index 0000000..ad5a174
--- /dev/null
+++ b/src/core/file.h
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2018-2021, OARC, Inc.
+ * All rights reserved.
+ *
+ * This file is part of dnsjit.
+ *
+ * dnsjit is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * dnsjit is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with dnsjit. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __dnsjit_core_file_h
+#define __dnsjit_core_file_h
+
+#include <dnsjit/core/file.hh>
+
+#endif
diff --git a/src/core/file.hh b/src/core/file.hh
new file mode 100644
index 0000000..70b1bc9
--- /dev/null
+++ b/src/core/file.hh
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2018-2021, OARC, Inc.
+ * All rights reserved.
+ *
+ * This file is part of dnsjit.
+ *
+ * dnsjit is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * dnsjit is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with dnsjit. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+int core_file_exists(const char*);
diff --git a/src/core/file.lua b/src/core/file.lua
new file mode 100644
index 0000000..5ce52d7
--- /dev/null
+++ b/src/core/file.lua
@@ -0,0 +1,37 @@
+-- Copyright (c) 2018-2021, OARC, Inc.
+-- All rights reserved.
+--
+-- This file is part of dnsjit.
+--
+-- dnsjit is free software: you can redistribute it and/or modify
+-- it under the terms of the GNU General Public License as published by
+-- the Free Software Foundation, either version 3 of the License, or
+-- (at your option) any later version.
+--
+-- dnsjit is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+-- GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License
+-- along with dnsjit. If not, see <http://www.gnu.org/licenses/>.
+
+-- dnsjit.core.file
+-- OS file operations
+-- require("dnsjit.core.file")
+-- local ffi = require("ffi")
+-- if ffi.C.core_file_exists("path/file") == 0 then
+-- ...
+-- end
+--
+-- Module that exposes some file operations that are missing from Lua.
+-- .SS C functions
+-- .TP
+-- core_file_exists(path/filename)
+-- Function that takes a string and uses
+-- .B stat()
+-- to check if that path/filename exists.
+-- Returns zero if it exists.
+module(...,package.seeall)
+
+require("dnsjit.core.file_h")
diff --git a/src/core/loader.lua b/src/core/loader.lua
new file mode 100644
index 0000000..b56a390
--- /dev/null
+++ b/src/core/loader.lua
@@ -0,0 +1,68 @@
+-- Copyright (c) 2018-2021, OARC, Inc.
+-- All rights reserved.
+--
+-- This file is part of dnsjit.
+--
+-- dnsjit is free software: you can redistribute it and/or modify
+-- it under the terms of the GNU General Public License as published by
+-- the Free Software Foundation, either version 3 of the License, or
+-- (at your option) any later version.
+--
+-- dnsjit is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+-- GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License
+-- along with dnsjit. If not, see <http://www.gnu.org/licenses/>.
+
+-- dnsjit.core.loader
+-- Dynamic library loader
+-- local loader = require("dnsjit.core.loader")
+-- loader.load("example-input-zero/zero")
+--
+-- Module for loading dynamic libraries (.so) in more ways then LuaJIT can.
+-- This is mainly used in external modules.
+module(...,package.seeall)
+
+require("dnsjit.core.file")
+local ffi = require("ffi")
+local C = ffi.C
+
+local Loader = {}
+
+-- Search
+-- .B package.cpath
+-- for the given name and load the first found.
+-- If
+-- .B global
+-- is true (default true if not given) then the loaded symbols will also
+-- be available globally.
+-- Returns the loaded C library as per
+-- .BR ffi.load() .
+-- .br
+-- The
+-- .B ?
+-- in each path of
+-- .B package.cpath
+-- will be replace by the given name, so usually the ".so" part of the
+-- library does not need to be given.
+-- See
+-- .I package.cpath
+-- and
+-- .I package.loaders
+-- in Lua 5.1 for more information.
+function Loader.load(name, global)
+ if global ~= false then
+ global = true
+ end
+ for path in string.gmatch(package.cpath, "[^;]+") do
+ path = path:gsub("?", name)
+ if C.core_file_exists(path) == 0 then
+ return ffi.load(path, global)
+ end
+ end
+ return ffi.load(name)
+end
+
+return Loader
diff --git a/src/core/log.h b/src/core/log.h
index d17c733..05b3db9 100644
--- a/src/core/log.h
+++ b/src/core/log.h
@@ -38,7 +38,7 @@
name, 1, LOG_SETTINGS_T_INIT, &_log.settings \
}
-#include "core/log.hh"
+#include <dnsjit/core/log.hh>
#ifdef DNSJIT_NO_LOGGING
#define ldebug(msg...)
diff --git a/src/core/object.h b/src/core/object.h
index c2eebb0..8729cde 100644
--- a/src/core/object.h
+++ b/src/core/object.h
@@ -44,7 +44,7 @@
#define CORE_OBJECT_DNS 50
#include <stdint.h>
-#include "core/object.hh"
+#include <dnsjit/core/object.hh>
#define CORE_OBJECT_INIT(type, prev) (core_object_t*)prev, type
diff --git a/src/core/object/dns.h b/src/core/object/dns.h
index 5fbaf53..68a2dc9 100644
--- a/src/core/object/dns.h
+++ b/src/core/object/dns.h
@@ -18,8 +18,8 @@
* along with dnsjit. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "core/log.h"
-#include "core/object.h"
+#include <dnsjit/core/log.h>
+#include <dnsjit/core/object.h>
#ifndef __dnsjit_core_object_dns_h
#define __dnsjit_core_object_dns_h
@@ -27,7 +27,7 @@
#include <netinet/in.h>
#include <sys/types.h>
-#include "core/object/dns.hh"
+#include <dnsjit/core/object/dns.hh>
#define CORE_OBJECT_DNS_INIT(prev) \
{ \
diff --git a/src/core/object/ether.h b/src/core/object/ether.h
index e35ecb2..0fc9e35 100644
--- a/src/core/object/ether.h
+++ b/src/core/object/ether.h
@@ -18,15 +18,15 @@
* along with dnsjit. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "core/object.h"
-#include "core/timespec.h"
+#include <dnsjit/core/object.h>
+#include <dnsjit/core/timespec.h>
#ifndef __dnsjit_core_object_ether_h
#define __dnsjit_core_object_ether_h
#include <stddef.h>
-#include "core/object/ether.hh"
+#include <dnsjit/core/object/ether.hh>
#define CORE_OBJECT_ETHER_INIT(prev) \
{ \
diff --git a/src/core/object/gre.h b/src/core/object/gre.h
index 8efa93c..a716787 100644
--- a/src/core/object/gre.h
+++ b/src/core/object/gre.h
@@ -18,15 +18,15 @@
* along with dnsjit. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "core/object.h"
-#include "core/timespec.h"
+#include <dnsjit/core/object.h>
+#include <dnsjit/core/timespec.h>
#ifndef __dnsjit_core_object_gre_h
#define __dnsjit_core_object_gre_h
#include <stddef.h>
-#include "core/object/gre.hh"
+#include <dnsjit/core/object/gre.hh>
#define CORE_OBJECT_GRE_INIT(prev) \
{ \
diff --git a/src/core/object/icmp.h b/src/core/object/icmp.h
index 346a3ea..65ffa7d 100644
--- a/src/core/object/icmp.h
+++ b/src/core/object/icmp.h
@@ -18,15 +18,15 @@
* along with dnsjit. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "core/object.h"
-#include "core/timespec.h"
+#include <dnsjit/core/object.h>
+#include <dnsjit/core/timespec.h>
#ifndef __dnsjit_core_object_icmp_h
#define __dnsjit_core_object_icmp_h
#include <stddef.h>
-#include "core/object/icmp.hh"
+#include <dnsjit/core/object/icmp.hh>
#define CORE_OBJECT_ICMP_INIT(prev) \
{ \
diff --git a/src/core/object/icmp6.h b/src/core/object/icmp6.h
index 569bf7f..4586d33 100644
--- a/src/core/object/icmp6.h
+++ b/src/core/object/icmp6.h
@@ -18,15 +18,15 @@
* along with dnsjit. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "core/object.h"
-#include "core/timespec.h"
+#include <dnsjit/core/object.h>
+#include <dnsjit/core/timespec.h>
#ifndef __dnsjit_core_object_icmp6_h
#define __dnsjit_core_object_icmp6_h
#include <stddef.h>
-#include "core/object/icmp6.hh"
+#include <dnsjit/core/object/icmp6.hh>
#define CORE_OBJECT_ICMP6_INIT(prev) \
{ \
diff --git a/src/core/object/ieee802.h b/src/core/object/ieee802.h
index ca4847c..388430d 100644
--- a/src/core/object/ieee802.h
+++ b/src/core/object/ieee802.h
@@ -18,15 +18,15 @@
* along with dnsjit. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "core/object.h"
-#include "core/timespec.h"
+#include <dnsjit/core/object.h>
+#include <dnsjit/core/timespec.h>
#ifndef __dnsjit_core_object_ieee802_h
#define __dnsjit_core_object_ieee802_h
#include <stddef.h>
-#include "core/object/ieee802.hh"
+#include <dnsjit/core/object/ieee802.hh>
#define CORE_OBJECT_IEEE802_INIT(prev) \
{ \
diff --git a/src/core/object/ip.h b/src/core/object/ip.h
index c2b9312..00e927b 100644
--- a/src/core/object/ip.h
+++ b/src/core/object/ip.h
@@ -18,15 +18,15 @@
* along with dnsjit. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "core/object.h"
-#include "core/timespec.h"
+#include <dnsjit/core/object.h>
+#include <dnsjit/core/timespec.h>
#ifndef __dnsjit_core_object_ip_h
#define __dnsjit_core_object_ip_h
#include <stddef.h>
-#include "core/object/ip.hh"
+#include <dnsjit/core/object/ip.hh>
#define CORE_OBJECT_IP_INIT(prev) \
{ \
diff --git a/src/core/object/ip6.h b/src/core/object/ip6.h
index 711f1a5..660b9e9 100644
--- a/src/core/object/ip6.h
+++ b/src/core/object/ip6.h
@@ -18,15 +18,15 @@
* along with dnsjit. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "core/object.h"
-#include "core/timespec.h"
+#include <dnsjit/core/object.h>
+#include <dnsjit/core/timespec.h>
#ifndef __dnsjit_core_object_ip6_h
#define __dnsjit_core_object_ip6_h
#include <stddef.h>
-#include "core/object/ip6.hh"
+#include <dnsjit/core/object/ip6.hh>
#define CORE_OBJECT_IP6_INIT(prev) \
{ \
diff --git a/src/core/object/linuxsll.h b/src/core/object/linuxsll.h
index 9484c0d..668581e 100644
--- a/src/core/object/linuxsll.h
+++ b/src/core/object/linuxsll.h
@@ -18,15 +18,15 @@
* along with dnsjit. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "core/object.h"
-#include "core/timespec.h"
+#include <dnsjit/core/object.h>
+#include <dnsjit/core/timespec.h>
#ifndef __dnsjit_core_object_linuxsll_h
#define __dnsjit_core_object_linuxsll_h
#include <stddef.h>
-#include "core/object/linuxsll.hh"
+#include <dnsjit/core/object/linuxsll.hh>
#define CORE_OBJECT_LINUXSLL_INIT(prev) \
{ \
diff --git a/src/core/object/loop.h b/src/core/object/loop.h
index 1d8670f..0cdb8e0 100644
--- a/src/core/object/loop.h
+++ b/src/core/object/loop.h
@@ -18,15 +18,15 @@
* along with dnsjit. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "core/object.h"
-#include "core/timespec.h"
+#include <dnsjit/core/object.h>
+#include <dnsjit/core/timespec.h>
#ifndef __dnsjit_core_object_loop_h
#define __dnsjit_core_object_loop_h
#include <stddef.h>
-#include "core/object/loop.hh"
+#include <dnsjit/core/object/loop.hh>
#define CORE_OBJECT_LOOP_INIT(prev) \
{ \
diff --git a/src/core/object/null.h b/src/core/object/null.h
index 0317fce..5127951 100644
--- a/src/core/object/null.h
+++ b/src/core/object/null.h
@@ -18,15 +18,15 @@
* along with dnsjit. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "core/object.h"
-#include "core/timespec.h"
+#include <dnsjit/core/object.h>
+#include <dnsjit/core/timespec.h>
#ifndef __dnsjit_core_object_null_h
#define __dnsjit_core_object_null_h
#include <stddef.h>
-#include "core/object/null.hh"
+#include <dnsjit/core/object/null.hh>
#define CORE_OBJECT_NULL_INIT(prev) \
{ \
diff --git a/src/core/object/payload.h b/src/core/object/payload.h
index 4b42a7c..07391aa 100644
--- a/src/core/object/payload.h
+++ b/src/core/object/payload.h
@@ -18,15 +18,15 @@
* along with dnsjit. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "core/object.h"
-#include "core/timespec.h"
+#include <dnsjit/core/object.h>
+#include <dnsjit/core/timespec.h>
#ifndef __dnsjit_core_object_payload_h
#define __dnsjit_core_object_payload_h
#include <stddef.h>
-#include "core/object/payload.hh"
+#include <dnsjit/core/object/payload.hh>
#define CORE_OBJECT_PAYLOAD_INIT(prev) \
{ \
diff --git a/src/core/object/pcap.h b/src/core/object/pcap.h
index 093549b..afcccf3 100644
--- a/src/core/object/pcap.h
+++ b/src/core/object/pcap.h
@@ -18,13 +18,13 @@
* along with dnsjit. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "core/object.h"
-#include "core/timespec.h"
+#include <dnsjit/core/object.h>
+#include <dnsjit/core/timespec.h>
#ifndef __dnsjit_core_object_pcap_h
#define __dnsjit_core_object_pcap_h
-#include "core/object/pcap.hh"
+#include <dnsjit/core/object/pcap.hh>
#define CORE_OBJECT_PCAP_INIT(prev) \
{ \
diff --git a/src/core/object/tcp.h b/src/core/object/tcp.h
index e62ad42..e851a8a 100644
--- a/src/core/object/tcp.h
+++ b/src/core/object/tcp.h
@@ -18,15 +18,15 @@
* along with dnsjit. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "core/object.h"
-#include "core/timespec.h"
+#include <dnsjit/core/object.h>
+#include <dnsjit/core/timespec.h>
#ifndef __dnsjit_core_object_tcp_h
#define __dnsjit_core_object_tcp_h
#include <stddef.h>
-#include "core/object/tcp.hh"
+#include <dnsjit/core/object/tcp.hh>
#define CORE_OBJECT_TCP_INIT(prev) \
{ \
diff --git a/src/core/object/udp.h b/src/core/object/udp.h
index 147e80b..e85208b 100644
--- a/src/core/object/udp.h
+++ b/src/core/object/udp.h
@@ -18,15 +18,15 @@
* along with dnsjit. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "core/object.h"
-#include "core/timespec.h"
+#include <dnsjit/core/object.h>
+#include <dnsjit/core/timespec.h>
#ifndef __dnsjit_core_object_udp_h
#define __dnsjit_core_object_udp_h
#include <stddef.h>
-#include "core/object/udp.hh"
+#include <dnsjit/core/object/udp.hh>
#define CORE_OBJECT_UDP_INIT(prev) \
{ \
diff --git a/src/core/producer.h b/src/core/producer.h
index e78d48b..da63c17 100644
--- a/src/core/producer.h
+++ b/src/core/producer.h
@@ -18,11 +18,11 @@
* along with dnsjit. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "core/object.h"
+#include <dnsjit/core/object.h>
#ifndef __dnsjit_core_producer_h
#define __dnsjit_core_producer_h
-#include "core/producer.hh"
+#include <dnsjit/core/producer.hh>
#endif
diff --git a/src/core/receiver.h b/src/core/receiver.h
index f592c0c..5530b6a 100644
--- a/src/core/receiver.h
+++ b/src/core/receiver.h
@@ -18,11 +18,11 @@
* along with dnsjit. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "core/object.h"
+#include <dnsjit/core/object.h>
#ifndef __dnsjit_core_receiver_h
#define __dnsjit_core_receiver_h
-#include "core/receiver.hh"
+#include <dnsjit/core/receiver.hh>
#endif
diff --git a/src/core/thread.h b/src/core/thread.h
index fc047d4..6b7ede6 100644
--- a/src/core/thread.h
+++ b/src/core/thread.h
@@ -18,7 +18,7 @@
* along with dnsjit. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "core/log.h"
+#include <dnsjit/core/log.h>
#ifndef __dnsjit_core_thread_h
#define __dnsjit_core_thread_h
@@ -26,6 +26,6 @@
#include <pthread.h>
#include <unistd.h>
-#include "core/thread.hh"
+#include <dnsjit/core/thread.hh>
#endif
diff --git a/src/core/timespec.h b/src/core/timespec.h
index e0aefce..2110c6d 100644
--- a/src/core/timespec.h
+++ b/src/core/timespec.h
@@ -23,7 +23,7 @@
#include <stdint.h>
-#include "core/timespec.hh"
+#include <dnsjit/core/timespec.hh>
#define CORE_TIMESPEC_INIT \
{ \
diff --git a/src/core/timespec.lua b/src/core/timespec.lua
index 0db4dd3..05c600f 100644
--- a/src/core/timespec.lua
+++ b/src/core/timespec.lua
@@ -19,14 +19,36 @@
-- dnsjit.core.receiver
-- Non-system depended time specification structure definition
-- typedef struct core_timespec {
--- uint64_t sec;
--- uint64_t nsec;
+-- int64_t sec;
+-- int64_t nsec;
-- } core_timespec_t;
-- .SS C
-- #include "core/timespec.h"
-- .SS Lua
-- require("dnsjit.core.timespec_h")
+-- .SS Lua functions
+-- local ts = require("dnsjit.core.timespec"):max_init()
--
-- Mainly used in C modules for a system independent time specification
-- structure that can be passed to Lua.
module(...,package.seeall)
+
+require("dnsjit.core.timespec_h")
+
+local ffi = require("ffi")
+
+local Timespec = {}
+
+-- Return a new structure with both
+-- .I sec
+-- and
+-- .I nsec
+-- set to 2LL ^ 62, the maximum positive values according to Lua.
+function Timespec:max_init()
+ local ts = ffi.new("core_timespec_t")
+ ts.sec = 2LL ^ 62
+ ts.nsec = 2LL ^ 62
+ return ts
+end
+
+return Timespec