Ejemplo n.º 1
0
Archivo: config.c Proyecto: Mendor/kore
static int
configure_max_connections(char **argv)
{
	int		err;

	if (argv[1] == NULL)
		return (KORE_RESULT_ERROR);

	worker_max_connections = kore_strtonum(argv[1], 10, 1, 65535, &err);
	if (err != KORE_RESULT_OK)
		return (KORE_RESULT_ERROR);

	return (KORE_RESULT_OK);
}
Ejemplo n.º 2
0
Archivo: config.c Proyecto: Mendor/kore
static int
configure_spdy_idle_time(char **argv)
{
	int		err;

	if (argv[1] == NULL)
		return (KORE_RESULT_ERROR);

	spdy_idle_time = kore_strtonum(argv[1], 10, 0, 65535, &err);
	if (err != KORE_RESULT_OK) {
		kore_debug("spdy_idle_time has invalid value: %s", argv[1]);
		return (KORE_RESULT_ERROR);
	}

	spdy_idle_time = spdy_idle_time * 1000;
	return (KORE_RESULT_OK);
}
Ejemplo n.º 3
0
Archivo: config.c Proyecto: Mendor/kore
static int
configure_workers(char **argv)
{
	int		err;

	if (worker_count != 0) {
		kore_debug("duplicate worker directive specified");
		return (KORE_RESULT_ERROR);
	}

	if (argv[1] == NULL)
		return (KORE_RESULT_ERROR);

	worker_count = kore_strtonum(argv[1], 10, 1, 255, &err);
	if (err != KORE_RESULT_OK) {
		kore_debug("%s is not a correct worker number", argv[1]);
		return (KORE_RESULT_ERROR);
	}

	return (KORE_RESULT_OK);
}
Ejemplo n.º 4
0
static int
configure_bind(char **argv)
{
    int		err;

    if (argv[1] == NULL || argv[2] == NULL)
        return (KORE_RESULT_ERROR);
    if (server_ip != NULL || server_port != 0) {
        kore_debug("duplicate bind directive seen");
        return (KORE_RESULT_ERROR);
    }

    server_ip = kore_strdup(argv[1]);
    server_port = kore_strtonum(argv[2], 1, 65535, &err);
    if (err != KORE_RESULT_OK) {
        kore_debug("%s is an invalid port number", argv[2]);
        return (KORE_RESULT_ERROR);
    }

    return (KORE_RESULT_OK);
}
Ejemplo n.º 5
0
Archivo: ktunnel.c Proyecto: 2ion/kore
/*
 * Connect to our target host:port and attach it to a struct connection that
 * Kore understands. We set the disconnect method so we get a callback
 * whenever either of the connections will go away so we can cleanup the
 * one it is attached to.
 */
static int
ktunnel_pipe_create(struct connection *c, const char *host, const char *port)
{
	struct sockaddr_in	sin;
	struct connection	*cpipe;
	u_int16_t		nport;
	int			fd, err;

	nport = kore_strtonum(port, 10, 1, SHRT_MAX, &err);
	if (err == KORE_RESULT_ERROR) {
		kore_log(LOG_ERR, "invalid port given %s", port);
		return (KORE_RESULT_ERROR);
	}

	if ((fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
		kore_log(LOG_ERR, "socket(): %s", errno_s);
		return (KORE_RESULT_ERROR);
	}

	memset(&sin, 0, sizeof(sin));
	sin.sin_family = AF_INET;
	sin.sin_port = htons(nport);
	sin.sin_addr.s_addr = inet_addr(host);

	kore_log(LOG_NOTICE, "Attempting to connect to %s:%s", host, port);

	if (connect(fd, (struct sockaddr *)&sin, sizeof(sin)) == -1) {
		close(fd);
		kore_log(LOG_ERR, "connect(): %s", errno_s);
		return (KORE_RESULT_ERROR);
	}

	if (!kore_connection_nonblock(fd)) {
		close(fd);
		return (KORE_RESULT_ERROR);
	}

	cpipe = kore_connection_new(c);
	cpipe->fd = fd;
	cpipe->addr.ipv4 = sin;
	cpipe->read = net_read;
	cpipe->write = net_write;
	cpipe->addrtype = AF_INET;
	cpipe->proto = CONN_PROTO_UNKNOWN;
	cpipe->state = CONN_STATE_ESTABLISHED;

	/* Don't let these connections timeout any time soon. */
	cpipe->idle_timer.length = 10000000000;
	c->idle_timer.length = 10000000000;

	c->hdlr_extra = cpipe;
	cpipe->hdlr_extra = c;
	c->disconnect = ktunnel_pipe_disconnect;
	cpipe->disconnect = ktunnel_pipe_disconnect;

	kore_worker_connection_add(cpipe);
	kore_connection_start_idletimer(cpipe);
	kore_platform_event_all(cpipe->fd, cpipe);

	net_recv_reset(c, NETBUF_SEND_PAYLOAD_MAX, ktunnel_pipe_data);
	net_recv_queue(cpipe, NETBUF_SEND_PAYLOAD_MAX, NETBUF_CALL_CB_ALWAYS,
	    ktunnel_pipe_data);

	printf("connection started to %s (%p -> %p)\n", host, c, cpipe);
	return (KORE_RESULT_OK);
}