Skip to content

Commit

Permalink
Merge pull request DNS-OARC#82 from jelu/badbits
Browse files Browse the repository at this point in the history
Channel, structures
  • Loading branch information
jelu authored Jun 26, 2018
2 parents 9868424 + 03ff97e commit 2f560bc
Show file tree
Hide file tree
Showing 12 changed files with 84 additions and 82 deletions.
1 change: 0 additions & 1 deletion src/core/channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 3 additions & 1 deletion src/core/channel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/core/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include <stdlib.h>
#include <errno.h>
#include <stdint.h>

#define LOG_SETTINGS_T_INIT \
{ \
Expand Down
12 changes: 6 additions & 6 deletions src/core/log.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
92 changes: 46 additions & 46 deletions src/core/object/dns.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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();
Expand Down
10 changes: 5 additions & 5 deletions src/core/object/ieee802.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
20 changes: 10 additions & 10 deletions src/core/object/ip.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions src/core/object/ip6.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/core/object/pcap.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/input/fpcap.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions src/input/mmpcap.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/input/pcap.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 2f560bc

Please sign in to comment.