aboutsummaryrefslogtreecommitdiff
path: root/src/dns
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-06-06 12:20:59 +0000
committerChristian Grothoff <christian@grothoff.org>2014-06-06 12:20:59 +0000
commit44aff2650f4c3d033049049ebbf08eed88b2b434 (patch)
treefc334cc4847e4e011562128a78e97c8499d199d7 /src/dns
parent62e273beeae391a44615e350e48f4ee40f2eab7a (diff)
downloadgnunet-44aff2650f4c3d033049049ebbf08eed88b2b434.tar.gz
gnunet-44aff2650f4c3d033049049ebbf08eed88b2b434.zip
towards sanity in SRV handling
Diffstat (limited to 'src/dns')
-rw-r--r--src/dns/dnsparser.c60
-rw-r--r--src/dns/gnunet-dns-monitor.c7
2 files changed, 8 insertions, 59 deletions
diff --git a/src/dns/dnsparser.c b/src/dns/dnsparser.c
index d4306c374..338591644 100644
--- a/src/dns/dnsparser.c
+++ b/src/dns/dnsparser.c
@@ -143,9 +143,6 @@ GNUNET_DNSPARSER_free_srv (struct GNUNET_DNSPARSER_SrvRecord *srv)
143 if (NULL == srv) 143 if (NULL == srv)
144 return; 144 return;
145 GNUNET_free_non_null (srv->target); 145 GNUNET_free_non_null (srv->target);
146 GNUNET_free_non_null (srv->domain_name);
147 GNUNET_free_non_null (srv->proto);
148 GNUNET_free_non_null (srv->service);
149 GNUNET_free (srv); 146 GNUNET_free (srv);
150} 147}
151 148
@@ -489,7 +486,6 @@ GNUNET_DNSPARSER_parse_mx (const char *udp_payload,
489/** 486/**
490 * Parse a DNS SRV record. 487 * Parse a DNS SRV record.
491 * 488 *
492 * @param r_name name of the SRV record
493 * @param udp_payload reference to UDP packet 489 * @param udp_payload reference to UDP packet
494 * @param udp_payload_length length of @a udp_payload 490 * @param udp_payload_length length of @a udp_payload
495 * @param off pointer to the offset of the query to parse in the SRV record (to be 491 * @param off pointer to the offset of the query to parse in the SRV record (to be
@@ -497,21 +493,14 @@ GNUNET_DNSPARSER_parse_mx (const char *udp_payload,
497 * @return the parsed SRV record, NULL on error 493 * @return the parsed SRV record, NULL on error
498 */ 494 */
499struct GNUNET_DNSPARSER_SrvRecord * 495struct GNUNET_DNSPARSER_SrvRecord *
500GNUNET_DNSPARSER_parse_srv (const char *r_name, 496GNUNET_DNSPARSER_parse_srv (const char *udp_payload,
501 const char *udp_payload,
502 size_t udp_payload_length, 497 size_t udp_payload_length,
503 size_t *off) 498 size_t *off)
504{ 499{
505 struct GNUNET_DNSPARSER_SrvRecord *srv; 500 struct GNUNET_DNSPARSER_SrvRecord *srv;
506 struct GNUNET_TUN_DnsSrvRecord srv_bin; 501 struct GNUNET_TUN_DnsSrvRecord srv_bin;
507 size_t old_off; 502 size_t old_off;
508 char *ndup;
509 char *tok;
510 503
511 if ('_' != *r_name)
512 return NULL; /* all valid srv names must start with "_" */
513 if (NULL == strstr (r_name, "._"))
514 return NULL; /* necessary string from "._$PROTO" not present */
515 old_off = *off; 504 old_off = *off;
516 if (*off + sizeof (struct GNUNET_TUN_DnsSrvRecord) > udp_payload_length) 505 if (*off + sizeof (struct GNUNET_TUN_DnsSrvRecord) > udp_payload_length)
517 return NULL; 506 return NULL;
@@ -523,32 +512,6 @@ GNUNET_DNSPARSER_parse_srv (const char *r_name,
523 srv->priority = ntohs (srv_bin.prio); 512 srv->priority = ntohs (srv_bin.prio);
524 srv->weight = ntohs (srv_bin.weight); 513 srv->weight = ntohs (srv_bin.weight);
525 srv->port = ntohs (srv_bin.port); 514 srv->port = ntohs (srv_bin.port);
526 /* parse 'data.hostname' into components, which are
527 "_$SERVICE._$PROTO.$DOMAIN_NAME" */
528 ndup = GNUNET_strdup (r_name);
529 tok = strtok (ndup, ".");
530 GNUNET_assert (NULL != tok);
531 GNUNET_assert ('_' == *tok);
532 srv->service = GNUNET_strdup (&tok[1]);
533 tok = strtok (NULL, ".");
534 if ( (NULL == tok) || ('_' != *tok) )
535 {
536 GNUNET_DNSPARSER_free_srv (srv);
537 GNUNET_free (ndup);
538 *off = old_off;
539 return NULL;
540 }
541 srv->proto = GNUNET_strdup (&tok[1]);
542 tok = strtok (NULL, ".");
543 if (NULL == tok)
544 {
545 GNUNET_DNSPARSER_free_srv (srv);
546 GNUNET_free (ndup);
547 *off = old_off;
548 return NULL;
549 }
550 srv->domain_name = GNUNET_strdup (tok);
551 GNUNET_free (ndup);
552 srv->target = GNUNET_DNSPARSER_parse_name (udp_payload, 515 srv->target = GNUNET_DNSPARSER_parse_name (udp_payload,
553 udp_payload_length, 516 udp_payload_length,
554 off); 517 off);
@@ -683,8 +646,7 @@ GNUNET_DNSPARSER_parse_record (const char *udp_payload,
683 } 646 }
684 return GNUNET_OK; 647 return GNUNET_OK;
685 case GNUNET_DNSPARSER_TYPE_SRV: 648 case GNUNET_DNSPARSER_TYPE_SRV:
686 r->data.srv = GNUNET_DNSPARSER_parse_srv (r->name, 649 r->data.srv = GNUNET_DNSPARSER_parse_srv (udp_payload,
687 udp_payload,
688 udp_payload_length, 650 udp_payload_length,
689 off); 651 off);
690 if ( (NULL == r->data.srv) || 652 if ( (NULL == r->data.srv) ||
@@ -1102,22 +1064,12 @@ add_record (char *dst,
1102 size_t start; 1064 size_t start;
1103 size_t pos; 1065 size_t pos;
1104 struct GNUNET_TUN_DnsRecordLine rl; 1066 struct GNUNET_TUN_DnsRecordLine rl;
1105 char *name;
1106 1067
1107 start = *off; 1068 start = *off;
1108 /* for SRV records, we can create the name from the details 1069 ret = GNUNET_DNSPARSER_builder_add_name (dst,
1109 of the record if needed */ 1070 dst_len - sizeof (struct GNUNET_TUN_DnsRecordLine),
1110 name = record->name; 1071 off,
1111 if ( (GNUNET_DNSPARSER_TYPE_SRV == record->type) && 1072 record->name);
1112 (NULL == name) )
1113 GNUNET_asprintf (&name,
1114 "_%s._%s.%s",
1115 record->data.srv->service,
1116 record->data.srv->proto,
1117 record->data.srv->domain_name);
1118 ret = GNUNET_DNSPARSER_builder_add_name (dst, dst_len - sizeof (struct GNUNET_TUN_DnsRecordLine), off, name);
1119 if (name != record->name)
1120 GNUNET_free (name);
1121 if (GNUNET_OK != ret) 1073 if (GNUNET_OK != ret)
1122 return ret; 1074 return ret;
1123 /* '*off' is now the position where we will need to write the record line */ 1075 /* '*off' is now the position where we will need to write the record line */
diff --git a/src/dns/gnunet-dns-monitor.c b/src/dns/gnunet-dns-monitor.c
index 48dd7a12d..a8ae1e668 100644
--- a/src/dns/gnunet-dns-monitor.c
+++ b/src/dns/gnunet-dns-monitor.c
@@ -164,7 +164,7 @@ display_record (const struct GNUNET_DNSPARSER_Record *record)
164 (unsigned int) record->data.soa->refresh, 164 (unsigned int) record->data.soa->refresh,
165 (unsigned int) record->data.soa->retry, 165 (unsigned int) record->data.soa->retry,
166 (unsigned int) record->data.soa->expire, 166 (unsigned int) record->data.soa->expire,
167 (unsigned int) record->data.soa->minimum_ttl); 167 (unsigned int) record->data.soa->minimum_ttl);
168 format = tmp; 168 format = tmp;
169 } 169 }
170 break; 170 break;
@@ -186,10 +186,7 @@ display_record (const struct GNUNET_DNSPARSER_Record *record)
186 else 186 else
187 { 187 {
188 GNUNET_asprintf (&tmp, 188 GNUNET_asprintf (&tmp,
189 "service: %s, protocol: %s, domain_name = %s, priority %u, weight = %s, port = %u, target = %s", 189 "priority %u, weight = %s, port = %u, target = %s",
190 record->data.srv->service,
191 record->data.srv->proto,
192 record->data.srv->domain_name,
193 (unsigned int) record->data.srv->priority, 190 (unsigned int) record->data.srv->priority,
194 (unsigned int) record->data.srv->weight, 191 (unsigned int) record->data.srv->weight,
195 (unsigned int) record->data.srv->port, 192 (unsigned int) record->data.srv->port,