blob: a51dd6d0f7fde5d0bccb431a43794c5ab9c16f71 [file] [log] [blame]
Neale Ranns5f8f6172019-04-18 10:23:56 +00001/*
2 *------------------------------------------------------------------
Neale Ranns03ce4622020-02-03 10:55:09 +00003 * teib_api.c - teib api
Neale Ranns5f8f6172019-04-18 10:23:56 +00004 *
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:
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
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 *------------------------------------------------------------------
18 */
19
20#include <vnet/vnet.h>
21#include <vlibmemory/api.h>
22
23#include <vnet/api_errno.h>
Neale Ranns03ce4622020-02-03 10:55:09 +000024#include <vnet/teib/teib.h>
Neale Ranns5f8f6172019-04-18 10:23:56 +000025#include <vnet/ip/ip_types_api.h>
26#include <vnet/fib/fib_table.h>
27
28/* define message IDs */
29#include <vnet/format_fns.h>
Neale Ranns03ce4622020-02-03 10:55:09 +000030#include <vnet/teib/teib.api_enum.h>
31#include <vnet/teib/teib.api_types.h>
Neale Ranns5f8f6172019-04-18 10:23:56 +000032
Neale Ranns03ce4622020-02-03 10:55:09 +000033static u32 teib_base_msg_id;
34#define REPLY_MSG_ID_BASE teib_base_msg_id
Neale Ranns5f8f6172019-04-18 10:23:56 +000035
36#include <vlibapi/api_helper_macros.h>
37
38static void
Neale Ranns03ce4622020-02-03 10:55:09 +000039vl_api_teib_entry_add_del_t_handler (vl_api_teib_entry_add_del_t * mp)
Neale Ranns5f8f6172019-04-18 10:23:56 +000040{
Neale Ranns03ce4622020-02-03 10:55:09 +000041 vl_api_teib_entry_add_del_reply_t *rmp;
Neale Ranns5f8f6172019-04-18 10:23:56 +000042 ip46_address_t peer, nh;
43 int rv;
44
45 VALIDATE_SW_IF_INDEX ((&mp->entry));
46
47 ip_address_decode (&mp->entry.peer, &peer);
48 ip_address_decode (&mp->entry.nh, &nh);
49
50 if (mp->is_add)
Neale Ranns03ce4622020-02-03 10:55:09 +000051 rv = teib_entry_add (ntohl (mp->entry.sw_if_index), &peer,
Neale Ranns5f8f6172019-04-18 10:23:56 +000052 ntohl (mp->entry.nh_table_id), &nh);
53 else
Neale Ranns03ce4622020-02-03 10:55:09 +000054 rv = teib_entry_del (ntohl (mp->entry.sw_if_index), &peer);
Neale Ranns5f8f6172019-04-18 10:23:56 +000055
56 BAD_SW_IF_INDEX_LABEL;
57
Neale Ranns03ce4622020-02-03 10:55:09 +000058 REPLY_MACRO (VL_API_TEIB_ENTRY_ADD_DEL_REPLY);
Neale Ranns5f8f6172019-04-18 10:23:56 +000059}
60
Neale Ranns03ce4622020-02-03 10:55:09 +000061typedef struct vl_api_teib_send_t_
Neale Ranns5f8f6172019-04-18 10:23:56 +000062{
63 vl_api_registration_t *reg;
64 u32 context;
Neale Ranns03ce4622020-02-03 10:55:09 +000065} vl_api_teib_send_t;
Neale Ranns5f8f6172019-04-18 10:23:56 +000066
67static walk_rc_t
Neale Ranns03ce4622020-02-03 10:55:09 +000068vl_api_teib_send_one (index_t nei, void *arg)
Neale Ranns5f8f6172019-04-18 10:23:56 +000069{
Neale Ranns03ce4622020-02-03 10:55:09 +000070 vl_api_teib_details_t *mp;
71 vl_api_teib_send_t *ctx = arg;
72 const teib_entry_t *ne;
Neale Ranns4c16d802019-12-17 20:15:03 +000073 const fib_prefix_t *pfx;
Neale Ranns5f8f6172019-04-18 10:23:56 +000074
75 mp = vl_msg_api_alloc (sizeof (*mp));
76 clib_memset (mp, 0, sizeof (*mp));
Neale Ranns03ce4622020-02-03 10:55:09 +000077 mp->_vl_msg_id = ntohs (VL_API_TEIB_DETAILS + REPLY_MSG_ID_BASE);
Neale Ranns5f8f6172019-04-18 10:23:56 +000078 mp->context = ctx->context;
79
Neale Ranns03ce4622020-02-03 10:55:09 +000080 ne = teib_entry_get (nei);
81 pfx = teib_entry_get_nh (ne);
Neale Ranns5f8f6172019-04-18 10:23:56 +000082
Neale Ranns03ce4622020-02-03 10:55:09 +000083 ip_address_encode (teib_entry_get_peer (ne), IP46_TYPE_ANY,
Neale Ranns4c16d802019-12-17 20:15:03 +000084 &mp->entry.peer);
85 ip_address_encode (&pfx->fp_addr, IP46_TYPE_ANY, &mp->entry.nh);
Neale Ranns5f8f6172019-04-18 10:23:56 +000086 mp->entry.nh_table_id =
Neale Ranns4c16d802019-12-17 20:15:03 +000087 htonl (fib_table_get_table_id
Neale Ranns03ce4622020-02-03 10:55:09 +000088 (teib_entry_get_fib_index (ne), pfx->fp_proto));
89 mp->entry.sw_if_index = htonl (teib_entry_get_sw_if_index (ne));
Neale Ranns5f8f6172019-04-18 10:23:56 +000090
91 vl_api_send_msg (ctx->reg, (u8 *) mp);
92
93 return (WALK_CONTINUE);
94}
95
96static void
Neale Ranns03ce4622020-02-03 10:55:09 +000097vl_api_teib_dump_t_handler (vl_api_teib_dump_t * mp)
Neale Ranns5f8f6172019-04-18 10:23:56 +000098{
99 vl_api_registration_t *reg;
100
101 reg = vl_api_client_index_to_registration (mp->client_index);
102 if (!reg)
103 return;
104
Neale Ranns03ce4622020-02-03 10:55:09 +0000105 vl_api_teib_send_t ctx = {
Neale Ranns5f8f6172019-04-18 10:23:56 +0000106 .reg = reg,
107 .context = mp->context,
108 };
109
Neale Ranns03ce4622020-02-03 10:55:09 +0000110 teib_walk (vl_api_teib_send_one, &ctx);
Neale Ranns5f8f6172019-04-18 10:23:56 +0000111}
112
113/*
Neale Ranns03ce4622020-02-03 10:55:09 +0000114 * teib_api_hookup
Neale Ranns5f8f6172019-04-18 10:23:56 +0000115 * Add vpe's API message handlers to the table.
116 * vlib has already mapped shared memory and
117 * added the client registration handlers.
118 * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
119 */
Neale Ranns03ce4622020-02-03 10:55:09 +0000120#include <vnet/teib/teib.api.c>
Neale Ranns5f8f6172019-04-18 10:23:56 +0000121
122static clib_error_t *
Neale Ranns03ce4622020-02-03 10:55:09 +0000123teib_api_hookup (vlib_main_t * vm)
Neale Ranns5f8f6172019-04-18 10:23:56 +0000124{
Neale Ranns03ce4622020-02-03 10:55:09 +0000125 teib_base_msg_id = setup_message_id_table ();
Neale Ranns5f8f6172019-04-18 10:23:56 +0000126
127 return (NULL);
128}
129
Neale Ranns03ce4622020-02-03 10:55:09 +0000130VLIB_API_INIT_FUNCTION (teib_api_hookup);
Neale Ranns5f8f6172019-04-18 10:23:56 +0000131
132/*
133 * fd.io coding-style-patch-verification: ON
134 *
135 * Local Variables:
136 * eval: (c-set-style "gnu")
137 * End:
138 */