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 clib_warning ("LDP<%d>: fd %d (0x%x) ", getpid (), fd, fd);
1592 if (sid != INVALID_SESSION_ID)
1595 u8 addr_buf[sizeof (struct in6_addr)];
1596 u32 size = sizeof (ep);
1599 func_str = "vppcom_session_attr[GET_PEER_ADDR]";
1602 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): sid %u (0x%x), "
1604 getpid (), fd, fd, func_str, sid, sid, addr, len);
1606 rv = vppcom_session_attr (sid, VPPCOM_ATTR_GET_PEER_ADDR, &ep, &size);
1607 if (rv != VPPCOM_OK)
1614 rv = vcom_copy_ep_to_sockaddr (addr, len, &ep);
1615 if (rv != VPPCOM_OK)
1624 func_str = "libc_getpeername";
1627 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
1629 getpid (), fd, fd, func_str, addr, len);
1631 rv = libc_getpeername (fd, addr, len);
1638 int errno_val = errno;
1640 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! "
1641 "rv %d, errno = %d", getpid (), fd, fd,
1642 func_str, rv, errno_val);
1646 clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)",
1647 getpid (), fd, fd, rv, rv);
1653 send (int fd, const void *buf, size_t n, int flags)
1656 const char *func_str;
1657 u32 sid = vcom_sid_from_fd (fd);
1659 if ((errno = -vcom_init ()))
1662 if (sid != INVALID_SESSION_ID)
1665 func_str = "vppcom_session_sendto";
1668 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): sid %u (0x%x), "
1669 "buf %p, n %u, flags 0x%x",
1670 getpid (), fd, fd, func_str, sid, sid, buf, n, flags);
1672 size = vppcom_session_sendto (sid, (void *) buf, n, flags, NULL);
1673 if (size != VPPCOM_OK)
1681 func_str = "libc_send";
1684 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
1685 "buf %p, n %u, flags 0x%x",
1686 getpid (), fd, fd, func_str, buf, n, flags);
1688 size = libc_send (fd, buf, n, flags);
1695 int errno_val = errno;
1697 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! "
1698 "rv %d, errno = %d", getpid (), fd, fd,
1699 func_str, size, errno_val);
1703 clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)",
1704 getpid (), fd, fd, size, size);
1710 sendfile (int out_fd, int in_fd, off_t * offset, size_t len)
1713 const char *func_str;
1714 u32 sid = vcom_sid_from_fd (out_fd);
1716 if ((errno = -vcom_init ()))
1719 if (sid != INVALID_SESSION_ID)
1722 ssize_t results = 0;
1723 size_t n_bytes_left = len;
1724 size_t bytes_to_read;
1728 u32 flags, flags_len = sizeof (flags);
1730 func_str = "vppcom_session_attr[GET_FLAGS]";
1731 rv = vppcom_session_attr (sid, VPPCOM_ATTR_GET_FLAGS, &flags,
1733 if (PREDICT_FALSE (rv != VPPCOM_OK))
1735 clib_warning ("LDP<%d>: ERROR: out fd %d (0x%x): %s(): "
1736 "sid %u (0x%x), returned %d (%s)!", getpid (),
1737 out_fd, out_fd, func_str, sid, sid, rv,
1738 vppcom_retval_str (rv));
1740 vec_reset_length (vcom->io_buffer);
1748 off_t off = lseek (in_fd, *offset, SEEK_SET);
1749 if (PREDICT_FALSE (off == -1))
1753 clib_warning ("LDP<%d>: ERROR: out fd %d (0x%x): %s(): "
1754 "SEEK_SET failed: in_fd %d, offset %p, "
1755 "*offset %ld, rv %ld, errno %d", getpid (),
1756 out_fd, out_fd, in_fd, offset, *offset, off,
1763 ASSERT (off == *offset);
1768 func_str = "vppcom_session_attr[GET_NWRITE]";
1769 size = vppcom_session_attr (sid, VPPCOM_ATTR_GET_NWRITE, 0, 0);
1773 ("LDP<%d>: ERROR: fd %d (0x%x): %s(): sid %u (0x%x), "
1774 "returned %d (%s)!", getpid (), out_fd, out_fd, func_str,
1775 sid, sid, size, vppcom_retval_str (size));
1776 vec_reset_length (vcom->io_buffer);
1782 bytes_to_read = size;
1785 ("LDP<%d>: fd %d (0x%x): called %s(): sid %u (0x%x), "
1786 "results %ld, n_bytes_left %lu, bytes_to_read %lu", getpid (),
1787 out_fd, out_fd, func_str, sid, sid, results, n_bytes_left,
1790 if (bytes_to_read == 0)
1792 if (flags & O_NONBLOCK)
1797 clib_warning ("LDP<%d>: fd %d (0x%x): sid %u (0x%x): "
1799 getpid (), out_fd, out_fd, sid, sid);
1807 bytes_to_read = clib_min (n_bytes_left, bytes_to_read);
1808 vec_validate (vcom->io_buffer, bytes_to_read);
1809 nbytes = libc_read (in_fd, vcom->io_buffer, bytes_to_read);
1812 func_str = "libc_read";
1814 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s(): in_fd (%d), "
1815 "io_buffer %p, bytes_to_read %lu, rv %d, "
1816 "errno %d", getpid (), out_fd, out_fd, func_str,
1817 in_fd, vcom->io_buffer, bytes_to_read, nbytes,
1823 vec_reset_length (vcom->io_buffer);
1829 func_str = "vppcom_session_write";
1832 ("LDP<%d>: fd %d (0x%x): calling %s(): sid %u (0x%x), "
1833 "buf %p, nbytes %u: results %d, n_bytes_left %d", getpid (),
1834 out_fd, out_fd, func_str, sid, sid, vcom->io_buffer, nbytes,
1835 results, n_bytes_left);
1837 size = vppcom_session_write (sid, vcom->io_buffer, nbytes);
1840 if (size == VPPCOM_EAGAIN)
1842 if (flags & O_NONBLOCK)
1848 ("LDP<%d>: fd %d (0x%x): sid %u (0x%x): "
1849 "EAGAIN", getpid (), out_fd, out_fd, sid, sid);
1859 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s():"
1860 "sid %u, io_buffer %p, nbytes %u "
1862 getpid (), out_fd, out_fd, func_str,
1863 sid, vcom->io_buffer, nbytes,
1864 size, vppcom_retval_str (size));
1868 vec_reset_length (vcom->io_buffer);
1877 ASSERT (n_bytes_left >= nbytes);
1878 n_bytes_left = n_bytes_left - nbytes;
1880 while (n_bytes_left > 0);
1883 vec_reset_length (vcom->io_buffer);
1886 off_t off = lseek (in_fd, *offset, SEEK_SET);
1887 if (PREDICT_FALSE (off == -1))
1891 clib_warning ("LDP<%d>: ERROR: %s(): SEEK_SET failed: "
1892 "in_fd %d, offset %p, *offset %ld, "
1893 "rv %ld, errno %d", getpid (), in_fd,
1894 offset, *offset, off, errno_val);
1900 ASSERT (off == *offset);
1901 *offset += results + 1;
1913 func_str = "libc_send";
1916 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
1917 "in_fd %d, offset %p, len %u",
1918 getpid (), out_fd, out_fd, func_str,
1919 in_fd, offset, len);
1921 size = libc_sendfile (out_fd, in_fd, offset, len);
1929 int errno_val = errno;
1931 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! "
1932 "rv %d, errno = %d", getpid (), out_fd, out_fd,
1933 func_str, size, errno_val);
1937 clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)",
1938 getpid (), out_fd, out_fd, size, size);
1944 sendfile64 (int out_fd, int in_fd, off_t * offset, size_t len)
1946 return sendfile (out_fd, in_fd, offset, len);
1950 recv (int fd, void *buf, size_t n, int flags)
1953 const char *func_str;
1954 u32 sid = vcom_sid_from_fd (fd);
1956 if ((errno = -vcom_init ()))
1959 if (sid != INVALID_SESSION_ID)
1961 func_str = "vppcom_session_recvfrom";
1964 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
1965 "sid %u (0x%x), buf %p, n %u, flags 0x%x", getpid (),
1966 fd, fd, func_str, sid, sid, buf, n, flags);
1968 size = vppcom_session_recvfrom (sid, buf, n, flags, NULL);
1977 func_str = "libc_recv";
1980 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
1981 "buf %p, n %u, flags 0x%x", getpid (),
1982 fd, fd, func_str, buf, n, flags);
1984 size = libc_recv (fd, buf, n, flags);
1991 int errno_val = errno;
1993 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! "
1994 "rv %d, errno = %d", getpid (), fd, fd,
1995 func_str, size, errno_val);
1999 clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)",
2000 getpid (), fd, fd, size, size);
2006 sendto (int fd, const void *buf, size_t n, int flags,
2007 __CONST_SOCKADDR_ARG addr, socklen_t addr_len)
2010 const char *func_str = __func__;
2011 u32 sid = vcom_sid_from_fd (fd);
2013 if ((errno = -vcom_init ()))
2016 if (sid != INVALID_SESSION_ID)
2018 vppcom_endpt_t *ep = 0;
2024 ep->vrf = VPPCOM_VRF_DEFAULT;
2025 switch (addr->sa_family)
2028 ep->is_ip4 = VPPCOM_IS_IP4;
2030 (uint8_t *) & ((const struct sockaddr_in *) addr)->sin_addr;
2032 (uint16_t) ((const struct sockaddr_in *) addr)->sin_port;
2036 ep->is_ip4 = VPPCOM_IS_IP6;
2038 (uint8_t *) & ((const struct sockaddr_in6 *) addr)->sin6_addr;
2040 (uint16_t) ((const struct sockaddr_in6 *) addr)->sin6_port;
2044 errno = EAFNOSUPPORT;
2050 func_str = "vppcom_session_sendto";
2053 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2054 "sid %u (0x%x), buf %p, n %u, flags 0x%x, ep %p",
2055 getpid (), fd, fd, func_str, sid, sid, buf, n,
2058 size = vppcom_session_sendto (sid, (void *) buf, n, flags, ep);
2067 func_str = "libc_sendto";
2070 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2071 "buf %p, n %u, flags 0x%x, addr %p, addr_len %d",
2072 getpid (), fd, fd, func_str, buf, n, flags,
2075 size = libc_sendto (fd, buf, n, flags, addr, addr_len);
2083 int errno_val = errno;
2085 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! "
2086 "rv %d, errno = %d", getpid (), fd, fd,
2087 func_str, size, errno_val);
2091 clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)",
2092 getpid (), fd, fd, size, size);
2098 recvfrom (int fd, void *__restrict buf, size_t n, int flags,
2099 __SOCKADDR_ARG addr, socklen_t * __restrict addr_len)
2102 const char *func_str;
2103 u32 sid = vcom_sid_from_fd (fd);
2105 if ((errno = -vcom_init ()))
2108 if (sid != INVALID_SESSION_ID)
2111 u8 src_addr[sizeof (struct sockaddr_in6)];
2113 func_str = "vppcom_session_recvfrom";
2116 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2117 "sid %u (0x%x), buf %p, n %u, flags 0x%x, ep %p",
2118 getpid (), fd, fd, func_str, sid, sid, buf, n,
2123 size = vppcom_session_recvfrom (sid, buf, n, flags, &ep);
2126 size = vcom_copy_ep_to_sockaddr (addr, addr_len, &ep);
2129 size = vppcom_session_recvfrom (sid, buf, n, flags, NULL);
2139 func_str = "libc_recvfrom";
2142 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2143 "buf %p, n %u, flags 0x%x, addr %p, addr_len %d",
2144 getpid (), fd, fd, func_str, buf, n, flags,
2147 size = libc_recvfrom (fd, buf, n, flags, addr, addr_len);
2154 int errno_val = errno;
2156 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! "
2157 "rv %d, errno = %d", getpid (), fd, fd,
2158 func_str, size, errno_val);
2162 clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)",
2163 getpid (), fd, fd, size, size);
2169 sendmsg (int fd, const struct msghdr * message, int flags)
2172 const char *func_str;
2173 u32 sid = vcom_sid_from_fd (fd);
2175 if ((errno = -vcom_init ()))
2178 if (sid != INVALID_SESSION_ID)
2180 func_str = __func__;
2182 clib_warning ("LDP<%d>: LDP-TBD", getpid ());
2188 func_str = "libc_sendmsg";
2191 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2192 "message %p, flags 0x%x",
2193 getpid (), fd, fd, func_str, message, flags);
2195 size = libc_sendmsg (fd, message, flags);
2202 int errno_val = errno;
2204 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! "
2205 "rv %d, errno = %d", getpid (), fd, fd,
2206 func_str, size, errno_val);
2210 clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)",
2211 getpid (), fd, fd, size, size);
2218 sendmmsg (int fd, struct mmsghdr *vmessages, unsigned int vlen, int flags)
2221 const char *func_str;
2222 u32 sid = vcom_sid_from_fd (fd);
2224 if ((errno = -vcom_init ()))
2227 if (sid != INVALID_SESSION_ID)
2229 clib_warning ("LDP<%d>: LDP-TBD", getpid ());
2235 func_str = "libc_sendmmsg";
2238 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2239 "vmessages %p, vlen %u, flags 0x%x",
2240 getpid (), fd, fd, func_str, vmessages, vlen, flags);
2242 size = libc_sendmmsg (fd, vmessages, vlen, flags);
2249 int errno_val = errno;
2251 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! "
2252 "rv %d, errno = %d", getpid (), fd, fd,
2253 func_str, size, errno_val);
2257 clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)",
2258 getpid (), fd, fd, size, size);
2265 recvmsg (int fd, struct msghdr * message, int flags)
2268 const char *func_str;
2269 u32 sid = vcom_sid_from_fd (fd);
2271 if ((errno = -vcom_init ()))
2274 if (sid != INVALID_SESSION_ID)
2276 func_str = __func__;
2278 clib_warning ("LDP<%d>: LDP-TBD", getpid ());
2284 func_str = "libc_recvmsg";
2287 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2288 "message %p, flags 0x%x",
2289 getpid (), fd, fd, func_str, message, flags);
2291 size = libc_recvmsg (fd, message, flags);
2298 int errno_val = errno;
2300 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! "
2301 "rv %d, errno = %d", getpid (), fd, fd,
2302 func_str, size, errno_val);
2306 clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)",
2307 getpid (), fd, fd, size, size);
2314 recvmmsg (int fd, struct mmsghdr *vmessages,
2315 unsigned int vlen, int flags, struct timespec *tmo)
2318 const char *func_str;
2319 u32 sid = vcom_sid_from_fd (fd);
2321 if ((errno = -vcom_init ()))
2324 if (sid != INVALID_SESSION_ID)
2326 clib_warning ("LDP<%d>: LDP-TBD", getpid ());
2332 func_str = "libc_recvmmsg";
2335 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2336 "vmessages %p, vlen %u, flags 0x%x, tmo %p",
2337 getpid (), fd, fd, func_str, vmessages, vlen,
2340 size = libc_recvmmsg (fd, vmessages, vlen, flags, tmo);
2347 int errno_val = errno;
2349 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! "
2350 "rv %d, errno = %d", getpid (), fd, fd,
2351 func_str, size, errno_val);
2355 clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)",
2356 getpid (), fd, fd, size, size);
2363 getsockopt (int fd, int level, int optname,
2364 void *__restrict optval, socklen_t * __restrict optlen)
2367 const char *func_str = __func__;
2368 u32 sid = vcom_sid_from_fd (fd);
2369 u32 buflen = optlen ? (u32) * optlen : 0;
2371 if ((errno = -vcom_init ()))
2374 if (sid != INVALID_SESSION_ID)
2384 func_str = "vppcom_session_attr[SOL_TCP,GET_TCP_NODELAY]";
2386 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2388 getpid (), fd, fd, func_str, sid, sid);
2389 rv = vppcom_session_attr (sid, VPPCOM_ATTR_GET_TCP_NODELAY,
2393 func_str = "vppcom_session_attr[SOL_TCP,GET_TCP_USER_MSS]";
2395 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2397 getpid (), fd, fd, func_str, sid, sid);
2398 rv = vppcom_session_attr (sid, VPPCOM_ATTR_GET_TCP_USER_MSS,
2402 func_str = "vppcom_session_attr[SOL_TCP,GET_TCP_KEEPIDLE]";
2404 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2406 getpid (), fd, fd, func_str, sid, sid);
2407 rv = vppcom_session_attr (sid, VPPCOM_ATTR_GET_TCP_KEEPIDLE,
2411 func_str = "vppcom_session_attr[SOL_TCP,GET_TCP_KEEPINTVL]";
2413 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2414 "sid %u (0x%x), SOL_TCP",
2415 getpid (), fd, fd, func_str, sid, sid);
2416 rv = vppcom_session_attr (sid, VPPCOM_ATTR_GET_TCP_KEEPINTVL,
2420 if (optval && optlen && (*optlen == sizeof (struct tcp_info)))
2423 clib_warning ("LDP<%d>: fd %d (0x%x): sid %u (0x%x), "
2424 "SOL_TCP, TCP_INFO, optval %p, "
2425 "optlen %d: #LDP-NOP#",
2426 getpid (), fd, fd, sid, sid,
2428 memset (optval, 0, *optlen);
2436 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s(): "
2437 "sid %u (0x%x), SOL_TCP, "
2438 "optname %d unsupported!",
2439 getpid (), fd, fd, func_str, sid, sid, optname);
2447 func_str = "vppcom_session_attr[SOL_IPV6,GET_V6ONLY]";
2449 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2451 getpid (), fd, fd, func_str, sid, sid);
2452 rv = vppcom_session_attr (sid, VPPCOM_ATTR_GET_V6ONLY,
2457 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s(): "
2458 "sid %u (0x%x), SOL_IPV6, "
2459 "optname %d unsupported!",
2460 getpid (), fd, fd, func_str, sid, sid, optname);
2468 func_str = "vppcom_session_attr[SOL_SOCKET,GET_ACCEPTCONN]";
2470 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2472 getpid (), fd, fd, func_str, sid, sid);
2473 rv = vppcom_session_attr (sid, VPPCOM_ATTR_GET_LISTEN,
2477 func_str = "vppcom_session_attr[SOL_SOCKET,GET_KEEPALIVE]";
2479 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2481 getpid (), fd, fd, func_str, sid, sid);
2482 rv = vppcom_session_attr (sid, VPPCOM_ATTR_GET_KEEPALIVE,
2486 func_str = "vppcom_session_attr[SOL_SOCKET,GET_PROTOCOL]";
2488 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2490 getpid (), fd, fd, func_str, sid, sid);
2491 rv = vppcom_session_attr (sid, VPPCOM_ATTR_GET_PROTOCOL,
2493 *(int *) optval = *(int *) optval ? SOCK_DGRAM : SOCK_STREAM;
2496 func_str = "vppcom_session_attr[SOL_SOCKET,GET_TX_FIFO_LEN]";
2498 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2499 "sid %u (0x%x), optlen %d",
2500 getpid (), fd, fd, func_str, sid, sid, buflen);
2501 rv = vppcom_session_attr (sid, VPPCOM_ATTR_GET_TX_FIFO_LEN,
2505 func_str = "vppcom_session_attr[SOL_SOCKET,GET_RX_FIFO_LEN]";
2507 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2508 "sid %u (0x%x), optlen %d",
2509 getpid (), fd, fd, func_str, sid, sid, buflen);
2510 rv = vppcom_session_attr (sid, VPPCOM_ATTR_GET_RX_FIFO_LEN,
2514 func_str = "vppcom_session_attr[SOL_SOCKET,GET_REUSEADDR]";
2516 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2518 getpid (), fd, fd, func_str, sid, sid);
2519 rv = vppcom_session_attr (sid, VPPCOM_ATTR_GET_REUSEADDR,
2523 func_str = "vppcom_session_attr[SOL_SOCKET,GET_BROADCAST]";
2525 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2527 getpid (), fd, fd, func_str, sid, sid);
2528 rv = vppcom_session_attr (sid, VPPCOM_ATTR_GET_BROADCAST,
2532 func_str = "vppcom_session_attr[SOL_SOCKET,GET_ERROR]";
2534 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2536 getpid (), fd, fd, func_str, sid, sid);
2537 rv = vppcom_session_attr (sid, VPPCOM_ATTR_GET_ERROR,
2542 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s(): "
2543 "sid %u (0x%x), SOL_SOCKET, "
2544 "optname %d unsupported!",
2545 getpid (), fd, fd, func_str, sid, sid, optname);
2553 if (rv != VPPCOM_OK)
2561 func_str = "libc_getsockopt";
2564 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): level %d, "
2565 "optname %d, optval %p, optlen %d",
2566 getpid (), fd, fd, func_str, level, optname,
2569 rv = libc_getsockopt (fd, level, optname, optval, optlen);
2576 int errno_val = errno;
2578 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! "
2579 "rv %d, errno = %d", getpid (), fd, fd,
2580 func_str, rv, errno_val);
2584 clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)",
2585 getpid (), fd, fd, rv, rv);
2591 setsockopt (int fd, int level, int optname,
2592 const void *optval, socklen_t optlen)
2595 const char *func_str = __func__;
2596 u32 sid = vcom_sid_from_fd (fd);
2598 if ((errno = -vcom_init ()))
2601 if (sid != INVALID_SESSION_ID)
2611 func_str = "vppcom_session_attr[SOL_TCP,SET_TCP_NODELAY]";
2613 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2615 getpid (), fd, fd, func_str, sid, sid);
2616 rv = vppcom_session_attr (sid, VPPCOM_ATTR_SET_TCP_NODELAY,
2617 (void *) optval, &optlen);
2620 func_str = "vppcom_session_attr[SOL_TCP,SET_TCP_USER_MSS]";
2622 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2624 getpid (), fd, fd, func_str, sid, sid);
2625 rv = vppcom_session_attr (sid, VPPCOM_ATTR_SET_TCP_USER_MSS,
2626 (void *) optval, &optlen);
2629 func_str = "vppcom_session_attr[SOL_TCP,SET_TCP_KEEPIDLE]";
2631 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2633 getpid (), fd, fd, func_str, sid, sid);
2634 rv = vppcom_session_attr (sid, VPPCOM_ATTR_SET_TCP_KEEPIDLE,
2635 (void *) optval, &optlen);
2638 func_str = "vppcom_session_attr[SOL_TCP,SET_TCP_KEEPINTVL]";
2640 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2641 "sid %u (0x%x), SOL_TCP",
2642 getpid (), fd, fd, func_str, sid, sid);
2643 rv = vppcom_session_attr (sid, VPPCOM_ATTR_SET_TCP_KEEPINTVL,
2644 (void *) optval, &optlen);
2648 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s(): "
2649 "sid %u (0x%x), SOL_TCP, "
2650 "optname %d unsupported!",
2651 getpid (), fd, fd, func_str, sid, sid, optname);
2659 func_str = "vppcom_session_attr[SOL_IPV6,SET_V6ONLY]";
2661 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2663 getpid (), fd, fd, func_str, sid, sid);
2664 rv = vppcom_session_attr (sid, VPPCOM_ATTR_SET_V6ONLY,
2665 (void *) optval, &optlen);
2669 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s(): "
2670 "sid %u (0x%x), SOL_IPV6, "
2671 "optname %d unsupported!",
2672 getpid (), fd, fd, func_str, sid, sid, optname);
2680 func_str = "vppcom_session_attr[SOL_SOCKET,SET_KEEPALIVE]";
2682 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2684 getpid (), fd, fd, func_str, sid, sid);
2685 rv = vppcom_session_attr (sid, VPPCOM_ATTR_SET_KEEPALIVE,
2686 (void *) optval, &optlen);
2689 func_str = "vppcom_session_attr[SOL_SOCKET,SET_REUSEADDR]";
2691 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2693 getpid (), fd, fd, func_str, sid, sid);
2694 rv = vppcom_session_attr (sid, VPPCOM_ATTR_SET_REUSEADDR,
2695 (void *) optval, &optlen);
2698 func_str = "vppcom_session_attr[SOL_SOCKET,SET_BROADCAST]";
2700 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2702 getpid (), fd, fd, func_str, sid, sid);
2703 rv = vppcom_session_attr (sid, VPPCOM_ATTR_SET_BROADCAST,
2704 (void *) optval, &optlen);
2708 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s(): "
2709 "sid %u (0x%x), SOL_SOCKET, "
2710 "optname %d unsupported!",
2711 getpid (), fd, fd, func_str, sid, sid, optname);
2719 if (rv != VPPCOM_OK)
2727 func_str = "libc_setsockopt";
2730 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): level %d, "
2731 "optname %d, optval %p, optlen %d",
2732 getpid (), fd, fd, func_str, level, optname,
2735 rv = libc_setsockopt (fd, level, optname, optval, optlen);
2742 int errno_val = errno;
2744 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! "
2745 "rv %d, errno = %d", getpid (), fd, fd,
2746 func_str, rv, errno_val);
2750 clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)",
2751 getpid (), fd, fd, rv, rv);
2757 listen (int fd, int n)
2760 const char *func_str;
2761 u32 sid = vcom_sid_from_fd (fd);
2763 if ((errno = -vcom_init ()))
2766 if (sid != INVALID_SESSION_ID)
2768 func_str = "vppcom_session_listen";
2772 ("LDP<%d>: fd %d (0x%x): calling %s(): sid %u (0x%x), n %d",
2773 getpid (), fd, fd, func_str, sid, sid, n);
2775 rv = vppcom_session_listen (sid, n);
2776 if (rv != VPPCOM_OK)
2784 func_str = "libc_listen";
2787 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): n %d",
2788 getpid (), fd, fd, func_str, n);
2790 rv = libc_listen (fd, n);
2797 int errno_val = errno;
2799 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! "
2800 "rv %d, errno = %d", getpid (), fd, fd,
2801 func_str, rv, errno_val);
2805 clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)",
2806 getpid (), fd, fd, rv, rv);
2812 vcom_accept4 (int listen_fd, __SOCKADDR_ARG addr,
2813 socklen_t * __restrict addr_len, int flags)
2816 const char *func_str;
2817 u32 listen_sid = vcom_sid_from_fd (listen_fd);
2820 if ((errno = -vcom_init ()))
2823 if (listen_sid != INVALID_SESSION_ID)
2826 u8 src_addr[sizeof (struct sockaddr_in6)];
2827 memset (&ep, 0, sizeof (ep));
2830 func_str = "vppcom_session_accept";
2833 clib_warning ("LDP<%d>: listen fd %d (0x%x): calling %s(): "
2834 "listen sid %u (0x%x), ep %p, flags 0x%x",
2835 getpid (), listen_fd, listen_fd, func_str,
2836 listen_sid, listen_sid, ep, flags);
2838 accept_sid = vppcom_session_accept (listen_sid, &ep, flags);
2841 errno = -accept_sid;
2846 rv = vcom_copy_ep_to_sockaddr (addr, addr_len, &ep);
2847 if (rv != VPPCOM_OK)
2849 (void) vppcom_session_close ((u32) accept_sid);
2855 func_str = "vcom_fd_from_sid";
2857 clib_warning ("LDP<%d>: listen fd %d (0x%x): calling %s(): "
2858 "accept sid %u (0x%x), ep %p, flags 0x%x",
2859 getpid (), listen_fd, listen_fd,
2860 func_str, accept_sid, accept_sid, ep, flags);
2861 rv = vcom_fd_from_sid ((u32) accept_sid);
2864 (void) vppcom_session_close ((u32) accept_sid);
2873 func_str = "libc_accept4";
2876 clib_warning ("LDP<%d>: listen fd %d (0x%x): calling %s(): "
2877 "addr %p, addr_len %p, flags 0x%x",
2878 getpid (), listen_fd, listen_fd, func_str,
2879 addr, addr_len, flags);
2881 rv = libc_accept4 (listen_fd, addr, addr_len, flags);
2888 int errno_val = errno;
2890 clib_warning ("LDP<%d>: ERROR: listen fd %d (0x%x): %s() failed! "
2891 "rv %d, errno = %d", getpid (), listen_fd,
2892 listen_fd, func_str, rv, errno_val);
2896 clib_warning ("LDP<%d>: listen fd %d (0x%x): returning %d (0x%x)",
2897 getpid (), listen_fd, listen_fd, rv, rv);
2903 accept4 (int fd, __SOCKADDR_ARG addr, socklen_t * __restrict addr_len,
2906 return vcom_accept4 (fd, addr, addr_len, flags);
2910 accept (int fd, __SOCKADDR_ARG addr, socklen_t * __restrict addr_len)
2912 return vcom_accept4 (fd, addr, addr_len, 0);
2916 shutdown (int fd, int how)
2919 const char *func_str;
2920 u32 sid = vcom_sid_from_fd (fd);
2922 if ((errno = -vcom_init ()))
2925 if (sid != INVALID_SESSION_ID)
2927 func_str = __func__;
2929 clib_warning ("LDP<%d>: LDP-TBD", getpid ());
2935 func_str = "libc_shutdown";
2938 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): how %d",
2939 getpid (), fd, fd, func_str, how);
2941 rv = libc_shutdown (fd, how);
2948 int errno_val = errno;
2950 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! "
2951 "rv %d, errno = %d", getpid (), fd, fd,
2952 func_str, rv, errno_val);
2956 clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)",
2957 getpid (), fd, fd, rv, rv);
2963 epoll_create1 (int flags)
2965 const char *func_str;
2968 if ((errno = -vcom_init ()))
2971 func_str = "vppcom_epoll_create";
2974 clib_warning ("LDP<%d>: calling %s()", getpid (), func_str);
2976 rv = vppcom_epoll_create ();
2978 if (PREDICT_FALSE (rv < 0))
2984 rv = vcom_fd_from_sid ((u32) rv);
2990 int errno_val = errno;
2992 clib_warning ("LDP<%d>: ERROR: %s() failed! "
2993 "rv %d, errno = %d",
2994 getpid (), func_str, rv, errno_val);
2998 clib_warning ("LDP<%d>: returning epfd %d (0x%x)", getpid (), rv, rv);
3004 epoll_create (int size)
3006 return epoll_create1 (0);
3010 epoll_ctl (int epfd, int op, int fd, struct epoll_event *event)
3013 const char *func_str;
3014 u32 vep_idx = vcom_sid_from_fd (epfd);
3016 if ((errno = -vcom_init ()))
3019 if (vep_idx != INVALID_SESSION_ID)
3021 u32 sid = vcom_sid_from_fd (fd);
3023 if (sid != INVALID_SESSION_ID)
3025 func_str = "vppcom_epoll_create";
3028 clib_warning ("LDP<%d>: epfd %d (0x%x): calling %s(): "
3029 "vep_idx %d (0x%x), op %d, sid %u (0x%x), event %p",
3030 getpid (), epfd, epfd, func_str, vep_idx, vep_idx,
3033 rv = vppcom_epoll_ctl (vep_idx, op, sid, event);
3034 if (rv != VPPCOM_OK)
3043 u32 size = sizeof (epfd);
3045 func_str = "vppcom_session_attr[GET_LIBC_EPFD]";
3046 epfd = vppcom_session_attr (vep_idx, VPPCOM_ATTR_GET_LIBC_EPFD,
3050 func_str = "libc_epoll_create1";
3053 clib_warning ("LDP<%d>: calling %s(): EPOLL_CLOEXEC",
3054 getpid (), func_str);
3056 epfd = libc_epoll_create1 (EPOLL_CLOEXEC);
3063 func_str = "vppcom_session_attr[SET_LIBC_EPFD]";
3064 rv = vppcom_session_attr (vep_idx, VPPCOM_ATTR_SET_LIBC_EPFD,
3073 else if (PREDICT_FALSE (epfd < 0))
3080 rv = libc_epoll_ctl (epfd, op, fd, event);
3085 func_str = "libc_epoll_ctl";
3088 clib_warning ("LDP<%d>: epfd %d (0x%x): calling %s(): "
3089 "op %d, fd %d (0x%x), event %p",
3090 getpid (), epfd, epfd, func_str, op, fd, fd, event);
3092 rv = libc_epoll_ctl (epfd, op, fd, event);
3100 int errno_val = errno;
3102 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! "
3103 "rv %d, errno = %d", getpid (), fd, fd,
3104 func_str, rv, errno_val);
3108 clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)",
3109 getpid (), fd, fd, rv, rv);
3115 vcom_epoll_pwait (int epfd, struct epoll_event *events,
3116 int maxevents, int timeout, const sigset_t * sigmask)
3118 const char *func_str;
3120 double time_to_wait = (double) 0;
3121 double time_out, now = 0;
3122 u32 vep_idx = vcom_sid_from_fd (epfd);
3125 if ((errno = -vcom_init ()))
3128 if (PREDICT_FALSE (!events || (timeout < -1)))
3134 if (PREDICT_FALSE (vep_idx == INVALID_SESSION_ID))
3136 clib_warning ("LDP<%d>: ERROR: epfd %d (0x%x): bad vep_idx %d (0x%x)!",
3137 getpid (), epfd, epfd, vep_idx, vep_idx);
3142 time_to_wait = ((timeout >= 0) ? (double) timeout / (double) 1000 : 0);
3143 time_out = clib_time_now (&vcom->clib_time) + time_to_wait;
3145 func_str = "vppcom_session_attr[GET_LIBC_EPFD]";
3146 libc_epfd = vppcom_session_attr (vep_idx, VPPCOM_ATTR_GET_LIBC_EPFD, 0, 0);
3147 if (PREDICT_FALSE (libc_epfd < 0))
3155 clib_warning ("LDP<%d>: epfd %d (0x%x): vep_idx %d (0x%x), "
3156 "libc_epfd %d (0x%x), events %p, maxevents %d, "
3157 "timeout %d, sigmask %p", getpid (), epfd, epfd,
3158 vep_idx, vep_idx, libc_epfd, libc_epfd, events,
3159 maxevents, timeout, sigmask);
3162 if (!vcom->epoll_wait_vcl)
3164 func_str = "vppcom_epoll_wait";
3167 clib_warning ("LDP<%d>: epfd %d (0x%x): calling %s(): "
3168 "vep_idx %d (0x%x), events %p, maxevents %d",
3169 getpid (), epfd, epfd, func_str,
3170 vep_idx, vep_idx, events, maxevents);
3172 rv = vppcom_epoll_wait (vep_idx, events, maxevents, 0);
3175 vcom->epoll_wait_vcl = 1;
3186 vcom->epoll_wait_vcl = 0;
3190 func_str = "libc_epoll_pwait";
3193 clib_warning ("LDP<%d>: epfd %d (0x%x): calling %s(): "
3194 "libc_epfd %d (0x%x), events %p, "
3195 "maxevents %d, sigmask %p",
3196 getpid (), epfd, epfd, func_str,
3197 libc_epfd, libc_epfd, events, maxevents, sigmask);
3199 rv = libc_epoll_pwait (epfd, events, maxevents, 1, sigmask);
3205 now = clib_time_now (&vcom->clib_time);
3207 while (now < time_out);
3214 int errno_val = errno;
3216 clib_warning ("LDP<%d>: ERROR: epfd %d (0x%x): %s() failed! "
3217 "rv %d, errno = %d", getpid (), epfd, epfd,
3218 func_str, rv, errno_val);
3222 clib_warning ("LDP<%d>: epfd %d (0x%x): returning %d (0x%x)",
3223 getpid (), epfd, epfd, rv, rv);
3229 epoll_pwait (int epfd, struct epoll_event *events,
3230 int maxevents, int timeout, const sigset_t * sigmask)
3232 return vcom_epoll_pwait (epfd, events, maxevents, timeout, sigmask);
3236 epoll_wait (int epfd, struct epoll_event *events, int maxevents, int timeout)
3238 return vcom_epoll_pwait (epfd, events, maxevents, timeout, NULL);
3242 poll (struct pollfd *fds, nfds_t nfds, int timeout)
3244 const char *func_str = __func__;
3245 int rv, i, n_libc_fds, n_revents;
3248 double wait_for_time;
3251 clib_warning ("LDP<%d>: fds %p, nfds %d, timeout %d",
3252 getpid (), fds, nfds, timeout);
3255 wait_for_time = (f64) timeout / 1000;
3260 for (i = 0; i < nfds; i++)
3265 clib_warning ("LDP<%d>: fds[%d].fd %d (0x%0x), .events = 0x%x, "
3266 ".revents = 0x%x", getpid (), i, fds[i].fd,
3267 fds[i].fd, fds[i].events, fds[i].revents);
3269 sid = vcom_sid_from_fd (fds[i].fd);
3270 if (sid != INVALID_SESSION_ID)
3272 fds[i].fd = -fds[i].fd;
3273 vec_add2 (vcom->vcl_poll, vp, 1);
3276 vp->events = fds[i].events;
3277 #ifdef __USE_XOPEN2K
3278 if (fds[i].events & POLLRDNORM)
3279 vp->events |= POLLIN;
3280 if (fds[i].events & POLLWRNORM)
3281 vp->events |= POLLOUT;
3283 vp->revents = &fds[i].revents;
3293 if (vec_len (vcom->vcl_poll))
3295 func_str = "vppcom_poll";
3298 clib_warning ("LDP<%d>: calling %s(): "
3299 "vcl_poll %p, n_sids %u (0x%x): "
3301 getpid (), func_str, vcom->vcl_poll,
3302 vec_len (vcom->vcl_poll), vec_len (vcom->vcl_poll),
3305 rv = vppcom_poll (vcom->vcl_poll, vec_len (vcom->vcl_poll), 0);
3318 func_str = "libc_poll";
3321 clib_warning ("LDP<%d>: calling %s(): fds %p, nfds %u: n_sids %u",
3322 getpid (), fds, nfds, vec_len (vcom->vcl_poll));
3324 rv = libc_poll (fds, nfds, 0);
3337 while ((wait_for_time == -1) ||
3338 (clib_time_now (&vcom->clib_time) < wait_for_time));
3342 vec_foreach (vp, vcom->vcl_poll)
3344 fds[vp->fds_ndx].fd = -fds[vp->fds_ndx].fd;
3345 #ifdef __USE_XOPEN2K
3346 if ((fds[vp->fds_ndx].revents & POLLIN) &&
3347 (fds[vp->fds_ndx].events & POLLRDNORM))
3348 fds[vp->fds_ndx].revents |= POLLRDNORM;
3349 if ((fds[vp->fds_ndx].revents & POLLOUT) &&
3350 (fds[vp->fds_ndx].events & POLLWRNORM))
3351 fds[vp->fds_ndx].revents |= POLLWRNORM;
3354 vec_reset_length (vcom->vcl_poll);
3360 int errno_val = errno;
3362 clib_warning ("LDP<%d>: ERROR: %s() failed! "
3363 "rv %d, errno = %d", getpid (),
3364 func_str, rv, errno_val);
3369 clib_warning ("LDP<%d>: returning %d (0x%x): n_sids %u, "
3370 "n_libc_fds %d", getpid (), rv, rv,
3371 vec_len (vcom->vcl_poll), n_libc_fds);
3373 for (i = 0; i < nfds; i++)
3378 clib_warning ("LDP<%d>: fds[%d].fd %d (0x%0x), "
3379 ".events = 0x%x, .revents = 0x%x",
3380 getpid (), i, fds[i].fd, fds[i].fd,
3381 fds[i].events, fds[i].revents);
3392 ppoll (struct pollfd *fds, nfds_t nfds,
3393 const struct timespec *timeout, const sigset_t * sigmask)
3395 if ((errno = -vcom_init ()))
3398 clib_warning ("LDP<%d>: LDP-TBD", getpid ());
3406 void CONSTRUCTOR_ATTRIBUTE vcom_constructor (void);
3408 void DESTRUCTOR_ATTRIBUTE vcom_destructor (void);
3411 * This function is called when the library is loaded
3414 vcom_constructor (void)
3416 swrap_constructor ();
3417 if (vcom_init () != 0)
3418 fprintf (stderr, "\nLDP<%d>: ERROR: vcom_constructor: failed!\n",
3421 clib_warning ("LDP<%d>: VCOM constructor: done!\n", getpid ());
3425 * This function is called when the library is unloaded
3428 vcom_destructor (void)
3430 swrap_destructor ();
3433 vppcom_app_destroy ();
3437 /* Don't use clib_warning() here because that calls writev()
3438 * which will call vcom_init().
3440 printf ("%s:%d: LDP<%d>: VCOM destructor: done!\n",
3441 __func__, __LINE__, getpid ());
3446 * fd.io coding-style-patch-verification: ON
3449 * eval: (c-set-style "gnu")