FD.io VPP  v18.01.2-1-g9b554f3
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 uword
70  vlib_node_runtime_t * node, vlib_frame_t * frame)
71 {
72  clib_warning ("you shouldn't be here, leaking buffers...");
73  return frame->n_vectors;
74 }
75 
76 static clib_error_t *
78 {
79  u32 hw_flags = (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
81  vnet_hw_interface_set_flags (vnm, hw_if_index, hw_flags);
82 
83  return /* no error */ 0;
84 }
85 
86 /* *INDENT-OFF* */
87 VNET_DEVICE_CLASS (pppoe_device_class,static) = {
88  .name = "PPPPOE",
89  .format_device_name = format_pppoe_name,
90  .tx_function = dummy_interface_tx,
91  .admin_up_down_function = pppoe_interface_admin_up_down,
92 };
93 /* *INDENT-ON* */
94 
95 static u8 *
96 format_pppoe_header_with_length (u8 * s, va_list * args)
97 {
98  u32 dev_instance = va_arg (*args, u32);
99  s = format (s, "unimplemented dev %u", dev_instance);
100  return s;
101 }
102 
103 static u8 *
105  u32 sw_if_index,
106  vnet_link_t link_type, const void *dst_address)
107 {
108  int len = sizeof (pppoe_header_t) + sizeof (ethernet_header_t);
109  pppoe_main_t *pem = &pppoe_main;
110  pppoe_session_t *t;
111  u32 session_id;
112  u8 *rw = 0;
113 
114  session_id = pem->session_index_by_sw_if_index[sw_if_index];
115  t = pool_elt_at_index (pem->sessions, session_id);
116 
118 
119  ethernet_header_t *eth_hdr = (ethernet_header_t *) rw;
120  clib_memcpy (eth_hdr->dst_address, t->client_mac, 6);
121  clib_memcpy (eth_hdr->src_address, t->local_mac, 6);
122  eth_hdr->type = clib_host_to_net_u16 (ETHERNET_TYPE_PPPOE_SESSION);
123 
124  pppoe_header_t *pppoe = (pppoe_header_t *) (eth_hdr + 1);
125  pppoe->ver_type = PPPOE_VER_TYPE;
126  pppoe->code = 0;
127  pppoe->session_id = clib_host_to_net_u16 (t->session_id);
128  pppoe->length = 0; /* To be filled in at run-time */
129 
130  switch (link_type)
131  {
132  case VNET_LINK_IP4:
133  pppoe->ppp_proto = clib_host_to_net_u16 (PPP_PROTOCOL_ip4);
134  break;
135  case VNET_LINK_IP6:
136  pppoe->ppp_proto = clib_host_to_net_u16 (PPP_PROTOCOL_ip6);
137  break;
138  default:
139  break;
140  }
141 
142  return rw;
143 }
144 
145 /**
146  * @brief Fixup the adj rewrite post encap. Insert the packet's length
147  */
148 static void
150 {
151  pppoe_header_t *pppoe0;
152 
153  pppoe0 = vlib_buffer_get_current (b0) + sizeof (ethernet_header_t);
154 
155  pppoe0->length = clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b0)
156  - sizeof (pppoe_header_t)
157  + sizeof (pppoe0->ppp_proto)
158  - sizeof (ethernet_header_t));
159 }
160 
161 static void
162 pppoe_update_adj (vnet_main_t * vnm, u32 sw_if_index, adj_index_t ai)
163 {
164  pppoe_main_t *pem = &pppoe_main;
165  dpo_id_t dpo = DPO_INVALID;
166  ip_adjacency_t *adj;
167  pppoe_session_t *t;
168  u32 session_id;
169 
170  ASSERT (ADJ_INDEX_INVALID != ai);
171 
172  adj = adj_get (ai);
173 
174  switch (adj->lookup_next_index)
175  {
176  case IP_LOOKUP_NEXT_ARP:
180  pppoe_build_rewrite (vnm,
181  sw_if_index,
182  adj->ia_link,
183  NULL));
184  break;
186  /*
187  * Construct a partial rewrite from the known ethernet mcast dest MAC
188  * There's no MAC fixup, so the last 2 parameters are 0
189  */
192  pppoe_build_rewrite (vnm,
193  sw_if_index,
194  adj->ia_link,
195  NULL), 0, 0);
196  break;
197 
198  case IP_LOOKUP_NEXT_DROP:
199  case IP_LOOKUP_NEXT_PUNT:
205  case IP_LOOKUP_N_NEXT:
206  ASSERT (0);
207  break;
208  }
209 
210  session_id = pem->session_index_by_sw_if_index[sw_if_index];
211  t = pool_elt_at_index (pem->sessions, session_id);
213  t->encap_if_index, &dpo);
214 
215  adj_nbr_midchain_stack (ai, &dpo);
216 
217  dpo_reset (&dpo);
218 }
219 
220 /* *INDENT-OFF* */
221 VNET_HW_INTERFACE_CLASS (pppoe_hw_class) =
222 {
223  .name = "PPPPOE",
224  .format_header = format_pppoe_header_with_length,
225  .build_rewrite = pppoe_build_rewrite,
226  .update_adjacency = pppoe_update_adj,
228 };
229 /* *INDENT-ON* */
230 
231 #define foreach_copy_field \
232 _(session_id) \
233 _(encap_if_index) \
234 _(decap_fib_index) \
235 _(client_ip)
236 
237 static bool
239  u32 decap_fib_index)
240 {
241  vlib_main_t *vm = pem->vlib_main;
242  u32 input_idx = (!is_ip6) ? ip4_input_node.index : ip6_input_node.index;
243  vlib_node_runtime_t *r = vlib_node_get_runtime (vm, input_idx);
244 
245  return decap_fib_index < r->n_next_nodes;
246 }
247 
250 {
251  pppoe_main_t *pem = &pppoe_main;
252  pppoe_session_t *t = 0;
253  vnet_main_t *vnm = pem->vnet_main;
254  u32 hw_if_index = ~0;
255  u32 sw_if_index = ~0;
256  u32 is_ip6 = a->is_ip6;
257  pppoe_entry_key_t cached_key;
258  pppoe_entry_result_t cached_result;
259  u32 bucket;
260  pppoe_entry_key_t key;
261  pppoe_entry_result_t result;
264  fib_prefix_t pfx;
265 
266  cached_key.raw = ~0;
267  cached_result.raw = ~0; /* warning be gone */
268  memset (&pfx, 0, sizeof (pfx));
269 
270  if (!is_ip6)
271  {
272  pfx.fp_addr.ip4.as_u32 = a->client_ip.ip4.as_u32;
273  pfx.fp_len = 32;
275  }
276  else
277  {
278  pfx.fp_addr.ip6.as_u64[0] = a->client_ip.ip6.as_u64[0];
279  pfx.fp_addr.ip6.as_u64[1] = a->client_ip.ip6.as_u64[1];
280  pfx.fp_len = 128;
282  }
283 
284  /* Get encap_if_index and local mac address from link_table */
285  pppoe_lookup_1 (&pem->link_table, &cached_key, &cached_result,
286  a->client_mac, 0, &key, &bucket, &result);
287  a->encap_if_index = result.fields.sw_if_index;
288 
289  if (a->encap_if_index == ~0)
290  return VNET_API_ERROR_INVALID_SW_IF_INDEX;
291 
292  si = vnet_get_sw_interface (vnm, a->encap_if_index);
293  hi = vnet_get_hw_interface (vnm, si->hw_if_index);
294 
295  /* lookup session_table */
296  pppoe_lookup_1 (&pem->session_table, &cached_key, &cached_result,
297  a->client_mac, clib_host_to_net_u16 (a->session_id),
298  &key, &bucket, &result);
299 
300  /* learn client session */
301  pppoe_learn_process (&pem->session_table, a->encap_if_index,
302  &key, &cached_key, &bucket, &result);
303 
304  if (a->is_add)
305  {
306  /* adding a session: session must not already exist */
307  if (result.fields.session_index != ~0)
308  return VNET_API_ERROR_TUNNEL_EXIST;
309 
310  /*if not set explicitly, default to ip4 */
311  if (!pppoe_decap_next_is_valid (pem, is_ip6, a->decap_fib_index))
312  return VNET_API_ERROR_INVALID_DECAP_NEXT;
313 
315  memset (t, 0, sizeof (*t));
316 
317  clib_memcpy (t->local_mac, hi->hw_address, 6);
318 
319  /* copy from arg structure */
320 #define _(x) t->x = a->x;
322 #undef _
323 
324  clib_memcpy (t->client_mac, a->client_mac, 6);
325 
326  /* update pppoe fib with session_index */
327  result.fields.session_index = t - pem->sessions;
328  pppoe_update_1 (&pem->session_table,
329  a->client_mac, clib_host_to_net_u16 (a->session_id),
330  &key, &bucket, &result);
331 
334  {
336  hw_if_index = pem->free_pppoe_session_hw_if_indices
338  _vec_len (pem->free_pppoe_session_hw_if_indices) -= 1;
339 
340  hi = vnet_get_hw_interface (vnm, hw_if_index);
341  hi->dev_instance = t - pem->sessions;
342  hi->hw_instance = hi->dev_instance;
343 
344  /* clear old stats of freed session before reuse */
345  sw_if_index = hi->sw_if_index;
349  sw_if_index);
352  sw_if_index);
355  sw_if_index);
357  }
358  else
359  {
360  hw_if_index = vnet_register_interface
361  (vnm, pppoe_device_class.index, t - pem->sessions,
362  pppoe_hw_class.index, t - pem->sessions);
363  hi = vnet_get_hw_interface (vnm, hw_if_index);
364  }
365 
366  t->hw_if_index = hw_if_index;
367  t->sw_if_index = sw_if_index = hi->sw_if_index;
368 
370  ~0);
371  pem->session_index_by_sw_if_index[sw_if_index] = t - pem->sessions;
372 
373  vnet_sw_interface_t *si = vnet_get_sw_interface (vnm, sw_if_index);
375  vnet_sw_interface_set_flags (vnm, sw_if_index,
377 
378  /* add reverse route for client ip */
382  &pfx.fp_addr, sw_if_index, ~0,
384 
385  }
386  else
387  {
388  /* deleting a session: session must exist */
389  if (result.fields.session_index == ~0)
390  return VNET_API_ERROR_NO_SUCH_ENTRY;
391 
392  t = pool_elt_at_index (pem->sessions, result.fields.session_index);
393  sw_if_index = t->sw_if_index;
394 
395  vnet_sw_interface_set_flags (vnm, t->sw_if_index, 0 /* down */ );
398 
400 
402 
403  /* update pppoe fib with session_inde=~0x */
404  result.fields.session_index = ~0;
405  pppoe_update_1 (&pem->session_table,
406  a->client_mac, clib_host_to_net_u16 (a->session_id),
407  &key, &bucket, &result);
408 
409 
410  /* delete reverse route for client ip */
414  &pfx.fp_addr,
415  sw_if_index, ~0, 1,
417 
418  pool_put (pem->sessions, t);
419  }
420 
421  if (sw_if_indexp)
422  *sw_if_indexp = sw_if_index;
423 
424  return 0;
425 }
426 
427 static clib_error_t *
429  unformat_input_t * input,
430  vlib_cli_command_t * cmd)
431 {
432  unformat_input_t _line_input, *line_input = &_line_input;
433  u16 session_id = 0;
434  ip46_address_t client_ip;
435  u8 is_add = 1;
436  u8 client_ip_set = 0;
437  u8 ipv4_set = 0;
438  u8 ipv6_set = 0;
439  u32 encap_if_index = 0;
440  u32 decap_fib_index = 0;
441  u8 client_mac[6] = { 0 };
442  u8 client_mac_set = 0;
443  int rv;
444  u32 tmp;
446  u32 session_sw_if_index;
447  clib_error_t *error = NULL;
448 
449  /* Cant "universally zero init" (={0}) due to GCC bug 53119 */
450  memset (&client_ip, 0, sizeof client_ip);
451 
452  /* Get a line of input. */
453  if (!unformat_user (input, unformat_line_input, line_input))
454  return 0;
455 
456  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
457  {
458  if (unformat (line_input, "del"))
459  {
460  is_add = 0;
461  }
462  else if (unformat (line_input, "session-id %d", &session_id))
463  ;
464  else if (unformat (line_input, "client-ip %U",
465  unformat_ip4_address, &client_ip.ip4))
466  {
467  client_ip_set = 1;
468  ipv4_set = 1;
469  }
470  else if (unformat (line_input, "client-ip %U",
471  unformat_ip6_address, &client_ip.ip6))
472  {
473  client_ip_set = 1;
474  ipv6_set = 1;
475  }
476  else if (unformat (line_input, "decap-vrf-id %d", &tmp))
477  {
478  if (ipv6_set)
479  decap_fib_index = fib_table_find (FIB_PROTOCOL_IP6, tmp);
480  else
481  decap_fib_index = fib_table_find (FIB_PROTOCOL_IP4, tmp);
482 
483  if (decap_fib_index == ~0)
484  {
485  error =
486  clib_error_return (0, "nonexistent decap fib id %d", tmp);
487  goto done;
488  }
489  }
490  else
491  if (unformat
492  (line_input, "client-mac %U", unformat_ethernet_address,
493  client_mac))
494  client_mac_set = 1;
495  else
496  {
497  error = clib_error_return (0, "parse error: '%U'",
498  format_unformat_error, line_input);
499  goto done;
500  }
501  }
502 
503  if (client_ip_set == 0)
504  {
505  error =
506  clib_error_return (0, "session client ip address not specified");
507  goto done;
508  }
509 
510  if (ipv4_set && ipv6_set)
511  {
512  error = clib_error_return (0, "both IPv4 and IPv6 addresses specified");
513  goto done;
514  }
515 
516  if (client_mac_set == 0)
517  {
518  error = clib_error_return (0, "session client mac not specified");
519  goto done;
520  }
521 
522  memset (a, 0, sizeof (*a));
523 
524  a->is_add = is_add;
525  a->is_ip6 = ipv6_set;
526 
527 #define _(x) a->x = x;
529 #undef _
530 
531  clib_memcpy (a->client_mac, client_mac, 6);
532 
533  rv = vnet_pppoe_add_del_session (a, &session_sw_if_index);
534 
535  switch (rv)
536  {
537  case 0:
538  if (is_add)
540  vnet_get_main (), session_sw_if_index);
541  break;
542 
543  case VNET_API_ERROR_TUNNEL_EXIST:
544  error = clib_error_return (0, "session already exists...");
545  goto done;
546 
547  case VNET_API_ERROR_NO_SUCH_ENTRY:
548  error = clib_error_return (0, "session does not exist...");
549  goto done;
550 
551  default:
552  error = clib_error_return
553  (0, "vnet_pppoe_add_del_session returned %d", rv);
554  goto done;
555  }
556 
557 done:
558  unformat_free (line_input);
559 
560  return error;
561 }
562 
563 /*?
564  * Add or delete a PPPPOE Session.
565  *
566  * @cliexpar
567  * Example of how to create a PPPPOE Session:
568  * @cliexcmd{create pppoe session client-ip 10.0.3.1 session-id 13
569  * client-mac 00:01:02:03:04:05 }
570  * Example of how to delete a PPPPOE Session:
571  * @cliexcmd{create pppoe session client-ip 10.0.3.1 session-id 13
572  * client-mac 00:01:02:03:04:05 del }
573  ?*/
574 /* *INDENT-OFF* */
575 VLIB_CLI_COMMAND (create_pppoe_session_command, static) = {
576  .path = "create pppoe session",
577  .short_help =
578  "create pppoe session client-ip <client-ip> session-id <nn>"
579  " client-mac <client-mac> [decap-vrf-id <nn>] [del]",
581 };
582 /* *INDENT-ON* */
583 
584 /* *INDENT-OFF* */
585 static clib_error_t *
587  unformat_input_t * input,
588  vlib_cli_command_t * cmd)
589 {
590  pppoe_main_t *pem = &pppoe_main;
591  pppoe_session_t *t;
592 
593  if (pool_elts (pem->sessions) == 0)
594  vlib_cli_output (vm, "No pppoe sessions configured...");
595 
596  pool_foreach (t, pem->sessions,
597  ({
598  vlib_cli_output (vm, "%U",format_pppoe_session, t);
599  }));
600 
601  return 0;
602 }
603 /* *INDENT-ON* */
604 
605 /*?
606  * Display all the PPPPOE Session entries.
607  *
608  * @cliexpar
609  * Example of how to display the PPPPOE Session entries:
610  * @cliexstart{show pppoe session}
611  * [0] client-ip 10.0.3.1 session_id 13 encap-if-index 0 decap-vrf-id 13 sw_if_index 5
612  * local-mac a0:b0:c0:d0:e0:f0 client-mac 00:01:02:03:04:05
613  * @cliexend
614  ?*/
615 /* *INDENT-OFF* */
616 VLIB_CLI_COMMAND (show_pppoe_session_command, static) = {
617  .path = "show pppoe session",
618  .short_help = "show pppoe session",
619  .function = show_pppoe_session_command_fn,
620 };
621 /* *INDENT-ON* */
622 
623 /** Display the contents of the PPPoE Fib. */
624 static clib_error_t *
626  unformat_input_t * input, vlib_cli_command_t * cmd)
627 {
628  pppoe_main_t *pem = &pppoe_main;
629  BVT (clib_bihash) * h = &pem->session_table;
630  BVT (clib_bihash_bucket) * b;
631  BVT (clib_bihash_value) * v;
632  pppoe_entry_key_t key;
633  pppoe_entry_result_t result;
634  u32 first_entry = 1;
635  u64 total_entries = 0;
636  int i, j, k;
637  u8 *s = 0;
638 
639  for (i = 0; i < h->nbuckets; i++)
640  {
641  b = &h->buckets[i];
642  if (b->offset == 0)
643  continue;
644  v = BV (clib_bihash_get_value) (h, b->offset);
645  for (j = 0; j < (1 << b->log2_pages); j++)
646  {
647  for (k = 0; k < BIHASH_KVP_PER_PAGE; k++)
648  {
649  if (v->kvp[k].key == ~0ULL && v->kvp[k].value == ~0ULL)
650  continue;
651 
652  if (first_entry)
653  {
654  first_entry = 0;
655  vlib_cli_output (vm,
656  "%=19s%=12s%=13s%=14s",
657  "Mac-Address", "session_id", "sw_if_index",
658  "session_index");
659  }
660 
661  key.raw = v->kvp[k].key;
662  result.raw = v->kvp[k].value;
663 
664 
665  vlib_cli_output (vm,
666  "%=19U%=12d%=13d%=14d",
668  clib_net_to_host_u16 (key.fields.session_id),
669  result.fields.sw_if_index == ~0
670  ? -1 : result.fields.sw_if_index,
671  result.fields.session_index == ~0
672  ? -1 : result.fields.session_index);
673  vec_reset_length (s);
674  total_entries++;
675  }
676  v++;
677  }
678  }
679 
680  if (total_entries == 0)
681  vlib_cli_output (vm, "no pppoe fib entries");
682  else
683  vlib_cli_output (vm, "%lld pppoe fib entries", total_entries);
684 
685  vec_free (s);
686  return 0;
687 }
688 
689 /*?
690  * This command dispays the MAC Address entries of the PPPoE FIB table.
691  * Output can be filtered to just get the number of MAC Addresses or display
692  * each MAC Address.
693  *
694  * @cliexpar
695  * Example of how to display the number of MAC Address entries in the PPPoE
696  * FIB table:
697  * @cliexstart{show pppoe fib}
698  * Mac Address session_id Interface sw_if_index session_index
699  * 52:54:00:53:18:33 1 GigabitEthernet0/8/0 2 0
700  * 52:54:00:53:18:55 2 GigabitEthernet0/8/1 3 1
701  * @cliexend
702 ?*/
703 /* *INDENT-OFF* */
704 VLIB_CLI_COMMAND (show_pppoe_fib_command, static) = {
705  .path = "show pppoe fib",
706  .short_help = "show pppoe fib",
707  .function = show_pppoe_fib_command_fn,
708 };
709 /* *INDENT-ON* */
710 
711 clib_error_t *
713 {
714  pppoe_main_t *pem = &pppoe_main;
715 
716  pem->vnet_main = vnet_get_main ();
717  pem->vlib_main = vm;
718 
719  /* Create the hash table */
720  BV (clib_bihash_init) (&pem->link_table, "pppoe link table",
722 
723  BV (clib_bihash_init) (&pem->session_table, "pppoe session table",
725 
726  ethernet_register_input_type (vm, ETHERNET_TYPE_PPPOE_SESSION,
727  pppoe_input_node.index);
728 
729  ethernet_register_input_type (vm, ETHERNET_TYPE_PPPOE_DISCOVERY,
730  pppoe_cp_dispatch_node.index);
731 
732  return 0;
733 }
734 
736 
737 /* *INDENT-OFF* */
739  .version = VPP_BUILD_VER,
740  .description = "PPPoE",
741 };
742 /* *INDENT-ON* */
743 
744 /*
745  * fd.io coding-style-patch-verification: ON
746  *
747  * Local Variables:
748  * eval: (c-set-style "gnu")
749  * End:
750  */
u16 ppp_proto
Definition: pppoe.h:43
VLIB_PLUGIN_REGISTER()
fib_protocol_t fp_proto
protocol type
Definition: fib_types.h:181
vmrglw vmrglh hi
Definition: pppoe.h:109
sll srl srl sll sra u16x4 i
Definition: vector_sse2.h:337
clib_error_t * vnet_hw_interface_set_flags(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
Definition: interface.c:538
#define BIHASH_KVP_PER_PAGE
Definition: bihash_16_8.h:20
vlib_main_t * vlib_main
Definition: pppoe.h:172
VNET_HW_INTERFACE_CLASS(pppoe_hw_class)
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:236
vnet_main_t * vnet_get_main(void)
Definition: misc.c:47
vnet_interface_main_t interface_main
Definition: vnet.h:56
u32 encap_if_index
Definition: pppoe.h:58
#define PPPOE_MEMORY_SIZE
Definition: pppoe.h:103
Multicast Adjacency.
Definition: adj.h:82
u16 session_id
Definition: pppoe.h:52
u64 raw
Definition: pppoe.h:143
#define NULL
Definition: clib.h:55
IP unicast adjacency.
Definition: adj.h:174
u8 src_address[6]
Definition: packet.h:54
static vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
static void pppoe_fixup(vlib_main_t *vm, ip_adjacency_t *adj, vlib_buffer_t *b0)
Fixup the adj rewrite post encap.
Definition: pppoe.c:149
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:518
struct pppoe_entry_result_t::@408::@410 fields
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:983
static clib_error_t * pppoe_interface_admin_up_down(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
Definition: pppoe.c:77
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:419
#define VNET_HW_INTERFACE_FLAG_LINK_UP
Definition: interface.h:394
#define vec_validate_aligned(V, I, A)
Make sure vector is long enough for given index (no header, specified alignment)
Definition: vec.h:443
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:107
format_function_t format_vnet_sw_if_index_name
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:625
clib_error_t * pppoe_init(vlib_main_t *vm)
Definition: pppoe.c:712
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
vnet_link_t ia_link
link/ether-type 1 bytes
Definition: adj.h:195
VNET_DEVICE_CLASS(pppoe_device_class, static)
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:162
void adj_nbr_midchain_update_rewrite(adj_index_t adj_index, adj_midchain_fixup_t fixup, adj_flags_t flags, u8 *rewrite)
adj_nbr_midchain_update_rewrite
Definition: adj_midchain.c:504
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:271
static ip_adjacency_t * adj_get(adj_index_t adj_index)
Get a pointer to an adjacency object from its index.
Definition: adj.h:365
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:438
unformat_function_t unformat_ip4_address
Definition: format.h:76
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:111
dpo_proto_t vnet_link_to_dpo_proto(vnet_link_t linkt)
Definition: dpo.c:94
vlib_combined_counter_main_t * combined_sw_if_counters
Definition: interface.h:672
u8 dst_address[6]
Definition: packet.h:53
static BVT(clib_bihash)
Definition: adj_nbr.c:26
A high priority source a plugin can use.
Definition: fib_entry.h:62
Aggregrate type for a prefix.
Definition: fib_types.h:172
#define clib_error_return(e, args...)
Definition: error.h:99
unsigned long u64
Definition: types.h:89
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:1028
u16 fp_len
The mask length.
Definition: fib_types.h:176
static bool pppoe_decap_next_is_valid(pppoe_main_t *pem, u32 is_ip6, u32 decap_fib_index)
Definition: pppoe.c:238
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:689
static u8 * format_pppoe_header_with_length(u8 *s, va_list *args)
Definition: pppoe.c:96
Definition: fib_entry.h:238
unformat_function_t unformat_line_input
Definition: format.h:281
u64 raw
Definition: pppoe.h:123
The identity of a DPO is a combination of its type and its instance number/index of objects of that t...
Definition: dpo.h:166
#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:459
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:276
vlib_node_registration_t ip4_input_node
Global ip4 input node.
Definition: ip4_input.c:277
ip46_address_t fp_addr
The address type is not deriveable from the fp_addr member.
Definition: fib_types.h:195
static uword dummy_interface_tx(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: pppoe.c:69
vlib_node_registration_t ip6_input_node
(constructor) VLIB_REGISTER_NODE (ip6_input_node)
Definition: ip6_input.c:228
#define v
Definition: acl.c:341
struct _unformat_input_t unformat_input_t
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:195
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:271
u32 hw_if_index
Definition: pppoe.h:68
ip46_address_t client_ip
Definition: pppoe.h:55
This packet matches an "interface route" and packets need to be passed to ARP to find rewrite string ...
Definition: adj.h:68
vlib_simple_counter_main_t * sw_if_counters
Definition: interface.h:671
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
unformat_function_t unformat_ip6_address
Definition: format.h:94
#define pool_get_aligned(P, E, A)
Allocate an object E from a pool P (general version).
Definition: pool.h:188
pppoe_main_t pppoe_main
Definition: pppoe.c:38
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:143
u16 n_vectors
Definition: node.h:344
vlib_main_t * vm
Definition: buffer.c:283
vec_header_t h
Definition: buffer.c:282
vlib_node_registration_t pppoe_input_node
(constructor) VLIB_REGISTER_NODE (pppoe_input_node)
Definition: pppoe_decap.c:401
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:336
Multicast Midchain Adjacency.
Definition: adj.h:86
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:428
#define PPPOE_NUM_BUCKETS
Definition: pppoe.h:102
#define clib_warning(format, args...)
Definition: error.h:59
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
#define clib_memcpy(a, b, c)
Definition: string.h:75
static void vnet_interface_counter_unlock(vnet_interface_main_t *im)
Definition: interface.h:697
#define VNET_SW_INTERFACE_FLAG_HIDDEN
Definition: interface.h:588
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
pppoe_session_t * sessions
Definition: pppoe.h:151
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:305
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:154
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:689
#define VNET_SW_INTERFACE_FLAG_ADMIN_UP
Definition: interface.h:576
uword unformat_ethernet_address(unformat_input_t *input, va_list *args)
Definition: format.c:227
#define ASSERT(truth)
void adj_nbr_midchain_stack(adj_index_t adj_index, const dpo_id_t *next)
adj_nbr_midchain_stack
Definition: adj_midchain.c:565
unsigned int u32
Definition: types.h:88
vnet_main_t * vnet_main
Definition: pppoe.h:173
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:132
u32 sw_if_index
Definition: pppoe.h:67
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:123
u8 client_mac[6]
Definition: pppoe.h:64
dpo_proto_t fib_proto_to_dpo(fib_protocol_t fib_proto)
Definition: fib_types.c:211
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:665
void ethernet_register_input_type(vlib_main_t *vm, ethernet_type_t type, u32 node_index)
Definition: node.c:1355
u32 * session_index_by_sw_if_index
Definition: pppoe.h:163
u64 uword
Definition: types.h:112
template key/value backing page structure
Definition: bihash_doc.h:44
int vnet_pppoe_add_del_session(vnet_pppoe_add_del_session_args_t *a, u32 *sw_if_indexp)
Definition: pppoe.c:249
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
unsigned short u16
Definition: types.h:57
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
#define foreach_copy_field
Definition: pppoe.c:231
unsigned char u8
Definition: types.h:56
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:104
ip_lookup_next_t lookup_next_index
Next hop after ip4-lookup.
Definition: adj.h:189
u32 decap_fib_index
FIB indices - inner IP packet lookup here.
Definition: pppoe.h:61
static void unformat_free(unformat_input_t *i)
Definition: format.h:161
struct pppoe_entry_key_t::@404::@406 fields
#define DPO_INVALID
An initialiser for DPOs declared on the stack.
Definition: dpo.h:193
a point 2 point interface
Definition: interface.h:289
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:586
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
void dpo_reset(dpo_id_t *dpo)
reset a DPO ID The DPO will be unlocked.
Definition: dpo.c:228
void adj_mcast_midchain_update_rewrite(adj_index_t adj_index, adj_midchain_fixup_t fixup, adj_flags_t flags, u8 *rewrite, u8 offset, u32 mask)
adj_mcast_midchain_update_rewrite
Definition: adj_mcast.c:140
clib_error_t * vnet_sw_interface_set_flags(vnet_main_t *vnm, u32 sw_if_index, u32 flags)
Definition: interface.c:546
static void * clib_bihash_get_value(clib_bihash *h, uword offset)
Get pointer to value page given its clib mheap offset.
u32 * free_pppoe_session_hw_if_indices
Definition: pppoe.h:160
u32 flags
Definition: vhost-user.h:77
#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:481
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:67
u8 ver_type
Definition: pppoe.h:39
u8 local_mac[6]
Definition: pppoe.h:63
#define PPPOE_VER_TYPE
Definition: pppoe.h:46
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:680
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:972
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:169
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, 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:505
static uword pool_elts(void *v)
Number of active elements in a pool.
Definition: pool.h:128