Ejemplo n.º 1
1
static void mat_loop_cb(struct uloop_timeout *timeout)
{
	void *c, *t;
	char buf[16];
	int i;

	if(sys->tbus_ctx->sock.fd >= 0){
		refresh_arp_table();
		update_mat_table();

		blob_buf_init(&traffic_b, 0);
		blobmsg_add_string(&traffic_b, "hw", sys->ap_hw);
		c = blobmsg_open_array(&traffic_b, "mat");

		for (i = 0; i < arp->idx; i++) {
			t = blobmsg_open_table(&traffic_b, "arp");
			blobmsg_add_string(&traffic_b, "sta", arp->arps[i].hw);
			if(arp->arps[i].ip){
				sprintf(buf, "%u.%u.%u.%u", NIPQUAD(arp->arps[i].ip));
				blobmsg_add_string(&traffic_b, "ip", buf);
			}
			blobmsg_close_table(&traffic_b, t);
		}

		blobmsg_close_array(&traffic_b, c);
		ubus_send_event(sys->tbus_ctx, sys->cfg.tbus_listen_event, traffic_b.head);
		D(SYSTEM, "send msg and wait %d(s)\n", TRAFFICD_WIFIAP_LOOP_TIME / 1000);
	}else{
		D(SYSTEM, "ctx->sock.fd[%d]\n", sys->tbus_ctx->sock.fd);
	}
	uloop_timeout_set(timeout, TRAFFICD_WIFIAP_LOOP_TIME);
}
Ejemplo n.º 2
0
static void __runqueue_start_next(struct uloop_timeout *timeout)
{
	struct runqueue *q = container_of(timeout, struct runqueue, timeout);
	struct runqueue_task *t;

	do {
		if (q->stopped)
			break;

		if (list_empty(&q->tasks_inactive.list))
			break;

		if (q->max_running_tasks && q->running_tasks >= q->max_running_tasks)
			break;

		t = list_first_entry(&q->tasks_inactive.list, struct runqueue_task, list.list);
		safe_list_del(&t->list);
		safe_list_add(&t->list, &q->tasks_active);
		t->running = true;
		q->running_tasks++;
		if (t->run_timeout)
			uloop_timeout_set(&t->timeout, t->run_timeout);
		t->type->run(q, t);
	} while (1);

	if (!q->empty &&
	    list_empty(&q->tasks_active.list) &&
	    list_empty(&q->tasks_inactive.list)) {
		q->empty = true;
		if (q->empty_cb) {
			q->timeout.cb = __runqueue_empty_cb;
			uloop_timeout_set(&q->timeout, 1);
		}
	}
}
Ejemplo n.º 3
0
int system_init()
{
	struct eth_drv_sc *sc = NULL;
	cyg_netdevtab_entry_t *t;

	if(!sys->cfg.is_router && sys->tbus_ctx){
		sd = calloc(1, sizeof(* sd));
		if (!sd){
			elog("calloc failed\n");
			return -1;
		}

		arp = calloc(1, sizeof(struct arp_table) +
				ARP_DEFAULT_SIZE * sizeof(struct _arp_entry));
		if(!arp){
			elog("calloc failed\n");
			return -1;
		}
		arp->size = ARP_DEFAULT_SIZE;

		dlog("set timeout_init\n");
		sd->timeout_init.cb = init_loop_cb;
		dlog("set timeout_mat\n");
		sd->timeout_mat.cb = mat_loop_cb;
		if(sys->init_mode){
			uloop_timeout_set(&sd->timeout_init, TRAFFICD_INIT_LOOP_TIME);
		}else{
			uloop_timeout_set(&sd->timeout_mat, TRAFFICD_WIFIAP_LOOP_TIME);
		}
	}

	for (t = &__NETDEVTAB__[0]; t != &__NETDEVTAB_END__; t++){
		sc = (struct eth_drv_sc *)t->device_instance;
		if (strcmp(sc->dev_name, TRAFFICD_IF_AP) == 0){
			break;
		}
	}

	if(sc){
		struct iwreq iwr;
		int status;
		memset(&iwr, 0, sizeof(iwr));
		iwr.u.data.pointer = (caddr_t) iw_callback;
		iwr.u.data.flags = RTPRIV_IOCTL_IW_CALLBACK;
		iwr.u.data.flags |= OID_GET_SET_TOGGLE;
		iwr.u.data.length = sizeof(caddr_t);
		status = rt28xx_ap_ioctl(sc, RTPRIV_IOCTL_IW_CALLBACK, (caddr_t)&iwr);
		dlog("!!Set callback for 2.4G device[%d]\n", status);
	}

	return 0;
}
Ejemplo n.º 4
0
int main()
{
	openlog("hnetd", LOG_PERROR | LOG_PID, LOG_DAEMON);
	uloop_init();
	to.pending = 0;
	to.cb = _t1;
	uloop_timeout_set(&to, 0);
	end.pending = 0;
	end.cb = _end_to;
	uloop_timeout_set(&end, 1000);
	uloop_run();
	return 0;
}
Ejemplo n.º 5
0
void network_update_local_address(struct uloop_timeout *timer)
{
  struct ifaddrs *ifaddr, *ifa;
  if (getifaddrs(&ifaddr) == -1) {
    syslog(LOG_ERR, "Failed to discover interface IP address.");
  } else {
    for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
      if (ifa->ifa_addr == NULL || strcmp(ifa->ifa_name, net_status.interface) != 0) {
        continue;
      }

      // Get IPv4 address.
      if (ifa->ifa_addr->sa_family == AF_INET) {
        char host[NI_MAXHOST];
        int s = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in), host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
        if (s != 0) {
          syslog(LOG_ERR, "Failed to discover interface IP address.");
          freeifaddrs(ifaddr);
          break;
        }

        if (!net_status.ip_address || strcmp(net_status.ip_address, host) != 0) {
          free(net_status.ip_address);
          net_status.ip_address = strdup(host);
        }
        break;
      }
    }

    freeifaddrs(ifaddr);
  }

  // Reschedule timer.
  uloop_timeout_set(timer, KORUZA_NETWORK_UPDATE_INTERVAL);
}
Ejemplo n.º 6
0
static void timer(struct uloop_timeout *t)
{
	static unsigned int counter = 0;

	flx_tx(FLX_TYPE_PING, (unsigned char *)&counter, sizeof(counter));
	uloop_timeout_set(t, CONFIG_ULOOP_TIMEOUT);
}
Ejemplo n.º 7
0
static void state_cb(struct ustream *s)
{
	___debug(".");

    usfd.stream.write_error = 1;
	uloop_timeout_set(&reconnect_timer, 1000);
}
Ejemplo n.º 8
0
// Signal handler to resend all RDs
static void sigusr1_refresh(_unused int signal)
{
	struct interface *iface;
	list_for_each_entry(iface, &interfaces, head)
		if (iface->ra == RELAYD_SERVER && !iface->master)
			uloop_timeout_set(&iface->timer_rs, 1000);
}
Ejemplo n.º 9
0
static void child_exit(struct uloop_process *proc, int ret)
{
	struct init_action *a = container_of(proc, struct init_action, proc);

	DEBUG(4, "pid:%d\n", proc->pid);
        uloop_timeout_set(&a->tout, a->respawn);
}
Ejemplo n.º 10
0
static void initialize_timer(struct uloop_timeout *t, TIMER_T timer_t)
{
	t = (struct uloop_timeout *) malloc (sizeof(struct uloop_timeout));
	memset(t, 0, sizeof(*t));
	t->cb = (timer_t == SET_INTERVAL) ? setInterval : setTimeout;
	uloop_timeout_set(t, delay_ms);
}
Ejemplo n.º 11
0
void uh_chunk_vprintf(struct client *cl, const char *format, va_list arg)
{
	char buf[256];
	va_list arg2;
	int len;

	if (cl->state == CLIENT_STATE_CLEANUP)
		return;

	uloop_timeout_set(&cl->timeout, conf.network_timeout * 1000);
	if (!uh_use_chunked(cl)) {
		ustream_vprintf(cl->us, format, arg);
		return;
	}

	va_copy(arg2, arg);
	len = vsnprintf(buf, sizeof(buf), format, arg2);
	va_end(arg2);

	ustream_printf(cl->us, "%X\r\n", len);
	if (len < sizeof(buf))
		ustream_write(cl->us, buf, len, true);
	else
		ustream_vprintf(cl->us, format, arg);
	ustream_printf(cl->us, "\r\n", len);
}
Ejemplo n.º 12
0
static void runqueue_start_next(struct runqueue *q)
{
	if (q->empty)
		return;

	q->timeout.cb = __runqueue_start_next;
	uloop_timeout_set(&q->timeout, 1);
}
Ejemplo n.º 13
0
static void
usertimer(struct uloop_timeout *timeout, int (*timer)(void))
{
    struct um_timer *utm = container_of(timeout, struct um_timer, tm);
    
    uloop_timeout_set(timeout, timerms(utm));
    
    (*timer)();
}
Ejemplo n.º 14
0
static void log_handle_fd(struct uloop_fd *u, unsigned int events)
{
	if (u->eof) {
		uloop_fd_delete(u);
		close(sender.fd);
		sender.fd = -1;
		uloop_timeout_set(&retry, 1000);
	}
}
Ejemplo n.º 15
0
Archivo: main.c Proyecto: lynxis/netifd
void netifd_restart(void)
{
	static struct uloop_timeout main_timer = {
		.cb = netifd_do_restart
	};

	interface_set_down(NULL);
	uloop_timeout_set(&main_timer, 1000);
}
Ejemplo n.º 16
0
void setInterval(struct uloop_timeout *t)
{
	if (ivalstop) {
		uloop_timeout_cancel(t);
	} else {
		// do some stuff here
		fprintf(stderr, "setInternal!\n");
		uloop_timeout_set(t, delay_ms);
	}
}
Ejemplo n.º 17
0
static void interface_start(struct interface *iface)
{
	if (iface->v6) {
		iface->fd.cb = read_socket6;
		iface->reconnect.cb = reconnect_socket6;
	} else {
		iface->fd.cb = read_socket4;
		iface->reconnect.cb = reconnect_socket4;
	}
	uloop_timeout_set(&iface->reconnect, 100);
}
Ejemplo n.º 18
0
int system_init()
{

	if(!sys->cfg.is_router && sys->tbus_ctx){
		sd = calloc(1, sizeof(* sd));
		if (!sd)
			return -1;

		dlog("set timeout_init\n");
		sd->timeout_init.cb = init_loop_cb;
		dlog("set timeout_mat\n");
		sd->timeout_mat.cb = mat_loop_cb;
		if(sys->init_mode){
			uloop_timeout_set(&sd->timeout_init, TRAFFICD_INIT_LOOP_TIME);
		}else{
			uloop_timeout_set(&sd->timeout_mat, TRAFFICD_WIFIAP_LOOP_TIME);
		}
	}
	return 0;
}
Ejemplo n.º 19
0
static void log_handle_reconnect(struct uloop_timeout *timeout)
{
	sender.fd = usock((log_udp) ? (USOCK_UDP) : (USOCK_TCP), log_ip, log_port);
	if (sender.fd < 0) {
		fprintf(stderr, "failed to connect: %s\n", strerror(errno));
		uloop_timeout_set(&retry, 1000);
	} else {
		uloop_fd_add(&sender, ULOOP_READ);
		syslog(LOG_INFO, "Logread connected to %s:%s\n", log_ip, log_port);
	}
}
Ejemplo n.º 20
0
void u_tcp_connect()
{
    usfd.stream.write_error = 1;

	ufd.fd = usock(USOCK_TCP, u_tcp_host, u_tcp_port);
	if (ufd.fd < 0) {
		_debug("connection to sysrepo failed"); 
		uloop_timeout_set(&reconnect_timer, 1000);
	}

	ufd.cb = connect_cb;
	uloop_fd_add(&ufd, ULOOP_WRITE | ULOOP_EDGE_TRIGGER);
}
Ejemplo n.º 21
0
void network_announce_ourselves(struct uloop_timeout *timer)
{
  // TODO: Generate announce message.
  message_t msg;
  message_init(&msg);
  network_send_message(&msg);
  message_free(&msg);

  // Reschedule timer if no peer selected.
  if (net_status.peer == NULL) {
    uloop_timeout_set(timer, KORUZA_ANNOUNCE_INTERVAL);
  }
}
Ejemplo n.º 22
0
void _t1(__unused struct uloop_timeout *t)
{
	exeq_init(&exeq[0]);
	exeq_init(&exeq[1]);
	char *argv1[] = { "/bin/echo", "1", NULL };
	exeq_add(&exeq[0], argv1);
	char *argv2[] = { "/bin/echo", "2", NULL };
	exeq_add(&exeq[0], argv2);
	char *argv3[] = { "/bin/echo", "3", NULL };
	exeq_add(&exeq[1], argv3);
	to.cb = _t2;
	uloop_timeout_set(&to, 200);
}
Ejemplo n.º 23
0
static int
easycwmpd_handle_command(struct ubus_context *ctx, struct ubus_object *obj,
			 struct ubus_request_data *req, const char *method,
			 struct blob_attr *msg)
{
	struct blob_attr *tb[__COMMAND_MAX];

