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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
26 #include <vpp/app/version.h>
28 #include <vlibapi/api.h>
29 #include <vlibmemory/api.h>
31 /* define message IDs */
32 #include <vnet/format_fns.h>
33 #include <abf/abf.api_enum.h>
34 #include <abf/abf.api_types.h>
37 * Base message ID for the plugin
39 static u32 abf_base_msg_id;
41 #define REPLY_MSG_ID_BASE (abf_base_msg_id)
42 #include <vlibapi/api_helper_macros.h>
45 vl_api_abf_plugin_get_version_t_handler (vl_api_abf_plugin_get_version_t * mp)
47 vl_api_abf_plugin_get_version_reply_t *rmp;
48 vl_api_registration_t *rp;
50 rp = vl_api_client_index_to_registration (mp->client_index);
54 rmp = vl_msg_api_alloc (sizeof (*rmp));
56 ntohs (VL_API_ABF_PLUGIN_GET_VERSION_REPLY + abf_base_msg_id);
57 rmp->context = mp->context;
58 rmp->major = htonl (ABF_PLUGIN_VERSION_MAJOR);
59 rmp->minor = htonl (ABF_PLUGIN_VERSION_MINOR);
61 vl_api_send_msg (rp, (u8 *) rmp);
65 vl_api_abf_policy_add_del_t_handler (vl_api_abf_policy_add_del_t * mp)
67 vl_api_abf_policy_add_del_reply_t *rmp;
68 fib_route_path_t *paths = NULL, *path;
72 vec_validate (paths, mp->policy.n_paths - 1);
74 for (pi = 0; pi < mp->policy.n_paths; pi++)
77 rv = fib_api_path_decode (&mp->policy.paths[pi], path);
87 rv = abf_policy_update (ntohl (mp->policy.policy_id),
88 ntohl (mp->policy.acl_index), paths);
92 rv = abf_policy_delete (ntohl (mp->policy.policy_id), paths);
97 REPLY_MACRO (VL_API_ABF_POLICY_ADD_DEL_REPLY);
101 vl_api_abf_itf_attach_add_del_t_handler (vl_api_abf_itf_attach_add_del_t * mp)
103 vl_api_abf_itf_attach_add_del_reply_t *rmp;
104 fib_protocol_t fproto = (mp->attach.is_ipv6 ?
105 FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4);
110 abf_itf_attach (fproto,
111 ntohl (mp->attach.policy_id),
112 ntohl (mp->attach.priority),
113 ntohl (mp->attach.sw_if_index));
117 abf_itf_detach (fproto,
118 ntohl (mp->attach.policy_id),
119 ntohl (mp->attach.sw_if_index));
122 REPLY_MACRO (VL_API_ABF_ITF_ATTACH_ADD_DEL_REPLY);
125 typedef struct abf_dump_walk_ctx_t_
127 vl_api_registration_t *rp;
129 } abf_dump_walk_ctx_t;
132 abf_policy_send_details (u32 api, void *args)
134 fib_path_encode_ctx_t walk_ctx = {
137 vl_api_abf_policy_details_t *mp;
138 abf_dump_walk_ctx_t *ctx;
139 fib_route_path_t *rpath;
140 vl_api_fib_path_t *fp;
146 ap = abf_policy_get (api);
147 n_paths = fib_path_list_get_n_paths (ap->ap_pl);
148 msg_size = sizeof (*mp) + sizeof (mp->policy.paths[0]) * n_paths;
150 mp = vl_msg_api_alloc (msg_size);
151 clib_memset (mp, 0, msg_size);
152 mp->_vl_msg_id = ntohs (VL_API_ABF_POLICY_DETAILS + abf_base_msg_id);
154 /* fill in the message */
155 mp->context = ctx->context;
156 mp->policy.n_paths = n_paths;
157 mp->policy.acl_index = htonl (ap->ap_acl);
158 mp->policy.policy_id = htonl (ap->ap_id);
160 fib_path_list_walk_w_ext (ap->ap_pl, NULL, fib_path_encode, &walk_ctx);
162 fp = mp->policy.paths;
163 vec_foreach (rpath, walk_ctx.rpaths)
165 fib_api_path_encode (rpath, fp);
169 vl_api_send_msg (ctx->rp, (u8 *) mp);
171 vec_free (walk_ctx.rpaths);
177 vl_api_abf_policy_dump_t_handler (vl_api_abf_policy_dump_t * mp)
179 vl_api_registration_t *rp;
181 rp = vl_api_client_index_to_registration (mp->client_index);
185 abf_dump_walk_ctx_t ctx = {
187 .context = mp->context,
190 abf_policy_walk (abf_policy_send_details, &ctx);
194 abf_itf_attach_send_details (u32 aiai, void *args)
196 vl_api_abf_itf_attach_details_t *mp;
197 abf_dump_walk_ctx_t *ctx;
198 abf_itf_attach_t *aia;
202 aia = abf_itf_attach_get (aiai);
203 ap = abf_policy_get (aia->aia_abf);
205 mp = vl_msg_api_alloc (sizeof (*mp));
206 mp->_vl_msg_id = ntohs (VL_API_ABF_ITF_ATTACH_DETAILS + abf_base_msg_id);
208 mp->context = ctx->context;
209 mp->attach.policy_id = htonl (ap->ap_id);
210 mp->attach.sw_if_index = htonl (aia->aia_sw_if_index);
211 mp->attach.priority = htonl (aia->aia_prio);
212 mp->attach.is_ipv6 = (aia->aia_proto == FIB_PROTOCOL_IP6);
214 vl_api_send_msg (ctx->rp, (u8 *) mp);
220 vl_api_abf_itf_attach_dump_t_handler (vl_api_abf_itf_attach_dump_t * mp)
222 vl_api_registration_t *rp;
224 rp = vl_api_client_index_to_registration (mp->client_index);
228 abf_dump_walk_ctx_t ctx = {
230 .context = mp->context,
233 abf_itf_attach_walk (abf_itf_attach_send_details, &ctx);
236 #include <abf/abf.api.c>
238 static clib_error_t *
239 abf_api_init (vlib_main_t * vm)
241 /* Ask for a correctly-sized block of API message decode slots */
242 abf_base_msg_id = setup_message_id_table ();
247 VLIB_INIT_FUNCTION (abf_api_init);
250 VLIB_PLUGIN_REGISTER () = {
251 .version = VPP_BUILD_VER,
252 .description = "Access Control List (ACL) Based Forwarding",
257 * fd.io coding-style-patch-verification: ON
260 * eval: (c-set-style "gnu")