summaryrefslogtreecommitdiffstats
path: root/extras/libmemif/src
diff options
context:
space:
mode:
Diffstat (limited to 'extras/libmemif/src')
-rw-r--r--extras/libmemif/src/CMakeLists.txt43
-rw-r--r--extras/libmemif/src/main.c34
-rw-r--r--extras/libmemif/src/memif.h2
-rw-r--r--extras/libmemif/src/socket.c4
4 files changed, 62 insertions, 21 deletions
diff --git a/extras/libmemif/src/CMakeLists.txt b/extras/libmemif/src/CMakeLists.txt
new file mode 100644
index 00000000000..09a2e4e6005
--- /dev/null
+++ b/extras/libmemif/src/CMakeLists.txt
@@ -0,0 +1,43 @@
+# Copyright (c) 2017 Cisco and/or its affiliates.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at:
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
+
+set(HEADERS_DIR ${CMAKE_CURRENT_SOURCE_DIR})
+
+list(APPEND MEMIF_HEADERS
+ libmemif.h
+ memif.h
+)
+
+list(APPEND MEMIF_PRIVATE_HEADERS
+ memif_private.h
+ socket.h
+)
+
+list(APPEND MEMIF_SOURCES
+ main.c
+ socket.c
+)
+
+include_directories(${HEADERS_DIR})
+
+add_vpp_library(${LIBMEMIF}
+ SOURCES ${MEMIF_SOURCES}
+
+ INSTALL_HEADERS ${MEMIF_HEADERS}
+
+ LINK_LIBRARIES ${CMAKE_THREAD_LIBS_INIT}
+
+ COMPONENT libmemif
+)
diff --git a/extras/libmemif/src/main.c b/extras/libmemif/src/main.c
index 782442d440b..c6a62bb2ddc 100644
--- a/extras/libmemif/src/main.c
+++ b/extras/libmemif/src/main.c
@@ -632,7 +632,7 @@ memif_create (memif_conn_handle_t * c, memif_conn_args_t * args,
memif_interrupt_t * on_interrupt, void *private_ctx)
{
libmemif_main_t *lm = &libmemif_main;
- int err, i, index, sockfd = -1;
+ int err, i, index = 0, sockfd = -1;
memif_list_elt_t list_elt;
memif_connection_t *conn = (memif_connection_t *) * c;
if (conn != NULL)
@@ -892,7 +892,7 @@ error:
int
memif_control_fd_handler (int fd, uint8_t events)
{
- int i, rv, sockfd = -1, err = MEMIF_ERR_SUCCESS; /* 0 */
+ int i, sockfd = -1, err = MEMIF_ERR_SUCCESS; /* 0 */
uint16_t num;
memif_list_elt_t *e = NULL;
memif_connection_t *conn;
@@ -902,6 +902,10 @@ memif_control_fd_handler (int fd, uint8_t events)
uint64_t b;
ssize_t size;
size = read (fd, &b, sizeof (b));
+
+ if (size == -1)
+ goto error;
+
for (i = 0; i < lm->control_list_len; i++)
{
if ((lm->control_list[i].key < 0)
@@ -1042,11 +1046,8 @@ error:
int
memif_poll_event (int timeout)
{
- libmemif_main_t *lm = &libmemif_main;
- memif_list_elt_t *elt;
- struct epoll_event evt, *e;
- int en = 0, err = MEMIF_ERR_SUCCESS, i = 0; /* 0 */
- uint16_t num;
+ struct epoll_event evt;
+ int en = 0, err = MEMIF_ERR_SUCCESS; /* 0 */
uint32_t events = 0;
uint64_t counter = 0;
ssize_t r = 0;
@@ -1066,6 +1067,9 @@ memif_poll_event (int timeout)
if (evt.data.fd == poll_cancel_fd)
{
r = read (evt.data.fd, &counter, sizeof (counter));
+ if (r == -1)
+ return MEMIF_ERR_DISCONNECTED;
+
return MEMIF_ERR_POLL_CANCEL;
}
if (evt.events & EPOLLIN)
@@ -1308,7 +1312,6 @@ memif_connect1 (memif_connection_t * c)
memif_region_t *mr;
memif_queue_t *mq;
int i;
- uint16_t num;
for (i = 0; i < c->regions_num; i++)
{
@@ -1530,11 +1533,8 @@ memif_init_queues (libmemif_main_t * lm, memif_connection_t * conn)
int
memif_init_regions_and_queues (memif_connection_t * conn)
{
- memif_ring_t *ring = NULL;
memif_region_t *r;
- int i, j;
libmemif_main_t *lm = &libmemif_main;
- memif_list_elt_t e;
/* region 0. rings */
memif_add_region (lm, conn, /* has_buffers */ 0);
@@ -1595,7 +1595,7 @@ memif_buffer_enq_tx (memif_conn_handle_t conn, uint16_t qid,
uint16_t mask = (1 << mq->log2_ring_size) - 1;
uint16_t ring_size;
uint16_t slot, ns;
- int i, err = MEMIF_ERR_SUCCESS; /* 0 */
+ int err = MEMIF_ERR_SUCCESS; /* 0 */
*count_out = 0;
ring_size = (1 << mq->log2_ring_size);
@@ -1645,7 +1645,6 @@ memif_buffer_enq_tx (memif_conn_handle_t conn, uint16_t qid,
err = MEMIF_ERR_NOBUF_RING;
}
-error:
return err;
}
@@ -1670,12 +1669,12 @@ memif_buffer_alloc (memif_conn_handle_t conn, uint16_t qid,
libmemif_main_t *lm = &libmemif_main;
memif_queue_t *mq = &c->tx_queues[qid];
memif_ring_t *ring = mq->ring;
- memif_buffer_t *b0, *b1;
+ memif_buffer_t *b0;
uint16_t mask = (1 << mq->log2_ring_size) - 1;
uint32_t offset_mask = c->run_args.buffer_size - 1;
uint16_t ring_size;
uint16_t slot, ns;
- int i, err = MEMIF_ERR_SUCCESS; /* 0 */
+ int err = MEMIF_ERR_SUCCESS; /* 0 */
uint16_t dst_left, src_left;
uint16_t saved_count;
memif_buffer_t *saved_b;
@@ -1772,7 +1771,6 @@ no_ns:
err = MEMIF_ERR_NOBUF_RING;
}
-error:
return err;
}
@@ -1919,7 +1917,7 @@ memif_rx_burst (memif_conn_handle_t conn, uint16_t qid,
uint16_t cur_slot, last_slot;
uint16_t ns;
uint16_t mask = (1 << mq->log2_ring_size) - 1;
- memif_buffer_t *b0, *b1;
+ memif_buffer_t *b0;
*rx = 0;
uint64_t b;
@@ -1992,7 +1990,7 @@ memif_get_details (memif_conn_handle_t conn, memif_details_t * md,
return MEMIF_ERR_NOCONN;
int err = MEMIF_ERR_SUCCESS, i;
- ssize_t l0, l1, total_l;
+ ssize_t l0, l1;
l0 = 0;
l1 = strlen ((char *) c->args.interface_name);
diff --git a/extras/libmemif/src/memif.h b/extras/libmemif/src/memif.h
index 3fbce91d68f..776baaf8a3a 100644
--- a/extras/libmemif/src/memif.h
+++ b/extras/libmemif/src/memif.h
@@ -18,6 +18,8 @@
#ifndef _MEMIF_H_
#define _MEMIF_H_
+#include <stdint.h>
+
#ifndef MEMIF_CACHELINE_SIZE
#define MEMIF_CACHELINE_SIZE 64
#endif
diff --git a/extras/libmemif/src/socket.c b/extras/libmemif/src/socket.c
index b25b0261d77..e1c3bd4a257 100644
--- a/extras/libmemif/src/socket.c
+++ b/extras/libmemif/src/socket.c
@@ -375,7 +375,6 @@ memif_msg_receive_init (memif_socket_t * ms, int fd, memif_msg_t * msg)
uint8_t err_string[96];
memset (err_string, 0, sizeof (char) * 96);
int err = MEMIF_ERR_SUCCESS; /* 0 */
- int err_disc;
if (i->version != MEMIF_VERSION)
{
DBG ("MEMIF_VER_ERR");
@@ -691,7 +690,6 @@ memif_msg_receive (int ifd)
return MEMIF_ERR_MFMSG;
}
- struct ucred *cr = 0;
struct cmsghdr *cmsg;
cmsg = CMSG_FIRSTHDR (&mh);
@@ -701,7 +699,7 @@ memif_msg_receive (int ifd)
{
if (cmsg->cmsg_type == SCM_CREDENTIALS)
{
- cr = (struct ucred *) CMSG_DATA (cmsg);
+ /* Do nothing */ ;
}
else if (cmsg->cmsg_type == SCM_RIGHTS)
{