From 1a02682d0695509bb8255b2d10dee48c61d83c34 Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Wed, 27 Apr 2016 18:36:31 +0200 Subject: lib: client-side flow allocation flow allocation now propagates on the client side up to the IPCP. added UNKNOWN_AP and UNKNOWN_AE definitions to dev.h --- src/ipcpd/ipcp.h | 3 --- src/ipcpd/shim-udp/main.c | 13 ++++++++++++- src/irmd/main.c | 40 +++++++++++++++++++++++++++++++++------- src/lib/dev.c | 6 ++++-- 4 files changed, 49 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/ipcpd/ipcp.h b/src/ipcpd/ipcp.h index f640d78b..9decac8b 100644 --- a/src/ipcpd/ipcp.h +++ b/src/ipcpd/ipcp.h @@ -26,9 +26,6 @@ #include "ipcp-ops.h" #include "ipcp-data.h" -/* needed to run over shim DIFs */ -#define ANONYMOUS_AP "__ANONYMOUS__" - enum ipcp_state { IPCP_INIT = 0, IPCP_ENROLLING, diff --git a/src/ipcpd/shim-udp/main.c b/src/ipcpd/shim-udp/main.c index c07d77c2..71c414ef 100644 --- a/src/ipcpd/shim-udp/main.c +++ b/src/ipcpd/shim-udp/main.c @@ -29,6 +29,7 @@ #include #include #include +#include #define OUROBOROS_PREFIX "ipcpd/shim-udp" @@ -192,7 +193,7 @@ static void * ipcp_udp_listener() /* reply to IRM */ flow->flow.port_id = ipcp_flow_req_arr(getpid(), buf, - ANONYMOUS_AP, ""); + UNKNOWN_AP, ""); if (flow->flow.port_id < 0) { LOG_ERR("Could not get port id from IRMd"); close(flow->fd); @@ -270,6 +271,7 @@ int ipcp_udp_bootstrap(struct dif_config * conf) char dnsstr[INET_ADDRSTRLEN]; pthread_t handler; pthread_t sdu_reader; + int enable = 1; if (conf->type != THIS_TYPE) { LOG_ERR("Config doesn't match IPCP type."); @@ -305,6 +307,14 @@ int ipcp_udp_bootstrap(struct dif_config * conf) return -1; } + if (setsockopt(shim_data(_ipcp)->s_fd, + SOL_SOCKET, + SO_REUSEADDR, + &enable, + sizeof(int)) < 0) { + LOG_DBGF("Setsockopt(SO_REUSEADDR) failed."); + } + shim_data(_ipcp)->s_saddr.sin_family = AF_INET; shim_data(_ipcp)->s_saddr.sin_addr.s_addr = conf->ip_addr; shim_data(_ipcp)->s_saddr.sin_port = LISTEN_PORT; @@ -419,6 +429,7 @@ int ipcp_udp_flow_alloc(uint32_t port_id, h = gethostbyname(dst_name); if (h == NULL) { + LOG_DBGF("Could not resolve %s.", dst_name); close(flow->fd); free(flow); return -1; diff --git a/src/irmd/main.c b/src/irmd/main.c index 31dabebb..67254feb 100644 --- a/src/irmd/main.c +++ b/src/irmd/main.c @@ -123,6 +123,20 @@ static instance_name_t * get_ipcp_by_dif_name(char * dif_name) return NULL; } +/* FIXME: this just returns the first IPCP for now */ +static instance_name_t * get_ipcp_by_dst_name(char * dst_name) +{ + struct list_head * pos = NULL; + + list_for_each(pos, &instance->ipcps) { + struct ipcp_entry * e = + list_entry(pos, struct ipcp_entry, next); + return e->api; + } + + return NULL; +} + static struct reg_name_entry * reg_name_entry_create() { struct reg_name_entry * e = malloc(sizeof(*e)); @@ -549,6 +563,7 @@ static int ap_unreg(char * ap_name, static int flow_accept(int fd, + pid_t pid, char * ap_name, char * ae_name) { @@ -558,17 +573,27 @@ static int flow_accept(int fd, static int flow_alloc_resp(int fd, int result) { - return -1; } -static int flow_alloc(char * dst_ap_name, +static int flow_alloc(char * dst_name, char * src_ap_name, char * src_ae_name, struct qos_spec * qos, int oflags) { - return -1; + int port_id = 0; + pid_t pid = get_ipcp_by_dst_name(dst_name)->id; + + LOG_DBG("flow alloc received from %s-%s to %s.", + src_ap_name, src_ae_name, dst_name); + + return ipcp_flow_alloc(pid, + port_id, + dst_name, + src_ap_name, + src_ae_name, + qos); } static int flow_alloc_res(int fd) @@ -588,9 +613,9 @@ static int flow_cntl(int fd, return -1; } -static int flow_req_arr(uint32_t reg_api_id, - char * ap_name, - char * ae_name) +static int flow_req_arr(char * dst_name, + char * ap_name, + char * ae_name) { return -1; } @@ -741,6 +766,7 @@ int main() case IRM_MSG_CODE__IRM_FLOW_ACCEPT: ret_msg.has_fd = true; ret_msg.fd = flow_accept(msg->fd, + msg->pid, ret_msg.ap_name, ret_msg.ae_name); break; @@ -772,7 +798,7 @@ int main() break; case IRM_MSG_CODE__IPCP_FLOW_REQ_ARR: ret_msg.has_port_id = true; - ret_msg.port_id = flow_req_arr(msg->port_id, + ret_msg.port_id = flow_req_arr(msg->dst_name, msg->ap_name, msg->ae_name); break; diff --git a/src/lib/dev.c b/src/lib/dev.c index 60dee701..6d8411c5 100644 --- a/src/lib/dev.c +++ b/src/lib/dev.c @@ -177,11 +177,13 @@ int flow_alloc(char * dst_name, int fd = 0; if (dst_name == NULL || - src_ap_name == NULL || - qos == NULL) { + src_ap_name == NULL) { return -EINVAL; } + if (src_ae_name == NULL) + src_ae_name = UNKNOWN_AE; + msg.code = IRM_MSG_CODE__IRM_FLOW_ALLOC; msg.dst_name = dst_name; msg.ap_name = src_ap_name; -- cgit v1.2.3