- st->nl.name,route->up?"adding":"deleting",network,
- route->net.len,route->up?"to":"from");
- sys_cmd(st->route_path,"route",route->up?"add":"del","-net",network,
- "netmask",mask,"gw",secnetaddr,(char *)0);
- free(network); free(mask); free(secnetaddr);
- route->kup=route->up;
- return True;
+ st->nl.name,routes->up?"adding":"deleting",network,
+ nets->list[i].len,routes->up?"to":"from");
+ switch (st->route_type) {
+ case TUN_CONFIG_LINUX:
+ sys_cmd(st->route_path,"route",routes->up?"add":"del",
+ "-net",network,"netmask",mask,
+ "gw",secnetaddr,(char *)0);
+ break;
+ case TUN_CONFIG_BSD:
+ sys_cmd(st->route_path,"route",routes->up?"add":"del",
+ "-net",network,secnetaddr,mask,(char *)0);
+ break;
+ case TUN_CONFIG_SOLARIS25:
+ sys_cmd(st->route_path,"route",routes->up?"add":"del",
+ network,secnetaddr,(char *)0);
+ break;
+ case TUN_CONFIG_IOCTL:
+ {
+ /* darwin rtentry has a different format, use /sbin/route instead */
+#if HAVE_NET_ROUTE_H && ! __APPLE__
+ struct rtentry rt;
+ struct sockaddr_in *sa;
+ int action;
+
+ memset(&rt,0,sizeof(rt));
+ sa=(struct sockaddr_in *)&rt.rt_dst;
+ sa->sin_family=AF_INET;
+ sa->sin_addr.s_addr=htonl(nets->list[i].prefix);
+ sa=(struct sockaddr_in *)&rt.rt_genmask;
+ sa->sin_family=AF_INET;
+ sa->sin_addr.s_addr=htonl(nets->list[i].mask);
+ sa=(struct sockaddr_in *)&rt.rt_gateway;
+ sa->sin_family=AF_INET;
+ sa->sin_addr.s_addr=htonl(st->nl.secnet_address);
+ rt.rt_flags=RTF_UP|RTF_GATEWAY;
+ action=routes->up?SIOCADDRT:SIOCDELRT;
+ if (ioctl(fd,action,&rt)<0) {
+ fatal_perror("tun_set_route: ioctl()");
+ }
+#else
+ fatal("tun_set_route: ioctl method not supported");
+#endif
+ }
+ break;
+ default:
+ fatal("tun_set_route: unsupported route command type");
+ break;
+ }
+ free(network); free(mask);
+ }
+ free(secnetaddr);
+ if (st->route_type==TUN_CONFIG_IOCTL) {
+ close(fd);