2 * Copyright (c) 2018, JANET(UK)
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of JANET(UK) nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
31 * OF THE POSSIBILITY OF SUCH DAMAGE.
36 #ifndef TRUST_ROUTER_MON_REQ_H
37 #define TRUST_ROUTER_MON_REQ_H
43 //#include <trp_internal.h>
44 #include <tr_gss_names.h>
45 #include <tr_name_internal.h>
47 #include <trust_router/tr_dh.h>
50 typedef struct mon_req MON_REQ;
51 typedef struct mon_resp MON_RESP;
53 typedef enum mon_cmd MON_CMD;
54 typedef enum mon_resp_code MON_RESP_CODE;
56 typedef struct mon_opt MON_OPT;
57 typedef enum mon_opt_type MON_OPT_TYPE;
59 typedef enum mon_rc MON_RC;
61 typedef struct mons_instance MONS_INSTANCE;
62 typedef struct monc_instance MONC_INSTANCE;
64 typedef int (MONS_REQ_FUNC)(MONS_INSTANCE *, MON_REQ *, MON_RESP *, void *);
65 typedef int (MONS_AUTH_FUNC)(gss_name_t client_name, TR_NAME *display_name, void *cookie);
66 typedef int (MONC_RESP_FUNC)(MONS_INSTANCE *, MON_REQ *, MON_RESP *, void *);
68 /* Struct and enum definitions */
71 MON_ERROR, /* generic error */
72 MON_BADARG, /* problem with the arguments */
73 MON_NOMEM, /* out of memory */
74 MON_NOPARSE, /* parsing failed */
83 /* These should be explicitly numbered because they form part of the public API */
86 MON_RESP_ERROR=1, // generic error
93 OPT_TYPE_SHOW_VERSION,
98 OPT_TYPE_SHOW_TID_REQ_COUNT,
99 OPT_TYPE_SHOW_TID_REQ_PENDING,
101 // Dynamic trust router state
102 OPT_TYPE_SHOW_ROUTES,
103 OPT_TYPE_SHOW_COMMUNITIES
116 MON_REQ *req; // request this responds to
122 /* Monitoring server instance */
123 struct mons_instance {
124 const char *hostname;
126 TR_GSS_NAMES *authorized_gss_names;
127 void *tids; // TODO sort out header file cycles and use typed pointers
128 void *trps; // TODO sort out header file cycles and use typed pointers
129 MONS_REQ_FUNC *req_handler;
130 MONS_AUTH_FUNC *auth_handler;
134 /* Monitoring client instance */
135 struct monc_instance {
141 const char *mon_cmd_to_string(MON_CMD cmd);
142 MON_CMD mon_cmd_from_string(const char *s);
143 const char *mon_opt_type_to_string(MON_OPT_TYPE opt_type);
144 MON_OPT_TYPE mon_opt_type_from_string(const char *s);
147 MON_REQ *mon_req_new(TALLOC_CTX *mem_ctx, MON_CMD cmd);
148 void mon_req_free(MON_REQ *req);
149 MON_RC mon_req_add_option(MON_REQ *req, MON_OPT_TYPE opt_type);
150 size_t mon_req_opt_count(MON_REQ *req);
151 MON_OPT *mon_req_opt_index(MON_REQ *req, size_t index);
153 /* mon_req_encode.c */
154 json_t *mon_req_encode(MON_REQ *req);
156 /* mon_req_decode.c */
157 MON_REQ *mon_req_decode(TALLOC_CTX *mem_ctx, json_t *req_json);
160 MON_RESP *mon_resp_new(TALLOC_CTX *mem_ctx,
165 void mon_resp_free(MON_RESP *resp);
167 /* mon_resp_encode.c */
168 json_t *mon_resp_encode(MON_RESP *resp);
171 MONS_INSTANCE *mons_new(TALLOC_CTX *mem_ctx);
172 int mons_get_listener(MONS_INSTANCE *mons, MONS_REQ_FUNC *req_handler, MONS_AUTH_FUNC *auth_handler, const char *hostname,
173 unsigned int port, void *cookie, int *fd_out, size_t max_fd);
174 int mons_accept(MONS_INSTANCE *mons, int listen);
177 MONC_INSTANCE *monc_create(void);
178 void monc_destroy(MONC_INSTANCE *monc);
179 int monc_open_connection (MONC_INSTANCE *monc, const char *server, unsigned int port, gss_ctx_id_t *gssctx);
180 int monc_send_request (MONC_INSTANCE *monc, int conn, gss_ctx_id_t gssctx, MONC_RESP_FUNC *resp_handler,
182 int monc_fwd_request(MONC_INSTANCE *monc, int conn, gss_ctx_id_t gssctx, MON_REQ *mon_req,
183 MONC_RESP_FUNC *resp_handler, void *cookie);
184 DH * monc_get_dh(MONC_INSTANCE *inst);
185 DH *monc_set_dh(MONC_INSTANCE *inst, DH *dh);
187 #endif //TRUST_ROUTER_MON_REQ_H