diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2014-04-10 08:04:26 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2014-04-10 08:04:26 +0000 |
commit | b293da0013726d44dc9c2341d52332eeac3e807d (patch) | |
tree | 61e0d20328b11b7b1282903cfe753b2e5bb7e3e7 /src | |
parent | d3c25d11c49cc8a5cc21db70b19d9f2e04f57dc1 (diff) | |
download | gnunet-b293da0013726d44dc9c2341d52332eeac3e807d.tar.gz gnunet-b293da0013726d44dc9c2341d52332eeac3e807d.zip |
upnp support just silently failed if upnp client is not available
Diffstat (limited to 'src')
-rw-r--r-- | src/nat/nat.c | 79 |
1 files changed, 61 insertions, 18 deletions
diff --git a/src/nat/nat.c b/src/nat/nat.c index 3ebfd26a8..79e393cbb 100644 --- a/src/nat/nat.c +++ b/src/nat/nat.c | |||
@@ -1024,32 +1024,51 @@ upnp_add (void *cls, | |||
1024 | struct LocalAddressList *pos; | 1024 | struct LocalAddressList *pos; |
1025 | struct LocalAddressList *next; | 1025 | struct LocalAddressList *next; |
1026 | 1026 | ||
1027 | |||
1027 | if (GNUNET_YES == add_remove) | 1028 | if (GNUNET_YES == add_remove) |
1028 | { | 1029 | { |
1029 | add_to_address_list (h, LAL_UPNP, addr, addrlen); | 1030 | add_to_address_list (h, LAL_UPNP, addr, addrlen); |
1030 | return; | 1031 | return; |
1031 | } | 1032 | } |
1032 | /* remove address */ | 1033 | else if (GNUNET_NO == add_remove) |
1033 | next = h->lal_head; | ||
1034 | while (NULL != (pos = next)) | ||
1035 | { | 1034 | { |
1036 | next = pos->next; | 1035 | /* remove address */ |
1037 | if ((pos->source != LAL_UPNP) || (pos->addrlen != addrlen) || | 1036 | next = h->lal_head; |
1038 | (0 != memcmp (&pos[1], addr, addrlen))) | 1037 | while (NULL != (pos = next)) |
1039 | continue; | 1038 | { |
1040 | GNUNET_CONTAINER_DLL_remove (h->lal_head, h->lal_tail, pos); | 1039 | next = pos->next; |
1041 | if (NULL != h->address_callback) | 1040 | if ((pos->source != LAL_UPNP) || (pos->addrlen != addrlen) || |
1042 | h->address_callback (h->callback_cls, GNUNET_NO, | 1041 | (0 != memcmp (&pos[1], addr, addrlen))) |
1043 | (const struct sockaddr *) &pos[1], pos->addrlen); | 1042 | continue; |
1044 | GNUNET_free (pos); | 1043 | GNUNET_CONTAINER_DLL_remove (h->lal_head, h->lal_tail, pos); |
1045 | return; /* only remove once */ | 1044 | if (NULL != h->address_callback) |
1045 | h->address_callback (h->callback_cls, GNUNET_NO, | ||
1046 | (const struct sockaddr *) &pos[1], pos->addrlen); | ||
1047 | GNUNET_free (pos); | ||
1048 | return; /* only remove once */ | ||
1049 | } | ||
1050 | /* asked to remove address that does not exist */ | ||
1051 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
1052 | "Asked to remove unkown address `%s'\n", | ||
1053 | GNUNET_a2s(addr, addrlen)); | ||
1054 | GNUNET_break (0); | ||
1055 | } | ||
1056 | else if (GNUNET_SYSERR == add_remove) | ||
1057 | { | ||
1058 | /* Error while running upnp client */ | ||
1059 | if (NULL != emsg) | ||
1060 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
1061 | _("Error while running upnp client: `%s'\n"), emsg); | ||
1062 | else | ||
1063 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
1064 | _("Error while running upnp client \n")); | ||
1065 | return; | ||
1046 | } | 1066 | } |
1047 | /* asked to remove address that does not exist */ | 1067 | else |
1048 | LOG (GNUNET_ERROR_TYPE_ERROR, | 1068 | { |
1049 | "Asked to remove unkown address `%s'\n", | ||
1050 | GNUNET_a2s(addr, addrlen)); | ||
1051 | GNUNET_break (0); | ||
1052 | 1069 | ||
1070 | GNUNET_break (0); | ||
1071 | } | ||
1053 | } | 1072 | } |
1054 | 1073 | ||
1055 | 1074 | ||
@@ -1072,9 +1091,19 @@ add_minis (struct GNUNET_NAT_Handle *h, | |||
1072 | return; /* already got this port */ | 1091 | return; /* already got this port */ |
1073 | ml = ml->next; | 1092 | ml = ml->next; |
1074 | } | 1093 | } |
1094 | |||
1075 | ml = GNUNET_new (struct MiniList); | 1095 | ml = GNUNET_new (struct MiniList); |
1076 | ml->port = port; | 1096 | ml->port = port; |
1077 | ml->mini = GNUNET_NAT_mini_map_start (port, h->is_tcp, &upnp_add, h); | 1097 | ml->mini = GNUNET_NAT_mini_map_start (port, h->is_tcp, &upnp_add, h); |
1098 | |||
1099 | if (NULL == ml->mini) | ||
1100 | { | ||
1101 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1102 | _("Failed to run upnp client for port %u\n"), ml->port); | ||
1103 | GNUNET_free (ml); | ||
1104 | return; | ||
1105 | } | ||
1106 | |||
1078 | GNUNET_CONTAINER_DLL_insert (h->mini_head, h->mini_tail, ml); | 1107 | GNUNET_CONTAINER_DLL_insert (h->mini_head, h->mini_tail, ml); |
1079 | } | 1108 | } |
1080 | 1109 | ||
@@ -1112,7 +1141,12 @@ add_from_bind (void *cls, | |||
1112 | add_to_address_list (h, LAL_BINDTO_ADDRESS, sa, | 1141 | add_to_address_list (h, LAL_BINDTO_ADDRESS, sa, |
1113 | sizeof (struct sockaddr_in)); | 1142 | sizeof (struct sockaddr_in)); |
1114 | if (h->enable_upnp) | 1143 | if (h->enable_upnp) |
1144 | { | ||
1145 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1146 | "Running upnp client for address `%s'\n", | ||
1147 | GNUNET_a2s (sa,sizeof (struct sockaddr_in))); | ||
1115 | add_minis (h, ntohs (v4->sin_port)); | 1148 | add_minis (h, ntohs (v4->sin_port)); |
1149 | } | ||
1116 | break; | 1150 | break; |
1117 | case AF_INET6: | 1151 | case AF_INET6: |
1118 | if (sizeof (struct sockaddr_in6) != h->local_addrlens[i]) | 1152 | if (sizeof (struct sockaddr_in6) != h->local_addrlens[i]) |
@@ -1254,6 +1288,15 @@ GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1254 | if (NULL == reversal_callback) | 1288 | if (NULL == reversal_callback) |
1255 | h->enable_nat_server = GNUNET_NO; | 1289 | h->enable_nat_server = GNUNET_NO; |
1256 | 1290 | ||
1291 | /* Check for UPnP client, disable immediately if not available */ | ||
1292 | if (GNUNET_SYSERR == | ||
1293 | GNUNET_OS_check_helper_binary ("upnpc", GNUNET_NO, NULL)) | ||
1294 | { | ||
1295 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
1296 | _("UPnP enable in configuration, but UPnP client `upnpc` command not found, disabling UPnP \n")); | ||
1297 | h->enable_upnp = GNUNET_NO; | ||
1298 | } | ||
1299 | |||
1257 | /* Check if NAT was hole-punched */ | 1300 | /* Check if NAT was hole-punched */ |
1258 | if ((NULL != h->address_callback) && | 1301 | if ((NULL != h->address_callback) && |
1259 | (NULL != h->external_address) && | 1302 | (NULL != h->external_address) && |