aboutsummaryrefslogtreecommitdiff
path: root/src/nat/gnunet-service-nat.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2017-01-02 20:13:38 +0100
committerChristian Grothoff <christian@grothoff.org>2017-01-02 20:13:38 +0100
commit60c6dfd1fe22a01a3f7723e7e2bb18d52895c527 (patch)
treef6ecf4f27ad1e91e4d49b061be0f4b05bda199f3 /src/nat/gnunet-service-nat.c
parentf28533eb5fbd2b8e00bb351eb9fd1da322c70505 (diff)
downloadgnunet-60c6dfd1fe22a01a3f7723e7e2bb18d52895c527.tar.gz
gnunet-60c6dfd1fe22a01a3f7723e7e2bb18d52895c527.zip
fixes for starting and stopping gnunet-helper-nat-server
Diffstat (limited to 'src/nat/gnunet-service-nat.c')
-rw-r--r--src/nat/gnunet-service-nat.c89
1 files changed, 59 insertions, 30 deletions
diff --git a/src/nat/gnunet-service-nat.c b/src/nat/gnunet-service-nat.c
index f432eca18..e29f37108 100644
--- a/src/nat/gnunet-service-nat.c
+++ b/src/nat/gnunet-service-nat.c
@@ -396,6 +396,31 @@ static struct in_addr mini_external_ipv4;
396 396
397 397
398/** 398/**
399 * Remove and free an entry from the #lal_head DLL.
400 *
401 * @param lal entry to free
402 */
403static void
404free_lal (struct LocalAddressList *lal)
405{
406 GNUNET_CONTAINER_DLL_remove (lal_head,
407 lal_tail,
408 lal);
409 if (NULL != lal->hc)
410 {
411 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
412 "Lost NATed local address %s, stopping NAT server\n",
413 GNUNET_a2s ((const struct sockaddr *) &lal->addr,
414 sizeof (struct sockaddr_in)));
415
416 GN_stop_gnunet_nat_server_ (lal->hc);
417 lal->hc = NULL;
418 }
419 GNUNET_free (lal);
420}
421
422
423/**
399 * Free the DLL starting at #lal_head. 424 * Free the DLL starting at #lal_head.
400 */ 425 */
401static void 426static void
@@ -404,17 +429,7 @@ destroy_lal ()
404 struct LocalAddressList *lal; 429 struct LocalAddressList *lal;
405 430
406 while (NULL != (lal = lal_head)) 431 while (NULL != (lal = lal_head))
407 { 432 free_lal (lal);
408 GNUNET_CONTAINER_DLL_remove (lal_head,
409 lal_tail,
410 lal);
411 if (NULL != lal->hc)
412 {
413 GN_stop_gnunet_nat_server_ (lal->hc);
414 lal->hc = NULL;
415 }
416 GNUNET_free (lal);
417 }
418} 433}
419 434
420 435
@@ -1099,6 +1114,7 @@ run_scan (void *cls)
1099 struct IfcProcContext ifc_ctx; 1114 struct IfcProcContext ifc_ctx;
1100 int found; 1115 int found;
1101 int have_nat; 1116 int have_nat;
1117 struct LocalAddressList *lnext;
1102 1118
1103 scan_task = GNUNET_SCHEDULER_add_delayed (SCAN_FREQ, 1119 scan_task = GNUNET_SCHEDULER_add_delayed (SCAN_FREQ,
1104 &run_scan, 1120 &run_scan,
@@ -1111,8 +1127,9 @@ run_scan (void *cls)
1111 /* remove addresses that disappeared */ 1127 /* remove addresses that disappeared */
1112 for (struct LocalAddressList *lal = lal_head; 1128 for (struct LocalAddressList *lal = lal_head;
1113 NULL != lal; 1129 NULL != lal;
1114 lal = lal->next) 1130 lal = lnext)
1115 { 1131 {
1132 lnext = lal->next;
1116 found = GNUNET_NO; 1133 found = GNUNET_NO;
1117 for (struct LocalAddressList *pos = ifc_ctx.lal_head; 1134 for (struct LocalAddressList *pos = ifc_ctx.lal_head;
1118 NULL != pos; 1135 NULL != pos;
@@ -1126,20 +1143,21 @@ run_scan (void *cls)
1126 : sizeof (struct sockaddr_in6))) ) 1143 : sizeof (struct sockaddr_in6))) )
1127 { 1144 {
1128 found = GNUNET_YES; 1145 found = GNUNET_YES;
1129 pos->hc = lal->hc;
1130 lal->hc = NULL;
1131 } 1146 }
1132 } 1147 }
1133 if (GNUNET_NO == found) 1148 if (GNUNET_NO == found)
1149 {
1134 notify_clients (lal, 1150 notify_clients (lal,
1135 GNUNET_NO); 1151 GNUNET_NO);
1152 free_lal (lal);
1153 }
1136 } 1154 }
1137 1155
1138 /* add addresses that appeared */ 1156 /* add addresses that appeared */
1139 have_nat = GNUNET_NO; 1157 have_nat = GNUNET_NO;
1140 for (struct LocalAddressList *pos = ifc_ctx.lal_head; 1158 for (struct LocalAddressList *pos = ifc_ctx.lal_head;
1141 NULL != pos; 1159 NULL != pos;
1142 pos = pos->next) 1160 pos = ifc_ctx.lal_head)
1143 { 1161 {
1144 found = GNUNET_NO; 1162 found = GNUNET_NO;
1145 if (GNUNET_NAT_AC_LAN == (GNUNET_NAT_AC_LAN & pos->ac)) 1163 if (GNUNET_NAT_AC_LAN == (GNUNET_NAT_AC_LAN & pos->ac))
@@ -1156,19 +1174,34 @@ run_scan (void *cls)
1156 : sizeof (struct sockaddr_in6))) ) 1174 : sizeof (struct sockaddr_in6))) )
1157 found = GNUNET_YES; 1175 found = GNUNET_YES;
1158 } 1176 }
1159 if (GNUNET_NO == found) 1177 GNUNET_CONTAINER_DLL_remove (ifc_ctx.lal_head,
1178 ifc_ctx.lal_tail,
1179 pos);
1180 if (GNUNET_YES == found)
1181 {
1182 GNUNET_free (pos);
1183 }
1184 else
1185 {
1160 notify_clients (pos, 1186 notify_clients (pos,
1161 GNUNET_YES); 1187 GNUNET_YES);
1162 if ( (AF_INET == pos->af) && 1188 GNUNET_CONTAINER_DLL_insert (lal_head,
1163 (NULL == pos->hc) && 1189 lal_tail,
1164 (0 != (GNUNET_NAT_AC_LAN & pos->ac)) ) 1190 pos);
1165 { 1191 if ( (AF_INET == pos->af) &&
1166 const struct sockaddr_in *s4 1192 (NULL == pos->hc) &&
1167 = (const struct sockaddr_in *) &pos->addr; 1193 (0 != (GNUNET_NAT_AC_LAN & pos->ac)) )
1168 1194 {
1169 pos->hc = GN_start_gnunet_nat_server_ (&s4->sin_addr, 1195 const struct sockaddr_in *s4
1170 &reversal_callback, 1196 = (const struct sockaddr_in *) &pos->addr;
1171 pos); 1197
1198 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
1199 "Found NATed local address %s, starting NAT server\n",
1200 GNUNET_a2s ((void *) &pos->addr, sizeof (*s4)));
1201 pos->hc = GN_start_gnunet_nat_server_ (&s4->sin_addr,
1202 &reversal_callback,
1203 pos);
1204 }
1172 } 1205 }
1173 } 1206 }
1174 if ( (GNUNET_YES == have_nat) && 1207 if ( (GNUNET_YES == have_nat) &&
@@ -1194,10 +1227,6 @@ run_scan (void *cls)
1194 probe_external_ip_op = NULL; 1227 probe_external_ip_op = NULL;
1195 } 1228 }
1196 } 1229 }
1197
1198 destroy_lal ();
1199 lal_head = ifc_ctx.lal_head;
1200 lal_tail = ifc_ctx.lal_tail;
1201} 1230}
1202 1231
1203 1232