From 2664b9de04d265fc028e07ffcf5f0d8b42523fb5 Mon Sep 17 00:00:00 2001 From: Jennifer Richards Date: Fri, 13 Apr 2018 11:01:32 -0400 Subject: [PATCH] Add stub of handler for monitoring requests Trust router now builds and opens monitoring port --- Makefile.am | 9 ++++++--- include/mon_internal.h | 3 +-- include/tr_mon.h | 47 +++++++++++++++++++++++++++++++++++++++++++++++ mon/mons.c | 15 +++++++++++++++ tr/tr_main.c | 29 +++++++++++++++++------------ tr/tr_mon.c | 6 +++++- 6 files changed, 91 insertions(+), 18 deletions(-) create mode 100644 include/tr_mon.h diff --git a/Makefile.am b/Makefile.am index e13e55a..4a4822d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -38,8 +38,9 @@ trp/trp_upd.c \ common/tr_config.c \ common/tr_mq.c -mon_srcs = \ - mon/mon_common.c \ +mon_srcs = \ + mon/mons.c \ + mon/mon_common.c \ mon/mon_req.c \ mon/mon_req_encode.c \ mon/mon_req_decode.c \ @@ -78,9 +79,11 @@ tr/tr_event.c \ tr/tr_cfgwatch.c \ tr/tr_tid.c \ tr/tr_trp.c \ +tr/tr_mon.c \ common/tr_gss.c \ $(tid_srcs) \ $(trp_srcs) \ +$(mon_srcs) \ $(common_srcs) tr_trust_router_LDFLAGS = $(AM_LDFLAGS) -levent_pthreads -pthread @@ -212,7 +215,7 @@ noinst_HEADERS = include/gsscon.h include/tr_config.h \ include/tr_msg.h include/tr.h \ include/tr_idp.h include/tr_rp.h \ include/tr_comm.h include/tr_apc.h \ - include/tr_tid.h include/tr_trp.h \ + include/tr_tid.h include/tr_trp.h include/tr_mon.h \ include/tr_filter.h include/tr_gss_names.h \ include/tid_internal.h include/trp_internal.h \ include/tr_cfgwatch.h include/tr_event.h \ diff --git a/include/mon_internal.h b/include/mon_internal.h index db9d1b4..d19e2a5 100644 --- a/include/mon_internal.h +++ b/include/mon_internal.h @@ -40,8 +40,7 @@ #include #include #include - -#include +#include #include #include #include diff --git a/include/tr_mon.h b/include/tr_mon.h new file mode 100644 index 0000000..e956db2 --- /dev/null +++ b/include/tr_mon.h @@ -0,0 +1,47 @@ +/* + * 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. + * + */ + +#ifndef TR_MON_H +#define TR_MON_H + +#include +#include +#include + +int tr_mons_event_init(struct event_base *base, + MONS_INSTANCE *mons, + TR_CFG_MGR *cfg_mgr, + struct tr_socket_event *mons_ev); + +#endif /* TR_MON_H */ diff --git a/mon/mons.c b/mon/mons.c index 31ecb15..f32c531 100644 --- a/mon/mons.c +++ b/mon/mons.c @@ -55,7 +55,10 @@ MONS_INSTANCE *mons_new(TALLOC_CTX *mem_ctx) MONS_INSTANCE *mons = talloc(mem_ctx, MONS_INSTANCE); if (mons) { + mons->hostname = NULL; mons->port = 0; + mons->tids = NULL; + mons->trps = NULL; mons->req_handler = NULL; mons->auth_handler = NULL; mons->cookie = NULL; @@ -69,6 +72,18 @@ MONS_INSTANCE *mons_new(TALLOC_CTX *mem_ctx) } /** + * Callback to process a request and produce a response + * + * @param req_str JSON-encoded request + * @param data pointer to a MONS_INSTANCE + * @return pointer to the response string or null to send no response + */ +static char *mons_req_cb(TALLOC_CTX *mem_ctx, const char *req_str, void *data) +{ + return "This is a response."; +} + +/** * Create a listener for monitoring requests * * Accept connections with mons_accept() diff --git a/tr/tr_main.c b/tr/tr_main.c index 86fb8a9..7fad36f 100644 --- a/tr/tr_main.c +++ b/tr/tr_main.c @@ -40,6 +40,8 @@ #include #include +#include +#include #include #include #include @@ -150,7 +152,7 @@ int main(int argc, char *argv[]) struct cmdline_args opts; struct event_base *ev_base; struct tr_socket_event tids_ev = {0}; -// struct tr_socket_event mon_ev = {0}; + struct tr_socket_event mon_ev = {0}; struct event *cfgwatch_ev; configure_signals(); @@ -201,11 +203,14 @@ int main(int argc, char *argv[]) return 1; } -// /***** initialize the monitoring interface instance *****/ -// if (NULL == (tr->mons = mons_new(tr))) { -// tr_crit("Error initializing monitoring interface instance."); -// return 1; -// } + /***** initialize the monitoring interface instance *****/ + if (NULL == (tr->mons = mons_new(tr))) { + tr_crit("Error initializing monitoring interface instance."); + return 1; + } + /* Monitor our tids/trps instances */ + tr->mons->tids = tr->tids; + tr->mons->trps = tr->trps; /***** process configuration *****/ tr->cfgwatch=tr_cfgwatch_create(tr); @@ -235,12 +240,12 @@ int main(int argc, char *argv[]) return 1; } -// /* install monitoring interface events */ -// tr_debug("Initializing monitoring interface events."); -// if (0 != tr_mon_event_init(tr->mons, ev_base, &mon_ev)) { -// tr_crit("Error initializing monitoring interface."); -// return 1; -// } + /* install monitoring interface events */ + tr_debug("Initializing monitoring interface events."); + if (0 != tr_mons_event_init(ev_base, tr->mons, tr->cfg_mgr, &mon_ev)) { + tr_crit("Error initializing monitoring interface."); + return 1; + } /* install TID server events */ tr_debug("Initializing TID server events."); diff --git a/tr/tr_mon.c b/tr/tr_mon.c index f96d0ed..01dab41 100644 --- a/tr/tr_mon.c +++ b/tr/tr_mon.c @@ -37,6 +37,7 @@ #include #include #include +#include /* * Cookie for the event handling callback @@ -128,7 +129,10 @@ static int tr_mons_auth_handler(gss_name_t client_name, TR_NAME *gss_name, void * @param mons_ev monitoring interface event instance * @return 0 on success, nonzero on failure. * */ -int tr_mon_event_init(struct event_base *base, MONS_INSTANCE *mons, TR_CFG_MGR *cfg_mgr, struct tr_socket_event *mons_ev) +int tr_mons_event_init(struct event_base *base, + MONS_INSTANCE *mons, + TR_CFG_MGR *cfg_mgr, + struct tr_socket_event *mons_ev) { TALLOC_CTX *tmp_ctx=talloc_new(NULL); struct tr_mons_event_cookie *cookie=NULL; -- 2.1.4