From 0d789ed8d938cc342c8f2138280795a1d5a61e3d Mon Sep 17 00:00:00 2001 From: Sander Vrijders Date: Tue, 28 Jun 2016 16:11:19 +0200 Subject: lib, irmd, ipcpd: Change of IRM API This changes the IRM API after discussions with Dimitri. The register operation is now split into a bind and register operation. The same for unregister; unbind and unregister. PIDs are now used as the application instance name. A name for a PID is only provided for scriptability in bash. It is therefore also no longer passed down to the IPCP. Every operation on an IPCP through the IRM API has to use the PID. Quering of the PIDs by name is possible. The IRM tool has been updated to use this new API as well. A subcommand 'ipcp' has been added for operations that take effect on IPCPs only. Fixes #12 --- src/ipcpd/local/main.c | 29 +++++------------------------ 1 file changed, 5 insertions(+), 24 deletions(-) (limited to 'src/ipcpd/local') diff --git a/src/ipcpd/local/main.c b/src/ipcpd/local/main.c index 06e2b0a4..1f1cf839 100644 --- a/src/ipcpd/local/main.c +++ b/src/ipcpd/local/main.c @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #include #include @@ -67,7 +67,7 @@ struct ipcp * _ipcp; /* the shim needs access to these internals */ struct shim_ap_data { - instance_name_t * api; + pid_t api; struct shm_du_map * dum; struct bmp * fds; struct shm_ap_rbuff * rb; @@ -82,7 +82,7 @@ struct shim_ap_data { } * _ap_instance; -static int shim_ap_init(char * ap_name) +static int shim_ap_init() { int i; @@ -91,30 +91,16 @@ static int shim_ap_init(char * ap_name) return -1; } - _ap_instance->api = instance_name_create(); - if (_ap_instance->api == NULL) { - free(_ap_instance); - return -1; - } - - if (instance_name_init_from(_ap_instance->api, - ap_name, - getpid()) == NULL) { - instance_name_destroy(_ap_instance->api); - free(_ap_instance); - return -1; - } + _ap_instance->api = getpid(); _ap_instance->fds = bmp_create(AP_MAX_FLOWS, 0); if (_ap_instance->fds == NULL) { - instance_name_destroy(_ap_instance->api); free(_ap_instance); return -1; } _ap_instance->dum = shm_du_map_open(); if (_ap_instance->dum == NULL) { - instance_name_destroy(_ap_instance->api); bmp_destroy(_ap_instance->fds); free(_ap_instance); return -1; @@ -122,7 +108,6 @@ static int shim_ap_init(char * ap_name) _ap_instance->rb = shm_ap_rbuff_create(); if (_ap_instance->rb == NULL) { - instance_name_destroy(_ap_instance->api); shm_du_map_close(_ap_instance->dum); bmp_destroy(_ap_instance->fds); free(_ap_instance); @@ -153,8 +138,6 @@ void shim_ap_fini() if (_ipcp->state != IPCP_SHUTDOWN) LOG_WARN("Cleaning up AP while not in shutdown."); - if (_ap_instance->api != NULL) - instance_name_destroy(_ap_instance->api); if (_ap_instance->fds != NULL) bmp_destroy(_ap_instance->fds); if (_ap_instance->dum != NULL) @@ -592,8 +575,6 @@ static struct ipcp * ipcp_local_create() int main (int argc, char * argv[]) { - /* argument 1: pid of irmd ? */ - /* argument 2: ap name */ struct sigaction sig_act; sigset_t sigset; sigemptyset(&sigset); @@ -607,7 +588,7 @@ int main (int argc, char * argv[]) exit(1); } - if (shim_ap_init(argv[2]) < 0) + if (shim_ap_init() < 0) exit(1); /* store the process id of the irmd */ -- cgit v1.2.3 From 99d19307fae8f1370f52a62aee88fded624ad464 Mon Sep 17 00:00:00 2001 From: Sander Vrijders Date: Tue, 28 Jun 2016 16:38:03 +0200 Subject: lib, irmd, ipcpd: Change pid to api Changes the variable name as well to API instead of PID. --- include/ouroboros/ipcp.h | 30 ++--- include/ouroboros/sockets.h | 2 +- src/ipcpd/ipcp-ops.h | 4 +- src/ipcpd/ipcp.c | 6 +- src/ipcpd/local/main.c | 20 ++-- src/ipcpd/shim-eth-llc/main.c | 16 +-- src/ipcpd/shim-udp/main.c | 36 +++--- src/ipcpd/shim-udp/tests/shim_udp_test.c | 3 - src/irmd/main.c | 200 ++++++++++++++++--------------- src/lib/dev.c | 20 ++-- src/lib/ipcp.c | 86 ++++++------- src/lib/ipcpd_messages.proto | 2 +- src/lib/irm.c | 6 +- src/lib/irmd_messages.proto | 9 +- src/lib/shm_ap_rbuff.c | 14 +-- src/lib/shm_du_map.c | 10 +- src/lib/sockets.c | 18 +-- 17 files changed, 240 insertions(+), 242 deletions(-) (limited to 'src/ipcpd/local') diff --git a/include/ouroboros/ipcp.h b/include/ouroboros/ipcp.h index 0c0afbe7..f5657b64 100644 --- a/include/ouroboros/ipcp.h +++ b/include/ouroboros/ipcp.h @@ -34,55 +34,55 @@ struct ipcp; /* Returns the process id */ pid_t ipcp_create(enum ipcp_type ipcp_type); -int ipcp_destroy(pid_t pid); +int ipcp_destroy(pid_t api); -int ipcp_reg(pid_t pid, +int ipcp_reg(pid_t api, char ** difs, size_t difs_size); -int ipcp_unreg(pid_t pid, +int ipcp_unreg(pid_t api, char ** difs, size_t difs_size); -int ipcp_enroll(pid_t pid, +int ipcp_enroll(pid_t api, char * dif_name, char * n_1_dif); -int ipcp_bootstrap(pid_t pid, +int ipcp_bootstrap(pid_t api, dif_config_msg_t * conf); /* Flow related ops, these go from IRMd to IPCP */ -int ipcp_name_reg(pid_t pid, +int ipcp_name_reg(pid_t api, char * name); -int ipcp_name_unreg(pid_t pid, +int ipcp_name_unreg(pid_t api, char * name); -int ipcp_flow_alloc(pid_t pid, +int ipcp_flow_alloc(pid_t api, int port_id, - pid_t n_pid, + pid_t n_api, char * dst_name, char * src_ae_name, enum qos_cube qos); -int ipcp_flow_alloc_resp(pid_t pid, +int ipcp_flow_alloc_resp(pid_t api, int port_id, - pid_t n_pid, + pid_t n_api, int response); /* These operations go from the IPCP to the IRMd */ /* Returns the port_id */ -int ipcp_flow_req_arr(pid_t pid, +int ipcp_flow_req_arr(pid_t api, char * dst_name, char * src_ae_name); -int ipcp_flow_alloc_reply(pid_t pid, +int ipcp_flow_alloc_reply(pid_t api, int port_id, int response); /* * This operation can go both ways - * pid == 0 means the IRMd is the destination + * api == 0 means the IRMd is the destination */ -int ipcp_flow_dealloc(pid_t pid, +int ipcp_flow_dealloc(pid_t api, int port_id); diff --git a/include/ouroboros/sockets.h b/include/ouroboros/sockets.h index 0a215a76..ce7876b3 100644 --- a/include/ouroboros/sockets.h +++ b/include/ouroboros/sockets.h @@ -46,7 +46,7 @@ typedef IpcpMsg ipcp_msg_t; #define IPCP_MSG_BUF_SIZE IRM_MSG_BUF_SIZE /* Returns the full socket path of an IPCP */ -char * ipcp_sock_path(pid_t pid); +char * ipcp_sock_path(pid_t api); int server_socket_open(char * file_name); int client_socket_open(char * file_name); diff --git a/src/ipcpd/ipcp-ops.h b/src/ipcpd/ipcp-ops.h index 879ce8e2..40c331ec 100644 --- a/src/ipcpd/ipcp-ops.h +++ b/src/ipcpd/ipcp-ops.h @@ -38,12 +38,12 @@ struct ipcp_ops { size_t len); int (* ipcp_name_reg)(char * name); int (* ipcp_name_unreg)(char * name); - int (* ipcp_flow_alloc)(pid_t n_pid, + int (* ipcp_flow_alloc)(pid_t n_api, int port_id, char * dst_ap_name, char * src_ae_name, enum qos_cube qos); - int (* ipcp_flow_alloc_resp)(pid_t n_pid, + int (* ipcp_flow_alloc_resp)(pid_t n_api, int port_id, int response); int (* ipcp_flow_dealloc)(int port_id); diff --git a/src/ipcpd/ipcp.c b/src/ipcpd/ipcp.c index 54d1fad3..4acbffa2 100644 --- a/src/ipcpd/ipcp.c +++ b/src/ipcpd/ipcp.c @@ -50,7 +50,7 @@ int ipcp_arg_check(int argc, char * argv[]) if (argc != 2) return -1; - /* argument 1: pid of irmd */ + /* argument 1: api of irmd */ if (atoi(argv[1]) == 0) return -1; @@ -203,7 +203,7 @@ void * ipcp_main_loop(void * o) } ret_msg.has_result = true; ret_msg.result = - _ipcp->ops->ipcp_flow_alloc(msg->pid, + _ipcp->ops->ipcp_flow_alloc(msg->api, msg->port_id, msg->dst_name, msg->src_ae_name, @@ -216,7 +216,7 @@ void * ipcp_main_loop(void * o) } ret_msg.has_result = true; ret_msg.result = - _ipcp->ops->ipcp_flow_alloc_resp(msg->pid, + _ipcp->ops->ipcp_flow_alloc_resp(msg->api, msg->port_id, msg->result); break; diff --git a/src/ipcpd/local/main.c b/src/ipcpd/local/main.c index 1f1cf839..2120e4e8 100644 --- a/src/ipcpd/local/main.c +++ b/src/ipcpd/local/main.c @@ -50,7 +50,7 @@ #define shim_data(type) ((struct ipcp_local_data *) type->data) /* global for trapping signal */ -int irmd_pid; +int irmd_api; /* this IPCP's data */ #ifdef MAKE_CHECK @@ -226,7 +226,7 @@ void ipcp_sig_handler(int sig, siginfo_t * info, void * c) case SIGTERM: case SIGHUP: case SIGQUIT: - if (info->si_pid == irmd_pid) { + if (info->si_pid == irmd_api) { bool clean_threads = false; LOG_DBG("Terminating by order of %d. Bye.", info->si_pid); @@ -276,7 +276,7 @@ static int ipcp_local_bootstrap(struct dif_config * conf) pthread_rwlock_unlock(&_ipcp->state_lock); - LOG_DBG("Bootstrapped local IPCP with pid %d.", + LOG_DBG("Bootstrapped local IPCP with api %d.", getpid()); return 0; @@ -320,7 +320,7 @@ static int ipcp_local_name_unreg(char * name) return 0; } -static int ipcp_local_flow_alloc(pid_t n_pid, +static int ipcp_local_flow_alloc(pid_t n_api, int port_id, char * dst_name, char * src_ae_name, @@ -346,7 +346,7 @@ static int ipcp_local_flow_alloc(pid_t n_pid, return -1; /* -ENOTENROLLED */ } - rb = shm_ap_rbuff_open(n_pid); + rb = shm_ap_rbuff_open(n_api); if (rb == NULL) { pthread_rwlock_unlock(&_ipcp->state_lock); return -1; /* -ENORBUFF */ @@ -376,13 +376,13 @@ static int ipcp_local_flow_alloc(pid_t n_pid, pthread_rwlock_unlock(&_ap_instance->flows_lock); pthread_rwlock_unlock(&_ipcp->state_lock); LOG_ERR("Could not get port id from IRMd"); - /* shm_ap_rbuff_close(n_pid); */ + /* shm_ap_rbuff_close(n_api); */ return -1; } out_fd = bmp_allocate(_ap_instance->fds); if (!bmp_is_id_valid(_ap_instance->fds, out_fd)) { - /* shm_ap_rbuff_close(n_pid); */ + /* shm_ap_rbuff_close(n_api); */ pthread_rwlock_unlock(&_ap_instance->flows_lock); pthread_rwlock_unlock(&_ipcp->state_lock); return -1; /* -ENOMOREFDS */ @@ -403,7 +403,7 @@ static int ipcp_local_flow_alloc(pid_t n_pid, return 0; } -static int ipcp_local_flow_alloc_resp(pid_t n_pid, +static int ipcp_local_flow_alloc_resp(pid_t n_api, int port_id, int response) { @@ -436,7 +436,7 @@ static int ipcp_local_flow_alloc_resp(pid_t n_pid, return -1; } - rb = shm_ap_rbuff_open(n_pid); + rb = shm_ap_rbuff_open(n_api); if (rb == NULL) { LOG_ERR("Could not open N + 1 ringbuffer."); _ap_instance->flows[in_fd].state = FLOW_NULL; @@ -592,7 +592,7 @@ int main (int argc, char * argv[]) exit(1); /* store the process id of the irmd */ - irmd_pid = atoi(argv[1]); + irmd_api = atoi(argv[1]); /* init sig_act */ memset(&sig_act, 0, sizeof(sig_act)); diff --git a/src/ipcpd/shim-eth-llc/main.c b/src/ipcpd/shim-eth-llc/main.c index 6cb5c9cc..48b6391f 100644 --- a/src/ipcpd/shim-eth-llc/main.c +++ b/src/ipcpd/shim-eth-llc/main.c @@ -70,7 +70,7 @@ typedef ShimEthLlcMsg shim_eth_llc_msg_t; #define MAX_SAPS 64 /* global for trapping signal */ -int irmd_pid; +int irmd_api; struct ipcp * _ipcp; @@ -816,7 +816,7 @@ void ipcp_sig_handler(int sig, siginfo_t * info, void * c) case SIGINT: case SIGTERM: case SIGHUP: - if (info->si_pid == irmd_pid) { + if (info->si_pid == irmd_api) { bool clean_threads = false; LOG_DBG("Terminating by order of %d. Bye.", info->si_pid); @@ -988,7 +988,7 @@ static int eth_llc_ipcp_bootstrap(struct dif_config * conf) pthread_rwlock_unlock(&_ipcp->state_lock); - LOG_DBG("Bootstrapped shim IPCP over Ethernet with LLC with pid %d.", + LOG_DBG("Bootstrapped shim IPCP over Ethernet with LLC with api %d.", getpid()); return 0; @@ -1028,7 +1028,7 @@ static int eth_llc_ipcp_name_unreg(char * name) return 0; } -static int eth_llc_ipcp_flow_alloc(pid_t n_pid, +static int eth_llc_ipcp_flow_alloc(pid_t n_api, int port_id, char * dst_name, char * src_ae_name, @@ -1047,7 +1047,7 @@ static int eth_llc_ipcp_flow_alloc(pid_t n_pid, if (qos != QOS_CUBE_BE) LOG_DBGF("QoS requested. Ethernet LLC can't do that. For now."); - rb = shm_ap_rbuff_open(n_pid); + rb = shm_ap_rbuff_open(n_api); if (rb == NULL) return -1; /* -ENORBUFF */ @@ -1106,7 +1106,7 @@ static int eth_llc_ipcp_flow_alloc(pid_t n_pid, return index; } -static int eth_llc_ipcp_flow_alloc_resp(pid_t n_pid, +static int eth_llc_ipcp_flow_alloc_resp(pid_t n_api, int port_id, int response) { @@ -1132,7 +1132,7 @@ static int eth_llc_ipcp_flow_alloc_resp(pid_t n_pid, return -1; } - rb = shm_ap_rbuff_open(n_pid); + rb = shm_ap_rbuff_open(n_api); if (rb == NULL) { LOG_ERR("Could not open N + 1 ringbuffer."); ipcp_flow(index)->state = FLOW_NULL; @@ -1250,7 +1250,7 @@ int main(int argc, char * argv[]) } /* store the process id of the irmd */ - irmd_pid = atoi(argv[1]); + irmd_api = atoi(argv[1]); /* init sig_act */ memset(&sig_act, 0, sizeof(sig_act)); diff --git a/src/ipcpd/shim-udp/main.c b/src/ipcpd/shim-udp/main.c index 99b8aa7f..a28c262f 100644 --- a/src/ipcpd/shim-udp/main.c +++ b/src/ipcpd/shim-udp/main.c @@ -69,7 +69,7 @@ typedef ShimUdpMsg shim_udp_msg_t; _ipcp->data)->s_saddr.sin_addr.s_addr) /* global for trapping signal */ -int irmd_pid; +int irmd_api; /* this IPCP's data */ #ifdef MAKE_CHECK @@ -817,7 +817,7 @@ void ipcp_sig_handler(int sig, siginfo_t * info, void * c) case SIGINT: case SIGTERM: case SIGHUP: - if (info->si_pid == irmd_pid) { + if (info->si_pid == irmd_api) { bool clean_threads = false; LOG_DBG("Terminating by order of %d. Bye.", info->si_pid); @@ -947,7 +947,7 @@ static int ipcp_udp_bootstrap(struct dif_config * conf) pthread_rwlock_unlock(&_ipcp->state_lock); - LOG_DBG("Bootstrapped shim IPCP over UDP with pid %d.", + LOG_DBG("Bootstrapped shim IPCP over UDP with api %d.", getpid()); LOG_DBG("Bound to IP address %s.", ipstr); @@ -961,7 +961,7 @@ static int ipcp_udp_bootstrap(struct dif_config * conf) /* NOTE: Disgusted with this crap */ static int ddns_send(char * cmd) { - pid_t pid = 0; + pid_t api = 0; int wstatus; int pipe_fd[2]; char * argv[] = {NSUPDATE_EXEC, 0}; @@ -972,13 +972,13 @@ static int ddns_send(char * cmd) return -1; } - pid = fork(); - if (pid == -1) { + api = fork(); + if (api == -1) { LOG_ERR("Failed to fork."); return -1; } - if (pid == 0) { + if (api == 0) { close(pipe_fd[1]); dup2(pipe_fd[0], 0); execve(argv[0], &argv[0], envp); @@ -992,7 +992,7 @@ static int ddns_send(char * cmd) return -1; } - waitpid(pid, &wstatus, 0); + waitpid(api, &wstatus, 0); if (WIFEXITED(wstatus) == true && WEXITSTATUS(wstatus) == 0) LOG_DBG("Succesfully communicated with DNS server."); @@ -1005,7 +1005,7 @@ static int ddns_send(char * cmd) static uint32_t ddns_resolve(char * name, uint32_t dns_addr) { - pid_t pid = 0; + pid_t api = 0; int wstatus; int pipe_fd[2]; char dnsstr[INET_ADDRSTRLEN]; @@ -1026,13 +1026,13 @@ static uint32_t ddns_resolve(char * name, uint32_t dns_addr) return 0; } - pid = fork(); - if (pid == -1) { + api = fork(); + if (api == -1) { LOG_ERR("Failed to fork."); return 0; } - if (pid == 0) { + if (api == 0) { char * argv[] = {NSLOOKUP_EXEC, name, dnsstr, 0}; char * envp[] = {0}; @@ -1052,7 +1052,7 @@ static uint32_t ddns_resolve(char * name, uint32_t dns_addr) close(pipe_fd[0]); - waitpid(pid, &wstatus, 0); + waitpid(api, &wstatus, 0); if (WIFEXITED(wstatus) == true && WEXITSTATUS(wstatus) == 0) LOG_DBG("Succesfully communicated with nslookup."); @@ -1198,7 +1198,7 @@ static int ipcp_udp_name_unreg(char * name) return 0; } -static int ipcp_udp_flow_alloc(pid_t n_pid, +static int ipcp_udp_flow_alloc(pid_t n_api, int port_id, char * dst_name, char * src_ae_name, @@ -1228,7 +1228,7 @@ static int ipcp_udp_flow_alloc(pid_t n_pid, if (qos != QOS_CUBE_BE) LOG_DBG("QoS requested. UDP/IP can't do that."); - rb = shm_ap_rbuff_open(n_pid); + rb = shm_ap_rbuff_open(n_api); if (rb == NULL) return -1; /* -ENORBUFF */ @@ -1348,7 +1348,7 @@ static int ipcp_udp_flow_alloc(pid_t n_pid, return fd; } -static int ipcp_udp_flow_alloc_resp(pid_t n_pid, +static int ipcp_udp_flow_alloc_resp(pid_t n_api, int port_id, int response) { @@ -1389,7 +1389,7 @@ static int ipcp_udp_flow_alloc_resp(pid_t n_pid, return -1; } - rb = shm_ap_rbuff_open(n_pid); + rb = shm_ap_rbuff_open(n_api); if (rb == NULL) { LOG_ERR("Could not open N + 1 ringbuffer."); _ap_instance->flows[fd].state = FLOW_NULL; @@ -1576,7 +1576,7 @@ int main (int argc, char * argv[]) exit(1); /* store the process id of the irmd */ - irmd_pid = atoi(argv[1]); + irmd_api = atoi(argv[1]); /* init sig_act */ memset(&sig_act, 0, sizeof(sig_act)); diff --git a/src/ipcpd/shim-udp/tests/shim_udp_test.c b/src/ipcpd/shim-udp/tests/shim_udp_test.c index e5e8b32d..b222ac42 100644 --- a/src/ipcpd/shim-udp/tests/shim_udp_test.c +++ b/src/ipcpd/shim-udp/tests/shim_udp_test.c @@ -34,9 +34,6 @@ struct ipcp * _ipcp; int shim_udp_test(int argc, char ** argv) { - /* argument 1: pid of irmd ? */ - /* argument 2: ap name */ - /* argument 3: instance id */ struct shm_du_map * dum; char * ipcp_name = "test-shim-ipcp"; int i = 0; diff --git a/src/irmd/main.c b/src/irmd/main.c index 74105653..f6c27377 100644 --- a/src/irmd/main.c +++ b/src/irmd/main.c @@ -48,6 +48,8 @@ #include #include +#define API_INVALID 0 + #define IRMD_MAX_FLOWS 4096 #define IRMD_THREADPOOL_SIZE 3 @@ -90,22 +92,22 @@ enum reg_i_state { struct reg_instance { struct list_head next; - pid_t pid; + pid_t api; - /* the pid will block on this */ + /* the api will block on this */ enum reg_i_state state; pthread_cond_t wakeup; pthread_mutex_t mutex; }; -static struct reg_instance * reg_instance_create(pid_t pid) +static struct reg_instance * reg_instance_create(pid_t api) { struct reg_instance * i; i = malloc(sizeof(*i)); if (i == NULL) return NULL; - i->pid = pid; + i->api = api; i->state = REG_I_WAKE; pthread_mutex_init(&i->mutex, NULL); @@ -217,8 +219,8 @@ struct port_map_entry { int port_id; - pid_t n_pid; - pid_t n_1_pid; + pid_t n_api; + pid_t n_1_api; pthread_cond_t res_signal; pthread_mutex_t res_lock; @@ -237,7 +239,7 @@ struct irm { /* keep track of all flows in this processing system */ struct bmp * port_ids; - /* maps port_ids to pid pair */ + /* maps port_ids to api pair */ struct list_head port_map; pthread_rwlock_t flows_lock; @@ -257,8 +259,8 @@ static struct port_map_entry * port_map_entry_create() if (e == NULL) return NULL; - e->n_pid = 0; - e->n_1_pid = 0; + e->n_api = 0; + e->n_1_api = 0; e->port_id = 0; e->state = FLOW_NULL; @@ -316,7 +318,7 @@ static struct port_map_entry * get_port_map_entry(int port_id) return NULL; } -static struct port_map_entry * get_port_map_entry_n(pid_t n_pid) +static struct port_map_entry * get_port_map_entry_n(pid_t n_api) { struct list_head * pos = NULL; @@ -324,7 +326,7 @@ static struct port_map_entry * get_port_map_entry_n(pid_t n_pid) struct port_map_entry * e = list_entry(pos, struct port_map_entry, next); - if (e->n_pid == n_pid) + if (e->n_api == n_api) return e; } @@ -359,7 +361,7 @@ static void ipcp_entry_destroy(struct ipcp_entry * e) free(e); } -static struct ipcp_entry * get_ipcp_entry_by_pid(pid_t api) +static struct ipcp_entry * get_ipcp_entry_by_api(pid_t api) { struct list_head * pos = NULL; @@ -539,7 +541,7 @@ static struct reg_ap_name * reg_entry_get_ap_name(struct reg_entry * e, } static struct reg_instance * reg_entry_get_reg_instance(struct reg_entry * e, - pid_t pid) + pid_t api) { struct list_head * pos = NULL; @@ -547,7 +549,7 @@ static struct reg_instance * reg_entry_get_reg_instance(struct reg_entry * e, struct reg_instance * r = list_entry(pos, struct reg_instance, next); - if (r->pid == pid) + if (r->api == api) return r; } @@ -606,7 +608,7 @@ static struct reg_entry * get_reg_entry_by_ap_name(char * ap_name) return NULL; } -static struct reg_entry * get_reg_entry_by_ap_id(pid_t pid) +static struct reg_entry * get_reg_entry_by_ap_id(pid_t api) { struct list_head * pos = NULL; @@ -619,7 +621,7 @@ static struct reg_entry * get_reg_entry_by_ap_id(pid_t pid) struct reg_instance * r = list_entry(p, struct reg_instance, next); - if (r->pid == pid) + if (r->api == api) return e; } } @@ -747,12 +749,12 @@ static int registry_remove_ap_auto(char * name, #endif static struct reg_instance * registry_add_ap_instance(char * name, - pid_t pid) + pid_t api) { struct reg_entry * e = NULL; struct reg_instance * i = NULL; - if (name == NULL || pid == 0) + if (name == NULL || api == 0) return NULL; e = get_reg_entry_by_name(name); @@ -761,12 +763,12 @@ static struct reg_instance * registry_add_ap_instance(char * name, return NULL; } - if (pid == 0) { - LOG_DBG("Invalid pid."); + if (api == API_INVALID) { + LOG_DBG("Invalid api."); return NULL; } - if (reg_entry_has_api(e, pid)) { + if (reg_entry_has_api(e, api)) { LOG_DBG("Instance already registered with this name."); return NULL; } @@ -776,7 +778,7 @@ static struct reg_instance * registry_add_ap_instance(char * name, return NULL; } - i = reg_instance_create(pid); + i = reg_instance_create(api); if (i == NULL) { LOG_DBG("Failed to create reg_instance"); return NULL; @@ -792,12 +794,12 @@ static struct reg_instance * registry_add_ap_instance(char * name, return i; } -static int registry_remove_ap_instance(char * name, pid_t pid) +static int registry_remove_ap_instance(char * name, pid_t api) { struct reg_entry * e = NULL; struct reg_instance * i = NULL; - if (name == NULL || pid == 0) + if (name == NULL || api == 0) return -1; e = get_reg_entry_by_name(name); @@ -806,10 +808,10 @@ static int registry_remove_ap_instance(char * name, pid_t pid) return -1; } - i = reg_entry_get_reg_instance(e, pid); + i = reg_entry_get_reg_instance(e, api); if (i == NULL) { LOG_DBG("Instance %d is not accepting flows for %s.", - pid, name); + api, name); return -1; } @@ -838,7 +840,7 @@ static pid_t registry_resolve_api(struct reg_entry * e) list_for_each(pos, &e->ap_instances) { struct reg_instance * r = list_entry(pos, struct reg_instance, next); - return r->pid; + return r->api; } return 0; @@ -873,7 +875,7 @@ static void registry_del_name(char * name) static pid_t create_ipcp(char * name, enum ipcp_type ipcp_type) { - pid_t pid; + pid_t api; struct ipcp_entry * tmp = NULL; pthread_rwlock_rdlock(&instance->state_lock); @@ -883,8 +885,8 @@ static pid_t create_ipcp(char * name, return 0; } - pid = ipcp_create(ipcp_type); - if (pid == -1) { + api = ipcp_create(ipcp_type); + if (api == -1) { pthread_rwlock_unlock(&instance->state_lock); LOG_ERR("Failed to create IPCP."); return -1; @@ -898,7 +900,7 @@ static pid_t create_ipcp(char * name, INIT_LIST_HEAD(&tmp->next); - tmp->api = pid; + tmp->api = api; tmp->name = strdup(name); if (tmp->name == NULL) { ipcp_entry_destroy(tmp); @@ -915,9 +917,9 @@ static pid_t create_ipcp(char * name, pthread_rwlock_unlock(&instance->reg_lock); pthread_rwlock_unlock(&instance->state_lock); - LOG_INFO("Created IPCP %d.", pid); + LOG_INFO("Created IPCP %d.", api); - return pid; + return api; } static int destroy_ipcp(pid_t api) @@ -962,7 +964,7 @@ static int bootstrap_ipcp(pid_t api, pthread_rwlock_wrlock(&instance->reg_lock); - entry = get_ipcp_entry_by_pid(api); + entry = get_ipcp_entry_by_api(api); if (entry == NULL) { pthread_rwlock_unlock(&instance->reg_lock); pthread_rwlock_unlock(&instance->state_lock); @@ -1012,7 +1014,7 @@ static int enroll_ipcp(pid_t api, pthread_rwlock_rdlock(&instance->reg_lock); - entry = get_ipcp_entry_by_pid(api); + entry = get_ipcp_entry_by_api(api); if (entry == NULL) { pthread_rwlock_unlock(&instance->reg_lock); pthread_rwlock_unlock(&instance->state_lock); @@ -1142,7 +1144,7 @@ static int unbind_name(char * name, } static ssize_t list_ipcps(char * name, - pid_t ** pids) + pid_t ** apis) { struct list_head * pos = NULL; ssize_t count = 0; @@ -1157,8 +1159,8 @@ static ssize_t list_ipcps(char * name, } } - *pids = malloc(count * sizeof(pid_t)); - if (*pids == NULL) { + *apis = malloc(count * sizeof(pid_t)); + if (*apis == NULL) { return -1; } @@ -1167,7 +1169,7 @@ static ssize_t list_ipcps(char * name, list_entry(pos, struct ipcp_entry, next); if (wildcard_match(name, tmp->name) == 0) { - (*pids)[i++] = tmp->api; + (*apis)[i++] = tmp->api; } } @@ -1287,7 +1289,7 @@ static int ap_unreg(char * name, return ret; } -static struct port_map_entry * flow_accept(pid_t pid, +static struct port_map_entry * flow_accept(pid_t api, char * srv_ap_name, char ** dst_ae_name) { @@ -1312,16 +1314,16 @@ static struct port_map_entry * flow_accept(pid_t pid, return NULL; } - if (!reg_entry_has_api(rne, pid)) { - rgi = registry_add_ap_instance(rne->name, pid); + if (!reg_entry_has_api(rne, api)) { + rgi = registry_add_ap_instance(rne->name, api); if (rgi == NULL) { pthread_rwlock_unlock(&instance->reg_lock); pthread_rwlock_unlock(&instance->state_lock); LOG_ERR("Failed to register instance %d with %s.", - pid,srv_ap_name); + api,srv_ap_name); return NULL; } - LOG_INFO("New instance (%d) of %s added.", pid, srv_ap_name); + LOG_INFO("New instance (%d) of %s added.", api, srv_ap_name); } pthread_rwlock_unlock(&instance->reg_lock); @@ -1345,7 +1347,7 @@ static struct port_map_entry * flow_accept(pid_t pid, pthread_rwlock_rdlock(&instance->flows_lock); - pme = get_port_map_entry_n(pid); + pme = get_port_map_entry_n(api); if (pme == NULL) { pthread_rwlock_unlock(&instance->flows_lock); pthread_rwlock_unlock(&instance->state_lock); @@ -1364,7 +1366,7 @@ static struct port_map_entry * flow_accept(pid_t pid, return pme; } -static int flow_alloc_resp(pid_t n_pid, +static int flow_alloc_resp(pid_t n_api, int port_id, int response) { @@ -1381,7 +1383,7 @@ static int flow_alloc_resp(pid_t n_pid, pthread_rwlock_wrlock(&instance->reg_lock); - rne = get_reg_entry_by_ap_id(n_pid); + rne = get_reg_entry_by_ap_id(n_api); if (rne == NULL) { pthread_rwlock_unlock(&instance->reg_lock); pthread_rwlock_unlock(&instance->state_lock); @@ -1397,7 +1399,7 @@ static int flow_alloc_resp(pid_t n_pid, pthread_mutex_lock(&rne->state_lock); - registry_remove_ap_instance(rne->name, n_pid); + registry_remove_ap_instance(rne->name, n_api); pthread_mutex_unlock(&rne->state_lock); @@ -1416,9 +1418,9 @@ static int flow_alloc_resp(pid_t n_pid, pme->state = FLOW_ALLOCATED; pthread_rwlock_unlock(&instance->flows_lock); - ret = ipcp_flow_alloc_resp(pme->n_1_pid, + ret = ipcp_flow_alloc_resp(pme->n_1_api, port_id, - pme->n_pid, + pme->n_api, response); } @@ -1427,7 +1429,7 @@ static int flow_alloc_resp(pid_t n_pid, return ret; } -static struct port_map_entry * flow_alloc(pid_t pid, +static struct port_map_entry * flow_alloc(pid_t api, char * dst_name, char * src_ae_name, struct qos_spec * qos) @@ -1452,7 +1454,7 @@ static struct port_map_entry * flow_alloc(pid_t pid, return NULL; } - pme->n_pid = pid; + pme->n_api = api; pme->state = FLOW_PENDING; if (clock_gettime(CLOCK_MONOTONIC, &pme->t0) < 0) LOG_WARN("Failed to set timestamp."); @@ -1474,7 +1476,7 @@ static struct port_map_entry * flow_alloc(pid_t pid, pthread_rwlock_wrlock(&instance->flows_lock); pme->port_id = bmp_allocate(instance->port_ids); - pme->n_1_pid = ipcp; + pme->n_1_api = ipcp; list_add(&pme->next, &instance->port_map); @@ -1483,7 +1485,7 @@ static struct port_map_entry * flow_alloc(pid_t pid, if (ipcp_flow_alloc(ipcp, pme->port_id, - pme->n_pid, + pme->n_api, dst_name, src_ae_name, QOS_CUBE_BE) < 0) { @@ -1578,7 +1580,7 @@ static int flow_alloc_res(int port_id) static int flow_dealloc(int port_id) { - pid_t n_1_pid; + pid_t n_1_api; int ret = 0; struct port_map_entry * e = NULL; @@ -1594,13 +1596,13 @@ static int flow_dealloc(int port_id) return 0; } - n_1_pid = e->n_1_pid; + n_1_api = e->n_1_api; list_del(&e->next); pthread_rwlock_unlock(&instance->flows_lock); - ret = ipcp_flow_dealloc(n_1_pid, port_id); + ret = ipcp_flow_dealloc(n_1_api, port_id); pthread_rwlock_unlock(&instance->state_lock); @@ -1611,16 +1613,16 @@ static int flow_dealloc(int port_id) static int auto_execute(char ** argv) { - pid_t pid; + pid_t api; LOG_INFO("Executing %s.", argv[0]); - pid = fork(); - if (pid == -1) { + api = fork(); + if (api == -1) { LOG_ERR("Failed to fork"); - return pid; + return api; } - if (pid != 0) { - return pid; + if (api != 0) { + return api; } execv(argv[0], argv); @@ -1630,7 +1632,7 @@ static int auto_execute(char ** argv) exit(EXIT_FAILURE); } -static struct port_map_entry * flow_req_arr(pid_t pid, +static struct port_map_entry * flow_req_arr(pid_t api, char * dst_name, char * ae_name) { @@ -1646,7 +1648,7 @@ static struct port_map_entry * flow_req_arr(pid_t pid, } pme->state = FLOW_PENDING; - pme->n_1_pid = pid; + pme->n_1_api = api; if (clock_gettime(CLOCK_MONOTONIC, &pme->t0) < 0) LOG_WARN("Failed to set timestamp."); @@ -1696,11 +1698,11 @@ static struct port_map_entry * flow_req_arr(pid_t pid, case REG_NAME_FLOW_ACCEPT: pthread_mutex_unlock(&rne->state_lock); - pme->n_pid = registry_resolve_api(rne); - if(pme->n_pid == 0) { + pme->n_api = registry_resolve_api(rne); + if(pme->n_api == 0) { pthread_rwlock_unlock(&instance->reg_lock); pthread_rwlock_unlock(&instance->state_lock); - LOG_ERR("Invalid pid returned."); + LOG_ERR("Invalid api returned."); return NULL; } @@ -1728,7 +1730,7 @@ static struct port_map_entry * flow_req_arr(pid_t pid, rne->state = REG_NAME_FLOW_ARRIVED; - reg_instance_wake(reg_entry_get_reg_instance(rne, pme->n_pid)); + reg_instance_wake(reg_entry_get_reg_instance(rne, pme->n_api)); pthread_mutex_unlock(&rne->state_lock); @@ -1933,19 +1935,19 @@ void * irm_flow_cleaner() pthread_mutex_unlock(&e->res_lock); - if (kill(e->n_pid, 0) < 0) { + if (kill(e->n_api, 0) < 0) { bmp_release(instance->port_ids, e->port_id); list_del(&e->next); LOG_INFO("Process %d gone, %d deallocated.", - e->n_pid, e->port_id); - ipcp_flow_dealloc(e->n_1_pid, e->port_id); + e->n_api, e->port_id); + ipcp_flow_dealloc(e->n_1_api, e->port_id); port_map_entry_destroy(e); } - if (kill(e->n_1_pid, 0) < 0) { + if (kill(e->n_1_api, 0) < 0) { list_del(&e->next); LOG_ERR("IPCP %d gone, flow %d removed.", - e->n_1_pid, e->port_id); + e->n_1_api, e->port_id); port_map_entry_destroy(e); } } @@ -1962,12 +1964,12 @@ void * irm_flow_cleaner() list_entry(pos2, struct reg_instance, next); - if (kill(r->pid, 0) < 0) { + if (kill(r->api, 0) < 0) { LOG_INFO("Process %d gone, " "instance deleted.", - r->pid); + r->api); registry_remove_ap_instance(e->name, - r->pid); + r->api); } } } @@ -1995,7 +1997,7 @@ void * mainloop() buffer_t buffer; irm_msg_t ret_msg = IRM_MSG__INIT; struct port_map_entry * e = NULL; - pid_t * pids = NULL; + pid_t * apis = NULL; ret_msg.code = IRM_MSG_CODE__IRM_REPLY; @@ -2055,9 +2057,9 @@ void * mainloop() msg->opts); break; case IRM_MSG_CODE__IRM_LIST_IPCPS: - ret_msg.n_pids = list_ipcps(msg->dst_name, - &pids); - ret_msg.pids = pids; + ret_msg.n_apis = list_ipcps(msg->dst_name, + &apis); + ret_msg.apis = apis; ret_msg.has_result = true; break; case IRM_MSG_CODE__IRM_REG: @@ -2073,7 +2075,7 @@ void * mainloop() msg->n_dif_name); break; case IRM_MSG_CODE__IRM_FLOW_ACCEPT: - e = flow_accept(msg->pid, + e = flow_accept(msg->api, msg->ap_name, &ret_msg.ae_name); @@ -2082,17 +2084,17 @@ void * mainloop() ret_msg.has_port_id = true; ret_msg.port_id = e->port_id; - ret_msg.has_pid = true; - ret_msg.pid = e->n_1_pid; + ret_msg.has_api = true; + ret_msg.api = e->n_1_api; break; case IRM_MSG_CODE__IRM_FLOW_ALLOC_RESP: ret_msg.has_result = true; - ret_msg.result = flow_alloc_resp(msg->pid, + ret_msg.result = flow_alloc_resp(msg->api, msg->port_id, msg->response); break; case IRM_MSG_CODE__IRM_FLOW_ALLOC: - e = flow_alloc(msg->pid, + e = flow_alloc(msg->api, msg->dst_name, msg->ae_name, NULL); @@ -2101,8 +2103,8 @@ void * mainloop() ret_msg.has_port_id = true; ret_msg.port_id = e->port_id; - ret_msg.has_pid = true; - ret_msg.pid = e->n_1_pid; + ret_msg.has_api = true; + ret_msg.api = e->n_1_api; break; case IRM_MSG_CODE__IRM_FLOW_ALLOC_RES: ret_msg.has_result = true; @@ -2113,7 +2115,7 @@ void * mainloop() ret_msg.result = flow_dealloc(msg->port_id); break; case IRM_MSG_CODE__IPCP_FLOW_REQ_ARR: - e = flow_req_arr(msg->pid, + e = flow_req_arr(msg->api, msg->dst_name, msg->ae_name); if (e == NULL) @@ -2121,8 +2123,8 @@ void * mainloop() ret_msg.has_port_id = true; ret_msg.port_id = e->port_id; - ret_msg.has_pid = true; - ret_msg.pid = e->n_pid; + ret_msg.has_api = true; + ret_msg.api = e->n_api; break; case IRM_MSG_CODE__IPCP_FLOW_ALLOC_REPLY: ret_msg.has_result = true; @@ -2143,16 +2145,16 @@ void * mainloop() buffer.size = irm_msg__get_packed_size(&ret_msg); if (buffer.size == 0) { LOG_ERR("Failed to send reply message."); - if (pids != NULL) - free(pids); + if (apis != NULL) + free(apis); close(cli_sockfd); continue; } buffer.data = malloc(buffer.size); if (buffer.data == NULL) { - if (pids != NULL) - free(pids); + if (apis != NULL) + free(apis); close(cli_sockfd); continue; } @@ -2161,14 +2163,14 @@ void * mainloop() if (write(cli_sockfd, buffer.data, buffer.size) == -1) { free(buffer.data); - if (pids != NULL) - free(pids); + if (apis != NULL) + free(apis); close(cli_sockfd); continue; } - if (pids != NULL) - free(pids); + if (apis != NULL) + free(apis); free(buffer.data); close(cli_sockfd); diff --git a/src/lib/dev.c b/src/lib/dev.c index c6f25cdf..ac995b2d 100644 --- a/src/lib/dev.c +++ b/src/lib/dev.c @@ -148,12 +148,12 @@ int flow_accept(char ** ae_name) int cfd = -1; msg.code = IRM_MSG_CODE__IRM_FLOW_ACCEPT; - msg.has_pid = true; + msg.has_api = true; pthread_rwlock_rdlock(&_ap_instance->data_lock); msg.ap_name = _ap_instance->ap_name; - msg.pid = _ap_instance->api; + msg.api = _ap_instance->api; pthread_rwlock_unlock(&_ap_instance->data_lock); @@ -162,7 +162,7 @@ int flow_accept(char ** ae_name) return -1; } - if (!recv_msg->has_pid || !recv_msg->has_port_id) { + if (!recv_msg->has_api || !recv_msg->has_port_id) { irm_msg__free_unpacked(recv_msg, NULL); return -1; } @@ -178,7 +178,7 @@ int flow_accept(char ** ae_name) return -1; } - _ap_instance->flows[cfd].rb = shm_ap_rbuff_open(recv_msg->pid); + _ap_instance->flows[cfd].rb = shm_ap_rbuff_open(recv_msg->api); if (_ap_instance->flows[cfd].rb == NULL) { bmp_release(_ap_instance->fds, cfd); pthread_rwlock_unlock(&_ap_instance->flows_lock); @@ -221,8 +221,8 @@ int flow_alloc_resp(int fd, return -EBADF; msg.code = IRM_MSG_CODE__IRM_FLOW_ALLOC_RESP; - msg.has_pid = true; - msg.pid = _ap_instance->api; + msg.has_api = true; + msg.api = _ap_instance->api; msg.has_port_id = true; pthread_rwlock_rdlock(&_ap_instance->data_lock); @@ -279,11 +279,11 @@ int flow_alloc(char * dst_name, msg.code = IRM_MSG_CODE__IRM_FLOW_ALLOC; msg.dst_name = dst_name; msg.ae_name = src_ae_name; - msg.has_pid = true; + msg.has_api = true; pthread_rwlock_rdlock(&_ap_instance->data_lock); - msg.pid = _ap_instance->api; + msg.api = _ap_instance->api; pthread_rwlock_unlock(&_ap_instance->data_lock); @@ -292,7 +292,7 @@ int flow_alloc(char * dst_name, return -1; } - if (!recv_msg->has_pid || !recv_msg->has_port_id) { + if (!recv_msg->has_api || !recv_msg->has_port_id) { irm_msg__free_unpacked(recv_msg, NULL); return -1; } @@ -308,7 +308,7 @@ int flow_alloc(char * dst_name, return -1; } - _ap_instance->flows[fd].rb = shm_ap_rbuff_open(recv_msg->pid); + _ap_instance->flows[fd].rb = shm_ap_rbuff_open(recv_msg->api); if (_ap_instance->flows[fd].rb == NULL) { bmp_release(_ap_instance->fds, fd); pthread_rwlock_unlock(&_ap_instance->flows_lock); diff --git a/src/lib/ipcp.c b/src/lib/ipcp.c index 70f73e0e..2b6b6825 100644 --- a/src/lib/ipcp.c +++ b/src/lib/ipcp.c @@ -35,7 +35,7 @@ #include #include -static ipcp_msg_t * send_recv_ipcp_msg(pid_t pid, +static ipcp_msg_t * send_recv_ipcp_msg(pid_t api, ipcp_msg_t * msg) { int sockfd = 0; @@ -44,7 +44,7 @@ static ipcp_msg_t * send_recv_ipcp_msg(pid_t pid, ssize_t count = 0; ipcp_msg_t * recv_msg = NULL; - sock_path = ipcp_sock_path(pid); + sock_path = ipcp_sock_path(api); if (sock_path == NULL) return NULL; @@ -101,23 +101,23 @@ static ipcp_msg_t * send_recv_ipcp_msg(pid_t pid, pid_t ipcp_create(enum ipcp_type ipcp_type) { - pid_t pid = 0; - char irmd_pid[10]; + pid_t api = 0; + char irmd_api[10]; size_t len = 0; char * ipcp_dir = "/sbin/"; char * full_name = NULL; char * exec_name = NULL; - sprintf(irmd_pid, "%u", getpid()); + sprintf(irmd_api, "%u", getpid()); - pid = fork(); - if (pid == -1) { + api = fork(); + if (api == -1) { LOG_ERR("Failed to fork"); - return pid; + return api; } - if (pid != 0) { - return pid; + if (api != 0) { + return api; } if (ipcp_type == IPCP_NORMAL) @@ -148,7 +148,7 @@ pid_t ipcp_create(enum ipcp_type ipcp_type) full_name[len] = '\0'; char * argv[] = {full_name, - irmd_pid, + irmd_api, 0}; char * envp[] = {0}; @@ -162,16 +162,16 @@ pid_t ipcp_create(enum ipcp_type ipcp_type) exit(EXIT_FAILURE); } -int ipcp_destroy(pid_t pid) +int ipcp_destroy(pid_t api) { int status; - if (kill(pid, SIGTERM)) { + if (kill(api, SIGTERM)) { LOG_ERR("Failed to destroy IPCP"); return -1; } - if (waitpid(pid, &status, 0) < 0) { + if (waitpid(api, &status, 0) < 0) { LOG_ERR("Failed to destroy IPCP"); return -1; } @@ -179,7 +179,7 @@ int ipcp_destroy(pid_t pid) return 0; } -int ipcp_reg(pid_t pid, +int ipcp_reg(pid_t api, char ** dif_names, size_t len) { @@ -196,7 +196,7 @@ int ipcp_reg(pid_t pid, msg.dif_names = dif_names; msg.len = len; - recv_msg = send_recv_ipcp_msg(pid, &msg); + recv_msg = send_recv_ipcp_msg(api, &msg); if (recv_msg == NULL) return -1; @@ -211,7 +211,7 @@ int ipcp_reg(pid_t pid, return ret; } -int ipcp_unreg(pid_t pid, +int ipcp_unreg(pid_t api, char ** dif_names, size_t len) { @@ -228,7 +228,7 @@ int ipcp_unreg(pid_t pid, msg.dif_names = dif_names; msg.len = len; - recv_msg = send_recv_ipcp_msg(pid, &msg); + recv_msg = send_recv_ipcp_msg(api, &msg); if (recv_msg == NULL) return -1; @@ -244,7 +244,7 @@ int ipcp_unreg(pid_t pid, } -int ipcp_bootstrap(pid_t pid, +int ipcp_bootstrap(pid_t api, dif_config_msg_t * conf) { ipcp_msg_t msg = IPCP_MSG__INIT; @@ -257,7 +257,7 @@ int ipcp_bootstrap(pid_t pid, msg.code = IPCP_MSG_CODE__IPCP_BOOTSTRAP; msg.conf = conf; - recv_msg = send_recv_ipcp_msg(pid, &msg); + recv_msg = send_recv_ipcp_msg(api, &msg); if (recv_msg == NULL) return -1; @@ -272,7 +272,7 @@ int ipcp_bootstrap(pid_t pid, return ret; } -int ipcp_enroll(pid_t pid, +int ipcp_enroll(pid_t api, char * dif_name, char * n_1_dif) { @@ -287,7 +287,7 @@ int ipcp_enroll(pid_t pid, msg.dif_name = dif_name; msg.n_1_dif = n_1_dif; - recv_msg = send_recv_ipcp_msg(pid, &msg); + recv_msg = send_recv_ipcp_msg(api, &msg); if (recv_msg == NULL) { return -1; } @@ -303,7 +303,7 @@ int ipcp_enroll(pid_t pid, return ret; } -int ipcp_name_reg(pid_t pid, +int ipcp_name_reg(pid_t api, char * name) { ipcp_msg_t msg = IPCP_MSG__INIT; @@ -316,7 +316,7 @@ int ipcp_name_reg(pid_t pid, msg.code = IPCP_MSG_CODE__IPCP_NAME_REG; msg.name = name; - recv_msg = send_recv_ipcp_msg(pid, &msg); + recv_msg = send_recv_ipcp_msg(api, &msg); if (recv_msg == NULL) return -1; @@ -331,7 +331,7 @@ int ipcp_name_reg(pid_t pid, return ret; } -int ipcp_name_unreg(pid_t pid, +int ipcp_name_unreg(pid_t api, char * name) { ipcp_msg_t msg = IPCP_MSG__INIT; @@ -341,7 +341,7 @@ int ipcp_name_unreg(pid_t pid, msg.code = IPCP_MSG_CODE__IPCP_NAME_UNREG; msg.name = name; - recv_msg = send_recv_ipcp_msg(pid, &msg); + recv_msg = send_recv_ipcp_msg(api, &msg); if (recv_msg == NULL) return -1; @@ -356,9 +356,9 @@ int ipcp_name_unreg(pid_t pid, return ret; } -int ipcp_flow_alloc(pid_t pid, +int ipcp_flow_alloc(pid_t api, int port_id, - pid_t n_pid, + pid_t n_api, char * dst_name, char * src_ae_name, enum qos_cube qos) @@ -373,14 +373,14 @@ int ipcp_flow_alloc(pid_t pid, msg.code = IPCP_MSG_CODE__IPCP_FLOW_ALLOC; msg.has_port_id = true; msg.port_id = port_id; - msg.has_pid = true; - msg.pid = n_pid; + msg.has_api = true; + msg.api = n_api; msg.src_ae_name = src_ae_name; msg.dst_name = dst_name; msg.has_qos_cube = true; msg.qos_cube = qos; - recv_msg = send_recv_ipcp_msg(pid, &msg); + recv_msg = send_recv_ipcp_msg(api, &msg); if (recv_msg == NULL) return -1; @@ -395,9 +395,9 @@ int ipcp_flow_alloc(pid_t pid, return ret; } -int ipcp_flow_alloc_resp(pid_t pid, +int ipcp_flow_alloc_resp(pid_t api, int port_id, - pid_t n_pid, + pid_t n_api, int response) { ipcp_msg_t msg = IPCP_MSG__INIT; @@ -407,12 +407,12 @@ int ipcp_flow_alloc_resp(pid_t pid, msg.code = IPCP_MSG_CODE__IPCP_FLOW_ALLOC_RESP; msg.has_port_id = true; msg.port_id = port_id; - msg.has_pid = true; - msg.pid = n_pid; + msg.has_api = true; + msg.api = n_api; msg.has_response = true; msg.response = response; - recv_msg = send_recv_ipcp_msg(pid, &msg); + recv_msg = send_recv_ipcp_msg(api, &msg); if (recv_msg == NULL) return -1; @@ -427,7 +427,7 @@ int ipcp_flow_alloc_resp(pid_t pid, return ret; } -int ipcp_flow_req_arr(pid_t pid, +int ipcp_flow_req_arr(pid_t api, char * dst_name, char * src_ae_name) { @@ -439,8 +439,8 @@ int ipcp_flow_req_arr(pid_t pid, return -EINVAL; msg.code = IRM_MSG_CODE__IPCP_FLOW_REQ_ARR; - msg.has_pid = true; - msg.pid = pid; + msg.has_api = true; + msg.api = api; msg.dst_name = dst_name; msg.ae_name = src_ae_name; @@ -459,7 +459,7 @@ int ipcp_flow_req_arr(pid_t pid, return port_id; } -int ipcp_flow_alloc_reply(pid_t pid, +int ipcp_flow_alloc_reply(pid_t api, int port_id, int response) { @@ -489,10 +489,10 @@ int ipcp_flow_alloc_reply(pid_t pid, } -int ipcp_flow_dealloc(pid_t pid, +int ipcp_flow_dealloc(pid_t api, int port_id) { - if (pid != 0) { + if (api != 0) { ipcp_msg_t msg = IPCP_MSG__INIT; ipcp_msg_t * recv_msg = NULL; int ret = -1; @@ -501,7 +501,7 @@ int ipcp_flow_dealloc(pid_t pid, msg.has_port_id = true; msg.port_id = port_id; - recv_msg = send_recv_ipcp_msg(pid, &msg); + recv_msg = send_recv_ipcp_msg(api, &msg); if (recv_msg == NULL) return 0; diff --git a/src/lib/ipcpd_messages.proto b/src/lib/ipcpd_messages.proto index 9eb5707c..f9e0f972 100644 --- a/src/lib/ipcpd_messages.proto +++ b/src/lib/ipcpd_messages.proto @@ -27,7 +27,7 @@ message ipcp_msg { optional sint32 qos_cube = 11; optional dif_config_msg conf = 12; optional sint32 fd = 13; - optional sint32 pid = 14; + optional sint32 api = 14; optional sint32 response = 15; optional sint32 result = 16; }; diff --git a/src/lib/irm.c b/src/lib/irm.c index e3902469..6b296258 100644 --- a/src/lib/irm.c +++ b/src/lib/irm.c @@ -177,12 +177,12 @@ ssize_t irm_list_ipcps(char * name, return -1; } - if (recv_msg->pids == NULL) { + if (recv_msg->apis == NULL) { irm_msg__free_unpacked(recv_msg, NULL); return -1; } - nr = recv_msg->n_pids; + nr = recv_msg->n_apis; *apis = malloc(nr * sizeof(pid_t)); if (*apis == NULL) { irm_msg__free_unpacked(recv_msg, NULL); @@ -190,7 +190,7 @@ ssize_t irm_list_ipcps(char * name, } for (i = 0; i < nr; i++) { - (*apis)[i] = recv_msg->pids[i]; + (*apis)[i] = recv_msg->apis[i]; } irm_msg__free_unpacked(recv_msg, NULL); diff --git a/src/lib/irmd_messages.proto b/src/lib/irmd_messages.proto index ab09f0db..fa2ca258 100644 --- a/src/lib/irmd_messages.proto +++ b/src/lib/irmd_messages.proto @@ -54,9 +54,8 @@ message irm_msg { optional sint32 response = 8; optional string dst_name = 9; optional sint32 port_id = 10; - optional int32 pid = 11; - optional dif_config_msg conf = 12; - optional uint32 opts = 13; - repeated int32 pids = 14; - optional sint32 result = 15; + optional dif_config_msg conf = 11; + optional uint32 opts = 12; + repeated int32 apis = 13; + optional sint32 result = 14; }; diff --git a/src/lib/shm_ap_rbuff.c b/src/lib/shm_ap_rbuff.c index 6ee2936c..69e96c40 100644 --- a/src/lib/shm_ap_rbuff.c +++ b/src/lib/shm_ap_rbuff.c @@ -55,7 +55,7 @@ struct shm_ap_rbuff { size_t * ptr_tail; /* start of ringbuffer tail */ pthread_mutex_t * shm_mutex; /* lock all free space in shm */ pthread_cond_t * work; /* threads will wait for a signal */ - pid_t pid; /* pid to which this rb belongs */ + pid_t api; /* api to which this rb belongs */ int fd; }; @@ -138,19 +138,19 @@ struct shm_ap_rbuff * shm_ap_rbuff_create() *rb->ptr_tail = 0; rb->fd = shm_fd; - rb->pid = getpid(); + rb->api = getpid(); return rb; } -struct shm_ap_rbuff * shm_ap_rbuff_open(pid_t pid) +struct shm_ap_rbuff * shm_ap_rbuff_open(pid_t api) { struct shm_ap_rbuff * rb; int shm_fd; struct rb_entry * shm_base; char fn[25]; - sprintf(fn, SHM_AP_RBUFF_PREFIX "%d", pid); + sprintf(fn, SHM_AP_RBUFF_PREFIX "%d", api); rb = malloc(sizeof(*rb)); if (rb == NULL) { @@ -190,7 +190,7 @@ struct shm_ap_rbuff * shm_ap_rbuff_open(pid_t pid) rb->work = (pthread_cond_t *) (rb->shm_mutex + 1); rb->fd = shm_fd; - rb->pid = pid; + rb->api = api; return rb; } @@ -219,7 +219,7 @@ void shm_ap_rbuff_destroy(struct shm_ap_rbuff * rb) return; } - if (rb->pid != getpid()) { + if (rb->api != getpid()) { LOG_ERR("Tried to destroy other AP's rbuff."); return; } @@ -227,7 +227,7 @@ void shm_ap_rbuff_destroy(struct shm_ap_rbuff * rb) if (close(rb->fd) < 0) LOG_DBGF("Couldn't close shared memory."); - sprintf(fn, SHM_AP_RBUFF_PREFIX "%d", rb->pid); + sprintf(fn, SHM_AP_RBUFF_PREFIX "%d", rb->api); if (munmap(rb->shm_base, SHM_RBUFF_FILE_SIZE) == -1) LOG_DBGF("Couldn't unmap shared memory."); diff --git a/src/lib/shm_du_map.c b/src/lib/shm_du_map.c index f5909e11..2a316265 100644 --- a/src/lib/shm_du_map.c +++ b/src/lib/shm_du_map.c @@ -75,7 +75,7 @@ struct shm_du_map { size_t * ptr_tail; /* start of ringbuffer tail */ pthread_mutex_t * shm_mutex; /* lock all free space in shm */ pthread_cond_t * sanitize; /* run sanitizer when buffer full */ - pid_t * pid; /* pid of the irmd owner */ + pid_t * api; /* api of the irmd owner */ int fd; }; @@ -141,7 +141,7 @@ struct shm_du_map * shm_du_map_create() dum->ptr_tail = dum->ptr_head + 1; dum->shm_mutex = (pthread_mutex_t *) (dum->ptr_tail + 1); dum->sanitize = (pthread_cond_t *) (dum->shm_mutex + 1); - dum->pid = (pid_t *) (dum->sanitize + 1); + dum->api = (pid_t *) (dum->sanitize + 1); pthread_mutexattr_init(&mattr); pthread_mutexattr_setpshared(&mattr, PTHREAD_PROCESS_SHARED); @@ -155,7 +155,7 @@ struct shm_du_map * shm_du_map_create() *dum->ptr_head = 0; *dum->ptr_tail = 0; - *dum->pid = getpid(); + *dum->api = getpid(); dum->fd = shm_fd; @@ -203,7 +203,7 @@ struct shm_du_map * shm_du_map_open() dum->ptr_tail = dum->ptr_head + 1; dum->shm_mutex = (pthread_mutex_t *) (dum->ptr_tail + 1); dum->sanitize = (pthread_cond_t *) (dum->shm_mutex + 1); - dum->pid = (pid_t *) (dum->sanitize + 1); + dum->api = (pid_t *) (dum->sanitize + 1); dum->fd = shm_fd; @@ -212,7 +212,7 @@ struct shm_du_map * shm_du_map_open() pid_t shm_du_map_owner(struct shm_du_map * dum) { - return *dum->pid; + return *dum->api; } void * shm_du_map_sanitize(void * o) diff --git a/src/lib/sockets.c b/src/lib/sockets.c index 403d2833..9bfbad5e 100644 --- a/src/lib/sockets.c +++ b/src/lib/sockets.c @@ -149,19 +149,19 @@ irm_msg_t * send_recv_irm_msg(irm_msg_t * msg) } -char * ipcp_sock_path(pid_t pid) +char * ipcp_sock_path(pid_t api) { char * full_name = NULL; - char * pid_string = NULL; + char * api_string = NULL; size_t len = 0; char * delim = "_"; - len = n_digits(pid); - pid_string = malloc(len + 1); - if (pid_string == NULL) + len = n_digits(api); + api_string = malloc(len + 1); + if (api_string == NULL) return NULL; - sprintf(pid_string, "%d", pid); + sprintf(api_string, "%d", api); len += strlen(IPCP_SOCK_PATH_PREFIX); len += strlen(delim); @@ -169,16 +169,16 @@ char * ipcp_sock_path(pid_t pid) full_name = malloc(len + 1); if (full_name == NULL) { - free(pid_string); + free(api_string); return NULL; } strcpy(full_name, IPCP_SOCK_PATH_PREFIX); strcat(full_name, delim); - strcat(full_name, pid_string); + strcat(full_name, api_string); strcat(full_name, SOCK_PATH_SUFFIX); - free(pid_string); + free(api_string); return full_name; } -- cgit v1.2.3