summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorReyk Floeter <reyk@cvs.openbsd.org>2007-02-03 20:24:22 +0000
committerReyk Floeter <reyk@cvs.openbsd.org>2007-02-03 20:24:22 +0000
commit78b1107f485cc3d37eabe1021d24d7db78853ca6 (patch)
tree7c8d11cb666e70570cf7d9b5a6db04b75fa9745f /usr.sbin
parentc4d668ebb8f16f41c48f44e722b5b5d1a2975fcf (diff)
merge tcp-based checks into one file, no functional changes
ok pyr@
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/hoststated/Makefile4
-rw-r--r--usr.sbin/hoststated/check_http.c114
-rw-r--r--usr.sbin/hoststated/check_send_expect.c61
-rw-r--r--usr.sbin/hoststated/check_tcp.c109
-rw-r--r--usr.sbin/relayd/Makefile4
-rw-r--r--usr.sbin/relayd/check_tcp.c109
6 files changed, 220 insertions, 181 deletions
diff --git a/usr.sbin/hoststated/Makefile b/usr.sbin/hoststated/Makefile
index 20eb9be0b1c..8475f8c2f7f 100644
--- a/usr.sbin/hoststated/Makefile
+++ b/usr.sbin/hoststated/Makefile
@@ -1,9 +1,9 @@
-# $OpenBSD: Makefile,v 1.6 2007/01/30 15:11:51 reyk Exp $
+# $OpenBSD: Makefile,v 1.7 2007/02/03 20:24:21 reyk Exp $
PROG= hoststated
SRCS= parse.y log.c control.c buffer.c imsg.c hoststated.c \
ssl.c pfe.c pfe_filter.c hce.c \
- check_icmp.c check_tcp.c check_http.c check_send_expect.c
+ check_icmp.c check_tcp.c
MAN= hoststated.8 hoststated.conf.5
LDADD= -levent -lssl -lcrypto
diff --git a/usr.sbin/hoststated/check_http.c b/usr.sbin/hoststated/check_http.c
deleted file mode 100644
index 47146c13b11..00000000000
--- a/usr.sbin/hoststated/check_http.c
+++ /dev/null
@@ -1,114 +0,0 @@
-/* $OpenBSD: check_http.c,v 1.11 2007/01/29 14:23:31 pyr Exp $ */
-/*
- * Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/socket.h>
-#include <sys/param.h>
-
-#include <net/if.h>
-#include <sha1.h>
-#include <limits.h>
-#include <event.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <errno.h>
-
-#include <openssl/ssl.h>
-
-#include "hoststated.h"
-
-int
-check_http_code(struct ctl_tcp_event *cte)
-{
- char *head;
- char scode[4];
- const char *estr;
- u_char *b;
- int code;
-
- /*
- * ensure string is nul-terminated.
- */
- b = buf_reserve(cte->buf, 1);
- if (b == NULL)
- fatal("out of memory");
- *b = '\0';
-
- head = cte->buf->buf;
- if (strncmp(head, "HTTP/1.1 ", strlen("HTTP/1.1 ")) &&
- strncmp(head, "HTTP/1.0 ", strlen("HTTP/1.0 "))) {
- log_debug("check_http_code: cannot parse HTTP version");
- cte->host->up = HOST_DOWN;
- return (1);
- }
- head += strlen("HTTP/1.1 ");
- if (strlen(head) < 5) /* code + \r\n */ {
- cte->host->up = HOST_DOWN;
- return (1);
- }
- strlcpy(scode, head, sizeof(scode));
- code = strtonum(scode, 100, 999, &estr);
- if (estr != NULL) {
- log_debug("check_http_code: cannot parse HTTP code");
- cte->host->up = HOST_DOWN;
- return (1);
- }
- if (code != cte->table->retcode) {
- log_debug("check_http_code: invalid HTTP code returned");
- cte->host->up = HOST_DOWN;
- } else
- cte->host->up = HOST_UP;
- return (!(cte->host->up == HOST_UP));
-}
-
-int
-check_http_digest(struct ctl_tcp_event *cte)
-{
- char *head;
- u_char *b;
- char digest[(SHA1_DIGEST_LENGTH*2)+1];
-
- /*
- * ensure string is nul-terminated.
- */
- b = buf_reserve(cte->buf, 1);
- if (b == NULL)
- fatal("out of memory");
- *b = '\0';
-
- head = cte->buf->buf;
- if ((head = strstr(head, "\r\n\r\n")) == NULL) {
- log_debug("check_http_digest: host %u no end of headers",
- cte->host->id);
- cte->host->up = HOST_DOWN;
- return (1);
- }
- head += strlen("\r\n\r\n");
- SHA1Data(head, strlen(head), digest);
-
- if (strcmp(cte->table->digest, digest)) {
- log_warnx("check_http_digest: wrong digest for host %u",
- cte->host->id);
- cte->host->up = HOST_DOWN;
- } else
- cte->host->up = HOST_UP;
- return (!(cte->host->up == HOST_UP));
-}
diff --git a/usr.sbin/hoststated/check_send_expect.c b/usr.sbin/hoststated/check_send_expect.c
deleted file mode 100644
index 7c727f3de69..00000000000
--- a/usr.sbin/hoststated/check_send_expect.c
+++ /dev/null
@@ -1,61 +0,0 @@
-/* $OpenBSD: check_send_expect.c,v 1.6 2007/01/29 14:23:31 pyr Exp $ */
-/*
- * Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/socket.h>
-#include <sys/param.h>
-
-#include <net/if.h>
-#include <limits.h>
-#include <event.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <fnmatch.h>
-#include <errno.h>
-
-#include <openssl/ssl.h>
-
-#include "hoststated.h"
-
-int
-check_send_expect(struct ctl_tcp_event *cte)
-{
- u_char *b;
-
- /*
- * ensure string is nul-terminated.
- */
- b = buf_reserve(cte->buf, 1);
- if (b == NULL)
- fatal("out of memory");
- *b = '\0';
- if (fnmatch(cte->table->exbuf, cte->buf->buf, 0) == 0) {
- cte->host->up = HOST_UP;
- return (0);
- }
- cte->host->up = HOST_UNKNOWN;
-
- /*
- * go back to original position.
- */
- cte->buf->wpos--;
- return (1);
-}
diff --git a/usr.sbin/hoststated/check_tcp.c b/usr.sbin/hoststated/check_tcp.c
index 7567a16184c..ede50ce5729 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.14 2007/02/03 17:45:59 reyk Exp $ */
+/* $OpenBSD: check_tcp.c,v 1.15 2007/02/03 20:24:21 reyk Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -20,8 +20,10 @@
#include <sys/queue.h>
#include <sys/socket.h>
#include <sys/param.h>
+
#include <netinet/in.h>
#include <net/if.h>
+
#include <limits.h>
#include <event.h>
#include <fcntl.h>
@@ -29,6 +31,8 @@
#include <string.h>
#include <stdlib.h>
#include <errno.h>
+#include <fnmatch.h>
+#include <sha1.h>
#include <openssl/ssl.h>
@@ -259,3 +263,106 @@ retry:
event_again(&cte->ev, s, EV_TIMEOUT|EV_READ, tcp_read_buf,
&cte->tv_start, &cte->table->timeout, cte);
}
+
+int
+check_send_expect(struct ctl_tcp_event *cte)
+{
+ u_char *b;
+
+ /*
+ * ensure string is nul-terminated.
+ */
+ b = buf_reserve(cte->buf, 1);
+ if (b == NULL)
+ fatal("out of memory");
+ *b = '\0';
+ if (fnmatch(cte->table->exbuf, cte->buf->buf, 0) == 0) {
+ cte->host->up = HOST_UP;
+ return (0);
+ }
+ cte->host->up = HOST_UNKNOWN;
+
+ /*
+ * go back to original position.
+ */
+ cte->buf->wpos--;
+ return (1);
+}
+
+int
+check_http_code(struct ctl_tcp_event *cte)
+{
+ char *head;
+ char scode[4];
+ const char *estr;
+ u_char *b;
+ int code;
+
+ /*
+ * ensure string is nul-terminated.
+ */
+ b = buf_reserve(cte->buf, 1);
+ if (b == NULL)
+ fatal("out of memory");
+ *b = '\0';
+
+ head = cte->buf->buf;
+ if (strncmp(head, "HTTP/1.1 ", strlen("HTTP/1.1 ")) &&
+ strncmp(head, "HTTP/1.0 ", strlen("HTTP/1.0 "))) {
+ log_debug("check_http_code: cannot parse HTTP version");
+ cte->host->up = HOST_DOWN;
+ return (1);
+ }
+ head += strlen("HTTP/1.1 ");
+ if (strlen(head) < 5) /* code + \r\n */ {
+ cte->host->up = HOST_DOWN;
+ return (1);
+ }
+ strlcpy(scode, head, sizeof(scode));
+ code = strtonum(scode, 100, 999, &estr);
+ if (estr != NULL) {
+ log_debug("check_http_code: cannot parse HTTP code");
+ cte->host->up = HOST_DOWN;
+ return (1);
+ }
+ if (code != cte->table->retcode) {
+ log_debug("check_http_code: invalid HTTP code returned");
+ cte->host->up = HOST_DOWN;
+ } else
+ cte->host->up = HOST_UP;
+ return (!(cte->host->up == HOST_UP));
+}
+
+int
+check_http_digest(struct ctl_tcp_event *cte)
+{
+ char *head;
+ u_char *b;
+ char digest[(SHA1_DIGEST_LENGTH*2)+1];
+
+ /*
+ * ensure string is nul-terminated.
+ */
+ b = buf_reserve(cte->buf, 1);
+ if (b == NULL)
+ fatal("out of memory");
+ *b = '\0';
+
+ head = cte->buf->buf;
+ if ((head = strstr(head, "\r\n\r\n")) == NULL) {
+ log_debug("check_http_digest: host %u no end of headers",
+ cte->host->id);
+ cte->host->up = HOST_DOWN;
+ return (1);
+ }
+ head += strlen("\r\n\r\n");
+ SHA1Data(head, strlen(head), digest);
+
+ if (strcmp(cte->table->digest, digest)) {
+ log_warnx("check_http_digest: wrong digest for host %u",
+ cte->host->id);
+ cte->host->up = HOST_DOWN;
+ } else
+ cte->host->up = HOST_UP;
+ return (!(cte->host->up == HOST_UP));
+}
diff --git a/usr.sbin/relayd/Makefile b/usr.sbin/relayd/Makefile
index 20eb9be0b1c..8475f8c2f7f 100644
--- a/usr.sbin/relayd/Makefile
+++ b/usr.sbin/relayd/Makefile
@@ -1,9 +1,9 @@
-# $OpenBSD: Makefile,v 1.6 2007/01/30 15:11:51 reyk Exp $
+# $OpenBSD: Makefile,v 1.7 2007/02/03 20:24:21 reyk Exp $
PROG= hoststated
SRCS= parse.y log.c control.c buffer.c imsg.c hoststated.c \
ssl.c pfe.c pfe_filter.c hce.c \
- check_icmp.c check_tcp.c check_http.c check_send_expect.c
+ check_icmp.c check_tcp.c
MAN= hoststated.8 hoststated.conf.5
LDADD= -levent -lssl -lcrypto
diff --git a/usr.sbin/relayd/check_tcp.c b/usr.sbin/relayd/check_tcp.c
index 7567a16184c..ede50ce5729 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.14 2007/02/03 17:45:59 reyk Exp $ */
+/* $OpenBSD: check_tcp.c,v 1.15 2007/02/03 20:24:21 reyk Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org>
@@ -20,8 +20,10 @@
#include <sys/queue.h>
#include <sys/socket.h>
#include <sys/param.h>
+
#include <netinet/in.h>
#include <net/if.h>
+
#include <limits.h>
#include <event.h>
#include <fcntl.h>
@@ -29,6 +31,8 @@
#include <string.h>
#include <stdlib.h>
#include <errno.h>
+#include <fnmatch.h>
+#include <sha1.h>
#include <openssl/ssl.h>
@@ -259,3 +263,106 @@ retry:
event_again(&cte->ev, s, EV_TIMEOUT|EV_READ, tcp_read_buf,
&cte->tv_start, &cte->table->timeout, cte);
}
+
+int
+check_send_expect(struct ctl_tcp_event *cte)
+{
+ u_char *b;
+
+ /*
+ * ensure string is nul-terminated.
+ */
+ b = buf_reserve(cte->buf, 1);
+ if (b == NULL)
+ fatal("out of memory");
+ *b = '\0';
+ if (fnmatch(cte->table->exbuf, cte->buf->buf, 0) == 0) {
+ cte->host->up = HOST_UP;
+ return (0);
+ }
+ cte->host->up = HOST_UNKNOWN;
+
+ /*
+ * go back to original position.
+ */
+ cte->buf->wpos--;
+ return (1);
+}
+
+int
+check_http_code(struct ctl_tcp_event *cte)
+{
+ char *head;
+ char scode[4];
+ const char *estr;
+ u_char *b;
+ int code;
+
+ /*
+ * ensure string is nul-terminated.
+ */
+ b = buf_reserve(cte->buf, 1);
+ if (b == NULL)
+ fatal("out of memory");
+ *b = '\0';
+
+ head = cte->buf->buf;
+ if (strncmp(head, "HTTP/1.1 ", strlen("HTTP/1.1 ")) &&
+ strncmp(head, "HTTP/1.0 ", strlen("HTTP/1.0 "))) {
+ log_debug("check_http_code: cannot parse HTTP version");
+ cte->host->up = HOST_DOWN;
+ return (1);
+ }
+ head += strlen("HTTP/1.1 ");
+ if (strlen(head) < 5) /* code + \r\n */ {
+ cte->host->up = HOST_DOWN;
+ return (1);
+ }
+ strlcpy(scode, head, sizeof(scode));
+ code = strtonum(scode, 100, 999, &estr);
+ if (estr != NULL) {
+ log_debug("check_http_code: cannot parse HTTP code");
+ cte->host->up = HOST_DOWN;
+ return (1);
+ }
+ if (code != cte->table->retcode) {
+ log_debug("check_http_code: invalid HTTP code returned");
+ cte->host->up = HOST_DOWN;
+ } else
+ cte->host->up = HOST_UP;
+ return (!(cte->host->up == HOST_UP));
+}
+
+int
+check_http_digest(struct ctl_tcp_event *cte)
+{
+ char *head;
+ u_char *b;
+ char digest[(SHA1_DIGEST_LENGTH*2)+1];
+
+ /*
+ * ensure string is nul-terminated.
+ */
+ b = buf_reserve(cte->buf, 1);
+ if (b == NULL)
+ fatal("out of memory");
+ *b = '\0';
+
+ head = cte->buf->buf;
+ if ((head = strstr(head, "\r\n\r\n")) == NULL) {
+ log_debug("check_http_digest: host %u no end of headers",
+ cte->host->id);
+ cte->host->up = HOST_DOWN;
+ return (1);
+ }
+ head += strlen("\r\n\r\n");
+ SHA1Data(head, strlen(head), digest);
+
+ if (strcmp(cte->table->digest, digest)) {
+ log_warnx("check_http_digest: wrong digest for host %u",
+ cte->host->id);
+ cte->host->up = HOST_DOWN;
+ } else
+ cte->host->up = HOST_UP;
+ return (!(cte->host->up == HOST_UP));
+}