X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=include%2Ftrp_internal.h;h=0655a62b3d28719a8f3537ddc355571e59ef069a;hb=fe3b5cb31ab0d19c2ead6465f82ceb749bf05b75;hp=c6828f63a83b7840ecd781aad862ca866dca18b9;hpb=f52f20507c568db42dbd2ddc99c7fa5a27012868;p=trust_router.git diff --git a/include/trp_internal.h b/include/trp_internal.h index c6828f6..0655a62 100644 --- a/include/trp_internal.h +++ b/include/trp_internal.h @@ -1,41 +1,95 @@ +/* + * Copyright (c) 2016, 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 TRP_INTERNAL_H #define TRP_INTERNAL_H +#include #include #include +#include #include #include #include +#include #include +#include #include +#include +#include #include +/* what clock do we use with clock_gettime() ? */ +#define TRP_CLOCK CLOCK_MONOTONIC + /* info records */ /* TRP update record types */ typedef struct trp_inforec_route { - TR_NAME *comm; - TR_NAME *realm; TR_NAME *trust_router; + int trust_router_port; TR_NAME *next_hop; + int next_hop_port; unsigned int metric; unsigned int interval; } TRP_INFOREC_ROUTE; -/* TODO: define struct trp_msg_info_community */ +typedef struct trp_inforec_comm { + TR_COMM_TYPE comm_type; + TR_REALM_ROLE role; + TR_APC *apcs; + TR_NAME *owner_realm; + TR_NAME *owner_contact; + time_t expiration_interval; /* Minutes to key expiration; only valid for an APC */ + json_t *provenance; + unsigned int interval; +} TRP_INFOREC_COMM; typedef union trp_inforec_data { TRP_INFOREC_ROUTE *route; - /* TRP_INFOREC_COMM *comm; */ + TRP_INFOREC_COMM *comm; } TRP_INFOREC_DATA; struct trp_inforec { TRP_INFOREC *next; TRP_INFOREC_TYPE type; - TRP_INFOREC_DATA data; /* contains pointer to one of the record types */ + TRP_INFOREC_DATA *data; /* contains pointer to one of the record types */ }; struct trp_update { + TR_NAME *realm; + TR_NAME *comm; TRP_INFOREC *records; TR_NAME *peer; /* who did this update come from? */ }; @@ -63,8 +117,8 @@ struct trp_connection { TRP_CONNECTION *next; pthread_t *thread; /* thread servicing this connection */ int fd; - TR_NAME *gssname; - TR_NAME *peer; /* TODO: why is there a peer and a gssname? jlr */ + TR_NAME *gssname; /* the gss service name we presented for passive auth */ + TR_NAME *peer; /* gssname of incoming peer */ gss_ctx_id_t *gssctx; TRP_CONNECTION_STATUS status; void (*status_change_cb)(TRP_CONNECTION *conn, void *cookie); @@ -86,7 +140,7 @@ struct trpc_instance { TRPC_INSTANCE *next; TR_NAME *gssname; char *server; - unsigned int port; + int port; TRP_CONNECTION *conn; TR_MQ *mq; /* msgs from master to trpc */ }; @@ -94,7 +148,8 @@ struct trpc_instance { /* TRP Server Instance Data */ struct trps_instance { char *hostname; - unsigned int port; + int trps_port; + int tids_port; /* used for route advertisements; must agree with our tids configuration */ TRP_AUTH_FUNC auth_handler; TRPS_MSG_FUNC msg_handler; void *cookie; @@ -103,6 +158,7 @@ struct trps_instance { TR_MQ *mq; /* incoming message queue */ TRP_PTABLE *ptable; /* peer table */ TRP_RTABLE *rtable; /* route table */ + TR_COMM_TABLE *ctable; /* community table */ struct timeval connect_interval; /* interval between connection refreshes */ struct timeval update_interval; /* interval between scheduled updates */ struct timeval sweep_interval; /* interval between route table sweeps */ @@ -133,8 +189,8 @@ TRP_CONNECTION *trp_connection_get_next(TRP_CONNECTION *conn); TRP_CONNECTION *trp_connection_remove(TRP_CONNECTION *conn, TRP_CONNECTION *remove); void trp_connection_append(TRP_CONNECTION *conn, TRP_CONNECTION *new); int trp_connection_auth(TRP_CONNECTION *conn, TRP_AUTH_FUNC auth_callback, void *callback_data); -TRP_CONNECTION *trp_connection_accept(TALLOC_CTX *mem_ctx, int listen, TR_NAME *gssname); -TRP_RC trp_connection_initiate(TRP_CONNECTION *conn, char *server, unsigned int port); +TRP_CONNECTION *trp_connection_accept(TALLOC_CTX *mem_ctx, int listen, TR_NAME *gss_servicename); +TRP_RC trp_connection_initiate(TRP_CONNECTION *conn, char *server, int port); TRPC_INSTANCE *trpc_new (TALLOC_CTX *mem_ctx); void trpc_free (TRPC_INSTANCE *trpc); @@ -149,12 +205,12 @@ void trpc_set_server(TRPC_INSTANCE *trpc, char *server); TR_NAME *trpc_get_gssname(TRPC_INSTANCE *trpc); void trpc_set_gssname(TRPC_INSTANCE *trpc, TR_NAME *gssname); unsigned int trpc_get_port(TRPC_INSTANCE *trpc); -void trpc_set_port(TRPC_INSTANCE *trpc, unsigned int port); +void trpc_set_port(TRPC_INSTANCE *trpc, int port); TRP_CONNECTION_STATUS trpc_get_status(TRPC_INSTANCE *trpc); TR_MQ *trpc_get_mq(TRPC_INSTANCE *trpc); void trpc_set_mq(TRPC_INSTANCE *trpc, TR_MQ *mq); void trpc_mq_add(TRPC_INSTANCE *trpc, TR_MQ_MSG *msg); -TR_MQ_MSG *trpc_mq_pop(TRPC_INSTANCE *trpc); +TR_MQ_MSG *trpc_mq_pop(TRPC_INSTANCE *trpc, struct timespec *ts_abort); void trpc_mq_clear(TRPC_INSTANCE *trpc); void trpc_master_mq_add(TRPC_INSTANCE *trpc, TR_MQ_MSG *msg); TR_MQ_MSG *trpc_master_mq_pop(TRPC_INSTANCE *trpc); @@ -163,7 +219,10 @@ TRP_RC trpc_send_msg(TRPC_INSTANCE *trpc, const char *msg_content); TRPS_INSTANCE *trps_new (TALLOC_CTX *mem_ctx); void trps_free (TRPS_INSTANCE *trps); +void trps_set_ctable(TRPS_INSTANCE *trps, TR_COMM_TABLE *comm); void trps_set_ptable(TRPS_INSTANCE *trps, TRP_PTABLE *ptable); +void trps_set_peer_status_callback(TRPS_INSTANCE *trps, void (*cb)(TRP_PEER *, void *), void *cookie); +TR_NAME *trps_dup_label(TRPS_INSTANCE *trps); TRP_RC trps_init_rtable(TRPS_INSTANCE *trps); void trps_clear_rtable(TRPS_INSTANCE *trps); void trps_set_connect_interval(TRPS_INSTANCE *trps, unsigned int interval); @@ -182,8 +241,10 @@ int trps_get_listener(TRPS_INSTANCE *trps, TRPS_MSG_FUNC msg_handler, TRP_AUTH_FUNC auth_handler, const char *hostname, - unsigned int port, - void *cookie); + int port, + void *cookie, + int *fd_out, + size_t max_fd); TR_MQ_MSG *trps_mq_pop(TRPS_INSTANCE *trps); void trps_mq_add(TRPS_INSTANCE *trps, TR_MQ_MSG *msg); TRP_RC trps_authorize_connection(TRPS_INSTANCE *trps, TRP_CONNECTION *conn); @@ -194,6 +255,7 @@ TRP_ROUTE *trps_get_route(TRPS_INSTANCE *trps, TR_NAME *comm, TR_NAME *realm, TR TRP_ROUTE *trps_get_selected_route(TRPS_INSTANCE *trps, TR_NAME *comm, TR_NAME *realm); TR_NAME *trps_get_next_hop(TRPS_INSTANCE *trps, TR_NAME *comm, TR_NAME *realm); TRP_RC trps_sweep_routes(TRPS_INSTANCE *trps); +TRP_RC trps_sweep_ctable(TRPS_INSTANCE *trps); TRP_RC trps_add_route(TRPS_INSTANCE *trps, TRP_ROUTE *route); TRP_RC trps_add_peer(TRPS_INSTANCE *trps, TRP_PEER *peer); TRP_PEER *trps_get_peer_by_gssname(TRPS_INSTANCE *trps, TR_NAME *gssname); @@ -201,4 +263,47 @@ TRP_PEER *trps_get_peer_by_servicename(TRPS_INSTANCE *trps, TR_NAME *servicename TRP_RC trps_update(TRPS_INSTANCE *trps, TRP_UPDATE_TYPE type); int trps_peer_connected(TRPS_INSTANCE *trps, TRP_PEER *peer); TRP_RC trps_wildcard_route_req(TRPS_INSTANCE *trps, TR_NAME *peer_gssname); + +TRP_INFOREC *trp_inforec_new(TALLOC_CTX *mem_ctx, TRP_INFOREC_TYPE type); +void trp_inforec_free(TRP_INFOREC *rec); +TRP_INFOREC *trp_inforec_get_next(TRP_INFOREC *rec); +void trp_inforec_set_next(TRP_INFOREC *rec, TRP_INFOREC *next_rec); +TRP_INFOREC_TYPE trp_inforec_get_type(TRP_INFOREC *rec); +void trp_inforec_set_type(TRP_INFOREC *rec, TRP_INFOREC_TYPE type); +TR_NAME *trp_inforec_get_comm(TRP_INFOREC *rec); +TR_NAME *trp_inforec_dup_comm(TRP_INFOREC *rec); +TRP_RC trp_inforec_set_comm(TRP_INFOREC *rec, TR_NAME *comm); +TR_NAME *trp_inforec_get_realm(TRP_INFOREC *rec); +TR_NAME *trp_inforec_dup_realm(TRP_INFOREC *rec); +TRP_RC trp_inforec_set_realm(TRP_INFOREC *rec, TR_NAME *realm); +TR_NAME *trp_inforec_get_trust_router(TRP_INFOREC *rec); +int trp_inforec_get_trust_router_port(TRP_INFOREC *rec); +TR_NAME *trp_inforec_dup_trust_router(TRP_INFOREC *rec); +TRP_RC trp_inforec_set_trust_router(TRP_INFOREC *rec, TR_NAME *trust_router, int port); +TR_NAME *trp_inforec_get_next_hop(TRP_INFOREC *rec); +int trp_inforec_get_next_hop_port(TRP_INFOREC *rec); +TR_NAME *trp_inforec_dup_next_hop(TRP_INFOREC *rec); +TRP_RC trp_inforec_set_next_hop(TRP_INFOREC *rec, TR_NAME *next_hop, int port); +unsigned int trp_inforec_get_metric(TRP_INFOREC *rec); +TRP_RC trp_inforec_set_metric(TRP_INFOREC *rec, unsigned int metric); +unsigned int trp_inforec_get_interval(TRP_INFOREC *rec); +TRP_RC trp_inforec_set_interval(TRP_INFOREC *rec, unsigned int interval); +TR_NAME *trp_inforec_get_owner_realm(TRP_INFOREC *rec); +TRP_RC trp_inforec_set_owner_realm(TRP_INFOREC *rec, TR_NAME *name); +TR_NAME *trp_inforec_get_owner_contact(TRP_INFOREC *rec); +TRP_RC trp_inforec_set_owner_contact(TRP_INFOREC *rec, TR_NAME *name); +json_t *trp_inforec_get_provenance(TRP_INFOREC *rec); +TRP_RC trp_inforec_set_provenance(TRP_INFOREC *rec, json_t *prov); +TRP_INFOREC_TYPE trp_inforec_type_from_string(const char *s); +const char *trp_inforec_type_to_string(TRP_INFOREC_TYPE msgtype); +time_t trp_inforec_get_exp_interval(TRP_INFOREC *rec); +TRP_RC trp_inforec_set_exp_interval(TRP_INFOREC *rec, time_t expint); +TR_COMM_TYPE trp_inforec_get_comm_type(TRP_INFOREC *rec); +TRP_RC trp_inforec_set_comm_type(TRP_INFOREC *rec, TR_COMM_TYPE type); +TR_REALM_ROLE trp_inforec_get_role(TRP_INFOREC *rec); +TRP_RC trp_inforec_set_role(TRP_INFOREC *rec, TR_REALM_ROLE role); +TR_APC *trp_inforec_get_apcs(TRP_INFOREC *rec); +TRP_RC trp_inforec_set_apcs(TRP_INFOREC *rec, TR_APC *apcs); +TR_NAME *trp_inforec_dup_origin(TRP_INFOREC *rec); + #endif /* TRP_INTERNAL_H */