FD.io VPP  v19.08.3-2-gbabecb413
Vector Packet Processing
pppoe.c
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * Copyright (c) 2017 Intel and/or its affiliates.
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *------------------------------------------------------------------
16  */
17 #include <stdint.h>
18 #include <net/if.h>
19 #include <sys/ioctl.h>
20 #include <inttypes.h>
21 
22 #include <vlib/vlib.h>
23 #include <vlib/unix/unix.h>
24 #include <vnet/ethernet/ethernet.h>
25 #include <vnet/fib/fib_entry.h>
26 #include <vnet/fib/fib_table.h>
28 #include <vnet/plugin/plugin.h>
29 #include <vpp/app/version.h>
30 #include <vnet/ppp/packet.h>
31 #include <pppoe/pppoe.h>
32 #include <vnet/adj/adj_midchain.h>
33 #include <vnet/adj/adj_mcast.h>
34 
35 #include <vppinfra/hash.h>
37 
39 
40 u8 *
41 format_pppoe_session (u8 * s, va_list * args)
42 {
43  pppoe_session_t *t = va_arg (*args, pppoe_session_t *);
44  pppoe_main_t *pem = &pppoe_main;
45 
46  s = format (s, "[%d] sw-if-index %d client-ip %U session-id %d ",
47  t - pem->sessions, t->sw_if_index,
49  t->session_id);
50 
51  s = format (s, "encap-if-index %d decap-fib-index %d\n",
53 
54  s = format (s, " local-mac %U client-mac %U",
57 
58  return s;
59 }
60 
61 static u8 *
62 format_pppoe_name (u8 * s, va_list * args)
63 {
64  u32 dev_instance = va_arg (*args, u32);
65  return format (s, "pppoe_session%d", dev_instance);
66 }
67 
68 static clib_error_t *
70 {
71  u32 hw_flags = (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
73  vnet_hw_interface_set_flags (vnm, hw_if_index, hw_flags);
74 
75  return /* no error */ 0;
76 }
77 
78 /* *INDENT-OFF* */
79 VNET_DEVICE_CLASS (pppoe_device_class,static) = {
80  .name = "PPPoE",
81  .format_device_name = format_pppoe_name,
82  .admin_up_down_function = pppoe_interface_admin_up_down,
83 };
84 /* *INDENT-ON* */
85 
86 static u8 *
87 format_pppoe_header_with_length (u8 * s, va_list * args)
88 {
89  u32 dev_instance = va_arg (*args, u32);
90  s = format (s, "unimplemented dev %u", dev_instance);
91  return s;
92 }
93 
94 static u8 *
97  vnet_link_t link_type, const void *dst_address)
98 {
99  int len = sizeof (pppoe_header_t) + sizeof (ethernet_header_t);
100  pppoe_main_t *pem = &pppoe_main;
101  pppoe_session_t *t;
102  u32 session_id;
103  u8 *rw = 0;
104 
105  session_id = pem->session_index_by_sw_if_index[sw_if_index];
106  t = pool_elt_at_index (pem->sessions, session_id);
107 
109 
110  ethernet_header_t *eth_hdr = (ethernet_header_t *) rw;
111  clib_memcpy (eth_hdr->dst_address, t->client_mac, 6);
112  clib_memcpy (eth_hdr->src_address, t->local_mac, 6);
113  eth_hdr->type = clib_host_to_net_u16 (ETHERNET_TYPE_PPPOE_SESSION);
114 
115  pppoe_header_t *pppoe = (pppoe_header_t *) (eth_hdr + 1);
116  pppoe->ver_type = PPPOE_VER_TYPE;
117  pppoe->code = 0;
118  pppoe->session_id = clib_host_to_net_u16 (t->session_id);
119  pppoe->length = 0; /* To be filled in at run-time */
120 
121  switch (link_type)
122  {
123  case VNET_LINK_IP4:
124  pppoe->ppp_proto = clib_host_to_net_u16 (PPP_PROTOCOL_ip4);
125  break;
126  case VNET_LINK_IP6:
127  pppoe->ppp_proto = clib_host_to_net_u16 (PPP_PROTOCOL_ip6);
128  break;
129  default:
130  break;
131  }
132 
133  return rw;
134 }
135 
136 /**
137  * @brief Fixup the adj rewrite post encap. Insert the packet's length
138  */
139 static void
141  ip_adjacency_t * adj, vlib_buffer_t * b0, const void *data)
142 {
143  const pppoe_session_t *t;
144  pppoe_header_t *pppoe0;
145 
146  /* update the rewrite string */
147  pppoe0 = vlib_buffer_get_current (b0) + sizeof (ethernet_header_t);
148 
149  pppoe0->length = clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b0)
150  - sizeof (pppoe_header_t)
151  + sizeof (pppoe0->ppp_proto)
152  - sizeof (ethernet_header_t));
153  /* Swap to the the packet's output interface to the encap (not the
154  * session) interface */
155  t = data;
156  vnet_buffer (b0)->sw_if_index[VLIB_TX] = t->encap_if_index;
157 }
158 
159 static void
161 {
162  pppoe_main_t *pem = &pppoe_main;
163  dpo_id_t dpo = DPO_INVALID;
164  ip_adjacency_t *adj;
165  pppoe_session_t *t;
166  u32 session_id;
167 
168  ASSERT (ADJ_INDEX_INVALID != ai);
169 
170  adj = adj_get (ai);
171  session_id = pem->session_index_by_sw_if_index[sw_if_index];
172  t = pool_elt_at_index (pem->sessions, session_id);
173 
174  switch (adj->lookup_next_index)
175  {
176  case IP_LOOKUP_NEXT_ARP:
181  pppoe_build_rewrite (vnm,
182  sw_if_index,
183  adj->ia_link,
184  NULL));
185  break;
187  /*
188  * Construct a partial rewrite from the known ethernet mcast dest MAC
189  * There's no MAC fixup, so the last 2 parameters are 0
190  */
193  pppoe_build_rewrite (vnm,
194  sw_if_index,
195  adj->ia_link,
196  NULL), 0, 0);
197  break;
198 
199  case IP_LOOKUP_NEXT_DROP:
200  case IP_LOOKUP_NEXT_PUNT:
206  case IP_LOOKUP_N_NEXT:
207  ASSERT (0);
208  break;
209  }
210 
212  t->encap_if_index, &dpo);
213 
214  adj_nbr_midchain_stack (ai, &dpo);
215 
216  dpo_reset (&dpo);
217 }
218 
219 /* *INDENT-OFF* */
220 VNET_HW_INTERFACE_CLASS (pppoe_hw_class) =
221 {
222  .name = "PPPoE",
223  .format_header = format_pppoe_header_with_length,
224  .build_rewrite = pppoe_build_rewrite,
225  .update_adjacency = pppoe_update_adj,
227 };
228 /* *INDENT-ON* */
229 
230 #define foreach_copy_field \
231 _(session_id) \
232 _(encap_if_index) \
233 _(decap_fib_index) \
234 _(client_ip)
235 
236 static bool
238  u32 decap_fib_index)
239 {
240  vlib_main_t *vm = pem->vlib_main;
241  u32 input_idx = (!is_ip6) ? ip4_input_node.index : ip6_input_node.index;
242  vlib_node_runtime_t *r = vlib_node_get_runtime (vm, input_idx);
243 
244  return decap_fib_index < r->n_next_nodes;
245 }
246 
249 {
250  pppoe_main_t *pem = &pppoe_main;
251  pppoe_session_t *t = 0;
252  vnet_main_t *vnm = pem->vnet_main;
253  u32 hw_if_index = ~0;
254  u32 sw_if_index = ~0;
255  u32 is_ip6 = a->is_ip6;
256  pppoe_entry_key_t cached_key;
257  pppoe_entry_result_t cached_result;
258  u32 bucket;
260  pppoe_entry_result_t result;
263  fib_prefix_t pfx;
264 
265  cached_key.raw = ~0;
266  cached_result.raw = ~0; /* warning be gone */
267  clib_memset (&pfx, 0, sizeof (pfx));
268 
269  if (!is_ip6)
270  {
271  pfx.fp_addr.ip4.as_u32 = a->client_ip.ip4.as_u32;
272  pfx.fp_len = 32;
274  }
275  else
276  {
277  pfx.fp_addr.ip6.as_u64[0] = a->client_ip.ip6.as_u64[0];
278  pfx.fp_addr.ip6.as_u64[1] = a->client_ip.ip6.as_u64[1];
279  pfx.fp_len = 128;
281  }
282 
283  /* Get encap_if_index and local mac address from link_table */
284  pppoe_lookup_1 (&pem->link_table, &cached_key, &cached_result,
285  a->client_mac, 0, &key, &bucket, &result);
286  a->encap_if_index = result.fields.sw_if_index;
287 
288  if (a->encap_if_index == ~0)
289  return VNET_API_ERROR_INVALID_SW_IF_INDEX;
290 
291  si = vnet_get_sw_interface (vnm, a->encap_if_index);
292  hi = vnet_get_hw_interface (vnm, si->hw_if_index);
293 
294  /* lookup session_table */
295  pppoe_lookup_1 (&pem->session_table, &cached_key, &cached_result,
296  a->client_mac, clib_host_to_net_u16 (a->session_id),
297  &key, &bucket, &result);
298 
299  /* learn client session */
300  pppoe_learn_process (&pem->session_table, a->encap_if_index,
301  &key, &cached_key, &bucket, &result);
302 
303  if (a->is_add)
304  {
305  /* adding a session: session must not already exist */
306  if (result.fields.session_index != ~0)
307  return VNET_API_ERROR_TUNNEL_EXIST;
308 
309  /*if not set explicitly, default to ip4 */
310  if (!pppoe_decap_next_is_valid (pem, is_ip6, a->decap_fib_index))
311  return VNET_API_ERROR_INVALID_DECAP_NEXT;
312 
314  clib_memset (t, 0, sizeof (*t));
315 
316  clib_memcpy (t->local_mac, hi->hw_address, 6);
317 
318  /* copy from arg structure */
319 #define _(x) t->x = a->x;
321 #undef _
322 
323  clib_memcpy (t->client_mac, a->client_mac, 6);
324 
325  /* update pppoe fib with session_index */
326  result.fields.session_index = t - pem->sessions;
327  pppoe_update_1 (&pem->session_table,
328  a->client_mac, clib_host_to_net_u16 (a->session_id),
329  &key, &bucket, &result);
330 
333  {
335  hw_if_index = pem->free_pppoe_session_hw_if_indices
337  _vec_len (pem->free_pppoe_session_hw_if_indices) -= 1;
338 
339  hi = vnet_get_hw_interface (vnm, hw_if_index);
340  hi->dev_instance = t - pem->sessions;
341  hi->hw_instance = hi->dev_instance;
342 
343  /* clear old stats of freed session before reuse */
344  sw_if_index = hi->sw_if_index;
348  sw_if_index);
351  sw_if_index);
354  sw_if_index);
356  }
357  else
358  {
359  hw_if_index = vnet_register_interface
360  (vnm, pppoe_device_class.index, t - pem->sessions,
361  pppoe_hw_class.index, t - pem->sessions);
362  hi = vnet_get_hw_interface (vnm, hw_if_index);
363  }
364 
365  t->hw_if_index = hw_if_index;
366  t->sw_if_index = sw_if_index = hi->sw_if_index;
367 
369  ~0);
371 
372  vnet_sw_interface_t *si = vnet_get_sw_interface (vnm, sw_if_index);
374  vnet_sw_interface_set_flags (vnm, sw_if_index,
376 
377  /* add reverse route for client ip */
381  &pfx.fp_addr, sw_if_index, ~0,
382  1, NULL, FIB_ROUTE_PATH_FLAG_NONE);
383 
384  }
385  else
386  {
387  /* deleting a session: session must exist */
388  if (result.fields.session_index == ~0)
389  return VNET_API_ERROR_NO_SUCH_ENTRY;
390 
391  t = pool_elt_at_index (pem->sessions, result.fields.session_index);
392  sw_if_index = t->sw_if_index;
393 
394  vnet_sw_interface_set_flags (vnm, t->sw_if_index, 0 /* down */ );
397 
399 
401 
402  /* update pppoe fib with session_inde=~0x */
403  result.fields.session_index = ~0;
404  pppoe_update_1 (&pem->session_table,
405  a->client_mac, clib_host_to_net_u16 (a->session_id),
406  &key, &bucket, &result);
407 
408 
409  /* delete reverse route for client ip */
413  &pfx.fp_addr,
414  sw_if_index, ~0, 1,
416 
417  pool_put (pem->sessions, t);
418  }
419 
420  if (sw_if_indexp)
421  *sw_if_indexp = sw_if_index;
422 
423  return 0;
424 }
425 
426 static clib_error_t *
428  unformat_input_t * input,
429  vlib_cli_command_t * cmd)
430 {
431  unformat_input_t _line_input, *line_input = &_line_input;
432  u16 session_id = 0;
433  ip46_address_t client_ip;
434  u8 is_add = 1;
435  u8 client_ip_set = 0;
436  u8 ipv4_set = 0;
437  u8 ipv6_set = 0;
438  u32 encap_if_index = 0;
439  u32 decap_fib_index = 0;
440  u8 client_mac[6] = { 0 };
441  u8 client_mac_set = 0;
442  int rv;
443  u32 tmp;
445  u32 session_sw_if_index;
446  clib_error_t *error = NULL;
447 
448  /* Cant "universally zero init" (={0}) due to GCC bug 53119 */
449  clib_memset (&client_ip, 0, sizeof client_ip);
450 
451  /* Get a line of input. */
452  if (!unformat_user (input, unformat_line_input, line_input))
453  return 0;
454 
455  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
456  {
457  if (unformat (line_input, "del"))
458  {
459  is_add = 0;
460  }
461  else if (unformat (line_input, "session-id %d", &session_id))
462  ;
463  else if (unformat (line_input, "client-ip %U",
464  unformat_ip4_address, &client_ip.ip4))
465  {
466  client_ip_set = 1;
467  ipv4_set = 1;
468  }
469  else if (unformat (line_input, "client-ip %U",
470  unformat_ip6_address, &client_ip.ip6))
471  {
472  client_ip_set = 1;
473  ipv6_set = 1;
474  }
475  else if (unformat (line_input, "decap-vrf-id %d", &tmp))
476  {
477  if (ipv6_set)
478  decap_fib_index = fib_table_find (FIB_PROTOCOL_IP6, tmp);
479  else
480  decap_fib_index = fib_table_find (FIB_PROTOCOL_IP4, tmp);
481 
482  if (decap_fib_index == ~0)
483  {
484  error =
485  clib_error_return (0, "nonexistent decap fib id %d", tmp);
486  goto done;
487  }
488  }
489  else
490  if (unformat
491  (line_input, "client-mac %U", unformat_ethernet_address,
492  client_mac))
493  client_mac_set = 1;
494  else
495  {
496  error = clib_error_return (0, "parse error: '%U'",
497  format_unformat_error, line_input);
498  goto done;
499  }
500  }
501 
502  if (client_ip_set == 0)
503  {
504  error =
505  clib_error_return (0, "session client ip address not specified");
506  goto done;
507  }
508 
509  if (ipv4_set && ipv6_set)
510  {
511  error = clib_error_return (0, "both IPv4 and IPv6 addresses specified");
512  goto done;
513  }
514 
515  if (client_mac_set == 0)
516  {
517  error = clib_error_return (0, "session client mac not specified");
518  goto done;
519  }
520 
521  clib_memset (a, 0, sizeof (*a));
522 
523  a->is_add = is_add;
524  a->is_ip6 = ipv6_set;
525 
526 #define _(x) a->x = x;
528 #undef _
529 
530  clib_memcpy (a->client_mac, client_mac, 6);
531 
532  rv = vnet_pppoe_add_del_session (a, &session_sw_if_index);
533 
534  switch (rv)
535  {
536  case 0:
537  if (is_add)
539  vnet_get_main (), session_sw_if_index);
540  break;
541 
542  case VNET_API_ERROR_TUNNEL_EXIST:
543  error = clib_error_return (0, "session already exists...");
544  goto done;
545 
546  case VNET_API_ERROR_NO_SUCH_ENTRY:
547  error = clib_error_return (0, "session does not exist...");
548  goto done;
549 
550  default:
551  error = clib_error_return
552  (0, "vnet_pppoe_add_del_session returned %d", rv);
553  goto done;
554  }
555 
556 done:
557  unformat_free (line_input);
558 
559  return error;
560 }
561 
562 /*?
563  * Add or delete a PPPoE Session.
564  *
565  * @cliexpar
566  * Example of how to create a PPPoE Session:
567  * @cliexcmd{create pppoe session client-ip 10.0.3.1 session-id 13
568  * client-mac 00:01:02:03:04:05 }
569  * Example of how to delete a PPPoE Session:
570  * @cliexcmd{create pppoe session client-ip 10.0.3.1 session-id 13
571  * client-mac 00:01:02:03:04:05 del }
572  ?*/
573 /* *INDENT-OFF* */
574 VLIB_CLI_COMMAND (create_pppoe_session_command, static) = {
575  .path = "create pppoe session",
576  .short_help =
577  "create pppoe session client-ip <client-ip> session-id <nn>"
578  " client-mac <client-mac> [decap-vrf-id <nn>] [del]",
580 };
581 /* *INDENT-ON* */
582 
583 /* *INDENT-OFF* */
584 static clib_error_t *
586  unformat_input_t * input,
587  vlib_cli_command_t * cmd)
588 {
589  pppoe_main_t *pem = &pppoe_main;
590  pppoe_session_t *t;
591 
592  if (pool_elts (pem->sessions) == 0)
593  vlib_cli_output (vm, "No pppoe sessions configured...");
594 
595  pool_foreach (t, pem->sessions,
596  ({
597  vlib_cli_output (vm, "%U",format_pppoe_session, t);
598  }));
599 
600  return 0;
601 }
602 /* *INDENT-ON* */
603 
604 /*?
605  * Display all the PPPoE Session entries.
606  *
607  * @cliexpar
608  * Example of how to display the PPPoE Session entries:
609  * @cliexstart{show pppoe session}
610  * [0] client-ip 10.0.3.1 session_id 13 encap-if-index 0 decap-vrf-id 13 sw_if_index 5
611  * local-mac a0:b0:c0:d0:e0:f0 client-mac 00:01:02:03:04:05
612  * @cliexend
613  ?*/
614 /* *INDENT-OFF* */
615 VLIB_CLI_COMMAND (show_pppoe_session_command, static) = {
616  .path = "show pppoe session",
617  .short_help = "show pppoe session",
618  .function = show_pppoe_session_command_fn,
619 };
620 /* *INDENT-ON* */
621 
623 {
628 
629 static void
630 pppoe_show_walk_cb (BVT (clib_bihash_kv) * kvp, void *arg)
631 {
632  pppoe_show_walk_ctx_t *ctx = arg;
633  pppoe_entry_result_t result;
635 
636  if (ctx->first_entry)
637  {
638  ctx->first_entry = 0;
639  vlib_cli_output (ctx->vm,
640  "%=19s%=12s%=13s%=14s",
641  "Mac-Address", "session_id", "sw_if_index",
642  "session_index");
643  }
644 
645  key.raw = kvp->key;
646  result.raw = kvp->value;
647 
648  vlib_cli_output (ctx->vm,
649  "%=19U%=12d%=13d%=14d",
651  clib_net_to_host_u16 (key.fields.session_id),
652  result.fields.sw_if_index == ~0
653  ? -1 : result.fields.sw_if_index,
654  result.fields.session_index == ~0
655  ? -1 : result.fields.session_index);
656  ctx->total_entries++;
657 }
658 
659 /** Display the contents of the PPPoE Fib. */
660 static clib_error_t *
662  unformat_input_t * input, vlib_cli_command_t * cmd)
663 {
664  pppoe_main_t *pem = &pppoe_main;
666  .first_entry = 1,
667  .vm = vm,
668  };
669 
671  (&pem->session_table, pppoe_show_walk_cb, &ctx);
672 
673  if (ctx.total_entries == 0)
674  vlib_cli_output (vm, "no pppoe fib entries");
675  else
676  vlib_cli_output (vm, "%lld pppoe fib entries", ctx.total_entries);
677 
678  return 0;
679 }
680 
681 /*?
682  * This command dispays the MAC Address entries of the PPPoE FIB table.
683  * Output can be filtered to just get the number of MAC Addresses or display
684  * each MAC Address.
685  *
686  * @cliexpar
687  * Example of how to display the number of MAC Address entries in the PPPoE
688  * FIB table:
689  * @cliexstart{show pppoe fib}
690  * Mac Address session_id Interface sw_if_index session_index
691  * 52:54:00:53:18:33 1 GigabitEthernet0/8/0 2 0
692  * 52:54:00:53:18:55 2 GigabitEthernet0/8/1 3 1
693  * @cliexend
694 ?*/
695 /* *INDENT-OFF* */
696 VLIB_CLI_COMMAND (show_pppoe_fib_command, static) = {
697  .path = "show pppoe fib",
698  .short_help = "show pppoe fib",
699  .function = show_pppoe_fib_command_fn,
700 };
701 /* *INDENT-ON* */
702 
703 clib_error_t *
705 {
706  pppoe_main_t *pem = &pppoe_main;
707 
708  pem->vnet_main = vnet_get_main ();
709  pem->vlib_main = vm;
710 
711  /* Create the hash table */
712  BV (clib_bihash_init) (&pem->link_table, "pppoe link table",
714 
715  BV (clib_bihash_init) (&pem->session_table, "pppoe session table",
717 
718  ethernet_register_input_type (vm, ETHERNET_TYPE_PPPOE_SESSION,
719  pppoe_input_node.index);
720 
721  ethernet_register_input_type (vm, ETHERNET_TYPE_PPPOE_DISCOVERY,
722  pppoe_cp_dispatch_node.index);
723 
724  return 0;
725 }
726 
728 
729 /* *INDENT-OFF* */
731  .version = VPP_BUILD_VER,
732  .description = "PPP over Ethernet (PPPoE)",
733 };
734 /* *INDENT-ON* */
735 
736 /*
737  * fd.io coding-style-patch-verification: ON
738  *
739  * Local Variables:
740  * eval: (c-set-style "gnu")
741  * End:
742  */
u16 ppp_proto
Definition: pppoe.h:43
VLIB_PLUGIN_REGISTER()
fib_protocol_t fp_proto
protocol type
Definition: fib_types.h:212
vmrglw vmrglh hi
fib_node_index_t fib_table_entry_path_add(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source, fib_entry_flag_t flags, dpo_proto_t next_hop_proto, const ip46_address_t *next_hop, u32 next_hop_sw_if_index, u32 next_hop_fib_index, u32 next_hop_weight, fib_mpls_label_t *next_hop_labels, fib_route_path_flags_t path_flags)
Add one path to an entry (aka route) in the FIB.
Definition: fib_table.c:532
Definition: pppoe.h:113
u32 flags
Definition: vhost_user.h:141
static_always_inline void pppoe_update_1(BVT(clib_bihash) *table, u8 *mac0, u16 session_id0, pppoe_entry_key_t *key0, u32 *bucket0, pppoe_entry_result_t *result0)
Definition: pppoe.h:309
struct pppoe_entry_key_t::@591::@593 fields
vlib_main_t * vlib_main
Definition: pppoe.h:176
VNET_HW_INTERFACE_CLASS(pppoe_hw_class)
vnet_main_t * vnet_get_main(void)
Definition: misc.c:46
vnet_interface_main_t interface_main
Definition: vnet.h:56
u32 encap_if_index
Definition: pppoe.h:61
#define PPPOE_MEMORY_SIZE
Definition: pppoe.h:107
Multicast Adjacency.
Definition: adj.h:82
u16 session_id
Definition: pppoe.h:55
u64 raw
Definition: pppoe.h:147
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
Broadcasr Adjacency.
Definition: adj.h:85
IP unicast adjacency.
Definition: adj.h:221
u8 src_address[6]
Definition: packet.h:56
static vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
This packet is to be rewritten and forwarded to the next processing node.
Definition: adj.h:73
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:522
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:989
static clib_error_t * pppoe_interface_admin_up_down(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
Definition: pppoe.c:69
format_function_t format_ip46_address
Definition: format.h:61
static vnet_sw_interface_t * vnet_get_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
u8 data[128]
Definition: ipsec.api:251
#define vec_validate_aligned(V, I, A)
Make sure vector is long enough for given index (no header, specified alignment)
Definition: vec.h:450
static uword vlib_buffer_length_in_chain(vlib_main_t *vm, vlib_buffer_t *b)
Get length in bytes of the buffer chain.
Definition: buffer_funcs.h:366
format_function_t format_vnet_sw_if_index_name
static void pppoe_show_walk_cb(BVT(clib_bihash_kv) *kvp, void *arg)
Definition: pppoe.c:630
unsigned char u8
Definition: types.h:56
static clib_error_t * show_pppoe_fib_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Display the contents of the PPPoE Fib.
Definition: pppoe.c:661
clib_error_t * pppoe_init(vlib_main_t *vm)
Definition: pppoe.c:704
vnet_link_t ia_link
link/ether-type 1 bytes
Definition: adj.h:242
VNET_DEVICE_CLASS(pppoe_device_class, static)
#define clib_memcpy(d, s, n)
Definition: string.h:180
Adjacency to punt this packet.
Definition: adj.h:55
static void pppoe_update_adj(vnet_main_t *vnm, u32 sw_if_index, adj_index_t ai)
Definition: pppoe.c:160
static ip_adjacency_t * adj_get(adj_index_t adj_index)
Get a pointer to an adjacency object from its index.
Definition: adj.h:433
u8 * format_ethernet_address(u8 *s, va_list *args)
Definition: format.c:44
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:493
unformat_function_t unformat_ip4_address
Definition: format.h:70
vl_api_interface_index_t sw_if_index
Definition: gre.api:50
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:173
dpo_proto_t vnet_link_to_dpo_proto(vnet_link_t linkt)
Definition: dpo.c:96
vlib_combined_counter_main_t * combined_sw_if_counters
Definition: interface.h:846
u8 dst_address[6]
Definition: packet.h:55
static BVT(clib_bihash)
Definition: adj_nbr.c:28
A high priority source a plugin can use.
Definition: fib_entry.h:67
Aggregate type for a prefix.
Definition: fib_types.h:203
#define clib_error_return(e, args...)
Definition: error.h:99
unsigned int u32
Definition: types.h:88
u32 fib_table_find(fib_protocol_t proto, u32 table_id)
Get the index of the FIB for a Table-ID.
Definition: fib_table.c:1080
u16 fp_len
The mask length.
Definition: fib_types.h:207
static bool pppoe_decap_next_is_valid(pppoe_main_t *pem, u32 is_ip6, u32 decap_fib_index)
Definition: pppoe.c:237
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:762
static u8 * format_pppoe_header_with_length(u8 *s, va_list *args)
Definition: pppoe.c:87
struct pppoe_entry_result_t::@595::@597 fields
Definition: fib_entry.h:281
unformat_function_t unformat_line_input
Definition: format.h:283
u64 raw
Definition: pppoe.h:127
The identity of a DPO is a combination of its type and its instance number/index of objects of that t...
Definition: dpo.h:170
#define ADJ_INDEX_INVALID
Invalid ADJ index - used when no adj is known likewise blazoned capitals INVALID speak volumes where ...
Definition: adj_types.h:36
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:514
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:285
vlib_node_registration_t ip4_input_node
Global ip4 input node.
Definition: ip4_input.c:317
ip46_address_t fp_addr
The address type is not deriveable from the fp_addr member.
Definition: fib_types.h:226
long ctx[MAX_CONNS]
Definition: main.c:144
vlib_node_registration_t ip6_input_node
(constructor) VLIB_REGISTER_NODE (ip6_input_node)
Definition: ip6_input.c:230
struct _unformat_input_t unformat_input_t
unsigned short u16
Definition: types.h:57
u16 session_id
Definition: pppoe.h:41
u16 length
Definition: pppoe.h:42
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:229
vlib_main_t * vm
Definition: pppoe.c:624
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:286
u32 hw_if_index
Definition: pppoe.h:71
ip46_address_t client_ip
Definition: pppoe.h:58
This packet matches an "interface route" and packets need to be passed to ARP to find rewrite string ...
Definition: adj.h:68
vnet_sw_interface_flags_t flags
Definition: interface.h:703
vlib_simple_counter_main_t * sw_if_counters
Definition: interface.h:845
void interface_tx_dpo_add_or_lock(dpo_proto_t proto, u32 sw_if_index, dpo_id_t *dpo)
The data-path object representing transmitting the packet on a n interface.
void clib_bihash_init(clib_bihash *h, char *name, u32 nbuckets, uword memory_size)
initialize a bounded index extensible hash table
u8 len
Definition: ip_types.api:90
unformat_function_t unformat_ip6_address
Definition: format.h:91
#define pool_get_aligned(P, E, A)
Allocate an object E from a pool P with alignment A.
Definition: pool.h:230
pppoe_main_t pppoe_main
Definition: pppoe.c:38
static_always_inline void pppoe_learn_process(BVT(clib_bihash) *table, u32 sw_if_index0, pppoe_entry_key_t *key0, pppoe_entry_key_t *cached_key, u32 *bucket0, pppoe_entry_result_t *result0)
Perform learning on one packet based on the mac table lookup result.
Definition: pppoe.h:240
void clib_bihash_foreach_key_value_pair(clib_bihash *h, void *callback, void *arg)
Visit active (key,value) pairs in a bi-hash table.
This packet matches an "incomplete adjacency" and packets need to be passed to ARP to find rewrite st...
Definition: adj.h:63
Adjacency to drop this packet.
Definition: adj.h:53
#define UNFORMAT_END_OF_INPUT
Definition: format.h:145
vlib_main_t * vm
Definition: buffer.c:323
vlib_node_registration_t pppoe_input_node
(constructor) VLIB_REGISTER_NODE (pppoe_input_node)
Definition: pppoe_decap.c:402
Multicast Midchain Adjacency.
Definition: adj.h:89
static clib_error_t * pppoe_add_del_session_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: pppoe.c:427
#define PPPOE_NUM_BUCKETS
Definition: pppoe.h:106
void adj_nbr_midchain_update_rewrite(adj_index_t adj_index, adj_midchain_fixup_t fixup, const void *fixup_data, adj_flags_t flags, u8 *rewrite)
adj_nbr_midchain_update_rewrite
Definition: adj_midchain.c:532
static vlib_node_runtime_t * vlib_node_get_runtime(vlib_main_t *vm, u32 node_index)
Get node runtime by node index.
Definition: node_funcs.h:89
static void vnet_interface_counter_unlock(vnet_interface_main_t *im)
Definition: interface.h:879
u8 * format_pppoe_session(u8 *s, va_list *args)
Definition: pppoe.c:41
u32 adj_index_t
An index for adjacencies.
Definition: adj_types.h:30
void adj_mcast_midchain_update_rewrite(adj_index_t adj_index, adj_midchain_fixup_t fixup, const void *fixup_data, adj_flags_t flags, u8 *rewrite, u8 offset, u32 mask)
adj_mcast_midchain_update_rewrite
Definition: adj_mcast.c:136
pppoe_session_t * sessions
Definition: pppoe.h:155
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:161
This packets follow a mid-chain adjacency.
Definition: adj.h:76
static void vnet_interface_counter_lock(vnet_interface_main_t *im)
Definition: interface.h:872
uword unformat_ethernet_address(unformat_input_t *input, va_list *args)
Definition: format.c:233
#define ASSERT(truth)
u16 session_id
Definition: gre.api:46
void adj_nbr_midchain_stack(adj_index_t adj_index, const dpo_id_t *next)
adj_nbr_midchain_stack
Definition: adj_midchain.c:674
vnet_main_t * vnet_main
Definition: pppoe.h:177
enum vnet_link_t_ vnet_link_t
Link Type: A description of the protocol of packets on the link.
static u8 * format_pppoe_name(u8 *s, va_list *args)
Definition: pppoe.c:62
Definition: pppoe.h:136
u32 sw_if_index
Definition: pppoe.h:70
vlib_node_registration_t pppoe_cp_dispatch_node
(constructor) VLIB_REGISTER_NODE (pppoe_cp_dispatch_node)
static void vlib_zero_simple_counter(vlib_simple_counter_main_t *cm, u32 index)
Clear a simple counter Clears the set of per-thread u16 counters, and the u64 counter.
Definition: counter.h:139
u8 client_mac[6]
Definition: pppoe.h:67
dpo_proto_t fib_proto_to_dpo(fib_protocol_t fib_proto)
Definition: fib_types.c:247
void fib_table_entry_path_remove(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source, dpo_proto_t next_hop_proto, const ip46_address_t *next_hop, u32 next_hop_sw_if_index, u32 next_hop_fib_index, u32 next_hop_weight, fib_route_path_flags_t path_flags)
remove one path to an entry (aka route) in the FIB.
Definition: fib_table.c:705
void ethernet_register_input_type(vlib_main_t *vm, ethernet_type_t type, u32 node_index)
Definition: node.c:2072
u32 * session_index_by_sw_if_index
Definition: pppoe.h:167
int vnet_pppoe_add_del_session(vnet_pppoe_add_del_session_args_t *a, u32 *sw_if_indexp)
Definition: pppoe.c:248
struct pppoe_show_walk_ctx_t_ pppoe_show_walk_ctx_t
This packets needs to go to ICMP error.
Definition: adj.h:79
This packet is for one of our own IP addresses.
Definition: adj.h:58
Definition: defs.h:47
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
#define foreach_copy_field
Definition: pppoe.c:230
static u8 * pppoe_build_rewrite(vnet_main_t *vnm, u32 sw_if_index, vnet_link_t link_type, const void *dst_address)
Definition: pppoe.c:95
ip_lookup_next_t lookup_next_index
Next hop after ip4-lookup.
Definition: adj.h:236
clib_error_t * vnet_hw_interface_set_flags(vnet_main_t *vnm, u32 hw_if_index, vnet_hw_interface_flags_t flags)
Definition: interface.c:492
u32 decap_fib_index
FIB indices - inner IP packet lookup here.
Definition: pppoe.h:64
VLIB buffer representation.
Definition: buffer.h:102
static void unformat_free(unformat_input_t *i)
Definition: format.h:163
typedef key
Definition: ipsec.api:247
#define DPO_INVALID
An initialiser for DPOs declared on the stack.
Definition: dpo.h:197
a point 2 point interface
Definition: interface.h:368
static clib_error_t * show_pppoe_session_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: pppoe.c:585
#define vnet_buffer(b)
Definition: buffer.h:365
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
static_always_inline void pppoe_lookup_1(BVT(clib_bihash) *table, pppoe_entry_key_t *cached_key, pppoe_entry_result_t *cached_result, u8 *mac0, u16 session_id0, pppoe_entry_key_t *key0, u32 *bucket0, pppoe_entry_result_t *result0)
Definition: pppoe.h:275
clib_error_t * vnet_sw_interface_set_flags(vnet_main_t *vnm, u32 sw_if_index, vnet_sw_interface_flags_t flags)
Definition: interface.c:501
void dpo_reset(dpo_id_t *dpo)
reset a DPO ID The DPO will be unlocked.
Definition: dpo.c:232
u32 * free_pppoe_session_hw_if_indices
Definition: pppoe.h:164
#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:486
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:59
u8 ver_type
Definition: pppoe.h:39
u8 local_mac[6]
Definition: pppoe.h:66
#define PPPOE_VER_TYPE
Definition: pppoe.h:46
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:772
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:171
static void pppoe_fixup(vlib_main_t *vm, ip_adjacency_t *adj, vlib_buffer_t *b0, const void *data)
Fixup the adj rewrite post encap.
Definition: pppoe.c:140
static uword pool_elts(void *v)
Number of active elements in a pool.
Definition: pool.h:128