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 Gert Döring, 11 years ago)

patch for TAP on solaris, adapted to 2.2-beta3

  • 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); 
    6363
    6464#ifdef TARGET_SOLARIS
    6565static void solaris_error_close (struct tuntap *tt, const struct env_set *es, const char *actual);
     66#include <stropts.h>
    6667#endif
    6768
    6869bool
    do_ifconfig (struct tuntap *tt, 
    701702                            );
    702703        }
    703704      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                            );
    705712
    706713      argv_msg (M_INFO, &argv);
    707714      if (!openvpn_execve_check (&argv, es, 0, "Solaris ifconfig phase-2 failed"))
    read_tun (struct tuntap* tt, uint8_t *buf, int len) 
    13721379void
    13731380open_tun (const char *dev, const char *dev_type, const char *dev_node, bool ipv6, struct tuntap *tt)
    13741381{
    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;
    13771384  const char *ptr;
    1378   const char *ip_node;
     1385  const char *ip_node, *arp_node;
    13791386  const char *dev_tuntap_type;
    13801387  int link_type;
    13811388  bool is_tun;
     1389  struct strioctl  strioc_if, strioc_ppa;
    13821390
    1383   ipv6_support (ipv6, false, tt);
     1391  ipv6_support (ipv6, true, tt);
     1392  memset(&ifr, 0x0, sizeof(ifr));
    13841393
    13851394  if (tt->type == DEV_TYPE_NULL)
    13861395    {
    open_tun (const char *dev, const char *dev_type, const char *dev_node, bool ipv6 
    13991408    }
    14001409  else if (tt->type == DEV_TYPE_TAP)
    14011410    {
    1402       ip_node = "/dev/ip";
     1411      ip_node = "/dev/udp";
    14031412      if (!dev_node)
    14041413        dev_node = "/dev/tap";
     1414      arp_node = dev_node;
    14051415      dev_tuntap_type = "tap";
    14061416      link_type = I_PLINK; /* was: I_LINK */
    14071417      is_tun = false;
    open_tun (const char *dev, const char *dev_type, const char *dev_node, bool ipv6 
    14281438    msg (M_ERR, "Can't open %s", dev_node);
    14291439
    14301440  /* 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)
    14321446    msg (M_ERR, "Can't assign new interface");
    14331447
    14341448  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 
    14371451  if (ioctl (if_fd, I_PUSH, "ip") < 0)
    14381452    msg (M_ERR, "Can't push IP module");
    14391453
     1454  if (tt->type == DEV_TYPE_TUN)
     1455    {
    14401456  /* Assign ppa according to the unit number returned by tun device */
    14411457  if (ioctl (if_fd, IF_UNITSEL, (char *) &ppa) < 0)
    14421458    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    }
    14481460
    14491461  tt->actual_name = (char *) malloc (32);
    14501462  check_malloc_return (tt->actual_name);
    14511463
    14521464  openvpn_snprintf (tt->actual_name, 32, "%s%d", dev_tuntap_type, ppa);
    14531465
     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 *)&ifr;
     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
    14541517  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  }
    14571523
    1458   if (ioctl (tt->ip_fd, SIOCSIFMUXID, &ifr) < 0)
     1524  if (ioctl (tt->ip_fd, SIOCSLIFMUXID, &ifr) < 0)
    14591525    {
    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);
    14611531      msg (M_ERR, "Can't set multiplexor id");
    14621532    }
    14631533
    solaris_close_tun (struct tuntap *tt) 
    14751545    {
    14761546      if (tt->ip_fd >= 0)
    14771547        {
    1478           struct ifreq ifr;
     1548          struct lifreq ifr;
    14791549          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));
    14811551
    1482           if (ioctl (tt->ip_fd, SIOCGIFFLAGS, &ifr) < 0)
     1552          if (ioctl (tt->ip_fd, SIOCGLIFFLAGS, &ifr) < 0)
    14831553            msg (M_WARN | M_ERRNO, "Can't get iface flags");
    14841554
    1485           if (ioctl (tt->ip_fd, SIOCGIFMUXID, &ifr) < 0)
     1555          if (ioctl (tt->ip_fd, SIOCGLIFMUXID, &ifr) < 0)
    14861556            msg (M_WARN | M_ERRNO, "Can't get multiplexor id");
    14871557
    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)");
    14901566
    14911567          close (tt->ip_fd);
    14921568          tt->ip_fd = -1;