1 /* Copyright 2008-2019 Bernhard R. Fischer, Daniel Haslinger. 2 * 3 * This file is part of OnionCat. 4 * 5 * OnionCat is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, version 3 of the License. 8 * 9 * OnionCat is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with OnionCat. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 /*! \file ocat.h 19 * This file is the central header file of OnionCat. It includes all other 20 * headers and contains all macros, structures, typedefs,... 21 * \author Bernhard R. Fischer 22 * \date 2019/09/08 23 */ 24 25 #ifndef OCAT_H 26 #define OCAT_H 27 28 #ifdef HAVE_CONFIG_H 29 #include "config.h" 30 #endif 31 32 #include <stdio.h> 33 #include <stdlib.h> 34 #include <stdarg.h> 35 #include <stddef.h> 36 #include <stdint.h> 37 #include <string.h> 38 #include <unistd.h> 39 #include <fcntl.h> 40 #include <pwd.h> 41 #include <errno.h> 42 #include <time.h> 43 #include <pthread.h> 44 #include <signal.h> 45 #include <ctype.h> 46 #include <syslog.h> 47 48 49 #include <sys/time.h> 50 #include <sys/select.h> 51 #include <sys/ioctl.h> 52 #include <sys/stat.h> 53 54 #ifdef HAVE_SYS_TYPES_H 55 #include <sys/types.h> 56 #endif 57 #ifdef HAVE_SYS_SOCKET_H 58 #include <sys/socket.h> 59 #endif 60 #ifdef HAVE_ENDIAN_H 61 #include <endian.h> 62 #elif HAVE_SYS_ENDIAN_H 63 #include <sys/endian.h> 64 #endif 65 #ifdef HAVE_SYS_WAIT_H 66 #include <sys/wait.h> 67 #endif 68 #ifdef HAVE_SYS_ETHERNET_H 69 #include <sys/ethernet.h> 70 #endif 71 #ifdef HAVE_NETINET_IN_H 72 #include <netinet/in.h> 73 #endif 74 #ifdef HAVE_NETINET_IN_SYSTM_H 75 #include <netinet/in_systm.h> 76 #endif 77 #ifdef HAVE_NET_IF_H 78 #include <net/if.h> 79 #endif 80 #ifdef HAVE_NETINET6_IN6_VAR_H 81 #include <netinet6/in6_var.h> 82 #endif 83 #ifdef HAVE_NETINET6_ND6_H 84 #include <netinet6/nd6.h> 85 #endif 86 #include <arpa/inet.h> 87 #ifdef HAVE_NET_IF_H 88 #include <net/if.h> 89 #endif 90 #ifdef HAVE_NETINET_IP_H 91 #include <netinet/ip.h> 92 #endif 93 #ifdef HAVE_NETINET_ICMP6_H 94 #include <netinet/icmp6.h> 95 #endif 96 #ifdef HAVE_NETINET_ETHER_H 97 #include <netinet/ether.h> 98 #endif 99 #ifdef HAVE_NETINET_IF_ETHER_H 100 #include <netinet/if_ether.h> 101 #endif 102 #ifdef HAVE_NETINET_IP6_H 103 #include <netinet/ip6.h> 104 #endif 105 #ifdef HAVE_NETINET_UDP_H 106 #include <netinet/udp.h> 107 #endif 108 #ifdef HAVE_ARPA_NAMESER_H 109 #include <arpa/nameser.h> 110 #endif 111 #ifdef HAVE_NET_ETHERNET_H 112 #include <net/ethernet.h> 113 #endif 114 #ifdef HAVE_LINUX_SOCKIOS_H 115 #include <linux/sockios.h> 116 #endif 117 #ifdef HAVE_LINUX_IF_TUN_H 118 #include <linux/if_tun.h> 119 #endif 120 #ifdef HAVE_LINUX_IPV6_H 121 #include <linux/ipv6.h> 122 #endif 123 #ifdef HAVE_NET_IF_TUN_H 124 #include <net/if_tun.h> 125 #endif 126 #ifdef HAVE_NET_TUN_IF_TUN_H 127 #include <net/tun/if_tun.h> 128 #endif 129 130 #ifdef __CYGWIN__ 131 #include "cygwin/ocat_cygwin.h" 132 #endif 133 134 #ifndef ETHERTYPE_IP 135 //! Ether type for IPv4. 136 #define ETHERTYPE_IP 0x0800 137 #endif 138 #ifndef ETHERTYPE_IPV6 139 //! Ether type for IPv6. 140 #define ETHERTYPE_IPV6 0x86dd 141 #endif 142 143 #ifndef ETHER_ADDR_LEN 144 #ifdef ETHERADDRL 145 #define ETHER_ADDR_LEN ETHERADDRL 146 #endif 147 #endif 148 149 // At least on Solaris the Ethernet addresses are defined as struct containing 150 // an array of bytes. This is different from most other OSes which define the 151 // addresses directly as array. 152 #ifdef HAVE_ETHER_ADDR_OCTET 153 #define ether_dst ether_dhost.ether_addr_octet 154 #define ether_src ether_shost.ether_addr_octet 155 #else 156 #define ether_dst ether_dhost 157 #define ether_src ether_shost 158 #endif 159 160 #define IP6HLEN sizeof(struct ip6_hdr) 161 //! Length of an .onion-URL (without ".onion" and '\0') 162 #define ONION_URL_LEN 16 163 164 //! Maximum number of peers allowed. 165 #define MAXPEERS 1024 166 #ifdef __OpenBSD__ 167 #define OCAT_UNAME "_tor" 168 #elif __FreeBSD__ 169 #define OCAT_UNAME "_tor" 170 #else 171 #define OCAT_UNAME "tor" 172 #endif 173 //! Uid of unprivileged user. 174 #define OCAT_UNPRIV_UID 65534 175 //! Name of unprivileged user (if system offers no name). 176 #define OCAT_UNPRIV_UNAME "(unknown)" 177 //! Project URL of OnionCat. 178 #define OCAT_URL "https://www.onioncat.org/" 179 //! Path to OnionCat logging directory (see option -a). 180 #define OCAT_DIR ".ocat" 181 //#define OCAT_CONNECT_LOG "connect_log" 182 //! Default path to PID file (option -P). 183 #define PID_FILE "/var/run/ocat.pid" 184 //! Name of the author of OnionCat. 185 #define OCAT_AUTHOR "Bernhard R. Fischer" 186 187 //! Maximum frame (packet) size, should be able to keep one maximum size ipv6-packet: 2^16 + 40 + 4 188 #define FRAME_SIZE 65580 189 190 //! Standard buffer size 1024 bytes 191 #define SIZE_1K 1024 192 //! Standard buffer size 256 bytes 193 #define SIZE_256 256 194 195 #define DEQUEUER_WAKEUP 3 196 //! maximum number a packet stays in queue 197 #define MAX_QUEUE_DELAY 10 198 199 //! Maximum idle time for a peer, after that time the peer is closed. 200 #define MAX_IDLE_TIME 180 201 //! \# of secs after a cleaner wakeup occurs 202 #define CLEANER_WAKEUP 10 203 //! \# of secs after stats output is generated 204 #define STAT_WAKEUP 600 205 //! keepalive time 206 #define KEEPALIVE_TIME 60 207 //! select timeout (to avoid endless blocking) 208 #define SELECT_TIMEOUT 10 209 210 #define LOG_FCONN 0x400 211 #define LOG_FERR 0x800 212 213 #define E_SOCKS_SOCK -1 214 #define E_SOCKS_CONN -2 215 #define E_SOCKS_REQ -3 216 #define E_SOCKS_RQFAIL -4 217 #define E_SOCKS_TERMREQ -5 218 219 #define E_FWD_NOPEER -1 220 #define E_FWD_NOBUF -2 221 222 //#define PEER_CONNECT 0 223 #define PEER_ACTIVE 1 224 #define PEER_DELETE 2 225 226 //! Outgoing peer => connect(). 227 #define PEER_INCOMING 0 228 //! Incoming peer => accept(). 229 #define PEER_OUTGOING 1 230 231 //! Maximum length of thread names. 232 #define THREAD_NAME_LEN 11 233 //! thread stack size (default stack size on OpenBSD is too small) 234 #define THREAD_STACK_SIZE 262144 235 236 //! Connection type SOCKS4A (option -5). 237 #define CONNTYPE_SOCKS4A 0 238 //! Connection type SOCKS5 (option -5). 239 #define CONNTYPE_SOCKS5 1 240 //! Connection type direct, i.e. no SOCKS (option -5). 241 #define CONNTYPE_DIRECT 2 242 243 //! SOCKS state machine: new connection 244 #define SOCKS_NEW 0 245 //! SOCKS state machine: connect() in progress 246 #define SOCKS_CONNECTING 1 247 //! SOCKS state machine: SOCKS4A request sent 248 #define SOCKS_4AREQ_SENT 2 249 //! SOCKS state machine: this state is NOT used! 250 #define SOCKS_4ARESPONSE 3 251 //! SOCKS state machine: SOCKS5 greeting sent 252 #define SOCKS_5GREET_SENT 4 253 //! SOCKS state machine: SOCK5 request sent 254 #define SOCKS_5REQ_SENT 5 255 //! SOCKS state machine: successfully opened, ready for data transfer 256 #define SOCKS_READY 126 257 //! SOCKS state machine: request ready for deletion 258 #define SOCKS_DELETE 127 259 260 //! maximum number of SOCKS retries before becoming deleted 261 #define SOCKS_MAX_RETRY 3 262 263 #define E_RT_NOMEM -1 264 #define E_RT_DUP -2 265 #define E_RT_ILLNM -3 266 #define E_RT_SYNTAX -4 267 #define E_RT_NULLPTR -5 268 #define E_RT_NOTORGW -6 269 #define E_RT_GWSELF -7 270 271 #define E_ETH_TRUNC -8 272 #define E_ETH_ILLDEST -9 273 #define E_ETH_ILLPROTO -10 274 #define E_ETH_INTERCEPT -11 275 276 //! maximum number of MAC address entries in table 277 #define MAX_MAC_ENTRY 128 278 //! maximum age of MAC address in table 279 #define MAX_MAC_AGE 120 280 /* 281 //! maximum number of IPv6 routes 282 #define MAX_IPV6_ROUTE 1024 283 */ 284 //! retry-delay if connection to TOR's SOCKS port fails 285 #define TOR_SOCKS_CONN_TIMEOUT 30 286 //! number of attempts for MIN_RECONNECT_TIME is measured 287 #define RECONN_ATTEMPTS 3 288 //! RECONN_ATTEMPTS must not be faster than MIN_RECONNECT_TIME 289 #define MIN_RECONNECT_TIME 30 290 //! define default maximum number of concurrent controller sessions 291 #define MAX_DEF_CTRL_SESS 5 292 293 #define MFD_SET(f,s,m) {FD_SET(f, s); m = f > m ? f : m;} 294 295 //! copy an IPv6 address from b to a 296 //#define IN6_ADDR_COPY(a,b) *((struct in6_addr*)a)=*(struct in6_addr*)b 297 #define IN6_ADDR_COPY(a,b) memcpy(a, b, sizeof(struct in6_addr)) 298 299 //! Index to OcatSetup.fhd_key for IPv4. 300 #define IPV4_KEY 0 301 //! Index to OcatSetup.fhd_key for IPv6. 302 #define IPV6_KEY 1 303 //! Macro to return size of anonymous sockaddr structure (only AF_INET and AF_INET6). 304 #define SOCKADDR_SIZE(x) (((struct sockaddr*) x)->sa_family == AF_INET ? sizeof(struct sockaddr_in) : ((struct sockaddr*) x)->sa_family == AF_INET6 ? sizeof(struct sockaddr_in6) : 0) 305 306 #define VERSION_STRING_LEN 256 307 308 #define MAX_DEF_CTRL 6 309 310 #define NTYPE_TOR 0 311 #define NTYPE_I2P 1 312 313 #ifndef SYSCONFDIR 314 #define SYSCONFDIR "/etc" 315 #endif 316 317 // this macro returns a constains string if a buffer points to NULL. 318 #define SSTR(x) (x != NULL ? x : "(nil)") 319 320 // Solaris and the Windows OpenVPN tunnel driver do not send a 4 byte tunnel 321 // header thus we adjust reads and writes. 322 #if defined(__sun__) || defined(__CYGWIN__) 323 #define BUF_OFF 4 324 #else 325 #define BUF_OFF 0 326 #endif 327 328 329 //! General configuration data 330 /*! OcatSetup is used as a global structure holding general configuration 331 * parameters for OnionCat. 332 */ 333 struct OcatSetup 334 { 335 //! frame header of local OS in network byte order 336 /*! for IPV4 (IPV4_KEY => 0) and IPv6 (IPV6_KEY => 1), it is initialized in ocattun.c */ 337 uint32_t fhd_key[2]; 338 //! size of the frame header, actually this is sizeof(uint32_t) which is 4 339 int fhd_key_len; 340 //! virtual port of OnionCat hidden service 341 uint16_t ocat_dest_port; 342 //! local port of controller interface 343 uint16_t ocat_ctrl_port; 344 //! file descriptors of TUN device (usually tunfd[0] == tunfd[1]) 345 int tunfd[2]; 346 //! configure IP addresses on startup 347 int ipconfig; 348 //! debug level 349 int debug_level; 350 //! user name to change uid to 351 char *usrname; 352 //! onion URL which corresponds to the IPv6 address 353 char onion_url[SIZE_256]; 354 //! long hs v3 onion name 355 char onion3_url[SIZE_256]; 356 //! IPv6 address of OnionCat 357 struct in6_addr ocat_addr; 358 //! flag to create connection log 359 int create_clog; 360 //! flag to not change uid to unprivileged user 361 int runasroot; 362 //! controller interface enabled/disabled (option -C) 363 int controller; 364 //! directory where OnionCat puts the connect log 365 char *ocat_dir; 366 //! name of tunnel charcter device FIXME: seems to be unnused, uses tun_dev_ instead -> needs fix 367 char *tun_dev; 368 //! Connection type (SOCKS4a, 5, or direct). 369 /*! use SOCKS5 (CONNTYPE_SOCKS5 => 1) or direct connects (CONNTYPE_DIRECT => 370 * 2) instead of SOCKS4A (CONNTYPE_SOCKS4A => 0), option -5 */ 371 int socks5; 372 //! length of long HS names 373 int l_hs_namelen; 374 //! tunnel interface name 375 char tunname[SIZE_256]; 376 //! transport of IPv4 enabled (option -4) 377 int ipv4_enable; 378 //! IPv4 address of OnionCat 379 struct in_addr ocat_addr4; 380 //! IPv4 netmask 381 union 382 { 383 //! netmask as int type 384 int ocat_addr4_mask; 385 //! netmask is struct in_addr type 386 struct in_addr ocat_addr4_netmask; 387 }; 388 char *config_file; 389 int config_read; 390 int config_failed; 391 char *ifup; //!< path to ifup scripts 392 int use_tap; 393 //! local OnionCat MAC address 394 uint8_t ocat_hwaddr[ETHER_ADDR_LEN]; 395 char *pid_file; 396 int create_pid_file; 397 char *logfn; 398 FILE *logf; 399 int use_syslog; 400 int daemon; 401 time_t uptime; 402 char *frandn; 403 //! destination socket address of Tor's SOCKS port 404 union 405 { 406 struct sockaddr_in *socks_dst; 407 struct sockaddr_in6 *socks_dst6; 408 }; 409 //! local listening socket address for incoming connections 410 struct sockaddr **oc_listen; 411 int *oc_listen_fd; 412 int oc_listen_cnt; 413 int rand_addr; 414 char version[VERSION_STRING_LEN]; 415 int sizeof_setup; 416 int sig_term, term_req; 417 pthread_mutex_t mutex; 418 //! listening sockets for controller interface 419 struct sockaddr **ctrl_listen; 420 int *ctrl_listen_fd; 421 int ctrl_listen_cnt; 422 //! communication pipe for socks "selected" connector 423 int socksfd[2]; 424 int net_type; 425 int max_ctrl, ctrl_active; 426 //! pipe filedescriptors for pid deletion process 427 int pid_fd[2]; 428 int sig_usr1, clear_stats; 429 /*! Define if OC connection should be used uni- or bidirectional. 430 Bidirectional has a faster setup time but unidirectional is more safe in 431 respect to security because both ends are verfied. */ 432 int unidirectional; 433 int hosts_lookup; 434 char *hosts_path; //!< path to hosts file, defaults to system hosts file if NULL 435 const char *domain; //!< domain name appended to network host name 436 struct in6_addr oc_vdns; 437 }; 438 439 #ifdef PACKET_QUEUE 440 typedef struct PacketQueue 441 { 442 struct PacketQueue *next; 443 struct in6_addr addr; 444 int psize; 445 time_t time; 446 void *data; 447 } PacketQueue_t; 448 #endif 449 450 //! This structure holds the SOCKS4A header. 451 typedef struct SocksHdr 452 { 453 char ver; 454 char cmd; 455 uint16_t port; 456 struct in_addr addr; 457 } __attribute__((packed)) SocksHdr_t; 458 459 //! Structure to hold the SOCKS5 header. 460 typedef struct Socks5Hdr 461 { 462 char ver; 463 char cmd; 464 char rsv; 465 char atyp; 466 char addr; 467 } __attribute__((packed)) Socks5Hdr_t; 468 469 //! This structure holds all data associated with a peer (a remote OnionCat). 470 typedef struct OcatPeer 471 { 472 struct OcatPeer *next; //!< pointer to next peer in list 473 struct in6_addr addr; //!< remote address of peer 474 int tcpfd; //!< remote file descriptor 475 time_t time; //!< timestamp of latest packet 476 time_t sdelay; //!< connection setup delay 477 time_t otime; //!< opening time 478 int state; //!< status of peer 479 int dir; //!< direction this session was opened 480 unsigned long out; //!< bytes output 481 unsigned long in; //!< bytes input 482 uint32_t *tunhdr; //!< pointer to local tun frame header 483 char *fragbuf; //!< pointer to (de)frag buffer 484 char _fragbuf[FRAME_SIZE]; //!< (de)frag buffer 485 int fraglen; //!< current frag buffer size 486 pthread_mutex_t mutex; //!< mutex for thread locking 487 int perm; //!< keep peer permanently open 488 time_t last_io; //!< timestamp when last I/O packet measurement started 489 unsigned inm; 490 unsigned outm; 491 int rand; //!< random peer number 492 } OcatPeer_t; 493 494 //! OcatThread is a control structure to manage each thread of OnionCat. 495 typedef struct OcatThread 496 { 497 struct OcatThread *next; 498 pthread_t handle; 499 pthread_attr_t attr; 500 int detached; 501 int id; 502 char name[THREAD_NAME_LEN]; 503 void *(*entry)(void*); 504 void *parm; 505 int ready; //!< thread is ready, i.e. every initialization is done 506 } OcatThread_t; 507 508 //! Data structure for SOCKS connections in progress. 509 /*! This structure holds all data associate with SOCKS connections which are 510 * currently in opening state, i.e. not connected but trying to connect. 511 */ 512 typedef struct SocksQueue 513 { 514 struct SocksQueue *next; 515 struct in6_addr addr; 516 int state; 517 int perm; 518 int fd; 519 time_t restart_time; 520 time_t connect_time; 521 int retry; 522 } SocksQueue_t; 523 524 //! IPv4 routing table entry 525 typedef struct IPv4Route 526 { 527 struct IPv4Route *next[2]; //!< pointer to next routes in binary tree 528 uint32_t dest; 529 uint32_t netmask; 530 struct in6_addr gw; 531 } IPv4Route_t; 532 533 //! IPv6 routing table entry 534 typedef struct IPv6Route 535 { 536 struct in6_addr dest; 537 int prefixlen; 538 struct in6_addr gw; 539 } IPv6Route_t; 540 541 //! IPv6 pseudo header used for checksum calculation 542 struct ip6_psh 543 { 544 struct in6_addr src; 545 struct in6_addr dst; 546 uint32_t len; 547 char _pad[3]; 548 uint8_t nxt; 549 } __attribute__((packed)); 550 551 //! MAC table entry for TAP mode. 552 typedef struct MACTable 553 { 554 uint16_t family; 555 union 556 { 557 struct in6_addr in6addr; 558 struct in_addr inaddr; 559 }; 560 uint8_t hwaddr[ETHER_ADDR_LEN]; 561 time_t age; 562 } MACTable_t; 563 564 //! NDP protocol header. 565 typedef struct ndp6 566 { 567 struct ether_header eth; 568 struct ip6_hdr ip6; 569 union 570 { 571 struct icmp6_hdr icmp6; 572 struct nd_neighbor_solicit ndp_sol; 573 struct nd_neighbor_advert ndp_adv; 574 }; 575 //struct nd_opt_hdr ndp_opt; 576 } __attribute__((packed)) ndp6_t; 577 578 //! Structure to hold socket address as a literal string. 579 struct sockaddr_str 580 { 581 sa_family_t sstr_family; 582 uint16_t sstr_port; 583 char sstr_addr[INET6_ADDRSTRLEN]; 584 }; 585 586 /* 587 // next header value for ocat internal use (RFC3692) 588 #define OCAT_NEXT_HEADER 254 589 590 typedef struct OcatHdr 591 { 592 uint16_t oh_plen; 593 uint8_t oh_nxt; 594 // struct ip6_hdrctl oh_ip6hdrctl; 595 // char oh_srcid[10]; 596 } OcatHdr_t; 597 598 599 #define OCAT_CTL_SRC 1 600 #define OCAT_CTL_EREQ 2 601 #define OCAT_CTL_ERES 3 602 603 typedef struct OcatCtrlHdr 604 { 605 uint8_t oct_type; 606 char oct_srcid[10]; 607 } OcatCtrlHdr_t; 608 */ 609 610 611 #ifndef WITHOUT_TUN 612 #ifdef __sun__ 613 #define TUN_DEV "/dev/tun" 614 #elif __ANDROID__ 615 #define TUN_DEV "/dev/tun" 616 #elif __linux__ 617 #define TUN_DEV "/dev/net/tun" 618 #else 619 #define TUN_DEV "/dev/tun0" 620 #endif 621 extern char *tun_dev_; 622 #else 623 #define TUN_DEV "STDIO" 624 #endif 625 626 /* ocat.c */ 627 628 629 /* ocatlog.c */ 630 int open_connect_log(const char*); 631 void log_msg(int, const char *, ...); 632 #ifdef DEBUG 633 #define log_debug(x...) log_msg(LOG_DEBUG, ## x) 634 #else 635 #define log_debug(x...) 636 #endif 637 638 /* ocatv6conv.c */ 639 char *ipv6tonion(const struct in6_addr *, char *); 640 int oniontipv6(const char *, struct in6_addr *); 641 int oniontipv4(const char *, struct in_addr *, int); 642 int has_tor_prefix(const struct in6_addr *); 643 void rand_onion(char *); 644 const char *inet_ntops(const struct sockaddr *, struct sockaddr_str *); 645 /* 646 #define IN6_HAS_TOR_PREFIX(a) ((((__const uint32_t *) (a))[0] == ((__const uint32_t*)(TOR_PREFIX))[0]) \ 647 && (((__const uint16_t*)(a))[2] == ((__const uint16_t*)(TOR_PREFIX))[2])) 648 */ 649 650 /* ocattun.c */ 651 #ifndef WITHOUT_TUN 652 int tun_alloc(char *, int, struct in6_addr); 653 #endif 654 655 /* ocatroute.c */ 656 extern int sockfd_[2]; 657 void init_peers(void); 658 void *socket_receiver(void *); 659 void packet_forwarder(void); 660 #ifdef PACKET_QUEUE 661 void *packet_dequeuer(void *); 662 #endif 663 void *socket_acceptor(void *); 664 void *socket_cleaner(void *); 665 void *ocat_controller(void *); 666 void *ctrl_handler(void *); 667 int insert_peer(int, const SocksQueue_t *, time_t); 668 int run_listeners(struct sockaddr **, int *, int, int (*)(int)); 669 int send_keepalive(OcatPeer_t *); 670 void set_select_timeout(struct timeval *); 671 void set_nonblock(int); 672 void set_tunheader(char *, uint32_t); 673 uint32_t get_tunheader(char *); 674 #ifdef WITH_LOOPBACK_RESPONDER 675 void *local_loopback_responder(void *); 676 void *remote_loopback_responder(void *); 677 int add_remote_loopback_route(void); 678 #endif 679 680 /* ocatthread.c */ 681 const OcatThread_t *init_ocat_thread(const char *); 682 int run_ocat_thread(const char *, void *(*)(void*), void*); 683 const OcatThread_t *get_thread(void); 684 int set_thread_name(const char *); 685 int join_threads(void); 686 void detach_thread(void); 687 void print_threads(FILE *); 688 int term_req(void); 689 void set_term_req(void); 690 int wait_thread_by_name_ready(const char *); 691 int set_thread_ready(void); 692 693 /* ocatcompat.c */ 694 #ifndef HAVE_STRLCAT 695 size_t strlcat(char*, const char*, size_t); 696 #endif 697 #ifndef HAVE_STRLCPY 698 size_t strlcpy(char*, const char*, size_t); 699 #endif 700 701 /* ocatpeer.c */ 702 OcatPeer_t *get_first_peer(void); 703 OcatPeer_t **get_first_peer_ptr(void); 704 int lock_peers(void); 705 int unlock_peers(void); 706 int lock_peer(OcatPeer_t *); 707 int unlock_peer(OcatPeer_t *); 708 OcatPeer_t *search_peer(const struct in6_addr *); 709 OcatPeer_t *get_empty_peer(void); 710 void delete_peer(OcatPeer_t *); 711 712 /* ocatsetup.c */ 713 #define CNF(x) setup_.x 714 extern struct OcatSetup setup_; 715 void print_setup_struct(FILE *); 716 void init_setup(void); 717 void post_init_setup(void); 718 void lock_setup(void); 719 void unlock_setup(void); 720 721 /* ocatipv4route.c */ 722 struct in6_addr *ipv4_lookup_route(uint32_t); 723 int parse_route(const char *); 724 void print_routes(FILE *); 725 726 /* ocateth.c */ 727 int eth_check(char *, int); 728 int mac_set(const struct in6_addr *, uint8_t *); 729 void print_mac_tbl(FILE *); 730 void mac_cleanup(void); 731 char *mac_hw2str(const uint8_t *, char *); 732 int ndp_solicit(const struct in6_addr *, const struct in6_addr *); 733 #ifndef HAVE_ETHER_NTOA_R 734 char *ether_ntoa_r(const struct ether_addr *, char *); 735 #endif 736 uint16_t checksum(const uint16_t *, int); 737 void free_ckbuf(uint16_t *); 738 uint16_t *malloc_ckbuf(struct in6_addr, struct in6_addr, uint16_t, uint8_t, const void *); 739 740 /* ocatsocks.c */ 741 void socks_queue(struct in6_addr, int); 742 void print_socks_queue(FILE *); 743 void sig_socks_connector(void); 744 void *socks_connector_sel(void *); 745 int test_socks_server(void); 746 int synchron_socks_connect(const struct in6_addr *); 747 748 /* ocatlibe.c */ 749 void oe_close(int); 750 int oe_remtr(char *); 751 int strsockaddr(const char *, struct sockaddr *); 752 void add_local_listeners(void); 753 void add_listener(const char *); 754 void delete_listeners(struct sockaddr **, int *, int); 755 int fdprintf(int, const char *, va_list); 756 757 /* ocatipv6route.c */ 758 struct in6_addr *ipv6_lookup_route(const struct in6_addr *); 759 void ipv6_print_routes(FILE *); 760 int ipv6_parse_route(const char *); 761 int ipv6_add_route(const IPv6Route_t *); 762 763 #ifdef __CYGWIN__ 764 /* ocat_wintuntap.c */ 765 int win_open_tun(char *, int); 766 int win_close_tun(void); 767 int win_read_tun(char *, int); 768 int win_write_tun(const char *, int); 769 #define tun_read(x,y,z) win_read_tun(y,z) 770 #define tun_write(x,y,z) win_write_tun(y,z) 771 #else 772 #define tun_read(x,y,z) read(x,y,z) 773 #define tun_write(x,y,z) write(x,y,z) 774 #endif 775 776 /* ocatresolv.c */ 777 int check_dns(const struct ip6_hdr *, int); 778 779 #endif 780 781