diff options
author | Sebastian Benoit <benno@cvs.openbsd.org> | 2014-07-13 00:32:09 +0000 |
---|---|---|
committer | Sebastian Benoit <benno@cvs.openbsd.org> | 2014-07-13 00:32:09 +0000 |
commit | cf20f329ba70c6a7dd4b1d1ef99c34404d232225 (patch) | |
tree | c83c4f489376615b0282cac908d40d66ef68b9c5 /usr.sbin/relayd | |
parent | 6870eb997071b5bf7e1b16803173707ef767ea66 (diff) |
improve log output for relays. adjust regress tests
ok reyk
Diffstat (limited to 'usr.sbin/relayd')
-rw-r--r-- | usr.sbin/relayd/relay.c | 11 | ||||
-rw-r--r-- | usr.sbin/relayd/relay_http.c | 17 | ||||
-rw-r--r-- | usr.sbin/relayd/relay_udp.c | 3 | ||||
-rw-r--r-- | usr.sbin/relayd/relayd.c | 17 | ||||
-rw-r--r-- | usr.sbin/relayd/relayd.h | 7 |
5 files changed, 42 insertions, 13 deletions
diff --git a/usr.sbin/relayd/relay.c b/usr.sbin/relayd/relay.c index 18879aef485..f4d093fdb82 100644 --- a/usr.sbin/relayd/relay.c +++ b/usr.sbin/relayd/relay.c @@ -1,4 +1,4 @@ -/* $OpenBSD: relay.c,v 1.173 2014/07/11 16:59:38 reyk Exp $ */ +/* $OpenBSD: relay.c,v 1.174 2014/07/13 00:32:08 benno Exp $ */ /* * Copyright (c) 2006 - 2014 Reyk Floeter <reyk@openbsd.org> @@ -1084,6 +1084,7 @@ relay_accept(int fd, short event, void *arg) } /* Pre-allocate log buffer */ + con->se_haslog = 0; con->se_log = evbuffer_new(); if (con->se_log == NULL) { relay_close(con, "failed to allocate log buffer"); @@ -2655,4 +2656,12 @@ relay_session_cmp(struct rsession *a, struct rsession *b) return ((int)a->se_id - b->se_id); } +void +relay_log(struct rsession *con, char *msg) +{ + if (con->se_haslog && con->se_log != NULL) { + evbuffer_add(con->se_log, msg, strlen(msg)); + } +} + SPLAY_GENERATE(session_tree, rsession, se_nodes, relay_session_cmp); diff --git a/usr.sbin/relayd/relay_http.c b/usr.sbin/relayd/relay_http.c index ede8aa4751b..4f2eb6c403f 100644 --- a/usr.sbin/relayd/relay_http.c +++ b/usr.sbin/relayd/relay_http.c @@ -1,4 +1,4 @@ -/* $OpenBSD: relay_http.c,v 1.28 2014/07/13 00:18:05 benno Exp $ */ +/* $OpenBSD: relay_http.c,v 1.29 2014/07/13 00:32:08 benno Exp $ */ /* * Copyright (c) 2006 - 2014 Reyk Floeter <reyk@openbsd.org> @@ -1389,6 +1389,8 @@ relay_apply_actions(struct ctl_relay_event *cre, struct kvlist *actions) struct kv *kv, *match, *kp, *mp, kvcopy, matchcopy, key; int addkv, ret; char buf[IBUF_READ_SIZE], *ptr; + char *msg = NULL; + const char *meth = NULL; memset(&kvcopy, 0, sizeof(kvcopy)); memset(&matchcopy, 0, sizeof(matchcopy)); @@ -1553,7 +1555,8 @@ relay_apply_actions(struct ctl_relay_event *cre, struct kvlist *actions) default: break; } - if (kv_log(con->se_log, mp, con->se_label) == -1) + if (kv_log(con, mp, con->se_label, cre->dir) + == -1) goto fail; break; default: @@ -1569,6 +1572,16 @@ relay_apply_actions(struct ctl_relay_event *cre, struct kvlist *actions) kv_free(&matchcopy); } + /* + * log tag for request and response, request method + * and end of request marker "," + */ + if ((con->se_log != NULL) && + ((meth = relay_httpmethod_byid(desc->http_method)) != NULL) && + (asprintf(&msg, " %s",meth) >= 0)) + evbuffer_add(con->se_log, msg, strlen(msg)); + free(msg); + relay_log(con, cre->dir == RELAY_DIR_REQUEST ? "" : ";"); ret = 0; fail: kv_free(&kvcopy); diff --git a/usr.sbin/relayd/relay_udp.c b/usr.sbin/relayd/relay_udp.c index 9d871c5af87..5ed418c5711 100644 --- a/usr.sbin/relayd/relay_udp.c +++ b/usr.sbin/relayd/relay_udp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: relay_udp.c,v 1.30 2014/07/09 16:42:05 reyk Exp $ */ +/* $OpenBSD: relay_udp.c,v 1.31 2014/07/13 00:32:08 benno Exp $ */ /* * Copyright (c) 2007 - 2013 Reyk Floeter <reyk@openbsd.org> @@ -280,6 +280,7 @@ relay_udp_server(int fd, short sig, void *arg) } /* Pre-allocate log buffer */ + con->se_haslog = 0; con->se_log = evbuffer_new(); if (con->se_log == NULL) { relay_close(con, "failed to allocate log buffer"); diff --git a/usr.sbin/relayd/relayd.c b/usr.sbin/relayd/relayd.c index cf434bd589f..2b0377d36a8 100644 --- a/usr.sbin/relayd/relayd.c +++ b/usr.sbin/relayd/relayd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: relayd.c,v 1.129 2014/07/11 11:48:50 reyk Exp $ */ +/* $OpenBSD: relayd.c,v 1.130 2014/07/13 00:32:08 benno Exp $ */ /* * Copyright (c) 2007 - 2014 Reyk Floeter <reyk@openbsd.org> @@ -804,25 +804,28 @@ kv_inherit(struct kv *dst, struct kv *src) } int -kv_log(struct evbuffer *log, struct kv *kv, u_int16_t labelid) +kv_log(struct rsession *con, struct kv *kv, u_int16_t labelid, + enum direction dir) { char *msg; - if (log == NULL) + if (con->se_log == NULL) return (0); - if (asprintf(&msg, " [%s%s%s%s%s]", + if (asprintf(&msg, " %s%s%s%s%s%s%s", + dir == RELAY_DIR_REQUEST ? "[" : "{", labelid == 0 ? "" : label_id2name(labelid), labelid == 0 ? "" : ", ", kv->kv_key == NULL ? "(unknown)" : kv->kv_key, kv->kv_value == NULL ? "" : ": ", - kv->kv_value == NULL ? "" : kv->kv_value) == -1) + kv->kv_value == NULL ? "" : kv->kv_value, + dir == RELAY_DIR_REQUEST ? "]" : "}") == -1) return (-1); - if (evbuffer_add(log, msg, strlen(msg)) == -1) { + if (evbuffer_add(con->se_log, msg, strlen(msg)) == -1) { free(msg); return (-1); } free(msg); - + con->se_haslog = 1; return (0); } diff --git a/usr.sbin/relayd/relayd.h b/usr.sbin/relayd/relayd.h index b103eda8d27..6c86e29cc29 100644 --- a/usr.sbin/relayd/relayd.h +++ b/usr.sbin/relayd/relayd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: relayd.h,v 1.187 2014/07/12 14:34:13 reyk Exp $ */ +/* $OpenBSD: relayd.h,v 1.188 2014/07/13 00:32:08 benno Exp $ */ /* * Copyright (c) 2006 - 2014 Reyk Floeter <reyk@openbsd.org> @@ -525,6 +525,7 @@ struct rsession { int se_retry; int se_retrycount; int se_connectcount; + int se_haslog; struct evbuffer *se_log; struct relay *se_relay; struct ctl_natlook *se_cnl; @@ -1253,7 +1254,9 @@ struct kv *kv_extend(struct kvtree *, struct kv *, char *); void kv_purge(struct kvtree *); void kv_free(struct kv *); struct kv *kv_inherit(struct kv *, struct kv *); -int kv_log(struct evbuffer *, struct kv *, u_int16_t); +void relay_log(struct rsession *, char *); +int kv_log(struct rsession *, struct kv *, u_int16_t, + enum direction); struct kv *kv_find(struct kvtree *, struct kv *); int kv_cmp(struct kv *, struct kv *); int rule_add(struct protocol *, struct relay_rule *, const char |