FD.io VPP  v20.01-48-g3e0dafb74
Vector Packet Processing
nhrp_api.c
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * nhrp_api.c - nhrp api
4  *
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>
24 #include <vnet/nhrp/nhrp.h>
25 #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>
30 #include <vnet/nhrp/nhrp.api_enum.h>
31 #include <vnet/nhrp/nhrp.api_types.h>
32 
34 #define REPLY_MSG_ID_BASE nhrp_base_msg_id
35 
37 
38 static void
40 {
41  vl_api_nhrp_entry_add_del_reply_t *rmp;
42  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)
51  rv = nhrp_entry_add (ntohl (mp->entry.sw_if_index), &peer,
52  ntohl (mp->entry.nh_table_id), &nh);
53  else
54  rv = nhrp_entry_del (ntohl (mp->entry.sw_if_index), &peer);
55 
57 
58  REPLY_MACRO (VL_API_NHRP_ENTRY_ADD_DEL_REPLY);
59 }
60 
61 typedef struct vl_api_nhrp_send_t_
62 {
66 
67 static walk_rc_t
68 vl_api_nhrp_send_one (index_t nei, void *arg)
69 {
71  vl_api_nhrp_send_t *ctx = arg;
72  const nhrp_entry_t *ne;
73  const fib_prefix_t *pfx;
74 
75  mp = vl_msg_api_alloc (sizeof (*mp));
76  clib_memset (mp, 0, sizeof (*mp));
77  mp->_vl_msg_id = ntohs (VL_API_NHRP_DETAILS + REPLY_MSG_ID_BASE);
78  mp->context = ctx->context;
79 
80  ne = nhrp_entry_get (nei);
81  pfx = nhrp_entry_get_nh (ne);
82 
84  &mp->entry.peer);
85  ip_address_encode (&pfx->fp_addr, IP46_TYPE_ANY, &mp->entry.nh);
86  mp->entry.nh_table_id =
88  (nhrp_entry_get_fib_index (ne), pfx->fp_proto));
89  mp->entry.sw_if_index = htonl (nhrp_entry_get_sw_if_index (ne));
90 
91  vl_api_send_msg (ctx->reg, (u8 *) mp);
92 
93  return (WALK_CONTINUE);
94 }
95 
96 static void
98 {
100 
102  if (!reg)
103  return;
104 
106  .reg = reg,
107  .context = mp->context,
108  };
109 
111 }
112 
113 /*
114  * nhrp_api_hookup
115  * 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  */
120 #include <vnet/nhrp/nhrp.api.c>
121 
122 static clib_error_t *
124 {
126 
127  return (NULL);
128 }
129 
131 
132 /*
133  * fd.io coding-style-patch-verification: ON
134  *
135  * Local Variables:
136  * eval: (c-set-style "gnu")
137  * End:
138  */
vl_api_nhrp_entry_t entry
Definition: nhrp.api:38
struct vl_api_nhrp_send_t_ vl_api_nhrp_send_t
fib_protocol_t fp_proto
protocol type
Definition: fib_types.h:212
VLIB_API_INIT_FUNCTION(nhrp_api_hookup)
#define REPLY_MSG_ID_BASE
Definition: nhrp_api.c:34
Definition: nhrp.c:29
vl_api_fib_path_nh_t nh
Definition: fib_types.api:126
static void vl_api_nhrp_dump_t_handler(vl_api_nhrp_dump_t *mp)
Definition: nhrp_api.c:97
#define NULL
Definition: clib.h:58
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
nhrp_entry_t * nhrp_entry_get(index_t nei)
Definition: nhrp.c:96
static void vl_api_send_msg(vl_api_registration_t *rp, u8 *elem)
Definition: api.h:35
u32 index_t
A Data-Path Object is an object that represents actions that are applied to packets are they are swit...
Definition: dpo.h:41
void nhrp_walk(nhrp_walk_cb_t fn, void *ctx)
Definition: nhrp.c:220
void * vl_msg_api_alloc(int nbytes)
unsigned char u8
Definition: types.h:56
static void vl_api_nhrp_entry_add_del_t_handler(vl_api_nhrp_entry_add_del_t *mp)
Definition: nhrp_api.c:39
static clib_error_t * nhrp_api_hookup(vlib_main_t *vm)
Definition: nhrp_api.c:123
int nhrp_entry_add(u32 sw_if_index, const ip46_address_t *peer, u32 nh_table_id, const ip46_address_t *nh)
Create a new NHRP entry.
Definition: nhrp.c:119
enum walk_rc_t_ walk_rc_t
Walk return code.
static u32 nhrp_base_msg_id
Definition: nhrp_api.c:33
Definition: nhrp.api:33
Aggregate type for a prefix.
Definition: fib_types.h:203
unsigned int u32
Definition: types.h:88
vl_api_address_t peer
Definition: nhrp.api:28
ip46_type_t ip_address_decode(const vl_api_address_t *in, ip46_address_t *out)
Definition: ip_types_api.c:161
ip46_address_t fp_addr
The address type is not deriveable from the fp_addr member.
Definition: fib_types.h:226
long ctx[MAX_CONNS]
Definition: main.c:144
#define REPLY_MACRO(t)
vlib_main_t * vm
Definition: in2out_ed.c:1810
u32 nhrp_entry_get_fib_index(const nhrp_entry_t *ne)
Definition: nhrp.c:56
An API client registration, only in vpp/vlib.
Definition: api_common.h:46
#define BAD_SW_IF_INDEX_LABEL
const ip46_address_t * nhrp_entry_get_peer(const nhrp_entry_t *ne)
Definition: nhrp.c:62
int nhrp_entry_del(u32 sw_if_index, const ip46_address_t *peer)
Definition: nhrp.c:173
static walk_rc_t vl_api_nhrp_send_one(index_t nei, void *arg)
Definition: nhrp_api.c:68
static vl_api_registration_t * vl_api_client_index_to_registration(u32 index)
Definition: api.h:57
u32 fib_table_get_table_id(u32 fib_index, fib_protocol_t proto)
Get the Table-ID of the FIB from protocol and index.
Definition: fib_table.c:1086
vl_api_registration_t * reg
Definition: nhrp_api.c:63
const fib_prefix_t * nhrp_entry_get_nh(const nhrp_entry_t *ne)
Definition: nhrp.c:68
void ip_address_encode(const ip46_address_t *in, ip46_type_t type, vl_api_address_t *out)
Definition: ip_types_api.c:178
static void setup_message_id_table(snat_main_t *sm, api_main_t *am)
Definition: nat_api.c:3410
u32 nhrp_entry_get_sw_if_index(const nhrp_entry_t *ne)
accessors for the opaque struct
Definition: nhrp.c:50
u8 is_add
Definition: nhrp.api:37
#define VALIDATE_SW_IF_INDEX(mp)
vl_api_nhrp_entry_t entry
Definition: nhrp.api:50