aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-06-04 11:45:14 +0200
committerChristian Grothoff <christian@grothoff.org>2019-06-04 11:45:14 +0200
commit6b9490cdf1a39464d512a54738f08a9caba18104 (patch)
treecfbd8091d0cc5b28eb75b9c0f2d8484f51e0632c
parentb3b3ef19da629d3f5e1e2806b0e02e57c4589c10 (diff)
downloadgnunet-6b9490cdf1a39464d512a54738f08a9caba18104.tar.gz
gnunet-6b9490cdf1a39464d512a54738f08a9caba18104.zip
fix bad use after free
-rw-r--r--src/nat/nat_api.c286
1 files changed, 126 insertions, 160 deletions
diff --git a/src/nat/nat_api.c b/src/nat/nat_api.c
index 04fa366aa..0dea501d3 100644
--- a/src/nat/nat_api.c
+++ b/src/nat/nat_api.c
@@ -11,7 +11,7 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
@@ -53,7 +53,7 @@ struct AddrEntry
53 * and retrieve on remove). 53 * and retrieve on remove).
54 */ 54 */
55 void *app_ctx; 55 void *app_ctx;
56 56
57 /** 57 /**
58 * Address class of the address. 58 * Address class of the address.
59 */ 59 */
@@ -150,23 +150,18 @@ reconnect (struct GNUNET_NAT_Handle *nh)
150 } 150 }
151 while (NULL != (ae = nh->ae_head)) 151 while (NULL != (ae = nh->ae_head))
152 { 152 {
153 GNUNET_CONTAINER_DLL_remove (nh->ae_head, 153 GNUNET_CONTAINER_DLL_remove (nh->ae_head, nh->ae_tail, ae);
154 nh->ae_tail,
155 ae);
156 nh->address_callback (nh->callback_cls, 154 nh->address_callback (nh->callback_cls,
157 &ae->app_ctx, 155 &ae->app_ctx,
158 GNUNET_NO, 156 GNUNET_NO,
159 ae->ac, 157 ae->ac,
160 (const struct sockaddr *) &ae[1], 158 (const struct sockaddr *) &ae[1],
161 ae->addrlen); 159 ae->addrlen);
162 GNUNET_free (ae); 160 GNUNET_free (ae);
163 } 161 }
164 nh->reconnect_delay 162 nh->reconnect_delay = GNUNET_TIME_STD_BACKOFF (nh->reconnect_delay);
165 = GNUNET_TIME_STD_BACKOFF (nh->reconnect_delay); 163 nh->reconnect_task =
166 nh->reconnect_task 164 GNUNET_SCHEDULER_add_delayed (nh->reconnect_delay, &do_connect, nh);
167 = GNUNET_SCHEDULER_add_delayed (nh->reconnect_delay,
168 &do_connect,
169 nh);
170} 165}
171 166
172 167
@@ -178,12 +173,11 @@ reconnect (struct GNUNET_NAT_Handle *nh)
178 * @return #GNUNET_OK if @a crm is well-formed 173 * @return #GNUNET_OK if @a crm is well-formed
179 */ 174 */
180static int 175static int
181check_connection_reversal_request (void *cls, 176check_connection_reversal_request (
182 const struct GNUNET_NAT_ConnectionReversalRequestedMessage *crm) 177 void *cls,
178 const struct GNUNET_NAT_ConnectionReversalRequestedMessage *crm)
183{ 179{
184 if (ntohs (crm->header.size) != 180 if (ntohs (crm->header.size) != sizeof (*crm) + sizeof (struct sockaddr_in))
185 sizeof (*crm) +
186 sizeof (struct sockaddr_in) )
187 { 181 {
188 GNUNET_break (0); 182 GNUNET_break (0);
189 return GNUNET_SYSERR; 183 return GNUNET_SYSERR;
@@ -199,14 +193,15 @@ check_connection_reversal_request (void *cls,
199 * @param crm the message 193 * @param crm the message
200 */ 194 */
201static void 195static void
202handle_connection_reversal_request (void *cls, 196handle_connection_reversal_request (
203 const struct GNUNET_NAT_ConnectionReversalRequestedMessage *crm) 197 void *cls,
198 const struct GNUNET_NAT_ConnectionReversalRequestedMessage *crm)
204{ 199{
205 struct GNUNET_NAT_Handle *nh = cls; 200 struct GNUNET_NAT_Handle *nh = cls;
206 201
207 nh->reversal_callback (nh->callback_cls, 202 nh->reversal_callback (nh->callback_cls,
208 (const struct sockaddr *) &crm[1], 203 (const struct sockaddr *) &crm[1],
209 sizeof (struct sockaddr_in)); 204 sizeof (struct sockaddr_in));
210} 205}
211 206
212 207
@@ -218,35 +213,32 @@ handle_connection_reversal_request (void *cls,
218 * @return #GNUNET_OK if @a crm is well-formed 213 * @return #GNUNET_OK if @a crm is well-formed
219 */ 214 */
220static int 215static int
221check_address_change_notification (void *cls, 216check_address_change_notification (
222 const struct GNUNET_NAT_AddressChangeNotificationMessage *acn) 217 void *cls,
218 const struct GNUNET_NAT_AddressChangeNotificationMessage *acn)
223{ 219{
224 size_t alen = ntohs (acn->header.size) - sizeof (*acn); 220 size_t alen = ntohs (acn->header.size) - sizeof (*acn);
225 221
226 switch (alen) 222 switch (alen)
227 { 223 {
228 case sizeof (struct sockaddr_in): 224 case sizeof (struct sockaddr_in): {
225 const struct sockaddr_in *s4 = (const struct sockaddr_in *) &acn[1];
226 if (AF_INET != s4->sin_family)
229 { 227 {
230 const struct sockaddr_in *s4 228 GNUNET_break (0);
231 = (const struct sockaddr_in *) &acn[1]; 229 return GNUNET_SYSERR;
232 if (AF_INET != s4->sin_family)
233 {
234 GNUNET_break (0);
235 return GNUNET_SYSERR;
236 }
237 } 230 }
238 break; 231 }
239 case sizeof (struct sockaddr_in6): 232 break;
233 case sizeof (struct sockaddr_in6): {
234 const struct sockaddr_in6 *s6 = (const struct sockaddr_in6 *) &acn[1];
235 if (AF_INET6 != s6->sin6_family)
240 { 236 {
241 const struct sockaddr_in6 *s6 237 GNUNET_break (0);
242 = (const struct sockaddr_in6 *) &acn[1]; 238 return GNUNET_SYSERR;
243 if (AF_INET6 != s6->sin6_family)
244 {
245 GNUNET_break (0);
246 return GNUNET_SYSERR;
247 }
248 } 239 }
249 break; 240 }
241 break;
250 default: 242 default:
251 GNUNET_break (0); 243 GNUNET_break (0);
252 return GNUNET_SYSERR; 244 return GNUNET_SYSERR;
@@ -262,8 +254,9 @@ check_address_change_notification (void *cls,
262 * @param acn the message 254 * @param acn the message
263 */ 255 */
264static void 256static void
265handle_address_change_notification (void *cls, 257handle_address_change_notification (
266 const struct GNUNET_NAT_AddressChangeNotificationMessage *acn) 258 void *cls,
259 const struct GNUNET_NAT_AddressChangeNotificationMessage *acn)
267{ 260{
268 struct GNUNET_NAT_Handle *nh = cls; 261 struct GNUNET_NAT_Handle *nh = cls;
269 size_t alen = ntohs (acn->header.size) - sizeof (*acn); 262 size_t alen = ntohs (acn->header.size) - sizeof (*acn);
@@ -279,38 +272,35 @@ handle_address_change_notification (void *cls,
279 ae = GNUNET_malloc (sizeof (*ae) + alen); 272 ae = GNUNET_malloc (sizeof (*ae) + alen);
280 ae->ac = ac; 273 ae->ac = ac;
281 ae->addrlen = alen; 274 ae->addrlen = alen;
282 GNUNET_memcpy (&ae[1], 275 GNUNET_memcpy (&ae[1], sa, alen);
283 sa, 276 GNUNET_CONTAINER_DLL_insert (nh->ae_head, nh->ae_tail, ae);
284 alen); 277 nh->address_callback (nh->callback_cls,
285 GNUNET_CONTAINER_DLL_insert (nh->ae_head, 278 &ae->app_ctx,
286 nh->ae_tail, 279 ntohl (acn->add_remove),
287 ae); 280 ac,
281 sa,
282 alen);
288 } 283 }
289 else 284 else
290 { 285 {
291 for (ae = nh->ae_head; NULL != ae; ae = ae->next) 286 for (ae = nh->ae_head; NULL != ae; ae = ae->next)
292 if ( (ae->addrlen == alen) && 287 if ((ae->addrlen == alen) && (0 == memcmp (&ae[1], sa, alen)))
293 (0 == memcmp (&ae[1], 288 break;
294 sa,
295 alen)) )
296 break;
297 if (NULL == ae) 289 if (NULL == ae)
298 { 290 {
299 GNUNET_break (0); 291 GNUNET_break (0);
300 reconnect (nh); 292 reconnect (nh);
301 return; 293 return;
302 } 294 }
303 GNUNET_CONTAINER_DLL_remove (nh->ae_head, 295 GNUNET_CONTAINER_DLL_remove (nh->ae_head, nh->ae_tail, ae);
304 nh->ae_tail, 296 nh->address_callback (nh->callback_cls,
305 ae); 297 &ae->app_ctx,
298 ntohl (acn->add_remove),
299 ac,
300 sa,
301 alen);
306 GNUNET_free (ae); 302 GNUNET_free (ae);
307 } 303 }
308 nh->address_callback (nh->callback_cls,
309 &ae->app_ctx,
310 ntohl (acn->add_remove),
311 ac,
312 sa,
313 alen);
314} 304}
315 305
316 306
@@ -321,8 +311,7 @@ handle_address_change_notification (void *cls,
321 * @param error details about the error 311 * @param error details about the error
322 */ 312 */
323static void 313static void
324mq_error_handler (void *cls, 314mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
325 enum GNUNET_MQ_Error error)
326{ 315{
327 struct GNUNET_NAT_Handle *nh = cls; 316 struct GNUNET_NAT_Handle *nh = cls;
328 317
@@ -339,33 +328,29 @@ static void
339do_connect (void *cls) 328do_connect (void *cls)
340{ 329{
341 struct GNUNET_NAT_Handle *nh = cls; 330 struct GNUNET_NAT_Handle *nh = cls;
342 struct GNUNET_MQ_MessageHandler handlers[] = { 331 struct GNUNET_MQ_MessageHandler handlers[] =
343 GNUNET_MQ_hd_var_size (connection_reversal_request, 332 {GNUNET_MQ_hd_var_size (connection_reversal_request,
344 GNUNET_MESSAGE_TYPE_NAT_CONNECTION_REVERSAL_REQUESTED, 333 GNUNET_MESSAGE_TYPE_NAT_CONNECTION_REVERSAL_REQUESTED,
345 struct GNUNET_NAT_ConnectionReversalRequestedMessage, 334 struct
346 nh), 335 GNUNET_NAT_ConnectionReversalRequestedMessage,
347 GNUNET_MQ_hd_var_size (address_change_notification, 336 nh),
348 GNUNET_MESSAGE_TYPE_NAT_ADDRESS_CHANGE, 337 GNUNET_MQ_hd_var_size (address_change_notification,
349 struct GNUNET_NAT_AddressChangeNotificationMessage, 338 GNUNET_MESSAGE_TYPE_NAT_ADDRESS_CHANGE,
350 nh), 339 struct GNUNET_NAT_AddressChangeNotificationMessage,
351 GNUNET_MQ_handler_end () 340 nh),
352 }; 341 GNUNET_MQ_handler_end ()};
353 struct GNUNET_MQ_Envelope *env; 342 struct GNUNET_MQ_Envelope *env;
354 343
355 nh->reconnect_task = NULL; 344 nh->reconnect_task = NULL;
356 nh->mq = GNUNET_CLIENT_connect (nh->cfg, 345 nh->mq =
357 "nat", 346 GNUNET_CLIENT_connect (nh->cfg, "nat", handlers, &mq_error_handler, nh);
358 handlers,
359 &mq_error_handler,
360 nh);
361 if (NULL == nh->mq) 347 if (NULL == nh->mq)
362 { 348 {
363 reconnect (nh); 349 reconnect (nh);
364 return; 350 return;
365 } 351 }
366 env = GNUNET_MQ_msg_copy (nh->reg); 352 env = GNUNET_MQ_msg_copy (nh->reg);
367 GNUNET_MQ_send (nh->mq, 353 GNUNET_MQ_send (nh->mq, env);
368 env);
369} 354}
370 355
371 356
@@ -407,12 +392,12 @@ GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg,
407 char *off; 392 char *off;
408 393
409 len = 0; 394 len = 0;
410 for (unsigned int i=0;i<num_addrs;i++) 395 for (unsigned int i = 0; i < num_addrs; i++)
411 len += addrlens[i]; 396 len += addrlens[i];
412 str_len = strlen (config_section) + 1; 397 str_len = strlen (config_section) + 1;
413 len += str_len; 398 len += str_len;
414 if ( (len > GNUNET_MAX_MESSAGE_SIZE - sizeof (*rm)) || 399 if ((len > GNUNET_MAX_MESSAGE_SIZE - sizeof (*rm)) ||
415 (num_addrs > UINT16_MAX) ) 400 (num_addrs > UINT16_MAX))
416 { 401 {
417 GNUNET_break (0); 402 GNUNET_break (0);
418 return NULL; 403 return NULL;
@@ -429,33 +414,33 @@ GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg,
429 rm->str_len = htons (str_len); 414 rm->str_len = htons (str_len);
430 rm->num_addrs = htons ((uint16_t) num_addrs); 415 rm->num_addrs = htons ((uint16_t) num_addrs);
431 off = (char *) &rm[1]; 416 off = (char *) &rm[1];
432 for (unsigned int i=0;i<num_addrs;i++) 417 for (unsigned int i = 0; i < num_addrs; i++)
433 { 418 {
434 switch (addrs[i]->sa_family) 419 switch (addrs[i]->sa_family)
435 { 420 {
436 case AF_INET: 421 case AF_INET:
437 if (sizeof (struct sockaddr_in) != addrlens[i]) 422 if (sizeof (struct sockaddr_in) != addrlens[i])
438 { 423 {
439 GNUNET_break (0); 424 GNUNET_break (0);
440 GNUNET_free (rm); 425 GNUNET_free (rm);
441 return NULL; 426 return NULL;
442 } 427 }
443 break; 428 break;
444 case AF_INET6: 429 case AF_INET6:
445 if (sizeof (struct sockaddr_in6) != addrlens[i]) 430 if (sizeof (struct sockaddr_in6) != addrlens[i])
446 { 431 {
447 GNUNET_break (0); 432 GNUNET_break (0);
448 GNUNET_free (rm); 433 GNUNET_free (rm);
449 return NULL; 434 return NULL;
450 } 435 }
451 break; 436 break;
452#if AF_UNIX 437#if AF_UNIX
453 case AF_UNIX: 438 case AF_UNIX:
454 if (sizeof (struct sockaddr_un) != addrlens[i]) 439 if (sizeof (struct sockaddr_un) != addrlens[i])
455 { 440 {
456 GNUNET_break (0); 441 GNUNET_break (0);
457 GNUNET_free (rm); 442 GNUNET_free (rm);
458 return NULL; 443 return NULL;
459 } 444 }
460 break; 445 break;
461#endif 446#endif
@@ -464,14 +449,10 @@ GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg,
464 GNUNET_free (rm); 449 GNUNET_free (rm);
465 return NULL; 450 return NULL;
466 } 451 }
467 GNUNET_memcpy (off, 452 GNUNET_memcpy (off, addrs[i], addrlens[i]);
468 addrs[i],
469 addrlens[i]);
470 off += addrlens[i]; 453 off += addrlens[i];
471 } 454 }
472 GNUNET_memcpy (off, 455 GNUNET_memcpy (off, config_section, str_len);
473 config_section,
474 str_len);
475 456
476 nh = GNUNET_new (struct GNUNET_NAT_Handle); 457 nh = GNUNET_new (struct GNUNET_NAT_Handle);
477 nh->reg = &rm->header; 458 nh->reg = &rm->header;
@@ -493,8 +474,7 @@ GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg,
493 * #GNUNET_NO if the packet is invalid (not a stun packet) 474 * #GNUNET_NO if the packet is invalid (not a stun packet)
494 */ 475 */
495static int 476static int
496test_stun_packet (const void *data, 477test_stun_packet (const void *data, size_t len)
497 size_t len)
498{ 478{
499 const struct stun_header *hdr; 479 const struct stun_header *hdr;
500 const struct stun_attr *attr; 480 const struct stun_attr *attr;
@@ -505,12 +485,12 @@ test_stun_packet (const void *data,
505 * initial checks it becomes the size of unprocessed options, 485 * initial checks it becomes the size of unprocessed options,
506 * while 'data' is advanced accordingly. 486 * while 'data' is advanced accordingly.
507 */ 487 */
508 if (len < sizeof(struct stun_header)) 488 if (len < sizeof (struct stun_header))
509 { 489 {
510 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 490 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
511 "STUN packet too short (only %d, wanting at least %d)\n", 491 "STUN packet too short (only %d, wanting at least %d)\n",
512 (int) len, 492 (int) len,
513 (int) sizeof (struct stun_header)); 493 (int) sizeof (struct stun_header));
514 return GNUNET_NO; 494 return GNUNET_NO;
515 } 495 }
516 hdr = (const struct stun_header *) data; 496 hdr = (const struct stun_header *) data;
@@ -525,17 +505,16 @@ test_stun_packet (const void *data,
525 /* Compare if the cookie match */ 505 /* Compare if the cookie match */
526 if (STUN_MAGIC_COOKIE != message_magic_cookie) 506 if (STUN_MAGIC_COOKIE != message_magic_cookie)
527 { 507 {
528 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 508 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Invalid magic cookie for STUN\n");
529 "Invalid magic cookie for STUN\n");
530 return GNUNET_NO; 509 return GNUNET_NO;
531 } 510 }
532 511
533 if (advertised_message_size > len) 512 if (advertised_message_size > len)
534 { 513 {
535 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 514 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
536 "Scrambled STUN packet length (got %d, expecting %d)\n", 515 "Scrambled STUN packet length (got %d, expecting %d)\n",
537 advertised_message_size, 516 advertised_message_size,
538 (int)len); 517 (int) len);
539 return GNUNET_NO; 518 return GNUNET_NO;
540 } 519 }
541 len = advertised_message_size; 520 len = advertised_message_size;
@@ -544,32 +523,33 @@ test_stun_packet (const void *data,
544 if (len < sizeof (struct stun_attr)) 523 if (len < sizeof (struct stun_attr))
545 { 524 {
546 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 525 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
547 "Attribute too short in STUN packet (got %d, expecting %d)\n", 526 "Attribute too short in STUN packet (got %d, expecting %d)\n",
548 (int) len, 527 (int) len,
549 (int) sizeof(struct stun_attr)); 528 (int) sizeof (struct stun_attr));
550 return GNUNET_NO; 529 return GNUNET_NO;
551 } 530 }
552 attr = (const struct stun_attr *) data; 531 attr = (const struct stun_attr *) data;
553 532
554 /* compute total attribute length */ 533 /* compute total attribute length */
555 advertised_message_size = ntohs (attr->len) + sizeof(struct stun_attr); 534 advertised_message_size = ntohs (attr->len) + sizeof (struct stun_attr);
556 535
557 /* Check if we still have space in our buffer */ 536 /* Check if we still have space in our buffer */
558 if (advertised_message_size > len) 537 if (advertised_message_size > len)
559 { 538 {
560 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 539 GNUNET_log (
561 "Inconsistent Attribute (length %d exceeds remaining msg len %d)\n", 540 GNUNET_ERROR_TYPE_DEBUG,
562 advertised_message_size, 541 "Inconsistent Attribute (length %d exceeds remaining msg len %d)\n",
563 (int) len); 542 advertised_message_size,
543 (int) len);
564 return GNUNET_NO; 544 return GNUNET_NO;
565 } 545 }
566 data += advertised_message_size; 546 data += advertised_message_size;
567 len -= advertised_message_size; 547 len -= advertised_message_size;
568 } 548 }
569 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 549 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
570 "STUN Packet, msg %04x, length: %d\n", 550 "STUN Packet, msg %04x, length: %d\n",
571 ntohs (hdr->msgtype), 551 ntohs (hdr->msgtype),
572 advertised_message_size); 552 advertised_message_size);
573 return GNUNET_OK; 553 return GNUNET_OK;
574} 554}
575 555
@@ -599,36 +579,29 @@ test_stun_packet (const void *data,
599 */ 579 */
600int 580int
601GNUNET_NAT_stun_handle_packet (struct GNUNET_NAT_Handle *nh, 581GNUNET_NAT_stun_handle_packet (struct GNUNET_NAT_Handle *nh,
602 const struct sockaddr *sender_addr, 582 const struct sockaddr *sender_addr,
603 size_t sender_addr_len, 583 size_t sender_addr_len,
604 const void *data, 584 const void *data,
605 size_t data_size) 585 size_t data_size)
606{ 586{
607 struct GNUNET_MQ_Envelope *env; 587 struct GNUNET_MQ_Envelope *env;
608 struct GNUNET_NAT_HandleStunMessage *hsn; 588 struct GNUNET_NAT_HandleStunMessage *hsn;
609 char *buf; 589 char *buf;
610 590
611 if (GNUNET_YES != 591 if (GNUNET_YES != test_stun_packet (data, data_size))
612 test_stun_packet (data,
613 data_size))
614 return GNUNET_NO; 592 return GNUNET_NO;
615 if (NULL == nh->mq) 593 if (NULL == nh->mq)
616 return GNUNET_SYSERR; 594 return GNUNET_SYSERR;
617 env = GNUNET_MQ_msg_extra (hsn, 595 env = GNUNET_MQ_msg_extra (hsn,
618 data_size + sender_addr_len, 596 data_size + sender_addr_len,
619 GNUNET_MESSAGE_TYPE_NAT_HANDLE_STUN); 597 GNUNET_MESSAGE_TYPE_NAT_HANDLE_STUN);
620 hsn->sender_addr_size = htons ((uint16_t) sender_addr_len); 598 hsn->sender_addr_size = htons ((uint16_t) sender_addr_len);
621 hsn->payload_size = htons ((uint16_t) data_size); 599 hsn->payload_size = htons ((uint16_t) data_size);
622 buf = (char *) &hsn[1]; 600 buf = (char *) &hsn[1];
623 GNUNET_memcpy (buf, 601 GNUNET_memcpy (buf, sender_addr, sender_addr_len);
624 sender_addr,
625 sender_addr_len);
626 buf += sender_addr_len; 602 buf += sender_addr_len;
627 GNUNET_memcpy (buf, 603 GNUNET_memcpy (buf, data, data_size);
628 data, 604 GNUNET_MQ_send (nh->mq, env);
629 data_size);
630 GNUNET_MQ_send (nh->mq,
631 env);
632 return GNUNET_OK; 605 return GNUNET_OK;
633} 606}
634 607
@@ -653,17 +626,14 @@ GNUNET_NAT_test_address (struct GNUNET_NAT_Handle *nh,
653{ 626{
654 struct AddrEntry *ae; 627 struct AddrEntry *ae;
655 628
656 if ( (addrlen != sizeof (struct sockaddr_in)) && 629 if ((addrlen != sizeof (struct sockaddr_in)) &&
657 (addrlen != sizeof (struct sockaddr_in6)) ) 630 (addrlen != sizeof (struct sockaddr_in6)))
658 { 631 {
659 GNUNET_break (0); 632 GNUNET_break (0);
660 return GNUNET_SYSERR; 633 return GNUNET_SYSERR;
661 } 634 }
662 for (ae = nh->ae_head; NULL != ae; ae = ae->next) 635 for (ae = nh->ae_head; NULL != ae; ae = ae->next)
663 if ( (addrlen == ae->addrlen) && 636 if ((addrlen == ae->addrlen) && (0 == memcmp (addr, &ae[1], addrlen)))
664 (0 == memcmp (addr,
665 &ae[1],
666 addrlen)) )
667 return GNUNET_YES; 637 return GNUNET_YES;
668 return GNUNET_NO; 638 return GNUNET_NO;
669} 639}
@@ -683,8 +653,8 @@ GNUNET_NAT_test_address (struct GNUNET_NAT_Handle *nh,
683 */ 653 */
684int 654int
685GNUNET_NAT_request_reversal (struct GNUNET_NAT_Handle *nh, 655GNUNET_NAT_request_reversal (struct GNUNET_NAT_Handle *nh,
686 const struct sockaddr_in *local_sa, 656 const struct sockaddr_in *local_sa,
687 const struct sockaddr_in *remote_sa) 657 const struct sockaddr_in *remote_sa)
688{ 658{
689 struct GNUNET_MQ_Envelope *env; 659 struct GNUNET_MQ_Envelope *env;
690 struct GNUNET_NAT_RequestConnectionReversalMessage *req; 660 struct GNUNET_NAT_RequestConnectionReversalMessage *req;
@@ -694,21 +664,17 @@ GNUNET_NAT_request_reversal (struct GNUNET_NAT_Handle *nh,
694 return GNUNET_SYSERR; 664 return GNUNET_SYSERR;
695 GNUNET_break (AF_INET == local_sa->sin_family); 665 GNUNET_break (AF_INET == local_sa->sin_family);
696 GNUNET_break (AF_INET == remote_sa->sin_family); 666 GNUNET_break (AF_INET == remote_sa->sin_family);
697 env = GNUNET_MQ_msg_extra (req, 667 env =
698 2 * sizeof (struct sockaddr_in), 668 GNUNET_MQ_msg_extra (req,
699 GNUNET_MESSAGE_TYPE_NAT_REQUEST_CONNECTION_REVERSAL); 669 2 * sizeof (struct sockaddr_in),
670 GNUNET_MESSAGE_TYPE_NAT_REQUEST_CONNECTION_REVERSAL);
700 req->local_addr_size = htons (sizeof (struct sockaddr_in)); 671 req->local_addr_size = htons (sizeof (struct sockaddr_in));
701 req->remote_addr_size = htons (sizeof (struct sockaddr_in)); 672 req->remote_addr_size = htons (sizeof (struct sockaddr_in));
702 buf = (char *) &req[1]; 673 buf = (char *) &req[1];
703 GNUNET_memcpy (buf, 674 GNUNET_memcpy (buf, local_sa, sizeof (struct sockaddr_in));
704 local_sa,
705 sizeof (struct sockaddr_in));
706 buf += sizeof (struct sockaddr_in); 675 buf += sizeof (struct sockaddr_in);
707 GNUNET_memcpy (buf, 676 GNUNET_memcpy (buf, remote_sa, sizeof (struct sockaddr_in));
708 remote_sa, 677 GNUNET_MQ_send (nh->mq, env);
709 sizeof (struct sockaddr_in));
710 GNUNET_MQ_send (nh->mq,
711 env);
712 return GNUNET_OK; 678 return GNUNET_OK;
713} 679}
714 680