#include <linux/if_tun.h>
#endif
-/* XXX where do we find if_tun on other platforms? */
+/* Where do we find if_tun on other platforms? */
/* Connection to the kernel through the universal TUN/TAP driver */
struct buffer_if *buff; /* We receive packets into here
and send them to the netlink code. */
netlink_deliver_fn *netlink_to_tunnel;
+ uint32_t local_address; /* host interface address */
};
static int tun_beforepoll(void *sst, struct pollfd *fds, int *nfds_io,
struct tun *st=sst;
int l;
+ if (nfds==0) return;
if (fds[0].revents&POLLERR) {
printf("tun_afterpoll: hup!\n");
}
struct tun *st=sst;
BUF_ASSERT_USED(buf);
-
- /* No error checking, because we'd just throw the packet away anyway */
+ /* No error checking, because we'd just throw the packet away
+ anyway if it didn't work. */
write(st->fd,buf->start,buf->size);
BUF_FREE(buf);
}
no extra headers */
if (st->interface_name)
strncpy(ifr.ifr_name,st->interface_name,IFNAMSIZ);
- Message(M_INFO,"%s: about to ioctl(TUNSETIFF)...\n",st->nl.name);
+ Message(M_DEBUG,"%s: about to ioctl(TUNSETIFF)...\n",st->nl.name);
if (ioctl(st->fd,TUNSETIFF,&ifr)<0) {
fatal_perror("%s: ioctl(TUNSETIFF)",st->nl.name);
}
to set the TUN device's address, and route to add routes to all
our networks. */
- hostaddr=ipaddr_to_string(st->nl.local_address);
+ hostaddr=ipaddr_to_string(st->local_address);
secnetaddr=ipaddr_to_string(st->nl.secnet_address);
snprintf(mtu,6,"%d",st->nl.mtu);
mtu[5]=0;
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);
+ st->local_address=string_to_ipaddr(
+ dict_find_item(dict,"local-address", True, "netlink", loc),"netlink");
add_hook(PHASE_GETRESOURCES,tun_phase_hook,st);
st=safe_malloc(sizeof(*st),"tun_old_apply");
- Message(M_WARNING,"the tun-old code has never been tested. Please report "
- "success or failure to steve@greenend.org.uk\n");
-
/* First parameter must be a dict */
item=list_elem(args,0);
if (!item || item->type!=t_dict)
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);
+ st->local_address=string_to_ipaddr(
+ dict_find_item(dict,"local-address", True, "netlink", loc),"netlink");
/* Old TUN interface: the network interface name depends on which
/dev/tunX file we open. If 'interface-search' is set to true, treat