subnetmod.c (938a3a5e) subnetmod.c (2308e98c)
1/*
2 * edns-subnet/subnetmod.c - edns subnet module. Must be called before validator
3 * and iterator.
4 *
5 * Copyright (c) 2013, NLnet Labs. All rights reserved.
6 *
7 * This software is open source.
8 *

--- 450 unchanged lines hidden (view full) ---

459
460 struct ecs_data *c_in = &sq->ecs_client_in; /* rcvd from client */
461 struct ecs_data *c_out = &sq->ecs_client_out;/* will send to client */
462 struct ecs_data *s_in = &sq->ecs_server_in; /* rcvd from auth */
463 struct ecs_data *s_out = &sq->ecs_server_out;/* sent to auth */
464
465 memset(c_out, 0, sizeof(*c_out));
466
1/*
2 * edns-subnet/subnetmod.c - edns subnet module. Must be called before validator
3 * and iterator.
4 *
5 * Copyright (c) 2013, NLnet Labs. All rights reserved.
6 *
7 * This software is open source.
8 *

--- 450 unchanged lines hidden (view full) ---

459
460 struct ecs_data *c_in = &sq->ecs_client_in; /* rcvd from client */
461 struct ecs_data *c_out = &sq->ecs_client_out;/* will send to client */
462 struct ecs_data *s_in = &sq->ecs_server_in; /* rcvd from auth */
463 struct ecs_data *s_out = &sq->ecs_server_out;/* sent to auth */
464
465 memset(c_out, 0, sizeof(*c_out));
466
467 if (!qstate->return_msg) return module_error;
467 if (!qstate->return_msg) {
468 /* already an answer and its not a message, but retain
469 * the actual rcode, instead of module_error, so send
470 * module_finished */
471 return module_finished;
472 }
468
469 /* We have not asked for subnet data */
470 if (!sq->subnet_sent) {
471 if (s_in->subnet_validdata)
472 verbose(VERB_QUERY, "subnet: received spurious data");
473 if (sq->subnet_downstream) /* Copy back to client */
474 cp_edns_bad_response(c_out, c_in);
475 return module_finished;

--- 30 unchanged lines hidden (view full) ---

506 (void)edns_opt_list_remove(&qstate->edns_opts_back_out,
507 qstate->env->cfg->client_subnet_opcode);
508 sq->subnet_sent = 0;
509 return module_restart_next;
510 }
511
512 lock_rw_wrlock(&sne->biglock);
513 update_cache(qstate, id);
473
474 /* We have not asked for subnet data */
475 if (!sq->subnet_sent) {
476 if (s_in->subnet_validdata)
477 verbose(VERB_QUERY, "subnet: received spurious data");
478 if (sq->subnet_downstream) /* Copy back to client */
479 cp_edns_bad_response(c_out, c_in);
480 return module_finished;

--- 30 unchanged lines hidden (view full) ---

511 (void)edns_opt_list_remove(&qstate->edns_opts_back_out,
512 qstate->env->cfg->client_subnet_opcode);
513 sq->subnet_sent = 0;
514 return module_restart_next;
515 }
516
517 lock_rw_wrlock(&sne->biglock);
518 update_cache(qstate, id);
519 sne->num_msg_nocache++;
514 lock_rw_unlock(&sne->biglock);
515
516 if (sq->subnet_downstream) {
517 /* Client wants to see the answer, echo option back
518 * and adjust the scope. */
519 c_out->subnet_addr_fam = c_in->subnet_addr_fam;
520 c_out->subnet_source_mask = c_in->subnet_source_mask;
521 memcpy(&c_out->subnet_addr, &c_in->subnet_addr, INET6_SIZE);

--- 166 unchanged lines hidden (view full) ---

688 sq->ecs_server_out.subnet_validdata = 0;
689 verbose(VERB_ALGO, "subnet: pass to next module");
690 qstate->ext_state[id] = module_wait_module;
691 return;
692 }
693
694 lock_rw_wrlock(&sne->biglock);
695 if (lookup_and_reply(qstate, id, sq)) {
520 lock_rw_unlock(&sne->biglock);
521
522 if (sq->subnet_downstream) {
523 /* Client wants to see the answer, echo option back
524 * and adjust the scope. */
525 c_out->subnet_addr_fam = c_in->subnet_addr_fam;
526 c_out->subnet_source_mask = c_in->subnet_source_mask;
527 memcpy(&c_out->subnet_addr, &c_in->subnet_addr, INET6_SIZE);

--- 166 unchanged lines hidden (view full) ---

694 sq->ecs_server_out.subnet_validdata = 0;
695 verbose(VERB_ALGO, "subnet: pass to next module");
696 qstate->ext_state[id] = module_wait_module;
697 return;
698 }
699
700 lock_rw_wrlock(&sne->biglock);
701 if (lookup_and_reply(qstate, id, sq)) {
702 sne->num_msg_cache++;
696 lock_rw_unlock(&sne->biglock);
697 verbose(VERB_QUERY, "subnet: answered from cache");
698 qstate->ext_state[id] = module_finished;
699
700 ecs_opt_list_append(&sq->ecs_client_out,
701 &qstate->edns_opts_front_out, qstate);
702 return;
703 }

--- 32 unchanged lines hidden (view full) ---

736 verbose(VERB_ALGO,
737 "subnet: not found in cache. pass to next module");
738 qstate->ext_state[id] = module_wait_module;
739 return;
740 }
741 /* Query handed back by next module, we have a 'final' answer */
742 if(sq && event == module_event_moddone) {
743 qstate->ext_state[id] = eval_response(qstate, id, sq);
703 lock_rw_unlock(&sne->biglock);
704 verbose(VERB_QUERY, "subnet: answered from cache");
705 qstate->ext_state[id] = module_finished;
706
707 ecs_opt_list_append(&sq->ecs_client_out,
708 &qstate->edns_opts_front_out, qstate);
709 return;
710 }

--- 32 unchanged lines hidden (view full) ---

743 verbose(VERB_ALGO,
744 "subnet: not found in cache. pass to next module");
745 qstate->ext_state[id] = module_wait_module;
746 return;
747 }
748 /* Query handed back by next module, we have a 'final' answer */
749 if(sq && event == module_event_moddone) {
750 qstate->ext_state[id] = eval_response(qstate, id, sq);
744 if(qstate->ext_state[id] == module_finished) {
751 if(qstate->ext_state[id] == module_finished &&
752 qstate->return_msg) {
745 ecs_opt_list_append(&sq->ecs_client_out,
746 &qstate->edns_opts_front_out, qstate);
747 }
748 return;
749 }
750 if(sq && outbound) {
751 return;
752 }

--- 63 unchanged lines hidden ---
753 ecs_opt_list_append(&sq->ecs_client_out,
754 &qstate->edns_opts_front_out, qstate);
755 }
756 return;
757 }
758 if(sq && outbound) {
759 return;
760 }

--- 63 unchanged lines hidden ---