summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryasuoka <yasuoka@openbsd.org>2015-08-21 08:45:51 +0000
committeryasuoka <yasuoka@openbsd.org>2015-08-21 08:45:51 +0000
commit403ae8a83e0f8f6aba649aedf7f3acba869b37df (patch)
treeb2cf43f593572b36da6af1cd8ff16777c4c5d1f7
parentUse reallocarray() instead of malloc() before strvisx(). (diff)
downloadwireguard-openbsd-403ae8a83e0f8f6aba649aedf7f3acba869b37df.tar.xz
wireguard-openbsd-403ae8a83e0f8f6aba649aedf7f3acba869b37df.zip
Increase the input side socket buffer size for "check icmp" not to
drop the reply messages when "check icmp" is used with many hosts. ok reyk benno
-rw-r--r--usr.sbin/relayd/check_icmp.c7
-rw-r--r--usr.sbin/relayd/check_tcp.c23
-rw-r--r--usr.sbin/relayd/relayd.h3
3 files changed, 28 insertions, 5 deletions
diff --git a/usr.sbin/relayd/check_icmp.c b/usr.sbin/relayd/check_icmp.c
index d6f5ffb7ba0..cf2b10f6b57 100644
--- a/usr.sbin/relayd/check_icmp.c
+++ b/usr.sbin/relayd/check_icmp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: check_icmp.c,v 1.40 2015/01/22 17:42:09 reyk Exp $ */
+/* $OpenBSD: check_icmp.c,v 1.41 2015/08/21 08:45:51 yasuoka Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -48,12 +48,15 @@ int in_cksum(u_short *, int);
void
icmp_setup(struct relayd *env, struct ctl_icmp_event *cie, int af)
{
- int proto = IPPROTO_ICMP;
+ int proto = IPPROTO_ICMP, val;
if (af == AF_INET6)
proto = IPPROTO_ICMPV6;
if ((cie->s = socket(af, SOCK_RAW, proto)) < 0)
fatal("icmp_setup: socket");
+ val = ICMP_RCVBUF_SIZE;
+ if (setsockopt(cie->s, SOL_SOCKET, SO_RCVBUF, &val, sizeof(val)) == -1)
+ fatal("icmp_setup: setsockopt");
socket_set_blockmode(cie->s, BM_NONBLOCK);
cie->env = env;
cie->af = af;
diff --git a/usr.sbin/relayd/check_tcp.c b/usr.sbin/relayd/check_tcp.c
index 246d0ec8062..e7f2c464a1f 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.46 2015/01/22 17:42:09 reyk Exp $ */
+/* $OpenBSD: check_tcp.c,v 1.47 2015/08/21 08:45:51 yasuoka Exp $ */
/*
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -41,6 +41,7 @@ void tcp_close(struct ctl_tcp_event *, int);
void tcp_send_req(int, short, void *);
void tcp_read_buf(int, short, void *);
+int check_http_resphead(struct ctl_tcp_event *);
int check_http_code(struct ctl_tcp_event *);
int check_http_digest(struct ctl_tcp_event *);
int check_send_expect(struct ctl_tcp_event *);
@@ -160,7 +161,7 @@ tcp_host_up(struct ctl_tcp_event *cte)
hce_notify_done(cte->host, HCE_TCP_CONNECT_OK);
return;
case CHECK_HTTP_CODE:
- cte->validate_read = NULL;
+ cte->validate_read = check_http_resphead;
cte->validate_close = check_http_code;
break;
case CHECK_HTTP_DIGEST:
@@ -302,6 +303,24 @@ check_send_expect(struct ctl_tcp_event *cte)
}
int
+check_http_resphead(struct ctl_tcp_event *cte)
+{
+ int i, siz;
+
+ /* checks whether the buffer contains the response header */
+ siz = ibuf_size(cte->buf);
+ for (i = 0; i <= siz - 4; i++) {
+ if (cte->buf->buf[i] == '\r' &&
+ cte->buf->buf[i + 1] == '\n' &&
+ cte->buf->buf[i + 2] == '\r' &&
+ cte->buf->buf[i + 3] == '\n')
+ return (0);
+ }
+
+ return (1);
+}
+
+int
check_http_code(struct ctl_tcp_event *cte)
{
char *head;
diff --git a/usr.sbin/relayd/relayd.h b/usr.sbin/relayd/relayd.h
index 37a40822a02..3c7dc89add2 100644
--- a/usr.sbin/relayd/relayd.h
+++ b/usr.sbin/relayd/relayd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: relayd.h,v 1.213 2015/07/18 16:01:28 benno Exp $ */
+/* $OpenBSD: relayd.h,v 1.214 2015/08/21 08:45:51 yasuoka Exp $ */
/*
* Copyright (c) 2006 - 2015 Reyk Floeter <reyk@openbsd.org>
@@ -89,6 +89,7 @@
#define SMALL_READ_BUF_SIZE 1024
#define ICMP_BUF_SIZE 64
+#define ICMP_RCVBUF_SIZE 262144
#define SNMP_RECONNECT_TIMEOUT { 3, 0 } /* sec, usec */