FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
abf_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 <abf/abf_policy.h>
21 #include <abf/abf_itf_attach.h>
22 #include <vnet/mpls/mpls_types.h>
23 #include <vnet/fib/fib_path_list.h>
24 #include <vnet/fib/fib_api.h>
25 
26 #include <vpp/app/version.h>
27 
28 #include <vlibapi/api.h>
29 #include <vlibmemory/api.h>
30 
31 /* define message IDs */
32 #include <vnet/format_fns.h>
33 #include <abf/abf.api_enum.h>
34 #include <abf/abf.api_types.h>
35 
36 /**
37  * Base message ID fot the plugin
38  */
40 
42 
43 static void
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_ABF_PLUGIN_GET_VERSION_REPLY + abf_base_msg_id);
56  rmp->context = mp->context;
57  rmp->major = htonl (ABF_PLUGIN_VERSION_MAJOR);
58  rmp->minor = htonl (ABF_PLUGIN_VERSION_MINOR);
59 
60  vl_api_send_msg (rp, (u8 *) rmp);
61 }
62 
63 static void
65 {
66  vl_api_abf_policy_add_del_reply_t *rmp;
67  fib_route_path_t *paths = NULL, *path;
68  int rv = 0;
69  u8 pi;
70 
71  vec_validate (paths, mp->policy.n_paths - 1);
72 
73  for (pi = 0; pi < mp->policy.n_paths; pi++)
74  {
75  path = &paths[pi];
76  rv = fib_api_path_decode (&mp->policy.paths[pi], path);
77 
78  if (0 != rv)
79  {
80  goto done;
81  }
82  }
83 
84  if (mp->is_add)
85  {
86  rv = abf_policy_update (ntohl (mp->policy.policy_id),
87  ntohl (mp->policy.acl_index), paths);
88  }
89  else
90  {
91  rv = abf_policy_delete (ntohl (mp->policy.policy_id), paths);
92  }
93 done:
94  vec_free (paths);
95 
96  REPLY_MACRO (VL_API_ABF_POLICY_ADD_DEL_REPLY + abf_base_msg_id);
97 }
98 
99 static void
101 {
102  vl_api_abf_itf_attach_add_del_reply_t *rmp;
103  fib_protocol_t fproto = (mp->attach.is_ipv6 ?
105  int rv = 0;
106 
107  if (mp->is_add)
108  {
109  abf_itf_attach (fproto,
110  ntohl (mp->attach.policy_id),
111  ntohl (mp->attach.priority),
112  ntohl (mp->attach.sw_if_index));
113  }
114  else
115  {
116  abf_itf_detach (fproto,
117  ntohl (mp->attach.policy_id),
118  ntohl (mp->attach.sw_if_index));
119  }
120 
121  REPLY_MACRO (VL_API_ABF_ITF_ATTACH_ADD_DEL_REPLY + abf_base_msg_id);
122 }
123 
124 typedef struct abf_dump_walk_ctx_t_
125 {
129 
130 static int
132 {
133  fib_path_encode_ctx_t walk_ctx = {
134  .rpaths = NULL,
135  };
138  fib_route_path_t *rpath;
139  vl_api_fib_path_t *fp;
140  size_t msg_size;
141  abf_policy_t *ap;
142  u8 n_paths;
143 
144  ctx = args;
145  ap = abf_policy_get (api);
147  msg_size = sizeof (*mp) + sizeof (mp->policy.paths[0]) * n_paths;
148 
149  mp = vl_msg_api_alloc (msg_size);
150  clib_memset (mp, 0, msg_size);
151  mp->_vl_msg_id = ntohs (VL_API_ABF_POLICY_DETAILS + abf_base_msg_id);
152 
153  /* fill in the message */
154  mp->context = ctx->context;
155  mp->policy.n_paths = n_paths;
156  mp->policy.acl_index = htonl (ap->ap_acl);
157  mp->policy.policy_id = htonl (ap->ap_id);
158 
159  fib_path_list_walk_w_ext (ap->ap_pl, NULL, fib_path_encode, &walk_ctx);
160 
161  fp = mp->policy.paths;
162  vec_foreach (rpath, walk_ctx.rpaths)
163  {
164  fib_api_path_encode (rpath, fp);
165  fp++;
166  }
167 
168  vl_api_send_msg (ctx->rp, (u8 *) mp);
169 
170  vec_free (walk_ctx.rpaths);
171 
172  return (1);
173 }
174 
175 static void
177 {
179 
181  if (rp == 0)
182  return;
183 
185  .rp = rp,
186  .context = mp->context,
187  };
188 
190 }
191 
192 static int
194 {
197  abf_itf_attach_t *aia;
198  abf_policy_t *ap;
199 
200  ctx = args;
201  aia = abf_itf_attach_get (aiai);
202  ap = abf_policy_get (aia->aia_abf);
203 
204  mp = vl_msg_api_alloc (sizeof (*mp));
205  mp->_vl_msg_id = ntohs (VL_API_ABF_ITF_ATTACH_DETAILS + abf_base_msg_id);
206 
207  mp->context = ctx->context;
208  mp->attach.policy_id = htonl (ap->ap_id);
209  mp->attach.sw_if_index = htonl (aia->aia_sw_if_index);
210  mp->attach.priority = htonl (aia->aia_prio);
211  mp->attach.is_ipv6 = (aia->aia_proto == FIB_PROTOCOL_IP6);
212 
213  vl_api_send_msg (ctx->rp, (u8 *) mp);
214 
215  return (1);
216 }
217 
218 static void
220 {
222 
224  if (rp == 0)
225  return;
226 
228  .rp = rp,
229  .context = mp->context,
230  };
231 
233 }
234 
235 #include <abf/abf.api.c>
236 
237 static clib_error_t *
239 {
240  /* Ask for a correctly-sized block of API message decode slots */
242 
243  return 0;
244 }
245 
247 
248 /* *INDENT-OFF* */
250  .version = VPP_BUILD_VER,
251  .description = "Access Control List (ACL) Based Forwarding",
252 };
253 /* *INDENT-ON* */
254 
255 /*
256  * fd.io coding-style-patch-verification: ON
257  *
258  * Local Variables:
259  * eval: (c-set-style "gnu")
260  * End:
261  */
vl_api_abf_itf_attach_add_del_t
Add or delete a policy attachment to an interface.
Definition: abf.api:115
abf_policy_t_::ap_id
u32 ap_id
The policy ID - as configured by the client.
Definition: abf_policy.h:58
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
vl_api_abf_itf_attach_dump_t::client_index
u32 client_index
Definition: abf.api:138
ntohs
#define ntohs(x)
Definition: af_xdp.bpf.c:29
ABF_PLUGIN_VERSION_MINOR
#define ABF_PLUGIN_VERSION_MINOR
Definition: abf_policy.h:22
abf_itf_attach_send_details
static int abf_itf_attach_send_details(u32 aiai, void *args)
Definition: abf_api.c:193
fib_path_encode_ctx_t_
Path encode context to use when walking a path-list to encode paths.
Definition: fib_path.h:219
vl_api_send_msg
static void vl_api_send_msg(vl_api_registration_t *rp, u8 *elem)
Definition: api.h:35
vl_api_abf_itf_attach_details_t
Attachment details from a dump.
Definition: abf.api:126
path
vl_api_fib_path_t path
Definition: mfib_types.api:44
VLIB_PLUGIN_REGISTER
VLIB_PLUGIN_REGISTER()
paths
paths
Definition: map.api:460
vl_api_abf_policy_dump_t
Dump all ABF policies.
Definition: abf.api:91
ABF_PLUGIN_VERSION_MAJOR
#define ABF_PLUGIN_VERSION_MAJOR
Definition: abf_policy.h:21
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
vl_api_abf_plugin_get_version_t_handler
static void vl_api_abf_plugin_get_version_t_handler(vl_api_abf_plugin_get_version_t *mp)
Definition: abf_api.c:44
api.h
abf_itf_attach_t_
Attachment data for an ABF policy to an interface.
Definition: abf_itf_attach.h:25
abf_policy_t_
An ACL based Forwarding 'policy'.
Definition: abf_policy.h:33
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
abf_policy_get
abf_policy_t * abf_policy_get(u32 index)
Get an ABF object from its VPP index.
Definition: abf_policy.c:41
abf_itf_attach_t_::aia_sw_if_index
u32 aia_sw_if_index
The interface for the attachment.
Definition: abf_itf_attach.h:65
vl_api_abf_itf_attach_add_del_t::attach
vl_api_abf_itf_attach_t attach
Definition: abf.api:121
vl_api_abf_policy_dump_t_handler
static void vl_api_abf_policy_dump_t_handler(vl_api_abf_policy_dump_t *mp)
Definition: abf_api.c:176
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
abf_itf_attach.h
api
import vnet interface_types api
Definition: sample.api:20
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_abf_policy_details_t
Policy description returned in the dump.
Definition: abf.api:82
abf_itf_attach_get
static abf_itf_attach_t * abf_itf_attach_get(u32 index)
Definition: abf_itf_attach.h:81
vl_api_abf_plugin_get_version_t::client_index
u32 client_index
Definition: abf.api:34
abf_policy_t_::ap_pl
fib_node_index_t ap_pl
The path-list describing how to forward in case of a match.
Definition: abf_policy.h:48
abf_dump_walk_ctx_t_::context
u32 context
Definition: abf_api.c:127
vl_api_abf_policy_add_del_t
A description of an ABF policy.
Definition: abf.api:71
vl_api_abf_plugin_get_version_reply_t::minor
u32 minor
Definition: abf.api:48
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
abf_api_init
static clib_error_t * abf_api_init(vlib_main_t *vm)
Definition: abf_api.c:238
vl_api_abf_plugin_get_version_reply_t::major
u32 major
Definition: abf.api:47
vl_api_abf_plugin_get_version_t::context
u32 context
Definition: abf.api:35
abf_policy_send_details
static int abf_policy_send_details(u32 api, void *args)
Definition: abf_api.c:131
vec_validate
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment)
Definition: vec.h:523
vl_api_abf_itf_attach_dump_t_handler
static void vl_api_abf_itf_attach_dump_t_handler(vl_api_abf_itf_attach_dump_t *mp)
Definition: abf_api.c:219
fib_protocol_t
enum fib_protocol_t_ fib_protocol_t
Protocol Type.
vl_api_abf_itf_attach_add_del_t::is_add
bool is_add
Definition: abf.api:120
FIB_PROTOCOL_IP4
@ FIB_PROTOCOL_IP4
Definition: fib_types.h:36
abf_dump_walk_ctx_t_::rp
vl_api_registration_t * rp
Definition: abf_api.c:126
vl_api_abf_itf_attach_details_t::context
u32 context
Definition: abf.api:129
fib_api.h
vl_api_abf_itf_attach_add_del_t_handler
static void vl_api_abf_itf_attach_add_del_t_handler(vl_api_abf_itf_attach_add_del_t *mp)
Definition: abf_api.c:100
mpls_types.h
vl_api_abf_policy_details_t::policy
vl_api_abf_policy_t policy
Definition: abf.api:86
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
vec_free
#define vec_free(V)
Free vector's memory (no header).
Definition: vec.h:395
abf_itf_attach
typedef abf_itf_attach
A description of a policy attachment to an interface.
Definition: abf.api:106
fib_path_list.h
vl_api_abf_plugin_get_version_reply_t
Reply to get the plugin version.
Definition: abf.api:43
format_fns.h
abf_policy_walk
void abf_policy_walk(abf_policy_walk_cb_t cb, void *ctx)
Walk/visit each of the ABF policies.
Definition: abf_policy.c:344
abf_policy_t_::ap_acl
u32 ap_acl
ACL index to match.
Definition: abf_policy.h:43
u32
unsigned int u32
Definition: types.h:88
VLIB_INIT_FUNCTION
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:172
vl_api_abf_plugin_get_version_reply_t::context
u32 context
Definition: abf.api:46
abf_policy_delete
int abf_policy_delete(u32 policy_id, const fib_route_path_t *rpaths)
Delete paths from an ABF Policy.
Definition: abf_policy.c:181
abf_itf_attach_t_::aia_prio
u32 aia_prio
The priority of this policy for attachment.
Definition: abf_itf_attach.h:72
FIB_PROTOCOL_IP6
@ FIB_PROTOCOL_IP6
Definition: fib_types.h:37
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_abf_policy_details_t::context
u32 context
Definition: abf.api:85
abf_itf_detach
int abf_itf_detach(fib_protocol_t fproto, u32 policy_id, u32 sw_if_index)
Definition: abf_itf_attach.c:250
api_helper_macros.h
vec_foreach
#define vec_foreach(var, vec)
Vector iterator.
Definition: vec_bootstrap.h:213
vl_api_abf_itf_attach_details_t::attach
vl_api_abf_itf_attach_t attach
Definition: abf.api:130
clib_memset
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
vlib_main_t
Definition: main.h:102
abf_dump_walk_ctx_t
struct abf_dump_walk_ctx_t_ abf_dump_walk_ctx_t
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
vlib_init_function_t
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
Definition: init.h:51
abf_policy.h
vl_api_abf_policy_add_del_t::is_add
bool is_add
Definition: abf.api:76
rv
int __clib_unused rv
Definition: application.c:491
abf_policy_update
int abf_policy_update(u32 policy_id, u32 acl_index, const fib_route_path_t *rpaths)
Create or update an ABF Policy.
Definition: abf_policy.c:80
vnet.h
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
vl_api_abf_plugin_get_version_t
Get the plugin version.
Definition: abf.api:31
vl_api_abf_policy_add_del_t_handler
static void vl_api_abf_policy_add_del_t_handler(vl_api_abf_policy_add_del_t *mp)
Definition: abf_api.c:64
abf_base_msg_id
static u32 abf_base_msg_id
Base message ID fot the plugin.
Definition: abf_api.c:39
abf_itf_attach_walk
void abf_itf_attach_walk(abf_itf_attach_walk_cb_t cb, void *ctx)
Definition: abf_itf_attach.c:470
vl_api_abf_policy_dump_t::context
u32 context
Definition: abf.api:95
abf_itf_attach_t_::aia_abf
u32 aia_abf
The VPP index of the ABF policy.
Definition: abf_itf_attach.h:49
abf_itf_attach_t_::aia_proto
fib_protocol_t aia_proto
The protocol for the attachment.
Definition: abf_itf_attach.h:60
vl_api_abf_policy_add_del_t::policy
vl_api_abf_policy_t policy
Definition: abf.api:77
vl_api_abf_itf_attach_dump_t::context
u32 context
Definition: abf.api:139
vl_msg_api_alloc
void * vl_msg_api_alloc(int nbytes)
Definition: memory_shared.c:199
abf_dump_walk_ctx_t_
Definition: abf_api.c:124
vl_api_abf_itf_attach_dump_t
Dump all the policy attachments.
Definition: abf.api:135
vl_api_abf_policy_dump_t::client_index
u32 client_index
Definition: abf.api:94