From 03ff97e1a0e60fcee696b815e51c41c77132c3eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jerry=20Lundstr=C3=B6m?= Date: Tue, 26 Jun 2018 15:33:37 +0200 Subject: [PATCH] Channel, structures - `core.channel`: Allow sending `nil` - Remove bit fields, not yet handled by the JIT compiler --- src/core/channel.c | 1 - src/core/channel.lua | 4 +- src/core/log.h | 1 + src/core/log.hh | 12 ++--- src/core/object/dns.hh | 92 +++++++++++++++++++------------------- src/core/object/ieee802.hh | 10 ++--- src/core/object/ip.hh | 20 ++++----- src/core/object/ip6.hh | 10 ++--- src/core/object/pcap.hh | 2 +- src/input/fpcap.hh | 6 +-- src/input/mmpcap.hh | 6 +-- src/input/pcap.hh | 2 +- 12 files changed, 84 insertions(+), 82 deletions(-) diff --git a/src/core/channel.c b/src/core/channel.c index c574b65c..4fe5a141 100644 --- a/src/core/channel.c +++ b/src/core/channel.c @@ -60,7 +60,6 @@ void core_channel_put(core_channel_t* self, const void* obj) { mlassert_self(); lassert(self->ring_buf, "ring_buf is nil"); - lassert(obj, "obj is nil"); while (!ck_ring_enqueue_spsc(&self->ring, self->ring_buf, (void*)obj)) { sched_yield(); diff --git a/src/core/channel.lua b/src/core/channel.lua index 16a10d21..2d354265 100644 --- a/src/core/channel.lua +++ b/src/core/channel.lua @@ -79,13 +79,15 @@ end -- Put an object into the channel, if the channel is full then it will -- stall and wait until space becomes available. +-- Object may be nil. function Channel:put(obj) C.core_channel_put(self, obj) end -- Get an object from the channel, if the channel is empty it will wait until -- an object is available. --- Returns nil if the channel is closed. +-- Returns nil if the channel is closed or if a nil object was explicitly put +-- into the channel. function Channel:get() return C.core_channel_get(self) end diff --git a/src/core/log.h b/src/core/log.h index 6b68e549..73164a64 100644 --- a/src/core/log.h +++ b/src/core/log.h @@ -23,6 +23,7 @@ #include #include +#include #define LOG_SETTINGS_T_INIT \ { \ diff --git a/src/core/log.hh b/src/core/log.hh index 6e30a73b..9a007e96 100644 --- a/src/core/log.hh +++ b/src/core/log.hh @@ -19,16 +19,16 @@ */ typedef struct core_log_settings { - unsigned short debug : 2; - unsigned short info : 2; - unsigned short notice : 2; - unsigned short warning : 2; - unsigned short display_file_line : 2; + uint8_t debug; + uint8_t info; + uint8_t notice; + uint8_t warning; + uint8_t display_file_line; } core_log_settings_t; typedef struct core_log { const char* name; - unsigned short is_obj : 1; + uint8_t is_obj; core_log_settings_t settings; const core_log_settings_t* module; } core_log_t; diff --git a/src/core/object/dns.hh b/src/core/object/dns.hh index ed8e537c..b16a9b38 100644 --- a/src/core/object/dns.hh +++ b/src/core/object/dns.hh @@ -22,25 +22,25 @@ //lua:require("dnsjit.core.object_h") typedef struct core_object_dns_label { - unsigned short is_end : 1; - unsigned short have_length : 1; - unsigned short have_offset : 1; - unsigned short have_extension_bits : 1; - unsigned short have_dn : 1; - unsigned short extension_bits : 2; + uint8_t is_end; + uint8_t have_length; + uint8_t have_offset; + uint8_t have_extension_bits; + uint8_t have_dn; + uint8_t extension_bits; uint8_t length; uint16_t offset; } core_object_dns_label_t; typedef struct core_object_dns_rr { - unsigned short have_type : 1; - unsigned short have_class : 1; - unsigned short have_ttl : 1; - unsigned short have_rdlength : 1; - unsigned short have_rdata : 1; - unsigned short have_rdata_labels : 1; - unsigned short have_padding : 1; + uint8_t have_type; + uint8_t have_class; + uint8_t have_ttl; + uint8_t have_rdlength; + uint8_t have_rdata; + uint8_t have_rdata_labels; + uint8_t have_padding; uint16_t type; uint16_t class; @@ -55,8 +55,8 @@ typedef struct core_object_dns_rr { } core_object_dns_rr_t; typedef struct core_object_dns_q { - unsigned short have_type : 1; - unsigned short have_class : 1; + uint8_t have_type; + uint8_t have_class; uint16_t type; uint16_t class; @@ -71,37 +71,37 @@ typedef struct core_object_dns { const uint8_t *payload, *at; size_t len, left; - unsigned short have_id : 1; - unsigned short have_qr : 1; - unsigned short have_opcode : 1; - unsigned short have_aa : 1; - unsigned short have_tc : 1; - unsigned short have_rd : 1; - unsigned short have_ra : 1; - unsigned short have_z : 1; - unsigned short have_ad : 1; - unsigned short have_cd : 1; - unsigned short have_rcode : 1; - unsigned short have_qdcount : 1; - unsigned short have_ancount : 1; - unsigned short have_nscount : 1; - unsigned short have_arcount : 1; - - uint16_t id; - unsigned short qr : 1; - unsigned short opcode : 4; - unsigned short aa : 1; - unsigned short tc : 1; - unsigned short rd : 1; - unsigned short ra : 1; - unsigned short z : 1; - unsigned short ad : 1; - unsigned short cd : 1; - unsigned short rcode : 4; - uint16_t qdcount; - uint16_t ancount; - uint16_t nscount; - uint16_t arcount; + uint8_t have_id; + uint8_t have_qr; + uint8_t have_opcode; + uint8_t have_aa; + uint8_t have_tc; + uint8_t have_rd; + uint8_t have_ra; + uint8_t have_z; + uint8_t have_ad; + uint8_t have_cd; + uint8_t have_rcode; + uint8_t have_qdcount; + uint8_t have_ancount; + uint8_t have_nscount; + uint8_t have_arcount; + + uint16_t id; + int8_t qr; + uint8_t opcode; + uint8_t aa; + uint8_t tc; + uint8_t rd; + uint8_t ra; + uint8_t z; + uint8_t ad; + uint8_t cd; + uint8_t rcode; + uint16_t qdcount; + uint16_t ancount; + uint16_t nscount; + uint16_t arcount; } core_object_dns_t; core_log_t* core_object_dns_log(); diff --git a/src/core/object/ieee802.hh b/src/core/object/ieee802.hh index 28d6564b..763aa477 100644 --- a/src/core/object/ieee802.hh +++ b/src/core/object/ieee802.hh @@ -24,11 +24,11 @@ typedef struct core_object_ieee802 { const core_object_t* obj_prev; int32_t obj_type; - uint16_t tpid; - unsigned short pcp : 3; - unsigned short dei : 1; - unsigned short vid : 12; - uint16_t ether_type; + uint16_t tpid; + uint8_t pcp; + uint8_t dei; + uint8_t vid; + uint16_t ether_type; } core_object_ieee802_t; core_object_ieee802_t* core_object_ieee802_copy(const core_object_ieee802_t* self); diff --git a/src/core/object/ip.hh b/src/core/object/ip.hh index 64f537c4..a8d5ff4e 100644 --- a/src/core/object/ip.hh +++ b/src/core/object/ip.hh @@ -24,16 +24,16 @@ typedef struct core_object_ip { const core_object_t* obj_prev; int32_t obj_type; - unsigned int v : 4; - unsigned int hl : 4; - uint8_t tos; - uint16_t len; - uint16_t id; - uint16_t off; - uint8_t ttl; - uint8_t p; - uint16_t sum; - uint8_t src[4], dst[4]; + uint8_t v; + uint8_t hl; + uint8_t tos; + uint16_t len; + uint16_t id; + uint16_t off; + uint8_t ttl; + uint8_t p; + uint16_t sum; + uint8_t src[4], dst[4]; } core_object_ip_t; core_object_ip_t* core_object_ip_copy(const core_object_ip_t* self); diff --git a/src/core/object/ip6.hh b/src/core/object/ip6.hh index 7ef224f6..e388597a 100644 --- a/src/core/object/ip6.hh +++ b/src/core/object/ip6.hh @@ -31,11 +31,11 @@ typedef struct core_object_ip6 { uint8_t src[16]; uint8_t dst[16]; - unsigned short is_frag : 1; - unsigned short have_rtdst : 1; - uint16_t frag_offlg; - uint16_t frag_ident; - uint8_t rtdst[16]; + uint8_t is_frag; + uint8_t have_rtdst; + uint16_t frag_offlg; + uint16_t frag_ident; + uint8_t rtdst[16]; } core_object_ip6_t; core_object_ip6_t* core_object_ip6_copy(const core_object_ip6_t* self); diff --git a/src/core/object/pcap.hh b/src/core/object/pcap.hh index 27669fbf..c887da09 100644 --- a/src/core/object/pcap.hh +++ b/src/core/object/pcap.hh @@ -31,7 +31,7 @@ typedef struct core_object_pcap { uint32_t caplen, len; const unsigned char* bytes; - unsigned short is_swapped : 1; + uint8_t is_swapped; } core_object_pcap_t; core_object_pcap_t* core_object_pcap_copy(const core_object_pcap_t* self); diff --git a/src/input/fpcap.hh b/src/input/fpcap.hh index 24de8418..bd4449d2 100644 --- a/src/input/fpcap.hh +++ b/src/input/fpcap.hh @@ -28,9 +28,9 @@ typedef struct input_fpcap { core_receiver_t recv; void* ctx; - unsigned short is_swapped : 1; - unsigned short is_nanosec : 1; - unsigned short is_broken : 1; + uint8_t is_swapped; + uint8_t is_nanosec; + uint8_t is_broken; core_object_pcap_t prod_pkt; diff --git a/src/input/mmpcap.hh b/src/input/mmpcap.hh index fc73c21e..8f66328e 100644 --- a/src/input/mmpcap.hh +++ b/src/input/mmpcap.hh @@ -28,9 +28,9 @@ typedef struct input_mmpcap { core_receiver_t recv; void* ctx; - unsigned short is_swapped : 1; - unsigned short is_nanosec : 1; - unsigned short is_broken : 1; + uint8_t is_swapped; + uint8_t is_nanosec; + uint8_t is_broken; core_object_pcap_t prod_pkt; diff --git a/src/input/pcap.hh b/src/input/pcap.hh index 9ef3a48b..7028f213 100644 --- a/src/input/pcap.hh +++ b/src/input/pcap.hh @@ -32,7 +32,7 @@ typedef struct input_pcap { core_receiver_t recv; void* ctx; - unsigned short is_swapped : 1; + uint8_t is_swapped; core_object_pcap_t prod_pkt;