diff options
Diffstat (limited to 'src/vpn')
-rw-r--r-- | src/vpn/gnunet-service-vpn.c | 129 |
1 files changed, 65 insertions, 64 deletions
diff --git a/src/vpn/gnunet-service-vpn.c b/src/vpn/gnunet-service-vpn.c index 5290ad69e..bd0aa4a74 100644 --- a/src/vpn/gnunet-service-vpn.c +++ b/src/vpn/gnunet-service-vpn.c | |||
@@ -2483,6 +2483,65 @@ expire_destination (struct DestinationEntry *except) | |||
2483 | 2483 | ||
2484 | 2484 | ||
2485 | /** | 2485 | /** |
2486 | * Allocate an IP address for the response. | ||
2487 | * | ||
2488 | * @param result_af desired address family; set to the actual | ||
2489 | * address family; can initially be AF_UNSPEC if there | ||
2490 | * is no preference; will be set to AF_UNSPEC if the | ||
2491 | * allocation failed | ||
2492 | * @param addr set to either v4 or v6 depending on which | ||
2493 | * storage location was used; set to NULL if allocation failed | ||
2494 | * @param v4 storage space for an IPv4 address | ||
2495 | * @param v6 storage space for an IPv6 address | ||
2496 | * @return GNUNET_OK normally, GNUNET_SYSERR if '*result_af' was | ||
2497 | * an unsupported address family (not AF_INET, AF_INET6 or AF_UNSPEC) | ||
2498 | */ | ||
2499 | static int | ||
2500 | allocate_response_ip (int *result_af, | ||
2501 | void **addr, | ||
2502 | struct in_addr *v4, | ||
2503 | struct in6_addr *v6) | ||
2504 | { | ||
2505 | *addr = NULL; | ||
2506 | switch (*result_af) | ||
2507 | { | ||
2508 | case AF_INET: | ||
2509 | if (GNUNET_OK != | ||
2510 | allocate_v4_address (v4)) | ||
2511 | *result_af = AF_UNSPEC; | ||
2512 | else | ||
2513 | *addr = v4; | ||
2514 | break; | ||
2515 | case AF_INET6: | ||
2516 | if (GNUNET_OK != | ||
2517 | allocate_v6_address (v6)) | ||
2518 | *result_af = AF_UNSPEC; | ||
2519 | else | ||
2520 | *addr = v6; | ||
2521 | break; | ||
2522 | case AF_UNSPEC: | ||
2523 | if (GNUNET_OK == | ||
2524 | allocate_v4_address (v4)) | ||
2525 | { | ||
2526 | *addr = v4; | ||
2527 | *result_af = AF_INET; | ||
2528 | } | ||
2529 | else if (GNUNET_OK == | ||
2530 | allocate_v6_address (v6)) | ||
2531 | { | ||
2532 | *addr = v6; | ||
2533 | *result_af = AF_INET6; | ||
2534 | } | ||
2535 | break; | ||
2536 | default: | ||
2537 | GNUNET_break (0); | ||
2538 | return GNUNET_SYSERR; | ||
2539 | } | ||
2540 | return GNUNET_OK; | ||
2541 | } | ||
2542 | |||
2543 | |||
2544 | /** | ||
2486 | * A client asks us to setup a redirection via some exit | 2545 | * A client asks us to setup a redirection via some exit |
2487 | * node to a particular IP. Setup the redirection and | 2546 | * node to a particular IP. Setup the redirection and |
2488 | * give the client the allocated IP. | 2547 | * give the client the allocated IP. |
@@ -2543,40 +2602,11 @@ service_redirect_to_ip (void *cls GNUNET_UNUSED, struct GNUNET_SERVER_Client *cl | |||
2543 | } | 2602 | } |
2544 | 2603 | ||
2545 | /* allocate response IP */ | 2604 | /* allocate response IP */ |
2546 | addr = NULL; | ||
2547 | result_af = (int) htonl (msg->result_af); | 2605 | result_af = (int) htonl (msg->result_af); |
2548 | switch (result_af) | 2606 | if (GNUNET_OK != allocate_response_ip (&result_af, |
2607 | &addr, | ||
2608 | &v4, &v6)) | ||
2549 | { | 2609 | { |
2550 | case AF_INET: | ||
2551 | if (GNUNET_OK != | ||
2552 | allocate_v4_address (&v4)) | ||
2553 | result_af = AF_UNSPEC; | ||
2554 | else | ||
2555 | addr = &v4; | ||
2556 | break; | ||
2557 | case AF_INET6: | ||
2558 | if (GNUNET_OK != | ||
2559 | allocate_v6_address (&v6)) | ||
2560 | result_af = AF_UNSPEC; | ||
2561 | else | ||
2562 | addr = &v6; | ||
2563 | break; | ||
2564 | case AF_UNSPEC: | ||
2565 | if (GNUNET_OK == | ||
2566 | allocate_v4_address (&v4)) | ||
2567 | { | ||
2568 | addr = &v4; | ||
2569 | result_af = AF_INET; | ||
2570 | } | ||
2571 | else if (GNUNET_OK == | ||
2572 | allocate_v6_address (&v6)) | ||
2573 | { | ||
2574 | addr = &v6; | ||
2575 | result_af = AF_INET6; | ||
2576 | } | ||
2577 | break; | ||
2578 | default: | ||
2579 | GNUNET_break (0); | ||
2580 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 2610 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2581 | return; | 2611 | return; |
2582 | } | 2612 | } |
@@ -2679,40 +2709,11 @@ service_redirect_to_service (void *cls GNUNET_UNUSED, struct GNUNET_SERVER_Clien | |||
2679 | msg = (const struct RedirectToServiceRequestMessage *) message; | 2709 | msg = (const struct RedirectToServiceRequestMessage *) message; |
2680 | 2710 | ||
2681 | /* allocate response IP */ | 2711 | /* allocate response IP */ |
2682 | addr = NULL; | ||
2683 | result_af = (int) htonl (msg->result_af); | 2712 | result_af = (int) htonl (msg->result_af); |
2684 | switch (result_af) | 2713 | if (GNUNET_OK != allocate_response_ip (&result_af, |
2714 | &addr, | ||
2715 | &v4, &v6)) | ||
2685 | { | 2716 | { |
2686 | case AF_INET: | ||
2687 | if (GNUNET_OK != | ||
2688 | allocate_v4_address (&v4)) | ||
2689 | result_af = AF_UNSPEC; | ||
2690 | else | ||
2691 | addr = &v4; | ||
2692 | break; | ||
2693 | case AF_INET6: | ||
2694 | if (GNUNET_OK != | ||
2695 | allocate_v6_address (&v6)) | ||
2696 | result_af = AF_UNSPEC; | ||
2697 | else | ||
2698 | addr = &v6; | ||
2699 | break; | ||
2700 | case AF_UNSPEC: | ||
2701 | if (GNUNET_OK == | ||
2702 | allocate_v4_address (&v4)) | ||
2703 | { | ||
2704 | addr = &v4; | ||
2705 | result_af = AF_INET; | ||
2706 | } | ||
2707 | else if (GNUNET_OK == | ||
2708 | allocate_v6_address (&v6)) | ||
2709 | { | ||
2710 | addr = &v6; | ||
2711 | result_af = AF_INET6; | ||
2712 | } | ||
2713 | break; | ||
2714 | default: | ||
2715 | GNUNET_break (0); | ||
2716 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 2717 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2717 | return; | 2718 | return; |
2718 | } | 2719 | } |