summaryrefslogtreecommitdiff
path: root/services/mesh.c
diff options
context:
space:
mode:
Diffstat (limited to 'services/mesh.c')
-rw-r--r--services/mesh.c107
1 files changed, 67 insertions, 40 deletions
diff --git a/services/mesh.c b/services/mesh.c
index 9114ef4c4e2d7..4b0c5db418f75 100644
--- a/services/mesh.c
+++ b/services/mesh.c
@@ -159,16 +159,28 @@ client_info_compare(const struct respip_client_info* ci_a,
return 1;
if(ci_a->taglen != ci_b->taglen)
return (ci_a->taglen < ci_b->taglen) ? -1 : 1;
- cmp = memcmp(ci_a->taglist, ci_b->taglist, ci_a->taglen);
- if(cmp != 0)
- return cmp;
+ if(ci_a->taglist && !ci_b->taglist)
+ return -1;
+ if(!ci_a->taglist && ci_b->taglist)
+ return 1;
+ if(ci_a->taglist && ci_b->taglist) {
+ cmp = memcmp(ci_a->taglist, ci_b->taglist, ci_a->taglen);
+ if(cmp != 0)
+ return cmp;
+ }
if(ci_a->tag_actions_size != ci_b->tag_actions_size)
return (ci_a->tag_actions_size < ci_b->tag_actions_size) ?
-1 : 1;
- cmp = memcmp(ci_a->tag_actions, ci_b->tag_actions,
- ci_a->tag_actions_size);
- if(cmp != 0)
- return cmp;
+ if(ci_a->tag_actions && !ci_b->tag_actions)
+ return -1;
+ if(!ci_a->tag_actions && ci_b->tag_actions)
+ return 1;
+ if(ci_a->tag_actions && ci_b->tag_actions) {
+ cmp = memcmp(ci_a->tag_actions, ci_b->tag_actions,
+ ci_a->tag_actions_size);
+ if(cmp != 0)
+ return cmp;
+ }
if(ci_a->tag_datas != ci_b->tag_datas)
return ci_a->tag_datas < ci_b->tag_datas ? -1 : 1;
if(ci_a->view != ci_b->view)
@@ -1284,7 +1296,7 @@ mesh_send_reply(struct mesh_state* m, int rcode, struct reply_info* rep,
void mesh_query_done(struct mesh_state* mstate)
{
- struct mesh_reply* r, *reply_list = NULL;
+ struct mesh_reply* r;
struct mesh_reply* prev = NULL;
struct sldns_buffer* prev_buffer = NULL;
struct mesh_cb* c;
@@ -1308,27 +1320,7 @@ void mesh_query_done(struct mesh_state* mstate)
free(err);
}
}
- if(mstate->reply_list) {
- /* set the reply_list to NULL during the mesh_query_done
- * processing, so that calls back into the mesh from
- * tcp_req_info (deciding to drop the reply and thus
- * unregister the mesh_reply from the mstate) are stopped
- * because the list is empty.
- * The mstate is then likely not a reply_state, and maybe
- * also a detached_state.
- */
- reply_list = mstate->reply_list;
- mstate->reply_list = NULL;
- if(!mstate->reply_list && !mstate->cb_list) {
- /* was a reply state, not anymore */
- log_assert(mstate->s.env->mesh->num_reply_states > 0);
- mstate->s.env->mesh->num_reply_states--;
- }
- if(!mstate->reply_list && !mstate->cb_list &&
- mstate->super_set.count == 0)
- mstate->s.env->mesh->num_detached_states++;
- }
- for(r = reply_list; r; r = r->next) {
+ for(r = mstate->reply_list; r; r = r->next) {
/* if a response-ip address block has been stored the
* information should be logged for each client. */
if(mstate->s.respip_action_info &&
@@ -1352,15 +1344,31 @@ void mesh_query_done(struct mesh_state* mstate)
/* if this query is determined to be dropped during the
* mesh processing, this is the point to take that action. */
if(mstate->s.is_drop) {
+ /* briefly set the reply_list to NULL, so that the
+ * tcp req info cleanup routine that calls the mesh
+ * to deregister the meshstate for it is not done
+ * because the list is NULL and also accounting is not
+ * done there, but instead we do that here. */
+ struct mesh_reply* reply_list = mstate->reply_list;
+ mstate->reply_list = NULL;
comm_point_drop_reply(&r->query_reply);
+ mstate->reply_list = reply_list;
} else {
struct sldns_buffer* r_buffer = r->query_reply.c->buffer;
+ struct mesh_reply* rlist = mstate->reply_list;
if(r->query_reply.c->tcp_req_info) {
r_buffer = r->query_reply.c->tcp_req_info->spool_buffer;
prev_buffer = NULL;
}
+ /* briefly set the replylist to null in case the
+ * meshsendreply calls tcpreqinfo sendreply that
+ * comm_point_drops because of size, and then the
+ * null stops the mesh state remove and thus
+ * reply_list modification and accounting */
+ mstate->reply_list = NULL;
mesh_send_reply(mstate, mstate->s.return_rcode, rep,
r, r_buffer, prev, prev_buffer);
+ mstate->reply_list = rlist;
if(r->query_reply.c->tcp_req_info) {
tcp_req_info_remove_mesh_state(r->query_reply.c->tcp_req_info, mstate);
r_buffer = NULL;
@@ -1369,6 +1377,17 @@ void mesh_query_done(struct mesh_state* mstate)
prev_buffer = r_buffer;
}
}
+ if(mstate->reply_list) {
+ mstate->reply_list = NULL;
+ if(!mstate->reply_list && !mstate->cb_list) {
+ /* was a reply state, not anymore */
+ log_assert(mstate->s.env->mesh->num_reply_states > 0);
+ mstate->s.env->mesh->num_reply_states--;
+ }
+ if(!mstate->reply_list && !mstate->cb_list &&
+ mstate->super_set.count == 0)
+ mstate->s.env->mesh->num_detached_states++;
+ }
mstate->replies_sent = 1;
while((c = mstate->cb_list) != NULL) {
/* take this cb off the list; so that the list can be
@@ -1863,7 +1882,7 @@ mesh_serve_expired_callback(void* arg)
{
struct mesh_state* mstate = (struct mesh_state*) arg;
struct module_qstate* qstate = &mstate->s;
- struct mesh_reply* r;
+ struct mesh_reply* r, *rlist;
struct mesh_area* mesh = qstate->env->mesh;
struct dns_msg* msg;
struct mesh_cb* c;
@@ -1946,16 +1965,7 @@ mesh_serve_expired_callback(void* arg)
if(verbosity >= VERB_ALGO)
log_dns_msg("Serve expired lookup", &qstate->qinfo, msg->rep);
- r = mstate->reply_list;
- mstate->reply_list = NULL;
- if(!mstate->reply_list && !mstate->cb_list) {
- log_assert(mesh->num_reply_states > 0);
- mesh->num_reply_states--;
- if(mstate->super_set.count == 0) {
- mesh->num_detached_states++;
- }
- }
- for(; r; r = r->next) {
+ for(r = mstate->reply_list; r; r = r->next) {
/* If address info is returned, it means the action should be an
* 'inform' variant and the information should be logged. */
if(actinfo.addrinfo) {
@@ -1977,8 +1987,15 @@ mesh_serve_expired_callback(void* arg)
r_buffer = r->query_reply.c->buffer;
if(r->query_reply.c->tcp_req_info)
r_buffer = r->query_reply.c->tcp_req_info->spool_buffer;
+ /* briefly set the replylist to null in case the meshsendreply
+ * calls tcpreqinfo sendreply that comm_point_drops because
+ * of size, and then the null stops the mesh state remove and
+ * thus reply_list modification and accounting */
+ rlist = mstate->reply_list;
+ mstate->reply_list = NULL;
mesh_send_reply(mstate, LDNS_RCODE_NOERROR, msg->rep,
r, r_buffer, prev, prev_buffer);
+ mstate->reply_list = rlist;
if(r->query_reply.c->tcp_req_info)
tcp_req_info_remove_mesh_state(r->query_reply.c->tcp_req_info, mstate);
prev = r;
@@ -1988,6 +2005,16 @@ mesh_serve_expired_callback(void* arg)
mesh->ans_expired++;
}
+ if(mstate->reply_list) {
+ mstate->reply_list = NULL;
+ if(!mstate->reply_list && !mstate->cb_list) {
+ log_assert(mesh->num_reply_states > 0);
+ mesh->num_reply_states--;
+ if(mstate->super_set.count == 0) {
+ mesh->num_detached_states++;
+ }
+ }
+ }
while((c = mstate->cb_list) != NULL) {
/* take this cb off the list; so that the list can be
* changed, eg. by adds from the callback routine */