aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Fuchs <christian.fuchs@cfuchs.net>2013-01-30 17:45:58 +0000
committerChristian Fuchs <christian.fuchs@cfuchs.net>2013-01-30 17:45:58 +0000
commita41c9ae56159e89e05770588bcb8ab23cc52a87a (patch)
treed8c13566d0c5d47101515e4119be95b71a4d394b /src
parentfcd297a816ac50e34d7b421fd5950c39da491e7d (diff)
downloadgnunet-a41c9ae56159e89e05770588bcb8ab23cc52a87a.tar.gz
gnunet-a41c9ae56159e89e05770588bcb8ab23cc52a87a.zip
added nice debug output for gnunet-herlper-vpn-windows.
Diffstat (limited to 'src')
-rw-r--r--src/vpn/gnunet-helper-vpn-windows.c142
1 files changed, 88 insertions, 54 deletions
diff --git a/src/vpn/gnunet-helper-vpn-windows.c b/src/vpn/gnunet-helper-vpn-windows.c
index 0a3bdad16..e58937c42 100644
--- a/src/vpn/gnunet-helper-vpn-windows.c
+++ b/src/vpn/gnunet-helper-vpn-windows.c
@@ -65,7 +65,7 @@
65 * Name or Path+Name of our driver in Unicode. 65 * Name or Path+Name of our driver in Unicode.
66 * The .sys and .cat files HAVE to be in the same location as this file! 66 * The .sys and .cat files HAVE to be in the same location as this file!
67 */ 67 */
68#define INF_FILE "OemWin2k.inf" 68#define INF_FILE "share/gnunet/tapw32/OemWin2k.inf"
69 69
70/** 70/**
71 * Hardware ID used in the inf-file. 71 * Hardware ID used in the inf-file.
@@ -430,7 +430,7 @@ setup_interface ()
430 str_length = strlen (hwidlist) + 1; 430 str_length = strlen (hwidlist) + 1;
431 strncpy (&hwidlist[str_length], secondary_hwid, LINE_LEN); 431 strncpy (&hwidlist[str_length], secondary_hwid, LINE_LEN);
432 str_length += strlen (&hwidlist[str_length]) + 1; 432 str_length += strlen (&hwidlist[str_length]) + 1;
433 433
434 /** 434 /**
435 * Locate the inf-file, we need to store it somewhere where the system can 435 * Locate the inf-file, we need to store it somewhere where the system can
436 * find it. A good choice would be CWD/PDW or %WINDIR$\system32\ 436 * find it. A good choice would be CWD/PDW or %WINDIR$\system32\
@@ -440,6 +440,7 @@ setup_interface ()
440 */ 440 */
441 GetFullPathNameA (INF_FILE, MAX_PATH, inf_file_path, &temp_inf_filename); 441 GetFullPathNameA (INF_FILE, MAX_PATH, inf_file_path, &temp_inf_filename);
442 442
443 fprintf (stderr, "INFO: Located our driver's .inf file at %s\n", inf_file_path);
443 /** 444 /**
444 * Bootstrap our device info using the drivers inf-file 445 * Bootstrap our device info using the drivers inf-file
445 */ 446 */
@@ -490,6 +491,7 @@ setup_interface ()
490 NULL)) //reboot required? NEVER! 491 NULL)) //reboot required? NEVER!
491 return FALSE; 492 return FALSE;
492 493
494 fprintf (stderr, "DEBUG: successfully created a network device\n");
493 return TRUE; 495 return TRUE;
494} 496}
495 497
@@ -530,6 +532,8 @@ remove_interface ()
530 return FALSE; 532 return FALSE;
531 533
532 SetupDiDestroyDeviceInfoList (DeviceInfo); 534 SetupDiDestroyDeviceInfoList (DeviceInfo);
535
536 fprintf (stderr, "DEBUG: removed interface successfully\n");
533 537
534 return TRUE; 538 return TRUE;
535} 539}
@@ -562,6 +566,8 @@ resolve_interface_name ()
562 0, //must be 0 566 0, //must be 0
563 NULL)) //hMachine, we are local 567 NULL)) //hMachine, we are local
564 return FALSE; 568 return FALSE;
569
570 fprintf (stderr, "DEBUG: Resolving interface name for network device %s\n",pnp_instance_id);
565 571
566 /* Registry is incredibly slow, retry for up to 30 seconds to allow registry to refresh */ 572 /* Registry is incredibly slow, retry for up to 30 seconds to allow registry to refresh */
567 for (retrys = 0; retrys < 120 && !retval; retrys++) 573 for (retrys = 0; retrys < 120 && !retval; retrys++)
@@ -663,7 +669,7 @@ resolve_interface_name ()
663 669
664 strncpy (device_guid, instance_key, 256); 670 strncpy (device_guid, instance_key, 256);
665 retval = TRUE; 671 retval = TRUE;
666 fprintf (stderr, "DEBUG: Interface Name lookup succeeded on retry %d\n", retrys); 672 fprintf (stderr, "DEBUG: Interface Name lookup succeeded on retry %d, got \"%s\" %s\n", retrys, device_visible_name, device_guid);
667 673
668cleanup: 674cleanup:
669 RegCloseKey (instance_key_handle); 675 RegCloseKey (instance_key_handle);
@@ -700,7 +706,7 @@ check_tapw32_version (HANDLE handle)
700 (version[2] ? "(DEBUG)" : "")); 706 (version[2] ? "(DEBUG)" : ""));
701 707
702 if (version[0] != TAP_WIN_MIN_MAJOR || version[1] < TAP_WIN_MIN_MINOR){ 708 if (version[0] != TAP_WIN_MIN_MAJOR || version[1] < TAP_WIN_MIN_MINOR){
703 fprintf (stderr, "FATAL: This version of gnunet requires a TAP-Windows driver that is at least version %d.%d!\n", 709 fprintf (stderr, "FATAL: This version of gnunet requires a TAP-Windows driver that is at least version %d.%d\n",
704 TAP_WIN_MIN_MAJOR, 710 TAP_WIN_MIN_MAJOR,
705 TAP_WIN_MIN_MINOR); 711 TAP_WIN_MIN_MINOR);
706 return FALSE; 712 return FALSE;
@@ -727,7 +733,7 @@ init_tun ()
727 return INVALID_HANDLE_VALUE; 733 return INVALID_HANDLE_VALUE;
728 } 734 }
729 735
730 if (!resolve_interface_name ()) 736 if (! resolve_interface_name ())
731 { 737 {
732 errno = ENODEV; 738 errno = ENODEV;
733 return INVALID_HANDLE_VALUE; 739 return INVALID_HANDLE_VALUE;
@@ -756,7 +762,7 @@ init_tun ()
756 } 762 }
757 763
758 /* get driver version info */ 764 /* get driver version info */
759 if (!check_tapw32_version (handle)) 765 if (! check_tapw32_version (handle))
760 { 766 {
761 CloseHandle (handle); 767 CloseHandle (handle);
762 return INVALID_HANDLE_VALUE; 768 return INVALID_HANDLE_VALUE;
@@ -764,6 +770,7 @@ init_tun ()
764 770
765 /* TODO (opt?): get MTU-Size */ 771 /* TODO (opt?): get MTU-Size */
766 772
773 fprintf (stderr, "DEBUG: successfully opened TAP device\n");
767 return handle; 774 return handle;
768} 775}
769 776
@@ -779,16 +786,17 @@ tun_up (HANDLE handle)
779{ 786{
780 ULONG status = TRUE; 787 ULONG status = TRUE;
781 DWORD len; 788 DWORD len;
782 if (!DeviceIoControl (handle, TAP_WIN_IOCTL_SET_MEDIA_STATUS, 789 if (! DeviceIoControl (handle, TAP_WIN_IOCTL_SET_MEDIA_STATUS,
783 &status, sizeof (status), 790 &status, sizeof (status),
784 &status, sizeof (status), &len, NULL)) 791 &status, sizeof (status), &len, NULL))
785 { 792 {
786 fprintf (stderr, "FATAL: TAP driver ignored request to UP interface (DeviceIoControl call)!\n"); 793 fprintf (stderr, "FATAL: TAP driver ignored request to UP interface (DeviceIoControl call)\n");
787 return FALSE; 794 return FALSE;
788 } 795 }
789 796
790 /* Wait for the device to go UP, might take some time. */ 797 /* Wait for the device to go UP, might take some time. */
791 Sleep (TAP32_POSTUP_WAITTIME * 1000); 798 Sleep (TAP32_POSTUP_WAITTIME * 1000);
799 fprintf (stderr, "DEBUG: successfully set TAP device to UP\n");
792 800
793 return TRUE; 801 return TRUE;
794 802
@@ -832,7 +840,7 @@ attempt_read_tap (struct io_facility * input_facility,
832 { 840 {
833 case IOSTATE_READY: 841 case IOSTATE_READY:
834 { 842 {
835 if (!ResetEvent (input_facility->overlapped.hEvent)) 843 if (! ResetEvent (input_facility->overlapped.hEvent))
836 { 844 {
837 return FALSE; 845 return FALSE;
838 } 846 }
@@ -849,9 +857,11 @@ attempt_read_tap (struct io_facility * input_facility,
849 {/* async event processed immediately*/ 857 {/* async event processed immediately*/
850 858
851 /* reset event manually*/ 859 /* reset event manually*/
852 if (!SetEvent (input_facility->overlapped.hEvent)) 860 if (! SetEvent (input_facility->overlapped.hEvent))
853 return FALSE; 861 return FALSE;
854 862
863 fprintf (stderr, "DEBUG: tap read succeeded immediately\n");
864
855 /* we successfully read something from the TAP and now need to 865 /* we successfully read something from the TAP and now need to
856 * send it our via STDOUT. Is that possible at the moment? */ 866 * send it our via STDOUT. Is that possible at the moment? */
857 if ((IOSTATE_READY == output_facility->facility_state || 867 if ((IOSTATE_READY == output_facility->facility_state ||
@@ -890,7 +900,7 @@ attempt_read_tap (struct io_facility * input_facility,
890 if (IOSTATE_WAITING == output_facility->facility_state) 900 if (IOSTATE_WAITING == output_facility->facility_state)
891 output_facility->path_open = FALSE; 901 output_facility->path_open = FALSE;
892 902
893 fprintf (stderr, "FATAL: Read from handle failed, allowing write to finish!\n"); 903 fprintf (stderr, "FATAL: Read from handle failed, allowing write to finish\n");
894 } 904 }
895 } 905 }
896 } 906 }
@@ -905,9 +915,11 @@ attempt_read_tap (struct io_facility * input_facility,
905 FALSE); 915 FALSE);
906 if (status) 916 if (status)
907 {/* successful return for a queued operation */ 917 {/* successful return for a queued operation */
908 if (!ResetEvent (input_facility->overlapped.hEvent)) 918 if (! ResetEvent (input_facility->overlapped.hEvent))
909 return FALSE; 919 return FALSE;
910 920
921 fprintf (stderr, "DEBUG: tap read succeeded delayed\n");
922
911 /* we successfully read something from the TAP and now need to 923 /* we successfully read something from the TAP and now need to
912 * send it our via STDOUT. Is that possible at the moment? */ 924 * send it our via STDOUT. Is that possible at the moment? */
913 if ((IOSTATE_READY == output_facility->facility_state || 925 if ((IOSTATE_READY == output_facility->facility_state ||
@@ -936,13 +948,13 @@ attempt_read_tap (struct io_facility * input_facility,
936 else 948 else
937 { /* operation still pending/queued or failed? */ 949 { /* operation still pending/queued or failed? */
938 int err = GetLastError (); 950 int err = GetLastError ();
939 if (ERROR_IO_INCOMPLETE != err && ERROR_IO_PENDING != err) 951 if ((ERROR_IO_INCOMPLETE != err) && (ERROR_IO_PENDING != err))
940 { /* error occurred, let the rest of the elements finish */ 952 { /* error occurred, let the rest of the elements finish */
941 input_facility->path_open = FALSE; 953 input_facility->path_open = FALSE;
942 input_facility->facility_state = IOSTATE_FAILED; 954 input_facility->facility_state = IOSTATE_FAILED;
943 if (IOSTATE_WAITING == output_facility->facility_state) 955 if (IOSTATE_WAITING == output_facility->facility_state)
944 output_facility->path_open = FALSE; 956 output_facility->path_open = FALSE;
945 fprintf (stderr, "FATAL: Read from handle failed, allowing write to finish!\n"); 957 fprintf (stderr, "FATAL: Read from handle failed, allowing write to finish\n");
946 } 958 }
947 } 959 }
948 } 960 }
@@ -1002,7 +1014,7 @@ attempt_read_stdin (struct io_facility * input_facility,
1002 { 1014 {
1003 case IOSTATE_READY: 1015 case IOSTATE_READY:
1004 { 1016 {
1005 if (!ResetEvent (input_facility->overlapped.hEvent)) 1017 if (! ResetEvent (input_facility->overlapped.hEvent))
1006 return FALSE; 1018 return FALSE;
1007 input_facility->buffer_size = 0; 1019 input_facility->buffer_size = 0;
1008 status = ReadFile (input_facility->handle, 1020 status = ReadFile (input_facility->handle,
@@ -1017,13 +1029,15 @@ attempt_read_stdin (struct io_facility * input_facility,
1017 hdr = (struct GNUNET_MessageHeader *) input_facility->buffer; 1029 hdr = (struct GNUNET_MessageHeader *) input_facility->buffer;
1018 1030
1019 /* reset event manually*/ 1031 /* reset event manually*/
1020 if (!SetEvent (input_facility->overlapped.hEvent)) 1032 if (! SetEvent (input_facility->overlapped.hEvent))
1021 return FALSE; 1033 return FALSE;
1022 1034
1035 fprintf (stderr, "DEBUG: stdin read succeeded immediately\n");
1036
1023 if (ntohs (hdr->type) != GNUNET_MESSAGE_TYPE_VPN_HELPER || 1037 if (ntohs (hdr->type) != GNUNET_MESSAGE_TYPE_VPN_HELPER ||
1024 ntohs (hdr->size) > sizeof (input_facility->buffer)) 1038 ntohs (hdr->size) > sizeof (input_facility->buffer))
1025 { 1039 {
1026 fprintf (stderr, "WARNING: Protocol violation, got GNUnet Message type %h, size %h!\n", ntohs (hdr->type), ntohs (hdr->size)); 1040 fprintf (stderr, "WARNING: Protocol violation, got GNUnet Message type %h, size %h\n", ntohs (hdr->type), ntohs (hdr->size));
1027 input_facility->facility_state = IOSTATE_READY; 1041 input_facility->facility_state = IOSTATE_READY;
1028 return TRUE; 1042 return TRUE;
1029 } 1043 }
@@ -1038,8 +1052,8 @@ attempt_read_stdin (struct io_facility * input_facility,
1038 IOSTATE_WAITING == output_facility->facility_state) 1052 IOSTATE_WAITING == output_facility->facility_state)
1039 { 1053 {
1040 /* hand over this buffers content and strip gnunet message header */ 1054 /* hand over this buffers content and strip gnunet message header */
1041 memcpy (output_facility->buffer + sizeof (struct GNUNET_MessageHeader), 1055 memcpy (output_facility->buffer,
1042 input_facility->buffer, 1056 input_facility->buffer + sizeof (struct GNUNET_MessageHeader),
1043 input_facility->buffer_size - sizeof (struct GNUNET_MessageHeader)); 1057 input_facility->buffer_size - sizeof (struct GNUNET_MessageHeader));
1044 output_facility->buffer_size = input_facility->buffer_size - sizeof (struct GNUNET_MessageHeader); 1058 output_facility->buffer_size = input_facility->buffer_size - sizeof (struct GNUNET_MessageHeader);
1045 output_facility->facility_state = IOSTATE_READY; 1059 output_facility->facility_state = IOSTATE_READY;
@@ -1053,7 +1067,7 @@ attempt_read_stdin (struct io_facility * input_facility,
1053 } 1067 }
1054 else if (status && 0 >= input_facility->buffer_size) 1068 else if (status && 0 >= input_facility->buffer_size)
1055 { 1069 {
1056 if (!SetEvent (input_facility->overlapped.hEvent)) 1070 if (! SetEvent (input_facility->overlapped.hEvent))
1057 return FALSE; 1071 return FALSE;
1058 1072
1059 input_facility->facility_state = IOSTATE_READY; 1073 input_facility->facility_state = IOSTATE_READY;
@@ -1072,7 +1086,7 @@ attempt_read_stdin (struct io_facility * input_facility,
1072 if (IOSTATE_WAITING == output_facility->facility_state) 1086 if (IOSTATE_WAITING == output_facility->facility_state)
1073 output_facility->path_open = FALSE; 1087 output_facility->path_open = FALSE;
1074 1088
1075 fprintf (stderr, "FATAL: Read from handle failed, allowing write to finish!\n"); 1089 fprintf (stderr, "FATAL: Read from handle failed, allowing write to finish\n");
1076 } 1090 }
1077 } 1091 }
1078 } 1092 }
@@ -1089,13 +1103,15 @@ attempt_read_stdin (struct io_facility * input_facility,
1089 {/* successful return for a queued operation */ 1103 {/* successful return for a queued operation */
1090 hdr = (struct GNUNET_MessageHeader *) input_facility->buffer; 1104 hdr = (struct GNUNET_MessageHeader *) input_facility->buffer;
1091 1105
1092 if (!ResetEvent (input_facility->overlapped.hEvent)) 1106 if (! ResetEvent (input_facility->overlapped.hEvent))
1093 return FALSE; 1107 return FALSE;
1094 1108
1095 if (ntohs (hdr->type) != GNUNET_MESSAGE_TYPE_VPN_HELPER || 1109 fprintf (stderr, "DEBUG: stdin read succeeded delayed\n");
1096 ntohs (hdr->size) > sizeof (input_facility->buffer)) 1110
1111 if ((ntohs (hdr->type) != GNUNET_MESSAGE_TYPE_VPN_HELPER) ||
1112 (ntohs (hdr->size) > sizeof (input_facility->buffer)))
1097 { 1113 {
1098 fprintf (stderr, "WARNING: Protocol violation, got GNUnet Message type %h, size %h!\n", ntohs (hdr->type), ntohs (hdr->size)); 1114 fprintf (stderr, "WARNING: Protocol violation, got GNUnet Message type %h, size %h\n", ntohs (hdr->type), ntohs (hdr->size));
1099 input_facility->facility_state = IOSTATE_READY; 1115 input_facility->facility_state = IOSTATE_READY;
1100 return TRUE; 1116 return TRUE;
1101 } 1117 }
@@ -1108,8 +1124,8 @@ attempt_read_stdin (struct io_facility * input_facility,
1108 IOSTATE_WAITING == output_facility->facility_state) 1124 IOSTATE_WAITING == output_facility->facility_state)
1109 && sizeof(struct GNUNET_MessageHeader) < input_facility->buffer_size) 1125 && sizeof(struct GNUNET_MessageHeader) < input_facility->buffer_size)
1110 { /* hand over this buffers content and strip gnunet message header */ 1126 { /* hand over this buffers content and strip gnunet message header */
1111 memcpy (output_facility->buffer + sizeof(struct GNUNET_MessageHeader), 1127 memcpy (output_facility->buffer,
1112 input_facility->buffer, 1128 input_facility->buffer + sizeof(struct GNUNET_MessageHeader),
1113 input_facility->buffer_size - sizeof(struct GNUNET_MessageHeader)); 1129 input_facility->buffer_size - sizeof(struct GNUNET_MessageHeader));
1114 output_facility->buffer_size = input_facility->buffer_size - sizeof(struct GNUNET_MessageHeader); 1130 output_facility->buffer_size = input_facility->buffer_size - sizeof(struct GNUNET_MessageHeader);
1115 output_facility->facility_state = IOSTATE_READY; 1131 output_facility->facility_state = IOSTATE_READY;
@@ -1126,20 +1142,20 @@ attempt_read_stdin (struct io_facility * input_facility,
1126 else 1142 else
1127 { /* operation still pending/queued or failed? */ 1143 { /* operation still pending/queued or failed? */
1128 int err = GetLastError (); 1144 int err = GetLastError ();
1129 if (ERROR_IO_INCOMPLETE != err && ERROR_IO_PENDING != err) 1145 if ((ERROR_IO_INCOMPLETE != err) && (ERROR_IO_PENDING != err))
1130 { /* error occurred, let the rest of the elements finish */ 1146 { /* error occurred, let the rest of the elements finish */
1131 input_facility->path_open = FALSE; 1147 input_facility->path_open = FALSE;
1132 input_facility->facility_state = IOSTATE_FAILED; 1148 input_facility->facility_state = IOSTATE_FAILED;
1133 if (IOSTATE_WAITING == output_facility->facility_state) 1149 if (IOSTATE_WAITING == output_facility->facility_state)
1134 output_facility->path_open = FALSE; 1150 output_facility->path_open = FALSE;
1135 fprintf (stderr, "FATAL: Read from handle failed, allowing write to finish!\n"); 1151 fprintf (stderr, "FATAL: Read from handle failed, allowing write to finish\n");
1136 } 1152 }
1137 } 1153 }
1138 } 1154 }
1139 return TRUE; 1155 return TRUE;
1140 case IOSTATE_RESUME: /* Our buffer was filled already but our write facility was busy. */ 1156 case IOSTATE_RESUME: /* Our buffer was filled already but our write facility was busy. */
1141 memcpy (output_facility->buffer + sizeof (struct GNUNET_MessageHeader), 1157 memcpy (output_facility->buffer,
1142 input_facility->buffer, 1158 input_facility->buffer + sizeof (struct GNUNET_MessageHeader),
1143 input_facility->buffer_size - sizeof (struct GNUNET_MessageHeader)); 1159 input_facility->buffer_size - sizeof (struct GNUNET_MessageHeader));
1144 output_facility->buffer_size = input_facility->buffer_size - sizeof (struct GNUNET_MessageHeader); 1160 output_facility->buffer_size = input_facility->buffer_size - sizeof (struct GNUNET_MessageHeader);
1145 output_facility->facility_state = IOSTATE_READY; 1161 output_facility->facility_state = IOSTATE_READY;
@@ -1169,7 +1185,7 @@ attempt_write (struct io_facility * output_facility,
1169 { 1185 {
1170 case IOSTATE_READY: 1186 case IOSTATE_READY:
1171 1187
1172 if (!ResetEvent (output_facility->overlapped.hEvent)) 1188 if (! ResetEvent (output_facility->overlapped.hEvent))
1173 return FALSE; 1189 return FALSE;
1174 1190
1175 output_facility->buffer_size_written = 0; 1191 output_facility->buffer_size_written = 0;
@@ -1184,8 +1200,10 @@ attempt_write (struct io_facility * output_facility,
1184 output_facility->buffer_size_written == output_facility->buffer_size) 1200 output_facility->buffer_size_written == output_facility->buffer_size)
1185 {/* async event processed immediately*/ 1201 {/* async event processed immediately*/
1186 1202
1203 fprintf (stderr, "DEBUG: write succeeded immediately\n");
1204
1187 /* reset event manually*/ 1205 /* reset event manually*/
1188 if (!SetEvent (output_facility->overlapped.hEvent)) 1206 if (! SetEvent (output_facility->overlapped.hEvent))
1189 return FALSE; 1207 return FALSE;
1190 1208
1191 /* we are now waiting for our buffer to be filled*/ 1209 /* we are now waiting for our buffer to be filled*/
@@ -1210,7 +1228,7 @@ attempt_write (struct io_facility * output_facility,
1210 { /* error occurred, close this path */ 1228 { /* error occurred, close this path */
1211 output_facility->path_open = FALSE; 1229 output_facility->path_open = FALSE;
1212 output_facility->facility_state = IOSTATE_FAILED; 1230 output_facility->facility_state = IOSTATE_FAILED;
1213 fprintf (stderr, "FATAL: Write to handle failed, exiting!\n"); 1231 fprintf (stderr, "FATAL: Write to handle failed, exiting\n");
1214 } 1232 }
1215 } 1233 }
1216 return TRUE; 1234 return TRUE;
@@ -1223,14 +1241,16 @@ attempt_write (struct io_facility * output_facility,
1223 if (status && 1241 if (status &&
1224 output_facility->buffer_size_written == output_facility->buffer_size) 1242 output_facility->buffer_size_written == output_facility->buffer_size)
1225 {/* successful return for a queued operation */ 1243 {/* successful return for a queued operation */
1226 if (!ResetEvent (output_facility->overlapped.hEvent)) 1244 if (! ResetEvent (output_facility->overlapped.hEvent))
1227 return FALSE; 1245 return FALSE;
1246
1247 fprintf (stderr, "DEBUG: write succeeded delayed\n");
1228 1248
1229 /* we are now waiting for our buffer to be filled*/ 1249 /* we are now waiting for our buffer to be filled*/
1230 output_facility->facility_state = IOSTATE_WAITING; 1250 output_facility->facility_state = IOSTATE_WAITING;
1231 output_facility->buffer_size = 0; 1251 output_facility->buffer_size = 0;
1232 output_facility->buffer_size_written = 0; 1252 output_facility->buffer_size_written = 0;
1233 1253
1234 /* we successfully wrote something and now need to reset our reader */ 1254 /* we successfully wrote something and now need to reset our reader */
1235 if (IOSTATE_WAITING == input_facility->facility_state) 1255 if (IOSTATE_WAITING == input_facility->facility_state)
1236 input_facility->facility_state = IOSTATE_RESUME; 1256 input_facility->facility_state = IOSTATE_RESUME;
@@ -1240,11 +1260,11 @@ attempt_write (struct io_facility * output_facility,
1240 else 1260 else
1241 { /* operation still pending/queued or failed? */ 1261 { /* operation still pending/queued or failed? */
1242 int err = GetLastError (); 1262 int err = GetLastError ();
1243 if (ERROR_IO_INCOMPLETE != err && ERROR_IO_PENDING != err) 1263 if ((ERROR_IO_INCOMPLETE != err) && (ERROR_IO_PENDING != err))
1244 { /* error occurred, close this path */ 1264 { /* error occurred, close this path */
1245 output_facility->path_open = FALSE; 1265 output_facility->path_open = FALSE;
1246 output_facility->facility_state = IOSTATE_FAILED; 1266 output_facility->facility_state = IOSTATE_FAILED;
1247 fprintf (stderr, "FATAL: Write to handle failed, exiting!\n"); 1267 fprintf (stderr, "FATAL: Write to handle failed, exiting\n");
1248 } 1268 }
1249 } 1269 }
1250 default: 1270 default:
@@ -1305,11 +1325,11 @@ run (HANDLE tap_handle)
1305 * DHCP and such are all features we will never use in gnunet afaik. 1325 * DHCP and such are all features we will never use in gnunet afaik.
1306 * But for openvpn those are essential. 1326 * But for openvpn those are essential.
1307 */ 1327 */
1308 if (!tun_up (tap_handle)) 1328 if (! tun_up (tap_handle))
1309 return; 1329 return;
1310 1330
1311 /* Initialize our overlapped IO structures*/ 1331 /* Initialize our overlapped IO structures*/
1312 if (!(initialize_io_facility (&tap_read, IOSTATE_READY, FALSE) 1332 if (! (initialize_io_facility (&tap_read, IOSTATE_READY, FALSE)
1313 && initialize_io_facility (&tap_write, IOSTATE_WAITING, TRUE) 1333 && initialize_io_facility (&tap_write, IOSTATE_WAITING, TRUE)
1314 && initialize_io_facility (&std_in, IOSTATE_READY, FALSE) 1334 && initialize_io_facility (&std_in, IOSTATE_READY, FALSE)
1315 && initialize_io_facility (&std_out, IOSTATE_WAITING, TRUE))) 1335 && initialize_io_facility (&std_out, IOSTATE_WAITING, TRUE)))
@@ -1323,17 +1343,18 @@ run (HANDLE tap_handle)
1323 /* Debug output to console STDIN/STDOUT*/ 1343 /* Debug output to console STDIN/STDOUT*/
1324 std_in.handle = parent_std_in_handle; 1344 std_in.handle = parent_std_in_handle;
1325 std_out.handle = parent_std_out_handle; 1345 std_out.handle = parent_std_out_handle;
1326#else
1327 1346
1347#else
1348 fprintf (stderr, "DEBUG: reopening stdin/out for overlapped IO\n");
1328 /* 1349 /*
1329 * Find out the types of our handles. 1350 * Find out the types of our handles.
1330 * This part is a problem, because in windows we need to handle files, 1351 * This part is a problem, because in windows we need to handle files,
1331 * pipes and the console differently. 1352 * pipes and the console differently.
1332 */ 1353 */
1333 if (FILE_TYPE_PIPE != GetFileType (parent_std_in_handle) || 1354 if ((FILE_TYPE_PIPE != GetFileType (parent_std_in_handle)) ||
1334 FILE_TYPE_PIPE != GetFileType (parent_std_out_handle)) 1355 (FILE_TYPE_PIPE != GetFileType (parent_std_out_handle)))
1335 { 1356 {
1336 fprintf (stderr, "ERROR: stdin/stdout must be named pipes!\n"); 1357 fprintf (stderr, "ERROR: stdin/stdout must be named pipes\n");
1337 goto teardown; 1358 goto teardown;
1338 } 1359 }
1339 1360
@@ -1344,7 +1365,7 @@ run (HANDLE tap_handle)
1344 1365
1345 if (INVALID_HANDLE_VALUE == std_in.handle) 1366 if (INVALID_HANDLE_VALUE == std_in.handle)
1346 { 1367 {
1347 fprintf (stderr, "FATAL: Could not reopen stdin for in overlapped mode, has to be a named pipe!\n"); 1368 fprintf (stderr, "FATAL: Could not reopen stdin for in overlapped mode, has to be a named pipe\n");
1348 goto teardown; 1369 goto teardown;
1349 } 1370 }
1350 1371
@@ -1355,38 +1376,42 @@ run (HANDLE tap_handle)
1355 1376
1356 if (INVALID_HANDLE_VALUE == std_out.handle) 1377 if (INVALID_HANDLE_VALUE == std_out.handle)
1357 { 1378 {
1358 fprintf (stderr, "FATAL: Could not reopen stdout for in overlapped mode, has to be a named pipe!\n"); 1379 fprintf (stderr, "FATAL: Could not reopen stdout for in overlapped mode, has to be a named pipe\n");
1359 goto teardown; 1380 goto teardown;
1360 } 1381 }
1361#endif 1382#endif
1362 1383
1384 fprintf (stderr, "DEBUG: mainloop has begun\n");
1385
1363 while (std_out.path_open || tap_write.path_open) 1386 while (std_out.path_open || tap_write.path_open)
1364 { 1387 {
1365 /* perform READ from stdin if possible */ 1388 /* perform READ from stdin if possible */
1366 if (std_in.path_open && (!attempt_read_stdin (&std_in, &tap_write))) 1389 if (std_in.path_open && (! attempt_read_stdin (&std_in, &tap_write)))
1367 break; 1390 break;
1368 1391
1369 /* perform READ from tap if possible */ 1392 /* perform READ from tap if possible */
1370 if (tap_read.path_open && (!attempt_read_tap (&tap_read, &std_out))) 1393 if (tap_read.path_open && (! attempt_read_tap (&tap_read, &std_out)))
1371 break; 1394 break;
1372 1395
1373 /* perform WRITE to tap if possible */ 1396 /* perform WRITE to tap if possible */
1374 if (tap_write.path_open && (!attempt_write (&tap_write, &std_in))) 1397 if (tap_write.path_open && (! attempt_write (&tap_write, &std_in)))
1375 break; 1398 break;
1376 1399
1377 /* perform WRITE to STDOUT if possible */ 1400 /* perform WRITE to STDOUT if possible */
1378 if (std_out.path_open && (!attempt_write (&std_out, &tap_read))) 1401 if (std_out.path_open && (! attempt_write (&std_out, &tap_read)))
1379 break; 1402 break;
1380 } 1403 }
1381 1404
1382teardown: 1405teardown:
1383 1406
1407 fprintf (stderr, "DEBUG: teardown initiated\n");
1408
1384 CancelIo (tap_handle); 1409 CancelIo (tap_handle);
1385 CancelIo (std_in.handle); 1410 CancelIo (std_in.handle);
1386 CancelIo (std_out.handle); 1411 CancelIo (std_out.handle);
1387 1412
1388teardown_final: 1413teardown_final:
1389 1414
1390 CloseHandle (tap_handle); 1415 CloseHandle (tap_handle);
1391} 1416}
1392 1417
@@ -1413,7 +1438,7 @@ main (int argc, char **argv)
1413 1438
1414 if (6 != argc) 1439 if (6 != argc)
1415 { 1440 {
1416 fprintf (stderr, "FATAL: must supply 5 arguments!\nUsage:\ngnunet-helper-vpn <if name prefix> <address6 or \"-\"> <netbits6> <address4 or \"-\"> <netmask4>\n", argv[0]); 1441 fprintf (stderr, "FATAL: must supply 5 arguments\nUsage:\ngnunet-helper-vpn <if name prefix> <address6 or \"-\"> <netbits6> <address4 or \"-\"> <netmask4>\n", argv[0]);
1417 return 1; 1442 return 1;
1418 } 1443 }
1419 1444
@@ -1441,6 +1466,7 @@ main (int argc, char **argv)
1441 goto cleanup; 1466 goto cleanup;
1442 } 1467 }
1443 1468
1469 fprintf (stderr, "DEBUG: Setting IPs, if needed\n");
1444 if (0 != strcmp (argv[2], "-")) 1470 if (0 != strcmp (argv[2], "-"))
1445 { 1471 {
1446 const char *address = argv[2]; 1472 const char *address = argv[2];
@@ -1448,11 +1474,12 @@ main (int argc, char **argv)
1448 1474
1449 if ((prefix_len < 1) || (prefix_len > 127)) 1475 if ((prefix_len < 1) || (prefix_len > 127))
1450 { 1476 {
1451 fprintf (stderr, "FATAL: prefix_len out of range\n"); 1477 fprintf (stderr, "FATAL: ipv6 prefix_len out of range\n");
1452 global_ret = -1; 1478 global_ret = -1;
1453 goto cleanup; 1479 goto cleanup;
1454 } 1480 }
1455 1481
1482 fprintf (stderr, "DEBUG: Setting IP6 address: %s/%d\n",address,prefix_len);
1456 if (0 != (global_ret = set_address6 (address, prefix_len))) 1483 if (0 != (global_ret = set_address6 (address, prefix_len)))
1457 goto cleanup; 1484 goto cleanup;
1458 1485
@@ -1464,6 +1491,7 @@ main (int argc, char **argv)
1464 const char *address = argv[4]; 1491 const char *address = argv[4];
1465 const char *mask = argv[5]; 1492 const char *mask = argv[5];
1466 1493
1494 fprintf (stderr, "DEBUG: Setting IP4 address: %s/%s\n",address,mask);
1467 if (0 != (global_ret = set_address4 (address, mask))) 1495 if (0 != (global_ret = set_address4 (address, mask)))
1468 goto cleanup; 1496 goto cleanup;
1469 1497
@@ -1477,13 +1505,19 @@ cleanup:
1477 if (have_ip4) 1505 if (have_ip4)
1478 { 1506 {
1479 const char *address = argv[4]; 1507 const char *address = argv[4];
1508 fprintf (stderr, "DEBUG: Removing IP4 address\n");
1480 remove_address4 (address); 1509 remove_address4 (address);
1481 } 1510 }
1482 if (have_ip6) 1511 if (have_ip6)
1483 { 1512 {
1484 const char *address = argv[2]; 1513 const char *address = argv[2];
1514 fprintf (stderr, "DEBUG: Removing IP6 address\n");
1485 remove_address6 (address); 1515 remove_address6 (address);
1486 } 1516 }
1517
1518 fprintf (stderr, "DEBUG: removing interface\n");
1487 remove_interface (); 1519 remove_interface ();
1520 fprintf (stderr, "DEBUG: graceful exit completed\n");
1521
1488 return global_ret; 1522 return global_ret;
1489} 1523}