FD.io VPP  v21.01.1
Vector Packet Processing
punt.c
Go to the documentation of this file.
1 /*
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:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
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.
14  */
15 
16 /**
17  * @file
18  * @brief Local TCP/IP stack punt infrastructure.
19  *
20  * Provides a set of VPP nodes together with the relevant APIs and CLI
21  * commands in order to adjust and dispatch packets from the VPP data plane
22  * to the local TCP/IP stack
23  */
24 
25 #include <vnet/ip/ip.h>
26 #include <vlib/vlib.h>
27 #include <vnet/udp/udp.h>
28 #include <vnet/tcp/tcp.h>
29 #include <vnet/ip/punt.h>
30 #include <vlib/unix/unix.h>
31 
32 #include <stdio.h>
33 #include <unistd.h>
34 #include <sys/socket.h>
35 #include <sys/uio.h>
36 #include <stdlib.h>
37 
39 
40 char *
42 {
43  punt_main_t *pm = &punt_main;
44  return pm->sun_path;
45 }
46 
47 static void
49 {
50  punt_main_t *pm = &punt_main;
51 
53  punt_client_l4_mk_key (af, port),
54  index);
55 }
56 
57 static u32
59 {
60  punt_main_t *pm = &punt_main;
61  u32 key, index = ~0;
62  uword *p;
63 
64  key = punt_client_l4_mk_key (af, port);
65  p = hash_get (pm->db.clients_by_l4_port, key);
66 
67  if (p)
68  index = p[0];
69 
70  hash_unset (pm->db.clients_by_l4_port, key);
71 
72  return (index);
73 }
74 
75 static void
78 {
79  punt_main_t *pm = &punt_main;
80 
83  proto),
84  index);
85 }
86 
87 static u32
89 {
90  punt_main_t *pm = &punt_main;
91  u32 key, index = ~0;
92  uword *p;
93 
94  key = punt_client_ip_proto_mk_key (af, proto);
95  p = hash_get (pm->db.clients_by_ip_proto, key);
96 
97  if (p)
98  index = p[0];
99 
100  hash_unset (pm->db.clients_by_ip_proto, key);
101 
102  return (index);
103 }
104 
105 static void
107 {
108  punt_main_t *pm = &punt_main;
109 
111 
112  pm->db.clients_by_exception[reason] = pci;
113 }
114 
115 static u32
117 {
118  punt_main_t *pm = &punt_main;
119  u32 pci = ~0;
120 
121  if (punt_client_exception_get (reason))
122  {
123  pci = pm->db.clients_by_exception[reason];
124  pm->db.clients_by_exception[reason] = ~0;
125  }
126 
127  return pci;
128 }
129 
130 static clib_error_t *
132 {
134  punt_main_t *pm = &punt_main;
135 
136  /** Schedule the rx node */
139 
140  return 0;
141 }
142 
143 static clib_error_t *
146  u8 protocol, u16 port, char *client_pathname)
147 {
148  punt_main_t *pm = &punt_main;
149  punt_client_t *c;
150 
151  /* For now we only support UDP punt */
152  if (protocol != IP_PROTOCOL_UDP)
153  return clib_error_return (0,
154  "only UDP protocol (%d) is supported, got %d",
155  IP_PROTOCOL_UDP, protocol);
156 
157  if (port == (u16) ~ 0)
158  return clib_error_return (0, "UDP port number required");
159 
160  c = punt_client_l4_get (af, port);
161 
162  if (NULL == c)
163  {
165  punt_client_l4_db_add (af, port, c - pm->punt_client_pool);
166  }
167 
168  memcpy (c->caddr.sun_path, client_pathname, sizeof (c->caddr.sun_path));
169  c->caddr.sun_family = AF_UNIX;
170  c->reg.type = PUNT_TYPE_L4;
171  c->reg.punt.l4.port = port;
172  c->reg.punt.l4.protocol = protocol;
173  c->reg.punt.l4.af = af;
174 
175  u32 node_index = (af == AF_IP4 ?
176  udp4_punt_socket_node.index :
177  udp6_punt_socket_node.index);
178 
179  udp_register_dst_port (vm, port, node_index, af == AF_IP4);
180 
181  return (NULL);
182 }
183 
184 static clib_error_t *
187  ip_protocol_t proto, char *client_pathname)
188 {
189  punt_main_t *pm = &punt_main;
190  punt_client_t *c;
191 
192  c = punt_client_ip_proto_get (af, proto);
193 
194  if (NULL == c)
195  {
197  punt_client_ip_proto_db_add (af, proto, c - pm->punt_client_pool);
198  }
199 
200  memcpy (c->caddr.sun_path, client_pathname, sizeof (c->caddr.sun_path));
201  c->caddr.sun_family = AF_UNIX;
202  c->reg.type = PUNT_TYPE_IP_PROTO;
204  c->reg.punt.ip_proto.af = af;
205 
206  if (af == AF_IP4)
208  else
210 
211  return (NULL);
212 }
213 
214 static clib_error_t *
216  vlib_punt_reason_t reason,
217  char *client_pathname)
218 {
219  punt_main_t *pm = &punt_main;
220  punt_client_t *pc;
221 
222  pc = punt_client_exception_get (reason);
223 
224  if (NULL == pc)
225  {
228  }
229 
230  memcpy (pc->caddr.sun_path, client_pathname, sizeof (pc->caddr.sun_path));
231  pc->caddr.sun_family = AF_UNIX;
232  pc->reg.type = PUNT_TYPE_EXCEPTION;
233  pc->reg.punt.exception.reason = reason;
234 
235  vlib_punt_register (pm->hdl,
236  pc->reg.punt.exception.reason, "exception-punt-socket");
237 
238  return (NULL);
239 }
240 
241 static clib_error_t *
244 {
245  u32 pci;
246 
247  udp_unregister_dst_port (vlib_get_main (), port, af == AF_IP4);
248 
249  pci = punt_client_l4_db_remove (af, port);
250 
251  if (~0 != pci)
252  pool_put_index (punt_main.punt_client_pool, pci);
253 
254  return (NULL);
255 }
256 
257 static clib_error_t *
259 {
260  u32 pci;
261 
262  if (af == AF_IP4)
263  ip4_unregister_protocol (proto);
264  else
265  ip6_unregister_protocol (proto);
266 
267  pci = punt_client_ip_proto_db_remove (af, proto);
268 
269  if (~0 != pci)
270  pool_put_index (punt_main.punt_client_pool, pci);
271 
272  return (NULL);
273 }
274 
275 static clib_error_t *
277 {
278  u32 pci;
279 
280  pci = punt_client_exception_db_remove (reason);
281 
282  if (~0 != pci)
283  pool_put_index (punt_main.punt_client_pool, pci);
284 
285  return (NULL);
286 }
287 
288 clib_error_t *
290  const punt_reg_t * pr, char *client_pathname)
291 {
292  punt_main_t *pm = &punt_main;
293 
294  if (!pm->is_configured)
295  return clib_error_return (0, "socket is not configured");
296 
297  if (header_version != PUNT_PACKETDESC_VERSION)
298  return clib_error_return (0, "Invalid packet descriptor version");
299 
300  if (strncmp (client_pathname, vnet_punt_get_server_pathname (),
301  UNIX_PATH_MAX) == 0)
302  return clib_error_return (0,
303  "Punt socket: Invalid client path: %s",
304  client_pathname);
305 
306  /* Register client */
307  switch (pr->type)
308  {
309  case PUNT_TYPE_L4:
310  return (punt_socket_register_l4 (vm,
311  pr->punt.l4.af,
312  pr->punt.l4.protocol,
313  pr->punt.l4.port, client_pathname));
314  case PUNT_TYPE_IP_PROTO:
315  return (punt_socket_register_ip_proto (vm,
316  pr->punt.ip_proto.af,
317  pr->punt.ip_proto.protocol,
318  client_pathname));
319  case PUNT_TYPE_EXCEPTION:
320  return (punt_socket_register_exception (vm,
321  pr->punt.exception.reason,
322  client_pathname));
323  }
324 
325  return 0;
326 }
327 
328 clib_error_t *
330 {
331  punt_main_t *pm = &punt_main;
332 
333  if (!pm->is_configured)
334  return clib_error_return (0, "socket is not configured");
335 
336  switch (pr->type)
337  {
338  case PUNT_TYPE_L4:
339  return (punt_socket_unregister_l4 (pr->punt.l4.af,
340  pr->punt.l4.protocol,
341  pr->punt.l4.port));
342  case PUNT_TYPE_IP_PROTO:
344  pr->punt.ip_proto.protocol));
345  case PUNT_TYPE_EXCEPTION:
347  }
348 
349  return 0;
350 }
351 
352 /**
353  * @brief Request IP L4 traffic punt to the local TCP/IP stack.
354  *
355  * @em Note
356  * - UDP is the only protocol supported in the current implementation
357  *
358  * @param vm vlib_main_t corresponding to the current thread
359  * @param af IP address family.
360  * @param protocol 8-bits L4 protocol value
361  * UDP is 17
362  * TCP is 1
363  * @param port 16-bits L4 (TCP/IP) port number when applicable (UDP only)
364  *
365  * @returns 0 on success, non-zero value otherwise
366  */
367 static clib_error_t *
370  ip_protocol_t protocol, u16 port, bool is_add)
371 {
372  /* For now we only support TCP and UDP punt */
373  if (protocol != IP_PROTOCOL_UDP && protocol != IP_PROTOCOL_TCP)
374  return clib_error_return (0,
375  "only UDP (%d) and TCP (%d) protocols are supported, got %d",
376  IP_PROTOCOL_UDP, IP_PROTOCOL_TCP, protocol);
377 
378  if (port == (u16) ~ 0)
379  {
380  if (protocol == IP_PROTOCOL_UDP)
381  udp_punt_unknown (vm, af == AF_IP4, is_add);
382  else if (protocol == IP_PROTOCOL_TCP)
383  tcp_punt_unknown (vm, af == AF_IP4, is_add);
384 
385  return 0;
386  }
387 
388  else if (is_add)
389  {
390  if (protocol == IP_PROTOCOL_TCP)
391  return clib_error_return (0, "punt TCP ports is not supported yet");
392 
393  udp_register_dst_port (vm, port, udp4_punt_node.index, af == AF_IP4);
394 
395  return 0;
396  }
397  else
398  {
399  if (protocol == IP_PROTOCOL_TCP)
400  return clib_error_return (0, "punt TCP ports is not supported yet");
401 
402  udp_unregister_dst_port (vm, port, af == AF_IP4);
403 
404  return 0;
405  }
406 }
407 
408 clib_error_t *
409 vnet_punt_add_del (vlib_main_t * vm, const punt_reg_t * pr, bool is_add)
410 {
411  switch (pr->type)
412  {
413  case PUNT_TYPE_L4:
414  return (punt_l4_add_del (vm, pr->punt.l4.af, pr->punt.l4.protocol,
415  pr->punt.l4.port, is_add));
416  case PUNT_TYPE_EXCEPTION:
417  case PUNT_TYPE_IP_PROTO:
418  break;
419  }
420 
421  return (clib_error_return (0, "Unsupported punt type: %d", pr->type));
422 }
423 
424 static clib_error_t *
426  unformat_input_t * input__, vlib_cli_command_t * cmd)
427 {
428  unformat_input_t line_input, *input = &line_input;
429  clib_error_t *error = NULL;
430  bool is_add = true;
431  /* *INDENT-OFF* */
432  punt_reg_t pr = {
433  .punt = {
434  .l4 = {
435  .af = AF_IP4,
436  .port = ~0,
437  .protocol = IP_PROTOCOL_UDP,
438  },
439  },
440  .type = PUNT_TYPE_L4,
441  };
442  u32 port;
443  /* *INDENT-ON* */
444 
445  if (!unformat_user (input__, unformat_line_input, input))
446  return 0;
447 
449  {
450  if (unformat (input, "del"))
451  is_add = false;
452  else if (unformat (input, "ipv4"))
453  pr.punt.l4.af = AF_IP4;
454  else if (unformat (input, "ipv6"))
455  pr.punt.l4.af = AF_IP6;
456  else if (unformat (input, "ip6"))
457  pr.punt.l4.af = AF_IP6;
458  else if (unformat (input, "%d", &port))
459  pr.punt.l4.port = port;
460  else if (unformat (input, "all"))
461  pr.punt.l4.port = ~0;
462  else if (unformat (input, "udp"))
463  pr.punt.l4.protocol = IP_PROTOCOL_UDP;
464  else if (unformat (input, "tcp"))
465  pr.punt.l4.protocol = IP_PROTOCOL_TCP;
466  else
467  {
468  error = clib_error_return (0, "parse error: '%U'",
469  format_unformat_error, input);
470  goto done;
471  }
472  }
473 
474  /* punt both IPv6 and IPv4 when used in CLI */
475  error = vnet_punt_add_del (vm, &pr, is_add);
476  if (error)
477  {
478  clib_error_report (error);
479  }
480 
481 done:
482  unformat_free (input);
483  return error;
484 }
485 
486 /*?
487  * The set of '<em>set punt</em>' commands allows specific IP traffic to
488  * be punted to the host TCP/IP stack
489  *
490  * @em Note
491  * - UDP is the only protocol supported in the current implementation
492  * - All TCP traffic is currently punted to the host by default
493  *
494  * @cliexpar
495  * @parblock
496  * Example of how to request NTP traffic to be punted
497  * @cliexcmd{set punt udp 125}
498  *
499  * Example of how to request all 'unknown' UDP traffic to be punted
500  * @cliexcmd{set punt udp all}
501  *
502  * Example of how to stop all 'unknown' UDP traffic to be punted
503  * @cliexcmd{set punt udp del all}
504  * @endparblock
505 ?*/
506 /* *INDENT-OFF* */
507 VLIB_CLI_COMMAND (punt_command, static) = {
508  .path = "set punt",
509  .short_help = "set punt [IPV4|ip6|ipv6] [UDP|tcp] [del] [ALL|<port-num>]",
510  .function = punt_cli,
511 };
512 /* *INDENT-ON* */
513 
514 static clib_error_t *
516  unformat_input_t * input__,
517  vlib_cli_command_t * cmd)
518 {
519  unformat_input_t line_input, *input = &line_input;
520  u8 *socket_name = 0;
521  clib_error_t *error = NULL;
522  /* *INDENT-OFF* */
523  punt_reg_t pr = {
524  .punt = {
525  .l4 = {
526  .af = AF_IP4,
527  .port = ~0,
528  .protocol = IP_PROTOCOL_UDP,
529  },
530  },
531  .type = PUNT_TYPE_L4,
532  };
533  /* *INDENT-ON* */
534 
535  if (!unformat_user (input__, unformat_line_input, input))
536  return 0;
537 
539  {
540  if (unformat (input, "ipv4"))
541  pr.punt.l4.af = AF_IP4;
542  else if (unformat (input, "ipv6"))
543  pr.punt.l4.af = AF_IP6;
544  else if (unformat (input, "udp"))
545  pr.punt.l4.protocol = IP_PROTOCOL_UDP;
546  else if (unformat (input, "tcp"))
547  pr.punt.l4.protocol = IP_PROTOCOL_TCP;
548  else if (unformat (input, "%d", &pr.punt.l4.port))
549  ;
550  else if (unformat (input, "all"))
551  pr.punt.l4.port = ~0;
552  else if (unformat (input, "socket %s", &socket_name))
553  ;
554  else
555  {
556  error = clib_error_return (0, "parse error: '%U'",
557  format_unformat_error, input);
558  goto done;
559  }
560  }
561 
562  if (!socket_name)
563  error = clib_error_return (0, "socket name not specified");
564  else
565  error = vnet_punt_socket_add (vm, 1, &pr, (char *) socket_name);
566 
567 done:
568  unformat_free (input);
569  return error;
570 }
571 
572 /*?
573  *
574  * @cliexpar
575  * @cliexcmd{punt socket register socket punt_l4_foo.sock}
576 
577  ?*/
578 /* *INDENT-OFF* */
579 VLIB_CLI_COMMAND (punt_socket_register_command, static) =
580 {
581  .path = "punt socket register",
582  .function = punt_socket_register_cmd,
583  .short_help = "punt socket register [IPV4|ipv6] [UDP|tcp] [ALL|<port-num>] socket <socket>",
584  .is_mp_safe = 1,
585 };
586 /* *INDENT-ON* */
587 
588 static clib_error_t *
590  unformat_input_t * input__,
591  vlib_cli_command_t * cmd)
592 {
593  unformat_input_t line_input, *input = &line_input;
594  clib_error_t *error = NULL;
595  /* *INDENT-OFF* */
596  punt_reg_t pr = {
597  .punt = {
598  .l4 = {
599  .af = AF_IP4,
600  .port = ~0,
601  .protocol = IP_PROTOCOL_UDP,
602  },
603  },
604  .type = PUNT_TYPE_L4,
605  };
606  /* *INDENT-ON* */
607 
608  if (!unformat_user (input__, unformat_line_input, input))
609  return 0;
610 
612  {
613  if (unformat (input, "ipv4"))
614  pr.punt.l4.af = AF_IP4;
615  else if (unformat (input, "ipv6"))
616  pr.punt.l4.af = AF_IP6;
617  else if (unformat (input, "udp"))
618  pr.punt.l4.protocol = IP_PROTOCOL_UDP;
619  else if (unformat (input, "tcp"))
620  pr.punt.l4.protocol = IP_PROTOCOL_TCP;
621  else if (unformat (input, "%d", &pr.punt.l4.port))
622  ;
623  else if (unformat (input, "all"))
624  pr.punt.l4.port = ~0;
625  else
626  {
627  error = clib_error_return (0, "parse error: '%U'",
628  format_unformat_error, input);
629  goto done;
630  }
631  }
632 
633  error = vnet_punt_socket_del (vm, &pr);
634 done:
635  unformat_free (input);
636  return error;
637 }
638 
639 /*?
640  *
641  * @cliexpar
642  * @cliexcmd{punt socket register}
643  ?*/
644 /* *INDENT-OFF* */
645 VLIB_CLI_COMMAND (punt_socket_deregister_command, static) =
646 {
647  .path = "punt socket deregister",
648  .function = punt_socket_deregister_cmd,
649  .short_help = "punt socket deregister [IPV4|ipv6] [UDP|tcp] [ALL|<port-num>]",
650  .is_mp_safe = 1,
651 };
652 /* *INDENT-ON* */
653 
654 void
656 {
657  punt_main_t *pm = &punt_main;
658 
659  switch (pt)
660  {
661  case PUNT_TYPE_L4:
662  {
663  u32 pci, key;
664 
665  /* *INDENT-OFF* */
666  hash_foreach(key, pci, pm->db.clients_by_l4_port,
667  ({
668  cb (pool_elt_at_index(pm->punt_client_pool, pci), ctx);
669  }));
670  /* *INDENT-ON* */
671  break;
672  }
673  case PUNT_TYPE_IP_PROTO:
674  {
675  u32 pci, key;
676 
677  /* *INDENT-OFF* */
678  hash_foreach(key, pci, pm->db.clients_by_ip_proto,
679  ({
680  cb (pool_elt_at_index(pm->punt_client_pool, pci), ctx);
681  }));
682  /* *INDENT-ON* */
683  break;
684  }
685  case PUNT_TYPE_EXCEPTION:
686  {
687  u32 *pci;
688 
690  {
691  if (~0 != *pci)
692  cb (pool_elt_at_index (pm->punt_client_pool, *pci), ctx);
693  }
694 
695  break;
696  }
697  }
698 }
699 
700 static u8 *
701 format_punt_client (u8 * s, va_list * args)
702 {
703  punt_client_t *pc = va_arg (*args, punt_client_t *);
704 
705  s = format (s, " punt ");
706 
707  switch (pc->reg.type)
708  {
709  case PUNT_TYPE_L4:
710  s = format (s, "%U %U port %d",
713  pc->reg.punt.l4.port);
714  break;
715  case PUNT_TYPE_IP_PROTO:
716  s = format (s, "%U %U",
719  break;
720  case PUNT_TYPE_EXCEPTION:
721  s = format (s, " %U", format_vlib_punt_reason,
722  pc->reg.punt.exception.reason);
723  break;
724  }
725 
726  s = format (s, " to socket %s \n", pc->caddr.sun_path);
727 
728  return (s);
729 }
730 
731 static walk_rc_t
733 {
734  vlib_cli_output (ctx, "%U", format_punt_client, pc);
735 
736  return (WALK_CONTINUE);
737 }
738 
739 static clib_error_t *
741  unformat_input_t * input__, vlib_cli_command_t * cmd)
742 {
743  unformat_input_t line_input, *input = &line_input;
744  clib_error_t *error = NULL;
745  punt_type_t pt;
746 
747  pt = PUNT_TYPE_L4;
748 
749  if (!unformat_user (input__, unformat_line_input, input))
750  return 0;
751 
753  {
754  if (unformat (input, "exception"))
755  pt = PUNT_TYPE_EXCEPTION;
756  else if (unformat (input, "l4"))
757  pt = PUNT_TYPE_L4;
758  else if (unformat (input, "ip"))
759  pt = PUNT_TYPE_IP_PROTO;
760  else
761  {
762  error = clib_error_return (0, "parse error: '%U'",
763  format_unformat_error, input);
764  goto done;
765  }
766  }
767 
769 
770 done:
771  unformat_free (input);
772  return (error);
773 }
774 
775 /*?
776  *
777  * @cliexpar
778  * @cliexcmd{show punt socket ipv4}
779  ?*/
780 /* *INDENT-OFF* */
781 VLIB_CLI_COMMAND (show_punt_socket_registration_command, static) =
782 {
783  .path = "show punt socket registrations",
784  .function = punt_socket_show_cmd,
785  .short_help = "show punt socket registrations [l4|exception]",
786  .is_mp_safe = 1,
787 };
788 /* *INDENT-ON* */
789 
790 clib_error_t *
792 {
793  clib_error_t *error = NULL;
794  punt_main_t *pm = &punt_main;
796 
797  pm->is_configured = false;
799  vlib_get_node_by_name (vm, (u8 *) "interface-output");
800 
801  if ((error = vlib_call_init_function (vm, punt_init)))
802  return error;
803 
804  pm->hdl = vlib_punt_client_register ("ip-punt");
805 
808 
809  return (error);
810 }
811 
813 
814 static clib_error_t *
816 {
817  punt_main_t *pm = &punt_main;
818  char *socket_path = 0;
819 
821  {
822  if (unformat (input, "socket %s", &socket_path))
823  strncpy (pm->sun_path, socket_path, UNIX_PATH_MAX - 1);
824  else
825  return clib_error_return (0, "unknown input `%U'",
826  format_unformat_error, input);
827  }
828 
829  if (socket_path == 0)
830  return 0;
831 
832  /* UNIX domain socket */
833  struct sockaddr_un addr;
834  if ((pm->socket_fd = socket (AF_UNIX, SOCK_DGRAM | SOCK_NONBLOCK, 0)) == -1)
835  {
836  return clib_error_return (0, "socket error");
837  }
838 
839  clib_memset (&addr, 0, sizeof (addr));
840  addr.sun_family = AF_UNIX;
841  if (*socket_path == '\0')
842  {
843  *addr.sun_path = '\0';
844  strncpy (addr.sun_path + 1, socket_path + 1,
845  sizeof (addr.sun_path) - 2);
846  }
847  else
848  {
849  strncpy (addr.sun_path, socket_path, sizeof (addr.sun_path) - 1);
850  unlink (socket_path);
851  }
852 
853  if (bind (pm->socket_fd, (struct sockaddr *) &addr, sizeof (addr)) == -1)
854  {
855  return clib_error_return (0, "bind error");
856  }
857 
858  int n_bytes = 0x10000;
859 
860  if (setsockopt
861  (pm->socket_fd, SOL_SOCKET, SO_SNDBUF, &n_bytes,
862  sizeof (n_bytes)) == -1)
863  {
864  return clib_error_return (0, "setsockopt error");
865  }
866 
867  /* Register socket */
869  clib_file_t template = { 0 };
871  template.file_descriptor = pm->socket_fd;
872  template.description = format (0, "%s", socket_path);
873  pm->clib_file_index = clib_file_add (fm, &template);
874 
875  pm->is_configured = true;
876 
877  return 0;
878 }
879 
881 
882 /*
883  * fd.io coding-style-patch-verification: ON
884  *
885  * Local Variables:
886  * eval: (c-set-style "gnu")
887  * End:
888  */
void udp_unregister_dst_port(vlib_main_t *vm, udp_dst_port_t dst_port, u8 is_ip4)
Definition: udp_local.c:506
vlib_node_t * interface_output_node
Definition: punt.h:127
enum punt_type_t_ punt_type_t
format_function_t format_ip_protocol
Definition: format.h:45
static u32 punt_client_exception_db_remove(vlib_punt_reason_t reason)
Definition: punt.c:116
A registration, by a client, to direct punted traffic to a given node.
Definition: punt.h:64
static u8 * format_punt_client(u8 *s, va_list *args)
Definition: punt.c:701
#define hash_set(h, key, value)
Definition: hash.h:255
#define hash_unset(h, key)
Definition: hash.h:261
void ip6_register_protocol(u32 protocol, u32 node_index)
Definition: ip6_forward.c:1668
ip_protocol_t protocol
Definition: punt.h:49
#define pool_get_zero(P, E)
Allocate an object E from a pool P and zero it.
Definition: pool.h:254
void ip6_unregister_protocol(u32 protocol)
Definition: ip6_forward.c:1680
static clib_error_t * punt_config(vlib_main_t *vm, unformat_input_t *input)
Definition: punt.c:815
static_always_inline u32 punt_client_l4_mk_key(ip_address_family_t af, u16 port)
Definition: punt.h:145
static clib_error_t * punt_socket_read_ready(clib_file_t *uf)
Definition: punt.c:131
vl_api_ip_proto_t protocol
Definition: lb_types.api:72
static void vlib_node_set_interrupt_pending(vlib_main_t *vm, u32 node_index)
Definition: node_funcs.h:255
vlib_node_registration_t ip4_proto_punt_socket_node
(constructor) VLIB_REGISTER_NODE (ip4_proto_punt_socket_node)
Definition: punt_node.c:458
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
u32 * ready_fds
Definition: punt.h:128
u32 clib_file_index
Definition: punt.h:125
u32 file_descriptor
Definition: file.h:54
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:592
punt_reg_t reg
Definition: punt.h:103
punt_type_t type
Definition: punt.h:66
static_always_inline punt_client_t * punt_client_l4_get(ip_address_family_t af, u16 port)
Definition: punt.h:151
void udp_register_dst_port(vlib_main_t *vm, udp_dst_port_t dst_port, u32 node_index, u8 is_ip4)
Definition: udp_local.c:468
vlib_node_registration_t udp4_punt_socket_node
(constructor) VLIB_REGISTER_NODE (udp4_punt_socket_node)
Definition: punt_node.c:439
int socket_fd
Definition: punt.h:121
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:989
static walk_rc_t punt_client_show_one(const punt_client_t *pc, void *ctx)
Definition: punt.c:732
clib_error_t * vnet_punt_socket_del(vlib_main_t *vm, const punt_reg_t *pr)
Definition: punt.c:329
vlib_main_t * vm
Definition: in2out_ed.c:1580
static_always_inline punt_client_t * punt_client_ip_proto_get(ip_address_family_t af, ip_protocol_t proto)
Definition: punt.h:171
#define vec_validate_aligned(V, I, A)
Make sure vector is long enough for given index (no header, specified alignment)
Definition: vec.h:520
void ip4_register_protocol(u32 protocol, u32 node_index)
Definition: ip4_forward.c:1894
unsigned char u8
Definition: types.h:56
punt_thread_data_t * thread_data
Definition: punt.h:130
clib_error_t * vnet_punt_socket_add(vlib_main_t *vm, u32 header_version, const punt_reg_t *pr, char *client_pathname)
Definition: punt.c:289
clib_file_function_t * read_function
Definition: file.h:67
u8 * format_vlib_punt_reason(u8 *s, va_list *args)
Format a punt reason.
Definition: punt.c:148
static clib_error_t * punt_socket_register_cmd(vlib_main_t *vm, unformat_input_t *input__, vlib_cli_command_t *cmd)
Definition: punt.c:515
#define fm
enum walk_rc_t_ walk_rc_t
Walk return code.
static clib_error_t * punt_socket_deregister_cmd(vlib_main_t *vm, unformat_input_t *input__, vlib_cli_command_t *cmd)
Definition: punt.c:589
static void punt_client_ip_proto_db_add(ip_address_family_t af, ip_protocol_t proto, u32 index)
Definition: punt.c:76
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:173
punt_client_t * punt_client_pool
Definition: punt.h:124
description fragment has unexpected format
Definition: map.api:433
#define hash_foreach(key_var, value_var, h, body)
Definition: hash.h:442
static u32 punt_client_ip_proto_db_remove(ip_address_family_t af, ip_protocol_t proto)
Definition: punt.c:88
#define clib_error_return(e, args...)
Definition: error.h:99
clib_file_main_t file_main
Definition: main.c:63
static_always_inline punt_client_t * punt_client_exception_get(vlib_punt_reason_t reason)
Definition: punt.h:187
unsigned int u32
Definition: types.h:88
#define vlib_call_init_function(vm, x)
Definition: init.h:270
static clib_error_t * punt_cli(vlib_main_t *vm, unformat_input_t *input__, vlib_cli_command_t *cmd)
Definition: punt.c:425
vlib_punt_hdl_t hdl
Definition: punt.h:131
vlib_punt_hdl_t vlib_punt_client_register(const char *who)
Register a new clinet.
Definition: punt.c:156
unformat_function_t unformat_line_input
Definition: format.h:282
static_always_inline u32 punt_client_ip_proto_mk_key(ip_address_family_t af, ip_protocol_t proto)
Definition: punt.h:165
enum ip_protocol ip_protocol_t
Definition: cJSON.c:84
static void punt_client_exception_db_add(vlib_punt_reason_t reason, u32 pci)
Definition: punt.c:106
#define hash_get(h, key)
Definition: hash.h:249
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:546
vlib_node_t * vlib_get_node_by_name(vlib_main_t *vm, u8 *name)
Definition: node.c:45
punt_ip_proto_t ip_proto
Definition: punt.h:61
vl_api_ip_proto_t proto
Definition: acl_types.api:51
long ctx[MAX_CONNS]
Definition: main.c:144
struct _unformat_input_t unformat_input_t
unsigned short u16
Definition: types.h:57
static clib_error_t * punt_l4_add_del(vlib_main_t *vm, ip_address_family_t af, ip_protocol_t protocol, u16 port, bool is_add)
Request IP L4 traffic punt to the local TCP/IP stack.
Definition: punt.c:368
ip_address_family_t af
Definition: punt.h:41
#define VLIB_CONFIG_FUNCTION(x, n,...)
Definition: init.h:182
vlib_node_registration_t punt_socket_rx_node
(constructor) VLIB_REGISTER_NODE (punt_socket_rx_node)
Definition: punt_node.c:620
u8 * format_ip_address_family(u8 *s, va_list *args)
Definition: ip.c:192
static clib_error_t * punt_init(vlib_main_t *vm)
Definition: punt.c:663
static clib_error_t * punt_socket_show_cmd(vlib_main_t *vm, unformat_input_t *input__, vlib_cli_command_t *cmd)
Definition: punt.c:740
punt_exception_t exception
Definition: punt.h:59
void udp_punt_unknown(vlib_main_t *vm, u8 is_ip4, u8 is_add)
Definition: udp_local.c:545
vlib_node_registration_t udp6_punt_socket_node
(constructor) VLIB_REGISTER_NODE (udp6_punt_socket_node)
Definition: punt_node.c:449
#define UNFORMAT_END_OF_INPUT
Definition: format.h:144
svmdb_client_t * c
static clib_error_t * punt_socket_unregister_exception(vlib_punt_reason_t reason)
Definition: punt.c:276
static clib_error_t * punt_socket_register_exception(vlib_main_t *vm, vlib_punt_reason_t reason, char *client_pathname)
Definition: punt.c:215
static clib_error_t * punt_socket_register_ip_proto(vlib_main_t *vm, ip_address_family_t af, ip_protocol_t proto, char *client_pathname)
Definition: punt.c:185
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:158
static clib_error_t * punt_socket_unregister_ip_proto(ip_address_family_t af, ip_protocol_t proto)
Definition: punt.c:258
#define pool_put_index(p, i)
Free pool element with given index.
Definition: pool.h:330
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:696
ip_address_family_t af
Definition: punt.h:48
walk_rc_t(* punt_client_walk_cb_t)(const punt_client_t *pc, void *ctx)
Definition: punt.h:136
ip_protocol_t protocol
Definition: punt.h:42
static uword clib_file_add(clib_file_main_t *um, clib_file_t *template)
Definition: file.h:96
char sun_path[sizeof(struct sockaddr_un)]
Definition: punt.h:122
punt_main_t punt_main
Definition: punt.c:38
punt_l4_t l4
Definition: punt.h:60
static u32 punt_client_l4_db_remove(ip_address_family_t af, u16 port)
Definition: punt.c:58
#define clib_error_report(e)
Definition: error.h:113
static vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:23
u32 * clients_by_exception
Definition: punt.h:110
enum ip_address_family_t_ ip_address_family_t
typedef key
Definition: ipsec_types.api:86
void tcp_punt_unknown(vlib_main_t *vm, u8 is_ip4, u8 is_add)
Definition: tcp.c:1396
int vlib_punt_register(vlib_punt_hdl_t client, vlib_punt_reason_t reason, const char *node_name)
Register a node to receive particular punted buffers.
Definition: punt.c:268
static void punt_client_l4_db_add(ip_address_family_t af, u16 port, u32 index)
Definition: punt.c:48
void * clients_by_ip_proto
Definition: punt.h:111
bool is_configured
Definition: punt.h:126
punt_union_t punt
Definition: punt.h:67
u64 uword
Definition: types.h:112
static void unformat_free(unformat_input_t *i)
Definition: format.h:162
vlib_node_registration_t ip6_proto_punt_socket_node
(constructor) VLIB_REGISTER_NODE (ip6_proto_punt_socket_node)
Definition: punt_node.c:468
u32 index
Definition: flow_types.api:221
punt_client_db_t db
Definition: punt.h:123
u16 port
Definition: lb_types.api:73
static clib_error_t * punt_socket_register_l4(vlib_main_t *vm, ip_address_family_t af, u8 protocol, u16 port, char *client_pathname)
Definition: punt.c:144
#define PUNT_PACKETDESC_VERSION
Definition: punt.h:91
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
static clib_error_t * punt_socket_unregister_l4(ip_address_family_t af, ip_protocol_t protocol, u16 port)
Definition: punt.c:242
static vlib_thread_main_t * vlib_get_thread_main()
Definition: global_funcs.h:32
#define vec_foreach(var, vec)
Vector iterator.
clib_error_t * ip_punt_init(vlib_main_t *vm)
Definition: punt.c:791
Definition: file.h:51
#define vec_validate_init_empty(V, I, INIT)
Make sure vector is long enough for given index and initialize empty space (no header, unspecified alignment)
Definition: vec.h:556
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:59
clib_error_t * vnet_punt_add_del(vlib_main_t *vm, const punt_reg_t *pr, bool is_add)
Definition: punt.c:409
vlib_punt_reason_t reason
Definition: punt.h:54
enum vlib_punt_reason_t_ vlib_punt_reason_t
The &#39;syatem&#39; defined punt reasons.
char * vnet_punt_get_server_pathname(void)
Definition: punt.c:41
void * clients_by_l4_port
Definition: punt.h:109
vlib_node_registration_t udp4_punt_node
(constructor) VLIB_REGISTER_NODE (udp4_punt_node)
Definition: punt_node.c:186
void ip4_unregister_protocol(u32 protocolx)
Definition: ip4_forward.c:1906
u16 port
Definition: punt.h:43
void punt_client_walk(punt_type_t pt, punt_client_walk_cb_t cb, void *ctx)
Definition: punt.c:655
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
struct sockaddr_un caddr
Definition: punt.h:104
Definitions for punt infrastructure.
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:170