2013-04-17 22:34:27 +02:00
|
|
|
/*
|
2015-04-07 13:08:26 +02:00
|
|
|
* Copyright (c) 2013-2015 Joris Vink <joris@coders.se>
|
2013-04-17 22:34:27 +02:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __H_KORE_H
|
|
|
|
#define __H_KORE_H
|
|
|
|
|
2014-04-12 18:49:01 +02:00
|
|
|
#if defined(__APPLE__)
|
|
|
|
#define daemon portability_is_king
|
|
|
|
#endif
|
|
|
|
|
2013-07-09 09:45:16 +02:00
|
|
|
#include <sys/types.h>
|
2013-07-06 20:55:22 +02:00
|
|
|
#include <sys/queue.h>
|
|
|
|
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
|
|
|
|
#include <openssl/err.h>
|
2013-08-07 16:51:39 +02:00
|
|
|
#include <openssl/dh.h>
|
2013-07-06 20:55:22 +02:00
|
|
|
#include <openssl/ssl.h>
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <regex.h>
|
|
|
|
#include <syslog.h>
|
2013-07-09 09:45:16 +02:00
|
|
|
#include <unistd.h>
|
2013-07-06 20:55:22 +02:00
|
|
|
#include <zlib.h>
|
|
|
|
|
2015-04-01 07:25:10 -04:00
|
|
|
#if defined(__cplusplus)
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2014-04-12 18:49:01 +02:00
|
|
|
#if defined(__APPLE__)
|
|
|
|
#undef daemon
|
|
|
|
extern int daemon(int, int);
|
|
|
|
#endif
|
|
|
|
|
2013-07-06 20:55:22 +02:00
|
|
|
#include "spdy.h"
|
|
|
|
|
2013-04-17 22:34:27 +02:00
|
|
|
#define KORE_RESULT_ERROR 0
|
|
|
|
#define KORE_RESULT_OK 1
|
2013-05-31 00:40:06 +02:00
|
|
|
#define KORE_RESULT_RETRY 2
|
2013-04-17 22:34:27 +02:00
|
|
|
|
2013-12-10 16:43:19 +01:00
|
|
|
#define KORE_VERSION_MAJOR 1
|
2014-07-17 10:22:45 +02:00
|
|
|
#define KORE_VERSION_MINOR 2
|
2015-05-21 15:50:12 +02:00
|
|
|
#define KORE_VERSION_PATCH 4
|
|
|
|
#define KORE_VERSION_STATE "develop"
|
2013-06-26 16:58:01 +02:00
|
|
|
|
2015-05-06 10:59:43 +02:00
|
|
|
#define KORE_TLS_VERSION_1_2 0
|
|
|
|
#define KORE_TLS_VERSION_1_0 1
|
|
|
|
#define KORE_TLS_VERSION_BOTH 2
|
|
|
|
|
2013-04-17 22:34:27 +02:00
|
|
|
#define errno_s strerror(errno)
|
2013-04-21 20:21:46 +02:00
|
|
|
#define ssl_errno_s ERR_error_string(ERR_get_error(), NULL)
|
2013-05-30 19:36:42 +02:00
|
|
|
|
2013-06-27 08:43:07 +02:00
|
|
|
#define KORE_DOMAINNAME_LEN 254
|
2014-08-05 13:10:34 +02:00
|
|
|
#define KORE_PIDFILE_DEFAULT "kore.pid"
|
2015-02-03 13:17:59 +01:00
|
|
|
#define KORE_DEFAULT_CIPHER_LIST "ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!3DES:!MD5:!PSK:!kRSA:!kDSA"
|
2013-06-04 16:53:30 +02:00
|
|
|
|
2013-07-15 10:13:36 +02:00
|
|
|
#if defined(KORE_DEBUG)
|
2013-06-04 16:30:53 +02:00
|
|
|
#define kore_debug(fmt, ...) \
|
2013-06-05 08:55:07 +02:00
|
|
|
if (kore_debug) \
|
|
|
|
kore_debug_internal(__FILE__, __LINE__, fmt, ##__VA_ARGS__)
|
2013-07-15 10:13:36 +02:00
|
|
|
#else
|
|
|
|
#define kore_debug(fmt, ...)
|
|
|
|
#endif
|
2013-04-17 22:34:27 +02:00
|
|
|
|
2013-10-26 00:48:09 +02:00
|
|
|
#define NETBUF_RECV 0
|
|
|
|
#define NETBUF_SEND 1
|
2014-08-08 14:18:15 +02:00
|
|
|
#define NETBUF_SEND_PAYLOAD_MAX 8192
|
|
|
|
|
|
|
|
#define NETBUF_LAST_CHAIN 0
|
|
|
|
#define NETBUF_BEFORE_CHAIN 1
|
2013-04-21 20:21:46 +02:00
|
|
|
|
2013-05-02 14:47:02 +02:00
|
|
|
#define NETBUF_CALL_CB_ALWAYS 0x01
|
|
|
|
#define NETBUF_FORCE_REMOVE 0x02
|
2014-08-07 10:22:54 +02:00
|
|
|
#define NETBUF_MUST_RESEND 0x04
|
2014-08-07 14:23:26 +02:00
|
|
|
#define NETBUF_IS_STREAM 0x10
|
2013-05-02 14:47:02 +02:00
|
|
|
|
2014-03-05 11:38:47 +01:00
|
|
|
#define X509_GET_CN(c, o, l) \
|
|
|
|
X509_NAME_get_text_by_NID(X509_get_subject_name(c), \
|
|
|
|
NID_commonName, o, l)
|
|
|
|
|
|
|
|
#define X509_CN_LENGTH (ub_common_name + 1)
|
|
|
|
|
2014-01-14 21:43:45 +01:00
|
|
|
/* XXX hackish. */
|
|
|
|
struct http_request;
|
|
|
|
struct spdy_stream;
|
|
|
|
|
2013-04-17 22:34:27 +02:00
|
|
|
struct netbuf {
|
2013-04-28 19:11:44 +02:00
|
|
|
u_int8_t *buf;
|
2013-10-25 14:22:29 +02:00
|
|
|
u_int32_t s_off;
|
|
|
|
u_int32_t b_len;
|
|
|
|
u_int32_t m_len;
|
2013-04-28 23:42:13 +02:00
|
|
|
u_int8_t type;
|
2013-05-02 00:28:49 +02:00
|
|
|
u_int8_t flags;
|
2013-04-28 23:42:13 +02:00
|
|
|
|
2013-04-17 22:34:27 +02:00
|
|
|
void *owner;
|
2014-01-14 21:43:45 +01:00
|
|
|
struct spdy_stream *stream;
|
|
|
|
|
2013-05-03 07:35:11 +02:00
|
|
|
void *extra;
|
2013-04-17 22:34:27 +02:00
|
|
|
int (*cb)(struct netbuf *);
|
|
|
|
|
|
|
|
TAILQ_ENTRY(netbuf) list;
|
|
|
|
};
|
|
|
|
|
2013-10-25 14:22:29 +02:00
|
|
|
TAILQ_HEAD(netbuf_head, netbuf);
|
|
|
|
|
2013-07-27 20:56:15 +02:00
|
|
|
#define KORE_TYPE_LISTENER 1
|
|
|
|
#define KORE_TYPE_CONNECTION 2
|
2014-03-30 23:54:35 +02:00
|
|
|
#define KORE_TYPE_PGSQL_CONN 3
|
2014-06-28 16:17:18 +02:00
|
|
|
#define KORE_TYPE_TASK 4
|
2013-07-27 20:56:15 +02:00
|
|
|
|
2013-04-17 22:34:27 +02:00
|
|
|
struct listener {
|
2013-07-27 20:56:15 +02:00
|
|
|
u_int8_t type;
|
|
|
|
|
2013-04-17 22:34:27 +02:00
|
|
|
int fd;
|
2013-07-27 20:56:15 +02:00
|
|
|
u_int8_t addrtype;
|
|
|
|
|
|
|
|
union {
|
|
|
|
struct sockaddr_in ipv4;
|
|
|
|
struct sockaddr_in6 ipv6;
|
|
|
|
} addr;
|
|
|
|
|
|
|
|
LIST_ENTRY(listener) list;
|
2013-04-17 22:34:27 +02:00
|
|
|
};
|
|
|
|
|
2013-07-27 20:56:15 +02:00
|
|
|
LIST_HEAD(listener_head, listener);
|
|
|
|
|
2013-05-02 09:10:35 +02:00
|
|
|
#define CONN_STATE_UNKNOWN 0
|
|
|
|
#define CONN_STATE_SSL_SHAKE 1
|
|
|
|
#define CONN_STATE_ESTABLISHED 2
|
|
|
|
#define CONN_STATE_DISCONNECTING 3
|
2013-04-21 20:21:46 +02:00
|
|
|
|
2013-04-21 20:35:47 +02:00
|
|
|
#define CONN_PROTO_UNKNOWN 0
|
|
|
|
#define CONN_PROTO_SPDY 1
|
|
|
|
#define CONN_PROTO_HTTP 2
|
2014-11-24 11:01:12 +01:00
|
|
|
#define CONN_PROTO_WEBSOCKET 3
|
2015-06-22 21:13:32 +02:00
|
|
|
#define CONN_PROTO_MSG 4
|
2013-04-21 20:35:47 +02:00
|
|
|
|
2013-05-01 13:43:47 +02:00
|
|
|
#define CONN_READ_POSSIBLE 0x01
|
|
|
|
#define CONN_WRITE_POSSIBLE 0x02
|
2013-07-01 11:30:18 +02:00
|
|
|
#define CONN_WRITE_BLOCK 0x04
|
2013-07-01 12:08:51 +02:00
|
|
|
#define CONN_IDLE_TIMER_ACT 0x10
|
2013-07-13 19:56:38 +02:00
|
|
|
#define CONN_READ_BLOCK 0x20
|
2014-01-29 22:48:51 +01:00
|
|
|
#define CONN_CLOSE_EMPTY 0x40
|
2014-08-08 14:18:15 +02:00
|
|
|
#define SPDY_CONN_GOAWAY 0x80
|
2013-07-01 12:08:51 +02:00
|
|
|
|
|
|
|
#define KORE_IDLE_TIMER_MAX 20000
|
2013-05-01 13:43:47 +02:00
|
|
|
|
2014-11-24 11:01:12 +01:00
|
|
|
#define WEBSOCKET_OP_CONT 0x00
|
|
|
|
#define WEBSOCKET_OP_TEXT 0x01
|
|
|
|
#define WEBSOCKET_OP_BINARY 0x02
|
|
|
|
#define WEBSOCKET_OP_CLOSE 0x08
|
|
|
|
#define WEBSOCKET_OP_PING 0x09
|
|
|
|
#define WEBSOCKET_OP_PONG 0x10
|
|
|
|
|
|
|
|
#define WEBSOCKET_BROADCAST_LOCAL 1
|
|
|
|
#define WEBSOCKET_BROADCAST_GLOBAL 2
|
|
|
|
|
2015-04-06 18:54:35 +02:00
|
|
|
#define KORE_TIMER_ONESHOT 0x01
|
|
|
|
|
2015-06-22 21:13:32 +02:00
|
|
|
#define KORE_CONNECTION_PRUNE_DISCONNECT 0
|
|
|
|
#define KORE_CONNECTION_PRUNE_ALL 1
|
|
|
|
|
2013-04-17 22:34:27 +02:00
|
|
|
struct connection {
|
2013-07-27 20:56:15 +02:00
|
|
|
u_int8_t type;
|
2013-04-17 22:34:27 +02:00
|
|
|
int fd;
|
2013-06-27 08:43:07 +02:00
|
|
|
u_int8_t state;
|
|
|
|
u_int8_t proto;
|
2013-04-17 22:34:27 +02:00
|
|
|
void *owner;
|
2013-04-21 20:21:46 +02:00
|
|
|
SSL *ssl;
|
2013-06-27 08:43:07 +02:00
|
|
|
u_int8_t flags;
|
2013-08-14 15:56:44 +02:00
|
|
|
void *hdlr_extra;
|
2014-03-05 11:38:47 +01:00
|
|
|
X509 *cert;
|
2014-11-24 11:01:12 +01:00
|
|
|
void *wscbs;
|
2015-05-20 16:36:13 +02:00
|
|
|
int tls_reneg;
|
2013-04-17 22:34:27 +02:00
|
|
|
|
2014-09-17 08:25:45 +02:00
|
|
|
void (*disconnect)(struct connection *);
|
|
|
|
int (*read)(struct connection *, int *);
|
|
|
|
int (*write)(struct connection *, int, int *);
|
|
|
|
|
2013-07-27 20:56:15 +02:00
|
|
|
u_int8_t addrtype;
|
|
|
|
union {
|
|
|
|
struct sockaddr_in ipv4;
|
|
|
|
struct sockaddr_in6 ipv6;
|
|
|
|
} addr;
|
|
|
|
|
2013-07-01 12:08:51 +02:00
|
|
|
struct {
|
|
|
|
u_int64_t length;
|
|
|
|
u_int64_t start;
|
|
|
|
} idle_timer;
|
|
|
|
|
2013-05-01 12:23:21 +02:00
|
|
|
u_int8_t inflate_started;
|
|
|
|
z_stream z_inflate;
|
|
|
|
u_int8_t deflate_started;
|
|
|
|
z_stream z_deflate;
|
2014-08-08 14:18:15 +02:00
|
|
|
|
2013-07-01 11:30:18 +02:00
|
|
|
u_int32_t wsize_initial;
|
2014-08-08 14:18:15 +02:00
|
|
|
u_int32_t spdy_send_wsize;
|
2014-08-10 21:39:47 +02:00
|
|
|
u_int32_t spdy_recv_wsize;
|
2013-05-01 12:23:21 +02:00
|
|
|
|
2014-08-07 10:22:54 +02:00
|
|
|
struct netbuf_head send_queue;
|
2014-08-08 14:18:15 +02:00
|
|
|
struct netbuf *snb;
|
|
|
|
struct netbuf *rnb;
|
2013-04-29 23:35:36 +02:00
|
|
|
|
2013-05-30 19:36:42 +02:00
|
|
|
u_int32_t client_stream_id;
|
2013-04-29 23:35:36 +02:00
|
|
|
TAILQ_HEAD(, spdy_stream) spdy_streams;
|
2013-09-09 10:59:56 +02:00
|
|
|
TAILQ_HEAD(, http_request) http_requests;
|
2013-05-02 09:10:35 +02:00
|
|
|
|
|
|
|
TAILQ_ENTRY(connection) list;
|
2013-10-25 14:22:29 +02:00
|
|
|
TAILQ_ENTRY(connection) flush_list;
|
2013-04-17 22:34:27 +02:00
|
|
|
};
|
|
|
|
|
2014-12-03 20:40:44 +01:00
|
|
|
TAILQ_HEAD(connection_list, connection);
|
2015-06-22 21:13:32 +02:00
|
|
|
extern struct connection_list connections;
|
|
|
|
extern struct connection_list disconnected;
|
2014-12-03 20:40:44 +01:00
|
|
|
|
2013-11-10 15:17:15 +01:00
|
|
|
struct kore_handler_params {
|
|
|
|
char *name;
|
|
|
|
u_int8_t method;
|
|
|
|
struct kore_validator *validator;
|
|
|
|
|
|
|
|
TAILQ_ENTRY(kore_handler_params) list;
|
|
|
|
};
|
|
|
|
|
2014-01-22 22:55:10 +01:00
|
|
|
#define KORE_AUTH_TYPE_COOKIE 1
|
2014-01-22 23:11:52 +01:00
|
|
|
#define KORE_AUTH_TYPE_HEADER 2
|
2014-03-01 19:18:30 +01:00
|
|
|
#define KORE_AUTH_TYPE_REQUEST 3
|
2014-01-22 22:55:10 +01:00
|
|
|
|
|
|
|
struct kore_auth {
|
|
|
|
u_int8_t type;
|
|
|
|
char *name;
|
|
|
|
char *value;
|
|
|
|
char *redirect;
|
|
|
|
struct kore_validator *validator;
|
|
|
|
|
|
|
|
TAILQ_ENTRY(kore_auth) list;
|
|
|
|
};
|
2013-05-01 16:03:48 +02:00
|
|
|
|
2013-12-21 13:37:34 +01:00
|
|
|
#define KORE_MODULE_LOAD 1
|
|
|
|
#define KORE_MODULE_UNLOAD 2
|
|
|
|
|
2014-01-22 22:55:10 +01:00
|
|
|
#define HANDLER_TYPE_STATIC 1
|
|
|
|
#define HANDLER_TYPE_DYNAMIC 2
|
|
|
|
|
2013-12-15 01:11:56 +01:00
|
|
|
struct kore_module {
|
|
|
|
void *handle;
|
|
|
|
char *path;
|
|
|
|
char *onload;
|
2015-05-07 13:03:10 +02:00
|
|
|
int (*ocb)(int);
|
2013-12-21 13:37:34 +01:00
|
|
|
|
2013-12-15 01:11:56 +01:00
|
|
|
time_t mtime;
|
|
|
|
|
|
|
|
TAILQ_ENTRY(kore_module) list;
|
|
|
|
};
|
|
|
|
|
2013-05-01 16:03:48 +02:00
|
|
|
struct kore_module_handle {
|
2013-05-29 14:29:46 +02:00
|
|
|
char *path;
|
2013-05-03 00:04:06 +02:00
|
|
|
char *func;
|
|
|
|
void *addr;
|
2013-05-01 16:03:48 +02:00
|
|
|
int type;
|
2013-07-07 14:48:32 +02:00
|
|
|
int errors;
|
2013-05-29 14:29:46 +02:00
|
|
|
regex_t rctx;
|
2014-07-30 09:11:21 +02:00
|
|
|
struct kore_domain *dom;
|
2014-01-22 22:55:10 +01:00
|
|
|
struct kore_auth *auth;
|
2013-05-01 16:03:48 +02:00
|
|
|
|
2013-11-10 15:17:15 +01:00
|
|
|
TAILQ_HEAD(, kore_handler_params) params;
|
2013-05-01 16:03:48 +02:00
|
|
|
TAILQ_ENTRY(kore_module_handle) list;
|
|
|
|
};
|
|
|
|
|
2013-05-30 19:36:42 +02:00
|
|
|
struct kore_worker {
|
2013-06-27 08:43:07 +02:00
|
|
|
u_int8_t id;
|
|
|
|
u_int8_t cpu;
|
2013-06-04 11:55:38 +02:00
|
|
|
pid_t pid;
|
2015-06-22 21:13:32 +02:00
|
|
|
int pipe[2];
|
|
|
|
struct connection *msg[2];
|
2013-06-27 08:43:07 +02:00
|
|
|
u_int8_t has_lock;
|
2013-07-07 14:48:32 +02:00
|
|
|
struct kore_module_handle *active_hdlr;
|
2013-05-30 19:36:42 +02:00
|
|
|
};
|
|
|
|
|
2013-06-24 11:32:45 +02:00
|
|
|
struct kore_domain {
|
2013-06-24 09:36:40 +02:00
|
|
|
char *domain;
|
2013-06-24 11:32:45 +02:00
|
|
|
char *certfile;
|
|
|
|
char *certkey;
|
2013-12-14 16:31:07 +01:00
|
|
|
char *cafile;
|
2014-10-18 02:32:05 +02:00
|
|
|
char *crlfile;
|
2013-06-24 09:36:40 +02:00
|
|
|
int accesslog;
|
2013-06-24 11:32:45 +02:00
|
|
|
SSL_CTX *ssl_ctx;
|
2013-06-24 09:36:40 +02:00
|
|
|
TAILQ_HEAD(, kore_module_handle) handlers;
|
2013-06-24 11:32:45 +02:00
|
|
|
TAILQ_ENTRY(kore_domain) list;
|
2013-06-24 09:36:40 +02:00
|
|
|
};
|
|
|
|
|
2013-06-24 11:32:45 +02:00
|
|
|
TAILQ_HEAD(kore_domain_h, kore_domain);
|
|
|
|
|
2013-11-09 16:21:52 +01:00
|
|
|
#define KORE_VALIDATOR_TYPE_REGEX 1
|
|
|
|
#define KORE_VALIDATOR_TYPE_FUNCTION 2
|
|
|
|
|
|
|
|
struct kore_validator {
|
2014-02-01 17:47:58 +01:00
|
|
|
u_int8_t type;
|
|
|
|
char *name;
|
|
|
|
char *arg;
|
|
|
|
regex_t rctx;
|
|
|
|
int (*func)(struct http_request *, char *);
|
2013-11-09 16:21:52 +01:00
|
|
|
|
|
|
|
TAILQ_ENTRY(kore_validator) list;
|
|
|
|
};
|
|
|
|
|
2013-05-02 15:14:00 +02:00
|
|
|
#define KORE_BUF_INITIAL 128
|
|
|
|
#define KORE_BUF_INCREMENT KORE_BUF_INITIAL
|
|
|
|
|
|
|
|
struct kore_buf {
|
|
|
|
u_int8_t *data;
|
2013-09-22 20:05:24 +02:00
|
|
|
u_int64_t length;
|
|
|
|
u_int64_t offset;
|
2013-05-02 15:14:00 +02:00
|
|
|
};
|
|
|
|
|
2013-07-15 10:13:36 +02:00
|
|
|
struct kore_pool_region {
|
|
|
|
void *start;
|
|
|
|
LIST_ENTRY(kore_pool_region) list;
|
2014-04-18 17:41:56 +02:00
|
|
|
};
|
2013-07-15 10:13:36 +02:00
|
|
|
|
|
|
|
struct kore_pool_entry {
|
|
|
|
u_int8_t state;
|
|
|
|
struct kore_pool_region *region;
|
|
|
|
LIST_ENTRY(kore_pool_entry) list;
|
2014-04-18 17:41:56 +02:00
|
|
|
};
|
2013-07-15 10:13:36 +02:00
|
|
|
|
|
|
|
struct kore_pool {
|
|
|
|
u_int32_t elen;
|
|
|
|
u_int32_t slen;
|
|
|
|
u_int32_t elms;
|
|
|
|
u_int32_t inuse;
|
|
|
|
char *name;
|
|
|
|
|
|
|
|
LIST_HEAD(, kore_pool_region) regions;
|
|
|
|
LIST_HEAD(, kore_pool_entry) freelist;
|
2014-04-18 17:41:56 +02:00
|
|
|
};
|
2013-07-15 10:13:36 +02:00
|
|
|
|
2014-11-24 11:01:12 +01:00
|
|
|
struct kore_wscbs {
|
|
|
|
void (*connect)(struct connection *);
|
|
|
|
void (*message)(struct connection *, u_int8_t,
|
|
|
|
void *, size_t);
|
|
|
|
void (*disconnect)(struct connection *);
|
|
|
|
};
|
|
|
|
|
2015-05-15 19:11:10 +02:00
|
|
|
struct kore_timer {
|
|
|
|
u_int64_t nextrun;
|
|
|
|
u_int64_t interval;
|
|
|
|
int flags;
|
|
|
|
void *arg;
|
|
|
|
void (*cb)(void *, u_int64_t, u_int64_t);
|
|
|
|
|
|
|
|
TAILQ_ENTRY(kore_timer) list;
|
|
|
|
};
|
|
|
|
|
2015-06-22 21:13:32 +02:00
|
|
|
struct kore_msg {
|
|
|
|
u_int8_t id;
|
|
|
|
u_int32_t length;
|
|
|
|
};
|
|
|
|
|
2013-06-26 11:18:32 +02:00
|
|
|
extern pid_t kore_pid;
|
2014-07-31 13:43:37 +02:00
|
|
|
extern int foreground;
|
2013-06-05 08:55:07 +02:00
|
|
|
extern int kore_debug;
|
2013-11-18 00:42:57 +01:00
|
|
|
extern int skip_chroot;
|
2013-05-04 22:18:27 +02:00
|
|
|
extern char *chroot_path;
|
2015-05-18 21:34:39 +02:00
|
|
|
extern int skip_runas;
|
2013-05-04 22:18:27 +02:00
|
|
|
extern char *runas_user;
|
2013-06-04 16:53:30 +02:00
|
|
|
extern char *kore_pidfile;
|
2013-06-26 11:18:32 +02:00
|
|
|
extern char *config_file;
|
2015-05-06 10:59:43 +02:00
|
|
|
extern char *kore_tls_cipher_list;
|
|
|
|
extern int tls_version;
|
|
|
|
extern DH *tls_dhparam;
|
2013-06-17 23:39:17 +02:00
|
|
|
|
2013-07-27 20:56:15 +02:00
|
|
|
extern u_int8_t nlisteners;
|
2013-07-13 20:19:01 +02:00
|
|
|
extern u_int64_t spdy_idle_time;
|
2013-06-17 23:39:17 +02:00
|
|
|
extern u_int16_t cpu_count;
|
|
|
|
extern u_int8_t worker_count;
|
2015-04-27 10:36:33 +02:00
|
|
|
extern u_int8_t worker_set_affinity;
|
2014-07-31 09:14:03 +02:00
|
|
|
extern u_int32_t worker_rlimit_nofiles;
|
2013-06-26 16:37:22 +02:00
|
|
|
extern u_int32_t worker_max_connections;
|
2013-06-27 00:22:48 +02:00
|
|
|
extern u_int32_t worker_active_connections;
|
2015-05-18 12:20:28 +02:00
|
|
|
extern u_int32_t worker_accept_threshold;
|
2014-11-24 11:01:12 +01:00
|
|
|
extern u_int64_t kore_websocket_maxframe;
|
|
|
|
extern u_int64_t kore_websocket_timeout;
|
2015-04-09 15:29:44 +02:00
|
|
|
extern u_int32_t kore_socket_backlog;
|
2013-06-17 23:39:17 +02:00
|
|
|
|
2013-07-27 20:56:15 +02:00
|
|
|
extern struct listener_head listeners;
|
2013-06-24 09:36:40 +02:00
|
|
|
extern struct kore_worker *worker;
|
2013-06-24 11:32:45 +02:00
|
|
|
extern struct kore_domain_h domains;
|
|
|
|
extern struct kore_domain *primary_dom;
|
2013-07-15 10:13:36 +02:00
|
|
|
extern struct kore_pool nb_pool;
|
2013-06-17 23:39:17 +02:00
|
|
|
|
2014-08-01 13:59:47 +02:00
|
|
|
void kore_cli_usage(int);
|
|
|
|
int kore_cli_main(int, char **);
|
|
|
|
|
2013-06-26 11:18:32 +02:00
|
|
|
void kore_signal(int);
|
2013-06-26 16:37:22 +02:00
|
|
|
void kore_worker_wait(int);
|
2013-06-17 23:39:17 +02:00
|
|
|
void kore_worker_init(void);
|
2013-06-26 16:37:22 +02:00
|
|
|
void kore_worker_shutdown(void);
|
|
|
|
void kore_worker_dispatch_signal(int);
|
2013-07-27 20:56:15 +02:00
|
|
|
void kore_worker_spawn(u_int16_t, u_int16_t);
|
|
|
|
void kore_worker_entry(struct kore_worker *);
|
2015-06-22 21:13:32 +02:00
|
|
|
|
|
|
|
struct kore_worker *kore_worker_data(u_int8_t);
|
2013-06-26 11:18:32 +02:00
|
|
|
|
2013-07-27 20:56:15 +02:00
|
|
|
void kore_platform_init(void);
|
2013-06-26 11:18:32 +02:00
|
|
|
void kore_platform_event_init(void);
|
|
|
|
void kore_platform_proctitle(char *);
|
2014-03-30 23:54:35 +02:00
|
|
|
void kore_platform_disable_read(int);
|
2013-06-26 16:37:22 +02:00
|
|
|
void kore_platform_enable_accept(void);
|
|
|
|
void kore_platform_disable_accept(void);
|
2014-10-22 21:16:49 +02:00
|
|
|
int kore_platform_event_wait(u_int64_t);
|
2014-09-17 08:25:45 +02:00
|
|
|
void kore_platform_event_all(int, void *);
|
2014-03-30 23:54:35 +02:00
|
|
|
void kore_platform_schedule_read(int, void *);
|
2013-06-26 11:18:32 +02:00
|
|
|
void kore_platform_event_schedule(int, int, int, void *);
|
|
|
|
void kore_platform_worker_setcpu(struct kore_worker *);
|
|
|
|
|
2013-06-24 09:36:40 +02:00
|
|
|
void kore_accesslog_init(void);
|
|
|
|
int kore_accesslog_wait(void);
|
|
|
|
void kore_accesslog_worker_init(void);
|
2013-07-27 20:56:15 +02:00
|
|
|
|
2015-04-02 13:45:42 +02:00
|
|
|
int kore_auth_run(struct http_request *, struct kore_auth *);
|
|
|
|
void kore_auth_init(void);
|
|
|
|
int kore_auth_new(const char *);
|
2014-08-04 12:40:21 +02:00
|
|
|
struct kore_auth *kore_auth_lookup(const char *);
|
2014-01-22 22:55:10 +01:00
|
|
|
|
2015-04-06 18:54:35 +02:00
|
|
|
void kore_timer_init(void);
|
|
|
|
u_int64_t kore_timer_run(u_int64_t);
|
2015-05-15 19:11:10 +02:00
|
|
|
void kore_timer_remove(struct kore_timer *);
|
|
|
|
struct kore_timer *kore_timer_add(void (*cb)(void *, u_int64_t,
|
|
|
|
u_int64_t), u_int64_t, void *, int);
|
2015-04-06 18:54:35 +02:00
|
|
|
|
2015-05-06 10:59:43 +02:00
|
|
|
int kore_tls_sni_cb(SSL *, int *, void *);
|
2013-07-27 20:56:15 +02:00
|
|
|
int kore_server_bind(const char *, const char *);
|
2015-05-06 10:59:43 +02:00
|
|
|
int kore_tls_npn_cb(SSL *, const u_char **, unsigned int *, void *);
|
2015-05-20 16:36:13 +02:00
|
|
|
void kore_tls_info_callback(const SSL *, int, int);
|
2013-05-01 16:03:48 +02:00
|
|
|
|
2014-09-17 08:25:45 +02:00
|
|
|
void kore_connection_init(void);
|
2015-06-22 21:13:32 +02:00
|
|
|
void kore_connection_prune(int);
|
2014-09-17 08:25:45 +02:00
|
|
|
struct connection *kore_connection_new(void *);
|
2015-06-22 21:13:32 +02:00
|
|
|
void kore_connection_check_timeout(void);
|
2015-06-22 22:11:03 +02:00
|
|
|
int kore_connection_nonblock(int, int);
|
2014-09-17 08:25:45 +02:00
|
|
|
int kore_connection_handle(struct connection *);
|
|
|
|
void kore_connection_remove(struct connection *);
|
|
|
|
void kore_connection_disconnect(struct connection *);
|
|
|
|
void kore_connection_start_idletimer(struct connection *);
|
|
|
|
void kore_connection_stop_idletimer(struct connection *);
|
|
|
|
void kore_connection_check_idletimer(u_int64_t,
|
|
|
|
struct connection *);
|
|
|
|
int kore_connection_accept(struct listener *,
|
|
|
|
struct connection **);
|
2013-06-26 11:18:32 +02:00
|
|
|
|
2013-06-24 09:36:40 +02:00
|
|
|
u_int64_t kore_time_ms(void);
|
2013-06-04 23:24:47 +02:00
|
|
|
void kore_log_init(void);
|
2013-06-27 08:43:07 +02:00
|
|
|
|
2013-04-17 22:34:27 +02:00
|
|
|
void *kore_malloc(size_t);
|
2013-06-26 11:18:32 +02:00
|
|
|
void kore_parse_config(void);
|
2013-04-17 22:34:27 +02:00
|
|
|
void *kore_calloc(size_t, size_t);
|
|
|
|
void *kore_realloc(void *, size_t);
|
2013-06-27 08:43:07 +02:00
|
|
|
void kore_mem_free(void *);
|
|
|
|
void kore_mem_init(void);
|
|
|
|
|
2014-04-22 12:46:23 +02:00
|
|
|
#if defined(KORE_PEDANTIC_MALLOC)
|
|
|
|
void explicit_bzero(void *, size_t);
|
|
|
|
#endif
|
|
|
|
|
2013-07-15 10:13:36 +02:00
|
|
|
void *kore_pool_get(struct kore_pool *);
|
|
|
|
void kore_pool_put(struct kore_pool *, void *);
|
2014-08-04 12:40:21 +02:00
|
|
|
void kore_pool_init(struct kore_pool *, const char *,
|
2013-07-15 10:13:36 +02:00
|
|
|
u_int32_t, u_int32_t);
|
|
|
|
|
2013-05-01 20:10:45 +02:00
|
|
|
time_t kore_date_to_time(char *);
|
2013-05-01 21:16:09 +02:00
|
|
|
char *kore_time_to_date(time_t);
|
2013-04-17 22:34:27 +02:00
|
|
|
char *kore_strdup(const char *);
|
2013-06-04 23:24:47 +02:00
|
|
|
void kore_log(int, const char *, ...);
|
2014-07-21 01:16:03 +02:00
|
|
|
u_int64_t kore_strtonum64(const char *, int, int *);
|
2013-05-01 00:35:33 +02:00
|
|
|
void kore_strlcpy(char *, const char *, size_t);
|
2013-05-01 08:09:04 +02:00
|
|
|
void kore_server_disconnect(struct connection *);
|
2013-05-01 20:10:45 +02:00
|
|
|
int kore_split_string(char *, char *, char **, size_t);
|
2013-09-10 11:02:59 +02:00
|
|
|
void kore_strip_chars(char *, char, char **);
|
2014-08-11 10:45:10 +02:00
|
|
|
int kore_snprintf(char *, size_t, int *, const char *, ...);
|
2013-12-12 00:58:32 +01:00
|
|
|
long long kore_strtonum(const char *, int, long long, long long, int *);
|
2013-07-10 15:00:53 +02:00
|
|
|
int kore_base64_encode(u_int8_t *, u_int32_t, char **);
|
|
|
|
int kore_base64_decode(char *, u_int8_t **, u_int32_t *);
|
2013-09-10 11:02:59 +02:00
|
|
|
void *kore_mem_find(void *, size_t, void *, u_int32_t);
|
2013-05-01 16:03:48 +02:00
|
|
|
|
2014-11-24 11:01:12 +01:00
|
|
|
void kore_websocket_handshake(struct http_request *,
|
|
|
|
struct kore_wscbs *);
|
|
|
|
void kore_websocket_send(struct connection *,
|
|
|
|
u_int8_t, void *, size_t);
|
|
|
|
void kore_websocket_broadcast(struct connection *,
|
|
|
|
u_int8_t, void *, size_t, int);
|
|
|
|
|
2015-06-22 21:13:32 +02:00
|
|
|
void kore_msg_init(void);
|
|
|
|
void kore_msg_worker_init(void);
|
|
|
|
void kore_msg_parent_init(void);
|
|
|
|
void kore_msg_parent_add(struct kore_worker *);
|
|
|
|
void kore_msg_parent_remove(struct kore_worker *);
|
|
|
|
void kore_msg_send(u_int8_t, void *, u_int32_t);
|
|
|
|
int kore_msg_register(u_int8_t,
|
|
|
|
void (*cb)(const void *, u_int32_t));
|
|
|
|
|
2013-06-24 11:32:45 +02:00
|
|
|
void kore_domain_init(void);
|
|
|
|
int kore_domain_new(char *);
|
2013-12-15 01:11:56 +01:00
|
|
|
void kore_module_init(void);
|
2014-06-29 21:15:23 +02:00
|
|
|
void kore_module_reload(int);
|
|
|
|
void kore_module_onload(void);
|
2013-05-01 16:03:48 +02:00
|
|
|
int kore_module_loaded(void);
|
2013-06-24 11:32:45 +02:00
|
|
|
void kore_domain_closelogs(void);
|
2014-08-04 12:40:21 +02:00
|
|
|
void *kore_module_getsym(const char *);
|
2014-10-18 02:32:05 +02:00
|
|
|
void kore_domain_load_crl(void);
|
2014-08-04 12:40:21 +02:00
|
|
|
void kore_module_load(const char *, const char *);
|
2013-06-24 11:32:45 +02:00
|
|
|
void kore_domain_sslstart(struct kore_domain *);
|
2014-08-04 12:40:21 +02:00
|
|
|
int kore_module_handler_new(const char *, const char *,
|
|
|
|
const char *, const char *, int);
|
|
|
|
|
2013-07-07 14:48:32 +02:00
|
|
|
struct kore_domain *kore_domain_lookup(const char *);
|
2014-08-04 12:40:21 +02:00
|
|
|
struct kore_module_handle *kore_module_handler_find(const char *,
|
|
|
|
const char *);
|
2013-04-17 22:34:27 +02:00
|
|
|
|
2013-11-09 16:21:52 +01:00
|
|
|
void kore_validator_init(void);
|
|
|
|
void kore_validator_reload(void);
|
2014-08-04 12:40:21 +02:00
|
|
|
int kore_validator_add(const char *, u_int8_t, const char *);
|
|
|
|
int kore_validator_run(struct http_request *, const char *, char *);
|
2014-02-01 17:47:58 +01:00
|
|
|
int kore_validator_check(struct http_request *,
|
2014-03-01 19:18:30 +01:00
|
|
|
struct kore_validator *, void *);
|
2014-08-04 12:40:21 +02:00
|
|
|
struct kore_validator *kore_validator_lookup(const char *);
|
2013-11-09 16:21:52 +01:00
|
|
|
|
2015-05-19 09:45:04 +02:00
|
|
|
void fatal(const char *, ...) __attribute__((noreturn));
|
2013-06-04 16:30:53 +02:00
|
|
|
void kore_debug_internal(char *, int, const char *, ...);
|
2013-04-17 22:34:27 +02:00
|
|
|
|
2013-05-01 00:35:33 +02:00
|
|
|
u_int16_t net_read16(u_int8_t *);
|
|
|
|
u_int32_t net_read32(u_int8_t *);
|
2014-11-24 11:01:12 +01:00
|
|
|
u_int64_t net_read64(u_int8_t *);
|
2013-05-01 08:09:04 +02:00
|
|
|
void net_write16(u_int8_t *, u_int16_t);
|
|
|
|
void net_write32(u_int8_t *, u_int32_t);
|
2014-11-24 11:01:12 +01:00
|
|
|
void net_write64(u_int8_t *, u_int64_t);
|
|
|
|
|
2013-07-15 10:13:36 +02:00
|
|
|
void net_init(void);
|
2013-04-28 19:11:44 +02:00
|
|
|
int net_send(struct connection *);
|
2013-05-01 13:43:47 +02:00
|
|
|
int net_send_flush(struct connection *);
|
|
|
|
int net_recv_flush(struct connection *);
|
2014-09-17 08:25:45 +02:00
|
|
|
int net_read(struct connection *, int *);
|
|
|
|
int net_read_ssl(struct connection *, int *);
|
|
|
|
int net_write(struct connection *, int, int *);
|
|
|
|
int net_write_ssl(struct connection *, int, int *);
|
2014-10-22 21:16:49 +02:00
|
|
|
void net_recv_reset(struct connection *, u_int32_t,
|
|
|
|
int (*cb)(struct netbuf *));
|
2014-08-07 10:22:54 +02:00
|
|
|
void net_remove_netbuf(struct netbuf_head *, struct netbuf *);
|
2014-08-10 18:46:44 +02:00
|
|
|
void net_recv_queue(struct connection *, u_int32_t, int,
|
2014-10-22 21:16:49 +02:00
|
|
|
int (*cb)(struct netbuf *));
|
2015-03-16 16:52:40 +01:00
|
|
|
void net_recv_expand(struct connection *c, u_int32_t,
|
2014-10-22 21:16:49 +02:00
|
|
|
int (*cb)(struct netbuf *));
|
2014-07-04 11:25:05 +02:00
|
|
|
void net_send_queue(struct connection *, void *,
|
2014-08-08 14:18:15 +02:00
|
|
|
u_int32_t, struct spdy_stream *, int);
|
2014-08-07 14:23:26 +02:00
|
|
|
void net_send_stream(struct connection *, void *,
|
2014-08-10 18:46:44 +02:00
|
|
|
u_int32_t, struct spdy_stream *,
|
|
|
|
int (*cb)(struct netbuf *), struct netbuf **);
|
2013-04-28 19:11:44 +02:00
|
|
|
|
2013-07-10 15:00:53 +02:00
|
|
|
void kore_buf_free(struct kore_buf *);
|
2013-05-02 15:14:00 +02:00
|
|
|
struct kore_buf *kore_buf_create(u_int32_t);
|
2013-08-22 10:06:39 +02:00
|
|
|
void kore_buf_append(struct kore_buf *, void *, u_int32_t);
|
2013-05-02 15:14:00 +02:00
|
|
|
u_int8_t *kore_buf_release(struct kore_buf *, u_int32_t *);
|
2013-05-04 19:09:07 +02:00
|
|
|
void kore_buf_appendf(struct kore_buf *, const char *, ...);
|
2014-04-22 12:16:21 +02:00
|
|
|
void kore_buf_appendv(struct kore_buf *, const char *, va_list);
|
2013-06-05 11:27:03 +02:00
|
|
|
void kore_buf_appendb(struct kore_buf *, struct kore_buf *);
|
2013-09-26 16:49:44 +02:00
|
|
|
void kore_buf_replace_string(struct kore_buf *, char *, void *, size_t);
|
2013-05-02 15:14:00 +02:00
|
|
|
|
2013-05-01 21:16:09 +02:00
|
|
|
struct spdy_stream *spdy_stream_lookup(struct connection *, u_int32_t);
|
|
|
|
int spdy_stream_get_header(struct spdy_header_block *,
|
2014-08-04 09:48:41 +02:00
|
|
|
const char *, char **);
|
2013-10-25 11:10:03 +02:00
|
|
|
void spdy_update_wsize(struct connection *,
|
|
|
|
struct spdy_stream *, u_int32_t);
|
2013-05-01 12:23:21 +02:00
|
|
|
|
2013-05-01 08:09:04 +02:00
|
|
|
int spdy_frame_recv(struct netbuf *);
|
2014-08-08 14:18:15 +02:00
|
|
|
int spdy_dataframe_begin(struct connection *);
|
2013-07-13 19:56:38 +02:00
|
|
|
void spdy_session_teardown(struct connection *c, u_int8_t);
|
2013-05-02 14:47:02 +02:00
|
|
|
void spdy_frame_send(struct connection *, u_int16_t,
|
2013-05-02 17:30:06 +02:00
|
|
|
u_int8_t, u_int32_t, struct spdy_stream *, u_int32_t);
|
2013-05-01 12:23:21 +02:00
|
|
|
void spdy_header_block_add(struct spdy_header_block *,
|
|
|
|
char *, char *);
|
|
|
|
u_int8_t *spdy_header_block_release(struct connection *,
|
|
|
|
struct spdy_header_block *, u_int32_t *);
|
2014-08-10 18:17:06 +02:00
|
|
|
void spdy_stream_close(struct connection *,
|
|
|
|
struct spdy_stream *, int);
|
2013-04-28 19:11:44 +02:00
|
|
|
|
2014-08-08 14:18:15 +02:00
|
|
|
struct spdy_header_block *spdy_header_block_create(int);
|
|
|
|
|
2015-04-01 07:25:10 -04:00
|
|
|
#if defined(__cplusplus)
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-04-17 22:34:27 +02:00
|
|
|
#endif /* !__H_KORE_H */
|