FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
l3xc_api.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <stddef.h>
17 
18 #include <vnet/vnet.h>
19 #include <vnet/plugin/plugin.h>
20 #include <l3xc/l3xc.h>
21 #include <vnet/mpls/mpls_types.h>
22 #include <vnet/fib/fib_path_list.h>
23 #include <vnet/fib/fib_api.h>
24 
25 #include <vpp/app/version.h>
26 
27 #include <vlibapi/api.h>
28 #include <vlibmemory/api.h>
29 
30 /* define message IDs */
31 #include <vnet/format_fns.h>
32 #include <l3xc/l3xc.api_enum.h>
33 #include <l3xc/l3xc.api_types.h>
34 
35 /**
36  * Base message ID fot the plugin
37  */
39 
41 
42 static void
44  mp)
45 {
48 
50  if (rp == 0)
51  return;
52 
53  rmp = vl_msg_api_alloc (sizeof (*rmp));
54  rmp->_vl_msg_id =
55  ntohs (VL_API_L3XC_PLUGIN_GET_VERSION_REPLY + l3xc_base_msg_id);
56  rmp->context = mp->context;
57  rmp->major = htonl (L3XC_PLUGIN_VERSION_MAJOR);
58  rmp->minor = htonl (L3XC_PLUGIN_VERSION_MINOR);
59 
60  vl_api_send_msg (rp, (u8 *) rmp);
61 }
62 
63 static void
65 {
67  fib_route_path_t *paths = NULL, *path;
68  int rv = 0;
69  u8 pi;
70 
72 
73  if (0 == mp->l3xc.n_paths)
74  {
75  rv = VNET_API_ERROR_INVALID_VALUE;
76  goto done;
77  }
78 
79  vec_validate (paths, mp->l3xc.n_paths - 1);
80 
81  for (pi = 0; pi < mp->l3xc.n_paths; pi++)
82  {
83  path = &paths[pi];
84  rv = fib_api_path_decode (&mp->l3xc.paths[pi], path);
85 
86  if (0 != rv)
87  {
88  goto done;
89  }
90  }
91 
92  rv = l3xc_update (ntohl (mp->l3xc.sw_if_index), mp->l3xc.is_ip6, paths);
93 
94 done:
95  vec_free (paths);
96 
98 
99  /* *INDENT-OFF* */
100  REPLY_MACRO2 (VL_API_L3XC_UPDATE_REPLY + l3xc_base_msg_id,
101  ({
102  rmp->stats_index = 0;
103  }))
104  /* *INDENT-ON* */
105 }
106 
107 static void
109 {
110  vl_api_l3xc_del_reply_t *rmp;
111  int rv = 0;
112 
114 
115  rv = l3xc_delete (ntohl (mp->sw_if_index), mp->is_ip6);
116 
118 
119  REPLY_MACRO (VL_API_L3XC_DEL_REPLY + l3xc_base_msg_id);
120 }
121 
122 typedef struct l3xc_dump_walk_ctx_t_
123 {
127 
128 static int
129 l3xc_send_details (u32 l3xci, void *args)
130 {
131  fib_path_encode_ctx_t path_ctx = {
132  .rpaths = NULL,
133  };
136  fib_route_path_t *rpath;
137  vl_api_fib_path_t *fp;
138  size_t msg_size;
139  l3xc_t *l3xc;
140  u8 n_paths;
141 
142  ctx = args;
143  l3xc = l3xc_get (l3xci);
145  msg_size = sizeof (*mp) + sizeof (mp->l3xc.paths[0]) * n_paths;
146 
147  mp = vl_msg_api_alloc (msg_size);
148  clib_memset (mp, 0, msg_size);
149  mp->_vl_msg_id = ntohs (VL_API_L3XC_DETAILS + l3xc_base_msg_id);
150 
151  /* fill in the message */
152  mp->context = ctx->context;
153  mp->l3xc.n_paths = n_paths;
154  mp->l3xc.sw_if_index = htonl (l3xc->l3xc_sw_if_index);
155 
156  fib_path_list_walk_w_ext (l3xc->l3xc_pl, NULL, fib_path_encode, &path_ctx);
157 
158  fp = mp->l3xc.paths;
159  vec_foreach (rpath, path_ctx.rpaths)
160  {
161  fib_api_path_encode (rpath, fp);
162  fp++;
163  }
164 
165  vl_api_send_msg (ctx->rp, (u8 *) mp);
166 
167  return (1);
168 }
169 
170 static void
172 {
175 
177  if (rp == 0)
178  return;
179 
181  .rp = rp,
182  .context = mp->context,
183  };
184 
185  sw_if_index = ntohl (mp->sw_if_index);
186 
187  if (~0 == sw_if_index)
189  else
190  {
191  fib_protocol_t fproto;
192  index_t l3xci;
193 
194  FOR_EACH_FIB_IP_PROTOCOL (fproto)
195  {
196  l3xci = l3xc_find (sw_if_index, fproto);
197 
198  if (INDEX_INVALID != l3xci)
199  l3xc_send_details (l3xci, &ctx);
200  }
201  }
202 }
203 
204 #include <l3xc/l3xc.api.c>
205 static clib_error_t *
207 {
208  /* Ask for a correctly-sized block of API message decode slots */
210 
211  return 0;
212 }
213 
215 
216 /* *INDENT-OFF* */
218  .version = VPP_BUILD_VER,
219  .description = "L3 Cross-Connect (L3XC)",
220 };
221 /* *INDENT-ON* */
222 
223 /*
224  * fd.io coding-style-patch-verification: ON
225  *
226  * Local Variables:
227  * eval: (c-set-style "gnu")
228  * End:
229  */
vl_api_l3xc_plugin_get_version_t::client_index
u32 client_index
Definition: l3xc.api:33
l3xc_delete
int l3xc_delete(u32 sw_if_index, u8 is_ip6)
Delete an L3XC.
Definition: l3xc.c:156
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_l3xc_dump_t::client_index
u32 client_index
Definition: l3xc.api:88
api.h
l3xc.h
ntohs
#define ntohs(x)
Definition: af_xdp.bpf.c:29
REPLY_MACRO2
#define REPLY_MACRO2(t, body)
Definition: api_helper_macros.h:65
fib_path_encode_ctx_t_
Path encode context to use when walking a path-list to encode paths.
Definition: fib_path.h:219
FOR_EACH_FIB_IP_PROTOCOL
#define FOR_EACH_FIB_IP_PROTOCOL(_item)
Definition: fib_types.h:69
vl_api_send_msg
static void vl_api_send_msg(vl_api_registration_t *rp, u8 *elem)
Definition: api.h:35
vl_api_l3xc_dump_t::sw_if_index
vl_api_interface_index_t sw_if_index
Definition: l3xc.api:90
path
vl_api_fib_path_t path
Definition: mfib_types.api:44
paths
paths
Definition: map.api:460
vl_api_l3xc_del_t::is_ip6
bool is_ip6
Definition: l3xc.api:81
l3xc_dump_walk_ctx_t_::context
u32 context
Definition: l3xc_api.c:125
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
api.h
vl_api_l3xc_plugin_get_version_t::context
u32 context
Definition: l3xc.api:34
vl_api_l3xc_plugin_get_version_t
Get the plugin version.
Definition: l3xc.api:31
n_paths
u8 n_paths
Definition: ip.api:147
fib_api_path_encode
void fib_api_path_encode(const fib_route_path_t *rpath, vl_api_fib_path_t *out)
Encode and decode functions from the API types to internal types.
Definition: fib_api.c:349
fib_path_list_get_n_paths
u32 fib_path_list_get_n_paths(fib_node_index_t path_list_index)
Definition: fib_path_list.c:595
fib_path_encode_ctx_t_::rpaths
fib_route_path_t * rpaths
Definition: fib_path.h:221
setup_message_id_table
static void setup_message_id_table(api_main_t *am)
Definition: bfd_api.c:451
vl_api_l3xc_del_t
Definition: l3xc.api:76
vl_api_l3xc_update_reply_t
Definition: l3xc.api:68
vl_api_l3xc_details_t
description returned in the dump
Definition: l3xc.api:95
vl_api_l3xc_plugin_get_version_t_handler
static void vl_api_l3xc_plugin_get_version_t_handler(vl_api_l3xc_plugin_get_version_t *mp)
Definition: l3xc_api.c:43
vl_api_l3xc_plugin_get_version_reply_t::minor
u32 minor
Definition: l3xc.api:46
l3xc_walk
void l3xc_walk(l3xc_walk_cb_t cb, void *ctx)
Walk/visit each of the L3XC policies.
Definition: l3xc.c:303
vl_api_l3xc_dump_t
Dump all L3XC policies.
Definition: l3xc.api:86
L3XC_PLUGIN_VERSION_MAJOR
#define L3XC_PLUGIN_VERSION_MAJOR
A L3 cross connect will send all traffic that is received on the input interface to the [set of] path...
Definition: l3xc.h:28
vl_api_l3xc_dump_t_handler
static void vl_api_l3xc_dump_t_handler(vl_api_l3xc_dump_t *mp)
Definition: l3xc_api.c:171
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
vl_api_l3xc_dump_t::context
u32 context
Definition: l3xc.api:89
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
VLIB_PLUGIN_REGISTER
VLIB_PLUGIN_REGISTER()
l3xc_dump_walk_ctx_t
struct l3xc_dump_walk_ctx_t_ l3xc_dump_walk_ctx_t
vec_validate
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment)
Definition: vec.h:523
l3xc_get
static_always_inline l3xc_t * l3xc_get(u32 index)
Definition: l3xc.h:104
fib_protocol_t
enum fib_protocol_t_ fib_protocol_t
Protocol Type.
l3xc_base_msg_id
static u32 l3xc_base_msg_id
Base message ID fot the plugin.
Definition: l3xc_api.c:38
vl_api_l3xc_update_reply_t::stats_index
u32 stats_index
Definition: l3xc.api:72
fib_api.h
vl_api_l3xc_plugin_get_version_reply_t::major
u32 major
Definition: l3xc.api:45
mpls_types.h
vl_api_l3xc_details_t::context
u32 context
Definition: l3xc.api:97
BAD_SW_IF_INDEX_LABEL
#define BAD_SW_IF_INDEX_LABEL
Definition: api_helper_macros.h:289
plugin.h
fib_path_list_walk_w_ext
void fib_path_list_walk_w_ext(fib_node_index_t path_list_index, const fib_path_ext_list_t *ext_list, fib_path_list_walk_w_ext_fn_t func, void *ctx)
Definition: fib_path_list.c:1401
l3xc
typedef l3xc
A description of an L3XC policy.
Definition: l3xc.api:55
vec_free
#define vec_free(V)
Free vector's memory (no header).
Definition: vec.h:395
l3xc_dump_walk_ctx_t_
Definition: l3xc_api.c:122
fib_path_list.h
format_fns.h
vl_api_l3xc_details_t::l3xc
vl_api_l3xc_t l3xc
Definition: l3xc.api:98
l3xc_update
int l3xc_update(u32 sw_if_index, u8 is_ip6, const fib_route_path_t *rpaths)
Create or update an L3XC Policy.
Definition: l3xc.c:83
u32
unsigned int u32
Definition: types.h:88
VLIB_INIT_FUNCTION
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:172
fib_route_path_t_
A representation of a path as described by a route producer.
Definition: fib_types.h:500
fib_path_encode
fib_path_list_walk_rc_t fib_path_encode(fib_node_index_t path_list_index, fib_node_index_t path_index, const fib_path_ext_t *path_ext, void *args)
Definition: fib_path.c:2708
ctx
long ctx[MAX_CONNS]
Definition: main.c:144
vl_api_l3xc_del_t_handler
static void vl_api_l3xc_del_t_handler(vl_api_l3xc_del_t *mp)
Definition: l3xc_api.c:108
api_helper_macros.h
vec_foreach
#define vec_foreach(var, vec)
Vector iterator.
Definition: vec_bootstrap.h:213
vl_api_l3xc_plugin_get_version_reply_t
Reply to get the plugin version.
Definition: l3xc.api:42
vl_api_l3xc_update_t
Definition: l3xc.api:62
vl_api_l3xc_del_t::sw_if_index
vl_api_interface_index_t sw_if_index
Definition: l3xc.api:80
vl_api_l3xc_plugin_get_version_reply_t::context
u32 context
Definition: l3xc.api:44
clib_memset
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
vlib_main_t
Definition: main.h:102
l3xc_dump_walk_ctx_t_::rp
vl_api_registration_t * rp
Definition: l3xc_api.c:124
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
L3XC_PLUGIN_VERSION_MINOR
#define L3XC_PLUGIN_VERSION_MINOR
Definition: l3xc.h:29
vlib_init_function_t
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
Definition: init.h:51
l3xc_t_
Definition: l3xc.h:33
rv
int __clib_unused rv
Definition: application.c:491
vnet.h
l3xc_find
index_t l3xc_find(u32 sw_if_index, fib_protocol_t fproto)
Find a L3 XC object from an interface and FIB protocol.
Definition: l3xc.c:38
INDEX_INVALID
#define INDEX_INVALID
Invalid index - used when no index is known blazoned capitals INVALID speak volumes where ~0 does not...
Definition: dpo.h:49
fib_api_path_decode
int fib_api_path_decode(vl_api_fib_path_t *in, fib_route_path_t *out)
Definition: fib_api.c:141
sw_if_index
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
l3xc_send_details
static int l3xc_send_details(u32 l3xci, void *args)
Definition: l3xc_api.c:129
l3xc_api_init
static clib_error_t * l3xc_api_init(vlib_main_t *vm)
Definition: l3xc_api.c:206
vl_api_l3xc_update_t_handler
static void vl_api_l3xc_update_t_handler(vl_api_l3xc_update_t *mp)
Definition: l3xc_api.c:64
vl_api_l3xc_update_t::l3xc
vl_api_l3xc_t l3xc
Definition: l3xc.api:66
vl_msg_api_alloc
void * vl_msg_api_alloc(int nbytes)
Definition: memory_shared.c:199