• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /netgear-R7000-V1.0.7.12_1.2.5/ap/gpl/openvpn-2.3.1/src/openvpn/

Lines Matching refs:tt

72 static void solaris_error_close (struct tuntap *tt, const struct env_set *es, const char *actual, bool unplumb_inet6);
307 ifconfig_options_string (const struct tuntap* tt, bool remote, bool disable, struct gc_arena *gc)
310 if (tt->did_ifconfig_setup && !disable)
312 if (tt->type == DEV_TYPE_TAP || (tt->type == DEV_TYPE_TUN && tt->topology == TOP_SUBNET))
315 print_in_addr_t (tt->local & tt->remote_netmask, 0, gc),
316 print_in_addr_t (tt->remote_netmask, 0, gc));
318 else if (tt->type == DEV_TYPE_TUN)
323 r = print_in_addr_t (tt->local, 0, gc);
324 l = print_in_addr_t (tt->remote_netmask, 0, gc);
328 l = print_in_addr_t (tt->local, 0, gc);
329 r = print_in_addr_t (tt->remote_netmask, 0, gc);
343 tun_stat (const struct tuntap *tt, unsigned int rwflags, struct gc_arena *gc)
346 if (tt)
351 (tt->rwflags_debug & EVENT_READ) ? "R" : "r");
354 overlapped_io_state_ascii (&tt->reads));
360 (tt->rwflags_debug & EVENT_WRITE) ? "W" : "w");
363 overlapped_io_state_ascii (&tt->writes));
378 is_tun_p2p (const struct tuntap *tt)
382 if (tt->type == DEV_TYPE_TAP || (tt->type == DEV_TYPE_TUN && tt->topology == TOP_SUBNET))
384 else if (tt->type == DEV_TYPE_TUN)
413 struct tuntap *tt;
415 ALLOC_OBJ (tt, struct tuntap);
416 clear_tuntap (tt);
418 tt->type = dev_type_enum (dev, dev_type);
419 tt->topology = topology;
431 tun = is_tun_p2p (tt);
437 tt->local = getaddr (
447 tt->remote_netmask = getaddr (
462 ifconfig_sanity_check (tt->type == DEV_TYPE_TUN, tt->remote_netmask, tt->topology);
470 tt->type,
472 tt->local,
473 tt->remote_netmask);
476 tt->type,
478 tt->local,
479 tt->remote_netmask);
481 if (tt->type == DEV_TYPE_TAP || (tt->type == DEV_TYPE_TUN && tt->topology == TOP_SUBNET))
482 check_subnet_conflict (tt->local, tt->remote_netmask, "TUN/TAP adapter");
483 else if (tt->type == DEV_TYPE_TUN)
484 check_subnet_conflict (tt->local, IPV4_NETMASK_HOST, "TUN/TAP adapter");
490 ifconfig_local = print_in_addr_t (tt->local, 0, &gc);
491 ifconfig_remote_netmask = print_in_addr_t (tt->remote_netmask, 0, &gc);
498 tt->broadcast = generate_ifconfig_broadcast_addr (tt->local, tt->remote_netmask);
499 ifconfig_broadcast = print_in_addr_t (tt->broadcast, 0, &gc);
519 tt->did_ifconfig_setup = true;
531 if ( inet_pton( AF_INET6, ifconfig_ipv6_local_parm, &tt->local_ipv6 ) != 1 ||
532 inet_pton( AF_INET6, ifconfig_ipv6_remote_parm, &tt->remote_ipv6 ) != 1 )
536 tt->netbits_ipv6 = ifconfig_ipv6_netbits_parm;
541 ifconfig_ipv6_local = print_in6_addr (tt->local_ipv6, 0, &gc);
542 ifconfig_ipv6_remote = print_in6_addr (tt->remote_ipv6, 0, &gc);
550 setenv_int (es, "ifconfig_ipv6_netbits", tt->netbits_ipv6);
553 tt->did_ifconfig_ipv6_setup = true;
557 return tt;
564 init_tun_post (struct tuntap *tt,
568 tt->options = *options;
570 overlapped_io_init (&tt->reads, frame, FALSE, true);
571 overlapped_io_init (&tt->writes, frame, TRUE, true);
572 tt->rw_handle.read = tt->reads.overlapped.hEvent;
573 tt->rw_handle.write = tt->writes.overlapped.hEvent;
574 tt->adapter_index = TUN_ADAPTER_INDEX_INVALID;
586 void add_route_connected_v6_net(struct tuntap * tt,
592 r6.network = tt->local_ipv6;
593 r6.netbits = tt->netbits_ipv6;
594 r6.gateway = tt->local_ipv6;
597 add_route_ipv6 (&r6, tt, 0, es);
600 void delete_route_connected_v6_net(struct tuntap * tt,
606 r6.network = tt->local_ipv6;
607 r6.netbits = tt->netbits_ipv6;
608 r6.gateway = tt->local_ipv6;
611 delete_route_ipv6 (&r6, tt, 0, es);
618 do_ifconfig (struct tuntap *tt,
625 if (tt->did_ifconfig_setup)
638 msg( M_INFO, "do_ifconfig, tt->ipv6=%d, tt->did_ifconfig_ipv6_setup=%d",
639 tt->ipv6, tt->did_ifconfig_ipv6_setup );
644 tun = is_tun_p2p (tt);
649 ifconfig_local = print_in_addr_t (tt->local, 0, &gc);
650 ifconfig_remote_netmask = print_in_addr_t (tt->remote_netmask, 0, &gc);
652 if ( tt->ipv6 && tt->did_ifconfig_ipv6_setup )
654 ifconfig_ipv6_local = print_in6_addr (tt->local_ipv6, 0, &gc);
655 ifconfig_ipv6_remote = print_in6_addr (tt->remote_ipv6, 0, &gc);
663 ifconfig_broadcast = print_in_addr_t (tt->broadcast, 0, &gc);
671 tt->local,
723 tt->netbits_ipv6,
729 tt->did_ifconfig = true;
759 tt->netbits_ipv6
764 tt->did_ifconfig = true;
787 solaris_error_close (tt, es, actual, false);
796 if (tt->topology == TOP_SUBNET)
819 solaris_error_close (tt, es, actual, false);
828 if ( tt->type == DEV_TYPE_TUN )
835 tt->netbits_ipv6,
847 solaris_error_close (tt, es, actual, true);
860 ifconfig_ipv6_local, tt->netbits_ipv6 );
864 solaris_error_close (tt, es, actual, true);
867 if (!tun && tt->topology == TOP_SUBNET)
873 r.network = tt->local & tt->remote_netmask;
874 r.netmask = tt->remote_netmask;
875 r.gateway = tt->local;
877 add_route (&r, tt, 0, NULL, es);
880 tt->did_ifconfig = true;
901 if ( tt->topology == TOP_SUBNET )
932 tt->netbits_ipv6
938 add_route_connected_v6_net(tt, es);
940 tt->did_ifconfig = true;
961 if ( tt->topology == TOP_SUBNET )
999 tt->netbits_ipv6
1005 add_route_connected_v6_net(tt, es);
1008 tt->ipv6 = false;
1011 tt->did_ifconfig = true;
1039 if (tt->topology == TOP_SUBNET)
1062 tt->did_ifconfig = true;
1065 if (!tun && tt->topology == TOP_SUBNET)
1070 r.network = tt->local & tt->remote_netmask;
1071 r.netmask = tt->remote_netmask;
1072 r.gateway = tt->local;
1073 add_route (&r, tt, 0, NULL, es);
1083 tt->netbits_ipv6
1089 add_route_connected_v6_net(tt, es);
1104 else if ( tt->topology == TOP_SUBNET )
1128 tt->did_ifconfig = true;
1131 if (!tun && tt->topology == TOP_SUBNET)
1136 r.network = tt->local & tt->remote_netmask;
1137 r.netmask = tt->remote_netmask;
1138 r.gateway = tt->local;
1139 add_route (&r, tt, 0, NULL, es);
1149 tt->netbits_ipv6
1163 verify_255_255_255_252 (tt->local, tt->remote_netmask);
1164 tt->adapter_netmask = ~3;
1168 tt->adapter_netmask = tt->remote_netmask;
1171 switch (tt->options.ip_win32_type)
1177 print_in_addr_t (tt->adapter_netmask, 0, &gc));
1183 netsh_ifconfig (&tt->options,
1185 tt->local,
1186 tt->adapter_netmask,
1191 tt->did_ifconfig = true;
1214 * tt->actual_name might not yet be initialized, but routing code
1217 saved_actual = tt->actual_name;
1218 tt->actual_name = (char*) actual;
1219 add_route_connected_v6_net(tt, es);
1220 tt->actual_name = saved_actual;
1246 open_null (struct tuntap *tt)
1248 tt->actual_name = string_alloc ("null", NULL);
1255 struct tuntap *tt)
1262 if ( tt->ipv6 && ! ipv6_explicitly_supported )
1265 if (tt->type == DEV_TYPE_NULL)
1267 open_null (tt);
1293 if ((tt->fd = open ( "/dev/tap", O_RDWR)) < 0)
1297 if ( ioctl( tt->fd, TAPGIFNAME, (void*)&ifr ) < 0 )
1318 if ((tt->fd = open (tunname, O_RDWR)) > 0)
1343 tt->persistent_if = true;
1346 if ((tt->fd = open (tunname, O_RDWR)) < 0)
1350 set_nonblock (tt->fd);
1351 set_cloexec (tt->fd); /* don't pass fd to scripts */
1354 /* tt->actual_name is passed to up and down scripts and used as the ifconfig dev name */
1355 tt->actual_name = string_alloc (dynamic_opened ? dynamic_name : dev, NULL);
1360 close_tun_generic (struct tuntap *tt)
1362 if (tt->fd >= 0)
1363 close (tt->fd);
1364 if (tt->actual_name)
1365 free (tt->actual_name);
1366 clear_tuntap (tt);
1382 open_tun (const char *dev, const char *dev_type, const char *dev_node, struct tuntap *tt)
1389 if (tt->type == DEV_TYPE_NULL)
1391 open_null (tt);
1405 if ((tt->fd = open (node, O_RDWR)) < 0)
1414 if (!tt->ipv6)
1424 if (tt->type == DEV_TYPE_TUN)
1428 else if (tt->type == DEV_TYPE_TAP)
1448 if (ioctl (tt->fd, TUNSETIFF, (void *) &ifr) < 0)
1459 if (tt->options.txqueuelen) {
1467 netifr.ifr_qlen = tt->options.txqueuelen;
1469 msg (D_OSBUF, "TUN/TAP TX queue length set to %d", tt->options.txqueuelen);
1481 set_nonblock (tt->fd);
1482 set_cloexec (tt->fd);
1483 tt->actual_name = string_alloc (ifr.ifr_name, NULL);
1491 open_tun (const char *dev, const char *dev_type, const char *dev_node, struct tuntap *tt)
1501 open_tun (const char *dev, const char *dev_type, const char *dev_node, struct tuntap *tt)
1503 open_tun_generic (dev, dev_type, dev_node, false, true, tt);
1525 struct tuntap *tt;
1527 ALLOC_OBJ (tt, struct tuntap);
1528 clear_tuntap (tt);
1529 tt->type = dev_type_enum (dev, dev_type);
1530 tt->options = *options;
1531 open_tun (dev, dev_type, dev_node, tt);
1532 if (ioctl (tt->fd, TUNSETPERSIST, persist_mode) < 0)
1541 if (ioctl (tt->fd, TUNSETOWNER, platform_state_user.pw->pw_uid) < 0)
1551 if (ioctl (tt->fd, TUNSETGROUP, platform_state_group.gr->gr_gid) < 0)
1554 close_tun (tt);
1561 close_tun (struct tuntap *tt)
1563 if (tt)
1565 if (tt->type != DEV_TYPE_NULL && tt->did_ifconfig)
1572 if (is_tun_p2p (tt))
1577 tt->actual_name,
1578 print_in_addr_t (tt->local, 0, &gc),
1579 print_in_addr_t (tt->remote_netmask, 0, &gc)
1587 tt->actual_name,
1588 print_in_addr_t (tt->local, 0, &gc),
1589 count_netmask_bits(print_in_addr_t (tt->remote_netmask, 0, &gc))
1596 tt->actual_name
1606 close_tun_generic (tt);
1607 free (tt);
1612 write_tun (struct tuntap* tt, uint8_t *buf, int len)
1614 if (tt->ipv6)
1635 ret = writev(tt->fd, vect, 2);
1639 return write (tt->fd, buf, len);
1643 read_tun (struct tuntap* tt, uint8_t *buf, int len)
1645 if (tt->ipv6)
1656 ret = readv(tt->fd, vect, 2);
1660 return read (tt->fd, buf, len);
1670 open_tun (const char *dev, const char *dev_type, const char *dev_node, struct tuntap *tt)
1687 if (tt->type == DEV_TYPE_NULL)
1689 open_null (tt);
1693 if (tt->type == DEV_TYPE_TUN)
1702 else if (tt->type == DEV_TYPE_TAP)
1718 if ((tt->ip_fd = open (ip_node, O_RDWR, 0)) < 0)
1721 if ((tt->fd = open (dev_node, O_RDWR, 0)) < 0)
1744 int new_ppa = ioctl (tt->fd, I_STR, &strioc_ppa);
1761 if ((ppa = ioctl (tt->fd, I_STR, &strioc_ppa)) < 0)
1771 if (tt->type == DEV_TYPE_TUN)
1778 tt->actual_name = (char *) malloc (32);
1779 check_malloc_return (tt->actual_name);
1781 openvpn_snprintf (tt->actual_name, 32, "%s%d", dev_tuntap_type, ppa);
1783 if (tt->type == DEV_TYPE_TAP)
1787 strncpynt (ifr.lifr_name, tt->actual_name, sizeof (ifr.lifr_name));
1801 if (ioctl (tt->ip_fd, I_POP, NULL) < 0)
1805 if (ioctl (tt->ip_fd, I_PUSH, "arp") < 0)
1825 if ((ip_muxid = ioctl (tt->ip_fd, link_type, if_fd)) < 0)
1828 if (tt->type == DEV_TYPE_TAP) {
1829 if ((arp_muxid = ioctl (tt->ip_fd, link_type, arp_fd)) < 0)
1835 strncpynt (ifr.lifr_name, tt->actual_name, sizeof (ifr.lifr_name));
1837 if (tt->type == DEV_TYPE_TAP) {
1841 if (ioctl (tt->ip_fd, SIOCSLIFMUXID, &ifr) < 0)
1843 if (tt->type == DEV_TYPE_TAP)
1845 ioctl (tt->ip_fd, I_PUNLINK , arp_muxid);
1847 ioctl (tt->ip_fd, I_PUNLINK, ip_muxid);
1851 set_nonblock (tt->fd);
1852 set_cloexec (tt->fd);
1853 set_cloexec (tt->ip_fd);
1855 msg (M_INFO, "TUN/TAP device %s opened", tt->actual_name);
1859 solaris_close_tun (struct tuntap *tt)
1861 if (tt)
1864 if ( tt->ipv6 && tt->did_ifconfig_ipv6_setup )
1869 IFCONFIG_PATH, tt->actual_name );
1875 if (tt->ip_fd >= 0)
1879 strncpynt (ifr.lifr_name, tt->actual_name, sizeof (ifr.lifr_name));
1881 if (ioctl (tt->ip_fd, SIOCGLIFFLAGS, &ifr) < 0)
1884 if (ioctl (tt->ip_fd, SIOCGLIFMUXID, &ifr) < 0)
1887 if (tt->type == DEV_TYPE_TAP)
1889 if (ioctl (tt->ip_fd, I_PUNLINK, ifr.lifr_arp_muxid) < 0)
1893 if (ioctl (tt->ip_fd, I_PUNLINK, ifr.lifr_ip_muxid) < 0)
1896 close (tt->ip_fd);
1897 tt->ip_fd = -1;
1900 if (tt->fd >= 0)
1902 close (tt->fd);
1903 tt->fd = -1;
1912 close_tun (struct tuntap *tt)
1914 if (tt)
1916 solaris_close_tun (tt);
1918 if (tt->actual_name)
1919 free (tt->actual_name);
1921 clear_tuntap (tt);
1922 free (tt);
1927 solaris_error_close (struct tuntap *tt, const struct env_set *es,
1948 close_tun (tt);
1954 write_tun (struct tuntap* tt, uint8_t *buf, int len)
1959 return putmsg (tt->fd, NULL, &sbuf, 0) >= 0 ? sbuf.len : -1;
1963 read_tun (struct tuntap* tt, uint8_t *buf, int len)
1970 return getmsg (tt->fd, NULL, &sbuf, &f) >= 0 ? sbuf.len : -1;
1993 open_tun (const char *dev, const char *dev_type, const char *dev_node, struct tuntap *tt)
1995 open_tun_generic (dev, dev_type, dev_node, true, true, tt);
1998 if (tt->fd >= 0)
2002 if (ioctl (tt->fd, TUNGIFINFO, &info) < 0) {
2011 if (ioctl (tt->fd, TUNSIFINFO, &info) < 0) {
2028 close_tun (struct tuntap* tt)
2032 if (tt && (tt->type == DEV_TYPE_TUN || tt->persistent_if ) )
2034 close_tun_generic (tt);
2035 free(tt);
2037 else if (tt)
2042 /* setup command, close tun dev (clears tt->actual_name!), run command
2047 IFCONFIG_PATH, tt->actual_name);
2049 close_tun_generic (tt);
2054 free (tt);
2068 write_tun (struct tuntap* tt, uint8_t *buf, int len)
2070 if (tt->type == DEV_TYPE_TUN)
2078 if (tt->ipv6 && iph->ip_v == 6)
2088 return openbsd_modify_read_write_return (writev (tt->fd, iv, 2));
2091 return write (tt->fd, buf, len);
2095 read_tun (struct tuntap* tt, uint8_t *buf, int len)
2097 if (tt->type == DEV_TYPE_TUN)
2107 return openbsd_modify_read_write_return (readv (tt->fd, iv, 2));
2110 return read (tt->fd, buf, len);
2130 open_tun (const char *dev, const char *dev_type, const char *dev_node, struct tuntap *tt)
2133 open_tun_generic (dev, dev_type, dev_node, true, true, tt);
2135 open_tun_generic (dev, dev_type, dev_node, false, true, tt);
2138 if (tt->fd >= 0)
2141 ioctl (tt->fd, TUNSIFMODE, &i); /* multicast on */
2143 ioctl (tt->fd, TUNSLMODE, &i); /* link layer mode off */
2146 if ( tt->type == DEV_TYPE_TUN )
2149 if (ioctl (tt->fd, TUNSIFHEAD, &i) < 0) /* multi-af mode on */
2163 close_tun (struct tuntap *tt)
2167 if (tt && ( tt->type != DEV_TYPE_TUN || tt->persistent_if ) )
2169 close_tun_generic (tt);
2170 free(tt);
2172 else if (tt)
2177 /* setup command, close tun dev (clears tt->actual_name!), run command
2182 IFCONFIG_PATH, tt->actual_name);
2184 close_tun_generic (tt);
2189 free (tt);
2205 write_tun (struct tuntap* tt, uint8_t *buf, int len)
2207 if (tt->type == DEV_TYPE_TUN)
2215 if (tt->ipv6 && OPENVPN_IPH_GET_VER(iph->version_len) == 6)
2225 return netbsd_modify_read_write_return (writev (tt->fd, iv, 2));
2228 return write (tt->fd, buf, len);
2232 read_tun (struct tuntap* tt, uint8_t *buf, int len)
2234 if (tt->type == DEV_TYPE_TUN)
2244 return netbsd_modify_read_write_return (readv (tt->fd, iv, 2));
2247 return read (tt->fd, buf, len);
2253 write_tun (struct tuntap* tt, uint8_t *buf, int len)
2255 return write (tt->fd, buf, len);
2259 read_tun (struct tuntap* tt, uint8_t *buf, int len)
2261 return read (tt->fd, buf, len);
2277 open_tun (const char *dev, const char *dev_type, const char *dev_node, struct tuntap *tt)
2279 open_tun_generic (dev, dev_type, dev_node, true, true, tt);
2281 if (tt->fd >= 0 && tt->type == DEV_TYPE_TUN)
2285 if (ioctl (tt->fd, TUNSIFMODE, &i) < 0) {
2289 if (ioctl (tt->fd, TUNSIFHEAD, &i) < 0) {
2303 close_tun (struct tuntap *tt)
2305 if (tt && tt->persistent_if ) /* keep pre-existing if around */
2307 close_tun_generic (tt);
2308 free (tt);
2310 else if (tt) /* close and destroy */
2315 /* setup command, close tun dev (clears tt->actual_name!), run command
2320 IFCONFIG_PATH, tt->actual_name);
2322 close_tun_generic (tt);
2327 free (tt);
2332 write_tun (struct tuntap* tt, uint8_t *buf, int len)
2334 if (tt->type == DEV_TYPE_TUN)
2342 if (tt->ipv6 && iph->ip_v == 6)
2352 return freebsd_modify_read_write_return (writev (tt->fd, iv, 2));
2355 return write (tt->fd, buf, len);
2359 read_tun (struct tuntap* tt, uint8_t *buf, int len)
2361 if (tt->type == DEV_TYPE_TUN)
2371 return freebsd_modify_read_write_return (readv (tt->fd, iv, 2));
2374 return read (tt->fd, buf, len);
2389 open_tun (const char *dev, const char *dev_type, const char *dev_node, struct tuntap *tt)
2391 open_tun_generic (dev, dev_type, dev_node, true, true, tt);
2393 if (tt->fd >= 0)
2398 ioctl (tt->fd, TUNSLMODE, &i);
2400 ioctl (tt->fd, TUNSIFHEAD, &i);
2405 close_tun (struct tuntap *tt)
2407 if (tt)
2409 close_tun_generic (tt);
2410 free (tt);
2415 write_tun (struct tuntap* tt, uint8_t *buf, int len)
2417 if (tt->type == DEV_TYPE_TUN)
2425 if (tt->ipv6 && iph->ip_v == 6)
2435 return dragonfly_modify_read_write_return (writev (tt->fd, iv, 2));
2438 return write (tt->fd, buf, len);
2442 read_tun (struct tuntap* tt, uint8_t *buf, int len)
2444 if (tt->type == DEV_TYPE_TUN)
2454 return dragonfly_modify_read_write_return (readv (tt->fd, iv, 2));
2457 return read (tt->fd, buf, len);
2471 open_tun (const char *dev, const char *dev_type, const char *dev_node, struct tuntap *tt)
2473 open_tun_generic (dev, dev_type, dev_node, true, true, tt);
2477 close_tun (struct tuntap* tt)
2479 if (tt)
2485 if ( tt->ipv6 && tt->did_ifconfig_ipv6_setup )
2488 print_in6_addr (tt->local_ipv6, 0, &gc);
2496 close_tun_generic (tt);
2497 free (tt);
2504 write_tun (struct tuntap* tt, uint8_t *buf, int len)
2506 return write (tt->fd, buf, len);
2510 read_tun (struct tuntap* tt, uint8_t *buf, int len)
2512 return read (tt->fd, buf, len);
2518 tun_read_queue (struct tuntap *tt, int maxsize)
2520 if (tt->reads.iostate == IOSTATE_INITIAL)
2527 tt->reads.buf = tt->reads.buf_init;
2529 len = maxsize ? maxsize : BLEN (&tt->reads.buf);
2530 ASSERT (len <= BLEN (&tt->reads.buf));
2533 ASSERT (ResetEvent (tt->reads.overlapped.hEvent));
2536 tt->hand,
2537 BPTR (&tt->reads.buf),
2539 &tt->reads.size,
2540 &tt->reads.overlapped
2546 ASSERT (SetEvent (tt->reads.overlapped.hEvent));
2548 tt->reads.iostate = IOSTATE_IMMEDIATE_RETURN;
2549 tt->reads.status = 0;
2553 (int) tt->reads.size);
2560 tt->reads.iostate = IOSTATE_QUEUED;
2561 tt->reads.status = err;
2568 ASSERT (SetEvent (tt->reads.overlapped.hEvent));
2569 tt->reads.iostate = IOSTATE_IMMEDIATE_RETURN;
2570 tt->reads.status = err;
2578 return tt->reads.iostate;
2582 tun_write_queue (struct tuntap *tt, struct buffer *buf)
2584 if (tt->writes.iostate == IOSTATE_INITIAL)
2590 tt->writes.buf = tt->writes.buf_init;
2591 tt->writes.buf.len = 0;
2592 ASSERT (buf_copy (&tt->writes.buf, buf));
2595 ASSERT (ResetEvent (tt->writes.overlapped.hEvent));
2598 tt->hand,
2599 BPTR (&tt->writes.buf),
2600 BLEN (&tt->writes.buf),
2601 &tt->writes.size,
2602 &tt->writes.overlapped
2607 tt->writes.iostate = IOSTATE_IMMEDIATE_RETURN;
2610 ASSERT (SetEvent (tt->writes.overlapped.hEvent));
2612 tt->writes.status = 0;
2615 BLEN (&tt->writes.buf),
2616 (int) tt->writes.size);
2623 tt->writes.iostate = IOSTATE_QUEUED;
2624 tt->writes.status = err;
2626 BLEN (&tt->writes.buf));
2631 ASSERT (SetEvent (tt->writes.overlapped.hEvent));
2632 tt->writes.iostate = IOSTATE_IMMEDIATE_RETURN;
2633 tt->writes.status = err;
2635 BLEN (&tt->writes.buf),
2641 return tt->writes.iostate;
3437 get_tun_adapter (const struct tuntap *tt, const IP_ADAPTER_INFO *list)
3439 if (list && tt)
3440 return get_adapter (list, tt->adapter_index);
3446 is_adapter_up (const struct tuntap *tt, const IP_ADAPTER_INFO *list)
3451 const IP_ADAPTER_INFO *ai = get_tun_adapter (tt, list);
3463 if (tt->local && tt->adapter_netmask)
3466 if (tt->local == ip && tt->adapter_netmask == netmask)
3934 dhcp_release (const struct tuntap *tt)
3936 if (tt && tt->options.ip_win32_type == IPW32_SET_DHCP_MASQ && tt->adapter_index != TUN_ADAPTER_INDEX_INVALID)
3937 return dhcp_release_by_adapter_index (tt->adapter_index);
3967 dhcp_renew (const struct tuntap *tt)
3969 if (tt && tt->options.ip_win32_type == IPW32_SET_DHCP_MASQ && tt->adapter_index != TUN_ADAPTER_INDEX_INVALID)
3970 return dhcp_renew_by_adapter_index (tt->adapter_index);
4329 tun_standby_init (struct tuntap *tt)
4331 tt->standby_iter = 0;
4335 tun_standby (struct tuntap *tt)
4338 ++tt->standby_iter;
4339 if (tt->options.ip_win32_type == IPW32_SET_ADAPTIVE)
4341 if (tt->standby_iter == IPW32_SET_ADAPTIVE_TRY_NETSH)
4344 netsh_ifconfig (&tt->options,
4345 tt->actual_name,
4346 tt->local,
4347 tt->adapter_netmask,
4350 else if (tt->standby_iter >= IPW32_SET_ADAPTIVE_TRY_NETSH*2)
4463 fork_dhcp_action (struct tuntap *tt)
4465 if (tt->options.dhcp_pre_release || tt->options.dhcp_renew)
4473 if (tt->options.dhcp_pre_release)
4475 if (tt->options.dhcp_renew)
4477 buf_printf (&cmd, " --dhcp-internal %u", (unsigned int)tt->adapter_index);
4485 fork_register_dns_action (struct tuntap *tt)
4487 if (tt && tt->options.register_dns)
4521 open_tun (const char *dev, const char *dev_type, const char *dev_node, struct tuntap *tt)
4532 msg( M_INFO, "open_tun, tt->ipv6=%d", tt->ipv6 );
4534 if (tt->type == DEV_TYPE_NULL)
4536 open_null (tt);
4540 else if (tt->type == DEV_TYPE_TAP || tt->type == DEV_TYPE_TUN)
4573 tt->hand = CreateFile (
4583 if (tt->hand == INVALID_HANDLE_VALUE)
4609 tt->hand = CreateFile (
4619 if (tt->hand == INVALID_HANDLE_VALUE)
4630 tt->actual_name = string_alloc (actual_buffer, NULL);
4633 msg (M_INFO, "TAP-WIN32 device [%s] opened: %s", tt->actual_name, device_path);
4634 tt->adapter_index = get_adapter_index (device_guid);
4640 if (DeviceIoControl (tt->hand, TAP_WIN_IOCTL_GET_VERSION,
4658 if ( tt->ipv6 && tt->type == DEV_TYPE_TUN &&
4662 tt->ipv6 = false;
4667 if ( tt->type == DEV_TYPE_TUN &&
4677 if (DeviceIoControl (tt->hand, TAP_WIN_IOCTL_GET_MTU,
4681 tt->post_open_mtu = (int) mtu;
4690 if (tt->did_ifconfig_setup)
4692 if (tt->options.ip_win32_type == IPW32_SET_DHCP_MASQ)
4697 if (dhcp_status (tt->adapter_index) == DHCP_STATUS_DISABLED)
4698 netsh_enable_dhcp (&tt->options, tt->actual_name);
4702 else if (tt->options.ip_win32_type == IPW32_SET_ADAPTIVE)
4707 if (dhcp_status (tt->adapter_index) != DHCP_STATUS_ENABLED)
4709 netsh_ifconfig (&tt->options,
4710 tt->actual_name,
4711 tt->local,
4712 tt->adapter_netmask,
4724 if (tt->type == DEV_TYPE_TUN)
4726 if (!tt->did_ifconfig_setup)
4731 if (tt->topology == TOP_SUBNET)
4736 ep[0] = htonl (tt->local);
4737 ep[1] = htonl (tt->local & tt->remote_netmask);
4738 ep[2] = htonl (tt->remote_netmask);
4740 status = DeviceIoControl (tt->hand, TAP_WIN_IOCTL_CONFIG_TUN,
4753 ep[0] = htonl (tt->local);
4754 ep[1] = htonl (tt->remote_netmask);
4756 if (!DeviceIoControl (tt->hand, TAP_WIN_IOCTL_CONFIG_POINT_TO_POINT,
4770 ep[0] = htonl (tt->local);
4771 ep[1] = htonl (tt->adapter_netmask);
4774 if (tt->type == DEV_TYPE_TUN)
4776 if (tt->topology == TOP_SUBNET)
4778 if (tt->options.dhcp_masq_custom_offset)
4779 ep[2] = dhcp_masq_addr (tt->local, tt->remote_netmask, tt->options.dhcp_masq_offset);
4781 ep[2] = dhcp_masq_addr (tt->local, tt->remote_netmask, -1);
4784 ep[2] = htonl (tt->remote_netmask);
4788 ASSERT (tt->type == DEV_TYPE_TAP);
4789 ep[2] = dhcp_masq_addr (tt->local, tt->adapter_netmask, tt->options.dhcp_masq_custom_offset ? tt->options.dhcp_masq_offset : 0);
4793 ep[3] = (uint32_t) tt->options.dhcp_lease_time;
4798 if (!DeviceIoControl (tt->hand, TAP_WIN_IOCTL_CONFIG_DHCP_MASQ,
4804 print_in_addr_t (tt->local, 0, &gc),
4805 print_in_addr_t (tt->adapter_netmask, 0, &gc),
4812 if (tt->options.dhcp_options)
4815 if (build_dhcp_options_string (&buf, &tt->options))
4818 if (!DeviceIoControl (tt->hand, TAP_WIN_IOCTL_CONFIG_DHCP_SET_OPT,
4833 if (!DeviceIoControl (tt->hand, TAP_WIN_IOCTL_SET_MEDIA_STATUS,
4841 int s = tt->options.tap_sleep;
4851 const DWORD index = tt->adapter_index;
4882 if (tt->options.dhcp_pre_release)
4883 dhcp_release (tt);
4884 if (tt->options.dhcp_renew)
4885 dhcp_renew (tt);
4888 fork_dhcp_action (tt);
4890 if (tt->did_ifconfig_setup && tt->options.ip_win32_type == IPW32_SET_IPAPI)
4912 if ((status = AddIPAddress (htonl(tt->local),
4913 htonl(tt->adapter_netmask),
4915 &tt->ipapi_context,
4916 &tt->ipapi_instance)) == NO_ERROR)
4918 print_in_addr_t (tt->local, 0, &gc),
4919 print_in_addr_t (tt->adapter_netmask, 0, &gc),
4924 print_in_addr_t (tt->local, 0, &gc),
4925 print_in_addr_t (tt->adapter_netmask, 0, &gc),
4931 tt->ipapi_context_defined = true;
4939 tap_win_getinfo (const struct tuntap *tt, struct gc_arena *gc)
4941 if (tt && tt->hand != NULL)
4945 if (DeviceIoControl (tt->hand, TAP_WIN_IOCTL_GET_INFO,
4957 tun_show_debug (struct tuntap *tt)
4959 if (tt && tt->hand != NULL)
4963 while (DeviceIoControl (tt->hand, TAP_WIN_IOCTL_GET_LOG_LINE,
4975 close_tun (struct tuntap *tt)
4979 if (tt)
4981 if ( tt->ipv6 && tt->did_ifconfig_ipv6_setup )
4988 delete_route_connected_v6_net(tt, NULL);
4991 ifconfig_ipv6_local = print_in6_addr (tt->local_ipv6, 0, &gc);
4996 tt->actual_name,
5003 if (tt->ipapi_context_defined)
5006 if ((status = DeleteIPAddress (tt->ipapi_context)) != NO_ERROR)
5009 (unsigned int)tt->ipapi_context,
5016 if (tt->options.dhcp_release)
5017 dhcp_release (tt);
5019 if (tt->hand != NULL)
5022 if (!CancelIo (tt->hand))
5027 overlapped_io_close (&tt->reads);
5030 overlapped_io_close (&tt->writes);
5032 if (tt->hand != NULL)
5035 if (!CloseHandle (tt->hand))
5039 if (tt->actual_name)
5040 free (tt->actual_name);
5042 clear_tuntap (tt);
5043 free (tt);
5105 open_tun (const char *dev, const char *dev_type, const char *dev_node, struct tuntap *tt)
5107 open_tun_generic (dev, dev_type, dev_node, false, true, tt);
5111 close_tun (struct tuntap* tt)
5113 if (tt)
5115 close_tun_generic (tt);
5116 free (tt);
5121 write_tun (struct tuntap* tt, uint8_t *buf, int len)
5123 return write (tt->fd, buf, len);
5127 read_tun (struct tuntap* tt, uint8_t *buf, int len)
5129 return read (tt->fd, buf, len);