summaryrefslogtreecommitdiffstats
path: root/src/vlib/physmem.c
blob: a36444fdc9f60e65224728f45fac37cc9238fe6c (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/*
 * 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 <unistd.h>
#include <sys/types.h>
#include <sys/mount.h>
#include <sys/mman.h>
#include <sys/fcntl.h>
#include <sys/stat.h>
#include <unistd.h>

#include <vppinfra/linux/sysfs.h>
#include <vlib/vlib.h>
#include <vlib/physmem.h>
#include <vlib/unix/unix.h>
#include <vlib/pci/pci.h>
#include <vlib/linux/vfio.h>

#if defined(__x86_64__) && !defined(CLIB_SANITIZE_ADDR)
/* we keep physmem in low 38 bits of VA address space as some
   IOMMU implamentation cannot map above that range */
#define VLIB_PHYSMEM_DEFAULT_BASE_ADDDR		(1ULL << 36)
#else
/* let kernel decide */
#define VLIB_PHYSMEM_DEFAULT_BASE_ADDDR		0
#endif

clib_error_t *
vlib_physmem_shared_map_create (vlib_main_t * vm, char *name, uword size,
				u32 log2_page_sz, u32 numa_node,
				u32 * map_index)
{
  clib_pmalloc_main_t *pm = vm->physmem_main.pmalloc_main;
  vlib_physmem_main_t *vpm = &vm->physmem_main;
  vlib_physmem_map_t *map;
  clib_pmalloc_arena_t *a;
  clib_error_t *error = 0;
  void *va;
  uword i;

  va = clib_pmalloc_create_shared_arena (pm, name, size, log2_page_sz,
					 numa_node);

  if (va == 0)
    return clib_error_return (0, "%U", format_clib_error,
			      clib_pmalloc_last_error (pm));

  a = clib_pmalloc_get_arena (pm, va);

  pool_get (vpm->maps, map);
  *map_index = map->index = map - vpm->maps;
  map->base = va;
  map->fd = a->fd;
  map->n_pages = a->n_pages * a->subpages_per_page;
  map->log2_page_size = a->log2_subpage_sz;
  map->numa_node = a->numa_node;

  for (i = 0; i < a->n_pages; i++)
    {
      uword pa =
	clib_pmalloc_get_pa (pm, (u8 *) va + (i << a->log2_subpage_sz));

      /* maybe iova */
      if (pa == 0)
	pa = pointer_to_uword (va);

      vec_add1 (map->page_table, pa);
    }

  return error;
}

vlib_physmem_map_t *
vlib_physmem_get_map (vlib_main_t * vm, u32 index)
{
  vlib_physmem_main_t *vpm = &vm->physmem_main;
  return pool_elt_at_index (vpm->maps, index);
}

clib_error_t *
vlib_physmem_init (vlib_main_t * vm)
{
  vlib_physmem_main_t *vpm = &vm->physmem_main;
  clib_error_t *error = 0;
  u64 *pt = 0;
  void *p;

  /* check if pagemap is accessible */
  pt = clib_mem_vm_get_paddr (&pt, min_log2 (sysconf (_SC_PAGESIZE)), 1);
  if (pt && pt[0])
    vpm->flags |= VLIB_PHYSMEM_MAIN_F_HAVE_PAGEMAP;
  vec_free (pt);

  if ((error = linux_vfio_init (vm)))
    return error;

  p = clib_mem_alloc_aligned (sizeof (clib_pmalloc_main_t),
			      CLIB_CACHE_LINE_BYTES);
  memset (p, 0, sizeof (clib_pmalloc_main_t));
  vpm->pmalloc_main = (clib_pmalloc_main_t *) p;

  if (vpm->base_addr == 0)
    vpm->base_addr = VLIB_PHYSMEM_DEFAULT_BASE_ADDDR;

  clib_pmalloc_init (vpm->pmalloc_main, vpm->base_addr, vpm->max_size);

  /* update base_addr and max_size per actual allocation */
  vpm->base_addr = (uword) vpm->pmalloc_main->base;
  vpm->max_size = (uword) vpm->pmalloc_main->max_pages <<
    vpm->pmalloc_main->def_log2_page_sz;

  return error;
}

static clib_error_t *
show_physmem (vlib_main_t * vm,
	      unformat_input_t * input, vlib_cli_command_t * cmd)
{
  vlib_physmem_main_t *vpm = &vm->physmem_main;
  unformat_input_t _line_input, *line_input = &_line_input;
  u32 verbose = 0, map = 0;

  if (unformat_user (input, unformat_line_input, line_input))
    {
      while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
	{
	  if (unformat (line_input, "verbose"))
	    verbose = 1;
	  else if (unformat (line_input, "v"))
	    verbose = 1;
	  else if (unformat (line_input, "detail"))
	    verbose = 2;
	  else if (unformat (line_input, "d"))
	    verbose = 2;
	  else if (unformat (line_input, "map"))
	    map = 1;
	  else
	    break;
	}
      unformat_free (line_input);
    }

  if (map)
    vlib_cli_output (vm, " %U", format_pmalloc_map, vpm->pmalloc_main);
  else
    vlib_cli_output (vm, " %U", format_pmalloc, vpm->pmalloc_main, verbose);

  return 0;
}

/* *INDENT-OFF* */
VLIB_CLI_COMMAND (show_physmem_command, static) = {
  .path = "show physmem",
  .short_help = "show physmem [verbose | detail | map]",
  .function = show_physmem,
};
/* *INDENT-ON* */

static clib_error_t *
vlib_physmem_config (vlib_main_t * vm, unformat_input_t * input)
{
  vlib_physmem_main_t *vpm = &vm->physmem_main;

  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
    {
      if (unformat (input, "base-addr 0x%lx", &vpm->base_addr))
	;
      else if (unformat (input, "max-size %U",
			 unformat_memory_size, &vpm->max_size))
	;
      else
	return unformat_parse_error (input);
    }

  unformat_free (input);
  return 0;
}

VLIB_EARLY_CONFIG_FUNCTION (vlib_physmem_config, "physmem");

/*
 * fd.io coding-style-patch-verification: ON
 *
 * Local Variables:
 * eval: (c-set-style "gnu")
 * End:
 */
(t->nsh_base.nsp_nsi); if (t->nsh_base.md_type == 1) { rmp->tlv_length = 4; rmp->c1 = htonl (t->md.md1_data.c1); rmp->c2 = htonl (t->md.md1_data.c2); rmp->c3 = htonl (t->md.md1_data.c3); rmp->c4 = htonl (t->md.md1_data.c4); } else if (t->nsh_base.md_type == 2) { rmp->tlv_length = t->tlvs_len; clib_memcpy (rmp->tlv, t->tlvs_data, t->tlvs_len); } rmp->context = context; vl_api_send_msg (rp, (u8 *) rmp); } static void send_nsh_map_details (nsh_map_t * t, vl_api_registration_t * rp, u32 context) { vl_api_nsh_map_details_t *rmp; nsh_main_t *nm = &nsh_main; rmp = vl_msg_api_alloc (sizeof (*rmp)); clib_memset (rmp, 0, sizeof (*rmp)); rmp->_vl_msg_id = ntohs ((VL_API_NSH_MAP_DETAILS) + nm->msg_id_base); rmp->nsp_nsi = htonl (t->nsp_nsi); rmp->mapped_nsp_nsi = htonl (t->mapped_nsp_nsi); rmp->nsh_action = htonl (t->nsh_action); rmp->sw_if_index = htonl (t->sw_if_index); rmp->rx_sw_if_index = htonl (t->rx_sw_if_index); rmp->next_node = htonl (t->next_node); rmp->context = context; vl_api_send_msg (rp, (u8 *) rmp); } static void vl_api_nsh_map_dump_t_handler (vl_api_nsh_map_dump_t * mp) { nsh_main_t *nm = &nsh_main; nsh_map_t *t; u32 map_index; vl_api_registration_t *rp; rp = vl_api_client_index_to_registration (mp->client_index); if (rp == 0) return; map_index = ntohl (mp->map_index); if (~0 == map_index) { pool_foreach (t, nm->nsh_mappings) { send_nsh_map_details (t, rp, mp->context); } } else { if (map_index >= vec_len (nm->nsh_mappings)) { return; } t = &nm->nsh_mappings[map_index]; send_nsh_map_details (t, rp, mp->context); } } /** API message handler */ static void vl_api_nsh_add_del_map_t_handler (vl_api_nsh_add_del_map_t * mp) { vl_api_nsh_add_del_map_reply_t *rmp; int rv; nsh_add_del_map_args_t _a = { 0 }, *a = &_a; u32 map_index = ~0; a->is_add = mp->is_add; a->map.nsp_nsi = ntohl (mp->nsp_nsi); a->map.mapped_nsp_nsi = ntohl (mp->mapped_nsp_nsi); a->map.nsh_action = ntohl (mp->nsh_action); a->map.sw_if_index = ntohl (mp->sw_if_index); a->map.rx_sw_if_index = ntohl (mp->rx_sw_if_index); a->map.next_node = ntohl (mp->next_node); rv = nsh_add_del_map (a, &map_index); if ((a->map.next_node == NSH_NODE_NEXT_ENCAP_VXLAN4) | (a->map.next_node == NSH_NODE_NEXT_ENCAP_VXLAN6)) { rv = nsh_add_del_proxy_session (a); } REPLY_MACRO2 (VL_API_NSH_ADD_DEL_MAP_REPLY, ( { rmp->map_index = htonl (map_index); } )); } int nsh_header_rewrite (nsh_entry_t * nsh_entry) { u8 *rw = 0; int len = 0; nsh_base_header_t *nsh_base; nsh_md1_data_t *nsh_md1; nsh_main_t *nm = &nsh_main; nsh_md2_data_t *opt0; nsh_md2_data_t *limit0; nsh_md2_data_t *nsh_md2; nsh_option_map_t _nsh_option, *nsh_option = &_nsh_option; u8 old_option_size = 0; u8 new_option_size = 0; vec_free (nsh_entry->rewrite); if (nsh_entry->nsh_base.md_type == 1) { len = sizeof (nsh_base_header_t) + sizeof (nsh_md1_data_t); } else if (nsh_entry->nsh_base.md_type == 2) { /* set to maxim, maybe dataplane will add more TLVs */ len = MAX_NSH_HEADER_LEN; } vec_validate_aligned (rw, len - 1, CLIB_CACHE_LINE_BYTES); clib_memset (rw, 0, len); nsh_base = (nsh_base_header_t *) rw; nsh_base->ver_o_c = nsh_entry->nsh_base.ver_o_c; nsh_base->length = nsh_entry->nsh_base.length; nsh_base->md_type = nsh_entry->nsh_base.md_type; nsh_base->next_protocol = nsh_entry->nsh_base.next_protocol; nsh_base->nsp_nsi = clib_host_to_net_u32 (nsh_entry->nsh_base.nsp_nsi); if (nsh_base->md_type == 1) { nsh_md1 = (nsh_md1_data_t *) (rw + sizeof (nsh_base_header_t)); nsh_md1->c1 = clib_host_to_net_u32 (nsh_entry->md.md1_data.c1); nsh_md1->c2 = clib_host_to_net_u32 (nsh_entry->md.md1_data.c2); nsh_md1->c3 = clib_host_to_net_u32 (nsh_entry->md.md1_data.c3); nsh_md1->c4 = clib_host_to_net_u32 (nsh_entry->md.md1_data.c4); nsh_entry->rewrite_size = 24; } else if (nsh_base->md_type == 2) { opt0 = (nsh_md2_data_t *) (nsh_entry->tlvs_data); limit0 = (nsh_md2_data_t *) ((u8 *) opt0 + nsh_entry->tlvs_len); nsh_md2 = (nsh_md2_data_t *) (rw + sizeof (nsh_base_header_t)); nsh_entry->rewrite_size = sizeof (nsh_base_header_t); while (opt0 < limit0) { old_option_size = sizeof (nsh_md2_data_t) + opt0->length; /* round to 4-byte */ old_option_size = ((old_option_size + 3) >> 2) << 2; nsh_option = nsh_md2_lookup_option (opt0->class, opt0->type); if (nsh_option == NULL) { goto next_tlv_md2; } if (nm->add_options[nsh_option->option_id] != NULL) { if (0 != nm->add_options[nsh_option->option_id] ((u8 *) nsh_md2, &new_option_size)) { goto next_tlv_md2; } /* round to 4-byte */ new_option_size = ((new_option_size + 3) >> 2) << 2; nsh_entry->rewrite_size += new_option_size; nsh_md2 = (nsh_md2_data_t *) (((u8 *) nsh_md2) + new_option_size); opt0 = (nsh_md2_data_t *) (((u8 *) opt0) + old_option_size); } else { next_tlv_md2: opt0 = (nsh_md2_data_t *) (((u8 *) opt0) + old_option_size); } } } nsh_entry->rewrite = rw; nsh_base->length = (nsh_base->length & NSH_TTL_L2_MASK) | ((nsh_entry->rewrite_size >> 2) & NSH_LEN_MASK); return 0; } extern vnet_hw_interface_class_t nsh_hw_class; /** * Action function to add or del an nsh map. * Shared by both CLI and binary API **/ int nsh_add_del_map (nsh_add_del_map_args_t * a, u32 * map_indexp) { nsh_main_t *nm = &nsh_main; vnet_main_t *vnm = nm->vnet_main; nsh_map_t *map = 0; u32 key, *key_copy; uword *entry; hash_pair_t *hp; u32 map_index = ~0; vnet_hw_interface_t *hi; u32 nsh_hw_if = ~0; u32 nsh_sw_if = ~0; /* net order, so data plane could use nsh header to lookup directly */ key = clib_host_to_net_u32 (a->map.nsp_nsi); entry = hash_get_mem (nm->nsh_mapping_by_key, &key); if (a->is_add) { /* adding an entry, must not already exist */ if (entry) return -1; //TODO API_ERROR_INVALID_VALUE; pool_get_aligned (nm->nsh_mappings, map, CLIB_CACHE_LINE_BYTES); clib_memset (map, 0, sizeof (*map)); /* copy from arg structure */ map->nsp_nsi = a->map.nsp_nsi; map->mapped_nsp_nsi = a->map.mapped_nsp_nsi; map->nsh_action = a->map.nsh_action; map->sw_if_index = a->map.sw_if_index; map->rx_sw_if_index = a->map.rx_sw_if_index; map->next_node = a->map.next_node; map->adj_index = a->map.adj_index; key_copy = clib_mem_alloc (sizeof (*key_copy)); clib_memcpy (key_copy, &key, sizeof (*key_copy)); hash_set_mem (nm->nsh_mapping_by_key, key_copy, map - nm->nsh_mappings); map_index = map - nm->nsh_mappings; if (vec_len (nm->free_nsh_tunnel_hw_if_indices) > 0) { nsh_hw_if = nm->free_nsh_tunnel_hw_if_indices [vec_len (nm->free_nsh_tunnel_hw_if_indices) - 1]; vec_dec_len (nm->free_nsh_tunnel_hw_if_indices, 1); hi = vnet_get_hw_interface (vnm, nsh_hw_if); hi->dev_instance = map_index; hi->hw_instance = hi->dev_instance; } else { nsh_hw_if = vnet_register_interface (vnm, nsh_device_class.index, map_index, nsh_hw_class.index, map_index); hi = vnet_get_hw_interface (vnm, nsh_hw_if); hi->output_node_index = nsh_aware_vnf_proxy_node.index; } map->nsh_hw_if = nsh_hw_if; map->nsh_sw_if = nsh_sw_if = hi->sw_if_index; vec_validate_init_empty (nm->tunnel_index_by_sw_if_index, nsh_sw_if, ~0); nm->tunnel_index_by_sw_if_index[nsh_sw_if] = key; vnet_sw_interface_set_flags (vnm, hi->sw_if_index, VNET_SW_INTERFACE_FLAG_ADMIN_UP); } else { if (!entry) return -2; //TODO API_ERROR_NO_SUCH_ENTRY; map = pool_elt_at_index (nm->nsh_mappings, entry[0]); vnet_sw_interface_set_flags (vnm, map->nsh_sw_if, VNET_SW_INTERFACE_FLAG_ADMIN_DOWN); vec_add1 (nm->free_nsh_tunnel_hw_if_indices, map->nsh_sw_if); nm->tunnel_index_by_sw_if_index[map->nsh_sw_if] = ~0; hp = hash_get_pair (nm->nsh_mapping_by_key, &key); key_copy = (void *) (hp->key); hash_unset_mem (nm->nsh_mapping_by_key, &key); clib_mem_free (key_copy); pool_put (nm->nsh_mappings, map); } if (map_indexp) *map_indexp = map_index; return 0; } /** * Action function to add or del an nsh-proxy-session. * Shared by both CLI and binary API **/ int nsh_add_del_proxy_session (nsh_add_del_map_args_t * a) { nsh_main_t *nm = &nsh_main; nsh_proxy_session_t *proxy = 0; nsh_proxy_session_by_key_t key, *key_copy; uword *entry; hash_pair_t *hp; u32 nsp = 0, nsi = 0; clib_memset (&key, 0, sizeof (key)); key.transport_type = a->map.next_node; key.transport_index = a->map.sw_if_index; entry = hash_get_mem (nm->nsh_proxy_session_by_key, &key); if (a->is_add) { /* adding an entry, must not already exist */ if (entry) return -1; //TODO API_ERROR_INVALID_VALUE; pool_get_aligned (nm->nsh_proxy_sessions, proxy, CLIB_CACHE_LINE_BYTES); clib_memset (proxy, 0, sizeof (*proxy)); /* Nsi needs to minus 1 within NSH-Proxy */ nsp = (a->map.nsp_nsi >> NSH_NSP_SHIFT) & NSH_NSP_MASK; nsi = a->map.nsp_nsi & NSH_NSI_MASK; if (nsi == 0) return -1; nsi = nsi - 1; /* net order, so could use it to lookup nsh map table directly */ proxy->nsp_nsi = clib_host_to_net_u32 ((nsp << NSH_NSP_SHIFT) | nsi); key_copy = clib_mem_alloc (sizeof (*key_copy)); clib_memcpy (key_copy, &key, sizeof (*key_copy)); hash_set_mem (nm->nsh_proxy_session_by_key, key_copy, proxy - nm->nsh_proxy_sessions); } else { if (!entry) return -2; //TODO API_ERROR_NO_SUCH_ENTRY; proxy = pool_elt_at_index (nm->nsh_proxy_sessions, entry[0]); hp = hash_get_pair (nm->nsh_proxy_session_by_key, &key); key_copy = (void *) (hp->key); hash_unset_mem (nm->nsh_proxy_session_by_key, &key); clib_mem_free (key_copy); pool_put (nm->nsh_proxy_sessions, proxy); } return 0; } /** * Action function for adding an NSH entry * nsh_add_del_entry_args_t *a: host order */ int nsh_add_del_entry (nsh_add_del_entry_args_t * a, u32 * entry_indexp) { nsh_main_t *nm = &nsh_main; nsh_entry_t *nsh_entry = 0; u32 key, *key_copy; uword *entry_id; hash_pair_t *hp; u32 entry_index = ~0; u8 tlvs_len = 0; u8 *data = 0; /* host order, because nsh map table stores nsp_nsi in host order */ key = a->nsh_entry.nsh_base.nsp_nsi; entry_id = hash_get_mem (nm->nsh_entry_by_key, &key); if (a->is_add) { /* adding an entry, must not already exist */ if (entry_id) return -1; // TODO VNET_API_ERROR_INVALID_VALUE; pool_get_aligned (nm->nsh_entries, nsh_entry, CLIB_CACHE_LINE_BYTES); clib_memset (nsh_entry, 0, sizeof (*nsh_entry)); /* copy from arg structure */ #define _(x) nsh_entry->nsh_base.x = a->nsh_entry.nsh_base.x; foreach_copy_nsh_base_hdr_field; #undef _ if (a->nsh_entry.nsh_base.md_type == 1) { nsh_entry->md.md1_data.c1 = a->nsh_entry.md.md1_data.c1; nsh_entry->md.md1_data.c2 = a->nsh_entry.md.md1_data.c2; nsh_entry->md.md1_data.c3 = a->nsh_entry.md.md1_data.c3; nsh_entry->md.md1_data.c4 = a->nsh_entry.md.md1_data.c4; } else if (a->nsh_entry.nsh_base.md_type == 2) { vec_free (nsh_entry->tlvs_data); tlvs_len = a->nsh_entry.tlvs_len; vec_validate_aligned (data, tlvs_len - 1, CLIB_CACHE_LINE_BYTES); clib_memcpy (data, a->nsh_entry.tlvs_data, tlvs_len); nsh_entry->tlvs_data = data; nsh_entry->tlvs_len = tlvs_len; vec_free (a->nsh_entry.tlvs_data); } nsh_header_rewrite (nsh_entry); key_copy = clib_mem_alloc (sizeof (*key_copy)); clib_memcpy (key_copy, &key, sizeof (*key_copy)); hash_set_mem (nm->nsh_entry_by_key, key_copy, nsh_entry - nm->nsh_entries); entry_index = nsh_entry - nm->nsh_entries; } else { if (!entry_id) return -2; //TODO API_ERROR_NO_SUCH_ENTRY; nsh_entry = pool_elt_at_index (nm->nsh_entries, entry_id[0]); hp = hash_get_pair (nm->nsh_entry_by_key, &key); key_copy = (void *) (hp->key); hash_unset_mem (nm->nsh_entry_by_key, &key); clib_mem_free (key_copy); vec_free (nsh_entry->tlvs_data); vec_free (nsh_entry->rewrite); pool_put (nm->nsh_entries, nsh_entry); } if (entry_indexp) *entry_indexp = entry_index; return 0; } /** API message handler */ static void vl_api_nsh_add_del_entry_t_handler (vl_api_nsh_add_del_entry_t * mp) { vl_api_nsh_add_del_entry_reply_t *rmp; int rv; nsh_add_del_entry_args_t _a = { 0 }, *a = &_a; u32 entry_index = ~0; u8 tlvs_len = 0; u8 *data = 0; a->is_add = mp->is_add; a->nsh_entry.nsh_base.ver_o_c = (mp->ver_o_c & 0xF0) | ((mp->ttl & NSH_LEN_MASK) >> 2); a->nsh_entry.nsh_base.length = (mp->length & NSH_LEN_MASK) | ((mp->ttl & 0x3) << 6); a->nsh_entry.nsh_base.md_type = mp->md_type; a->nsh_entry.nsh_base.next_protocol = mp->next_protocol; a->nsh_entry.nsh_base.nsp_nsi = ntohl (mp->nsp_nsi); if (mp->md_type == 1) { a->nsh_entry.md.md1_data.c1 = ntohl (mp->c1); a->nsh_entry.md.md1_data.c2 = ntohl (mp->c2); a->nsh_entry.md.md1_data.c3 = ntohl (mp->c3); a->nsh_entry.md.md1_data.c4 = ntohl (mp->c4); } else if (mp->md_type == 2) { tlvs_len = mp->tlv_length; vec_validate_aligned (data, tlvs_len - 1, CLIB_CACHE_LINE_BYTES); clib_memcpy (data, mp->tlv, tlvs_len); a->nsh_entry.tlvs_data = data; a->nsh_entry.tlvs_len = tlvs_len; } rv = nsh_add_del_entry (a, &entry_index); REPLY_MACRO2 (VL_API_NSH_ADD_DEL_ENTRY_REPLY, ( { rmp->entry_index = htonl (entry_index); } )); } static void vl_api_nsh_entry_dump_t_handler (vl_api_nsh_entry_dump_t * mp) { nsh_main_t *nm = &nsh_main; nsh_entry_t *t; u32 entry_index; vl_api_registration_t *rp; rp = vl_api_client_index_to_registration (mp->client_index); if (rp == 0) return; entry_index = ntohl (mp->entry_index); if (~0 == entry_index) { pool_foreach (t, nm->nsh_entries) { send_nsh_entry_details (t, rp, mp->context); } } else { if (entry_index >= vec_len (nm->nsh_entries)) { return; } t = &nm->nsh_entries[entry_index]; send_nsh_entry_details (t, rp, mp->context); } } #include <nsh/nsh.api.c> /* Set up the API message handling tables */ clib_error_t * nsh_api_init (vlib_main_t * vm, nsh_main_t * nm) { /* Add our API messages to the global name_crc hash table */ nm->msg_id_base = setup_message_id_table (); return 0; } /* * fd.io coding-style-patch-verification: ON * * Local Variables: * eval: (c-set-style "gnu") * End: */