summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorReyk Floeter <reyk@cvs.openbsd.org>2006-12-16 12:42:15 +0000
committerReyk Floeter <reyk@cvs.openbsd.org>2006-12-16 12:42:15 +0000
commit474330739d2effcf5f82056b412155be23b391fb (patch)
tree940e84afeb89de17ab45e525e29ed18e852e43fd
parent9fa0416a4ea8f7c2ebae2f738ee534787b8d0e48 (diff)
knf, spacing
please note that some editors will replace tabs with multiple spaces if you cut & paste code from other sections. please try to keep the tabs ;).
-rw-r--r--usr.sbin/hostated/check_http.c12
-rw-r--r--usr.sbin/hostated/check_tcp.c7
-rw-r--r--usr.sbin/hostated/control.c6
-rw-r--r--usr.sbin/hostated/hce.c137
-rw-r--r--usr.sbin/hostated/hostated.84
-rw-r--r--usr.sbin/hostated/hostated.c129
-rw-r--r--usr.sbin/hostated/hostated.conf.510
-rw-r--r--usr.sbin/hostated/hostated.h173
-rw-r--r--usr.sbin/hostated/parse.y82
-rw-r--r--usr.sbin/hostated/pfe.c94
-rw-r--r--usr.sbin/hostated/pfe_filter.c68
-rw-r--r--usr.sbin/hoststated/check_http.c12
-rw-r--r--usr.sbin/hoststated/check_tcp.c7
-rw-r--r--usr.sbin/hoststated/control.c6
-rw-r--r--usr.sbin/hoststated/hce.c137
-rw-r--r--usr.sbin/hoststated/hoststated.84
-rw-r--r--usr.sbin/hoststated/hoststated.c129
-rw-r--r--usr.sbin/hoststated/hoststated.conf.510
-rw-r--r--usr.sbin/hoststated/hoststated.h173
-rw-r--r--usr.sbin/hoststated/parse.y82
-rw-r--r--usr.sbin/hoststated/pfe.c94
-rw-r--r--usr.sbin/hoststated/pfe_filter.c68
-rw-r--r--usr.sbin/relayd/check_tcp.c7
-rw-r--r--usr.sbin/relayd/control.c6
-rw-r--r--usr.sbin/relayd/hce.c137
-rw-r--r--usr.sbin/relayd/parse.y82
-rw-r--r--usr.sbin/relayd/pfe.c94
-rw-r--r--usr.sbin/relayd/pfe_filter.c68
-rw-r--r--usr.sbin/relayd/relayd.84
-rw-r--r--usr.sbin/relayd/relayd.c129
-rw-r--r--usr.sbin/relayd/relayd.conf.510
-rw-r--r--usr.sbin/relayd/relayd.h173
32 files changed, 1080 insertions, 1074 deletions
diff --git a/usr.sbin/hostated/check_http.c b/usr.sbin/hostated/check_http.c
index 3d39ceebe27..5dc759e4c42 100644
--- a/usr.sbin/hostated/check_http.c
+++ b/usr.sbin/hostated/check_http.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: check_http.c,v 1.1 2006/12/16 11:45:07 reyk Exp $ */
+/* $OpenBSD: check_http.c,v 1.2 2006/12/16 12:42:14 reyk Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
*
@@ -43,8 +43,8 @@ http_request(struct host *host, struct table *table, int s, const char *req)
if ((fl = fcntl(s, F_GETFL, 0)) == -1)
fatal("http_request: cannot get flags for socket");
- if (fcntl(s, F_SETFL, fl & ~(O_NONBLOCK)) == -1)
- fatal("http_request: cannot set blocking socket");
+ if (fcntl(s, F_SETFL, fl & ~(O_NONBLOCK)) == -1)
+ fatal("http_request: cannot set blocking socket");
if ((buf = buf_dynamic(sizeof(rbuf), UINT_MAX)) == NULL)
fatalx("http_request: cannot create dynamic buffer");
@@ -126,7 +126,7 @@ check_http_digest(struct host *host, struct table *table)
head = buf->buf;
if ((head = strstr(head, "\r\n\r\n")) == NULL) {
log_debug("check_http_digest: host %u no end of headers",
- host->id);
+ host->id);
close(s);
return (HOST_DOWN);
}
@@ -137,8 +137,8 @@ check_http_digest(struct host *host, struct table *table)
if (strcmp(table->digest, digest)) {
log_warnx("check_http_digest: wrong digest for host %u",
- host->id);
- return(HOST_DOWN);
+ host->id);
+ return (HOST_DOWN);
}
return (HOST_UP);
}
diff --git a/usr.sbin/hostated/check_tcp.c b/usr.sbin/hostated/check_tcp.c
index 5ef386731f9..a0390326a7a 100644
--- a/usr.sbin/hostated/check_tcp.c
+++ b/usr.sbin/hostated/check_tcp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: check_tcp.c,v 1.1 2006/12/16 11:45:07 reyk Exp $ */
+/* $OpenBSD: check_tcp.c,v 1.2 2006/12/16 12:42:14 reyk Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -83,12 +83,13 @@ tcp_connect(struct host *host, struct table *table)
FD_ZERO(&fdset);
FD_SET(s, &fdset);
- switch(select(s + 1, NULL, &fdset, NULL, &tv)) {
+ /* XXX This needs to be rewritten */
+ switch (select(s + 1, NULL, &fdset, NULL, &tv)) {
case -1:
if (errno != EINTR)
fatal("check_tcp: select");
else
- return(HOST_UNKNOWN);
+ return (HOST_UNKNOWN);
case 0:
close(s);
return (HOST_DOWN);
diff --git a/usr.sbin/hostated/control.c b/usr.sbin/hostated/control.c
index 2f994e458f4..764053bafe4 100644
--- a/usr.sbin/hostated/control.c
+++ b/usr.sbin/hostated/control.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: control.c,v 1.1 2006/12/16 11:45:07 reyk Exp $ */
+/* $OpenBSD: control.c,v 1.2 2006/12/16 12:42:14 reyk Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -189,9 +189,9 @@ void
control_dispatch_imsg(int fd, short event, void *arg)
{
struct ctl_conn *c;
- struct imsg imsg;
+ struct imsg imsg;
objid_t id;
- int n;
+ int n;
if ((c = control_connbyfd(fd)) == NULL) {
log_warn("control_dispatch_imsg: fd %d: not found", fd);
diff --git a/usr.sbin/hostated/hce.c b/usr.sbin/hostated/hce.c
index 7144357538b..3bed9f206e3 100644
--- a/usr.sbin/hostated/hce.c
+++ b/usr.sbin/hostated/hce.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: hce.c,v 1.1 2006/12/16 11:45:07 reyk Exp $ */
+/* $OpenBSD: hce.c,v 1.2 2006/12/16 12:42:14 reyk Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -98,45 +98,45 @@ hce(struct hostated *x_env, int pipe_parent2pfe[2], int pipe_parent2hce[2],
setproctitle("host check engine");
hostated_process = PROC_HCE;
- if (setgroups(1, &pw->pw_gid) ||
- setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) ||
- setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid))
- fatal("hce: can't drop privileges");
+ if (setgroups(1, &pw->pw_gid) ||
+ setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) ||
+ setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid))
+ fatal("hce: can't drop privileges");
event_init();
- signal_set(&ev_sigint, SIGINT, hce_sig_handler, NULL);
- signal_set(&ev_sigterm, SIGTERM, hce_sig_handler, NULL);
- signal_add(&ev_sigint, NULL);
- signal_add(&ev_sigterm, NULL);
-
- /* setup pipes */
- close(pipe_pfe2hce[1]);
- close(pipe_parent2hce[0]);
- close(pipe_parent2pfe[0]);
- close(pipe_parent2pfe[1]);
-
- if ((ibuf_pfe = calloc(1, sizeof(struct imsgbuf))) == NULL ||
- (ibuf_main = calloc(1, sizeof(struct imsgbuf))) == NULL)
- fatal("hce");
- imsg_init(ibuf_pfe, pipe_pfe2hce[0], hce_dispatch_imsg);
- imsg_init(ibuf_main, pipe_parent2hce[1], hce_dispatch_parent);
-
- ibuf_pfe->events = EV_READ;
- event_set(&ibuf_pfe->ev, ibuf_pfe->fd, ibuf_pfe->events,
- ibuf_pfe->handler, ibuf_pfe);
- event_add(&ibuf_pfe->ev, NULL);
-
- ibuf_main->events = EV_READ;
- event_set(&ibuf_main->ev, ibuf_main->fd, ibuf_main->events,
- ibuf_main->handler, ibuf_main);
- event_add(&ibuf_main->ev, NULL);
-
- evtimer_set(&env->ev, hce_launch_checks, NULL);
+ signal_set(&ev_sigint, SIGINT, hce_sig_handler, NULL);
+ signal_set(&ev_sigterm, SIGTERM, hce_sig_handler, NULL);
+ signal_add(&ev_sigint, NULL);
+ signal_add(&ev_sigterm, NULL);
+
+ /* setup pipes */
+ close(pipe_pfe2hce[1]);
+ close(pipe_parent2hce[0]);
+ close(pipe_parent2pfe[0]);
+ close(pipe_parent2pfe[1]);
+
+ if ((ibuf_pfe = calloc(1, sizeof(struct imsgbuf))) == NULL ||
+ (ibuf_main = calloc(1, sizeof(struct imsgbuf))) == NULL)
+ fatal("hce");
+ imsg_init(ibuf_pfe, pipe_pfe2hce[0], hce_dispatch_imsg);
+ imsg_init(ibuf_main, pipe_parent2hce[1], hce_dispatch_parent);
+
+ ibuf_pfe->events = EV_READ;
+ event_set(&ibuf_pfe->ev, ibuf_pfe->fd, ibuf_pfe->events,
+ ibuf_pfe->handler, ibuf_pfe);
+ event_add(&ibuf_pfe->ev, NULL);
+
+ ibuf_main->events = EV_READ;
+ event_set(&ibuf_main->ev, ibuf_main->fd, ibuf_main->events,
+ ibuf_main->handler, ibuf_main);
+ event_add(&ibuf_main->ev, NULL);
+
+ evtimer_set(&env->ev, hce_launch_checks, NULL);
tv.tv_sec = env->interval;
tv.tv_usec = 0;
evtimer_add(&env->ev, &tv);
-
+
hce_launch_checks(0, 0, NULL);
event_dispatch();
@@ -149,8 +149,8 @@ void
hce_launch_checks(int fd, short event, void *arg)
{
int previous_up;
- struct host *host;
- struct table *table;
+ struct host *host;
+ struct table *table;
struct ctl_status st;
struct timeval tv;
@@ -168,8 +168,7 @@ hce_launch_checks(int fd, short event, void *arg)
switch (table->check) {
case CHECK_ICMP:
host->up = check_icmp(host, env->icmp_sock,
- env->icmp6_sock,
- table->timeout);
+ env->icmp6_sock, table->timeout);
break;
case CHECK_TCP:
host->up = check_tcp(host, table);
@@ -188,7 +187,7 @@ hce_launch_checks(int fd, short event, void *arg)
st.id = host->id;
st.up = host->up;
imsg_compose(ibuf_pfe, IMSG_HOST_STATUS, 0, 0,
- &st, sizeof(st));
+ &st, sizeof(st));
}
}
}
@@ -280,39 +279,39 @@ hce_dispatch_imsg(int fd, short event, void *ptr)
void
hce_dispatch_parent(int fd, short event, void * ptr)
{
- struct imsgbuf *ibuf;
- struct imsg imsg;
- ssize_t n;
+ struct imsgbuf *ibuf;
+ struct imsg imsg;
+ ssize_t n;
ibuf = ptr;
switch (event) {
- case EV_READ:
- if ((n = imsg_read(ibuf)) == -1)
- fatal("hce_dispatch_parent: imsg_read error");
- if (n == 0) /* connection closed */
- fatalx("hce_dispatch_parent: pipe closed");
- break;
- case EV_WRITE:
- if (msgbuf_write(&ibuf->w) == -1)
- fatal("hce_dispatch_parent: msgbuf_write");
- imsg_event_add(ibuf);
- return;
- default:
- fatalx("hce_dispatch_parent: unknown event");
+ case EV_READ:
+ if ((n = imsg_read(ibuf)) == -1)
+ fatal("hce_dispatch_parent: imsg_read error");
+ if (n == 0) /* connection closed */
+ fatalx("hce_dispatch_parent: pipe closed");
+ break;
+ case EV_WRITE:
+ if (msgbuf_write(&ibuf->w) == -1)
+ fatal("hce_dispatch_parent: msgbuf_write");
+ imsg_event_add(ibuf);
+ return;
+ default:
+ fatalx("hce_dispatch_parent: unknown event");
}
- for (;;) {
- if ((n = imsg_get(ibuf, &imsg)) == -1)
- fatal("hce_dispatch_parent: imsg_read error");
- if (n == 0)
- break;
-
- switch (imsg.hdr.type) {
- default:
- log_debug("hce_dispatch_parent: unexpected imsg %d",
- imsg.hdr.type);
- break;
- }
- imsg_free(&imsg);
- }
+ for (;;) {
+ if ((n = imsg_get(ibuf, &imsg)) == -1)
+ fatal("hce_dispatch_parent: imsg_read error");
+ if (n == 0)
+ break;
+
+ switch (imsg.hdr.type) {
+ default:
+ log_debug("hce_dispatch_parent: unexpected imsg %d",
+ imsg.hdr.type);
+ break;
+ }
+ imsg_free(&imsg);
+ }
}
diff --git a/usr.sbin/hostated/hostated.8 b/usr.sbin/hostated/hostated.8
index 8696bf6e2d5..ff8c587f978 100644
--- a/usr.sbin/hostated/hostated.8
+++ b/usr.sbin/hostated/hostated.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: hostated.8,v 1.2 2006/12/16 11:52:51 reyk Exp $
+.\" $OpenBSD: hostated.8,v 1.3 2006/12/16 12:42:14 reyk Exp $
.\"
.\" Copyright (c) 2006 Pierre-Yves Ritschard <pyr@openbsd.org>
.\"
@@ -37,7 +37,7 @@ To enable
.Nm
to install rulesets through the anchor you will
need the following line in the NAT section of your
-.Xr pf.conf 5
+.Xr pf.conf 5
configuration file:
.Bd -literal -offset 2n
rdr-anchor "hostated/*"
diff --git a/usr.sbin/hostated/hostated.c b/usr.sbin/hostated/hostated.c
index 32c0989c4cc..734db8d401b 100644
--- a/usr.sbin/hostated/hostated.c
+++ b/usr.sbin/hostated/hostated.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: hostated.c,v 1.1 2006/12/16 11:45:07 reyk Exp $ */
+/* $OpenBSD: hostated.c,v 1.2 2006/12/16 12:42:14 reyk Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -89,7 +89,7 @@ usage(void)
extern char *__progname;
fprintf(stderr, "%s [-dnv] [-f file]\n", __progname);
- exit (1);
+ exit(1);
}
int main(int argc, char *argv[])
@@ -98,7 +98,7 @@ int main(int argc, char *argv[])
int debug;
u_int32_t opts;
struct hostated env;
- const char *conffile;
+ const char *conffile;
struct event ev_sigint;
struct event ev_sigterm;
struct event ev_sigchld;
@@ -126,7 +126,6 @@ int main(int argc, char *argv[])
default:
usage();
}
-
}
log_init(debug);
@@ -166,7 +165,7 @@ int main(int argc, char *argv[])
pfe_pid = pfe(&env, pipe_parent2pfe, pipe_parent2hce, pipe_pfe2hce);
hce_pid = hce(&env, pipe_parent2pfe, pipe_parent2hce, pipe_pfe2hce);
-
+
setproctitle("parent");
event_init();
@@ -179,7 +178,7 @@ int main(int argc, char *argv[])
signal_add(&ev_sigterm, NULL);
signal_add(&ev_sigchld, NULL);
signal_add(&ev_sighup, NULL);
-
+
close(pipe_parent2pfe[1]);
close(pipe_parent2hce[1]);
close(pipe_pfe2hce[0]);
@@ -192,15 +191,15 @@ int main(int argc, char *argv[])
imsg_init(ibuf_pfe, pipe_parent2pfe[0], main_dispatch_pfe);
imsg_init(ibuf_hce, pipe_parent2hce[0], main_dispatch_hce);
- ibuf_pfe->events = EV_READ;
- event_set(&ibuf_pfe->ev, ibuf_pfe->fd, ibuf_pfe->events,
- ibuf_pfe->handler, ibuf_pfe);
- event_add(&ibuf_pfe->ev, NULL);
+ ibuf_pfe->events = EV_READ;
+ event_set(&ibuf_pfe->ev, ibuf_pfe->fd, ibuf_pfe->events,
+ ibuf_pfe->handler, ibuf_pfe);
+ event_add(&ibuf_pfe->ev, NULL);
- ibuf_hce->events = EV_READ;
- event_set(&ibuf_hce->ev, ibuf_hce->fd, ibuf_hce->events,
- ibuf_hce->handler, ibuf_hce);
- event_add(&ibuf_hce->ev, NULL);
+ ibuf_hce->events = EV_READ;
+ event_set(&ibuf_hce->ev, ibuf_hce->fd, ibuf_hce->events,
+ ibuf_hce->handler, ibuf_hce);
+ event_add(&ibuf_hce->ev, NULL);
event_dispatch();
@@ -217,11 +216,11 @@ main_shutdown(void)
if (hce_pid)
kill(hce_pid, SIGTERM);
- do {
- if ((pid = wait(NULL)) == -1 &&
- errno != EINTR && errno != ECHILD)
- fatal("wait");
- } while (pid != -1 || (pid == -1 && errno == EINTR));
+ do {
+ if ((pid = wait(NULL)) == -1 &&
+ errno != EINTR && errno != ECHILD)
+ fatal("wait");
+ } while (pid != -1 || (pid == -1 && errno == EINTR));
control_cleanup();
log_info("terminating");
@@ -231,21 +230,21 @@ main_shutdown(void)
int
check_child(pid_t pid, const char *pname)
{
- int status;
-
- if (waitpid(pid, &status, WNOHANG) > 0) {
- if (WIFEXITED(status)) {
- log_warnx("check_child: lost child: %s exited", pname);
- return (1);
- }
- if (WIFSIGNALED(status)) {
- log_warnx("check_child: lost child: %s terminated; signal %d",
- pname, WTERMSIG(status));
- return (1);
- }
- }
-
- return (0);
+ int status;
+
+ if (waitpid(pid, &status, WNOHANG) > 0) {
+ if (WIFEXITED(status)) {
+ log_warnx("check_child: lost child: %s exited", pname);
+ return (1);
+ }
+ if (WIFSIGNALED(status)) {
+ log_warnx("check_child: lost child: %s terminated; "
+ "signal %d", pname, WTERMSIG(status));
+ return (1);
+ }
+ }
+
+ return (0);
}
void
@@ -256,8 +255,8 @@ imsg_event_add(struct imsgbuf *ibuf)
ibuf->events |= EV_WRITE;
event_del(&ibuf->ev);
- event_set(&ibuf->ev, ibuf->fd, ibuf->events, ibuf->handler, ibuf);
- event_add(&ibuf->ev, NULL);
+ event_set(&ibuf->ev, ibuf->fd, ibuf->events, ibuf->handler, ibuf);
+ event_add(&ibuf->ev, NULL);
}
void
@@ -305,40 +304,40 @@ void
main_dispatch_hce(int fd, short event, void * ptr)
{
struct imsgbuf *ibuf;
- struct imsg imsg;
- ssize_t n;
+ struct imsg imsg;
+ ssize_t n;
ibuf = ptr;
switch (event) {
- case EV_READ:
- if ((n = imsg_read(ibuf)) == -1)
- fatal("imsg_read error");
- if (n == 0) /* connection closed */
- fatalx("parent: pipe closed");
- break;
- case EV_WRITE:
- if (msgbuf_write(&ibuf->w) == -1)
- fatal("msgbuf_write");
- imsg_event_add(ibuf);
- return;
- default:
- fatalx("unknown event");
+ case EV_READ:
+ if ((n = imsg_read(ibuf)) == -1)
+ fatal("imsg_read error");
+ if (n == 0) /* connection closed */
+ fatalx("parent: pipe closed");
+ break;
+ case EV_WRITE:
+ if (msgbuf_write(&ibuf->w) == -1)
+ fatal("msgbuf_write");
+ imsg_event_add(ibuf);
+ return;
+ default:
+ fatalx("unknown event");
}
- for (;;) {
- if ((n = imsg_get(ibuf, &imsg)) == -1)
- fatal("main_dispatch_hce: imsg_read error");
- if (n == 0)
- break;
-
- switch (imsg.hdr.type) {
- default:
- log_debug("main_dispatch_hce: unexpected imsg %d",
- imsg.hdr.type);
- break;
- }
- imsg_free(&imsg);
- }
+ for (;;) {
+ if ((n = imsg_get(ibuf, &imsg)) == -1)
+ fatal("main_dispatch_hce: imsg_read error");
+ if (n == 0)
+ break;
+
+ switch (imsg.hdr.type) {
+ default:
+ log_debug("main_dispatch_hce: unexpected imsg %d",
+ imsg.hdr.type);
+ break;
+ }
+ imsg_free(&imsg);
+ }
}
struct host *
diff --git a/usr.sbin/hostated/hostated.conf.5 b/usr.sbin/hostated/hostated.conf.5
index 93addf71f15..4b41e0b26b3 100644
--- a/usr.sbin/hostated/hostated.conf.5
+++ b/usr.sbin/hostated/hostated.conf.5
@@ -1,4 +1,4 @@
-.\" $OpenBSD: hostated.conf.5,v 1.2 2006/12/16 11:52:51 reyk Exp $
+.\" $OpenBSD: hostated.conf.5,v 1.3 2006/12/16 12:42:14 reyk Exp $
.\"
.\" Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
.\"
@@ -23,7 +23,7 @@
.Sh DESCRIPTION
The
.Xr hostated 8
-daemon maintains
+daemon maintains
.Xr pf 4
tables up to date.
.Sh SECTIONS
@@ -38,7 +38,7 @@ configuration file.
Global settings for
.Xr hostated 8 .
.It Sy Tables
-Table definitions describe the content of a
+Table definitions describe the content of a
.Xr pf 4
table and the method used for checking the health of the hosts
they contain.
@@ -135,7 +135,7 @@ The table can be later enabled through
.Sh SERVICES
Services represent a
.Xr pf 4
-rdr rule, they are used to specify which addresses will be redirected
+rdr rule, they are used to specify which addresses will be redirected
to the hosts in the specified tables.
The configuration directives that are valid in this context are described
below.
@@ -198,7 +198,7 @@ table sorryhost {
host sorryhost.private.example.com
}
-service www {
+service www {
virtual ip www.example.com port 8080 interface trunk0
virtual ip www6.example.com port 80 interface trunk0
diff --git a/usr.sbin/hostated/hostated.h b/usr.sbin/hostated/hostated.h
index d59a934be48..0191df4100c 100644
--- a/usr.sbin/hostated/hostated.h
+++ b/usr.sbin/hostated/hostated.h
@@ -32,38 +32,38 @@
/* buffer */
struct buf {
- TAILQ_ENTRY(buf) entry;
- u_char *buf;
- size_t size;
- size_t max;
- size_t wpos;
- size_t rpos;
+ TAILQ_ENTRY(buf) entry;
+ u_char *buf;
+ size_t size;
+ size_t max;
+ size_t wpos;
+ size_t rpos;
};
struct msgbuf {
- TAILQ_HEAD(, buf) bufs;
- u_int32_t queued;
- int fd;
+ TAILQ_HEAD(, buf) bufs;
+ u_int32_t queued;
+ int fd;
};
-#define IMSG_HEADER_SIZE sizeof(struct imsg_hdr)
-#define MAX_IMSGSIZE 8192
+#define IMSG_HEADER_SIZE sizeof(struct imsg_hdr)
+#define MAX_IMSGSIZE 8192
-struct buf_read {
- u_char buf[READ_BUF_SIZE];
- u_char *rptr;
- size_t wpos;
+struct buf_read {
+ u_char buf[READ_BUF_SIZE];
+ u_char *rptr;
+ size_t wpos;
};
struct imsgbuf {
- TAILQ_HEAD(, imsg_fd) fds;
- struct buf_read r;
- struct msgbuf w;
- struct event ev;
- void (*handler)(int, short, void *);
- int fd;
- pid_t pid;
- short events;
+ TAILQ_HEAD(, imsg_fd) fds;
+ struct buf_read r;
+ struct msgbuf w;
+ struct event ev;
+ void (*handler)(int, short, void *);
+ int fd;
+ pid_t pid;
+ short events;
};
enum imsg_type {
@@ -95,18 +95,18 @@ enum imsg_type {
};
struct imsg_hdr {
- enum imsg_type type;
- u_int16_t len;
- u_int32_t peerid;
- pid_t pid;
+ enum imsg_type type;
+ u_int16_t len;
+ u_int32_t peerid;
+ pid_t pid;
};
struct imsg {
- struct imsg_hdr hdr;
- void *data;
+ struct imsg_hdr hdr;
+ void *data;
};
-typedef u_int32_t objid_t;
+typedef u_int32_t objid_t;
struct ctl_status {
objid_t id;
@@ -121,14 +121,14 @@ struct address {
};
TAILQ_HEAD(addresslist, address);
-#define F_DISABLE 0x01
-#define F_BACKUP 0x02
-#define F_USED 0x04
-#define F_ACTIVE_RULESET 0x04
-#define F_DOWN 0x08
-#define F_ADD 0x10
-#define F_DEL 0x20
-#define F_CHANGED 0x40
+#define F_DISABLE 0x01
+#define F_BACKUP 0x02
+#define F_USED 0x04
+#define F_ACTIVE_RULESET 0x04
+#define F_DOWN 0x08
+#define F_ADD 0x10
+#define F_DEL 0x20
+#define F_CHANGED 0x40
struct host {
u_int8_t flags;
@@ -137,27 +137,23 @@ struct host {
char *tablename;
char name[MAXHOSTNAMELEN];
int up;
-#define HOST_DOWN -1
-#define HOST_UNKNOWN 0
-#define HOST_UP 1
struct sockaddr_storage ss;
TAILQ_ENTRY(host) entry;
};
TAILQ_HEAD(hostlist, host);
+#define HOST_DOWN -1
+#define HOST_UNKNOWN 0
+#define HOST_UP 1
+
struct table {
objid_t id;
objid_t serviceid;
u_int8_t flags;
int check;
-#define CHECK_NOCHECK 0
-#define CHECK_ICMP 1
-#define CHECK_TCP 2
-#define CHECK_HTTP_CODE 3
-#define CHECK_HTTP_DIGEST 4
int up;
in_port_t port;
- int retcode;
+ int retcode;
int timeout;
char name[TABLE_NAME_SIZE];
char path[MAXPATHLEN];
@@ -167,6 +163,12 @@ struct table {
};
TAILQ_HEAD(tablelist, table);
+#define CHECK_NOCHECK 0
+#define CHECK_ICMP 1
+#define CHECK_TCP 2
+#define CHECK_HTTP_CODE 3
+#define CHECK_HTTP_DIGEST 4
+
struct service {
objid_t id;
u_int8_t flags;
@@ -187,9 +189,7 @@ enum {
} hostated_process;
struct hostated {
- u_int8_t opts;
-#define HOSTATED_OPT_VERBOSE 0x01
-#define HOSTATED_OPT_NOACTION 0x04
+ u_int8_t opts;
struct pfdata *pf;
int interval;
int icmp_sock;
@@ -202,20 +202,23 @@ struct hostated {
struct servicelist services;
};
+#define HOSTATED_OPT_VERBOSE 0x01
+#define HOSTATED_OPT_NOACTION 0x04
+
/* initially control.h */
struct {
- struct event ev;
- int fd;
+ struct event ev;
+ int fd;
} control_state;
enum blockmodes {
- BM_NORMAL,
- BM_NONBLOCK
+ BM_NORMAL,
+ BM_NONBLOCK
};
struct ctl_conn {
- TAILQ_ENTRY(ctl_conn) entry;
- struct imsgbuf ibuf;
+ TAILQ_ENTRY(ctl_conn) entry;
+ struct imsgbuf ibuf;
};
TAILQ_HEAD(ctl_connlist, ctl_conn);
@@ -233,41 +236,41 @@ void session_socket_blockmode(int, enum blockmodes);
extern struct ctl_connlist ctl_conns;
/* parse.y */
-int parse_config(struct hostated *, const char *, int);
+int parse_config(struct hostated *, const char *, int);
/* log.c */
-void log_init(int);
-void log_warn(const char *, ...);
-void log_warnx(const char *, ...);
-void log_info(const char *, ...);
-void log_debug(const char *, ...);
-void fatal(const char *);
-void fatalx(const char *);
+void log_init(int);
+void log_warn(const char *, ...);
+void log_warnx(const char *, ...);
+void log_info(const char *, ...);
+void log_debug(const char *, ...);
+void fatal(const char *);
+void fatalx(const char *);
/* buffer.c */
-struct buf *buf_open(size_t);
-struct buf *buf_dynamic(size_t, size_t);
-int buf_add(struct buf *, void *, size_t);
-void *buf_reserve(struct buf *, size_t);
-void *buf_seek(struct buf *, size_t, size_t);
-int buf_close(struct msgbuf *, struct buf *);
-void buf_free(struct buf *);
-void msgbuf_init(struct msgbuf *);
-void msgbuf_clear(struct msgbuf *);
-int msgbuf_write(struct msgbuf *);
+struct buf *buf_open(size_t);
+struct buf *buf_dynamic(size_t, size_t);
+int buf_add(struct buf *, void *, size_t);
+void *buf_reserve(struct buf *, size_t);
+void *buf_seek(struct buf *, size_t, size_t);
+int buf_close(struct msgbuf *, struct buf *);
+void buf_free(struct buf *);
+void msgbuf_init(struct msgbuf *);
+void msgbuf_clear(struct msgbuf *);
+int msgbuf_write(struct msgbuf *);
/* imsg.c */
-void imsg_init(struct imsgbuf *, int, void (*)(int, short, void *));
-ssize_t imsg_read(struct imsgbuf *);
-ssize_t imsg_get(struct imsgbuf *, struct imsg *);
-int imsg_compose(struct imsgbuf *, enum imsg_type, u_int32_t, pid_t,
- void *, u_int16_t);
-struct buf *imsg_create(struct imsgbuf *, enum imsg_type, u_int32_t, pid_t,
- u_int16_t);
-int imsg_add(struct buf *, void *, u_int16_t);
-int imsg_close(struct imsgbuf *, struct buf *);
-void imsg_free(struct imsg *);
-void imsg_event_add(struct imsgbuf *); /* needs to be provided externally */
+void imsg_init(struct imsgbuf *, int, void (*)(int, short, void *));
+ssize_t imsg_read(struct imsgbuf *);
+ssize_t imsg_get(struct imsgbuf *, struct imsg *);
+int imsg_compose(struct imsgbuf *, enum imsg_type, u_int32_t, pid_t,
+ void *, u_int16_t);
+struct buf *imsg_create(struct imsgbuf *, enum imsg_type, u_int32_t, pid_t,
+ u_int16_t);
+int imsg_add(struct buf *, void *, u_int16_t);
+int imsg_close(struct imsgbuf *, struct buf *);
+void imsg_free(struct imsg *);
+void imsg_event_add(struct imsgbuf *); /* needs to be provided externally */
/* pfe.c */
pid_t pfe(struct hostated *, int [2], int [2], int [2]);
diff --git a/usr.sbin/hostated/parse.y b/usr.sbin/hostated/parse.y
index 977b7a74cb1..f2e008340ff 100644
--- a/usr.sbin/hostated/parse.y
+++ b/usr.sbin/hostated/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.1 2006/12/16 11:45:07 reyk Exp $ */
+/* $OpenBSD: parse.y,v 1.2 2006/12/16 12:42:14 reyk Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -74,16 +74,16 @@ struct sym {
char *val;
};
-int symset(const char *, const char *, int);
-char *symget(const char *);
-int cmdline_symset(char *);
+int symset(const char *, const char *, int);
+char *symget(const char *);
+int cmdline_symset(char *);
struct address *host_v4(const char *);
struct address *host_v6(const char *);
int host_dns(const char *, struct addresslist *,
- int, in_port_t, const char *);
+ int, in_port_t, const char *);
int host(const char *, struct addresslist *,
- int, in_port_t, const char *);
+ int, in_port_t, const char *);
typedef struct {
union {
@@ -117,7 +117,7 @@ grammar : /* empty */
| grammar error '\n' { errors++; }
;
-number : STRING {
+number : STRING {
const char *estr;
$$ = strtonum($1, 0, UINT_MAX, &estr);
@@ -142,7 +142,7 @@ varset : STRING '=' STRING {
main : INTERVAL number { conf->interval = $2; }
;
-service : SERVICE STRING {
+service : SERVICE STRING {
struct service *srv;
TAILQ_FOREACH(srv, &conf->services, entry)
@@ -156,12 +156,12 @@ service : SERVICE STRING {
if ((srv = calloc(1, sizeof (*srv))) == NULL)
fatal("out of memory");
- if (strlcpy(srv->name, $2, sizeof (srv->name)) >=
- sizeof (srv->name)) {
+ if (strlcpy(srv->name, $2, sizeof(srv->name)) >=
+ sizeof(srv->name)) {
yyerror("service name truncated");
YYERROR;
}
- free ($2);
+ free($2);
srv->id = last_service_id++;
if (last_service_id == UINT_MAX) {
yyerror("too many services defined");
@@ -183,13 +183,13 @@ service : SERVICE STRING {
if (service->backup == NULL)
service->backup = &conf->empty_table;
else if (service->backup->port !=
- service->table->port) {
+ service->table->port) {
yyerror("service %s uses two different ports "
- "for its table and backup table",
- service->name);
+ "for its table and backup table",
+ service->name);
YYERROR;
}
-
+
if (!(service->flags & F_DISABLE))
service->flags |= F_ADD;
TAILQ_INSERT_HEAD(&conf->services, service, entry);
@@ -200,7 +200,7 @@ serviceopts_l : serviceopts_l serviceoptsl nl
| serviceoptsl optnl
;
-serviceoptsl : TABLE STRING {
+serviceoptsl : TABLE STRING {
struct table *tb;
TAILQ_FOREACH(tb, &conf->tables, entry)
@@ -217,7 +217,7 @@ serviceoptsl : TABLE STRING {
free($2);
}
}
- | BACKUP TABLE STRING {
+ | BACKUP TABLE STRING {
struct table *tb;
if (service->backup) {
@@ -270,7 +270,7 @@ serviceoptsl : TABLE STRING {
}
;
-table : TABLE STRING {
+table : TABLE STRING {
struct table *tb;
TAILQ_FOREACH(tb, &conf->tables, entry)
@@ -281,12 +281,12 @@ table : TABLE STRING {
free($2);
YYERROR;
}
-
+
if ((tb = calloc(1, sizeof (*tb))) == NULL)
fatal("out of memory");
-
- if (strlcpy(tb->name, $2, sizeof (tb->name)) >=
- sizeof (tb->name)) {
+
+ if (strlcpy(tb->name, $2, sizeof(tb->name)) >=
+ sizeof(tb->name)) {
yyerror("table name truncated");
YYERROR;
}
@@ -296,9 +296,9 @@ table : TABLE STRING {
yyerror("too many tables defined");
YYERROR;
}
- free ($2);
+ free($2);
table = tb;
- } '{' optnl tableopts_l '}' {
+ } '{' optnl tableopts_l '}' {
if (table->port == 0) {
yyerror("table %s has no port", table->name);
YYERROR;
@@ -320,25 +320,25 @@ tableopts_l : tableopts_l tableoptsl nl
| tableoptsl optnl
;
-tableoptsl : host {
+tableoptsl : host {
$1->tableid = table->id;
$1->tablename = table->name;
TAILQ_INSERT_HEAD(&table->hosts, $1, entry);
}
- | TIMEOUT number {
+ | TIMEOUT number {
table->timeout = $2;
}
- | CHECK ICMP {
+ | CHECK ICMP {
table->check = CHECK_ICMP;
}
- | CHECK TCP {
+ | CHECK TCP {
table->check = CHECK_TCP;
}
| CHECK HTTP STRING CODE number {
table->check = CHECK_HTTP_CODE;
table->retcode = $5;
- if (strlcpy(table->path, $3, sizeof (table->path)) >=
- sizeof (table->path)) {
+ if (strlcpy(table->path, $3, sizeof(table->path)) >=
+ sizeof(table->path)) {
yyerror("http path truncated");
free($3);
YYERROR;
@@ -346,8 +346,8 @@ tableoptsl : host {
}
| CHECK HTTP STRING DIGEST STRING {
table->check = CHECK_HTTP_DIGEST;
- if (strlcpy(table->path, $3, sizeof (table->path)) >=
- sizeof (table->path)) {
+ if (strlcpy(table->path, $3, sizeof(table->path)) >=
+ sizeof(table->path)) {
yyerror("http path truncated");
free($3);
free($5);
@@ -378,12 +378,12 @@ interface : /*empty*/ { $$ = NULL; }
;
host : HOST STRING {
- struct host *r;
+ struct host *r;
struct address *a;
struct addresslist al;
- if ((r = calloc(1, sizeof (*r))) == NULL)
- fatal("out of memory");
+ if ((r = calloc(1, sizeof(*r))) == NULL)
+ fatal("out of memory");
TAILQ_INIT(&al);
if (host($2, &al, 1, 0, NULL) <= 0) {
@@ -395,8 +395,8 @@ host : HOST STRING {
memcpy(&r->ss, &a->ss, sizeof(r->ss));
free(a);
- if (strlcpy(r->name, $2, sizeof (r->name)) >=
- sizeof (r->name)) {
+ if (strlcpy(r->name, $2, sizeof(r->name)) >=
+ sizeof(r->name)) {
yyerror("host name truncated");
free($2);
YYERROR;
@@ -683,7 +683,7 @@ parse_config(struct hostated *x_conf, const char *filename, int opts)
conf->empty_table.id = EMPTY_TABLE;
conf->empty_table.flags |= F_DISABLE;
(void)strlcpy(conf->empty_table.name, "empty",
- sizeof(conf->empty_table.name));
+ sizeof(conf->empty_table.name));
conf->interval = CHECK_INTERVAL;
conf->opts = opts;
@@ -835,7 +835,7 @@ host_v6(const char *s)
bzero(&ina6, sizeof(ina6));
if (inet_pton(AF_INET6, s, &ina6) != 1)
return (NULL);
-
+
if ((h = calloc(1, sizeof(*h))) == NULL)
fatal(NULL);
sin6 = (struct sockaddr_in6 *)&h->ss;
@@ -912,7 +912,7 @@ host(const char *s, struct addresslist *al, int max,
in_port_t port, const char *ifname)
{
struct address *h;
-
+
h = host_v4(s);
/* IPv6 address? */
@@ -928,7 +928,7 @@ host(const char *s, struct addresslist *al, int max,
return (-1);
}
}
-
+
TAILQ_INSERT_HEAD(al, h, entry);
return (1);
}
diff --git a/usr.sbin/hostated/pfe.c b/usr.sbin/hostated/pfe.c
index 0a7ff43949f..3fe5f29039a 100644
--- a/usr.sbin/hostated/pfe.c
+++ b/usr.sbin/hostated/pfe.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pfe.c,v 1.1 2006/12/16 11:45:07 reyk Exp $ */
+/* $OpenBSD: pfe.c,v 1.2 2006/12/16 12:42:14 reyk Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -94,10 +94,10 @@ pfe(struct hostated *x_env, int pipe_parent2pfe[2], int pipe_parent2hce[2],
setproctitle("pf update engine");
hostated_process = PROC_PFE;
- if (setgroups(1, &pw->pw_gid) ||
- setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) ||
- setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid))
- fatal("pfe: cannot drop privileges");
+ if (setgroups(1, &pw->pw_gid) ||
+ setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) ||
+ setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid))
+ fatal("pfe: cannot drop privileges");
event_init();
@@ -115,17 +115,17 @@ pfe(struct hostated *x_env, int pipe_parent2pfe[2], int pipe_parent2hce[2],
if ((ibuf_hce = calloc(1, sizeof(struct imsgbuf))) == NULL ||
(ibuf_main = calloc(1, sizeof(struct imsgbuf))) == NULL)
fatal("pfe");
- imsg_init(ibuf_hce, pipe_pfe2hce[1], pfe_dispatch_imsg);
- imsg_init(ibuf_main, pipe_parent2pfe[1], pfe_dispatch_parent);
+ imsg_init(ibuf_hce, pipe_pfe2hce[1], pfe_dispatch_imsg);
+ imsg_init(ibuf_main, pipe_parent2pfe[1], pfe_dispatch_parent);
ibuf_hce->events = EV_READ;
event_set(&ibuf_hce->ev, ibuf_hce->fd, ibuf_hce->events,
- ibuf_hce->handler, ibuf_hce);
+ ibuf_hce->handler, ibuf_hce);
event_add(&ibuf_hce->ev, NULL);
ibuf_main->events = EV_READ;
event_set(&ibuf_main->ev, ibuf_main->fd, ibuf_main->events,
- ibuf_main->handler, ibuf_main);
+ ibuf_main->handler, ibuf_main);
event_add(&ibuf_main->ev, NULL);
TAILQ_INIT(&ctl_conns);
@@ -188,7 +188,7 @@ pfe_dispatch_imsg(int fd, short event, void *ptr)
fatalx("pfe_dispatch_imsg: invalid host id");
if (host->up == st.up) {
log_debug("pfe_dispatch_imsg: host %d => %d",
- host->id, host->up);
+ host->id, host->up);
fatalx("pfe_dispatch_imsg: desynchronized");
}
@@ -196,7 +196,7 @@ pfe_dispatch_imsg(int fd, short event, void *ptr)
fatalx("pfe_dispatch_imsg: invalid table id");
log_debug("pfe_dispatch_imsg: state %d for host %u %s",
- st.up, host->id, host->name);
+ st.up, host->id, host->name);
if ((st.up == HOST_UNKNOWN && host->up == HOST_DOWN) ||
(st.up == HOST_DOWN && host->up == HOST_UNKNOWN)) {
@@ -222,7 +222,7 @@ pfe_dispatch_imsg(int fd, short event, void *ptr)
break;
default:
log_debug("pfe_dispatch_imsg: unexpected imsg %d",
- imsg.hdr.type);
+ imsg.hdr.type);
break;
}
imsg_free(&imsg);
@@ -234,40 +234,40 @@ void
pfe_dispatch_parent(int fd, short event, void * ptr)
{
struct imsgbuf *ibuf;
- struct imsg imsg;
- ssize_t n;
+ struct imsg imsg;
+ ssize_t n;
ibuf = ptr;
switch (event) {
- case EV_READ:
- if ((n = imsg_read(ibuf)) == -1)
- fatal("imsg_read error");
- if (n == 0) /* connection closed */
- fatalx("pfe_dispatch_parent: pipe closed");
- break;
- case EV_WRITE:
- if (msgbuf_write(&ibuf->w) == -1)
- fatal("msgbuf_write");
- imsg_event_add(ibuf);
- return;
- default:
- fatalx("pfe_dispatch_parent: unknown event");
+ case EV_READ:
+ if ((n = imsg_read(ibuf)) == -1)
+ fatal("imsg_read error");
+ if (n == 0) /* connection closed */
+ fatalx("pfe_dispatch_parent: pipe closed");
+ break;
+ case EV_WRITE:
+ if (msgbuf_write(&ibuf->w) == -1)
+ fatal("msgbuf_write");
+ imsg_event_add(ibuf);
+ return;
+ default:
+ fatalx("pfe_dispatch_parent: unknown event");
}
- for (;;) {
- if ((n = imsg_get(ibuf, &imsg)) == -1)
- fatal("pfe_dispatch_parent: imsg_read error");
- if (n == 0)
- break;
-
- switch (imsg.hdr.type) {
- default:
- log_debug("pfe_dispatch_parent: unexpected imsg %d",
- imsg.hdr.type);
- break;
- }
- imsg_free(&imsg);
- }
+ for (;;) {
+ if ((n = imsg_get(ibuf, &imsg)) == -1)
+ fatal("pfe_dispatch_parent: imsg_read error");
+ if (n == 0)
+ break;
+
+ switch (imsg.hdr.type) {
+ default:
+ log_debug("pfe_dispatch_parent: unexpected imsg %d",
+ imsg.hdr.type);
+ break;
+ }
+ imsg_free(&imsg);
+ }
}
void
@@ -278,25 +278,25 @@ show(struct ctl_conn *c)
TAILQ_FOREACH(service, &env->services, entry) {
imsg_compose(&c->ibuf, IMSG_CTL_SERVICE, 0, 0,
- service, sizeof(*service));
+ service, sizeof(*service));
if (service->flags & F_DISABLE)
continue;
imsg_compose(&c->ibuf, IMSG_CTL_TABLE, 0, 0,
- service->table, sizeof(*service->table));
+ service->table, sizeof(*service->table));
if (!(service->table->flags & F_DISABLE))
TAILQ_FOREACH(host, &service->table->hosts, entry)
imsg_compose(&c->ibuf, IMSG_CTL_HOST, 0, 0,
- host, sizeof(*host));
+ host, sizeof(*host));
if (service->backup->id == EMPTY_TABLE)
continue;
imsg_compose(&c->ibuf, IMSG_CTL_TABLE, 0, 0,
- service->backup, sizeof(*service->backup));
+ service->backup, sizeof(*service->backup));
if (!(service->backup->flags & F_DISABLE))
TAILQ_FOREACH(host, &service->backup->hosts, entry)
imsg_compose(&c->ibuf, IMSG_CTL_HOST, 0, 0,
- host, sizeof(*host));
+ host, sizeof(*host));
}
imsg_compose(&c->ibuf, IMSG_CTL_END, 0, 0, NULL, 0);
}
@@ -480,7 +480,7 @@ pfe_sync(void)
service->table->flags &= ~(F_CHANGED);
service->backup->flags &= ~(F_CHANGED);
-
+
if (service->flags & F_DOWN) {
if (service->flags & F_ACTIVE_RULESET) {
flush_table(env, service);
diff --git a/usr.sbin/hostated/pfe_filter.c b/usr.sbin/hostated/pfe_filter.c
index b7bd7550070..89ea50b48c5 100644
--- a/usr.sbin/hostated/pfe_filter.c
+++ b/usr.sbin/hostated/pfe_filter.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pfe_filter.c,v 1.1 2006/12/16 11:45:07 reyk Exp $ */
+/* $OpenBSD: pfe_filter.c,v 1.2 2006/12/16 12:42:14 reyk Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -52,7 +52,7 @@ void
init_filter(struct hostated *env)
{
struct pf_status status;
-
+
if ((env->pf = calloc(1, sizeof(*(env->pf)))) == NULL)
fatal("calloc");
if ((env->pf->dev = open(PF_SOCKET, O_RDWR)) == -1)
@@ -75,14 +75,14 @@ init_tables(struct hostated *env)
if ((tables = calloc(env->servicecount, sizeof(*tables))) == NULL)
fatal("calloc");
i = 0;
-
+
TAILQ_FOREACH(service, &env->services, entry) {
(void)strlcpy(tables[i].pfrt_anchor, HOSTATED_ANCHOR "/",
- sizeof(tables[i].pfrt_anchor));
+ sizeof(tables[i].pfrt_anchor));
(void)strlcat(tables[i].pfrt_anchor, service->name,
- sizeof(tables[i].pfrt_anchor));
+ sizeof(tables[i].pfrt_anchor));
(void)strlcpy(tables[i].pfrt_name, service->name,
- sizeof(tables[i].pfrt_name));
+ sizeof(tables[i].pfrt_name));
tables[i].pfrt_flags |= PFR_TFLAG_PERSIST;
i++;
}
@@ -116,9 +116,9 @@ kill_tables(struct hostated *env) {
memset(&io, 0, sizeof(io));
TAILQ_FOREACH(service, &env->services, entry) {
(void)strlcpy(io.pfrio_table.pfrt_anchor, HOSTATED_ANCHOR "/",
- sizeof(io.pfrio_table.pfrt_anchor));
+ sizeof(io.pfrio_table.pfrt_anchor));
(void)strlcat(io.pfrio_table.pfrt_anchor, service->name,
- sizeof(io.pfrio_table.pfrt_anchor));
+ sizeof(io.pfrio_table.pfrt_anchor));
if (ioctl(env->pf->dev, DIOCRCLRTABLES, &io) == -1)
fatal("kill_tables: ioctl faile: ioctl failed");
}
@@ -152,11 +152,11 @@ sync_table(struct hostated *env, struct service *service, struct table *table)
io.pfrio_size2 = 0;
io.pfrio_buffer = addlist;
(void)strlcpy(io.pfrio_table.pfrt_anchor, HOSTATED_ANCHOR "/",
- sizeof(io.pfrio_table.pfrt_anchor));
+ sizeof(io.pfrio_table.pfrt_anchor));
(void)strlcat(io.pfrio_table.pfrt_anchor, service->name,
- sizeof(io.pfrio_table.pfrt_anchor));
+ sizeof(io.pfrio_table.pfrt_anchor));
(void)strlcpy(io.pfrio_table.pfrt_name, service->name,
- sizeof(io.pfrio_table.pfrt_name));
+ sizeof(io.pfrio_table.pfrt_name));
i = 0;
TAILQ_FOREACH(host, &table->hosts, entry) {
@@ -168,14 +168,14 @@ sync_table(struct hostated *env, struct service *service, struct table *table)
sain = (struct sockaddr_in *)&host->ss;
addlist[i].pfra_af = AF_INET;
memcpy(&(addlist[i].pfra_ip4addr), &sain->sin_addr,
- sizeof(sain->sin_addr));
+ sizeof(sain->sin_addr));
addlist[i].pfra_net = 32;
break;
case AF_INET6:
sain6 = (struct sockaddr_in6 *)&host->ss;
addlist[i].pfra_af = AF_INET6;
memcpy(&(addlist[i].pfra_ip6addr), &sain6->sin6_addr,
- sizeof(sain6->sin6_addr));
+ sizeof(sain6->sin6_addr));
addlist[i].pfra_net = 128;
break;
default:
@@ -191,8 +191,8 @@ sync_table(struct hostated *env, struct service *service, struct table *table)
fatal("sync_table: cannot set address list");
log_debug("sync_table: table %s: %d added, %d deleted, %d changed",
- io.pfrio_table.pfrt_name,
- io.pfrio_nadd, io.pfrio_ndel, io.pfrio_nchange);
+ io.pfrio_table.pfrt_name,
+ io.pfrio_nadd, io.pfrio_ndel, io.pfrio_nchange);
}
void
@@ -202,11 +202,11 @@ flush_table(struct hostated *env, struct service *service)
memset(&io, 0, sizeof(io));
(void)strlcpy(io.pfrio_table.pfrt_anchor, HOSTATED_ANCHOR "/",
- sizeof(io.pfrio_table.pfrt_anchor));
+ sizeof(io.pfrio_table.pfrt_anchor));
(void)strlcat(io.pfrio_table.pfrt_anchor, service->name,
- sizeof(io.pfrio_table.pfrt_anchor));
+ sizeof(io.pfrio_table.pfrt_anchor));
(void)strlcpy(io.pfrio_table.pfrt_name, service->name,
- sizeof(io.pfrio_table.pfrt_name));
+ sizeof(io.pfrio_table.pfrt_name));
if (ioctl(env->pf->dev, DIOCRCLRADDRS, &io) == -1)
fatal("flush_table: cannot flush table");
log_debug("flush_table: flushed table %s", service->name);
@@ -216,17 +216,17 @@ flush_table(struct hostated *env, struct service *service)
int
transaction_init(struct hostated *env, const char *anchor)
{
- env->pf->pft.size = 1;
- env->pf->pft.esize = sizeof env->pf->pfte;
- env->pf->pft.array = &env->pf->pfte;
+ env->pf->pft.size = 1;
+ env->pf->pft.esize = sizeof env->pf->pfte;
+ env->pf->pft.array = &env->pf->pfte;
memset(&env->pf->pfte, 0, sizeof env->pf->pfte);
strlcpy(env->pf->pfte.anchor, anchor, PF_ANCHOR_NAME_SIZE);
env->pf->pfte.rs_num = PF_RULESET_RDR;
- if (ioctl(env->pf->dev, DIOCXBEGIN, &env->pf->pft) == -1)
- return (-1);
- return (0);
+ if (ioctl(env->pf->dev, DIOCXBEGIN, &env->pf->pft) == -1)
+ return (-1);
+ return (0);
}
int
@@ -278,30 +278,30 @@ sync_ruleset(struct hostated *env, struct service *service, int enable)
rio.rule.action = PF_RDR;
if (strlen(service->tag))
(void)strlcpy(rio.rule.tagname, service->tag,
- sizeof(rio.rule.tagname));
+ sizeof(rio.rule.tagname));
if (strlen(address->ifname))
(void)strlcpy(rio.rule.ifname, address->ifname,
- sizeof(rio.rule.ifname));
+ sizeof(rio.rule.ifname));
if (address->ss.ss_family == AF_INET) {
sain = (struct sockaddr_in *)&address->ss;
-
- rio.rule.dst.addr.v.a.addr.addr32[0] =
- sain->sin_addr.s_addr;
+
+ rio.rule.dst.addr.v.a.addr.addr32[0] =
+ sain->sin_addr.s_addr;
rio.rule.dst.addr.v.a.mask.addr32[0] = 0xffffffff;
} else {
sain6 = (struct sockaddr_in6 *)&address->ss;
-
+
memcpy(&rio.rule.dst.addr.v.a.addr.v6,
- &sain6->sin6_addr.s6_addr,
- sizeof(sain6->sin6_addr.s6_addr));
+ &sain6->sin6_addr.s6_addr,
+ sizeof(sain6->sin6_addr.s6_addr));
memset(&rio.rule.dst.addr.v.a.mask.addr8, 0xff, 16);
}
pio.addr.addr.type = PF_ADDR_TABLE;
(void)strlcpy(pio.addr.addr.v.tblname, service->name,
- sizeof(pio.addr.addr.v.tblname));
+ sizeof(pio.addr.addr.v.tblname));
if (ioctl(env->pf->dev, DIOCADDADDR, &pio) == -1)
fatal("sync_ruleset: cannot add address to pool");
@@ -328,7 +328,7 @@ flush_rulesets(struct hostated *env)
strlcat(anchor, service->name, sizeof(anchor));
transaction_init(env, anchor);
transaction_commit(env);
- }
+ }
strlcpy(anchor, HOSTATED_ANCHOR, sizeof(anchor));
transaction_init(env, anchor);
transaction_commit(env);
diff --git a/usr.sbin/hoststated/check_http.c b/usr.sbin/hoststated/check_http.c
index 3d39ceebe27..5dc759e4c42 100644
--- a/usr.sbin/hoststated/check_http.c
+++ b/usr.sbin/hoststated/check_http.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: check_http.c,v 1.1 2006/12/16 11:45:07 reyk Exp $ */
+/* $OpenBSD: check_http.c,v 1.2 2006/12/16 12:42:14 reyk Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
*
@@ -43,8 +43,8 @@ http_request(struct host *host, struct table *table, int s, const char *req)
if ((fl = fcntl(s, F_GETFL, 0)) == -1)
fatal("http_request: cannot get flags for socket");
- if (fcntl(s, F_SETFL, fl & ~(O_NONBLOCK)) == -1)
- fatal("http_request: cannot set blocking socket");
+ if (fcntl(s, F_SETFL, fl & ~(O_NONBLOCK)) == -1)
+ fatal("http_request: cannot set blocking socket");
if ((buf = buf_dynamic(sizeof(rbuf), UINT_MAX)) == NULL)
fatalx("http_request: cannot create dynamic buffer");
@@ -126,7 +126,7 @@ check_http_digest(struct host *host, struct table *table)
head = buf->buf;
if ((head = strstr(head, "\r\n\r\n")) == NULL) {
log_debug("check_http_digest: host %u no end of headers",
- host->id);
+ host->id);
close(s);
return (HOST_DOWN);
}
@@ -137,8 +137,8 @@ check_http_digest(struct host *host, struct table *table)
if (strcmp(table->digest, digest)) {
log_warnx("check_http_digest: wrong digest for host %u",
- host->id);
- return(HOST_DOWN);
+ host->id);
+ return (HOST_DOWN);
}
return (HOST_UP);
}
diff --git a/usr.sbin/hoststated/check_tcp.c b/usr.sbin/hoststated/check_tcp.c
index 5ef386731f9..a0390326a7a 100644
--- a/usr.sbin/hoststated/check_tcp.c
+++ b/usr.sbin/hoststated/check_tcp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: check_tcp.c,v 1.1 2006/12/16 11:45:07 reyk Exp $ */
+/* $OpenBSD: check_tcp.c,v 1.2 2006/12/16 12:42:14 reyk Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -83,12 +83,13 @@ tcp_connect(struct host *host, struct table *table)
FD_ZERO(&fdset);
FD_SET(s, &fdset);
- switch(select(s + 1, NULL, &fdset, NULL, &tv)) {
+ /* XXX This needs to be rewritten */
+ switch (select(s + 1, NULL, &fdset, NULL, &tv)) {
case -1:
if (errno != EINTR)
fatal("check_tcp: select");
else
- return(HOST_UNKNOWN);
+ return (HOST_UNKNOWN);
case 0:
close(s);
return (HOST_DOWN);
diff --git a/usr.sbin/hoststated/control.c b/usr.sbin/hoststated/control.c
index 2f994e458f4..764053bafe4 100644
--- a/usr.sbin/hoststated/control.c
+++ b/usr.sbin/hoststated/control.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: control.c,v 1.1 2006/12/16 11:45:07 reyk Exp $ */
+/* $OpenBSD: control.c,v 1.2 2006/12/16 12:42:14 reyk Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -189,9 +189,9 @@ void
control_dispatch_imsg(int fd, short event, void *arg)
{
struct ctl_conn *c;
- struct imsg imsg;
+ struct imsg imsg;
objid_t id;
- int n;
+ int n;
if ((c = control_connbyfd(fd)) == NULL) {
log_warn("control_dispatch_imsg: fd %d: not found", fd);
diff --git a/usr.sbin/hoststated/hce.c b/usr.sbin/hoststated/hce.c
index 7144357538b..3bed9f206e3 100644
--- a/usr.sbin/hoststated/hce.c
+++ b/usr.sbin/hoststated/hce.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: hce.c,v 1.1 2006/12/16 11:45:07 reyk Exp $ */
+/* $OpenBSD: hce.c,v 1.2 2006/12/16 12:42:14 reyk Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -98,45 +98,45 @@ hce(struct hostated *x_env, int pipe_parent2pfe[2], int pipe_parent2hce[2],
setproctitle("host check engine");
hostated_process = PROC_HCE;
- if (setgroups(1, &pw->pw_gid) ||
- setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) ||
- setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid))
- fatal("hce: can't drop privileges");
+ if (setgroups(1, &pw->pw_gid) ||
+ setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) ||
+ setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid))
+ fatal("hce: can't drop privileges");
event_init();
- signal_set(&ev_sigint, SIGINT, hce_sig_handler, NULL);
- signal_set(&ev_sigterm, SIGTERM, hce_sig_handler, NULL);
- signal_add(&ev_sigint, NULL);
- signal_add(&ev_sigterm, NULL);
-
- /* setup pipes */
- close(pipe_pfe2hce[1]);
- close(pipe_parent2hce[0]);
- close(pipe_parent2pfe[0]);
- close(pipe_parent2pfe[1]);
-
- if ((ibuf_pfe = calloc(1, sizeof(struct imsgbuf))) == NULL ||
- (ibuf_main = calloc(1, sizeof(struct imsgbuf))) == NULL)
- fatal("hce");
- imsg_init(ibuf_pfe, pipe_pfe2hce[0], hce_dispatch_imsg);
- imsg_init(ibuf_main, pipe_parent2hce[1], hce_dispatch_parent);
-
- ibuf_pfe->events = EV_READ;
- event_set(&ibuf_pfe->ev, ibuf_pfe->fd, ibuf_pfe->events,
- ibuf_pfe->handler, ibuf_pfe);
- event_add(&ibuf_pfe->ev, NULL);
-
- ibuf_main->events = EV_READ;
- event_set(&ibuf_main->ev, ibuf_main->fd, ibuf_main->events,
- ibuf_main->handler, ibuf_main);
- event_add(&ibuf_main->ev, NULL);
-
- evtimer_set(&env->ev, hce_launch_checks, NULL);
+ signal_set(&ev_sigint, SIGINT, hce_sig_handler, NULL);
+ signal_set(&ev_sigterm, SIGTERM, hce_sig_handler, NULL);
+ signal_add(&ev_sigint, NULL);
+ signal_add(&ev_sigterm, NULL);
+
+ /* setup pipes */
+ close(pipe_pfe2hce[1]);
+ close(pipe_parent2hce[0]);
+ close(pipe_parent2pfe[0]);
+ close(pipe_parent2pfe[1]);
+
+ if ((ibuf_pfe = calloc(1, sizeof(struct imsgbuf))) == NULL ||
+ (ibuf_main = calloc(1, sizeof(struct imsgbuf))) == NULL)
+ fatal("hce");
+ imsg_init(ibuf_pfe, pipe_pfe2hce[0], hce_dispatch_imsg);
+ imsg_init(ibuf_main, pipe_parent2hce[1], hce_dispatch_parent);
+
+ ibuf_pfe->events = EV_READ;
+ event_set(&ibuf_pfe->ev, ibuf_pfe->fd, ibuf_pfe->events,
+ ibuf_pfe->handler, ibuf_pfe);
+ event_add(&ibuf_pfe->ev, NULL);
+
+ ibuf_main->events = EV_READ;
+ event_set(&ibuf_main->ev, ibuf_main->fd, ibuf_main->events,
+ ibuf_main->handler, ibuf_main);
+ event_add(&ibuf_main->ev, NULL);
+
+ evtimer_set(&env->ev, hce_launch_checks, NULL);
tv.tv_sec = env->interval;
tv.tv_usec = 0;
evtimer_add(&env->ev, &tv);
-
+
hce_launch_checks(0, 0, NULL);
event_dispatch();
@@ -149,8 +149,8 @@ void
hce_launch_checks(int fd, short event, void *arg)
{
int previous_up;
- struct host *host;
- struct table *table;
+ struct host *host;
+ struct table *table;
struct ctl_status st;
struct timeval tv;
@@ -168,8 +168,7 @@ hce_launch_checks(int fd, short event, void *arg)
switch (table->check) {
case CHECK_ICMP:
host->up = check_icmp(host, env->icmp_sock,
- env->icmp6_sock,
- table->timeout);
+ env->icmp6_sock, table->timeout);
break;
case CHECK_TCP:
host->up = check_tcp(host, table);
@@ -188,7 +187,7 @@ hce_launch_checks(int fd, short event, void *arg)
st.id = host->id;
st.up = host->up;
imsg_compose(ibuf_pfe, IMSG_HOST_STATUS, 0, 0,
- &st, sizeof(st));
+ &st, sizeof(st));
}
}
}
@@ -280,39 +279,39 @@ hce_dispatch_imsg(int fd, short event, void *ptr)
void
hce_dispatch_parent(int fd, short event, void * ptr)
{
- struct imsgbuf *ibuf;
- struct imsg imsg;
- ssize_t n;
+ struct imsgbuf *ibuf;
+ struct imsg imsg;
+ ssize_t n;
ibuf = ptr;
switch (event) {
- case EV_READ:
- if ((n = imsg_read(ibuf)) == -1)
- fatal("hce_dispatch_parent: imsg_read error");
- if (n == 0) /* connection closed */
- fatalx("hce_dispatch_parent: pipe closed");
- break;
- case EV_WRITE:
- if (msgbuf_write(&ibuf->w) == -1)
- fatal("hce_dispatch_parent: msgbuf_write");
- imsg_event_add(ibuf);
- return;
- default:
- fatalx("hce_dispatch_parent: unknown event");
+ case EV_READ:
+ if ((n = imsg_read(ibuf)) == -1)
+ fatal("hce_dispatch_parent: imsg_read error");
+ if (n == 0) /* connection closed */
+ fatalx("hce_dispatch_parent: pipe closed");
+ break;
+ case EV_WRITE:
+ if (msgbuf_write(&ibuf->w) == -1)
+ fatal("hce_dispatch_parent: msgbuf_write");
+ imsg_event_add(ibuf);
+ return;
+ default:
+ fatalx("hce_dispatch_parent: unknown event");
}
- for (;;) {
- if ((n = imsg_get(ibuf, &imsg)) == -1)
- fatal("hce_dispatch_parent: imsg_read error");
- if (n == 0)
- break;
-
- switch (imsg.hdr.type) {
- default:
- log_debug("hce_dispatch_parent: unexpected imsg %d",
- imsg.hdr.type);
- break;
- }
- imsg_free(&imsg);
- }
+ for (;;) {
+ if ((n = imsg_get(ibuf, &imsg)) == -1)
+ fatal("hce_dispatch_parent: imsg_read error");
+ if (n == 0)
+ break;
+
+ switch (imsg.hdr.type) {
+ default:
+ log_debug("hce_dispatch_parent: unexpected imsg %d",
+ imsg.hdr.type);
+ break;
+ }
+ imsg_free(&imsg);
+ }
}
diff --git a/usr.sbin/hoststated/hoststated.8 b/usr.sbin/hoststated/hoststated.8
index 18715f082f9..d7f7806b161 100644
--- a/usr.sbin/hoststated/hoststated.8
+++ b/usr.sbin/hoststated/hoststated.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: hoststated.8,v 1.2 2006/12/16 11:52:51 reyk Exp $
+.\" $OpenBSD: hoststated.8,v 1.3 2006/12/16 12:42:14 reyk Exp $
.\"
.\" Copyright (c) 2006 Pierre-Yves Ritschard <pyr@openbsd.org>
.\"
@@ -37,7 +37,7 @@ To enable
.Nm
to install rulesets through the anchor you will
need the following line in the NAT section of your
-.Xr pf.conf 5
+.Xr pf.conf 5
configuration file:
.Bd -literal -offset 2n
rdr-anchor "hostated/*"
diff --git a/usr.sbin/hoststated/hoststated.c b/usr.sbin/hoststated/hoststated.c
index 3932ab3e723..8c2e8d5768b 100644
--- a/usr.sbin/hoststated/hoststated.c
+++ b/usr.sbin/hoststated/hoststated.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: hoststated.c,v 1.1 2006/12/16 11:45:07 reyk Exp $ */
+/* $OpenBSD: hoststated.c,v 1.2 2006/12/16 12:42:14 reyk Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -89,7 +89,7 @@ usage(void)
extern char *__progname;
fprintf(stderr, "%s [-dnv] [-f file]\n", __progname);
- exit (1);
+ exit(1);
}
int main(int argc, char *argv[])
@@ -98,7 +98,7 @@ int main(int argc, char *argv[])
int debug;
u_int32_t opts;
struct hostated env;
- const char *conffile;
+ const char *conffile;
struct event ev_sigint;
struct event ev_sigterm;
struct event ev_sigchld;
@@ -126,7 +126,6 @@ int main(int argc, char *argv[])
default:
usage();
}
-
}
log_init(debug);
@@ -166,7 +165,7 @@ int main(int argc, char *argv[])
pfe_pid = pfe(&env, pipe_parent2pfe, pipe_parent2hce, pipe_pfe2hce);
hce_pid = hce(&env, pipe_parent2pfe, pipe_parent2hce, pipe_pfe2hce);
-
+
setproctitle("parent");
event_init();
@@ -179,7 +178,7 @@ int main(int argc, char *argv[])
signal_add(&ev_sigterm, NULL);
signal_add(&ev_sigchld, NULL);
signal_add(&ev_sighup, NULL);
-
+
close(pipe_parent2pfe[1]);
close(pipe_parent2hce[1]);
close(pipe_pfe2hce[0]);
@@ -192,15 +191,15 @@ int main(int argc, char *argv[])
imsg_init(ibuf_pfe, pipe_parent2pfe[0], main_dispatch_pfe);
imsg_init(ibuf_hce, pipe_parent2hce[0], main_dispatch_hce);
- ibuf_pfe->events = EV_READ;
- event_set(&ibuf_pfe->ev, ibuf_pfe->fd, ibuf_pfe->events,
- ibuf_pfe->handler, ibuf_pfe);
- event_add(&ibuf_pfe->ev, NULL);
+ ibuf_pfe->events = EV_READ;
+ event_set(&ibuf_pfe->ev, ibuf_pfe->fd, ibuf_pfe->events,
+ ibuf_pfe->handler, ibuf_pfe);
+ event_add(&ibuf_pfe->ev, NULL);
- ibuf_hce->events = EV_READ;
- event_set(&ibuf_hce->ev, ibuf_hce->fd, ibuf_hce->events,
- ibuf_hce->handler, ibuf_hce);
- event_add(&ibuf_hce->ev, NULL);
+ ibuf_hce->events = EV_READ;
+ event_set(&ibuf_hce->ev, ibuf_hce->fd, ibuf_hce->events,
+ ibuf_hce->handler, ibuf_hce);
+ event_add(&ibuf_hce->ev, NULL);
event_dispatch();
@@ -217,11 +216,11 @@ main_shutdown(void)
if (hce_pid)
kill(hce_pid, SIGTERM);
- do {
- if ((pid = wait(NULL)) == -1 &&
- errno != EINTR && errno != ECHILD)
- fatal("wait");
- } while (pid != -1 || (pid == -1 && errno == EINTR));
+ do {
+ if ((pid = wait(NULL)) == -1 &&
+ errno != EINTR && errno != ECHILD)
+ fatal("wait");
+ } while (pid != -1 || (pid == -1 && errno == EINTR));
control_cleanup();
log_info("terminating");
@@ -231,21 +230,21 @@ main_shutdown(void)
int
check_child(pid_t pid, const char *pname)
{
- int status;
-
- if (waitpid(pid, &status, WNOHANG) > 0) {
- if (WIFEXITED(status)) {
- log_warnx("check_child: lost child: %s exited", pname);
- return (1);
- }
- if (WIFSIGNALED(status)) {
- log_warnx("check_child: lost child: %s terminated; signal %d",
- pname, WTERMSIG(status));
- return (1);
- }
- }
-
- return (0);
+ int status;
+
+ if (waitpid(pid, &status, WNOHANG) > 0) {
+ if (WIFEXITED(status)) {
+ log_warnx("check_child: lost child: %s exited", pname);
+ return (1);
+ }
+ if (WIFSIGNALED(status)) {
+ log_warnx("check_child: lost child: %s terminated; "
+ "signal %d", pname, WTERMSIG(status));
+ return (1);
+ }
+ }
+
+ return (0);
}
void
@@ -256,8 +255,8 @@ imsg_event_add(struct imsgbuf *ibuf)
ibuf->events |= EV_WRITE;
event_del(&ibuf->ev);
- event_set(&ibuf->ev, ibuf->fd, ibuf->events, ibuf->handler, ibuf);
- event_add(&ibuf->ev, NULL);
+ event_set(&ibuf->ev, ibuf->fd, ibuf->events, ibuf->handler, ibuf);
+ event_add(&ibuf->ev, NULL);
}
void
@@ -305,40 +304,40 @@ void
main_dispatch_hce(int fd, short event, void * ptr)
{
struct imsgbuf *ibuf;
- struct imsg imsg;
- ssize_t n;
+ struct imsg imsg;
+ ssize_t n;
ibuf = ptr;
switch (event) {
- case EV_READ:
- if ((n = imsg_read(ibuf)) == -1)
- fatal("imsg_read error");
- if (n == 0) /* connection closed */
- fatalx("parent: pipe closed");
- break;
- case EV_WRITE:
- if (msgbuf_write(&ibuf->w) == -1)
- fatal("msgbuf_write");
- imsg_event_add(ibuf);
- return;
- default:
- fatalx("unknown event");
+ case EV_READ:
+ if ((n = imsg_read(ibuf)) == -1)
+ fatal("imsg_read error");
+ if (n == 0) /* connection closed */
+ fatalx("parent: pipe closed");
+ break;
+ case EV_WRITE:
+ if (msgbuf_write(&ibuf->w) == -1)
+ fatal("msgbuf_write");
+ imsg_event_add(ibuf);
+ return;
+ default:
+ fatalx("unknown event");
}
- for (;;) {
- if ((n = imsg_get(ibuf, &imsg)) == -1)
- fatal("main_dispatch_hce: imsg_read error");
- if (n == 0)
- break;
-
- switch (imsg.hdr.type) {
- default:
- log_debug("main_dispatch_hce: unexpected imsg %d",
- imsg.hdr.type);
- break;
- }
- imsg_free(&imsg);
- }
+ for (;;) {
+ if ((n = imsg_get(ibuf, &imsg)) == -1)
+ fatal("main_dispatch_hce: imsg_read error");
+ if (n == 0)
+ break;
+
+ switch (imsg.hdr.type) {
+ default:
+ log_debug("main_dispatch_hce: unexpected imsg %d",
+ imsg.hdr.type);
+ break;
+ }
+ imsg_free(&imsg);
+ }
}
struct host *
diff --git a/usr.sbin/hoststated/hoststated.conf.5 b/usr.sbin/hoststated/hoststated.conf.5
index d0eb3484e72..ea3ecf75b0a 100644
--- a/usr.sbin/hoststated/hoststated.conf.5
+++ b/usr.sbin/hoststated/hoststated.conf.5
@@ -1,4 +1,4 @@
-.\" $OpenBSD: hoststated.conf.5,v 1.2 2006/12/16 11:52:51 reyk Exp $
+.\" $OpenBSD: hoststated.conf.5,v 1.3 2006/12/16 12:42:14 reyk Exp $
.\"
.\" Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
.\"
@@ -23,7 +23,7 @@
.Sh DESCRIPTION
The
.Xr hostated 8
-daemon maintains
+daemon maintains
.Xr pf 4
tables up to date.
.Sh SECTIONS
@@ -38,7 +38,7 @@ configuration file.
Global settings for
.Xr hostated 8 .
.It Sy Tables
-Table definitions describe the content of a
+Table definitions describe the content of a
.Xr pf 4
table and the method used for checking the health of the hosts
they contain.
@@ -135,7 +135,7 @@ The table can be later enabled through
.Sh SERVICES
Services represent a
.Xr pf 4
-rdr rule, they are used to specify which addresses will be redirected
+rdr rule, they are used to specify which addresses will be redirected
to the hosts in the specified tables.
The configuration directives that are valid in this context are described
below.
@@ -198,7 +198,7 @@ table sorryhost {
host sorryhost.private.example.com
}
-service www {
+service www {
virtual ip www.example.com port 8080 interface trunk0
virtual ip www6.example.com port 80 interface trunk0
diff --git a/usr.sbin/hoststated/hoststated.h b/usr.sbin/hoststated/hoststated.h
index d59a934be48..0191df4100c 100644
--- a/usr.sbin/hoststated/hoststated.h
+++ b/usr.sbin/hoststated/hoststated.h
@@ -32,38 +32,38 @@
/* buffer */
struct buf {
- TAILQ_ENTRY(buf) entry;
- u_char *buf;
- size_t size;
- size_t max;
- size_t wpos;
- size_t rpos;
+ TAILQ_ENTRY(buf) entry;
+ u_char *buf;
+ size_t size;
+ size_t max;
+ size_t wpos;
+ size_t rpos;
};
struct msgbuf {
- TAILQ_HEAD(, buf) bufs;
- u_int32_t queued;
- int fd;
+ TAILQ_HEAD(, buf) bufs;
+ u_int32_t queued;
+ int fd;
};
-#define IMSG_HEADER_SIZE sizeof(struct imsg_hdr)
-#define MAX_IMSGSIZE 8192
+#define IMSG_HEADER_SIZE sizeof(struct imsg_hdr)
+#define MAX_IMSGSIZE 8192
-struct buf_read {
- u_char buf[READ_BUF_SIZE];
- u_char *rptr;
- size_t wpos;
+struct buf_read {
+ u_char buf[READ_BUF_SIZE];
+ u_char *rptr;
+ size_t wpos;
};
struct imsgbuf {
- TAILQ_HEAD(, imsg_fd) fds;
- struct buf_read r;
- struct msgbuf w;
- struct event ev;
- void (*handler)(int, short, void *);
- int fd;
- pid_t pid;
- short events;
+ TAILQ_HEAD(, imsg_fd) fds;
+ struct buf_read r;
+ struct msgbuf w;
+ struct event ev;
+ void (*handler)(int, short, void *);
+ int fd;
+ pid_t pid;
+ short events;
};
enum imsg_type {
@@ -95,18 +95,18 @@ enum imsg_type {
};
struct imsg_hdr {
- enum imsg_type type;
- u_int16_t len;
- u_int32_t peerid;
- pid_t pid;
+ enum imsg_type type;
+ u_int16_t len;
+ u_int32_t peerid;
+ pid_t pid;
};
struct imsg {
- struct imsg_hdr hdr;
- void *data;
+ struct imsg_hdr hdr;
+ void *data;
};
-typedef u_int32_t objid_t;
+typedef u_int32_t objid_t;
struct ctl_status {
objid_t id;
@@ -121,14 +121,14 @@ struct address {
};
TAILQ_HEAD(addresslist, address);
-#define F_DISABLE 0x01
-#define F_BACKUP 0x02
-#define F_USED 0x04
-#define F_ACTIVE_RULESET 0x04
-#define F_DOWN 0x08
-#define F_ADD 0x10
-#define F_DEL 0x20
-#define F_CHANGED 0x40
+#define F_DISABLE 0x01
+#define F_BACKUP 0x02
+#define F_USED 0x04
+#define F_ACTIVE_RULESET 0x04
+#define F_DOWN 0x08
+#define F_ADD 0x10
+#define F_DEL 0x20
+#define F_CHANGED 0x40
struct host {
u_int8_t flags;
@@ -137,27 +137,23 @@ struct host {
char *tablename;
char name[MAXHOSTNAMELEN];
int up;
-#define HOST_DOWN -1
-#define HOST_UNKNOWN 0
-#define HOST_UP 1
struct sockaddr_storage ss;
TAILQ_ENTRY(host) entry;
};
TAILQ_HEAD(hostlist, host);
+#define HOST_DOWN -1
+#define HOST_UNKNOWN 0
+#define HOST_UP 1
+
struct table {
objid_t id;
objid_t serviceid;
u_int8_t flags;
int check;
-#define CHECK_NOCHECK 0
-#define CHECK_ICMP 1
-#define CHECK_TCP 2
-#define CHECK_HTTP_CODE 3
-#define CHECK_HTTP_DIGEST 4
int up;
in_port_t port;
- int retcode;
+ int retcode;
int timeout;
char name[TABLE_NAME_SIZE];
char path[MAXPATHLEN];
@@ -167,6 +163,12 @@ struct table {
};
TAILQ_HEAD(tablelist, table);
+#define CHECK_NOCHECK 0
+#define CHECK_ICMP 1
+#define CHECK_TCP 2
+#define CHECK_HTTP_CODE 3
+#define CHECK_HTTP_DIGEST 4
+
struct service {
objid_t id;
u_int8_t flags;
@@ -187,9 +189,7 @@ enum {
} hostated_process;
struct hostated {
- u_int8_t opts;
-#define HOSTATED_OPT_VERBOSE 0x01
-#define HOSTATED_OPT_NOACTION 0x04
+ u_int8_t opts;
struct pfdata *pf;
int interval;
int icmp_sock;
@@ -202,20 +202,23 @@ struct hostated {
struct servicelist services;
};
+#define HOSTATED_OPT_VERBOSE 0x01
+#define HOSTATED_OPT_NOACTION 0x04
+
/* initially control.h */
struct {
- struct event ev;
- int fd;
+ struct event ev;
+ int fd;
} control_state;
enum blockmodes {
- BM_NORMAL,
- BM_NONBLOCK
+ BM_NORMAL,
+ BM_NONBLOCK
};
struct ctl_conn {
- TAILQ_ENTRY(ctl_conn) entry;
- struct imsgbuf ibuf;
+ TAILQ_ENTRY(ctl_conn) entry;
+ struct imsgbuf ibuf;
};
TAILQ_HEAD(ctl_connlist, ctl_conn);
@@ -233,41 +236,41 @@ void session_socket_blockmode(int, enum blockmodes);
extern struct ctl_connlist ctl_conns;
/* parse.y */
-int parse_config(struct hostated *, const char *, int);
+int parse_config(struct hostated *, const char *, int);
/* log.c */
-void log_init(int);
-void log_warn(const char *, ...);
-void log_warnx(const char *, ...);
-void log_info(const char *, ...);
-void log_debug(const char *, ...);
-void fatal(const char *);
-void fatalx(const char *);
+void log_init(int);
+void log_warn(const char *, ...);
+void log_warnx(const char *, ...);
+void log_info(const char *, ...);
+void log_debug(const char *, ...);
+void fatal(const char *);
+void fatalx(const char *);
/* buffer.c */
-struct buf *buf_open(size_t);
-struct buf *buf_dynamic(size_t, size_t);
-int buf_add(struct buf *, void *, size_t);
-void *buf_reserve(struct buf *, size_t);
-void *buf_seek(struct buf *, size_t, size_t);
-int buf_close(struct msgbuf *, struct buf *);
-void buf_free(struct buf *);
-void msgbuf_init(struct msgbuf *);
-void msgbuf_clear(struct msgbuf *);
-int msgbuf_write(struct msgbuf *);
+struct buf *buf_open(size_t);
+struct buf *buf_dynamic(size_t, size_t);
+int buf_add(struct buf *, void *, size_t);
+void *buf_reserve(struct buf *, size_t);
+void *buf_seek(struct buf *, size_t, size_t);
+int buf_close(struct msgbuf *, struct buf *);
+void buf_free(struct buf *);
+void msgbuf_init(struct msgbuf *);
+void msgbuf_clear(struct msgbuf *);
+int msgbuf_write(struct msgbuf *);
/* imsg.c */
-void imsg_init(struct imsgbuf *, int, void (*)(int, short, void *));
-ssize_t imsg_read(struct imsgbuf *);
-ssize_t imsg_get(struct imsgbuf *, struct imsg *);
-int imsg_compose(struct imsgbuf *, enum imsg_type, u_int32_t, pid_t,
- void *, u_int16_t);
-struct buf *imsg_create(struct imsgbuf *, enum imsg_type, u_int32_t, pid_t,
- u_int16_t);
-int imsg_add(struct buf *, void *, u_int16_t);
-int imsg_close(struct imsgbuf *, struct buf *);
-void imsg_free(struct imsg *);
-void imsg_event_add(struct imsgbuf *); /* needs to be provided externally */
+void imsg_init(struct imsgbuf *, int, void (*)(int, short, void *));
+ssize_t imsg_read(struct imsgbuf *);
+ssize_t imsg_get(struct imsgbuf *, struct imsg *);
+int imsg_compose(struct imsgbuf *, enum imsg_type, u_int32_t, pid_t,
+ void *, u_int16_t);
+struct buf *imsg_create(struct imsgbuf *, enum imsg_type, u_int32_t, pid_t,
+ u_int16_t);
+int imsg_add(struct buf *, void *, u_int16_t);
+int imsg_close(struct imsgbuf *, struct buf *);
+void imsg_free(struct imsg *);
+void imsg_event_add(struct imsgbuf *); /* needs to be provided externally */
/* pfe.c */
pid_t pfe(struct hostated *, int [2], int [2], int [2]);
diff --git a/usr.sbin/hoststated/parse.y b/usr.sbin/hoststated/parse.y
index 977b7a74cb1..f2e008340ff 100644
--- a/usr.sbin/hoststated/parse.y
+++ b/usr.sbin/hoststated/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.1 2006/12/16 11:45:07 reyk Exp $ */
+/* $OpenBSD: parse.y,v 1.2 2006/12/16 12:42:14 reyk Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -74,16 +74,16 @@ struct sym {
char *val;
};
-int symset(const char *, const char *, int);
-char *symget(const char *);
-int cmdline_symset(char *);
+int symset(const char *, const char *, int);
+char *symget(const char *);
+int cmdline_symset(char *);
struct address *host_v4(const char *);
struct address *host_v6(const char *);
int host_dns(const char *, struct addresslist *,
- int, in_port_t, const char *);
+ int, in_port_t, const char *);
int host(const char *, struct addresslist *,
- int, in_port_t, const char *);
+ int, in_port_t, const char *);
typedef struct {
union {
@@ -117,7 +117,7 @@ grammar : /* empty */
| grammar error '\n' { errors++; }
;
-number : STRING {
+number : STRING {
const char *estr;
$$ = strtonum($1, 0, UINT_MAX, &estr);
@@ -142,7 +142,7 @@ varset : STRING '=' STRING {
main : INTERVAL number { conf->interval = $2; }
;
-service : SERVICE STRING {
+service : SERVICE STRING {
struct service *srv;
TAILQ_FOREACH(srv, &conf->services, entry)
@@ -156,12 +156,12 @@ service : SERVICE STRING {
if ((srv = calloc(1, sizeof (*srv))) == NULL)
fatal("out of memory");
- if (strlcpy(srv->name, $2, sizeof (srv->name)) >=
- sizeof (srv->name)) {
+ if (strlcpy(srv->name, $2, sizeof(srv->name)) >=
+ sizeof(srv->name)) {
yyerror("service name truncated");
YYERROR;
}
- free ($2);
+ free($2);
srv->id = last_service_id++;
if (last_service_id == UINT_MAX) {
yyerror("too many services defined");
@@ -183,13 +183,13 @@ service : SERVICE STRING {
if (service->backup == NULL)
service->backup = &conf->empty_table;
else if (service->backup->port !=
- service->table->port) {
+ service->table->port) {
yyerror("service %s uses two different ports "
- "for its table and backup table",
- service->name);
+ "for its table and backup table",
+ service->name);
YYERROR;
}
-
+
if (!(service->flags & F_DISABLE))
service->flags |= F_ADD;
TAILQ_INSERT_HEAD(&conf->services, service, entry);
@@ -200,7 +200,7 @@ serviceopts_l : serviceopts_l serviceoptsl nl
| serviceoptsl optnl
;
-serviceoptsl : TABLE STRING {
+serviceoptsl : TABLE STRING {
struct table *tb;
TAILQ_FOREACH(tb, &conf->tables, entry)
@@ -217,7 +217,7 @@ serviceoptsl : TABLE STRING {
free($2);
}
}
- | BACKUP TABLE STRING {
+ | BACKUP TABLE STRING {
struct table *tb;
if (service->backup) {
@@ -270,7 +270,7 @@ serviceoptsl : TABLE STRING {
}
;
-table : TABLE STRING {
+table : TABLE STRING {
struct table *tb;
TAILQ_FOREACH(tb, &conf->tables, entry)
@@ -281,12 +281,12 @@ table : TABLE STRING {
free($2);
YYERROR;
}
-
+
if ((tb = calloc(1, sizeof (*tb))) == NULL)
fatal("out of memory");
-
- if (strlcpy(tb->name, $2, sizeof (tb->name)) >=
- sizeof (tb->name)) {
+
+ if (strlcpy(tb->name, $2, sizeof(tb->name)) >=
+ sizeof(tb->name)) {
yyerror("table name truncated");
YYERROR;
}
@@ -296,9 +296,9 @@ table : TABLE STRING {
yyerror("too many tables defined");
YYERROR;
}
- free ($2);
+ free($2);
table = tb;
- } '{' optnl tableopts_l '}' {
+ } '{' optnl tableopts_l '}' {
if (table->port == 0) {
yyerror("table %s has no port", table->name);
YYERROR;
@@ -320,25 +320,25 @@ tableopts_l : tableopts_l tableoptsl nl
| tableoptsl optnl
;
-tableoptsl : host {
+tableoptsl : host {
$1->tableid = table->id;
$1->tablename = table->name;
TAILQ_INSERT_HEAD(&table->hosts, $1, entry);
}
- | TIMEOUT number {
+ | TIMEOUT number {
table->timeout = $2;
}
- | CHECK ICMP {
+ | CHECK ICMP {
table->check = CHECK_ICMP;
}
- | CHECK TCP {
+ | CHECK TCP {
table->check = CHECK_TCP;
}
| CHECK HTTP STRING CODE number {
table->check = CHECK_HTTP_CODE;
table->retcode = $5;
- if (strlcpy(table->path, $3, sizeof (table->path)) >=
- sizeof (table->path)) {
+ if (strlcpy(table->path, $3, sizeof(table->path)) >=
+ sizeof(table->path)) {
yyerror("http path truncated");
free($3);
YYERROR;
@@ -346,8 +346,8 @@ tableoptsl : host {
}
| CHECK HTTP STRING DIGEST STRING {
table->check = CHECK_HTTP_DIGEST;
- if (strlcpy(table->path, $3, sizeof (table->path)) >=
- sizeof (table->path)) {
+ if (strlcpy(table->path, $3, sizeof(table->path)) >=
+ sizeof(table->path)) {
yyerror("http path truncated");
free($3);
free($5);
@@ -378,12 +378,12 @@ interface : /*empty*/ { $$ = NULL; }
;
host : HOST STRING {
- struct host *r;
+ struct host *r;
struct address *a;
struct addresslist al;
- if ((r = calloc(1, sizeof (*r))) == NULL)
- fatal("out of memory");
+ if ((r = calloc(1, sizeof(*r))) == NULL)
+ fatal("out of memory");
TAILQ_INIT(&al);
if (host($2, &al, 1, 0, NULL) <= 0) {
@@ -395,8 +395,8 @@ host : HOST STRING {
memcpy(&r->ss, &a->ss, sizeof(r->ss));
free(a);
- if (strlcpy(r->name, $2, sizeof (r->name)) >=
- sizeof (r->name)) {
+ if (strlcpy(r->name, $2, sizeof(r->name)) >=
+ sizeof(r->name)) {
yyerror("host name truncated");
free($2);
YYERROR;
@@ -683,7 +683,7 @@ parse_config(struct hostated *x_conf, const char *filename, int opts)
conf->empty_table.id = EMPTY_TABLE;
conf->empty_table.flags |= F_DISABLE;
(void)strlcpy(conf->empty_table.name, "empty",
- sizeof(conf->empty_table.name));
+ sizeof(conf->empty_table.name));
conf->interval = CHECK_INTERVAL;
conf->opts = opts;
@@ -835,7 +835,7 @@ host_v6(const char *s)
bzero(&ina6, sizeof(ina6));
if (inet_pton(AF_INET6, s, &ina6) != 1)
return (NULL);
-
+
if ((h = calloc(1, sizeof(*h))) == NULL)
fatal(NULL);
sin6 = (struct sockaddr_in6 *)&h->ss;
@@ -912,7 +912,7 @@ host(const char *s, struct addresslist *al, int max,
in_port_t port, const char *ifname)
{
struct address *h;
-
+
h = host_v4(s);
/* IPv6 address? */
@@ -928,7 +928,7 @@ host(const char *s, struct addresslist *al, int max,
return (-1);
}
}
-
+
TAILQ_INSERT_HEAD(al, h, entry);
return (1);
}
diff --git a/usr.sbin/hoststated/pfe.c b/usr.sbin/hoststated/pfe.c
index 0a7ff43949f..3fe5f29039a 100644
--- a/usr.sbin/hoststated/pfe.c
+++ b/usr.sbin/hoststated/pfe.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pfe.c,v 1.1 2006/12/16 11:45:07 reyk Exp $ */
+/* $OpenBSD: pfe.c,v 1.2 2006/12/16 12:42:14 reyk Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -94,10 +94,10 @@ pfe(struct hostated *x_env, int pipe_parent2pfe[2], int pipe_parent2hce[2],
setproctitle("pf update engine");
hostated_process = PROC_PFE;
- if (setgroups(1, &pw->pw_gid) ||
- setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) ||
- setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid))
- fatal("pfe: cannot drop privileges");
+ if (setgroups(1, &pw->pw_gid) ||
+ setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) ||
+ setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid))
+ fatal("pfe: cannot drop privileges");
event_init();
@@ -115,17 +115,17 @@ pfe(struct hostated *x_env, int pipe_parent2pfe[2], int pipe_parent2hce[2],
if ((ibuf_hce = calloc(1, sizeof(struct imsgbuf))) == NULL ||
(ibuf_main = calloc(1, sizeof(struct imsgbuf))) == NULL)
fatal("pfe");
- imsg_init(ibuf_hce, pipe_pfe2hce[1], pfe_dispatch_imsg);
- imsg_init(ibuf_main, pipe_parent2pfe[1], pfe_dispatch_parent);
+ imsg_init(ibuf_hce, pipe_pfe2hce[1], pfe_dispatch_imsg);
+ imsg_init(ibuf_main, pipe_parent2pfe[1], pfe_dispatch_parent);
ibuf_hce->events = EV_READ;
event_set(&ibuf_hce->ev, ibuf_hce->fd, ibuf_hce->events,
- ibuf_hce->handler, ibuf_hce);
+ ibuf_hce->handler, ibuf_hce);
event_add(&ibuf_hce->ev, NULL);
ibuf_main->events = EV_READ;
event_set(&ibuf_main->ev, ibuf_main->fd, ibuf_main->events,
- ibuf_main->handler, ibuf_main);
+ ibuf_main->handler, ibuf_main);
event_add(&ibuf_main->ev, NULL);
TAILQ_INIT(&ctl_conns);
@@ -188,7 +188,7 @@ pfe_dispatch_imsg(int fd, short event, void *ptr)
fatalx("pfe_dispatch_imsg: invalid host id");
if (host->up == st.up) {
log_debug("pfe_dispatch_imsg: host %d => %d",
- host->id, host->up);
+ host->id, host->up);
fatalx("pfe_dispatch_imsg: desynchronized");
}
@@ -196,7 +196,7 @@ pfe_dispatch_imsg(int fd, short event, void *ptr)
fatalx("pfe_dispatch_imsg: invalid table id");
log_debug("pfe_dispatch_imsg: state %d for host %u %s",
- st.up, host->id, host->name);
+ st.up, host->id, host->name);
if ((st.up == HOST_UNKNOWN && host->up == HOST_DOWN) ||
(st.up == HOST_DOWN && host->up == HOST_UNKNOWN)) {
@@ -222,7 +222,7 @@ pfe_dispatch_imsg(int fd, short event, void *ptr)
break;
default:
log_debug("pfe_dispatch_imsg: unexpected imsg %d",
- imsg.hdr.type);
+ imsg.hdr.type);
break;
}
imsg_free(&imsg);
@@ -234,40 +234,40 @@ void
pfe_dispatch_parent(int fd, short event, void * ptr)
{
struct imsgbuf *ibuf;
- struct imsg imsg;
- ssize_t n;
+ struct imsg imsg;
+ ssize_t n;
ibuf = ptr;
switch (event) {
- case EV_READ:
- if ((n = imsg_read(ibuf)) == -1)
- fatal("imsg_read error");
- if (n == 0) /* connection closed */
- fatalx("pfe_dispatch_parent: pipe closed");
- break;
- case EV_WRITE:
- if (msgbuf_write(&ibuf->w) == -1)
- fatal("msgbuf_write");
- imsg_event_add(ibuf);
- return;
- default:
- fatalx("pfe_dispatch_parent: unknown event");
+ case EV_READ:
+ if ((n = imsg_read(ibuf)) == -1)
+ fatal("imsg_read error");
+ if (n == 0) /* connection closed */
+ fatalx("pfe_dispatch_parent: pipe closed");
+ break;
+ case EV_WRITE:
+ if (msgbuf_write(&ibuf->w) == -1)
+ fatal("msgbuf_write");
+ imsg_event_add(ibuf);
+ return;
+ default:
+ fatalx("pfe_dispatch_parent: unknown event");
}
- for (;;) {
- if ((n = imsg_get(ibuf, &imsg)) == -1)
- fatal("pfe_dispatch_parent: imsg_read error");
- if (n == 0)
- break;
-
- switch (imsg.hdr.type) {
- default:
- log_debug("pfe_dispatch_parent: unexpected imsg %d",
- imsg.hdr.type);
- break;
- }
- imsg_free(&imsg);
- }
+ for (;;) {
+ if ((n = imsg_get(ibuf, &imsg)) == -1)
+ fatal("pfe_dispatch_parent: imsg_read error");
+ if (n == 0)
+ break;
+
+ switch (imsg.hdr.type) {
+ default:
+ log_debug("pfe_dispatch_parent: unexpected imsg %d",
+ imsg.hdr.type);
+ break;
+ }
+ imsg_free(&imsg);
+ }
}
void
@@ -278,25 +278,25 @@ show(struct ctl_conn *c)
TAILQ_FOREACH(service, &env->services, entry) {
imsg_compose(&c->ibuf, IMSG_CTL_SERVICE, 0, 0,
- service, sizeof(*service));
+ service, sizeof(*service));
if (service->flags & F_DISABLE)
continue;
imsg_compose(&c->ibuf, IMSG_CTL_TABLE, 0, 0,
- service->table, sizeof(*service->table));
+ service->table, sizeof(*service->table));
if (!(service->table->flags & F_DISABLE))
TAILQ_FOREACH(host, &service->table->hosts, entry)
imsg_compose(&c->ibuf, IMSG_CTL_HOST, 0, 0,
- host, sizeof(*host));
+ host, sizeof(*host));
if (service->backup->id == EMPTY_TABLE)
continue;
imsg_compose(&c->ibuf, IMSG_CTL_TABLE, 0, 0,
- service->backup, sizeof(*service->backup));
+ service->backup, sizeof(*service->backup));
if (!(service->backup->flags & F_DISABLE))
TAILQ_FOREACH(host, &service->backup->hosts, entry)
imsg_compose(&c->ibuf, IMSG_CTL_HOST, 0, 0,
- host, sizeof(*host));
+ host, sizeof(*host));
}
imsg_compose(&c->ibuf, IMSG_CTL_END, 0, 0, NULL, 0);
}
@@ -480,7 +480,7 @@ pfe_sync(void)
service->table->flags &= ~(F_CHANGED);
service->backup->flags &= ~(F_CHANGED);
-
+
if (service->flags & F_DOWN) {
if (service->flags & F_ACTIVE_RULESET) {
flush_table(env, service);
diff --git a/usr.sbin/hoststated/pfe_filter.c b/usr.sbin/hoststated/pfe_filter.c
index b7bd7550070..89ea50b48c5 100644
--- a/usr.sbin/hoststated/pfe_filter.c
+++ b/usr.sbin/hoststated/pfe_filter.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pfe_filter.c,v 1.1 2006/12/16 11:45:07 reyk Exp $ */
+/* $OpenBSD: pfe_filter.c,v 1.2 2006/12/16 12:42:14 reyk Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -52,7 +52,7 @@ void
init_filter(struct hostated *env)
{
struct pf_status status;
-
+
if ((env->pf = calloc(1, sizeof(*(env->pf)))) == NULL)
fatal("calloc");
if ((env->pf->dev = open(PF_SOCKET, O_RDWR)) == -1)
@@ -75,14 +75,14 @@ init_tables(struct hostated *env)
if ((tables = calloc(env->servicecount, sizeof(*tables))) == NULL)
fatal("calloc");
i = 0;
-
+
TAILQ_FOREACH(service, &env->services, entry) {
(void)strlcpy(tables[i].pfrt_anchor, HOSTATED_ANCHOR "/",
- sizeof(tables[i].pfrt_anchor));
+ sizeof(tables[i].pfrt_anchor));
(void)strlcat(tables[i].pfrt_anchor, service->name,
- sizeof(tables[i].pfrt_anchor));
+ sizeof(tables[i].pfrt_anchor));
(void)strlcpy(tables[i].pfrt_name, service->name,
- sizeof(tables[i].pfrt_name));
+ sizeof(tables[i].pfrt_name));
tables[i].pfrt_flags |= PFR_TFLAG_PERSIST;
i++;
}
@@ -116,9 +116,9 @@ kill_tables(struct hostated *env) {
memset(&io, 0, sizeof(io));
TAILQ_FOREACH(service, &env->services, entry) {
(void)strlcpy(io.pfrio_table.pfrt_anchor, HOSTATED_ANCHOR "/",
- sizeof(io.pfrio_table.pfrt_anchor));
+ sizeof(io.pfrio_table.pfrt_anchor));
(void)strlcat(io.pfrio_table.pfrt_anchor, service->name,
- sizeof(io.pfrio_table.pfrt_anchor));
+ sizeof(io.pfrio_table.pfrt_anchor));
if (ioctl(env->pf->dev, DIOCRCLRTABLES, &io) == -1)
fatal("kill_tables: ioctl faile: ioctl failed");
}
@@ -152,11 +152,11 @@ sync_table(struct hostated *env, struct service *service, struct table *table)
io.pfrio_size2 = 0;
io.pfrio_buffer = addlist;
(void)strlcpy(io.pfrio_table.pfrt_anchor, HOSTATED_ANCHOR "/",
- sizeof(io.pfrio_table.pfrt_anchor));
+ sizeof(io.pfrio_table.pfrt_anchor));
(void)strlcat(io.pfrio_table.pfrt_anchor, service->name,
- sizeof(io.pfrio_table.pfrt_anchor));
+ sizeof(io.pfrio_table.pfrt_anchor));
(void)strlcpy(io.pfrio_table.pfrt_name, service->name,
- sizeof(io.pfrio_table.pfrt_name));
+ sizeof(io.pfrio_table.pfrt_name));
i = 0;
TAILQ_FOREACH(host, &table->hosts, entry) {
@@ -168,14 +168,14 @@ sync_table(struct hostated *env, struct service *service, struct table *table)
sain = (struct sockaddr_in *)&host->ss;
addlist[i].pfra_af = AF_INET;
memcpy(&(addlist[i].pfra_ip4addr), &sain->sin_addr,
- sizeof(sain->sin_addr));
+ sizeof(sain->sin_addr));
addlist[i].pfra_net = 32;
break;
case AF_INET6:
sain6 = (struct sockaddr_in6 *)&host->ss;
addlist[i].pfra_af = AF_INET6;
memcpy(&(addlist[i].pfra_ip6addr), &sain6->sin6_addr,
- sizeof(sain6->sin6_addr));
+ sizeof(sain6->sin6_addr));
addlist[i].pfra_net = 128;
break;
default:
@@ -191,8 +191,8 @@ sync_table(struct hostated *env, struct service *service, struct table *table)
fatal("sync_table: cannot set address list");
log_debug("sync_table: table %s: %d added, %d deleted, %d changed",
- io.pfrio_table.pfrt_name,
- io.pfrio_nadd, io.pfrio_ndel, io.pfrio_nchange);
+ io.pfrio_table.pfrt_name,
+ io.pfrio_nadd, io.pfrio_ndel, io.pfrio_nchange);
}
void
@@ -202,11 +202,11 @@ flush_table(struct hostated *env, struct service *service)
memset(&io, 0, sizeof(io));
(void)strlcpy(io.pfrio_table.pfrt_anchor, HOSTATED_ANCHOR "/",
- sizeof(io.pfrio_table.pfrt_anchor));
+ sizeof(io.pfrio_table.pfrt_anchor));
(void)strlcat(io.pfrio_table.pfrt_anchor, service->name,
- sizeof(io.pfrio_table.pfrt_anchor));
+ sizeof(io.pfrio_table.pfrt_anchor));
(void)strlcpy(io.pfrio_table.pfrt_name, service->name,
- sizeof(io.pfrio_table.pfrt_name));
+ sizeof(io.pfrio_table.pfrt_name));
if (ioctl(env->pf->dev, DIOCRCLRADDRS, &io) == -1)
fatal("flush_table: cannot flush table");
log_debug("flush_table: flushed table %s", service->name);
@@ -216,17 +216,17 @@ flush_table(struct hostated *env, struct service *service)
int
transaction_init(struct hostated *env, const char *anchor)
{
- env->pf->pft.size = 1;
- env->pf->pft.esize = sizeof env->pf->pfte;
- env->pf->pft.array = &env->pf->pfte;
+ env->pf->pft.size = 1;
+ env->pf->pft.esize = sizeof env->pf->pfte;
+ env->pf->pft.array = &env->pf->pfte;
memset(&env->pf->pfte, 0, sizeof env->pf->pfte);
strlcpy(env->pf->pfte.anchor, anchor, PF_ANCHOR_NAME_SIZE);
env->pf->pfte.rs_num = PF_RULESET_RDR;
- if (ioctl(env->pf->dev, DIOCXBEGIN, &env->pf->pft) == -1)
- return (-1);
- return (0);
+ if (ioctl(env->pf->dev, DIOCXBEGIN, &env->pf->pft) == -1)
+ return (-1);
+ return (0);
}
int
@@ -278,30 +278,30 @@ sync_ruleset(struct hostated *env, struct service *service, int enable)
rio.rule.action = PF_RDR;
if (strlen(service->tag))
(void)strlcpy(rio.rule.tagname, service->tag,
- sizeof(rio.rule.tagname));
+ sizeof(rio.rule.tagname));
if (strlen(address->ifname))
(void)strlcpy(rio.rule.ifname, address->ifname,
- sizeof(rio.rule.ifname));
+ sizeof(rio.rule.ifname));
if (address->ss.ss_family == AF_INET) {
sain = (struct sockaddr_in *)&address->ss;
-
- rio.rule.dst.addr.v.a.addr.addr32[0] =
- sain->sin_addr.s_addr;
+
+ rio.rule.dst.addr.v.a.addr.addr32[0] =
+ sain->sin_addr.s_addr;
rio.rule.dst.addr.v.a.mask.addr32[0] = 0xffffffff;
} else {
sain6 = (struct sockaddr_in6 *)&address->ss;
-
+
memcpy(&rio.rule.dst.addr.v.a.addr.v6,
- &sain6->sin6_addr.s6_addr,
- sizeof(sain6->sin6_addr.s6_addr));
+ &sain6->sin6_addr.s6_addr,
+ sizeof(sain6->sin6_addr.s6_addr));
memset(&rio.rule.dst.addr.v.a.mask.addr8, 0xff, 16);
}
pio.addr.addr.type = PF_ADDR_TABLE;
(void)strlcpy(pio.addr.addr.v.tblname, service->name,
- sizeof(pio.addr.addr.v.tblname));
+ sizeof(pio.addr.addr.v.tblname));
if (ioctl(env->pf->dev, DIOCADDADDR, &pio) == -1)
fatal("sync_ruleset: cannot add address to pool");
@@ -328,7 +328,7 @@ flush_rulesets(struct hostated *env)
strlcat(anchor, service->name, sizeof(anchor));
transaction_init(env, anchor);
transaction_commit(env);
- }
+ }
strlcpy(anchor, HOSTATED_ANCHOR, sizeof(anchor));
transaction_init(env, anchor);
transaction_commit(env);
diff --git a/usr.sbin/relayd/check_tcp.c b/usr.sbin/relayd/check_tcp.c
index 5ef386731f9..a0390326a7a 100644
--- a/usr.sbin/relayd/check_tcp.c
+++ b/usr.sbin/relayd/check_tcp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: check_tcp.c,v 1.1 2006/12/16 11:45:07 reyk Exp $ */
+/* $OpenBSD: check_tcp.c,v 1.2 2006/12/16 12:42:14 reyk Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -83,12 +83,13 @@ tcp_connect(struct host *host, struct table *table)
FD_ZERO(&fdset);
FD_SET(s, &fdset);
- switch(select(s + 1, NULL, &fdset, NULL, &tv)) {
+ /* XXX This needs to be rewritten */
+ switch (select(s + 1, NULL, &fdset, NULL, &tv)) {
case -1:
if (errno != EINTR)
fatal("check_tcp: select");
else
- return(HOST_UNKNOWN);
+ return (HOST_UNKNOWN);
case 0:
close(s);
return (HOST_DOWN);
diff --git a/usr.sbin/relayd/control.c b/usr.sbin/relayd/control.c
index 2f994e458f4..764053bafe4 100644
--- a/usr.sbin/relayd/control.c
+++ b/usr.sbin/relayd/control.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: control.c,v 1.1 2006/12/16 11:45:07 reyk Exp $ */
+/* $OpenBSD: control.c,v 1.2 2006/12/16 12:42:14 reyk Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -189,9 +189,9 @@ void
control_dispatch_imsg(int fd, short event, void *arg)
{
struct ctl_conn *c;
- struct imsg imsg;
+ struct imsg imsg;
objid_t id;
- int n;
+ int n;
if ((c = control_connbyfd(fd)) == NULL) {
log_warn("control_dispatch_imsg: fd %d: not found", fd);
diff --git a/usr.sbin/relayd/hce.c b/usr.sbin/relayd/hce.c
index 7144357538b..3bed9f206e3 100644
--- a/usr.sbin/relayd/hce.c
+++ b/usr.sbin/relayd/hce.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: hce.c,v 1.1 2006/12/16 11:45:07 reyk Exp $ */
+/* $OpenBSD: hce.c,v 1.2 2006/12/16 12:42:14 reyk Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -98,45 +98,45 @@ hce(struct hostated *x_env, int pipe_parent2pfe[2], int pipe_parent2hce[2],
setproctitle("host check engine");
hostated_process = PROC_HCE;
- if (setgroups(1, &pw->pw_gid) ||
- setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) ||
- setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid))
- fatal("hce: can't drop privileges");
+ if (setgroups(1, &pw->pw_gid) ||
+ setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) ||
+ setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid))
+ fatal("hce: can't drop privileges");
event_init();
- signal_set(&ev_sigint, SIGINT, hce_sig_handler, NULL);
- signal_set(&ev_sigterm, SIGTERM, hce_sig_handler, NULL);
- signal_add(&ev_sigint, NULL);
- signal_add(&ev_sigterm, NULL);
-
- /* setup pipes */
- close(pipe_pfe2hce[1]);
- close(pipe_parent2hce[0]);
- close(pipe_parent2pfe[0]);
- close(pipe_parent2pfe[1]);
-
- if ((ibuf_pfe = calloc(1, sizeof(struct imsgbuf))) == NULL ||
- (ibuf_main = calloc(1, sizeof(struct imsgbuf))) == NULL)
- fatal("hce");
- imsg_init(ibuf_pfe, pipe_pfe2hce[0], hce_dispatch_imsg);
- imsg_init(ibuf_main, pipe_parent2hce[1], hce_dispatch_parent);
-
- ibuf_pfe->events = EV_READ;
- event_set(&ibuf_pfe->ev, ibuf_pfe->fd, ibuf_pfe->events,
- ibuf_pfe->handler, ibuf_pfe);
- event_add(&ibuf_pfe->ev, NULL);
-
- ibuf_main->events = EV_READ;
- event_set(&ibuf_main->ev, ibuf_main->fd, ibuf_main->events,
- ibuf_main->handler, ibuf_main);
- event_add(&ibuf_main->ev, NULL);
-
- evtimer_set(&env->ev, hce_launch_checks, NULL);
+ signal_set(&ev_sigint, SIGINT, hce_sig_handler, NULL);
+ signal_set(&ev_sigterm, SIGTERM, hce_sig_handler, NULL);
+ signal_add(&ev_sigint, NULL);
+ signal_add(&ev_sigterm, NULL);
+
+ /* setup pipes */
+ close(pipe_pfe2hce[1]);
+ close(pipe_parent2hce[0]);
+ close(pipe_parent2pfe[0]);
+ close(pipe_parent2pfe[1]);
+
+ if ((ibuf_pfe = calloc(1, sizeof(struct imsgbuf))) == NULL ||
+ (ibuf_main = calloc(1, sizeof(struct imsgbuf))) == NULL)
+ fatal("hce");
+ imsg_init(ibuf_pfe, pipe_pfe2hce[0], hce_dispatch_imsg);
+ imsg_init(ibuf_main, pipe_parent2hce[1], hce_dispatch_parent);
+
+ ibuf_pfe->events = EV_READ;
+ event_set(&ibuf_pfe->ev, ibuf_pfe->fd, ibuf_pfe->events,
+ ibuf_pfe->handler, ibuf_pfe);
+ event_add(&ibuf_pfe->ev, NULL);
+
+ ibuf_main->events = EV_READ;
+ event_set(&ibuf_main->ev, ibuf_main->fd, ibuf_main->events,
+ ibuf_main->handler, ibuf_main);
+ event_add(&ibuf_main->ev, NULL);
+
+ evtimer_set(&env->ev, hce_launch_checks, NULL);
tv.tv_sec = env->interval;
tv.tv_usec = 0;
evtimer_add(&env->ev, &tv);
-
+
hce_launch_checks(0, 0, NULL);
event_dispatch();
@@ -149,8 +149,8 @@ void
hce_launch_checks(int fd, short event, void *arg)
{
int previous_up;
- struct host *host;
- struct table *table;
+ struct host *host;
+ struct table *table;
struct ctl_status st;
struct timeval tv;
@@ -168,8 +168,7 @@ hce_launch_checks(int fd, short event, void *arg)
switch (table->check) {
case CHECK_ICMP:
host->up = check_icmp(host, env->icmp_sock,
- env->icmp6_sock,
- table->timeout);
+ env->icmp6_sock, table->timeout);
break;
case CHECK_TCP:
host->up = check_tcp(host, table);
@@ -188,7 +187,7 @@ hce_launch_checks(int fd, short event, void *arg)
st.id = host->id;
st.up = host->up;
imsg_compose(ibuf_pfe, IMSG_HOST_STATUS, 0, 0,
- &st, sizeof(st));
+ &st, sizeof(st));
}
}
}
@@ -280,39 +279,39 @@ hce_dispatch_imsg(int fd, short event, void *ptr)
void
hce_dispatch_parent(int fd, short event, void * ptr)
{
- struct imsgbuf *ibuf;
- struct imsg imsg;
- ssize_t n;
+ struct imsgbuf *ibuf;
+ struct imsg imsg;
+ ssize_t n;
ibuf = ptr;
switch (event) {
- case EV_READ:
- if ((n = imsg_read(ibuf)) == -1)
- fatal("hce_dispatch_parent: imsg_read error");
- if (n == 0) /* connection closed */
- fatalx("hce_dispatch_parent: pipe closed");
- break;
- case EV_WRITE:
- if (msgbuf_write(&ibuf->w) == -1)
- fatal("hce_dispatch_parent: msgbuf_write");
- imsg_event_add(ibuf);
- return;
- default:
- fatalx("hce_dispatch_parent: unknown event");
+ case EV_READ:
+ if ((n = imsg_read(ibuf)) == -1)
+ fatal("hce_dispatch_parent: imsg_read error");
+ if (n == 0) /* connection closed */
+ fatalx("hce_dispatch_parent: pipe closed");
+ break;
+ case EV_WRITE:
+ if (msgbuf_write(&ibuf->w) == -1)
+ fatal("hce_dispatch_parent: msgbuf_write");
+ imsg_event_add(ibuf);
+ return;
+ default:
+ fatalx("hce_dispatch_parent: unknown event");
}
- for (;;) {
- if ((n = imsg_get(ibuf, &imsg)) == -1)
- fatal("hce_dispatch_parent: imsg_read error");
- if (n == 0)
- break;
-
- switch (imsg.hdr.type) {
- default:
- log_debug("hce_dispatch_parent: unexpected imsg %d",
- imsg.hdr.type);
- break;
- }
- imsg_free(&imsg);
- }
+ for (;;) {
+ if ((n = imsg_get(ibuf, &imsg)) == -1)
+ fatal("hce_dispatch_parent: imsg_read error");
+ if (n == 0)
+ break;
+
+ switch (imsg.hdr.type) {
+ default:
+ log_debug("hce_dispatch_parent: unexpected imsg %d",
+ imsg.hdr.type);
+ break;
+ }
+ imsg_free(&imsg);
+ }
}
diff --git a/usr.sbin/relayd/parse.y b/usr.sbin/relayd/parse.y
index 977b7a74cb1..f2e008340ff 100644
--- a/usr.sbin/relayd/parse.y
+++ b/usr.sbin/relayd/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.1 2006/12/16 11:45:07 reyk Exp $ */
+/* $OpenBSD: parse.y,v 1.2 2006/12/16 12:42:14 reyk Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -74,16 +74,16 @@ struct sym {
char *val;
};
-int symset(const char *, const char *, int);
-char *symget(const char *);
-int cmdline_symset(char *);
+int symset(const char *, const char *, int);
+char *symget(const char *);
+int cmdline_symset(char *);
struct address *host_v4(const char *);
struct address *host_v6(const char *);
int host_dns(const char *, struct addresslist *,
- int, in_port_t, const char *);
+ int, in_port_t, const char *);
int host(const char *, struct addresslist *,
- int, in_port_t, const char *);
+ int, in_port_t, const char *);
typedef struct {
union {
@@ -117,7 +117,7 @@ grammar : /* empty */
| grammar error '\n' { errors++; }
;
-number : STRING {
+number : STRING {
const char *estr;
$$ = strtonum($1, 0, UINT_MAX, &estr);
@@ -142,7 +142,7 @@ varset : STRING '=' STRING {
main : INTERVAL number { conf->interval = $2; }
;
-service : SERVICE STRING {
+service : SERVICE STRING {
struct service *srv;
TAILQ_FOREACH(srv, &conf->services, entry)
@@ -156,12 +156,12 @@ service : SERVICE STRING {
if ((srv = calloc(1, sizeof (*srv))) == NULL)
fatal("out of memory");
- if (strlcpy(srv->name, $2, sizeof (srv->name)) >=
- sizeof (srv->name)) {
+ if (strlcpy(srv->name, $2, sizeof(srv->name)) >=
+ sizeof(srv->name)) {
yyerror("service name truncated");
YYERROR;
}
- free ($2);
+ free($2);
srv->id = last_service_id++;
if (last_service_id == UINT_MAX) {
yyerror("too many services defined");
@@ -183,13 +183,13 @@ service : SERVICE STRING {
if (service->backup == NULL)
service->backup = &conf->empty_table;
else if (service->backup->port !=
- service->table->port) {
+ service->table->port) {
yyerror("service %s uses two different ports "
- "for its table and backup table",
- service->name);
+ "for its table and backup table",
+ service->name);
YYERROR;
}
-
+
if (!(service->flags & F_DISABLE))
service->flags |= F_ADD;
TAILQ_INSERT_HEAD(&conf->services, service, entry);
@@ -200,7 +200,7 @@ serviceopts_l : serviceopts_l serviceoptsl nl
| serviceoptsl optnl
;
-serviceoptsl : TABLE STRING {
+serviceoptsl : TABLE STRING {
struct table *tb;
TAILQ_FOREACH(tb, &conf->tables, entry)
@@ -217,7 +217,7 @@ serviceoptsl : TABLE STRING {
free($2);
}
}
- | BACKUP TABLE STRING {
+ | BACKUP TABLE STRING {
struct table *tb;
if (service->backup) {
@@ -270,7 +270,7 @@ serviceoptsl : TABLE STRING {
}
;
-table : TABLE STRING {
+table : TABLE STRING {
struct table *tb;
TAILQ_FOREACH(tb, &conf->tables, entry)
@@ -281,12 +281,12 @@ table : TABLE STRING {
free($2);
YYERROR;
}
-
+
if ((tb = calloc(1, sizeof (*tb))) == NULL)
fatal("out of memory");
-
- if (strlcpy(tb->name, $2, sizeof (tb->name)) >=
- sizeof (tb->name)) {
+
+ if (strlcpy(tb->name, $2, sizeof(tb->name)) >=
+ sizeof(tb->name)) {
yyerror("table name truncated");
YYERROR;
}
@@ -296,9 +296,9 @@ table : TABLE STRING {
yyerror("too many tables defined");
YYERROR;
}
- free ($2);
+ free($2);
table = tb;
- } '{' optnl tableopts_l '}' {
+ } '{' optnl tableopts_l '}' {
if (table->port == 0) {
yyerror("table %s has no port", table->name);
YYERROR;
@@ -320,25 +320,25 @@ tableopts_l : tableopts_l tableoptsl nl
| tableoptsl optnl
;
-tableoptsl : host {
+tableoptsl : host {
$1->tableid = table->id;
$1->tablename = table->name;
TAILQ_INSERT_HEAD(&table->hosts, $1, entry);
}
- | TIMEOUT number {
+ | TIMEOUT number {
table->timeout = $2;
}
- | CHECK ICMP {
+ | CHECK ICMP {
table->check = CHECK_ICMP;
}
- | CHECK TCP {
+ | CHECK TCP {
table->check = CHECK_TCP;
}
| CHECK HTTP STRING CODE number {
table->check = CHECK_HTTP_CODE;
table->retcode = $5;
- if (strlcpy(table->path, $3, sizeof (table->path)) >=
- sizeof (table->path)) {
+ if (strlcpy(table->path, $3, sizeof(table->path)) >=
+ sizeof(table->path)) {
yyerror("http path truncated");
free($3);
YYERROR;
@@ -346,8 +346,8 @@ tableoptsl : host {
}
| CHECK HTTP STRING DIGEST STRING {
table->check = CHECK_HTTP_DIGEST;
- if (strlcpy(table->path, $3, sizeof (table->path)) >=
- sizeof (table->path)) {
+ if (strlcpy(table->path, $3, sizeof(table->path)) >=
+ sizeof(table->path)) {
yyerror("http path truncated");
free($3);
free($5);
@@ -378,12 +378,12 @@ interface : /*empty*/ { $$ = NULL; }
;
host : HOST STRING {
- struct host *r;
+ struct host *r;
struct address *a;
struct addresslist al;
- if ((r = calloc(1, sizeof (*r))) == NULL)
- fatal("out of memory");
+ if ((r = calloc(1, sizeof(*r))) == NULL)
+ fatal("out of memory");
TAILQ_INIT(&al);
if (host($2, &al, 1, 0, NULL) <= 0) {
@@ -395,8 +395,8 @@ host : HOST STRING {
memcpy(&r->ss, &a->ss, sizeof(r->ss));
free(a);
- if (strlcpy(r->name, $2, sizeof (r->name)) >=
- sizeof (r->name)) {
+ if (strlcpy(r->name, $2, sizeof(r->name)) >=
+ sizeof(r->name)) {
yyerror("host name truncated");
free($2);
YYERROR;
@@ -683,7 +683,7 @@ parse_config(struct hostated *x_conf, const char *filename, int opts)
conf->empty_table.id = EMPTY_TABLE;
conf->empty_table.flags |= F_DISABLE;
(void)strlcpy(conf->empty_table.name, "empty",
- sizeof(conf->empty_table.name));
+ sizeof(conf->empty_table.name));
conf->interval = CHECK_INTERVAL;
conf->opts = opts;
@@ -835,7 +835,7 @@ host_v6(const char *s)
bzero(&ina6, sizeof(ina6));
if (inet_pton(AF_INET6, s, &ina6) != 1)
return (NULL);
-
+
if ((h = calloc(1, sizeof(*h))) == NULL)
fatal(NULL);
sin6 = (struct sockaddr_in6 *)&h->ss;
@@ -912,7 +912,7 @@ host(const char *s, struct addresslist *al, int max,
in_port_t port, const char *ifname)
{
struct address *h;
-
+
h = host_v4(s);
/* IPv6 address? */
@@ -928,7 +928,7 @@ host(const char *s, struct addresslist *al, int max,
return (-1);
}
}
-
+
TAILQ_INSERT_HEAD(al, h, entry);
return (1);
}
diff --git a/usr.sbin/relayd/pfe.c b/usr.sbin/relayd/pfe.c
index 0a7ff43949f..3fe5f29039a 100644
--- a/usr.sbin/relayd/pfe.c
+++ b/usr.sbin/relayd/pfe.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pfe.c,v 1.1 2006/12/16 11:45:07 reyk Exp $ */
+/* $OpenBSD: pfe.c,v 1.2 2006/12/16 12:42:14 reyk Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -94,10 +94,10 @@ pfe(struct hostated *x_env, int pipe_parent2pfe[2], int pipe_parent2hce[2],
setproctitle("pf update engine");
hostated_process = PROC_PFE;
- if (setgroups(1, &pw->pw_gid) ||
- setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) ||
- setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid))
- fatal("pfe: cannot drop privileges");
+ if (setgroups(1, &pw->pw_gid) ||
+ setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) ||
+ setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid))
+ fatal("pfe: cannot drop privileges");
event_init();
@@ -115,17 +115,17 @@ pfe(struct hostated *x_env, int pipe_parent2pfe[2], int pipe_parent2hce[2],
if ((ibuf_hce = calloc(1, sizeof(struct imsgbuf))) == NULL ||
(ibuf_main = calloc(1, sizeof(struct imsgbuf))) == NULL)
fatal("pfe");
- imsg_init(ibuf_hce, pipe_pfe2hce[1], pfe_dispatch_imsg);
- imsg_init(ibuf_main, pipe_parent2pfe[1], pfe_dispatch_parent);
+ imsg_init(ibuf_hce, pipe_pfe2hce[1], pfe_dispatch_imsg);
+ imsg_init(ibuf_main, pipe_parent2pfe[1], pfe_dispatch_parent);
ibuf_hce->events = EV_READ;
event_set(&ibuf_hce->ev, ibuf_hce->fd, ibuf_hce->events,
- ibuf_hce->handler, ibuf_hce);
+ ibuf_hce->handler, ibuf_hce);
event_add(&ibuf_hce->ev, NULL);
ibuf_main->events = EV_READ;
event_set(&ibuf_main->ev, ibuf_main->fd, ibuf_main->events,
- ibuf_main->handler, ibuf_main);
+ ibuf_main->handler, ibuf_main);
event_add(&ibuf_main->ev, NULL);
TAILQ_INIT(&ctl_conns);
@@ -188,7 +188,7 @@ pfe_dispatch_imsg(int fd, short event, void *ptr)
fatalx("pfe_dispatch_imsg: invalid host id");
if (host->up == st.up) {
log_debug("pfe_dispatch_imsg: host %d => %d",
- host->id, host->up);
+ host->id, host->up);
fatalx("pfe_dispatch_imsg: desynchronized");
}
@@ -196,7 +196,7 @@ pfe_dispatch_imsg(int fd, short event, void *ptr)
fatalx("pfe_dispatch_imsg: invalid table id");
log_debug("pfe_dispatch_imsg: state %d for host %u %s",
- st.up, host->id, host->name);
+ st.up, host->id, host->name);
if ((st.up == HOST_UNKNOWN && host->up == HOST_DOWN) ||
(st.up == HOST_DOWN && host->up == HOST_UNKNOWN)) {
@@ -222,7 +222,7 @@ pfe_dispatch_imsg(int fd, short event, void *ptr)
break;
default:
log_debug("pfe_dispatch_imsg: unexpected imsg %d",
- imsg.hdr.type);
+ imsg.hdr.type);
break;
}
imsg_free(&imsg);
@@ -234,40 +234,40 @@ void
pfe_dispatch_parent(int fd, short event, void * ptr)
{
struct imsgbuf *ibuf;
- struct imsg imsg;
- ssize_t n;
+ struct imsg imsg;
+ ssize_t n;
ibuf = ptr;
switch (event) {
- case EV_READ:
- if ((n = imsg_read(ibuf)) == -1)
- fatal("imsg_read error");
- if (n == 0) /* connection closed */
- fatalx("pfe_dispatch_parent: pipe closed");
- break;
- case EV_WRITE:
- if (msgbuf_write(&ibuf->w) == -1)
- fatal("msgbuf_write");
- imsg_event_add(ibuf);
- return;
- default:
- fatalx("pfe_dispatch_parent: unknown event");
+ case EV_READ:
+ if ((n = imsg_read(ibuf)) == -1)
+ fatal("imsg_read error");
+ if (n == 0) /* connection closed */
+ fatalx("pfe_dispatch_parent: pipe closed");
+ break;
+ case EV_WRITE:
+ if (msgbuf_write(&ibuf->w) == -1)
+ fatal("msgbuf_write");
+ imsg_event_add(ibuf);
+ return;
+ default:
+ fatalx("pfe_dispatch_parent: unknown event");
}
- for (;;) {
- if ((n = imsg_get(ibuf, &imsg)) == -1)
- fatal("pfe_dispatch_parent: imsg_read error");
- if (n == 0)
- break;
-
- switch (imsg.hdr.type) {
- default:
- log_debug("pfe_dispatch_parent: unexpected imsg %d",
- imsg.hdr.type);
- break;
- }
- imsg_free(&imsg);
- }
+ for (;;) {
+ if ((n = imsg_get(ibuf, &imsg)) == -1)
+ fatal("pfe_dispatch_parent: imsg_read error");
+ if (n == 0)
+ break;
+
+ switch (imsg.hdr.type) {
+ default:
+ log_debug("pfe_dispatch_parent: unexpected imsg %d",
+ imsg.hdr.type);
+ break;
+ }
+ imsg_free(&imsg);
+ }
}
void
@@ -278,25 +278,25 @@ show(struct ctl_conn *c)
TAILQ_FOREACH(service, &env->services, entry) {
imsg_compose(&c->ibuf, IMSG_CTL_SERVICE, 0, 0,
- service, sizeof(*service));
+ service, sizeof(*service));
if (service->flags & F_DISABLE)
continue;
imsg_compose(&c->ibuf, IMSG_CTL_TABLE, 0, 0,
- service->table, sizeof(*service->table));
+ service->table, sizeof(*service->table));
if (!(service->table->flags & F_DISABLE))
TAILQ_FOREACH(host, &service->table->hosts, entry)
imsg_compose(&c->ibuf, IMSG_CTL_HOST, 0, 0,
- host, sizeof(*host));
+ host, sizeof(*host));
if (service->backup->id == EMPTY_TABLE)
continue;
imsg_compose(&c->ibuf, IMSG_CTL_TABLE, 0, 0,
- service->backup, sizeof(*service->backup));
+ service->backup, sizeof(*service->backup));
if (!(service->backup->flags & F_DISABLE))
TAILQ_FOREACH(host, &service->backup->hosts, entry)
imsg_compose(&c->ibuf, IMSG_CTL_HOST, 0, 0,
- host, sizeof(*host));
+ host, sizeof(*host));
}
imsg_compose(&c->ibuf, IMSG_CTL_END, 0, 0, NULL, 0);
}
@@ -480,7 +480,7 @@ pfe_sync(void)
service->table->flags &= ~(F_CHANGED);
service->backup->flags &= ~(F_CHANGED);
-
+
if (service->flags & F_DOWN) {
if (service->flags & F_ACTIVE_RULESET) {
flush_table(env, service);
diff --git a/usr.sbin/relayd/pfe_filter.c b/usr.sbin/relayd/pfe_filter.c
index b7bd7550070..89ea50b48c5 100644
--- a/usr.sbin/relayd/pfe_filter.c
+++ b/usr.sbin/relayd/pfe_filter.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pfe_filter.c,v 1.1 2006/12/16 11:45:07 reyk Exp $ */
+/* $OpenBSD: pfe_filter.c,v 1.2 2006/12/16 12:42:14 reyk Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -52,7 +52,7 @@ void
init_filter(struct hostated *env)
{
struct pf_status status;
-
+
if ((env->pf = calloc(1, sizeof(*(env->pf)))) == NULL)
fatal("calloc");
if ((env->pf->dev = open(PF_SOCKET, O_RDWR)) == -1)
@@ -75,14 +75,14 @@ init_tables(struct hostated *env)
if ((tables = calloc(env->servicecount, sizeof(*tables))) == NULL)
fatal("calloc");
i = 0;
-
+
TAILQ_FOREACH(service, &env->services, entry) {
(void)strlcpy(tables[i].pfrt_anchor, HOSTATED_ANCHOR "/",
- sizeof(tables[i].pfrt_anchor));
+ sizeof(tables[i].pfrt_anchor));
(void)strlcat(tables[i].pfrt_anchor, service->name,
- sizeof(tables[i].pfrt_anchor));
+ sizeof(tables[i].pfrt_anchor));
(void)strlcpy(tables[i].pfrt_name, service->name,
- sizeof(tables[i].pfrt_name));
+ sizeof(tables[i].pfrt_name));
tables[i].pfrt_flags |= PFR_TFLAG_PERSIST;
i++;
}
@@ -116,9 +116,9 @@ kill_tables(struct hostated *env) {
memset(&io, 0, sizeof(io));
TAILQ_FOREACH(service, &env->services, entry) {
(void)strlcpy(io.pfrio_table.pfrt_anchor, HOSTATED_ANCHOR "/",
- sizeof(io.pfrio_table.pfrt_anchor));
+ sizeof(io.pfrio_table.pfrt_anchor));
(void)strlcat(io.pfrio_table.pfrt_anchor, service->name,
- sizeof(io.pfrio_table.pfrt_anchor));
+ sizeof(io.pfrio_table.pfrt_anchor));
if (ioctl(env->pf->dev, DIOCRCLRTABLES, &io) == -1)
fatal("kill_tables: ioctl faile: ioctl failed");
}
@@ -152,11 +152,11 @@ sync_table(struct hostated *env, struct service *service, struct table *table)
io.pfrio_size2 = 0;
io.pfrio_buffer = addlist;
(void)strlcpy(io.pfrio_table.pfrt_anchor, HOSTATED_ANCHOR "/",
- sizeof(io.pfrio_table.pfrt_anchor));
+ sizeof(io.pfrio_table.pfrt_anchor));
(void)strlcat(io.pfrio_table.pfrt_anchor, service->name,
- sizeof(io.pfrio_table.pfrt_anchor));
+ sizeof(io.pfrio_table.pfrt_anchor));
(void)strlcpy(io.pfrio_table.pfrt_name, service->name,
- sizeof(io.pfrio_table.pfrt_name));
+ sizeof(io.pfrio_table.pfrt_name));
i = 0;
TAILQ_FOREACH(host, &table->hosts, entry) {
@@ -168,14 +168,14 @@ sync_table(struct hostated *env, struct service *service, struct table *table)
sain = (struct sockaddr_in *)&host->ss;
addlist[i].pfra_af = AF_INET;
memcpy(&(addlist[i].pfra_ip4addr), &sain->sin_addr,
- sizeof(sain->sin_addr));
+ sizeof(sain->sin_addr));
addlist[i].pfra_net = 32;
break;
case AF_INET6:
sain6 = (struct sockaddr_in6 *)&host->ss;
addlist[i].pfra_af = AF_INET6;
memcpy(&(addlist[i].pfra_ip6addr), &sain6->sin6_addr,
- sizeof(sain6->sin6_addr));
+ sizeof(sain6->sin6_addr));
addlist[i].pfra_net = 128;
break;
default:
@@ -191,8 +191,8 @@ sync_table(struct hostated *env, struct service *service, struct table *table)
fatal("sync_table: cannot set address list");
log_debug("sync_table: table %s: %d added, %d deleted, %d changed",
- io.pfrio_table.pfrt_name,
- io.pfrio_nadd, io.pfrio_ndel, io.pfrio_nchange);
+ io.pfrio_table.pfrt_name,
+ io.pfrio_nadd, io.pfrio_ndel, io.pfrio_nchange);
}
void
@@ -202,11 +202,11 @@ flush_table(struct hostated *env, struct service *service)
memset(&io, 0, sizeof(io));
(void)strlcpy(io.pfrio_table.pfrt_anchor, HOSTATED_ANCHOR "/",
- sizeof(io.pfrio_table.pfrt_anchor));
+ sizeof(io.pfrio_table.pfrt_anchor));
(void)strlcat(io.pfrio_table.pfrt_anchor, service->name,
- sizeof(io.pfrio_table.pfrt_anchor));
+ sizeof(io.pfrio_table.pfrt_anchor));
(void)strlcpy(io.pfrio_table.pfrt_name, service->name,
- sizeof(io.pfrio_table.pfrt_name));
+ sizeof(io.pfrio_table.pfrt_name));
if (ioctl(env->pf->dev, DIOCRCLRADDRS, &io) == -1)
fatal("flush_table: cannot flush table");
log_debug("flush_table: flushed table %s", service->name);
@@ -216,17 +216,17 @@ flush_table(struct hostated *env, struct service *service)
int
transaction_init(struct hostated *env, const char *anchor)
{
- env->pf->pft.size = 1;
- env->pf->pft.esize = sizeof env->pf->pfte;
- env->pf->pft.array = &env->pf->pfte;
+ env->pf->pft.size = 1;
+ env->pf->pft.esize = sizeof env->pf->pfte;
+ env->pf->pft.array = &env->pf->pfte;
memset(&env->pf->pfte, 0, sizeof env->pf->pfte);
strlcpy(env->pf->pfte.anchor, anchor, PF_ANCHOR_NAME_SIZE);
env->pf->pfte.rs_num = PF_RULESET_RDR;
- if (ioctl(env->pf->dev, DIOCXBEGIN, &env->pf->pft) == -1)
- return (-1);
- return (0);
+ if (ioctl(env->pf->dev, DIOCXBEGIN, &env->pf->pft) == -1)
+ return (-1);
+ return (0);
}
int
@@ -278,30 +278,30 @@ sync_ruleset(struct hostated *env, struct service *service, int enable)
rio.rule.action = PF_RDR;
if (strlen(service->tag))
(void)strlcpy(rio.rule.tagname, service->tag,
- sizeof(rio.rule.tagname));
+ sizeof(rio.rule.tagname));
if (strlen(address->ifname))
(void)strlcpy(rio.rule.ifname, address->ifname,
- sizeof(rio.rule.ifname));
+ sizeof(rio.rule.ifname));
if (address->ss.ss_family == AF_INET) {
sain = (struct sockaddr_in *)&address->ss;
-
- rio.rule.dst.addr.v.a.addr.addr32[0] =
- sain->sin_addr.s_addr;
+
+ rio.rule.dst.addr.v.a.addr.addr32[0] =
+ sain->sin_addr.s_addr;
rio.rule.dst.addr.v.a.mask.addr32[0] = 0xffffffff;
} else {
sain6 = (struct sockaddr_in6 *)&address->ss;
-
+
memcpy(&rio.rule.dst.addr.v.a.addr.v6,
- &sain6->sin6_addr.s6_addr,
- sizeof(sain6->sin6_addr.s6_addr));
+ &sain6->sin6_addr.s6_addr,
+ sizeof(sain6->sin6_addr.s6_addr));
memset(&rio.rule.dst.addr.v.a.mask.addr8, 0xff, 16);
}
pio.addr.addr.type = PF_ADDR_TABLE;
(void)strlcpy(pio.addr.addr.v.tblname, service->name,
- sizeof(pio.addr.addr.v.tblname));
+ sizeof(pio.addr.addr.v.tblname));
if (ioctl(env->pf->dev, DIOCADDADDR, &pio) == -1)
fatal("sync_ruleset: cannot add address to pool");
@@ -328,7 +328,7 @@ flush_rulesets(struct hostated *env)
strlcat(anchor, service->name, sizeof(anchor));
transaction_init(env, anchor);
transaction_commit(env);
- }
+ }
strlcpy(anchor, HOSTATED_ANCHOR, sizeof(anchor));
transaction_init(env, anchor);
transaction_commit(env);
diff --git a/usr.sbin/relayd/relayd.8 b/usr.sbin/relayd/relayd.8
index 7e02600665a..1997019152d 100644
--- a/usr.sbin/relayd/relayd.8
+++ b/usr.sbin/relayd/relayd.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: relayd.8,v 1.2 2006/12/16 11:52:51 reyk Exp $
+.\" $OpenBSD: relayd.8,v 1.3 2006/12/16 12:42:14 reyk Exp $
.\"
.\" Copyright (c) 2006 Pierre-Yves Ritschard <pyr@openbsd.org>
.\"
@@ -37,7 +37,7 @@ To enable
.Nm
to install rulesets through the anchor you will
need the following line in the NAT section of your
-.Xr pf.conf 5
+.Xr pf.conf 5
configuration file:
.Bd -literal -offset 2n
rdr-anchor "hostated/*"
diff --git a/usr.sbin/relayd/relayd.c b/usr.sbin/relayd/relayd.c
index fb67140c8c8..dd0f8577258 100644
--- a/usr.sbin/relayd/relayd.c
+++ b/usr.sbin/relayd/relayd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: relayd.c,v 1.1 2006/12/16 11:45:07 reyk Exp $ */
+/* $OpenBSD: relayd.c,v 1.2 2006/12/16 12:42:14 reyk Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -89,7 +89,7 @@ usage(void)
extern char *__progname;
fprintf(stderr, "%s [-dnv] [-f file]\n", __progname);
- exit (1);
+ exit(1);
}
int main(int argc, char *argv[])
@@ -98,7 +98,7 @@ int main(int argc, char *argv[])
int debug;
u_int32_t opts;
struct hostated env;
- const char *conffile;
+ const char *conffile;
struct event ev_sigint;
struct event ev_sigterm;
struct event ev_sigchld;
@@ -126,7 +126,6 @@ int main(int argc, char *argv[])
default:
usage();
}
-
}
log_init(debug);
@@ -166,7 +165,7 @@ int main(int argc, char *argv[])
pfe_pid = pfe(&env, pipe_parent2pfe, pipe_parent2hce, pipe_pfe2hce);
hce_pid = hce(&env, pipe_parent2pfe, pipe_parent2hce, pipe_pfe2hce);
-
+
setproctitle("parent");
event_init();
@@ -179,7 +178,7 @@ int main(int argc, char *argv[])
signal_add(&ev_sigterm, NULL);
signal_add(&ev_sigchld, NULL);
signal_add(&ev_sighup, NULL);
-
+
close(pipe_parent2pfe[1]);
close(pipe_parent2hce[1]);
close(pipe_pfe2hce[0]);
@@ -192,15 +191,15 @@ int main(int argc, char *argv[])
imsg_init(ibuf_pfe, pipe_parent2pfe[0], main_dispatch_pfe);
imsg_init(ibuf_hce, pipe_parent2hce[0], main_dispatch_hce);
- ibuf_pfe->events = EV_READ;
- event_set(&ibuf_pfe->ev, ibuf_pfe->fd, ibuf_pfe->events,
- ibuf_pfe->handler, ibuf_pfe);
- event_add(&ibuf_pfe->ev, NULL);
+ ibuf_pfe->events = EV_READ;
+ event_set(&ibuf_pfe->ev, ibuf_pfe->fd, ibuf_pfe->events,
+ ibuf_pfe->handler, ibuf_pfe);
+ event_add(&ibuf_pfe->ev, NULL);
- ibuf_hce->events = EV_READ;
- event_set(&ibuf_hce->ev, ibuf_hce->fd, ibuf_hce->events,
- ibuf_hce->handler, ibuf_hce);
- event_add(&ibuf_hce->ev, NULL);
+ ibuf_hce->events = EV_READ;
+ event_set(&ibuf_hce->ev, ibuf_hce->fd, ibuf_hce->events,
+ ibuf_hce->handler, ibuf_hce);
+ event_add(&ibuf_hce->ev, NULL);
event_dispatch();
@@ -217,11 +216,11 @@ main_shutdown(void)
if (hce_pid)
kill(hce_pid, SIGTERM);
- do {
- if ((pid = wait(NULL)) == -1 &&
- errno != EINTR && errno != ECHILD)
- fatal("wait");
- } while (pid != -1 || (pid == -1 && errno == EINTR));
+ do {
+ if ((pid = wait(NULL)) == -1 &&
+ errno != EINTR && errno != ECHILD)
+ fatal("wait");
+ } while (pid != -1 || (pid == -1 && errno == EINTR));
control_cleanup();
log_info("terminating");
@@ -231,21 +230,21 @@ main_shutdown(void)
int
check_child(pid_t pid, const char *pname)
{
- int status;
-
- if (waitpid(pid, &status, WNOHANG) > 0) {
- if (WIFEXITED(status)) {
- log_warnx("check_child: lost child: %s exited", pname);
- return (1);
- }
- if (WIFSIGNALED(status)) {
- log_warnx("check_child: lost child: %s terminated; signal %d",
- pname, WTERMSIG(status));
- return (1);
- }
- }
-
- return (0);
+ int status;
+
+ if (waitpid(pid, &status, WNOHANG) > 0) {
+ if (WIFEXITED(status)) {
+ log_warnx("check_child: lost child: %s exited", pname);
+ return (1);
+ }
+ if (WIFSIGNALED(status)) {
+ log_warnx("check_child: lost child: %s terminated; "
+ "signal %d", pname, WTERMSIG(status));
+ return (1);
+ }
+ }
+
+ return (0);
}
void
@@ -256,8 +255,8 @@ imsg_event_add(struct imsgbuf *ibuf)
ibuf->events |= EV_WRITE;
event_del(&ibuf->ev);
- event_set(&ibuf->ev, ibuf->fd, ibuf->events, ibuf->handler, ibuf);
- event_add(&ibuf->ev, NULL);
+ event_set(&ibuf->ev, ibuf->fd, ibuf->events, ibuf->handler, ibuf);
+ event_add(&ibuf->ev, NULL);
}
void
@@ -305,40 +304,40 @@ void
main_dispatch_hce(int fd, short event, void * ptr)
{
struct imsgbuf *ibuf;
- struct imsg imsg;
- ssize_t n;
+ struct imsg imsg;
+ ssize_t n;
ibuf = ptr;
switch (event) {
- case EV_READ:
- if ((n = imsg_read(ibuf)) == -1)
- fatal("imsg_read error");
- if (n == 0) /* connection closed */
- fatalx("parent: pipe closed");
- break;
- case EV_WRITE:
- if (msgbuf_write(&ibuf->w) == -1)
- fatal("msgbuf_write");
- imsg_event_add(ibuf);
- return;
- default:
- fatalx("unknown event");
+ case EV_READ:
+ if ((n = imsg_read(ibuf)) == -1)
+ fatal("imsg_read error");
+ if (n == 0) /* connection closed */
+ fatalx("parent: pipe closed");
+ break;
+ case EV_WRITE:
+ if (msgbuf_write(&ibuf->w) == -1)
+ fatal("msgbuf_write");
+ imsg_event_add(ibuf);
+ return;
+ default:
+ fatalx("unknown event");
}
- for (;;) {
- if ((n = imsg_get(ibuf, &imsg)) == -1)
- fatal("main_dispatch_hce: imsg_read error");
- if (n == 0)
- break;
-
- switch (imsg.hdr.type) {
- default:
- log_debug("main_dispatch_hce: unexpected imsg %d",
- imsg.hdr.type);
- break;
- }
- imsg_free(&imsg);
- }
+ for (;;) {
+ if ((n = imsg_get(ibuf, &imsg)) == -1)
+ fatal("main_dispatch_hce: imsg_read error");
+ if (n == 0)
+ break;
+
+ switch (imsg.hdr.type) {
+ default:
+ log_debug("main_dispatch_hce: unexpected imsg %d",
+ imsg.hdr.type);
+ break;
+ }
+ imsg_free(&imsg);
+ }
}
struct host *
diff --git a/usr.sbin/relayd/relayd.conf.5 b/usr.sbin/relayd/relayd.conf.5
index 8e243e50a40..e8275a9b26b 100644
--- a/usr.sbin/relayd/relayd.conf.5
+++ b/usr.sbin/relayd/relayd.conf.5
@@ -1,4 +1,4 @@
-.\" $OpenBSD: relayd.conf.5,v 1.2 2006/12/16 11:52:51 reyk Exp $
+.\" $OpenBSD: relayd.conf.5,v 1.3 2006/12/16 12:42:14 reyk Exp $
.\"
.\" Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
.\"
@@ -23,7 +23,7 @@
.Sh DESCRIPTION
The
.Xr hostated 8
-daemon maintains
+daemon maintains
.Xr pf 4
tables up to date.
.Sh SECTIONS
@@ -38,7 +38,7 @@ configuration file.
Global settings for
.Xr hostated 8 .
.It Sy Tables
-Table definitions describe the content of a
+Table definitions describe the content of a
.Xr pf 4
table and the method used for checking the health of the hosts
they contain.
@@ -135,7 +135,7 @@ The table can be later enabled through
.Sh SERVICES
Services represent a
.Xr pf 4
-rdr rule, they are used to specify which addresses will be redirected
+rdr rule, they are used to specify which addresses will be redirected
to the hosts in the specified tables.
The configuration directives that are valid in this context are described
below.
@@ -198,7 +198,7 @@ table sorryhost {
host sorryhost.private.example.com
}
-service www {
+service www {
virtual ip www.example.com port 8080 interface trunk0
virtual ip www6.example.com port 80 interface trunk0
diff --git a/usr.sbin/relayd/relayd.h b/usr.sbin/relayd/relayd.h
index d59a934be48..0191df4100c 100644
--- a/usr.sbin/relayd/relayd.h
+++ b/usr.sbin/relayd/relayd.h
@@ -32,38 +32,38 @@
/* buffer */
struct buf {
- TAILQ_ENTRY(buf) entry;
- u_char *buf;
- size_t size;
- size_t max;
- size_t wpos;
- size_t rpos;
+ TAILQ_ENTRY(buf) entry;
+ u_char *buf;
+ size_t size;
+ size_t max;
+ size_t wpos;
+ size_t rpos;
};
struct msgbuf {
- TAILQ_HEAD(, buf) bufs;
- u_int32_t queued;
- int fd;
+ TAILQ_HEAD(, buf) bufs;
+ u_int32_t queued;
+ int fd;
};
-#define IMSG_HEADER_SIZE sizeof(struct imsg_hdr)
-#define MAX_IMSGSIZE 8192
+#define IMSG_HEADER_SIZE sizeof(struct imsg_hdr)
+#define MAX_IMSGSIZE 8192
-struct buf_read {
- u_char buf[READ_BUF_SIZE];
- u_char *rptr;
- size_t wpos;
+struct buf_read {
+ u_char buf[READ_BUF_SIZE];
+ u_char *rptr;
+ size_t wpos;
};
struct imsgbuf {
- TAILQ_HEAD(, imsg_fd) fds;
- struct buf_read r;
- struct msgbuf w;
- struct event ev;
- void (*handler)(int, short, void *);
- int fd;
- pid_t pid;
- short events;
+ TAILQ_HEAD(, imsg_fd) fds;
+ struct buf_read r;
+ struct msgbuf w;
+ struct event ev;
+ void (*handler)(int, short, void *);
+ int fd;
+ pid_t pid;
+ short events;
};
enum imsg_type {
@@ -95,18 +95,18 @@ enum imsg_type {
};
struct imsg_hdr {
- enum imsg_type type;
- u_int16_t len;
- u_int32_t peerid;
- pid_t pid;
+ enum imsg_type type;
+ u_int16_t len;
+ u_int32_t peerid;
+ pid_t pid;
};
struct imsg {
- struct imsg_hdr hdr;
- void *data;
+ struct imsg_hdr hdr;
+ void *data;
};
-typedef u_int32_t objid_t;
+typedef u_int32_t objid_t;
struct ctl_status {
objid_t id;
@@ -121,14 +121,14 @@ struct address {
};
TAILQ_HEAD(addresslist, address);
-#define F_DISABLE 0x01
-#define F_BACKUP 0x02
-#define F_USED 0x04
-#define F_ACTIVE_RULESET 0x04
-#define F_DOWN 0x08
-#define F_ADD 0x10
-#define F_DEL 0x20
-#define F_CHANGED 0x40
+#define F_DISABLE 0x01
+#define F_BACKUP 0x02
+#define F_USED 0x04
+#define F_ACTIVE_RULESET 0x04
+#define F_DOWN 0x08
+#define F_ADD 0x10
+#define F_DEL 0x20
+#define F_CHANGED 0x40
struct host {
u_int8_t flags;
@@ -137,27 +137,23 @@ struct host {
char *tablename;
char name[MAXHOSTNAMELEN];
int up;
-#define HOST_DOWN -1
-#define HOST_UNKNOWN 0
-#define HOST_UP 1
struct sockaddr_storage ss;
TAILQ_ENTRY(host) entry;
};
TAILQ_HEAD(hostlist, host);
+#define HOST_DOWN -1
+#define HOST_UNKNOWN 0
+#define HOST_UP 1
+
struct table {
objid_t id;
objid_t serviceid;
u_int8_t flags;
int check;
-#define CHECK_NOCHECK 0
-#define CHECK_ICMP 1
-#define CHECK_TCP 2
-#define CHECK_HTTP_CODE 3
-#define CHECK_HTTP_DIGEST 4
int up;
in_port_t port;
- int retcode;
+ int retcode;
int timeout;
char name[TABLE_NAME_SIZE];
char path[MAXPATHLEN];
@@ -167,6 +163,12 @@ struct table {
};
TAILQ_HEAD(tablelist, table);
+#define CHECK_NOCHECK 0
+#define CHECK_ICMP 1
+#define CHECK_TCP 2
+#define CHECK_HTTP_CODE 3
+#define CHECK_HTTP_DIGEST 4
+
struct service {
objid_t id;
u_int8_t flags;
@@ -187,9 +189,7 @@ enum {
} hostated_process;
struct hostated {
- u_int8_t opts;
-#define HOSTATED_OPT_VERBOSE 0x01
-#define HOSTATED_OPT_NOACTION 0x04
+ u_int8_t opts;
struct pfdata *pf;
int interval;
int icmp_sock;
@@ -202,20 +202,23 @@ struct hostated {
struct servicelist services;
};
+#define HOSTATED_OPT_VERBOSE 0x01
+#define HOSTATED_OPT_NOACTION 0x04
+
/* initially control.h */
struct {
- struct event ev;
- int fd;
+ struct event ev;
+ int fd;
} control_state;
enum blockmodes {
- BM_NORMAL,
- BM_NONBLOCK
+ BM_NORMAL,
+ BM_NONBLOCK
};
struct ctl_conn {
- TAILQ_ENTRY(ctl_conn) entry;
- struct imsgbuf ibuf;
+ TAILQ_ENTRY(ctl_conn) entry;
+ struct imsgbuf ibuf;
};
TAILQ_HEAD(ctl_connlist, ctl_conn);
@@ -233,41 +236,41 @@ void session_socket_blockmode(int, enum blockmodes);
extern struct ctl_connlist ctl_conns;
/* parse.y */
-int parse_config(struct hostated *, const char *, int);
+int parse_config(struct hostated *, const char *, int);
/* log.c */
-void log_init(int);
-void log_warn(const char *, ...);
-void log_warnx(const char *, ...);
-void log_info(const char *, ...);
-void log_debug(const char *, ...);
-void fatal(const char *);
-void fatalx(const char *);
+void log_init(int);
+void log_warn(const char *, ...);
+void log_warnx(const char *, ...);
+void log_info(const char *, ...);
+void log_debug(const char *, ...);
+void fatal(const char *);
+void fatalx(const char *);
/* buffer.c */
-struct buf *buf_open(size_t);
-struct buf *buf_dynamic(size_t, size_t);
-int buf_add(struct buf *, void *, size_t);
-void *buf_reserve(struct buf *, size_t);
-void *buf_seek(struct buf *, size_t, size_t);
-int buf_close(struct msgbuf *, struct buf *);
-void buf_free(struct buf *);
-void msgbuf_init(struct msgbuf *);
-void msgbuf_clear(struct msgbuf *);
-int msgbuf_write(struct msgbuf *);
+struct buf *buf_open(size_t);
+struct buf *buf_dynamic(size_t, size_t);
+int buf_add(struct buf *, void *, size_t);
+void *buf_reserve(struct buf *, size_t);
+void *buf_seek(struct buf *, size_t, size_t);
+int buf_close(struct msgbuf *, struct buf *);
+void buf_free(struct buf *);
+void msgbuf_init(struct msgbuf *);
+void msgbuf_clear(struct msgbuf *);
+int msgbuf_write(struct msgbuf *);
/* imsg.c */
-void imsg_init(struct imsgbuf *, int, void (*)(int, short, void *));
-ssize_t imsg_read(struct imsgbuf *);
-ssize_t imsg_get(struct imsgbuf *, struct imsg *);
-int imsg_compose(struct imsgbuf *, enum imsg_type, u_int32_t, pid_t,
- void *, u_int16_t);
-struct buf *imsg_create(struct imsgbuf *, enum imsg_type, u_int32_t, pid_t,
- u_int16_t);
-int imsg_add(struct buf *, void *, u_int16_t);
-int imsg_close(struct imsgbuf *, struct buf *);
-void imsg_free(struct imsg *);
-void imsg_event_add(struct imsgbuf *); /* needs to be provided externally */
+void imsg_init(struct imsgbuf *, int, void (*)(int, short, void *));
+ssize_t imsg_read(struct imsgbuf *);
+ssize_t imsg_get(struct imsgbuf *, struct imsg *);
+int imsg_compose(struct imsgbuf *, enum imsg_type, u_int32_t, pid_t,
+ void *, u_int16_t);
+struct buf *imsg_create(struct imsgbuf *, enum imsg_type, u_int32_t, pid_t,
+ u_int16_t);
+int imsg_add(struct buf *, void *, u_int16_t);
+int imsg_close(struct imsgbuf *, struct buf *);
+void imsg_free(struct imsg *);
+void imsg_event_add(struct imsgbuf *); /* needs to be provided externally */
/* pfe.c */
pid_t pfe(struct hostated *, int [2], int [2], int [2]);