aboutsummaryrefslogtreecommitdiff
path: root/src/vpn/gnunet-daemon-vpn-helper.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/vpn/gnunet-daemon-vpn-helper.c')
-rw-r--r--src/vpn/gnunet-daemon-vpn-helper.c109
1 files changed, 51 insertions, 58 deletions
diff --git a/src/vpn/gnunet-daemon-vpn-helper.c b/src/vpn/gnunet-daemon-vpn-helper.c
index 65e92b8f9..71fdefc0a 100644
--- a/src/vpn/gnunet-daemon-vpn-helper.c
+++ b/src/vpn/gnunet-daemon-vpn-helper.c
@@ -122,13 +122,10 @@ start_helper_and_schedule (void *cls,
122 * When the helper dies, this function will be called again with the 122 * When the helper dies, this function will be called again with the
123 * helper_handle as cls. 123 * helper_handle as cls.
124 */ 124 */
125 helper_handle = start_helper (ifname, 125 helper_handle =
126 ipv6addr, 126 start_helper (ifname, ipv6addr, ipv6prefix, ipv4addr, ipv4mask,
127 ipv6prefix, 127 "vpn-gnunet", start_helper_and_schedule, message_token,
128 ipv4addr, 128 NULL);
129 ipv4mask,
130 "vpn-gnunet",
131 start_helper_and_schedule, message_token, NULL);
132 129
133 GNUNET_free (ipv6addr); 130 GNUNET_free (ipv6addr);
134 GNUNET_free (ipv6prefix); 131 GNUNET_free (ipv6prefix);
@@ -230,16 +227,15 @@ helper_write (void *cls
230 /* if more packets are available, reschedule */ 227 /* if more packets are available, reschedule */
231 if (answer_proc_head != NULL) 228 if (answer_proc_head != NULL)
232 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, 229 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
233 helper_handle->fh_to_helper, 230 helper_handle->fh_to_helper, &helper_write,
234 &helper_write, NULL); 231 NULL);
235} 232}
236 233
237/** 234/**
238 * Receive packets from the helper-process 235 * Receive packets from the helper-process
239 */ 236 */
240void 237void
241message_token (void *cls __attribute__ ((unused)), 238message_token (void *cls __attribute__ ((unused)), void *client
242 void *client
243 __attribute__ ((unused)), 239 __attribute__ ((unused)),
244 const struct GNUNET_MessageHeader *message) 240 const struct GNUNET_MessageHeader *message)
245{ 241{
@@ -274,17 +270,17 @@ message_token (void *cls __attribute__ ((unused)),
274 270
275 size_t size = 271 size_t size =
276 sizeof (struct GNUNET_MESH_Tunnel *) + 272 sizeof (struct GNUNET_MESH_Tunnel *) +
277 sizeof (struct GNUNET_MessageHeader) + 273 sizeof (struct GNUNET_MessageHeader) + sizeof (GNUNET_HashCode) +
278 sizeof (GNUNET_HashCode) + ntohs (pkt6->ip6_hdr.paylgth); 274 ntohs (pkt6->ip6_hdr.paylgth);
279 275
280 struct GNUNET_MESH_Tunnel **cls = GNUNET_malloc (size); 276 struct GNUNET_MESH_Tunnel **cls = GNUNET_malloc (size);
281 struct GNUNET_MessageHeader *hdr = 277 struct GNUNET_MessageHeader *hdr =
282 (struct GNUNET_MessageHeader *) (cls + 1); 278 (struct GNUNET_MessageHeader *) (cls + 1);
283 GNUNET_HashCode *hc = (GNUNET_HashCode *) (hdr + 1); 279 GNUNET_HashCode *hc = (GNUNET_HashCode *) (hdr + 1);
284 280
285 hdr->size = htons (sizeof (struct GNUNET_MessageHeader) + 281 hdr->size =
286 sizeof (GNUNET_HashCode) + 282 htons (sizeof (struct GNUNET_MessageHeader) +
287 ntohs (pkt6->ip6_hdr.paylgth)); 283 sizeof (GNUNET_HashCode) + ntohs (pkt6->ip6_hdr.paylgth));
288 284
289 GNUNET_MESH_ApplicationType app_type; 285 GNUNET_MESH_ApplicationType app_type;
290 286
@@ -295,21 +291,19 @@ message_token (void *cls __attribute__ ((unused)),
295 /* This is a mapping to a gnunet-service */ 291 /* This is a mapping to a gnunet-service */
296 memcpy (hc, &me->desc.service_descriptor, sizeof (GNUNET_HashCode)); 292 memcpy (hc, &me->desc.service_descriptor, sizeof (GNUNET_HashCode));
297 293
298 if (0x11 == pkt6->ip6_hdr.nxthdr 294 if (0x11 == pkt6->ip6_hdr.nxthdr &&
299 && (me->desc.service_type & htonl (GNUNET_DNS_SERVICE_TYPE_UDP)) 295 (me->desc.service_type & htonl (GNUNET_DNS_SERVICE_TYPE_UDP)) &&
300 && (port_in_ports (me->desc.ports, pkt6_udp->udp_hdr.dpt) 296 (port_in_ports (me->desc.ports, pkt6_udp->udp_hdr.dpt) ||
301 || testBit (me->additional_ports, 297 testBit (me->additional_ports, ntohs (pkt6_udp->udp_hdr.dpt))))
302 ntohs (pkt6_udp->udp_hdr.dpt))))
303 { 298 {
304 hdr->type = ntohs (GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP); 299 hdr->type = ntohs (GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP);
305 300
306 memcpy (hc + 1, &pkt6_udp->udp_hdr, ntohs (pkt6_udp->udp_hdr.len)); 301 memcpy (hc + 1, &pkt6_udp->udp_hdr, ntohs (pkt6_udp->udp_hdr.len));
307 302
308 } 303 }
309 else if (0x06 == pkt6->ip6_hdr.nxthdr 304 else if (0x06 == pkt6->ip6_hdr.nxthdr &&
310 && (me->desc. 305 (me->desc.service_type & htonl (GNUNET_DNS_SERVICE_TYPE_TCP))
311 service_type & htonl (GNUNET_DNS_SERVICE_TYPE_TCP)) && 306 && (port_in_ports (me->desc.ports, pkt6_tcp->tcp_hdr.dpt)))
312 (port_in_ports (me->desc.ports, pkt6_tcp->tcp_hdr.dpt)))
313 { 307 {
314 hdr->type = ntohs (GNUNET_MESSAGE_TYPE_VPN_SERVICE_TCP); 308 hdr->type = ntohs (GNUNET_MESSAGE_TYPE_VPN_SERVICE_TCP);
315 309
@@ -323,10 +317,10 @@ message_token (void *cls __attribute__ ((unused)),
323 GNUNET_TIME_UNIT_FOREVER_REL, 317 GNUNET_TIME_UNIT_FOREVER_REL,
324 1, 318 1,
325 (struct 319 (struct
326 GNUNET_PeerIdentity 320 GNUNET_PeerIdentity *)
327 *) &me->desc.peer, 321 &me->desc.peer,
328 send_pkt_to_peer, 322 send_pkt_to_peer, NULL,
329 NULL, cls); 323 cls);
330 me->tunnel = *cls; 324 me->tunnel = *cls;
331 } 325 }
332 else if (NULL != cls) 326 else if (NULL != cls)
@@ -364,11 +358,12 @@ message_token (void *cls __attribute__ ((unused)),
364 } 358 }
365 if (me->tunnel == NULL && NULL != cls) 359 if (me->tunnel == NULL && NULL != cls)
366 { 360 {
367 *cls = GNUNET_MESH_peer_request_connect_by_type (mesh_handle, 361 *cls =
368 GNUNET_TIME_UNIT_FOREVER_REL, 362 GNUNET_MESH_peer_request_connect_by_type (mesh_handle,
369 app_type, 363 GNUNET_TIME_UNIT_FOREVER_REL,
370 send_pkt_to_peer, 364 app_type,
371 NULL, cls); 365 send_pkt_to_peer,
366 NULL, cls);
372 me->tunnel = *cls; 367 me->tunnel = *cls;
373 if (GNUNET_APPLICATION_TYPE_INTERNET_UDP_GATEWAY == app_type) 368 if (GNUNET_APPLICATION_TYPE_INTERNET_UDP_GATEWAY == app_type)
374 udp_tunnel = *cls; 369 udp_tunnel = *cls;
@@ -400,8 +395,8 @@ message_token (void *cls __attribute__ ((unused)),
400 /* ICMPv6 */ 395 /* ICMPv6 */
401 pkt6_icmp = (struct ip6_icmp *) pkt6; 396 pkt6_icmp = (struct ip6_icmp *) pkt6;
402 /* If this packet is an icmp-echo-request and a mapping exists, answer */ 397 /* If this packet is an icmp-echo-request and a mapping exists, answer */
403 if (pkt6_icmp->icmp_hdr.type == 0x80 398 if (pkt6_icmp->icmp_hdr.type == 0x80 &&
404 && (key = address6_mapping_exists (pkt6->ip6_hdr.dadr)) != NULL) 399 (key = address6_mapping_exists (pkt6->ip6_hdr.dadr)) != NULL)
405 { 400 {
406 GNUNET_free (key); 401 GNUNET_free (key);
407 pkt6_icmp = GNUNET_malloc (ntohs (pkt6->shdr.size)); 402 pkt6_icmp = GNUNET_malloc (ntohs (pkt6->shdr.size));
@@ -442,8 +437,7 @@ message_token (void *cls __attribute__ ((unused)),
442 GNUNET_assert (head != NULL); 437 GNUNET_assert (head != NULL);
443 438
444 if (dns_connection != NULL) 439 if (dns_connection != NULL)
445 GNUNET_CLIENT_notify_transmit_ready (dns_connection, 440 GNUNET_CLIENT_notify_transmit_ready (dns_connection, len,
446 len,
447 GNUNET_TIME_UNIT_FOREVER_REL, 441 GNUNET_TIME_UNIT_FOREVER_REL,
448 GNUNET_YES, &send_query, NULL); 442 GNUNET_YES, &send_query, NULL);
449 } 443 }
@@ -470,9 +464,8 @@ message_token (void *cls __attribute__ ((unused)),
470 464
471 size_t size = 465 size_t size =
472 sizeof (struct GNUNET_MESH_Tunnel *) + 466 sizeof (struct GNUNET_MESH_Tunnel *) +
473 sizeof (struct GNUNET_MessageHeader) + 467 sizeof (struct GNUNET_MessageHeader) + sizeof (GNUNET_HashCode) +
474 sizeof (GNUNET_HashCode) + ntohs (pkt->ip_hdr.tot_lngth) - 468 ntohs (pkt->ip_hdr.tot_lngth) - 4 * pkt->ip_hdr.hdr_lngth;
475 4 * pkt->ip_hdr.hdr_lngth;
476 469
477 struct GNUNET_MESH_Tunnel **cls = GNUNET_malloc (size); 470 struct GNUNET_MESH_Tunnel **cls = GNUNET_malloc (size);
478 struct GNUNET_MessageHeader *hdr = 471 struct GNUNET_MessageHeader *hdr =
@@ -493,20 +486,19 @@ message_token (void *cls __attribute__ ((unused)),
493 /* This is a mapping to a gnunet-service */ 486 /* This is a mapping to a gnunet-service */
494 memcpy (hc, &me->desc.service_descriptor, sizeof (GNUNET_HashCode)); 487 memcpy (hc, &me->desc.service_descriptor, sizeof (GNUNET_HashCode));
495 488
496 if (0x11 == pkt->ip_hdr.proto 489 if (0x11 == pkt->ip_hdr.proto &&
497 && (me->desc.service_type & htonl (GNUNET_DNS_SERVICE_TYPE_UDP)) 490 (me->desc.service_type & htonl (GNUNET_DNS_SERVICE_TYPE_UDP)) &&
498 && (port_in_ports (me->desc.ports, pkt_udp->udp_hdr.dpt) 491 (port_in_ports (me->desc.ports, pkt_udp->udp_hdr.dpt) ||
499 || testBit (me->additional_ports, 492 testBit (me->additional_ports, ntohs (pkt_udp->udp_hdr.dpt))))
500 ntohs (pkt_udp->udp_hdr.dpt))))
501 { 493 {
502 hdr->type = ntohs (GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP); 494 hdr->type = ntohs (GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP);
503 495
504 memcpy (hc + 1, &pkt_udp->udp_hdr, ntohs (pkt_udp->udp_hdr.len)); 496 memcpy (hc + 1, &pkt_udp->udp_hdr, ntohs (pkt_udp->udp_hdr.len));
505 497
506 } 498 }
507 else if (0x06 == pkt->ip_hdr.proto 499 else if (0x06 == pkt->ip_hdr.proto &&
508 && (me->desc.service_type & 500 (me->desc.
509 htonl (GNUNET_DNS_SERVICE_TYPE_TCP)) && 501 service_type & htonl (GNUNET_DNS_SERVICE_TYPE_TCP)) &&
510 (port_in_ports (me->desc.ports, pkt_tcp->tcp_hdr.dpt))) 502 (port_in_ports (me->desc.ports, pkt_tcp->tcp_hdr.dpt)))
511 { 503 {
512 hdr->type = ntohs (GNUNET_MESSAGE_TYPE_VPN_SERVICE_TCP); 504 hdr->type = ntohs (GNUNET_MESSAGE_TYPE_VPN_SERVICE_TCP);
@@ -523,10 +515,10 @@ message_token (void *cls __attribute__ ((unused)),
523 GNUNET_TIME_UNIT_FOREVER_REL, 515 GNUNET_TIME_UNIT_FOREVER_REL,
524 1, 516 1,
525 (struct 517 (struct
526 GNUNET_PeerIdentity 518 GNUNET_PeerIdentity *)
527 *) &me->desc.peer, 519 &me->desc.peer,
528 send_pkt_to_peer, 520 send_pkt_to_peer, NULL,
529 NULL, cls); 521 cls);
530 me->tunnel = *cls; 522 me->tunnel = *cls;
531 } 523 }
532 else if (NULL != cls) 524 else if (NULL != cls)
@@ -563,11 +555,12 @@ message_token (void *cls __attribute__ ((unused)),
563 } 555 }
564 if (me->tunnel == NULL && NULL != cls) 556 if (me->tunnel == NULL && NULL != cls)
565 { 557 {
566 *cls = GNUNET_MESH_peer_request_connect_by_type (mesh_handle, 558 *cls =
567 GNUNET_TIME_UNIT_FOREVER_REL, 559 GNUNET_MESH_peer_request_connect_by_type (mesh_handle,
568 app_type, 560 GNUNET_TIME_UNIT_FOREVER_REL,
569 send_pkt_to_peer, 561 app_type,
570 NULL, cls); 562 send_pkt_to_peer,
563 NULL, cls);
571 me->tunnel = *cls; 564 me->tunnel = *cls;
572 } 565 }
573 else if (NULL != cls) 566 else if (NULL != cls)