- /* All the networks we'll be using have been registered. Invoke ifconfig
- to set the TUN device's address, and route to add routes to all
- our networks. */
-
- hostaddr=ipaddr_to_string(st->nl.local_address);
- secnetaddr=ipaddr_to_string(st->nl.secnet_address);
- snprintf(mtu,6,"%d",st->nl.mtu);
- mtu[5]=0;
-
- sys_cmd(st->ifconfig_path,"ifconfig",st->interface_name,
- hostaddr,"netmask","255.255.255.255","-broadcast",
- "pointopoint",secnetaddr,"mtu",mtu,"up",(char *)0);
-
- for (c=st->nl.clients; c; c=c->next) {
- for (i=0; i<c->networks->entries; i++) {
- network=ipaddr_to_string(c->networks->list[i].prefix);
- mask=ipaddr_to_string(c->networks->list[i].mask);
- sys_cmd(st->route_path,"route","add","-net",network,
- "netmask",mask,"gw",secnetaddr,(char *)0);
- }
- }
-
- /* Register for poll() */
- register_for_poll(st, tun_beforepoll, tun_afterpoll, 1, st->nl.name);
-}
-
-#ifdef HAVE_LINUX_IF_H
-static list_t *tun_apply(closure_t *self, struct cloc loc, dict_t *context,
- list_t *args)
-{
- struct tun *st;
- item_t *item;
- dict_t *dict;
-
- st=safe_malloc(sizeof(*st),"tun_apply");
-
- /* First parameter must be a dict */
- item=list_elem(args,0);
- if (!item || item->type!=t_dict)
- cfgfatal(loc,"tun","parameter must be a dictionary\n");
-
- dict=item->data.dict;
-
- st->netlink_to_tunnel=
- netlink_init(&st->nl,st,loc,dict,
- "netlink-tun",tun_deliver_to_kernel);
-
- st->tun_old=False;
- st->device_path=dict_read_string(dict,"device",False,"tun-netlink",loc);
- st->interface_name=dict_read_string(dict,"interface",False,
- "tun-netlink",loc);
- st->ifconfig_path=dict_read_string(dict,"ifconfig-path",
- False,"tun-netlink",loc);
- st->route_path=dict_read_string(dict,"route-path",
- False,"tun-netlink",loc);
-
- if (!st->device_path) st->device_path="/dev/net/tun";
- if (!st->ifconfig_path) st->ifconfig_path="ifconfig";
- if (!st->route_path) st->route_path="route";
- st->buff=find_cl_if(dict,"buffer",CL_BUFFER,True,"tun-netlink",loc);
-
- add_hook(PHASE_GETRESOURCES,tun_phase_hook,st);
-
- return new_closure(&st->nl.cl);
-}
-#endif /* HAVE_LINUX_IF_H */
-
-static list_t *tun_old_apply(closure_t *self, struct cloc loc, dict_t *context,
- list_t *args)
-{
- struct tun *st;
- item_t *item;
- dict_t *dict;
-
- st=safe_malloc(sizeof(*st),"tun_old_apply");