1 // SoftEther VPN Source Code - Stable Edition Repository 2 // Mayaqua Kernel 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 // Network.h 103 // Header of Network.c 104 105 #ifndef NETWORK_H 106 #define NETWORK_H 107 108 // Dynamic Value 109 struct DYN_VALUE 110 { 111 char Name[256]; // Name 112 UINT64 Value; // Value 113 }; 114 115 #define DYN64(id, default_value) ( (UINT64)GetDynValueOrDefaultSafe ( #id , (UINT64)( default_value ))) 116 #define DYN32(id, default_value) (UINT)DYN64(id, (UINT)default_value) 117 118 #define MAX_HOST_NAME_LEN 255 // Maximum length of the host name 119 120 #define TIMEOUT_GETIP 2300 121 122 #define TIMEOUT_INFINITE (0x7fffffff) 123 #define TIMEOUT_TCP_PORT_CHECK (10 * 1000) 124 #define TIMEOUT_SSL_CONNECT (15 * 1000) 125 126 #define TIMEOUT_HOSTNAME (500) 127 #define TIMEOUT_NETBIOS_HOSTNAME (100) 128 #define EXPIRES_HOSTNAME (10 * 60 * 1000) 129 130 #define SOCKET_BUFFER_SIZE 0x10000000 131 132 #define IPV6_DUMMY_FOR_IPV4 0xFEFFFFDF 133 134 #define UDPLISTENER_CHECK_INTERVAL 1000ULL 135 #define UDPLISTENER_WAIT_INTERVAL 1234 136 137 #define UDP_MAX_MSG_SIZE_DEFAULT 65507 138 139 #define MAX_NUM_IGNORE_ERRORS 1024 140 141 #ifndef USE_STRATEGY_LOW_MEMORY 142 #define DEFAULT_GETIP_THREAD_MAX_NUM 512 143 #else // USE_STRATEGY_LOW_MEMORY 144 #define DEFAULT_GETIP_THREAD_MAX_NUM 64 145 #endif // USE_STRATEGY_LOW_MEMORY 146 147 148 // SSL logging function 149 //#define ENABLE_SSL_LOGGING 150 #define SSL_LOGGING_DIRNAME "@ssl_log" 151 152 // Private IP list file 153 #define PRIVATE_IP_TXT_FILENAME "$private_ip.txt" 154 155 // Start range of the random UDP port 156 #define RAND_UDP_PORT_START 5000 157 #define RAND_UDP_PORT_END 65530 158 #define RAND_UDP_PORT_DEFAULT_NUM_RETRY 64 159 160 // Special Port 161 #define MAKE_SPECIAL_PORT(p) (UINT)((UINT)0x10000 | (UINT)(p)) 162 #define IS_SPECIAL_PORT(p) (MAKEBOOL((p) & (UINT)0x10000)) 163 #define GET_SPECIAL_PORT(p) (UINT)((UINT)(p) & (UINT)0xffff) 164 165 // Random R-UDP port ID 166 #define RAND_PORT_ID_SERVER_LISTEN 1 167 168 // UDP buffer size 169 #define UDP_MAX_BUFFER_SIZE 11911168 170 171 // Expiration of the cache acquired from the IP address list of the host 172 #define HOST_IP_ADDRESS_LIST_CACHE (5 * 1000) 173 174 // IP address 175 struct IP 176 { 177 UCHAR addr[4]; // IPv4 address, (meaning that 223.255.255.254 = IPv6) 178 UCHAR ipv6_addr[16]; // IPv6 address 179 UINT ipv6_scope_id; // IPv6 scope ID 180 }; 181 182 // Size when comparing the IP structures only in the address part 183 #define SIZE_OF_IP_FOR_ADDR (sizeof(UCHAR) * 20) 184 185 // Compare the IP address part 186 #define CmpIpAddr(ip1, ip2) (Cmp((ip1), (ip2), SIZE_OF_IP_FOR_ADDR)) 187 188 // IPv6 address (different format) 189 struct IPV6_ADDR 190 { 191 UCHAR Value[16]; // Value 192 } GCC_PACKED; 193 194 // IPv6 Address Types 195 #define IPV6_ADDR_UNICAST 1 // Unicast 196 #define IPV6_ADDR_LOCAL_UNICAST 2 // Local unicast 197 #define IPV6_ADDR_GLOBAL_UNICAST 4 // Global Unicast 198 #define IPV6_ADDR_MULTICAST 8 // Multicast 199 #define IPV6_ADDR_ALL_NODE_MULTICAST 16 // All-nodes multicast 200 #define IPV6_ADDR_ALL_ROUTER_MULTICAST 32 // All routers multicast 201 #define IPV6_ADDR_SOLICIATION_MULTICAST 64 // Solicited-node multicast 202 #define IPV6_ADDR_ZERO 128 // All zeros 203 #define IPV6_ADDR_LOOPBACK 256 // Loop-back 204 205 206 // DNS cache list 207 struct DNSCACHE 208 { 209 char *HostName; 210 IP IpAddress; 211 }; 212 213 // Client list 214 struct IP_CLIENT 215 { 216 IP IpAddress; // IP address 217 UINT NumConnections; // The number of connections 218 }; 219 220 // Socket event 221 struct SOCK_EVENT 222 { 223 REF *ref; // Reference counter 224 #ifdef OS_WIN32 225 void *hEvent; // Pointer to a Win32 event handle 226 #else // OS_WIN32 227 LIST *SockList; // Socket list 228 int pipe_read, pipe_write; // Pipe 229 UINT current_pipe_data; // Amount of data in the current pipe 230 #endif // OS_WIN32 231 }; 232 233 // Type of socket 234 #define SOCK_TCP 1 235 #define SOCK_UDP 2 236 #define SOCK_INPROC 3 237 #define SOCK_RUDP_LISTEN 5 238 #define SOCK_REVERSE_LISTEN 6 239 240 // SSL Accept Settings 241 struct SSL_ACCEPT_SETTINGS 242 { 243 bool AcceptOnlyTls; 244 bool Tls_Disable1_0; 245 bool Tls_Disable1_1; 246 bool Tls_Disable1_2; 247 bool Tls_Disable1_3; 248 }; 249 250 // Socket 251 struct SOCK 252 { 253 REF *ref; // Reference counter 254 LOCK *lock; // Lock 255 LOCK *ssl_lock; // Lock related to the SSL 256 LOCK *disconnect_lock; // Disconnection lock 257 SOCKET socket; // Socket number 258 SSL *ssl; // SSL object 259 struct ssl_ctx_st *ssl_ctx; // SSL_CTX 260 char SniHostname[256]; // SNI host name 261 UINT Type; // Type of socket 262 bool Connected; // Connecting flag 263 bool ServerMode; // Server mode 264 bool AsyncMode; // Asynchronous mode 265 bool SecureMode; // SSL communication mode 266 bool ListenMode; // In listening 267 BUF *SendBuf; // Transmission buffer 268 bool IpClientAdded; // Whether it has been added to the list IP_CLIENT 269 bool LocalOnly; // Only local 270 bool EnableConditionalAccept; // Conditional Accept is Enabled 271 IP RemoteIP; // IP address of the remote host 272 IP LocalIP; // IP address of the local host 273 char *RemoteHostname; // Remote host name 274 UINT RemotePort; // Port number of the remote side 275 UINT LocalPort; // Port number of the local side 276 UINT64 SendSize; // Total size of the sent data 277 UINT64 RecvSize; // Total size of received data 278 UINT64 SendNum; // Number of sent data blocks 279 UINT64 RecvNum; // Number of received data blocks 280 X *RemoteX; // Certificate of the remote host 281 X *LocalX; // Certificate of the local host 282 char *CipherName; // Cipher algorithm name 283 char *WaitToUseCipher; // Set the algorithm name to want to use 284 bool IgnoreRecvErr; // Whether the RecvFrom error is ignorable 285 bool IgnoreSendErr; // Whether the SendTo error is ignorable 286 UINT TimeOut; // Time-out value 287 SOCK_EVENT *SockEvent; // Associated socket-event 288 bool CancelAccept; // Cancel flag of the Accept 289 bool AcceptCanceled; // Flag which shows canceling of the Accept 290 bool WriteBlocked; // Previous write is blocked 291 bool NoNeedToRead; // Is not required to read 292 bool Disconnecting; // Disconnecting 293 bool UdpBroadcast; // UDP broadcast mode 294 void *Param; // Any parameters 295 bool IPv6; // IPv6 296 bool IsRawSocket; // Whether it is a raw socket 297 const char *SslVersion; // SSL version 298 UINT RawSocketIPProtocol; // IP protocol number if it's a raw socket 299 TUBE *SendTube; // Tube for transmission 300 TUBE *RecvTube; // Tube for reception 301 QUEUE *InProcAcceptQueue; // Accept queue of the in-process socket 302 EVENT *InProcAcceptEvent; // Accept event of the in-process socket 303 FIFO *InProcRecvFifo; // Receive FIFO of the in-process socket 304 UINT UdpMaxMsgSize; // Maximum transmitting and receiving size at a time on UDP 305 int CurrentTos; // Current ToS value 306 bool IsTtlSupported; // Whether the TTL value is supported 307 UINT CurrentTtl; // Current TTL value 308 RUDP_STACK *R_UDP_Stack; // R-UDP stack 309 char UnderlayProtocol[64]; // Underlying protocol 310 char ProtocolDetails[256]; // Protocol Details 311 QUEUE *ReverseAcceptQueue; // Accept queue for the reverse socket 312 EVENT *ReverseAcceptEvent; // Accept event for the reverse socket 313 bool IsReverseAcceptedSocket; // Whether it is a reverse socket 314 IP Reverse_MyServerGlobalIp; // Self global IP address when using the reverse socket 315 UINT Reverse_MyServerPort; // Self port number when using the reverse socket 316 UCHAR Ssl_Init_Async_SendAlert[2]; // Initial state of SSL send_alert 317 SSL_ACCEPT_SETTINGS SslAcceptSettings; // SSL Accept Settings 318 bool RawIP_HeaderIncludeFlag; 319 320 #ifdef ENABLE_SSL_LOGGING 321 // SSL Logging (for debug) 322 bool IsSslLoggingEnabled; // Flag 323 IO *SslLogging_Recv; // for Recv 324 IO *SslLogging_Send; // for Send 325 LOCK *SslLogging_Lock; // Locking 326 #endif // ENABLE_SSL_LOGGING 327 328 void *hAcceptEvent; // Event for Accept 329 330 // R-UDP socket related 331 bool IsRUDPSocket; // Whether this is R-UDP socket 332 TUBE *BulkSendTube; // Tube for Bulk send 333 TUBE *BulkRecvTube; // Tube for Bulk receive 334 SHARED_BUFFER *BulkSendKey; // Bulk send key 335 SHARED_BUFFER *BulkRecvKey; // Bulk receive key 336 UINT RUDP_OptimizedMss; // Optimal MSS value 337 338 #ifdef OS_UNIX 339 pthread_t CallingThread; // Thread that is calling the system call 340 #endif // OS_UNIX 341 342 #ifdef OS_WIN32 343 void *hEvent; // Event for asynchronous mode 344 #endif // OS_WIN32 345 }; 346 347 // Underlying protocol description string of socket 348 #define SOCK_UNDERLAY_NATIVE_V6 "Standard TCP/IP (IPv6)" 349 #define SOCK_UNDERLAY_NATIVE_V4 "Standard TCP/IP (IPv4)" 350 #define SOCK_UNDERLAY_NAT_T "VPN over UDP with NAT-T (IPv4)" 351 #define SOCK_UNDERLAY_DNS "VPN over DNS (IPv4)" 352 #define SOCK_UNDERLAY_ICMP "VPN over ICMP (IPv4)" 353 #define SOCK_UNDERLAY_INPROC "In-Process Pipe" 354 #define SOCK_UNDERLAY_INPROC_EX "Legacy VPN - %s" 355 #define SOCK_UNDERLAY_AZURE "TCP/IP via VPN Azure (IPv4)" 356 357 // Constant of the return value 358 #define SOCK_LATER (0xffffffff) // In blocking 359 360 // Socket Set 361 #define MAX_SOCKSET_NUM 60 // Number of sockets that can be stored in a socket set 362 struct SOCKSET 363 { 364 UINT NumSocket; // The number of sockets 365 SOCK *Sock[MAX_SOCKSET_NUM]; // Array of pointers to the socket 366 }; 367 368 // Cancel object 369 struct CANCEL 370 { 371 REF *ref; // Reference counter 372 bool SpecialFlag; // Special flag (associated to the event which is generated by Win32 driver) 373 #ifdef OS_WIN32 374 void *hEvent; // Pointer to a Win32 event handle 375 #else // OS_WIN32 376 int pipe_read, pipe_write; // Pipe 377 int pipe_special_read2, pipe_special_read3; 378 #endif // OS_WIN32 379 }; 380 381 // Routing table entry 382 struct ROUTE_ENTRY 383 { 384 IP DestIP; 385 IP DestMask; 386 IP GatewayIP; 387 bool LocalRouting; 388 bool PPPConnection; 389 UINT Metric; 390 UINT OldIfMetric; 391 UINT InterfaceID; 392 UINT64 InnerScore; 393 }; 394 395 // Routing table 396 struct ROUTE_TABLE 397 { 398 UINT NumEntry; 399 UINT HashedValue; 400 ROUTE_ENTRY **Entry; 401 }; 402 403 // ICMP response result 404 struct ICMP_RESULT 405 { 406 bool Ok; // Whether a correct response returned 407 bool Timeout; // Whether a time-out is occurred 408 UCHAR Type; // Message type 409 UCHAR Code; // Message code 410 UCHAR Ttl; // TTL 411 UCHAR *Data; // Data body 412 UINT DataSize; // Data size 413 UINT Rtt; // Round Trip Time 414 IP IpAddress; // IP address 415 }; 416 417 418 // Host name cache list 419 typedef struct HOSTCACHE 420 { 421 UINT64 Expires; // Expiration 422 IP IpAddress; // IP address 423 char HostName[256]; // Host name 424 } HOSTCACHE; 425 426 // NETBIOS name requests 427 typedef struct NBTREQUEST 428 { 429 USHORT TransactionId; 430 USHORT Flags; 431 USHORT NumQuestions; 432 USHORT AnswerRRs; 433 USHORT AuthorityRRs; 434 USHORT AdditionalRRs; 435 UCHAR Query[38]; 436 } NBTREQUEST; 437 438 // NETBIOS name response 439 typedef struct NBTRESPONSE 440 { 441 USHORT TransactionId; 442 USHORT Flags; 443 USHORT NumQuestions; 444 USHORT AnswerRRs; 445 USHORT AuthorityRRs; 446 USHORT AdditionalRRs; 447 UCHAR Response[61]; 448 } NBTRESPONSE; 449 450 // Socket list 451 typedef struct SOCKLIST 452 { 453 LIST *SockList; 454 } SOCKLIST; 455 456 457 // Parameters for timeout thread for Solaris 458 typedef struct SOCKET_TIMEOUT_PARAM{ 459 SOCK *sock; 460 CANCEL *cancel; 461 THREAD *thread; 462 bool unblocked; 463 } SOCKET_TIMEOUT_PARAM; 464 465 // Parameters for GetIP thread 466 struct GETIP_THREAD_PARAM 467 { 468 REF *Ref; 469 char HostName[MAX_PATH]; 470 bool IPv6; 471 UINT Timeout; 472 IP Ip; 473 bool Ok; 474 }; 475 476 // Parameters for the IP address release thread 477 struct WIN32_RELEASEADDRESS_THREAD_PARAM 478 { 479 REF *Ref; 480 char Guid[MAX_SIZE]; 481 UINT Timeout; 482 bool Ok; 483 bool Renew; 484 }; 485 486 // TCP table entry 487 typedef struct TCPTABLE 488 { 489 UINT Status; 490 IP LocalIP; 491 UINT LocalPort; 492 IP RemoteIP; 493 UINT RemotePort; 494 UINT ProcessId; 495 } TCPTABLE; 496 497 // State of TCP 498 #define TCP_STATE_CLOSED 1 499 #define TCP_STATE_LISTEN 2 500 #define TCP_STATE_SYN_SENT 3 501 #define TCP_STATE_SYN_RCVD 4 502 #define TCP_STATE_ESTAB 5 503 #define TCP_STATE_FIN_WAIT1 6 504 #define TCP_STATE_FIN_WAIT2 7 505 #define TCP_STATE_CLOSE_WAIT 8 506 #define TCP_STATE_CLOSING 9 507 #define TCP_STATE_LAST_ACK 10 508 #define TCP_STATE_TIME_WAIT 11 509 #define TCP_STATE_DELETE_TCB 12 510 511 // Routing table changing notification 512 struct ROUTE_CHANGE 513 { 514 ROUTE_CHANGE_DATA *Data; 515 }; 516 517 // Tube flush list 518 struct TUBE_FLUSH_LIST 519 { 520 LIST *List; // List 521 }; 522 523 // Tube 524 struct TUBE 525 { 526 REF *Ref; // Reference counter 527 LOCK *Lock; // Lock 528 QUEUE *Queue; // Packet queue 529 EVENT *Event; // Event 530 SOCK_EVENT *SockEvent; // SockEvent 531 UINT SizeOfHeader; // Header size 532 TUBEPAIR_DATA *TubePairData; // Tube pair data 533 UINT IndexInTubePair; // Number in the tube pair 534 bool IsInFlushList; // Whether it is registered in the Tube Flush List 535 void *Param1, *Param2, *Param3; 536 UINT IntParam1, IntParam2, IntParam3; 537 }; 538 539 // Data that is to send and to receive in the tube 540 struct TUBEDATA 541 { 542 void *Data; // Body of data 543 UINT DataSize; // The size of the data 544 void *Header; // The body of the header 545 UINT HeaderSize; // Size of the header 546 }; 547 548 // Tube pair data 549 struct TUBEPAIR_DATA 550 { 551 bool IsDisconnected; // Disconnection flag 552 REF *Ref; // Reference counter 553 LOCK *Lock; // Lock 554 EVENT *Event1, *Event2; // Event 555 SOCK_EVENT *SockEvent1, *SockEvent2; // SockEvent 556 }; 557 558 // UDP listener socket entry 559 struct UDPLISTENER_SOCK 560 { 561 IP IpAddress; // IP address 562 UINT Port; // Port number 563 SOCK *Sock; // Socket 564 bool HasError; // Whether an error occurs 565 bool Mark; // Mark 566 bool ErrorDebugDisplayed; // Whether the error has been displayed 567 UINT64 NextMyIpAndPortPollTick; // Time to check the self IP address and port number next 568 IP PublicIpAddress; // Global IP address 569 UINT PublicPort; // Global port number 570 }; 571 572 // UDP packet 573 struct UDPPACKET 574 { 575 IP SrcIP; // Source IP address 576 IP DstIP; // Destination IP address 577 UINT SrcPort; // Source port 578 UINT DestPort; // Destination port 579 UINT Size; // Data size 580 void *Data; // Data body 581 UINT Type; // Type 582 }; 583 584 // UDP listener packet receipt notification procedure 585 typedef void (UDPLISTENER_RECV_PROC)(UDPLISTENER *u, LIST *packet_list); 586 587 // UDP listener 588 struct UDPLISTENER 589 { 590 bool Halt; // Halting flag 591 SOCK_EVENT *Event; // Event 592 THREAD *Thread; // Thread 593 LIST *PortList; // Port list 594 LIST *SockList; // Socket list 595 UINT64 LastCheckTick; // Time which the socket list was checked last 596 UDPLISTENER_RECV_PROC *RecvProc; // Receive procedure 597 LIST *SendPacketList; // Transmission packet list 598 void *Param; // Parameters 599 INTERRUPT_MANAGER *Interrupts; // Interrupt manager 600 bool HostIPAddressListChanged; // IP address list of the host has changed 601 bool IsEspRawPortOpened; // Whether the raw port opens 602 bool PollMyIpAndPort; // Examine whether the global IP and the port number of its own 603 QUERYIPTHREAD *GetNatTIpThread; // NAT-T IP address acquisition thread 604 }; 605 606 #define QUERYIPTHREAD_INTERVAL_LAST_OK (3 * 60 * 60 * 1000) 607 #define QUERYIPTHREAD_INTERVAL_LAST_NG (30 * 1000) 608 609 // IP address acquisition thread 610 struct QUERYIPTHREAD 611 { 612 THREAD *Thread; // Thread 613 EVENT *HaltEvent; // Halting event 614 bool Halt; // Halting flag 615 LOCK *Lock; // Lock 616 IP Ip; // Get the IP address 617 char Hostname[MAX_SIZE]; // Host name 618 UINT IntervalLastOk; // Interval if last was OK 619 UINT IntervalLastNg; // Interval if last was NG 620 }; 621 622 // Interrupt management 623 struct INTERRUPT_MANAGER 624 { 625 LIST *TickList; // Time list 626 }; 627 628 // SSL BIO 629 struct SSL_BIO 630 { 631 BIO *bio; // BIO 632 FIFO *SendFifo; // Transmission FIFO 633 FIFO *RecvFifo; // Reception FIFO 634 bool IsDisconnected; // Disconnected 635 bool NoFree; // Not to release the BIO 636 }; 637 638 // SSL pipe 639 struct SSL_PIPE 640 { 641 bool ServerMode; // Whether it's in the server mode 642 bool IsDisconnected; // Disconnected 643 SSL *ssl; // SSL object 644 struct ssl_ctx_st *ssl_ctx; // SSL_CTX 645 SSL_BIO *SslInOut; // I/O BIO for the data in the SSL tunnel 646 SSL_BIO *RawIn, *RawOut; // Input and output BIO of the data flowing through the physical network 647 }; 648 649 // IP address block list 650 struct IPBLOCK 651 { 652 IP Ip; // IP address 653 IP Mask; // Subnet mask 654 }; 655 656 657 // R-UDP related constants 658 #define RUDP_RESEND_TIMER 200 // Retransmission timer (initial value) 659 #define RUDP_RESEND_TIMER_MAX 4792 // Retransmission timer (maximum value) 660 #define RUDP_KEEPALIVE_INTERVAL_MIN 2500 // Transmission interval of Keep Alive (minimum) 661 #define RUDP_KEEPALIVE_INTERVAL_MAX 4792 // Transmission interval of Keep Alive (maximum) 662 #define RUDP_TIMEOUT 12000 // Time-out of R-UDP communication 663 #define RUDP_DIRECT_CONNECT_TIMEOUT 5000 // R-UDP direct connection time-out 664 #define RUDP_MAX_SEGMENT_SIZE 512 // Maximum segment size 665 #define RUDP_BULK_KEY_SIZE_MAX 128 // Bulk key size Max 666 667 #define RUDP_BULK_KEY_SIZE_V2 32 // V2: Bulk key size 668 #define RUDP_BULK_IV_SIZE_V2 12 // V2: Bulk IV size 669 #define RUDP_BULK_MAC_SIZE_V2 16 // V2: Bulk MAC size 670 671 // Maximum R-UDP packet size 672 #define RUDP_MAX_PACKET_SIZE (RUDP_MAX_SEGMENT_SIZE + sizeof(UINT64) * RUDP_MAX_NUM_ACK + SHA1_SIZE * 2 + sizeof(UINT64) * 4 + sizeof(UINT) + 255) 673 #define RUDP_MAX_NUM_ACK 64 // Maximum number of ACKs 674 #define RUDP_LOOP_WAIT_INTERVAL_S 1234 // Waiting time in the thread main loop (in server side) 675 #define RUDP_LOOP_WAIT_INTERVAL_C 100 // Waiting time in the thread main loop (in client side) 676 #define RUDP_MAX_FIFO_SIZE (1600 * 1600) // The maximum FIFO buffer size 677 678 // Interval for sending ICMP Echo from the client side when R-UDP used in ICMP mode 679 #define RUDP_CLIENT_ECHO_REQUEST_SEND_INTERVAL_MIN 1000 680 #define RUDP_CLIENT_ECHO_REQUEST_SEND_INTERVAL_MAX 3000 681 682 // R-UDP error code 683 #define RUDP_ERROR_OK 0 // Success 684 #define RUDP_ERROR_UNKNOWN 1 // Unknown Error 685 #define RUDP_ERROR_TIMEOUT 2 // Time-out 686 #define RUDP_ERROR_NAT_T_GETIP_FAILED 3 // IP address acquisition failure of NAT-T server 687 #define RUDP_ERROR_NAT_T_NO_RESPONSE 4 // There is no response from the NAT-T server 688 #define RUDP_ERROR_NAT_T_TWO_OR_MORE 5 // There are two or more hosts on the same destination IP address 689 #define RUDP_ERROR_NAT_T_NOT_FOUND 6 // Host does not exist at the specified IP address 690 #define RUDP_ERROR_USER_CANCELED 7 // Cancel by the user 691 692 // R-UDP segment 693 struct RUDP_SEGMENT 694 { 695 UINT64 SeqNo; // Sequence number 696 UINT Size; // Size 697 UCHAR Data[RUDP_MAX_SEGMENT_SIZE]; // Data 698 UINT64 NextSendTick; // Next transmission time 699 UINT NumSent; // Number of times sent 700 }; 701 702 // Status of R-UDP session 703 #define RUDP_SESSION_STATUS_CONNECT_SENT 0 // Connection request sent 704 #define RUDP_SESSION_STATUS_ESTABLISHED 1 // Connection established 705 706 // Quota 707 #define RUDP_QUOTA_MAX_NUM_SESSIONS_PER_IP DYN32(RUDP_QUOTA_MAX_NUM_SESSIONS_PER_IP, 1000) // The number of R-UDP sessions per an IP address 708 #define RUDP_QUOTA_MAX_NUM_SESSIONS DYN32(RUDP_QUOTA_MAX_NUM_SESSIONS, 30000) // Limit of the Number of sessions 709 710 // Range of the sequence numbers of bulk packet 711 #define RUDP_BULK_SEQ_NO_RANGE 16384ULL 712 #define RUDP_BULK_MAX_RECV_PKTS_IN_QUEUE 8192 713 714 // R-UDP session 715 struct RUDP_SESSION 716 { 717 UINT Status; // Status 718 bool ServerMode; // Whether it's in the server mode 719 bool DisconnectFlag; // Disconnection flag 720 bool DisconnectedByYou; // Disconnected from opponent 721 bool UseHMac; 722 IP MyIp; // IP address of itself 723 UINT MyPort; // Port number of itself 724 IP YourIp; // Opponent IP address 725 UINT YourPort; // Opponent port number 726 LIST *SendSegmentList; // Transmission segment list 727 LIST *RecvSegmentList; // Received segments list 728 LIST *ReplyAckList; // List of ACKs in response 729 SOCK *TcpSock; // Corresponding TCP socket 730 UINT64 LastSentTick; // Time which the data has been sent last 731 UINT64 LastRecvTick; // Time which the data has been received last 732 UCHAR Key_Init[SHA1_SIZE]; // Initial key 733 UCHAR Key_Send[SHA1_SIZE]; // Key that is used to send 734 UCHAR Key_Recv[SHA1_SIZE]; // Key that is used to receive 735 UCHAR Magic_KeepAliveRequest[SHA1_SIZE]; // The magic number for the KeepAlive request 736 UCHAR Magic_KeepAliveResponse[SHA1_SIZE]; // The magic number for KeepAlive response 737 UINT64 Magic_Disconnect; // Disconnection Signal 738 UINT64 NextSendSeqNo; // Transmission sequence number to be used next 739 UINT64 LastRecvCompleteSeqNo; // Sequence number of receiving complete 740 // (This indicates all segments which have sequence number up to this number are received completely) 741 UCHAR NextIv[SHA1_SIZE]; // IV value to be used next 742 UINT NextKeepAliveInterval; // Interval value of KeepAlive to be used next 743 FIFO *RecvFifo; // Reception FIFO 744 FIFO *SendFifo; // Transmission FIFO 745 UINT64 YourTick; // The largest value among received Tick from the opponent 746 UINT64 LatestRecvMyTick; // Value of the last tick among the received tick values 747 UINT64 LatestRecvMyTick2; // Variable for confirming whether LatestRecvMyTick2 changes 748 UINT CurrentRtt; // Current RTT value 749 750 UINT Icmp_Type; // Number of Type to be used in the ICMP 751 USHORT Dns_TranId; // Value of transaction ID used in DNS 752 UINT64 Client_Icmp_NextSendEchoRequest; // Time to send the next Echo Request in the ICMP 753 SHARED_BUFFER *BulkSendKey; // Bulk send key 754 SHARED_BUFFER *BulkRecvKey; // Bulk receive key 755 UCHAR BulkNextIv[SHA1_SIZE]; // Next IV to the bulk send 756 UINT64 BulkNextSeqNo; // Next SEQ NO to the bulk send 757 bool FlushBulkSendTube; // Flag to be Flush the bulk send Tube 758 UINT64 BulkRecvSeqNoMax; // Highest sequence number received 759 UCHAR BulkNextIv_V2[RUDP_BULK_IV_SIZE_V2]; // Next IV to the bulk send (Ver 2) 760 }; 761 762 // NAT Traversal Server Information 763 #define UDP_NAT_T_SERVER_TAG "x%c.x%c.servers.nat-traversal.softether-network.net." 764 #define UDP_NAT_T_SERVER_TAG_ALT "x%c.x%c.servers.nat-traversal.uxcom.jp." 765 #define UDP_NAT_T_PORT 5004 766 767 // Related to processing to get the IP address of the NAT-T server 768 #define UDP_NAT_T_GET_IP_INTERVAL DYN32(UDP_NAT_T_GET_IP_INTERVAL, (5 * 1000)) // IP address acquisition interval of NAT-T server (before success) 769 #define UDP_NAT_T_GET_IP_INTERVAL_MAX DYN32(UDP_NAT_T_GET_IP_INTERVAL, (150 * 1000)) // IP address acquisition interval of NAT-T server (before success) 770 #define UDP_NAT_T_GET_IP_INTERVAL_AFTER DYN32(UDP_NAT_T_GET_IP_INTERVAL_AFTER, (5 * 60 * 1000)) // IP address acquisition interval of NAT-T server (after success) 771 772 // Related to process to get the private IP address of itself with making a TCP connection to the NAT-T server 773 #define UDP_NAT_T_GET_PRIVATE_IP_TCP_SERVER "www.msftncsi.com." 774 775 #define UDP_NAT_T_PORT_FOR_TCP_1 80 776 #define UDP_NAT_T_PORT_FOR_TCP_2 443 777 778 #define UDP_NAT_TRAVERSAL_VERSION 1 779 780 #define UDP_NAT_T_GET_PRIVATE_IP_INTERVAL DYN32(UDP_NAT_T_GET_PRIVATE_IP_INTERVAL, (15 * 60 * 1000)) // Polling interval (before success) 781 #define UDP_NAT_T_GET_PRIVATE_IP_INTERVAL_AFTER_MIN DYN32(UDP_NAT_T_GET_PRIVATE_IP_INTERVAL_AFTER_MIN, (30 * 60 * 1000)) // Polling interval (after success) 782 #define UDP_NAT_T_GET_PRIVATE_IP_INTERVAL_AFTER_MAX DYN32(UDP_NAT_T_GET_PRIVATE_IP_INTERVAL_AFTER_MAX, (60 * 60 * 1000)) // Polling interval (after success) 783 #define UDP_NAT_T_GET_PRIVATE_IP_CONNECT_TIMEOUT DYN32(UDP_NAT_T_GET_PRIVATE_IP_CONNECT_TIMEOUT, (5 * 1000)) // TCP connection time-out 784 785 // About token acquisition from the NAT-T server 786 #define UDP_NAT_T_GET_TOKEN_INTERVAL_1 DYN32(UDP_NAT_T_GET_TOKEN_INTERVAL_1, (5 * 1000)) // Token acquisition interval from the NAT-T server (If not acquired) 787 #define UDP_NAT_T_GET_TOKEN_INTERVAL_FAIL_MAX DYN32(UDP_NAT_T_GET_TOKEN_INTERVAL_FAIL_MAX, 20) 788 #define UDP_NAT_T_GET_TOKEN_INTERVAL_2_MIN DYN32(UDP_NAT_T_GET_TOKEN_INTERVAL_2_MIN, (20 * 60 * 1000)) // Token acquisition interval minimum value from the NAT-T server (If token have been obtained) 789 #define UDP_NAT_T_GET_TOKEN_INTERVAL_2_MAX DYN32(UDP_NAT_T_GET_TOKEN_INTERVAL_2_MAX, (30 * 60 * 1000)) // Token acquisition interval maximum value from the NAT-T server (If token have been obtained) 790 791 // The Register interval for NAT-T server 792 #define UDP_NAT_T_REGISTER_INTERVAL_INITIAL DYN32(UDP_NAT_T_REGISTER_INTERVAL_INITIAL, (5 * 1000)) // Transmission interval when the Register is not completed 793 #define UDP_NAT_T_REGISTER_INTERVAL_FAIL_MAX DYN32(UDP_NAT_T_REGISTER_INTERVAL_FAIL_MAX, 20) 794 #define UDP_NAT_T_REGISTER_INTERVAL_MIN DYN32(UDP_NAT_T_REGISTER_INTERVAL_MIN, (220 * 1000)) // Minimum value of the Register interval 795 #define UDP_NAT_T_REGISTER_INTERVAL_MAX DYN32(UDP_NAT_T_REGISTER_INTERVAL_MAX, (240 * 1000)) // Maximum value of the Register interval 796 797 // Interval for checking whether the port number or the IP address is changed 798 #define UDP_NAT_T_NAT_STATUS_CHECK_INTERVAL_MIN DYN32(UDP_NAT_T_NAT_STATUS_CHECK_INTERVAL_MIN, (24 * 1000)) 799 #define UDP_NAT_T_NAT_STATUS_CHECK_INTERVAL_MAX DYN32(UDP_NAT_T_NAT_STATUS_CHECK_INTERVAL_MAX, (28 * 1000)) 800 801 // The Connect Request interval for NAT-T server 802 #define UDP_NAT_T_CONNECT_INTERVAL DYN32(UDP_NAT_T_CONNECT_INTERVAL, 200) 803 804 // Polling interval for its own IP information acquisition to the NAT-T server in regular communication between the client and the server 805 #define UDP_NAT_T_INTERVAL_MIN DYN32(UDP_NAT_T_INTERVAL_MIN, (5 * 60 * 1000)) 806 #define UDP_NAT_T_INTERVAL_MAX DYN32(UDP_NAT_T_INTERVAL_MAX, (10 * 60 * 1000)) 807 #define UDP_NAT_T_INTERVAL_INITIAL DYN32(UDP_NAT_T_INTERVAL_INITIAL, (3 * 1000)) 808 #define UDP_NAT_T_INTERVAL_FAIL_MAX DYN32(UDP_NAT_T_INTERVAL_FAIL_MAX, 60) 809 810 // R-UDP stack callback function definition 811 typedef void (RUDP_STACK_INTERRUPTS_PROC)(RUDP_STACK *r); 812 typedef bool (RUDP_STACK_RPC_RECV_PROC)(RUDP_STACK *r, UDPPACKET *p); 813 814 // ICMP protocol number 815 #define IP_PROTO_ICMPV4 0x01 // ICMPv4 protocol 816 #define IP_PROTO_ICMPV6 0x3a // ICMPv6 protocol 817 818 // R-UDP protocol 819 #define RUDP_PROTOCOL_UDP 0 // UDP 820 #define RUDP_PROTOCOL_ICMP 1 // ICMP 821 #define RUDP_PROTOCOL_DNS 2 // DNS 822 823 // Maximum time of continously changing of the NAT-T hostname 824 #define RUDP_NATT_MAX_CONT_CHANGE_HOSTNAME 30 825 #define RUDP_NATT_CONT_CHANGE_HOSTNAME_RESET_INTERVAL (5 * 60 * 1000) 826 827 // Minimum time to wait for a trial to connect by ICMP and DNS in case failing to connect by TCP 828 #define SOCK_CONNECT_WAIT_FOR_ICMP_AND_DNS_AT_LEAST 5000 829 830 #define RUDP_MAX_VALIDATED_SOURCE_IP_ADDRESSES 512 831 #define RUDP_VALIDATED_SOURCE_IP_ADDRESS_EXPIRES (RUDP_TIMEOUT * 2) 832 833 // Validated Source IP Addresses for R-UDP 834 struct RUDP_SOURCE_IP 835 { 836 UINT64 ExpiresTick; // Expires 837 IP ClientIP; // Client IP address 838 }; 839 840 // R-UDP stack 841 struct RUDP_STACK 842 { 843 bool ServerMode; // Whether it's in the server mode 844 char SvcName[MAX_SIZE]; // Service name 845 UCHAR SvcNameHash[SHA1_SIZE]; // Hash of the service name 846 bool Halt; // Halting flag 847 void *Param; // Parameters that can be used by developers 848 UINT64 Now; // Current time 849 EVENT *HaltEvent; // Halting event 850 INTERRUPT_MANAGER *Interrupt; // Interrupt manager 851 LIST *SessionList; // Session List 852 SOCK *UdpSock; // UDP socket 853 UINT Port; // Port number 854 UINT Protocol; // Protocol 855 SOCK_EVENT *SockEvent; // Socket event 856 THREAD *Thread; // Thread 857 LOCK *Lock; // Lock 858 RUDP_STACK_INTERRUPTS_PROC *ProcInterrupts; // Interrupt notification callback 859 RUDP_STACK_RPC_RECV_PROC *ProcRpcRecv; // RPC reception notification callback 860 THREAD *IpQueryThread; // NAT-T server IP inquiry thread 861 UCHAR TmpBuf[65536]; // Temporary buffer 862 LIST *SendPacketList; // Transmission UDP packet list 863 EVENT *NewSockConnectEvent; // Event to inform that a new socket is connected 864 QUEUE *NewSockQueue; // Queue of new socket 865 UINT64 TotalPhysicalReceived; // Physical amount of data received 866 UINT64 TotalLogicalReceived; // Logical amount of data received 867 UINT64 TotalPhysicalSent; // Physical amount of data transmitted 868 UINT64 TotalLogicalSent; // Logical amount of data transmitted 869 char CurrentRegisterHostname[MAX_SIZE]; // The host name of the the current destination of registration 870 UINT NumChangedHostname; // How number of changing NAT-T hostname has occured continously 871 UINT64 NumChangedHostnameValueResetTick; 872 873 // NAT-T server related 874 bool NoNatTRegister; // Flag not to register with the NAT-T server 875 UINT64 NatT_TranId; // Transaction ID is used to communicate with the NAT-T server 876 UINT64 NatT_SessionKey; // Current Session Key 877 IP NatT_IP; // IP address of the NAT-T server 878 IP NatT_IP_Safe; // IP address of the NAT-T server (thread-safe) 879 IP My_Private_IP; // Private IP address of itself 880 IP My_Private_IP_Safe; // Private IP address of itself (thread-safe) 881 UINT64 NatT_GetTokenNextTick; // Time to get the next token 882 UINT NatT_GetTokenFailNum; // Token acquisition failure times 883 char NatT_Token[MAX_SIZE]; // Token needed to communicate with NAT-T Server 884 bool NatT_Token_Ok; // Flag of whether it have a valid token 885 UINT64 NatT_RegisterNextTick; // Time to register next 886 UINT NatT_RegisterFailNum; // The number of Register failures 887 bool NatT_Register_Ok; // Is a successful registration 888 char NatT_Registered_IPAndPort[128]; // IP address and port number at the time of registration success 889 UINT64 NatT_NextNatStatusCheckTick; // Time to check the NAT state next 890 UINT LastDDnsFqdnHash; // DNS FQDN hash value when last checked 891 volatile UINT *NatTGlobalUdpPort; // NAT-T global UDP port 892 UCHAR RandPortId; // Random UDP port ID 893 bool NatT_EnableSourceIpValidation; // Enable the source IP address validation mechanism 894 LIST *NatT_SourceIpList; // Authenticated source IP adddress list 895 896 // For Client 897 bool TargetIpAndPortInited; // The target IP address and the port number are initialized 898 IP TargetIp; // Target IP address 899 UINT TargetPort; // Target port number 900 EVENT *TargetConnectedEvent; // Event to be set when the connection to the target is successful 901 SOCK *TargetConnectedSock; // Connected socket 902 bool ClientInitiated; // Flag to indicate that the connection is initiated 903 bool DoNotSetTargetConnectedSock; // Flag indicating that it should not set the TargetConnectedSock 904 USHORT Client_IcmpId, Client_IcmpSeqNo; // Sequence number and ICMP ID that is randomly generated on the client side 905 }; 906 907 // Data for the thread for concurrent connection attempts for the R-UDP and TCP 908 struct CONNECT_TCP_RUDP_PARAM 909 { 910 IP Ip; 911 UINT Port; 912 UINT Timeout; 913 char Hostname[MAX_SIZE]; 914 bool *CancelFlag; 915 UINT NatT_ErrorCode; 916 char SvcName[MAX_SIZE]; 917 char HintStr[MAX_SIZE]; 918 char TargetHostname[MAX_SIZE]; 919 SOCK *Result_Nat_T_Sock; 920 SOCK *Result_Tcp_Sock; 921 bool Finished; 922 bool Ok; 923 UINT64 FinishedTick; 924 EVENT *FinishEvent; 925 UINT RUdpProtocol; 926 UINT Delay; 927 bool Tcp_TryStartSsl; 928 bool Tcp_SslNoTls; 929 LOCK *CancelLock; 930 SOCK *CancelDisconnectSock; 931 bool Tcp_InNegotiation; 932 }; 933 934 #define SSL_DEFAULT_CONNECT_TIMEOUT (15 * 1000) // SSL default timeout 935 936 // Header for TCP Pair 937 struct TCP_PAIR_HEADER 938 { 939 bool EnableHMac; 940 }; 941 942 // The constants for file query by using UDP 943 #define UDP_FILE_QUERY_RETRY_INTERVAL 100 // Retry interval 944 #define UDP_FILE_QUERY_DST_PORT 5004 // Destination UDP port number 945 #define UDP_FILE_QUERY_MAGIC_NUMBER "{5E465695-7923-4CCD-9B51-44444BE1E758}" // Magic number 946 #define UDP_FILE_QUERY_BFLETS_TXT_FILENAME "|BFletsUdpList.txt" // Text file name of the IPv6 node list 947 948 // The constant for DNS proxy for the B FLETs 949 #define BFLETS_DNS_PROXY_PORT 443 950 #define BFLETS_DNS_PROXY_PATH "/ddns/queryhost.aspx" 951 #define BFLETS_DNS_PROXY_CERT_HASH "EFAC5FA0CDD14E0F864EED58A73C35D7E33B62F3" 952 #define BFLETS_DNS_PROXY_TIMEOUT_FOR_GET_F 500 // Timeout when searching for the server by UDP 953 #define BFLETS_DNS_PROXY_TIMEOUT_FOR_QUERY 3000 // Timeout for the response from the proxy DNS server 954 955 // FLET'S Hikar-Next (East) DNS proxy host name 956 #define FLETS_NGN_EAST_DNS_PROXY_HOSTNAME "senet.aoi.flets-east.jp" 957 #define FLETS_NGN_WEST_DNS_PROXY_HOSTNAME "senet.p-ns.flets-west.jp" 958 #define FLETS_NGN_DNS_QUERY_TIMEOUT 1000 // FLET'S Hikar-Next host name query timeout 959 960 // Detection result of the type of FLET'S line 961 #define FLETS_DETECT_TYPE_EAST_BFLETS_PRIVATE 1 // NTT East B-FLETs 962 #define FLETS_DETECT_TYPE_EAST_NGN_PRIVATE 2 // Wrapping in network of NTT East NGN 963 #define FLETS_DETECT_TYPE_WEST_NGN_PRIVATE 4 // Wrapping in network of NTT West NGN 964 965 // NIC adapter entry 966 struct NIC_ENTRY 967 { 968 char IfName[MAX_SIZE]; 969 UCHAR MacAddress[6]; 970 }; 971 972 973 // HTTP value 974 struct HTTP_VALUE 975 { 976 char *Name; // Name 977 char *Data; // Data 978 }; 979 980 // HTTP header 981 struct HTTP_HEADER 982 { 983 char *Method; // Method 984 char *Target; // Target 985 char *Version; // Version 986 LIST *ValueList; // Value list 987 }; 988 989 // HTTPS server / client related string constant 990 #define DEFAULT_USER_AGENT "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:29.0) Gecko/20100101 Firefox/29.0" 991 #define DEFAULT_ACCEPT "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/msword, application/vnd.ms-powerpoint, application/vnd.ms-excel, */*" 992 #define DEFAULT_ENCODING "gzip, deflate" 993 #define HTTP_CONTENT_TYPE "text/html; charset=iso-8859-1" 994 #define HTTP_CONTENT_TYPE2 "application/octet-stream" 995 #define HTTP_CONTENT_TYPE3 "image/jpeg" 996 #define HTTP_CONTENT_TYPE4 "text/html" 997 #define HTTP_CONTENT_TYPE5 "message/rfc822" 998 #define HTTP_KEEP_ALIVE "timeout=15; max=19" 999 #define HTTP_VPN_TARGET "/vpnsvc/vpn.cgi" 1000 #define HTTP_VPN_TARGET2 "/vpnsvc/connect.cgi" 1001 #define HTTP_VPN_TARGET_POSTDATA "VPNCONNECT" 1002 #define HTTP_SAITAMA "/saitama.jpg" 1003 #define HTTP_PICTURES "/picture" 1004 // Maximum size of a single line in the HTTP header 1005 #define HTTP_HEADER_LINE_MAX_SIZE 4096 1006 // Maximum number of lines in the HTTP header 1007 #define HTTP_HEADER_MAX_LINES 128 1008 // Maximum size of the random number to be included in the PACK 1009 #define HTTP_PACK_RAND_SIZE_MAX 1000 1010 // Maximum PACK size in the HTTP 1011 #define HTTP_PACK_MAX_SIZE 65536 1012 1013 1014 1015 1016 1017 int GetCurrentTimezone(); 1018 1019 bool GetSniNameFromSslPacket(UCHAR *packet_buf, UINT packet_size, char *sni, UINT sni_size); 1020 bool GetSniNameFromPreSslConnection(SOCK *s, char *sni, UINT sni_size); 1021 1022 bool IsUseDnsProxy(); 1023 bool IsUseAlternativeHostname(); 1024 1025 #ifdef OS_WIN32 1026 int GetCurrentTimezoneWin32(); 1027 #endif // OS_WIN32 1028 1029 HTTP_VALUE *GetHttpValue(HTTP_HEADER *header, char *name); 1030 void AddHttpValue(HTTP_HEADER *header, HTTP_VALUE *value); 1031 HTTP_HEADER *NewHttpHeader(char *method, char *target, char *version); 1032 HTTP_HEADER *NewHttpHeaderEx(char *method, char *target, char *version, bool no_sort); 1033 int CompareHttpValue(void *p1, void *p2); 1034 void FreeHttpValue(HTTP_VALUE *value); 1035 void FreeHttpHeader(HTTP_HEADER *header); 1036 1037 bool SendPack(SOCK *s, PACK *p); 1038 PACK *RecvPack(SOCK *s); 1039 PACK *RecvPackWithHash(SOCK *s); 1040 bool SendPackWithHash(SOCK *s, PACK *p); 1041 1042 UINT GetErrorFromPack(PACK *p); 1043 PACK *PackError(UINT error); 1044 1045 void CreateDummyValue(PACK *p); 1046 1047 HTTP_VALUE *NewHttpValue(char *name, char *data); 1048 char *RecvLine(SOCK *s, UINT max_size); 1049 HTTP_HEADER *RecvHttpHeader(SOCK *s); 1050 bool SendHttpHeader(SOCK *s, HTTP_HEADER *header); 1051 char *HttpHeaderToStr(HTTP_HEADER *header); 1052 bool PostHttp(SOCK *s, HTTP_HEADER *header, void *post_data, UINT post_size); 1053 UINT GetContentLength(HTTP_HEADER *header); 1054 void GetHttpDateStr(char *str, UINT size, UINT64 t); 1055 bool HttpSendForbidden(SOCK *s, char *target, char *server_id); 1056 bool HttpSendNotFound(SOCK *s, char *target); 1057 bool HttpSendBody(SOCK *s, void *data, UINT size, char *contents_type); 1058 bool HttpSendNotImplemented(SOCK *s, char *method, char *target, char *version); 1059 bool HttpSendInvalidHostname(SOCK *s, char *method); 1060 bool HttpServerSend(SOCK *s, PACK *p); 1061 bool HttpClientSend(SOCK *s, PACK *p); 1062 PACK *HttpServerRecv(SOCK *s); 1063 PACK *HttpServerRecvEx(SOCK *s, UINT max_data_size); 1064 PACK *HttpClientRecv(SOCK *s); 1065 1066 bool HttpSendServerError(SOCK *s, char *target); 1067 1068 bool GetIPViaDnsProxyForJapanFlets(IP *ip_ret, char *hostname, bool ipv6, UINT timeout, bool *cancel, char *dns_proxy_hostname); 1069 bool GetDnsProxyIPAddressForJapanBFlets(IP *ip_ret, UINT timeout, bool *cancel); 1070 BUF *QueryFileByUdpForJapanBFlets(UINT timeout, bool *cancel); 1071 BUF *QueryFileByIPv6Udp(LIST *ip_list, UINT timeout, bool *cancel); 1072 UINT DetectFletsType(); 1073 1074 void ListenTcpForPopupFirewallDialog(); 1075 1076 bool DetectIsServerSoftEtherVPN(SOCK *s); 1077 void ConnectThreadForTcp(THREAD *thread, void *param); 1078 void ConnectThreadForRUDP(THREAD *thread, void *param); 1079 void ConnectThreadForOverDnsOrIcmp(THREAD *thread, void *param); 1080 SOCK *NewRUDPClientNatT(char *svc_name, IP *ip, UINT *error_code, UINT timeout, bool *cancel, char *hint_str, char *target_hostname); 1081 RUDP_STACK *NewRUDPServer(char *svc_name, RUDP_STACK_INTERRUPTS_PROC *proc_interrupts, RUDP_STACK_RPC_RECV_PROC *proc_rpc_recv, void *param, UINT port, bool no_natt_register, bool over_dns_mode, volatile UINT *natt_global_udp_port, UCHAR rand_port_id); 1082 SOCK *NewRUDPClientDirect(char *svc_name, IP *ip, UINT port, UINT *error_code, UINT timeout, bool *cancel, SOCK *sock, SOCK_EVENT *sock_event, UINT local_port, bool over_dns_mode); 1083 RUDP_STACK *NewRUDP(bool server_mode, char *svc_name, RUDP_STACK_INTERRUPTS_PROC *proc_interrupts, RUDP_STACK_RPC_RECV_PROC *proc_rpc_recv, void *param, UINT port, SOCK *sock, SOCK_EVENT *sock_event, bool server_no_natt_register, bool over_dns_mode, IP *client_target_ip, volatile UINT *natt_global_udp_port, UCHAR rand_port_id); 1084 void FreeRUDP(RUDP_STACK *r); 1085 void RUDPMainThread(THREAD *thread, void *param); 1086 void RUDPRecvProc(RUDP_STACK *r, UDPPACKET *p); 1087 void RUDPInterruptProc(RUDP_STACK *r); 1088 void RUDPIpQueryThread(THREAD *thread, void *param); 1089 void RUDPSendPacket(RUDP_STACK *r, IP *dest_ip, UINT dest_port, void *data, UINT size, UINT icmp_type); 1090 void GetCurrentMachineIpProcessHash(void *hash); 1091 void GetCurrentMachineIpProcessHashInternal(void *hash); 1092 int RUDPCompareSessionList(void *p1, void *p2); 1093 RUDP_SESSION *RUDPNewSession(bool server_mode, IP *my_ip, UINT my_port, IP *your_ip, UINT your_port, UCHAR *init_key); 1094 void RUDPFreeSession(RUDP_SESSION *se); 1095 int RUDPCompareSegmentList(void *p1, void *p2); 1096 RUDP_SESSION *RUDPSearchSession(RUDP_STACK *r, IP *my_ip, UINT my_port, IP *your_ip, UINT your_port); 1097 void RUDPSendSegmentNow(RUDP_STACK *r, RUDP_SESSION *se, UINT64 seq_no, void *data, UINT size); 1098 void RUDPSendSegment(RUDP_STACK *r, RUDP_SESSION *se, void *data, UINT size); 1099 bool RUDPProcessRecvPacket(RUDP_STACK *r, RUDP_SESSION *se, void *recv_data, UINT recv_size); 1100 bool RUDPCheckSignOfRecvPacket(RUDP_STACK *r, RUDP_SESSION *se, void *recv_data, UINT recv_size); 1101 void RUDPProcessAck(RUDP_STACK *r, RUDP_SESSION *se, UINT64 seq); 1102 void RUDPProcessAck2(RUDP_STACK *r, RUDP_SESSION *se, UINT64 max_seq); 1103 void RUDPProcessRecvPayload(RUDP_STACK *r, RUDP_SESSION *se, UINT64 seq, void *payload_data, UINT payload_size); 1104 void RUDPInitSock(RUDP_STACK *r, RUDP_SESSION *se); 1105 void RUDPDisconnectSession(RUDP_STACK *r, RUDP_SESSION *se, bool disconnected_by_you); 1106 UINT64 RUDPGetCurrentSendingMinSeqNo(RUDP_SESSION *se); 1107 UINT64 RUDPGetCurrentSendingMaxSeqNo(RUDP_SESSION *se); 1108 SOCK *ListenRUDP(char *svc_name, RUDP_STACK_INTERRUPTS_PROC *proc_interrupts, RUDP_STACK_RPC_RECV_PROC *proc_rpc_recv, void *param, UINT port, bool no_natt_register, bool over_dns_mode); 1109 SOCK *ListenRUDPEx(char *svc_name, RUDP_STACK_INTERRUPTS_PROC *proc_interrupts, RUDP_STACK_RPC_RECV_PROC *proc_rpc_recv, void *param, UINT port, bool no_natt_register, bool over_dns_mode, 1110 volatile UINT *natt_global_udp_port, UCHAR rand_port_id); 1111 SOCK *AcceptRUDP(SOCK *s); 1112 void *InitWaitUntilHostIPAddressChanged(); 1113 void FreeWaitUntilHostIPAddressChanged(void *p); 1114 void WaitUntilHostIPAddressChanged(void *p, EVENT *event, UINT timeout, UINT ip_check_interval); 1115 UINT GetHostIPAddressHash32(); 1116 bool GetMyPrivateIP(IP *ip, bool from_vg); 1117 char *GetRandHostNameForGetMyPrivateIP(); 1118 UINT GenRandInterval(UINT min, UINT max); 1119 void RUDPProcess_NatT_Recv(RUDP_STACK *r, UDPPACKET *udp); 1120 void RUDPDo_NatT_Interrupt(RUDP_STACK *r); 1121 void RUDPGetRegisterHostNameByIP(char *dst, UINT size, IP *ip); 1122 bool RUDPParseIPAndPortStr(void *data, UINT data_size, IP *ip, UINT *port); 1123 void ParseNtUsername(char *src_username, char *dst_username, UINT dst_username_size, char *dst_domain, UINT dst_domain_size, bool do_not_parse_atmark); 1124 void RUDPBulkSend(RUDP_STACK *r, RUDP_SESSION *se, void *data, UINT data_size); 1125 bool RUDPProcessBulkRecvPacket(RUDP_STACK *r, RUDP_SESSION *se, void *recv_data, UINT recv_size); 1126 UINT RUDPCalcBestMssForBulk(RUDP_STACK *r, RUDP_SESSION *se); 1127 bool IsIPLocalHostOrMySelf(IP *ip); 1128 UINT RUDPGetRandPortNumber(UCHAR rand_port_id); 1129 void RUDPSetSourceIpValidationForceDisable(bool b); 1130 bool RUDPIsIpInValidateList(RUDP_STACK *r, IP *ip); 1131 void RUDPAddIpToValidateList(RUDP_STACK *r, IP *ip); 1132 1133 bool GetBestLocalIpForTarget(IP *local_ip, IP *target_ip); 1134 SOCK *NewUDP4ForSpecificIp(IP *target_ip, UINT port); 1135 1136 #ifdef OS_WIN32 1137 1138 // Function prototype for Win32 1139 void Win32InitSocketLibrary(); 1140 void Win32FreeSocketLibrary(); 1141 void Win32Select(SOCKSET *set, UINT timeout, CANCEL *c1, CANCEL *c2); 1142 void Win32InitAsyncSocket(SOCK *sock); 1143 void Win32JoinSockToSockEvent(SOCK *sock, SOCK_EVENT *event); 1144 void Win32FreeAsyncSocket(SOCK *sock); 1145 void Win32IpForwardRowToRouteEntry(ROUTE_ENTRY *entry, void *ip_forward_row); 1146 void Win32RouteEntryToIpForwardRow(void *ip_forward_row, ROUTE_ENTRY *entry); 1147 int Win32CompareRouteEntryByMetric(void *p1, void *p2); 1148 ROUTE_TABLE *Win32GetRouteTable(); 1149 bool Win32AddRouteEntry(ROUTE_ENTRY *e, bool *already_exists); 1150 void Win32DeleteRouteEntry(ROUTE_ENTRY *e); 1151 void Win32UINTToIP(IP *ip, UINT i); 1152 UINT Win32IPToUINT(IP *ip); 1153 UINT Win32GetVLanInterfaceID(char *instance_name); 1154 char **Win32EnumVLan(char *tag_name); 1155 void Win32Cancel(CANCEL *c); 1156 void Win32CleanupCancel(CANCEL *c); 1157 CANCEL *Win32NewCancel(); 1158 SOCK_EVENT *Win32NewSockEvent(); 1159 void Win32SetSockEvent(SOCK_EVENT *event); 1160 void Win32CleanupSockEvent(SOCK_EVENT *event); 1161 bool Win32WaitSockEvent(SOCK_EVENT *event, UINT timeout); 1162 bool Win32GetDefaultDns(IP *ip, char *domain, UINT size); 1163 bool Win32GetDnsSuffix(char *domain, UINT size); 1164 void Win32RenewDhcp(); 1165 void Win32RenewDhcp9x(UINT if_id); 1166 void Win32ReleaseDhcp9x(UINT if_id, bool wait); 1167 void Win32FlushDnsCache(); 1168 int CompareIpAdapterIndexMap(void *p1, void *p2); 1169 LIST *Win32GetTcpTableList(); 1170 LIST *Win32GetTcpTableListByGetExtendedTcpTable(); 1171 LIST *Win32GetTcpTableListByAllocateAndGetTcpExTableFromStack(); 1172 LIST *Win32GetTcpTableListByGetTcpTable(); 1173 ROUTE_CHANGE *Win32NewRouteChange(); 1174 void Win32FreeRouteChange(ROUTE_CHANGE *r); 1175 bool Win32IsRouteChanged(ROUTE_CHANGE *r); 1176 bool Win32GetAdapterFromGuid(void *a, char *guid); 1177 SOCKET Win32Accept(SOCK *sock, SOCKET s, struct sockaddr *addr, int *addrlen, bool ipv6); 1178 1179 bool Win32ReleaseAddress(void *a); 1180 bool Win32ReleaseAddressByGuid(char *guid); 1181 bool Win32ReleaseAddressByGuidEx(char *guid, UINT timeout); 1182 void Win32ReleaseAddressByGuidExThread(THREAD *t, void *param); 1183 void ReleaseWin32ReleaseAddressByGuidThreadParam(WIN32_RELEASEADDRESS_THREAD_PARAM *p); 1184 bool Win32ReleaseOrRenewAddressByGuidEx(char *guid, UINT timeout, bool renew); 1185 bool Win32RenewAddress(void *a); 1186 bool Win32RenewAddressByGuid(char *guid); 1187 bool Win32RenewAddressByGuidEx(char *guid, UINT timeout); 1188 1189 1190 #else // OS_WIN32 1191 1192 // Function prototype for UNIX 1193 void UnixInitSocketLibrary(); 1194 void UnixFreeSocketLibrary(); 1195 void UnixSelect(SOCKSET *set, UINT timeout, CANCEL *c1, CANCEL *c2); 1196 void UnixInitAsyncSocket(SOCK *sock); 1197 void UnixJoinSockToSockEvent(SOCK *sock, SOCK_EVENT *event); 1198 void UnixFreeAsyncSocket(SOCK *sock); 1199 void UnixIpForwardRowToRouteEntry(ROUTE_ENTRY *entry, void *ip_forward_row); 1200 void UnixRouteEntryToIpForwardRow(void *ip_forward_row, ROUTE_ENTRY *entry); 1201 int UnixCompareRouteEntryByMetric(void *p1, void *p2); 1202 ROUTE_TABLE *UnixGetRouteTable(); 1203 bool UnixAddRouteEntry(ROUTE_ENTRY *e, bool *already_exists); 1204 void UnixDeleteRouteEntry(ROUTE_ENTRY *e); 1205 UINT UnixGetVLanInterfaceID(char *instance_name); 1206 char **UnixEnumVLan(char *tag_name); 1207 void UnixCancel(CANCEL *c); 1208 void UnixCleanupCancel(CANCEL *c); 1209 CANCEL *UnixNewCancel(); 1210 SOCK_EVENT *UnixNewSockEvent(); 1211 void UnixSetSockEvent(SOCK_EVENT *event); 1212 void UnixCleanupSockEvent(SOCK_EVENT *event); 1213 bool UnixWaitSockEvent(SOCK_EVENT *event, UINT timeout); 1214 bool UnixGetDefaultDns(IP *ip); 1215 void UnixRenewDhcp(); 1216 void UnixNewPipe(int *pipe_read, int *pipe_write); 1217 void UnixWritePipe(int pipe_write); 1218 void UnixDeletePipe(int p1, int p2); 1219 void UnixSelectInner(UINT num_read, UINT *reads, UINT num_write, UINT *writes, UINT timeout); 1220 void UnixSetSocketNonBlockingMode(int fd, bool nonblock); 1221 1222 #endif // OS_WIN32 1223 1224 // Function prototype 1225 void InitNetwork(); 1226 void FreeNetwork(); 1227 void InitDnsCache(); 1228 void FreeDnsCache(); 1229 void LockDnsCache(); 1230 void UnlockDnsCache(); 1231 int CompareDnsCache(void *p1, void *p2); 1232 void GenDnsCacheKeyName(char *dst, UINT size, char *src, bool ipv6); 1233 void NewDnsCacheEx(char *hostname, IP *ip, bool ipv6); 1234 DNSCACHE *FindDnsCacheEx(char *hostname, bool ipv6); 1235 bool QueryDnsCacheEx(IP *ip, char *hostname, bool ipv6); 1236 void NewDnsCache(char *hostname, IP *ip); 1237 DNSCACHE *FindDnsCache(char *hostname); 1238 bool QueryDnsCache(IP *ip, char *hostname); 1239 void InAddrToIP(IP *ip, struct in_addr *addr); 1240 void InAddrToIP6(IP *ip, struct in6_addr *addr); 1241 void IPToInAddr(struct in_addr *addr, IP *ip); 1242 void IPToInAddr6(struct in6_addr *addr, IP *ip); 1243 bool StrToIP(IP *ip, char *str); 1244 UINT StrToIP32(char *str); 1245 bool UniStrToIP(IP *ip, wchar_t *str); 1246 UINT UniStrToIP32(wchar_t *str); 1247 void IPToStr(char *str, UINT size, IP *ip); 1248 void IPToStr4(char *str, UINT size, IP *ip); 1249 void IPToStr32(char *str, UINT size, UINT ip); 1250 void IPToStr128(char *str, UINT size, UCHAR *ip_bytes); 1251 void IPToStr4or6(char *str, UINT size, UINT ip_4_uint, UCHAR *ip_6_bytes); 1252 void IPToUniStr(wchar_t *str, UINT size, IP *ip); 1253 void IPToUniStr32(wchar_t *str, UINT size, UINT ip); 1254 bool GetIPEx(IP *ip, char *hostname, bool ipv6); 1255 bool GetIP46(IP *ip4, IP *ip6, char *hostname); 1256 bool GetIP46Ex(IP *ip4, IP *ip6, char *hostname, UINT timeout, bool *cancel); 1257 bool GetIP46Any4(IP *ip, char *hostname); 1258 bool GetIP46Any6(IP *ip, char *hostname); 1259 bool GetIP(IP *ip, char *hostname); 1260 bool GetIP4(IP *ip, char *hostname); 1261 bool GetIP6(IP *ip, char *hostname); 1262 bool GetIP4Ex(IP *ip, char *hostname, UINT timeout, bool *cancel); 1263 bool GetIP6Ex(IP *ip, char *hostname, UINT timeout, bool *cancel); 1264 bool GetIP4Ex6Ex(IP *ip, char *hostname, UINT timeout, bool ipv6, bool *cancel); 1265 bool GetIP4Ex6Ex2(IP *ip, char *hostname, UINT timeout, bool ipv6, bool *cancel, bool only_direct_dns); 1266 void GetIP4Ex6ExThread(THREAD *t, void *param); 1267 void ReleaseGetIPThreadParam(GETIP_THREAD_PARAM *p); 1268 void CleanupGetIPThreadParam(GETIP_THREAD_PARAM *p); 1269 bool GetIP4Inner(IP *ip, char *hostname); 1270 bool GetIP6Inner(IP *ip, char *hostname); 1271 bool GetHostNameInner(char *hostname, UINT size, IP *ip); 1272 bool GetHostNameInner6(char *hostname, UINT size, IP *ip); 1273 bool GetHostName(char *hostname, UINT size, IP *ip); 1274 void GetHostNameThread(THREAD *t, void *p); 1275 void GetMachineName(char *name, UINT size); 1276 void GetMachineNameEx(char *name, UINT size, bool no_load_hosts); 1277 bool GetMachineNameFromHosts(char *name, UINT size); 1278 void GetMachineIp(IP *ip); 1279 void GetMachineHostName(char *name, UINT size); 1280 void UINTToIP(IP *ip, UINT value); 1281 UINT IPToUINT(IP *ip); 1282 SOCK *NewSock(); 1283 void ReleaseSock(SOCK *s); 1284 void CleanupSock(SOCK *s); 1285 SOCK *Connect(char *hostname, UINT port); 1286 SOCK *ConnectEx(char *hostname, UINT port, UINT timeout); 1287 SOCK *ConnectEx2(char *hostname, UINT port, UINT timeout, bool *cancel_flag); 1288 SOCK *ConnectEx3(char *hostname, UINT port, UINT timeout, bool *cancel_flag, char *nat_t_svc_name, UINT *nat_t_error_code, bool try_start_ssl, bool ssl_no_tls, bool no_get_hostname); 1289 SOCK *ConnectEx4(char *hostname, UINT port, UINT timeout, bool *cancel_flag, char *nat_t_svc_name, UINT *nat_t_error_code, bool try_start_ssl, bool ssl_no_tls, bool no_get_hostname, IP *ret_ip); 1290 SOCKET ConnectTimeoutIPv4(IP *ip, UINT port, UINT timeout, bool *cancel_flag); 1291 void SetSocketSendRecvBufferSize(SOCKET s, UINT size); 1292 UINT GetSocketBufferSize(SOCKET s, bool send); 1293 bool SetSocketBufferSize(SOCKET s, bool send, UINT size); 1294 UINT SetSocketBufferSizeWithBestEffort(SOCKET s, bool send, UINT size); 1295 void InitUdpSocketBufferSize(SOCKET s); 1296 void QuerySocketInformation(SOCK *sock); 1297 bool SetTtl(SOCK *sock, UINT ttl); 1298 void Disconnect(SOCK *sock); 1299 SOCK *Listen(UINT port); 1300 SOCK *ListenEx(UINT port, bool local_only); 1301 SOCK *ListenEx2(UINT port, bool local_only, bool enable_ca); 1302 SOCK *Listen6(UINT port); 1303 SOCK *ListenEx6(UINT port, bool local_only); 1304 SOCK *ListenEx62(UINT port, bool local_only, bool enable_ca); 1305 SOCK *Accept(SOCK *sock); 1306 SOCK *Accept6(SOCK *sock); 1307 UINT Send(SOCK *sock, void *data, UINT size, bool secure); 1308 UINT Recv(SOCK *sock, void *data, UINT size, bool secure); 1309 UINT Peek(SOCK *sock, void *data, UINT size); 1310 void SetNoNeedToRead(SOCK *sock); 1311 UINT SecureSend(SOCK *sock, void *data, UINT size); 1312 UINT SecureRecv(SOCK *sock, void *data, UINT size); 1313 bool StartSSL(SOCK *sock, X *x, K *priv); 1314 bool StartSSLEx(SOCK *sock, X *x, K *priv, bool client_tls, UINT ssl_timeout, char *sni_hostname); 1315 bool AddChainSslCert(struct ssl_ctx_st *ctx, X *x); 1316 void AddChainSslCertOnDirectory(struct ssl_ctx_st *ctx); 1317 bool SendAll(SOCK *sock, void *data, UINT size, bool secure); 1318 void SendAdd(SOCK *sock, void *data, UINT size); 1319 bool SendNow(SOCK *sock, int secure); 1320 bool RecvAll(SOCK *sock, void *data, UINT size, bool secure); 1321 bool RecvAllWithDiscard(SOCK *sock, UINT size, bool secure); 1322 void InitSockSet(SOCKSET *set); 1323 void AddSockSet(SOCKSET *set, SOCK *sock); 1324 CANCEL *NewCancel(); 1325 CANCEL *NewCancelSpecial(void *hEvent); 1326 void ReleaseCancel(CANCEL *c); 1327 void CleanupCancel(CANCEL *c); 1328 void Cancel(CANCEL *c); 1329 void Select(SOCKSET *set, UINT timeout, CANCEL *c1, CANCEL *c2); 1330 void SetWantToUseCipher(SOCK *sock, char *name); 1331 void InitAsyncSocket(SOCK *sock); 1332 SOCK *NewUDP(UINT port); 1333 SOCK *NewUDPEx(UINT port, bool ipv6); 1334 SOCK *NewUDPEx2(UINT port, bool ipv6, IP *ip); 1335 SOCK *NewUDPEx3(UINT port, IP *ip); 1336 SOCK *NewUDP4(UINT port, IP *ip); 1337 SOCK *NewUDP6(UINT port, IP *ip); 1338 SOCK *NewUDPEx2Rand(bool ipv6, IP *ip, void *rand_seed, UINT rand_seed_size, UINT num_retry); 1339 SOCK *NewUDPEx2RandMachineAndExePath(bool ipv6, IP *ip, UINT num_retry, UCHAR rand_port_id); 1340 void ClearSockDfBit(SOCK *s); 1341 void SetRawSockHeaderIncludeOption(SOCK *s, bool enable); 1342 UINT GetNewAvailableUdpPortRand(); 1343 UINT NewRandPortByMachineAndExePath(UINT start_port, UINT end_port, UINT additional_int); 1344 void DisableUDPChecksum(SOCK *s); 1345 UINT SendTo(SOCK *sock, IP *dest_addr, UINT dest_port, void *data, UINT size); 1346 UINT SendToEx(SOCK *sock, IP *dest_addr, UINT dest_port, void *data, UINT size, bool broadcast); 1347 UINT SendTo6(SOCK *sock, IP *dest_addr, UINT dest_port, void *data, UINT size); 1348 UINT SendTo6Ex(SOCK *sock, IP *dest_addr, UINT dest_port, void *data, UINT size, bool broadcast); 1349 UINT RecvFrom(SOCK *sock, IP *src_addr, UINT *src_port, void *data, UINT size); 1350 UINT RecvFrom6(SOCK *sock, IP *src_addr, UINT *src_port, void *data, UINT size); 1351 void SetTimeout(SOCK *sock, UINT timeout); 1352 UINT GetTimeout(SOCK *sock); 1353 bool CheckTCPPort(char *hostname, UINT port); 1354 bool CheckTCPPortEx(char *hostname, UINT port, UINT timeout); 1355 void CheckTCPPortThread(THREAD *thread, void *param); 1356 ROUTE_TABLE *GetRouteTable(); 1357 void FreeRouteTable(ROUTE_TABLE *t); 1358 bool AddRouteEntryEx(ROUTE_ENTRY *e, bool *already_exists); 1359 bool AddRouteEntry(ROUTE_ENTRY *e); 1360 void DeleteRouteEntry(ROUTE_ENTRY *e); 1361 char **EnumVLan(char *tag_name); 1362 void FreeEnumVLan(char **s); 1363 UINT GetVLanInterfaceID(char *tag_name); 1364 ROUTE_ENTRY *GetBestRouteEntry(IP *ip); 1365 ROUTE_ENTRY *GetBestRouteEntryEx(IP *ip, UINT exclude_if_id); 1366 ROUTE_ENTRY *GetBestRouteEntryFromRouteTable(ROUTE_TABLE *table, IP *ip); 1367 ROUTE_ENTRY *GetBestRouteEntryFromRouteTableEx(ROUTE_TABLE *table, IP *ip, UINT exclude_if_id); 1368 void FreeRouteEntry(ROUTE_ENTRY *e); 1369 void JoinSockToSockEvent(SOCK *sock, SOCK_EVENT *event); 1370 SOCK_EVENT *NewSockEvent(); 1371 void SetSockEvent(SOCK_EVENT *event); 1372 void CleanupSockEvent(SOCK_EVENT *event); 1373 bool WaitSockEvent(SOCK_EVENT *event, UINT timeout); 1374 void ReleaseSockEvent(SOCK_EVENT *event); 1375 void SetIP(IP *ip, UCHAR a1, UCHAR a2, UCHAR a3, UCHAR a4); 1376 UINT SetIP32(UCHAR a1, UCHAR a2, UCHAR a3, UCHAR a4); 1377 bool GetDefaultDns(IP *ip); 1378 bool GetDomainName(char *name, UINT size); 1379 bool UnixGetDomainName(char *name, UINT size); 1380 void RenewDhcp(); 1381 void AcceptInit(SOCK *s); 1382 void AcceptInitEx(SOCK *s, bool no_lookup_hostname); 1383 void DisableGetHostNameWhenAcceptInit(); 1384 bool CheckCipherListName(char *name); 1385 TOKEN_LIST *GetCipherList(); 1386 COUNTER *GetNumTcpConnectionsCounter(); 1387 void InitWaitThread(); 1388 void FreeWaitThread(); 1389 void AddWaitThread(THREAD *t); 1390 void DelWaitThread(THREAD *t); 1391 void InitHostCache(); 1392 void FreeHostCache(); 1393 int CompareHostCache(void *p1, void *p2); 1394 void AddHostCache(IP *ip, char *hostname); 1395 bool GetHostCache(char *hostname, UINT size, IP *ip); 1396 bool IsSubnetMask(IP *ip); 1397 bool IsSubnetMask4(IP *ip); 1398 bool IsSubnetMask32(UINT ip); 1399 bool IsNetworkAddress(IP *ip, IP *mask); 1400 bool IsNetworkAddress4(IP *ip, IP *mask); 1401 bool IsNetworkAddress32(UINT ip, UINT mask); 1402 bool IsHostIPAddress4(IP *ip); 1403 bool IsHostIPAddress32(UINT ip); 1404 bool IsZeroIp(IP *ip); 1405 bool IsZeroIP(IP *ip); 1406 bool IsZeroIP6Addr(IPV6_ADDR *addr); 1407 UINT IntToSubnetMask32(UINT i); 1408 void IntToSubnetMask4(IP *ip, UINT i); 1409 bool GetNetBiosName(char *name, UINT size, IP *ip); 1410 bool NormalizeMacAddress(char *dst, UINT size, char *src); 1411 SOCKLIST *NewSockList(); 1412 void AddSockList(SOCKLIST *sl, SOCK *s); 1413 void DelSockList(SOCKLIST *sl, SOCK *s); 1414 void StopSockList(SOCKLIST *sl); 1415 void FreeSockList(SOCKLIST *sl); 1416 bool IsIPv6Supported(); 1417 void SetSockTos(SOCK *s, int tos); 1418 void SetSockHighPriority(SOCK *s, bool flag); 1419 void InitIpClientList(); 1420 void FreeIpClientList(); 1421 int CompareIpClientList(void *p1, void *p2); 1422 void AddIpClient(IP *ip); 1423 void DelIpClient(IP *ip); 1424 IP_CLIENT *SearchIpClient(IP *ip); 1425 UINT GetNumIpClient(IP *ip); 1426 void SetLinuxArpFilter(); 1427 LIST *GetTcpTableList(); 1428 void FreeTcpTableList(LIST *o); 1429 int CompareTcpTable(void *p1, void *p2); 1430 void PrintTcpTableList(LIST *o); 1431 TCPTABLE *GetTcpTableFromEndPoint(LIST *o, IP *local_ip, UINT local_port, IP *remote_ip, UINT remote_port); 1432 UINT GetTcpProcessIdFromSocket(SOCK *s); 1433 UINT GetTcpProcessIdFromSocketReverse(SOCK *s); 1434 bool CanGetTcpProcessId(); 1435 int connect_timeout(SOCKET s, struct sockaddr *addr, int size, int timeout, bool *cancel_flag); 1436 void EnableNetworkNameCache(); 1437 void DisableNetworkNameCache(); 1438 bool IsNetworkNameCacheEnabled(); 1439 ROUTE_CHANGE *NewRouteChange(); 1440 void FreeRouteChange(ROUTE_CHANGE *r); 1441 bool IsRouteChanged(ROUTE_CHANGE *r); 1442 void RouteToStr(char *str, UINT str_size, ROUTE_ENTRY *e); 1443 void DebugPrintRoute(ROUTE_ENTRY *e); 1444 void DebugPrintRouteTable(ROUTE_TABLE *r); 1445 bool IsIPv6LocalNetworkAddress(IP *ip); 1446 UINT GetNumWaitThread(); 1447 void AddProtocolDetailsStr(char *dst, UINT dst_size, char *str); 1448 void AddProtocolDetailsKeyValueStr(char *dst, UINT dst_size, char *key, char *value); 1449 void AddProtocolDetailsKeyValueInt(char *dst, UINT dst_size, char *key, UINT value); 1450 void TryGetCurrentAcceptingIPv4Address(IP *ip); 1451 1452 #ifdef ENABLE_SSL_LOGGING 1453 void SockEnableSslLogging(SOCK *s); 1454 void SockWriteSslLog(SOCK *s, void *send_data, UINT send_size, void *recv_data, UINT recv_size); 1455 void SockCloseSslLogging(SOCK *s); 1456 #endif // ENABLE_SSL_LOGGING 1457 1458 void SocketTimeoutThread(THREAD *t, void *param); 1459 SOCKET_TIMEOUT_PARAM *NewSocketTimeout(SOCK *sock); 1460 void FreeSocketTimeout(SOCKET_TIMEOUT_PARAM *ttp); 1461 1462 void CopyIP(IP *dst, IP *src); 1463 bool CheckSubnetLength6(UINT i); 1464 bool IsIP6(IP *ip); 1465 bool IsIP4(IP *ip); 1466 bool IsSameIPVer(IP *ip1, IP *ip2); 1467 void IPv6AddrToIP(IP *ip, IPV6_ADDR *addr); 1468 bool IPToIPv6Addr(IPV6_ADDR *addr, IP *ip); 1469 void SetIP6(IP *ip, UCHAR *value); 1470 void GetLocalHostIP6(IP *ip); 1471 void GetLocalHostIP4(IP *ip); 1472 bool IsLocalHostIP6(IP *ip); 1473 bool IsLocalHostIP4(IP *ip); 1474 bool IsLocalHostIP(IP *ip); 1475 void ZeroIP6(IP *ip); 1476 void ZeroIP4(IP *ip); 1477 bool CheckIPItemStr6(char *str); 1478 void IPItemStrToChars6(UCHAR *chars, char *str); 1479 bool StrToIP6(IP *ip, char *str); 1480 bool StrToIP6Addr(IPV6_ADDR *ip, char *str); 1481 void IPToStr6(char *str, UINT size, IP *ip); 1482 void IP6AddrToStr(char *str, UINT size, IPV6_ADDR *addr); 1483 void IPToStr6Array(char *str, UINT size, UCHAR *bytes); 1484 void IPToStr6Inner(char *str, IP *ip); 1485 void IntToSubnetMask6(IP *ip, UINT i); 1486 void IPNot6(IP *dst, IP *a); 1487 void IPOr6(IP *dst, IP *a, IP *b); 1488 void IPAnd6(IP *dst, IP *a, IP *b); 1489 void GetAllRouterMulticastAddress6(IP *ip); 1490 void GetAllNodeMulticaseAddress6(IP *ip); 1491 void GetLoopbackAddress6(IP *ip); 1492 void GetAllFilledAddress6(IP *ip); 1493 UINT GetIPAddrType6(IP *ip); 1494 UINT GetIPv6AddrType(IPV6_ADDR *addr); 1495 void GenerateMulticastMacAddress6(UCHAR *mac, IP *ip); 1496 void GetSoliciationMulticastAddr6(IP *dst, IP *src); 1497 bool CheckUnicastAddress(IP *ip); 1498 bool IsNetworkPrefixAddress6(IP *ip, IP *subnet); 1499 bool IsNetworkAddress6(IP *ip, IP *subnet); 1500 void GetHostAddress6(IP *dst, IP *ip, IP *subnet); 1501 void GetPrefixAddress6(IP *dst, IP *ip, IP *subnet); 1502 bool IsNetworkPrefixAddress6(IP *ip, IP *subnet); 1503 bool IsInSameNetwork6(IP *a1, IP *a2, IP *subnet); 1504 bool IsInSameNetwork6ByStr(char *ip1, char *ip2, char *subnet); 1505 void GenerateEui64Address6(UCHAR *dst, UCHAR *mac); 1506 void GenerateEui64LocalAddress(IP *a, UCHAR *mac); 1507 void GenerateEui64GlobalAddress(IP *ip, IP *prefix, IP *subnet, UCHAR *mac); 1508 bool IsSubnetMask6(IP *a); 1509 UINT SubnetMaskToInt(IP *a); 1510 UINT SubnetMaskToInt6(IP *a); 1511 UINT SubnetMaskToInt4(IP *a); 1512 bool IsStrIPv6Address(char *str); 1513 void IPNot4(IP *dst, IP *a); 1514 void IPOr4(IP *dst, IP *a, IP *b); 1515 void IPAnd4(IP *dst, IP *a, IP *b); 1516 bool IsInSameNetwork4(IP *a1, IP *a2, IP *subnet); 1517 bool IsInSameNetwork4Standard(IP *a1, IP *a2); 1518 bool IsInSameLocalNetworkToMe4(IP *a); 1519 1520 bool ParseIpAndSubnetMask4(char *src, UINT *ip, UINT *mask); 1521 bool ParseIpAndSubnetMask6(char *src, IP *ip, IP *mask); 1522 bool ParseIpAndSubnetMask46(char *src, IP *ip, IP *mask); 1523 bool ParseIpAndMask4(char *src, UINT *ip, UINT *mask); 1524 bool ParseIpAndMask6(char *src, IP *ip, IP *mask); 1525 bool ParseIpAndMask46(char *src, IP *ip, IP *mask); 1526 bool IsIpStr4(char *str); 1527 bool IsIpStr6(char *str); 1528 bool IsIpMask6(char *str); 1529 bool IsIpStr46(char *str); 1530 bool StrToMask4(IP *mask, char *str); 1531 bool StrToMask6(IP *mask, char *str); 1532 bool StrToMask6Addr(IPV6_ADDR *mask, char *str); 1533 bool StrToMask46(IP *mask, char *str, bool ipv6); 1534 void MaskToStr(char *str, UINT size, IP *mask); 1535 void Mask6AddrToStrEx(char *str, UINT size, IPV6_ADDR *mask, bool always_full_address); 1536 void Mask6AddrToStr(char *str, UINT size, IPV6_ADDR *mask); 1537 void MaskToStr32(char *str, UINT size, UINT mask); 1538 void MaskToStr32Ex(char *str, UINT size, UINT mask, bool always_full_address); 1539 void MaskToStrEx(char *str, UINT size, IP *mask, bool always_full_address); 1540 1541 TUBEDATA *NewTubeData(void *data, UINT size, void *header, UINT header_size); 1542 void FreeTubeData(TUBEDATA *d); 1543 TUBE *NewTube(UINT size_of_header); 1544 void ReleaseTube(TUBE *t); 1545 void CleanupTube(TUBE *t); 1546 bool TubeSend(TUBE *t, void *data, UINT size, void *header); 1547 bool TubeSendEx(TUBE *t, void *data, UINT size, void *header, bool no_flush); 1548 bool TubeSendEx2(TUBE *t, void *data, UINT size, void *header, bool no_flush, UINT max_num_in_queue); 1549 void TubeFlush(TUBE *t); 1550 void TubeFlushEx(TUBE *t, bool force); 1551 TUBEDATA *TubeRecvAsync(TUBE *t); 1552 TUBEDATA *TubeRecvSync(TUBE *t, UINT timeout); 1553 TUBEPAIR_DATA *NewTubePairData(); 1554 void ReleaseTubePairData(TUBEPAIR_DATA *d); 1555 void CleanupTubePairData(TUBEPAIR_DATA *d); 1556 void NewTubePair(TUBE **t1, TUBE **t2, UINT size_of_header); 1557 void TubeDisconnect(TUBE *t); 1558 bool IsTubeConnected(TUBE *t); 1559 void SetTubeSockEvent(TUBE *t, SOCK_EVENT *e); 1560 SOCK_EVENT *GetTubeSockEvent(TUBE *t); 1561 1562 TUBE_FLUSH_LIST *NewTubeFlushList(); 1563 void FreeTubeFlushList(TUBE_FLUSH_LIST *f); 1564 void AddTubeToFlushList(TUBE_FLUSH_LIST *f, TUBE *t); 1565 void FlushTubeFlushList(TUBE_FLUSH_LIST *f); 1566 1567 LIST *GetHostIPAddressListInternal(); 1568 LIST *GetHostIPAddressList(); 1569 LIST *CloneIPAddressList(LIST *o); 1570 bool IsMyIPAddress(IP *ip); 1571 void FreeHostIPAddressList(LIST *o); 1572 void AddHostIPAddressToList(LIST *o, IP *ip); 1573 int CmpIpAddressList(void *p1, void *p2); 1574 UINT64 GetHostIPAddressListHash(); 1575 1576 UDPLISTENER *NewUdpListener(UDPLISTENER_RECV_PROC *recv_proc, void *param); 1577 void UdpListenerThread(THREAD *thread, void *param); 1578 void UdpListenerGetPublicPortList(UDPLISTENER *u, char *dst, UINT size); 1579 void FreeUdpListener(UDPLISTENER *u); 1580 void AddPortToUdpListener(UDPLISTENER *u, UINT port); 1581 void DeletePortFromUdpListener(UDPLISTENER *u, UINT port); 1582 void DeleteAllPortFromUdpListener(UDPLISTENER *u); 1583 UINT GetUdpListenerPortList(UDPLISTENER *u, UINT **port_list); 1584 void UdpListenerSendPackets(UDPLISTENER *u, LIST *packet_list); 1585 void UdpListenerSendPacket(UDPLISTENER *u, UDPPACKET *packet); 1586 UDPPACKET *NewUdpPacket(IP *src_ip, UINT src_port, IP *dst_ip, UINT dst_port, void *data, UINT size); 1587 void FreeUdpPacket(UDPPACKET *p); 1588 UDPLISTENER_SOCK *DetermineUdpSocketForSending(UDPLISTENER *u, UDPPACKET *p); 1589 bool IsUdpPortOpened(UDPLISTENER *u, IP *server_ip, UINT port); 1590 1591 INTERRUPT_MANAGER *NewInterruptManager(); 1592 void FreeInterruptManager(INTERRUPT_MANAGER *m); 1593 void AddInterrupt(INTERRUPT_MANAGER *m, UINT64 tick); 1594 UINT GetNextIntervalForInterrupt(INTERRUPT_MANAGER *m); 1595 1596 void NewSocketPair(SOCK **client, SOCK **server, IP *client_ip, UINT client_port, IP *server_ip, UINT server_port); 1597 SOCK *NewInProcSocket(TUBE *tube_send, TUBE *tube_recv); 1598 SOCK *ListenInProc(); 1599 SOCK *AcceptInProc(SOCK *s); 1600 SOCK *ConnectInProc(SOCK *listen_sock, IP *client_ip, UINT client_port, IP *server_ip, UINT server_port); 1601 UINT SendInProc(SOCK *sock, void *data, UINT size); 1602 UINT RecvInProc(SOCK *sock, void *data, UINT size); 1603 void WaitForTubes(TUBE **tubes, UINT num, UINT timeout); 1604 1605 SOCK *ListenReverse(); 1606 SOCK *AcceptReverse(SOCK *s); 1607 void InjectNewReverseSocketToAccept(SOCK *listen_sock, SOCK *s, IP *client_ip, UINT client_port); 1608 1609 bool NewTcpPair(SOCK **s1, SOCK **s2); 1610 SOCK *ListenAnyPortEx(bool local_only); 1611 SOCK *ListenAnyPortEx2(bool local_only, bool disable_ca); 1612 1613 bool IsIcmpApiSupported(); 1614 ICMP_RESULT *IcmpApiEchoSend(IP *dest_ip, UCHAR ttl, UCHAR *data, UINT size, UINT timeout); 1615 void IcmpApiFreeResult(ICMP_RESULT *ret); 1616 1617 #ifdef OS_WIN32 1618 void Win32WaitForTubes(TUBE **tubes, UINT num, UINT timeout); 1619 #else // OS_WIN32 1620 void UnixWaitForTubes(TUBE **tubes, UINT num, UINT timeout); 1621 #endif // OS_WIN32 1622 1623 #define PREVERIFY_ERR_MESSAGE_SIZE 100 1624 // Info on client certificate collected during TLS handshake 1625 struct SslClientCertInfo { 1626 int PreverifyErr; 1627 char PreverifyErrMessage[PREVERIFY_ERR_MESSAGE_SIZE]; 1628 X *X; 1629 }; 1630 1631 SSL_PIPE *NewSslPipe(bool server_mode, X *x, K *k, DH_CTX *dh); 1632 SSL_PIPE *NewSslPipeEx(bool server_mode, X *x, K *k, DH_CTX *dh, bool verify_peer, struct SslClientCertInfo *clientcert); 1633 void FreeSslPipe(SSL_PIPE *s); 1634 bool SyncSslPipe(SSL_PIPE *s); 1635 1636 SSL_BIO *NewSslBioMem(); 1637 SSL_BIO *NewSslBioSsl(); 1638 void FreeSslBio(SSL_BIO *b); 1639 bool SslBioSync(SSL_BIO *b, bool sync_send, bool sync_recv); 1640 1641 void SetCurrentGlobalIP(IP *ip, bool ipv6); 1642 bool GetCurrentGlobalIP(IP *ip, bool ipv6); 1643 void GetCurrentGlobalIPGuess(IP *ip, bool ipv6); 1644 bool IsIPAddressInSameLocalNetwork(IP *a); 1645 1646 bool IsIPPrivate(IP *ip); 1647 bool IsIPLocalOrPrivate(IP *ip); 1648 bool IsIPMyHost(IP *ip); 1649 void LoadPrivateIPFile(); 1650 bool IsOnPrivateIPFile(UINT ip); 1651 void FreePrivateIPFile(); 1652 1653 LIST *GetNicList(); 1654 void FreeNicList(LIST *o); 1655 bool IsMacAddressLocal(void *addr); 1656 bool IsMacAddressLocalInner(LIST *o, void *addr); 1657 bool IsMacAddressLocalFast(void *addr); 1658 void RefreshLocalMacAddressList(); 1659 1660 struct ssl_ctx_st *NewSSLCtx(bool server_mode); 1661 void FreeSSLCtx(struct ssl_ctx_st *ctx); 1662 1663 void SetCurrentDDnsFqdn(char *name); 1664 void GetCurrentDDnsFqdn(char *name, UINT size); 1665 UINT GetCurrentDDnsFqdnHash(); 1666 1667 void GetSimpleHostname(char *hostname, UINT hostname_size, char *fqdn); 1668 1669 void DisableRDUPServerGlobally(); 1670 void DisableRUDPRegisterGlobally(); 1671 void SetNatTLowPriority(); 1672 1673 void QueryIpThreadMain(THREAD *thread, void *param); 1674 QUERYIPTHREAD *NewQueryIpThread(char *hostname, UINT interval_last_ok, UINT interval_last_ng); 1675 bool GetQueryIpThreadResult(QUERYIPTHREAD *t, IP *ip); 1676 void FreeQueryIpThread(QUERYIPTHREAD *t); 1677 1678 void SetGetIpThreadMaxNum(UINT num); 1679 UINT GetGetIpThreadMaxNum(); 1680 UINT GetCurrentGetIpThreadNum(); 1681 1682 1683 1684 bool IsIpInStrList(IP *ip, char *ip_list); 1685 bool IsInStrByStrList(char *str, char *str_list); 1686 1687 #ifdef OS_WIN32 1688 LIST *Win32GetNicList(); 1689 #endif // OS_WIN32 1690 1691 1692 void InitDynList(); 1693 void FreeDynList(); 1694 void AddDynList(BUF *b); 1695 void ExtractAndApplyDynList(PACK *p); 1696 void SetDynListValue(char *name, UINT64 value); 1697 UINT64 GetDynValue(char *name); 1698 UINT64 GetDynValueOrDefault(char *name, UINT64 default_value, UINT64 min_value, UINT64 max_value); 1699 UINT64 GetDynValueOrDefaultSafe(char *name, UINT64 default_value); 1700 1701 1702 #endif // NETWORK_H 1703 1704