Ticket #10: 0001-Integrate-support-for-TAP-mode-on-Solaris-written-by.patch
File 0001-Integrate-support-for-TAP-mode-on-Solaris-written-by.patch, 7.4 KB (added by , 14 years ago) |
---|
-
tun.c
From c1d75d70006dc2c1cac10249abf7e0cf3d90553a Mon Sep 17 00:00:00 2001 From: Gert Doering <gert@greenie.muc.de> Date: Fri, 29 Oct 2010 17:41:53 +0200 Subject: [PATCH 1/2] Integrate support for TAP mode on Solaris, written by Kazuyoshi Aizawa <admin2@whiteboard.ne.jp>. See also http://www.whiteboard.ne.jp/~admin2/tuntap/ Signed-off-by: Gert Doering <gert@greenie.muc.de> --- tun.c | 120 +++++++++++++++++++++++++++++++++++++++++++++++++++++------------ 1 files changed, 98 insertions(+), 22 deletions(-) diff --git a/tun.c b/tun.c index 10dde6b..f001a64 100644
a b static const char *netsh_get_id (const char *dev_node, struct gc_arena *gc); 63 63 64 64 #ifdef TARGET_SOLARIS 65 65 static void solaris_error_close (struct tuntap *tt, const struct env_set *es, const char *actual); 66 #include <stropts.h> 66 67 #endif 67 68 68 69 bool … … do_ifconfig (struct tuntap *tt, 701 702 ); 702 703 } 703 704 else 704 no_tap_ifconfig (); 705 argv_printf (&argv, 706 " %s %s %s netmask %s broadcast + up", 707 IFCONFIG_PATH, 708 actual, 709 ifconfig_local, 710 ifconfig_remote_netmask 711 ); 705 712 706 713 argv_msg (M_INFO, &argv); 707 714 if (!openvpn_execve_check (&argv, es, 0, "Solaris ifconfig phase-2 failed")) … … read_tun (struct tuntap* tt, uint8_t *buf, int len) 1372 1379 void 1373 1380 open_tun (const char *dev, const char *dev_type, const char *dev_node, bool ipv6, struct tuntap *tt) 1374 1381 { 1375 int if_fd, muxid, ppa = -1;1376 struct ifreq ifr;1382 int if_fd, ip_muxid, arp_muxid, arp_fd, ppa = -1; 1383 struct lifreq ifr; 1377 1384 const char *ptr; 1378 const char *ip_node ;1385 const char *ip_node, *arp_node; 1379 1386 const char *dev_tuntap_type; 1380 1387 int link_type; 1381 1388 bool is_tun; 1389 struct strioctl strioc_if, strioc_ppa; 1382 1390 1383 ipv6_support (ipv6, false, tt); 1391 ipv6_support (ipv6, true, tt); 1392 memset(&ifr, 0x0, sizeof(ifr)); 1384 1393 1385 1394 if (tt->type == DEV_TYPE_NULL) 1386 1395 { … … open_tun (const char *dev, const char *dev_type, const char *dev_node, bool ipv6 1399 1408 } 1400 1409 else if (tt->type == DEV_TYPE_TAP) 1401 1410 { 1402 ip_node = "/dev/ ip";1411 ip_node = "/dev/udp"; 1403 1412 if (!dev_node) 1404 1413 dev_node = "/dev/tap"; 1414 arp_node = dev_node; 1405 1415 dev_tuntap_type = "tap"; 1406 1416 link_type = I_PLINK; /* was: I_LINK */ 1407 1417 is_tun = false; … … open_tun (const char *dev, const char *dev_type, const char *dev_node, bool ipv6 1428 1438 msg (M_ERR, "Can't open %s", dev_node); 1429 1439 1430 1440 /* Assign a new PPA and get its unit number. */ 1431 if ((ppa = ioctl (tt->fd, TUNNEWPPA, ppa)) < 0) 1441 strioc_ppa.ic_cmd = TUNNEWPPA; 1442 strioc_ppa.ic_timout = 0; 1443 strioc_ppa.ic_len = sizeof(ppa); 1444 strioc_ppa.ic_dp = (char *)&ppa; 1445 if ((ppa = ioctl (tt->fd, I_STR, &strioc_ppa)) < 0) 1432 1446 msg (M_ERR, "Can't assign new interface"); 1433 1447 1434 1448 if ((if_fd = open (dev_node, O_RDWR, 0)) < 0) … … open_tun (const char *dev, const char *dev_type, const char *dev_node, bool ipv6 1437 1451 if (ioctl (if_fd, I_PUSH, "ip") < 0) 1438 1452 msg (M_ERR, "Can't push IP module"); 1439 1453 1454 if (tt->type == DEV_TYPE_TUN) 1455 { 1440 1456 /* Assign ppa according to the unit number returned by tun device */ 1441 1457 if (ioctl (if_fd, IF_UNITSEL, (char *) &ppa) < 0) 1442 1458 msg (M_ERR, "Can't set PPA %d", ppa); 1443 1444 if ((muxid = ioctl (tt->ip_fd, link_type, if_fd)) < 0) 1445 msg (M_ERR, "Can't link %s device to IP", dev_tuntap_type); 1446 1447 close (if_fd); 1459 } 1448 1460 1449 1461 tt->actual_name = (char *) malloc (32); 1450 1462 check_malloc_return (tt->actual_name); 1451 1463 1452 1464 openvpn_snprintf (tt->actual_name, 32, "%s%d", dev_tuntap_type, ppa); 1453 1465 1466 if (tt->type == DEV_TYPE_TAP) 1467 { 1468 if (ioctl(if_fd, SIOCGLIFFLAGS, &ifr) < 0) 1469 msg (M_ERR, "Can't get flags\n"); 1470 strncpynt (ifr.lifr_name, tt->actual_name, sizeof (ifr.lifr_name)); 1471 ifr.lifr_ppa = ppa; 1472 /* Assign ppa according to the unit number returned by tun device */ 1473 if (ioctl (if_fd, SIOCSLIFNAME, &ifr) < 0) 1474 msg (M_ERR, "Can't set PPA %d", ppa); 1475 if (ioctl(if_fd, SIOCGLIFFLAGS, &ifr) <0) 1476 msg (M_ERR, "Can't get flags\n"); 1477 /* Push arp module to if_fd */ 1478 if (ioctl (if_fd, I_PUSH, "arp") < 0) 1479 msg (M_ERR, "Can't push ARP module"); 1480 1481 /* Pop any modules on the stream */ 1482 while (true) 1483 { 1484 if (ioctl (tt->ip_fd, I_POP, NULL) < 0) 1485 break; 1486 } 1487 /* Push arp module to ip_fd */ 1488 if (ioctl (tt->ip_fd, I_PUSH, "arp") < 0) 1489 msg (M_ERR, "Can't push ARP module\n"); 1490 1491 /* Open arp_fd */ 1492 if ((arp_fd = open (arp_node, O_RDWR, 0)) < 0) 1493 msg (M_ERR, "Can't open %s\n", arp_node); 1494 /* Push arp module to arp_fd */ 1495 if (ioctl (arp_fd, I_PUSH, "arp") < 0) 1496 msg (M_ERR, "Can't push ARP module\n"); 1497 1498 /* Set ifname to arp */ 1499 strioc_if.ic_cmd = SIOCSLIFNAME; 1500 strioc_if.ic_timout = 0; 1501 strioc_if.ic_len = sizeof(ifr); 1502 strioc_if.ic_dp = (char *)𝔦 1503 if (ioctl(arp_fd, I_STR, &strioc_if) < 0){ 1504 msg (M_ERR, "Can't set ifname to arp\n"); 1505 } 1506 } 1507 1508 if ((ip_muxid = ioctl (tt->ip_fd, link_type, if_fd)) < 0) 1509 msg (M_ERR, "Can't link %s device to IP", dev_tuntap_type); 1510 1511 if (tt->type == DEV_TYPE_TAP) { 1512 if ((arp_muxid = ioctl (tt->ip_fd, link_type, arp_fd)) < 0) 1513 msg (M_ERR, "Can't link %s device to ARP", dev_tuntap_type); 1514 close (arp_fd); 1515 } 1516 1454 1517 CLEAR (ifr); 1455 strncpynt (ifr.ifr_name, tt->actual_name, sizeof (ifr.ifr_name)); 1456 ifr.ifr_ip_muxid = muxid; 1518 strncpynt (ifr.lifr_name, tt->actual_name, sizeof (ifr.lifr_name)); 1519 ifr.lifr_ip_muxid = ip_muxid; 1520 if (tt->type == DEV_TYPE_TAP) { 1521 ifr.lifr_arp_muxid = arp_muxid; 1522 } 1457 1523 1458 if (ioctl (tt->ip_fd, SIOCS IFMUXID, &ifr) < 0)1524 if (ioctl (tt->ip_fd, SIOCSLIFMUXID, &ifr) < 0) 1459 1525 { 1460 ioctl (tt->ip_fd, I_PUNLINK, muxid); 1526 if (tt->type == DEV_TYPE_TAP) 1527 { 1528 ioctl (tt->ip_fd, I_PUNLINK , arp_muxid); 1529 } 1530 ioctl (tt->ip_fd, I_PUNLINK, ip_muxid); 1461 1531 msg (M_ERR, "Can't set multiplexor id"); 1462 1532 } 1463 1533 … … solaris_close_tun (struct tuntap *tt) 1475 1545 { 1476 1546 if (tt->ip_fd >= 0) 1477 1547 { 1478 structifreq ifr;1548 struct lifreq ifr; 1479 1549 CLEAR (ifr); 1480 strncpynt (ifr.ifr_name, tt->actual_name, sizeof (ifr.ifr_name));1550 strncpynt (ifr.lifr_name, tt->actual_name, sizeof (ifr.lifr_name)); 1481 1551 1482 if (ioctl (tt->ip_fd, SIOCGIFFLAGS, &ifr) < 0)1552 if (ioctl (tt->ip_fd, SIOCGLIFFLAGS, &ifr) < 0) 1483 1553 msg (M_WARN | M_ERRNO, "Can't get iface flags"); 1484 1554 1485 if (ioctl (tt->ip_fd, SIOCGIFMUXID, &ifr) < 0)1555 if (ioctl (tt->ip_fd, SIOCGLIFMUXID, &ifr) < 0) 1486 1556 msg (M_WARN | M_ERRNO, "Can't get multiplexor id"); 1487 1557 1488 if (ioctl (tt->ip_fd, I_PUNLINK, ifr.ifr_ip_muxid) < 0) 1489 msg (M_WARN | M_ERRNO, "Can't unlink interface"); 1558 if (tt->type == DEV_TYPE_TAP) 1559 { 1560 if (ioctl (tt->ip_fd, I_PUNLINK, ifr.lifr_arp_muxid) < 0) 1561 msg (M_WARN | M_ERRNO, "Can't unlink interface(arp)"); 1562 } 1563 1564 if (ioctl (tt->ip_fd, I_PUNLINK, ifr.lifr_ip_muxid) < 0) 1565 msg (M_WARN | M_ERRNO, "Can't unlink interface(ip)"); 1490 1566 1491 1567 close (tt->ip_fd); 1492 1568 tt->ip_fd = -1;