aboutsummaryrefslogtreecommitdiffstats
path: root/src/vnet/ip-neighbor/ip_neighbor_types.c
blob: 27262a5d62c2440fe4dac9c8d2e325ab44a617f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
 * ip_neighboor.h: ip neighbor generic services
 *
 * Copyright (c) 2018 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.
 */

#include <vnet/ip-neighbor/ip_neighbor_types.h>

u8 *
format_ip_neighbor_flags (u8 * s, va_list * args)
{
  ip_neighbor_flags_t flags = va_arg (*args, int);

  if (flags & IP_NEIGHBOR_FLAG_STATIC)
    s = format (s, "S");

  if (flags & IP_NEIGHBOR_FLAG_DYNAMIC)
    s = format (s, "D");

  if (flags & IP_NEIGHBOR_FLAG_NO_FIB_ENTRY)
    s = format (s, "N");

  return s;
}


u8 *
format_ip_neighbor_key (u8 * s, va_list * va)
{
  ip_neighbor_key_t *key = va_arg (*va, ip_neighbor_key_t *);

  return (format (s, "[%U, %U]",
		  format_vnet_sw_if_index_name, vnet_get_main (),
		  key->ipnk_sw_if_index,
		  format_ip46_address, &key->ipnk_ip, key->ipnk_type));
}

u8 *
format_ip_neighbor_watcher (u8 * s, va_list * va)
{
  ip_neighbor_watcher_t *watcher = va_arg (*va, ip_neighbor_watcher_t *);

  return (format (s, "[pid:%d, client:%d]",
		  clib_host_to_net_u32 (watcher->ipw_pid),
		  clib_host_to_net_u32 (watcher->ipw_client)));
}

u8 *
format_ip_neighbor (u8 * s, va_list * va)
{
  index_t ipni = va_arg (*va, index_t);
  ip_neighbor_t *ipn;

  ipn = ip_neighbor_get (ipni);

  return (format (s, "%=12U%=40U%=6U%=20U%U",
		  format_vlib_time, vlib_get_main (),
		  ipn->ipn_time_last_updated,
		  format_ip46_address, &ipn->ipn_key->ipnk_ip, IP46_TYPE_ANY,
		  format_ip_neighbor_flags, ipn->ipn_flags,
		  format_mac_address_t, &ipn->ipn_mac,
		  format_vnet_sw_if_index_name, vnet_get_main (),
		  ipn->ipn_key->ipnk_sw_if_index));
}

/*
 * fd.io coding-style-patch-verification: ON
 *
 * Local Variables:
 * eval: (c-set-style "gnu")
 * End:
 */
t = "INVALID"; break; } vec_add (s, t, strlen (t)); return s; } /* Formats buffer data as printable ascii or as hex. */ u8 * format_vlib_buffer_data (u8 * s, va_list * args) { u8 *data = va_arg (*args, u8 *); u32 n_data_bytes = va_arg (*args, u32); u32 i, is_printable; is_printable = 1; for (i = 0; i < n_data_bytes && is_printable; i++) { u8 c = data[i]; if (c < 0x20) is_printable = 0; else if (c >= 0x7f) is_printable = 0; } if (is_printable) vec_add (s, data, n_data_bytes); else s = format (s, "%U", format_hex_bytes, data, n_data_bytes); return s; } /* Enable/on => 1; disable/off => 0. */ uword unformat_vlib_enable_disable (unformat_input_t * input, va_list * args) { int *result = va_arg (*args, int *); int enable; if (unformat (input, "enable") || unformat (input, "on")) enable = 1; else if (unformat (input, "disable") || unformat (input, "off")) enable = 0; else return 0; *result = enable; return 1; } /* rx/tx => VLIB_RX/VLIB_TX. */ uword unformat_vlib_rx_tx (unformat_input_t * input, va_list * args) { int *result = va_arg (*args, int *); if (unformat (input, "rx")) *result = VLIB_RX; else if (unformat (input, "tx")) *result = VLIB_TX; else return 0; return 1; } /* Parse an int either %d or 0x%x. */ uword unformat_vlib_number (unformat_input_t * input, va_list * args) { int *result = va_arg (*args, int *); return (unformat (input, "0x%x", result) || unformat (input, "%d", result)); } /* Parse a-zA-Z0-9_ token and hash to value. */ uword unformat_vlib_number_by_name (unformat_input_t * input, va_list * args) { uword *hash = va_arg (*args, uword *); int *result = va_arg (*args, int *); uword *p; u8 *token; int i; if (!unformat_user (input, unformat_token, "a-zA-Z0-9_", &token)) return 0; /* Null terminate. */ if (vec_len (token) > 0 && token[vec_len (token) - 1] != 0) vec_add1 (token, 0); /* Check for exact match. */ p = hash_get_mem (hash, token); if (p) goto done; /* Convert to upper case & try match. */ for (i = 0; i < vec_len (token); i++) if (token[i] >= 'a' && token[i] <= 'z') token[i] = 'A' + token[i] - 'a'; p = hash_get_mem (hash, token); done: vec_free (token); if (p) *result = p[0]; return p != 0; } /* * fd.io coding-style-patch-verification: ON * * Local Variables: * eval: (c-set-style "gnu") * End: */