	blobmsg_parse(command_policy, ARRAY_SIZE(command_policy), tb,
			  blob_data(msg), blob_len(msg));

	if (!tb[COMMAND_NAME])
		return UBUS_STATUS_INVALID_ARGUMENT;

	blob_buf_init(&b, 0);

	char *cmd = blobmsg_data(tb[COMMAND_NAME]);
	char *info;

	if (!strcmp("reload", cmd)) {
		log_message(NAME, L_NOTICE, "triggered ubus reload\n");
		easycwmp_reload();
		blobmsg_add_u32(&b, "status", 0);
		if (asprintf(&info, "easycwmpd reloaded") == -1)
			goto error;
	} else if (!strcmp("stop", cmd)) {
		log_message(NAME, L_NOTICE, "triggered ubus stop\n");
		ubus_timer.cb = ubus_easycwmpd_stop_callback;
		uloop_timeout_set(&ubus_timer, 1000);
		blobmsg_add_u32(&b, "status", 0);
		if (asprintf(&info, "easycwmpd stopped") == -1)
			goto error;
	} else {
		blobmsg_add_u32(&b, "status", -1);
		if (asprintf(&info, "%s command is not supported", cmd) == -1)
			goto error;
	}

	blobmsg_add_string(&b, "info", info);
	free(info);

