From 283699f7ec7db8a8ebe322ccb2568910b5c8701c Mon Sep 17 00:00:00 2001 From: Jennifer Richards Date: Wed, 18 Apr 2018 11:41:06 -0400 Subject: [PATCH] Add TID_REQ_COUNT handler * Add a separate source file for TID-related monitoring handlers * Increment tids->req_count in the main process, otherwise it will always seem to be zero. This does mean any connection to the TID port is counted as a tid request, which is not perfect. * --- CMakeLists.txt | 2 +- Makefile.am | 1 + include/tr_tid.h | 4 ++++ tid/example/tids_main.c | 3 --- tid/tids.c | 2 ++ tr/tr_main.c | 3 ++- tr/tr_tid.c | 1 - tr/tr_tid_mons.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 63 insertions(+), 6 deletions(-) create mode 100644 tr/tr_tid_mons.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 17843d1..0d660b5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -96,7 +96,7 @@ set(SOURCE_FILES trp/trp_upd.c trp/trpc.c trp/trps.c include/tr_name_internal.h mon/mon_req.c mon/mon_req_encode.c mon/mon_req_decode.c - mon/mon_resp.c mon/mon_common.c mon/mon_resp_encode.c mon/mon_resp_decode.c tr/tr_mon.c mon/mons.c include/tr_socket.h common/tr_gss.c include/tr_gss.h common/tr_config_internal.c mon/mons_handlers.c include/mons_handlers.h) + mon/mon_resp.c mon/mon_common.c mon/mon_resp_encode.c mon/mon_resp_decode.c tr/tr_mon.c mon/mons.c include/tr_socket.h common/tr_gss.c include/tr_gss.h common/tr_config_internal.c mon/mons_handlers.c include/mons_handlers.h tr/tr_tid_mons.c) # Does not actually build! add_executable(trust_router ${SOURCE_FILES}) diff --git a/Makefile.am b/Makefile.am index c73c623..a65f9c9 100644 --- a/Makefile.am +++ b/Makefile.am @@ -86,6 +86,7 @@ tr/tr.c \ tr/tr_event.c \ tr/tr_cfgwatch.c \ tr/tr_tid.c \ +tr/tr_tid_mons.c \ tr/tr_trp.c \ tr/tr_mon.c \ common/tr_gss.c \ diff --git a/include/tr_tid.h b/include/tr_tid.h index 924293d..2e839e2 100644 --- a/include/tr_tid.h +++ b/include/tr_tid.h @@ -38,6 +38,7 @@ #include #include #include +#include #define TR_TID_MAX_AAA_SERVERS 10 @@ -47,4 +48,7 @@ int tr_tids_event_init(struct event_base *base, TRPS_INSTANCE *trps, struct tr_socket_event *tids_ev); +/* tr_tid_mons.c */ +void tr_tid_register_mons_handlers(TIDS_INSTANCE *tids, MONS_INSTANCE *mons); + #endif /* TR_TID_H */ diff --git a/tid/example/tids_main.c b/tid/example/tids_main.c index 8673cdd..1ecc494 100644 --- a/tid/example/tids_main.c +++ b/tid/example/tids_main.c @@ -167,9 +167,6 @@ static int tids_req_handler (TIDS_INSTANCE *tids, tr_debug("tids_req_handler: Request received! target_realm = %s, community = %s", req->realm->buf, req->comm->buf); - if (tids) - tids->req_count++; - if (!(resp) || !resp) { tr_debug("tids_req_handler: No response structure."); return -1; diff --git a/tid/tids.c b/tid/tids.c index 2e5dbea..7975ddc 100644 --- a/tid/tids.c +++ b/tid/tids.c @@ -389,6 +389,8 @@ int tids_accept(TIDS_INSTANCE *tids, int listen) return 1; } + tids->req_count++; /* increment this in both processes after forking */ + if (pid == 0) { close(listen); tr_gss_handle_connection(conn, diff --git a/tr/tr_main.c b/tr/tr_main.c index bb04beb..91d225b 100644 --- a/tr/tr_main.c +++ b/tr/tr_main.c @@ -232,7 +232,8 @@ int main(int argc, char *argv[]) /* TODO do this more systematically */ mons_register_handler(tr->mons, MON_CMD_SHOW, OPT_TYPE_SHOW_VERSION, tr_mon_handle_version, NULL); mons_register_handler(tr->mons, MON_CMD_SHOW, OPT_TYPE_SHOW_UPTIME, tr_mon_handle_uptime, &start_time); - + tr_tid_register_mons_handlers(tr->tids, tr->mons); + /***** process configuration *****/ tr->cfgwatch=tr_cfgwatch_create(tr); if (tr->cfgwatch == NULL) { diff --git a/tr/tr_tid.c b/tr/tr_tid.c index 89fe994..1bec328 100644 --- a/tr/tr_tid.c +++ b/tr/tr_tid.c @@ -287,7 +287,6 @@ static int tr_tids_req_handler(TIDS_INSTANCE *tids, tr_debug("tr_tids_req_handler: Request received (conn = %d)! Realm = %s, Comm = %s", orig_req->conn, orig_req->realm->buf, orig_req->comm->buf); - tids->req_count++; /* Duplicate the request, so we can modify and forward it */ if (NULL == (fwd_req=tid_dup_req(orig_req))) { diff --git a/tr/tr_tid_mons.c b/tr/tr_tid_mons.c new file mode 100644 index 0000000..38fbbdd --- /dev/null +++ b/tr/tr_tid_mons.c @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2018, JANET(UK) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of JANET(UK) nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +/* Monitoring handlers for trust router TID server */ + +#include +#include +#include +#include +#include + +static MON_RC handle_show_req_count(void *cookie, json_t **response_ptr) +{ + TIDS_INSTANCE *tids = talloc_get_type_abort(cookie, TIDS_INSTANCE); + *response_ptr = json_integer(tids->req_count); + return (*response_ptr) ? MON_NOMEM : MON_SUCCESS; +} + +void tr_tid_register_mons_handlers(TIDS_INSTANCE *tids, MONS_INSTANCE *mons) +{ + mons_register_handler(mons, MON_CMD_SHOW, OPT_TYPE_SHOW_TID_REQ_COUNT, handle_show_req_count, tids); +} -- 2.1.4