static_fn int
memif_msg_enq_ack (memif_connection_t * c)
{
- libmemif_main_t *lm = &libmemif_main;
+ libmemif_main_t *lm = get_libmemif_main (c->args.socket);
memif_msg_queue_elt_t *e =
(memif_msg_queue_elt_t *) lm->alloc (sizeof (memif_msg_queue_elt_t));
if (e == NULL)
}
static_fn int
-memif_msg_send_hello (int fd)
+memif_msg_send_hello (libmemif_main_t * lm, int fd)
{
- libmemif_main_t *lm = &libmemif_main;
memif_msg_t msg = { 0 };
memif_msg_hello_t *h = &msg.hello;
msg.type = MEMIF_MSG_TYPE_HELLO;
h->max_region = MEMIF_MAX_REGION;
h->max_log2_ring_size = MEMIF_MAX_LOG2_RING_SIZE;
- strncpy ((char *) h->name, (char *) lm->app_name,
- strlen ((char *) lm->app_name));
+ strlcpy ((char *) h->name, (char *) lm->app_name, sizeof (h->name));
/* msg hello is not enqueued but sent directly,
because it is the first msg to be sent */
static_fn int
memif_msg_enq_init (memif_connection_t * c)
{
- libmemif_main_t *lm = &libmemif_main;
+ libmemif_main_t *lm = get_libmemif_main (c->args.socket);
memif_msg_queue_elt_t *e =
(memif_msg_queue_elt_t *) lm->alloc (sizeof (memif_msg_queue_elt_t));
if (e == NULL)
i->id = c->args.interface_id;
i->mode = c->args.mode;
- strncpy ((char *) i->name, (char *) lm->app_name,
- strlen ((char *) lm->app_name));
+ strlcpy ((char *) i->name, (char *) lm->app_name, sizeof (i->name));
if (strlen ((char *) c->args.secret) > 0)
strncpy ((char *) i->secret, (char *) c->args.secret, sizeof (i->secret));
static_fn int
memif_msg_enq_add_region (memif_connection_t * c, uint8_t region_index)
{
- libmemif_main_t *lm = &libmemif_main;
+ libmemif_main_t *lm = get_libmemif_main (c->args.socket);
memif_region_t *mr = &c->regions[region_index];
memif_msg_queue_elt_t *e =
static_fn int
memif_msg_enq_add_ring (memif_connection_t * c, uint8_t index, uint8_t dir)
{
- libmemif_main_t *lm = &libmemif_main;
+ libmemif_main_t *lm = get_libmemif_main (c->args.socket);
memif_msg_queue_elt_t *e =
(memif_msg_queue_elt_t *) lm->alloc (sizeof (memif_msg_queue_elt_t));
if (e == NULL)
static_fn int
memif_msg_enq_connect (memif_connection_t * c)
{
- libmemif_main_t *lm = &libmemif_main;
+ libmemif_main_t *lm = get_libmemif_main (c->args.socket);
memif_msg_queue_elt_t *e =
(memif_msg_queue_elt_t *) lm->alloc (sizeof (memif_msg_queue_elt_t));
if (e == NULL)
e->msg.type = MEMIF_MSG_TYPE_CONNECT;
e->fd = -1;
- strncpy ((char *) cm->if_name, (char *) c->args.interface_name,
- strlen ((char *) c->args.interface_name));
+ strlcpy ((char *) cm->if_name, (char *) c->args.interface_name,
+ sizeof (cm->if_name));
e->next = NULL;
if (c->msg_queue == NULL)
static_fn int
memif_msg_enq_connected (memif_connection_t * c)
{
- libmemif_main_t *lm = &libmemif_main;
+ libmemif_main_t *lm = get_libmemif_main (c->args.socket);
memif_msg_queue_elt_t *e =
(memif_msg_queue_elt_t *) lm->alloc (sizeof (memif_msg_queue_elt_t));
if (e == NULL)
e->msg.type = MEMIF_MSG_TYPE_CONNECTED;
e->fd = -1;
- strncpy ((char *) cm->if_name, (char *) c->args.interface_name,
- strlen ((char *) c->args.interface_name));
+ strlcpy ((char *) cm->if_name, (char *) c->args.interface_name,
+ sizeof (cm->if_name));
e->next = NULL;
if (c->msg_queue == NULL)
}
/* immediately send disconnect msg */
- /* specifie protocol for disconnect msg err_code
+ /* specify protocol for disconnect msg err_code
so that it will be compatible with VPP? (header/doc) */
int
memif_msg_send_disconnect (int fd, uint8_t * err_string, uint32_t err_code)
msg.type = MEMIF_MSG_TYPE_DISCONNECT;
d->code = err_code;
uint16_t l = strlen ((char *) err_string);
- if (l > 96)
+ if (l > sizeof (d->string) - 1)
{
- DBG ("Disconnect string too long. Sending first 96 characters.");
- l = 96;
+ DBG ("Disconnect string too long. Sending the first %d characters.",
+ sizeof (d->string) - 1);
}
- strncpy ((char *) d->string, (char *) err_string, l);
+ strlcpy ((char *) d->string, (char *) err_string, sizeof (d->string));
return memif_msg_send (fd, &msg, -1);
}
c->run_args.log2_ring_size = memif_min (h->max_log2_ring_size,
c->args.log2_ring_size);
c->run_args.buffer_size = c->args.buffer_size;
- strncpy ((char *) c->remote_name, (char *) h->name,
- strlen ((char *) h->name));
+ strlcpy ((char *) c->remote_name, (char *) h->name, sizeof (c->remote_name));
return MEMIF_ERR_SUCCESS; /* 0 */
}
memif_list_elt_t *elt = NULL;
memif_list_elt_t elt2;
memif_connection_t *c = NULL;
- libmemif_main_t *lm = &libmemif_main;
+ libmemif_main_t *lm = get_libmemif_main (ms);
uint8_t err_string[96];
memset (err_string, 0, sizeof (char) * 96);
int err = MEMIF_ERR_SUCCESS; /* 0 */
+
if (i->version != MEMIF_VERSION)
{
DBG ("MEMIF_VER_ERR");
goto error;
}
- strncpy ((char *) c->remote_name, (char *) i->name,
- strlen ((char *) i->name));
+ strlcpy ((char *) c->remote_name, (char *) i->name, sizeof (c->remote_name));
if (strlen ((char *) c->args.secret) > 0)
{
elt2.key = c->fd;
elt2.data_struct = c;
- add_list_elt (&elt2, &lm->control_list, &lm->control_list_len);
+ add_list_elt (lm, &elt2, &lm->control_list, &lm->control_list_len);
free_list_elt (lm->pending_list, lm->pending_list_len, fd);
return err;
error:
memif_msg_send_disconnect (fd, err_string, 0);
- lm->control_fd_update (fd, MEMIF_FD_EVENT_DEL);
+ lm->control_fd_update (fd, MEMIF_FD_EVENT_DEL, lm->private_ctx);
free_list_elt (lm->pending_list, lm->pending_list_len, fd);
close (fd);
fd = -1;
memif_msg_receive_add_region (memif_connection_t * c, memif_msg_t * msg,
int fd)
{
- libmemif_main_t *lm = &libmemif_main;
+ libmemif_main_t *lm = get_libmemif_main (c->args.socket);
memif_msg_add_region_t *ar = &msg->add_region;
memif_region_t *mr;
static_fn int
memif_msg_receive_add_ring (memif_connection_t * c, memif_msg_t * msg, int fd)
{
- libmemif_main_t *lm = &libmemif_main;
+ libmemif_main_t *lm = get_libmemif_main (c->args.socket);
memif_msg_add_ring_t *ar = &msg->add_ring;
memif_msg_receive_connect (memif_connection_t * c, memif_msg_t * msg)
{
memif_msg_connect_t *cm = &msg->connect;
- libmemif_main_t *lm = &libmemif_main;
+ libmemif_main_t *lm = get_libmemif_main (c->args.socket);
memif_list_elt_t elt;
int err;
if (err != MEMIF_ERR_SUCCESS)
return err;
- strncpy ((char *) c->remote_if_name, (char *) cm->if_name,
- strlen ((char *) cm->if_name));
+ strlcpy ((char *) c->remote_if_name, (char *) cm->if_name,
+ sizeof (c->remote_if_name));
int i;
if (c->on_interrupt != NULL)
{
elt.key = c->rx_queues[i].int_fd;
elt.data_struct = c;
- add_list_elt (&elt, &lm->interrupt_list, &lm->interrupt_list_len);
+ add_list_elt (lm, &elt, &lm->interrupt_list,
+ &lm->interrupt_list_len);
- lm->control_fd_update (c->rx_queues[i].int_fd, MEMIF_FD_EVENT_READ);
+ lm->control_fd_update (c->rx_queues[i].int_fd, MEMIF_FD_EVENT_READ,
+ lm->private_ctx);
}
}
memif_msg_receive_connected (memif_connection_t * c, memif_msg_t * msg)
{
memif_msg_connect_t *cm = &msg->connect;
- libmemif_main_t *lm = &libmemif_main;
+ libmemif_main_t *lm = get_libmemif_main (c->args.socket);
int err;
err = memif_connect1 (c);
return err;
strncpy ((char *) c->remote_if_name, (char *) cm->if_name,
- strlen ((char *) cm->if_name));
+ sizeof (c->remote_if_name));
int i;
if (c->on_interrupt != NULL)
{
for (i = 0; i < c->run_args.num_s2m_rings; i++)
{
- lm->control_fd_update (c->rx_queues[i].int_fd, MEMIF_FD_EVENT_READ);
+ lm->control_fd_update (c->rx_queues[i].int_fd, MEMIF_FD_EVENT_READ,
+ lm->private_ctx);
}
}
memset (c->remote_disconnect_string, 0,
sizeof (c->remote_disconnect_string));
strncpy ((char *) c->remote_disconnect_string, (char *) d->string,
- strlen ((char *) d->string));
+ sizeof (c->remote_disconnect_string));
/* on returning error, handle function will call memif_disconnect () */
DBG ("disconnect received: %s, mode: %d",
}
static_fn int
-memif_msg_receive (int ifd)
+memif_msg_receive (libmemif_main_t * lm, int ifd)
{
char ctl[CMSG_SPACE (sizeof (int)) +
CMSG_SPACE (sizeof (struct ucred))] = { 0 };
int err = MEMIF_ERR_SUCCESS; /* 0 */
int fd = -1;
int i;
- libmemif_main_t *lm = &libmemif_main;
memif_connection_t *c = NULL;
memif_socket_t *ms = NULL;
memif_list_elt_t *elt = NULL;
if (c != NULL)
c->flags |= MEMIF_CONNECTION_FLAG_WRITE;
-/* libmemif_main_t *lm = &libmemif_main;
- lm->control_fd_update (c->fd, MEMIF_FD_EVENT_READ | MEMIF_FD_EVENT_MOD); */
+
return MEMIF_ERR_SUCCESS; /* 0 */
}
int
memif_conn_fd_read_ready (memif_connection_t * c)
{
+ libmemif_main_t *lm = get_libmemif_main (c->args.socket);
int err;
- err = memif_msg_receive (c->fd);
+
+ err = memif_msg_receive (lm, c->fd);
if (err != 0)
{
err = memif_disconnect_internal (c);
int
memif_conn_fd_write_ready (memif_connection_t * c)
{
- libmemif_main_t *lm = &libmemif_main;
+ libmemif_main_t *lm = get_libmemif_main (c->args.socket);
int err = MEMIF_ERR_SUCCESS; /* 0 */
c->msg_queue = c->msg_queue->next;
c->flags &= ~MEMIF_CONNECTION_FLAG_WRITE;
-/*
- libmemif_main_t *lm = &libmemif_main;
- lm->control_fd_update (c->fd,
- MEMIF_FD_EVENT_READ | MEMIF_FD_EVENT_WRITE | MEMIF_FD_EVENT_MOD);
-*/
err = memif_msg_send (c->fd, &e->msg, e->fd);
lm->free (e);
goto done;
int addr_len;
struct sockaddr_un client;
int conn_fd;
- libmemif_main_t *lm = &libmemif_main;
+ libmemif_main_t *lm = get_libmemif_main (ms);
DBG ("accept called");
elt.key = conn_fd;
elt.data_struct = ms;
- add_list_elt (&elt, &lm->pending_list, &lm->pending_list_len);
- lm->control_fd_update (conn_fd, MEMIF_FD_EVENT_READ | MEMIF_FD_EVENT_WRITE);
+ add_list_elt (lm, &elt, &lm->pending_list, &lm->pending_list_len);
+ lm->control_fd_update (conn_fd, MEMIF_FD_EVENT_READ | MEMIF_FD_EVENT_WRITE,
+ lm->private_ctx);
- return memif_msg_send_hello (conn_fd);
+ return memif_msg_send_hello (lm, conn_fd);
}
int
-memif_read_ready (int fd)
+memif_read_ready (libmemif_main_t * lm, int fd)
{
int err;
- err = memif_msg_receive (fd);
+ err = memif_msg_receive (lm, fd);
return err;
}