summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@intec.ugent.be>2017-02-28 13:56:57 +0000
committerSander Vrijders <sander.vrijders@intec.ugent.be>2017-02-28 13:56:57 +0000
commita5796c7f02570a2878f9c6a5d28dca80beabed12 (patch)
treec69603a29712665f3c7e8ee4e90d7209d61d3d85
parent6450c9d385ff9ec5234a489130a45378cafb8a6e (diff)
parente6f5d45855b4a8091b52b3fc91451d2d132a5a6d (diff)
downloadouroboros-a5796c7f02570a2878f9c6a5d28dca80beabed12.tar.gz
ouroboros-a5796c7f02570a2878f9c6a5d28dca80beabed12.zip
Merged in dstaesse/ouroboros/be-cacep (pull request #394)
lib: Split CACEP into request/response protocol
-rw-r--r--include/ouroboros/cacep.h10
-rw-r--r--src/ipcpd/normal/cdap_flow.c48
-rw-r--r--src/ipcpd/normal/gam.c43
-rw-r--r--src/lib/cacep.c32
4 files changed, 94 insertions, 39 deletions
diff --git a/include/ouroboros/cacep.h b/include/ouroboros/cacep.h
index 5ef66433..c7b7f38c 100644
--- a/include/ouroboros/cacep.h
+++ b/include/ouroboros/cacep.h
@@ -43,12 +43,10 @@ struct conn_info{
} ae;
};
-int cacep_connect(int fd,
- const struct conn_info * in,
- struct conn_info * out);
+int cacep_snd(int fd,
+ const struct conn_info * in);
-int cacep_listen(int fd,
- const struct conn_info * in,
- struct conn_info * out);
+int cacep_rcv(int fd,
+ struct conn_info * out);
#endif /* OUROBOROS_CACEP_H */
diff --git a/src/ipcpd/normal/cdap_flow.c b/src/ipcpd/normal/cdap_flow.c
index d3d98884..c694e637 100644
--- a/src/ipcpd/normal/cdap_flow.c
+++ b/src/ipcpd/normal/cdap_flow.c
@@ -67,12 +67,32 @@ struct cdap_flow * cdap_flow_arr(int fd,
flow->fd = fd;
flow->ci = NULL;
- if (cacep_listen(fd, info, &flow->info)) {
+ if (cacep_rcv(fd, &flow->info)) {
log_err("Error establishing application connection.");
cdap_flow_destroy(flow);
return NULL;
}
+ if (cacep_snd(fd, info)) {
+ log_err("Failed to respond to application connection request.");
+ cdap_flow_destroy(flow);
+ return NULL;
+ }
+
+ if (strcmp(flow->info.ae_name, info->ae_name)) {
+ log_err("Received connection for wrong AE.");
+ cdap_flow_destroy(flow);
+ return NULL;
+ }
+
+ if (strcmp(flow->info.protocol, info->protocol) ||
+ flow->info.pref_version != info->pref_version ||
+ flow->info.pref_syntax != info->pref_syntax) {
+ log_err("Unknown protocol.");
+ cdap_flow_destroy(flow);
+ return NULL;
+ }
+
flow->ci = cdap_create(fd);
if (flow->ci == NULL) {
log_err("Failed to create CDAP instance.");
@@ -87,8 +107,8 @@ struct cdap_flow * cdap_flow_alloc(const char * dst_name,
qosspec_t * qs,
const struct conn_info * info)
{
- struct cdap_flow * flow;
- int fd;
+ struct cdap_flow * flow;
+ int fd;
log_dbg("Allocating flow to %s.", dst_name);
@@ -120,12 +140,32 @@ struct cdap_flow * cdap_flow_alloc(const char * dst_name,
flow->fd = fd;
flow->ci = NULL;
- if (cacep_connect(fd, info, &flow->info)) {
+ if (cacep_snd(fd, info)) {
+ log_err("Failed to send connection request.");
+ cdap_flow_dealloc(flow);
+ return NULL;
+ }
+
+ if (cacep_rcv(fd, &flow->info)) {
log_err("Failed to connect to application.");
cdap_flow_dealloc(flow);
return NULL;
}
+ if (strcmp(flow->info.ae_name, info->ae_name)) {
+ log_err("Received connection for wrong AE.");
+ cdap_flow_destroy(flow);
+ return NULL;
+ }
+
+ if (strcmp(flow->info.protocol, info->protocol) ||
+ flow->info.pref_version != info->pref_version ||
+ flow->info.pref_syntax != info->pref_syntax) {
+ log_err("Unknown protocol.");
+ cdap_flow_destroy(flow);
+ return NULL;
+ }
+
flow->ci = cdap_create(fd);
if (flow->ci == NULL) {
log_err("Failed to create CDAP instance.");
diff --git a/src/ipcpd/normal/gam.c b/src/ipcpd/normal/gam.c
index bdfc8cb9..f98c0d4f 100644
--- a/src/ipcpd/normal/gam.c
+++ b/src/ipcpd/normal/gam.c
@@ -187,8 +187,30 @@ int gam_flow_arr(struct gam * instance,
snd_info.pref_syntax = PROTO_GPB;
snd_info.ae.addr = ipcpi.address;
- if (cacep_listen(fd, &snd_info, rcv_info)) {
- log_err("Failed to create application connection.");
+ if (cacep_rcv(fd, rcv_info)) {
+ log_err("Error establishing application connection.");
+ flow_dealloc(fd);
+ free(rcv_info);
+ return -1;
+ }
+
+ if (cacep_snd(fd, &snd_info)) {
+ log_err("Failed to respond to application connection request.");
+ flow_dealloc(fd);
+ free(rcv_info);
+ return -1;
+ }
+
+ if (strcmp(snd_info.ae_name, rcv_info->ae_name)) {
+ log_err("Received connection for wrong AE.");
+ flow_dealloc(fd);
+ free(rcv_info);
+ return -1;
+ }
+
+ if (strcmp(snd_info.protocol, rcv_info->protocol) ||
+ snd_info.pref_version != rcv_info->pref_version ||
+ snd_info.pref_syntax != rcv_info->pref_syntax) {
flow_dealloc(fd);
free(rcv_info);
return -1;
@@ -246,13 +268,28 @@ int gam_flow_alloc(struct gam * instance,
snd_info.pref_syntax = PROTO_GPB;
snd_info.ae.addr = ipcpi.address;
- if (cacep_connect(fd, &snd_info, rcv_info)) {
+ if (cacep_snd(fd, &snd_info)) {
log_err("Failed to create application connection.");
flow_dealloc(fd);
free(rcv_info);
return -1;
}
+ if (cacep_rcv(fd, rcv_info)) {
+ log_err("Failed to connect to application.");
+ flow_dealloc(fd);
+ free(rcv_info);
+ return -1;
+ }
+
+ if (strcmp(snd_info.protocol, rcv_info->protocol) ||
+ snd_info.pref_version != rcv_info->pref_version ||
+ snd_info.pref_syntax != rcv_info->pref_syntax) {
+ flow_dealloc(fd);
+ free(rcv_info);
+ return -1;
+ }
+
if (instance->ops->accept_flow(instance->ops_o, qs, rcv_info)) {
flow_dealloc(fd);
free(rcv_info);
diff --git a/src/lib/cacep.c b/src/lib/cacep.c
index badeccc0..abff0aaa 100644
--- a/src/lib/cacep.c
+++ b/src/lib/cacep.c
@@ -93,46 +93,26 @@ static int send_msg(int fd,
return 0;
}
-int cacep_connect(int fd,
- const struct conn_info * in,
- struct conn_info * out)
+int cacep_snd(int fd,
+ const struct conn_info * in)
{
- if (in == NULL || out == NULL)
+ if (in == NULL)
return -EINVAL;
if (send_msg(fd, in))
return -1;
- if (read_msg(fd, out))
- return -1;
-
- if (strcmp(in->ae_name, out->ae_name) ||
- strcmp(in->protocol, out->protocol) ||
- in->pref_version != out->pref_version ||
- in->pref_syntax != out->pref_syntax)
- return -EPROTO;
-
return 0;
}
-int cacep_listen(int fd,
- const struct conn_info * in,
- struct conn_info * out)
+int cacep_rcv(int fd,
+ struct conn_info * out)
{
- if (in == NULL || out == NULL)
+ if (out == NULL)
return -EINVAL;
- if (send_msg(fd, in))
- return -1;
-
if (read_msg(fd, out))
return -1;
- if (strcmp(in->ae_name, out->ae_name) ||
- strcmp(in->protocol, out->protocol) ||
- in->pref_version != out->pref_version ||
- in->pref_syntax != out->pref_syntax)
- return -EPROTO;
-
return 0;
}