-/* $OpenBSD: httpd.h,v 1.15 2014/07/25 23:30:58 reyk Exp $ */
+/* $OpenBSD: httpd.h,v 1.16 2014/07/29 12:16:36 reyk Exp $ */
/*
* Copyright (c) 2006 - 2014 Reyk Floeter <reyk@openbsd.org>
#define CONFIG_SERVERS 0x02
#define CONFIG_ALL 0xff
-#define TCPFLAG_NODELAY 0x01
-#define TCPFLAG_NNODELAY 0x02
-#define TCPFLAG_SACK 0x04
-#define TCPFLAG_NSACK 0x08
-#define TCPFLAG_BUFSIZ 0x10
-#define TCPFLAG_IPTTL 0x20
-#define TCPFLAG_IPMINTTL 0x40
-#define TCPFLAG_NSPLICE 0x80
-#define TCPFLAG_DEFAULT 0x00
-
-#define TCPFLAG_BITS \
- "\10\01NODELAY\02NO_NODELAY\03SACK\04NO_SACK" \
- "\05SOCKET_BUFFER_SIZE\06IP_TTL\07IP_MINTTL\10NO_SPLICE"
-
enum httpchunk {
TOREAD_UNLIMITED = -1,
TOREAD_HTTP_HEADER = -2,
};
SPLAY_HEAD(client_tree, client);
+#define TCPFLAG_NODELAY 0x01
+#define TCPFLAG_NNODELAY 0x02
+#define TCPFLAG_SACK 0x04
+#define TCPFLAG_NSACK 0x08
+#define TCPFLAG_BUFSIZ 0x10
+#define TCPFLAG_IPTTL 0x20
+#define TCPFLAG_IPMINTTL 0x40
+#define TCPFLAG_NSPLICE 0x80
+#define TCPFLAG_DEFAULT 0x00
+
+#define TCPFLAG_BITS \
+ "\10\01NODELAY\02NO_NODELAY\03SACK\04NO_SACK" \
+ "\05SOCKET_BUFFER_SIZE\06IP_TTL\07IP_MINTTL\10NO_SPLICE"
+
struct server_config {
u_int32_t id;
u_int32_t flags;
int prefixlen;
struct timeval timeout;
+ u_int8_t tcpflags;
+ int tcpbufsiz;
+ int tcpbacklog;
+ u_int8_t tcpipttl;
+ u_int8_t tcpipminttl;
+
TAILQ_ENTRY(server_config) entry;
};
TAILQ_HEAD(serverhosts, server_config);
struct server_config srv_conf;
struct serverhosts srv_hosts;
- u_int8_t srv_tcpflags;
- int srv_tcpbufsiz;
- int srv_tcpbacklog;
- u_int8_t srv_tcpipttl;
- u_int8_t srv_tcpipminttl;
-
int srv_s;
struct event srv_ev;
struct event srv_evt;
-/* $OpenBSD: server.c,v 1.13 2014/07/25 23:30:58 reyk Exp $ */
+/* $OpenBSD: server.c,v 1.14 2014/07/29 12:16:36 reyk Exp $ */
/*
* Copyright (c) 2006 - 2014 Reyk Floeter <reyk@openbsd.org>
void server_init(struct privsep *, struct privsep_proc *p, void *);
void server_launch(void);
int server_socket(struct sockaddr_storage *, in_port_t,
- struct server *, int, int);
+ struct server_config *, int, int);
int server_socket_listen(struct sockaddr_storage *, in_port_t,
- struct server *);
+ struct server_config *);
void server_accept(int, short, void *);
void server_input(struct client *);
log_debug("%s: adding server %s", __func__, srv->srv_conf.name);
if ((srv->srv_s = server_socket_listen(&srv->srv_conf.ss,
- srv->srv_conf.port, srv)) == -1)
+ srv->srv_conf.port, &srv->srv_conf)) == -1)
return (-1);
return (0);
int
server_socket(struct sockaddr_storage *ss, in_port_t port,
- struct server *srv, int fd, int reuseport)
+ struct server_config *srv_conf, int fd, int reuseport)
{
struct linger lng;
int s = -1, val;
}
if (fcntl(s, F_SETFL, O_NONBLOCK) == -1)
goto bad;
- if (srv->srv_tcpflags & TCPFLAG_BUFSIZ) {
- val = srv->srv_tcpbufsiz;
+ if (srv_conf->tcpflags & TCPFLAG_BUFSIZ) {
+ val = srv_conf->tcpbufsiz;
if (setsockopt(s, SOL_SOCKET, SO_RCVBUF,
&val, sizeof(val)) == -1)
goto bad;
- val = srv->srv_tcpbufsiz;
+ val = srv_conf->tcpbufsiz;
if (setsockopt(s, SOL_SOCKET, SO_SNDBUF,
&val, sizeof(val)) == -1)
goto bad;
/*
* IP options
*/
- if (srv->srv_tcpflags & TCPFLAG_IPTTL) {
- val = (int)srv->srv_tcpipttl;
+ if (srv_conf->tcpflags & TCPFLAG_IPTTL) {
+ val = (int)srv_conf->tcpipttl;
if (setsockopt(s, IPPROTO_IP, IP_TTL,
&val, sizeof(val)) == -1)
goto bad;
}
- if (srv->srv_tcpflags & TCPFLAG_IPMINTTL) {
- val = (int)srv->srv_tcpipminttl;
+ if (srv_conf->tcpflags & TCPFLAG_IPMINTTL) {
+ val = (int)srv_conf->tcpipminttl;
if (setsockopt(s, IPPROTO_IP, IP_MINTTL,
&val, sizeof(val)) == -1)
goto bad;
/*
* TCP options
*/
- if (srv->srv_tcpflags & (TCPFLAG_NODELAY|TCPFLAG_NNODELAY)) {
- if (srv->srv_tcpflags & TCPFLAG_NNODELAY)
+ if (srv_conf->tcpflags & (TCPFLAG_NODELAY|TCPFLAG_NNODELAY)) {
+ if (srv_conf->tcpflags & TCPFLAG_NNODELAY)
val = 0;
else
val = 1;
&val, sizeof(val)) == -1)
goto bad;
}
- if (srv->srv_tcpflags & (TCPFLAG_SACK|TCPFLAG_NSACK)) {
- if (srv->srv_tcpflags & TCPFLAG_NSACK)
+ if (srv_conf->tcpflags & (TCPFLAG_SACK|TCPFLAG_NSACK)) {
+ if (srv_conf->tcpflags & TCPFLAG_NSACK)
val = 0;
else
val = 1;
int
server_socket_listen(struct sockaddr_storage *ss, in_port_t port,
- struct server *srv)
+ struct server_config *srv_conf)
{
int s;
- if ((s = server_socket(ss, port, srv, -1, 1)) == -1)
+ if ((s = server_socket(ss, port, srv_conf, -1, 1)) == -1)
return (-1);
if (bind(s, (struct sockaddr *)ss, ss->ss_len) == -1)
goto bad;
- if (listen(s, srv->srv_tcpbacklog) == -1)
+ if (listen(s, srv_conf->tcpbacklog) == -1)
goto bad;
return (s);