aboutsummaryrefslogtreecommitdiff
path: root/src/vpn
diff options
context:
space:
mode:
authorPhilipp Tölke <toelke@in.tum.de>2011-06-15 07:15:33 +0000
committerPhilipp Tölke <toelke@in.tum.de>2011-06-15 07:15:33 +0000
commit73c443600ed1c75ccaa1436d81dd89da7968e5f5 (patch)
tree47901fc1e9ca7a6525aa5d2038b3213d53abb8ee /src/vpn
parent2a77b2231c6718843ad5cfe1be0697aa4a725d03 (diff)
downloadgnunet-73c443600ed1c75ccaa1436d81dd89da7968e5f5.tar.gz
gnunet-73c443600ed1c75ccaa1436d81dd89da7968e5f5.zip
send packets back from the exit to the -vpn
Diffstat (limited to 'src/vpn')
-rw-r--r--src/vpn/gnunet-daemon-exit.c94
1 files changed, 57 insertions, 37 deletions
diff --git a/src/vpn/gnunet-daemon-exit.c b/src/vpn/gnunet-daemon-exit.c
index 7ccf2b26b..8abfdc31f 100644
--- a/src/vpn/gnunet-daemon-exit.c
+++ b/src/vpn/gnunet-daemon-exit.c
@@ -139,6 +139,8 @@ struct redirect_state
139 struct GNUNET_CONTAINER_MultiHashMap *hashmap; 139 struct GNUNET_CONTAINER_MultiHashMap *hashmap;
140 GNUNET_HashCode hash; 140 GNUNET_HashCode hash;
141 141
142 enum { SERVICE, REMOTE } type;
143
142 /** 144 /**
143 * The source-address and -port of this connection 145 * The source-address and -port of this connection
144 */ 146 */
@@ -267,42 +269,49 @@ udp_from_helper (struct udp_pkt *udp, unsigned char *dadr, size_t addrlen,
267 269
268 tunnel = state->tunnel; 270 tunnel = state->tunnel;
269 271
270 /* check if spt == serv.remote if yes: set spt = serv.myport ("nat") */ 272 if (state->type == SERVICE)
271 if (ntohs (udp->spt) == state->serv->remote_port)
272 {
273 udp->spt = htons (state->serv->my_port);
274 }
275 else
276 { 273 {
277 /* otherwise the answer came from a different port (tftp does this) 274 /* check if spt == serv.remote if yes: set spt = serv.myport ("nat") */
278 * add this new port to the list of all services, so that the packets 275 if (ntohs (udp->spt) == state->serv->remote_port)
279 * coming back from the client to this new port will be routed correctly 276 {
280 */ 277 udp->spt = htons (state->serv->my_port);
281 struct redirect_service *serv = 278 }
282 GNUNET_malloc (sizeof (struct redirect_service)); 279 else
283 memcpy (serv, state->serv, sizeof (struct redirect_service)); 280 {
284 serv->my_port = ntohs (udp->spt); 281 /* otherwise the answer came from a different port (tftp does this)
285 serv->remote_port = ntohs (udp->spt); 282 * add this new port to the list of all services, so that the packets
286 uint16_t *desc = alloca (sizeof (GNUNET_HashCode) + 2); 283 * coming back from the client to this new port will be routed correctly
287 memcpy ((GNUNET_HashCode *) (desc + 1), &state->desc, 284 */
288 sizeof (GNUNET_HashCode)); 285 struct redirect_service *serv =
289 *desc = ntohs (udp->spt); 286 GNUNET_malloc (sizeof (struct redirect_service));
290 GNUNET_assert (GNUNET_OK == 287 memcpy (serv, state->serv, sizeof (struct redirect_service));
291 GNUNET_CONTAINER_multihashmap_put (udp_services, 288 serv->my_port = ntohs (udp->spt);
292 (GNUNET_HashCode*)desc, serv, 289 serv->remote_port = ntohs (udp->spt);
293 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 290 uint16_t *desc = alloca (sizeof (GNUNET_HashCode) + 2);
294 291 memcpy ((GNUNET_HashCode *) (desc + 1), &state->desc,
295 state->serv = serv; 292 sizeof (GNUNET_HashCode));
293 *desc = ntohs (udp->spt);
294 GNUNET_assert (GNUNET_OK ==
295 GNUNET_CONTAINER_multihashmap_put (udp_services,
296 (GNUNET_HashCode*)desc, serv,
297 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
298
299 state->serv = serv;
300 }
296 } 301 }
302
297 /* send udp-packet back */ 303 /* send udp-packet back */
298 len = 304 len =
299 sizeof (struct GNUNET_MessageHeader) + sizeof (GNUNET_HashCode) + 305 sizeof (struct GNUNET_MessageHeader) + sizeof (GNUNET_HashCode) +
300 ntohs (udp->len); 306 ntohs (udp->len);
301 msg = GNUNET_malloc (len); 307 msg = GNUNET_malloc (len);
302 msg->size = htons (len); 308 msg->size = htons (len);
303 msg->type = htons (GNUNET_MESSAGE_TYPE_SERVICE_UDP_BACK); 309 msg->type = htons (state->type == SERVICE ? GNUNET_MESSAGE_TYPE_SERVICE_UDP_BACK : GNUNET_MESSAGE_TYPE_REMOTE_UDP_BACK);
304 GNUNET_HashCode *desc = (GNUNET_HashCode *) (msg + 1); 310 GNUNET_HashCode *desc = (GNUNET_HashCode *) (msg + 1);
305 memcpy (desc, &state->desc, sizeof (GNUNET_HashCode)); 311 if (state->type == SERVICE)
312 memcpy (desc, &state->desc, sizeof (GNUNET_HashCode));
313 else
314 memcpy (desc, &state->remote, sizeof (struct remote_addr));
306 void *_udp = desc + 1; 315 void *_udp = desc + 1;
307 memcpy (_udp, udp, ntohs (udp->len)); 316 memcpy (_udp, udp, ntohs (udp->len));
308 317
@@ -352,25 +361,32 @@ tcp_from_helper (struct tcp_pkt *tcp, unsigned char *dadr, size_t addrlen,
352 361
353 tunnel = state->tunnel; 362 tunnel = state->tunnel;
354 363
355 /* check if spt == serv.remote if yes: set spt = serv.myport ("nat") */ 364 if (state->type == SERVICE)
356 if (ntohs (tcp->spt) == state->serv->remote_port)
357 {
358 tcp->spt = htons (state->serv->my_port);
359 }
360 else
361 { 365 {
362 // This is an illegal packet. 366 /* check if spt == serv.remote if yes: set spt = serv.myport ("nat") */
363 return; 367 if (ntohs (tcp->spt) == state->serv->remote_port)
368 {
369 tcp->spt = htons (state->serv->my_port);
370 }
371 else
372 {
373 // This is an illegal packet.
374 return;
375 }
364 } 376 }
377
365 /* send tcp-packet back */ 378 /* send tcp-packet back */
366 len = 379 len =
367 sizeof (struct GNUNET_MessageHeader) + sizeof (GNUNET_HashCode) + pktlen; 380 sizeof (struct GNUNET_MessageHeader) + sizeof (GNUNET_HashCode) + pktlen;
368 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "len: %d\n", pktlen); 381 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "len: %d\n", pktlen);
369 msg = GNUNET_malloc (len); 382 msg = GNUNET_malloc (len);
370 msg->size = htons (len); 383 msg->size = htons (len);
371 msg->type = htons (GNUNET_MESSAGE_TYPE_SERVICE_TCP_BACK); 384 msg->type = htons (state->type == SERVICE ? GNUNET_MESSAGE_TYPE_SERVICE_TCP_BACK : GNUNET_MESSAGE_TYPE_REMOTE_TCP_BACK);
372 GNUNET_HashCode *desc = (GNUNET_HashCode *) (msg + 1); 385 GNUNET_HashCode *desc = (GNUNET_HashCode *) (msg + 1);
373 memcpy (desc, &state->desc, sizeof (GNUNET_HashCode)); 386 if (state->type == SERVICE)
387 memcpy (desc, &state->desc, sizeof (GNUNET_HashCode));
388 else
389 memcpy (desc, &state->remote, sizeof (struct remote_addr));
374 void *_tcp = desc + 1; 390 void *_tcp = desc + 1;
375 memcpy (_tcp, tcp, pktlen); 391 memcpy (_tcp, tcp, pktlen);
376 392
@@ -869,6 +885,7 @@ receive_tcp_service (void *cls,
869 memset (state, 0, sizeof (struct redirect_state)); 885 memset (state, 0, sizeof (struct redirect_state));
870 state->tunnel = tunnel; 886 state->tunnel = tunnel;
871 state->serv = serv; 887 state->serv = serv;
888 state->type = SERVICE;
872 state->hashmap = tcp_connections; 889 state->hashmap = tcp_connections;
873 memcpy (&state->desc, desc, sizeof (GNUNET_HashCode)); 890 memcpy (&state->desc, desc, sizeof (GNUNET_HashCode));
874 891
@@ -937,6 +954,7 @@ receive_tcp_remote (void *cls,
937 GNUNET_malloc (sizeof (struct redirect_state)); 954 GNUNET_malloc (sizeof (struct redirect_state));
938 memset (state, 0, sizeof (struct redirect_state)); 955 memset (state, 0, sizeof (struct redirect_state));
939 state->tunnel = tunnel; 956 state->tunnel = tunnel;
957 state->type = REMOTE;
940 state->hashmap = tcp_connections; 958 state->hashmap = tcp_connections;
941 memcpy (&state->remote, s, sizeof (struct remote_addr)); 959 memcpy (&state->remote, s, sizeof (struct remote_addr));
942 960
@@ -1013,6 +1031,7 @@ receive_udp_remote (void *cls,
1013 memset (state, 0, sizeof (struct redirect_state)); 1031 memset (state, 0, sizeof (struct redirect_state));
1014 state->tunnel = tunnel; 1032 state->tunnel = tunnel;
1015 state->hashmap = udp_connections; 1033 state->hashmap = udp_connections;
1034 state->type = REMOTE;
1016 memcpy (&state->remote, s, sizeof (struct remote_addr)); 1035 memcpy (&state->remote, s, sizeof (struct remote_addr));
1017 1036
1018 len = sizeof (struct GNUNET_MessageHeader) + sizeof (struct pkt_tun) + 1037 len = sizeof (struct GNUNET_MessageHeader) + sizeof (struct pkt_tun) +
@@ -1109,6 +1128,7 @@ receive_udp_service (void *cls,
1109 memset (state, 0, sizeof (struct redirect_state)); 1128 memset (state, 0, sizeof (struct redirect_state));
1110 state->tunnel = tunnel; 1129 state->tunnel = tunnel;
1111 state->serv = serv; 1130 state->serv = serv;
1131 state->type = SERVICE;
1112 state->hashmap = udp_connections; 1132 state->hashmap = udp_connections;
1113 memcpy (&state->desc, desc, sizeof (GNUNET_HashCode)); 1133 memcpy (&state->desc, desc, sizeof (GNUNET_HashCode));
1114 1134