FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
ip6_ll_table.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <vlib/vlib.h>
17 #include <vnet/dpo/drop_dpo.h>
18 #include <vnet/fib/ip6_fib.h>
19 
20 #include <vnet/ip/ip6_ll_table.h>
21 
22 /**
23  * There's only one IP6 link local table
24  */
26 
27 u32
29 {
31 
33 }
34 
37 {
38  return (ip6_fib_table_lookup (ip6_ll_fib_get (prefix->ilp_sw_if_index),
39  &prefix->ilp_addr, 128));
40 }
41 
44 {
46  (ip6_ll_fib_get (prefix->ilp_sw_if_index), &prefix->ilp_addr, 128));
47 }
48 
49 static void
51 {
52  vnet_main_t *vnm = vnet_get_main ();
53  u8 *desc;
54 
55  desc = format (NULL, "IP6-link-local:%U",
58 
61  FIB_TABLE_FLAG_IP6_LL, desc);
62 
63  /*
64  * leave the default route as a drop, but fix fe::/10 to be a glean
65  * via the interface.
66  */
67  /* *INDENT-OFF* */
68  fib_prefix_t pfx = {
70  .fp_len = 10,
71  .fp_addr = {
72  .ip6 = {
73  .as_u8 = {
74  [0] = 0xFE,
75  [1] = 0x80,
76  }
77  },
78  }
79  };
82  &pfx,
87  NULL,
89  ~0,
90  1,
91  NULL,
93  /* *INDENT-ON* */
94 }
95 
96 static void
98 {
100  fp->fp_len = 128;
101  fp->fp_addr.ip6 = ilp->ilp_addr;
102  fp->___fp___pad = 0;
103 }
104 
108 {
109  fib_node_index_t ip6_ll_entry_index;
110  fib_route_path_t *rpaths, rpath = {
111  .frp_flags = flags,
112  .frp_sw_if_index = ilp->ilp_sw_if_index,
113  .frp_proto = DPO_PROTO_IP6,
114  };
115  fib_prefix_t fp;
116 
118 
119  if (0 == ip6_ll_fib_get (ilp->ilp_sw_if_index))
120  {
122  }
123 
124  rpaths = NULL;
125  vec_add1 (rpaths, rpath);
126 
127  ip6_ll_prefix_to_fib (ilp, &fp);
128  ip6_ll_entry_index =
133  rpaths);
134  vec_free (rpaths);
135 
136  return (ip6_ll_entry_index);
137 }
138 
139 void
141 {
142  fib_node_index_t ip6_ll_entry_index;
143  u32 fib_index;
144 
145  ip6_ll_entry_index = ip6_ll_table_lookup_exact_match (ilp);
146 
147  if (FIB_NODE_INDEX_INVALID != ip6_ll_entry_index)
148  fib_table_entry_delete_index (ip6_ll_entry_index, FIB_SOURCE_IP6_ND);
149 
150  /*
151  * if there are no ND sourced prefixes left, then we can clean up this FIB
152  */
153  fib_index = ip6_ll_fib_get (ilp->ilp_sw_if_index);
154  if (0 == fib_table_get_num_entries (fib_index,
156  {
159  }
160 }
161 
162 static void
164 {
165  vlib_cli_output (vm, "%U",
167  ip6_ll_table_lookup (ilp),
168  (detail ?
170 }
171 
172 typedef struct ip6_ll_show_ctx_t_
173 {
176 
177 static fib_table_walk_rc_t
178 ip6_ll_table_show_walk (fib_node_index_t fib_entry_index, void *arg)
179 {
180  ip6_ll_show_ctx_t *ctx = arg;
181 
182  vec_add1 (ctx->entries, fib_entry_index);
183 
184  return (FIB_TABLE_WALK_CONTINUE);
185 }
186 
187 static void
189 {
190  fib_node_index_t *fib_entry_index;
192  .entries = NULL,
193  };
194 
197 
198  vec_foreach (fib_entry_index, ctx.entries)
199  {
200  vlib_cli_output (vm, "%U",
202  *fib_entry_index, FIB_ENTRY_FORMAT_BRIEF);
203  }
204 
205  vec_free (ctx.entries);
206 }
207 
208 typedef struct
209 {
210  u32 fib_index;
211  u64 count_by_prefix_length[129];
213 
214 static int
216 {
218  int mask_width;
219 
220  if ((kvp->key[2] >> 32) != ap->fib_index)
221  return (BIHASH_WALK_CONTINUE);
222 
223  mask_width = kvp->key[2] & 0xFF;
224 
226 
227  return (BIHASH_WALK_CONTINUE);
228 }
229 
230 static clib_error_t *
232  unformat_input_t * input, vlib_cli_command_t * cmd)
233 {
235  fib_table_t *fib_table;
236  int verbose, matching;
237  ip6_address_t matching_address;
238  u32 mask_len = 128;
239  u32 sw_if_index = ~0;
240  int detail = 0;
241  vnet_main_t *vnm = vnet_get_main ();
242  u32 fib_index;
243 
244  verbose = 1;
245  matching = 0;
246 
248  {
249  if (unformat (input, "brief") ||
250  unformat (input, "summary") || unformat (input, "sum"))
251  verbose = 0;
252 
253  else if (unformat (input, "detail") || unformat (input, "det"))
254  detail = 1;
255 
256  else if (unformat (input, "%U/%d",
257  unformat_ip6_address, &matching_address, &mask_len))
258  matching = 1;
259 
260  else
261  if (unformat (input, "%U", unformat_ip6_address, &matching_address))
262  matching = 1;
263  else if (unformat (input, "%U",
265  ;
266  else
267  break;
268  }
269 
271  {
272  fib_source_t source;
273  u8 *s = NULL;
274 
275  fib_index = ip6_ll_table.ilt_fibs[sw_if_index];
276 
277  if (0 == fib_index)
278  continue;
279 
280  fib_table = fib_table_get (fib_index, FIB_PROTOCOL_IP6);
281 
282  if (!(fib_table->ft_flags & FIB_TABLE_FLAG_IP6_LL))
283  continue;
284 
285  s = format (s, "%U, fib_index:%d, locks:[",
286  format_fib_table_name, fib_index,
287  FIB_PROTOCOL_IP6, fib_index);
288  vec_foreach_index (source, fib_table->ft_locks)
289  {
290  if (0 != fib_table->ft_locks[source])
291  {
292  s = format (s, "%U:%d, ",
293  format_fib_source, source, fib_table->ft_locks[source]);
294  }
295  }
296  s = format (s, "]");
297  vlib_cli_output (vm, "%v", s);
298  vec_free (s);
299 
300  /* Show summary? */
301  if (!verbose)
302  {
303  clib_bihash_24_8_t *h =
305  int len;
306 
307  vlib_cli_output (vm, "%=20s%=16s", "Prefix length", "Count");
308 
309  clib_memset (ca, 0, sizeof (*ca));
310  ca->fib_index = fib_index;
311 
312  clib_bihash_foreach_key_value_pair_24_8
314 
315  for (len = 128; len >= 0; len--)
316  {
317  if (ca->count_by_prefix_length[len])
318  vlib_cli_output (vm, "%=20d%=16lld",
320  }
321  continue;
322  }
323 
324  if (!matching)
325  {
326  ip6_ll_table_show_all (vm, fib_index);
327  }
328  else
329  {
330  if (~0 == sw_if_index)
331  {
332  vlib_cli_output (vm, "specify the interface");
333  }
334  else
335  {
336  ip6_ll_prefix_t ilp = {
337  .ilp_addr = matching_address,
338  .ilp_sw_if_index = sw_if_index,
339  };
340  ip6_ll_table_show_one (vm, &ilp, detail);
341  }
342  }
343  };
344 
345  return 0;
346 }
347 
348 /* *INDENT-OFF* */
350  .path = "show ip6-ll",
351  .short_help = "show ip6-ll [summary] [interface] [<ip6-addr>[/<width>]] [detail]",
352  .function = ip6_ll_show_fib,
353 };
354 /* *INDENT-ON* */
355 
356 static clib_error_t *
358 {
360 
362 
363  return (error);
364 }
365 
367 
368 /*
369  * fd.io coding-style-patch-verification: ON
370  *
371  * Local Variables:
372  * eval: (c-set-style "gnu")
373  * End:
374  */
vlib.h
ip6_ll_table_t_::ilt_fibs
u32 * ilt_fibs
A vector, indexed by sw_if_index, of unicast IPv6 FIBs.
Definition: ip6_ll_table.h:32
count_routes_in_fib_at_prefix_length_arg_t::fib_index
u32 fib_index
Definition: ip6_fib.c:615
FIB_SOURCE_IP6_ND
@ FIB_SOURCE_IP6_ND
IPv6 ND (seen in the link-local tables)
Definition: fib_source.h:99
ip6_ll_show_ctx_t_::entries
fib_node_index_t * entries
Definition: ip6_ll_table.c:174
fib_table_entry_update_one_path
fib_node_index_t fib_table_entry_update_one_path(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)
Update the entry to have just one path.
Definition: fib_table.c:814
ip6_ll_module_init
static clib_error_t * ip6_ll_module_init(vlib_main_t *vm)
Definition: ip6_ll_table.c:357
fib_entry_cmp_for_sort
int fib_entry_cmp_for_sort(void *i1, void *i2)
Definition: fib_entry.c:1660
ip6_ll_show_ctx_t_
Definition: ip6_ll_table.c:172
FIB_ENTRY_FORMAT_DETAIL
#define FIB_ENTRY_FORMAT_DETAIL
Definition: fib_entry.h:360
ip6_fib_table_lookup_exact_match
fib_node_index_t ip6_fib_table_lookup_exact_match(u32 fib_index, const ip6_address_t *addr, u32 len)
Definition: ip6_fib.c:229
FIB_ENTRY_FORMAT_DETAIL2
#define FIB_ENTRY_FORMAT_DETAIL2
Definition: fib_entry.h:361
IP6_FIB_TABLE_NON_FWDING
@ IP6_FIB_TABLE_NON_FWDING
The table that stores ALL routes learned by the DP.
Definition: ip6_fib.h:50
count_routes_in_fib_at_prefix_length_arg_t::count_by_prefix_length
u64 count_by_prefix_length[129]
Definition: ip6_fib.c:616
format_fib_table_name
u8 * format_fib_table_name(u8 *s, va_list *ap)
Format the description/name of the table.
Definition: fib_table.c:1379
FIB_ENTRY_FLAG_ATTACHED
@ FIB_ENTRY_FLAG_ATTACHED
Definition: fib_entry.h:114
vlib_cli_command_t::path
char * path
Definition: cli.h:96
clib_bihash_kv_24_8_t
Definition: bihash_24_8.h:40
FIB_NODE_INDEX_INVALID
#define FIB_NODE_INDEX_INVALID
Definition: fib_types.h:30
fib_table_get_num_entries
u32 fib_table_get_num_entries(u32 fib_index, fib_protocol_t proto, fib_source_t source)
Return the number of entries in the FIB added by a given source.
Definition: fib_table.c:1367
fib_prefix_t_::fp_len
u16 fp_len
The mask length.
Definition: fib_types.h:206
vlib_call_init_function
#define vlib_call_init_function(vm, x)
Definition: init.h:259
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
ip6_ll_table_t_
A protocol Independent IP multicast FIB table.
Definition: ip6_ll_table.h:27
ip6_ll_table_lookup_exact_match
fib_node_index_t ip6_ll_table_lookup_exact_match(const ip6_ll_prefix_t *prefix)
Perfom an exact match in the non-forwarding table.
Definition: ip6_ll_table.c:43
vnet_get_sw_interface
static vnet_sw_interface_t * vnet_get_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
Definition: interface_funcs.h:58
ip6_ll_prefix_t_::ilp_sw_if_index
u32 ilp_sw_if_index
The interface.
Definition: ip6_ll_types.h:29
fib_table_walk
void fib_table_walk(u32 fib_index, fib_protocol_t proto, fib_table_walk_fn_t fn, void *ctx)
Walk all entries in a FIB table N.B: This is NOT safe to deletes.
Definition: fib_table.c:1239
ip6_ll_table_entry_delete
void ip6_ll_table_entry_delete(const ip6_ll_prefix_t *ilp)
Delete a IP6 link-local entry.
Definition: ip6_ll_table.c:140
ip6_ll_table_entry_update
fib_node_index_t ip6_ll_table_entry_update(const ip6_ll_prefix_t *ilp, fib_route_path_flags_t flags)
Update an entry in the table.
Definition: ip6_ll_table.c:106
unformat_input_t
struct _unformat_input_t unformat_input_t
ip6_ll_table.h
drop_dpo.h
h
h
Definition: flowhash_template.h:372
error
Definition: cJSON.c:88
ip6_ll_fib_create
static void ip6_ll_fib_create(u32 sw_if_index)
Definition: ip6_ll_table.c:50
mask_width
u8 mask_width
Definition: dhcp.api:204
unformat
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
fib_table_t_
A protocol Independent FIB table.
Definition: fib_table.h:71
vec_len
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
Definition: vec_bootstrap.h:142
len
u8 len
Definition: ip_types.api:103
vec_add1
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:606
vnet_get_main
vnet_main_t * vnet_get_main(void)
Definition: pnat_test_stubs.h:56
unformat_check_input
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:163
fib_table_t_::ft_locks
u32 * ft_locks
per-source number of locks on the table
Definition: fib_table.h:86
FIB_ENTRY_FLAG_NONE
@ FIB_ENTRY_FLAG_NONE
Definition: fib_entry.h:112
format_fib_source
u8 * format_fib_source(u8 *s, va_list *args)
Definition: fib_source.c:66
ip6_ll_prefix_to_fib
static void ip6_ll_prefix_to_fib(const ip6_ll_prefix_t *ilp, fib_prefix_t *fp)
Definition: ip6_ll_table.c:97
fib_node_index_t
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:29
vec_foreach_index
#define vec_foreach_index(var, v)
Iterate over vector indices.
Definition: vec_bootstrap.h:220
ip6_ll_table
static ip6_ll_table_t ip6_ll_table
There's only one IP6 link local table.
Definition: ip6_ll_table.c:25
ip6_show_fib_command
static vlib_cli_command_t ip6_show_fib_command
(constructor) VLIB_CLI_COMMAND (ip6_show_fib_command)
Definition: ip6_ll_table.c:349
fib_table_t_::ft_flags
fib_table_flags_t ft_flags
Table flags.
Definition: fib_table.h:81
vec_validate
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment)
Definition: vec.h:523
FIB_TABLE_FLAG_IP6_LL
@ FIB_TABLE_FLAG_IP6_LL
Definition: fib_table.h:61
VLIB_CLI_COMMAND
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:163
ip6_fib_table
ip6_fib_table_instance_t ip6_fib_table[IP6_FIB_NUM_TABLES]
The two FIB tables; fwding and non-fwding.
Definition: ip6_fib.c:23
count_routes_in_fib_at_prefix_length_arg_t
Definition: ip6_fib.c:614
ip6_ll_prefix_t_
Aggregate type for a prefix in the IPv6 Link-local table.
Definition: ip6_ll_types.h:24
ip6_lookup_init
static clib_error_t * ip6_lookup_init(vlib_main_t *vm)
Definition: ip6_forward.c:2791
FIB_ENTRY_FLAG_LOCAL
@ FIB_ENTRY_FLAG_LOCAL
Definition: fib_entry.h:117
vlib_cli_output
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:716
fib_prefix_t_::fp_addr
ip46_address_t fp_addr
The address type is not deriveable from the fp_addr member.
Definition: fib_types.h:225
ip6_ll_table_show_walk
static fib_table_walk_rc_t ip6_ll_table_show_walk(fib_node_index_t fib_entry_index, void *arg)
Definition: ip6_ll_table.c:178
vnet_main_t
Definition: vnet.h:76
vec_free
#define vec_free(V)
Free vector's memory (no header).
Definition: vec.h:395
ip6_ll_show_ctx_t
struct ip6_ll_show_ctx_t_ ip6_ll_show_ctx_t
ip6_fib_table_create_and_lock
u32 ip6_fib_table_create_and_lock(fib_source_t src, fib_table_flags_t flags, u8 *desc)
Definition: ip6_fib.c:119
fib_route_path_t_::frp_flags
fib_route_path_flags_t frp_flags
flags on the path
Definition: fib_types.h:609
u64
unsigned long u64
Definition: types.h:89
unformat_vnet_sw_interface
unformat_function_t unformat_vnet_sw_interface
Definition: interface_funcs.h:459
format
description fragment has unexpected format
Definition: map.api:433
ASSERT
#define ASSERT(truth)
Definition: error_bootstrap.h:69
fib_table_get
fib_table_t * fib_table_get(fib_node_index_t index, fib_protocol_t proto)
Get a pointer to a FIB table.
Definition: fib_table.c:29
DPO_PROTO_IP6
@ DPO_PROTO_IP6
Definition: dpo.h:65
FIB_ROUTE_PATH_FLAG_NONE
@ FIB_ROUTE_PATH_FLAG_NONE
Definition: fib_types.h:332
u32
unsigned int u32
Definition: types.h:88
VLIB_INIT_FUNCTION
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:172
fib_table_walk_rc_t
enum fib_table_walk_rc_t_ fib_table_walk_rc_t
return code controlling how a table walk proceeds
FIB_PROTOCOL_IP6
@ FIB_PROTOCOL_IP6
Definition: fib_types.h:37
ip6_ll_table_lookup
fib_node_index_t ip6_ll_table_lookup(const ip6_ll_prefix_t *prefix)
Perfom a longest prefix match in the non-forwarding table.
Definition: ip6_ll_table.c:36
fib_route_path_t_
A representation of a path as described by a route producer.
Definition: fib_types.h:500
ctx
long ctx[MAX_CONNS]
Definition: main.c:144
clib_bihash_kv_24_8_t::key
u64 key[3]
Definition: bihash_24_8.h:42
count_routes_in_fib_at_prefix_length
static int count_routes_in_fib_at_prefix_length(clib_bihash_kv_24_8_t *kvp, void *arg)
Definition: ip6_ll_table.c:215
vec_foreach
#define vec_foreach(var, vec)
Vector iterator.
Definition: vec_bootstrap.h:213
FIB_ENTRY_FORMAT_BRIEF
#define FIB_ENTRY_FORMAT_BRIEF
Definition: fib_entry.h:359
fib_prefix_t_::fp_proto
fib_protocol_t fp_proto
protocol type
Definition: fib_types.h:211
FIB_SOURCE_SPECIAL
@ FIB_SOURCE_SPECIAL
Special sources.
Definition: fib_source.h:45
ip6_fib.h
vec_sort_with_function
#define vec_sort_with_function(vec, f)
Sort a vector using the supplied element comparison function.
Definition: vec.h:1097
FIB_TABLE_WALK_CONTINUE
@ FIB_TABLE_WALK_CONTINUE
Continue on to the next entry.
Definition: fib_table.h:916
clib_memset
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
vlib_main_t
Definition: main.h:102
ip6_ll_table_show_all
static void ip6_ll_table_show_all(vlib_main_t *vm, u32 fib_index)
Definition: ip6_ll_table.c:188
ip6_fib_table_lookup
fib_node_index_t ip6_fib_table_lookup(u32 fib_index, const ip6_address_t *addr, u32 len)
Definition: ip6_fib.c:183
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
ip6_ll_show_fib
static clib_error_t * ip6_ll_show_fib(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: ip6_ll_table.c:231
vlib_init_function_t
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
Definition: init.h:51
fib_table_unlock
void fib_table_unlock(u32 fib_index, fib_protocol_t proto, fib_source_t source)
Take a reference counting lock on the table.
Definition: fib_table.c:1336
ip6_ll_fib_get
u32 ip6_ll_fib_get(u32 sw_if_index)
For use in the data plane.
Definition: ip6_ll_table.c:28
ip6_ll_table_show_one
static void ip6_ll_table_show_one(vlib_main_t *vm, ip6_ll_prefix_t *ilp, int detail)
Definition: ip6_ll_table.c:163
ip6_ll_prefix_t_::ilp_addr
ip6_address_t ilp_addr
the IP6 address
Definition: ip6_ll_types.h:34
fib_route_path_flags_t
enum fib_route_path_flags_t_ fib_route_path_flags_t
Path flags from the control plane.
fib_source_t
enum fib_source_t_ fib_source_t
The different sources that can create a route.
unformat_ip6_address
unformat_function_t unformat_ip6_address
Definition: format.h:89
fib_table_entry_delete_index
void fib_table_entry_delete_index(fib_node_index_t fib_entry_index, fib_source_t source)
Delete a FIB entry.
Definition: fib_table.c:919
vlib_cli_command_t
Definition: cli.h:92
sw_if_index
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
fib_prefix_t_
Aggregate type for a prefix.
Definition: fib_types.h:202
FIB_ROUTE_PATH_LOCAL
@ FIB_ROUTE_PATH_LOCAL
A for-us/local path.
Definition: fib_types.h:344
fib_table_entry_update
fib_node_index_t fib_table_entry_update(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source, fib_entry_flag_t flags, fib_route_path_t *paths)
Update an entry to have a new set of paths.
Definition: fib_table.c:765
UNFORMAT_END_OF_INPUT
#define UNFORMAT_END_OF_INPUT
Definition: format.h:137
prefix
vl_api_prefix_t prefix
Definition: ip.api:146
format_vnet_sw_interface_name
format_function_t format_vnet_sw_interface_name
Definition: interface_funcs.h:453
ip6_fib_table_instance_t_::ip6_hash
clib_bihash_24_8_t ip6_hash
Definition: ip6_fib.h:61
flags
vl_api_wireguard_peer_flags_t flags
Definition: wireguard.api:105
FIB_ENTRY_FLAG_NO_ATTACHED_EXPORT
@ FIB_ENTRY_FLAG_NO_ATTACHED_EXPORT
Definition: fib_entry.h:119
format_fib_entry
u8 * format_fib_entry(u8 *s, va_list *args)
Definition: fib_entry.c:130