From a68848db159cc1cafa82f9d383432fda459c8745 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 17 Jul 2021 09:11:16 +0200 Subject: Merging upstream version 1.2.1. Signed-off-by: Daniel Baumann --- src/core/assert.h | 2 +- src/core/channel.h | 6 ++-- src/core/file.c | 37 +++++++++++++++++++++++++ src/core/file.h | 26 ++++++++++++++++++ src/core/file.hh | 21 ++++++++++++++ src/core/file.lua | 37 +++++++++++++++++++++++++ src/core/loader.lua | 68 ++++++++++++++++++++++++++++++++++++++++++++++ src/core/log.h | 2 +- src/core/object.h | 2 +- src/core/object/dns.h | 6 ++-- src/core/object/ether.h | 6 ++-- src/core/object/gre.h | 6 ++-- src/core/object/icmp.h | 6 ++-- src/core/object/icmp6.h | 6 ++-- src/core/object/ieee802.h | 6 ++-- src/core/object/ip.h | 6 ++-- src/core/object/ip6.h | 6 ++-- src/core/object/linuxsll.h | 6 ++-- src/core/object/loop.h | 6 ++-- src/core/object/null.h | 6 ++-- src/core/object/payload.h | 6 ++-- src/core/object/pcap.h | 6 ++-- src/core/object/tcp.h | 6 ++-- src/core/object/udp.h | 6 ++-- src/core/producer.h | 4 +-- src/core/receiver.h | 4 +-- src/core/thread.h | 4 +-- src/core/timespec.h | 2 +- src/core/timespec.lua | 26 ++++++++++++++++-- 29 files changed, 271 insertions(+), 60 deletions(-) create mode 100644 src/core/file.c create mode 100644 src/core/file.h create mode 100644 src/core/file.hh create mode 100644 src/core/file.lua create mode 100644 src/core/loader.lua (limited to 'src/core') 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 #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 . */ -#include "core/log.h" -#include "core/receiver.h" +#include +#include #ifndef __dnsjit_core_channel_h #define __dnsjit_core_channel_h @@ -36,6 +36,6 @@ #include #include -#include "core/channel.hh" +#include #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 . + */ + +#include "config.h" + +#include "core/file.h" + +#include +#include +#include + +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 . + */ + +#ifndef __dnsjit_core_file_h +#define __dnsjit_core_file_h + +#include + +#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 . + */ + +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 . + +-- 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 . + +-- 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 #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 -#include "core/object.hh" +#include #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 . */ -#include "core/log.h" -#include "core/object.h" +#include +#include #ifndef __dnsjit_core_object_dns_h #define __dnsjit_core_object_dns_h @@ -27,7 +27,7 @@ #include #include -#include "core/object/dns.hh" +#include #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 . */ -#include "core/object.h" -#include "core/timespec.h" +#include +#include #ifndef __dnsjit_core_object_ether_h #define __dnsjit_core_object_ether_h #include -#include "core/object/ether.hh" +#include #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 . */ -#include "core/object.h" -#include "core/timespec.h" +#include +#include #ifndef __dnsjit_core_object_gre_h #define __dnsjit_core_object_gre_h #include -#include "core/object/gre.hh" +#include #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 . */ -#include "core/object.h" -#include "core/timespec.h" +#include +#include #ifndef __dnsjit_core_object_icmp_h #define __dnsjit_core_object_icmp_h #include -#include "core/object/icmp.hh" +#include #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 . */ -#include "core/object.h" -#include "core/timespec.h" +#include +#include #ifndef __dnsjit_core_object_icmp6_h #define __dnsjit_core_object_icmp6_h #include -#include "core/object/icmp6.hh" +#include #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 . */ -#include "core/object.h" -#include "core/timespec.h" +#include +#include #ifndef __dnsjit_core_object_ieee802_h #define __dnsjit_core_object_ieee802_h #include -#include "core/object/ieee802.hh" +#include #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 . */ -#include "core/object.h" -#include "core/timespec.h" +#include +#include #ifndef __dnsjit_core_object_ip_h #define __dnsjit_core_object_ip_h #include -#include "core/object/ip.hh" +#include #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 . */ -#include "core/object.h" -#include "core/timespec.h" +#include +#include #ifndef __dnsjit_core_object_ip6_h #define __dnsjit_core_object_ip6_h #include -#include "core/object/ip6.hh" +#include #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 . */ -#include "core/object.h" -#include "core/timespec.h" +#include +#include #ifndef __dnsjit_core_object_linuxsll_h #define __dnsjit_core_object_linuxsll_h #include -#include "core/object/linuxsll.hh" +#include #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 . */ -#include "core/object.h" -#include "core/timespec.h" +#include +#include #ifndef __dnsjit_core_object_loop_h #define __dnsjit_core_object_loop_h #include -#include "core/object/loop.hh" +#include #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 . */ -#include "core/object.h" -#include "core/timespec.h" +#include +#include #ifndef __dnsjit_core_object_null_h #define __dnsjit_core_object_null_h #include -#include "core/object/null.hh" +#include #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 . */ -#include "core/object.h" -#include "core/timespec.h" +#include +#include #ifndef __dnsjit_core_object_payload_h #define __dnsjit_core_object_payload_h #include -#include "core/object/payload.hh" +#include #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 . */ -#include "core/object.h" -#include "core/timespec.h" +#include +#include #ifndef __dnsjit_core_object_pcap_h #define __dnsjit_core_object_pcap_h -#include "core/object/pcap.hh" +#include #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 . */ -#include "core/object.h" -#include "core/timespec.h" +#include +#include #ifndef __dnsjit_core_object_tcp_h #define __dnsjit_core_object_tcp_h #include -#include "core/object/tcp.hh" +#include #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 . */ -#include "core/object.h" -#include "core/timespec.h" +#include +#include #ifndef __dnsjit_core_object_udp_h #define __dnsjit_core_object_udp_h #include -#include "core/object/udp.hh" +#include #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 . */ -#include "core/object.h" +#include #ifndef __dnsjit_core_producer_h #define __dnsjit_core_producer_h -#include "core/producer.hh" +#include #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 . */ -#include "core/object.h" +#include #ifndef __dnsjit_core_receiver_h #define __dnsjit_core_receiver_h -#include "core/receiver.hh" +#include #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 . */ -#include "core/log.h" +#include #ifndef __dnsjit_core_thread_h #define __dnsjit_core_thread_h @@ -26,6 +26,6 @@ #include #include -#include "core/thread.hh" +#include #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 -#include "core/timespec.hh" +#include #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 -- cgit v1.2.3