	ubus_send_reply(ctx, req, b.head);

	blob_buf_free(&b);
	return 0;

error:
	blob_buf_free(&b);
	return -1;

}
Ejemplo n.º 24
0
void uh_chunk_write(struct client *cl, const void *data, int len)
{
	bool chunked = uh_use_chunked(cl);

	if (cl->state == CLIENT_STATE_CLEANUP)
		return;

	uloop_timeout_set(&cl->timeout, conf.network_timeout * 1000);
	if (chunked)
		ustream_printf(cl->us, "%X\r\n", len);
	ustream_write(cl->us, data, len, true);
	if (chunked)
		ustream_printf(cl->us, "\r\n", len);
}
Ejemplo n.º 25
0
static inline void pa_timer_update_to(struct pa_timer *t)
{
	if(t->when >= 0) {
		hnetd_time_t when = t->when;
		int delay;
		if(when < t->not_before)
			when = t->not_before;
		delay = TODELAY(when - hnetd_time());
		L_INFO("Scheduling %s in %d ms", t->name, delay);
		uloop_timeout_set(&t->t, delay);
	} else if(t->t.pending) {
		L_INFO("Canceling %s", t->name);
		uloop_timeout_cancel(&t->t);
	}
}
Ejemplo n.º 26
0
static void loop_detect_ubus_reconnect_timer(struct uloop_timeout *timeout)
{
	static struct uloop_timeout retry = {
		.cb = loop_detect_ubus_reconnect_timer,
	};
	int t = 2;

	if (ubus_reconnect(ctx, ubus_path) != 0) {
		WARNING(LR_OUT_GROUP1,"failed to reconnect, trying again in %d seconds\n", t);
		uloop_timeout_set(&retry, t * 1000);
		return;
	}

	INFO(LR_OUT_GROUP1,"reconnected to ubus, new id: %08x\n", ctx->local_id);
	loop_detect_ubus_add_fd();
}
Ejemplo n.º 27
0
void runqueue_task_cancel(struct runqueue_task *t, int type)
{
	if (!t->queued)
		return;

	if (!t->running) {
		runqueue_task_complete(t);
		return;
	}

	t->cancelled = true;
	if (t->cancel_timeout)
		uloop_timeout_set(&t->timeout, t->cancel_timeout);
	if (t->type->cancel)
		t->type->cancel(t->q, t, type);
}
Ejemplo n.º 28
0
static void
reconnect_socket6(struct uloop_timeout *timeout)
{
	struct interface *iface = container_of(timeout, struct interface, reconnect);
	char mcast_addr[128];
	int ttl = 255;
	int yes = 1;

	snprintf(mcast_addr, sizeof(mcast_addr), "%s%%%s", (iface->multicast) ? (iface->mcast_addr) : (iface->v6_addrs), iface->name);
	iface->fd.fd = usock(USOCK_UDP | USOCK_SERVER | USOCK_NONBLOCK | USOCK_IPV6ONLY, mcast_addr, "5353");
	if (iface->fd.fd < 0) {
		fprintf(stderr, "failed to add listener %s: %s\n", mcast_addr, strerror(errno));
		goto retry;
	}

	if (setsockopt(iface->fd.fd, SOL_SOCKET, SO_BINDTODEVICE, iface->name, strlen(iface->name) < 0))
		fprintf(stderr, "ioctl failed: SO_BINDTODEVICE\n");

	if (setsockopt(iface->fd.fd, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &ttl, sizeof(ttl)) < 0)
		fprintf(stderr, "ioctl failed: IPV6_UNICAST_HOPS\n");

	if (setsockopt(iface->fd.fd, IPPROTO_IPV6, IPV6_RECVPKTINFO, &yes, sizeof(yes)) < 0)
		fprintf(stderr, "ioctl failed: IPV6_RECVPKTINFO\n");

	if (setsockopt(iface->fd.fd, IPPROTO_IPV6, IPV6_RECVHOPLIMIT, &yes, sizeof(yes)) < 0)
		fprintf(stderr, "ioctl failed: IPV6_RECVHOPLIMIT\n");

	if (setsockopt(iface->fd.fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) < 0)
		fprintf(stderr, "ioctl failed: SO_REUSEADDR\n");

	if (iface->multicast && interface_socket_setup6(iface)) {
		iface->fd.fd = -1;
		goto retry;
	}

	uloop_fd_add(&iface->fd, ULOOP_READ);

	if (iface->multicast) {
		dns_send_question(iface, "_services._dns-sd._udp.local", TYPE_PTR, 1);
		announce_init(iface);
	}

	return;

retry:
	uloop_timeout_set(timeout, 1000);
}
Ejemplo n.º 29
0
static void
ubus_queue_msg(struct ubus_context *ctx, struct ubus_msghdr *hdr)
{
	struct ubus_pending_msg *pending;

	pending = calloc(1, sizeof(*pending));
	if (!pending)
		return;
	pending->hdr.data = calloc(1, blob_raw_len(ubus_msghdr_data(hdr)));
	if (!pending->hdr.data)
		return;

	memcpy(&pending->hdr.hdr, hdr, sizeof(*hdr));
	memcpy(pending->hdr.data, ubus_msghdr_data(hdr), blob_raw_len(ubus_msghdr_data(hdr)));
	list_add(&pending->list, &ctx->pending);
	if (ctx->sock.registered)
		uloop_timeout_set(&ctx->pending_timer, 1);
}
Ejemplo n.º 30
0
static void
reconnect_socket4(struct uloop_timeout *timeout)
{
	struct interface *iface = container_of(timeout, struct interface, reconnect);
	int yes = 1;

	iface->fd.fd = usock(USOCK_UDP | USOCK_SERVER | USOCK_NONBLOCK | USOCK_IPV4ONLY,
		(iface->multicast) ? (iface->mcast_addr) : (iface->v4_addrs), "5353");
	if (iface->fd.fd < 0) {
		fprintf(stderr, "failed to add listener %s: %s\n", iface->mcast_addr, strerror(errno));
		goto retry;
	}

	if (setsockopt(iface->fd.fd, SOL_SOCKET, SO_BINDTODEVICE, iface->name, strlen(iface->name) < 0))
		fprintf(stderr, "ioctl failed: SO_BINDTODEVICE\n");

	if (setsockopt(iface->fd.fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) < 0)
		fprintf(stderr, "ioctl failed: SO_REUSEADDR\n");

	if (setsockopt(iface->fd.fd, IPPROTO_IP, IP_RECVTTL, &yes, sizeof(yes)) < 0)
		fprintf(stderr, "ioctl failed: IP_RECVTTL\n");

	if (setsockopt(iface->fd.fd, IPPROTO_IP, IP_PKTINFO, &yes, sizeof(yes)) < 0)
		fprintf(stderr, "ioctl failed: IP_PKTINFO\n");

	if (iface->multicast && interface_mcast_setup4(iface)) {
		iface->fd.fd = -1;
		goto retry;
	}

	uloop_fd_add(&iface->fd, ULOOP_READ);
	if (iface->multicast) {
		dns_send_question(iface, "_services._dns-sd._udp.local", TYPE_PTR, 1);
		announce_init(iface);
	}

	return;

retry:
	uloop_timeout_set(timeout, 1000);
}