diff options
-rw-r--r-- | src/vpn/gnunet-helper-vpn-windows.c | 173 |
1 files changed, 101 insertions, 72 deletions
diff --git a/src/vpn/gnunet-helper-vpn-windows.c b/src/vpn/gnunet-helper-vpn-windows.c index 2214f0695..39aa84d9d 100644 --- a/src/vpn/gnunet-helper-vpn-windows.c +++ b/src/vpn/gnunet-helper-vpn-windows.c | |||
@@ -136,6 +136,33 @@ static SP_DEVINFO_DATA DeviceNode; | |||
136 | * {12345678-1234-1234-1234-123456789abc} - in hex | 136 | * {12345678-1234-1234-1234-123456789abc} - in hex |
137 | */ | 137 | */ |
138 | static char device_guid[256]; | 138 | static char device_guid[256]; |
139 | |||
140 | /* Overlapped IO Begins here (warning: nasty!) */ | ||
141 | |||
142 | /** | ||
143 | * A overlapped-IO Object + read/writebuffer + buffer-size for windows asynchronous IO handling | ||
144 | */ | ||
145 | struct overlapped_facility | ||
146 | { | ||
147 | int iostate; | ||
148 | BOOL status; // BOOL is winbool, NOT boolean! | ||
149 | DWORD flags; | ||
150 | |||
151 | OVERLAPPED overlapped; | ||
152 | |||
153 | DWORD buffer_size; | ||
154 | unsigned char buffer[MAX_SIZE]; | ||
155 | }; | ||
156 | |||
157 | /** | ||
158 | * Operlapped IO states for its objects | ||
159 | */ | ||
160 | #define IOSTATE_INITIAL 0 | ||
161 | #define IOSTATE_QUEUED 1 /* overlapped I/O has been queued */ | ||
162 | #define IOSTATE_IMMEDIATE_RETURN 2 /* I/O function returned immediately without queueing */ | ||
163 | |||
164 | #if WINVER < 0x0600 | ||
165 | |||
139 | /** | 166 | /** |
140 | * inet_pton() wrapper for WSAStringToAddress() | 167 | * inet_pton() wrapper for WSAStringToAddress() |
141 | * | 168 | * |
@@ -147,10 +174,6 @@ static char device_guid[256]; | |||
147 | * @param dst - OUT - the numerical form of the address | 174 | * @param dst - OUT - the numerical form of the address |
148 | * @return 0 on success, 1 on failure | 175 | * @return 0 on success, 1 on failure |
149 | */ | 176 | */ |
150 | #if WINVER >= 0x0600 | ||
151 | int inet_pton (int af, const char *src, void *dst); | ||
152 | #else | ||
153 | |||
154 | int | 177 | int |
155 | inet_pton (int af, const char *src, void *dst) | 178 | inet_pton (int af, const char *src, void *dst) |
156 | { | 179 | { |
@@ -648,7 +671,7 @@ init_tun () | |||
648 | CloseHandle (handle); | 671 | CloseHandle (handle); |
649 | return INVALID_HANDLE_VALUE; | 672 | return INVALID_HANDLE_VALUE; |
650 | } | 673 | } |
651 | 674 | ||
652 | /* TODO (opt?): get MTU-Size */ | 675 | /* TODO (opt?): get MTU-Size */ |
653 | 676 | ||
654 | return handle; | 677 | return handle; |
@@ -675,6 +698,30 @@ tun_up (HANDLE handle) | |||
675 | } | 698 | } |
676 | 699 | ||
677 | /** | 700 | /** |
701 | * Initialize a overlapped structure | ||
702 | * | ||
703 | * @param elem the element to initilize | ||
704 | * @param initial_state the initial state for this instance | ||
705 | * @param signaled if the hEvent created should default to signaled or not | ||
706 | * @return true on success, else false | ||
707 | */ | ||
708 | static boolean | ||
709 | initialize_overlapped_facility (struct overlapped_facility * elem, | ||
710 | BOOL initial_state, | ||
711 | BOOL signaled) | ||
712 | { | ||
713 | |||
714 | elem->status = initial_state; | ||
715 | elem->iostate = 0; | ||
716 | elem->buffer_size = MAX_SIZE; | ||
717 | elem->overlapped.hEvent = CreateEvent (NULL, TRUE, signaled, NULL); | ||
718 | if (NULL == elem->overlapped.hEvent) | ||
719 | return FALSE; | ||
720 | |||
721 | return TRUE; | ||
722 | } | ||
723 | |||
724 | /** | ||
678 | * Start forwarding to and from the tunnel. | 725 | * Start forwarding to and from the tunnel. |
679 | * | 726 | * |
680 | * @param fd_tun tunnel FD | 727 | * @param fd_tun tunnel FD |
@@ -682,25 +729,19 @@ tun_up (HANDLE handle) | |||
682 | static void | 729 | static void |
683 | run (HANDLE handle) | 730 | run (HANDLE handle) |
684 | { | 731 | { |
685 | /* | 732 | /* read refers to reading from fd_tun, writing to stdout */ |
686 | * The buffer filled by reading from fd_tun | 733 | int read_open = 1; |
687 | */ | 734 | /* write refers to reading from stdin, writing to fd_tun */ |
688 | unsigned char buftun[MAX_SIZE]; | 735 | int write_open = 1; |
689 | ssize_t buftun_size = 0; | ||
690 | unsigned char *buftun_read = NULL; | ||
691 | |||
692 | /* | ||
693 | * The buffer filled by reading from stdin | ||
694 | */ | ||
695 | unsigned char bufin[MAX_SIZE]; | ||
696 | ssize_t bufin_size = 0; | ||
697 | ssize_t bufin_rpos = 0; | ||
698 | unsigned char *bufin_read = NULL; | ||
699 | 736 | ||
700 | //openvpn | 737 | /* IO-Facility for reading from our virtual interface */ |
701 | // Set Device to Subnet-Mode? | 738 | struct overlapped_facility tap_read; |
702 | // do we really need tun.c:2925 ? | 739 | /* IO-Facility for writing to our virtual interface */ |
703 | // Why does openvpn assign IPv4's there??? Foobar?? | 740 | struct overlapped_facility tap_write; |
741 | /* IO-Facility for reading from stdin */ | ||
742 | struct overlapped_facility std_in; | ||
743 | /* IO-Facility for writing to stdout */ | ||
744 | struct overlapped_facility std_out; | ||
704 | 745 | ||
705 | /* tun up: */ | 746 | /* tun up: */ |
706 | /* we do this HERE and not beforehand (in init_tun()), in contrast to openvpn | 747 | /* we do this HERE and not beforehand (in init_tun()), in contrast to openvpn |
@@ -711,65 +752,53 @@ run (HANDLE handle) | |||
711 | */ | 752 | */ |
712 | if (!tun_up (handle)) | 753 | if (!tun_up (handle)) |
713 | goto teardown; | 754 | goto teardown; |
714 | |||
715 | fd_set fds_w; | ||
716 | fd_set fds_r; | ||
717 | 755 | ||
718 | /* read refers to reading from fd_tun, writing to stdout */ | 756 | if (!) |
719 | int read_open = 1; | 757 | goto teardown; |
720 | 758 | ||
721 | /* write refers to reading from stdin, writing to fd_tun */ | 759 | /* Initialize our overlapped IO structures*/ |
722 | int write_open = 1; | 760 | if (initialize_overlapped_facility (&tap_read, TRUE, FALSE) |
761 | && initialize_overlapped_facility (&tap_write, FALSE, TRUE) | ||
762 | && initialize_overlapped_facility (&std_in, TRUE, FALSE) | ||
763 | && initialize_overlapped_facility (&std_out, FALSE, TRUE)) | ||
764 | goto teardown; | ||
765 | |||
766 | |||
767 | //openvpn | ||
768 | // Set Device to Subnet-Mode? | ||
769 | // do we really need tun.c:2925 ? | ||
770 | // Why does openvpn assign IPv4's there??? Foobar?? | ||
723 | 771 | ||
724 | // Setup should be complete here. | 772 | // Setup should be complete here. |
725 | // If something is missing, check init.c:3400+ | 773 | // If something is missing, check init.c:3400+ |
726 | 774 | ||
727 | // mainloop: | 775 | // mainloop: |
728 | // tunnel_point_to_point | 776 | // tunnel_point_to_point |
729 | // openvpn.c:62 | 777 | // openvpn.c:62 |
730 | 778 | ||
731 | while ((1 == read_open) || (1 == write_open)) | 779 | while ((1 == read_open) || (1 == write_open)) |
732 | { | 780 | { |
733 | FD_ZERO (&fds_w); | 781 | |
734 | FD_ZERO (&fds_r); | 782 | /* READ from stdin is possible */ |
735 | 783 | if (std_in.status) | |
736 | // openvpn.c:80 ? | 784 | { |
737 | 785 | ||
738 | /* | 786 | } |
739 | * We are supposed to read and the buffer is empty | 787 | /* READ from tap is possible */ |
740 | * -> select on read from tun | 788 | if (tap_read.status) |
741 | */ | 789 | { |
742 | if (read_open && (0 == buftun_size)) | 790 | |
743 | // FD_SET (fd_tun, &fds_r); | 791 | } |
744 | ; | 792 | /* WRITE to tap is possible */ |
745 | 793 | if (tap_write.status) | |
746 | /* | 794 | { |
747 | * We are supposed to read and the buffer is not empty | ||
748 | * -> select on write to stdout | ||
749 | */ | ||
750 | if (read_open && (0 != buftun_size)) | ||
751 | FD_SET (1, &fds_w); | ||
752 | |||
753 | /* | ||
754 | * We are supposed to write and the buffer is empty | ||
755 | * -> select on read from stdin | ||
756 | */ | ||
757 | if (write_open && (NULL == bufin_read)) | ||
758 | FD_SET (0, &fds_r); | ||
759 | |||
760 | /* | ||
761 | * We are supposed to write and the buffer is not empty | ||
762 | * -> select on write to tun | ||
763 | */ | ||
764 | if (write_open && (NULL != bufin_read)) | ||
765 | // FD_SET (fd_tun, &fds_w); | ||
766 | ; | ||
767 | |||
768 | |||
769 | // init.c:3337 | ||
770 | /* setup ansync IO */ | ||
771 | //forward.c: 1515 | ||
772 | 795 | ||
796 | } | ||
797 | /* WRITE to STDOUT is possible */ | ||
798 | if (std_out.status) | ||
799 | { | ||
800 | |||
801 | } | ||
773 | } | 802 | } |
774 | teardown: | 803 | teardown: |
775 | ; | 804 | ; |