2 * Copyright (c) 2015 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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 * ip/ip_lookup.c: ip4/6 adjacency and lookup table managment
18 * Copyright (c) 2008 Eliot Dresselhaus
20 * Permission is hereby granted, free of charge, to any person obtaining
21 * a copy of this software and associated documentation files (the
22 * "Software"), to deal in the Software without restriction, including
23 * without limitation the rights to use, copy, modify, merge, publish,
24 * distribute, sublicense, and/or sell copies of the Software, and to
25 * permit persons to whom the Software is furnished to do so, subject to
26 * the following conditions:
28 * The above copyright notice and this permission notice shall be
29 * included in all copies or substantial portions of the Software.
31 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
32 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
33 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
34 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
35 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
36 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
37 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
40 #include <vnet/ip/ip.h>
41 #include <vnet/adj/adj.h>
42 #include <vnet/fib/fib_table.h>
43 #include <vnet/fib/ip4_fib.h>
44 #include <vnet/fib/ip6_fib.h>
45 #include <vnet/mpls/mpls.h>
46 #include <vnet/dpo/drop_dpo.h>
47 #include <vnet/dpo/classify_dpo.h>
48 #include <vnet/dpo/punt_dpo.h>
49 #include <vnet/dpo/receive_dpo.h>
53 * @brief IPv4 and IPv6 adjacency and lookup table managment.
58 ip_interface_address_add_del (ip_lookup_main_t * lm,
63 u32 * result_if_address_index)
65 vnet_main_t * vnm = vnet_get_main();
66 ip_interface_address_t * a, * prev, * next;
67 uword * p = mhash_get (&lm->address_to_if_address_index, addr_fib);
69 vec_validate_init_empty (lm->if_address_pool_index_by_sw_if_index, sw_if_index, ~0);
70 a = p ? pool_elt_at_index (lm->if_address_pool, p[0]) : 0;
72 /* Verify given length. */
73 if ((a && (address_length != a->address_length)) || (address_length == 0))
75 vnm->api_errno = VNET_API_ERROR_ADDRESS_LENGTH_MISMATCH;
76 return clib_error_create
77 ( "%U wrong length (expected %d) for interface %U",
78 lm->format_address_and_length, addr_fib,
79 address_length, a? a->address_length : -1,
80 format_vnet_sw_if_index_name, vnm, sw_if_index);
87 vnet_sw_interface_t * si = vnet_get_sw_interface (vnm, sw_if_index);
88 vnm->api_errno = VNET_API_ERROR_ADDRESS_NOT_FOUND_FOR_INTERFACE;
89 return clib_error_create ("%U not found for interface %U",
90 lm->format_address_and_length,
91 addr_fib, address_length,
92 format_vnet_sw_interface_name, vnm, si);
95 if (a->prev_this_sw_interface != ~0)
97 prev = pool_elt_at_index (lm->if_address_pool, a->prev_this_sw_interface);
98 prev->next_this_sw_interface = a->next_this_sw_interface;
100 if (a->next_this_sw_interface != ~0)
102 next = pool_elt_at_index (lm->if_address_pool, a->next_this_sw_interface);
103 next->prev_this_sw_interface = a->prev_this_sw_interface;
105 if(a->prev_this_sw_interface == ~0)
106 lm->if_address_pool_index_by_sw_if_index[sw_if_index] = a->next_this_sw_interface;
109 if ((a->next_this_sw_interface == ~0) && (a->prev_this_sw_interface == ~0))
110 lm->if_address_pool_index_by_sw_if_index[sw_if_index] = ~0;
112 mhash_unset (&lm->address_to_if_address_index, addr_fib,
114 pool_put (lm->if_address_pool, a);
116 if (result_if_address_index)
117 *result_if_address_index = ~0;
122 u32 pi; /* previous index */
124 u32 hi; /* head index */
126 pool_get (lm->if_address_pool, a);
127 memset (a, ~0, sizeof (a[0]));
128 ai = a - lm->if_address_pool;
130 hi = pi = lm->if_address_pool_index_by_sw_if_index[sw_if_index];
132 while (pi != (u32)~0)
134 prev = pool_elt_at_index(lm->if_address_pool, pi);
135 pi = prev->next_this_sw_interface;
137 pi = prev ? prev - lm->if_address_pool : (u32)~0;
139 a->address_key = mhash_set (&lm->address_to_if_address_index,
140 addr_fib, ai, /* old_value */ 0);
141 a->address_length = address_length;
142 a->sw_if_index = sw_if_index;
144 a->prev_this_sw_interface = pi;
145 a->next_this_sw_interface = ~0;
147 prev->next_this_sw_interface = ai;
149 lm->if_address_pool_index_by_sw_if_index[sw_if_index] =
150 (hi != ~0) ? hi : ai;
151 if (result_if_address_index)
152 *result_if_address_index = ai;
156 if (result_if_address_index)
157 *result_if_address_index = a - lm->if_address_pool;
161 return /* no error */ 0;
164 void ip_lookup_init (ip_lookup_main_t * lm, u32 is_ip6)
166 /* ensure that adjacency is cacheline aligned and sized */
167 ASSERT(STRUCT_OFFSET_OF(ip_adjacency_t, cacheline0) == 0);
168 ASSERT(STRUCT_OFFSET_OF(ip_adjacency_t, cacheline1) == CLIB_CACHE_LINE_BYTES);
170 /* Preallocate three "special" adjacencies */
171 lm->adjacency_heap = adj_pool;
173 if (! lm->fib_result_n_bytes)
174 lm->fib_result_n_bytes = sizeof (uword);
179 lm->format_address_and_length = format_ip6_address_and_length;
180 mhash_init (&lm->address_to_if_address_index, sizeof (uword),
181 sizeof (ip6_address_fib_t));
185 lm->format_address_and_length = format_ip4_address_and_length;
186 mhash_init (&lm->address_to_if_address_index, sizeof (uword),
187 sizeof (ip4_address_fib_t));
193 /* Setup all IP protocols to be punted and builtin-unknown. */
194 for (i = 0; i < 256; i++)
196 lm->local_next_by_ip_protocol[i] = IP_LOCAL_NEXT_PUNT;
197 lm->builtin_protocol_by_ip_protocol[i] = IP_BUILTIN_PROTOCOL_UNKNOWN;
200 lm->local_next_by_ip_protocol[IP_PROTOCOL_UDP] = IP_LOCAL_NEXT_UDP_LOOKUP;
201 lm->local_next_by_ip_protocol[is_ip6 ? IP_PROTOCOL_ICMP6 : IP_PROTOCOL_ICMP] = IP_LOCAL_NEXT_ICMP;
202 lm->builtin_protocol_by_ip_protocol[IP_PROTOCOL_UDP] = IP_BUILTIN_PROTOCOL_UDP;
203 lm->builtin_protocol_by_ip_protocol[is_ip6 ? IP_PROTOCOL_ICMP6 : IP_PROTOCOL_ICMP] = IP_BUILTIN_PROTOCOL_ICMP;
207 u8 * format_ip_flow_hash_config (u8 * s, va_list * args)
209 flow_hash_config_t flow_hash_config = va_arg (*args, u32);
211 #define _(n,v) if (flow_hash_config & v) s = format (s, "%s ", #n);
212 foreach_flow_hash_bit;
218 u8 * format_ip_lookup_next (u8 * s, va_list * args)
220 ip_lookup_next_t n = va_arg (*args, ip_lookup_next_t);
226 s = format (s, "unknown %d", n);
229 case IP_LOOKUP_NEXT_DROP: t = "drop"; break;
230 case IP_LOOKUP_NEXT_PUNT: t = "punt"; break;
231 case IP_LOOKUP_NEXT_ARP: t = "arp"; break;
232 case IP_LOOKUP_NEXT_MIDCHAIN: t="midchain"; break;
233 case IP_LOOKUP_NEXT_GLEAN: t="glean"; break;
234 case IP_LOOKUP_NEXT_REWRITE:
239 vec_add (s, t, strlen (t));
244 u8 * format_ip_adjacency_packet_data (u8 * s, va_list * args)
246 vnet_main_t * vnm = va_arg (*args, vnet_main_t *);
247 u32 adj_index = va_arg (*args, u32);
248 u8 * packet_data = va_arg (*args, u8 *);
249 u32 n_packet_data_bytes = va_arg (*args, u32);
250 ip_adjacency_t * adj = adj_get(adj_index);
252 switch (adj->lookup_next_index)
254 case IP_LOOKUP_NEXT_REWRITE:
256 format_vnet_rewrite_header,
257 vnm->vlib_main, &adj->rewrite_header, packet_data, n_packet_data_bytes);
267 static uword unformat_dpo (unformat_input_t * input, va_list * args)
269 dpo_id_t *dpo = va_arg (*args, dpo_id_t *);
270 fib_protocol_t fp = va_arg (*args, int);
273 proto = fib_proto_to_dpo(fp);
275 if (unformat (input, "drop"))
276 dpo_copy(dpo, drop_dpo_get(proto));
277 else if (unformat (input, "punt"))
278 dpo_copy(dpo, punt_dpo_get(proto));
279 else if (unformat (input, "local"))
280 receive_dpo_add_or_lock(proto, ~0, NULL, dpo);
281 else if (unformat (input, "classify"))
283 u32 classify_table_index;
285 if (!unformat (input, "%d", &classify_table_index))
287 clib_warning ("classify adj must specify table index");
291 dpo_set(dpo, DPO_CLASSIFY, proto,
292 classify_dpo_create(fp, classify_table_index));
300 const ip46_address_t zero_addr = {
307 fib_table_id_find_fib_index (fib_protocol_t proto,
310 ip4_main_t *im4 = &ip4_main;
311 ip6_main_t *im6 = &ip6_main;
316 case FIB_PROTOCOL_IP4:
317 p = hash_get(im4->fib_index_by_table_id, table_id);
319 case FIB_PROTOCOL_IP6:
320 p = hash_get(im6->fib_index_by_table_id, table_id);
334 vnet_ip_route_cmd (vlib_main_t * vm,
335 unformat_input_t * main_input,
336 vlib_cli_command_t * cmd)
338 unformat_input_t _line_input, * line_input = &_line_input;
339 fib_route_path_t *rpaths = NULL, rpath;
340 dpo_id_t dpo = DPO_NULL, *dpos = NULL;
341 fib_prefix_t *prefixs = NULL, pfx;
342 clib_error_t * error = NULL;
343 mpls_label_t out_label;
344 u32 table_id, is_del;
350 vnm = vnet_get_main();
354 memset(&pfx, 0, sizeof(pfx));
356 /* Get a line of input. */
357 if (! unformat_user (main_input, unformat_line_input, line_input))
360 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
362 memset(&rpath, 0, sizeof(rpath));
364 if (unformat (line_input, "table %d", &table_id))
366 else if (unformat (line_input, "del"))
368 else if (unformat (line_input, "add"))
370 else if (unformat (line_input, "resolve-via-host"))
372 if (vec_len(rpaths) == 0)
374 error = clib_error_return(0 , "Paths then flags");
377 rpaths[vec_len(rpaths)-1].frp_flags |= FIB_ROUTE_PATH_RESOLVE_VIA_HOST;
379 else if (unformat (line_input, "resolve-via-attached"))
381 if (vec_len(rpaths) == 0)
383 error = clib_error_return(0 , "Paths then flags");
386 rpaths[vec_len(rpaths)-1].frp_flags |=
387 FIB_ROUTE_PATH_RESOLVE_VIA_ATTACHED;
389 else if (unformat (line_input, "out-label %U",
390 unformat_mpls_unicast_label, &out_label))
392 if (vec_len(rpaths) == 0)
394 error = clib_error_return(0 , "Paths then labels");
397 rpaths[vec_len(rpaths)-1].frp_label = out_label;
399 else if (unformat (line_input, "count %f", &count))
402 else if (unformat (line_input, "%U/%d",
403 unformat_ip4_address,
407 pfx.fp_proto = FIB_PROTOCOL_IP4;
408 vec_add1(prefixs, pfx);
410 else if (unformat (line_input, "%U/%d",
411 unformat_ip6_address,
415 pfx.fp_proto = FIB_PROTOCOL_IP6;
416 vec_add1(prefixs, pfx);
418 else if (unformat (line_input, "via %U %U weight %u",
419 unformat_ip4_address,
421 unformat_vnet_sw_interface, vnm,
422 &rpath.frp_sw_if_index,
425 rpath.frp_label = MPLS_LABEL_INVALID;
426 rpath.frp_proto = FIB_PROTOCOL_IP4;
427 vec_add1(rpaths, rpath);
430 else if (unformat (line_input, "via %U %U weight %u",
431 unformat_ip6_address,
433 unformat_vnet_sw_interface, vnm,
434 &rpath.frp_sw_if_index,
437 rpath.frp_label = MPLS_LABEL_INVALID;
438 rpath.frp_proto = FIB_PROTOCOL_IP6;
439 vec_add1(rpaths, rpath);
442 else if (unformat (line_input, "via %U %U",
443 unformat_ip4_address,
445 unformat_vnet_sw_interface, vnm,
446 &rpath.frp_sw_if_index))
448 rpath.frp_label = MPLS_LABEL_INVALID;
449 rpath.frp_weight = 1;
450 rpath.frp_proto = FIB_PROTOCOL_IP4;
451 vec_add1(rpaths, rpath);
454 else if (unformat (line_input, "via %U %U",
455 unformat_ip6_address,
457 unformat_vnet_sw_interface, vnm,
458 &rpath.frp_sw_if_index))
460 rpath.frp_label = MPLS_LABEL_INVALID;
461 rpath.frp_weight = 1;
462 rpath.frp_proto = FIB_PROTOCOL_IP6;
463 vec_add1(rpaths, rpath);
465 else if (unformat (line_input, "via %U next-hop-table %d",
466 unformat_ip4_address,
468 &rpath.frp_fib_index))
470 rpath.frp_weight = 1;
471 rpath.frp_sw_if_index = ~0;
472 rpath.frp_label = MPLS_LABEL_INVALID;
473 rpath.frp_proto = FIB_PROTOCOL_IP4;
474 vec_add1(rpaths, rpath);
476 else if (unformat (line_input, "via %U next-hop-table %d",
477 unformat_ip6_address,
479 &rpath.frp_fib_index))
481 rpath.frp_weight = 1;
482 rpath.frp_sw_if_index = ~0;
483 rpath.frp_label = MPLS_LABEL_INVALID;
484 rpath.frp_proto = FIB_PROTOCOL_IP6;
485 vec_add1(rpaths, rpath);
487 else if (unformat (line_input, "via %U",
488 unformat_ip4_address,
489 &rpath.frp_addr.ip4))
492 * the recursive next-hops are by default in the same table
495 rpath.frp_fib_index = table_id;
496 rpath.frp_weight = 1;
497 rpath.frp_sw_if_index = ~0;
498 rpath.frp_label = MPLS_LABEL_INVALID;
499 rpath.frp_proto = FIB_PROTOCOL_IP4;
500 vec_add1(rpaths, rpath);
502 else if (unformat (line_input, "via %U",
503 unformat_ip6_address,
504 &rpath.frp_addr.ip6))
506 rpath.frp_fib_index = table_id;
507 rpath.frp_weight = 1;
508 rpath.frp_sw_if_index = ~0;
509 rpath.frp_label = MPLS_LABEL_INVALID;
510 rpath.frp_proto = FIB_PROTOCOL_IP6;
511 vec_add1(rpaths, rpath);
513 else if (unformat (line_input,
514 "lookup in table %d",
515 &rpath.frp_fib_index))
517 rpath.frp_label = MPLS_LABEL_INVALID;
518 rpath.frp_proto = pfx.fp_proto;
519 rpath.frp_sw_if_index = ~0;
520 vec_add1(rpaths, rpath);
522 else if (vec_len (prefixs) > 0 &&
523 unformat (line_input, "via %U",
524 unformat_dpo, &dpo, prefixs[0].fp_proto))
526 rpath.frp_label = MPLS_LABEL_INVALID;
527 vec_add1 (dpos, dpo);
531 error = unformat_parse_error (line_input);
536 unformat_free (line_input);
538 if (vec_len (prefixs) == 0)
540 error = clib_error_return (0, "expected ip4/ip6 destination address/length.");
544 if (!is_del && vec_len (rpaths) + vec_len (dpos) == 0)
546 error = clib_error_return (0, "expected paths.");
553 * if no table_id is passed we will manipulate the default
559 fib_index = fib_table_id_find_fib_index(prefixs[0].fp_proto,
564 error = clib_error_return (0,
565 "Nonexistent table id %d",
571 for (i = 0; i < vec_len (prefixs); i++)
573 if (is_del && 0 == vec_len (rpaths))
575 fib_table_entry_delete(fib_index,
579 else if (!is_del && 1 == vec_len (dpos))
581 fib_table_entry_special_dpo_add(fib_index,
584 FIB_ENTRY_FLAG_EXCLUSIVE,
588 else if (vec_len (dpos) > 0)
590 error = clib_error_return(0 , "Load-balancing over multiple special adjacencies is unsupported");
593 else if (0 < vec_len (rpaths))
596 ip46_address_t dst = prefixs[i].fp_addr;
599 t[0] = vlib_time_now (vm);
600 incr = 1 << ((FIB_PROTOCOL_IP4 == prefixs[0].fp_proto ? 32 : 128) -
603 for (k = 0; k < n; k++)
605 for (j = 0; j < vec_len (rpaths); j++)
609 * the CLI parsing stored table Ids, swap to FIB indicies
611 fi = fib_table_id_find_fib_index(prefixs[i].fp_proto,
612 rpaths[i].frp_fib_index);
616 error = clib_error_return(0 , "Via table %d does not exist",
617 rpaths[i].frp_fib_index);
620 rpaths[i].frp_fib_index = fi;
622 fib_prefix_t rpfx = {
623 .fp_len = prefixs[i].fp_len,
624 .fp_proto = prefixs[i].fp_proto,
629 fib_table_entry_path_remove2(fib_index,
634 fib_table_entry_path_add2(fib_index,
641 if (FIB_PROTOCOL_IP4 == prefixs[0].fp_proto)
644 clib_host_to_net_u32(incr +
645 clib_net_to_host_u32 (dst.ip4.as_u32));
649 int bucket = (incr < 64 ? 0 : 1);
650 dst.ip6.as_u64[bucket] =
651 clib_host_to_net_u64(incr +
652 clib_net_to_host_u64 (
653 dst.ip6.as_u64[bucket]));
657 t[1] = vlib_time_now (vm);
659 vlib_cli_output (vm, "%.6e routes/sec", count / (t[1] - t[0]));
663 error = clib_error_return(0 , "Don't understand what you want...");
676 VLIB_CLI_COMMAND (vlib_cli_ip_command, static) = {
678 .short_help = "Internet protocol (IP) commands",
681 VLIB_CLI_COMMAND (vlib_cli_ip6_command, static) = {
683 .short_help = "Internet protocol version 6 (IPv6) commands",
686 VLIB_CLI_COMMAND (vlib_cli_show_ip_command, static) = {
688 .short_help = "Internet protocol (IP) show commands",
691 VLIB_CLI_COMMAND (vlib_cli_show_ip6_command, static) = {
693 .short_help = "Internet protocol version 6 (IPv6) show commands",
697 * This command is used to add or delete IPv4 or IPv6 routes. All
698 * IP Addresses ('<em><dst-ip-addr>/<width></em>',
699 * '<em><next-hop-ip-addr></em>' and '<em><adj-hop-ip-addr></em>')
700 * can be IPv4 or IPv6, but all must be of the same form in a single
701 * command. To display the current set of routes, use the commands
702 * '<em>show ip fib</em>' and '<em>show ip6 fib</em>'.
705 * Example of how to add a straight forward static route:
706 * @cliexcmd{ip route add 6.0.1.2/32 via 6.0.0.1 GigabitEthernet2/0/0}
707 * Example of how to delete a straight forward static route:
708 * @cliexcmd{ip route del 6.0.1.2/32 via 6.0.0.1 GigabitEthernet2/0/0}
709 * Mainly for route add/del performance testing, one can add or delete
710 * multiple routes by adding 'count N' to the previous item:
711 * @cliexcmd{ip route add count 10 7.0.0.0/24 via 6.0.0.1 GigabitEthernet2/0/0}
712 * Add multiple routes for the same destination to create equal-cost multipath:
713 * @cliexcmd{ip route add 7.0.0.1/32 via 6.0.0.1 GigabitEthernet2/0/0}
714 * @cliexcmd{ip route add 7.0.0.1/32 via 6.0.0.2 GigabitEthernet2/0/0}
715 * For unequal-cost multipath, specify the desired weights. This
716 * combination of weights results in 3/4 of the traffic following the
717 * second path, 1/4 following the first path:
718 * @cliexcmd{ip route add 7.0.0.1/32 via 6.0.0.1 GigabitEthernet2/0/0 weight 1}
719 * @cliexcmd{ip route add 7.0.0.1/32 via 6.0.0.2 GigabitEthernet2/0/0 weight 3}
720 * To add a route to a particular FIB table (VRF), use:
721 * @cliexcmd{ip route add 172.16.24.0/24 table 7 via GigabitEthernet2/0/0}
724 VLIB_CLI_COMMAND (ip_route_command, static) = {
726 .short_help = "ip route [add|del] [count <n>] <dst-ip-addr>/<width> [table <table-id>] [via <next-hop-ip-addr> [<interface>] [weight <weight>]] | [via arp <interface> <adj-hop-ip-addr>] | [via drop|punt|local<id>|arp|classify <classify-idx>] [lookup in table <out-table-id>]",
727 .function = vnet_ip_route_cmd,
733 * The next two routines address a longstanding script hemorrhoid.
734 * Probing a v4 or v6 neighbor needs to appear to be synchronous,
735 * or dependent route-adds will simply fail.
737 static clib_error_t *
738 ip6_probe_neighbor_wait (vlib_main_t *vm, ip6_address_t * a, u32 sw_if_index,
741 vnet_main_t * vnm = vnet_get_main();
746 uword *event_data = 0;
748 ASSERT (vlib_in_process_context(vm));
751 vnet_register_ip6_neighbor_resolution_event
752 (vnm, a, vlib_get_current_process (vm)->node_runtime.node_index,
753 1 /* event */, 0 /* data */);
755 for (i = 0; i < retry_count; i++)
757 /* The interface may be down, etc. */
758 e = ip6_probe_neighbor (vm, a, sw_if_index);
763 vlib_process_wait_for_event_or_clock (vm, 1.0);
764 event_type = vlib_process_get_events (vm, &event_data);
767 case 1: /* resolved... */
768 vlib_cli_output (vm, "Resolved %U",
769 format_ip6_address, a);
773 case ~0: /* timeout */
777 clib_warning ("unknown event_type %d", event_type);
779 vec_reset_length (event_data);
785 return clib_error_return (0, "Resolution failed for %U",
786 format_ip6_address, a);
790 static clib_error_t *
791 ip4_probe_neighbor_wait (vlib_main_t *vm, ip4_address_t * a, u32 sw_if_index,
794 vnet_main_t * vnm = vnet_get_main();
799 uword *event_data = 0;
801 ASSERT (vlib_in_process_context(vm));
804 vnet_register_ip4_arp_resolution_event
805 (vnm, a, vlib_get_current_process (vm)->node_runtime.node_index,
806 1 /* event */, 0 /* data */);
808 for (i = 0; i < retry_count; i++)
810 /* The interface may be down, etc. */
811 e = ip4_probe_neighbor (vm, a, sw_if_index);
816 vlib_process_wait_for_event_or_clock (vm, 1.0);
817 event_type = vlib_process_get_events (vm, &event_data);
820 case 1: /* resolved... */
821 vlib_cli_output (vm, "Resolved %U",
822 format_ip4_address, a);
826 case ~0: /* timeout */
830 clib_warning ("unknown event_type %d", event_type);
832 vec_reset_length (event_data);
837 vec_reset_length (event_data);
840 return clib_error_return (0, "Resolution failed for %U",
841 format_ip4_address, a);
845 static clib_error_t *
846 probe_neighbor_address (vlib_main_t * vm,
847 unformat_input_t * input,
848 vlib_cli_command_t * cmd)
850 vnet_main_t * vnm = vnet_get_main();
851 unformat_input_t _line_input, * line_input = &_line_input;
854 clib_error_t * error = 0;
855 u32 sw_if_index = ~0;
860 /* Get a line of input. */
861 if (! unformat_user (input, unformat_line_input, line_input))
864 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
866 if (unformat_user (line_input, unformat_vnet_sw_interface, vnm,
869 else if (unformat (line_input, "retry %d", &retry_count))
872 else if (unformat (line_input, "%U", unformat_ip4_address, &a4))
874 else if (unformat (line_input, "%U", unformat_ip6_address, &a6))
880 return clib_error_return (0, "unknown input '%U'",
881 format_unformat_error, line_input);
884 unformat_free (line_input);
886 if (sw_if_index == ~0)
887 return clib_error_return (0, "Interface required, not set.");
888 if (address_set == 0)
889 return clib_error_return (0, "ip address required, not set.");
891 return clib_error_return (0, "Multiple ip addresses not supported.");
894 error = ip4_probe_neighbor_wait (vm, &a4, sw_if_index, retry_count);
896 error = ip6_probe_neighbor_wait (vm, &a6, sw_if_index, retry_count);
902 * The '<em>ip probe-neighbor</em>' command ARPs for IPv4 addresses or
903 * attempts IPv6 neighbor discovery depending on the supplied IP address
906 * @note This command will not immediately affect the indicated FIB; it
907 * is not suitable for use in establishing a FIB entry prior to adding
908 * recursive FIB entries. As in: don't use it in a script to probe a
909 * gateway prior to adding a default route. It won't work. Instead,
910 * configure a static ARP cache entry [see '<em>set ip arp</em>'], or
911 * a static IPv6 neighbor [see '<em>set ip6 neighbor</em>'].
914 * Example of probe for an IPv4 address:
915 * @cliexcmd{ip probe-neighbor GigabitEthernet2/0/0 172.16.1.2}
918 VLIB_CLI_COMMAND (ip_probe_neighbor_command, static) = {
919 .path = "ip probe-neighbor",
920 .function = probe_neighbor_address,
921 .short_help = "ip probe-neighbor <interface> <ip4-addr> | <ip6-addr> [retry nn]",