diff --git a/README.md b/README.md index 75e3063..2d40876 100644 --- a/README.md +++ b/README.md @@ -191,13 +191,19 @@ forward match) info *-a-*. In the list, DNS issues are presented like so: # DNS is good 0 Dec 04 11:04 185.31.204.22 1/0 offenses GB [BLK] mail.damianbasel.audise.com -# Reverse lookup does not match forward lookup +# Reverse lookup failed with DNS server +0 Dec 05 14:14 120.230.127.69 1/0 offenses CN [BLK] SERVFAIL + +# Reverse lookup is a non-existent domain +0 Dec 05 13:14 103.95.9.208 1/0 offenses ID [BLK] NXDOMAIN + +# Forward lookup does not match reverse lookup 0 Dec 04 08:47 103.238.80.23 2/0 offenses VN [BLK] example.com ! -# Forward DNS is unavailable +# Forward DNS record does not exist 4 Dec 04 10:54 106.51.230.190 2/0 offenses IN [BLK] broadband.actcorp.in !! -# DNS is inconclusive due to lack of response from DNS servers +# DNS is inconclusive due to lack of response from a DNS server 0 Dec 04 04:13 87.120.246.53 1/0 offenses BG [BLK] client.playtime.bg ~ ``` diff --git a/es.c b/es.c index 0cae792..3b89732 100644 --- a/es.c +++ b/es.c @@ -7,9 +7,9 @@ #include #include "util.h" -#include "map.h" #include "msgqueue.h" #include "ez_es.h" +#include "map.h" #include "ez_libpthread.h" /* Types of registered callbacks */ @@ -95,7 +95,7 @@ static _Thread_local struct _TS { struct { /* virtual signal message queue */ MSGQUEUE mq; - MAP map; + MAP cb_map; } vsig; } TS; @@ -294,22 +294,34 @@ sigusr2_h(void *ctxt, int unused) * Handle any vsignals. */ { - int vsigno; + int rtn= 0, + vsigno; + Cb *cb_arr[VSIG_QUEUE_MAX]; + /* Protected operation */ +// ez_pthread_mutex_lock(&S.vsig.mtx); + while(EOF != MSGQUEUE_extractMsg(&TS.vsig.mq, &vsigno)) { - int rc= MAP_findItems(&TS.vsig.map, (void**)cb_arr, VSIG_QUEUE_MAX, &vsigno, sizeof(int)); - assert(-1 != rc); - if(!rc) continue; + int rc= MAP_findItems(&TS.vsig.cb_map, (void**)cb_arr, VSIG_QUEUE_MAX, &vsigno, sizeof(int)); + if(-1 == rc) { + eprintf("FATAL: MAP_findItems() failed"); + abort(); + } + + if(!rc) goto abort; for(int i= 0; i < rc; ++i) { Cb *cb= cb_arr[i]; - int error= (* cb->un.sig.callback_f)(cb->ctxt, vsigno); - if(error) return error; + rtn= (* cb->un.sig.callback_f)(cb->ctxt, vsigno); + if(rtn) goto abort; } } - return 0; + +abort: +// ez_pthread_mutex_unlock(&S.vsig.mtx); + return rtn; } static void @@ -350,7 +362,7 @@ initialize() /*--- virtual signal infrastructure ---*/ MSGQUEUE_constructor(&TS.vsig.mq, sizeof(int), VSIG_QUEUE_MAX); - MAP_constructor(&TS.vsig.map, 10, 10); + MAP_constructor(&TS.vsig.cb_map, 10, 10); /* Register a signal handler for SIGUSR2 so we can have virtual signals. */ ez_ES_registerSignal(SIGUSR2, sigusr2_h, NULL); ez_pthread_mutex_unlock(&S.vsig.mtx); @@ -446,7 +458,7 @@ ES_registerVSignal ( if(!Cb_VSignalCreate(cb, signum, callback_f, ctxt)) assert(0); /* Place in the virtual signal map indexed on signum */ - MAP_addTypedKey(&TS.vsig.map, cb->un.sig.signum, cb); + MAP_addTypedKey(&TS.vsig.cb_map, cb->un.sig.signum, cb); /* All callbacks are put in the key table */ MAP_addTypedKey(&TS.key_map, cb->key, cb); @@ -512,7 +524,6 @@ ES_unregister (int key) { if(TS.tid != pthread_self()) initialize(); -// unsigned i; Cb *cb = MAP_findTypedItem(&TS.key_map, key); if(!cb) return -1; @@ -545,7 +556,7 @@ ES_unregister (int key) } break; case ES_VSIG_TYPE: - if(!MAP_removeSpecificTypedItem(&TS.vsig.map, cb->un.sig.signum, cb)) assert(0); + if(!MAP_removeSpecificTypedItem(&TS.vsig.cb_map, cb->un.sig.signum, cb)) assert(0); break; case ES_TIMER_TYPE: @@ -908,30 +919,18 @@ ES_cleanup(void) /* Remove ourself from the vsig thread to TS map */ ez_pthread_mutex_lock(&S.vsig.mtx); MAP_removeTypedItem(&S.vsig.thrd_ts_map, TS.tid); + ez_pthread_mutex_unlock(&S.vsig.mtx); - { /* Destroy key map */ - unsigned len= MAP_numItems(&TS.key_map); - Cb *cbArr[len]; - MAP_fetchAllItems(&TS.key_map, (void**)cbArr); - for(unsigned i= 0; i < len; ++i) { - Cb_destroy(cbArr[i]); - } + /* Destroy all callbacks, which are indexed in key map, + * and the key map itself. + */ + MAP_clearAndDestroy(&TS.key_map, (void*(*)(void*))Cb_destructor); - MAP_destructor(&TS.key_map); - } + /* Destroy vsignal infrastructure */ + MAP_destructor(&TS.vsig.cb_map); - { /* Destroy vsignal infrastructure */ - unsigned len= MAP_numItems(&TS.vsig.map); - Cb *cbArr[len]; - MAP_fetchAllItems(&TS.vsig.map, (void**)cbArr); - for(unsigned i= 0; i < len; ++i) { - Cb_destroy(cbArr[i]); - } - MAP_destructor(&TS.vsig.map); - - /* Tear down the message queue */ - MSGQUEUE_destructor(&TS.vsig.mq); - } + /* Tear down the message queue */ + MSGQUEUE_destructor(&TS.vsig.mq); PTRVEC_destructor(&TS.fd_vec); PTRVEC_destructor(&TS.timer_vec); @@ -939,7 +938,6 @@ ES_cleanup(void) for(unsigned i= 0; i < NUMSIGS; ++i) { PTRVEC_destructor(TS.sig_vec_arr+i); } - ez_pthread_mutex_unlock(&S.vsig.mtx); } int diff --git a/pdns.c b/pdns.c index f62d0d2..7a9f7bf 100644 --- a/pdns.c +++ b/pdns.c @@ -371,7 +371,7 @@ eprintf("thread %u exiting at %f seconds", ndx, (double)ms/1000.); /* Free resources for this thread */ // JDR Wed 04 Dec 2019 11:52:15 AM EST // This causes a double free() error, so let it leak for now. -// ES_cleanup(); + ES_cleanup(); return NULL; }