| 1 |
/* |
| 2 |
* Copyright (c) 1998-2001, Robert O'Callahan |
| 3 |
* (C) 2004- TeraTerm Project |
| 4 |
* All rights reserved. |
| 5 |
* |
| 6 |
* Redistribution and use in source and binary forms, with or without |
| 7 |
* modification, are permitted provided that the following conditions |
| 8 |
* are met: |
| 9 |
* |
| 10 |
* 1. Redistributions of source code must retain the above copyright |
| 11 |
* notice, this list of conditions and the following disclaimer. |
| 12 |
* 2. Redistributions in binary form must reproduce the above copyright |
| 13 |
* notice, this list of conditions and the following disclaimer in the |
| 14 |
* documentation and/or other materials provided with the distribution. |
| 15 |
* 3. The name of the author may not be used to endorse or promote products |
| 16 |
* derived from this software without specific prior written permission. |
| 17 |
* |
| 18 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR |
| 19 |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 20 |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 21 |
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 22 |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 23 |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 24 |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 25 |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 27 |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 |
*/ |
| 29 |
|
| 30 |
/* |
| 31 |
This code is copyright (C) 1998-1999 Robert O'Callahan. |
| 32 |
See LICENSE.TXT for the license. |
| 33 |
*/ |
| 34 |
|
| 35 |
#ifndef __FWD_H |
| 36 |
#define __FWD_H |
| 37 |
|
| 38 |
// �|�[�g�]�����������t���[���������l |
| 39 |
// �K�p�� Channel_t.bufchain_amount |
| 40 |
#define FWD_HIGH_WATER_MARK (1 * 1024 * 1024) // 1MB |
| 41 |
#define FWD_LOW_WATER_MARK (0) // 0MB |
| 42 |
|
| 43 |
#define FWD_REMOTE_CONNECTED 0x01 |
| 44 |
#define FWD_LOCAL_CONNECTED 0x02 |
| 45 |
#define FWD_BOTH_CONNECTED (FWD_REMOTE_CONNECTED | FWD_LOCAL_CONNECTED) |
| 46 |
#define FWD_CLOSED_REMOTE_IN 0x04 |
| 47 |
#define FWD_CLOSED_REMOTE_OUT 0x08 |
| 48 |
#define FWD_CLOSED_LOCAL_IN 0x10 |
| 49 |
#define FWD_CLOSED_LOCAL_OUT 0x20 |
| 50 |
#define FWD_AGENT_DUMMY 0x40 |
| 51 |
|
| 52 |
typedef enum { |
| 53 |
FWD_FILTER_REMOVE, FWD_FILTER_RETAIN, FWD_FILTER_CLOSECHANNEL |
| 54 |
} FwdFilterResult; |
| 55 |
|
| 56 |
typedef enum { |
| 57 |
FWD_FILTER_CLEANUP, |
| 58 |
FWD_FILTER_OPENCONFIRM, |
| 59 |
FWD_FILTER_OPENFAILURE, |
| 60 |
FWD_FILTER_FROM_CLIENT, |
| 61 |
FWD_FILTER_FROM_SERVER |
| 62 |
} FwdFilterEvent; |
| 63 |
|
| 64 |
/* a length == 0 means that we're killing the channel and the filter should deallocate */ |
| 65 |
typedef FwdFilterResult (* FWDFilter)(void *closure, FwdFilterEvent event, int *length, unsigned char **buf); |
| 66 |
|
| 67 |
typedef struct { |
| 68 |
int status; |
| 69 |
int remote_num; |
| 70 |
SOCKET local_socket; |
| 71 |
int request_num; |
| 72 |
UTILSockWriteBuf writebuf; |
| 73 |
|
| 74 |
void *filter_closure; |
| 75 |
FWDFilter filter; |
| 76 |
struct addrinfo *to_host_addrs; |
| 77 |
|
| 78 |
// for agent forwarding |
| 79 |
buffer_t *agent_msg; |
| 80 |
int agent_request_len; |
| 81 |
enum channel_type type; |
| 82 |
} FWDChannel; |
| 83 |
|
| 84 |
/* Request types */ |
| 85 |
typedef enum { |
| 86 |
FWD_NONE, |
| 87 |
FWD_LOCAL_TO_REMOTE, |
| 88 |
FWD_LOCAL_DYNAMIC, |
| 89 |
FWD_LISTENING_LOCAL, // ���r�p���_�~�[�B���[�J���� listen ������������������������ |
| 90 |
FWD_REMOTE_TO_LOCAL, |
| 91 |
FWD_REMOTE_X11_TO_LOCAL |
| 92 |
} FWDType; |
| 93 |
|
| 94 |
#define FwdTypeIsLocal(type) ((type) > FWD_NONE && (type) < FWD_LISTENING_LOCAL) |
| 95 |
#define FwdTypeIsRemote(type) ((type) > FWD_LISTENING_LOCAL) |
| 96 |
#define FwdListeningType(type) (FwdTypeIsLocal(type)?FWD_LOCAL_TO_REMOTE:(type)) |
| 97 |
|
| 98 |
/* If 'type' is FWD_REMOTE_X11_TO_LOCAL, then from_port must be |
| 99 |
-1, to_port must be 6000 + display number, and to_host must |
| 100 |
be the desired X server host. |
| 101 |
|
| 102 |
There can be no more than one spec of a given type and from_port |
| 103 |
at one time. |
| 104 |
*/ |
| 105 |
typedef struct { |
| 106 |
FWDType type; |
| 107 |
int from_port; |
| 108 |
char from_port_name[32]; |
| 109 |
int to_port; |
| 110 |
char to_port_name[32]; |
| 111 |
char to_host[256]; |
| 112 |
char bind_address[256]; |
| 113 |
int x11_screen; |
| 114 |
} FWDRequestSpec; |
| 115 |
|
| 116 |
#define FWD_DELETED 0x01 |
| 117 |
|
| 118 |
#define MAX_LISTENING_SOCKETS 4096 |
| 119 |
typedef struct { |
| 120 |
int num_listening_sockets; |
| 121 |
SOCKET *listening_sockets; |
| 122 |
struct addrinfo *to_host_addrs; |
| 123 |
HANDLE to_host_lookup_handle; |
| 124 |
|
| 125 |
int num_channels; |
| 126 |
|
| 127 |
int status; |
| 128 |
FWDRequestSpec spec; |
| 129 |
} FWDRequest; |
| 130 |
|
| 131 |
typedef struct { |
| 132 |
HWND accept_wnd; |
| 133 |
WNDPROC old_accept_wnd_proc; |
| 134 |
int num_server_listening_specs; |
| 135 |
/* stored in sorted order */ |
| 136 |
FWDRequestSpec *server_listening_specs; |
| 137 |
int num_requests; |
| 138 |
FWDRequest *requests; |
| 139 |
int num_channels; |
| 140 |
FWDChannel *channels; |
| 141 |
struct _X11AuthData *X11_auth_data; |
| 142 |
BOOL in_interactive_mode; |
| 143 |
} FWDState; |
| 144 |
|
| 145 |
void FWD_init(PTInstVar pvar); |
| 146 |
BOOL FWD_can_server_listen_for(PTInstVar pvar, FWDRequestSpec *spec); |
| 147 |
int FWD_get_num_request_specs(PTInstVar pvar); |
| 148 |
void FWD_get_request_specs(PTInstVar pvar, FWDRequestSpec *specs, int num_specs); |
| 149 |
void FWD_set_request_specs(PTInstVar pvar, FWDRequestSpec *specs, int num_specs); |
| 150 |
int FWD_compare_specs(void const *void_spec1, void const *void_spec2); |
| 151 |
void FWD_prep_forwarding(PTInstVar pvar); |
| 152 |
void FWD_enter_interactive_mode(PTInstVar pvar); |
| 153 |
void FWD_open(PTInstVar pvar, uint32 remote_channel_num, |
| 154 |
char *local_hostname, int local_port, |
| 155 |
char *originator, int originator_len, |
| 156 |
int *chan_num); |
| 157 |
void FWD_X11_open(PTInstVar pvar, uint32 remote_channel_num, |
| 158 |
char *originator, int originator_len, |
| 159 |
int *chan_num); |
| 160 |
void FWD_confirmed_open(PTInstVar pvar, uint32 local_channel_num, |
| 161 |
uint32 remote_channel_num); |
| 162 |
void FWD_failed_open(PTInstVar pvar, uint32 local_channel_num, int reason); |
| 163 |
void FWD_received_data(PTInstVar pvar, uint32 local_channel_num, |
| 164 |
unsigned char *data, int length); |
| 165 |
void FWD_channel_input_eof(PTInstVar pvar, uint32 local_channel_num); |
| 166 |
void FWD_channel_output_eof(PTInstVar pvar, uint32 local_channel_num); |
| 167 |
void FWD_end(PTInstVar pvar); |
| 168 |
void FWD_free_channel(PTInstVar pvar, uint32 local_channel_num); |
| 169 |
int FWD_check_local_channel_num(PTInstVar pvar, int local_num); |
| 170 |
int FWD_agent_open(PTInstVar pvar, uint32 remote_channel_num); |
| 171 |
BOOL FWD_agent_forward_confirm(PTInstVar pvar); |
| 172 |
void FWD_suspend_resume_local_connection(PTInstVar pvar, Channel_t* c, int notify); |
| 173 |
|
| 174 |
#endif |