diff options
62 files changed, 333 insertions, 293 deletions
@@ -1 +1,3 @@ -*~
\ No newline at end of file +*~ +*# +build/
\ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index b41114f8..3ab2f35e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,6 +44,11 @@ test_and_set_c_compiler_flag_global(-Wall) test_and_set_c_compiler_flag_global(-Wextra) test_and_set_c_compiler_flag_global(-Werror) test_and_set_c_compiler_flag_global(-Wundef) +test_and_set_c_compiler_flag_global(-Wpointer-arith) +test_and_set_c_compiler_flag_global(-Wstrict-prototypes) +test_and_set_c_compiler_flag_global(-Wswitch-default) +test_and_set_c_compiler_flag_global(-Wstrict-overflow=5) +test_and_set_c_compiler_flag_global(-Wunreachable-code) test_and_set_c_compiler_flag_global(-Wdeclaration-after-statement) test_and_set_c_compiler_flag_global(-fmax-errors=5) diff --git a/include/ouroboros/bitmap.h b/include/ouroboros/bitmap.h index c109f3e8..a8d03759 100644 --- a/include/ouroboros/bitmap.h +++ b/include/ouroboros/bitmap.h @@ -30,12 +30,17 @@ struct bmp; -struct bmp * bmp_create(size_t bits, ssize_t offset); +struct bmp * bmp_create(size_t bits, + ssize_t offset); + int bmp_destroy(struct bmp * b); ssize_t bmp_allocate(struct bmp * instance); + int bmp_release(struct bmp * instance, ssize_t id); -bool bmp_is_id_valid(struct bmp * b, ssize_t id); + +bool bmp_is_id_valid(struct bmp * b, + ssize_t id); #endif diff --git a/include/ouroboros/config.h.in b/include/ouroboros/config.h.in index a9d65aec..6ffcb97f 100644 --- a/include/ouroboros/config.h.in +++ b/include/ouroboros/config.h.in @@ -41,7 +41,7 @@ #define SHM_RDRB_MULTI_BLOCK #define SHM_RDRB_PREFIX "/ouroboros.rdrb." #define LOCKFILE_NAME "/ouroboros.lockfile" -#define SHM_BUFFER_SIZE (1 << 14) +#define SHM_BUFFER_SIZE 1 << 14 #define DU_BUFF_HEADSPACE 128 #define DU_BUFF_TAILSPACE 0 #define SHM_RBUFF_PREFIX "/ouroboros.rbuff." diff --git a/include/ouroboros/fqueue.h b/include/ouroboros/fqueue.h index 943d6510..4534d706 100644 --- a/include/ouroboros/fqueue.h +++ b/include/ouroboros/fqueue.h @@ -34,11 +34,11 @@ struct fqueue; typedef struct flow_set flow_set_t; typedef struct fqueue fqueue_t; -flow_set_t * flow_set_create(); +flow_set_t * flow_set_create(void); void flow_set_destroy(flow_set_t * set); -fqueue_t * fqueue_create(); +fqueue_t * fqueue_create(void); void fqueue_destroy(struct fqueue * fq); diff --git a/include/ouroboros/local-dev.h b/include/ouroboros/local-dev.h index 30f440b1..3a2cd812 100644 --- a/include/ouroboros/local-dev.h +++ b/include/ouroboros/local-dev.h @@ -25,7 +25,7 @@ ssize_t local_flow_read(int fd); -int local_flow_write(int fd, - ssize_t idx); +int local_flow_write(int fd, + size_t idx); #endif /* OUROBOROS_LOCAL_DEV_H */ diff --git a/include/ouroboros/lockfile.h b/include/ouroboros/lockfile.h index c2cf4572..571780b6 100644 --- a/include/ouroboros/lockfile.h +++ b/include/ouroboros/lockfile.h @@ -27,8 +27,8 @@ struct lockfile; -struct lockfile * lockfile_create(); -struct lockfile * lockfile_open(); +struct lockfile * lockfile_create(void); +struct lockfile * lockfile_open(void); void lockfile_close(struct lockfile * lf); void lockfile_destroy(struct lockfile * lf); diff --git a/include/ouroboros/logs.h b/include/ouroboros/logs.h index db3f8519..56eac068 100644 --- a/include/ouroboros/logs.h +++ b/include/ouroboros/logs.h @@ -31,7 +31,7 @@ #endif int set_logfile(char * filename); -void close_logfile(); +void close_logfile(void); #define ANSI_COLOR_RED "\x1b[31m" #define ANSI_COLOR_GREEN "\x1b[32m" diff --git a/include/ouroboros/shm_flow_set.h b/include/ouroboros/shm_flow_set.h index 32db5d36..de5a9add 100644 --- a/include/ouroboros/shm_flow_set.h +++ b/include/ouroboros/shm_flow_set.h @@ -29,7 +29,7 @@ struct shm_flow_set; -struct shm_flow_set * shm_flow_set_create(); +struct shm_flow_set * shm_flow_set_create(void); void shm_flow_set_destroy(struct shm_flow_set * set); @@ -38,25 +38,25 @@ struct shm_flow_set * shm_flow_set_open(pid_t api); void shm_flow_set_close(struct shm_flow_set * set); void shm_flow_set_zero(struct shm_flow_set * shm_set, - ssize_t idx); + size_t idx); int shm_flow_set_add(struct shm_flow_set * shm_set, - ssize_t idx, + size_t idx, int port_id); int shm_flow_set_has(struct shm_flow_set * shm_set, - ssize_t idx, + size_t idx, int port_id); void shm_flow_set_del(struct shm_flow_set * shm_set, - ssize_t idx, + size_t idx, int port_id); void shm_flow_set_notify(struct shm_flow_set * set, int port_id); -int shm_flow_set_wait(const struct shm_flow_set * shm_set, - ssize_t idx, +ssize_t shm_flow_set_wait(const struct shm_flow_set * shm_set, + size_t idx, int * fqueue, const struct timespec * timeout); diff --git a/include/ouroboros/shm_rbuff.h b/include/ouroboros/shm_rbuff.h index 4c4e8c64..d9422ab9 100644 --- a/include/ouroboros/shm_rbuff.h +++ b/include/ouroboros/shm_rbuff.h @@ -41,7 +41,7 @@ int shm_rbuff_block(struct shm_rbuff * rb); void shm_rbuff_unblock(struct shm_rbuff * rb); int shm_rbuff_write(struct shm_rbuff * rb, - ssize_t idx); + size_t idx); ssize_t shm_rbuff_read(struct shm_rbuff * rb); diff --git a/include/ouroboros/shm_rdrbuff.h b/include/ouroboros/shm_rdrbuff.h index f1be3652..b16e2530 100644 --- a/include/ouroboros/shm_rdrbuff.h +++ b/include/ouroboros/shm_rdrbuff.h @@ -35,9 +35,9 @@ struct shm_rdrbuff; size_t shm_du_buff_get_idx(struct shm_du_buff * sdb); -struct shm_rdrbuff * shm_rdrbuff_create(); +struct shm_rdrbuff * shm_rdrbuff_create(void); -struct shm_rdrbuff * shm_rdrbuff_open(); +struct shm_rdrbuff * shm_rdrbuff_open(void); void shm_rdrbuff_close(struct shm_rdrbuff * rdrb); @@ -60,15 +60,15 @@ ssize_t shm_rdrbuff_write_b(struct shm_rdrbuff * rdrb, uint8_t * data, size_t data_len); -int shm_rdrbuff_read(uint8_t ** dst, +ssize_t shm_rdrbuff_read(uint8_t ** dst, struct shm_rdrbuff * rdrb, - ssize_t idx); + size_t idx); struct shm_du_buff * shm_rdrbuff_get(struct shm_rdrbuff * rdrb, - ssize_t idx); + size_t idx); int shm_rdrbuff_remove(struct shm_rdrbuff * rdrb, - ssize_t idx); + size_t idx); uint8_t * shm_du_buff_head(struct shm_du_buff * sdb); 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; }; diff --git a/src/irmd/irm_flow.h b/src/irmd/irm_flow.h index 507295bd..40a6bb8d 100644 --- a/src/irmd/irm_flow.h +++ b/src/irmd/irm_flow.h @@ -56,7 +56,7 @@ struct irm_flow { pthread_mutex_t state_lock; }; -struct irm_flow * irm_flow_create(); +struct irm_flow * irm_flow_create(void); void irm_flow_destroy(struct irm_flow * f); diff --git a/src/irmd/main.c b/src/irmd/main.c index 12da81aa..4dee4b91 100644 --- a/src/irmd/main.c +++ b/src/irmd/main.c @@ -129,7 +129,7 @@ static struct irm_flow * get_irm_flow_n(pid_t n_api) return NULL; } -static struct ipcp_entry * ipcp_entry_create() +static struct ipcp_entry * ipcp_entry_create(void) { struct ipcp_entry * e = malloc(sizeof(*e)); if (e == NULL) @@ -694,7 +694,7 @@ static int unbind_api(pid_t api, char * name) static ssize_t list_ipcps(char * name, pid_t ** apis) { struct list_head * pos = NULL; - ssize_t count = 0; + size_t count = 0; int i = 0; pthread_rwlock_rdlock(&irmd->state_lock); @@ -1163,10 +1163,18 @@ static struct irm_flow * flow_alloc(pid_t api, pthread_rwlock_wrlock(&irmd->flows_lock); port_id = f->port_id = bmp_allocate(irmd->port_ids); - f->n_1_api = ipcp; + if (!bmp_is_id_valid(irmd->port_ids, (ssize_t) port_id)) { + pthread_rwlock_unlock(&irmd->flows_lock); + pthread_rwlock_unlock(&irmd->state_lock); + LOG_ERR("Could not allocate port_id."); + irm_flow_destroy(f); + return NULL; + } + f->n_1_api = ipcp; f->n_rb = shm_rbuff_create(api, port_id); if (f->n_rb == NULL) { + bmp_release(irmd->port_ids, port_id); pthread_rwlock_unlock(&irmd->flows_lock); pthread_rwlock_unlock(&irmd->state_lock); LOG_ERR("Could not create ringbuffer for AP-I %d.", api); @@ -1176,6 +1184,7 @@ static struct irm_flow * flow_alloc(pid_t api, f->n_1_rb = shm_rbuff_create(ipcp, port_id); if (f->n_1_rb == NULL) { + bmp_release(irmd->port_ids, port_id); pthread_rwlock_unlock(&irmd->flows_lock); pthread_rwlock_unlock(&irmd->state_lock); LOG_ERR("Could not create ringbuffer for AP-I %d.", ipcp); @@ -1461,6 +1470,13 @@ static struct irm_flow * flow_req_arr(pid_t api, pthread_rwlock_wrlock(&irmd->flows_lock); f->port_id = bmp_allocate(irmd->port_ids); + if (!bmp_is_id_valid(irmd->port_ids, f->port_id)) { + pthread_rwlock_unlock(&irmd->flows_lock); + pthread_rwlock_unlock(&irmd->state_lock); + LOG_ERR("Could not create ringbuffer for AP-I %d.", f->n_api); + irm_flow_destroy(f); + return NULL; + } f->n_rb = shm_rbuff_create(f->n_api, f->port_id); if (f->n_rb == NULL) { @@ -1546,7 +1562,7 @@ static int flow_alloc_reply(int port_id, int response) return 0; } -static void irm_destroy() +static void irm_destroy(void) { struct list_head * p; struct list_head * h; @@ -1653,7 +1669,7 @@ void irmd_sig_handler(int sig, siginfo_t * info, void * c) } } -void * irm_sanitize() +void * irm_sanitize(void * o) { struct timespec now; struct list_head * p = NULL; @@ -1663,6 +1679,8 @@ void * irm_sanitize() IRMD_CLEANUP_TIMER % BILLION}; int s; + (void) o; + while (true) { if (clock_gettime(CLOCK_MONOTONIC, &now) < 0) LOG_WARN("Failed to get time."); @@ -1762,10 +1780,12 @@ void * irm_sanitize() } } -void * mainloop() +void * mainloop(void * o) { uint8_t buf[IRM_MSG_BUF_SIZE]; + (void) o; + while (true) { int cli_sockfd; irm_msg_t * msg; @@ -1971,7 +1991,7 @@ void * mainloop() return (void *) 0; } -static int irm_create() +static int irm_create(void) { struct stat st = {0}; struct timeval timeout = {(IRMD_ACCEPT_TIMEOUT / 1000), @@ -2057,7 +2077,7 @@ static int irm_create() if (kill(lockfile_owner(irmd->lf), 0) < 0) { LOG_INFO("IRMd didn't properly shut down last time."); /* FIXME: do this for each QOS_CUBE in the system */ - shm_rdrbuff_destroy(shm_rdrbuff_open(QOS_CUBE_BE)); + shm_rdrbuff_destroy(shm_rdrbuff_open()); LOG_INFO("Stale resources cleaned"); lockfile_destroy(irmd->lf); irmd->lf = lockfile_create(); @@ -2076,7 +2096,7 @@ static int irm_create() } /* FIXME: create an rdrb for each QOS_CUBE in the system */ - if ((irmd->rdrb = shm_rdrbuff_create(QOS_CUBE_BE)) == NULL) { + if ((irmd->rdrb = shm_rdrbuff_create()) == NULL) { irm_destroy(); return -1; } @@ -2088,7 +2108,7 @@ static int irm_create() return 0; } -static void usage() +static void usage(void) { LOG_ERR("Usage: irmd \n\n" " [--stdout (Print to stdout instead of logs)]\n"); diff --git a/src/irmd/registry.c b/src/irmd/registry.c index f57d833a..9442f3db 100644 --- a/src/irmd/registry.c +++ b/src/irmd/registry.c @@ -42,7 +42,7 @@ struct reg_dif { enum ipcp_type type; }; -static struct reg_entry * reg_entry_create() +static struct reg_entry * reg_entry_create(void) { struct reg_entry * e = malloc(sizeof(*e)); if (e == NULL) diff --git a/src/lib/bitmap.c b/src/lib/bitmap.c index 916ab2ee..94f5654f 100644 --- a/src/lib/bitmap.c +++ b/src/lib/bitmap.c @@ -28,25 +28,25 @@ #include <assert.h> #include <stdlib.h> #include <string.h> +#include <limits.h> -#define BITS_PER_BYTE 8 +#define BITS_PER_BYTE CHAR_BIT -#define BITS_PER_LONG (sizeof(long) * BITS_PER_BYTE) +#define BITS_PER_LONG (sizeof(size_t) * BITS_PER_BYTE) #define BIT_WORD(nr) ((nr) / BITS_PER_LONG) #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) #define BITS_TO_LONGS(nr) \ - DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long)) + DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(size_t)) -static unsigned long find_next_zero_bit(const unsigned long * addr, - unsigned long nbits) +static size_t find_next_zero_bit(const size_t * addr, size_t nbits) { - unsigned long tmp; - unsigned long start = 0; - unsigned long pos = 0; - unsigned long mask; + size_t tmp; + size_t start = 0; + size_t pos = 0; + size_t mask; /* First find correct word */ tmp = ~addr[start]; @@ -68,36 +68,33 @@ static unsigned long find_next_zero_bit(const unsigned long * addr, return (start * BITS_PER_LONG) + pos; } -static void bitmap_zero(unsigned long * dst, - unsigned int nbits) +static void bitmap_zero(size_t * dst, size_t nbits) { - unsigned int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long); + size_t len = BITS_TO_LONGS(nbits) * sizeof(size_t); memset(dst, 0, len); } -static void bitmap_clear(unsigned long * map, - unsigned int start) +static void bitmap_clear(size_t * map, size_t start) { - unsigned long * p = map + BIT_WORD(start); - unsigned long mask = ~(1UL << (start % (BITS_PER_LONG))); + size_t * p = map + BIT_WORD(start); + size_t mask = ~(1UL << (start % (BITS_PER_LONG))); *p &= mask; } -static void bitmap_set(unsigned long * map, - unsigned int start) +static void bitmap_set(size_t * map, size_t start) { - unsigned long * p = map + BIT_WORD(start); - unsigned long mask = 1UL << (start % (BITS_PER_LONG)); + size_t * p = map + BIT_WORD(start); + size_t mask = 1UL << (start % (BITS_PER_LONG)); *p |= mask; } struct bmp { ssize_t offset; - size_t size; + size_t size; - unsigned long * bitmap; + size_t * bitmap; }; struct bmp * bmp_create(size_t bits, ssize_t offset) @@ -111,7 +108,7 @@ struct bmp * bmp_create(size_t bits, ssize_t offset) if (tmp == NULL) return NULL; - tmp->bitmap = malloc(BITS_TO_LONGS(bits) * sizeof(unsigned long)); + tmp->bitmap = malloc(BITS_TO_LONGS(bits) * sizeof(size_t)); if (tmp->bitmap == NULL) { free(tmp); return NULL; @@ -150,15 +147,13 @@ static ssize_t bad_id(struct bmp * b) ssize_t bmp_allocate(struct bmp * b) { - ssize_t id; + size_t id; if (b == NULL) return -1; - id = (ssize_t) find_next_zero_bit(b->bitmap, - b->size); - - if (id >= (ssize_t) b->size) + id = find_next_zero_bit(b->bitmap, b->size); + if (id >= b->size) return bad_id(b); bitmap_set(b->bitmap, id); @@ -166,8 +161,7 @@ ssize_t bmp_allocate(struct bmp * b) return id + b->offset; } -static bool is_id_valid(struct bmp * b, - ssize_t id) +static bool is_id_valid(struct bmp * b, ssize_t id) { assert(b); @@ -177,8 +171,7 @@ static bool is_id_valid(struct bmp * b, return true; } -bool bmp_is_id_valid(struct bmp * b, - ssize_t id) +bool bmp_is_id_valid(struct bmp * b, ssize_t id) { if (b == NULL) return false; @@ -186,10 +179,9 @@ bool bmp_is_id_valid(struct bmp * b, return is_id_valid(b, id); } -int bmp_release(struct bmp * b, - ssize_t id) +int bmp_release(struct bmp * b, ssize_t id) { - ssize_t rid; + size_t rid; if (b == NULL) return -1; diff --git a/src/lib/cdap.c b/src/lib/cdap.c index 92a05221..4a6408f6 100644 --- a/src/lib/cdap.c +++ b/src/lib/cdap.c @@ -56,13 +56,14 @@ static int next_invoke_id(struct cdap * instance) pthread_mutex_lock(&instance->ids_lock); ret = bmp_allocate(instance->ids); + if (!bmp_is_id_valid(instance->ids, ret)) + ret = -1; /* INVALID_INVOKE_ID */ pthread_mutex_unlock(&instance->ids_lock); return ret; } -static int release_invoke_id(struct cdap * instance, - int id) +static int release_invoke_id(struct cdap * instance, int id) { int ret; diff --git a/src/lib/dev.c b/src/lib/dev.c index c349846f..86a5913e 100644 --- a/src/lib/dev.c +++ b/src/lib/dev.c @@ -285,7 +285,7 @@ void ap_fini() for (i = 0; i < AP_MAX_FLOWS; ++i) { if (ai.flows[i].tx_rb != NULL) { - int idx; + ssize_t idx; while ((idx = shm_rbuff_read(ai.flows[i].rx_rb)) >= 0) shm_rdrbuff_remove(ai.rdrb, idx); shm_rbuff_close(ai.flows[i].rx_rb); @@ -758,7 +758,7 @@ ssize_t flow_write(int fd, void * buf, size_t count) ssize_t flow_read(int fd, void * buf, size_t count) { - int idx = -1; + ssize_t idx = -1; ssize_t n; uint8_t * sdu; @@ -797,7 +797,7 @@ ssize_t flow_read(int fd, void * buf, size_t count) return -1; } - memcpy(buf, sdu, MIN(n, (ssize_t) count)); + memcpy(buf, sdu, MIN((size_t) n, count)); shm_rdrbuff_remove(ai.rdrb, idx); @@ -952,7 +952,7 @@ int flow_event_wait(struct flow_set * set, struct fqueue * fq, const struct timespec * timeout) { - int ret; + ssize_t ret; if (set == NULL) return -EINVAL; @@ -964,9 +964,6 @@ int flow_event_wait(struct flow_set * set, if (ret == -ETIMEDOUT) return -ETIMEDOUT; - if (ret < 0) - return ret; - fq->fqsize = ret; fq->next = 0; @@ -1217,7 +1214,7 @@ int ipcp_flow_alloc_reply(int fd, int response) int ipcp_flow_read(int fd, struct shm_du_buff ** sdb) { - int idx = -1; + ssize_t idx = -1; int port_id = -1; pthread_rwlock_rdlock(&ai.data_lock); @@ -1252,7 +1249,7 @@ int ipcp_flow_read(int fd, struct shm_du_buff ** sdb) int ipcp_flow_write(int fd, struct shm_du_buff * sdb) { - ssize_t idx; + size_t idx; if (sdb == NULL) return -EINVAL; @@ -1288,7 +1285,7 @@ ssize_t local_flow_read(int fd) return shm_rbuff_read(ai.flows[fd].rx_rb); } -int local_flow_write(int fd, ssize_t idx) +int local_flow_write(int fd, size_t idx) { if (fd < 0) return -EINVAL; @@ -1326,6 +1323,12 @@ int ipcp_read_shim(int fd, struct shm_du_buff ** sdb) } idx = shm_rbuff_read(ai.flows[fd].rx_rb); + if (idx < 0) { + pthread_rwlock_unlock(&ai.flows_lock); + pthread_rwlock_unlock(&ai.data_lock); + return -EAGAIN; + } + *sdb = shm_rdrbuff_get(ai.rdrb, idx); pthread_rwlock_unlock(&ai.flows_lock); diff --git a/src/lib/irm.c b/src/lib/irm.c index c4c6395b..c68aa0f6 100644 --- a/src/lib/irm.c +++ b/src/lib/irm.c @@ -166,8 +166,8 @@ ssize_t irm_list_ipcps(char * name, { irm_msg_t msg = IRM_MSG__INIT; irm_msg_t * recv_msg = NULL; - ssize_t nr = -1; - int i; + size_t nr = 0; + size_t i; if (apis == NULL) return -EINVAL; diff --git a/src/lib/shm_flow_set.c b/src/lib/shm_flow_set.c index 04de9fc5..f68773aa 100644 --- a/src/lib/shm_flow_set.c +++ b/src/lib/shm_flow_set.c @@ -43,7 +43,7 @@ #define FN_MAX_CHARS 255 -#define FQUEUESIZE (SHM_BUFFER_SIZE * sizeof(int)) +#define FQUEUESIZE ((SHM_BUFFER_SIZE) * sizeof(int)) #define SHM_FLOW_SET_FILE_SIZE (IRMD_MAX_FLOWS * sizeof(ssize_t) \ + AP_MAX_FQUEUES * sizeof(size_t) \ @@ -51,7 +51,7 @@ + AP_MAX_FQUEUES * FQUEUESIZE \ + sizeof(pthread_mutex_t)) -#define fqueue_ptr(fs, idx) (fs->fqueues + SHM_BUFFER_SIZE * idx) +#define fqueue_ptr(fs, idx) (fs->fqueues + (SHM_BUFFER_SIZE) * idx) struct shm_flow_set { ssize_t * mtable; @@ -123,7 +123,7 @@ struct shm_flow_set * shm_flow_set_create() set->conds = (pthread_cond_t *)(set->heads + AP_MAX_FQUEUES); set->fqueues = (int *) (set->conds + AP_MAX_FQUEUES); set->lock = (pthread_mutex_t *) - (set->fqueues + AP_MAX_FQUEUES * SHM_BUFFER_SIZE); + (set->fqueues + AP_MAX_FQUEUES * (SHM_BUFFER_SIZE)); pthread_mutexattr_init(&mattr); #ifndef __APPLE__ @@ -194,7 +194,7 @@ struct shm_flow_set * shm_flow_set_open(pid_t api) set->conds = (pthread_cond_t *)(set->heads + AP_MAX_FQUEUES); set->fqueues = (int *) (set->conds + AP_MAX_FQUEUES); set->lock = (pthread_mutex_t *) - (set->fqueues + AP_MAX_FQUEUES * SHM_BUFFER_SIZE); + (set->fqueues + AP_MAX_FQUEUES * (SHM_BUFFER_SIZE)); set->api = api; @@ -249,16 +249,16 @@ void shm_flow_set_close(struct shm_flow_set * set) } void shm_flow_set_zero(struct shm_flow_set * shm_set, - ssize_t idx) + size_t idx) { ssize_t i = 0; - assert(!(idx < 0) && idx < AP_MAX_FQUEUES); + assert(idx < AP_MAX_FQUEUES); pthread_mutex_lock(shm_set->lock); for (i = 0; i < IRMD_MAX_FLOWS; ++i) - if (shm_set->mtable[i] == idx) + if (shm_set->mtable[i] == (ssize_t) idx) shm_set->mtable[i] = -1; shm_set->heads[idx] = 0; @@ -268,12 +268,12 @@ void shm_flow_set_zero(struct shm_flow_set * shm_set, int shm_flow_set_add(struct shm_flow_set * shm_set, - ssize_t idx, + size_t idx, int port_id) { assert(shm_set); assert(!(port_id < 0) && port_id < IRMD_MAX_FLOWS); - assert(!(idx < 0) && idx < AP_MAX_FQUEUES); + assert(idx < AP_MAX_FQUEUES); pthread_mutex_lock(shm_set->lock); @@ -290,34 +290,34 @@ int shm_flow_set_add(struct shm_flow_set * shm_set, } void shm_flow_set_del(struct shm_flow_set * shm_set, - ssize_t idx, + size_t idx, int port_id) { assert(shm_set); assert(!(port_id < 0) && port_id < IRMD_MAX_FLOWS); - assert(!(idx < 0) && idx < AP_MAX_FQUEUES); + assert(idx < AP_MAX_FQUEUES); pthread_mutex_lock(shm_set->lock); - if (shm_set->mtable[port_id] == idx) + if (shm_set->mtable[port_id] == (ssize_t) idx) shm_set->mtable[port_id] = -1; pthread_mutex_unlock(shm_set->lock); } int shm_flow_set_has(struct shm_flow_set * shm_set, - ssize_t idx, + size_t idx, int port_id) { int ret = 0; assert(shm_set); assert(!(port_id < 0) && port_id < IRMD_MAX_FLOWS); - assert(!(idx < 0) && idx < AP_MAX_FQUEUES); + assert(idx < AP_MAX_FQUEUES); pthread_mutex_lock(shm_set->lock); - if (shm_set->mtable[port_id] == idx) + if (shm_set->mtable[port_id] == (ssize_t) idx) ret = 1; pthread_mutex_unlock(shm_set->lock); @@ -346,16 +346,16 @@ void shm_flow_set_notify(struct shm_flow_set * shm_set, int port_id) } -int shm_flow_set_wait(const struct shm_flow_set * shm_set, - ssize_t idx, - int * fqueue, - const struct timespec * timeout) +ssize_t shm_flow_set_wait(const struct shm_flow_set * shm_set, + size_t idx, + int * fqueue, + const struct timespec * timeout) { - int ret = 0; + ssize_t ret = 0; struct timespec abstime; assert(shm_set); - assert(!(idx < 0) && idx < AP_MAX_FQUEUES); + assert(idx < AP_MAX_FQUEUES); #ifdef __APPLE__ pthread_mutex_lock(shm_set->lock); @@ -397,11 +397,10 @@ int shm_flow_set_wait(const struct shm_flow_set * shm_set, memcpy(fqueue, fqueue_ptr(shm_set, idx), shm_set->heads[idx] * sizeof(int)); - ret = shm_set->heads[idx]; shm_set->heads[idx] = 0; } pthread_cleanup_pop(true); - return ret; + return 0; } diff --git a/src/lib/shm_rbuff.c b/src/lib/shm_rbuff.c index a933fbff..8b2e9229 100644 --- a/src/lib/shm_rbuff.c +++ b/src/lib/shm_rbuff.c @@ -44,14 +44,14 @@ #define FN_MAX_CHARS 255 -#define SHM_RBUFF_FILE_SIZE (SHM_BUFFER_SIZE * sizeof(ssize_t) \ +#define SHM_RBUFF_FILE_SIZE ((SHM_BUFFER_SIZE) * sizeof(ssize_t) \ + 2 * sizeof(size_t) + sizeof(int8_t) \ + sizeof(pthread_mutex_t) \ + 2 * sizeof (pthread_cond_t)) -#define shm_rbuff_used(rb) ((*rb->head + SHM_BUFFER_SIZE - *rb->tail) \ - & (SHM_BUFFER_SIZE - 1)) -#define shm_rbuff_free(rb) (shm_rbuff_used(rb) + 1 < SHM_BUFFER_SIZE) +#define shm_rbuff_used(rb) ((*rb->head + (SHM_BUFFER_SIZE) - *rb->tail) \ + & ((SHM_BUFFER_SIZE) - 1)) +#define shm_rbuff_free(rb) (shm_rbuff_used(rb) + 1 < (SHM_BUFFER_SIZE)) #define shm_rbuff_empty(rb) (*rb->head == *rb->tail) #define head_el_ptr(rb) (rb->shm_base + *rb->head) #define tail_el_ptr(rb) (rb->shm_base + *rb->tail) @@ -122,7 +122,7 @@ struct shm_rbuff * shm_rbuff_create(pid_t api, int port_id) } rb->shm_base = shm_base; - rb->head = (size_t *) (rb->shm_base + SHM_BUFFER_SIZE); + rb->head = (size_t *) (rb->shm_base + (SHM_BUFFER_SIZE)); rb->tail = rb->head + 1; rb->acl = (int8_t *) (rb->tail + 1); rb->lock = (pthread_mutex_t *) (rb->acl + 1); @@ -198,7 +198,7 @@ struct shm_rbuff * shm_rbuff_open(pid_t api, int port_id) } rb->shm_base = shm_base; - rb->head = (size_t *) (rb->shm_base + SHM_BUFFER_SIZE); + rb->head = (size_t *) (rb->shm_base + (SHM_BUFFER_SIZE)); rb->tail = rb->head + 1; rb->acl = (int8_t *) (rb->tail + 1); rb->lock = (pthread_mutex_t *) (rb->acl + 1); @@ -236,10 +236,10 @@ void shm_rbuff_destroy(struct shm_rbuff * rb) free(rb); } -int shm_rbuff_write(struct shm_rbuff * rb, ssize_t idx) +int shm_rbuff_write(struct shm_rbuff * rb, size_t idx) { assert(rb); - assert(idx >= 0); + assert(idx < SHM_BUFFER_SIZE); #ifdef __APPLE__ pthread_mutex_lock(rb->lock); @@ -262,8 +262,8 @@ int shm_rbuff_write(struct shm_rbuff * rb, ssize_t idx) if (shm_rbuff_empty(rb)) pthread_cond_broadcast(rb->add); - *head_el_ptr(rb) = idx; - *rb->head = (*rb->head + 1) & (SHM_BUFFER_SIZE -1); + *head_el_ptr(rb) = (ssize_t) idx; + *rb->head = (*rb->head + 1) & ((SHM_BUFFER_SIZE) -1); pthread_mutex_unlock(rb->lock); @@ -272,7 +272,7 @@ int shm_rbuff_write(struct shm_rbuff * rb, ssize_t idx) ssize_t shm_rbuff_read(struct shm_rbuff * rb) { - int ret = 0; + ssize_t ret = 0; assert(rb); @@ -286,11 +286,11 @@ ssize_t shm_rbuff_read(struct shm_rbuff * rb) #endif if (shm_rbuff_empty(rb)) { pthread_mutex_unlock(rb->lock); - return -1; + return -EAGAIN; } ret = *tail_el_ptr(rb); - *rb->tail = (*rb->tail + 1) & (SHM_BUFFER_SIZE -1); + *rb->tail = (*rb->tail + 1) & ((SHM_BUFFER_SIZE) - 1); pthread_mutex_unlock(rb->lock); @@ -344,7 +344,7 @@ ssize_t shm_rbuff_read_b(struct shm_rbuff * rb, if (idx != -ETIMEDOUT) { idx = *tail_el_ptr(rb); - *rb->tail = (*rb->tail + 1) & (SHM_BUFFER_SIZE -1); + *rb->tail = (*rb->tail + 1) & ((SHM_BUFFER_SIZE) - 1); pthread_cond_broadcast(rb->del); } diff --git a/src/lib/shm_rdrbuff.c b/src/lib/shm_rdrbuff.c index 1f93f1c7..dc1feb10 100644 --- a/src/lib/shm_rdrbuff.c +++ b/src/lib/shm_rdrbuff.c @@ -41,30 +41,30 @@ #include <ouroboros/logs.h> -#define SHM_BLOCKS_SIZE (SHM_BUFFER_SIZE * SHM_RDRB_BLOCK_SIZE) -#define SHM_FILE_SIZE (SHM_BLOCKS_SIZE + 3 * sizeof (size_t) \ +#define SHM_BLOCKS_SIZE ((SHM_BUFFER_SIZE) * SHM_RDRB_BLOCK_SIZE) +#define SHM_FILE_SIZE (SHM_BLOCKS_SIZE + 3 * sizeof(size_t) \ + sizeof(pthread_mutex_t) + 2 * sizeof(pthread_cond_t) \ + sizeof(pid_t)) #define get_head_ptr(rdrb) \ - ((struct shm_du_buff *)(rdrb->shm_base + (*rdrb->ptr_head * \ - SHM_RDRB_BLOCK_SIZE))) + ((struct shm_du_buff *) (rdrb->shm_base + (*rdrb->ptr_head \ + * SHM_RDRB_BLOCK_SIZE))) #define get_tail_ptr(rdrb) \ - ((struct shm_du_buff *)(rdrb->shm_base + (*rdrb->ptr_tail * \ - SHM_RDRB_BLOCK_SIZE))) + ((struct shm_du_buff *) (rdrb->shm_base + (*rdrb->ptr_tail \ + * SHM_RDRB_BLOCK_SIZE))) #define idx_to_du_buff_ptr(rdrb, idx) \ - ((struct shm_du_buff *)(rdrb->shm_base + (idx * SHM_RDRB_BLOCK_SIZE))) + ((struct shm_du_buff *) (rdrb->shm_base + idx * SHM_RDRB_BLOCK_SIZE)) #define block_ptr_to_idx(rdrb, sdb) \ (((uint8_t *)sdb - rdrb->shm_base) / SHM_RDRB_BLOCK_SIZE) #define shm_rdrb_used(rdrb) \ - ((*rdrb->ptr_head + SHM_BUFFER_SIZE - *rdrb->ptr_tail) \ - & (SHM_BUFFER_SIZE - 1)) + ((*rdrb->ptr_head + (SHM_BUFFER_SIZE) - *rdrb->ptr_tail) \ + & ((SHM_BUFFER_SIZE) - 1)) #define shm_rdrb_free(rdrb, i) \ - (shm_rdrb_used(rdrb) + i < SHM_BUFFER_SIZE) + (shm_rdrb_used(rdrb) + i < (SHM_BUFFER_SIZE)) #define shm_rdrb_empty(rdrb) \ (*rdrb->ptr_tail == *rdrb->ptr_head) @@ -99,11 +99,11 @@ static void garbage_collect(struct shm_rdrbuff * rdrb) while (!shm_rdrb_empty(rdrb) && (sdb = get_tail_ptr(rdrb))->dst_api == -1) *rdrb->ptr_tail = (*rdrb->ptr_tail + sdb->blocks) - & (SHM_BUFFER_SIZE - 1); + & ((SHM_BUFFER_SIZE) - 1); #else while (!shm_rdrb_empty(rdrb) && get_tail_ptr(rdrb)->dst_api == -1) *rdrb->ptr_tail = - (*rdrb->ptr_tail + 1) & (SHM_BUFFER_SIZE - 1); + (*rdrb->ptr_tail + 1) & ((SHM_BUFFER_SIZE) - 1); #endif } @@ -118,9 +118,9 @@ static void clean_sdus(struct shm_rdrbuff * rdrb, pid_t api) if (buf->dst_api == api) buf->dst_api = -1; #ifdef SHM_RDRB_MULTI_BLOCK - idx = (idx + buf->blocks) & (SHM_BUFFER_SIZE - 1); + idx = (idx + buf->blocks) & ((SHM_BUFFER_SIZE) - 1); #else - idx = (idx + 1) & (SHM_BUFFER_SIZE - 1); + idx = (idx + 1) & ((SHM_BUFFER_SIZE) - 1); #endif } @@ -131,7 +131,7 @@ static void clean_sdus(struct shm_rdrbuff * rdrb, pid_t api) static char * rdrb_filename(enum qos_cube qos) { - int chars = 0; + size_t chars = 0; char * str; int qm = QOS_MAX; @@ -440,10 +440,10 @@ ssize_t shm_rdrbuff_write(struct shm_rdrbuff * rdrb, struct shm_du_buff * sdb; size_t size = headspace + len + tailspace; #ifdef SHM_RDRB_MULTI_BLOCK - long blocks = 0; - long padblocks = 0; + size_t blocks = 0; + size_t padblocks = 0; #endif - int sz = size + sizeof *sdb; + ssize_t sz = size + sizeof(*sdb); uint8_t * write_pos; assert(rdrb); @@ -469,10 +469,10 @@ ssize_t shm_rdrbuff_write(struct shm_rdrbuff * rdrb, ++blocks; } - if (blocks + *rdrb->ptr_head > SHM_BUFFER_SIZE) - padblocks = SHM_BUFFER_SIZE - *rdrb->ptr_head; + if (blocks + *rdrb->ptr_head > (SHM_BUFFER_SIZE)) + padblocks = (SHM_BUFFER_SIZE) - *rdrb->ptr_head; - if (!shm_rdrb_free(rdrb, (blocks + padblocks))) { + if (!shm_rdrb_free(rdrb, blocks + padblocks)) { #else if (!shm_rdrb_free(rdrb, 1)) { #endif @@ -508,9 +508,9 @@ ssize_t shm_rdrbuff_write(struct shm_rdrbuff * rdrb, sdb->idx = *rdrb->ptr_head; #ifdef SHM_RDRB_MULTI_BLOCK - *rdrb->ptr_head = (*rdrb->ptr_head + blocks) & (SHM_BUFFER_SIZE - 1); + *rdrb->ptr_head = (*rdrb->ptr_head + blocks) & ((SHM_BUFFER_SIZE) - 1); #else - *rdrb->ptr_head = (*rdrb->ptr_head + 1) & (SHM_BUFFER_SIZE - 1); + *rdrb->ptr_head = (*rdrb->ptr_head + 1) & ((SHM_BUFFER_SIZE) - 1); #endif pthread_mutex_unlock(rdrb->lock); @@ -527,10 +527,10 @@ ssize_t shm_rdrbuff_write_b(struct shm_rdrbuff * rdrb, struct shm_du_buff * sdb; size_t size = headspace + len + tailspace; #ifdef SHM_RDRB_MULTI_BLOCK - long blocks = 0; - long padblocks = 0; + size_t blocks = 0; + size_t padblocks = 0; #endif - int sz = size + sizeof *sdb; + ssize_t sz = size + sizeof(*sdb); uint8_t * write_pos; assert(rdrb); @@ -550,7 +550,7 @@ ssize_t shm_rdrbuff_write_b(struct shm_rdrbuff * rdrb, pthread_mutex_consistent(rdrb->lock); } #endif - pthread_cleanup_push((void(*)(void *))pthread_mutex_unlock, + pthread_cleanup_push((void (*) (void *)) pthread_mutex_unlock, (void *) rdrb->lock); #ifdef SHM_RDRB_MULTI_BLOCK @@ -559,8 +559,8 @@ ssize_t shm_rdrbuff_write_b(struct shm_rdrbuff * rdrb, ++blocks; } - if (blocks + *rdrb->ptr_head > SHM_BUFFER_SIZE) - padblocks = SHM_BUFFER_SIZE - *rdrb->ptr_head; + if (blocks + *rdrb->ptr_head > (SHM_BUFFER_SIZE)) + padblocks = (SHM_BUFFER_SIZE) - *rdrb->ptr_head; while (!shm_rdrb_free(rdrb, (blocks + padblocks))) { #else @@ -597,27 +597,26 @@ ssize_t shm_rdrbuff_write_b(struct shm_rdrbuff * rdrb, sdb->idx = *rdrb->ptr_head; #ifdef SHM_RDRB_MULTI_BLOCK - *rdrb->ptr_head = (*rdrb->ptr_head + blocks) & (SHM_BUFFER_SIZE - 1); + *rdrb->ptr_head = (*rdrb->ptr_head + blocks) & ((SHM_BUFFER_SIZE) - 1); #else - *rdrb->ptr_head = (*rdrb->ptr_head + 1) & (SHM_BUFFER_SIZE - 1); + *rdrb->ptr_head = (*rdrb->ptr_head + 1) & ((SHM_BUFFER_SIZE) - 1); #endif pthread_cleanup_pop(true); return sdb->idx; } -int shm_rdrbuff_read(uint8_t ** dst, - struct shm_rdrbuff * rdrb, - ssize_t idx) +ssize_t shm_rdrbuff_read(uint8_t ** dst, + struct shm_rdrbuff * rdrb, + size_t idx) { - size_t len = 0; + ssize_t len = 0; struct shm_du_buff * sdb; assert(dst); assert(rdrb); + assert(idx < (SHM_BUFFER_SIZE)); - if (idx > SHM_BUFFER_SIZE) - return -1; #ifdef __APPLE__ pthread_mutex_lock(rdrb->lock); #else @@ -632,7 +631,7 @@ int shm_rdrbuff_read(uint8_t ** dst, } sdb = idx_to_du_buff_ptr(rdrb, idx); - len = sdb->du_tail - sdb->du_head; + len = (ssize_t) (sdb->du_tail - sdb->du_head); *dst = ((uint8_t *) (sdb + 1)) + sdb->du_head; pthread_mutex_unlock(rdrb->lock); @@ -640,14 +639,13 @@ int shm_rdrbuff_read(uint8_t ** dst, return len; } -struct shm_du_buff * shm_rdrbuff_get(struct shm_rdrbuff * rdrb, ssize_t idx) +struct shm_du_buff * shm_rdrbuff_get(struct shm_rdrbuff * rdrb, size_t idx) { struct shm_du_buff * sdb; assert(rdrb); + assert(idx < (SHM_BUFFER_SIZE)); - if (idx > SHM_BUFFER_SIZE) - return NULL; #ifdef __APPLE__ pthread_mutex_lock(rdrb->lock); #else @@ -668,12 +666,11 @@ struct shm_du_buff * shm_rdrbuff_get(struct shm_rdrbuff * rdrb, ssize_t idx) return sdb; } -int shm_rdrbuff_remove(struct shm_rdrbuff * rdrb, ssize_t idx) +int shm_rdrbuff_remove(struct shm_rdrbuff * rdrb, size_t idx) { assert(rdrb); + assert(idx < (SHM_BUFFER_SIZE)); - if (idx > SHM_BUFFER_SIZE) - return -1; #ifdef __APPLE__ pthread_mutex_lock(rdrb->lock); #else @@ -689,7 +686,7 @@ int shm_rdrbuff_remove(struct shm_rdrbuff * rdrb, ssize_t idx) idx_to_du_buff_ptr(rdrb, idx)->dst_api = -1; - if (idx != (ssize_t) *rdrb->ptr_tail) { + if (idx != *rdrb->ptr_tail) { pthread_mutex_unlock(rdrb->lock); return 0; } diff --git a/src/lib/sockets.c b/src/lib/sockets.c index c8375c22..db1f3f6b 100644 --- a/src/lib/sockets.c +++ b/src/lib/sockets.c @@ -144,7 +144,6 @@ static irm_msg_t * send_recv_irm_msg_timed(irm_msg_t * msg, bool timed) if (write(sockfd, buf.data, buf.len) != -1) count = read(sockfd, buf.data, IRM_MSG_BUF_SIZE); - if (count > 0) recv_msg = irm_msg__unpack(NULL, count, buf.data); diff --git a/src/nsmd/main.c b/src/nsmd/main.c index e2971dca..b30b9dd9 100644 --- a/src/nsmd/main.c +++ b/src/nsmd/main.c @@ -2,7 +2,7 @@ #include <ouroboros/logs.h> -int main() +int main(void) { LOG_DBG("Test of the DA"); diff --git a/src/tools/cbr/cbr.c b/src/tools/cbr/cbr.c index 27c51586..efcb2847 100644 --- a/src/tools/cbr/cbr.c +++ b/src/tools/cbr/cbr.c @@ -64,7 +64,7 @@ static void usage(void) int main(int argc, char ** argv) { - int duration = 60; /* One minute test */ + int duration = 60; /* One minute test */ int size = 1000; /* 1000 byte SDUs */ long rate = 1000000; /* 1 Mb/s */ bool flood = false; diff --git a/src/tools/cbr/cbr_client.c b/src/tools/cbr/cbr_client.c index af766599..b2cf7d7f 100644 --- a/src/tools/cbr/cbr_client.c +++ b/src/tools/cbr/cbr_client.c @@ -46,8 +46,8 @@ int client_main(char * server, int result = 0; bool stop = false; char buf[size]; - long seqnr = 0; - unsigned long gap = size * 8.0 * (BILLION / (double) rate); + int seqnr = 0; + long gap = size * 8.0 * (BILLION / (double) rate); struct timespec start; struct timespec end; @@ -55,7 +55,7 @@ int client_main(char * server, int ms; printf("Client started, duration %d, rate %lu b/s, size %d B.\n", - duration, rate, size); + duration, rate, size); fd = flow_alloc(server, NULL, NULL); if (fd < 0) { @@ -85,18 +85,17 @@ int client_main(char * server, if (sleep) nanosleep(&intv, NULL); else - busy_wait_until(&end); + busy_wait_until(&end); ++seqnr; - if (ts_diff_us(&start, &end) / MILLION - >= (long) duration) + if (ts_diff_us(&start, &end) / MILLION >= duration) stop = true; } } else { /* flood */ while (!stop) { clock_gettime(CLOCK_REALTIME, &end); - if (flow_write(fd, buf, size) == -1) { + if (flow_write(fd, buf, (size_t) size) == -1) { stop = true; continue; } @@ -115,7 +114,7 @@ int client_main(char * server, ms = ts_diff_ms(&start, &end); printf("sent statistics: " - "%9ld SDUs, %12ld bytes in %9d ms, %4.4f Mb/s\n", + "%9d SDUs, %12d bytes in %9d ms, %4.4f Mb/s\n", seqnr, seqnr * size, ms, (seqnr * size * 8.0)/(ms * 1000)); flow_dealloc(fd); diff --git a/src/tools/cbr/cbr_server.c b/src/tools/cbr/cbr_server.c index d40ae2cb..f1c342d1 100644 --- a/src/tools/cbr/cbr_server.c +++ b/src/tools/cbr/cbr_server.c @@ -63,7 +63,7 @@ void shutdown_server(int signo, siginfo_t * info, void * c) void handle_flow(int fd) { - ssize_t count = 0; + int count = 0; char buf[BUF_SIZE]; struct timespec now; @@ -112,9 +112,9 @@ void handle_flow(int fd) sdus - sdus_intv, bytes_read - bytes_read_intv, us / 1000, - ((sdus - sdus_intv) / (float) us) * MILLION, + ((sdus - sdus_intv) / (double) us) * MILLION, 8 * (bytes_read - bytes_read_intv) - / (float)(us)); + / (double)(us)); iv_start = iv_end; sdus_intv = sdus; bytes_read_intv = bytes_read; @@ -197,7 +197,7 @@ void * listener(void * o) return 0; } -int server_main() +int server_main(void) { struct sigaction sig_act; int i; diff --git a/src/tools/echo/echo.c b/src/tools/echo/echo.c index 28ae4c1a..82d280f9 100644 --- a/src/tools/echo/echo.c +++ b/src/tools/echo/echo.c @@ -30,7 +30,7 @@ #include "echo_client.c" #include "echo_server.c" -static void usage() +static void usage(void) { printf("Usage: echo-app [OPTION]...\n" "Sends an echo between a server and a client\n\n" diff --git a/src/tools/echo/echo_client.c b/src/tools/echo/echo_client.c index f006273c..3507364a 100644 --- a/src/tools/echo/echo_client.c +++ b/src/tools/echo/echo_client.c @@ -23,7 +23,7 @@ #include <ouroboros/dev.h> #include <stdlib.h> -int client_main() +int client_main(void) { int fd = 0; int result = 0; diff --git a/src/tools/echo/echo_server.c b/src/tools/echo/echo_server.c index acf691b3..070f0ce3 100644 --- a/src/tools/echo/echo_server.c +++ b/src/tools/echo/echo_server.c @@ -35,7 +35,7 @@ void shutdown_server(int signo) exit(EXIT_SUCCESS); } -int server_main() +int server_main(void) { int client_fd = 0; char buf[BUF_SIZE]; diff --git a/src/tools/irm/irm.c b/src/tools/irm/irm.c index 1c75a7a5..be758098 100644 --- a/src/tools/irm/irm.c +++ b/src/tools/irm/irm.c @@ -27,7 +27,7 @@ #include "irm_ops.h" #include "irm_utils.h" -static void usage() +static void usage(void) { printf("Usage: irm [OPERATION]\n\n" "where OPERATION = {ipcp bind unbind\n" diff --git a/src/tools/irm/irm_bind.c b/src/tools/irm/irm_bind.c index a12a812b..bb441573 100644 --- a/src/tools/irm/irm_bind.c +++ b/src/tools/irm/irm_bind.c @@ -28,7 +28,7 @@ #include "irm_ops.h" #include "irm_utils.h" -static void usage() +static void usage(void) { printf("Usage: irm bind [OPERATION]\n" "where OPERATION = {ap api ipcp help}\n"); diff --git a/src/tools/irm/irm_bind_ap.c b/src/tools/irm/irm_bind_ap.c index 189b197e..b558f072 100644 --- a/src/tools/irm/irm_bind_ap.c +++ b/src/tools/irm/irm_bind_ap.c @@ -30,7 +30,7 @@ #include "irm_ops.h" #include "irm_utils.h" -static void usage() +static void usage(void) { printf("Usage: irm bind ap <ap>\n" " name <name>\n" diff --git a/src/tools/irm/irm_bind_api.c b/src/tools/irm/irm_bind_api.c index abc21b3d..54ecf51d 100644 --- a/src/tools/irm/irm_bind_api.c +++ b/src/tools/irm/irm_bind_api.c @@ -30,7 +30,7 @@ #include "irm_ops.h" #include "irm_utils.h" -static void usage() +static void usage(void) { printf("Usage: irm bind api <pid> name <name>\n"); } diff --git a/src/tools/irm/irm_bind_ipcp.c b/src/tools/irm/irm_bind_ipcp.c index 2d517994..f30c6ef8 100644 --- a/src/tools/irm/irm_bind_ipcp.c +++ b/src/tools/irm/irm_bind_ipcp.c @@ -30,7 +30,7 @@ #include "irm_ops.h" #include "irm_utils.h" -static void usage() +static void usage(void) { printf("Usage: irm bind ipcp <name> name <name>\n"); } diff --git a/src/tools/irm/irm_ipcp.c b/src/tools/irm/irm_ipcp.c index 9d7d9532..795281bb 100644 --- a/src/tools/irm/irm_ipcp.c +++ b/src/tools/irm/irm_ipcp.c @@ -25,7 +25,7 @@ #include "irm_ops.h" #include "irm_utils.h" -static void usage() +static void usage(void) { printf("Usage: irm ipcp [OPERATION]\n\n" "where OPERATION = {create destroy\n" diff --git a/src/tools/irm/irm_ipcp_bootstrap.c b/src/tools/irm/irm_ipcp_bootstrap.c index ba9b7e2e..cc1bf6f9 100644 --- a/src/tools/irm/irm_ipcp_bootstrap.c +++ b/src/tools/irm/irm_ipcp_bootstrap.c @@ -46,7 +46,7 @@ #define DEFAULT_MAX_PDU_SIZE 9000 #define DEFAULT_DDNS 0 -static void usage() +static void usage(void) { /* FIXME: Add dif_config stuff */ printf("Usage: irm ipcp bootstrap\n" diff --git a/src/tools/irm/irm_ipcp_create.c b/src/tools/irm/irm_ipcp_create.c index b43a544e..e9921112 100644 --- a/src/tools/irm/irm_ipcp_create.c +++ b/src/tools/irm/irm_ipcp_create.c @@ -33,7 +33,7 @@ #define SHIM_ETH_LLC "shim-eth-llc" #define LOCAL "local" -static void usage() +static void usage(void) { printf("Usage: irm ipcp create\n" " name <ipcp name>\n" diff --git a/src/tools/irm/irm_ipcp_destroy.c b/src/tools/irm/irm_ipcp_destroy.c index 9768b5e1..d3bc0cf3 100644 --- a/src/tools/irm/irm_ipcp_destroy.c +++ b/src/tools/irm/irm_ipcp_destroy.c @@ -28,7 +28,7 @@ #include "irm_ops.h" #include "irm_utils.h" -static void usage() +static void usage(void) { printf("Usage: irm ipcp destroy\n" " name <ipcp name>\n"); diff --git a/src/tools/irm/irm_ipcp_enroll.c b/src/tools/irm/irm_ipcp_enroll.c index 32d8be54..b5517bcd 100644 --- a/src/tools/irm/irm_ipcp_enroll.c +++ b/src/tools/irm/irm_ipcp_enroll.c @@ -28,7 +28,7 @@ #include "irm_ops.h" #include "irm_utils.h" -static void usage() +static void usage(void) { printf("Usage: irm ipcp enroll\n" " name <ipcp name>\n" diff --git a/src/tools/irm/irm_register.c b/src/tools/irm/irm_register.c index 62470d1d..22de402f 100644 --- a/src/tools/irm/irm_register.c +++ b/src/tools/irm/irm_register.c @@ -30,7 +30,7 @@ #define MAX_DIFS 128 -static void usage() +static void usage(void) { printf("Usage: irm register\n" " name <name>\n" diff --git a/src/tools/irm/irm_unbind.c b/src/tools/irm/irm_unbind.c index 7f2d0d7d..5d167e1c 100644 --- a/src/tools/irm/irm_unbind.c +++ b/src/tools/irm/irm_unbind.c @@ -28,7 +28,7 @@ #include "irm_ops.h" #include "irm_utils.h" -static void usage() +static void usage(void) { printf("Usage: irm unbind [OPERATION]\n" "where OPERATION = {ap api ipcp help}\n"); diff --git a/src/tools/irm/irm_unbind_ap.c b/src/tools/irm/irm_unbind_ap.c index bdfcbaad..8ad3d670 100644 --- a/src/tools/irm/irm_unbind_ap.c +++ b/src/tools/irm/irm_unbind_ap.c @@ -29,7 +29,7 @@ #include "irm_ops.h" #include "irm_utils.h" -static void usage() +static void usage(void) { printf("Usage: irm unbind ap <ap>\n" " [name <name>, omit: remove all AP info]\n"); diff --git a/src/tools/irm/irm_unbind_api.c b/src/tools/irm/irm_unbind_api.c index b69a4579..d332f438 100644 --- a/src/tools/irm/irm_unbind_api.c +++ b/src/tools/irm/irm_unbind_api.c @@ -30,7 +30,7 @@ #include "irm_ops.h" #include "irm_utils.h" -static void usage() +static void usage(void) { printf("Usage: irm unbind api <pid>\n" " [name <name>, omit: remove all AP-I info]\n"); diff --git a/src/tools/irm/irm_unbind_ipcp.c b/src/tools/irm/irm_unbind_ipcp.c index db310e05..33d7a818 100644 --- a/src/tools/irm/irm_unbind_ipcp.c +++ b/src/tools/irm/irm_unbind_ipcp.c @@ -30,7 +30,7 @@ #include "irm_ops.h" #include "irm_utils.h" -static void usage() +static void usage(void) { printf("Usage: irm unbind ipcp <name>\n" " [name <name>, omit: remove all information.\n"); diff --git a/src/tools/irm/irm_unregister.c b/src/tools/irm/irm_unregister.c index edcd42bb..12c1eb22 100644 --- a/src/tools/irm/irm_unregister.c +++ b/src/tools/irm/irm_unregister.c @@ -31,7 +31,7 @@ #define MAX_DIFS 128 -static void usage() +static void usage(void) { printf("Usage: irm unregister\n" " name <name>\n" diff --git a/src/tools/oping/oping.c b/src/tools/oping/oping.c index 0ca40326..b476b33a 100644 --- a/src/tools/oping/oping.c +++ b/src/tools/oping/oping.c @@ -48,10 +48,10 @@ struct c { /* stats */ int sent; int rcvd; - float rtt_min; - float rtt_max; - float rtt_avg; - float rtt_m2; + double rtt_min; + double rtt_max; + double rtt_avg; + double rtt_m2; flow_set_t * flows; @@ -82,7 +82,7 @@ struct oping_msg { #include "oping_client.c" #include "oping_server.c" -static void usage() +static void usage(void) { printf("Usage: oping [OPTION]...\n" "Checks liveness between a client and a server\n" diff --git a/src/tools/oping/oping_client.c b/src/tools/oping/oping_client.c index c2471b46..9f49a1df 100644 --- a/src/tools/oping/oping_client.c +++ b/src/tools/oping/oping_client.c @@ -62,8 +62,8 @@ void * reader(void * o) struct oping_msg * msg = (struct oping_msg *) buf; int fd = 0; int msg_len = 0; - float ms = 0; - float d = 0; + double ms = 0; + double d = 0; fqueue_t * fq = fqueue_create(); if (fq == NULL) return (void *) 1; @@ -83,7 +83,7 @@ void * reader(void * o) continue; } - if ((int) ntohl(msg->id) >= client.count) { + if (ntohl(msg->id) >= (ssize_t) client.count) { printf("Invalid id.\n"); continue; } @@ -94,7 +94,7 @@ void * reader(void * o) pthread_mutex_lock(&client.lock); ms = ts_diff_us(&client.times[ntohl(msg->id)], &now) - /1000.0; + / 1000.0; pthread_mutex_unlock(&client.lock); printf("%d bytes from %s: seq=%d time=%.3f ms\n", @@ -164,7 +164,7 @@ void * writer(void * o) return (void *) 0; } -int client_main() +int client_main(void) { struct sigaction sig_act; diff --git a/src/tools/oping/oping_server.c b/src/tools/oping/oping_server.c index 8680b11b..193b76d1 100644 --- a/src/tools/oping/oping_server.c +++ b/src/tools/oping/oping_server.c @@ -107,7 +107,7 @@ void * server_thread(void *o) server.times[fd] = now; pthread_mutex_unlock(&server.lock); - msg->type = htonl((uint32_t) ECHO_REPLY); + msg->type = htonl(ECHO_REPLY); if (flow_write(fd, buf, msg_len) < 0) { printf("Error writing to flow (fd %d).\n", fd); @@ -156,7 +156,7 @@ void * accept_thread(void * o) return (void *) 0; } -int server_main() +int server_main(void) { struct sigaction sig_act; |