FD.io VPP  v19.01.3-6-g70449b9b9
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 {
30  ASSERT (vec_len (ip6_ll_table.ilt_fibs) > sw_if_index);
31 
32  return (ip6_ll_table.ilt_fibs[sw_if_index]);
33 }
34 
37 {
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",
57  vnm, vnet_get_sw_interface (vnm, sw_if_index));
58 
59  ip6_ll_table.ilt_fibs[sw_if_index] =
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  };
81  ip6_ll_table.ilt_fibs[sw_if_index],
82  &pfx,
87  NULL,
88  sw_if_index,
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 }
103 
107 {
108  fib_node_index_t ip6_ll_entry_index;
109  fib_route_path_t *rpaths, rpath = {
110  .frp_flags = flags,
111  .frp_sw_if_index = ilp->ilp_sw_if_index,
112  .frp_proto = DPO_PROTO_IP6,
113  };
114  fib_prefix_t fp;
115 
116  vec_validate (ip6_ll_table.ilt_fibs, ilp->ilp_sw_if_index);
117 
118  if (0 == ip6_ll_fib_get (ilp->ilp_sw_if_index))
119  {
121  }
122 
123  rpaths = NULL;
124  vec_add1 (rpaths, rpath);
125 
126  ip6_ll_prefix_to_fib (ilp, &fp);
127  ip6_ll_entry_index =
130  (flags & FIB_ROUTE_PATH_LOCAL ?
132  rpaths);
133  vec_free (rpaths);
134 
135  return (ip6_ll_entry_index);
136 }
137 
138 void
140 {
141  fib_node_index_t ip6_ll_entry_index;
142  u32 fib_index;
143 
144  ip6_ll_entry_index = ip6_ll_table_lookup_exact_match (ilp);
145 
146  if (FIB_NODE_INDEX_INVALID != ip6_ll_entry_index)
147  fib_table_entry_delete_index (ip6_ll_entry_index, FIB_SOURCE_IP6_ND);
148 
149  /*
150  * if there are no ND sourced prefixes left, then we can clean up this FIB
151  */
152  fib_index = ip6_ll_fib_get (ilp->ilp_sw_if_index);
153  if (0 == fib_table_get_num_entries (fib_index,
155  {
157  ip6_ll_table.ilt_fibs[ilp->ilp_sw_if_index] = 0;
158  }
159 }
160 
161 static void
163 {
164  vlib_cli_output (vm, "%U",
166  ip6_ll_table_lookup (ilp),
167  (detail ?
169 }
170 
171 typedef struct ip6_ll_show_ctx_t_
172 {
175 
176 static fib_table_walk_rc_t
177 ip6_ll_table_show_walk (fib_node_index_t fib_entry_index, void *arg)
178 {
179  ip6_ll_show_ctx_t *ctx = arg;
180 
181  vec_add1 (ctx->entries, fib_entry_index);
182 
183  return (FIB_TABLE_WALK_CONTINUE);
184 }
185 
186 static void
188 {
189  fib_node_index_t *fib_entry_index;
191  .entries = NULL,
192  };
193 
196 
197  vec_foreach (fib_entry_index, ctx.entries)
198  {
199  vlib_cli_output (vm, "%U",
201  *fib_entry_index, FIB_ENTRY_FORMAT_BRIEF);
202  }
203 
204  vec_free (ctx.entries);
205 }
206 
207 typedef struct
208 {
209  u32 fib_index;
210  u64 count_by_prefix_length[129];
212 
213 static void
214 count_routes_in_fib_at_prefix_length (BVT (clib_bihash_kv) * kvp, void *arg)
215 {
217  int mask_width;
218 
219  if ((kvp->key[2] >> 32) != ap->fib_index)
220  return;
221 
222  mask_width = kvp->key[2] & 0xFF;
223 
225 }
226 
227 static clib_error_t *
229  unformat_input_t * input, vlib_cli_command_t * cmd)
230 {
232  ip6_main_t *im6 = &ip6_main;
233  fib_table_t *fib_table;
234  int verbose, matching;
235  ip6_address_t matching_address;
236  u32 mask_len = 128;
237  u32 sw_if_index = ~0;
238  int detail = 0;
239  vnet_main_t *vnm = vnet_get_main ();
240  u32 fib_index;
241 
242  verbose = 1;
243  matching = 0;
244 
246  {
247  if (unformat (input, "brief") ||
248  unformat (input, "summary") || unformat (input, "sum"))
249  verbose = 0;
250 
251  else if (unformat (input, "detail") || unformat (input, "det"))
252  detail = 1;
253 
254  else if (unformat (input, "%U/%d",
255  unformat_ip6_address, &matching_address, &mask_len))
256  matching = 1;
257 
258  else
259  if (unformat (input, "%U", unformat_ip6_address, &matching_address))
260  matching = 1;
261  else if (unformat (input, "%U",
262  unformat_vnet_sw_interface, vnm, &sw_if_index))
263  ;
264  else
265  break;
266  }
267 
268  vec_foreach_index (sw_if_index, ip6_ll_table.ilt_fibs)
269  {
270  fib_source_t source;
271  u8 *s = NULL;
272 
273  fib_index = ip6_ll_table.ilt_fibs[sw_if_index];
274 
275  if (0 == fib_index)
276  continue;
277 
278  fib_table = fib_table_get (fib_index, FIB_PROTOCOL_IP6);
279 
280  if (!(fib_table->ft_flags & FIB_TABLE_FLAG_IP6_LL))
281  continue;
282 
283  s = format (s, "%U, fib_index:%d, locks:[",
284  format_fib_table_name, fib_index,
285  FIB_PROTOCOL_IP6, fib_index);
286  FOR_EACH_FIB_SOURCE (source)
287  {
288  if (0 != fib_table->ft_locks[source])
289  {
290  s = format (s, "%U:%d, ",
291  format_fib_source, source, fib_table->ft_locks[source]);
292  }
293  }
294  s = format (s, "]");
295  vlib_cli_output (vm, "%v", s);
296  vec_free (s);
297 
298  /* Show summary? */
299  if (!verbose)
300  {
301  clib_bihash_24_8_t *h =
303  int len;
304 
305  vlib_cli_output (vm, "%=20s%=16s", "Prefix length", "Count");
306 
307  clib_memset (ca, 0, sizeof (*ca));
308  ca->fib_index = fib_index;
309 
310  clib_bihash_foreach_key_value_pair_24_8
312 
313  for (len = 128; len >= 0; len--)
314  {
315  if (ca->count_by_prefix_length[len])
316  vlib_cli_output (vm, "%=20d%=16lld",
317  len, ca->count_by_prefix_length[len]);
318  }
319  continue;
320  }
321 
322  if (!matching)
323  {
324  ip6_ll_table_show_all (vm, fib_index);
325  }
326  else
327  {
328  if (~0 == sw_if_index)
329  {
330  vlib_cli_output (vm, "specify the interface");
331  }
332  else
333  {
334  ip6_ll_prefix_t ilp = {
335  .ilp_addr = matching_address,
336  .ilp_sw_if_index = sw_if_index,
337  };
338  ip6_ll_table_show_one (vm, &ilp, detail);
339  }
340  }
341  };
342 
343  return 0;
344 }
345 
346 /* *INDENT-OFF* */
347 VLIB_CLI_COMMAND (ip6_show_fib_command, static) = {
348  .path = "show ip6-ll",
349  .short_help = "show ip6-ll [summary] [interface] [<ip6-addr>[/<width>]] [detail]",
350  .function = ip6_ll_show_fib,
351 };
352 /* *INDENT-ON* */
353 
354 static clib_error_t *
356 {
357  clib_error_t *error;
358 
360 
361  return (error);
362 }
363 
365 
366 /*
367  * fd.io coding-style-patch-verification: ON
368  *
369  * Local Variables:
370  * eval: (c-set-style "gnu")
371  * End:
372  */
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:439
fib_protocol_t fp_proto
protocol type
Definition: fib_types.h:212
u8 * format_fib_entry(u8 *s, va_list *args)
Definition: fib_entry.c:139
#define vec_foreach_index(var, v)
Iterate over vector indices.
Continue on to the next entry.
Definition: fib_table.h:868
static void count_routes_in_fib_at_prefix_length(BVT(clib_bihash_kv) *kvp, void *arg)
Definition: ip6_ll_table.c:214
u32 flags
Definition: vhost_user.h:115
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
static void ip6_ll_table_show_all(vlib_main_t *vm, u32 fib_index)
Definition: ip6_ll_table.c:187
A representation of a path as described by a route producer.
Definition: fib_types.h:470
static void ip6_ll_fib_create(u32 sw_if_index)
Definition: ip6_ll_table.c:50
vnet_main_t * vnet_get_main(void)
Definition: misc.c:47
The table that stores ALL routes learned by the DP.
Definition: ip6.h:133
#define FIB_ENTRY_FORMAT_DETAIL
Definition: fib_entry.h:517
unsigned long u64
Definition: types.h:89
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:723
#define NULL
Definition: clib.h:58
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
static void ip6_ll_table_show_one(vlib_main_t *vm, ip6_ll_prefix_t *ilp, int detail)
Definition: ip6_ll_table.c:162
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:525
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
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
unformat_function_t unformat_vnet_sw_interface
Definition: fib_entry.h:277
unsigned char u8
Definition: types.h:56
static ip6_ll_table_t ip6_ll_table
There&#39;s only one IP6 link local table.
Definition: ip6_ll_table.c:25
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:772
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:177
fib_node_index_t ip6_fib_table_lookup_exact_match(u32 fib_index, const ip6_address_t *addr, u32 len)
Definition: ip6_fib.c:218
clib_bihash_24_8_t ip6_hash
Definition: ip6.h:144
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:163
u32 sw_if_index
Definition: vxlan_gbp.api:37
static BVT(clib_bihash)
Definition: adj_nbr.c:28
Aggregrate type for a prefix.
Definition: fib_types.h:203
enum fib_route_path_flags_t_ fib_route_path_flags_t
Path flags from the control plane.
unsigned int u32
Definition: types.h:88
u16 fp_len
The mask length.
Definition: fib_types.h:207
#define vlib_call_init_function(vm, x)
Definition: init.h:260
int fib_entry_cmp_for_sort(void *i1, void *i2)
Definition: fib_entry.c:1616
Definition: fib_entry.h:275
Definition: fib_entry.h:280
IPv6 ND (seen in the link-local tables)
Definition: fib_entry.h:102
format_function_t format_vnet_sw_interface_name
enum fib_source_t_ fib_source_t
The different sources that can create a route.
ip46_address_t fp_addr
The address type is not deriveable from the fp_addr member.
Definition: fib_types.h:226
u16 ft_locks[FIB_TABLE_N_LOCKS]
per-source number of locks on the table
Definition: fib_table.h:84
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:228
long ctx[MAX_CONNS]
Definition: main.c:144
struct _unformat_input_t unformat_input_t
static void ip6_ll_prefix_to_fib(const ip6_ll_prefix_t *ilp, fib_prefix_t *fp)
Definition: ip6_ll_table.c:97
u32 ip6_ll_fib_get(u32 sw_if_index)
For use in the data plane.
Definition: ip6_ll_table.c:28
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:1281
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:1237
u8 len
Definition: ip_types.api:49
unformat_function_t unformat_ip6_address
Definition: format.h:91
#define UNFORMAT_END_OF_INPUT
Definition: format.h:144
vlib_main_t * vm
Definition: buffer.c:301
u8 * format_fib_source(u8 *s, va_list *args)
Definition: fib_entry.c:99
uint32_t mask_width(const boost::asio::ip::address &addr)
Get the prefix mask length of a host route from the boost address.
Definition: prefix.cpp:242
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:877
enum fib_table_walk_rc_t_ fib_table_walk_rc_t
return code controlling how a table walk proceeds
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:341
u32 ip6_fib_table_create_and_lock(fib_source_t src, fib_table_flags_t flags, u8 *desc)
Definition: ip6_fib.c:113
#define FOR_EACH_FIB_SOURCE(_item)
Definition: fib_entry.h:185
fib_table_flags_t ft_flags
Table flags.
Definition: fib_table.h:79
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:30
u32 * ilt_fibs
A vector, indexed by sw_if_index, of unicast IPv6 FIBs.
Definition: ip6_ll_table.h:32
ip6_address_t ilp_addr
the IP6 address
Definition: ip6_ll_types.h:34
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:155
#define ASSERT(truth)
ip6_main_t ip6_main
Definition: ip6_forward.c:2624
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:1197
fib_node_index_t * entries
Definition: ip6_ll_table.c:173
fib_route_path_flags_t frp_flags
flags on the path
Definition: fib_types.h:571
Aggregrate type for a prefix in the IPv6 Link-local table.
Definition: ip6_ll_types.h:24
ip6_fib_table_instance_t ip6_table[IP6_FIB_NUM_TABLES]
The two FIB tables; fwding and non-fwding.
Definition: ip6.h:171
#define FIB_ENTRY_FORMAT_BRIEF
Definition: fib_entry.h:516
#define FIB_NODE_INDEX_INVALID
Definition: fib_types.h:31
A for-us/local path.
Definition: fib_types.h:332
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
#define vec_sort_with_function(vec, f)
Sort a vector using the supplied element comparison function.
Definition: vec.h:984
u32 ilp_sw_if_index
The interface.
Definition: ip6_ll_types.h:29
void ip6_ll_table_entry_delete(const ip6_ll_prefix_t *ilp)
Delete a IP6 link-local entry.
Definition: ip6_ll_table.c:139
Special sources.
Definition: fib_entry.h:40
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:27
typedef prefix
Definition: ip_types.api:35
static clib_error_t * ip6_ll_module_init(vlib_main_t *vm)
Definition: ip6_ll_table.c:355
u8 * format_fib_table_name(u8 *s, va_list *ap)
Format the description/name of the table.
Definition: fib_table.c:1293
#define FIB_ENTRY_FORMAT_DETAIL2
Definition: fib_entry.h:518
#define vec_foreach(var, vec)
Vector iterator.
fib_node_index_t ip6_fib_table_lookup(u32 fib_index, const ip6_address_t *addr, u32 len)
Definition: ip6_fib.c:172
A protocol Independent IP multicast FIB table.
Definition: ip6_ll_table.h:27
static clib_error_t * ip6_lookup_init(vlib_main_t *vm)
Definition: ip6_forward.c:2627
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:105
Definition: fib_entry.h:282
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:762
struct ip6_ll_show_ctx_t_ ip6_ll_show_ctx_t
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:170
A protocol Independent FIB table.
Definition: fib_table.h:69