FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
svs_api.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 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 <svs/svs.h>
21 #include <vnet/fib/fib_api.h>
22 #include <vnet/ip/ip_types_api.h>
23 
24 #include <vpp/app/version.h>
25 
26 #include <vlibapi/api.h>
27 #include <vlibmemory/api.h>
28 
29 /* define message IDs */
30 #include <vnet/format_fns.h>
31 #include <svs/svs.api_enum.h>
32 #include <svs/svs.api_types.h>
33 
34 /**
35  * Base message ID fot the plugin
36  */
39 
40 static void
42 {
44  int msg_size = sizeof (*rmp);
46 
48  if (rp == 0)
49  return;
50 
51  rmp = vl_msg_api_alloc (msg_size);
52  clib_memset (rmp, 0, msg_size);
53  rmp->_vl_msg_id =
54  ntohs (VL_API_SVS_PLUGIN_GET_VERSION_REPLY + svs_base_msg_id);
55  rmp->context = mp->context;
56  rmp->major = htonl (SVS_PLUGIN_VERSION_MAJOR);
57  rmp->minor = htonl (SVS_PLUGIN_VERSION_MINOR);
58 
59  vl_api_send_msg (rp, (u8 *) rmp);
60 }
61 
62 static void
64 {
65  vl_api_svs_table_add_del_reply_t *rmp;
66  fib_protocol_t fproto;
67  int rv = 0;
68 
69  rv = fib_proto_from_api_address_family (mp->af, &fproto);
70  if (rv < 0)
71  goto error;
72 
73  if (mp->is_add)
74  {
75  rv = svs_table_add (fproto, ntohl (mp->table_id));
76  }
77  else
78  {
79  rv = svs_table_delete (fproto, ntohl (mp->table_id));
80  }
81 
82 error:
83  REPLY_MACRO (VL_API_SVS_TABLE_ADD_DEL_REPLY + svs_base_msg_id);
84 }
85 
86 static void
88 {
89  vl_api_svs_route_add_del_reply_t *rmp;
90  fib_prefix_t pfx;
91  int rv = 0;
92 
93  ip_prefix_decode (&mp->prefix, &pfx);
94 
95  if (mp->is_add)
96  {
97  rv = svs_route_add (ntohl (mp->table_id), &pfx,
98  ntohl (mp->source_table_id));
99  }
100  else
101  {
102  rv = svs_route_delete (ntohl (mp->table_id), &pfx);
103  }
104 
105  REPLY_MACRO (VL_API_SVS_ROUTE_ADD_DEL_REPLY + svs_base_msg_id);
106 }
107 
108 static void
110 {
111  vl_api_svs_enable_disable_reply_t *rmp;
112  fib_protocol_t fproto;
113  int rv = 0;
114 
116 
117  rv = fib_proto_from_api_address_family (mp->af, &fproto);
118  if (rv < 0)
119  goto error;
120 
121  if (mp->is_enable)
122  {
123  rv = svs_enable (fproto, ntohl (mp->table_id), ntohl (mp->sw_if_index));
124  }
125  else
126  {
127  rv =
128  svs_disable (fproto, ntohl (mp->table_id), ntohl (mp->sw_if_index));
129  }
130 
132 error:
133  REPLY_MACRO (VL_API_SVS_ENABLE_DISABLE_REPLY + svs_base_msg_id);
134 }
135 
136 typedef struct svs_dump_walk_ctx_t_
137 {
141 
142 
143 static walk_rc_t
145  u32 table_id, u32 sw_if_index, void *args)
146 {
149 
150  ctx = args;
151 
152  mp = vl_msg_api_alloc (sizeof (*mp));
153  mp->_vl_msg_id = ntohs (VL_API_SVS_DETAILS + svs_base_msg_id);
154 
155  mp->context = ctx->context;
156  mp->sw_if_index = htonl (sw_if_index);
157  mp->table_id = htonl (table_id);
158  mp->af = fib_proto_to_api_address_family (fproto);
159 
160  vl_api_send_msg (ctx->rp, (u8 *) mp);
161 
162  return (WALK_CONTINUE);
163 }
164 
165 static void
167 {
169 
171  if (rp == 0)
172  return;
173 
175  .rp = rp,
176  .context = mp->context,
177  };
178 
180 }
181 
182 #include <svs/svs.api.c>
183 static clib_error_t *
185 {
186  /* Ask for a correctly-sized block of API message decode slots */
188 
189  return 0;
190 }
191 
193 
194 /* *INDENT-OFF* */
196  .version = VPP_BUILD_VER,
197  .description = "Source Virtual Routing and Fowarding (VRF) Select",
198 };
199 /* *INDENT-ON* */
200 
201 /*
202  * fd.io coding-style-patch-verification: ON
203  *
204  * Local Variables:
205  * eval: (c-set-style "gnu")
206  * End:
207  */
vl_api_svs_plugin_get_version_reply_t::context
u32 context
Definition: svs.api:46
vl_api_svs_details_t
SVS table-id to interface mapping.
Definition: svs.api:125
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
api.h
svs_api_init
static clib_error_t * svs_api_init(vlib_main_t *vm)
Definition: svs_api.c:184
vl_api_svs_table_add_del_t
Add a table in which to add routes that will match against source addresses.
Definition: svs.api:60
vl_api_svs_route_add_del_t
Add a route into the source address matching table.
Definition: svs.api:79
ntohs
#define ntohs(x)
Definition: af_xdp.bpf.c:29
vl_api_svs_plugin_get_version_reply_t::minor
u32 minor
Definition: svs.api:48
WALK_CONTINUE
@ WALK_CONTINUE
Definition: interface_funcs.h:174
vl_api_svs_route_add_del_t::source_table_id
u32 source_table_id
Definition: svs.api:86
vl_api_send_msg
static void vl_api_send_msg(vl_api_registration_t *rp, u8 *elem)
Definition: api.h:35
svs_dump_walk_ctx_t_::context
u32 context
Definition: svs_api.c:139
svs_route_add
int svs_route_add(u32 table_id, const fib_prefix_t *pfx, u32 source_table_id)
Definition: svs.c:82
svs_enable
int svs_enable(fib_protocol_t fproto, u32 table_id, u32 sw_if_index)
Definition: svs.c:118
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
api.h
vl_api_svs_plugin_get_version_t::context
u32 context
Definition: svs.api:35
SVS_PLUGIN_VERSION_MINOR
#define SVS_PLUGIN_VERSION_MINOR
Definition: svs.h:28
svs.h
vl_api_svs_dump_t
Dump the SVS table mappings of table_id to interface To see the routes added to a given table use ip_...
Definition: svs.api:112
vl_api_svs_enable_disable_t::af
vl_api_address_family_t af
Definition: svs.api:103
error
Definition: cJSON.c:88
svs_table_delete
int svs_table_delete(fib_protocol_t fproto, u32 table_id)
Definition: svs.c:40
svs_dump_walk_ctx_t_
Definition: svs_api.c:136
fib_proto_to_api_address_family
vl_api_address_family_t fib_proto_to_api_address_family(fib_protocol_t fproto)
Definition: fib_api.c:548
svs_walk
void svs_walk(svs_walk_fn_t fn, void *ctx)
Definition: svs.c:225
vl_api_svs_enable_disable_t::table_id
u32 table_id
Definition: svs.api:104
svs_disable
int svs_disable(fib_protocol_t fproto, u32 table_id, u32 sw_if_index)
Definition: svs.c:195
vl_api_svs_details_t::table_id
u32 table_id
Definition: svs.api:128
svs_base_msg_id
static u32 svs_base_msg_id
Base message ID fot the plugin.
Definition: svs_api.c:37
fib_proto_from_api_address_family
int fib_proto_from_api_address_family(vl_api_address_family_t af, fib_protocol_t *out)
Definition: fib_api.c:532
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
vl_api_svs_enable_disable_t_handler
static void vl_api_svs_enable_disable_t_handler(vl_api_svs_enable_disable_t *mp)
Definition: svs_api.c:109
vl_api_svs_route_add_del_t::prefix
vl_api_prefix_t prefix
Definition: svs.api:84
ip_prefix_decode
void ip_prefix_decode(const vl_api_prefix_t *in, fib_prefix_t *out)
Definition: ip_types_api.c:245
vl_api_svs_route_add_del_t::is_add
bool is_add
Definition: svs.api:83
svs_dump_walk_ctx_t_::rp
vl_api_registration_t * rp
Definition: svs_api.c:138
vl_api_svs_enable_disable_t::is_enable
bool is_enable
Definition: svs.api:102
fib_protocol_t
enum fib_protocol_t_ fib_protocol_t
Protocol Type.
vl_api_svs_dump_t_handler
static void vl_api_svs_dump_t_handler(vl_api_svs_dump_t *mp)
Definition: svs_api.c:166
vl_api_svs_plugin_get_version_t::client_index
u32 client_index
Definition: svs.api:34
fib_api.h
BAD_SW_IF_INDEX_LABEL
#define BAD_SW_IF_INDEX_LABEL
Definition: api_helper_macros.h:289
svs_dump_walk_ctx_t
struct svs_dump_walk_ctx_t_ svs_dump_walk_ctx_t
plugin.h
vl_api_svs_route_add_del_t::table_id
u32 table_id
Definition: svs.api:85
svs_table_add
int svs_table_add(fib_protocol_t fproto, u32 table_id)
Definition: svs.c:32
vl_api_svs_dump_t::context
u32 context
Definition: svs.api:115
format_fns.h
vl_api_svs_details_t::sw_if_index
vl_api_interface_index_t sw_if_index
Definition: svs.api:129
vl_api_svs_dump_t::client_index
u32 client_index
Definition: svs.api:114
u32
unsigned int u32
Definition: types.h:88
VLIB_INIT_FUNCTION
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:172
table_id
u32 table_id
Definition: wireguard.api:102
vl_api_svs_table_add_del_t::af
vl_api_address_family_t af
Definition: svs.api:65
ctx
long ctx[MAX_CONNS]
Definition: main.c:144
api_helper_macros.h
vl_api_svs_details_t::af
vl_api_address_family_t af
Definition: svs.api:130
vl_api_svs_enable_disable_t
Enable SVS on a given interface by using the given table to match RX'd packets' source addresses.
Definition: svs.api:98
svs_route_delete
int svs_route_delete(u32 table_id, const fib_prefix_t *pfx)
Definition: svs.c:103
svs_send_details
static walk_rc_t svs_send_details(fib_protocol_t fproto, u32 table_id, u32 sw_if_index, void *args)
Definition: svs_api.c:144
vl_api_svs_table_add_del_t::is_add
bool is_add
Definition: svs.api:64
clib_memset
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
vlib_main_t
Definition: main.h:102
vl_api_svs_enable_disable_t::sw_if_index
vl_api_interface_index_t sw_if_index
Definition: svs.api:105
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
vl_api_svs_plugin_get_version_t_handler
static void vl_api_svs_plugin_get_version_t_handler(vl_api_svs_plugin_get_version_t *mp)
Definition: svs_api.c:41
vlib_init_function_t
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
Definition: init.h:51
vl_api_svs_plugin_get_version_reply_t
Reply to get the plugin version.
Definition: svs.api:44
vl_api_svs_table_add_del_t::table_id
u32 table_id
Definition: svs.api:66
vl_api_svs_details_t::context
u32 context
Definition: svs.api:127
rv
int __clib_unused rv
Definition: application.c:491
VLIB_PLUGIN_REGISTER
VLIB_PLUGIN_REGISTER()
vnet.h
vl_api_svs_route_add_del_t_handler
static void vl_api_svs_route_add_del_t_handler(vl_api_svs_route_add_del_t *mp)
Definition: svs_api.c:87
sw_if_index
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
ip_types_api.h
walk_rc_t
enum walk_rc_t_ walk_rc_t
Walk return code.
vl_api_svs_table_add_del_t_handler
static void vl_api_svs_table_add_del_t_handler(vl_api_svs_table_add_del_t *mp)
Definition: svs_api.c:63
vl_api_svs_plugin_get_version_t
brief Get the plugin version
Definition: svs.api:32
fib_prefix_t_
Aggregate type for a prefix.
Definition: fib_types.h:202
SVS_PLUGIN_VERSION_MAJOR
#define SVS_PLUGIN_VERSION_MAJOR
Source VRF Selection matches against a packet's source address to set the VRF in which the subsequnet...
Definition: svs.h:27
vl_msg_api_alloc
void * vl_msg_api_alloc(int nbytes)
Definition: memory_shared.c:199
vl_api_svs_plugin_get_version_reply_t::major
u32 major
Definition: svs.api:47