diff options
author | Florin Coras <fcoras@cisco.com> | 2018-08-03 02:50:43 -0700 |
---|---|---|
committer | Dave Barach <openvpp@barachs.net> | 2018-08-04 16:00:32 +0000 |
commit | 466f289c27f290a2764a82f57f5c20d080227ead (patch) | |
tree | f37fd2763c95e3139d57423d06ae993453dc382c | |
parent | e7a9b3d2545c00689fe7547e7d807fe4a9b3365d (diff) |
socket api: multiple fds in one msg
Change-Id: I77a6e092a42290eed7201ad4a62e0d00ef997d2b
Signed-off-by: Florin Coras <fcoras@cisco.com>
-rw-r--r-- | src/tests/vnet/session/tcp_echo.c | 4 | ||||
-rw-r--r-- | src/vlibmemory/api.h | 9 | ||||
-rw-r--r-- | src/vlibmemory/socket_api.c | 14 | ||||
-rw-r--r-- | src/vlibmemory/socket_api.h | 4 | ||||
-rw-r--r-- | src/vlibmemory/socket_client.c | 13 | ||||
-rw-r--r-- | src/vlibmemory/socket_client.h | 2 | ||||
-rwxr-xr-x | src/vnet/session/session_api.c | 3 |
7 files changed, 26 insertions, 23 deletions
diff --git a/src/tests/vnet/session/tcp_echo.c b/src/tests/vnet/session/tcp_echo.c index 626ef847e16..6a5d8c4b034 100644 --- a/src/tests/vnet/session/tcp_echo.c +++ b/src/tests/vnet/session/tcp_echo.c @@ -353,7 +353,7 @@ memfd_segment_attach (void) clib_error_t *error; int rv; - if ((error = vl_socket_client_recv_fd_msg (&ssvm->fd, 5))) + if ((error = vl_socket_client_recv_fd_msg (&ssvm->fd, 1, 5))) { clib_error_report (error); return -1; @@ -379,7 +379,7 @@ fifo_segment_attach (char *name, u32 size, ssvm_segment_type_t type) if (type == SSVM_SEGMENT_MEMFD) { - if ((error = vl_socket_client_recv_fd_msg (&a->memfd_fd, 5))) + if ((error = vl_socket_client_recv_fd_msg (&a->memfd_fd, 1, 5))) { clib_error_report (error); return -1; diff --git a/src/vlibmemory/api.h b/src/vlibmemory/api.h index 8d2b191fb81..2146b16c5b0 100644 --- a/src/vlibmemory/api.h +++ b/src/vlibmemory/api.h @@ -82,20 +82,21 @@ vl_api_registration_del_file (vl_api_registration_t * reg) } always_inline clib_error_t * -vl_api_send_fd_msg (vl_api_registration_t * reg, int fd_to_send) +vl_api_send_fd_msg (vl_api_registration_t * reg, int fds[], int n_fds) { clib_file_t *cf = vl_api_registration_file (reg); if (cf) - return vl_sock_api_send_fd_msg (cf->file_descriptor, fd_to_send); + return vl_sock_api_send_fd_msg (cf->file_descriptor, fds, n_fds); return 0; } always_inline clib_error_t * -vl_api_recv_fd_msg (vl_api_registration_t * reg, int *fd_to_recv, u32 wait) +vl_api_recv_fd_msg (vl_api_registration_t * reg, int fds[], int n_fds, + u32 wait) { clib_file_t *cf = vl_api_registration_file (reg); if (cf) - return vl_sock_api_recv_fd_msg (cf->file_descriptor, fd_to_recv, wait); + return vl_sock_api_recv_fd_msg (cf->file_descriptor, fds, n_fds, wait); return 0; } diff --git a/src/vlibmemory/socket_api.c b/src/vlibmemory/socket_api.c index 7d271276be2..5587611d65a 100644 --- a/src/vlibmemory/socket_api.c +++ b/src/vlibmemory/socket_api.c @@ -449,12 +449,13 @@ vl_api_sockclnt_delete_t_handler (vl_api_sockclnt_delete_t * mp) } clib_error_t * -vl_sock_api_send_fd_msg (int socket_fd, int fd_to_share) +vl_sock_api_send_fd_msg (int socket_fd, int fds[], int n_fds) { struct msghdr mh = { 0 }; struct iovec iov[1]; - char ctl[CMSG_SPACE (sizeof (int))]; - char *msg = "memfd"; + char ctl[CMSG_SPACE (sizeof (int)) * n_fds]; + struct cmsghdr *cmsg; + char *msg = "fdmsg"; int rv; iov[0].iov_base = msg; @@ -462,15 +463,14 @@ vl_sock_api_send_fd_msg (int socket_fd, int fd_to_share) mh.msg_iov = iov; mh.msg_iovlen = 1; - struct cmsghdr *cmsg; memset (&ctl, 0, sizeof (ctl)); mh.msg_control = ctl; mh.msg_controllen = sizeof (ctl); cmsg = CMSG_FIRSTHDR (&mh); - cmsg->cmsg_len = CMSG_LEN (sizeof (int)); + cmsg->cmsg_len = CMSG_LEN (sizeof (int) * n_fds); cmsg->cmsg_level = SOL_SOCKET; cmsg->cmsg_type = SCM_RIGHTS; - memcpy (CMSG_DATA (cmsg), &fd_to_share, sizeof (int)); + memcpy (CMSG_DATA (cmsg), fds, sizeof (int) * n_fds); rv = sendmsg (socket_fd, &mh, 0); if (rv < 0) @@ -629,7 +629,7 @@ reply: cf->write_function (cf); /* Send the magic "here's your sign (aka fd)" socket message */ - vl_sock_api_send_fd_msg (cf->file_descriptor, memfd->fd); + vl_sock_api_send_fd_msg (cf->file_descriptor, &memfd->fd, 1); } #define foreach_vlib_api_msg \ diff --git a/src/vlibmemory/socket_api.h b/src/vlibmemory/socket_api.h index d12b427a6a4..86fd600edbb 100644 --- a/src/vlibmemory/socket_api.h +++ b/src/vlibmemory/socket_api.h @@ -77,8 +77,8 @@ void vl_socket_process_api_msg (clib_file_t * uf, vl_api_registration_t * rp, i8 * input_v); void vl_sock_api_dump_clients (vlib_main_t * vm, api_main_t * am); clib_error_t *vl_sock_api_init (vlib_main_t * vm); -clib_error_t *vl_sock_api_send_fd_msg (int socket_fd, int fd_to_share); -clib_error_t *vl_sock_api_recv_fd_msg (int socket_fd, int *fd_to_share, +clib_error_t *vl_sock_api_send_fd_msg (int socket_fd, int fds[], int n_fds); +clib_error_t *vl_sock_api_recv_fd_msg (int socket_fd, int fds[], int n_fds, u32 wait); #endif /* SRC_VLIBMEMORY_SOCKET_API_H_ */ diff --git a/src/vlibmemory/socket_client.c b/src/vlibmemory/socket_client.c index a49d335e732..3d933deecb6 100644 --- a/src/vlibmemory/socket_client.c +++ b/src/vlibmemory/socket_client.c @@ -177,11 +177,12 @@ vl_socket_client_enable_disable (int enable) } clib_error_t * -vl_sock_api_recv_fd_msg (int socket_fd, int *my_fd, u32 wait) +vl_sock_api_recv_fd_msg (int socket_fd, int fds[], int n_fds, u32 wait) { socket_client_main_t *scm = &socket_client_main; char msgbuf[16]; - char ctl[CMSG_SPACE (sizeof (int)) + CMSG_SPACE (sizeof (struct ucred))]; + char ctl[CMSG_SPACE (sizeof (int) * n_fds) + + CMSG_SPACE (sizeof (struct ucred))]; struct msghdr mh = { 0 }; struct iovec iov[1]; ssize_t size = 0; @@ -231,7 +232,7 @@ vl_sock_api_recv_fd_msg (int socket_fd, int *my_fd, u32 wait) } else if (cmsg->cmsg_type == SCM_RIGHTS) { - clib_memcpy (my_fd, CMSG_DATA (cmsg), sizeof (int)); + clib_memcpy (fds, CMSG_DATA (cmsg), sizeof (int) * n_fds); } } cmsg = CMSG_NXTHDR (&mh, cmsg); @@ -259,7 +260,7 @@ static void vl_api_sock_init_shm_reply_t_handler /* * Check the socket for the magic fd */ - error = vl_sock_api_recv_fd_msg (scm->socket_fd, &my_fd, 5); + error = vl_sock_api_recv_fd_msg (scm->socket_fd, &my_fd, 1, 5); if (error) { clib_error_report (error); @@ -409,12 +410,12 @@ vl_socket_client_init_shm (vl_api_shm_elem_config_t * config) } clib_error_t * -vl_socket_client_recv_fd_msg (int *fd_to_recv, u32 wait) +vl_socket_client_recv_fd_msg (int fds[], int n_fds, u32 wait) { socket_client_main_t *scm = &socket_client_main; if (!scm->socket_fd) return clib_error_return (0, "no socket"); - return vl_sock_api_recv_fd_msg (scm->client_socket.fd, fd_to_recv, wait); + return vl_sock_api_recv_fd_msg (scm->client_socket.fd, fds, n_fds, wait); } /* diff --git a/src/vlibmemory/socket_client.h b/src/vlibmemory/socket_client.h index 74be5a96f53..5612a9809a5 100644 --- a/src/vlibmemory/socket_client.h +++ b/src/vlibmemory/socket_client.h @@ -53,7 +53,7 @@ int vl_socket_client_write (void); void vl_socket_client_enable_disable (int enable); void *vl_socket_client_msg_alloc (int nbytes); int vl_socket_client_init_shm (vl_api_shm_elem_config_t * config); -clib_error_t *vl_socket_client_recv_fd_msg (int *fd_to_recv, u32 wait); +clib_error_t *vl_socket_client_recv_fd_msg (int fds[], int n_fds, u32 wait); #endif /* SRC_VLIBMEMORY_SOCKET_CLIENT_H_ */ diff --git a/src/vnet/session/session_api.c b/src/vnet/session/session_api.c index 8585b57b030..76c10210a50 100755 --- a/src/vnet/session/session_api.c +++ b/src/vnet/session/session_api.c @@ -63,12 +63,13 @@ static int session_send_memfd_fd (vl_api_registration_t * reg, const ssvm_private_t * sp) { clib_error_t *error; + int fd = sp->fd; if (vl_api_registration_file_index (reg) == VL_API_INVALID_FI) { clib_warning ("can't send memfd fd"); return -1; } - error = vl_api_send_fd_msg (reg, sp->fd); + error = vl_api_send_fd_msg (reg, &fd, 1); if (error) { clib_error_report (error); |