diff options
Diffstat (limited to 'src/ipcpd')
-rw-r--r-- | src/ipcpd/ipcp-data.h | 2 | ||||
-rw-r--r-- | src/ipcpd/ipcp.c | 3 | ||||
-rw-r--r-- | src/ipcpd/ipcp.h | 7 | ||||
-rw-r--r-- | src/ipcpd/local/main.c | 27 | ||||
-rw-r--r-- | src/ipcpd/normal/cdap_request.c | 3 | ||||
-rw-r--r-- | src/ipcpd/normal/fmgr.h | 10 | ||||
-rw-r--r-- | src/ipcpd/normal/frct.c | 19 | ||||
-rw-r--r-- | src/ipcpd/normal/frct.h | 7 | ||||
-rw-r--r-- | src/ipcpd/normal/ribmgr.h | 11 | ||||
-rw-r--r-- | src/ipcpd/normal/shm_pci.c | 16 | ||||
-rw-r--r-- | src/ipcpd/shim-eth-llc/main.c | 36 | ||||
-rw-r--r-- | src/ipcpd/shim-eth-llc/shim_eth_llc_messages.proto | 4 | ||||
-rw-r--r-- | src/ipcpd/shim-udp/main.c | 27 | ||||
-rw-r--r-- | src/ipcpd/shim-udp/shim_udp_messages.proto | 4 |
14 files changed, 97 insertions, 79 deletions
diff --git a/src/ipcpd/ipcp-data.h b/src/ipcpd/ipcp-data.h index 4971dbb5..a9a637f0 100644 --- a/src/ipcpd/ipcp-data.h +++ b/src/ipcpd/ipcp-data.h @@ -44,7 +44,7 @@ struct ipcp_data { pthread_mutex_t lock; }; -struct ipcp_data * ipcp_data_create(); +struct ipcp_data * ipcp_data_create(void); struct ipcp_data * ipcp_data_init(struct ipcp_data * dst, enum ipcp_type ipcp_type); diff --git a/src/ipcpd/ipcp.c b/src/ipcpd/ipcp.c index eab02f7d..c2d343f8 100644 --- a/src/ipcpd/ipcp.c +++ b/src/ipcpd/ipcp.c @@ -257,8 +257,7 @@ void * ipcp_main_loop(void * o) if (conf_msg->ipcp_type == IPCP_NORMAL) { conf.addr_size = conf_msg->addr_size; conf.cep_id_size = conf_msg->cep_id_size; - conf.pdu_length_size - = conf_msg->pdu_length_size; + conf.pdu_length_size = conf_msg->pdu_length_size; conf.qos_id_size = conf_msg->qos_id_size; conf.seqno_size = conf_msg->seqno_size; conf.has_ttl = conf_msg->has_ttl; diff --git a/src/ipcpd/ipcp.h b/src/ipcpd/ipcp.h index 87c0c5d1..18a5bdab 100644 --- a/src/ipcpd/ipcp.h +++ b/src/ipcpd/ipcp.h @@ -53,13 +53,14 @@ struct ipcp { pthread_t mainloop; } ipcpi; -int ipcp_init(); +int ipcp_init(enum ipcp_type type, + struct ipcp_ops * ops); -void ipcp_fini(); +void ipcp_fini(void); void ipcp_set_state(enum ipcp_state state); -enum ipcp_state ipcp_get_state(); +enum ipcp_state ipcp_get_state(void); int ipcp_wait_state(enum ipcp_state state, const struct timespec * timeout); diff --git a/src/ipcpd/local/main.c b/src/ipcpd/local/main.c index 761577ea..c9ad0ae6 100644 --- a/src/ipcpd/local/main.c +++ b/src/ipcpd/local/main.c @@ -38,6 +38,7 @@ #include <pthread.h> #include <sys/wait.h> #include <fcntl.h> +#include <assert.h> #define EVENT_WAIT_TIMEOUT 100 /* us */ #define THIS_TYPE IPCP_LOCAL @@ -53,7 +54,7 @@ struct { pthread_t sduloop; } local_data; -int local_data_init() +static int local_data_init(void) { int i; for (i = 0; i < IRMD_MAX_FLOWS; ++i) @@ -68,7 +69,7 @@ int local_data_init() return 0; } -void local_data_fini() +static void local_data_fini(void) { pthread_rwlock_destroy(&local_data.lock); } @@ -91,10 +92,7 @@ static void * ipcp_local_sdu_loop(void * o) if (ret == -ETIMEDOUT) continue; - if (ret < 0) { - LOG_ERR("Event wait returned error code %d.", -ret); - continue; - } + assert(!ret); pthread_rwlock_rdlock(&ipcpi.state_lock); @@ -108,6 +106,8 @@ static void * ipcp_local_sdu_loop(void * o) while ((fd = fqueue_next(fq)) >= 0) { idx = local_flow_read(fd); + assert((size_t) idx < (SHM_BUFFER_SIZE)); + fd = local_data.in_out[fd]; if (fd != -1) @@ -147,10 +147,7 @@ void ipcp_sig_handler(int sig, siginfo_t * info, void * c) static int ipcp_local_bootstrap(struct dif_config * conf) { - if (conf->type != THIS_TYPE) { - LOG_ERR("Config doesn't match IPCP type."); - return -1; - } + assert (conf->type == THIS_TYPE); pthread_rwlock_wrlock(&ipcpi.state_lock); @@ -208,15 +205,12 @@ static int ipcp_local_flow_alloc(int fd, { int out_fd = -1; - /* FIXME: support qos */ + /* This ipcpd has all QoS */ (void) qos; LOG_DBG("Allocating flow to %s on fd %d.", dst_name, fd); - if (dst_name == NULL || src_ae_name == NULL) - return -1; - - /* This ipcpd has all QoS */ + assert(dst_name || src_ae_name); pthread_rwlock_rdlock(&ipcpi.state_lock); @@ -278,8 +272,7 @@ static int ipcp_local_flow_dealloc(int fd) { struct timespec t = {0, 10000}; - if (fd < 0) - return -EINVAL; + assert(!(fd < 0)); flow_set_del(local_data.flows, fd); diff --git a/src/ipcpd/normal/cdap_request.c b/src/ipcpd/normal/cdap_request.c index 5839360b..8409b508 100644 --- a/src/ipcpd/normal/cdap_request.c +++ b/src/ipcpd/normal/cdap_request.c @@ -134,8 +134,7 @@ int cdap_request_wait(struct cdap_request * creq) return ret; } -void cdap_request_respond(struct cdap_request * creq, - int response) +void cdap_request_respond(struct cdap_request * creq, int response) { if (creq == NULL) return; diff --git a/src/ipcpd/normal/fmgr.h b/src/ipcpd/normal/fmgr.h index f97cf858..faa8a0e4 100644 --- a/src/ipcpd/normal/fmgr.h +++ b/src/ipcpd/normal/fmgr.h @@ -34,28 +34,34 @@ #define MGMT_AE "Management" #define DT_AE "Data transfer" -int fmgr_init(); -int fmgr_fini(); +int fmgr_init(void); + +int fmgr_fini(void); int fmgr_np1_alloc(int fd, char * dst_ap_name, char * src_ae_name, enum qos_cube qos); + int fmgr_np1_alloc_resp(int fd, int response); + int fmgr_np1_dealloc(int fd); int fmgr_np1_post_buf(cep_id_t id, buffer_t * buf); + int fmgr_np1_post_sdu(cep_id_t id, struct shm_du_buff * sdb); int fmgr_nm1_mgmt_flow(char * dst_name); + int fmgr_nm1_dt_flow(char * dst_name, enum qos_cube qos); int fmgr_nm1_write_sdu(struct pci * pci, struct shm_du_buff * sdb); + int fmgr_nm1_write_buf(struct pci * pci, buffer_t * buf); diff --git a/src/ipcpd/normal/frct.c b/src/ipcpd/normal/frct.c index 9daf8755..3f80f91e 100644 --- a/src/ipcpd/normal/frct.c +++ b/src/ipcpd/normal/frct.c @@ -42,7 +42,7 @@ enum conn_state { struct frct_i { uint32_t cep_id; - uint32_t r_address; + uint64_t r_address; uint32_t r_cep_id; enum qos_cube cube; uint64_t seqno; @@ -58,18 +58,20 @@ struct { pthread_mutex_t cep_ids_lock; } frct; -static int next_cep_id() +static cep_id_t next_cep_id(void) { - int ret; + cep_id_t ret; pthread_mutex_lock(&frct.cep_ids_lock); ret = bmp_allocate(frct.cep_ids); + if (!bmp_is_id_valid(frct.cep_ids, ret)) + ret = INVALID_CEP_ID; pthread_mutex_unlock(&frct.cep_ids_lock); return ret; } -static int release_cep_id(int id) +static int release_cep_id(cep_id_t id) { int ret; @@ -117,7 +119,7 @@ int frct_fini() return 0; } -static struct frct_i * create_frct_i(uint32_t address, +static struct frct_i * create_frct_i(uint64_t address, cep_id_t r_cep_id) { struct frct_i * instance; @@ -128,6 +130,11 @@ static struct frct_i * create_frct_i(uint32_t address, return NULL; id = next_cep_id(); + if (id == INVALID_CEP_ID) { + free(instance); + return NULL; + } + instance->r_address = address; instance->cep_id = id; instance->r_cep_id = r_cep_id; @@ -191,7 +198,7 @@ static void destroy_frct_i(struct frct_i * instance) free(instance); } -cep_id_t frct_i_create(uint32_t address, +cep_id_t frct_i_create(uint64_t address, buffer_t * buf, enum qos_cube cube) { diff --git a/src/ipcpd/normal/frct.h b/src/ipcpd/normal/frct.h index b9e70d0f..572c1f61 100644 --- a/src/ipcpd/normal/frct.h +++ b/src/ipcpd/normal/frct.h @@ -30,10 +30,11 @@ struct frct_i; -int frct_init(); -int frct_fini(); +int frct_init(void); -cep_id_t frct_i_create(uint32_t address, +int frct_fini(void); + +cep_id_t frct_i_create(uint64_t address, buffer_t * buf, enum qos_cube cube); diff --git a/src/ipcpd/normal/ribmgr.h b/src/ipcpd/normal/ribmgr.h index ed8bae03..01bfcb40 100644 --- a/src/ipcpd/normal/ribmgr.h +++ b/src/ipcpd/normal/ribmgr.h @@ -27,10 +27,12 @@ #include "dt_const.h" -int ribmgr_init(); -int ribmgr_fini(); +int ribmgr_init(void); + +int ribmgr_fini(void); int ribmgr_add_flow(int fd); + int ribmgr_remove_flow(int fd); int ribmgr_bootstrap(struct dif_config * conf); @@ -39,7 +41,8 @@ int ribmgr_bootstrap(struct dif_config * conf); * FIXME: Should we expose the RIB? * Else we may end up with a lot of getters and setters */ -struct dt_const * ribmgr_dt_const(); -uint32_t ribmgr_address(); +struct dt_const * ribmgr_dt_const(void); + +uint32_t ribmgr_address(void); #endif diff --git a/src/ipcpd/normal/shm_pci.c b/src/ipcpd/normal/shm_pci.c index 3a16a2da..aa18fa38 100644 --- a/src/ipcpd/normal/shm_pci.c +++ b/src/ipcpd/normal/shm_pci.c @@ -39,13 +39,12 @@ #define TTL_SIZE 1 #define CHK_SIZE 4 -static int shm_pci_head_size(struct dt_const * dtc) +static size_t shm_pci_head_size(struct dt_const * dtc) { - int len = 0; + size_t len = 0; len = dtc->addr_size * 2 + dtc->cep_id_size * 2 - + dtc->pdu_length_size + dtc->seqno_size - + QOS_ID_SIZE; + + dtc->pdu_length_size + dtc->seqno_size + QOS_ID_SIZE; if (dtc->has_ttl) len += TTL_SIZE; @@ -53,7 +52,7 @@ static int shm_pci_head_size(struct dt_const * dtc) return len; } -static int shm_pci_tail_size(struct dt_const * dtc) +static size_t shm_pci_tail_size(struct dt_const * dtc) { return dtc->has_chk ? CHK_SIZE : 0; } @@ -162,10 +161,11 @@ struct pci * shm_pci_des(struct shm_du_buff * sdb) int offset = 0; struct dt_const * dtc; - head = shm_du_buff_head(sdb); - if (head == NULL) + if (sdb == NULL) return NULL; + head = shm_du_buff_head(sdb); + dtc = ribmgr_dt_const(); if (dtc == NULL) return NULL; @@ -221,7 +221,7 @@ int shm_pci_shrink(struct shm_du_buff * sdb) int shm_pci_dec_ttl(struct shm_du_buff * sdb) { struct dt_const * dtc; - int offset = 0; + size_t offset = 0; uint8_t * head; uint8_t * tail; diff --git a/src/ipcpd/shim-eth-llc/main.c b/src/ipcpd/shim-eth-llc/main.c index dfb6e21c..7976a2d1 100644 --- a/src/ipcpd/shim-eth-llc/main.c +++ b/src/ipcpd/shim-eth-llc/main.c @@ -123,7 +123,7 @@ struct { pthread_t sdu_reader; } eth_llc_data; -static int eth_llc_data_init() +static int eth_llc_data_init(void) { int i; @@ -166,7 +166,7 @@ static int eth_llc_data_init() return 0; } -void eth_llc_data_fini() +void eth_llc_data_fini(void) { bmp_destroy(eth_llc_data.saps); flow_set_destroy(eth_llc_data.np1_flows); @@ -190,7 +190,7 @@ static int eth_llc_ipcp_send_frame(uint8_t * dst_addr, uint8_t * payload, size_t len) { - int frame_len = 0; + uint32_t frame_len = 0; uint8_t cf = 0x03; uint16_t length; #if defined(PACKET_RX_RING) && defined(PACKET_TX_RING) @@ -262,7 +262,7 @@ static int eth_llc_ipcp_send_frame(uint8_t * dst_addr, } eth_llc_data.tx_offset = - (eth_llc_data.tx_offset + 1) & (SHM_BUFFER_SIZE - 1); + (eth_llc_data.tx_offset + 1) & ((SHM_BUFFER_SIZE) - 1); #else if (sendto(eth_llc_data.s_fd, frame, @@ -534,7 +534,7 @@ static void * eth_llc_ipcp_sdu_reader(void * o) MAC_SIZE) && memcmp(br_addr, llc_frame->dst_hwaddr, MAC_SIZE)) { #if defined(PACKET_RX_RING) && defined(PACKET_TX_RING) - offset = (offset + 1) & (SHM_BUFFER_SIZE - 1); + offset = (offset + 1) & ((SHM_BUFFER_SIZE) - 1); header->tp_status = TP_STATUS_KERNEL; #endif continue; @@ -545,7 +545,7 @@ static void * eth_llc_ipcp_sdu_reader(void * o) if (length > 0x05FF) { /* DIX */ #if defined(PACKET_RX_RING) && defined(PACKET_TX_RING) - offset = (offset + 1) & (SHM_BUFFER_SIZE -1); + offset = (offset + 1) & ((SHM_BUFFER_SIZE) -1); header->tp_status = TP_STATUS_KERNEL; #endif continue; @@ -567,7 +567,7 @@ static void * eth_llc_ipcp_sdu_reader(void * o) if (fd < 0) { pthread_rwlock_unlock(ð_llc_data.flows_lock); #if defined(PACKET_RX_RING) && defined(PACKET_TX_RING) - offset = (offset + 1) & (SHM_BUFFER_SIZE - 1); + offset = (offset + 1) & ((SHM_BUFFER_SIZE) - 1); header->tp_status = TP_STATUS_KERNEL; #endif continue; @@ -578,7 +578,7 @@ static void * eth_llc_ipcp_sdu_reader(void * o) llc_frame->src_hwaddr, MAC_SIZE)) { pthread_rwlock_unlock(ð_llc_data.flows_lock); #if defined(PACKET_RX_RING) && defined(PACKET_TX_RING) - offset = (offset + 1) & (SHM_BUFFER_SIZE -1); + offset = (offset + 1) & ((SHM_BUFFER_SIZE) -1); header->tp_status = TP_STATUS_KERNEL; #endif continue; @@ -590,7 +590,7 @@ static void * eth_llc_ipcp_sdu_reader(void * o) } #if defined(PACKET_RX_RING) && defined(PACKET_TX_RING) - offset = (offset + 1) & (SHM_BUFFER_SIZE -1); + offset = (offset + 1) & ((SHM_BUFFER_SIZE) - 1); header->tp_status = TP_STATUS_KERNEL; #endif } @@ -807,7 +807,7 @@ static int eth_llc_ipcp_bootstrap(struct dif_config * conf) #if defined(PACKET_RX_RING) && defined(PACKET_TX_RING) eth_llc_data.rx_ring = mmap(NULL, 2 * SHM_RDRB_BLOCK_SIZE - * SHM_BUFFER_SIZE, + * (SHM_BUFFER_SIZE), PROT_READ | PROT_WRITE, MAP_SHARED, skfd, 0); if (eth_llc_data.rx_ring == NULL) { @@ -817,7 +817,7 @@ static int eth_llc_ipcp_bootstrap(struct dif_config * conf) } eth_llc_data.tx_ring = eth_llc_data.rx_ring - + SHM_RDRB_BLOCK_SIZE * SHM_BUFFER_SIZE; + + SHM_RDRB_BLOCK_SIZE * (SHM_BUFFER_SIZE); #endif pthread_rwlock_wrlock(&ipcpi.state_lock); @@ -908,7 +908,7 @@ static int eth_llc_ipcp_flow_alloc(int fd, pthread_rwlock_wrlock(ð_llc_data.flows_lock); - ssap = bmp_allocate(eth_llc_data.saps); + ssap = bmp_allocate(eth_llc_data.saps); if (!bmp_is_id_valid(eth_llc_data.saps, ssap)) { pthread_rwlock_unlock(ð_llc_data.flows_lock); pthread_rwlock_unlock(&ipcpi.state_lock); @@ -923,7 +923,10 @@ static int eth_llc_ipcp_flow_alloc(int fd, memset(r_addr, 0xff, MAC_SIZE); - if (eth_llc_ipcp_sap_alloc(r_addr, ssap, dst_name, src_ae_name) < 0) { + if (eth_llc_ipcp_sap_alloc(r_addr, + ssap, + dst_name, + src_ae_name) < 0) { pthread_rwlock_rdlock(&ipcpi.state_lock); pthread_rwlock_wrlock(ð_llc_data.flows_lock); bmp_release(eth_llc_data.saps, eth_llc_data.fd_to_ef[fd].sap); @@ -965,7 +968,10 @@ static int eth_llc_ipcp_flow_alloc_resp(int fd, int response) pthread_rwlock_unlock(ð_llc_data.flows_lock); pthread_rwlock_unlock(&ipcpi.state_lock); - if (eth_llc_ipcp_sap_alloc_resp(r_addr, ssap, r_sap, response) < 0) { + if (eth_llc_ipcp_sap_alloc_resp(r_addr, + ssap, + r_sap, + response) < 0) { pthread_rwlock_rdlock(&ipcpi.state_lock); pthread_rwlock_wrlock(ð_llc_data.flows_lock); bmp_release(eth_llc_data.saps, eth_llc_data.fd_to_ef[fd].sap); @@ -976,7 +982,7 @@ static int eth_llc_ipcp_flow_alloc_resp(int fd, int response) flow_set_add(eth_llc_data.np1_flows, fd); - LOG_DBG("Accepted flow, fd %d, SAP %d.", fd, ssap); + LOG_DBG("Accepted flow, fd %d, SAP %d.", fd, (uint8_t)ssap); return 0; } diff --git a/src/ipcpd/shim-eth-llc/shim_eth_llc_messages.proto b/src/ipcpd/shim-eth-llc/shim_eth_llc_messages.proto index dbad4964..0e8a1ce2 100644 --- a/src/ipcpd/shim-eth-llc/shim_eth_llc_messages.proto +++ b/src/ipcpd/shim-eth-llc/shim_eth_llc_messages.proto @@ -8,7 +8,7 @@ message shim_eth_llc_msg { required shim_eth_llc_msg_code code = 1; optional string dst_name = 2; optional string src_ae_name = 3; - required sint32 ssap = 4; - optional sint32 dsap = 5; + required uint32 ssap = 4; + optional uint32 dsap = 5; optional sint32 response = 6; }; diff --git a/src/ipcpd/shim-udp/main.c b/src/ipcpd/shim-udp/main.c index f97a6bc1..62e1b2d0 100644 --- a/src/ipcpd/shim-udp/main.c +++ b/src/ipcpd/shim-udp/main.c @@ -94,7 +94,7 @@ struct { pthread_mutex_t fd_set_lock; } udp_data; -static int udp_data_init() +static int udp_data_init(void) { int i; @@ -119,7 +119,7 @@ static int udp_data_init() return 0; } -static void udp_data_fini() +static void udp_data_fini(void) { flow_set_destroy(udp_data.np1_flows); @@ -192,7 +192,7 @@ static int send_shim_udp_msg(shim_udp_msg_t * msg, uint32_t dst_ip_addr) } static int ipcp_udp_port_alloc(uint32_t dst_ip_addr, - uint32_t src_udp_port, + uint16_t src_udp_port, char * dst_name, char * src_ae_name) { @@ -314,8 +314,8 @@ static int udp_port_to_fd(int udp_port) return -1; } -static int ipcp_udp_port_alloc_reply(int src_udp_port, - int dst_udp_port, +static int ipcp_udp_port_alloc_reply(uint16_t src_udp_port, + uint16_t dst_udp_port, int response) { int fd = -1; @@ -368,7 +368,7 @@ static int ipcp_udp_port_alloc_reply(int src_udp_port, return ret; } -static int ipcp_udp_flow_dealloc_req(int udp_port) +static int ipcp_udp_flow_dealloc_req(uint16_t udp_port) { int skfd = -1; int fd = -1; @@ -408,13 +408,15 @@ static int ipcp_udp_flow_dealloc_req(int udp_port) return 0; } -static void * ipcp_udp_listener() +static void * ipcp_udp_listener(void * o) { uint8_t buf[SHIM_UDP_MSG_SIZE]; - int n = 0; + ssize_t n = 0; struct sockaddr_in c_saddr; int sfd = udp_data.s_fd; + (void) o; + while (true) { shim_udp_msg_t * msg = NULL; @@ -464,9 +466,9 @@ static void * ipcp_udp_listener() return 0; } -static void * ipcp_udp_sdu_reader() +static void * ipcp_udp_sdu_reader(void * o) { - int n; + ssize_t n; int skfd; int fd; /* FIXME: avoid this copy */ @@ -476,6 +478,8 @@ static void * ipcp_udp_sdu_reader() int flags; struct timeval tv = {0, FD_UPDATE_TIMEOUT}; + (void) o; + while (true) { pthread_rwlock_rdlock(&ipcpi.state_lock); pthread_rwlock_rdlock(&udp_data.flows_lock); @@ -507,7 +511,6 @@ static void * ipcp_udp_sdu_reader() (unsigned *) &n)) <= 0) continue; - /* send the sdu to the correct fd */ flow_write(fd, buf, n); } } @@ -1109,7 +1112,7 @@ static int ipcp_udp_flow_alloc_resp(int fd, int response) static int ipcp_udp_flow_dealloc(int fd) { int skfd = -1; - int remote_udp = -1; + uint16_t remote_udp; struct timespec t = {0, 10000}; struct sockaddr_in r_saddr; socklen_t r_saddr_len = sizeof(r_saddr); diff --git a/src/ipcpd/shim-udp/shim_udp_messages.proto b/src/ipcpd/shim-udp/shim_udp_messages.proto index e6bac908..bd9bd3aa 100644 --- a/src/ipcpd/shim-udp/shim_udp_messages.proto +++ b/src/ipcpd/shim-udp/shim_udp_messages.proto @@ -8,7 +8,7 @@ message shim_udp_msg { required shim_udp_msg_code code = 1; optional string dst_name = 2; optional string src_ae_name = 4; - required sint32 src_udp_port = 5; - optional sint32 dst_udp_port = 6; + required uint32 src_udp_port = 5; + optional uint32 dst_udp_port = 6; optional sint32 response = 7; }; |