1 // SoftEther VPN Source Code - Stable Edition Repository 2 // Cedar Communication Module 3 // 4 // SoftEther VPN Server, Client and Bridge are free software under the Apache License, Version 2.0. 5 // 6 // Copyright (c) Daiyuu Nobori. 7 // Copyright (c) SoftEther VPN Project, University of Tsukuba, Japan. 8 // Copyright (c) SoftEther Corporation. 9 // Copyright (c) all contributors on SoftEther VPN project in GitHub. 10 // 11 // All Rights Reserved. 12 // 13 // http://www.softether.org/ 14 // 15 // This stable branch is officially managed by Daiyuu Nobori, the owner of SoftEther VPN Project. 16 // Pull requests should be sent to the Developer Edition Master Repository on https://github.com/SoftEtherVPN/SoftEtherVPN 17 // 18 // License: The Apache License, Version 2.0 19 // https://www.apache.org/licenses/LICENSE-2.0 20 // 21 // DISCLAIMER 22 // ========== 23 // 24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 25 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 26 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 27 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 28 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 29 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 30 // SOFTWARE. 31 // 32 // THIS SOFTWARE IS DEVELOPED IN JAPAN, AND DISTRIBUTED FROM JAPAN, UNDER 33 // JAPANESE LAWS. YOU MUST AGREE IN ADVANCE TO USE, COPY, MODIFY, MERGE, PUBLISH, 34 // DISTRIBUTE, SUBLICENSE, AND/OR SELL COPIES OF THIS SOFTWARE, THAT ANY 35 // JURIDICAL DISPUTES WHICH ARE CONCERNED TO THIS SOFTWARE OR ITS CONTENTS, 36 // AGAINST US (SOFTETHER PROJECT, SOFTETHER CORPORATION, DAIYUU NOBORI OR OTHER 37 // SUPPLIERS), OR ANY JURIDICAL DISPUTES AGAINST US WHICH ARE CAUSED BY ANY KIND 38 // OF USING, COPYING, MODIFYING, MERGING, PUBLISHING, DISTRIBUTING, SUBLICENSING, 39 // AND/OR SELLING COPIES OF THIS SOFTWARE SHALL BE REGARDED AS BE CONSTRUED AND 40 // CONTROLLED BY JAPANESE LAWS, AND YOU MUST FURTHER CONSENT TO EXCLUSIVE 41 // JURISDICTION AND VENUE IN THE COURTS SITTING IN TOKYO, JAPAN. YOU MUST WAIVE 42 // ALL DEFENSES OF LACK OF PERSONAL JURISDICTION AND FORUM NON CONVENIENS. 43 // PROCESS MAY BE SERVED ON EITHER PARTY IN THE MANNER AUTHORIZED BY APPLICABLE 44 // LAW OR COURT RULE. 45 // 46 // USE ONLY IN JAPAN. DO NOT USE THIS SOFTWARE IN ANOTHER COUNTRY UNLESS YOU HAVE 47 // A CONFIRMATION THAT THIS SOFTWARE DOES NOT VIOLATE ANY CRIMINAL LAWS OR CIVIL 48 // RIGHTS IN THAT PARTICULAR COUNTRY. USING THIS SOFTWARE IN OTHER COUNTRIES IS 49 // COMPLETELY AT YOUR OWN RISK. THE SOFTETHER VPN PROJECT HAS DEVELOPED AND 50 // DISTRIBUTED THIS SOFTWARE TO COMPLY ONLY WITH THE JAPANESE LAWS AND EXISTING 51 // CIVIL RIGHTS INCLUDING PATENTS WHICH ARE SUBJECTS APPLY IN JAPAN. OTHER 52 // COUNTRIES' LAWS OR CIVIL RIGHTS ARE NONE OF OUR CONCERNS NOR RESPONSIBILITIES. 53 // WE HAVE NEVER INVESTIGATED ANY CRIMINAL REGULATIONS, CIVIL LAWS OR 54 // INTELLECTUAL PROPERTY RIGHTS INCLUDING PATENTS IN ANY OF OTHER 200+ COUNTRIES 55 // AND TERRITORIES. BY NATURE, THERE ARE 200+ REGIONS IN THE WORLD, WITH 56 // DIFFERENT LAWS. IT IS IMPOSSIBLE TO VERIFY EVERY COUNTRIES' LAWS, REGULATIONS 57 // AND CIVIL RIGHTS TO MAKE THE SOFTWARE COMPLY WITH ALL COUNTRIES' LAWS BY THE 58 // PROJECT. EVEN IF YOU WILL BE SUED BY A PRIVATE ENTITY OR BE DAMAGED BY A 59 // PUBLIC SERVANT IN YOUR COUNTRY, THE DEVELOPERS OF THIS SOFTWARE WILL NEVER BE 60 // LIABLE TO RECOVER OR COMPENSATE SUCH DAMAGES, CRIMINAL OR CIVIL 61 // RESPONSIBILITIES. NOTE THAT THIS LINE IS NOT LICENSE RESTRICTION BUT JUST A 62 // STATEMENT FOR WARNING AND DISCLAIMER. 63 // 64 // READ AND UNDERSTAND THE 'WARNING.TXT' FILE BEFORE USING THIS SOFTWARE. 65 // SOME SOFTWARE PROGRAMS FROM THIRD PARTIES ARE INCLUDED ON THIS SOFTWARE WITH 66 // LICENSE CONDITIONS WHICH ARE DESCRIBED ON THE 'THIRD_PARTY.TXT' FILE. 67 // 68 // 69 // SOURCE CODE CONTRIBUTION 70 // ------------------------ 71 // 72 // Your contribution to SoftEther VPN Project is much appreciated. 73 // Please send patches to us through GitHub. 74 // Read the SoftEther VPN Patch Acceptance Policy in advance: 75 // http://www.softether.org/5-download/src/9.patch 76 // 77 // 78 // DEAR SECURITY EXPERTS 79 // --------------------- 80 // 81 // If you find a bug or a security vulnerability please kindly inform us 82 // about the problem immediately so that we can fix the security problem 83 // to protect a lot of users around the world as soon as possible. 84 // 85 // Our e-mail address for security reports is: 86 // softether-vpn-security [at] softether.org 87 // 88 // Please note that the above e-mail address is not a technical support 89 // inquiry address. If you need technical assistance, please visit 90 // http://www.softether.org/ and ask your question on the users forum. 91 // 92 // Thank you for your cooperation. 93 // 94 // 95 // NO MEMORY OR RESOURCE LEAKS 96 // --------------------------- 97 // 98 // The memory-leaks and resource-leaks verification under the stress 99 // test has been passed before release this source code. 100 101 102 // BridgeUnix.h 103 // Header of BridgeUnix.c 104 105 #ifndef BRIDGEUNIX_H 106 #define BRIDGEUNIX_H 107 108 // Macro 109 #ifndef SOL_PACKET 110 #define SOL_PACKET 263 111 #endif 112 #ifndef ifr_newname 113 #define ifr_newname ifr_ifru.ifru_slave 114 #endif 115 116 // Constants 117 #define UNIX_ETH_TMP_BUFFER_SIZE (2000) 118 #define SOLARIS_MAXDLBUF (32768) 119 #define BRIDGE_MAX_QUEUE_SIZE (4096*1500) 120 121 // ETH structure 122 struct ETH 123 { 124 char *Name; // Adapter name 125 char *Title; // Adapter title 126 CANCEL *Cancel; // Cancel object 127 int IfIndex; // Index 128 int Socket; // Socket 129 UINT InitialMtu; // Initial MTU value 130 UINT CurrentMtu; // Current MTU value 131 int SocketBsdIf; // BSD interface operation socket 132 UCHAR MacAddress[6]; // MAC address 133 134 #ifdef BRIDGE_PCAP 135 void *Pcap; // Pcap descriptor 136 QUEUE *Queue; // Queue of the relay thread 137 UINT QueueSize; // Number of bytes in Queue 138 THREAD *CaptureThread; // Pcap relay thread 139 #endif // BRIDGE_PCAP 140 141 #ifdef BRIDGE_BPF 142 UINT BufSize; // Buffer size to read the BPF (error for other) 143 #ifdef BRIDGE_BPF_THREAD 144 QUEUE *Queue; // Queue of the relay thread 145 UINT QueueSize; // Number of bytes in Queue 146 THREAD *CaptureThread; // BPF relay thread 147 #else // BRIDGE_BPF_THREAD 148 UCHAR *Buffer; // Buffer to read the BPF 149 UCHAR *Next; 150 int Rest; 151 #endif // BRIDGE_BPF_THREAD 152 #endif // BRIDGE_BPF 153 154 VLAN *Tap; // tap 155 bool Linux_IsAuxDataSupported; // Is PACKET_AUXDATA supported 156 157 bool IsRawIpMode; // RAW IP mode 158 SOCK *RawTcp, *RawUdp, *RawIcmp; // RAW sockets 159 bool RawIp_HasError; 160 UCHAR RawIpMyMacAddr[6]; 161 UCHAR RawIpYourMacAddr[6]; 162 IP MyIP; 163 IP YourIP; 164 QUEUE *RawIpSendQueue; 165 IP MyPhysicalIP; 166 IP MyPhysicalIPForce; 167 UCHAR *RawIP_TmpBuffer; 168 UINT RawIP_TmpBufferSize; 169 }; 170 171 #if defined( BRIDGE_BPF ) || defined( BRIDGE_PCAP ) 172 struct CAPTUREBLOCK{ 173 UINT Size; 174 UCHAR *Buf; 175 }; 176 #endif // BRIDGE_BPF 177 178 179 // Function prototype 180 void InitEth(); 181 void FreeEth(); 182 bool IsEthSupported(); 183 bool IsEthSupportedLinux(); 184 bool IsEthSupportedSolaris(); 185 bool IsEthSupportedPcap(); 186 TOKEN_LIST *GetEthList(); 187 TOKEN_LIST *GetEthListEx(UINT *total_num_including_hidden, bool enum_normal, bool enum_rawip); 188 TOKEN_LIST *GetEthListLinux(bool enum_normal, bool enum_rawip); 189 TOKEN_LIST *GetEthListSolaris(); 190 TOKEN_LIST *GetEthListPcap(); 191 ETH *OpenEth(char *name, bool local, bool tapmode, char *tapaddr); 192 ETH *OpenEthLinux(char *name, bool local, bool tapmode, char *tapaddr); 193 ETH *OpenEthSolaris(char *name, bool local, bool tapmode, char *tapaddr); 194 ETH *OpenEthPcap(char *name, bool local, bool tapmode, char *tapaddr); 195 bool ParseUnixEthDeviceName(char *dst_devname, UINT dst_devname_size, UINT *dst_devid, char *src_name); 196 void CloseEth(ETH *e); 197 CANCEL *EthGetCancel(ETH *e); 198 UINT EthGetPacket(ETH *e, void **data); 199 UINT EthGetPacketLinux(ETH *e, void **data); 200 UINT EthGetPacketSolaris(ETH *e, void **data); 201 UINT EthGetPacketPcap(ETH *e, void **data); 202 UINT EthGetPacketBpf(ETH *e, void **data); 203 void EthPutPacket(ETH *e, void *data, UINT size); 204 void EthPutPackets(ETH *e, UINT num, void **datas, UINT *sizes); 205 UINT EthGetMtu(ETH *e); 206 bool EthSetMtu(ETH *e, UINT mtu); 207 bool EthIsChangeMtuSupported(ETH *e); 208 bool EthGetInterfaceDescriptionUnix(char *name, char *str, UINT size); 209 bool EthIsInterfaceDescriptionSupportedUnix(); 210 211 ETH *OpenEthLinuxIpRaw(); 212 void CloseEthLinuxIpRaw(ETH *e); 213 UINT EthGetPacketLinuxIpRaw(ETH *e, void **data); 214 UINT EthGetPacketLinuxIpRawForSock(ETH *e, void **data, SOCK *s, UINT proto); 215 void EthPutPacketLinuxIpRaw(ETH *e, void *data, UINT size); 216 bool EthProcessIpPacketInnerIpRaw(ETH *e, PKT *p); 217 void EthSendIpPacketInnerIpRaw(ETH *e, void *data, UINT size, USHORT protocol); 218 219 #ifdef UNIX_SOLARIS 220 // Function prototype for Solaris 221 bool DlipAttatchRequest(int fd, UINT devid); 222 bool DlipReceiveAck(int fd); 223 bool DlipPromiscuous(int fd, UINT level); 224 bool DlipBindRequest(int fd); 225 #endif // OS_SOLARIS 226 227 int UnixEthOpenRawSocket(); 228 229 #endif // BRIDGEUNIX_H 230 231 232