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, 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 clib_warning ("LDP<%d>: LDP-TBD", getpid ());
1228 func_str = "libc_socket";
1231 clib_warning ("LDP<%d>: : calling %s()", getpid (), func_str);
1233 rv = libc_socket (domain, type, protocol);
1240 int errno_val = errno;
1242 clib_warning ("LDP<%d>: ERROR: %s() failed! "
1243 "rv %d, errno = %d",
1244 getpid (), func_str, rv, errno_val);
1248 clib_warning ("LDP<%d>: : returning fd %d (0x%x)", getpid (), rv, rv);
1254 bind (int fd, __CONST_SOCKADDR_ARG addr, socklen_t len)
1257 const char *func_str;
1258 u32 sid = vcom_sid_from_fd (fd);
1260 if ((errno = -vcom_init ()))
1263 if (sid != INVALID_SESSION_ID)
1267 func_str = "vppcom_session_bind";
1269 ep.vrf = VPPCOM_VRF_DEFAULT;
1270 switch (addr->sa_family)
1273 if (len != sizeof (struct sockaddr_in))
1276 ("LDP<%d>: ERROR: fd %d (0x%x): sid %u (0x%x): Invalid "
1277 "AF_INET addr len %u!", getpid (), fd, fd, sid, sid, len);
1282 ep.is_ip4 = VPPCOM_IS_IP4;
1283 ep.ip = (u8 *) & ((const struct sockaddr_in *) addr)->sin_addr;
1284 ep.port = (u16) ((const struct sockaddr_in *) addr)->sin_port;
1288 if (len != sizeof (struct sockaddr_in6))
1291 ("LDP<%d>: ERROR: fd %d (0x%x): sid %u (0x%x): Invalid "
1292 "AF_INET6 addr len %u!", getpid (), fd, fd, sid, sid, len);
1297 ep.is_ip4 = VPPCOM_IS_IP6;
1298 ep.ip = (u8 *) & ((const struct sockaddr_in6 *) addr)->sin6_addr;
1299 ep.port = (u16) ((const struct sockaddr_in6 *) addr)->sin6_port;
1303 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): sid %u (0x%x): "
1304 "Unsupported address family %u!",
1305 getpid (), fd, fd, sid, sid, addr->sa_family);
1306 errno = EAFNOSUPPORT;
1311 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): sid %u (0x%x), "
1313 getpid (), fd, fd, func_str, sid, sid, addr, len);
1315 rv = vppcom_session_bind (sid, &ep);
1316 if (rv != VPPCOM_OK)
1324 func_str = "libc_bind";
1327 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
1329 getpid (), fd, fd, func_str, addr, len);
1331 rv = libc_bind (fd, addr, len);
1339 int errno_val = errno;
1341 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! "
1342 "rv %d, errno = %d", getpid (), fd, fd,
1343 func_str, rv, errno_val);
1347 clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)",
1348 getpid (), fd, fd, rv, rv);
1354 vcom_copy_ep_to_sockaddr (__SOCKADDR_ARG addr, socklen_t * __restrict len,
1355 vppcom_endpt_t * ep)
1358 int sa_len, copy_len;
1360 if ((errno = -vcom_init ()))
1363 if (addr && len && ep)
1365 addr->sa_family = (ep->is_ip4 == VPPCOM_IS_IP4) ? AF_INET : AF_INET6;
1366 switch (addr->sa_family)
1369 ((struct sockaddr_in *) addr)->sin_port = ep->port;
1370 if (*len > sizeof (struct sockaddr_in))
1371 *len = sizeof (struct sockaddr_in);
1372 sa_len = sizeof (struct sockaddr_in) - sizeof (struct in_addr);
1373 copy_len = *len - sa_len;
1375 memcpy (&((struct sockaddr_in *) addr)->sin_addr, ep->ip,
1380 ((struct sockaddr_in6 *) addr)->sin6_port = ep->port;
1381 if (*len > sizeof (struct sockaddr_in6))
1382 *len = sizeof (struct sockaddr_in6);
1383 sa_len = sizeof (struct sockaddr_in6) - sizeof (struct in6_addr);
1384 copy_len = *len - sa_len;
1386 memcpy (((struct sockaddr_in6 *) addr)->sin6_addr.
1387 __in6_u.__u6_addr8, ep->ip, copy_len);
1400 getsockname (int fd, __SOCKADDR_ARG addr, socklen_t * __restrict len)
1403 const char *func_str;
1404 u32 sid = vcom_sid_from_fd (fd);
1406 if ((errno = -vcom_init ()))
1409 if (sid != INVALID_SESSION_ID)
1412 u8 addr_buf[sizeof (struct in6_addr)];
1413 u32 size = sizeof (ep);
1416 func_str = "vppcom_session_attr[GET_LCL_ADDR]";
1419 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): sid %u (0x%x), "
1421 getpid (), fd, fd, func_str, sid, sid, addr, len);
1423 rv = vppcom_session_attr (sid, VPPCOM_ATTR_GET_LCL_ADDR, &ep, &size);
1424 if (rv != VPPCOM_OK)
1431 rv = vcom_copy_ep_to_sockaddr (addr, len, &ep);
1432 if (rv != VPPCOM_OK)
1441 func_str = "libc_getsockname";
1444 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
1446 getpid (), fd, fd, func_str, addr, len);
1448 rv = libc_getsockname (fd, addr, len);
1455 int errno_val = errno;
1457 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! "
1458 "rv %d, errno = %d", getpid (), fd, fd,
1459 func_str, rv, errno_val);
1463 clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)",
1464 getpid (), fd, fd, rv, rv);
1470 connect (int fd, __CONST_SOCKADDR_ARG addr, socklen_t len)
1473 const char *func_str = __func__;
1474 u32 sid = vcom_sid_from_fd (fd);
1476 if ((errno = -vcom_init ()))
1481 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): NULL addr, len %u",
1482 getpid (), fd, fd, len);
1488 if (sid != INVALID_SESSION_ID)
1492 func_str = "vppcom_session_connect";
1494 ep.vrf = VPPCOM_VRF_DEFAULT;
1495 switch (addr->sa_family)
1498 if (len != sizeof (struct sockaddr_in))
1501 ("LDP<%d>: fd %d (0x%x): ERROR sid %u (0x%x): Invalid "
1502 "AF_INET addr len %u!", getpid (), fd, fd, sid, sid, len);
1507 ep.is_ip4 = VPPCOM_IS_IP4;
1508 ep.ip = (u8 *) & ((const struct sockaddr_in *) addr)->sin_addr;
1509 ep.port = (u16) ((const struct sockaddr_in *) addr)->sin_port;
1513 if (len != sizeof (struct sockaddr_in6))
1516 ("LDP<%d>: fd %d (0x%x): ERROR sid %u (0x%x): Invalid "
1517 "AF_INET6 addr len %u!", getpid (), fd, fd, sid, sid, len);
1522 ep.is_ip4 = VPPCOM_IS_IP6;
1523 ep.ip = (u8 *) & ((const struct sockaddr_in6 *) addr)->sin6_addr;
1524 ep.port = (u16) ((const struct sockaddr_in6 *) addr)->sin6_port;
1528 clib_warning ("LDP<%d>: fd %d (0x%x): ERROR sid %u (0x%x): "
1529 "Unsupported address family %u!",
1530 getpid (), fd, fd, sid, sid, addr->sa_family);
1531 errno = EAFNOSUPPORT;
1536 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): sid %u (0x%x) "
1538 getpid (), fd, fd, func_str, sid, sid, addr, len);
1540 rv = vppcom_session_connect (sid, &ep);
1541 if (rv != VPPCOM_OK)
1549 func_str = "libc_connect";
1552 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
1554 getpid (), fd, fd, func_str, addr, len);
1556 rv = libc_connect (fd, addr, len);
1564 int errno_val = errno;
1566 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! "
1567 "rv %d, errno = %d", getpid (), fd, fd,
1568 func_str, rv, errno_val);
1572 clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)",
1573 getpid (), fd, fd, rv, rv);
1579 getpeername (int fd, __SOCKADDR_ARG addr, socklen_t * __restrict len)
1582 const char *func_str;
1583 u32 sid = vcom_sid_from_fd (fd);
1585 if ((errno = -vcom_init ()))
1588 clib_warning ("LDP<%d>: fd %d (0x%x) ", getpid (), fd, fd);
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 clib_warning ("LDP<%d>: LDP-TBD", getpid ());
2184 func_str = "libc_sendmsg";
2187 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2188 "message %p, flags 0x%x",
2189 getpid (), fd, fd, func_str, message, flags);
2191 size = libc_sendmsg (fd, message, flags);
2198 int errno_val = errno;
2200 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! "
2201 "rv %d, errno = %d", getpid (), fd, fd,
2202 func_str, size, errno_val);
2206 clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)",
2207 getpid (), fd, fd, size, size);
2214 sendmmsg (int fd, struct mmsghdr *vmessages, unsigned int vlen, int flags)
2217 const char *func_str;
2218 u32 sid = vcom_sid_from_fd (fd);
2220 if ((errno = -vcom_init ()))
2223 if (sid != INVALID_SESSION_ID)
2225 clib_warning ("LDP<%d>: LDP-TBD", getpid ());
2231 func_str = "libc_sendmmsg";
2234 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2235 "vmessages %p, vlen %u, flags 0x%x",
2236 getpid (), fd, fd, func_str, vmessages, vlen, flags);
2238 size = libc_sendmmsg (fd, vmessages, vlen, flags);
2245 int errno_val = errno;
2247 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! "
2248 "rv %d, errno = %d", getpid (), fd, fd,
2249 func_str, size, errno_val);
2253 clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)",
2254 getpid (), fd, fd, size, size);
2261 recvmsg (int fd, struct msghdr * message, int flags)
2264 const char *func_str;
2265 u32 sid = vcom_sid_from_fd (fd);
2267 if ((errno = -vcom_init ()))
2270 if (sid != INVALID_SESSION_ID)
2272 clib_warning ("LDP<%d>: LDP-TBD", getpid ());
2278 func_str = "libc_recvmsg";
2281 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2282 "message %p, flags 0x%x",
2283 getpid (), fd, fd, func_str, message, flags);
2285 size = libc_recvmsg (fd, message, flags);
2292 int errno_val = errno;
2294 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! "
2295 "rv %d, errno = %d", getpid (), fd, fd,
2296 func_str, size, errno_val);
2300 clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)",
2301 getpid (), fd, fd, size, size);
2308 recvmmsg (int fd, struct mmsghdr *vmessages,
2309 unsigned int vlen, int flags, struct timespec *tmo)
2312 const char *func_str;
2313 u32 sid = vcom_sid_from_fd (fd);
2315 if ((errno = -vcom_init ()))
2318 if (sid != INVALID_SESSION_ID)
2320 clib_warning ("LDP<%d>: LDP-TBD", getpid ());
2326 func_str = "libc_recvmmsg";
2329 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2330 "vmessages %p, vlen %u, flags 0x%x, tmo %p",
2331 getpid (), fd, fd, func_str, vmessages, vlen,
2334 size = libc_recvmmsg (fd, vmessages, vlen, flags, tmo);
2341 int errno_val = errno;
2343 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! "
2344 "rv %d, errno = %d", getpid (), fd, fd,
2345 func_str, size, errno_val);
2349 clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)",
2350 getpid (), fd, fd, size, size);
2357 getsockopt (int fd, int level, int optname,
2358 void *__restrict optval, socklen_t * __restrict optlen)
2361 const char *func_str = __func__;
2362 u32 sid = vcom_sid_from_fd (fd);
2363 u32 buflen = (u32) * optlen;
2365 if ((errno = -vcom_init ()))
2368 if (sid != INVALID_SESSION_ID)
2378 func_str = "vppcom_session_attr[SOL_TCP,GET_TCP_NODELAY]";
2380 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2382 getpid (), fd, fd, func_str, sid, sid);
2383 rv = vppcom_session_attr (sid, VPPCOM_ATTR_GET_TCP_NODELAY,
2387 func_str = "vppcom_session_attr[SOL_TCP,GET_TCP_USER_MSS]";
2389 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2391 getpid (), fd, fd, func_str, sid, sid);
2392 rv = vppcom_session_attr (sid, VPPCOM_ATTR_GET_TCP_USER_MSS,
2396 func_str = "vppcom_session_attr[SOL_TCP,GET_TCP_KEEPIDLE]";
2398 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2400 getpid (), fd, fd, func_str, sid, sid);
2401 rv = vppcom_session_attr (sid, VPPCOM_ATTR_GET_TCP_KEEPIDLE,
2405 func_str = "vppcom_session_attr[SOL_TCP,GET_TCP_KEEPINTVL]";
2407 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2408 "sid %u (0x%x), SOL_TCP",
2409 getpid (), fd, fd, func_str, sid, sid);
2410 rv = vppcom_session_attr (sid, VPPCOM_ATTR_GET_TCP_KEEPINTVL,
2414 if (optval && optlen && (*optlen == sizeof (struct tcp_info)))
2417 clib_warning ("LDP<%d>: fd %d (0x%x): sid %u (0x%x), "
2418 "SOL_TCP, TCP_INFO, optval %p, "
2419 "optlen %d: #LDP-NOP#",
2420 getpid (), fd, fd, sid, sid,
2422 memset (optval, 0, *optlen);
2430 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s(): "
2431 "sid %u (0x%x), SOL_TCP, "
2432 "optname %d unsupported!",
2433 getpid (), fd, fd, func_str, sid, sid, optname);
2441 func_str = "vppcom_session_attr[SOL_IPV6,GET_V6ONLY]";
2443 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2445 getpid (), fd, fd, func_str, sid, sid);
2446 rv = vppcom_session_attr (sid, VPPCOM_ATTR_GET_V6ONLY,
2451 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s(): "
2452 "sid %u (0x%x), SOL_IPV6, "
2453 "optname %d unsupported!",
2454 getpid (), fd, fd, func_str, sid, sid, optname);
2462 func_str = "vppcom_session_attr[SOL_SOCKET,GET_ACCEPTCONN]";
2464 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2466 getpid (), fd, fd, func_str, sid, sid);
2467 rv = vppcom_session_attr (sid, VPPCOM_ATTR_GET_LISTEN,
2471 func_str = "vppcom_session_attr[SOL_SOCKET,GET_KEEPALIVE]";
2473 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2475 getpid (), fd, fd, func_str, sid, sid);
2476 rv = vppcom_session_attr (sid, VPPCOM_ATTR_GET_KEEPALIVE,
2480 func_str = "vppcom_session_attr[SOL_SOCKET,GET_PROTOCOL]";
2482 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2484 getpid (), fd, fd, func_str, sid, sid);
2485 rv = vppcom_session_attr (sid, VPPCOM_ATTR_GET_PROTOCOL,
2487 *(int *) optval = *(int *) optval ? SOCK_DGRAM : SOCK_STREAM;
2490 func_str = "vppcom_session_attr[SOL_SOCKET,GET_TX_FIFO_LEN]";
2492 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2493 "sid %u (0x%x), optlen %d",
2494 getpid (), fd, fd, func_str, sid, sid, buflen);
2495 rv = vppcom_session_attr (sid, VPPCOM_ATTR_GET_TX_FIFO_LEN,
2499 func_str = "vppcom_session_attr[SOL_SOCKET,GET_RX_FIFO_LEN]";
2501 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2502 "sid %u (0x%x), optlen %d",
2503 getpid (), fd, fd, func_str, sid, sid, *optlen);
2504 rv = vppcom_session_attr (sid, VPPCOM_ATTR_GET_RX_FIFO_LEN,
2508 func_str = "vppcom_session_attr[SOL_SOCKET,GET_REUSEADDR]";
2510 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2512 getpid (), fd, fd, func_str, sid, sid);
2513 rv = vppcom_session_attr (sid, VPPCOM_ATTR_GET_REUSEADDR,
2517 func_str = "vppcom_session_attr[SOL_SOCKET,GET_BROADCAST]";
2519 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2521 getpid (), fd, fd, func_str, sid, sid);
2522 rv = vppcom_session_attr (sid, VPPCOM_ATTR_GET_BROADCAST,
2526 func_str = "vppcom_session_attr[SOL_SOCKET,GET_ERROR]";
2528 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2530 getpid (), fd, fd, func_str, sid, sid);
2531 rv = vppcom_session_attr (sid, VPPCOM_ATTR_GET_ERROR,
2536 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s(): "
2537 "sid %u (0x%x), SOL_SOCKET, "
2538 "optname %d unsupported!",
2539 getpid (), fd, fd, func_str, sid, sid, optname);
2547 if (rv != VPPCOM_OK)
2555 func_str = "libc_getsockopt";
2558 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): level %d, "
2559 "optname %d, optval %p, optlen %d",
2560 getpid (), fd, fd, func_str, level, optname,
2563 rv = libc_getsockopt (fd, level, optname, optval, optlen);
2570 int errno_val = errno;
2572 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! "
2573 "rv %d, errno = %d", getpid (), fd, fd,
2574 func_str, rv, errno_val);
2578 clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)",
2579 getpid (), fd, fd, rv, rv);
2585 setsockopt (int fd, int level, int optname,
2586 const void *optval, socklen_t optlen)
2589 const char *func_str = __func__;
2590 u32 sid = vcom_sid_from_fd (fd);
2592 if ((errno = -vcom_init ()))
2595 if (sid != INVALID_SESSION_ID)
2605 func_str = "vppcom_session_attr[SOL_TCP,SET_TCP_NODELAY]";
2607 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2609 getpid (), fd, fd, func_str, sid, sid);
2610 rv = vppcom_session_attr (sid, VPPCOM_ATTR_SET_TCP_NODELAY,
2611 (void *) optval, &optlen);
2614 func_str = "vppcom_session_attr[SOL_TCP,SET_TCP_USER_MSS]";
2616 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2618 getpid (), fd, fd, func_str, sid, sid);
2619 rv = vppcom_session_attr (sid, VPPCOM_ATTR_SET_TCP_USER_MSS,
2620 (void *) optval, &optlen);
2623 func_str = "vppcom_session_attr[SOL_TCP,SET_TCP_KEEPIDLE]";
2625 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2627 getpid (), fd, fd, func_str, sid, sid);
2628 rv = vppcom_session_attr (sid, VPPCOM_ATTR_SET_TCP_KEEPIDLE,
2629 (void *) optval, &optlen);
2632 func_str = "vppcom_session_attr[SOL_TCP,SET_TCP_KEEPINTVL]";
2634 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2635 "sid %u (0x%x), SOL_TCP",
2636 getpid (), fd, fd, func_str, sid, sid);
2637 rv = vppcom_session_attr (sid, VPPCOM_ATTR_SET_TCP_KEEPINTVL,
2638 (void *) optval, &optlen);
2642 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s(): "
2643 "sid %u (0x%x), SOL_TCP, "
2644 "optname %d unsupported!",
2645 getpid (), fd, fd, func_str, sid, sid, optname);
2653 func_str = "vppcom_session_attr[SOL_IPV6,SET_V6ONLY]";
2655 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2657 getpid (), fd, fd, func_str, sid, sid);
2658 rv = vppcom_session_attr (sid, VPPCOM_ATTR_SET_V6ONLY,
2659 (void *) optval, &optlen);
2663 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s(): "
2664 "sid %u (0x%x), SOL_IPV6, "
2665 "optname %d unsupported!",
2666 getpid (), fd, fd, func_str, sid, sid, optname);
2674 func_str = "vppcom_session_attr[SOL_SOCKET,SET_KEEPALIVE]";
2676 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2678 getpid (), fd, fd, func_str, sid, sid);
2679 rv = vppcom_session_attr (sid, VPPCOM_ATTR_SET_KEEPALIVE,
2680 (void *) optval, &optlen);
2683 func_str = "vppcom_session_attr[SOL_SOCKET,SET_REUSEADDR]";
2685 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2687 getpid (), fd, fd, func_str, sid, sid);
2688 rv = vppcom_session_attr (sid, VPPCOM_ATTR_SET_REUSEADDR,
2689 (void *) optval, &optlen);
2692 func_str = "vppcom_session_attr[SOL_SOCKET,SET_BROADCAST]";
2694 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): "
2696 getpid (), fd, fd, func_str, sid, sid);
2697 rv = vppcom_session_attr (sid, VPPCOM_ATTR_SET_BROADCAST,
2698 (void *) optval, &optlen);
2702 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s(): "
2703 "sid %u (0x%x), SOL_SOCKET, "
2704 "optname %d unsupported!",
2705 getpid (), fd, fd, func_str, sid, sid, optname);
2713 if (rv != VPPCOM_OK)
2721 func_str = "libc_setsockopt";
2724 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): level %d, "
2725 "optname %d, optval %p, optlen %d",
2726 getpid (), fd, fd, func_str, level, optname,
2729 rv = libc_setsockopt (fd, level, optname, optval, optlen);
2736 int errno_val = errno;
2738 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! "
2739 "rv %d, errno = %d", getpid (), fd, fd,
2740 func_str, rv, errno_val);
2744 clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)",
2745 getpid (), fd, fd, rv, rv);
2751 listen (int fd, int n)
2754 const char *func_str;
2755 u32 sid = vcom_sid_from_fd (fd);
2757 if ((errno = -vcom_init ()))
2760 if (sid != INVALID_SESSION_ID)
2762 func_str = "vppcom_session_listen";
2766 ("LDP<%d>: fd %d (0x%x): calling %s(): sid %u (0x%x), n %d",
2767 getpid (), fd, fd, func_str, sid, sid, n);
2769 rv = vppcom_session_listen (sid, n);
2770 if (rv != VPPCOM_OK)
2778 func_str = "libc_listen";
2781 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): n %d",
2782 getpid (), fd, fd, func_str, n);
2784 rv = libc_listen (fd, n);
2791 int errno_val = errno;
2793 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! "
2794 "rv %d, errno = %d", getpid (), fd, fd,
2795 func_str, rv, errno_val);
2799 clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)",
2800 getpid (), fd, fd, rv, rv);
2806 vcom_accept4 (int listen_fd, __SOCKADDR_ARG addr,
2807 socklen_t * __restrict addr_len, int flags)
2810 const char *func_str;
2811 u32 listen_sid = vcom_sid_from_fd (listen_fd);
2814 if ((errno = -vcom_init ()))
2817 if (listen_sid != INVALID_SESSION_ID)
2820 u8 src_addr[sizeof (struct sockaddr_in6)];
2823 func_str = "vppcom_session_accept";
2826 clib_warning ("LDP<%d>: listen fd %d (0x%x): calling %s(): "
2827 "listen sid %u (0x%x), ep %p, flags 0x%x",
2828 getpid (), listen_fd, listen_fd, func_str,
2829 listen_sid, listen_sid, ep, flags);
2831 accept_sid = vppcom_session_accept (listen_sid, &ep, flags);
2834 errno = -accept_sid;
2839 rv = vcom_copy_ep_to_sockaddr (addr, addr_len, &ep);
2840 if (rv != VPPCOM_OK)
2842 (void) vppcom_session_close ((u32) accept_sid);
2848 func_str = "vcom_fd_from_sid";
2850 clib_warning ("LDP<%d>: listen fd %d (0x%x): calling %s(): "
2851 "accept sid %u (0x%x), ep %p, flags 0x%x",
2852 getpid (), listen_fd, listen_fd,
2853 func_str, accept_sid, accept_sid, ep, flags);
2854 rv = vcom_fd_from_sid ((u32) accept_sid);
2857 (void) vppcom_session_close ((u32) accept_sid);
2866 func_str = "libc_accept4";
2869 clib_warning ("LDP<%d>: listen fd %d (0x%x): calling %s(): "
2870 "addr %p, addr_len %p, flags 0x%x",
2871 getpid (), listen_fd, listen_fd, func_str,
2872 addr, addr_len, flags);
2874 rv = libc_accept4 (listen_fd, addr, addr_len, flags);
2881 int errno_val = errno;
2883 clib_warning ("LDP<%d>: ERROR: listen fd %d (0x%x): %s() failed! "
2884 "rv %d, errno = %d", getpid (), listen_fd,
2885 listen_fd, func_str, rv, errno_val);
2889 clib_warning ("LDP<%d>: listen fd %d (0x%x): returning %d (0x%x)",
2890 getpid (), listen_fd, listen_fd, rv, rv);
2896 accept4 (int fd, __SOCKADDR_ARG addr, socklen_t * __restrict addr_len,
2899 return vcom_accept4 (fd, addr, addr_len, flags);
2903 accept (int fd, __SOCKADDR_ARG addr, socklen_t * __restrict addr_len)
2905 return vcom_accept4 (fd, addr, addr_len, 0);
2909 shutdown (int fd, int how)
2912 const char *func_str;
2913 u32 sid = vcom_sid_from_fd (fd);
2915 if ((errno = -vcom_init ()))
2918 if (sid != INVALID_SESSION_ID)
2920 clib_warning ("LDP<%d>: LDP-TBD", getpid ());
2926 func_str = "libc_shutdown";
2929 clib_warning ("LDP<%d>: fd %d (0x%x): calling %s(): how %d",
2930 getpid (), fd, fd, func_str, how);
2932 rv = libc_shutdown (fd, how);
2939 int errno_val = errno;
2941 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! "
2942 "rv %d, errno = %d", getpid (), fd, fd,
2943 func_str, rv, errno_val);
2947 clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)",
2948 getpid (), fd, fd, rv, rv);
2954 epoll_create1 (int flags)
2956 const char *func_str;
2959 if ((errno = -vcom_init ()))
2962 func_str = "vppcom_epoll_create";
2965 clib_warning ("LDP<%d>: calling %s()", getpid (), func_str);
2967 rv = vppcom_epoll_create ();
2969 if (PREDICT_FALSE (rv < 0))
2975 rv = vcom_fd_from_sid ((u32) rv);
2981 int errno_val = errno;
2983 clib_warning ("LDP<%d>: ERROR: %s() failed! "
2984 "rv %d, errno = %d",
2985 getpid (), func_str, rv, errno_val);
2989 clib_warning ("LDP<%d>: returning epfd %d (0x%x)", getpid (), rv, rv);
2995 epoll_create (int size)
2997 return epoll_create1 (0);
3001 epoll_ctl (int epfd, int op, int fd, struct epoll_event *event)
3004 const char *func_str;
3005 u32 vep_idx = vcom_sid_from_fd (epfd);
3007 if ((errno = -vcom_init ()))
3010 if (vep_idx != INVALID_SESSION_ID)
3012 u32 sid = vcom_sid_from_fd (fd);
3014 if (sid != INVALID_SESSION_ID)
3016 func_str = "vppcom_epoll_create";
3019 clib_warning ("LDP<%d>: epfd %d (0x%x): calling %s(): "
3020 "vep_idx %d (0x%x), op %d, sid %u (0x%x), event %p",
3021 getpid (), epfd, epfd, func_str, vep_idx, vep_idx,
3024 rv = vppcom_epoll_ctl (vep_idx, op, sid, event);
3025 if (rv != VPPCOM_OK)
3034 u32 size = sizeof (epfd);
3036 func_str = "vppcom_session_attr[GET_LIBC_EPFD]";
3037 epfd = vppcom_session_attr (vep_idx, VPPCOM_ATTR_GET_LIBC_EPFD,
3041 func_str = "libc_epoll_create1";
3044 clib_warning ("LDP<%d>: calling %s(): EPOLL_CLOEXEC",
3045 getpid (), func_str);
3047 epfd = libc_epoll_create1 (EPOLL_CLOEXEC);
3054 func_str = "vppcom_session_attr[SET_LIBC_EPFD]";
3055 rv = vppcom_session_attr (vep_idx, VPPCOM_ATTR_SET_LIBC_EPFD,
3064 else if (PREDICT_FALSE (epfd < 0))
3071 rv = libc_epoll_ctl (epfd, op, fd, event);
3076 func_str = "libc_epoll_ctl";
3079 clib_warning ("LDP<%d>: epfd %d (0x%x): calling %s(): "
3080 "op %d, fd %d (0x%x), event %p",
3081 getpid (), epfd, epfd, func_str, op, fd, fd, event);
3083 rv = libc_epoll_ctl (epfd, op, fd, event);
3091 int errno_val = errno;
3093 clib_warning ("LDP<%d>: ERROR: fd %d (0x%x): %s() failed! "
3094 "rv %d, errno = %d", getpid (), fd, fd,
3095 func_str, rv, errno_val);
3099 clib_warning ("LDP<%d>: fd %d (0x%x): returning %d (0x%x)",
3100 getpid (), fd, fd, rv, rv);
3106 vcom_epoll_pwait (int epfd, struct epoll_event *events,
3107 int maxevents, int timeout, const sigset_t * sigmask)
3109 const char *func_str;
3111 double time_to_wait = (double) 0;
3112 double time_out, now = 0;
3113 u32 vep_idx = vcom_sid_from_fd (epfd);
3116 if ((errno = -vcom_init ()))
3119 if (PREDICT_FALSE (!events || (timeout < -1)))
3125 if (PREDICT_FALSE (vep_idx == INVALID_SESSION_ID))
3127 clib_warning ("LDP<%d>: ERROR: epfd %d (0x%x): bad vep_idx %d (0x%x)!",
3128 getpid (), epfd, epfd, vep_idx, vep_idx);
3133 time_to_wait = ((timeout >= 0) ? (double) timeout / (double) 1000 : 0);
3134 time_out = clib_time_now (&vcom->clib_time) + time_to_wait;
3136 func_str = "vppcom_session_attr[GET_LIBC_EPFD]";
3137 libc_epfd = vppcom_session_attr (vep_idx, VPPCOM_ATTR_GET_LIBC_EPFD, 0, 0);
3138 if (PREDICT_FALSE (libc_epfd < 0))
3146 clib_warning ("LDP<%d>: epfd %d (0x%x): vep_idx %d (0x%x), "
3147 "libc_epfd %d (0x%x), events %p, maxevents %d, "
3148 "timeout %d, sigmask %p", getpid (), epfd, epfd,
3149 vep_idx, vep_idx, libc_epfd, libc_epfd, events,
3150 maxevents, timeout, sigmask);
3153 if (!vcom->epoll_wait_vcl)
3155 func_str = "vppcom_epoll_wait";
3158 clib_warning ("LDP<%d>: epfd %d (0x%x): calling %s(): "
3159 "vep_idx %d (0x%x), events %p, maxevents %d",
3160 getpid (), epfd, epfd, func_str,
3161 vep_idx, vep_idx, events, maxevents);
3163 rv = vppcom_epoll_wait (vep_idx, events, maxevents, 0);
3166 vcom->epoll_wait_vcl = 1;
3177 vcom->epoll_wait_vcl = 0;
3181 func_str = "libc_epoll_pwait";
3184 clib_warning ("LDP<%d>: epfd %d (0x%x): calling %s(): "
3185 "libc_epfd %d (0x%x), events %p, "
3186 "maxevents %d, sigmask %p",
3187 getpid (), epfd, epfd, func_str,
3188 libc_epfd, libc_epfd, events, maxevents, sigmask);
3190 rv = libc_epoll_pwait (epfd, events, maxevents, 1, sigmask);
3196 now = clib_time_now (&vcom->clib_time);
3198 while (now < time_out);
3205 int errno_val = errno;
3207 clib_warning ("LDP<%d>: ERROR: epfd %d (0x%x): %s() failed! "
3208 "rv %d, errno = %d", getpid (), epfd, epfd,
3209 func_str, rv, errno_val);
3213 clib_warning ("LDP<%d>: epfd %d (0x%x): returning %d (0x%x)",
3214 getpid (), epfd, epfd, rv, rv);
3220 epoll_pwait (int epfd, struct epoll_event *events,
3221 int maxevents, int timeout, const sigset_t * sigmask)
3223 return vcom_epoll_pwait (epfd, events, maxevents, timeout, sigmask);
3227 epoll_wait (int epfd, struct epoll_event *events, int maxevents, int timeout)
3229 return vcom_epoll_pwait (epfd, events, maxevents, timeout, NULL);
3233 poll (struct pollfd *fds, nfds_t nfds, int timeout)
3235 const char *func_str = __func__;
3236 int rv, i, n_libc_fds, n_revents;
3239 double wait_for_time;
3242 clib_warning ("LDP<%d>: fds %p, nfds %d, timeout %d",
3243 getpid (), fds, nfds, timeout);
3246 wait_for_time = (f64) timeout / 1000;
3251 for (i = 0; i < nfds; i++)
3256 clib_warning ("LDP<%d>: fds[%d].fd %d (0x%0x), .events = 0x%x, "
3257 ".revents = 0x%x", getpid (), i, fds[i].fd,
3258 fds[i].fd, fds[i].events, fds[i].revents);
3260 sid = vcom_sid_from_fd (fds[i].fd);
3261 if (sid != INVALID_SESSION_ID)
3263 fds[i].fd = -fds[i].fd;
3264 vec_add2 (vcom->vcl_poll, vp, 1);
3267 vp->events = fds[i].events;
3268 #ifdef __USE_XOPEN2K
3269 if (fds[i].events & POLLRDNORM)
3270 vp->events |= POLLIN;
3271 if (fds[i].events & POLLWRNORM)
3272 vp->events |= POLLOUT;
3274 vp->revents = &fds[i].revents;
3284 if (vec_len (vcom->vcl_poll))
3286 func_str = "vppcom_poll";
3289 clib_warning ("LDP<%d>: calling %s(): "
3290 "vcl_poll %p, n_sids %u (0x%x): "
3292 getpid (), func_str, vcom->vcl_poll,
3293 vec_len (vcom->vcl_poll), vec_len (vcom->vcl_poll),
3296 rv = vppcom_poll (vcom->vcl_poll, vec_len (vcom->vcl_poll), 0);
3309 func_str = "libc_poll";
3312 clib_warning ("LDP<%d>: calling %s(): fds %p, nfds %u: n_sids %u",
3313 getpid (), fds, nfds, vec_len (vcom->vcl_poll));
3315 rv = libc_poll (fds, nfds, 0);
3328 while ((wait_for_time == -1) ||
3329 (clib_time_now (&vcom->clib_time) < wait_for_time));
3333 vec_foreach (vp, vcom->vcl_poll)
3335 fds[vp->fds_ndx].fd = -fds[vp->fds_ndx].fd;
3336 #ifdef __USE_XOPEN2K
3337 if ((fds[vp->fds_ndx].revents & POLLIN) &&
3338 (fds[vp->fds_ndx].events & POLLRDNORM))
3339 fds[vp->fds_ndx].revents |= POLLRDNORM;
3340 if ((fds[vp->fds_ndx].revents & POLLOUT) &&
3341 (fds[vp->fds_ndx].events & POLLWRNORM))
3342 fds[vp->fds_ndx].revents |= POLLWRNORM;
3345 vec_reset_length (vcom->vcl_poll);
3351 int errno_val = errno;
3353 clib_warning ("LDP<%d>: ERROR: %s() failed! "
3354 "rv %d, errno = %d", getpid (),
3355 func_str, rv, errno_val);
3360 clib_warning ("LDP<%d>: returning %d (0x%x): n_sids %u, "
3361 "n_libc_fds %d", getpid (), rv, rv,
3362 vec_len (vcom->vcl_poll), n_libc_fds);
3364 for (i = 0; i < nfds; i++)
3369 clib_warning ("LDP<%d>: fds[%d].fd %d (0x%0x), "
3370 ".events = 0x%x, .revents = 0x%x",
3371 getpid (), i, fds[i].fd, fds[i].fd,
3372 fds[i].events, fds[i].revents);
3383 ppoll (struct pollfd *fds, nfds_t nfds,
3384 const struct timespec *timeout, const sigset_t * sigmask)
3386 if ((errno = -vcom_init ()))
3389 clib_warning ("LDP<%d>: LDP-TBD", getpid ());
3397 void CONSTRUCTOR_ATTRIBUTE vcom_constructor (void);
3399 void DESTRUCTOR_ATTRIBUTE vcom_destructor (void);
3402 * This function is called when the library is loaded
3405 vcom_constructor (void)
3407 swrap_constructor ();
3408 if (vcom_init () != 0)
3409 fprintf (stderr, "\nLDP<%d>: ERROR: vcom_constructor: failed!\n",
3412 clib_warning ("LDP<%d>: VCOM constructor: done!\n", getpid ());
3416 * This function is called when the library is unloaded
3419 vcom_destructor (void)
3421 swrap_destructor ();
3424 vppcom_app_destroy ();
3428 /* Don't use clib_warning() here because that calls writev()
3429 * which will call vcom_init().
3431 printf ("%s:%d: LDP<%d>: VCOM destructor: done!\n",
3432 __func__, __LINE__, getpid ());
3437 * fd.io coding-style-patch-verification: ON
3440 * eval: (c-set-style "gnu")