X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=secnet.git;a=blobdiff_plain;f=tun.c;h=efcf6b6e90e4b9b7dfa5e335df5f8595e5234e03;hp=a36f444adf78d281a5e46426c6672a3235a468d8;hb=7138d0c54cd2212439434d27cb2d6ea775c3039b;hpb=9d3a4132788b198345116624761c12ed7bc936b6 diff --git a/tun.c b/tun.c index a36f444..efcf6b6 100644 --- a/tun.c +++ b/tun.c @@ -28,6 +28,7 @@ struct tun { 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, @@ -47,6 +48,7 @@ static void tun_afterpoll(void *sst, struct pollfd *fds, int nfds, struct tun *st=sst; int l; + if (nfds==0) return; if (fds[0].revents&POLLERR) { printf("tun_afterpoll: hup!\n"); } @@ -156,7 +158,7 @@ static void tun_phase_hook(void *sst, uint32_t newphase) 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); } @@ -174,7 +176,7 @@ static void tun_phase_hook(void *sst, uint32_t newphase) 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; @@ -232,6 +234,8 @@ static list_t *tun_apply(closure_t *self, struct cloc loc, dict_t *context, 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); @@ -276,6 +280,8 @@ static list_t *tun_old_apply(closure_t *self, struct cloc loc, dict_t *context, 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