Changeset 547 for trunk/src/ocattun.c


Ignore:
Timestamp:
04/26/10 13:29:15 (2 years ago)
Author:
eagle
Message:
  • configure.ac refined
  • OC now compiles and runs on Solaris 10 using the Universal TUN/TAP driver version 1.1 (http://vtun.sourceforge.net/tun/index.html)
  • ocathosts.[ch] added. It reads IPv6 addresses from /etc/hosts
  • /etc/hosts reverse lookup for I2P .b32 names added
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/ocattun.c

    r534 r547  
    2323 */ 
    2424 
    25 #ifndef WITHOUT_TUN 
    2625 
    2726 
     
    2928#include "ocat_netdesc.h" 
    3029 
     30#ifndef WITHOUT_TUN 
    3131 
    3232char *tun_dev_ = TUN_DEV; 
    3333 
    3434#define IFCBUF 1024 
     35 
     36 
     37void system_w(const char *s) 
     38{ 
     39   int e; 
     40 
     41   log_debug("running command \"%s\"", s); 
     42   if ((e = system(s)) == -1) 
     43      log_msg(LOG_ERR, "could not exec \"%s\": \"%s\"", s, strerror(errno)); 
     44   log_debug("exit status = %d", WEXITSTATUS(e)); 
     45} 
     46 
    3547 
    3648int tun_alloc(char *dev, int dev_s, struct in6_addr addr) 
     
    3951   struct ifreq ifr; 
    4052#endif 
     53#ifdef __sun__ 
     54   int ppa = -1; 
     55#endif 
    4156   int fd; 
    4257   char astr[INET6_ADDRSTRLEN]; 
    4358   char astr4[INET_ADDRSTRLEN]; 
    4459   char buf[IFCBUF]; 
    45    struct in_addr netmask = {CNF(ocat_addr4_mask)}; 
    46  
     60   struct in_addr netmask;// = {CNF(ocat_addr4_mask)}; 
     61 
     62   memcpy(&netmask, &CNF(ocat_addr4_mask), sizeof(netmask)); 
    4763   inet_ntop(AF_INET6, &addr, astr, INET6_ADDRSTRLEN); 
    4864   inet_ntop(AF_INET, &CNF(ocat_addr4), astr4, INET_ADDRSTRLEN); 
     
    5874 
    5975   snprintf(buf, sizeof(buf), "netsh interface ipv6 add address \"%s\" %s", dev, astr); 
    60    log_debug("setting IP on tun: \"%s\"", buf); 
    61    if (system(buf) == -1) 
    62       log_msg(LOG_ERR, "could not exec \"%s\": \"%s\"", buf, strerror(errno)); 
     76   system_w(buf); 
    6377 
    6478   snprintf(buf, sizeof(buf), "netsh interface ipv6 add route %s/%d \"%s\"", astr, NDESC(prefix_len), dev); 
    65    log_debug("setting IP routing: \"%s\"", buf); 
    66    if (system(buf) == -1) 
    67       log_msg(LOG_ERR, "could not exec \"%s\": \"%s\"", buf, strerror(errno)); 
     79   system_w(buf); 
    6880 
    6981   return 0; 
     
    94106   { 
    95107      snprintf(buf, sizeof(buf), "ifconfig %s add %s/%d up", dev, astr, NDESC(prefix_len)); 
    96       log_msg(LOG_INFO, "configuring tun IP: \"%s\"", buf); 
    97       if (system(buf) == -1) 
    98          log_msg(LOG_ERR, "could not exec \"%s\": \"%s\"", buf, strerror(errno)); 
     108      system_w(buf); 
    99109   } 
    100110 
     
    105115      */ 
    106116 
    107    // set tun frame header to ethertype IPv6 
    108    CNF(fhd_key[IPV6_KEY]) = htonl(ETHERTYPE_IPV6); 
    109    CNF(fhd_key[IPV4_KEY]) = htonl(ETHERTYPE_IP); 
    110  
    111117#else 
    112  
    113    // set tun frame header to address family AF_INET6 (FreeBSD = 0x1c, OpenBSD = 0x18) 
    114    CNF(fhd_key[IPV6_KEY]) = htonl(AF_INET6); 
    115    CNF(fhd_key[IPV4_KEY]) = htonl(AF_INET); 
    116118 
    117119   // get interface name 
     
    166168#endif /* __linux__ */ 
    167169 
     170#ifdef __sun__ 
     171   if( (ppa = ioctl(fd, TUNNEWPPA, ppa)) == -1) 
     172      log_msg(LOG_ERR, "Can't assign new interface"); 
     173   else 
     174      snprintf(dev, dev_s, "%s%d", dev, ppa); 
     175 
     176#endif 
    168177 
    169178   if (!CNF(use_tap)) 
     
    171180#ifdef __OpenBSD__ 
    172181      snprintf(buf, sizeof(buf), "ifconfig %s inet6 %s prefixlen %d up", dev, astr, NDESC(prefix_len)); 
     182#elif __sun__ 
     183      snprintf(buf, sizeof(buf), "ifconfig %s inet6 plumb %s/%d %s up", dev, astr, NDESC(prefix_len), astr); 
    173184#else 
    174185      snprintf(buf, sizeof(buf), "ifconfig %s inet6 %s/%d up", dev, astr, NDESC(prefix_len)); 
    175186#endif 
    176       log_debug("setting IP on tun: \"%s\"", buf); 
    177       if (system(buf) == -1) 
    178          log_msg(LOG_ERR, "could not exec \"%s\": \"%s\"", buf, strerror(errno)); 
    179  
     187      system_w(buf); 
     188 
     189      // some OSes require routes to be set manually 
    180190#ifdef __APPLE__ 
    181  
    182191      // MacOSX requires the route to be set up manually 
    183192      // FIXME: the prefix shouldn't be hardcoded here 
    184193      snprintf(buf, sizeof(buf), "route add -inet6 -net fd87:d87e:eb43:: -prefixlen %d -gateway %s", NDESC(prefix_len), astr); 
    185       log_msg(LOG_INFO, "setup routing: \"%s\"", buf); 
    186       if (system(buf) == -1) 
    187          log_msg(LOG_ERR, "could not exec \"%s\": \"%s\"", buf, strerror(errno)); 
    188   
     194      system_w(buf); 
     195#elif __sun__ 
     196      // Solaris requires the route to be set up manually 
     197      // FIXME: the prefix shouldn't be hardcoded here 
     198      snprintf(buf, sizeof(buf), "route add -inet6 fd87:d87e:eb43::/%d %s -iface", NDESC(prefix_len), astr); 
     199      system_w(buf); 
    189200#endif 
    190201 
     
    197208   { 
    198209      snprintf(buf, sizeof(buf), "ifconfig %s %s netmask %s", dev, astr4, inet_ntoa(netmask)); 
    199       log_msg(LOG_INFO, "configuring tun IP: \"%s\"", buf); 
    200       if (system(buf) == -1) 
    201          log_msg(LOG_ERR, "could not exec \"%s\": \"%s\"", buf, strerror(errno)); 
     210      system_w(buf); 
    202211   } 
    203212 
     
    206215   { 
    207216      snprintf(buf, sizeof(buf), "ifconfig %s up", dev); 
    208       log_msg(LOG_INFO, "bringing up TAP device \"%s\"", buf); 
    209       if (system(buf) == -1) 
    210          log_msg(LOG_ERR, "could not exec \"%s\": \"%s\"", buf, strerror(errno)); 
     217      system_w(buf); 
    211218   } 
    212219 
Note: See TracChangeset for help on using the changeset viewer.