From adc6766221327f99ab484d66f6f92050ec9e62d7 Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Tue, 21 Feb 2017 08:02:37 +0100 Subject: lib: Exchange protocol info during CACEP This exchanges a protocol name, a protocol version and concrete syntax for the protocol upon CACEP. For CDAP, only version 1 and GPB are supported. No lists for other supported versions or syntaxes are exchanged (but the proto file supports it). CACEP fails if there is a mismatch between the protocol names, version and syntax specified by the communicating parties. --- src/ipcpd/normal/cdap_flow.c | 7 ++---- src/ipcpd/normal/enroll.c | 36 ++++++++++++++++++++++++++-- src/ipcpd/normal/gam.c | 57 +++++++++++++++++++++++++++++++++++--------- 3 files changed, 82 insertions(+), 18 deletions(-) (limited to 'src/ipcpd') diff --git a/src/ipcpd/normal/cdap_flow.c b/src/ipcpd/normal/cdap_flow.c index 2895af0d..a94627c2 100644 --- a/src/ipcpd/normal/cdap_flow.c +++ b/src/ipcpd/normal/cdap_flow.c @@ -37,12 +37,9 @@ static void cdap_flow_destroy(struct cdap_flow * flow) if (flow->ci != NULL) cdap_destroy(flow->ci); - if (flow->info != NULL) { - if (flow->info->name != NULL) - free(flow->info->name); - if (flow->info->data != NULL) - free(flow->info->data); + cacep_info_fini(flow->info); + free(flow->info); } free(flow); diff --git a/src/ipcpd/normal/enroll.c b/src/ipcpd/normal/enroll.c index e8c085a8..ce6768fb 100644 --- a/src/ipcpd/normal/enroll.c +++ b/src/ipcpd/normal/enroll.c @@ -26,6 +26,7 @@ #include #include #include +#include #include "ae.h" #include "cdap_flow.h" @@ -43,6 +44,7 @@ int enroll_handle(int fd) { struct cdap_flow * flow; + struct cacep_info info; cdap_key_t key; enum cdap_opcode oc; char * name; @@ -59,13 +61,27 @@ int enroll_handle(int fd) char * members_ro = MEMBERS_PATH; char * dif_ro = DIF_PATH; - flow = cdap_flow_arr(fd, 0, ANONYMOUS_AUTH, NULL); + cacep_info_init(&info); + + info.proto.protocol = strdup(CDAP_PROTO); + if (info.proto.protocol == NULL) { + cacep_info_fini(&info); + return -ENOMEM; + } + + info.proto.pref_version = 1; + info.proto.pref_syntax = PROTO_GPB; + + flow = cdap_flow_arr(fd, 0, ANONYMOUS_AUTH, &info); if (flow == NULL) { log_err("Failed to auth enrollment request."); + cacep_info_fini(&info); flow_dealloc(fd); return -1; } + cacep_info_fini(&info); + while (!(boot_r && members_r && dif_name_r)) { key = cdap_request_wait(flow->ci, &oc, &name, &data, (size_t *) &len , &flags); @@ -140,6 +156,7 @@ int enroll_handle(int fd) int enroll_boot(char * dst_name) { struct cdap_flow * flow; + struct cacep_info info; cdap_key_t key; uint8_t * data; size_t len; @@ -153,12 +170,27 @@ int enroll_boot(char * dst_name) char * members_ro = MEMBERS_PATH; char * dif_ro = DIF_PATH; - flow = cdap_flow_alloc(dst_name, ENROLL_AE, NULL, ANONYMOUS_AUTH, NULL); + cacep_info_init(&info); + + info.proto.protocol = strdup(CDAP_PROTO); + if (info.proto.protocol == NULL) { + cacep_info_fini(&info); + return -ENOMEM; + } + + info.proto.pref_version = 1; + info.proto.pref_syntax = PROTO_GPB; + + flow = cdap_flow_alloc(dst_name, ENROLL_AE, NULL, ANONYMOUS_AUTH, + &info); if (flow == NULL) { log_err("Failed to allocate flow for enrollment request."); + cacep_info_fini(&info); return -1; } + cacep_info_fini(&info); + log_dbg("Getting boot information from %s.", dst_name); clock_gettime(CLOCK_REALTIME, &t0); diff --git a/src/ipcpd/normal/gam.c b/src/ipcpd/normal/gam.c index bc71f0d8..791cf34e 100644 --- a/src/ipcpd/normal/gam.c +++ b/src/ipcpd/normal/gam.c @@ -23,6 +23,7 @@ #define OUROBOROS_PREFIX "graph-adjacency-manager" #include +#include #include #include #include @@ -181,32 +182,48 @@ int gam_flow_arr(struct gam * instance, struct cacep_info * rcv_info; struct cacep_info snd_info; - snd_info.name = ipcpi.name; - snd_info.addr = ipcpi.address; - snd_info.data = NULL; - if (flow_alloc_resp(fd, instance->ops->accept_new_flow(instance->ops_o)) < 0) { log_err("Could not respond to new flow."); return -1; } + cacep_info_init(&snd_info); + snd_info.proto.protocol = strdup(CDAP_PROTO); + if (snd_info.proto.protocol == NULL) { + cacep_info_fini(&snd_info); + return -ENOMEM; + } + + snd_info.proto.pref_version = 1; + snd_info.proto.pref_syntax = PROTO_GPB; + snd_info.addr = ipcpi.address; + snd_info.name = strdup(ipcpi.name); + if (snd_info.name == NULL) { + cacep_info_fini(&snd_info); + return -ENOMEM; + } + rcv_info = cacep_auth_wait(fd, SIMPLE_AUTH, &snd_info); if (rcv_info == NULL) { log_err("Other side failed to authenticate."); + cacep_info_fini(&snd_info); return -1; } + cacep_info_fini(&snd_info); + if (instance->ops->accept_flow(instance->ops_o, qs, rcv_info)) { flow_dealloc(fd); - free(rcv_info->name); + cacep_info_fini(rcv_info); free(rcv_info); return 0; } if (add_ga(instance, fd, qs, rcv_info)) { log_err("Failed to add ga to graph adjacency manager list."); - free(rcv_info->name); + flow_dealloc(fd); + cacep_info_fini(rcv_info); free(rcv_info); return -1; } @@ -222,9 +239,7 @@ int gam_flow_alloc(struct gam * instance, struct cacep_info snd_info; int fd; - snd_info.name = ipcpi.name; - snd_info.addr = ipcpi.address; - snd_info.data = NULL; + log_dbg("Allocating flow to %s.", dst_name); fd = flow_alloc(dst_name, instance->ae_name, NULL); if (fd < 0) { @@ -238,22 +253,42 @@ int gam_flow_alloc(struct gam * instance, return -1; } + cacep_info_init(&snd_info); + snd_info.proto.protocol = strdup(CDAP_PROTO); + if (snd_info.proto.protocol == NULL) { + cacep_info_fini(&snd_info); + return -ENOMEM; + } + + snd_info.proto.pref_version = 1; + snd_info.proto.pref_syntax = PROTO_GPB; + snd_info.addr = ipcpi.address; + snd_info.name = strdup(ipcpi.name); + if (snd_info.name == NULL) { + cacep_info_fini(&snd_info); + return -ENOMEM; + } + rcv_info = cacep_auth(fd, SIMPLE_AUTH, &snd_info); if (rcv_info == NULL) { log_err("Other side failed to authenticate."); + cacep_info_fini(&snd_info); return -1; } + cacep_info_fini(&snd_info); + if (instance->ops->accept_flow(instance->ops_o, qs, rcv_info)) { flow_dealloc(fd); - free(rcv_info->name); + cacep_info_fini(rcv_info); free(rcv_info); return 0; } if (add_ga(instance, fd, qs, rcv_info)) { log_err("Failed to add GA to graph adjacency manager list."); - free(rcv_info->name); + flow_dealloc(fd); + cacep_info_fini(rcv_info); free(rcv_info); return -1; } -- cgit v1.2.3