aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/dns/dnsparser.c60
-rw-r--r--src/dns/gnunet-dns-monitor.c7
-rw-r--r--src/gns/gnunet-service-gns_resolver.c4
-rw-r--r--src/gnsrecord/plugin_gnsrecord_dns.c15
-rw-r--r--src/include/gnunet_dnsparser_lib.h39
5 files changed, 18 insertions, 107 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,
diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c
index 9db5b1b99..c505ca59a 100644
--- a/src/gns/gnunet-service-gns_resolver.c
+++ b/src/gns/gnunet-service-gns_resolver.c
@@ -1628,8 +1628,7 @@ handle_gns_resolution_result (void *cls,
1628 struct GNUNET_DNSPARSER_SrvRecord *srv; 1628 struct GNUNET_DNSPARSER_SrvRecord *srv;
1629 1629
1630 off = 0; 1630 off = 0;
1631 srv = GNUNET_DNSPARSER_parse_srv (rh->name, 1631 srv = GNUNET_DNSPARSER_parse_srv (rd[i].data,
1632 rd[i].data,
1633 rd[i].data_size, 1632 rd[i].data_size,
1634 &off); 1633 &off);
1635 if ( (NULL == srv) || 1634 if ( (NULL == srv) ||
@@ -1639,7 +1638,6 @@ handle_gns_resolution_result (void *cls,
1639 } 1638 }
1640 else 1639 else
1641 { 1640 {
1642 srv->domain_name = translate_dot_plus (rh, srv->domain_name);
1643 srv->target = translate_dot_plus (rh, srv->target); 1641 srv->target = translate_dot_plus (rh, srv->target);
1644 scratch_start = scratch_off; 1642 scratch_start = scratch_off;
1645 if (GNUNET_OK != 1643 if (GNUNET_OK !=
diff --git a/src/gnsrecord/plugin_gnsrecord_dns.c b/src/gnsrecord/plugin_gnsrecord_dns.c
index 362acbf87..a9dff4088 100644
--- a/src/gnsrecord/plugin_gnsrecord_dns.c
+++ b/src/gnsrecord/plugin_gnsrecord_dns.c
@@ -209,8 +209,7 @@ dns_value_to_string (void *cls,
209 size_t off; 209 size_t off;
210 210
211 off = 0; 211 off = 0;
212 srv = GNUNET_DNSPARSER_parse_srv ("+", /* FIXME: is this OK? */ 212 srv = GNUNET_DNSPARSER_parse_srv (data,
213 data,
214 data_size, 213 data_size,
215 &off); 214 &off);
216 if ( (NULL == srv) || 215 if ( (NULL == srv) ||
@@ -222,13 +221,11 @@ dns_value_to_string (void *cls,
222 return NULL; 221 return NULL;
223 } 222 }
224 GNUNET_asprintf (&result, 223 GNUNET_asprintf (&result,
225 "%d %d %d _%s._%s.%s", 224 "%d %d %d %s",
226 srv->priority, 225 srv->priority,
227 srv->weight, 226 srv->weight,
228 srv->port, 227 srv->port,
229 srv->service, 228 srv->target);
230 srv->proto,
231 srv->domain_name);
232 GNUNET_DNSPARSER_free_srv (srv); 229 GNUNET_DNSPARSER_free_srv (srv);
233 return result; 230 return result;
234 } 231 }
@@ -536,8 +533,10 @@ dns_string_to_value (void *cls,
536 return GNUNET_OK; 533 return GNUNET_OK;
537 } 534 }
538 case GNUNET_DNSPARSER_TYPE_SRV: 535 case GNUNET_DNSPARSER_TYPE_SRV:
539 GNUNET_break (0); // FIXME: not implemented! 536 {
540 return GNUNET_SYSERR; 537 GNUNET_break (0); // FIXME: not implemented!
538 return GNUNET_SYSERR;
539 }
541 case GNUNET_DNSPARSER_TYPE_TXT: 540 case GNUNET_DNSPARSER_TYPE_TXT:
542 *data = GNUNET_strdup (s); 541 *data = GNUNET_strdup (s);
543 *data_size = strlen (s); 542 *data_size = strlen (s);
diff --git a/src/include/gnunet_dnsparser_lib.h b/src/include/gnunet_dnsparser_lib.h
index 6dc75b9a4..fc4b7444e 100644
--- a/src/include/gnunet_dnsparser_lib.h
+++ b/src/include/gnunet_dnsparser_lib.h
@@ -109,45 +109,12 @@ struct GNUNET_DNSPARSER_MxRecord
109 109
110 110
111/** 111/**
112 * Information from SRV records (RFC 2782). The 'service', 'proto' 112 * Information from SRV records (RFC 2782).
113 * and 'domain_name' fields together give the DNS-name which for SRV
114 * records is of the form "_$SERVICE._$PROTO.$DOMAIN_NAME". The DNS
115 * parser provides the full name in `struct DNSPARSER_Record` and the
116 * individual components in the respective fields of this struct.
117 * When serializing, you CAN set the 'name' field of 'struct
118 * GNUNET_DNSPARSER_Record' to NULL, in which case the DNSPARSER code
119 * will populate 'name' from the 'service', 'proto' and 'domain_name'
120 * fields in this struct.
121 */ 113 */
122struct GNUNET_DNSPARSER_SrvRecord 114struct GNUNET_DNSPARSER_SrvRecord
123{ 115{
124 116
125 /** 117 /**
126 * Service name without the underscore (!). Note that RFC 6335 clarifies the
127 * set of legal characters for service names.
128 * In UTF-8 format. The library will convert from and to DNS-IDNA
129 * as necessary. Use #GNUNET_DNSPARSER_check_label() to test if an
130 * individual label is well-formed. If a given name is not well-formed,
131 * creating the DNS packet will fail.
132 */
133 char *service;
134
135 /**
136 * Transport protocol (typcially "tcp" or "udp", but others might be allowed).
137 * Without the underscore (!).
138 */
139 char *proto;
140
141 /**
142 * Domain name for which the record is valid
143 * In UTF-8 format. The library will convert from and to DNS-IDNA
144 * as necessary. Use #GNUNET_DNSPARSER_check_label() to test if an
145 * individual label is well-formed. If a given name is not well-formed,
146 * creating the DNS packet will fail.
147 */
148 char *domain_name;
149
150 /**
151 * Hostname offering the service. 118 * Hostname offering the service.
152 * In UTF-8 format. The library will convert from and to DNS-IDNA 119 * In UTF-8 format. The library will convert from and to DNS-IDNA
153 * as necessary. Use #GNUNET_DNSPARSER_check_label() to test if an 120 * as necessary. Use #GNUNET_DNSPARSER_check_label() to test if an
@@ -834,7 +801,6 @@ GNUNET_DNSPARSER_parse_mx (const char *udp_payload,
834/** 801/**
835 * Parse a DNS SRV record. 802 * Parse a DNS SRV record.
836 * 803 *
837 * @param r_name name of the SRV record
838 * @param udp_payload reference to UDP packet 804 * @param udp_payload reference to UDP packet
839 * @param udp_payload_length length of @a udp_payload 805 * @param udp_payload_length length of @a udp_payload
840 * @param off pointer to the offset of the query to parse in the SRV record (to be 806 * @param off pointer to the offset of the query to parse in the SRV record (to be
@@ -842,8 +808,7 @@ GNUNET_DNSPARSER_parse_mx (const char *udp_payload,
842 * @return the parsed SRV record, NULL on error 808 * @return the parsed SRV record, NULL on error
843 */ 809 */
844struct GNUNET_DNSPARSER_SrvRecord * 810struct GNUNET_DNSPARSER_SrvRecord *
845GNUNET_DNSPARSER_parse_srv (const char *r_name, 811GNUNET_DNSPARSER_parse_srv (const char *udp_payload,
846 const char *udp_payload,
847 size_t udp_payload_length, 812 size_t udp_payload_length,
848 size_t *off); 813 size_t *off);
849 814