diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-10-06 20:55:28 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-10-06 20:55:28 +0000 |
commit | 61c39c60565b386e0e12ea669556b030e8cd7180 (patch) | |
tree | 59109aeab8297bdc996faca8c4e38ec7426c36cf /src/vpn | |
parent | 780eb09dd8040ecf8649d40ddf8314464e0fc48e (diff) | |
download | gnunet-61c39c60565b386e0e12ea669556b030e8cd7180.tar.gz gnunet-61c39c60565b386e0e12ea669556b030e8cd7180.zip |
-remove trailing whitespace
Diffstat (limited to 'src/vpn')
-rw-r--r-- | src/vpn/gnunet-helper-vpn-windows.c | 234 | ||||
-rw-r--r-- | src/vpn/gnunet-helper-vpn.c | 2 | ||||
-rw-r--r-- | src/vpn/gnunet-service-vpn.c | 258 | ||||
-rw-r--r-- | src/vpn/gnunet-vpn.c | 10 | ||||
-rw-r--r-- | src/vpn/vpn.h | 12 | ||||
-rw-r--r-- | src/vpn/vpn_api.c | 34 |
6 files changed, 275 insertions, 275 deletions
diff --git a/src/vpn/gnunet-helper-vpn-windows.c b/src/vpn/gnunet-helper-vpn-windows.c index 15dc5a667..3f4920a6f 100644 --- a/src/vpn/gnunet-helper-vpn-windows.c +++ b/src/vpn/gnunet-helper-vpn-windows.c | |||
@@ -19,8 +19,8 @@ | |||
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file vpn/gnunet-helper-vpn-windows.c | 21 | * @file vpn/gnunet-helper-vpn-windows.c |
22 | * @brief the helper for the VPN service in win32 builds. | 22 | * @brief the helper for the VPN service in win32 builds. |
23 | * Opens a virtual network-interface, sends data received on the if to stdout, | 23 | * Opens a virtual network-interface, sends data received on the if to stdout, |
24 | * sends data received on stdin to the interface | 24 | * sends data received on stdin to the interface |
25 | * @author Christian M. Fuchs | 25 | * @author Christian M. Fuchs |
26 | * | 26 | * |
@@ -68,7 +68,7 @@ | |||
68 | #endif | 68 | #endif |
69 | 69 | ||
70 | /** | 70 | /** |
71 | * Will this binary be run in permissions testing mode? | 71 | * Will this binary be run in permissions testing mode? |
72 | */ | 72 | */ |
73 | static boolean privilege_testing = FALSE; | 73 | static boolean privilege_testing = FALSE; |
74 | 74 | ||
@@ -90,7 +90,7 @@ static boolean privilege_testing = FALSE; | |||
90 | #define INF_FILE64 "share/gnunet/openvpn-tap32/tapw64/OemWin2k.inf" | 90 | #define INF_FILE64 "share/gnunet/openvpn-tap32/tapw64/OemWin2k.inf" |
91 | 91 | ||
92 | /** | 92 | /** |
93 | * Hardware ID used in the inf-file. | 93 | * Hardware ID used in the inf-file. |
94 | * This might change over time, as openvpn advances their driver | 94 | * This might change over time, as openvpn advances their driver |
95 | */ | 95 | */ |
96 | #define HARDWARE_ID "tap0901" | 96 | #define HARDWARE_ID "tap0901" |
@@ -101,7 +101,7 @@ static boolean privilege_testing = FALSE; | |||
101 | #define TAP_WIN_MIN_MAJOR 9 | 101 | #define TAP_WIN_MIN_MAJOR 9 |
102 | 102 | ||
103 | /** | 103 | /** |
104 | * Minimum minor-id of the driver version we can work with. | 104 | * Minimum minor-id of the driver version we can work with. |
105 | * v <= 7 has buggy IPv6. | 105 | * v <= 7 has buggy IPv6. |
106 | * v == 8 is broken for small IPv4 Packets | 106 | * v == 8 is broken for small IPv4 Packets |
107 | */ | 107 | */ |
@@ -109,7 +109,7 @@ static boolean privilege_testing = FALSE; | |||
109 | 109 | ||
110 | /** | 110 | /** |
111 | * Time in seconds to wait for our virtual device to go up after telling it to do so. | 111 | * Time in seconds to wait for our virtual device to go up after telling it to do so. |
112 | * | 112 | * |
113 | * openvpn doesn't specify a value, 4 seems sane for testing, even for openwrt | 113 | * openvpn doesn't specify a value, 4 seems sane for testing, even for openwrt |
114 | * (in fact, 4 was chosen by a fair dice roll...) | 114 | * (in fact, 4 was chosen by a fair dice roll...) |
115 | */ | 115 | */ |
@@ -121,7 +121,7 @@ static boolean privilege_testing = FALSE; | |||
121 | #define INTERFACE_REGISTRY_LOCATION "SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}" | 121 | #define INTERFACE_REGISTRY_LOCATION "SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}" |
122 | 122 | ||
123 | /** | 123 | /** |
124 | * Our local process' PID. Used for creating a sufficiently unique additional | 124 | * Our local process' PID. Used for creating a sufficiently unique additional |
125 | * hardware ID for our device. | 125 | * hardware ID for our device. |
126 | */ | 126 | */ |
127 | static char secondary_hwid[LINE_LEN / 2]; | 127 | static char secondary_hwid[LINE_LEN / 2]; |
@@ -132,13 +132,13 @@ static char secondary_hwid[LINE_LEN / 2]; | |||
132 | */ | 132 | */ |
133 | static char device_visible_name[256]; | 133 | static char device_visible_name[256]; |
134 | 134 | ||
135 | /** | 135 | /** |
136 | * This is our own local instance of a virtual network interface | 136 | * This is our own local instance of a virtual network interface |
137 | * It is (somewhat) equivalent to using tun/tap in unixoid systems | 137 | * It is (somewhat) equivalent to using tun/tap in unixoid systems |
138 | * | 138 | * |
139 | * Upon initialization, we create such an device node. | 139 | * Upon initialization, we create such an device node. |
140 | * Upon termination, we remove it again. | 140 | * Upon termination, we remove it again. |
141 | * | 141 | * |
142 | * If we crash this device might stay around. | 142 | * If we crash this device might stay around. |
143 | */ | 143 | */ |
144 | static HDEVINFO DeviceInfo = INVALID_HANDLE_VALUE; | 144 | static HDEVINFO DeviceInfo = INVALID_HANDLE_VALUE; |
@@ -149,7 +149,7 @@ static HDEVINFO DeviceInfo = INVALID_HANDLE_VALUE; | |||
149 | static SP_DEVINFO_DATA DeviceNode; | 149 | static SP_DEVINFO_DATA DeviceNode; |
150 | 150 | ||
151 | /** | 151 | /** |
152 | * GUID of our virtual device in the form of | 152 | * GUID of our virtual device in the form of |
153 | * {12345678-1234-1234-1234-123456789abc} - in hex | 153 | * {12345678-1234-1234-1234-123456789abc} - in hex |
154 | */ | 154 | */ |
155 | static char device_guid[256]; | 155 | static char device_guid[256]; |
@@ -161,36 +161,36 @@ static char device_guid[256]; | |||
161 | enum IO_State | 161 | enum IO_State |
162 | { | 162 | { |
163 | 163 | ||
164 | /** | 164 | /** |
165 | * overlapped I/O is ready for work | 165 | * overlapped I/O is ready for work |
166 | */ | 166 | */ |
167 | IOSTATE_READY = 0, | 167 | IOSTATE_READY = 0, |
168 | 168 | ||
169 | /** | 169 | /** |
170 | * overlapped I/O has been queued | 170 | * overlapped I/O has been queued |
171 | */ | 171 | */ |
172 | IOSTATE_QUEUED, | 172 | IOSTATE_QUEUED, |
173 | 173 | ||
174 | /** | 174 | /** |
175 | * overlapped I/O has finished, but is waiting for it's write-partner | 175 | * overlapped I/O has finished, but is waiting for it's write-partner |
176 | */ | 176 | */ |
177 | IOSTATE_WAITING, | 177 | IOSTATE_WAITING, |
178 | 178 | ||
179 | /** | 179 | /** |
180 | * there is a full buffer waiting | 180 | * there is a full buffer waiting |
181 | */ | 181 | */ |
182 | IOSTATE_RESUME, | 182 | IOSTATE_RESUME, |
183 | 183 | ||
184 | /** | 184 | /** |
185 | * Operlapped IO states for facility objects | 185 | * Operlapped IO states for facility objects |
186 | * overlapped I/O has failed, stop processing | 186 | * overlapped I/O has failed, stop processing |
187 | */ | 187 | */ |
188 | IOSTATE_FAILED | 188 | IOSTATE_FAILED |
189 | 189 | ||
190 | }; | 190 | }; |
191 | 191 | ||
192 | 192 | ||
193 | /** | 193 | /** |
194 | * A IO Object + read/writebuffer + buffer-size for windows asynchronous IO handling | 194 | * A IO Object + read/writebuffer + buffer-size for windows asynchronous IO handling |
195 | */ | 195 | */ |
196 | struct io_facility | 196 | struct io_facility |
@@ -229,7 +229,7 @@ struct io_facility | |||
229 | * Amount of data actually written or read by readfile/writefile. | 229 | * Amount of data actually written or read by readfile/writefile. |
230 | */ | 230 | */ |
231 | DWORD buffer_size_processed; | 231 | DWORD buffer_size_processed; |
232 | 232 | ||
233 | /** | 233 | /** |
234 | * How much of this buffer we have writte in total | 234 | * How much of this buffer we have writte in total |
235 | */ | 235 | */ |
@@ -248,32 +248,32 @@ typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL); | |||
248 | 248 | ||
249 | /** | 249 | /** |
250 | * Determines if the host OS is win32 or win64 | 250 | * Determines if the host OS is win32 or win64 |
251 | * | 251 | * |
252 | * @return true if | 252 | * @return true if |
253 | */ | 253 | */ |
254 | BOOL | 254 | BOOL |
255 | is_win64 () | 255 | is_win64 () |
256 | { | 256 | { |
257 | #if defined(_WIN64) | 257 | #if defined(_WIN64) |
258 | //this is a win64 binary, | 258 | //this is a win64 binary, |
259 | return TRUE; | 259 | return TRUE; |
260 | #elif defined(_WIN32) | 260 | #elif defined(_WIN32) |
261 | //this is a 32bit binary, and we need to check if we are running in WOW64 | 261 | //this is a 32bit binary, and we need to check if we are running in WOW64 |
262 | BOOL success = FALSE; | 262 | BOOL success = FALSE; |
263 | BOOL on_wow64 = FALSE; | 263 | BOOL on_wow64 = FALSE; |
264 | LPFN_ISWOW64PROCESS IsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress (GetModuleHandle ("kernel32"), "IsWow64Process"); | 264 | LPFN_ISWOW64PROCESS IsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress (GetModuleHandle ("kernel32"), "IsWow64Process"); |
265 | 265 | ||
266 | if (NULL != IsWow64Process) | 266 | if (NULL != IsWow64Process) |
267 | success = IsWow64Process (GetCurrentProcess (), &on_wow64); | 267 | success = IsWow64Process (GetCurrentProcess (), &on_wow64); |
268 | 268 | ||
269 | return success && on_wow64; | 269 | return success && on_wow64; |
270 | #endif | 270 | #endif |
271 | } | 271 | } |
272 | /** | 272 | /** |
273 | * Wrapper for executing a shellcommand in windows. | 273 | * Wrapper for executing a shellcommand in windows. |
274 | * | 274 | * |
275 | * @param command - the command + parameters to execute | 275 | * @param command - the command + parameters to execute |
276 | * @return * exitcode of the program executed, | 276 | * @return * exitcode of the program executed, |
277 | * * EINVAL (cmd/file not found) | 277 | * * EINVAL (cmd/file not found) |
278 | * * EPIPE (could not read STDOUT) | 278 | * * EPIPE (could not read STDOUT) |
279 | */ | 279 | */ |
@@ -365,7 +365,7 @@ remove_address6 (const char *address) | |||
365 | 365 | ||
366 | /* Did it work?*/ | 366 | /* Did it work?*/ |
367 | if (0 != ret) | 367 | if (0 != ret) |
368 | fprintf (stderr, | 368 | fprintf (stderr, |
369 | "FATAL: removing IPv6 address failed: %s\n", | 369 | "FATAL: removing IPv6 address failed: %s\n", |
370 | strerror (ret)); | 370 | strerror (ret)); |
371 | } | 371 | } |
@@ -410,8 +410,8 @@ set_address4 (const char *address, const char *mask) | |||
410 | 410 | ||
411 | /* Did it work?*/ | 411 | /* Did it work?*/ |
412 | if (0 != ret) | 412 | if (0 != ret) |
413 | fprintf (stderr, | 413 | fprintf (stderr, |
414 | "FATAL: Setting IPv4 address failed: %s\n", | 414 | "FATAL: Setting IPv4 address failed: %s\n", |
415 | strerror (ret)); | 415 | strerror (ret)); |
416 | return ret; | 416 | return ret; |
417 | } | 417 | } |
@@ -448,8 +448,8 @@ remove_address4 (const char *address) | |||
448 | 448 | ||
449 | 449 | ||
450 | /** | 450 | /** |
451 | * Setup a new virtual interface to use for tunneling. | 451 | * Setup a new virtual interface to use for tunneling. |
452 | * | 452 | * |
453 | * @return: TRUE if setup was successful, else FALSE | 453 | * @return: TRUE if setup was successful, else FALSE |
454 | */ | 454 | */ |
455 | static BOOL | 455 | static BOOL |
@@ -457,7 +457,7 @@ setup_interface () | |||
457 | { | 457 | { |
458 | /* | 458 | /* |
459 | * where to find our inf-file. (+ the "full" path, after windows found") | 459 | * where to find our inf-file. (+ the "full" path, after windows found") |
460 | * | 460 | * |
461 | * We do not directly input all the props here, because openvpn will update | 461 | * We do not directly input all the props here, because openvpn will update |
462 | * these details over time. | 462 | * these details over time. |
463 | */ | 463 | */ |
@@ -468,22 +468,22 @@ setup_interface () | |||
468 | GUID class_guid; | 468 | GUID class_guid; |
469 | int str_length = 0; | 469 | int str_length = 0; |
470 | 470 | ||
471 | /** | 471 | /** |
472 | * Set the device's hardware ID and add it to a list. | 472 | * Set the device's hardware ID and add it to a list. |
473 | * This information will later on identify this device in registry. | 473 | * This information will later on identify this device in registry. |
474 | */ | 474 | */ |
475 | strncpy (hwidlist, HARDWARE_ID, LINE_LEN); | 475 | strncpy (hwidlist, HARDWARE_ID, LINE_LEN); |
476 | /** | 476 | /** |
477 | * this is kind of over-complicated, but allows keeps things independent of | 477 | * this is kind of over-complicated, but allows keeps things independent of |
478 | * how the openvpn-hwid is actually stored. | 478 | * how the openvpn-hwid is actually stored. |
479 | * | 479 | * |
480 | * A HWID list is double-\0 terminated and \0 separated | 480 | * A HWID list is double-\0 terminated and \0 separated |
481 | */ | 481 | */ |
482 | str_length = strlen (hwidlist) + 1; | 482 | str_length = strlen (hwidlist) + 1; |
483 | strncpy (&hwidlist[str_length], secondary_hwid, LINE_LEN); | 483 | strncpy (&hwidlist[str_length], secondary_hwid, LINE_LEN); |
484 | str_length += strlen (&hwidlist[str_length]) + 1; | 484 | str_length += strlen (&hwidlist[str_length]) + 1; |
485 | 485 | ||
486 | /** | 486 | /** |
487 | * Locate the inf-file, we need to store it somewhere where the system can | 487 | * Locate the inf-file, we need to store it somewhere where the system can |
488 | * find it. We need to pick the correct driver for win32/win64. | 488 | * find it. We need to pick the correct driver for win32/win64. |
489 | */ | 489 | */ |
@@ -493,7 +493,7 @@ setup_interface () | |||
493 | GetFullPathNameA (INF_FILE, MAX_PATH, inf_file_path, &temp_inf_filename); | 493 | GetFullPathNameA (INF_FILE, MAX_PATH, inf_file_path, &temp_inf_filename); |
494 | 494 | ||
495 | fprintf (stderr, "INFO: Located our driver's .inf file at %s\n", inf_file_path); | 495 | fprintf (stderr, "INFO: Located our driver's .inf file at %s\n", inf_file_path); |
496 | /** | 496 | /** |
497 | * Bootstrap our device info using the drivers inf-file | 497 | * Bootstrap our device info using the drivers inf-file |
498 | */ | 498 | */ |
499 | if ( ! SetupDiGetINFClassA (inf_file_path, | 499 | if ( ! SetupDiGetINFClassA (inf_file_path, |
@@ -502,9 +502,9 @@ setup_interface () | |||
502 | NULL)) | 502 | NULL)) |
503 | return FALSE; | 503 | return FALSE; |
504 | 504 | ||
505 | /** | 505 | /** |
506 | * Collect all the other needed information... | 506 | * Collect all the other needed information... |
507 | * let the system fill our this form | 507 | * let the system fill our this form |
508 | */ | 508 | */ |
509 | DeviceInfo = SetupDiCreateDeviceInfoList (&class_guid, NULL); | 509 | DeviceInfo = SetupDiCreateDeviceInfoList (&class_guid, NULL); |
510 | if (DeviceInfo == INVALID_HANDLE_VALUE) | 510 | if (DeviceInfo == INVALID_HANDLE_VALUE) |
@@ -549,9 +549,9 @@ setup_interface () | |||
549 | 549 | ||
550 | 550 | ||
551 | /** | 551 | /** |
552 | * Remove our new virtual interface to use for tunneling. | 552 | * Remove our new virtual interface to use for tunneling. |
553 | * This function must be called AFTER setup_interface! | 553 | * This function must be called AFTER setup_interface! |
554 | * | 554 | * |
555 | * @return: TRUE if destruction was successful, else FALSE | 555 | * @return: TRUE if destruction was successful, else FALSE |
556 | */ | 556 | */ |
557 | static BOOL | 557 | static BOOL |
@@ -567,7 +567,7 @@ remove_interface () | |||
567 | remove.Scope = DI_REMOVEDEVICE_GLOBAL; | 567 | remove.Scope = DI_REMOVEDEVICE_GLOBAL; |
568 | remove.ClassInstallHeader.InstallFunction = DIF_REMOVE; | 568 | remove.ClassInstallHeader.InstallFunction = DIF_REMOVE; |
569 | /* | 569 | /* |
570 | * 1. Prepare our existing device information set, and place the | 570 | * 1. Prepare our existing device information set, and place the |
571 | * uninstall related information into the structure | 571 | * uninstall related information into the structure |
572 | */ | 572 | */ |
573 | if ( ! SetupDiSetClassInstallParamsA (DeviceInfo, | 573 | if ( ! SetupDiSetClassInstallParamsA (DeviceInfo, |
@@ -584,7 +584,7 @@ remove_interface () | |||
584 | return FALSE; | 584 | return FALSE; |
585 | 585 | ||
586 | SetupDiDestroyDeviceInfoList (DeviceInfo); | 586 | SetupDiDestroyDeviceInfoList (DeviceInfo); |
587 | 587 | ||
588 | fprintf (stderr, "DEBUG: removed interface successfully\n"); | 588 | fprintf (stderr, "DEBUG: removed interface successfully\n"); |
589 | 589 | ||
590 | return TRUE; | 590 | return TRUE; |
@@ -593,8 +593,8 @@ remove_interface () | |||
593 | 593 | ||
594 | /** | 594 | /** |
595 | * Do all the lookup necessary to retrieve the inteface's actual name | 595 | * Do all the lookup necessary to retrieve the inteface's actual name |
596 | * off the registry. | 596 | * off the registry. |
597 | * | 597 | * |
598 | * @return: TRUE if we were able to lookup the interface's name, else FALSE | 598 | * @return: TRUE if we were able to lookup the interface's name, else FALSE |
599 | */ | 599 | */ |
600 | static BOOL | 600 | static BOOL |
@@ -618,7 +618,7 @@ resolve_interface_name () | |||
618 | 0, //must be 0 | 618 | 0, //must be 0 |
619 | NULL)) //hMachine, we are local | 619 | NULL)) //hMachine, we are local |
620 | return FALSE; | 620 | return FALSE; |
621 | 621 | ||
622 | fprintf (stderr, "DEBUG: Resolving interface name for network device %s\n",pnp_instance_id); | 622 | fprintf (stderr, "DEBUG: Resolving interface name for network device %s\n",pnp_instance_id); |
623 | 623 | ||
624 | /* Registry is incredibly slow, retry for up to 30 seconds to allow registry to refresh */ | 624 | /* Registry is incredibly slow, retry for up to 30 seconds to allow registry to refresh */ |
@@ -636,7 +636,7 @@ resolve_interface_name () | |||
636 | &adapter_key_handle)) | 636 | &adapter_key_handle)) |
637 | return FALSE; | 637 | return FALSE; |
638 | 638 | ||
639 | /* Of course there is a multitude of entries here, with arbitrary names, | 639 | /* Of course there is a multitude of entries here, with arbitrary names, |
640 | * thus we need to iterate through there. | 640 | * thus we need to iterate through there. |
641 | */ | 641 | */ |
642 | while (!retval) | 642 | while (!retval) |
@@ -661,7 +661,7 @@ resolve_interface_name () | |||
661 | NULL, | 661 | NULL, |
662 | NULL); | 662 | NULL); |
663 | 663 | ||
664 | /* this may fail due to one of two reasons: | 664 | /* this may fail due to one of two reasons: |
665 | * we are at the end of the list*/ | 665 | * we are at the end of the list*/ |
666 | if (ERROR_NO_MORE_ITEMS == status) | 666 | if (ERROR_NO_MORE_ITEMS == status) |
667 | break; | 667 | break; |
@@ -712,8 +712,8 @@ resolve_interface_name () | |||
712 | if (status != ERROR_SUCCESS || data_type != REG_SZ) | 712 | if (status != ERROR_SUCCESS || data_type != REG_SZ) |
713 | goto cleanup; | 713 | goto cleanup; |
714 | 714 | ||
715 | /* | 715 | /* |
716 | * we have successfully found OUR instance, | 716 | * we have successfully found OUR instance, |
717 | * save the device GUID before exiting | 717 | * save the device GUID before exiting |
718 | */ | 718 | */ |
719 | 719 | ||
@@ -735,7 +735,7 @@ cleanup: | |||
735 | 735 | ||
736 | /** | 736 | /** |
737 | * Determines the version of the installed TAP32 driver and checks if it's sufficiently new for GNUNET | 737 | * Determines the version of the installed TAP32 driver and checks if it's sufficiently new for GNUNET |
738 | * | 738 | * |
739 | * @param handle the handle to our tap device | 739 | * @param handle the handle to our tap device |
740 | * @return TRUE if the version is sufficient, else FALSE | 740 | * @return TRUE if the version is sufficient, else FALSE |
741 | */ | 741 | */ |
@@ -761,7 +761,7 @@ check_tapw32_version (HANDLE handle) | |||
761 | TAP_WIN_MIN_MINOR); | 761 | TAP_WIN_MIN_MINOR); |
762 | return FALSE; | 762 | return FALSE; |
763 | } | 763 | } |
764 | 764 | ||
765 | return TRUE; | 765 | return TRUE; |
766 | } | 766 | } |
767 | 767 | ||
@@ -827,8 +827,8 @@ init_tun () | |||
827 | 827 | ||
828 | /** | 828 | /** |
829 | * Brings a TAP device up and sets it to connected state. | 829 | * Brings a TAP device up and sets it to connected state. |
830 | * | 830 | * |
831 | * @param handle the handle to our TAP device | 831 | * @param handle the handle to our TAP device |
832 | * @return True if the operation succeeded, else false | 832 | * @return True if the operation succeeded, else false |
833 | */ | 833 | */ |
834 | static BOOL | 834 | static BOOL |
@@ -854,25 +854,25 @@ tun_up (HANDLE handle) | |||
854 | 854 | ||
855 | /** | 855 | /** |
856 | * Attempts to read off an input facility (tap or named pipe) in overlapped mode. | 856 | * Attempts to read off an input facility (tap or named pipe) in overlapped mode. |
857 | * | 857 | * |
858 | * 1. | 858 | * 1. |
859 | * If the input facility is in IOSTATE_READY, it will issue a new read operation to the | 859 | * If the input facility is in IOSTATE_READY, it will issue a new read operation to the |
860 | * input handle. Then it goes into IOSTATE_QUEUED state. | 860 | * input handle. Then it goes into IOSTATE_QUEUED state. |
861 | * In case the read succeeded instantly the input facility enters 3. | 861 | * In case the read succeeded instantly the input facility enters 3. |
862 | * | 862 | * |
863 | * 2. | 863 | * 2. |
864 | * If the input facility is in IOSTATE_QUEUED state, it will check if the queued read has finished already. | 864 | * If the input facility is in IOSTATE_QUEUED state, it will check if the queued read has finished already. |
865 | * If it has finished, go to state 3. | 865 | * If it has finished, go to state 3. |
866 | * If it has failed, set IOSTATE_FAILED | 866 | * If it has failed, set IOSTATE_FAILED |
867 | * | 867 | * |
868 | * 3. | 868 | * 3. |
869 | * If the output facility is in state IOSTATE_READY, the read-buffer is copied to the output buffer. | 869 | * If the output facility is in state IOSTATE_READY, the read-buffer is copied to the output buffer. |
870 | * The input facility enters state IOSTATE_READY | 870 | * The input facility enters state IOSTATE_READY |
871 | * The output facility enters state IOSTATE_READY | 871 | * The output facility enters state IOSTATE_READY |
872 | * If the output facility is in state IOSTATE_QUEUED, the input facility enters IOSTATE_WAITING | 872 | * If the output facility is in state IOSTATE_QUEUED, the input facility enters IOSTATE_WAITING |
873 | * | 873 | * |
874 | * IOSTATE_WAITING is reset by the output facility, once it has completed. | 874 | * IOSTATE_WAITING is reset by the output facility, once it has completed. |
875 | * | 875 | * |
876 | * @param input_facility input named pipe or file to work with. | 876 | * @param input_facility input named pipe or file to work with. |
877 | * @param output_facility output pipe or file to hand over data to. | 877 | * @param output_facility output pipe or file to hand over data to. |
878 | * @return false if an event reset was impossible (OS error), else true | 878 | * @return false if an event reset was impossible (OS error), else true |
@@ -883,11 +883,11 @@ attempt_read_tap (struct io_facility * input_facility, | |||
883 | { | 883 | { |
884 | struct GNUNET_MessageHeader * hdr; | 884 | struct GNUNET_MessageHeader * hdr; |
885 | unsigned short size; | 885 | unsigned short size; |
886 | 886 | ||
887 | switch (input_facility->facility_state) | 887 | switch (input_facility->facility_state) |
888 | { | 888 | { |
889 | case IOSTATE_READY: | 889 | case IOSTATE_READY: |
890 | { | 890 | { |
891 | if (! ResetEvent (input_facility->overlapped.hEvent)) | 891 | if (! ResetEvent (input_facility->overlapped.hEvent)) |
892 | { | 892 | { |
893 | return FALSE; | 893 | return FALSE; |
@@ -906,9 +906,9 @@ attempt_read_tap (struct io_facility * input_facility, | |||
906 | /* reset event manually*/ | 906 | /* reset event manually*/ |
907 | if (! SetEvent (input_facility->overlapped.hEvent)) | 907 | if (! SetEvent (input_facility->overlapped.hEvent)) |
908 | return FALSE; | 908 | return FALSE; |
909 | 909 | ||
910 | fprintf (stderr, "DEBUG: tap read succeeded immediately\n"); | 910 | fprintf (stderr, "DEBUG: tap read succeeded immediately\n"); |
911 | 911 | ||
912 | /* we successfully read something from the TAP and now need to | 912 | /* we successfully read something from the TAP and now need to |
913 | * send it our via STDOUT. Is that possible at the moment? */ | 913 | * send it our via STDOUT. Is that possible at the moment? */ |
914 | if ((IOSTATE_READY == output_facility->facility_state || | 914 | if ((IOSTATE_READY == output_facility->facility_state || |
@@ -917,7 +917,7 @@ attempt_read_tap (struct io_facility * input_facility, | |||
917 | { /* hand over this buffers content and apply message header for gnunet */ | 917 | { /* hand over this buffers content and apply message header for gnunet */ |
918 | hdr = (struct GNUNET_MessageHeader *) output_facility->buffer; | 918 | hdr = (struct GNUNET_MessageHeader *) output_facility->buffer; |
919 | size = input_facility->buffer_size + sizeof (struct GNUNET_MessageHeader); | 919 | size = input_facility->buffer_size + sizeof (struct GNUNET_MessageHeader); |
920 | 920 | ||
921 | memcpy (output_facility->buffer + sizeof (struct GNUNET_MessageHeader), | 921 | memcpy (output_facility->buffer + sizeof (struct GNUNET_MessageHeader), |
922 | input_facility->buffer, | 922 | input_facility->buffer, |
923 | input_facility->buffer_size); | 923 | input_facility->buffer_size); |
@@ -964,7 +964,7 @@ attempt_read_tap (struct io_facility * input_facility, | |||
964 | return FALSE; | 964 | return FALSE; |
965 | 965 | ||
966 | fprintf (stderr, "DEBUG: tap read succeeded delayed\n"); | 966 | fprintf (stderr, "DEBUG: tap read succeeded delayed\n"); |
967 | 967 | ||
968 | /* we successfully read something from the TAP and now need to | 968 | /* we successfully read something from the TAP and now need to |
969 | * send it our via STDOUT. Is that possible at the moment? */ | 969 | * send it our via STDOUT. Is that possible at the moment? */ |
970 | if ((IOSTATE_READY == output_facility->facility_state || | 970 | if ((IOSTATE_READY == output_facility->facility_state || |
@@ -973,7 +973,7 @@ attempt_read_tap (struct io_facility * input_facility, | |||
973 | { /* hand over this buffers content and apply message header for gnunet */ | 973 | { /* hand over this buffers content and apply message header for gnunet */ |
974 | hdr = (struct GNUNET_MessageHeader *) output_facility->buffer; | 974 | hdr = (struct GNUNET_MessageHeader *) output_facility->buffer; |
975 | size = input_facility->buffer_size + sizeof (struct GNUNET_MessageHeader); | 975 | size = input_facility->buffer_size + sizeof (struct GNUNET_MessageHeader); |
976 | 976 | ||
977 | memcpy (output_facility->buffer + sizeof (struct GNUNET_MessageHeader), | 977 | memcpy (output_facility->buffer + sizeof (struct GNUNET_MessageHeader), |
978 | input_facility->buffer, | 978 | input_facility->buffer, |
979 | input_facility->buffer_size); | 979 | input_facility->buffer_size); |
@@ -1026,26 +1026,26 @@ attempt_read_tap (struct io_facility * input_facility, | |||
1026 | 1026 | ||
1027 | /** | 1027 | /** |
1028 | * Attempts to read off an input facility (tap or named pipe) in overlapped mode. | 1028 | * Attempts to read off an input facility (tap or named pipe) in overlapped mode. |
1029 | * | 1029 | * |
1030 | * 1. | 1030 | * 1. |
1031 | * If the input facility is in IOSTATE_READY, it will issue a new read operation to the | 1031 | * If the input facility is in IOSTATE_READY, it will issue a new read operation to the |
1032 | * input handle. Then it goes into IOSTATE_QUEUED state. | 1032 | * input handle. Then it goes into IOSTATE_QUEUED state. |
1033 | * In case the read succeeded instantly the input facility enters 3. | 1033 | * In case the read succeeded instantly the input facility enters 3. |
1034 | * | 1034 | * |
1035 | * 2. | 1035 | * 2. |
1036 | * If the input facility is in IOSTATE_QUEUED state, it will check if the queued read has finished already. | 1036 | * If the input facility is in IOSTATE_QUEUED state, it will check if the queued read has finished already. |
1037 | * If it has finished, go to state 3. | 1037 | * If it has finished, go to state 3. |
1038 | * If it has failed, set IOSTATE_FAILED | 1038 | * If it has failed, set IOSTATE_FAILED |
1039 | * | 1039 | * |
1040 | * 3. | 1040 | * 3. |
1041 | * If the facility is finished with ready | 1041 | * If the facility is finished with ready |
1042 | * The read-buffer is copied to the output buffer, except for the GNUNET_MessageHeader. | 1042 | * The read-buffer is copied to the output buffer, except for the GNUNET_MessageHeader. |
1043 | * The input facility enters state IOSTATE_READY | 1043 | * The input facility enters state IOSTATE_READY |
1044 | * The output facility enters state IOSTATE_READY | 1044 | * The output facility enters state IOSTATE_READY |
1045 | * If the output facility is in state IOSTATE_QUEUED, the input facility enters IOSTATE_WAITING | 1045 | * If the output facility is in state IOSTATE_QUEUED, the input facility enters IOSTATE_WAITING |
1046 | * | 1046 | * |
1047 | * IOSTATE_WAITING is reset by the output facility, once it has completed. | 1047 | * IOSTATE_WAITING is reset by the output facility, once it has completed. |
1048 | * | 1048 | * |
1049 | * @param input_facility input named pipe or file to work with. | 1049 | * @param input_facility input named pipe or file to work with. |
1050 | * @param output_facility output pipe or file to hand over data to. | 1050 | * @param output_facility output pipe or file to hand over data to. |
1051 | * @return false if an event reset was impossible (OS error), else true | 1051 | * @return false if an event reset was impossible (OS error), else true |
@@ -1055,17 +1055,17 @@ attempt_read_stdin (struct io_facility * input_facility, | |||
1055 | struct io_facility * output_facility) | 1055 | struct io_facility * output_facility) |
1056 | { | 1056 | { |
1057 | struct GNUNET_MessageHeader * hdr; | 1057 | struct GNUNET_MessageHeader * hdr; |
1058 | 1058 | ||
1059 | switch (input_facility->facility_state) | 1059 | switch (input_facility->facility_state) |
1060 | { | 1060 | { |
1061 | case IOSTATE_READY: | 1061 | case IOSTATE_READY: |
1062 | { | 1062 | { |
1063 | input_facility->buffer_size = 0; | 1063 | input_facility->buffer_size = 0; |
1064 | 1064 | ||
1065 | partial_read_iostate_ready: | 1065 | partial_read_iostate_ready: |
1066 | if (! ResetEvent (input_facility->overlapped.hEvent)) | 1066 | if (! ResetEvent (input_facility->overlapped.hEvent)) |
1067 | return FALSE; | 1067 | return FALSE; |
1068 | 1068 | ||
1069 | /* Check how the task is handled */ | 1069 | /* Check how the task is handled */ |
1070 | if (ReadFile (input_facility->handle, | 1070 | if (ReadFile (input_facility->handle, |
1071 | input_facility->buffer + input_facility->buffer_size, | 1071 | input_facility->buffer + input_facility->buffer_size, |
@@ -1113,7 +1113,7 @@ partial_read_iostate_ready: | |||
1113 | input_facility->facility_state = IOSTATE_WAITING; | 1113 | input_facility->facility_state = IOSTATE_WAITING; |
1114 | else /* we read nothing */ | 1114 | else /* we read nothing */ |
1115 | input_facility->facility_state = IOSTATE_READY; | 1115 | input_facility->facility_state = IOSTATE_READY; |
1116 | } | 1116 | } |
1117 | else /* operation was either queued or failed*/ | 1117 | else /* operation was either queued or failed*/ |
1118 | { | 1118 | { |
1119 | int err = GetLastError (); | 1119 | int err = GetLastError (); |
@@ -1141,13 +1141,13 @@ partial_read_iostate_ready: | |||
1141 | FALSE)) | 1141 | FALSE)) |
1142 | {/* successful return for a queued operation */ | 1142 | {/* successful return for a queued operation */ |
1143 | hdr = (struct GNUNET_MessageHeader *) input_facility->buffer; | 1143 | hdr = (struct GNUNET_MessageHeader *) input_facility->buffer; |
1144 | 1144 | ||
1145 | if (! ResetEvent (input_facility->overlapped.hEvent)) | 1145 | if (! ResetEvent (input_facility->overlapped.hEvent)) |
1146 | return FALSE; | 1146 | return FALSE; |
1147 | 1147 | ||
1148 | fprintf (stderr, "DEBUG: stdin read succeeded delayed\n"); | 1148 | fprintf (stderr, "DEBUG: stdin read succeeded delayed\n"); |
1149 | input_facility->buffer_size += input_facility->buffer_size_processed; | 1149 | input_facility->buffer_size += input_facility->buffer_size_processed; |
1150 | 1150 | ||
1151 | if ((ntohs (hdr->type) != GNUNET_MESSAGE_TYPE_VPN_HELPER) || | 1151 | if ((ntohs (hdr->type) != GNUNET_MESSAGE_TYPE_VPN_HELPER) || |
1152 | (ntohs (hdr->size) > sizeof (input_facility->buffer))) | 1152 | (ntohs (hdr->size) > sizeof (input_facility->buffer))) |
1153 | { | 1153 | { |
@@ -1209,7 +1209,7 @@ partial_read_iostate_ready: | |||
1209 | * Attempts to write to an output facility (tap or named pipe) in overlapped mode. | 1209 | * Attempts to write to an output facility (tap or named pipe) in overlapped mode. |
1210 | * | 1210 | * |
1211 | * TODO: high level description | 1211 | * TODO: high level description |
1212 | * | 1212 | * |
1213 | * @param output_facility output pipe or file to hand over data to. | 1213 | * @param output_facility output pipe or file to hand over data to. |
1214 | * @param input_facility input named pipe or file to work with. | 1214 | * @param input_facility input named pipe or file to work with. |
1215 | * @return false if an event reset was impossible (OS error), else true | 1215 | * @return false if an event reset was impossible (OS error), else true |
@@ -1222,7 +1222,7 @@ attempt_write (struct io_facility * output_facility, | |||
1222 | { | 1222 | { |
1223 | case IOSTATE_READY: | 1223 | case IOSTATE_READY: |
1224 | output_facility->buffer_size_written = 0; | 1224 | output_facility->buffer_size_written = 0; |
1225 | 1225 | ||
1226 | continue_partial_write: | 1226 | continue_partial_write: |
1227 | if (! ResetEvent (output_facility->overlapped.hEvent)) | 1227 | if (! ResetEvent (output_facility->overlapped.hEvent)) |
1228 | return FALSE; | 1228 | return FALSE; |
@@ -1237,7 +1237,7 @@ continue_partial_write: | |||
1237 | 1237 | ||
1238 | fprintf (stderr, "DEBUG: write succeeded immediately\n"); | 1238 | fprintf (stderr, "DEBUG: write succeeded immediately\n"); |
1239 | output_facility->buffer_size_written += output_facility->buffer_size_processed; | 1239 | output_facility->buffer_size_written += output_facility->buffer_size_processed; |
1240 | 1240 | ||
1241 | /* reset event manually*/ | 1241 | /* reset event manually*/ |
1242 | if (! SetEvent (output_facility->overlapped.hEvent)) | 1242 | if (! SetEvent (output_facility->overlapped.hEvent)) |
1243 | return FALSE; | 1243 | return FALSE; |
@@ -1245,7 +1245,7 @@ continue_partial_write: | |||
1245 | /* partial write */ | 1245 | /* partial write */ |
1246 | if (output_facility->buffer_size_written < output_facility->buffer_size) | 1246 | if (output_facility->buffer_size_written < output_facility->buffer_size) |
1247 | goto continue_partial_write; | 1247 | goto continue_partial_write; |
1248 | 1248 | ||
1249 | /* we are now waiting for our buffer to be filled*/ | 1249 | /* we are now waiting for our buffer to be filled*/ |
1250 | output_facility->facility_state = IOSTATE_WAITING; | 1250 | output_facility->facility_state = IOSTATE_WAITING; |
1251 | 1251 | ||
@@ -1272,7 +1272,7 @@ continue_partial_write: | |||
1272 | return TRUE; | 1272 | return TRUE; |
1273 | case IOSTATE_QUEUED: | 1273 | case IOSTATE_QUEUED: |
1274 | // there was an operation going on already, check if that has completed now. | 1274 | // there was an operation going on already, check if that has completed now. |
1275 | 1275 | ||
1276 | if (GetOverlappedResult (output_facility->handle, | 1276 | if (GetOverlappedResult (output_facility->handle, |
1277 | &output_facility->overlapped, | 1277 | &output_facility->overlapped, |
1278 | &output_facility->buffer_size_processed, | 1278 | &output_facility->buffer_size_processed, |
@@ -1280,17 +1280,17 @@ continue_partial_write: | |||
1280 | {/* successful return for a queued operation */ | 1280 | {/* successful return for a queued operation */ |
1281 | if (! ResetEvent (output_facility->overlapped.hEvent)) | 1281 | if (! ResetEvent (output_facility->overlapped.hEvent)) |
1282 | return FALSE; | 1282 | return FALSE; |
1283 | 1283 | ||
1284 | fprintf (stderr, "DEBUG: write succeeded delayed\n"); | 1284 | fprintf (stderr, "DEBUG: write succeeded delayed\n"); |
1285 | output_facility->buffer_size_written += output_facility->buffer_size_processed; | 1285 | output_facility->buffer_size_written += output_facility->buffer_size_processed; |
1286 | 1286 | ||
1287 | /* partial write */ | 1287 | /* partial write */ |
1288 | if (output_facility->buffer_size_written < output_facility->buffer_size) | 1288 | if (output_facility->buffer_size_written < output_facility->buffer_size) |
1289 | goto continue_partial_write; | 1289 | goto continue_partial_write; |
1290 | 1290 | ||
1291 | /* we are now waiting for our buffer to be filled*/ | 1291 | /* we are now waiting for our buffer to be filled*/ |
1292 | output_facility->facility_state = IOSTATE_WAITING; | 1292 | output_facility->facility_state = IOSTATE_WAITING; |
1293 | 1293 | ||
1294 | /* we successfully wrote something and now need to reset our reader */ | 1294 | /* we successfully wrote something and now need to reset our reader */ |
1295 | if (IOSTATE_WAITING == input_facility->facility_state) | 1295 | if (IOSTATE_WAITING == input_facility->facility_state) |
1296 | input_facility->facility_state = IOSTATE_RESUME; | 1296 | input_facility->facility_state = IOSTATE_RESUME; |
@@ -1307,7 +1307,7 @@ continue_partial_write: | |||
1307 | fprintf (stderr, "FATAL: Write to handle failed, exiting\n"); | 1307 | fprintf (stderr, "FATAL: Write to handle failed, exiting\n"); |
1308 | } | 1308 | } |
1309 | } | 1309 | } |
1310 | default: | 1310 | default: |
1311 | return TRUE; | 1311 | return TRUE; |
1312 | } | 1312 | } |
1313 | } | 1313 | } |
@@ -1315,7 +1315,7 @@ continue_partial_write: | |||
1315 | 1315 | ||
1316 | /** | 1316 | /** |
1317 | * Initialize a overlapped structure | 1317 | * Initialize a overlapped structure |
1318 | * | 1318 | * |
1319 | * @param elem the element to initilize | 1319 | * @param elem the element to initilize |
1320 | * @param initial_state the initial state for this instance | 1320 | * @param initial_state the initial state for this instance |
1321 | * @param signaled if the hEvent created should default to signaled or not | 1321 | * @param signaled if the hEvent created should default to signaled or not |
@@ -1361,7 +1361,7 @@ run (HANDLE tap_handle) | |||
1361 | /* tun up: */ | 1361 | /* tun up: */ |
1362 | /* we do this HERE and not beforehand (in init_tun()), in contrast to openvpn | 1362 | /* we do this HERE and not beforehand (in init_tun()), in contrast to openvpn |
1363 | * to remove the need to flush the arp cache, handle DHCP and wrong IPs. | 1363 | * to remove the need to flush the arp cache, handle DHCP and wrong IPs. |
1364 | * | 1364 | * |
1365 | * DHCP and such are all features we will never use in gnunet afaik. | 1365 | * DHCP and such are all features we will never use in gnunet afaik. |
1366 | * But for openvpn those are essential. | 1366 | * But for openvpn those are essential. |
1367 | */ | 1367 | */ |
@@ -1383,12 +1383,12 @@ run (HANDLE tap_handle) | |||
1383 | /* Debug output to console STDIN/STDOUT*/ | 1383 | /* Debug output to console STDIN/STDOUT*/ |
1384 | std_in.handle = parent_std_in_handle; | 1384 | std_in.handle = parent_std_in_handle; |
1385 | std_out.handle = parent_std_out_handle; | 1385 | std_out.handle = parent_std_out_handle; |
1386 | 1386 | ||
1387 | #else | 1387 | #else |
1388 | fprintf (stderr, "DEBUG: reopening stdin/out for overlapped IO\n"); | 1388 | fprintf (stderr, "DEBUG: reopening stdin/out for overlapped IO\n"); |
1389 | /* | 1389 | /* |
1390 | * Find out the types of our handles. | 1390 | * Find out the types of our handles. |
1391 | * This part is a problem, because in windows we need to handle files, | 1391 | * This part is a problem, because in windows we need to handle files, |
1392 | * pipes and the console differently. | 1392 | * pipes and the console differently. |
1393 | */ | 1393 | */ |
1394 | if ((FILE_TYPE_PIPE != GetFileType (parent_std_in_handle)) || | 1394 | if ((FILE_TYPE_PIPE != GetFileType (parent_std_in_handle)) || |
@@ -1472,16 +1472,16 @@ main (int argc, char **argv) | |||
1472 | int global_ret = 0; | 1472 | int global_ret = 0; |
1473 | BOOL have_ip4 = FALSE; | 1473 | BOOL have_ip4 = FALSE; |
1474 | BOOL have_ip6 = FALSE; | 1474 | BOOL have_ip6 = FALSE; |
1475 | 1475 | ||
1476 | if (argc > 1 && 0 != strcmp (argv[1], "-d")){ | 1476 | if (argc > 1 && 0 != strcmp (argv[1], "-d")){ |
1477 | privilege_testing = TRUE; | 1477 | privilege_testing = TRUE; |
1478 | fprintf (stderr, | 1478 | fprintf (stderr, |
1479 | "%s", | 1479 | "%s", |
1480 | "DEBUG: Running binary in privilege testing mode."); | 1480 | "DEBUG: Running binary in privilege testing mode."); |
1481 | argv++; | 1481 | argv++; |
1482 | argc--; | 1482 | argc--; |
1483 | } | 1483 | } |
1484 | 1484 | ||
1485 | if (6 != argc) | 1485 | if (6 != argc) |
1486 | { | 1486 | { |
1487 | fprintf (stderr, | 1487 | fprintf (stderr, |
@@ -1493,9 +1493,9 @@ main (int argc, char **argv) | |||
1493 | strncpy (hwid, argv[1], LINE_LEN); | 1493 | strncpy (hwid, argv[1], LINE_LEN); |
1494 | hwid[LINE_LEN - 1] = '\0'; | 1494 | hwid[LINE_LEN - 1] = '\0'; |
1495 | 1495 | ||
1496 | /* | 1496 | /* |
1497 | * We use our PID for finding/resolving the control-panel name of our virtual | 1497 | * We use our PID for finding/resolving the control-panel name of our virtual |
1498 | * device. PIDs are (of course) unique at runtime, thus we can safely use it | 1498 | * device. PIDs are (of course) unique at runtime, thus we can safely use it |
1499 | * as additional hardware-id for our device. | 1499 | * as additional hardware-id for our device. |
1500 | */ | 1500 | */ |
1501 | snprintf (secondary_hwid, LINE_LEN / 2, "%s-%d", | 1501 | snprintf (secondary_hwid, LINE_LEN / 2, "%s-%d", |
diff --git a/src/vpn/gnunet-helper-vpn.c b/src/vpn/gnunet-helper-vpn.c index c8f4530eb..57e5008e0 100644 --- a/src/vpn/gnunet-helper-vpn.c +++ b/src/vpn/gnunet-helper-vpn.c | |||
@@ -585,7 +585,7 @@ main (int argc, char **argv) | |||
585 | 585 | ||
586 | set_address4 (dev, address, mask); | 586 | set_address4 (dev, address, mask); |
587 | } | 587 | } |
588 | 588 | ||
589 | uid_t uid = getuid (); | 589 | uid_t uid = getuid (); |
590 | #ifdef HAVE_SETRESUID | 590 | #ifdef HAVE_SETRESUID |
591 | if (0 != setresuid (uid, uid, uid)) | 591 | if (0 != setresuid (uid, uid, uid)) |
diff --git a/src/vpn/gnunet-service-vpn.c b/src/vpn/gnunet-service-vpn.c index 13cbf5021..4ecd0dfc1 100644 --- a/src/vpn/gnunet-service-vpn.c +++ b/src/vpn/gnunet-service-vpn.c | |||
@@ -22,7 +22,7 @@ | |||
22 | * @file vpn/gnunet-service-vpn.c | 22 | * @file vpn/gnunet-service-vpn.c |
23 | * @brief service that opens a virtual interface and allows its clients | 23 | * @brief service that opens a virtual interface and allows its clients |
24 | * to allocate IPs on the virtual interface and to then redirect | 24 | * to allocate IPs on the virtual interface and to then redirect |
25 | * IP traffic received on those IPs via the GNUnet mesh | 25 | * IP traffic received on those IPs via the GNUnet mesh |
26 | * @author Philipp Toelke | 26 | * @author Philipp Toelke |
27 | * @author Christian Grothoff | 27 | * @author Christian Grothoff |
28 | * | 28 | * |
@@ -150,14 +150,14 @@ struct DestinationEntry | |||
150 | 150 | ||
151 | } service_destination; | 151 | } service_destination; |
152 | 152 | ||
153 | struct | 153 | struct |
154 | { | 154 | { |
155 | 155 | ||
156 | /** | 156 | /** |
157 | * Address family used (AF_INET or AF_INET6). | 157 | * Address family used (AF_INET or AF_INET6). |
158 | */ | 158 | */ |
159 | int af; | 159 | int af; |
160 | 160 | ||
161 | /** | 161 | /** |
162 | * IP address of the ultimate destination (only used for exit tunnels). | 162 | * IP address of the ultimate destination (only used for exit tunnels). |
163 | */ | 163 | */ |
@@ -177,7 +177,7 @@ struct DestinationEntry | |||
177 | } exit_destination; | 177 | } exit_destination; |
178 | 178 | ||
179 | } details; | 179 | } details; |
180 | 180 | ||
181 | }; | 181 | }; |
182 | 182 | ||
183 | 183 | ||
@@ -195,7 +195,7 @@ struct TunnelMessageQueueEntry | |||
195 | * This is a doubly-linked list. | 195 | * This is a doubly-linked list. |
196 | */ | 196 | */ |
197 | struct TunnelMessageQueueEntry *prev; | 197 | struct TunnelMessageQueueEntry *prev; |
198 | 198 | ||
199 | /** | 199 | /** |
200 | * Number of bytes in 'msg'. | 200 | * Number of bytes in 'msg'. |
201 | */ | 201 | */ |
@@ -244,7 +244,7 @@ struct TunnelState | |||
244 | /** | 244 | /** |
245 | * Tail of list of messages scheduled for transmission. | 245 | * Tail of list of messages scheduled for transmission. |
246 | */ | 246 | */ |
247 | struct TunnelMessageQueueEntry *tmq_tail; | 247 | struct TunnelMessageQueueEntry *tmq_tail; |
248 | 248 | ||
249 | /** | 249 | /** |
250 | * Destination entry that has a pointer to this tunnel state; | 250 | * Destination entry that has a pointer to this tunnel state; |
@@ -284,7 +284,7 @@ struct TunnelState | |||
284 | * Address if af is AF_INET. | 284 | * Address if af is AF_INET. |
285 | */ | 285 | */ |
286 | struct in_addr v4; | 286 | struct in_addr v4; |
287 | 287 | ||
288 | /** | 288 | /** |
289 | * Address if af is AF_INET6. | 289 | * Address if af is AF_INET6. |
290 | */ | 290 | */ |
@@ -302,7 +302,7 @@ struct TunnelState | |||
302 | * Address if af is AF_INET. | 302 | * Address if af is AF_INET. |
303 | */ | 303 | */ |
304 | struct in_addr v4; | 304 | struct in_addr v4; |
305 | 305 | ||
306 | /** | 306 | /** |
307 | * Address if af is AF_INET6. | 307 | * Address if af is AF_INET6. |
308 | */ | 308 | */ |
@@ -506,7 +506,7 @@ send_client_reply (struct GNUNET_SERVER_Client *client, | |||
506 | switch (result_af) | 506 | switch (result_af) |
507 | { | 507 | { |
508 | case AF_INET: | 508 | case AF_INET: |
509 | rlen = sizeof (struct in_addr); | 509 | rlen = sizeof (struct in_addr); |
510 | break; | 510 | break; |
511 | case AF_INET6: | 511 | case AF_INET6: |
512 | rlen = sizeof (struct in6_addr); | 512 | rlen = sizeof (struct in6_addr); |
@@ -632,8 +632,8 @@ send_to_peer_notify_callback (void *cls, size_t size, void *buf) | |||
632 | ret = tnq->len; | 632 | ret = tnq->len; |
633 | GNUNET_free (tnq); | 633 | GNUNET_free (tnq); |
634 | if (NULL != (tnq = ts->tmq_head)) | 634 | if (NULL != (tnq = ts->tmq_head)) |
635 | ts->th = GNUNET_MESH_notify_transmit_ready (ts->tunnel, | 635 | ts->th = GNUNET_MESH_notify_transmit_ready (ts->tunnel, |
636 | GNUNET_NO /* cork */, | 636 | GNUNET_NO /* cork */, |
637 | GNUNET_TIME_UNIT_FOREVER_REL, | 637 | GNUNET_TIME_UNIT_FOREVER_REL, |
638 | tnq->len, | 638 | tnq->len, |
639 | &send_to_peer_notify_callback, | 639 | &send_to_peer_notify_callback, |
@@ -678,12 +678,12 @@ send_to_tunnel (struct TunnelMessageQueueEntry *tnq, | |||
678 | ts->th = NULL; | 678 | ts->th = NULL; |
679 | GNUNET_STATISTICS_update (stats, | 679 | GNUNET_STATISTICS_update (stats, |
680 | gettext_noop ("# Bytes dropped in mesh queue (overflow)"), | 680 | gettext_noop ("# Bytes dropped in mesh queue (overflow)"), |
681 | dq->len, | 681 | dq->len, |
682 | GNUNET_NO); | 682 | GNUNET_NO); |
683 | GNUNET_free (dq); | 683 | GNUNET_free (dq); |
684 | } | 684 | } |
685 | if (NULL == ts->th) | 685 | if (NULL == ts->th) |
686 | ts->th = GNUNET_MESH_notify_transmit_ready (ts->tunnel, | 686 | ts->th = GNUNET_MESH_notify_transmit_ready (ts->tunnel, |
687 | GNUNET_NO /* cork */, | 687 | GNUNET_NO /* cork */, |
688 | GNUNET_TIME_UNIT_FOREVER_REL, | 688 | GNUNET_TIME_UNIT_FOREVER_REL, |
689 | tnq->len, | 689 | tnq->len, |
@@ -803,7 +803,7 @@ create_tunnel_to_destination (struct DestinationTunnel *dt, | |||
803 | char address[GNUNET_TUN_IPV4_REGEXLEN]; | 803 | char address[GNUNET_TUN_IPV4_REGEXLEN]; |
804 | 804 | ||
805 | GNUNET_TUN_ipv4toregexsearch (&dt->destination->details.exit_destination.ip.v4, | 805 | GNUNET_TUN_ipv4toregexsearch (&dt->destination->details.exit_destination.ip.v4, |
806 | "255.255.255.255", | 806 | "255.255.255.255", |
807 | address); | 807 | address); |
808 | GNUNET_asprintf (&policy, "%s%s%s:%u", | 808 | GNUNET_asprintf (&policy, "%s%s%s:%u", |
809 | GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX, | 809 | GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX, |
@@ -815,7 +815,7 @@ create_tunnel_to_destination (struct DestinationTunnel *dt, | |||
815 | case AF_INET6: | 815 | case AF_INET6: |
816 | { | 816 | { |
817 | char address[GNUNET_TUN_IPV6_REGEXLEN]; | 817 | char address[GNUNET_TUN_IPV6_REGEXLEN]; |
818 | 818 | ||
819 | GNUNET_TUN_ipv6toregexsearch (&dt->destination->details.exit_destination.ip.v6, | 819 | GNUNET_TUN_ipv6toregexsearch (&dt->destination->details.exit_destination.ip.v6, |
820 | 128, address); | 820 | 128, address); |
821 | GNUNET_asprintf (&policy, "%s%s%s:%u", | 821 | GNUNET_asprintf (&policy, "%s%s%s:%u", |
@@ -862,7 +862,7 @@ expire_tunnel (struct TunnelState *except) | |||
862 | 862 | ||
863 | 863 | ||
864 | /** | 864 | /** |
865 | * Route a packet via mesh to the given destination. | 865 | * Route a packet via mesh to the given destination. |
866 | * | 866 | * |
867 | * @param destination description of the destination | 867 | * @param destination description of the destination |
868 | * @param af address family on this end (AF_INET or AF_INET6) | 868 | * @param af address family on this end (AF_INET or AF_INET6) |
@@ -930,7 +930,7 @@ route_packet (struct DestinationEntry *destination, | |||
930 | /* blame kernel? */ | 930 | /* blame kernel? */ |
931 | GNUNET_break (0); | 931 | GNUNET_break (0); |
932 | return; | 932 | return; |
933 | } | 933 | } |
934 | udp = NULL; /* make compiler happy */ | 934 | udp = NULL; /* make compiler happy */ |
935 | icmp = NULL; /* make compiler happy */ | 935 | icmp = NULL; /* make compiler happy */ |
936 | tcp = payload; | 936 | tcp = payload; |
@@ -950,8 +950,8 @@ route_packet (struct DestinationEntry *destination, | |||
950 | &key); | 950 | &key); |
951 | } | 951 | } |
952 | break; | 952 | break; |
953 | case IPPROTO_ICMP: | 953 | case IPPROTO_ICMP: |
954 | case IPPROTO_ICMPV6: | 954 | case IPPROTO_ICMPV6: |
955 | { | 955 | { |
956 | if ( (AF_INET == af) ^ (protocol == IPPROTO_ICMP) ) | 956 | if ( (AF_INET == af) ^ (protocol == IPPROTO_ICMP) ) |
957 | { | 957 | { |
@@ -986,7 +986,7 @@ route_packet (struct DestinationEntry *destination, | |||
986 | } | 986 | } |
987 | alen = 0; | 987 | alen = 0; |
988 | if (! destination->is_service) | 988 | if (! destination->is_service) |
989 | { | 989 | { |
990 | switch (destination->details.exit_destination.af) | 990 | switch (destination->details.exit_destination.af) |
991 | { | 991 | { |
992 | case AF_INET: | 992 | case AF_INET: |
@@ -1003,7 +1003,7 @@ route_packet (struct DestinationEntry *destination, | |||
1003 | char sbuf[INET6_ADDRSTRLEN]; | 1003 | char sbuf[INET6_ADDRSTRLEN]; |
1004 | char dbuf[INET6_ADDRSTRLEN]; | 1004 | char dbuf[INET6_ADDRSTRLEN]; |
1005 | char xbuf[INET6_ADDRSTRLEN]; | 1005 | char xbuf[INET6_ADDRSTRLEN]; |
1006 | 1006 | ||
1007 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1007 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1008 | "Routing %s packet from %s:%u -> %s:%u to destination %s:%u\n", | 1008 | "Routing %s packet from %s:%u -> %s:%u to destination %s:%u\n", |
1009 | (protocol == IPPROTO_TCP) ? "TCP" : "UDP", | 1009 | (protocol == IPPROTO_TCP) ? "TCP" : "UDP", |
@@ -1025,7 +1025,7 @@ route_packet (struct DestinationEntry *destination, | |||
1025 | { | 1025 | { |
1026 | char sbuf[INET6_ADDRSTRLEN]; | 1026 | char sbuf[INET6_ADDRSTRLEN]; |
1027 | char dbuf[INET6_ADDRSTRLEN]; | 1027 | char dbuf[INET6_ADDRSTRLEN]; |
1028 | 1028 | ||
1029 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1029 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1030 | "Routing %s packet from %s:%u -> %s:%u to service %s at peer %s\n", | 1030 | "Routing %s packet from %s:%u -> %s:%u to service %s at peer %s\n", |
1031 | (protocol == IPPROTO_TCP) ? "TCP" : "UDP", | 1031 | (protocol == IPPROTO_TCP) ? "TCP" : "UDP", |
@@ -1066,7 +1066,7 @@ route_packet (struct DestinationEntry *destination, | |||
1066 | ts->destination_container = NULL; /* no longer 'contained' */ | 1066 | ts->destination_container = NULL; /* no longer 'contained' */ |
1067 | /* now bind existing "unbound" tunnel to our IP/port tuple */ | 1067 | /* now bind existing "unbound" tunnel to our IP/port tuple */ |
1068 | ts->protocol = protocol; | 1068 | ts->protocol = protocol; |
1069 | ts->af = af; | 1069 | ts->af = af; |
1070 | if (AF_INET == af) | 1070 | if (AF_INET == af) |
1071 | { | 1071 | { |
1072 | ts->source_ip.v4 = * (const struct in_addr *) source_ip; | 1072 | ts->source_ip.v4 = * (const struct in_addr *) source_ip; |
@@ -1086,7 +1086,7 @@ route_packet (struct DestinationEntry *destination, | |||
1086 | GNUNET_CONTAINER_multihashmap_put (tunnel_map, | 1086 | GNUNET_CONTAINER_multihashmap_put (tunnel_map, |
1087 | &key, | 1087 | &key, |
1088 | ts, | 1088 | ts, |
1089 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 1089 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
1090 | GNUNET_STATISTICS_update (stats, | 1090 | GNUNET_STATISTICS_update (stats, |
1091 | gettext_noop ("# Active tunnels"), | 1091 | gettext_noop ("# Active tunnels"), |
1092 | 1, GNUNET_NO); | 1092 | 1, GNUNET_NO); |
@@ -1096,12 +1096,12 @@ route_packet (struct DestinationEntry *destination, | |||
1096 | else | 1096 | else |
1097 | { | 1097 | { |
1098 | is_new = GNUNET_NO; | 1098 | is_new = GNUNET_NO; |
1099 | GNUNET_CONTAINER_heap_update_cost (tunnel_heap, | 1099 | GNUNET_CONTAINER_heap_update_cost (tunnel_heap, |
1100 | ts->heap_node, | 1100 | ts->heap_node, |
1101 | GNUNET_TIME_absolute_get ().abs_value_us); | 1101 | GNUNET_TIME_absolute_get ().abs_value_us); |
1102 | } | 1102 | } |
1103 | GNUNET_assert (NULL != ts->tunnel); | 1103 | GNUNET_assert (NULL != ts->tunnel); |
1104 | 1104 | ||
1105 | /* send via tunnel */ | 1105 | /* send via tunnel */ |
1106 | switch (protocol) | 1106 | switch (protocol) |
1107 | { | 1107 | { |
@@ -1110,7 +1110,7 @@ route_packet (struct DestinationEntry *destination, | |||
1110 | { | 1110 | { |
1111 | struct GNUNET_EXIT_UdpServiceMessage *usm; | 1111 | struct GNUNET_EXIT_UdpServiceMessage *usm; |
1112 | 1112 | ||
1113 | mlen = sizeof (struct GNUNET_EXIT_UdpServiceMessage) + | 1113 | mlen = sizeof (struct GNUNET_EXIT_UdpServiceMessage) + |
1114 | payload_length - sizeof (struct GNUNET_TUN_UdpHeader); | 1114 | payload_length - sizeof (struct GNUNET_TUN_UdpHeader); |
1115 | if (mlen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | 1115 | if (mlen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) |
1116 | { | 1116 | { |
@@ -1139,7 +1139,7 @@ route_packet (struct DestinationEntry *destination, | |||
1139 | struct in6_addr *ip6dst; | 1139 | struct in6_addr *ip6dst; |
1140 | void *payload; | 1140 | void *payload; |
1141 | 1141 | ||
1142 | mlen = sizeof (struct GNUNET_EXIT_UdpInternetMessage) + | 1142 | mlen = sizeof (struct GNUNET_EXIT_UdpInternetMessage) + |
1143 | alen + payload_length - sizeof (struct GNUNET_TUN_UdpHeader); | 1143 | alen + payload_length - sizeof (struct GNUNET_TUN_UdpHeader); |
1144 | if (mlen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | 1144 | if (mlen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) |
1145 | { | 1145 | { |
@@ -1151,7 +1151,7 @@ route_packet (struct DestinationEntry *destination, | |||
1151 | tnq->msg = &tnq[1]; | 1151 | tnq->msg = &tnq[1]; |
1152 | uim = (struct GNUNET_EXIT_UdpInternetMessage *) &tnq[1]; | 1152 | uim = (struct GNUNET_EXIT_UdpInternetMessage *) &tnq[1]; |
1153 | uim->header.size = htons ((uint16_t) mlen); | 1153 | uim->header.size = htons ((uint16_t) mlen); |
1154 | uim->header.type = htons (GNUNET_MESSAGE_TYPE_VPN_UDP_TO_INTERNET); | 1154 | uim->header.type = htons (GNUNET_MESSAGE_TYPE_VPN_UDP_TO_INTERNET); |
1155 | uim->af = htonl (destination->details.exit_destination.af); | 1155 | uim->af = htonl (destination->details.exit_destination.af); |
1156 | uim->source_port = (ntohs (udp->source_port) < 32000) ? udp->source_port : 0; | 1156 | uim->source_port = (ntohs (udp->source_port) < 32000) ? udp->source_port : 0; |
1157 | uim->destination_port = udp->destination_port; | 1157 | uim->destination_port = udp->destination_port; |
@@ -1182,7 +1182,7 @@ route_packet (struct DestinationEntry *destination, | |||
1182 | { | 1182 | { |
1183 | struct GNUNET_EXIT_TcpServiceStartMessage *tsm; | 1183 | struct GNUNET_EXIT_TcpServiceStartMessage *tsm; |
1184 | 1184 | ||
1185 | mlen = sizeof (struct GNUNET_EXIT_TcpServiceStartMessage) + | 1185 | mlen = sizeof (struct GNUNET_EXIT_TcpServiceStartMessage) + |
1186 | payload_length - sizeof (struct GNUNET_TUN_TcpHeader); | 1186 | payload_length - sizeof (struct GNUNET_TUN_TcpHeader); |
1187 | if (mlen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | 1187 | if (mlen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) |
1188 | { | 1188 | { |
@@ -1209,7 +1209,7 @@ route_packet (struct DestinationEntry *destination, | |||
1209 | struct in6_addr *ip6dst; | 1209 | struct in6_addr *ip6dst; |
1210 | void *payload; | 1210 | void *payload; |
1211 | 1211 | ||
1212 | mlen = sizeof (struct GNUNET_EXIT_TcpInternetStartMessage) + | 1212 | mlen = sizeof (struct GNUNET_EXIT_TcpInternetStartMessage) + |
1213 | alen + payload_length - sizeof (struct GNUNET_TUN_TcpHeader); | 1213 | alen + payload_length - sizeof (struct GNUNET_TUN_TcpHeader); |
1214 | if (mlen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | 1214 | if (mlen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) |
1215 | { | 1215 | { |
@@ -1248,7 +1248,7 @@ route_packet (struct DestinationEntry *destination, | |||
1248 | { | 1248 | { |
1249 | struct GNUNET_EXIT_TcpDataMessage *tdm; | 1249 | struct GNUNET_EXIT_TcpDataMessage *tdm; |
1250 | 1250 | ||
1251 | mlen = sizeof (struct GNUNET_EXIT_TcpDataMessage) + | 1251 | mlen = sizeof (struct GNUNET_EXIT_TcpDataMessage) + |
1252 | payload_length - sizeof (struct GNUNET_TUN_TcpHeader); | 1252 | payload_length - sizeof (struct GNUNET_TUN_TcpHeader); |
1253 | if (mlen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | 1253 | if (mlen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) |
1254 | { | 1254 | { |
@@ -1274,7 +1274,7 @@ route_packet (struct DestinationEntry *destination, | |||
1274 | { | 1274 | { |
1275 | struct GNUNET_EXIT_IcmpServiceMessage *ism; | 1275 | struct GNUNET_EXIT_IcmpServiceMessage *ism; |
1276 | 1276 | ||
1277 | mlen = sizeof (struct GNUNET_EXIT_IcmpServiceMessage) + | 1277 | mlen = sizeof (struct GNUNET_EXIT_IcmpServiceMessage) + |
1278 | payload_length - sizeof (struct GNUNET_TUN_IcmpHeader); | 1278 | payload_length - sizeof (struct GNUNET_TUN_IcmpHeader); |
1279 | if (mlen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | 1279 | if (mlen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) |
1280 | { | 1280 | { |
@@ -1303,7 +1303,7 @@ route_packet (struct DestinationEntry *destination, | |||
1303 | case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH: | 1303 | case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH: |
1304 | case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED: | 1304 | case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED: |
1305 | /* throw away ICMP payload, won't be useful for the other side anyway */ | 1305 | /* throw away ICMP payload, won't be useful for the other side anyway */ |
1306 | payload_length = sizeof (struct GNUNET_TUN_IcmpHeader); | 1306 | payload_length = sizeof (struct GNUNET_TUN_IcmpHeader); |
1307 | break; | 1307 | break; |
1308 | default: | 1308 | default: |
1309 | GNUNET_STATISTICS_update (stats, | 1309 | GNUNET_STATISTICS_update (stats, |
@@ -1321,7 +1321,7 @@ route_packet (struct DestinationEntry *destination, | |||
1321 | case GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED: | 1321 | case GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED: |
1322 | case GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM: | 1322 | case GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM: |
1323 | /* throw away ICMP payload, won't be useful for the other side anyway */ | 1323 | /* throw away ICMP payload, won't be useful for the other side anyway */ |
1324 | payload_length = sizeof (struct GNUNET_TUN_IcmpHeader); | 1324 | payload_length = sizeof (struct GNUNET_TUN_IcmpHeader); |
1325 | break; | 1325 | break; |
1326 | case GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST: | 1326 | case GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST: |
1327 | case GNUNET_TUN_ICMPTYPE6_ECHO_REPLY: | 1327 | case GNUNET_TUN_ICMPTYPE6_ECHO_REPLY: |
@@ -1340,8 +1340,8 @@ route_packet (struct DestinationEntry *destination, | |||
1340 | } | 1340 | } |
1341 | 1341 | ||
1342 | /* update length calculations, as payload_length may have changed */ | 1342 | /* update length calculations, as payload_length may have changed */ |
1343 | mlen = sizeof (struct GNUNET_EXIT_IcmpServiceMessage) + | 1343 | mlen = sizeof (struct GNUNET_EXIT_IcmpServiceMessage) + |
1344 | alen + payload_length - sizeof (struct GNUNET_TUN_IcmpHeader); | 1344 | alen + payload_length - sizeof (struct GNUNET_TUN_IcmpHeader); |
1345 | tnq->len = mlen; | 1345 | tnq->len = mlen; |
1346 | ism->header.size = htons ((uint16_t) mlen); | 1346 | ism->header.size = htons ((uint16_t) mlen); |
1347 | /* finally, copy payload (if there is any left...) */ | 1347 | /* finally, copy payload (if there is any left...) */ |
@@ -1356,7 +1356,7 @@ route_packet (struct DestinationEntry *destination, | |||
1356 | struct in6_addr *ip6dst; | 1356 | struct in6_addr *ip6dst; |
1357 | void *payload; | 1357 | void *payload; |
1358 | 1358 | ||
1359 | mlen = sizeof (struct GNUNET_EXIT_IcmpInternetMessage) + | 1359 | mlen = sizeof (struct GNUNET_EXIT_IcmpInternetMessage) + |
1360 | alen + payload_length - sizeof (struct GNUNET_TUN_IcmpHeader); | 1360 | alen + payload_length - sizeof (struct GNUNET_TUN_IcmpHeader); |
1361 | if (mlen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | 1361 | if (mlen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) |
1362 | { | 1362 | { |
@@ -1366,7 +1366,7 @@ route_packet (struct DestinationEntry *destination, | |||
1366 | tnq = GNUNET_malloc (sizeof (struct TunnelMessageQueueEntry) + mlen); | 1366 | tnq = GNUNET_malloc (sizeof (struct TunnelMessageQueueEntry) + mlen); |
1367 | tnq->msg = &tnq[1]; | 1367 | tnq->msg = &tnq[1]; |
1368 | iim = (struct GNUNET_EXIT_IcmpInternetMessage *) &tnq[1]; | 1368 | iim = (struct GNUNET_EXIT_IcmpInternetMessage *) &tnq[1]; |
1369 | iim->header.type = htons (GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_INTERNET); | 1369 | iim->header.type = htons (GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_INTERNET); |
1370 | iim->icmp_header = *icmp; | 1370 | iim->icmp_header = *icmp; |
1371 | /* Perform ICMP protocol-translation (depending on destination AF and source AF) | 1371 | /* Perform ICMP protocol-translation (depending on destination AF and source AF) |
1372 | and throw away ICMP payload depending on ICMP message type */ | 1372 | and throw away ICMP payload depending on ICMP message type */ |
@@ -1375,11 +1375,11 @@ route_packet (struct DestinationEntry *destination, | |||
1375 | case AF_INET: | 1375 | case AF_INET: |
1376 | switch (icmp->type) | 1376 | switch (icmp->type) |
1377 | { | 1377 | { |
1378 | case GNUNET_TUN_ICMPTYPE_ECHO_REPLY: | 1378 | case GNUNET_TUN_ICMPTYPE_ECHO_REPLY: |
1379 | if (destination->details.exit_destination.af == AF_INET6) | 1379 | if (destination->details.exit_destination.af == AF_INET6) |
1380 | iim->icmp_header.type = GNUNET_TUN_ICMPTYPE6_ECHO_REPLY; | 1380 | iim->icmp_header.type = GNUNET_TUN_ICMPTYPE6_ECHO_REPLY; |
1381 | break; | 1381 | break; |
1382 | case GNUNET_TUN_ICMPTYPE_ECHO_REQUEST: | 1382 | case GNUNET_TUN_ICMPTYPE_ECHO_REQUEST: |
1383 | if (destination->details.exit_destination.af == AF_INET6) | 1383 | if (destination->details.exit_destination.af == AF_INET6) |
1384 | iim->icmp_header.type = GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST; | 1384 | iim->icmp_header.type = GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST; |
1385 | break; | 1385 | break; |
@@ -1411,7 +1411,7 @@ route_packet (struct DestinationEntry *destination, | |||
1411 | GNUNET_STATISTICS_update (stats, | 1411 | GNUNET_STATISTICS_update (stats, |
1412 | gettext_noop ("# ICMPv4 packets dropped (type not allowed)"), | 1412 | gettext_noop ("# ICMPv4 packets dropped (type not allowed)"), |
1413 | 1, GNUNET_NO); | 1413 | 1, GNUNET_NO); |
1414 | GNUNET_free (tnq); | 1414 | GNUNET_free (tnq); |
1415 | return; | 1415 | return; |
1416 | } | 1416 | } |
1417 | /* end of AF_INET */ | 1417 | /* end of AF_INET */ |
@@ -1467,17 +1467,17 @@ route_packet (struct DestinationEntry *destination, | |||
1467 | GNUNET_STATISTICS_update (stats, | 1467 | GNUNET_STATISTICS_update (stats, |
1468 | gettext_noop ("# ICMPv6 packets dropped (type not allowed)"), | 1468 | gettext_noop ("# ICMPv6 packets dropped (type not allowed)"), |
1469 | 1, GNUNET_NO); | 1469 | 1, GNUNET_NO); |
1470 | GNUNET_free (tnq); | 1470 | GNUNET_free (tnq); |
1471 | return; | 1471 | return; |
1472 | } | 1472 | } |
1473 | /* end of AF_INET6 */ | 1473 | /* end of AF_INET6 */ |
1474 | break; | 1474 | break; |
1475 | default: | 1475 | default: |
1476 | GNUNET_assert (0); | 1476 | GNUNET_assert (0); |
1477 | } | 1477 | } |
1478 | /* update length calculations, as payload_length may have changed */ | 1478 | /* update length calculations, as payload_length may have changed */ |
1479 | mlen = sizeof (struct GNUNET_EXIT_IcmpInternetMessage) + | 1479 | mlen = sizeof (struct GNUNET_EXIT_IcmpInternetMessage) + |
1480 | alen + payload_length - sizeof (struct GNUNET_TUN_IcmpHeader); | 1480 | alen + payload_length - sizeof (struct GNUNET_TUN_IcmpHeader); |
1481 | tnq->len = mlen; | 1481 | tnq->len = mlen; |
1482 | iim->header.size = htons ((uint16_t) mlen); | 1482 | iim->header.size = htons ((uint16_t) mlen); |
1483 | 1483 | ||
@@ -1549,7 +1549,7 @@ message_token (void *cls, | |||
1549 | case ETH_P_IPV6: | 1549 | case ETH_P_IPV6: |
1550 | { | 1550 | { |
1551 | const struct GNUNET_TUN_IPv6Header *pkt6; | 1551 | const struct GNUNET_TUN_IPv6Header *pkt6; |
1552 | 1552 | ||
1553 | if (mlen < sizeof (struct GNUNET_TUN_IPv6Header)) | 1553 | if (mlen < sizeof (struct GNUNET_TUN_IPv6Header)) |
1554 | { | 1554 | { |
1555 | /* blame kernel */ | 1555 | /* blame kernel */ |
@@ -1576,8 +1576,8 @@ message_token (void *cls, | |||
1576 | route_packet (de, | 1576 | route_packet (de, |
1577 | AF_INET6, | 1577 | AF_INET6, |
1578 | pkt6->next_header, | 1578 | pkt6->next_header, |
1579 | &pkt6->source_address, | 1579 | &pkt6->source_address, |
1580 | &pkt6->destination_address, | 1580 | &pkt6->destination_address, |
1581 | &pkt6[1], | 1581 | &pkt6[1], |
1582 | mlen - sizeof (struct GNUNET_TUN_IPv6Header)); | 1582 | mlen - sizeof (struct GNUNET_TUN_IPv6Header)); |
1583 | } | 1583 | } |
@@ -1612,14 +1612,14 @@ message_token (void *cls, | |||
1612 | if (pkt4->header_length * 4 != sizeof (struct GNUNET_TUN_IPv4Header)) | 1612 | if (pkt4->header_length * 4 != sizeof (struct GNUNET_TUN_IPv4Header)) |
1613 | { | 1613 | { |
1614 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1614 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1615 | _("Received IPv4 packet with options (dropping it)\n")); | 1615 | _("Received IPv4 packet with options (dropping it)\n")); |
1616 | return GNUNET_OK; | 1616 | return GNUNET_OK; |
1617 | } | 1617 | } |
1618 | route_packet (de, | 1618 | route_packet (de, |
1619 | AF_INET, | 1619 | AF_INET, |
1620 | pkt4->protocol, | 1620 | pkt4->protocol, |
1621 | &pkt4->source_address, | 1621 | &pkt4->source_address, |
1622 | &pkt4->destination_address, | 1622 | &pkt4->destination_address, |
1623 | &pkt4[1], | 1623 | &pkt4[1], |
1624 | mlen - sizeof (struct GNUNET_TUN_IPv4Header)); | 1624 | mlen - sizeof (struct GNUNET_TUN_IPv4Header)); |
1625 | } | 1625 | } |
@@ -1696,7 +1696,7 @@ make_up_icmpv6_payload (struct TunnelState *ts, | |||
1696 | * @param message the actual message | 1696 | * @param message the actual message |
1697 | * @return #GNUNET_OK to keep the connection open, | 1697 | * @return #GNUNET_OK to keep the connection open, |
1698 | * #GNUNET_SYSERR to close it (signal serious error) | 1698 | * #GNUNET_SYSERR to close it (signal serious error) |
1699 | */ | 1699 | */ |
1700 | static int | 1700 | static int |
1701 | receive_icmp_back (void *cls, | 1701 | receive_icmp_back (void *cls, |
1702 | struct GNUNET_MESH_Tunnel *tunnel, | 1702 | struct GNUNET_MESH_Tunnel *tunnel, |
@@ -1731,7 +1731,7 @@ receive_icmp_back (void *cls, | |||
1731 | { | 1731 | { |
1732 | char sbuf[INET6_ADDRSTRLEN]; | 1732 | char sbuf[INET6_ADDRSTRLEN]; |
1733 | char dbuf[INET6_ADDRSTRLEN]; | 1733 | char dbuf[INET6_ADDRSTRLEN]; |
1734 | 1734 | ||
1735 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1735 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1736 | "Received ICMP packet from mesh, sending %u bytes from %s -> %s via TUN\n", | 1736 | "Received ICMP packet from mesh, sending %u bytes from %s -> %s via TUN\n", |
1737 | (unsigned int) mlen, | 1737 | (unsigned int) mlen, |
@@ -1742,8 +1742,8 @@ receive_icmp_back (void *cls, | |||
1742 | { | 1742 | { |
1743 | case AF_INET: | 1743 | case AF_INET: |
1744 | { | 1744 | { |
1745 | size_t size = sizeof (struct GNUNET_TUN_IPv4Header) | 1745 | size_t size = sizeof (struct GNUNET_TUN_IPv4Header) |
1746 | + sizeof (struct GNUNET_TUN_IcmpHeader) | 1746 | + sizeof (struct GNUNET_TUN_IcmpHeader) |
1747 | + sizeof (struct GNUNET_MessageHeader) + | 1747 | + sizeof (struct GNUNET_MessageHeader) + |
1748 | sizeof (struct GNUNET_TUN_Layer2PacketHeader) + | 1748 | sizeof (struct GNUNET_TUN_Layer2PacketHeader) + |
1749 | mlen; | 1749 | mlen; |
@@ -1767,12 +1767,12 @@ receive_icmp_back (void *cls, | |||
1767 | memcpy (&icmp[1], | 1767 | memcpy (&icmp[1], |
1768 | &i2v[1], | 1768 | &i2v[1], |
1769 | mlen); | 1769 | mlen); |
1770 | /* For some ICMP types, we need to adjust (make up) the payload here. | 1770 | /* For some ICMP types, we need to adjust (make up) the payload here. |
1771 | Also, depending on the AF used on the other side, we have to | 1771 | Also, depending on the AF used on the other side, we have to |
1772 | do ICMP PT (translate ICMP types) */ | 1772 | do ICMP PT (translate ICMP types) */ |
1773 | switch (ntohl (i2v->af)) | 1773 | switch (ntohl (i2v->af)) |
1774 | { | 1774 | { |
1775 | case AF_INET: | 1775 | case AF_INET: |
1776 | switch (icmp->type) | 1776 | switch (icmp->type) |
1777 | { | 1777 | { |
1778 | case GNUNET_TUN_ICMPTYPE_ECHO_REPLY: | 1778 | case GNUNET_TUN_ICMPTYPE_ECHO_REPLY: |
@@ -1780,11 +1780,11 @@ receive_icmp_back (void *cls, | |||
1780 | break; | 1780 | break; |
1781 | case GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE: | 1781 | case GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE: |
1782 | case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH: | 1782 | case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH: |
1783 | case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED: | 1783 | case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED: |
1784 | { | 1784 | { |
1785 | struct GNUNET_TUN_IPv4Header *ipp = (struct GNUNET_TUN_IPv4Header *) &icmp[1]; | 1785 | struct GNUNET_TUN_IPv4Header *ipp = (struct GNUNET_TUN_IPv4Header *) &icmp[1]; |
1786 | struct GNUNET_TUN_UdpHeader *udp = (struct GNUNET_TUN_UdpHeader *) &ipp[1]; | 1786 | struct GNUNET_TUN_UdpHeader *udp = (struct GNUNET_TUN_UdpHeader *) &ipp[1]; |
1787 | 1787 | ||
1788 | if (mlen != 0) | 1788 | if (mlen != 0) |
1789 | { | 1789 | { |
1790 | /* sender did not strip ICMP payload? */ | 1790 | /* sender did not strip ICMP payload? */ |
@@ -1814,7 +1814,7 @@ receive_icmp_back (void *cls, | |||
1814 | { | 1814 | { |
1815 | struct GNUNET_TUN_IPv4Header *ipp = (struct GNUNET_TUN_IPv4Header *) &icmp[1]; | 1815 | struct GNUNET_TUN_IPv4Header *ipp = (struct GNUNET_TUN_IPv4Header *) &icmp[1]; |
1816 | struct GNUNET_TUN_UdpHeader *udp = (struct GNUNET_TUN_UdpHeader *) &ipp[1]; | 1816 | struct GNUNET_TUN_UdpHeader *udp = (struct GNUNET_TUN_UdpHeader *) &ipp[1]; |
1817 | 1817 | ||
1818 | if (mlen != 0) | 1818 | if (mlen != 0) |
1819 | { | 1819 | { |
1820 | /* sender did not strip ICMP payload? */ | 1820 | /* sender did not strip ICMP payload? */ |
@@ -1831,7 +1831,7 @@ receive_icmp_back (void *cls, | |||
1831 | { | 1831 | { |
1832 | struct GNUNET_TUN_IPv4Header *ipp = (struct GNUNET_TUN_IPv4Header *) &icmp[1]; | 1832 | struct GNUNET_TUN_IPv4Header *ipp = (struct GNUNET_TUN_IPv4Header *) &icmp[1]; |
1833 | struct GNUNET_TUN_UdpHeader *udp = (struct GNUNET_TUN_UdpHeader *) &ipp[1]; | 1833 | struct GNUNET_TUN_UdpHeader *udp = (struct GNUNET_TUN_UdpHeader *) &ipp[1]; |
1834 | 1834 | ||
1835 | if (mlen != 0) | 1835 | if (mlen != 0) |
1836 | { | 1836 | { |
1837 | /* sender did not strip ICMP payload? */ | 1837 | /* sender did not strip ICMP payload? */ |
@@ -1881,8 +1881,8 @@ receive_icmp_back (void *cls, | |||
1881 | break; | 1881 | break; |
1882 | case AF_INET6: | 1882 | case AF_INET6: |
1883 | { | 1883 | { |
1884 | size_t size = sizeof (struct GNUNET_TUN_IPv6Header) | 1884 | size_t size = sizeof (struct GNUNET_TUN_IPv6Header) |
1885 | + sizeof (struct GNUNET_TUN_IcmpHeader) | 1885 | + sizeof (struct GNUNET_TUN_IcmpHeader) |
1886 | + sizeof (struct GNUNET_MessageHeader) + | 1886 | + sizeof (struct GNUNET_MessageHeader) + |
1887 | sizeof (struct GNUNET_TUN_Layer2PacketHeader) + | 1887 | sizeof (struct GNUNET_TUN_Layer2PacketHeader) + |
1888 | mlen; | 1888 | mlen; |
@@ -1905,12 +1905,12 @@ receive_icmp_back (void *cls, | |||
1905 | &i2v[1], | 1905 | &i2v[1], |
1906 | mlen); | 1906 | mlen); |
1907 | 1907 | ||
1908 | /* For some ICMP types, we need to adjust (make up) the payload here. | 1908 | /* For some ICMP types, we need to adjust (make up) the payload here. |
1909 | Also, depending on the AF used on the other side, we have to | 1909 | Also, depending on the AF used on the other side, we have to |
1910 | do ICMP PT (translate ICMP types) */ | 1910 | do ICMP PT (translate ICMP types) */ |
1911 | switch (ntohl (i2v->af)) | 1911 | switch (ntohl (i2v->af)) |
1912 | { | 1912 | { |
1913 | case AF_INET: | 1913 | case AF_INET: |
1914 | /* ICMP PT 4-to-6 and possibly making up payloads */ | 1914 | /* ICMP PT 4-to-6 and possibly making up payloads */ |
1915 | switch (icmp->type) | 1915 | switch (icmp->type) |
1916 | { | 1916 | { |
@@ -1925,7 +1925,7 @@ receive_icmp_back (void *cls, | |||
1925 | { | 1925 | { |
1926 | struct GNUNET_TUN_IPv6Header *ipp = (struct GNUNET_TUN_IPv6Header *) &icmp[1]; | 1926 | struct GNUNET_TUN_IPv6Header *ipp = (struct GNUNET_TUN_IPv6Header *) &icmp[1]; |
1927 | struct GNUNET_TUN_UdpHeader *udp = (struct GNUNET_TUN_UdpHeader *) &ipp[1]; | 1927 | struct GNUNET_TUN_UdpHeader *udp = (struct GNUNET_TUN_UdpHeader *) &ipp[1]; |
1928 | 1928 | ||
1929 | if (mlen != 0) | 1929 | if (mlen != 0) |
1930 | { | 1930 | { |
1931 | /* sender did not strip ICMP payload? */ | 1931 | /* sender did not strip ICMP payload? */ |
@@ -1937,12 +1937,12 @@ receive_icmp_back (void *cls, | |||
1937 | make_up_icmpv6_payload (ts, ipp, udp); | 1937 | make_up_icmpv6_payload (ts, ipp, udp); |
1938 | } | 1938 | } |
1939 | break; | 1939 | break; |
1940 | case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED: | 1940 | case GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED: |
1941 | icmp->type = GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED; | 1941 | icmp->type = GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED; |
1942 | { | 1942 | { |
1943 | struct GNUNET_TUN_IPv6Header *ipp = (struct GNUNET_TUN_IPv6Header *) &icmp[1]; | 1943 | struct GNUNET_TUN_IPv6Header *ipp = (struct GNUNET_TUN_IPv6Header *) &icmp[1]; |
1944 | struct GNUNET_TUN_UdpHeader *udp = (struct GNUNET_TUN_UdpHeader *) &ipp[1]; | 1944 | struct GNUNET_TUN_UdpHeader *udp = (struct GNUNET_TUN_UdpHeader *) &ipp[1]; |
1945 | 1945 | ||
1946 | if (mlen != 0) | 1946 | if (mlen != 0) |
1947 | { | 1947 | { |
1948 | /* sender did not strip ICMP payload? */ | 1948 | /* sender did not strip ICMP payload? */ |
@@ -1957,7 +1957,7 @@ receive_icmp_back (void *cls, | |||
1957 | case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH: | 1957 | case GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH: |
1958 | GNUNET_STATISTICS_update (stats, | 1958 | GNUNET_STATISTICS_update (stats, |
1959 | gettext_noop ("# ICMPv4 packets dropped (impossible PT to v6)"), | 1959 | gettext_noop ("# ICMPv4 packets dropped (impossible PT to v6)"), |
1960 | 1, GNUNET_NO); | 1960 | 1, GNUNET_NO); |
1961 | return GNUNET_OK; | 1961 | return GNUNET_OK; |
1962 | default: | 1962 | default: |
1963 | GNUNET_break_op (0); | 1963 | GNUNET_break_op (0); |
@@ -1978,7 +1978,7 @@ receive_icmp_back (void *cls, | |||
1978 | { | 1978 | { |
1979 | struct GNUNET_TUN_IPv6Header *ipp = (struct GNUNET_TUN_IPv6Header *) &icmp[1]; | 1979 | struct GNUNET_TUN_IPv6Header *ipp = (struct GNUNET_TUN_IPv6Header *) &icmp[1]; |
1980 | struct GNUNET_TUN_UdpHeader *udp = (struct GNUNET_TUN_UdpHeader *) &ipp[1]; | 1980 | struct GNUNET_TUN_UdpHeader *udp = (struct GNUNET_TUN_UdpHeader *) &ipp[1]; |
1981 | 1981 | ||
1982 | if (mlen != 0) | 1982 | if (mlen != 0) |
1983 | { | 1983 | { |
1984 | /* sender did not strip ICMP payload? */ | 1984 | /* sender did not strip ICMP payload? */ |
@@ -2018,7 +2018,7 @@ receive_icmp_back (void *cls, | |||
2018 | default: | 2018 | default: |
2019 | GNUNET_assert (0); | 2019 | GNUNET_assert (0); |
2020 | } | 2020 | } |
2021 | GNUNET_CONTAINER_heap_update_cost (tunnel_heap, | 2021 | GNUNET_CONTAINER_heap_update_cost (tunnel_heap, |
2022 | ts->heap_node, | 2022 | ts->heap_node, |
2023 | GNUNET_TIME_absolute_get ().abs_value_us); | 2023 | GNUNET_TIME_absolute_get ().abs_value_us); |
2024 | return GNUNET_OK; | 2024 | return GNUNET_OK; |
@@ -2035,7 +2035,7 @@ receive_icmp_back (void *cls, | |||
2035 | * @param message the actual message | 2035 | * @param message the actual message |
2036 | * @return #GNUNET_OK to keep the connection open, | 2036 | * @return #GNUNET_OK to keep the connection open, |
2037 | * #GNUNET_SYSERR to close it (signal serious error) | 2037 | * #GNUNET_SYSERR to close it (signal serious error) |
2038 | */ | 2038 | */ |
2039 | static int | 2039 | static int |
2040 | receive_udp_back (void *cls, | 2040 | receive_udp_back (void *cls, |
2041 | struct GNUNET_MESH_Tunnel *tunnel, | 2041 | struct GNUNET_MESH_Tunnel *tunnel, |
@@ -2070,7 +2070,7 @@ receive_udp_back (void *cls, | |||
2070 | { | 2070 | { |
2071 | char sbuf[INET6_ADDRSTRLEN]; | 2071 | char sbuf[INET6_ADDRSTRLEN]; |
2072 | char dbuf[INET6_ADDRSTRLEN]; | 2072 | char dbuf[INET6_ADDRSTRLEN]; |
2073 | 2073 | ||
2074 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2074 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2075 | "Received UDP reply from mesh, sending %u bytes from %s:%u -> %s:%u via TUN\n", | 2075 | "Received UDP reply from mesh, sending %u bytes from %s:%u -> %s:%u via TUN\n", |
2076 | (unsigned int) mlen, | 2076 | (unsigned int) mlen, |
@@ -2083,8 +2083,8 @@ receive_udp_back (void *cls, | |||
2083 | { | 2083 | { |
2084 | case AF_INET: | 2084 | case AF_INET: |
2085 | { | 2085 | { |
2086 | size_t size = sizeof (struct GNUNET_TUN_IPv4Header) | 2086 | size_t size = sizeof (struct GNUNET_TUN_IPv4Header) |
2087 | + sizeof (struct GNUNET_TUN_UdpHeader) | 2087 | + sizeof (struct GNUNET_TUN_UdpHeader) |
2088 | + sizeof (struct GNUNET_MessageHeader) + | 2088 | + sizeof (struct GNUNET_MessageHeader) + |
2089 | sizeof (struct GNUNET_TUN_Layer2PacketHeader) + | 2089 | sizeof (struct GNUNET_TUN_Layer2PacketHeader) + |
2090 | mlen; | 2090 | mlen; |
@@ -2128,8 +2128,8 @@ receive_udp_back (void *cls, | |||
2128 | break; | 2128 | break; |
2129 | case AF_INET6: | 2129 | case AF_INET6: |
2130 | { | 2130 | { |
2131 | size_t size = sizeof (struct GNUNET_TUN_IPv6Header) | 2131 | size_t size = sizeof (struct GNUNET_TUN_IPv6Header) |
2132 | + sizeof (struct GNUNET_TUN_UdpHeader) | 2132 | + sizeof (struct GNUNET_TUN_UdpHeader) |
2133 | + sizeof (struct GNUNET_MessageHeader) + | 2133 | + sizeof (struct GNUNET_MessageHeader) + |
2134 | sizeof (struct GNUNET_TUN_Layer2PacketHeader) + | 2134 | sizeof (struct GNUNET_TUN_Layer2PacketHeader) + |
2135 | mlen; | 2135 | mlen; |
@@ -2173,7 +2173,7 @@ receive_udp_back (void *cls, | |||
2173 | default: | 2173 | default: |
2174 | GNUNET_assert (0); | 2174 | GNUNET_assert (0); |
2175 | } | 2175 | } |
2176 | GNUNET_CONTAINER_heap_update_cost (tunnel_heap, | 2176 | GNUNET_CONTAINER_heap_update_cost (tunnel_heap, |
2177 | ts->heap_node, | 2177 | ts->heap_node, |
2178 | GNUNET_TIME_absolute_get ().abs_value_us); | 2178 | GNUNET_TIME_absolute_get ().abs_value_us); |
2179 | return GNUNET_OK; | 2179 | return GNUNET_OK; |
@@ -2190,7 +2190,7 @@ receive_udp_back (void *cls, | |||
2190 | * @param message the actual message | 2190 | * @param message the actual message |
2191 | * @return #GNUNET_OK to keep the connection open, | 2191 | * @return #GNUNET_OK to keep the connection open, |
2192 | * #GNUNET_SYSERR to close it (signal serious error) | 2192 | * #GNUNET_SYSERR to close it (signal serious error) |
2193 | */ | 2193 | */ |
2194 | static int | 2194 | static int |
2195 | receive_tcp_back (void *cls, | 2195 | receive_tcp_back (void *cls, |
2196 | struct GNUNET_MESH_Tunnel *tunnel, | 2196 | struct GNUNET_MESH_Tunnel *tunnel, |
@@ -2220,7 +2220,7 @@ receive_tcp_back (void *cls, | |||
2220 | { | 2220 | { |
2221 | char sbuf[INET6_ADDRSTRLEN]; | 2221 | char sbuf[INET6_ADDRSTRLEN]; |
2222 | char dbuf[INET6_ADDRSTRLEN]; | 2222 | char dbuf[INET6_ADDRSTRLEN]; |
2223 | 2223 | ||
2224 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2224 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2225 | "Received TCP reply from mesh, sending %u bytes from %s:%u -> %s:%u via TUN\n", | 2225 | "Received TCP reply from mesh, sending %u bytes from %s:%u -> %s:%u via TUN\n", |
2226 | (unsigned int) mlen, | 2226 | (unsigned int) mlen, |
@@ -2238,8 +2238,8 @@ receive_tcp_back (void *cls, | |||
2238 | { | 2238 | { |
2239 | case AF_INET: | 2239 | case AF_INET: |
2240 | { | 2240 | { |
2241 | size_t size = sizeof (struct GNUNET_TUN_IPv4Header) | 2241 | size_t size = sizeof (struct GNUNET_TUN_IPv4Header) |
2242 | + sizeof (struct GNUNET_TUN_TcpHeader) | 2242 | + sizeof (struct GNUNET_TUN_TcpHeader) |
2243 | + sizeof (struct GNUNET_MessageHeader) + | 2243 | + sizeof (struct GNUNET_MessageHeader) + |
2244 | sizeof (struct GNUNET_TUN_Layer2PacketHeader) + | 2244 | sizeof (struct GNUNET_TUN_Layer2PacketHeader) + |
2245 | mlen; | 2245 | mlen; |
@@ -2277,8 +2277,8 @@ receive_tcp_back (void *cls, | |||
2277 | break; | 2277 | break; |
2278 | case AF_INET6: | 2278 | case AF_INET6: |
2279 | { | 2279 | { |
2280 | size_t size = sizeof (struct GNUNET_TUN_IPv6Header) | 2280 | size_t size = sizeof (struct GNUNET_TUN_IPv6Header) |
2281 | + sizeof (struct GNUNET_TUN_TcpHeader) | 2281 | + sizeof (struct GNUNET_TUN_TcpHeader) |
2282 | + sizeof (struct GNUNET_MessageHeader) + | 2282 | + sizeof (struct GNUNET_MessageHeader) + |
2283 | sizeof (struct GNUNET_TUN_Layer2PacketHeader) + | 2283 | sizeof (struct GNUNET_TUN_Layer2PacketHeader) + |
2284 | mlen; | 2284 | mlen; |
@@ -2315,7 +2315,7 @@ receive_tcp_back (void *cls, | |||
2315 | } | 2315 | } |
2316 | break; | 2316 | break; |
2317 | } | 2317 | } |
2318 | GNUNET_CONTAINER_heap_update_cost (tunnel_heap, | 2318 | GNUNET_CONTAINER_heap_update_cost (tunnel_heap, |
2319 | ts->heap_node, | 2319 | ts->heap_node, |
2320 | GNUNET_TIME_absolute_get ().abs_value_us); | 2320 | GNUNET_TIME_absolute_get ().abs_value_us); |
2321 | return GNUNET_OK; | 2321 | return GNUNET_OK; |
@@ -2342,10 +2342,10 @@ allocate_v4_address (struct in_addr *v4) | |||
2342 | unsigned int tries; | 2342 | unsigned int tries; |
2343 | 2343 | ||
2344 | GNUNET_assert (1 == inet_pton (AF_INET, ipv4addr, &addr)); | 2344 | GNUNET_assert (1 == inet_pton (AF_INET, ipv4addr, &addr)); |
2345 | GNUNET_assert (1 == inet_pton (AF_INET, ipv4mask, &mask)); | 2345 | GNUNET_assert (1 == inet_pton (AF_INET, ipv4mask, &mask)); |
2346 | /* Given 192.168.0.1/255.255.0.0, we want a mask | 2346 | /* Given 192.168.0.1/255.255.0.0, we want a mask |
2347 | of '192.168.255.255', thus: */ | 2347 | of '192.168.255.255', thus: */ |
2348 | mask.s_addr = addr.s_addr | ~mask.s_addr; | 2348 | mask.s_addr = addr.s_addr | ~mask.s_addr; |
2349 | tries = 0; | 2349 | tries = 0; |
2350 | do | 2350 | do |
2351 | { | 2351 | { |
@@ -2357,9 +2357,9 @@ allocate_v4_address (struct in_addr *v4) | |||
2357 | return GNUNET_SYSERR; | 2357 | return GNUNET_SYSERR; |
2358 | } | 2358 | } |
2359 | /* Pick random IPv4 address within the subnet, except 'addr' or 'mask' itself */ | 2359 | /* Pick random IPv4 address within the subnet, except 'addr' or 'mask' itself */ |
2360 | rnd.s_addr = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 2360 | rnd.s_addr = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
2361 | UINT32_MAX); | 2361 | UINT32_MAX); |
2362 | v4->s_addr = (addr.s_addr | rnd.s_addr) & mask.s_addr; | 2362 | v4->s_addr = (addr.s_addr | rnd.s_addr) & mask.s_addr; |
2363 | get_destination_key_from_ip (AF_INET, | 2363 | get_destination_key_from_ip (AF_INET, |
2364 | v4, | 2364 | v4, |
2365 | &key); | 2365 | &key); |
@@ -2399,7 +2399,7 @@ allocate_v6_address (struct in6_addr *v6) | |||
2399 | mask = addr; | 2399 | mask = addr; |
2400 | for (i=127;i>=ipv6prefix;i--) | 2400 | for (i=127;i>=ipv6prefix;i--) |
2401 | mask.s6_addr[i / 8] |= (1 << (i % 8)); | 2401 | mask.s6_addr[i / 8] |= (1 << (i % 8)); |
2402 | 2402 | ||
2403 | /* Pick random IPv6 address within the subnet, except 'addr' or 'mask' itself */ | 2403 | /* Pick random IPv6 address within the subnet, except 'addr' or 'mask' itself */ |
2404 | tries = 0; | 2404 | tries = 0; |
2405 | do | 2405 | do |
@@ -2414,7 +2414,7 @@ allocate_v6_address (struct in6_addr *v6) | |||
2414 | } | 2414 | } |
2415 | for (i=0;i<16;i++) | 2415 | for (i=0;i<16;i++) |
2416 | { | 2416 | { |
2417 | rnd.s6_addr[i] = (unsigned char) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 2417 | rnd.s6_addr[i] = (unsigned char) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
2418 | 256); | 2418 | 256); |
2419 | v6->s6_addr[i] | 2419 | v6->s6_addr[i] |
2420 | = (addr.s6_addr[i] | rnd.s6_addr[i]) & mask.s6_addr[i]; | 2420 | = (addr.s6_addr[i] | rnd.s6_addr[i]) & mask.s6_addr[i]; |
@@ -2466,7 +2466,7 @@ free_destination_entry (struct DestinationEntry *de) | |||
2466 | if (NULL != de->heap_node) | 2466 | if (NULL != de->heap_node) |
2467 | { | 2467 | { |
2468 | GNUNET_CONTAINER_heap_remove_node (de->heap_node); | 2468 | GNUNET_CONTAINER_heap_remove_node (de->heap_node); |
2469 | de->heap_node = NULL; | 2469 | de->heap_node = NULL; |
2470 | GNUNET_assert (GNUNET_YES == | 2470 | GNUNET_assert (GNUNET_YES == |
2471 | GNUNET_CONTAINER_multihashmap_remove (destination_map, | 2471 | GNUNET_CONTAINER_multihashmap_remove (destination_map, |
2472 | &de->key, | 2472 | &de->key, |
@@ -2481,7 +2481,7 @@ free_destination_entry (struct DestinationEntry *de) | |||
2481 | * | 2481 | * |
2482 | * @param except destination that must NOT be cleaned up, even if it is the oldest | 2482 | * @param except destination that must NOT be cleaned up, even if it is the oldest |
2483 | */ | 2483 | */ |
2484 | static void | 2484 | static void |
2485 | expire_destination (struct DestinationEntry *except) | 2485 | expire_destination (struct DestinationEntry *except) |
2486 | { | 2486 | { |
2487 | struct DestinationEntry *de; | 2487 | struct DestinationEntry *de; |
@@ -2495,13 +2495,13 @@ expire_destination (struct DestinationEntry *except) | |||
2495 | 2495 | ||
2496 | 2496 | ||
2497 | /** | 2497 | /** |
2498 | * Allocate an IP address for the response. | 2498 | * Allocate an IP address for the response. |
2499 | * | 2499 | * |
2500 | * @param result_af desired address family; set to the actual | 2500 | * @param result_af desired address family; set to the actual |
2501 | * address family; can initially be AF_UNSPEC if there | 2501 | * address family; can initially be AF_UNSPEC if there |
2502 | * is no preference; will be set to AF_UNSPEC if the | 2502 | * is no preference; will be set to AF_UNSPEC if the |
2503 | * allocation failed | 2503 | * allocation failed |
2504 | * @param addr set to either v4 or v6 depending on which | 2504 | * @param addr set to either v4 or v6 depending on which |
2505 | * storage location was used; set to NULL if allocation failed | 2505 | * storage location was used; set to NULL if allocation failed |
2506 | * @param v4 storage space for an IPv4 address | 2506 | * @param v4 storage space for an IPv4 address |
2507 | * @param v6 storage space for an IPv6 address | 2507 | * @param v6 storage space for an IPv6 address |
@@ -2550,7 +2550,7 @@ allocate_response_ip (int *result_af, | |||
2550 | return GNUNET_SYSERR; | 2550 | return GNUNET_SYSERR; |
2551 | } | 2551 | } |
2552 | return GNUNET_OK; | 2552 | return GNUNET_OK; |
2553 | } | 2553 | } |
2554 | 2554 | ||
2555 | 2555 | ||
2556 | /** | 2556 | /** |
@@ -2577,7 +2577,7 @@ service_redirect_to_ip (void *cls, | |||
2577 | void *addr; | 2577 | void *addr; |
2578 | struct DestinationEntry *de; | 2578 | struct DestinationEntry *de; |
2579 | struct GNUNET_HashCode key; | 2579 | struct GNUNET_HashCode key; |
2580 | 2580 | ||
2581 | /* validate and parse request */ | 2581 | /* validate and parse request */ |
2582 | mlen = ntohs (message->size); | 2582 | mlen = ntohs (message->size); |
2583 | if (mlen < sizeof (struct RedirectToIpRequestMessage)) | 2583 | if (mlen < sizeof (struct RedirectToIpRequestMessage)) |
@@ -2596,7 +2596,7 @@ service_redirect_to_ip (void *cls, | |||
2596 | { | 2596 | { |
2597 | GNUNET_break (0); | 2597 | GNUNET_break (0); |
2598 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 2598 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2599 | return; | 2599 | return; |
2600 | } | 2600 | } |
2601 | break; | 2601 | break; |
2602 | case AF_INET6: | 2602 | case AF_INET6: |
@@ -2604,13 +2604,13 @@ service_redirect_to_ip (void *cls, | |||
2604 | { | 2604 | { |
2605 | GNUNET_break (0); | 2605 | GNUNET_break (0); |
2606 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 2606 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2607 | return; | 2607 | return; |
2608 | } | 2608 | } |
2609 | break; | 2609 | break; |
2610 | default: | 2610 | default: |
2611 | GNUNET_break (0); | 2611 | GNUNET_break (0); |
2612 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 2612 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2613 | return; | 2613 | return; |
2614 | } | 2614 | } |
2615 | 2615 | ||
2616 | /* allocate response IP */ | 2616 | /* allocate response IP */ |
@@ -2620,13 +2620,13 @@ service_redirect_to_ip (void *cls, | |||
2620 | &v4, &v6)) | 2620 | &v4, &v6)) |
2621 | { | 2621 | { |
2622 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 2622 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2623 | return; | 2623 | return; |
2624 | } | 2624 | } |
2625 | /* send reply with our IP address */ | 2625 | /* send reply with our IP address */ |
2626 | send_client_reply (client, | 2626 | send_client_reply (client, |
2627 | msg->request_id, | 2627 | msg->request_id, |
2628 | result_af, | 2628 | result_af, |
2629 | addr); | 2629 | addr); |
2630 | if (result_af == AF_UNSPEC) | 2630 | if (result_af == AF_UNSPEC) |
2631 | { | 2631 | { |
2632 | /* failure, we're done */ | 2632 | /* failure, we're done */ |
@@ -2637,14 +2637,14 @@ service_redirect_to_ip (void *cls, | |||
2637 | { | 2637 | { |
2638 | char sbuf[INET6_ADDRSTRLEN]; | 2638 | char sbuf[INET6_ADDRSTRLEN]; |
2639 | char dbuf[INET6_ADDRSTRLEN]; | 2639 | char dbuf[INET6_ADDRSTRLEN]; |
2640 | 2640 | ||
2641 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2641 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2642 | "Allocated address %s for redirection via exit to %s\n", | 2642 | "Allocated address %s for redirection via exit to %s\n", |
2643 | inet_ntop (result_af, addr, sbuf, sizeof (sbuf)), | 2643 | inet_ntop (result_af, addr, sbuf, sizeof (sbuf)), |
2644 | inet_ntop (addr_af, | 2644 | inet_ntop (addr_af, |
2645 | &msg[1], dbuf, sizeof (dbuf))); | 2645 | &msg[1], dbuf, sizeof (dbuf))); |
2646 | } | 2646 | } |
2647 | 2647 | ||
2648 | /* setup destination record */ | 2648 | /* setup destination record */ |
2649 | de = GNUNET_new (struct DestinationEntry); | 2649 | de = GNUNET_new (struct DestinationEntry); |
2650 | de->is_service = GNUNET_NO; | 2650 | de->is_service = GNUNET_NO; |
@@ -2683,7 +2683,7 @@ service_redirect_to_ip (void *cls, | |||
2683 | * @param message redirection request (a `struct RedirectToPeerRequestMessage`) | 2683 | * @param message redirection request (a `struct RedirectToPeerRequestMessage`) |
2684 | */ | 2684 | */ |
2685 | static void | 2685 | static void |
2686 | service_redirect_to_service (void *cls, | 2686 | service_redirect_to_service (void *cls, |
2687 | struct GNUNET_SERVER_Client *client, | 2687 | struct GNUNET_SERVER_Client *client, |
2688 | const struct GNUNET_MessageHeader *message) | 2688 | const struct GNUNET_MessageHeader *message) |
2689 | { | 2689 | { |
@@ -2696,7 +2696,7 @@ service_redirect_to_service (void *cls, | |||
2696 | struct GNUNET_HashCode key; | 2696 | struct GNUNET_HashCode key; |
2697 | struct TunnelState *ts; | 2697 | struct TunnelState *ts; |
2698 | struct DestinationTunnel *dt; | 2698 | struct DestinationTunnel *dt; |
2699 | 2699 | ||
2700 | /* parse request */ | 2700 | /* parse request */ |
2701 | msg = (const struct RedirectToServiceRequestMessage *) message; | 2701 | msg = (const struct RedirectToServiceRequestMessage *) message; |
2702 | 2702 | ||
@@ -2707,12 +2707,12 @@ service_redirect_to_service (void *cls, | |||
2707 | &v4, &v6)) | 2707 | &v4, &v6)) |
2708 | { | 2708 | { |
2709 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 2709 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2710 | return; | 2710 | return; |
2711 | } | 2711 | } |
2712 | send_client_reply (client, | 2712 | send_client_reply (client, |
2713 | msg->request_id, | 2713 | msg->request_id, |
2714 | result_af, | 2714 | result_af, |
2715 | addr); | 2715 | addr); |
2716 | if (result_af == AF_UNSPEC) | 2716 | if (result_af == AF_UNSPEC) |
2717 | { | 2717 | { |
2718 | /* failure, we're done */ | 2718 | /* failure, we're done */ |
@@ -2724,14 +2724,14 @@ service_redirect_to_service (void *cls, | |||
2724 | 2724 | ||
2725 | { | 2725 | { |
2726 | char sbuf[INET6_ADDRSTRLEN]; | 2726 | char sbuf[INET6_ADDRSTRLEN]; |
2727 | 2727 | ||
2728 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2728 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2729 | "Allocated address %s for redirection to service %s on peer %s\n", | 2729 | "Allocated address %s for redirection to service %s on peer %s\n", |
2730 | inet_ntop (result_af, addr, sbuf, sizeof (sbuf)), | 2730 | inet_ntop (result_af, addr, sbuf, sizeof (sbuf)), |
2731 | GNUNET_h2s (&msg->service_descriptor), | 2731 | GNUNET_h2s (&msg->service_descriptor), |
2732 | GNUNET_i2s (&msg->target)); | 2732 | GNUNET_i2s (&msg->target)); |
2733 | } | 2733 | } |
2734 | 2734 | ||
2735 | /* setup destination record */ | 2735 | /* setup destination record */ |
2736 | de = GNUNET_new (struct DestinationEntry); | 2736 | de = GNUNET_new (struct DestinationEntry); |
2737 | de->is_service = GNUNET_YES; | 2737 | de->is_service = GNUNET_YES; |
@@ -2778,15 +2778,15 @@ service_redirect_to_service (void *cls, | |||
2778 | /** | 2778 | /** |
2779 | * Function called whenever a tunnel is destroyed. Should clean up | 2779 | * Function called whenever a tunnel is destroyed. Should clean up |
2780 | * any associated state. | 2780 | * any associated state. |
2781 | * | 2781 | * |
2782 | * @param cls closure (set from #GNUNET_MESH_connect) | 2782 | * @param cls closure (set from #GNUNET_MESH_connect) |
2783 | * @param tunnel connection to the other end (henceforth invalid) | 2783 | * @param tunnel connection to the other end (henceforth invalid) |
2784 | * @param tunnel_ctx place where local state associated | 2784 | * @param tunnel_ctx place where local state associated |
2785 | * with the tunnel is stored (our `struct TunnelState`) | 2785 | * with the tunnel is stored (our `struct TunnelState`) |
2786 | */ | 2786 | */ |
2787 | static void | 2787 | static void |
2788 | tunnel_cleaner (void *cls, | 2788 | tunnel_cleaner (void *cls, |
2789 | const struct GNUNET_MESH_Tunnel *tunnel, | 2789 | const struct GNUNET_MESH_Tunnel *tunnel, |
2790 | void *tunnel_ctx) | 2790 | void *tunnel_ctx) |
2791 | { | 2791 | { |
2792 | struct TunnelState *ts = tunnel_ctx; | 2792 | struct TunnelState *ts = tunnel_ctx; |
@@ -2851,7 +2851,7 @@ cleanup (void *cls, | |||
2851 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2851 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2852 | "VPN is shutting down\n"); | 2852 | "VPN is shutting down\n"); |
2853 | if (NULL != destination_map) | 2853 | if (NULL != destination_map) |
2854 | { | 2854 | { |
2855 | GNUNET_CONTAINER_multihashmap_iterate (destination_map, | 2855 | GNUNET_CONTAINER_multihashmap_iterate (destination_map, |
2856 | &cleanup_destination, | 2856 | &cleanup_destination, |
2857 | NULL); | 2857 | NULL); |
@@ -2864,7 +2864,7 @@ cleanup (void *cls, | |||
2864 | destination_heap = NULL; | 2864 | destination_heap = NULL; |
2865 | } | 2865 | } |
2866 | if (NULL != tunnel_map) | 2866 | if (NULL != tunnel_map) |
2867 | { | 2867 | { |
2868 | GNUNET_CONTAINER_multihashmap_iterate (tunnel_map, | 2868 | GNUNET_CONTAINER_multihashmap_iterate (tunnel_map, |
2869 | &cleanup_tunnel, | 2869 | &cleanup_tunnel, |
2870 | NULL); | 2870 | NULL); |
@@ -2916,8 +2916,8 @@ run (void *cls, | |||
2916 | static const struct GNUNET_SERVER_MessageHandler service_handlers[] = { | 2916 | static const struct GNUNET_SERVER_MessageHandler service_handlers[] = { |
2917 | /* callback, cls, type, size */ | 2917 | /* callback, cls, type, size */ |
2918 | { &service_redirect_to_ip, NULL, GNUNET_MESSAGE_TYPE_VPN_CLIENT_REDIRECT_TO_IP, 0}, | 2918 | { &service_redirect_to_ip, NULL, GNUNET_MESSAGE_TYPE_VPN_CLIENT_REDIRECT_TO_IP, 0}, |
2919 | { &service_redirect_to_service, NULL, | 2919 | { &service_redirect_to_service, NULL, |
2920 | GNUNET_MESSAGE_TYPE_VPN_CLIENT_REDIRECT_TO_SERVICE, | 2920 | GNUNET_MESSAGE_TYPE_VPN_CLIENT_REDIRECT_TO_SERVICE, |
2921 | sizeof (struct RedirectToServiceRequestMessage) }, | 2921 | sizeof (struct RedirectToServiceRequestMessage) }, |
2922 | {NULL, NULL, 0, 0} | 2922 | {NULL, NULL, 0, 0} |
2923 | }; | 2923 | }; |
@@ -2982,7 +2982,7 @@ run (void *cls, | |||
2982 | &ipv6addr) || | 2982 | &ipv6addr) || |
2983 | (1 != inet_pton (AF_INET6, ipv6addr, &v6))) ) | 2983 | (1 != inet_pton (AF_INET6, ipv6addr, &v6))) ) |
2984 | { | 2984 | { |
2985 | GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, "VPN", "IPV6ADDR", | 2985 | GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, "VPN", "IPV6ADDR", |
2986 | _("Must specify valid IPv6 address")); | 2986 | _("Must specify valid IPv6 address")); |
2987 | GNUNET_SCHEDULER_shutdown (); | 2987 | GNUNET_SCHEDULER_shutdown (); |
2988 | return; | 2988 | return; |
@@ -3023,7 +3023,7 @@ run (void *cls, | |||
3023 | &ipv4addr) || | 3023 | &ipv4addr) || |
3024 | (1 != inet_pton (AF_INET, ipv4addr, &v4))) ) | 3024 | (1 != inet_pton (AF_INET, ipv4addr, &v4))) ) |
3025 | { | 3025 | { |
3026 | GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, "VPN", "IPV4ADDR", | 3026 | GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, "VPN", "IPV4ADDR", |
3027 | _("Must specify valid IPv4 address")); | 3027 | _("Must specify valid IPv4 address")); |
3028 | GNUNET_SCHEDULER_shutdown (); | 3028 | GNUNET_SCHEDULER_shutdown (); |
3029 | return; | 3029 | return; |
@@ -3051,9 +3051,9 @@ run (void *cls, | |||
3051 | vpn_argv[6] = NULL; | 3051 | vpn_argv[6] = NULL; |
3052 | 3052 | ||
3053 | mesh_handle = | 3053 | mesh_handle = |
3054 | GNUNET_MESH_connect (cfg_, NULL, | 3054 | GNUNET_MESH_connect (cfg_, NULL, |
3055 | NULL, | 3055 | NULL, |
3056 | &tunnel_cleaner, | 3056 | &tunnel_cleaner, |
3057 | mesh_handlers, | 3057 | mesh_handlers, |
3058 | NULL); | 3058 | NULL); |
3059 | helper_handle = GNUNET_HELPER_start (GNUNET_NO, | 3059 | helper_handle = GNUNET_HELPER_start (GNUNET_NO, |
@@ -3076,7 +3076,7 @@ int | |||
3076 | main (int argc, char *const *argv) | 3076 | main (int argc, char *const *argv) |
3077 | { | 3077 | { |
3078 | return (GNUNET_OK == | 3078 | return (GNUNET_OK == |
3079 | GNUNET_SERVICE_run (argc, argv, "vpn", | 3079 | GNUNET_SERVICE_run (argc, argv, "vpn", |
3080 | GNUNET_SERVICE_OPTION_NONE, | 3080 | GNUNET_SERVICE_OPTION_NONE, |
3081 | &run, NULL)) ? global_ret : 1; | 3081 | &run, NULL)) ? global_ret : 1; |
3082 | } | 3082 | } |
diff --git a/src/vpn/gnunet-vpn.c b/src/vpn/gnunet-vpn.c index b4d6824d9..5a35a0df5 100644 --- a/src/vpn/gnunet-vpn.c +++ b/src/vpn/gnunet-vpn.c | |||
@@ -122,7 +122,7 @@ do_disconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
122 | * will match 'result_af' from the request | 122 | * will match 'result_af' from the request |
123 | * @param address IP address (struct in_addr or struct in_addr6, depending on 'af') | 123 | * @param address IP address (struct in_addr or struct in_addr6, depending on 'af') |
124 | * that the VPN allocated for the redirection; | 124 | * that the VPN allocated for the redirection; |
125 | * traffic to this IP will now be redirected to the | 125 | * traffic to this IP will now be redirected to the |
126 | * specified target peer; NULL on error | 126 | * specified target peer; NULL on error |
127 | */ | 127 | */ |
128 | static void | 128 | static void |
@@ -167,7 +167,7 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
167 | { | 167 | { |
168 | int dst_af; | 168 | int dst_af; |
169 | int req_af; | 169 | int req_af; |
170 | struct GNUNET_PeerIdentity peer; | 170 | struct GNUNET_PeerIdentity peer; |
171 | struct GNUNET_HashCode sd; | 171 | struct GNUNET_HashCode sd; |
172 | const void *addr; | 172 | const void *addr; |
173 | struct in_addr v4; | 173 | struct in_addr v4; |
@@ -194,7 +194,7 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
194 | } | 194 | } |
195 | if (ipv6) | 195 | if (ipv6) |
196 | req_af = AF_INET6; | 196 | req_af = AF_INET6; |
197 | 197 | ||
198 | if (NULL == target_ip) | 198 | if (NULL == target_ip) |
199 | { | 199 | { |
200 | if (NULL == service_name) | 200 | if (NULL == service_name) |
@@ -233,7 +233,7 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
233 | FPRINTF (stderr, _("`%s' is not a valid peer identifier.\n"), | 233 | FPRINTF (stderr, _("`%s' is not a valid peer identifier.\n"), |
234 | peer_id); | 234 | peer_id); |
235 | goto error; | 235 | goto error; |
236 | } | 236 | } |
237 | GNUNET_CRYPTO_hash (service_name, | 237 | GNUNET_CRYPTO_hash (service_name, |
238 | strlen (service_name), | 238 | strlen (service_name), |
239 | &sd); | 239 | &sd); |
@@ -265,7 +265,7 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
265 | { | 265 | { |
266 | dst_af = AF_INET6; | 266 | dst_af = AF_INET6; |
267 | addr = &v6; | 267 | addr = &v6; |
268 | } | 268 | } |
269 | request = GNUNET_VPN_redirect_to_ip (handle, | 269 | request = GNUNET_VPN_redirect_to_ip (handle, |
270 | req_af, | 270 | req_af, |
271 | dst_af, | 271 | dst_af, |
diff --git a/src/vpn/vpn.h b/src/vpn/vpn.h index b74b5b766..a487d8113 100644 --- a/src/vpn/vpn.h +++ b/src/vpn/vpn.h | |||
@@ -46,7 +46,7 @@ struct RedirectToIpRequestMessage | |||
46 | * Always zero. | 46 | * Always zero. |
47 | */ | 47 | */ |
48 | uint32_t reserved GNUNET_PACKED; | 48 | uint32_t reserved GNUNET_PACKED; |
49 | 49 | ||
50 | /** | 50 | /** |
51 | * How long should the redirection be maintained at most? | 51 | * How long should the redirection be maintained at most? |
52 | */ | 52 | */ |
@@ -69,7 +69,7 @@ struct RedirectToIpRequestMessage | |||
69 | uint64_t request_id GNUNET_PACKED; | 69 | uint64_t request_id GNUNET_PACKED; |
70 | 70 | ||
71 | /* followed by destination address ('struct in_addr' or 'struct in6_addr') */ | 71 | /* followed by destination address ('struct in_addr' or 'struct in6_addr') */ |
72 | 72 | ||
73 | }; | 73 | }; |
74 | 74 | ||
75 | 75 | ||
@@ -89,7 +89,7 @@ struct RedirectToServiceRequestMessage | |||
89 | * Always zero. | 89 | * Always zero. |
90 | */ | 90 | */ |
91 | uint32_t reserved GNUNET_PACKED; | 91 | uint32_t reserved GNUNET_PACKED; |
92 | 92 | ||
93 | /** | 93 | /** |
94 | * How long should the redirection be maintained at most? | 94 | * How long should the redirection be maintained at most? |
95 | */ | 95 | */ |
@@ -99,7 +99,7 @@ struct RedirectToServiceRequestMessage | |||
99 | * Desired protocol (IPPROTO_UDP or IPPROTO_TCP) | 99 | * Desired protocol (IPPROTO_UDP or IPPROTO_TCP) |
100 | */ | 100 | */ |
101 | int32_t protocol GNUNET_PACKED; | 101 | int32_t protocol GNUNET_PACKED; |
102 | 102 | ||
103 | /** | 103 | /** |
104 | * Address family desired for the result (AF_INET or AF_INET6 or AF_UNSPEC, in nbo) | 104 | * Address family desired for the result (AF_INET or AF_INET6 or AF_UNSPEC, in nbo) |
105 | */ | 105 | */ |
@@ -130,7 +130,7 @@ struct RedirectToServiceRequestMessage | |||
130 | */ | 130 | */ |
131 | struct RedirectToIpResponseMessage | 131 | struct RedirectToIpResponseMessage |
132 | { | 132 | { |
133 | 133 | ||
134 | /** | 134 | /** |
135 | * Type is #GNUNET_MESSAGE_TYPE_VPN_CLIENT_USE_IP | 135 | * Type is #GNUNET_MESSAGE_TYPE_VPN_CLIENT_USE_IP |
136 | */ | 136 | */ |
@@ -148,7 +148,7 @@ struct RedirectToIpResponseMessage | |||
148 | uint64_t request_id GNUNET_PACKED; | 148 | uint64_t request_id GNUNET_PACKED; |
149 | 149 | ||
150 | /* followed by destination address ('struct in_addr' or 'struct in6_addr') */ | 150 | /* followed by destination address ('struct in_addr' or 'struct in6_addr') */ |
151 | 151 | ||
152 | }; | 152 | }; |
153 | 153 | ||
154 | GNUNET_NETWORK_STRUCT_END | 154 | GNUNET_NETWORK_STRUCT_END |
diff --git a/src/vpn/vpn_api.c b/src/vpn/vpn_api.c index 8539a6a37..cf493cc52 100644 --- a/src/vpn/vpn_api.c +++ b/src/vpn/vpn_api.c | |||
@@ -106,7 +106,7 @@ struct GNUNET_VPN_RedirectionRequest | |||
106 | * Function to call with the designated IP address. | 106 | * Function to call with the designated IP address. |
107 | */ | 107 | */ |
108 | GNUNET_VPN_AllocationCallback cb; | 108 | GNUNET_VPN_AllocationCallback cb; |
109 | 109 | ||
110 | /** | 110 | /** |
111 | * Closure for 'cb'. | 111 | * Closure for 'cb'. |
112 | */ | 112 | */ |
@@ -120,7 +120,7 @@ struct GNUNET_VPN_RedirectionRequest | |||
120 | /** | 120 | /** |
121 | * For service redirection, service descriptor. | 121 | * For service redirection, service descriptor. |
122 | */ | 122 | */ |
123 | struct GNUNET_HashCode serv; | 123 | struct GNUNET_HashCode serv; |
124 | 124 | ||
125 | /** | 125 | /** |
126 | * At what time should the created service mapping expire? | 126 | * At what time should the created service mapping expire? |
@@ -141,7 +141,7 @@ struct GNUNET_VPN_RedirectionRequest | |||
141 | * Address family of 'addr'. AF_INET or AF_INET6. | 141 | * Address family of 'addr'. AF_INET or AF_INET6. |
142 | */ | 142 | */ |
143 | int addr_af; | 143 | int addr_af; |
144 | 144 | ||
145 | /** | 145 | /** |
146 | * For service redirection, IPPROT_UDP or IPPROTO_TCP. | 146 | * For service redirection, IPPROT_UDP or IPPROTO_TCP. |
147 | */ | 147 | */ |
@@ -165,7 +165,7 @@ reconnect (struct GNUNET_VPN_Handle *vh); | |||
165 | * @param cls the 'struct GNUNET_VPN_Handle' | 165 | * @param cls the 'struct GNUNET_VPN_Handle' |
166 | * @param msg message received, NULL on timeout or fatal error | 166 | * @param msg message received, NULL on timeout or fatal error |
167 | */ | 167 | */ |
168 | static void | 168 | static void |
169 | receive_response (void *cls, | 169 | receive_response (void *cls, |
170 | const struct GNUNET_MessageHeader* msg) | 170 | const struct GNUNET_MessageHeader* msg) |
171 | { | 171 | { |
@@ -176,7 +176,7 @@ receive_response (void *cls, | |||
176 | size_t alen; | 176 | size_t alen; |
177 | int af; | 177 | int af; |
178 | 178 | ||
179 | if (NULL == msg) | 179 | if (NULL == msg) |
180 | { | 180 | { |
181 | reconnect (vh); | 181 | reconnect (vh); |
182 | return; | 182 | return; |
@@ -212,10 +212,10 @@ receive_response (void *cls, | |||
212 | GNUNET_break (0); | 212 | GNUNET_break (0); |
213 | reconnect (vh); | 213 | reconnect (vh); |
214 | return; | 214 | return; |
215 | } | 215 | } |
216 | GNUNET_CLIENT_receive (vh->client, | 216 | GNUNET_CLIENT_receive (vh->client, |
217 | &receive_response, vh, | 217 | &receive_response, vh, |
218 | GNUNET_TIME_UNIT_FOREVER_REL); | 218 | GNUNET_TIME_UNIT_FOREVER_REL); |
219 | for (rr = vh->rr_head; NULL != rr; rr = rr->next) | 219 | for (rr = vh->rr_head; NULL != rr; rr = rr->next) |
220 | { | 220 | { |
221 | if (rr->request_id == rm->request_id) | 221 | if (rr->request_id == rm->request_id) |
@@ -260,9 +260,9 @@ transmit_request (void *cls, | |||
260 | while ( (NULL != rr) && | 260 | while ( (NULL != rr) && |
261 | (0 != rr->request_id) ) | 261 | (0 != rr->request_id) ) |
262 | rr = rr->next; | 262 | rr = rr->next; |
263 | if (NULL == rr) | 263 | if (NULL == rr) |
264 | return 0; | 264 | return 0; |
265 | if (0 == size) | 265 | if (0 == size) |
266 | { | 266 | { |
267 | reconnect (vh); | 267 | reconnect (vh); |
268 | return 0; | 268 | return 0; |
@@ -272,7 +272,7 @@ transmit_request (void *cls, | |||
272 | if (0 == vh->request_id_gen) | 272 | if (0 == vh->request_id_gen) |
273 | GNUNET_CLIENT_receive (vh->client, | 273 | GNUNET_CLIENT_receive (vh->client, |
274 | &receive_response, vh, | 274 | &receive_response, vh, |
275 | GNUNET_TIME_UNIT_FOREVER_REL); | 275 | GNUNET_TIME_UNIT_FOREVER_REL); |
276 | if (NULL == rr->addr) | 276 | if (NULL == rr->addr) |
277 | { | 277 | { |
278 | ret = sizeof (struct RedirectToServiceRequestMessage); | 278 | ret = sizeof (struct RedirectToServiceRequestMessage); |
@@ -285,7 +285,7 @@ transmit_request (void *cls, | |||
285 | rs.result_af = htonl (rr->result_af); | 285 | rs.result_af = htonl (rr->result_af); |
286 | rs.target = rr->peer; | 286 | rs.target = rr->peer; |
287 | rs.service_descriptor = rr->serv; | 287 | rs.service_descriptor = rr->serv; |
288 | rs.request_id = rr->request_id = ++vh->request_id_gen; | 288 | rs.request_id = rr->request_id = ++vh->request_id_gen; |
289 | memcpy (buf, &rs, sizeof (struct RedirectToServiceRequestMessage)); | 289 | memcpy (buf, &rs, sizeof (struct RedirectToServiceRequestMessage)); |
290 | } | 290 | } |
291 | else | 291 | else |
@@ -332,7 +332,7 @@ transmit_request (void *cls, | |||
332 | 332 | ||
333 | /** | 333 | /** |
334 | * Add a request to our request queue and transmit it. | 334 | * Add a request to our request queue and transmit it. |
335 | * | 335 | * |
336 | * @param rr request to queue and transmit. | 336 | * @param rr request to queue and transmit. |
337 | */ | 337 | */ |
338 | static void | 338 | static void |
@@ -366,12 +366,12 @@ connect_task (void *cls, | |||
366 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 366 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
367 | { | 367 | { |
368 | struct GNUNET_VPN_Handle *vh = cls; | 368 | struct GNUNET_VPN_Handle *vh = cls; |
369 | 369 | ||
370 | vh->rt = GNUNET_SCHEDULER_NO_TASK; | 370 | vh->rt = GNUNET_SCHEDULER_NO_TASK; |
371 | vh->client = GNUNET_CLIENT_connect ("vpn", vh->cfg); | 371 | vh->client = GNUNET_CLIENT_connect ("vpn", vh->cfg); |
372 | GNUNET_assert (NULL != vh->client); | 372 | GNUNET_assert (NULL != vh->client); |
373 | GNUNET_assert (NULL == vh->th); | 373 | GNUNET_assert (NULL == vh->th); |
374 | if (NULL != vh->rr_head) | 374 | if (NULL != vh->rr_head) |
375 | vh->th = GNUNET_CLIENT_notify_transmit_ready (vh->client, | 375 | vh->th = GNUNET_CLIENT_notify_transmit_ready (vh->client, |
376 | sizeof (struct RedirectToServiceRequestMessage), | 376 | sizeof (struct RedirectToServiceRequestMessage), |
377 | GNUNET_TIME_UNIT_FOREVER_REL, | 377 | GNUNET_TIME_UNIT_FOREVER_REL, |
@@ -395,7 +395,7 @@ reconnect (struct GNUNET_VPN_Handle *vh) | |||
395 | { | 395 | { |
396 | GNUNET_CLIENT_notify_transmit_ready_cancel (vh->th); | 396 | GNUNET_CLIENT_notify_transmit_ready_cancel (vh->th); |
397 | vh->th = NULL; | 397 | vh->th = NULL; |
398 | } | 398 | } |
399 | GNUNET_CLIENT_disconnect (vh->client); | 399 | GNUNET_CLIENT_disconnect (vh->client); |
400 | vh->client = NULL; | 400 | vh->client = NULL; |
401 | vh->request_id_gen = 0; | 401 | vh->request_id_gen = 0; |
@@ -405,7 +405,7 @@ reconnect (struct GNUNET_VPN_Handle *vh) | |||
405 | GNUNET_TIME_relative_min (GNUNET_TIME_relative_multiply (vh->backoff, 2), | 405 | GNUNET_TIME_relative_min (GNUNET_TIME_relative_multiply (vh->backoff, 2), |
406 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30))); | 406 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30))); |
407 | vh->rt = GNUNET_SCHEDULER_add_delayed (vh->backoff, | 407 | vh->rt = GNUNET_SCHEDULER_add_delayed (vh->backoff, |
408 | &connect_task, | 408 | &connect_task, |
409 | vh); | 409 | vh); |
410 | } | 410 | } |
411 | 411 | ||
@@ -540,7 +540,7 @@ GNUNET_VPN_redirect_to_ip (struct GNUNET_VPN_Handle *vh, | |||
540 | * Connect to the VPN service | 540 | * Connect to the VPN service |
541 | * | 541 | * |
542 | * @param cfg configuration to use | 542 | * @param cfg configuration to use |
543 | * @return VPN handle | 543 | * @return VPN handle |
544 | */ | 544 | */ |
545 | struct GNUNET_VPN_Handle * | 545 | struct GNUNET_VPN_Handle * |
546 | GNUNET_VPN_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) | 546 | GNUNET_VPN_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) |