FD.io VPP  v16.09
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 <vnet/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 
75  counter_index =
78 
79  vlib_get_combined_counter (&lm->counter_main, counter_index, &v);
80  if (v.packets != 0)
81  s = format (s, " user-to-net: %llu pkts %llu bytes\n",
82  v.packets, v.bytes);
83 
84  vlib_get_combined_counter (&lm->counter_main, counter_index + 1, &v);
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* */
144 VLIB_CLI_COMMAND (show_session_detail_command, static) = {
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;
160  u32 cpu_index = os_get_cpu_number ();
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,
168  SESSION_COUNTER_USER_TO_NETWORK);
169  vlib_increment_combined_counter (&lm->counter_main,
170  cpu_index,
171  counter_index,
172  1/*pkt*/, 1111 /*bytes*/);
173  vlib_increment_combined_counter (&lm->counter_main,
174  cpu_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* */
187 VLIB_CLI_COMMAND (test_counters_command, static) = {
188  .path = "test 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,
210  SESSION_COUNTER_USER_TO_NETWORK);
211  vlib_zero_combined_counter (&lm->counter_main, counter_index);
212  vlib_zero_combined_counter (&lm->counter_main, counter_index+1);
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* */
222 VLIB_CLI_COMMAND (clear_counters_command, static) = {
223  .path = "clear 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 
251 
252  lm->dev_inst_by_real[hi->dev_instance] = new_dev_instance;
253 
254  return 0;
255 }
256 
257 static uword
259  vlib_node_runtime_t * node, vlib_frame_t * frame)
260 {
261  clib_warning ("you shouldn't be here, leaking buffers...");
262  return frame->n_vectors;
263 }
264 
265 /* *INDENT-OFF* */
266 VNET_DEVICE_CLASS (l2tpv3_device_class,static) = {
267  .name = "L2TPv3",
268  .format_device_name = format_l2tpv3_name,
269  .name_renumber = l2tpv3_name_renumber,
270  .tx_function = dummy_interface_tx,
271 };
272 /* *INDENT-ON* */
273 
274 static uword
276  u32 sw_if_index,
277  u32 l3_type,
278  void *dst_address, void *rewrite, uword max_rewrite_bytes)
279 {
280  /*
281  * Conundrum: packets from tun/tap destined for the tunnel
282  * actually have this rewrite applied. Transit packets do not.
283  * To make the two cases equivalent, don't generate a
284  * rewrite here, build the entire header in the fast path.
285  */
286  return 0;
287 }
288 
289 static u8 *
290 format_l2tp_header_with_length (u8 * s, va_list * args)
291 {
292  u32 dev_instance = va_arg (*args, u32);
293  s = format (s, "unimplemented dev %u", dev_instance);
294  return s;
295 }
296 
297 /* *INDENT-OFF* */
298 VNET_HW_INTERFACE_CLASS (l2tpv3_hw_class) = {
299  .name = "L2TPV3",
300  .format_header = format_l2tp_header_with_length,
301  .set_rewrite = dummy_set_rewrite,
302 };
303 /* *INDENT-ON* */
304 
305 int
307  ip6_address_t * client_address,
308  ip6_address_t * our_address,
309  u32 local_session_id,
310  u32 remote_session_id,
311  u64 local_cookie,
312  u64 remote_cookie,
313  int l2_sublayer_present,
314  u32 encap_fib_index, u32 * sw_if_index)
315 {
316  l2t_session_t *s = 0;
317  vnet_main_t *vnm = lm->vnet_main;
319  uword *p = (uword *) ~ 0;
320  u32 hw_if_index;
321  l2tpv3_header_t l2tp_hdr;
322  ip6_address_t *dst_address_copy, *src_address_copy;
324 
325  remote_session_id = clib_host_to_net_u32 (remote_session_id);
326  local_session_id = clib_host_to_net_u32 (local_session_id);
327 
328  switch (lm->lookup_type)
329  {
331  p = hash_get_mem (lm->session_by_src_address, client_address);
332  break;
333 
335  p = hash_get_mem (lm->session_by_dst_address, our_address);
336  break;
337 
339  p = hash_get (lm->session_by_session_id, local_session_id);
340  break;
341 
342  default:
343  ASSERT (0);
344  }
345 
346  /* adding a session: session must not already exist */
347  if (p)
348  return VNET_API_ERROR_INVALID_VALUE;
349 
350  pool_get (lm->sessions, s);
351  memset (s, 0, sizeof (*s));
352  clib_memcpy (&s->our_address, our_address, sizeof (s->our_address));
353  clib_memcpy (&s->client_address, client_address,
354  sizeof (s->client_address));
355  s->local_cookie[0] = clib_host_to_net_u64 (local_cookie);
356  s->remote_cookie = clib_host_to_net_u64 (remote_cookie);
357  s->local_session_id = local_session_id;
358  s->remote_session_id = remote_session_id;
359  s->l2_sublayer_present = l2_sublayer_present;
360  /* precompute l2tp header size */
361  s->l2tp_hdr_size = l2_sublayer_present ?
362  sizeof (l2tpv3_header_t) :
363  sizeof (l2tpv3_header_t) - sizeof (l2tp_hdr.l2_specific_sublayer);
364  s->admin_up = 0;
365  s->encap_fib_index = encap_fib_index;
366 
367  /* Setup hash table entries */
368  switch (lm->lookup_type)
369  {
371  src_address_copy = clib_mem_alloc (sizeof (*src_address_copy));
372  clib_memcpy (src_address_copy, client_address,
373  sizeof (*src_address_copy));
374  hash_set_mem (lm->session_by_src_address, src_address_copy,
375  s - lm->sessions);
376  break;
378  dst_address_copy = clib_mem_alloc (sizeof (*dst_address_copy));
379  clib_memcpy (dst_address_copy, our_address, sizeof (*dst_address_copy));
380  hash_set_mem (lm->session_by_dst_address, dst_address_copy,
381  s - lm->sessions);
382  break;
384  hash_set (lm->session_by_session_id, local_session_id,
385  s - lm->sessions);
386  break;
387 
388  default:
389  ASSERT (0);
390  }
391 
392  /* validate counters */
393  counter_index =
396  vlib_validate_combined_counter (&lm->counter_main, counter_index);
397  vlib_validate_combined_counter (&lm->counter_main, counter_index + 1);
398 
400  {
401  hw_if_index = lm->free_l2tpv3_tunnel_hw_if_indices
403  _vec_len (lm->free_l2tpv3_tunnel_hw_if_indices) -= 1;
404 
405  hi = vnet_get_hw_interface (vnm, hw_if_index);
406  hi->dev_instance = s - lm->sessions;
407  hi->hw_instance = hi->dev_instance;
408  }
409  else
410  {
411  hw_if_index = vnet_register_interface
412  (vnm, l2tpv3_device_class.index, s - lm->sessions,
413  l2tpv3_hw_class.index, s - lm->sessions);
414  hi = vnet_get_hw_interface (vnm, hw_if_index);
415  hi->output_node_index = l2t_encap_node.index;
416  /* $$$$ initialize custom dispositions, if needed */
417  }
418 
419  s->hw_if_index = hw_if_index;
420  s->sw_if_index = hi->sw_if_index;
421 
422  if (sw_if_index)
423  *sw_if_index = hi->sw_if_index;
424 
425  return 0;
426 }
427 
428 static clib_error_t *
430  unformat_input_t * input,
431  vlib_cli_command_t * cmd)
432 {
433  ip6_address_t client_address, our_address;
434  unformat_input_t _line_input, *line_input = &_line_input;
435  l2t_main_t *lm = &l2t_main;
436  u64 local_cookie = (u64) ~ 0, remote_cookie = (u64) ~ 0;
437  u32 local_session_id = 1, remote_session_id = 1;
438  int our_address_set = 0, client_address_set = 0;
439  int l2_sublayer_present = 0;
440  int rv;
441  u32 sw_if_index;
442  u32 encap_fib_id = ~0;
443  u32 encap_fib_index = ~0;
444 
445  /* Get a line of input. */
446  if (!unformat_user (input, unformat_line_input, line_input))
447  return 0;
448 
449  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
450  {
451  if (unformat (line_input, "client %U",
452  unformat_ip6_address, &client_address))
453  client_address_set = 1;
454  else if (unformat (line_input, "our %U",
455  unformat_ip6_address, &our_address))
456  our_address_set = 1;
457  else if (unformat (line_input, "local-cookie %llx", &local_cookie))
458  ;
459  else if (unformat (line_input, "remote-cookie %llx", &remote_cookie))
460  ;
461  else if (unformat (line_input, "local-session-id %d",
462  &local_session_id))
463  ;
464  else if (unformat (line_input, "remote-session-id %d",
465  &remote_session_id))
466  ;
467  else if (unformat (line_input, "fib-id %d", &encap_fib_id))
468  ;
469  else if (unformat (line_input, "l2-sublayer-present"))
470  l2_sublayer_present = 1;
471  else
472  return clib_error_return (0, "parse error: '%U'",
473  format_unformat_error, line_input);
474  }
475 
476  unformat_free (line_input);
477 
478  if (encap_fib_id != ~0)
479  {
480  uword *p;
481  ip6_main_t *im = &ip6_main;
482  if (!(p = hash_get (im->fib_index_by_table_id, encap_fib_id)))
483  return clib_error_return (0, "No fib with id %d", encap_fib_id);
484  encap_fib_index = p[0];
485  }
486  else
487  {
488  encap_fib_index = ~0;
489  }
490 
491  if (our_address_set == 0)
492  return clib_error_return (0, "our address not specified");
493  if (client_address_set == 0)
494  return clib_error_return (0, "client address not specified");
495 
496  rv = create_l2tpv3_ipv6_tunnel (lm, &client_address, &our_address,
497  local_session_id, remote_session_id,
498  local_cookie, remote_cookie,
499  l2_sublayer_present,
500  encap_fib_index, &sw_if_index);
501  switch (rv)
502  {
503  case 0:
505  vnet_get_main (), sw_if_index);
506  break;
507  case VNET_API_ERROR_INVALID_VALUE:
508  return clib_error_return (0, "session already exists...");
509 
510  case VNET_API_ERROR_NO_SUCH_ENTRY:
511  return clib_error_return (0, "session does not exist...");
512 
513  default:
514  return clib_error_return (0, "l2tp_session_add_del returned %d", rv);
515  }
516 
517  return 0;
518 }
519 
520 /* *INDENT-OFF* */
521 VLIB_CLI_COMMAND (create_l2tpv3_tunnel_command, static) =
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
532  u32 sw_if_index,
533  u64 new_local_cookie, u64 new_remote_cookie)
534 {
535  l2t_session_t *s;
537  vnet_main_t *vnm = vnet_get_main ();
538  hi = vnet_get_sup_hw_interface (vnm, sw_if_index);
539 
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 
584  rv = l2tpv3_set_tunnel_cookies (lm, sw_if_index,
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* */
604 VLIB_CLI_COMMAND (set_l2tp_tunnel_cookie_command, static) =
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  ip6_main_t *im = &ip6_main;
618  ip_lookup_main_t *lm = &im->lookup_main;
620  u32 ci;
621  ip6_l2tpv3_config_t config;
622  u32 feature_index;
623 
624  if (pool_is_free_index (vnm->interface_main.sw_interfaces, sw_if_index))
625  return VNET_API_ERROR_INVALID_SW_IF_INDEX;
626 
627  feature_index = im->ip6_unicast_rx_feature_l2tp_decap;
628 
629  ci = rx_cm->config_index_by_sw_if_index[sw_if_index];
630  ci = (enable_disable
633  (vlib_get_main (), &rx_cm->config_main,
634  ci, feature_index, &config, sizeof (config));
635  rx_cm->config_index_by_sw_if_index[sw_if_index] = ci;
636  return 0;
637 }
638 
639 /* Enable/disable L2TPv3 intercept on IP6 fowarding path */
640 static clib_error_t *
642  unformat_input_t * input, vlib_cli_command_t * cmd)
643 {
644  u32 sw_if_index = ~0;
645  int is_add = 1;
646  int rv;
647  vnet_main_t *vnm = vnet_get_main ();
648 
650  {
651  if (unformat (input, "%U", unformat_vnet_sw_interface, vnm,
652  &sw_if_index))
653  ;
654  else if (unformat (input, "del"))
655  is_add = 0;
656  else
657  break;
658  }
659 
660  if (sw_if_index == ~0)
661  return clib_error_return (0, "interface required");
662 
663  rv = l2tpv3_interface_enable_disable (vnm, sw_if_index, is_add);
664 
665  switch (rv)
666  {
667  case 0:
668  break;
669 
670  case VNET_API_ERROR_INVALID_SW_IF_INDEX:
671  return clib_error_return (0, "invalid interface");
672 
673  default:
674  return clib_error_return (0,
675  "l2tp_interface_enable_disable returned %d",
676  rv);
677  }
678  return 0;
679 }
680 
681 /* *INDENT-OFF* */
682 VLIB_CLI_COMMAND (set_interface_ip6_l2tpv3, static) =
683 {
684  .path = "set interface ip6 l2tpv3",
685  .function = set_ip6_l2tpv3,
686  .short_help = "set interface ip6 l2tpv3 <intfc> [del]",
687 };
688 /* *INDENT-ON* */
689 
690 static clib_error_t *
692 {
693  l2t_main_t *lm = &l2t_main;
694 
696  {
697  if (unformat (input, "lookup-v6-src"))
699  else if (unformat (input, "lookup-v6-dst"))
701  else if (unformat (input, "lookup-session-id"))
703  else
704  return clib_error_return (0, "unknown input `%U'",
705  format_unformat_error, input);
706  }
707  return 0;
708 }
709 
711 
712 
713 clib_error_t *
715 {
716  l2t_main_t *lm = &l2t_main;
717  vnet_hw_interface_t *hi = vnet_get_sup_hw_interface (vnm, sw_if_index);
718  if (hi->hw_class_index != l2tpv3_hw_class.index)
719  return 0;
720 
721  u32 session_index = hi->dev_instance;
722  l2t_session_t *s = pool_elt_at_index (lm->sessions, session_index);
723  s->admin_up = ! !(flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP);
724  return 0;
725 }
726 
728 
729 clib_error_t *
731 {
732  l2t_main_t *lm = &l2t_main;
733  ip_main_t *im = &ip_main;
734  ip_protocol_info_t *pi;
735 
736  lm->vnet_main = vnet_get_main ();
737  lm->vlib_main = vm;
739 
741  (0, sizeof (ip6_address_t) /* key bytes */ ,
742  sizeof (u32) /* value bytes */ );
744  (0, sizeof (ip6_address_t) /* key bytes */ ,
745  sizeof (u32) /* value bytes */ );
746  lm->session_by_session_id = hash_create (0, sizeof (uword));
747 
748  pi = ip_get_protocol_info (im, IP_PROTOCOL_L2TP);
750 
751  /* insure these nodes are included in build */
752  l2tp_encap_init (vm);
753  l2tp_decap_init ();
754 
755  return 0;
756 }
757 
759 
760 /*
761  * fd.io coding-style-patch-verification: ON
762  *
763  * Local Variables:
764  * eval: (c-set-style "gnu")
765  * End:
766  */
int is_user_to_network
Definition: l2tp.h:88
u64 local_cookie[2]
Definition: l2tp.h:32
vmrglw vmrglh hi
u64 packets
packet counter
Definition: counter.h:166
#define hash_set(h, key, value)
Definition: hash.h:254
ip6_address_t client_address
Definition: l2tp.h:91
sll srl srl sll sra u16x4 i
Definition: vector_sse2.h:343
#define CLIB_UNUSED(x)
Definition: clib.h:79
u32 * config_index_by_sw_if_index
Definition: lookup.h:369
uword unformat(unformat_input_t *i, char *fmt,...)
Definition: unformat.c:966
void vlib_validate_combined_counter(vlib_combined_counter_main_t *cm, u32 index)
validate a combined counter
Definition: counter.c:110
static u8 * format_l2tpv3_name(u8 *s, va_list *args)
Definition: l2tp.c:230
format_function_t format_ip6_address
Definition: format.h:87
static vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:23
static vnet_hw_interface_t * vnet_get_sup_hw_interface(vnet_main_t *vnm, u32 sw_if_index)
vnet_interface_main_t interface_main
Definition: vnet.h:64
uword * session_by_session_id
Definition: l2tp.h:66
#define UNFORMAT_END_OF_INPUT
Definition: format.h:143
ip6_address_t our_address
Definition: l2tp.h:28
vlib_node_registration_t l2t_encap_node
(constructor) VLIB_REGISTER_NODE (l2t_encap_node)
Definition: encap.c:60
u32 vnet_config_del_feature(vlib_main_t *vm, vnet_config_main_t *cm, u32 config_string_heap_index, u32 feature_index, void *feature_config, u32 n_feature_config_bytes)
Definition: config.c:300
ip_config_main_t rx_config_mains[VNET_N_CAST]
rx/tx interface/feature configuration.
Definition: lookup.h:452
static vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
u32 encap_fib_index
Definition: l2tp.h:42
Combined counter to hold both packets and byte differences.
Definition: counter.h:164
#define hash_set_mem(h, key, value)
Definition: hash.h:274
static vnet_sw_interface_t * vnet_get_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
unformat_function_t unformat_vnet_sw_interface
Definition: ip.h:109
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:200
u64 remote_cookie
Definition: l2tp.h:33
static u32 session_index_to_counter_index(u32 session_index, u32 counter_id)
Definition: l2tp.h:106
format_function_t format_vnet_sw_if_index_name
VNET_HW_INTERFACE_CLASS(l2tpv3_hw_class)
ip6_address_t client_address
Definition: l2tp.h:29
static int l2tpv3_name_renumber(vnet_hw_interface_t *hi, u32 new_dev_instance)
Definition: l2tp.c:246
vnet_main_t * vnet_get_main(void)
Definition: misc.c:45
unformat_function_t * unformat_pg_edit
Definition: ip.h:91
l2t_main_t l2t_main
Definition: l2tp.c:26
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:348
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:111
VNET_DEVICE_CLASS(l2tpv3_device_class, static)
static u32 counter_index(vlib_main_t *vm, vlib_error_t e)
static void unformat_free(unformat_input_t *i)
Definition: format.h:161
#define clib_warning(format, args...)
Definition: error.h:59
unsigned long u64
Definition: types.h:89
clib_error_t * l2tp_init(vlib_main_t *vm)
Definition: l2tp.c:730
void l2tp_encap_init(vlib_main_t *vm)
Definition: encap.c:222
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:977
int l2tpv3_interface_enable_disable(vnet_main_t *vnm, u32 sw_if_index, int enable_disable)
Definition: l2tp.c:614
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
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:650
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
u32 hw_if_index
Definition: l2tp.h:38
#define hash_create_mem(elts, key_bytes, value_bytes)
Definition: hash.h:626
#define hash_get(h, key)
Definition: hash.h:248
format_function_t format_vnet_sw_interface_name
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:369
static ip_protocol_info_t * ip_get_protocol_info(ip_main_t *im, u32 protocol)
Definition: ip.h:136
u32 local_session_id
Definition: l2tp.h:34
u8 * format_l2t_trace(u8 *s, va_list *args)
Definition: l2tp.c:30
uword os_get_cpu_number(void)
Definition: unix-misc.c:224
static void vlib_get_combined_counter(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 mini co...
Definition: counter.h:287
#define VLIB_CONFIG_FUNCTION(x, n,...)
Definition: init.h:118
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:575
static uword dummy_set_rewrite(vnet_main_t *vnm, u32 sw_if_index, u32 l3_type, void *dst_address, void *rewrite, uword max_rewrite_bytes)
Definition: l2tp.c:275
ip6_to_l2_lookup_t lookup_type
Definition: l2tp.h:68
unformat_function_t unformat_ip6_address
Definition: format.h:86
uword * fib_index_by_table_id
Definition: ip6.h:127
ip6_address_t our_address
Definition: l2tp.h:90
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:429
u16 n_vectors
Definition: node.h:344
u32 * free_l2tpv3_tunnel_hw_if_indices
Definition: l2tp.h:74
ip_main_t ip_main
Definition: ip_init.c:42
clib_error_t * l2tp_sw_interface_up_down(vnet_main_t *vnm, u32 sw_if_index, u32 flags)
Definition: l2tp.c:714
uword unformat_pg_l2tp_header(unformat_input_t *input, va_list *args)
Definition: pg.c:41
u64 bytes
byte counter
Definition: counter.h:167
#define clib_memcpy(a, b, c)
Definition: string.h:63
u8 * format_l2t_session(u8 *s, va_list *args)
Definition: l2tp.c:48
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
Definition: pool.h:211
#define hash_create(elts, value_bytes)
Definition: hash.h:647
#define VNET_SW_INTERFACE_FLAG_ADMIN_UP
Definition: interface.h:415
#define ASSERT(truth)
vlib_main_t * vlib_main
Definition: l2tp.h:80
u32 remote_session_id
Definition: l2tp.h:35
unsigned int u32
Definition: types.h:88
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
ip6_main_t ip6_main
Definition: ip6_forward.c:2955
ip_lookup_main_t lookup_main
Definition: ip6.h:110
u8 * format(u8 *s, char *fmt,...)
Definition: format.c:418
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:306
static uword dummy_interface_tx(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: l2tp.c:258
vnet_main_t * vnet_main
Definition: l2tp.h:81
u32 vnet_config_add_feature(vlib_main_t *vm, vnet_config_main_t *cm, u32 config_string_heap_index, u32 feature_index, void *feature_config, u32 n_feature_config_bytes)
Definition: config.c:239
u32 ip6_unicast_rx_feature_l2tp_decap
Definition: ip6.h:153
uword * session_by_dst_address
Definition: l2tp.h:65
static void * clib_mem_alloc(uword size)
Definition: mem.h:107
vlib_combined_counter_main_t counter_main
Definition: l2tp.h:71
u64 uword
Definition: types.h:112
void l2tp_decap_init(void)
Definition: decap.c:304
VLIB_CLI_COMMAND(set_interface_ip_source_and_port_range_check_command, static)
u8 l2tp_hdr_size
Definition: l2tp.h:44
static clib_error_t * l2tp_config(vlib_main_t *vm, unformat_input_t *input)
Definition: l2tp.c:691
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
unsigned char u8
Definition: types.h:56
vnet_sw_interface_t * sw_interfaces
Definition: interface.h:492
l2t_session_t * sessions
Definition: l2tp.h:61
#define hash_get_mem(h, key)
Definition: hash.h:268
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
static u8 * format_l2tp_header_with_length(u8 *s, va_list *args)
Definition: l2tp.c:290
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:169
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
u8 admin_up
Definition: l2tp.h:48
VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION(l2tp_sw_interface_up_down)
u32 * dev_inst_by_real
Definition: l2tp.h:77
#define clib_error_return(e, args...)
Definition: error.h:111
struct _unformat_input_t unformat_input_t
uword * session_by_src_address
Definition: l2tp.h:64
u8 l2_sublayer_present
Definition: l2tp.h:45
u32 flags
Definition: vhost-user.h:76
#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:445
u32 sw_if_index
Definition: l2tp.h:39
unformat_function_t unformat_line_input
Definition: format.h:281
vnet_config_main_t config_main
Definition: lookup.h:367
u32 session_index
Definition: l2tp.h:89
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
static clib_error_t * set_ip6_l2tpv3(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: l2tp.c:641
static uword pool_elts(void *v)
Number of active elements in a pool.
Definition: pool.h:109