Example #1
0
static int module_init(void)
{
	struct sa laddr_udp, laddr_http;
	struct pl addr;
	uint32_t port;
	int err;

	/* UDP bind address */
	if (conf_get(restund_conf(), "status_udp_addr", &addr))
		pl_set_str(&addr, "127.0.0.1");

	if (conf_get_u32(restund_conf(), "status_udp_port", &port))
		port = 33000;

	err = sa_set(&laddr_udp, &addr, port);
	if (err) {
		restund_error("status: bad udp bind address: %r:%u",
			      &addr, port);
		goto out;
	}

	/* HTTP bind address */
	if (conf_get(restund_conf(), "status_http_addr", &addr))
		pl_set_str(&addr, "127.0.0.1");

	if (conf_get_u32(restund_conf(), "status_http_port", &port))
		port = 8080;

	err = sa_set(&laddr_http, &addr, port);
	if (err) {
		restund_error("status: bad http bind address: %r:%u",
			      &addr, port);
		goto out;
	}

	err = udp_listen(&stg.us, &laddr_udp, udp_recv, NULL);
	if (err) {
		restund_warning("status: udp_listen: %m\n", err);
		goto out;
	}

	err = httpd_alloc(&stg.httpd, &laddr_http, httpd_handler);
	if (err) {
		restund_warning("status: httpd: %m\n", err);
		goto out;
	}

	stg.start = time(NULL);

	restund_debug("status: module loaded (udp=%J http=%J)\n",
		      &laddr_udp, &laddr_http);

 out:
	if (err) {
		stg.us = mem_deref(stg.us);
		stg.httpd = mem_deref(stg.httpd);
	}

	return err;
}
Example #2
0
static int module_init(void)
{
	auth.nonce_expiry = NONCE_EXPIRY;
	auth.secret = rand_u64();

	conf_get_u32(restund_conf(), "auth_nonce_expiry", &auth.nonce_expiry);

	auth.sharedsecret_length = 0;
	auth.sharedsecret2_length = 0;
    conf_get_str(restund_conf(), "auth_shared", auth.sharedsecret, sizeof(auth.sharedsecret));
    auth.sharedsecret_length = strlen(auth.sharedsecret);
    conf_get_str(restund_conf(), "auth_shared_rollover", auth.sharedsecret2, sizeof(auth.sharedsecret2));
    auth.sharedsecret2_length = strlen(auth.sharedsecret2);
    if (auth.sharedsecret_length > 0 || auth.sharedsecret2_length > 0) {
        restund_debug("auth: module loaded shared secret lengths %d and %d\n", 
                      auth.sharedsecret_length,
                      auth.sharedsecret2_length);
    }

	restund_stun_register_handler(&stun);

	restund_debug("auth: module loaded (nonce_expiry=%us)\n",
		      auth.nonce_expiry);

	return 0;
}
Example #3
0
int restund_udp_init(void)
{
    uint32_t sockbuf_size = 0;
    int err;

    list_init(&lstnrl);

    (void)conf_get_u32(restund_conf(), "udp_sockbuf_size", &sockbuf_size);

    err = conf_apply(restund_conf(), "udp_listen", listen_handler,
                     &sockbuf_size);
    if (err)
        goto out;

out:
    if (err)
        restund_udp_close();

    return err;
}
Example #4
0
static int module_init(void)
{
	static struct restund_db db = {
		.allh  = accounts_getall,
		.cnth  = accounts_count,
		.tlogh = NULL,
	};

	conf_get_str(restund_conf(), "mysql_host", my.host, sizeof(my.host));
	conf_get_str(restund_conf(), "mysql_user", my.user, sizeof(my.user));
	conf_get_str(restund_conf(), "mysql_pass", my.pass, sizeof(my.pass));
	conf_get_str(restund_conf(), "mysql_db",   my.db,   sizeof(my.db));
	conf_get_u32(restund_conf(), "mysql_ser", &my.version);

	if (myconnect()) {
		restund_error("mysql: %s\n", mysql_error(&my.mysql));
	}

	restund_db_set_handler(&db);

	return 0;
}
Example #5
0
static int module_init(void)
{
	auth.nonce_expiry = NONCE_EXPIRY;
	auth.rand_time = rand_u32();
	auth.rand_addr = rand_u32();

	conf_get_u32(restund_conf(), "auth_nonce_expiry", &auth.nonce_expiry);

	restund_stun_register_handler(&stun);

	restund_debug("auth: module loaded (nonce_expiry=%us)\n",
		      auth.nonce_expiry);

	return 0;
}
Example #6
0
static int module_init(void)
{
	uint32_t x, bsize = ALLOC_DEFAULT_BSIZE;
	struct pl opt;
	int err = 0;

	restund_stun_register_handler(&stun);
	restund_cmd_subscribe(&cmd_turn);
	restund_cmd_subscribe(&cmd_turnstats);

	/* turn_external_addr */
	if (!conf_get(restund_conf(), "turn_relay_addr", &opt))
		err = sa_set(&turnd.rel_addr, &opt, 0);
	else
		sa_init(&turnd.rel_addr, AF_UNSPEC);

	if (err) {
		restund_error("turn: bad turn_relay_addr: '%r'\n", &opt);
		goto out;
	}

	/* turn_external_addr6 */
	if (!conf_get(restund_conf(), "turn_relay_addr6", &opt))
		err = sa_set(&turnd.rel_addr6, &opt, 0);
	else
		sa_init(&turnd.rel_addr6, AF_UNSPEC);

	if (err) {
		restund_error("turn: bad turn_relay_addr6: '%r'\n", &opt);
		goto out;
	}

	if (!sa_isset(&turnd.rel_addr, SA_ADDR) &&
	    !sa_isset(&turnd.rel_addr6, SA_ADDR)) {
		restund_error("turn: no relay address configured\n");
		err = EINVAL;
		goto out;
	}

	/* turn_max_lifetime, turn_max_allocations, udp_sockbuf_size */
	turnd.lifetime_max = TURN_DEFAULT_LIFETIME;
	conf_get_u32(restund_conf(), "turn_max_lifetime", &turnd.lifetime_max);
	conf_get_u32(restund_conf(), "turn_max_allocations", &bsize);
	conf_get_u32(restund_conf(), "udp_sockbuf_size",
		     &turnd.udp_sockbuf_size);

	for (x=2; (uint32_t)1<<x<bsize; x++);
	bsize = 1<<x;

	err = hash_alloc(&turnd.ht_alloc, bsize);
	if (err) {
		restund_error("turnd hash alloc error: %m\n", err);
		goto out;
	}

	restund_debug("turn: lifetime=%u ext=%j ext6=%j bsz=%u\n",
		      turnd.lifetime_max, &turnd.rel_addr, &turnd.rel_addr6,
		      bsize);

 out:
	return err;
}