Add TID_REQ_COUNT handler
authorJennifer Richards <jennifer@painless-security.com>
Wed, 18 Apr 2018 15:41:06 +0000 (11:41 -0400)
committerJennifer Richards <jennifer@painless-security.com>
Wed, 18 Apr 2018 15:41:06 +0000 (11:41 -0400)
  * 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
Makefile.am
include/tr_tid.h
tid/example/tids_main.c
tid/tids.c
tr/tr_main.c
tr/tr_tid.c
tr/tr_tid_mons.c [new file with mode: 0644]

index 17843d1..0d660b5 100644 (file)
@@ -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})
index c73c623..a65f9c9 100644 (file)
@@ -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 \
index 924293d..2e839e2 100644 (file)
@@ -38,6 +38,7 @@
 #include <trp_internal.h>
 #include <tr_event.h>
 #include <tr_config.h>
+#include <mon.h>
 
 #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 */
index 8673cdd..1ecc494 100644 (file)
@@ -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;
index 2e5dbea..7975ddc 100644 (file)
@@ -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,
index bb04beb..91d225b 100644 (file)
@@ -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) {
index 89fe994..1bec328 100644 (file)
@@ -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 (file)
index 0000000..38fbbdd
--- /dev/null
@@ -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 <jansson.h>
+#include <tid_internal.h>
+#include <tr_tid.h>
+#include <mon_internal.h>
+#include <mons_handlers.h>
+
+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);
+}