diff options
Diffstat (limited to 'src/ipcpd')
-rw-r--r-- | src/ipcpd/ipcp-data.c | 94 | ||||
-rw-r--r-- | src/ipcpd/ipcp-data.h | 13 | ||||
-rw-r--r-- | src/ipcpd/ipcp-ops.h | 5 | ||||
-rw-r--r-- | src/ipcpd/ipcp.c | 22 | ||||
-rw-r--r-- | src/ipcpd/shim-udp/main.c | 24 | ||||
-rw-r--r-- | src/ipcpd/shim-udp/tests/shim_udp_test.c | 13 |
6 files changed, 51 insertions, 120 deletions
diff --git a/src/ipcpd/ipcp-data.c b/src/ipcpd/ipcp-data.c index 1828fda9..e6997e3e 100644 --- a/src/ipcpd/ipcp-data.c +++ b/src/ipcpd/ipcp-data.c @@ -35,8 +35,7 @@ struct reg_entry { struct list_head list; - char * ap_name; - uint32_t reg_ap_id; + char * name; }; struct dir_entry { @@ -45,16 +44,14 @@ struct dir_entry { uint64_t addr; }; -static struct reg_entry * reg_entry_create(const char * ap_name, - uint32_t reg_ap_id) +static struct reg_entry * reg_entry_create(const char * name) { struct reg_entry * entry = malloc(sizeof *entry); if (entry == NULL) return NULL; - entry->reg_ap_id = reg_ap_id; - entry->ap_name = strdup(ap_name); - if (entry->ap_name == NULL) + entry->name = strdup(name); + if (entry->name == NULL) return NULL; return entry; @@ -65,7 +62,7 @@ static void reg_entry_destroy(struct reg_entry * entry) if (entry == NULL) return; - free(entry->ap_name); + free(entry->name); free(entry); } @@ -194,25 +191,12 @@ void ipcp_data_destroy(struct ipcp_data * data) static struct reg_entry * find_reg_entry_by_name(struct ipcp_data * data, - const char * ap_name) + const char * name) { struct list_head * h; list_for_each(h, &data->registry) { struct reg_entry * e = list_entry(h, struct reg_entry, list); - if (!strcmp(e->ap_name, ap_name)) - return e; - } - - return NULL; -} - -static struct reg_entry * find_reg_entry_by_id(struct ipcp_data * data, - uint32_t reg_ap_id) -{ - struct list_head * h; - list_for_each(h, &data->registry) { - struct reg_entry * e = list_entry(h, struct reg_entry, list); - if (e->reg_ap_id == reg_ap_id) + if (!strcmp(e->name, name)) return e; } @@ -253,7 +237,7 @@ bool ipcp_data_is_in_directory(struct ipcp_data * data, } int ipcp_data_del_reg_entry(struct ipcp_data * data, - uint32_t reg_ap_id) + const char * name) { struct reg_entry * e; if (data == NULL) @@ -261,7 +245,7 @@ int ipcp_data_del_reg_entry(struct ipcp_data * data, pthread_mutex_lock(&data->reg_lock); - e = find_reg_entry_by_id(data, reg_ap_id); + e = find_reg_entry_by_name(data, name); if (e == NULL) { pthread_mutex_unlock(&data->reg_lock); return 0; /* nothing to do */ @@ -302,23 +286,21 @@ int ipcp_data_del_dir_entry(struct ipcp_data * data, } int ipcp_data_add_reg_entry(struct ipcp_data * data, - char * ap_name, - uint32_t reg_ap_id) + const char * name) { struct reg_entry * entry; - if (data == NULL || ap_name == NULL) + if (data == NULL || name == NULL) return -1; pthread_mutex_lock(&data->reg_lock); - if (find_reg_entry_by_name(data, ap_name) || - find_reg_entry_by_id(data, reg_ap_id)) { + if (find_reg_entry_by_name(data, name)) { pthread_mutex_unlock(&data->reg_lock); return -2; } - entry = reg_entry_create(ap_name, reg_ap_id); + entry = reg_entry_create(name); if (entry == NULL) { pthread_mutex_unlock(&data->reg_lock); return -1; @@ -332,7 +314,7 @@ int ipcp_data_add_reg_entry(struct ipcp_data * data, } int ipcp_data_add_dir_entry(struct ipcp_data * data, - char * ap_name, + const char * ap_name, uint64_t addr) { struct dir_entry * entry; @@ -366,54 +348,6 @@ bool ipcp_data_is_in_registry(struct ipcp_data * data, return find_reg_entry_by_name(data, ap_name) != NULL; } -uint32_t ipcp_data_get_reg_ap_id(struct ipcp_data * data, - const char * ap_name) -{ - struct reg_entry * entry; - uint32_t id; - - pthread_mutex_lock(&data->reg_lock); - - entry = find_reg_entry_by_name(data, ap_name); - - if (entry == NULL) { - pthread_mutex_unlock(&data->reg_lock); - return 0; /* undefined behaviour */ - } - - id = entry->reg_ap_id; - - pthread_mutex_unlock(&data->reg_lock); - - return id; -} - -const char * ipcp_data_get_reg_ap_name(struct ipcp_data * data, - uint32_t reg_ap_id) -{ - struct reg_entry * entry; - char * name; - - pthread_mutex_lock(&data->reg_lock); - - entry = find_reg_entry_by_id(data, reg_ap_id); - - if (entry == NULL) { - pthread_mutex_unlock(&data->reg_lock); - return NULL; - } - - name = strdup(entry->ap_name); - if (name == NULL) { - pthread_mutex_unlock(&data->reg_lock); - return NULL; - } - - pthread_mutex_unlock(&data->reg_lock); - - return name; -} - uint64_t ipcp_data_get_addr(struct ipcp_data * data, const char * ap_name) { diff --git a/src/ipcpd/ipcp-data.h b/src/ipcpd/ipcp-data.h index 3f036ef5..7e48df24 100644 --- a/src/ipcpd/ipcp-data.h +++ b/src/ipcpd/ipcp-data.h @@ -58,22 +58,17 @@ struct ipcp_data * ipcp_data_init(struct ipcp_data * dst, void ipcp_data_destroy(struct ipcp_data * data); int ipcp_data_add_reg_entry(struct ipcp_data * data, - char * ap_name, - uint32_t reg_ap_id); + const char * name); int ipcp_data_del_reg_entry(struct ipcp_data * data, - uint32_t reg_ap_id); + const char * name); int ipcp_data_add_dir_entry(struct ipcp_data * data, - char * ap_name, + const char * ap_name, uint64_t addr); int ipcp_data_del_dir_entry(struct ipcp_data * data, const char * ap_name, uint64_t addr); bool ipcp_data_is_in_registry(struct ipcp_data * data, - const char * ap_name); -uint32_t ipcp_data_get_reg_ap_id(struct ipcp_data * data, - const char * ap_name); -const char * ipcp_data_get_reg_ap_name(struct ipcp_data * data, - uint32_t reg_ap_id); + const char * name); bool ipcp_data_is_in_directory(struct ipcp_data * data, const char * ap_name); uint64_t ipcp_data_get_addr(struct ipcp_data * data, diff --git a/src/ipcpd/ipcp-ops.h b/src/ipcpd/ipcp-ops.h index 5c917229..2ccb2e59 100644 --- a/src/ipcpd/ipcp-ops.h +++ b/src/ipcpd/ipcp-ops.h @@ -36,9 +36,8 @@ struct ipcp_ops { size_t len); int (* ipcp_unreg)(char ** dif_names, size_t len); - int (* ipcp_ap_reg)(char * ap_name, - uint32_t reg_ap_id); - int (* ipcp_ap_unreg)(uint32_t reg_ap_id); + int (* ipcp_name_reg)(char * name); + int (* ipcp_name_unreg)(char * name); int (* ipcp_flow_alloc)(uint32_t port_id, char * dst_ap_name, char * src_ap_name, diff --git a/src/ipcpd/ipcp.c b/src/ipcpd/ipcp.c index e0dac20b..c1071e05 100644 --- a/src/ipcpd/ipcp.c +++ b/src/ipcpd/ipcp.c @@ -151,23 +151,23 @@ int ipcp_main_loop(struct ipcp * _ipcp) ret_msg.result = _ipcp->ops->ipcp_unreg( msg->dif_names, msg->len); break; - case IPCP_MSG_CODE__IPCP_AP_REG: - if (_ipcp->ops->ipcp_ap_reg == NULL) { + case IPCP_MSG_CODE__IPCP_NAME_REG: + if (_ipcp->ops->ipcp_name_reg == NULL) { LOG_ERR("Ap_reg unsupported."); break; } ret_msg.has_result = true; - ret_msg.result = _ipcp->ops->ipcp_ap_reg( - msg->ap_name, msg->reg_ap_id); + ret_msg.result = _ipcp->ops->ipcp_name_reg( + msg->name); break; - case IPCP_MSG_CODE__IPCP_AP_UNREG: - if (_ipcp->ops->ipcp_ap_unreg == NULL) { + case IPCP_MSG_CODE__IPCP_NAME_UNREG: + if (_ipcp->ops->ipcp_name_unreg == NULL) { LOG_ERR("Ap_unreg unsupported."); break; } ret_msg.has_result = true; - ret_msg.result = _ipcp->ops->ipcp_ap_unreg( - msg->reg_ap_id); + ret_msg.result = _ipcp->ops->ipcp_name_unreg( + msg->name); break; case IPCP_MSG_CODE__IPCP_FLOW_ALLOC: if (_ipcp->ops->ipcp_flow_alloc == NULL) { @@ -177,9 +177,9 @@ int ipcp_main_loop(struct ipcp * _ipcp) ret_msg.has_fd = true; ret_msg.fd = _ipcp->ops->ipcp_flow_alloc( msg->port_id, - msg->dst_ap_name, - msg->ap_name, - msg->ae_name, + msg->dst_name, + msg->src_ap_name, + msg->src_ae_name, NULL); break; case IPCP_MSG_CODE__IPCP_FLOW_ALLOC_RESP: diff --git a/src/ipcpd/shim-udp/main.c b/src/ipcpd/shim-udp/main.c index 14b08ba8..a65aa11d 100644 --- a/src/ipcpd/shim-udp/main.c +++ b/src/ipcpd/shim-udp/main.c @@ -214,8 +214,7 @@ static void * ipcp_udp_listener() msg.code = IRM_MSG_CODE__IPCP_FLOW_REQ_ARR; msg.ap_name = ANONYMOUS_AP; msg.ae_name = ""; /* no AE */ - msg.has_reg_ap_id = true; - msg.reg_ap_id = ipcp_data_get_reg_ap_id(_ipcp->data, buf); + msg.dst_name = buf; ret_msg = send_recv_irm_msg(&msg); if (ret_msg == NULL) { @@ -247,8 +246,9 @@ static void * ipcp_udp_listener() FD_SET(flow->fd, &shim_data(_ipcp)->flow_fd_s); shim_data(_ipcp)->fd_to_flow_ptr[flow->fd] = &flow->flow; - } + + return 0; } static void * ipcp_udp_sdu_reader() @@ -364,19 +364,19 @@ int ipcp_udp_bootstrap(struct dif_config * conf) return 0; } -int ipcp_udp_ap_reg(char * ap_name, uint32_t reg_ap_id) +int ipcp_udp_name_reg(char * name) { if (_ipcp->state != IPCP_ENROLLED) { LOG_DBGF("Won't register with non-enrolled IPCP."); return -1; } - if (ipcp_data_add_reg_entry(_ipcp->data, ap_name, reg_ap_id)) { - LOG_ERR("Failed to add AP to local registry."); + if (ipcp_data_add_reg_entry(_ipcp->data, name)) { + LOG_ERR("Failed to add %s to local registry.", name); return -1; } - LOG_DBG("Registered local ap %s, %u.", ap_name, reg_ap_id); + LOG_DBG("Registered %s", name); /* FIXME: register application with DNS server */ LOG_MISSING; @@ -384,9 +384,11 @@ int ipcp_udp_ap_reg(char * ap_name, uint32_t reg_ap_id) return 0; } -int ipcp_udp_ap_unreg(uint32_t reg_ap_id) +int ipcp_udp_name_unreg(char * name) { - ipcp_data_del_reg_entry(_ipcp->data, reg_ap_id); + ipcp_data_del_reg_entry(_ipcp->data, name); + + LOG_DBG("Unregistered %s.", name); /* FIXME: unregister application from DNS server */ LOG_MISSING; @@ -573,8 +575,8 @@ struct ipcp * ipcp_udp_create(char * ap_name, char * i_id) ops->ipcp_enroll = NULL; /* shim */ ops->ipcp_reg = NULL; /* shim */ ops->ipcp_unreg = NULL; /* shim */ - ops->ipcp_ap_reg = ipcp_udp_ap_reg; - ops->ipcp_ap_unreg = ipcp_udp_ap_unreg; + ops->ipcp_name_reg = ipcp_udp_name_reg; + ops->ipcp_name_unreg = ipcp_udp_name_unreg; ops->ipcp_flow_alloc = ipcp_udp_flow_alloc; ops->ipcp_flow_alloc_resp = ipcp_udp_flow_alloc_resp; ops->ipcp_flow_dealloc = ipcp_udp_flow_dealloc; diff --git a/src/ipcpd/shim-udp/tests/shim_udp_test.c b/src/ipcpd/shim-udp/tests/shim_udp_test.c index 427d0e1e..0fcf9f4d 100644 --- a/src/ipcpd/shim-udp/tests/shim_udp_test.c +++ b/src/ipcpd/shim-udp/tests/shim_udp_test.c @@ -68,21 +68,21 @@ int shim_udp_test(int argc, char ** argv) LOG_ERR("Could not bootstrap."); } - if(ipcp_udp_ap_reg("bogus ap", 1865)) { + if(ipcp_udp_name_reg("bogus name")) { LOG_ERR("Failed to register application."); shm_du_map_close(dum); exit(1); } - if (ipcp_udp_ap_unreg(1865)) { + if (ipcp_udp_name_unreg("bogus name")) { LOG_ERR("Failed to unregister application."); shm_du_map_close(dum); exit(1); } for (i = 0; i < 1000; ++i) { - sprintf (bogus, "bogus ap %4d", i); - if(ipcp_udp_ap_reg(bogus, i)) { + sprintf (bogus, "bogus name %4d", i); + if(ipcp_udp_name_reg(bogus)) { LOG_ERR("Failed to register application %s.", bogus); shm_du_map_close(dum); exit(1); @@ -90,8 +90,9 @@ int shim_udp_test(int argc, char ** argv) } for (i = 0; i < 1000; ++i) { - if(ipcp_udp_ap_unreg(i)) { - LOG_ERR("Failed to unregister application %d.", i); + sprintf (bogus, "bogus name %4d", i); + if(ipcp_udp_name_unreg(bogus)) { + LOG_ERR("Failed to unregister application %s.", bogus); shm_du_map_close(dum); exit(1); } |