2 *------------------------------------------------------------------
3 * nhrp_api.c - nhrp api
5 * Copyright (c) 2016 Cisco and/or its affiliates.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at:
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *------------------------------------------------------------------
20 #include <vnet/vnet.h>
21 #include <vlibmemory/api.h>
23 #include <vnet/api_errno.h>
24 #include <vnet/nhrp/nhrp.h>
25 #include <vnet/ip/ip_types_api.h>
26 #include <vnet/fib/fib_table.h>
28 /* define message IDs */
29 #include <vnet/format_fns.h>
30 #include <vnet/nhrp/nhrp.api_enum.h>
31 #include <vnet/nhrp/nhrp.api_types.h>
33 static u32 nhrp_base_msg_id;
34 #define REPLY_MSG_ID_BASE nhrp_base_msg_id
36 #include <vlibapi/api_helper_macros.h>
39 vl_api_nhrp_entry_add_del_t_handler (vl_api_nhrp_entry_add_del_t * mp)
41 vl_api_nhrp_entry_add_del_reply_t *rmp;
42 ip46_address_t peer, nh;
45 VALIDATE_SW_IF_INDEX ((&mp->entry));
47 ip_address_decode (&mp->entry.peer, &peer);
48 ip_address_decode (&mp->entry.nh, &nh);
51 rv = nhrp_entry_add (ntohl (mp->entry.sw_if_index), &peer,
52 ntohl (mp->entry.nh_table_id), &nh);
54 rv = nhrp_entry_del (ntohl (mp->entry.sw_if_index), &peer);
56 BAD_SW_IF_INDEX_LABEL;
58 REPLY_MACRO (VL_API_NHRP_ENTRY_ADD_DEL_REPLY);
61 typedef struct vl_api_nhrp_send_t_
63 vl_api_registration_t *reg;
68 vl_api_nhrp_send_one (index_t nei, void *arg)
70 vl_api_nhrp_details_t *mp;
71 vl_api_nhrp_send_t *ctx = arg;
72 const nhrp_entry_t *ne;
74 mp = vl_msg_api_alloc (sizeof (*mp));
75 clib_memset (mp, 0, sizeof (*mp));
76 mp->_vl_msg_id = ntohs (VL_API_NHRP_DETAILS + REPLY_MSG_ID_BASE);
77 mp->context = ctx->context;
79 ne = nhrp_entry_get (nei);
81 ip_address_encode (&ne->ne_key->nk_peer, IP46_TYPE_ANY, &mp->entry.peer);
82 ip_address_encode (&ne->ne_nh.fp_addr, IP46_TYPE_ANY, &mp->entry.nh);
83 mp->entry.nh_table_id =
84 htonl (fib_table_get_table_id (ne->ne_fib_index, ne->ne_nh.fp_proto));
85 mp->entry.sw_if_index = htonl (ne->ne_key->nk_sw_if_index);
87 vl_api_send_msg (ctx->reg, (u8 *) mp);
89 return (WALK_CONTINUE);
93 vl_api_nhrp_dump_t_handler (vl_api_nhrp_dump_t * mp)
95 vl_api_registration_t *reg;
97 reg = vl_api_client_index_to_registration (mp->client_index);
101 vl_api_nhrp_send_t ctx = {
103 .context = mp->context,
106 nhrp_walk (vl_api_nhrp_send_one, &ctx);
111 * Add vpe's API message handlers to the table.
112 * vlib has already mapped shared memory and
113 * added the client registration handlers.
114 * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
116 #include <vnet/nhrp/nhrp.api.c>
118 static clib_error_t *
119 nhrp_api_hookup (vlib_main_t * vm)
121 nhrp_base_msg_id = setup_message_id_table ();
126 VLIB_API_INIT_FUNCTION (nhrp_api_hookup);
129 * fd.io coding-style-patch-verification: ON
132 * eval: (c-set-style "gnu")