socket api: multiple fds in one msg

Change-Id: I77a6e092a42290eed7201ad4a62e0d00ef997d2b
Signed-off-by: Florin Coras <fcoras@cisco.com>
diff --git a/src/vlibmemory/socket_api.c b/src/vlibmemory/socket_api.c
index 7d27127..5587611 100644
--- a/src/vlibmemory/socket_api.c
+++ b/src/vlibmemory/socket_api.c
@@ -449,12 +449,13 @@
 }
 
 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 @@
   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 @@
   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                    	\