aboutsummaryrefslogtreecommitdiff
path: root/src/nat/nat_api.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2017-01-02 19:15:51 +0100
committerChristian Grothoff <christian@grothoff.org>2017-01-02 19:15:51 +0100
commitf28533eb5fbd2b8e00bb351eb9fd1da322c70505 (patch)
tree793b1949dd681414d51ea18c151dd6684efa6b9f /src/nat/nat_api.c
parent1082a8e39e4f3d9b908b14995653ac262f640adb (diff)
downloadgnunet-f28533eb5fbd2b8e00bb351eb9fd1da322c70505.tar.gz
gnunet-f28533eb5fbd2b8e00bb351eb9fd1da322c70505.zip
preparations for proper manual hole punching support in new NAT API
Diffstat (limited to 'src/nat/nat_api.c')
-rw-r--r--src/nat/nat_api.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/nat/nat_api.c b/src/nat/nat_api.c
index ab36d6162..e4dfc1629 100644
--- a/src/nat/nat_api.c
+++ b/src/nat/nat_api.c
@@ -369,8 +369,7 @@ do_connect (void *cls)
369 * 369 *
370 * @param cfg configuration to use 370 * @param cfg configuration to use
371 * @param proto protocol this is about, IPPROTO_TCP or IPPROTO_UDP 371 * @param proto protocol this is about, IPPROTO_TCP or IPPROTO_UDP
372 * @param adv_port advertised port (port we are either bound to or that our OS 372 * @param hole_external hostname and port of manually punched hole in NAT, otherwise NULL (or empty string)
373 * locally performs redirection from to our bound port).
374 * @param num_addrs number of addresses in @a addrs 373 * @param num_addrs number of addresses in @a addrs
375 * @param addrs list of local addresses packets should be redirected to 374 * @param addrs list of local addresses packets should be redirected to
376 * @param addrlens actual lengths of the addresses in @a addrs 375 * @param addrlens actual lengths of the addresses in @a addrs
@@ -383,7 +382,7 @@ do_connect (void *cls)
383struct GNUNET_NAT_Handle * 382struct GNUNET_NAT_Handle *
384GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg, 383GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg,
385 uint8_t proto, 384 uint8_t proto,
386 uint16_t adv_port, 385 const char *hole_external,
387 unsigned int num_addrs, 386 unsigned int num_addrs,
388 const struct sockaddr **addrs, 387 const struct sockaddr **addrs,
389 const socklen_t *addrlens, 388 const socklen_t *addrlens,
@@ -394,11 +393,17 @@ GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg,
394 struct GNUNET_NAT_Handle *nh; 393 struct GNUNET_NAT_Handle *nh;
395 struct GNUNET_NAT_RegisterMessage *rm; 394 struct GNUNET_NAT_RegisterMessage *rm;
396 size_t len; 395 size_t len;
396 size_t hole_external_len;
397 char *off; 397 char *off;
398 398
399 len = 0; 399 len = 0;
400 for (unsigned int i=0;i<num_addrs;i++) 400 for (unsigned int i=0;i<num_addrs;i++)
401 len += addrlens[i]; 401 len += addrlens[i];
402 hole_external_len
403 = (NULL == hole_external)
404 ? 0
405 : strlen (hole_external);
406 len += hole_external_len;
402 if ( (len > GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (*rm)) || 407 if ( (len > GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (*rm)) ||
403 (num_addrs > UINT16_MAX) ) 408 (num_addrs > UINT16_MAX) )
404 { 409 {
@@ -414,7 +419,7 @@ GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg,
414 if (NULL != reversal_callback) 419 if (NULL != reversal_callback)
415 rm->flags |= GNUNET_NAT_RF_REVERSAL; 420 rm->flags |= GNUNET_NAT_RF_REVERSAL;
416 rm->proto = proto; 421 rm->proto = proto;
417 rm->adv_port = htons (adv_port); 422 rm->hole_external_len = htons (hole_external_len);
418 rm->num_addrs = htons ((uint16_t) num_addrs); 423 rm->num_addrs = htons ((uint16_t) num_addrs);
419 off = (char *) &rm[1]; 424 off = (char *) &rm[1];
420 for (unsigned int i=0;i<num_addrs;i++) 425 for (unsigned int i=0;i<num_addrs;i++)
@@ -453,6 +458,9 @@ GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg,
453 addrlens[i]); 458 addrlens[i]);
454 off += addrlens[i]; 459 off += addrlens[i];
455 } 460 }
461 GNUNET_memcpy (off,
462 hole_external,
463 hole_external_len);
456 464
457 nh = GNUNET_new (struct GNUNET_NAT_Handle); 465 nh = GNUNET_new (struct GNUNET_NAT_Handle);
458 nh->reg = &rm->header; 466 nh->reg = &rm->header;