int tun_name2idx(struct tun_t *tun, char *name) { int i; for (i=0; i<TUN_MAX_INTERFACES; i++) if (!strcmp(name, tun->_interfaces[i].devname)) return tun->_interfaces[i].idx; /* Not found? Check for discovery */ { struct rtmon_iface *rti = rtmon_find(&_rtmon, name); if (rti) { net_interface *newif = 0; net_interface netif; if (_options.debug) syslog(LOG_DEBUG, "Discoving TUN %s", name); memset(&netif, 0, sizeof(netif)); strlcpy(netif.devname, rti->devname, sizeof(netif.devname)); memcpy(netif.hwaddr, rti->hwaddr, sizeof(netif.hwaddr)); netif.address = rti->address; netif.netmask = rti->netmask; netif.gateway = rti->gateway; netif.broadcast = rti->broadcast; netif.devflags = rti->devflags; netif.mtu = rti->mtu; netif.ifindex = rti->index; newif = tun_newif(tun, &netif); if (newif) { if (net_init(newif, 0, ETH_P_ALL, 1, 0) < 0) { syslog(LOG_ERR, "%s: net_init", strerror(errno)); } else { net_select_reg(tun->sctx, newif->fd, SELECT_READ, (select_callback) tun_decaps, tun, newif->idx); } return newif->idx; } } } return 0; /* tun/tap index */ }
static int module_net_select(select_ctx *sctx) { log_dbg("%s", __FUNCTION__); net_select_reg(sctx, fd, SELECT_READ, (select_callback) acc, 0, 0); return CHILLI_MOD_OK; }