FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
l2tp.c
Go to the documentation of this file.
1 /*
2  * l2tp.c : L2TPv3 tunnel support
3  *
4  * Copyright (c) 2013 Cisco and/or its affiliates.
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #include <vppinfra/error.h>
19 #include <vppinfra/hash.h>
20 #include <vnet/vnet.h>
21 #include <vnet/ip/ip.h>
22 #include <vnet/l2/l2_input.h>
23 #include <vnet/ethernet/ethernet.h>
24 #include <l2tp/l2tp.h>
25 
27 
28 /* packet trace format function */
29 u8 *
30 format_l2t_trace (u8 * s, va_list * args)
31 {
32  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
33  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
34  l2t_trace_t *t = va_arg (*args, l2t_trace_t *);
35 
36  if (t->is_user_to_network)
37  s = format (s, "L2T: %U (client) -> %U (our) session %d",
40  else
41  s = format (s, "L2T: %U (our) -> %U (client) session %d)",
44  return s;
45 }
46 
47 u8 *
48 format_l2t_session (u8 * s, va_list * args)
49 {
50  l2t_session_t *session = va_arg (*args, l2t_session_t *);
51  l2t_main_t *lm = &l2t_main;
54 
55  s = format (s, "[%d] %U (our) %U (client) %U (sw_if_index %d)\n",
56  session - lm->sessions,
61  session->sw_if_index);
62 
63  s = format (s, " local cookies %016llx %016llx remote cookie %016llx\n",
64  clib_net_to_host_u64 (session->local_cookie[0]),
65  clib_net_to_host_u64 (session->local_cookie[1]),
66  clib_net_to_host_u64 (session->remote_cookie));
67 
68  s = format (s, " local session-id %d remote session-id %d\n",
69  clib_net_to_host_u32 (session->local_session_id),
70  clib_net_to_host_u32 (session->remote_session_id));
71 
72  s = format (s, " l2 specific sublayer %s\n",
73  session->l2_sublayer_present ? "preset" : "absent");
74 
78 
80  if (v.packets != 0)
81  s = format (s, " user-to-net: %llu pkts %llu bytes\n",
82  v.packets, v.bytes);
83 
85 
86  if (v.packets != 0)
87  s = format (s, " net-to-user: %llu pkts %llu bytes\n",
88  v.packets, v.bytes);
89  return s;
90 }
91 
92 static clib_error_t *
94  unformat_input_t * input, vlib_cli_command_t * cmd)
95 {
96  l2t_session_t *session;
97  l2t_main_t *lm = &l2t_main;
98  char *keystr = 0;
99  int verbose = 0;
100 
101  if (unformat (input, "verbose") || unformat (input, "v"))
102  verbose = 1;
103 
104  if (pool_elts (lm->sessions) == 0)
105  vlib_cli_output (vm, "No l2tp sessions...");
106  else
107  vlib_cli_output (vm, "%u l2tp sessions...", pool_elts (lm->sessions));
108 
109  if (verbose)
110  {
111  switch (lm->lookup_type)
112  {
114  keystr = "src address";
115  break;
116 
118  keystr = "dst address";
119  break;
120 
122  keystr = "session id";
123  break;
124 
125  default:
126  keystr = "BOGUS!";
127  break;
128  }
129 
130  vlib_cli_output (vm, "L2tp session lookup on %s", keystr);
131 
132  /* *INDENT-OFF* */
133  pool_foreach (session, lm->sessions)
134  {
135  vlib_cli_output (vm, "%U", format_l2t_session, session);
136  }
137  /* *INDENT-ON* */
138  }
139 
140  return 0;
141 }
142 
143 /* *INDENT-OFF* */
145  .path = "show l2tpv3",
146  .short_help = "show l2tpv3 [verbose]",
147  .function = show_l2tp_command_fn,
148 };
149 /* *INDENT-ON* */
150 
151 static clib_error_t *
153  unformat_input_t * input, vlib_cli_command_t * cmd)
154 {
155  l2t_session_t *session;
156  l2t_main_t *lm = &l2t_main;
157  u32 session_index;
159  u32 nincr = 0;
161 
162  /* *INDENT-OFF* */
163  pool_foreach (session, lm->sessions)
164  {
165  session_index = session - lm->sessions;
166  counter_index =
167  session_index_to_counter_index (session_index,
170  thread_index,
172  1/*pkt*/, 1111 /*bytes*/);
174  thread_index,
175  counter_index+1,
176  1/*pkt*/, 2222 /*bytes*/);
177  nincr++;
178 
179  }
180  /* *INDENT-ON* */
181  vlib_cli_output (vm, "Incremented %d active counters\n", nincr);
182 
183  return 0;
184 }
185 
186 /* *INDENT-OFF* */
188  .path = "test lt2p counters",
189  .short_help = "increment all active counters",
190  .function = test_counters_command_fn,
191 };
192 /* *INDENT-ON* */
193 
194 static clib_error_t *
196  unformat_input_t * input, vlib_cli_command_t * cmd)
197 {
198  l2t_session_t *session;
199  l2t_main_t *lm = &l2t_main;
200  u32 session_index;
202  u32 nincr = 0;
203 
204  /* *INDENT-OFF* */
205  pool_foreach (session, lm->sessions)
206  {
207  session_index = session - lm->sessions;
208  counter_index =
209  session_index_to_counter_index (session_index,
213  nincr++;
214  }
215  /* *INDENT-ON* */
216  vlib_cli_output (vm, "Cleared %d active counters\n", nincr);
217 
218  return 0;
219 }
220 
221 /* *INDENT-OFF* */
223  .path = "clear l2tp counters",
224  .short_help = "clear all active counters",
225  .function = clear_counters_command_fn,
226 };
227 /* *INDENT-ON* */
228 
229 static u8 *
230 format_l2tpv3_name (u8 * s, va_list * args)
231 {
232  l2t_main_t *lm = &l2t_main;
233  u32 i = va_arg (*args, u32);
234  u32 show_dev_instance = ~0;
235 
236  if (i < vec_len (lm->dev_inst_by_real))
237  show_dev_instance = lm->dev_inst_by_real[i];
238 
239  if (show_dev_instance != ~0)
240  i = show_dev_instance;
241 
242  return format (s, "l2tpv3_tunnel%d", i);
243 }
244 
245 static int
247 {
248  l2t_main_t *lm = &l2t_main;
249 
250  vec_validate_init_empty (lm->dev_inst_by_real, hi->dev_instance, ~0);
251 
252  lm->dev_inst_by_real[hi->dev_instance] = new_dev_instance;
253 
254  return 0;
255 }
256 
257 /* *INDENT-OFF* */
258 VNET_DEVICE_CLASS (l2tpv3_device_class,static) = {
259  .name = "L2TPv3",
260  .format_device_name = format_l2tpv3_name,
261  .name_renumber = l2tpv3_name_renumber,
262 };
263 /* *INDENT-ON* */
264 
265 static u8 *
266 format_l2tp_header_with_length (u8 * s, va_list * args)
267 {
268  u32 dev_instance = va_arg (*args, u32);
269  s = format (s, "unimplemented dev %u", dev_instance);
270  return s;
271 }
272 
273 /* *INDENT-OFF* */
274 VNET_HW_INTERFACE_CLASS (l2tpv3_hw_class) = {
275  .name = "L2TPV3",
276  .format_header = format_l2tp_header_with_length,
277  .build_rewrite = default_build_rewrite,
279 };
280 /* *INDENT-ON* */
281 
282 int
284  ip6_address_t * client_address,
285  ip6_address_t * our_address,
286  u32 local_session_id,
287  u32 remote_session_id,
288  u64 local_cookie,
289  u64 remote_cookie,
290  int l2_sublayer_present,
291  u32 encap_fib_index, u32 * sw_if_index)
292 {
293  l2t_session_t *s = 0;
294  vnet_main_t *vnm = lm->vnet_main;
296  uword *p = (uword *) ~ 0;
297  u32 hw_if_index;
298  l2tpv3_header_t l2tp_hdr;
299  ip6_address_t *dst_address_copy, *src_address_copy;
301 
302  remote_session_id = clib_host_to_net_u32 (remote_session_id);
303  local_session_id = clib_host_to_net_u32 (local_session_id);
304 
305  switch (lm->lookup_type)
306  {
308  p = hash_get_mem (lm->session_by_src_address, client_address);
309  break;
310 
312  p = hash_get_mem (lm->session_by_dst_address, our_address);
313  break;
314 
316  p = hash_get (lm->session_by_session_id, local_session_id);
317  break;
318 
319  default:
320  ASSERT (0);
321  }
322 
323  /* adding a session: session must not already exist */
324  if (p)
325  return VNET_API_ERROR_INVALID_VALUE;
326 
327  pool_get (lm->sessions, s);
328  clib_memset (s, 0, sizeof (*s));
329  clib_memcpy (&s->our_address, our_address, sizeof (s->our_address));
330  clib_memcpy (&s->client_address, client_address,
331  sizeof (s->client_address));
332  s->local_cookie[0] = clib_host_to_net_u64 (local_cookie);
333  s->remote_cookie = clib_host_to_net_u64 (remote_cookie);
334  s->local_session_id = local_session_id;
335  s->remote_session_id = remote_session_id;
336  s->l2_sublayer_present = l2_sublayer_present;
337  /* precompute l2tp header size */
338  s->l2tp_hdr_size = l2_sublayer_present ?
339  sizeof (l2tpv3_header_t) :
340  sizeof (l2tpv3_header_t) - sizeof (l2tp_hdr.l2_specific_sublayer);
341  s->admin_up = 0;
342  s->encap_fib_index = encap_fib_index;
343 
344  /* Setup hash table entries */
345  switch (lm->lookup_type)
346  {
348  src_address_copy = clib_mem_alloc (sizeof (*src_address_copy));
349  clib_memcpy (src_address_copy, client_address,
350  sizeof (*src_address_copy));
351  hash_set_mem (lm->session_by_src_address, src_address_copy,
352  s - lm->sessions);
353  break;
355  dst_address_copy = clib_mem_alloc (sizeof (*dst_address_copy));
356  clib_memcpy (dst_address_copy, our_address, sizeof (*dst_address_copy));
357  hash_set_mem (lm->session_by_dst_address, dst_address_copy,
358  s - lm->sessions);
359  break;
361  hash_set (lm->session_by_session_id, local_session_id,
362  s - lm->sessions);
363  break;
364 
365  default:
366  ASSERT (0);
367  }
368 
369  /* validate counters */
370  counter_index =
375 
377  {
378  hw_if_index = lm->free_l2tpv3_tunnel_hw_if_indices
380  _vec_len (lm->free_l2tpv3_tunnel_hw_if_indices) -= 1;
381 
382  hi = vnet_get_hw_interface (vnm, hw_if_index);
383  hi->dev_instance = s - lm->sessions;
384  hi->hw_instance = hi->dev_instance;
385  }
386  else
387  {
388  hw_if_index = vnet_register_interface
389  (vnm, l2tpv3_device_class.index, s - lm->sessions,
390  l2tpv3_hw_class.index, s - lm->sessions);
391  hi = vnet_get_hw_interface (vnm, hw_if_index);
392  hi->output_node_index = l2t_encap_node.index;
393  /* $$$$ initialize custom dispositions, if needed */
394  }
395 
396  s->hw_if_index = hw_if_index;
397  s->sw_if_index = hi->sw_if_index;
398 
399  if (sw_if_index)
400  *sw_if_index = hi->sw_if_index;
401 
402  if (!lm->proto_registered)
403  {
404  ip6_register_protocol (IP_PROTOCOL_L2TP, l2t_decap_local_node.index);
405  lm->proto_registered = true;
406  }
407 
408  return 0;
409 }
410 
411 static clib_error_t *
413  unformat_input_t * input,
414  vlib_cli_command_t * cmd)
415 {
416  ip6_address_t client_address, our_address;
417  unformat_input_t _line_input, *line_input = &_line_input;
418  l2t_main_t *lm = &l2t_main;
419  u64 local_cookie = (u64) ~ 0, remote_cookie = (u64) ~ 0;
420  u32 local_session_id = 1, remote_session_id = 1;
421  int our_address_set = 0, client_address_set = 0;
422  int l2_sublayer_present = 0;
423  int rv;
425  u32 encap_fib_id = ~0;
426  u32 encap_fib_index = ~0;
427  clib_error_t *error = NULL;
428 
429  /* Get a line of input. */
430  if (!unformat_user (input, unformat_line_input, line_input))
431  return 0;
432 
433  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
434  {
435  if (unformat (line_input, "client %U",
436  unformat_ip6_address, &client_address))
437  client_address_set = 1;
438  else if (unformat (line_input, "our %U",
439  unformat_ip6_address, &our_address))
440  our_address_set = 1;
441  else if (unformat (line_input, "local-cookie %llx", &local_cookie))
442  ;
443  else if (unformat (line_input, "remote-cookie %llx", &remote_cookie))
444  ;
445  else if (unformat (line_input, "local-session-id %d",
446  &local_session_id))
447  ;
448  else if (unformat (line_input, "remote-session-id %d",
449  &remote_session_id))
450  ;
451  else if (unformat (line_input, "fib-id %d", &encap_fib_id))
452  ;
453  else if (unformat (line_input, "l2-sublayer-present"))
454  l2_sublayer_present = 1;
455  else
456  {
457  error = clib_error_return (0, "parse error: '%U'",
458  format_unformat_error, line_input);
459  goto done;
460  }
461  }
462 
463  if (encap_fib_id != ~0)
464  {
465  uword *p;
466  ip6_main_t *im = &ip6_main;
467  if (!(p = hash_get (im->fib_index_by_table_id, encap_fib_id)))
468  {
469  error = clib_error_return (0, "No fib with id %d", encap_fib_id);
470  goto done;
471  }
472  encap_fib_index = p[0];
473  }
474  else
475  {
476  encap_fib_index = ~0;
477  }
478 
479  if (our_address_set == 0)
480  {
481  error = clib_error_return (0, "our address not specified");
482  goto done;
483  }
484  if (client_address_set == 0)
485  {
486  error = clib_error_return (0, "client address not specified");
487  goto done;
488  }
489 
490  rv = create_l2tpv3_ipv6_tunnel (lm, &client_address, &our_address,
491  local_session_id, remote_session_id,
492  local_cookie, remote_cookie,
493  l2_sublayer_present,
494  encap_fib_index, &sw_if_index);
495  switch (rv)
496  {
497  case 0:
500  break;
501  case VNET_API_ERROR_INVALID_VALUE:
502  error = clib_error_return (0, "session already exists...");
503  goto done;
504 
505  case VNET_API_ERROR_NO_SUCH_ENTRY:
506  error = clib_error_return (0, "session does not exist...");
507  goto done;
508 
509  default:
510  error = clib_error_return (0, "l2tp_session_add_del returned %d", rv);
511  goto done;
512  }
513 
514 done:
515  unformat_free (line_input);
516 
517  return error;
518 }
519 
520 /* *INDENT-OFF* */
522 {
523  .path = "create l2tpv3 tunnel",
524  .short_help =
525  "create l2tpv3 tunnel client <ip6> our <ip6> local-cookie <hex> remote-cookie <hex> local-session <dec> remote-session <dec>",
527 };
528 /* *INDENT-ON* */
529 
530 int
533  u64 new_local_cookie, u64 new_remote_cookie)
534 {
535  l2t_session_t *s;
537  vnet_main_t *vnm = vnet_get_main ();
539 
540  if (pool_is_free_index (lm->sessions, hi->dev_instance))
541  return VNET_API_ERROR_INVALID_VALUE;
542 
543  s = pool_elt_at_index (lm->sessions, hi->dev_instance);
544 
545  s->local_cookie[1] = s->local_cookie[0];
546  s->local_cookie[0] = clib_host_to_net_u64 (new_local_cookie);
547  s->remote_cookie = clib_host_to_net_u64 (new_remote_cookie);
548 
549  return 0;
550 }
551 
552 
553 static clib_error_t *
555  unformat_input_t * input,
556  vlib_cli_command_t * cmd)
557 {
558  l2t_main_t *lm = &l2t_main;
559  vnet_main_t *vnm = vnet_get_main ();
560  u32 sw_if_index = ~0;
561  u64 local_cookie = (u64) ~ 0, remote_cookie = (u64) ~ 0;
562 
563  int rv;
564 
566  {
567  if (unformat (input, "%U", unformat_vnet_sw_interface, vnm,
568  &sw_if_index))
569  ;
570  else if (unformat (input, "local %llx", &local_cookie))
571  ;
572  else if (unformat (input, "remote %llx", &remote_cookie))
573  ;
574  else
575  break;
576  }
577  if (sw_if_index == ~0)
578  return clib_error_return (0, "unknown interface");
579  if (local_cookie == ~0)
580  return clib_error_return (0, "local cookie required");
581  if (remote_cookie == ~0)
582  return clib_error_return (0, "remote cookie required");
583 
585  local_cookie, remote_cookie);
586 
587  switch (rv)
588  {
589  case 0:
590  break;
591 
592  case VNET_API_ERROR_INVALID_SW_IF_INDEX:
593  return clib_error_return (0, "invalid interface");
594 
595  default:
596  return clib_error_return (0, "l2tp_session_set_cookies returned %d",
597  rv);
598  }
599 
600  return 0;
601 }
602 
603 /* *INDENT-OFF* */
605 {
606  .path = "set l2tpv3 tunnel cookie",
607  .short_help =
608  "set l2tpv3 tunnel cookie <intfc> local <hex> remote <hex>",
610 };
611 /* *INDENT-ON* */
612 
613 int
615  u32 sw_if_index, int enable_disable)
616 {
617 
619  return VNET_API_ERROR_INVALID_SW_IF_INDEX;
620 
621  vnet_feature_enable_disable ("ip6-unicast", "l2tp-decap", sw_if_index,
622  enable_disable, 0, 0);
623  return 0;
624 }
625 
626 /* Enable/disable L2TPv3 intercept on IP6 forwarding path */
627 static clib_error_t *
629  unformat_input_t * input, vlib_cli_command_t * cmd)
630 {
631  u32 sw_if_index = ~0;
632  int is_add = 1;
633  int rv;
634  vnet_main_t *vnm = vnet_get_main ();
635 
637  {
638  if (unformat (input, "%U", unformat_vnet_sw_interface, vnm,
639  &sw_if_index))
640  ;
641  else if (unformat (input, "del"))
642  is_add = 0;
643  else
644  break;
645  }
646 
647  if (sw_if_index == ~0)
648  return clib_error_return (0, "interface required");
649 
651 
652  switch (rv)
653  {
654  case 0:
655  break;
656 
657  case VNET_API_ERROR_INVALID_SW_IF_INDEX:
658  return clib_error_return (0, "invalid interface");
659 
660  default:
661  return clib_error_return (0,
662  "l2tp_interface_enable_disable returned %d",
663  rv);
664  }
665  return 0;
666 }
667 
668 /* *INDENT-OFF* */
670 {
671  .path = "set interface ip6 l2tpv3",
672  .function = set_ip6_l2tpv3,
673  .short_help = "set interface ip6 l2tpv3 <intfc> [del]",
674 };
675 /* *INDENT-ON* */
676 
677 static clib_error_t *
679 {
680  l2t_main_t *lm = &l2t_main;
681 
683  {
684  if (unformat (input, "lookup-v6-src"))
686  else if (unformat (input, "lookup-v6-dst"))
688  else if (unformat (input, "lookup-session-id"))
690  else
691  return clib_error_return (0, "unknown input `%U'",
692  format_unformat_error, input);
693  }
694  return 0;
695 }
696 
698 
699 
700 clib_error_t *
702 {
703  l2t_main_t *lm = &l2t_main;
705  if (hi->hw_class_index != l2tpv3_hw_class.index)
706  return 0;
707 
708  u32 session_index = hi->dev_instance;
709  l2t_session_t *s = pool_elt_at_index (lm->sessions, session_index);
711  return 0;
712 }
713 
715 
716 clib_error_t *
718 {
719  l2t_main_t *lm = &l2t_main;
720  ip_main_t *im = &ip_main;
721  ip_protocol_info_t *pi;
722 
723  lm->vnet_main = vnet_get_main ();
724  lm->vlib_main = vm;
726 
728  (0, sizeof (ip6_address_t) /* key bytes */ ,
729  sizeof (u32) /* value bytes */ );
731  (0, sizeof (ip6_address_t) /* key bytes */ ,
732  sizeof (u32) /* value bytes */ );
733  lm->session_by_session_id = hash_create (0, sizeof (uword));
734 
735  pi = ip_get_protocol_info (im, IP_PROTOCOL_L2TP);
737 
738  lm->proto_registered = false;
739 
740  /* insure these nodes are included in build */
742 
743  return 0;
744 }
745 
747 
748 clib_error_t *
750 {
752 
753  return 0;
754 }
755 
757 
758 /*
759  * fd.io coding-style-patch-verification: ON
760  *
761  * Local Variables:
762  * eval: (c-set-style "gnu")
763  * End:
764  */
im
vnet_interface_main_t * im
Definition: interface_output.c:395
unformat_user
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:989
set_ip6_l2tpv3
static clib_error_t * set_ip6_l2tpv3(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: l2tp.c:628
VNET_HW_INTERFACE_CLASS
VNET_HW_INTERFACE_CLASS(l2tpv3_hw_class)
thread_index
u32 thread_index
Definition: nat44_ei_hairpinning.c:492
l2tp_config
static clib_error_t * l2tp_config(vlib_main_t *vm, unformat_input_t *input)
Definition: l2tp.c:678
l2t_session_t::sw_if_index
u32 sw_if_index
Definition: l2tp.h:39
set_interface_ip6_l2tpv3
static vlib_cli_command_t set_interface_ip6_l2tpv3
(constructor) VLIB_CLI_COMMAND (set_interface_ip6_l2tpv3)
Definition: l2tp.c:669
clib_memcpy
#define clib_memcpy(d, s, n)
Definition: string.h:197
l2t_session_t::l2_sublayer_present
u8 l2_sublayer_present
Definition: l2tp.h:45
l2tpv3_name_renumber
static int l2tpv3_name_renumber(vnet_hw_interface_t *hi, u32 new_dev_instance)
Definition: l2tp.c:246
unformat_line_input
unformat_function_t unformat_line_input
Definition: format.h:275
pool_elt_at_index
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:553
l2t_main_t
Definition: l2tp.h:58
l2t_main_t::sessions
l2t_session_t * sessions
Definition: l2tp.h:61
L2T_LOOKUP_SESSION_ID
@ L2T_LOOKUP_SESSION_ID
Definition: l2tp.h:55
format_l2t_trace
u8 * format_l2t_trace(u8 *s, va_list *args)
Definition: l2tp.c:30
l2t_trace_t::is_user_to_network
int is_user_to_network
Definition: l2tp.h:90
l2tp_init
clib_error_t * l2tp_init(vlib_main_t *vm)
Definition: l2tp.c:717
node
vlib_main_t vlib_node_runtime_t * node
Definition: nat44_ei.c:3047
ip_main
ip_main_t ip_main
Definition: ip_init.c:42
ip_get_protocol_info
static ip_protocol_info_t * ip_get_protocol_info(ip_main_t *im, u32 protocol)
Definition: ip.h:134
clib_error_return
#define clib_error_return(e, args...)
Definition: error.h:99
vlib_cli_command_t::path
char * path
Definition: cli.h:96
create_l2tpv3_ipv6_tunnel
int create_l2tpv3_ipv6_tunnel(l2t_main_t *lm, ip6_address_t *client_address, ip6_address_t *our_address, u32 local_session_id, u32 remote_session_id, u64 local_cookie, u64 remote_cookie, int l2_sublayer_present, u32 encap_fib_index, u32 *sw_if_index)
Definition: l2tp.c:283
l2t_session_t::hw_if_index
u32 hw_if_index
Definition: l2tp.h:38
VNET_SW_INTERFACE_FLAG_ADMIN_UP
@ VNET_SW_INTERFACE_FLAG_ADMIN_UP
Definition: interface.h:843
vlib_validate_combined_counter
void vlib_validate_combined_counter(vlib_combined_counter_main_t *cm, u32 index)
validate a combined counter
Definition: counter.c:119
l2t_session_t::local_session_id
u32 local_session_id
Definition: l2tp.h:34
l2t_main_t::session_by_dst_address
uword * session_by_dst_address
Definition: l2tp.h:65
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
counter_index
static u32 counter_index(vlib_main_t *vm, vlib_error_t e)
Definition: drop.c:67
set_l2tp_tunnel_cookie_command
static vlib_cli_command_t set_l2tp_tunnel_cookie_command
(constructor) VLIB_CLI_COMMAND (set_l2tp_tunnel_cookie_command)
Definition: l2tp.c:604
vnet_get_sw_interface
static vnet_sw_interface_t * vnet_get_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
Definition: interface_funcs.h:58
VLIB_WORKER_INIT_FUNCTION
VLIB_WORKER_INIT_FUNCTION(l2tp_worker_init)
hi
vl_api_ip4_address_t hi
Definition: arp.api:37
clear_counters_command_fn
static clib_error_t * clear_counters_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: l2tp.c:195
unformat_input_t
struct _unformat_input_t unformat_input_t
format_l2t_session
u8 * format_l2t_session(u8 *s, va_list *args)
Definition: l2tp.c:48
hash_create
#define hash_create(elts, value_bytes)
Definition: hash.h:695
show_l2tp_command_fn
static clib_error_t * show_l2tp_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: l2tp.c:93
ethernet.h
session_index_to_counter_index
static u32 session_index_to_counter_index(u32 session_index, u32 counter_id)
Definition: l2tp.h:108
error
Definition: cJSON.c:88
l2t_session_t::admin_up
u8 admin_up
Definition: l2tp.h:48
VLIB_CONFIG_FUNCTION
#define VLIB_CONFIG_FUNCTION(x, n,...)
Definition: init.h:181
unformat
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
pool_is_free_index
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
Definition: pool.h:302
hash_set
#define hash_set(h, key, value)
Definition: hash.h:255
pool_foreach
#define pool_foreach(VAR, POOL)
Iterate through pool.
Definition: pool.h:534
vec_len
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
Definition: vec_bootstrap.h:142
unformat_free
static void unformat_free(unformat_input_t *i)
Definition: format.h:155
error.h
l2t_main_t::vlib_main
vlib_main_t * vlib_main
Definition: l2tp.h:80
l2t_main_t::vnet_main
vnet_main_t * vnet_main
Definition: l2tp.h:81
l2t_session_t::l2tp_hdr_size
u8 l2tp_hdr_size
Definition: l2tp.h:44
CLIB_UNUSED
#define CLIB_UNUSED(x)
Definition: clib.h:90
vnet_get_hw_interface
static vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
Definition: interface_funcs.h:44
vnet_get_main
vnet_main_t * vnet_get_main(void)
Definition: pnat_test_stubs.h:56
l2t_main_t::session_by_session_id
uword * session_by_session_id
Definition: l2tp.h:66
vlib_counter_t
Combined counter to hold both packets and byte differences.
Definition: counter_types.h:26
unformat_check_input
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:163
vlib_config_function_runtime_t
Definition: init.h:68
l2t_main_t::lookup_type
ip6_to_l2_lookup_t lookup_type
Definition: l2tp.h:68
uword
u64 uword
Definition: types.h:112
vlib_zero_combined_counter
static void vlib_zero_combined_counter(vlib_combined_counter_main_t *cm, u32 index)
Clear a combined counter Clears the set of per-thread counters.
Definition: counter.h:298
hash_create_mem
#define hash_create_mem(elts, key_bytes, value_bytes)
Definition: hash.h:660
hash_get
#define hash_get(h, key)
Definition: hash.h:249
l2t_main_t::free_l2tpv3_tunnel_hw_if_indices
u32 * free_l2tpv3_tunnel_hw_if_indices
Definition: l2tp.h:74
hash_set_mem
#define hash_set_mem(h, key, value)
Definition: hash.h:275
vlib_main_t::thread_index
u32 thread_index
Definition: main.h:213
l2t_trace_t::client_address
ip6_address_t client_address
Definition: l2tp.h:93
l2tp_worker_init
clib_error_t * l2tp_worker_init(vlib_main_t *vm)
Definition: l2tp.c:749
i
sll srl srl sll sra u16x4 i
Definition: vector_sse42.h:261
clear_counters_command
static vlib_cli_command_t clear_counters_command
(constructor) VLIB_CLI_COMMAND (clear_counters_command)
Definition: l2tp.c:222
format_unformat_error
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
pool_get
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:255
l2tp_sw_interface_up_down
clib_error_t * l2tp_sw_interface_up_down(vnet_main_t *vnm, u32 sw_if_index, u32 flags)
Definition: l2tp.c:701
l2t_session_t::client_address
ip6_address_t client_address
Definition: l2tp.h:29
test_counters_command_fn
static clib_error_t * test_counters_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: l2tp.c:152
VLIB_CLI_COMMAND
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:163
set_l2tp_tunnel_cookie_command_fn
static clib_error_t * set_l2tp_tunnel_cookie_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: l2tp.c:554
vlib_counter_t::packets
counter_t packets
packet counter
Definition: counter_types.h:28
l2tpv3_interface_enable_disable
int l2tpv3_interface_enable_disable(vnet_main_t *vnm, u32 sw_if_index, int enable_disable)
Definition: l2tp.c:614
vlib_cli_output
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:716
vnet_interface_main_t::sw_interfaces
vnet_sw_interface_t * sw_interfaces
Definition: interface.h:1014
format_l2tpv3_name
static u8 * format_l2tpv3_name(u8 *s, va_list *args)
Definition: l2tp.c:230
l2_input.h
ip6_main
ip6_main_t ip6_main
Definition: ip6_forward.c:2787
create_l2tpv3_tunnel_command
static vlib_cli_command_t create_l2tpv3_tunnel_command
(constructor) VLIB_CLI_COMMAND (create_l2tpv3_tunnel_command)
Definition: l2tp.c:521
vlib_get_combined_counter
static void vlib_get_combined_counter(const vlib_combined_counter_main_t *cm, u32 index, vlib_counter_t *result)
Get the value of a combined counter, never called in the speed path Scrapes the entire set of per-thr...
Definition: counter.h:272
l2t_main_t::session_by_src_address
uword * session_by_src_address
Definition: l2tp.h:64
vnet_hw_interface_t
Definition: interface.h:638
vnet_main_t
Definition: vnet.h:76
l2t_session_t::remote_cookie
u64 remote_cookie
Definition: l2tp.h:33
l2t_encap_node
vlib_node_registration_t l2t_encap_node
(constructor) VLIB_REGISTER_NODE (l2t_encap_node)
Definition: encap.c:196
hash_get_mem
#define hash_get_mem(h, key)
Definition: hash.h:269
u64
unsigned long u64
Definition: types.h:89
format_vnet_sw_if_index_name
format_function_t format_vnet_sw_if_index_name
Definition: interface_funcs.h:455
l2t_session_t::local_cookie
u64 local_cookie[2]
Definition: l2tp.h:32
unformat_vnet_sw_interface
unformat_function_t unformat_vnet_sw_interface
Definition: interface_funcs.h:459
l2t_main_t::proto_registered
bool proto_registered
Definition: l2tp.h:83
format
description fragment has unexpected format
Definition: map.api:433
ASSERT
#define ASSERT(truth)
Definition: error_bootstrap.h:69
vec_validate_init_empty
#define vec_validate_init_empty(V, I, INIT)
Make sure vector is long enough for given index and initialize empty space (no header,...
Definition: vec.h:570
ip.h
L2T_LOOKUP_DST_ADDRESS
@ L2T_LOOKUP_DST_ADDRESS
Definition: l2tp.h:54
u32
unsigned int u32
Definition: types.h:88
VLIB_INIT_FUNCTION
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:172
vnet_get_sup_hw_interface
static vnet_hw_interface_t * vnet_get_sup_hw_interface(vnet_main_t *vnm, u32 sw_if_index)
Definition: interface_funcs.h:92
l2t_trace_t::our_address
ip6_address_t our_address
Definition: l2tp.h:92
SESSION_COUNTER_USER_TO_NETWORK
@ SESSION_COUNTER_USER_TO_NETWORK
Definition: l2tp.h:103
ip_protocol_info_t
Definition: ip.h:70
vlib_counter_t::bytes
counter_t bytes
byte counter
Definition: counter_types.h:29
pool_elts
static uword pool_elts(void *v)
Number of active elements in a pool.
Definition: pool.h:127
L2T_LOOKUP_SRC_ADDRESS
@ L2T_LOOKUP_SRC_ADDRESS
Definition: l2tp.h:53
VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION
VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION(l2tp_sw_interface_up_down)
ip6_main_t
Definition: ip6.h:110
vnet_feature_enable_disable
int vnet_feature_enable_disable(const char *arc_name, const char *node_name, u32 sw_if_index, int enable_disable, void *feature_config, u32 n_feature_config_bytes)
Definition: pnat_test_stubs.h:50
l2t_main
l2t_main_t l2t_main
Definition: l2tp.c:26
clib_memset
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
vlib_main_t
Definition: main.h:102
vlib_node_t
Definition: node.h:247
hash.h
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
VNET_DEVICE_CLASS
VNET_DEVICE_CLASS(l2tpv3_device_class, static)
format_l2tp_header_with_length
static u8 * format_l2tp_header_with_length(u8 *s, va_list *args)
Definition: l2tp.c:266
vlib_init_function_t
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
Definition: init.h:51
format_ip6_address
format_function_t format_ip6_address
Definition: format.h:91
l2tp_encap_init
void l2tp_encap_init(vlib_main_t *vm)
Definition: encap.c:218
default_build_rewrite
u8 * default_build_rewrite(vnet_main_t *vnm, u32 sw_if_index, vnet_link_t link_type, const void *dst_address)
Return a complete, zero-length (aka placeholder) rewrite.
Definition: interface.c:1705
l2t_main_t::dev_inst_by_real
u32 * dev_inst_by_real
Definition: l2tp.h:77
l2t_session_t
Definition: l2tp.h:25
VNET_HW_INTERFACE_CLASS_FLAG_P2P
@ VNET_HW_INTERFACE_CLASS_FLAG_P2P
a point 2 point interface
Definition: interface.h:394
l2t_trace_t
Definition: l2tp.h:88
ip6_register_protocol
void ip6_register_protocol(u32 protocol, u32 node_index)
Definition: ip6_forward.c:1679
l2t_decap_local_node
vlib_node_registration_t l2t_decap_local_node
(constructor) VLIB_REGISTER_NODE (l2t_decap_local_node)
Definition: decap.c:275
l2t_main_t::counter_main
vlib_combined_counter_main_t counter_main
Definition: l2tp.h:71
l2tp.h
unformat_ip6_address
unformat_function_t unformat_ip6_address
Definition: format.h:89
rv
int __clib_unused rv
Definition: application.c:491
ip_main_t
Definition: ip.h:107
unformat_pg_l2tp_header
uword unformat_pg_l2tp_header(unformat_input_t *input, va_list *args)
Definition: pg.c:41
vnet.h
vlib_cli_command_t
Definition: cli.h:92
sw_if_index
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
l2t_trace_t::session_index
u32 session_index
Definition: l2tp.h:91
l2tpv3_set_tunnel_cookies
int l2tpv3_set_tunnel_cookies(l2t_main_t *lm, u32 sw_if_index, u64 new_local_cookie, u64 new_remote_cookie)
Definition: l2tp.c:531
test_counters_command
static vlib_cli_command_t test_counters_command
(constructor) VLIB_CLI_COMMAND (test_counters_command)
Definition: l2tp.c:187
ip_protocol_info_t::unformat_pg_edit
unformat_function_t * unformat_pg_edit
Definition: ip.h:88
show_session_detail_command
static vlib_cli_command_t show_session_detail_command
(constructor) VLIB_CLI_COMMAND (show_session_detail_command)
Definition: l2tp.c:144
l2t_session_t::remote_session_id
u32 remote_session_id
Definition: l2tp.h:35
clib_mem_alloc
static void * clib_mem_alloc(uword size)
Definition: mem.h:253
l2t_session_t::encap_fib_index
u32 encap_fib_index
Definition: l2tp.h:42
create_l2tpv3_tunnel_command_fn
static clib_error_t * create_l2tpv3_tunnel_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: l2tp.c:412
vnet_register_interface
u32 vnet_register_interface(vnet_main_t *vnm, u32 dev_class_index, u32 dev_instance, u32 hw_class_index, u32 hw_instance)
Definition: interface.c:812
vnet_main_t::interface_main
vnet_interface_main_t interface_main
Definition: vnet.h:81
vlib_increment_combined_counter
vlib_increment_combined_counter(ccm, ti, sw_if_index, n_buffers, n_bytes)
l2t_session_t::our_address
ip6_address_t our_address
Definition: l2tp.h:28
UNFORMAT_END_OF_INPUT
#define UNFORMAT_END_OF_INPUT
Definition: format.h:137
format_vnet_sw_interface_name
format_function_t format_vnet_sw_interface_name
Definition: interface_funcs.h:453
flags
vl_api_wireguard_peer_flags_t flags
Definition: wireguard.api:105