2 * Copyright (c) 2016 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
22 #include <sys/resource.h>
23 #include <netinet/tcp.h>
25 #include <vcl/vcom_socket_wrapper.h>
29 #include <vcl/vppcom.h>
30 #include <vppinfra/time.h>
31 #include <vppinfra/bitmap.h>
33 #define HAVE_CONSTRUCTOR_ATTRIBUTE
34 #ifdef HAVE_CONSTRUCTOR_ATTRIBUTE
35 #define CONSTRUCTOR_ATTRIBUTE \
36 __attribute__ ((constructor))
38 #define CONSTRUCTOR_ATTRIBUTE
39 #endif /* HAVE_CONSTRUCTOR_ATTRIBUTE */
41 #define HAVE_DESTRUCTOR_ATTRIBUTE
42 #ifdef HAVE_DESTRUCTOR_ATTRIBUTE
43 #define DESTRUCTOR_ATTRIBUTE \
44 __attribute__ ((destructor))
46 #define DESTRUCTOR_ATTRIBUTE
52 char app_name[VCOM_APP_NAME_MAX];
57 clib_time_t clib_time;
58 clib_bitmap_t *rd_bitmap;
59 clib_bitmap_t *wr_bitmap;
60 clib_bitmap_t *ex_bitmap;
61 clib_bitmap_t *sid_rd_bitmap;
62 clib_bitmap_t *sid_wr_bitmap;
63 clib_bitmap_t *sid_ex_bitmap;
64 clib_bitmap_t *libc_rd_bitmap;
65 clib_bitmap_t *libc_wr_bitmap;
66 clib_bitmap_t *libc_ex_bitmap;
71 #define VCOM_DEBUG vcom->debug
73 static vcom_main_t vcom_main = {
74 .sid_bit_val = (1 << VCOM_SID_BIT_MIN),
75 .sid_bit_mask = (1 << VCOM_SID_BIT_MIN) - 1,
76 .debug = VCOM_DEBUG_INIT,
79 static vcom_main_t *vcom = &vcom_main;
82 * RETURN: 0 on success or -1 on error.
85 vcom_set_app_name (char *app_name)
87 int rv = snprintf (vcom->app_name, VCOM_APP_NAME_MAX,
88 "vcom-%d-%s", getpid (), app_name);
90 if (rv >= VCOM_APP_NAME_MAX)
91 app_name[VCOM_APP_NAME_MAX - 1] = 0;
97 if (vcom->app_name[0] == '\0')
98 vcom_set_app_name ("app");
100 return vcom->app_name;
104 vcom_fd_from_sid (u32 sid)
106 if (PREDICT_FALSE (sid >= vcom->sid_bit_val))
109 return (sid | vcom->sid_bit_val);
113 vcom_fd_is_sid (int fd)
115 return ((u32) fd & vcom->sid_bit_val) ? 1 : 0;
119 vcom_sid_from_fd (int fd)
121 return (vcom_fd_is_sid (fd) ? ((u32) fd & vcom->sid_bit_mask) :
130 if (PREDICT_FALSE (!vcom->init))
133 rv = vppcom_app_create (vcom_get_app_name ());
136 char *env_var_str = getenv (VCOM_ENV_DEBUG);
140 if (sscanf (env_var_str, "%u", &tmp) != 1)
141 clib_warning ("LDP<%d>: WARNING: Invalid VCOM debug level "
142 "specified in the env var " VCOM_ENV_DEBUG
143 " (%s)!", getpid (), env_var_str);
147 clib_warning ("LDP<%d>: configured VCOM debug level (%u) "
148 "from the env var " VCOM_ENV_DEBUG "!",
149 getpid (), vcom->debug);
153 env_var_str = getenv (VCOM_ENV_APP_NAME);
156 vcom_set_app_name (env_var_str);
157 clib_warning ("LDP<%d>: configured VCOM app name (%s) "
158 "from the env var " VCOM_ENV_APP_NAME "!",
159 getpid (), vcom->app_name);
162 env_var_str = getenv (VCOM_ENV_SID_BIT);
166 if (sscanf (env_var_str, "%u", &sb) != 1)
168 clib_warning ("LDP<%d>: WARNING: Invalid VCOM sid bit "
169 "specified in the env var "
170 VCOM_ENV_SID_BIT " (%s)!"
171 "sid bit value %d (0x%x)",
172 getpid (), env_var_str,
173 vcom->sid_bit_val, vcom->sid_bit_val);
175 else if (sb < VCOM_SID_BIT_MIN)
177 vcom->sid_bit_val = (1 << VCOM_SID_BIT_MIN);
178 vcom->sid_bit_mask = vcom->sid_bit_val - 1;
180 clib_warning ("LDP<%d>: WARNING: VCOM sid bit (%u) "
181 "specified in the env var "
182 VCOM_ENV_SID_BIT " (%s) is too small. "
183 "Using VCOM_SID_BIT_MIN (%d)! "
184 "sid bit value %d (0x%x)",
185 getpid (), sb, env_var_str, VCOM_SID_BIT_MIN,
186 vcom->sid_bit_val, vcom->sid_bit_val);
188 else if (sb > VCOM_SID_BIT_MAX)
190 vcom->sid_bit_val = (1 << VCOM_SID_BIT_MAX);
191 vcom->sid_bit_mask = vcom->sid_bit_val - 1;
193 clib_warning ("LDP<%d>: WARNING: VCOM sid bit (%u) "
194 "specified in the env var "
195 VCOM_ENV_SID_BIT " (%s) is too big. "
196 "Using VCOM_SID_BIT_MAX (%d)! "
197 "sid bit value %d (0x%x)",
198 getpid (), sb, env_var_str, VCOM_SID_BIT_MAX,
199 vcom->sid_bit_val, vcom->sid_bit_val);
203 vcom->sid_bit_val = (1 << sb);
204 vcom->sid_bit_mask = vcom->sid_bit_val - 1;
206 clib_warning ("LDP<%d>: configured VCOM sid bit (%u) "
207 "from " VCOM_ENV_SID_BIT
208 "! sid bit value %d (0x%x)", getpid (),
209 sb, vcom->sid_bit_val, vcom->sid_bit_val);
213 clib_time_init (&vcom->clib_time);
214 clib_warning ("LDP<%d>: VCOM initialization: done!", getpid ());
218 fprintf (stderr, "\nLDP<%d>: ERROR: vcom_init: vppcom_app_create()"
219 " failed! rv = %d (%s)\n",
220 getpid (), rv, vppcom_retval_str (rv));
231 const char *func_str;
232 u32 sid = vcom_sid_from_fd (fd);
234 if ((errno = -vcom_init ()))
237 if (sid != INVALID_SESSION_ID)
241 func_str = "vppcom_session_attr[GET_LIBC_EPFD]";
242 epfd = vppcom_session_attr (sid, VPPCOM_ATTR_GET_LIBC_EPFD, 0, 0);
245 func_str = "libc_close";
249 ("LDP<%d>: fd %d (0x%x): calling %s(): epfd %u (0x%x)",
250 getpid (), fd, fd, func_str, epfd, epfd);
252 rv = libc_close (epfd);
255 u32 size = sizeof (epfd);
258 (void) vppcom_session_attr (sid, VPPCOM_ATTR_SET_LIBC_EPFD,
262 else if (PREDICT_FALSE (epfd < 0))
269 func_str = "vppcom_session_close";
272 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): sid %u (0x%x)",
273 getpid (), fd, fd, func_str, sid, sid);
275 rv = vppcom_session_close (sid);
284 func_str = "libc_close";
287 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s()",
288 getpid (), fd, fd, func_str);
290 rv = libc_close (fd);
298 int errno_val = errno;
300 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! "
301 "rv %d, errno = %d", getpid (), fd, fd,
302 func_str, rv, errno_val);
306 clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)",
307 getpid (), fd, fd, rv, rv);
313 read (int fd, void *buf, size_t nbytes)
316 const char *func_str;
317 u32 sid = vcom_sid_from_fd (fd);
319 if ((errno = -vcom_init ()))
322 if (sid != INVALID_SESSION_ID)
324 func_str = "vppcom_session_read";
327 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
328 "sid %u (0x%x), buf %p, nbytes %u", getpid (),
329 fd, fd, func_str, sid, sid, buf, nbytes);
331 size = vppcom_session_read (sid, buf, nbytes);
340 func_str = "libc_read";
343 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
344 "buf %p, nbytes %u", getpid (),
345 fd, fd, func_str, buf, nbytes);
347 size = libc_read (fd, buf, nbytes);
354 int errno_val = errno;
356 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! "
357 "rv %d, errno = %d", getpid (), fd, fd,
358 func_str, size, errno_val);
362 clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)",
363 getpid (), fd, fd, size, size);
369 readv (int fd, const struct iovec * iov, int iovcnt)
371 const char *func_str;
373 u32 sid = vcom_sid_from_fd (fd);
374 int rv = 0, i, total = 0;
376 if ((errno = -vcom_init ()))
379 if (sid != INVALID_SESSION_ID)
381 func_str = "vppcom_session_read";
384 for (i = 0; i < iovcnt; ++i)
387 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s() [%d]: "
388 "sid %u (0x%x), iov %p, iovcnt %d, total %d",
389 getpid (), fd, fd, func_str, i, sid, sid,
392 rv = vppcom_session_read (sid, iov[i].iov_base, iov[i].iov_len);
398 if (rv < iov[i].iov_len)
401 clib_warning ("LDP<%d>: fd %d (0x%x): "
402 "rv (%d) < iov[%d].iov_len (%d)",
403 getpid (), fd, fd, rv, i,
410 while ((rv >= 0) && (total == 0));
422 func_str = "libc_readv";
425 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
426 "iov %p, iovcnt %d", getpid (), fd, fd, iov, iovcnt);
428 size = libc_readv (fd, iov, iovcnt);
435 int errno_val = errno;
437 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! "
438 "rv %d, errno = %d", getpid (), fd, fd,
439 func_str, size, errno_val);
443 clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)",
444 getpid (), fd, fd, size, size);
450 write (int fd, const void *buf, size_t nbytes)
452 const char *func_str;
454 u32 sid = vcom_sid_from_fd (fd);
456 if ((errno = -vcom_init ()))
459 if (sid != INVALID_SESSION_ID)
461 func_str = "vppcom_session_write";
464 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
465 "sid %u (0x%x), buf %p, nbytes %u", getpid (),
466 fd, fd, func_str, sid, sid, buf, nbytes);
468 size = vppcom_session_write (sid, (void *) buf, nbytes);
477 func_str = "libc_write";
480 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
481 "buf %p, nbytes %u", getpid (),
482 fd, fd, func_str, buf, nbytes);
484 size = libc_write (fd, buf, nbytes);
491 int errno_val = errno;
493 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! "
494 "rv %d, errno = %d", getpid (), fd, fd,
495 func_str, size, errno_val);
499 clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)",
500 getpid (), fd, fd, size, size);
506 writev (int fd, const struct iovec * iov, int iovcnt)
508 const char *func_str;
509 ssize_t size = 0, total = 0;
510 u32 sid = vcom_sid_from_fd (fd);
514 * Use [f]printf() instead of clib_warning() to prevent recursion SIGSEGV.
517 if ((errno = -vcom_init ()))
520 if (sid != INVALID_SESSION_ID)
522 func_str = "vppcom_session_write";
525 for (i = 0; i < iovcnt; ++i)
528 printf ("%s:%d: LDP<%d>: fd %d (0x%x): calling %s() [%d]: "
529 "sid %u (0x%x), buf %p, nbytes %ld, total %ld",
530 __func__, __LINE__, getpid (), fd, fd, func_str,
531 i, sid, sid, iov[i].iov_base, iov[i].iov_len, total);
533 rv = vppcom_session_write (sid, iov[i].iov_base,
540 if (rv < iov[i].iov_len)
543 printf ("%s:%d: LDP<%d>: fd %d (0x%x): "
544 "rv (%d) < iov[%d].iov_len (%ld)",
545 __func__, __LINE__, getpid (), fd, fd,
546 rv, i, iov[i].iov_len);
552 while ((rv >= 0) && (total == 0));
564 func_str = "libc_writev";
567 printf ("%s:%d: LDP<%d>: fd %d (0x%x): calling %s(): "
568 "iov %p, iovcnt %d\n", __func__, __LINE__, getpid (),
569 fd, fd, func_str, iov, iovcnt);
571 size = libc_writev (fd, iov, iovcnt);
578 int errno_val = errno;
581 "%s:%d: LDP<%d>: ERROR: fd %d (0x%x): %s() failed! "
582 "rv %ld, errno = %d\n", __func__, __LINE__, getpid (), fd,
583 fd, func_str, size, errno_val);
587 printf ("%s:%d: LDP<%d>: fd %d (0x%x): returning %ld\n",
588 __func__, __LINE__, getpid (), fd, fd, size);
594 fcntl (int fd, int cmd, ...)
596 const char *func_str = __func__;
599 u32 sid = vcom_sid_from_fd (fd);
601 if ((errno = -vcom_init ()))
605 if (sid != INVALID_SESSION_ID)
607 int flags = va_arg (ap, int);
610 size = sizeof (flags);
615 func_str = "vppcom_session_attr[SET_FLAGS]";
617 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
618 "sid %u (0x%x) flags %d (0x%x), size %d",
619 getpid (), fd, fd, func_str, sid, sid,
623 vppcom_session_attr (sid, VPPCOM_ATTR_SET_FLAGS, &flags, &size);
627 func_str = "vppcom_session_attr[GET_FLAGS]";
630 ("LDP<%d>: fd %d (0x%x): calling %s(): sid %u (0x%x), "
631 "flags %d (0x%x), size %d", getpid (), fd, fd, func_str, sid,
632 sid, flags, flags, size);
635 vppcom_session_attr (sid, VPPCOM_ATTR_GET_FLAGS, &flags, &size);
639 clib_warning ("LDP<%d>: fd %d (0x%x), cmd %d (F_GETFL): "
640 "%s() returned flags %d (0x%x)",
641 getpid (), fd, fd, cmd, func_str, flags, flags);
658 func_str = "libc_vfcntl";
661 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): cmd %d",
662 getpid (), fd, fd, func_str, cmd);
664 rv = libc_vfcntl (fd, cmd, ap);
673 int errno_val = errno;
675 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! "
676 "rv %d, errno = %d", getpid (), fd, fd,
677 func_str, rv, errno_val);
681 clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)",
682 getpid (), fd, fd, rv, rv);
688 ioctl (int fd, unsigned long int cmd, ...)
690 const char *func_str;
693 u32 sid = vcom_sid_from_fd (fd);
695 if ((errno = -vcom_init ()))
699 if (sid != INVALID_SESSION_ID)
701 func_str = "vppcom_session_attr[GET_NREAD]";
708 ("LDP<%d>: fd %d (0x%x): calling %s(): sid %u (0x%x)",
709 getpid (), fd, fd, func_str, sid, sid);
711 rv = vppcom_session_attr (sid, VPPCOM_ATTR_GET_NREAD, 0, 0);
716 u32 flags = va_arg (ap, int) ? O_NONBLOCK : 0;
717 u32 size = sizeof (flags);
719 /* TBD: When VPPCOM_ATTR_[GS]ET_FLAGS supports flags other than
720 * non-blocking, the flags should be read here and merged
724 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
725 "sid %u (0x%x), flags %d (0x%x), size %d",
726 getpid (), fd, fd, func_str, sid, sid,
729 rv = vppcom_session_attr (sid, VPPCOM_ATTR_SET_FLAGS, &flags,
746 func_str = "libc_vioctl";
749 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): cmd %d",
750 getpid (), fd, fd, func_str, cmd);
752 rv = libc_vioctl (fd, cmd, ap);
759 int errno_val = errno;
761 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! "
762 "rv %d, errno = %d", getpid (), fd, fd,
763 func_str, rv, errno_val);
767 clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)",
768 getpid (), fd, fd, rv, rv);
775 vcom_pselect (int nfds, fd_set * __restrict readfds,
776 fd_set * __restrict writefds,
777 fd_set * __restrict exceptfds,
778 const struct timespec *__restrict timeout,
779 const __sigset_t * __restrict sigmask)
782 char *func_str = "##";
785 uword sid_bits, sid_bits_set, libc_bits, libc_bits_set;
786 u32 minbits = clib_max (nfds, BITS (uword));
795 if (nfds <= vcom->sid_bit_val)
797 func_str = "libc_pselect";
801 ("LDP<%d>: calling %s(): nfds %d, readfds %p, writefds %p, "
802 "exceptfds %p, timeout %p, sigmask %p", getpid (), func_str, nfds,
803 readfds, writefds, exceptfds, timeout, sigmask);
805 rv = libc_pselect (nfds, readfds, writefds, exceptfds,
810 if (PREDICT_FALSE (vcom->sid_bit_val > FD_SETSIZE / 2))
812 clib_warning ("LDP<%d>: ERROR: VCOM sid bit value %d (0x%x) > "
813 "FD_SETSIZE/2 %d (0x%x)!", getpid (),
814 vcom->sid_bit_val, vcom->sid_bit_val,
815 FD_SETSIZE / 2, FD_SETSIZE / 2);
822 time_out = (timeout->tv_sec == 0 && timeout->tv_nsec == 0) ?
823 (f64) 0 : (f64) timeout->tv_sec +
824 (f64) timeout->tv_nsec / (f64) 1000000000 +
825 (f64) (timeout->tv_nsec % 1000000000) / (f64) 1000000000;
827 /* select as fine grained sleep */
831 clib_warning ("LDP<%d>: sleeping for %f seconds",
832 getpid (), time_out);
834 time_out += clib_time_now (&vcom->clib_time);
835 while (clib_time_now (&vcom->clib_time) < time_out)
848 sid_bits = libc_bits = 0;
851 clib_bitmap_validate (vcom->sid_rd_bitmap, minbits);
852 clib_bitmap_validate (vcom->libc_rd_bitmap, minbits);
853 clib_bitmap_validate (vcom->rd_bitmap, minbits);
854 clib_memcpy (vcom->rd_bitmap, readfds,
855 vec_len (vcom->rd_bitmap) * sizeof (clib_bitmap_t));
859 clib_bitmap_foreach (fd, vcom->rd_bitmap,
861 sid = vcom_sid_from_fd (fd);
863 clib_warning ("LDP<%d>: readfds: fd %d (0x%x), sid %u (0x%x)",
864 getpid (), fd, fd, sid, sid);
865 if (sid == INVALID_SESSION_ID)
866 clib_bitmap_set_no_check (vcom->libc_rd_bitmap, fd, 1);
868 clib_bitmap_set_no_check (vcom->sid_rd_bitmap, sid, 1);
872 sid_bits_set = clib_bitmap_last_set (vcom->sid_rd_bitmap) + 1;
873 sid_bits = (sid_bits_set > sid_bits) ? sid_bits_set : sid_bits;
875 libc_bits_set = clib_bitmap_last_set (vcom->libc_rd_bitmap) + 1;
876 libc_bits = (libc_bits_set > libc_bits) ? libc_bits_set : libc_bits;
879 clib_warning ("LDP<%d>: readfds: sid_bits_set %d, sid_bits %d, "
880 "libc_bits_set %d, libc_bits %d", getpid (),
881 sid_bits_set, sid_bits, libc_bits_set, libc_bits);
885 clib_bitmap_validate (vcom->sid_wr_bitmap, minbits);
886 clib_bitmap_validate (vcom->libc_wr_bitmap, minbits);
887 clib_bitmap_validate (vcom->wr_bitmap, minbits);
888 clib_memcpy (vcom->wr_bitmap, writefds,
889 vec_len (vcom->wr_bitmap) * sizeof (clib_bitmap_t));
893 clib_bitmap_foreach (fd, vcom->wr_bitmap,
895 sid = vcom_sid_from_fd (fd);
897 clib_warning ("LDP<%d>: writefds: fd %d (0x%x), sid %u (0x%x)",
898 getpid (), fd, fd, sid, sid);
899 if (sid == INVALID_SESSION_ID)
900 clib_bitmap_set_no_check (vcom->libc_wr_bitmap, fd, 1);
902 clib_bitmap_set_no_check (vcom->sid_wr_bitmap, sid, 1);
906 sid_bits_set = clib_bitmap_last_set (vcom->sid_wr_bitmap) + 1;
907 sid_bits = (sid_bits_set > sid_bits) ? sid_bits_set : sid_bits;
909 libc_bits_set = clib_bitmap_last_set (vcom->libc_wr_bitmap) + 1;
910 libc_bits = (libc_bits_set > libc_bits) ? libc_bits_set : libc_bits;
913 clib_warning ("LDP<%d>: writefds: sid_bits_set %d, sid_bits %d, "
914 "libc_bits_set %d, libc_bits %d", getpid (),
915 sid_bits_set, sid_bits, libc_bits_set, libc_bits);
919 clib_bitmap_validate (vcom->sid_ex_bitmap, minbits);
920 clib_bitmap_validate (vcom->libc_ex_bitmap, minbits);
921 clib_bitmap_validate (vcom->ex_bitmap, minbits);
922 clib_memcpy (vcom->ex_bitmap, exceptfds,
923 vec_len (vcom->ex_bitmap) * sizeof (clib_bitmap_t));
927 clib_bitmap_foreach (fd, vcom->ex_bitmap,
929 sid = vcom_sid_from_fd (fd);
931 clib_warning ("LDP<%d>: exceptfds: fd %d (0x%x), sid %u (0x%x)",
932 getpid (), fd, fd, sid, sid);
933 if (sid == INVALID_SESSION_ID)
934 clib_bitmap_set_no_check (vcom->libc_ex_bitmap, fd, 1);
936 clib_bitmap_set_no_check (vcom->sid_ex_bitmap, sid, 1);
940 sid_bits_set = clib_bitmap_last_set (vcom->sid_ex_bitmap) + 1;
941 sid_bits = (sid_bits_set > sid_bits) ? sid_bits_set : sid_bits;
943 libc_bits_set = clib_bitmap_last_set (vcom->libc_ex_bitmap) + 1;
944 libc_bits = (libc_bits_set > libc_bits) ? libc_bits_set : libc_bits;
947 clib_warning ("LDP<%d>: exceptfds: sid_bits_set %d, sid_bits %d, "
948 "libc_bits_set %d, libc_bits %d", getpid (),
949 sid_bits_set, sid_bits, libc_bits_set, libc_bits);
952 if (PREDICT_FALSE (!sid_bits && !libc_bits))
963 if (!vcom->select_vcl)
965 func_str = "vppcom_select";
968 clib_memcpy (vcom->rd_bitmap, vcom->sid_rd_bitmap,
969 vec_len (vcom->rd_bitmap) *
970 sizeof (clib_bitmap_t));
972 clib_memcpy (vcom->wr_bitmap, vcom->sid_wr_bitmap,
973 vec_len (vcom->wr_bitmap) *
974 sizeof (clib_bitmap_t));
976 clib_memcpy (vcom->ex_bitmap, vcom->sid_ex_bitmap,
977 vec_len (vcom->ex_bitmap) *
978 sizeof (clib_bitmap_t));
980 rv = vppcom_select (sid_bits,
981 readfds ? vcom->rd_bitmap : NULL,
982 writefds ? vcom->wr_bitmap : NULL,
983 exceptfds ? vcom->ex_bitmap : NULL, 0);
994 clib_bitmap_foreach (sid, vcom->rd_bitmap,
996 fd = vcom_fd_from_sid (sid);
997 if (PREDICT_FALSE (fd < 0))
1003 FD_SET (fd, readfds);
1010 clib_bitmap_foreach (sid, vcom->wr_bitmap,
1012 fd = vcom_fd_from_sid (sid);
1013 if (PREDICT_FALSE (fd < 0))
1019 FD_SET (fd, writefds);
1026 clib_bitmap_foreach (sid, vcom->ex_bitmap,
1028 fd = vcom_fd_from_sid (sid);
1029 if (PREDICT_FALSE (fd < 0))
1035 FD_SET (fd, exceptfds);
1039 vcom->select_vcl = 1;
1044 vcom->select_vcl = 0;
1048 struct timespec tspec;
1050 func_str = "libc_pselect";
1053 clib_memcpy (readfds, vcom->libc_rd_bitmap,
1054 vec_len (vcom->rd_bitmap) * sizeof (clib_bitmap_t));
1056 clib_memcpy (writefds, vcom->libc_wr_bitmap,
1057 vec_len (vcom->wr_bitmap) * sizeof (clib_bitmap_t));
1059 clib_memcpy (exceptfds, vcom->libc_ex_bitmap,
1060 vec_len (vcom->ex_bitmap) * sizeof (clib_bitmap_t));
1061 tspec.tv_sec = tspec.tv_nsec = 0;
1062 rv = libc_pselect (libc_bits,
1063 readfds ? readfds : NULL,
1064 writefds ? writefds : NULL,
1065 exceptfds ? exceptfds : NULL, &tspec, sigmask);
1070 while ((time_out == -1) || (clib_time_now (&vcom->clib_time) < time_out));
1074 /* TBD: set timeout to amount of time left */
1075 vec_reset_length (vcom->rd_bitmap);
1076 vec_reset_length (vcom->sid_rd_bitmap);
1077 vec_reset_length (vcom->libc_rd_bitmap);
1078 vec_reset_length (vcom->wr_bitmap);
1079 vec_reset_length (vcom->sid_wr_bitmap);
1080 vec_reset_length (vcom->libc_wr_bitmap);
1081 vec_reset_length (vcom->ex_bitmap);
1082 vec_reset_length (vcom->sid_ex_bitmap);
1083 vec_reset_length (vcom->libc_ex_bitmap);
1089 int errno_val = errno;
1091 clib_warning ("LDP<%d>: ERROR: %s() failed! "
1092 "rv %d, errno = %d", getpid (),
1093 func_str, rv, errno_val);
1097 clib_warning ("LDP<%d>: returning %d (0x%x)", getpid (), rv, rv);
1103 select (int nfds, fd_set * __restrict readfds,
1104 fd_set * __restrict writefds,
1105 fd_set * __restrict exceptfds, struct timeval *__restrict timeout)
1107 struct timespec tspec;
1111 tspec.tv_sec = timeout->tv_sec;
1112 tspec.tv_nsec = timeout->tv_usec * 1000;
1114 return vcom_pselect (nfds, readfds, writefds, exceptfds,
1115 timeout ? &tspec : NULL, NULL);
1118 #ifdef __USE_XOPEN2K
1120 pselect (int nfds, fd_set * __restrict readfds,
1121 fd_set * __restrict writefds,
1122 fd_set * __restrict exceptfds,
1123 const struct timespec *__restrict timeout,
1124 const __sigset_t * __restrict sigmask)
1126 return vcom_pselect (nfds, readfds, writefds, exceptfds, timeout, 0);
1131 socket (int domain, int type, int protocol)
1133 const char *func_str;
1135 u8 is_nonblocking = type & SOCK_NONBLOCK ? 1 : 0;
1136 int sock_type = type & ~(SOCK_CLOEXEC | SOCK_NONBLOCK);
1138 if ((errno = -vcom_init ()))
1141 if (((domain == AF_INET) || (domain == AF_INET6)) &&
1142 ((sock_type == SOCK_STREAM) || (sock_type == SOCK_DGRAM)))
1145 u32 vrf = VPPCOM_VRF_DEFAULT;
1146 u8 proto = ((sock_type == SOCK_DGRAM) ?
1147 VPPCOM_PROTO_UDP : VPPCOM_PROTO_TCP);
1149 func_str = "vppcom_session_create";
1152 clib_warning ("LDP<%d>: : calling %s(): vrf %u, "
1153 "proto %u (%s), is_nonblocking %u",
1154 getpid (), func_str, vrf, proto,
1155 vppcom_proto_str (proto), is_nonblocking);
1157 sid = vppcom_session_create (vrf, proto, is_nonblocking);
1165 func_str = "vcom_fd_from_sid";
1166 rv = vcom_fd_from_sid (sid);
1169 (void) vppcom_session_close (sid);
1177 func_str = "libc_socket";
1180 clib_warning ("LDP<%d>: : calling %s()", getpid (), func_str);
1182 rv = libc_socket (domain, type, protocol);
1189 int errno_val = errno;
1191 clib_warning ("LDP<%d>: ERROR: %s() failed! "
1192 "rv %d, errno = %d",
1193 getpid (), func_str, rv, errno_val);
1197 clib_warning ("LDP<%d>: : returning fd %d (0x%x)", getpid (), rv, rv);
1203 * Create two new sockets, of type TYPE in domain DOMAIN and using
1204 * protocol PROTOCOL, which are connected to each other, and put file
1205 * descriptors for them in FDS[0] and FDS[1]. If PROTOCOL is zero,
1206 * one will be chosen automatically.
1207 * Returns 0 on success, -1 for errors.
1210 socketpair (int domain, int type, int protocol, int fds[2])
1212 const char *func_str;
1214 int sock_type = type & ~(SOCK_CLOEXEC | SOCK_NONBLOCK);
1216 if ((errno = -vcom_init ()))
1219 if (((domain == AF_INET) || (domain == AF_INET6)) &&
1220 ((sock_type == SOCK_STREAM) || (sock_type == SOCK_DGRAM)))
1222 func_str = __func__;
1224 clib_warning ("LDP<%d>: LDP-TBD", getpid ());
1230 func_str = "libc_socket";
1233 clib_warning ("LDP<%d>: : calling %s()", getpid (), func_str);
1235 rv = libc_socket (domain, type, protocol);
1242 int errno_val = errno;
1244 clib_warning ("LDP<%d>: ERROR: %s() failed! "
1245 "rv %d, errno = %d",
1246 getpid (), func_str, rv, errno_val);
1250 clib_warning ("LDP<%d>: : returning fd %d (0x%x)", getpid (), rv, rv);
1256 bind (int fd, __CONST_SOCKADDR_ARG addr, socklen_t len)
1259 const char *func_str;
1260 u32 sid = vcom_sid_from_fd (fd);
1262 if ((errno = -vcom_init ()))
1265 if (sid != INVALID_SESSION_ID)
1269 func_str = "vppcom_session_bind";
1271 ep.vrf = VPPCOM_VRF_DEFAULT;
1272 switch (addr->sa_family)
1275 if (len != sizeof (struct sockaddr_in))
1278 ("LDP<%d>: ERROR: fd %d (0x%x): sid %u (0x%x): Invalid "
1279 "AF_INET addr len %u!", getpid (), fd, fd, sid, sid, len);
1284 ep.is_ip4 = VPPCOM_IS_IP4;
1285 ep.ip = (u8 *) & ((const struct sockaddr_in *) addr)->sin_addr;
1286 ep.port = (u16) ((const struct sockaddr_in *) addr)->sin_port;
1290 if (len != sizeof (struct sockaddr_in6))
1293 ("LDP<%d>: ERROR: fd %d (0x%x): sid %u (0x%x): Invalid "
1294 "AF_INET6 addr len %u!", getpid (), fd, fd, sid, sid, len);
1299 ep.is_ip4 = VPPCOM_IS_IP6;
1300 ep.ip = (u8 *) & ((const struct sockaddr_in6 *) addr)->sin6_addr;
1301 ep.port = (u16) ((const struct sockaddr_in6 *) addr)->sin6_port;
1305 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): sid %u (0x%x): "
1306 "Unsupported address family %u!",
1307 getpid (), fd, fd, sid, sid, addr->sa_family);
1308 errno = EAFNOSUPPORT;
1313 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): sid %u (0x%x), "
1315 getpid (), fd, fd, func_str, sid, sid, addr, len);
1317 rv = vppcom_session_bind (sid, &ep);
1318 if (rv != VPPCOM_OK)
1326 func_str = "libc_bind";
1329 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
1331 getpid (), fd, fd, func_str, addr, len);
1333 rv = libc_bind (fd, addr, len);
1341 int errno_val = errno;
1343 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! "
1344 "rv %d, errno = %d", getpid (), fd, fd,
1345 func_str, rv, errno_val);
1349 clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)",
1350 getpid (), fd, fd, rv, rv);
1356 vcom_copy_ep_to_sockaddr (__SOCKADDR_ARG addr, socklen_t * __restrict len,
1357 vppcom_endpt_t * ep)
1360 int sa_len, copy_len;
1362 if ((errno = -vcom_init ()))
1365 if (addr && len && ep)
1367 addr->sa_family = (ep->is_ip4 == VPPCOM_IS_IP4) ? AF_INET : AF_INET6;
1368 switch (addr->sa_family)
1371 ((struct sockaddr_in *) addr)->sin_port = ep->port;
1372 if (*len > sizeof (struct sockaddr_in))
1373 *len = sizeof (struct sockaddr_in);
1374 sa_len = sizeof (struct sockaddr_in) - sizeof (struct in_addr);
1375 copy_len = *len - sa_len;
1377 memcpy (&((struct sockaddr_in *) addr)->sin_addr, ep->ip,
1382 ((struct sockaddr_in6 *) addr)->sin6_port = ep->port;
1383 if (*len > sizeof (struct sockaddr_in6))
1384 *len = sizeof (struct sockaddr_in6);
1385 sa_len = sizeof (struct sockaddr_in6) - sizeof (struct in6_addr);
1386 copy_len = *len - sa_len;
1388 memcpy (((struct sockaddr_in6 *) addr)->sin6_addr.
1389 __in6_u.__u6_addr8, ep->ip, copy_len);
1402 getsockname (int fd, __SOCKADDR_ARG addr, socklen_t * __restrict len)
1405 const char *func_str;
1406 u32 sid = vcom_sid_from_fd (fd);
1408 if ((errno = -vcom_init ()))
1411 if (sid != INVALID_SESSION_ID)
1414 u8 addr_buf[sizeof (struct in6_addr)];
1415 u32 size = sizeof (ep);
1418 func_str = "vppcom_session_attr[GET_LCL_ADDR]";
1421 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): sid %u (0x%x), "
1423 getpid (), fd, fd, func_str, sid, sid, addr, len);
1425 rv = vppcom_session_attr (sid, VPPCOM_ATTR_GET_LCL_ADDR, &ep, &size);
1426 if (rv != VPPCOM_OK)
1433 rv = vcom_copy_ep_to_sockaddr (addr, len, &ep);
1434 if (rv != VPPCOM_OK)
1443 func_str = "libc_getsockname";
1446 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
1448 getpid (), fd, fd, func_str, addr, len);
1450 rv = libc_getsockname (fd, addr, len);
1457 int errno_val = errno;
1459 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! "
1460 "rv %d, errno = %d", getpid (), fd, fd,
1461 func_str, rv, errno_val);
1465 clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)",
1466 getpid (), fd, fd, rv, rv);
1472 connect (int fd, __CONST_SOCKADDR_ARG addr, socklen_t len)
1475 const char *func_str = __func__;
1476 u32 sid = vcom_sid_from_fd (fd);
1478 if ((errno = -vcom_init ()))
1483 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): NULL addr, len %u",
1484 getpid (), fd, fd, len);
1490 if (sid != INVALID_SESSION_ID)
1494 func_str = "vppcom_session_connect";
1496 ep.vrf = VPPCOM_VRF_DEFAULT;
1497 switch (addr->sa_family)
1500 if (len != sizeof (struct sockaddr_in))
1503 ("LDP<%d>: fd %d (0x%x): ERROR sid %u (0x%x): Invalid "
1504 "AF_INET addr len %u!", getpid (), fd, fd, sid, sid, len);
1509 ep.is_ip4 = VPPCOM_IS_IP4;
1510 ep.ip = (u8 *) & ((const struct sockaddr_in *) addr)->sin_addr;
1511 ep.port = (u16) ((const struct sockaddr_in *) addr)->sin_port;
1515 if (len != sizeof (struct sockaddr_in6))
1518 ("LDP<%d>: fd %d (0x%x): ERROR sid %u (0x%x): Invalid "
1519 "AF_INET6 addr len %u!", getpid (), fd, fd, sid, sid, len);
1524 ep.is_ip4 = VPPCOM_IS_IP6;
1525 ep.ip = (u8 *) & ((const struct sockaddr_in6 *) addr)->sin6_addr;
1526 ep.port = (u16) ((const struct sockaddr_in6 *) addr)->sin6_port;
1530 clib_warning ("LDP<%d>: fd %d (0x%x): ERROR sid %u (0x%x): "
1531 "Unsupported address family %u!",
1532 getpid (), fd, fd, sid, sid, addr->sa_family);
1533 errno = EAFNOSUPPORT;
1538 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): sid %u (0x%x) "
1540 getpid (), fd, fd, func_str, sid, sid, addr, len);
1542 rv = vppcom_session_connect (sid, &ep);
1543 if (rv != VPPCOM_OK)
1551 func_str = "libc_connect";
1554 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
1556 getpid (), fd, fd, func_str, addr, len);
1558 rv = libc_connect (fd, addr, len);
1566 int errno_val = errno;
1568 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! "
1569 "rv %d, errno = %d", getpid (), fd, fd,
1570 func_str, rv, errno_val);
1574 clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)",
1575 getpid (), fd, fd, rv, rv);
1581 getpeername (int fd, __SOCKADDR_ARG addr, socklen_t * __restrict len)
1584 const char *func_str;
1585 u32 sid = vcom_sid_from_fd (fd);
1587 if ((errno = -vcom_init ()))
1590 if (sid != INVALID_SESSION_ID)
1593 u8 addr_buf[sizeof (struct in6_addr)];
1594 u32 size = sizeof (ep);
1597 func_str = "vppcom_session_attr[GET_PEER_ADDR]";
1600 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): sid %u (0x%x), "
1602 getpid (), fd, fd, func_str, sid, sid, addr, len);
1604 rv = vppcom_session_attr (sid, VPPCOM_ATTR_GET_PEER_ADDR, &ep, &size);
1605 if (rv != VPPCOM_OK)
1612 rv = vcom_copy_ep_to_sockaddr (addr, len, &ep);
1613 if (rv != VPPCOM_OK)
1622 func_str = "libc_getpeername";
1625 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
1627 getpid (), fd, fd, func_str, addr, len);
1629 rv = libc_getpeername (fd, addr, len);
1636 int errno_val = errno;
1638 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! "
1639 "rv %d, errno = %d", getpid (), fd, fd,
1640 func_str, rv, errno_val);
1644 clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)",
1645 getpid (), fd, fd, rv, rv);
1651 send (int fd, const void *buf, size_t n, int flags)
1654 const char *func_str;
1655 u32 sid = vcom_sid_from_fd (fd);
1657 if ((errno = -vcom_init ()))
1660 if (sid != INVALID_SESSION_ID)
1663 func_str = "vppcom_session_sendto";
1666 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): sid %u (0x%x), "
1667 "buf %p, n %u, flags 0x%x",
1668 getpid (), fd, fd, func_str, sid, sid, buf, n, flags);
1670 size = vppcom_session_sendto (sid, (void *) buf, n, flags, NULL);
1671 if (size != VPPCOM_OK)
1679 func_str = "libc_send";
1682 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
1683 "buf %p, n %u, flags 0x%x",
1684 getpid (), fd, fd, func_str, buf, n, flags);
1686 size = libc_send (fd, buf, n, flags);
1693 int errno_val = errno;
1695 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! "
1696 "rv %d, errno = %d", getpid (), fd, fd,
1697 func_str, size, errno_val);
1701 clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)",
1702 getpid (), fd, fd, size, size);
1708 sendfile (int out_fd, int in_fd, off_t * offset, size_t len)
1711 const char *func_str;
1712 u32 sid = vcom_sid_from_fd (out_fd);
1714 if ((errno = -vcom_init ()))
1717 if (sid != INVALID_SESSION_ID)
1720 ssize_t results = 0;
1721 size_t n_bytes_left = len;
1722 size_t bytes_to_read;
1726 u32 flags, flags_len = sizeof (flags);
1728 func_str = "vppcom_session_attr[GET_FLAGS]";
1729 rv = vppcom_session_attr (sid, VPPCOM_ATTR_GET_FLAGS, &flags,
1731 if (PREDICT_FALSE (rv != VPPCOM_OK))
1733 clib_warning ("LDP<%d>: ERROR: out fd %d (0x%x): %s(): "
1734 "sid %u (0x%x), returned %d (%s)!", getpid (),
1735 out_fd, out_fd, func_str, sid, sid, rv,
1736 vppcom_retval_str (rv));
1738 vec_reset_length (vcom->io_buffer);
1746 off_t off = lseek (in_fd, *offset, SEEK_SET);
1747 if (PREDICT_FALSE (off == -1))
1751 clib_warning ("LDP<%d>: ERROR: out fd %d (0x%x): %s(): "
1752 "SEEK_SET failed: in_fd %d, offset %p, "
1753 "*offset %ld, rv %ld, errno %d", getpid (),
1754 out_fd, out_fd, in_fd, offset, *offset, off,
1761 ASSERT (off == *offset);
1766 func_str = "vppcom_session_attr[GET_NWRITE]";
1767 size = vppcom_session_attr (sid, VPPCOM_ATTR_GET_NWRITE, 0, 0);
1771 ("LDP<%d>: ERROR: fd %d (0x%x): %s(): sid %u (0x%x), "
1772 "returned %d (%s)!", getpid (), out_fd, out_fd, func_str,
1773 sid, sid, size, vppcom_retval_str (size));
1774 vec_reset_length (vcom->io_buffer);
1780 bytes_to_read = size;
1783 ("LDP<%d>: fd %d (0x%x): called %s(): sid %u (0x%x), "
1784 "results %ld, n_bytes_left %lu, bytes_to_read %lu", getpid (),
1785 out_fd, out_fd, func_str, sid, sid, results, n_bytes_left,
1788 if (bytes_to_read == 0)
1790 if (flags & O_NONBLOCK)
1795 clib_warning ("LDP<%d>: fd %d (0x%x): sid %u (0x%x): "
1797 getpid (), out_fd, out_fd, sid, sid);
1805 bytes_to_read = clib_min (n_bytes_left, bytes_to_read);
1806 vec_validate (vcom->io_buffer, bytes_to_read);
1807 nbytes = libc_read (in_fd, vcom->io_buffer, bytes_to_read);
1810 func_str = "libc_read";
1812 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s(): in_fd (%d), "
1813 "io_buffer %p, bytes_to_read %lu, rv %d, "
1814 "errno %d", getpid (), out_fd, out_fd, func_str,
1815 in_fd, vcom->io_buffer, bytes_to_read, nbytes,
1821 vec_reset_length (vcom->io_buffer);
1827 func_str = "vppcom_session_write";
1830 ("LDP<%d>: fd %d (0x%x): calling %s(): sid %u (0x%x), "
1831 "buf %p, nbytes %u: results %d, n_bytes_left %d", getpid (),
1832 out_fd, out_fd, func_str, sid, sid, vcom->io_buffer, nbytes,
1833 results, n_bytes_left);
1835 size = vppcom_session_write (sid, vcom->io_buffer, nbytes);
1838 if (size == VPPCOM_EAGAIN)
1840 if (flags & O_NONBLOCK)
1846 ("LDP<%d>: fd %d (0x%x): sid %u (0x%x): "
1847 "EAGAIN", getpid (), out_fd, out_fd, sid, sid);
1857 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s():"
1858 "sid %u, io_buffer %p, nbytes %u "
1860 getpid (), out_fd, out_fd, func_str,
1861 sid, vcom->io_buffer, nbytes,
1862 size, vppcom_retval_str (size));
1866 vec_reset_length (vcom->io_buffer);
1875 ASSERT (n_bytes_left >= nbytes);
1876 n_bytes_left = n_bytes_left - nbytes;
1878 while (n_bytes_left > 0);
1881 vec_reset_length (vcom->io_buffer);
1884 off_t off = lseek (in_fd, *offset, SEEK_SET);
1885 if (PREDICT_FALSE (off == -1))
1889 clib_warning ("LDP<%d>: ERROR: %s(): SEEK_SET failed: "
1890 "in_fd %d, offset %p, *offset %ld, "
1891 "rv %ld, errno %d", getpid (), in_fd,
1892 offset, *offset, off, errno_val);
1898 ASSERT (off == *offset);
1899 *offset += results + 1;
1911 func_str = "libc_send";
1914 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
1915 "in_fd %d, offset %p, len %u",
1916 getpid (), out_fd, out_fd, func_str,
1917 in_fd, offset, len);
1919 size = libc_sendfile (out_fd, in_fd, offset, len);
1927 int errno_val = errno;
1929 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! "
1930 "rv %d, errno = %d", getpid (), out_fd, out_fd,
1931 func_str, size, errno_val);
1935 clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)",
1936 getpid (), out_fd, out_fd, size, size);
1942 sendfile64 (int out_fd, int in_fd, off_t * offset, size_t len)
1944 return sendfile (out_fd, in_fd, offset, len);
1948 recv (int fd, void *buf, size_t n, int flags)
1951 const char *func_str;
1952 u32 sid = vcom_sid_from_fd (fd);
1954 if ((errno = -vcom_init ()))
1957 if (sid != INVALID_SESSION_ID)
1959 func_str = "vppcom_session_recvfrom";
1962 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
1963 "sid %u (0x%x), buf %p, n %u, flags 0x%x", getpid (),
1964 fd, fd, func_str, sid, sid, buf, n, flags);
1966 size = vppcom_session_recvfrom (sid, buf, n, flags, NULL);
1975 func_str = "libc_recv";
1978 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
1979 "buf %p, n %u, flags 0x%x", getpid (),
1980 fd, fd, func_str, buf, n, flags);
1982 size = libc_recv (fd, buf, n, flags);
1989 int errno_val = errno;
1991 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! "
1992 "rv %d, errno = %d", getpid (), fd, fd,
1993 func_str, size, errno_val);
1997 clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)",
1998 getpid (), fd, fd, size, size);
2004 sendto (int fd, const void *buf, size_t n, int flags,
2005 __CONST_SOCKADDR_ARG addr, socklen_t addr_len)
2008 const char *func_str = __func__;
2009 u32 sid = vcom_sid_from_fd (fd);
2011 if ((errno = -vcom_init ()))
2014 if (sid != INVALID_SESSION_ID)
2016 vppcom_endpt_t *ep = 0;
2022 ep->vrf = VPPCOM_VRF_DEFAULT;
2023 switch (addr->sa_family)
2026 ep->is_ip4 = VPPCOM_IS_IP4;
2028 (uint8_t *) & ((const struct sockaddr_in *) addr)->sin_addr;
2030 (uint16_t) ((const struct sockaddr_in *) addr)->sin_port;
2034 ep->is_ip4 = VPPCOM_IS_IP6;
2036 (uint8_t *) & ((const struct sockaddr_in6 *) addr)->sin6_addr;
2038 (uint16_t) ((const struct sockaddr_in6 *) addr)->sin6_port;
2042 errno = EAFNOSUPPORT;
2048 func_str = "vppcom_session_sendto";
2051 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2052 "sid %u (0x%x), buf %p, n %u, flags 0x%x, ep %p",
2053 getpid (), fd, fd, func_str, sid, sid, buf, n,
2056 size = vppcom_session_sendto (sid, (void *) buf, n, flags, ep);
2065 func_str = "libc_sendto";
2068 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2069 "buf %p, n %u, flags 0x%x, addr %p, addr_len %d",
2070 getpid (), fd, fd, func_str, buf, n, flags,
2073 size = libc_sendto (fd, buf, n, flags, addr, addr_len);
2081 int errno_val = errno;
2083 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! "
2084 "rv %d, errno = %d", getpid (), fd, fd,
2085 func_str, size, errno_val);
2089 clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)",
2090 getpid (), fd, fd, size, size);
2096 recvfrom (int fd, void *__restrict buf, size_t n, int flags,
2097 __SOCKADDR_ARG addr, socklen_t * __restrict addr_len)
2100 const char *func_str;
2101 u32 sid = vcom_sid_from_fd (fd);
2103 if ((errno = -vcom_init ()))
2106 if (sid != INVALID_SESSION_ID)
2109 u8 src_addr[sizeof (struct sockaddr_in6)];
2111 func_str = "vppcom_session_recvfrom";
2114 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2115 "sid %u (0x%x), buf %p, n %u, flags 0x%x, ep %p",
2116 getpid (), fd, fd, func_str, sid, sid, buf, n,
2121 size = vppcom_session_recvfrom (sid, buf, n, flags, &ep);
2124 size = vcom_copy_ep_to_sockaddr (addr, addr_len, &ep);
2127 size = vppcom_session_recvfrom (sid, buf, n, flags, NULL);
2137 func_str = "libc_recvfrom";
2140 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2141 "buf %p, n %u, flags 0x%x, addr %p, addr_len %d",
2142 getpid (), fd, fd, func_str, buf, n, flags,
2145 size = libc_recvfrom (fd, buf, n, flags, addr, addr_len);
2152 int errno_val = errno;
2154 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! "
2155 "rv %d, errno = %d", getpid (), fd, fd,
2156 func_str, size, errno_val);
2160 clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)",
2161 getpid (), fd, fd, size, size);
2167 sendmsg (int fd, const struct msghdr * message, int flags)
2170 const char *func_str;
2171 u32 sid = vcom_sid_from_fd (fd);
2173 if ((errno = -vcom_init ()))
2176 if (sid != INVALID_SESSION_ID)
2178 func_str = __func__;
2180 clib_warning ("LDP<%d>: LDP-TBD", getpid ());
2186 func_str = "libc_sendmsg";
2189 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2190 "message %p, flags 0x%x",
2191 getpid (), fd, fd, func_str, message, flags);
2193 size = libc_sendmsg (fd, message, flags);
2200 int errno_val = errno;
2202 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! "
2203 "rv %d, errno = %d", getpid (), fd, fd,
2204 func_str, size, errno_val);
2208 clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)",
2209 getpid (), fd, fd, size, size);
2216 sendmmsg (int fd, struct mmsghdr *vmessages, unsigned int vlen, int flags)
2219 const char *func_str;
2220 u32 sid = vcom_sid_from_fd (fd);
2222 if ((errno = -vcom_init ()))
2225 if (sid != INVALID_SESSION_ID)
2227 clib_warning ("LDP<%d>: LDP-TBD", getpid ());
2233 func_str = "libc_sendmmsg";
2236 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2237 "vmessages %p, vlen %u, flags 0x%x",
2238 getpid (), fd, fd, func_str, vmessages, vlen, flags);
2240 size = libc_sendmmsg (fd, vmessages, vlen, flags);
2247 int errno_val = errno;
2249 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! "
2250 "rv %d, errno = %d", getpid (), fd, fd,
2251 func_str, size, errno_val);
2255 clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)",
2256 getpid (), fd, fd, size, size);
2263 recvmsg (int fd, struct msghdr * message, int flags)
2266 const char *func_str;
2267 u32 sid = vcom_sid_from_fd (fd);
2269 if ((errno = -vcom_init ()))
2272 if (sid != INVALID_SESSION_ID)
2274 func_str = __func__;
2276 clib_warning ("LDP<%d>: LDP-TBD", getpid ());
2282 func_str = "libc_recvmsg";
2285 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2286 "message %p, flags 0x%x",
2287 getpid (), fd, fd, func_str, message, flags);
2289 size = libc_recvmsg (fd, message, flags);
2296 int errno_val = errno;
2298 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! "
2299 "rv %d, errno = %d", getpid (), fd, fd,
2300 func_str, size, errno_val);
2304 clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)",
2305 getpid (), fd, fd, size, size);
2312 recvmmsg (int fd, struct mmsghdr *vmessages,
2313 unsigned int vlen, int flags, struct timespec *tmo)
2316 const char *func_str;
2317 u32 sid = vcom_sid_from_fd (fd);
2319 if ((errno = -vcom_init ()))
2322 if (sid != INVALID_SESSION_ID)
2324 clib_warning ("LDP<%d>: LDP-TBD", getpid ());
2330 func_str = "libc_recvmmsg";
2333 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2334 "vmessages %p, vlen %u, flags 0x%x, tmo %p",
2335 getpid (), fd, fd, func_str, vmessages, vlen,
2338 size = libc_recvmmsg (fd, vmessages, vlen, flags, tmo);
2345 int errno_val = errno;
2347 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! "
2348 "rv %d, errno = %d", getpid (), fd, fd,
2349 func_str, size, errno_val);
2353 clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)",
2354 getpid (), fd, fd, size, size);
2361 getsockopt (int fd, int level, int optname,
2362 void *__restrict optval, socklen_t * __restrict optlen)
2365 const char *func_str = __func__;
2366 u32 sid = vcom_sid_from_fd (fd);
2367 u32 buflen = optlen ? (u32) * optlen : 0;
2369 if ((errno = -vcom_init ()))
2372 if (sid != INVALID_SESSION_ID)
2382 func_str = "vppcom_session_attr[SOL_TCP,GET_TCP_NODELAY]";
2384 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2386 getpid (), fd, fd, func_str, sid, sid);
2387 rv = vppcom_session_attr (sid, VPPCOM_ATTR_GET_TCP_NODELAY,
2391 func_str = "vppcom_session_attr[SOL_TCP,GET_TCP_USER_MSS]";
2393 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2395 getpid (), fd, fd, func_str, sid, sid);
2396 rv = vppcom_session_attr (sid, VPPCOM_ATTR_GET_TCP_USER_MSS,
2400 func_str = "vppcom_session_attr[SOL_TCP,GET_TCP_KEEPIDLE]";
2402 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2404 getpid (), fd, fd, func_str, sid, sid);
2405 rv = vppcom_session_attr (sid, VPPCOM_ATTR_GET_TCP_KEEPIDLE,
2409 func_str = "vppcom_session_attr[SOL_TCP,GET_TCP_KEEPINTVL]";
2411 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2412 "sid %u (0x%x), SOL_TCP",
2413 getpid (), fd, fd, func_str, sid, sid);
2414 rv = vppcom_session_attr (sid, VPPCOM_ATTR_GET_TCP_KEEPINTVL,
2418 if (optval && optlen && (*optlen == sizeof (struct tcp_info)))
2421 clib_warning ("LDP<%d>: fd %d (0x%x): sid %u (0x%x), "
2422 "SOL_TCP, TCP_INFO, optval %p, "
2423 "optlen %d: #LDP-NOP#",
2424 getpid (), fd, fd, sid, sid,
2426 memset (optval, 0, *optlen);
2434 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s(): "
2435 "sid %u (0x%x), SOL_TCP, "
2436 "optname %d unsupported!",
2437 getpid (), fd, fd, func_str, sid, sid, optname);
2445 func_str = "vppcom_session_attr[SOL_IPV6,GET_V6ONLY]";
2447 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2449 getpid (), fd, fd, func_str, sid, sid);
2450 rv = vppcom_session_attr (sid, VPPCOM_ATTR_GET_V6ONLY,
2455 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s(): "
2456 "sid %u (0x%x), SOL_IPV6, "
2457 "optname %d unsupported!",
2458 getpid (), fd, fd, func_str, sid, sid, optname);
2466 func_str = "vppcom_session_attr[SOL_SOCKET,GET_ACCEPTCONN]";
2468 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2470 getpid (), fd, fd, func_str, sid, sid);
2471 rv = vppcom_session_attr (sid, VPPCOM_ATTR_GET_LISTEN,
2475 func_str = "vppcom_session_attr[SOL_SOCKET,GET_KEEPALIVE]";
2477 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2479 getpid (), fd, fd, func_str, sid, sid);
2480 rv = vppcom_session_attr (sid, VPPCOM_ATTR_GET_KEEPALIVE,
2484 func_str = "vppcom_session_attr[SOL_SOCKET,GET_PROTOCOL]";
2486 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2488 getpid (), fd, fd, func_str, sid, sid);
2489 rv = vppcom_session_attr (sid, VPPCOM_ATTR_GET_PROTOCOL,
2491 *(int *) optval = *(int *) optval ? SOCK_DGRAM : SOCK_STREAM;
2494 func_str = "vppcom_session_attr[SOL_SOCKET,GET_TX_FIFO_LEN]";
2496 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2497 "sid %u (0x%x), optlen %d",
2498 getpid (), fd, fd, func_str, sid, sid, buflen);
2499 rv = vppcom_session_attr (sid, VPPCOM_ATTR_GET_TX_FIFO_LEN,
2503 func_str = "vppcom_session_attr[SOL_SOCKET,GET_RX_FIFO_LEN]";
2505 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2506 "sid %u (0x%x), optlen %d",
2507 getpid (), fd, fd, func_str, sid, sid, buflen);
2508 rv = vppcom_session_attr (sid, VPPCOM_ATTR_GET_RX_FIFO_LEN,
2512 func_str = "vppcom_session_attr[SOL_SOCKET,GET_REUSEADDR]";
2514 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2516 getpid (), fd, fd, func_str, sid, sid);
2517 rv = vppcom_session_attr (sid, VPPCOM_ATTR_GET_REUSEADDR,
2521 func_str = "vppcom_session_attr[SOL_SOCKET,GET_BROADCAST]";
2523 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2525 getpid (), fd, fd, func_str, sid, sid);
2526 rv = vppcom_session_attr (sid, VPPCOM_ATTR_GET_BROADCAST,
2530 func_str = "vppcom_session_attr[SOL_SOCKET,GET_ERROR]";
2532 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2534 getpid (), fd, fd, func_str, sid, sid);
2535 rv = vppcom_session_attr (sid, VPPCOM_ATTR_GET_ERROR,
2540 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s(): "
2541 "sid %u (0x%x), SOL_SOCKET, "
2542 "optname %d unsupported!",
2543 getpid (), fd, fd, func_str, sid, sid, optname);
2551 if (rv != VPPCOM_OK)
2559 func_str = "libc_getsockopt";
2562 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): level %d, "
2563 "optname %d, optval %p, optlen %d",
2564 getpid (), fd, fd, func_str, level, optname,
2567 rv = libc_getsockopt (fd, level, optname, optval, optlen);
2574 int errno_val = errno;
2576 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! "
2577 "rv %d, errno = %d", getpid (), fd, fd,
2578 func_str, rv, errno_val);
2582 clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)",
2583 getpid (), fd, fd, rv, rv);
2589 setsockopt (int fd, int level, int optname,
2590 const void *optval, socklen_t optlen)
2593 const char *func_str = __func__;
2594 u32 sid = vcom_sid_from_fd (fd);
2596 if ((errno = -vcom_init ()))
2599 if (sid != INVALID_SESSION_ID)
2609 func_str = "vppcom_session_attr[SOL_TCP,SET_TCP_NODELAY]";
2611 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2613 getpid (), fd, fd, func_str, sid, sid);
2614 rv = vppcom_session_attr (sid, VPPCOM_ATTR_SET_TCP_NODELAY,
2615 (void *) optval, &optlen);
2618 func_str = "vppcom_session_attr[SOL_TCP,SET_TCP_USER_MSS]";
2620 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2622 getpid (), fd, fd, func_str, sid, sid);
2623 rv = vppcom_session_attr (sid, VPPCOM_ATTR_SET_TCP_USER_MSS,
2624 (void *) optval, &optlen);
2627 func_str = "vppcom_session_attr[SOL_TCP,SET_TCP_KEEPIDLE]";
2629 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2631 getpid (), fd, fd, func_str, sid, sid);
2632 rv = vppcom_session_attr (sid, VPPCOM_ATTR_SET_TCP_KEEPIDLE,
2633 (void *) optval, &optlen);
2636 func_str = "vppcom_session_attr[SOL_TCP,SET_TCP_KEEPINTVL]";
2638 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2639 "sid %u (0x%x), SOL_TCP",
2640 getpid (), fd, fd, func_str, sid, sid);
2641 rv = vppcom_session_attr (sid, VPPCOM_ATTR_SET_TCP_KEEPINTVL,
2642 (void *) optval, &optlen);
2646 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s(): "
2647 "sid %u (0x%x), SOL_TCP, "
2648 "optname %d unsupported!",
2649 getpid (), fd, fd, func_str, sid, sid, optname);
2657 func_str = "vppcom_session_attr[SOL_IPV6,SET_V6ONLY]";
2659 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2661 getpid (), fd, fd, func_str, sid, sid);
2662 rv = vppcom_session_attr (sid, VPPCOM_ATTR_SET_V6ONLY,
2663 (void *) optval, &optlen);
2667 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s(): "
2668 "sid %u (0x%x), SOL_IPV6, "
2669 "optname %d unsupported!",
2670 getpid (), fd, fd, func_str, sid, sid, optname);
2678 func_str = "vppcom_session_attr[SOL_SOCKET,SET_KEEPALIVE]";
2680 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2682 getpid (), fd, fd, func_str, sid, sid);
2683 rv = vppcom_session_attr (sid, VPPCOM_ATTR_SET_KEEPALIVE,
2684 (void *) optval, &optlen);
2687 func_str = "vppcom_session_attr[SOL_SOCKET,SET_REUSEADDR]";
2689 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2691 getpid (), fd, fd, func_str, sid, sid);
2692 rv = vppcom_session_attr (sid, VPPCOM_ATTR_SET_REUSEADDR,
2693 (void *) optval, &optlen);
2696 func_str = "vppcom_session_attr[SOL_SOCKET,SET_BROADCAST]";
2698 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2700 getpid (), fd, fd, func_str, sid, sid);
2701 rv = vppcom_session_attr (sid, VPPCOM_ATTR_SET_BROADCAST,
2702 (void *) optval, &optlen);
2706 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s(): "
2707 "sid %u (0x%x), SOL_SOCKET, "
2708 "optname %d unsupported!",
2709 getpid (), fd, fd, func_str, sid, sid, optname);
2717 if (rv != VPPCOM_OK)
2725 func_str = "libc_setsockopt";
2728 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): level %d, "
2729 "optname %d, optval %p, optlen %d",
2730 getpid (), fd, fd, func_str, level, optname,
2733 rv = libc_setsockopt (fd, level, optname, optval, optlen);
2740 int errno_val = errno;
2742 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! "
2743 "rv %d, errno = %d", getpid (), fd, fd,
2744 func_str, rv, errno_val);
2748 clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)",
2749 getpid (), fd, fd, rv, rv);
2755 listen (int fd, int n)
2758 const char *func_str;
2759 u32 sid = vcom_sid_from_fd (fd);
2761 if ((errno = -vcom_init ()))
2764 if (sid != INVALID_SESSION_ID)
2766 func_str = "vppcom_session_listen";
2770 ("LDP<%d>: fd %d (0x%x): calling %s(): sid %u (0x%x), n %d",
2771 getpid (), fd, fd, func_str, sid, sid, n);
2773 rv = vppcom_session_listen (sid, n);
2774 if (rv != VPPCOM_OK)
2782 func_str = "libc_listen";
2785 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): n %d",
2786 getpid (), fd, fd, func_str, n);
2788 rv = libc_listen (fd, n);
2795 int errno_val = errno;
2797 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! "
2798 "rv %d, errno = %d", getpid (), fd, fd,
2799 func_str, rv, errno_val);
2803 clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)",
2804 getpid (), fd, fd, rv, rv);
2810 vcom_accept4 (int listen_fd, __SOCKADDR_ARG addr,
2811 socklen_t * __restrict addr_len, int flags)
2814 const char *func_str;
2815 u32 listen_sid = vcom_sid_from_fd (listen_fd);
2818 if ((errno = -vcom_init ()))
2821 if (listen_sid != INVALID_SESSION_ID)
2824 u8 src_addr[sizeof (struct sockaddr_in6)];
2825 memset (&ep, 0, sizeof (ep));
2828 func_str = "vppcom_session_accept";
2831 clib_warning ("LDP<%d>: listen fd %d (0x%x): calling %s(): "
2832 "listen sid %u (0x%x), ep %p, flags 0x%x",
2833 getpid (), listen_fd, listen_fd, func_str,
2834 listen_sid, listen_sid, ep, flags);
2836 accept_sid = vppcom_session_accept (listen_sid, &ep, flags);
2839 errno = -accept_sid;
2844 rv = vcom_copy_ep_to_sockaddr (addr, addr_len, &ep);
2845 if (rv != VPPCOM_OK)
2847 (void) vppcom_session_close ((u32) accept_sid);
2853 func_str = "vcom_fd_from_sid";
2855 clib_warning ("LDP<%d>: listen fd %d (0x%x): calling %s(): "
2856 "accept sid %u (0x%x), ep %p, flags 0x%x",
2857 getpid (), listen_fd, listen_fd,
2858 func_str, accept_sid, accept_sid, ep, flags);
2859 rv = vcom_fd_from_sid ((u32) accept_sid);
2862 (void) vppcom_session_close ((u32) accept_sid);
2871 func_str = "libc_accept4";
2874 clib_warning ("LDP<%d>: listen fd %d (0x%x): calling %s(): "
2875 "addr %p, addr_len %p, flags 0x%x",
2876 getpid (), listen_fd, listen_fd, func_str,
2877 addr, addr_len, flags);
2879 rv = libc_accept4 (listen_fd, addr, addr_len, flags);
2886 int errno_val = errno;
2888 clib_warning ("LDP<%d>: ERROR: listen fd %d (0x%x): %s() failed! "
2889 "rv %d, errno = %d", getpid (), listen_fd,
2890 listen_fd, func_str, rv, errno_val);
2894 clib_warning ("LDP<%d>: listen fd %d (0x%x): returning %d (0x%x)",
2895 getpid (), listen_fd, listen_fd, rv, rv);
2901 accept4 (int fd, __SOCKADDR_ARG addr, socklen_t * __restrict addr_len,
2904 return vcom_accept4 (fd, addr, addr_len, flags);
2908 accept (int fd, __SOCKADDR_ARG addr, socklen_t * __restrict addr_len)
2910 return vcom_accept4 (fd, addr, addr_len, 0);
2914 shutdown (int fd, int how)
2917 const char *func_str;
2918 u32 sid = vcom_sid_from_fd (fd);
2920 if ((errno = -vcom_init ()))
2923 if (sid != INVALID_SESSION_ID)
2925 func_str = __func__;
2927 clib_warning ("LDP<%d>: LDP-TBD", getpid ());
2933 func_str = "libc_shutdown";
2936 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): how %d",
2937 getpid (), fd, fd, func_str, how);
2939 rv = libc_shutdown (fd, how);
2946 int errno_val = errno;
2948 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! "
2949 "rv %d, errno = %d", getpid (), fd, fd,
2950 func_str, rv, errno_val);
2954 clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)",
2955 getpid (), fd, fd, rv, rv);
2961 epoll_create1 (int flags)
2963 const char *func_str;
2966 if ((errno = -vcom_init ()))
2969 func_str = "vppcom_epoll_create";
2972 clib_warning ("LDP<%d>: calling %s()", getpid (), func_str);
2974 rv = vppcom_epoll_create ();
2976 if (PREDICT_FALSE (rv < 0))
2982 rv = vcom_fd_from_sid ((u32) rv);
2988 int errno_val = errno;
2990 clib_warning ("LDP<%d>: ERROR: %s() failed! "
2991 "rv %d, errno = %d",
2992 getpid (), func_str, rv, errno_val);
2996 clib_warning ("LDP<%d>: returning epfd %d (0x%x)", getpid (), rv, rv);
3002 epoll_create (int size)
3004 return epoll_create1 (0);
3008 epoll_ctl (int epfd, int op, int fd, struct epoll_event *event)
3011 const char *func_str;
3012 u32 vep_idx = vcom_sid_from_fd (epfd);
3014 if ((errno = -vcom_init ()))
3017 if (vep_idx != INVALID_SESSION_ID)
3019 u32 sid = vcom_sid_from_fd (fd);
3021 if (sid != INVALID_SESSION_ID)
3023 func_str = "vppcom_epoll_create";
3026 clib_warning ("LDP<%d>: epfd %d (0x%x): calling %s(): "
3027 "vep_idx %d (0x%x), op %d, sid %u (0x%x), event %p",
3028 getpid (), epfd, epfd, func_str, vep_idx, vep_idx,
3031 rv = vppcom_epoll_ctl (vep_idx, op, sid, event);
3032 if (rv != VPPCOM_OK)
3041 u32 size = sizeof (epfd);
3043 func_str = "vppcom_session_attr[GET_LIBC_EPFD]";
3044 epfd = vppcom_session_attr (vep_idx, VPPCOM_ATTR_GET_LIBC_EPFD,
3048 func_str = "libc_epoll_create1";
3051 clib_warning ("LDP<%d>: calling %s(): EPOLL_CLOEXEC",
3052 getpid (), func_str);
3054 epfd = libc_epoll_create1 (EPOLL_CLOEXEC);
3061 func_str = "vppcom_session_attr[SET_LIBC_EPFD]";
3062 rv = vppcom_session_attr (vep_idx, VPPCOM_ATTR_SET_LIBC_EPFD,
3071 else if (PREDICT_FALSE (epfd < 0))
3078 rv = libc_epoll_ctl (epfd, op, fd, event);
3083 func_str = "libc_epoll_ctl";
3086 clib_warning ("LDP<%d>: epfd %d (0x%x): calling %s(): "
3087 "op %d, fd %d (0x%x), event %p",
3088 getpid (), epfd, epfd, func_str, op, fd, fd, event);
3090 rv = libc_epoll_ctl (epfd, op, fd, event);
3098 int errno_val = errno;
3100 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! "
3101 "rv %d, errno = %d", getpid (), fd, fd,
3102 func_str, rv, errno_val);
3106 clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)",
3107 getpid (), fd, fd, rv, rv);
3113 vcom_epoll_pwait (int epfd, struct epoll_event *events,
3114 int maxevents, int timeout, const sigset_t * sigmask)
3116 const char *func_str;
3118 double time_to_wait = (double) 0;
3119 double time_out, now = 0;
3120 u32 vep_idx = vcom_sid_from_fd (epfd);
3123 if ((errno = -vcom_init ()))
3126 if (PREDICT_FALSE (!events || (timeout < -1)))
3132 if (PREDICT_FALSE (vep_idx == INVALID_SESSION_ID))
3134 clib_warning ("LDP<%d>: ERROR: epfd %d (0x%x): bad vep_idx %d (0x%x)!",
3135 getpid (), epfd, epfd, vep_idx, vep_idx);
3140 time_to_wait = ((timeout >= 0) ? (double) timeout / (double) 1000 : 0);
3141 time_out = clib_time_now (&vcom->clib_time) + time_to_wait;
3143 func_str = "vppcom_session_attr[GET_LIBC_EPFD]";
3144 libc_epfd = vppcom_session_attr (vep_idx, VPPCOM_ATTR_GET_LIBC_EPFD, 0, 0);
3145 if (PREDICT_FALSE (libc_epfd < 0))
3153 clib_warning ("LDP<%d>: epfd %d (0x%x): vep_idx %d (0x%x), "
3154 "libc_epfd %d (0x%x), events %p, maxevents %d, "
3155 "timeout %d, sigmask %p", getpid (), epfd, epfd,
3156 vep_idx, vep_idx, libc_epfd, libc_epfd, events,
3157 maxevents, timeout, sigmask);
3160 if (!vcom->epoll_wait_vcl)
3162 func_str = "vppcom_epoll_wait";
3165 clib_warning ("LDP<%d>: epfd %d (0x%x): calling %s(): "
3166 "vep_idx %d (0x%x), events %p, maxevents %d",
3167 getpid (), epfd, epfd, func_str,
3168 vep_idx, vep_idx, events, maxevents);
3170 rv = vppcom_epoll_wait (vep_idx, events, maxevents, 0);
3173 vcom->epoll_wait_vcl = 1;
3184 vcom->epoll_wait_vcl = 0;
3188 func_str = "libc_epoll_pwait";
3191 clib_warning ("LDP<%d>: epfd %d (0x%x): calling %s(): "
3192 "libc_epfd %d (0x%x), events %p, "
3193 "maxevents %d, sigmask %p",
3194 getpid (), epfd, epfd, func_str,
3195 libc_epfd, libc_epfd, events, maxevents, sigmask);
3197 rv = libc_epoll_pwait (epfd, events, maxevents, 1, sigmask);
3203 now = clib_time_now (&vcom->clib_time);
3205 while (now < time_out);
3212 int errno_val = errno;
3214 clib_warning ("LDP<%d>: ERROR: epfd %d (0x%x): %s() failed! "
3215 "rv %d, errno = %d", getpid (), epfd, epfd,
3216 func_str, rv, errno_val);
3220 clib_warning ("LDP<%d>: epfd %d (0x%x): returning %d (0x%x)",
3221 getpid (), epfd, epfd, rv, rv);
3227 epoll_pwait (int epfd, struct epoll_event *events,
3228 int maxevents, int timeout, const sigset_t * sigmask)
3230 return vcom_epoll_pwait (epfd, events, maxevents, timeout, sigmask);
3234 epoll_wait (int epfd, struct epoll_event *events, int maxevents, int timeout)
3236 return vcom_epoll_pwait (epfd, events, maxevents, timeout, NULL);
3240 poll (struct pollfd *fds, nfds_t nfds, int timeout)
3242 const char *func_str = __func__;
3243 int rv, i, n_libc_fds, n_revents;
3246 double wait_for_time;
3249 clib_warning ("LDP<%d>: fds %p, nfds %d, timeout %d",
3250 getpid (), fds, nfds, timeout);
3253 wait_for_time = (f64) timeout / 1000;
3258 for (i = 0; i < nfds; i++)
3263 clib_warning ("LDP<%d>: fds[%d].fd %d (0x%0x), .events = 0x%x, "
3264 ".revents = 0x%x", getpid (), i, fds[i].fd,
3265 fds[i].fd, fds[i].events, fds[i].revents);
3267 sid = vcom_sid_from_fd (fds[i].fd);
3268 if (sid != INVALID_SESSION_ID)
3270 fds[i].fd = -fds[i].fd;
3271 vec_add2 (vcom->vcl_poll, vp, 1);
3274 vp->events = fds[i].events;
3275 #ifdef __USE_XOPEN2K
3276 if (fds[i].events & POLLRDNORM)
3277 vp->events |= POLLIN;
3278 if (fds[i].events & POLLWRNORM)
3279 vp->events |= POLLOUT;
3281 vp->revents = &fds[i].revents;
3291 if (vec_len (vcom->vcl_poll))
3293 func_str = "vppcom_poll";
3296 clib_warning ("LDP<%d>: calling %s(): "
3297 "vcl_poll %p, n_sids %u (0x%x): "
3299 getpid (), func_str, vcom->vcl_poll,
3300 vec_len (vcom->vcl_poll), vec_len (vcom->vcl_poll),
3303 rv = vppcom_poll (vcom->vcl_poll, vec_len (vcom->vcl_poll), 0);
3316 func_str = "libc_poll";
3319 clib_warning ("LDP<%d>: calling %s(): fds %p, nfds %u: n_sids %u",
3320 getpid (), fds, nfds, vec_len (vcom->vcl_poll));
3322 rv = libc_poll (fds, nfds, 0);
3335 while ((wait_for_time == -1) ||
3336 (clib_time_now (&vcom->clib_time) < wait_for_time));
3340 vec_foreach (vp, vcom->vcl_poll)
3342 fds[vp->fds_ndx].fd = -fds[vp->fds_ndx].fd;
3343 #ifdef __USE_XOPEN2K
3344 if ((fds[vp->fds_ndx].revents & POLLIN) &&
3345 (fds[vp->fds_ndx].events & POLLRDNORM))
3346 fds[vp->fds_ndx].revents |= POLLRDNORM;
3347 if ((fds[vp->fds_ndx].revents & POLLOUT) &&
3348 (fds[vp->fds_ndx].events & POLLWRNORM))
3349 fds[vp->fds_ndx].revents |= POLLWRNORM;
3352 vec_reset_length (vcom->vcl_poll);
3358 int errno_val = errno;
3360 clib_warning ("LDP<%d>: ERROR: %s() failed! "
3361 "rv %d, errno = %d", getpid (),
3362 func_str, rv, errno_val);
3367 clib_warning ("LDP<%d>: returning %d (0x%x): n_sids %u, "
3368 "n_libc_fds %d", getpid (), rv, rv,
3369 vec_len (vcom->vcl_poll), n_libc_fds);
3371 for (i = 0; i < nfds; i++)
3376 clib_warning ("LDP<%d>: fds[%d].fd %d (0x%0x), "
3377 ".events = 0x%x, .revents = 0x%x",
3378 getpid (), i, fds[i].fd, fds[i].fd,
3379 fds[i].events, fds[i].revents);
3390 ppoll (struct pollfd *fds, nfds_t nfds,
3391 const struct timespec *timeout, const sigset_t * sigmask)
3393 if ((errno = -vcom_init ()))
3396 clib_warning ("LDP<%d>: LDP-TBD", getpid ());
3404 void CONSTRUCTOR_ATTRIBUTE vcom_constructor (void);
3406 void DESTRUCTOR_ATTRIBUTE vcom_destructor (void);
3409 * This function is called when the library is loaded
3412 vcom_constructor (void)
3414 swrap_constructor ();
3415 if (vcom_init () != 0)
3416 fprintf (stderr, "\nLDP<%d>: ERROR: vcom_constructor: failed!\n",
3419 clib_warning ("LDP<%d>: VCOM constructor: done!\n", getpid ());
3423 * This function is called when the library is unloaded
3426 vcom_destructor (void)
3428 swrap_destructor ();
3431 vppcom_app_destroy ();
3435 /* Don't use clib_warning() here because that calls writev()
3436 * which will call vcom_init().
3438 printf ("%s:%d: LDP<%d>: VCOM destructor: done!\n",
3439 __func__, __LINE__, getpid ());
3444 * fd.io coding-style-patch-verification: ON
3447 * eval: (c-set-style "gnu")