diff options
author | Pavel Kotucek <pkotucek@cisco.com> | 2016-12-05 08:27:37 +0100 |
---|---|---|
committer | Damjan Marion <dmarion.lists@gmail.com> | 2016-12-06 12:08:46 +0000 |
commit | 3e046ea96e7e9d98a8dd67eab84031e1d71b4422 (patch) | |
tree | 3a1b3b25fd28808236fc4179f20d893aecac2ad7 /vnet | |
parent | 397fd7d39f023887e428de37a1929c366a99b8d5 (diff) |
api: missing support for dumping of neighbours (VPP-333)
added API to dump ipv4/ipv6 neighboors (added by ip_neighbor_add_del).
Change-Id: I33209a3d06beba64d68465c0892a9f4c65657334
Signed-off-by: Pavel Kotucek <pkotucek@cisco.com>
Diffstat (limited to 'vnet')
-rw-r--r-- | vnet/Makefile.am | 1 | ||||
-rw-r--r-- | vnet/vnet/ethernet/arp.c | 52 | ||||
-rw-r--r-- | vnet/vnet/ethernet/arp_packet.h | 22 | ||||
-rw-r--r-- | vnet/vnet/ip/ip6_neighbor.c | 47 | ||||
-rw-r--r-- | vnet/vnet/ip/ip6_neighbor.h | 42 |
5 files changed, 109 insertions, 55 deletions
diff --git a/vnet/Makefile.am b/vnet/Makefile.am index fc91bcd2a7a..7cf19eb8156 100644 --- a/vnet/Makefile.am +++ b/vnet/Makefile.am @@ -322,6 +322,7 @@ nobase_include_HEADERS += \ vnet/ip/ip6_hop_by_hop.h \ vnet/ip/ip6_hop_by_hop_packet.h \ vnet/ip/ip6_packet.h \ + vnet/ip/ip6_neighbor.h \ vnet/ip/ip.h \ vnet/ip/ip_packet.h \ vnet/ip/ip_source_and_port_range_check.h \ diff --git a/vnet/vnet/ethernet/arp.c b/vnet/vnet/ethernet/arp.c index 4968d7b780d..ec138586ff4 100644 --- a/vnet/vnet/ethernet/arp.c +++ b/vnet/vnet/ethernet/arp.c @@ -36,25 +36,6 @@ void vl_api_rpc_call_main_thread (void *fp, u8 * data, u32 data_length); -typedef struct -{ - u32 sw_if_index; - ip4_address_t ip4_address; - - u8 ethernet_address[6]; - - u16 flags; -#define ETHERNET_ARP_IP4_ENTRY_FLAG_STATIC (1 << 0) -#define ETHERNET_ARP_IP4_ENTRY_FLAG_DYNAMIC (1 << 1) - - u64 cpu_time_last_updated; - - /** - * The index of the adj-fib entry created - */ - fib_node_index_t fib_entry_index; -} ethernet_arp_ip4_entry_t; - /** * @brief Per-interface ARP configuration and state */ @@ -252,7 +233,7 @@ format_ethernet_arp_header (u8 * s, va_list * va) return s; } -static u8 * +u8 * format_ethernet_arp_ip4_entry (u8 * s, va_list * va) { vnet_main_t *vnm = va_arg (*va, vnet_main_t *); @@ -1284,6 +1265,25 @@ ip4_arp_entry_sort (void *a1, void *a2) return cmp; } +ethernet_arp_ip4_entry_t * +ip4_neighbor_entries (u32 sw_if_index) +{ + ethernet_arp_main_t *am = ðernet_arp_main; + ethernet_arp_ip4_entry_t *n, *ns = 0; + + /* *INDENT-OFF* */ + pool_foreach (n, am->ip4_entry_pool, ({ + if (sw_if_index != ~0 && n->sw_if_index != sw_if_index) + continue; + vec_add1 (ns, n[0]); + })); + /* *INDENT-ON* */ + + if (ns) + vec_sort_with_function (ns, ip4_arp_entry_sort); + return ns; +} + static clib_error_t * show_ip4_arp (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) @@ -1299,22 +1299,12 @@ show_ip4_arp (vlib_main_t * vm, sw_if_index = ~0; (void) unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index); - es = 0; - /* *INDENT-OFF* */ - pool_foreach (e, am->ip4_entry_pool, - ({ - vec_add1 (es, e[0]); - })); - /* *INDENT-ON* */ - + es = ip4_neighbor_entries (sw_if_index); if (es) { - vec_sort_with_function (es, ip4_arp_entry_sort); vlib_cli_output (vm, "%U", format_ethernet_arp_ip4_entry, vnm, 0); vec_foreach (e, es) { - if (sw_if_index != ~0 && e->sw_if_index != sw_if_index) - continue; vlib_cli_output (vm, "%U", format_ethernet_arp_ip4_entry, vnm, e); } vec_free (es); diff --git a/vnet/vnet/ethernet/arp_packet.h b/vnet/vnet/ethernet/arp_packet.h index 8befb6c5115..e762ffa4018 100644 --- a/vnet/vnet/ethernet/arp_packet.h +++ b/vnet/vnet/ethernet/arp_packet.h @@ -140,6 +140,28 @@ typedef struct }; } ethernet_arp_header_t; +typedef struct +{ + u32 sw_if_index; + ip4_address_t ip4_address; + + u8 ethernet_address[6]; + + u16 flags; +#define ETHERNET_ARP_IP4_ENTRY_FLAG_STATIC (1 << 0) +#define ETHERNET_ARP_IP4_ENTRY_FLAG_DYNAMIC (1 << 1) + + u64 cpu_time_last_updated; + + /** + * The index of the adj-fib entry created + */ + fib_node_index_t fib_entry_index; +} ethernet_arp_ip4_entry_t; + +ethernet_arp_ip4_entry_t *ip4_neighbor_entries (u32 sw_if_index); +u8 *format_ethernet_arp_ip4_entry (u8 * s, va_list * va); + #endif /* included_ethernet_arp_packet_h */ /* diff --git a/vnet/vnet/ip/ip6_neighbor.c b/vnet/vnet/ip/ip6_neighbor.c index 5380950ae6b..92417a44025 100644 --- a/vnet/vnet/ip/ip6_neighbor.c +++ b/vnet/vnet/ip/ip6_neighbor.c @@ -16,6 +16,7 @@ */ #include <vnet/ip/ip.h> +#include <vnet/ip/ip6_neighbor.h> #include <vnet/ethernet/ethernet.h> #include <vppinfra/mhash.h> #include <vppinfra/md5.h> @@ -31,26 +32,10 @@ * adjacency tables and neighbor discovery logic. */ -typedef struct { - ip6_address_t ip6_address; - u32 sw_if_index; - u32 pad; -} ip6_neighbor_key_t; - -/* can't use sizeof link_layer_address, that's 8 */ +/* can't use sizeof link_layer_address, that's 8 */ #define ETHER_MAC_ADDR_LEN 6 -typedef struct { - ip6_neighbor_key_t key; - u8 link_layer_address[8]; - u16 flags; -#define IP6_NEIGHBOR_FLAG_STATIC (1 << 0) -#define IP6_NEIGHBOR_FLAG_DYNAMIC (2 << 0) - u64 cpu_time_last_updated; - fib_node_index_t fib_entry_index; -} ip6_neighbor_t; - -/* advertised prefix option */ +/* advertised prefix option */ typedef struct { /* basic advertised information */ ip6_address_t prefix; @@ -737,13 +722,31 @@ ip6_neighbor_sort (void *a1, void *a2) return cmp; } +ip6_neighbor_t * +ip6_neighbors_entries (u32 sw_if_index) +{ + ip6_neighbor_main_t * nm = &ip6_neighbor_main; + ip6_neighbor_t *n, *ns = 0; + + /* *INDENT-OFF* */ + pool_foreach (n, nm->neighbor_pool, ({ + if (sw_if_index != ~0 && n->key.sw_if_index != sw_if_index) + continue; + vec_add1 (ns, n[0]); + })); + /* *INDENT-ON* */ + + if (ns) + vec_sort_with_function (ns, ip6_neighbor_sort); + return ns; +} + static clib_error_t * show_ip6_neighbors (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { vnet_main_t * vnm = vnet_get_main(); - ip6_neighbor_main_t * nm = &ip6_neighbor_main; ip6_neighbor_t * n, * ns; clib_error_t * error = 0; u32 sw_if_index; @@ -752,15 +755,11 @@ show_ip6_neighbors (vlib_main_t * vm, sw_if_index = ~0; (void) unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index); - ns = 0; - pool_foreach (n, nm->neighbor_pool, ({ vec_add1 (ns, n[0]); })); + ns = ip6_neighbors_entries (sw_if_index); if (ns) { - vec_sort_with_function (ns, ip6_neighbor_sort); vlib_cli_output (vm, "%U", format_ip6_neighbor_ip6_entry, vm, 0); vec_foreach (n, ns) { - if (sw_if_index != ~0 && n->key.sw_if_index != sw_if_index) - continue; vlib_cli_output (vm, "%U", format_ip6_neighbor_ip6_entry, vm, n); } vec_free (ns); diff --git a/vnet/vnet/ip/ip6_neighbor.h b/vnet/vnet/ip/ip6_neighbor.h new file mode 100644 index 00000000000..2d572089dc2 --- /dev/null +++ b/vnet/vnet/ip/ip6_neighbor.h @@ -0,0 +1,42 @@ +/* + * + * ip6_neighboor.h: ip6 neighbor structures + * + * Copyright (c) 2016 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef included_ip6_neighbor_h +#define included_ip6_neighbor_h + +#include <vnet/fib/fib_types.h> + +typedef struct { + ip6_address_t ip6_address; + u32 sw_if_index; + u32 pad; +} ip6_neighbor_key_t; + +typedef struct { + ip6_neighbor_key_t key; + u8 link_layer_address[8]; + u16 flags; +#define IP6_NEIGHBOR_FLAG_STATIC (1 << 0) +#define IP6_NEIGHBOR_FLAG_DYNAMIC (2 << 0) + u64 cpu_time_last_updated; + fib_node_index_t fib_entry_index; +} ip6_neighbor_t; + +ip6_neighbor_t * ip6_neighbors_entries (u32 sw_if_index); + +#endif /* included_ip6_neighbor_h */ |