summaryrefslogtreecommitdiffstats
path: root/extras/libmemif/src
diff options
context:
space:
mode:
Diffstat (limited to 'extras/libmemif/src')
-rw-r--r--extras/libmemif/src/libmemif.h4
-rw-r--r--extras/libmemif/src/main.c13
-rw-r--r--extras/libmemif/src/memif_private.h19
3 files changed, 21 insertions, 15 deletions
diff --git a/extras/libmemif/src/libmemif.h b/extras/libmemif/src/libmemif.h
index f5df79c9c69..a14a1025a54 100644
--- a/extras/libmemif/src/libmemif.h
+++ b/extras/libmemif/src/libmemif.h
@@ -169,7 +169,7 @@ typedef struct
memif_interface_id_t interface_id;
uint8_t interface_name[32];
- uint8_t instance_name[32];
+ uint8_t instance_name[32]; /*!< deprecated, will be removed in 2.0 */
memif_interface_mode_t mode:8;
} memif_conn_args_t;
@@ -308,7 +308,7 @@ int memif_get_details (memif_conn_handle_t conn, memif_details_t * md,
/** \brief Memif initialization
@param on_control_fd_update - if control fd updates inform user to watch new fd
- @param app_name - application name
+ @param app_name - application name (will be truncated to 32 chars)
if param on_control_fd_update is set to NULL,
libmemif will handle file descriptor event polling
diff --git a/extras/libmemif/src/main.c b/extras/libmemif/src/main.c
index 372bf756a02..cb24083c8e3 100644
--- a/extras/libmemif/src/main.c
+++ b/extras/libmemif/src/main.c
@@ -406,17 +406,16 @@ memif_init (memif_control_fd_update_t * on_control_fd_update, char *app_name)
{
int err = MEMIF_ERR_SUCCESS; /* 0 */
libmemif_main_t *lm = &libmemif_main;
+ memset (lm, 0, sizeof (libmemif_main_t));
if (app_name)
{
- lm->app_name = malloc (strlen (app_name) + sizeof (char));
- memset (lm->app_name, 0, strlen (app_name) + sizeof (char));
+ uint8_t len = (strlen (app_name) < MEMIF_NAME_LEN)
+ ? MEMIF_NAME_LEN : strlen (app_name);
strncpy ((char *) lm->app_name, app_name, strlen (app_name));
}
else
{
- lm->app_name = malloc (strlen (MEMIF_DEFAULT_APP_NAME) + sizeof (char));
- memset (lm->app_name, 0, strlen (app_name) + sizeof (char));
strncpy ((char *) lm->app_name, MEMIF_DEFAULT_APP_NAME,
strlen (MEMIF_DEFAULT_APP_NAME));
}
@@ -438,8 +437,6 @@ memif_init (memif_control_fd_update_t * on_control_fd_update, char *app_name)
DBG ("libmemif event polling initialized");
}
- memset (&lm->ms, 0, sizeof (memif_socket_t));
-
lm->control_list_len = 2;
lm->interrupt_list_len = 2;
lm->listener_list_len = 1;
@@ -490,7 +487,6 @@ memif_init (memif_control_fd_update_t * on_control_fd_update, char *app_name)
lm->arm.it_value.tv_nsec = 0;
lm->arm.it_interval.tv_sec = 2;
lm->arm.it_interval.tv_nsec = 0;
- memset (&lm->disarm, 0, sizeof (lm->disarm));
if (lm->control_fd_update (lm->timerfd, MEMIF_FD_EVENT_READ) < 0)
{
@@ -2096,9 +2092,6 @@ int
memif_cleanup ()
{
libmemif_main_t *lm = &libmemif_main;
- if (lm->app_name)
- free (lm->app_name);
- lm->app_name = NULL;
if (lm->control_list)
free (lm->control_list);
lm->control_list = NULL;
diff --git a/extras/libmemif/src/memif_private.h b/extras/libmemif/src/memif_private.h
index c213ee635aa..a512ed4eaaa 100644
--- a/extras/libmemif/src/memif_private.h
+++ b/extras/libmemif/src/memif_private.h
@@ -26,9 +26,14 @@
#include <inttypes.h>
#include <limits.h>
#include <sys/timerfd.h>
+#include <string.h>
#include <libmemif.h>
+#define MEMIF_NAME_LEN 32
+_Static_assert (strlen (MEMIF_DEFAULT_APP_NAME) <= MEMIF_NAME_LEN,
+ "MEMIF_DEFAULT_APP_NAME max length is 32");
+
#define MEMIF_DEFAULT_SOCKET_DIR "/run/vpp"
#define MEMIF_DEFAULT_SOCKET_FILENAME "memif.sock"
#define MEMIF_DEFAULT_RING_SIZE 1024
@@ -142,8 +147,8 @@ typedef struct memif_connection
/* connection message queue */
memif_msg_queue_elt_t *msg_queue;
- uint8_t remote_if_name[32];
- uint8_t remote_name[32];
+ uint8_t remote_if_name[MEMIF_NAME_LEN];
+ uint8_t remote_name[MEMIF_NAME_LEN];
uint8_t remote_disconnect_string[96];
memif_region_t *regions;
@@ -186,7 +191,7 @@ typedef struct
int timerfd;
struct itimerspec arm, disarm;
uint16_t disconn_slaves;
- uint8_t *app_name;
+ uint8_t app_name[MEMIF_NAME_LEN];
/* master implementation... */
memif_socket_t ms;
@@ -237,11 +242,13 @@ int free_list_elt (memif_list_elt_t * list, uint16_t len, int key);
#endif
#endif
+#ifndef HAVE_MEMFD_CREATE
static inline int
memfd_create (const char *name, unsigned int flags)
{
return syscall (__NR_memfd_create, name, flags);
}
+#endif
static inline void *
memif_get_buffer (memif_connection_t * conn, memif_ring_t * ring,
@@ -254,7 +261,12 @@ memif_get_buffer (memif_connection_t * conn, memif_ring_t * ring,
#ifndef F_LINUX_SPECIFIC_BASE
#define F_LINUX_SPECIFIC_BASE 1024
#endif
+
+#ifndef MFD_ALLOW_SEALING
#define MFD_ALLOW_SEALING 0x0002U
+#endif
+
+#ifndef F_ADD_SEALS
#define F_ADD_SEALS (F_LINUX_SPECIFIC_BASE + 9)
#define F_GET_SEALS (F_LINUX_SPECIFIC_BASE + 10)
@@ -262,5 +274,6 @@ memif_get_buffer (memif_connection_t * conn, memif_ring_t * ring,
#define F_SEAL_SHRINK 0x0002 /* prevent file from shrinking */
#define F_SEAL_GROW 0x0004 /* prevent file from growing */
#define F_SEAL_WRITE 0x0008 /* prevent writes */
+#endif
#endif /* _MEMIF_PRIVATE_H_ */