sync
This commit is contained in:
parent
a2dd1eda92
commit
8e644b001d
41 changed files with 541 additions and 216 deletions
|
@ -1,4 +1,4 @@
|
|||
/* $OpenBSD: check_tcp.c,v 1.59 2023/06/20 09:54:57 claudio Exp $ */
|
||||
/* $OpenBSD: check_tcp.c,v 1.60 2023/06/21 07:54:54 claudio Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2006 Pierre-Yves Ritschard <pyr@openbsd.org>
|
||||
|
@ -183,10 +183,6 @@ tcp_host_up(struct ctl_tcp_event *cte)
|
|||
return;
|
||||
}
|
||||
|
||||
if (cte->table->sendbuf != NULL && cte->table->sendbinbuf == NULL) {
|
||||
cte->req = cte->table->sendbuf;
|
||||
} else if (cte->table->sendbinbuf != NULL)
|
||||
cte->req = cte->table->sendbinbuf->buf;
|
||||
if (cte->table->sendbuf != NULL || cte->table->sendbinbuf != NULL) {
|
||||
event_again(&cte->ev, cte->s, EV_TIMEOUT|EV_WRITE, tcp_send_req,
|
||||
&cte->tv_start, &cte->table->conf.timeout, cte);
|
||||
|
@ -203,6 +199,7 @@ void
|
|||
tcp_send_req(int s, short event, void *arg)
|
||||
{
|
||||
struct ctl_tcp_event *cte = arg;
|
||||
char *req;
|
||||
int bs;
|
||||
int len;
|
||||
|
||||
|
@ -214,14 +211,17 @@ tcp_send_req(int s, short event, void *arg)
|
|||
|
||||
if (cte->table->sendbinbuf != NULL) {
|
||||
len = ibuf_size(cte->table->sendbinbuf);
|
||||
req = ibuf_data(cte->table->sendbinbuf);
|
||||
log_debug("%s: table %s sending binary", __func__,
|
||||
cte->table->conf.name);
|
||||
print_hex(cte->table->sendbinbuf->buf, 0, len);
|
||||
} else
|
||||
len = strlen(cte->req);
|
||||
} else {
|
||||
len = strlen(cte->table->sendbuf);
|
||||
req = cte->table->sendbuf;
|
||||
}
|
||||
|
||||
do {
|
||||
bs = write(s, cte->req, len);
|
||||
bs = write(s, req, len);
|
||||
if (bs == -1) {
|
||||
if (errno == EAGAIN || errno == EINTR)
|
||||
goto retry;
|
||||
|
@ -230,7 +230,7 @@ tcp_send_req(int s, short event, void *arg)
|
|||
hce_notify_done(cte->host, HCE_TCP_WRITE_FAIL);
|
||||
return;
|
||||
}
|
||||
cte->req += bs;
|
||||
req += bs;
|
||||
len -= bs;
|
||||
} while (len > 0);
|
||||
|
||||
|
@ -302,20 +302,22 @@ check_send_expect(struct ctl_tcp_event *cte)
|
|||
u_char *b;
|
||||
|
||||
if (cte->table->conf.check == CHECK_BINSEND_EXPECT) {
|
||||
size_t exlen;
|
||||
|
||||
exlen = strlen(cte->table->conf.exbuf) / 2;
|
||||
log_debug("%s: table %s expecting binary",
|
||||
__func__, cte->table->conf.name);
|
||||
print_hex(cte->table->conf.exbinbuf, 0,
|
||||
strlen(cte->table->conf.exbuf) / 2);
|
||||
print_hex(cte->table->conf.exbinbuf, 0, exlen);
|
||||
|
||||
if (memcmp(cte->table->conf.exbinbuf, cte->buf->buf,
|
||||
strlen(cte->table->conf.exbuf) / 2) == 0) {
|
||||
if (ibuf_size(cte->buf) >= exlen && memcmp(ibuf_data(cte->buf),
|
||||
cte->table->conf.exbinbuf, exlen) == 0) {
|
||||
cte->host->he = HCE_SEND_EXPECT_OK;
|
||||
cte->host->up = HOST_UP;
|
||||
return (0);
|
||||
} else {
|
||||
} else if (ibuf_size(cte->buf) >= exlen) {
|
||||
log_debug("%s: table %s received mismatching binary",
|
||||
__func__, cte->table->conf.name);
|
||||
print_hex(cte->buf->buf, 0, ibuf_size(cte->buf));
|
||||
print_hex(ibuf_data(cte->buf), 0, ibuf_size(cte->buf));
|
||||
}
|
||||
} else if (cte->table->conf.check == CHECK_SEND_EXPECT) {
|
||||
/*
|
||||
|
@ -353,7 +355,7 @@ check_http_code(struct ctl_tcp_event *cte)
|
|||
if (ibuf_add_zero(cte->buf, 1) == -1)
|
||||
fatal("out of memory");
|
||||
|
||||
head = cte->buf->buf;
|
||||
head = ibuf_data(cte->buf);
|
||||
host = cte->host;
|
||||
host->he = HCE_HTTP_CODE_ERROR;
|
||||
host->code = 0;
|
||||
|
@ -404,7 +406,7 @@ check_http_digest(struct ctl_tcp_event *cte)
|
|||
if (ibuf_add_zero(cte->buf, 1) == -1)
|
||||
fatal("out of memory");
|
||||
|
||||
head = cte->buf->buf;
|
||||
head = ibuf_data(cte->buf);
|
||||
host = cte->host;
|
||||
host->he = HCE_HTTP_DIGEST_ERROR;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $OpenBSD: relayd.h,v 1.269 2022/08/31 16:17:18 dv Exp $ */
|
||||
/* $OpenBSD: relayd.h,v 1.270 2023/06/21 07:54:54 claudio Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2006 - 2016 Reyk Floeter <reyk@openbsd.org>
|
||||
|
@ -176,7 +176,6 @@ struct ctl_icmp_event {
|
|||
|
||||
struct ctl_tcp_event {
|
||||
int s;
|
||||
char *req;
|
||||
struct ibuf *buf;
|
||||
struct host *host;
|
||||
struct table *table;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $OpenBSD: util.c,v 1.3 2019/09/15 19:23:29 rob Exp $ */
|
||||
/* $OpenBSD: util.c,v 1.4 2023/06/21 07:49:24 claudio Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2006 - 2015 Reyk Floeter <reyk@openbsd.org>
|
||||
|
@ -289,44 +289,42 @@ getmonotime(struct timeval *tv)
|
|||
struct ibuf *
|
||||
string2binary(const char *string)
|
||||
{
|
||||
unsigned long i, j, x;
|
||||
unsigned char *binary = NULL;
|
||||
struct ibuf *ibuf = NULL;
|
||||
char hex[3];
|
||||
int len;
|
||||
unsigned char ch, r;
|
||||
size_t i, len;
|
||||
|
||||
if (strlen(string) % 2 != 0) {
|
||||
return NULL;
|
||||
}
|
||||
len = strlen(string);
|
||||
if (len % 2 != 0)
|
||||
goto fail;
|
||||
if ((ibuf = ibuf_open(len / 2)) == NULL)
|
||||
goto fail;
|
||||
|
||||
binary = calloc(strlen(string), sizeof(unsigned char));
|
||||
if (binary == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
hex[2] = '\0';
|
||||
j = 0;
|
||||
for (i = 0; i < strlen(string); i++) {
|
||||
if (isxdigit(string[i]) == 0 || isxdigit(string[i+1]) == 0) {
|
||||
free(binary);
|
||||
return NULL;
|
||||
} else {
|
||||
hex[0] = string[i];
|
||||
hex[1] = string[i+1];
|
||||
x = strtoul(hex, NULL, 16);
|
||||
binary[j++] = (unsigned char)x;
|
||||
i++;
|
||||
while (*string) {
|
||||
r = 0;
|
||||
for (i = 0; i < 2; i++) {
|
||||
ch = string[i];
|
||||
if (isdigit(ch))
|
||||
ch -= '0';
|
||||
else if (islower(ch))
|
||||
ch -= ('a' - 10);
|
||||
else if (isupper(ch))
|
||||
ch -= ('A' - 10);
|
||||
else
|
||||
goto fail;
|
||||
if (ch > 0xf)
|
||||
goto fail;
|
||||
r = r << 4 | ch;
|
||||
}
|
||||
if (ibuf_add_n8(ibuf, r) == -1)
|
||||
goto fail;
|
||||
string += 2;
|
||||
}
|
||||
len = strlen(string) / 2;
|
||||
if ((ibuf = ibuf_open(len)) == NULL ||
|
||||
ibuf_add(ibuf, binary, len) == -1) {
|
||||
ibuf_free(ibuf);
|
||||
free(binary);
|
||||
return NULL;
|
||||
}
|
||||
free(binary);
|
||||
|
||||
return ibuf;
|
||||
|
||||
fail:
|
||||
ibuf_free(ibuf);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue