FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
teib_api.c
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * teib_api.c - teib 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/teib/teib.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/teib/teib.api_enum.h>
31 #include <vnet/teib/teib.api_types.h>
32 
34 #define REPLY_MSG_ID_BASE teib_base_msg_id
35 
37 
38 static void
40 {
41  vl_api_teib_entry_add_del_reply_t *rmp;
43  int rv;
44 
45  VALIDATE_SW_IF_INDEX ((&mp->entry));
46 
47  ip_address_decode2 (&mp->entry.peer, &peer);
48  ip_address_decode2 (&mp->entry.nh, &nh);
49 
50  if (mp->is_add)
51  rv = teib_entry_add (ntohl (mp->entry.sw_if_index),
52  &peer, ntohl (mp->entry.nh_table_id), &nh);
53  else
54  rv = teib_entry_del (ntohl (mp->entry.sw_if_index), &peer);
55 
57 
58  REPLY_MACRO (VL_API_TEIB_ENTRY_ADD_DEL_REPLY);
59 }
60 
61 typedef struct vl_api_teib_send_t_
62 {
66 
67 static walk_rc_t
68 vl_api_teib_send_one (index_t nei, void *arg)
69 {
71  vl_api_teib_send_t *ctx = arg;
72  const teib_entry_t *ne;
73  const fib_prefix_t *pfx;
74 
75  mp = vl_msg_api_alloc_zero (sizeof (*mp));
76  mp->_vl_msg_id = ntohs (VL_API_TEIB_DETAILS + REPLY_MSG_ID_BASE);
77  mp->context = ctx->context;
78 
79  ne = teib_entry_get (nei);
80  pfx = teib_entry_get_nh (ne);
81 
83  ip_address_encode (&pfx->fp_addr, IP46_TYPE_ANY, &mp->entry.nh);
84  mp->entry.nh_table_id =
86  (teib_entry_get_fib_index (ne), pfx->fp_proto));
87  mp->entry.sw_if_index = htonl (teib_entry_get_sw_if_index (ne));
88 
89  vl_api_send_msg (ctx->reg, (u8 *) mp);
90 
91  return (WALK_CONTINUE);
92 }
93 
94 static void
96 {
98 
100  if (!reg)
101  return;
102 
104  .reg = reg,
105  .context = mp->context,
106  };
107 
109 }
110 
111 /*
112  * teib_api_hookup
113  * Add vpe's API message handlers to the table.
114  * vlib has already mapped shared memory and
115  * added the client registration handlers.
116  * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
117  */
118 #include <vnet/teib/teib.api.c>
119 
120 static clib_error_t *
122 {
124 
125  return (NULL);
126 }
127 
129 
130 /*
131  * fd.io coding-style-patch-verification: ON
132  *
133  * Local Variables:
134  * eval: (c-set-style "gnu")
135  * End:
136  */
ip_address
Definition: ip_types.h:79
VALIDATE_SW_IF_INDEX
#define VALIDATE_SW_IF_INDEX(mp)
Definition: api_helper_macros.h:281
vl_api_client_index_to_registration
static vl_api_registration_t * vl_api_client_index_to_registration(u32 index)
Definition: api.h:79
vl_api_teib_dump_t
Definition: teib.api:41
api.h
vl_api_teib_dump_t_handler
static void vl_api_teib_dump_t_handler(vl_api_teib_dump_t *mp)
Definition: teib_api.c:95
ntohs
#define ntohs(x)
Definition: af_xdp.bpf.c:29
vl_api_teib_dump_t::client_index
u32 client_index
Definition: teib.api:43
WALK_CONTINUE
@ WALK_CONTINUE
Definition: interface_funcs.h:174
fib_table_get_table_id
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:1100
vl_api_send_msg
static void vl_api_send_msg(vl_api_registration_t *rp, u8 *elem)
Definition: api.h:35
vl_api_teib_send_t_
Definition: teib_api.c:61
fib_table.h
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
vl_msg_api_alloc_zero
void * vl_msg_api_alloc_zero(int nbytes)
Definition: memory_shared.c:214
teib_entry_add
int teib_entry_add(u32 sw_if_index, const ip_address_t *peer, u32 nh_table_id, const ip_address_t *nh)
Create a new TEIB entry.
Definition: teib.c:200
teib_entry_get_nh
const fib_prefix_t * teib_entry_get_nh(const teib_entry_t *te)
Definition: teib.c:96
teib_entry_get
teib_entry_t * teib_entry_get(index_t tei)
Definition: teib.c:108
ip_address_encode2
void ip_address_encode2(const ip_address_t *in, vl_api_address_t *out)
Definition: ip_types_api.c:228
vl_api_teib_entry_add_del_t
Definition: teib.api:33
teib.h
teib_entry_t_
Definition: teib.c:33
vl_api_teib_send_one
static walk_rc_t vl_api_teib_send_one(index_t nei, void *arg)
Definition: teib_api.c:68
vl_api_teib_send_t
struct vl_api_teib_send_t_ vl_api_teib_send_t
vl_api_registration_
An API client registration, only in vpp/vlib.
Definition: api_common.h:47
REPLY_MACRO
#define REPLY_MACRO(t)
Definition: api_helper_macros.h:30
setup_message_id_table
static void setup_message_id_table(api_main_t *am)
Definition: sr_mpls_api.c:174
index_t
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:43
vl_api_teib_entry_add_del_t_handler
static void vl_api_teib_entry_add_del_t_handler(vl_api_teib_entry_add_del_t *mp)
Definition: teib_api.c:39
peer
vl_api_address_t peer
Definition: teib.api:28
teib_api_hookup
static clib_error_t * teib_api_hookup(vlib_main_t *vm)
Definition: teib_api.c:121
REPLY_MSG_ID_BASE
#define REPLY_MSG_ID_BASE
Definition: teib_api.c:34
nh
vl_api_fib_path_nh_t nh
Definition: fib_types.api:126
vl_api_teib_entry_add_del_t::entry
vl_api_teib_entry_t entry
Definition: teib.api:38
teib_entry_get_fib_index
u32 teib_entry_get_fib_index(const teib_entry_t *te)
Definition: teib.c:84
vl_api_teib_send_t_::reg
vl_api_registration_t * reg
Definition: teib_api.c:63
fib_prefix_t_::fp_addr
ip46_address_t fp_addr
The address type is not deriveable from the fp_addr member.
Definition: fib_types.h:225
VLIB_API_INIT_FUNCTION
VLIB_API_INIT_FUNCTION(teib_api_hookup)
ip_address_decode2
void ip_address_decode2(const vl_api_address_t *in, ip_address_t *out)
Definition: ip_types_api.c:178
BAD_SW_IF_INDEX_LABEL
#define BAD_SW_IF_INDEX_LABEL
Definition: api_helper_macros.h:289
format_fns.h
vl_api_teib_details_t::context
u32 context
Definition: teib.api:49
teib_entry_get_sw_if_index
u32 teib_entry_get_sw_if_index(const teib_entry_t *te)
accessors for the opaque struct
Definition: teib.c:72
u32
unsigned int u32
Definition: types.h:88
vl_api_teib_dump_t::context
u32 context
Definition: teib.api:44
ctx
long ctx[MAX_CONNS]
Definition: main.c:144
teib_entry_get_peer
const ip_address_t * teib_entry_get_peer(const teib_entry_t *te)
Definition: teib.c:90
vl_api_teib_details_t::entry
vl_api_teib_entry_t entry
Definition: teib.api:50
api_helper_macros.h
vl_api_teib_send_t_::context
u32 context
Definition: teib_api.c:64
fib_prefix_t_::fp_proto
fib_protocol_t fp_proto
protocol type
Definition: fib_types.h:211
vlib_main_t
Definition: main.h:102
teib_entry_del
int teib_entry_del(u32 sw_if_index, const ip_address_t *peer)
Definition: teib.c:258
ip_address_encode
void ip_address_encode(const ip46_address_t *in, ip46_type_t type, vl_api_address_t *out)
Definition: ip_types_api.c:206
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
teib_walk
void teib_walk(teib_walk_cb_t fn, void *ctx)
Definition: teib.c:315
rv
int __clib_unused rv
Definition: application.c:491
IP46_TYPE_ANY
@ IP46_TYPE_ANY
Definition: ip46_address.h:24
vnet.h
api_errno.h
vl_api_teib_details_t
Definition: teib.api:47
ip_types_api.h
walk_rc_t
enum walk_rc_t_ walk_rc_t
Walk return code.
fib_prefix_t_
Aggregate type for a prefix.
Definition: fib_types.h:202
teib_base_msg_id
static u32 teib_base_msg_id
Definition: teib_api.c:33
vl_api_teib_entry_add_del_t::is_add
u8 is_add
Definition: teib.api:37