Changeset 547 for trunk/src/ocattun.c
- Timestamp:
- 04/26/10 13:29:15 (2 years ago)
- File:
-
- 1 edited
-
trunk/src/ocattun.c (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/ocattun.c
r534 r547 23 23 */ 24 24 25 #ifndef WITHOUT_TUN26 25 27 26 … … 29 28 #include "ocat_netdesc.h" 30 29 30 #ifndef WITHOUT_TUN 31 31 32 32 char *tun_dev_ = TUN_DEV; 33 33 34 34 #define IFCBUF 1024 35 36 37 void 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 35 47 36 48 int tun_alloc(char *dev, int dev_s, struct in6_addr addr) … … 39 51 struct ifreq ifr; 40 52 #endif 53 #ifdef __sun__ 54 int ppa = -1; 55 #endif 41 56 int fd; 42 57 char astr[INET6_ADDRSTRLEN]; 43 58 char astr4[INET_ADDRSTRLEN]; 44 59 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)); 47 63 inet_ntop(AF_INET6, &addr, astr, INET6_ADDRSTRLEN); 48 64 inet_ntop(AF_INET, &CNF(ocat_addr4), astr4, INET_ADDRSTRLEN); … … 58 74 59 75 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); 63 77 64 78 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); 68 80 69 81 return 0; … … 94 106 { 95 107 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); 99 109 } 100 110 … … 105 115 */ 106 116 107 // set tun frame header to ethertype IPv6108 CNF(fhd_key[IPV6_KEY]) = htonl(ETHERTYPE_IPV6);109 CNF(fhd_key[IPV4_KEY]) = htonl(ETHERTYPE_IP);110 111 117 #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);116 118 117 119 // get interface name … … 166 168 #endif /* __linux__ */ 167 169 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 168 177 169 178 if (!CNF(use_tap)) … … 171 180 #ifdef __OpenBSD__ 172 181 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); 173 184 #else 174 185 snprintf(buf, sizeof(buf), "ifconfig %s inet6 %s/%d up", dev, astr, NDESC(prefix_len)); 175 186 #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 180 190 #ifdef __APPLE__ 181 182 191 // MacOSX requires the route to be set up manually 183 192 // FIXME: the prefix shouldn't be hardcoded here 184 193 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); 189 200 #endif 190 201 … … 197 208 { 198 209 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); 202 211 } 203 212 … … 206 215 { 207 216 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); 211 218 } 212 219
Note: See TracChangeset
for help on using the changeset viewer.
