blob: c039da01c6376fe726cd9a768180aa19508ebde1 [file] [log] [blame]
Pavel Kotucek0f971d82017-01-03 10:48:54 +01001/*
2 *------------------------------------------------------------------
3 * sr_api.c - ipv6 segment routing 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>
Pablo Camarillo5d73eec2017-04-24 17:51:56 +020021#include <vnet/srv6/sr.h>
Pavel Kotucek0f971d82017-01-03 10:48:54 +010022#include <vlibmemory/api.h>
23
24#include <vnet/interface.h>
25#include <vnet/api_errno.h>
26#include <vnet/feature/feature.h>
Ahmed Abdelsalam13e6fce2019-12-08 12:58:27 +010027#include <vnet/fib/fib_table.h>
Pavel Kotucek0f971d82017-01-03 10:48:54 +010028
Jakub Grajciar0938eba2020-03-04 13:08:27 +010029#include <vnet/ip/ip_types_api.h>
30
Pavel Kotucek0f971d82017-01-03 10:48:54 +010031#include <vnet/vnet_msg_enum.h>
32
33#define vl_typedefs /* define message structures */
34#include <vnet/vnet_all_api_h.h>
35#undef vl_typedefs
36
37#define vl_endianfun /* define message structures */
38#include <vnet/vnet_all_api_h.h>
39#undef vl_endianfun
40
41/* instantiate all the print functions we know about */
42#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
43#define vl_printfun
44#include <vnet/vnet_all_api_h.h>
45#undef vl_printfun
46
47#include <vlibapi/api_helper_macros.h>
48
49#define foreach_vpe_api_msg \
Pablo Camarillofb380952016-12-07 18:34:18 +010050_(SR_LOCALSID_ADD_DEL, sr_localsid_add_del) \
Pablo Camarillo3337bd22018-06-19 15:49:02 +020051_(SR_POLICY_ADD, sr_policy_add) \
52_(SR_POLICY_MOD, sr_policy_mod) \
Pablo Camarillofb380952016-12-07 18:34:18 +010053_(SR_POLICY_DEL, sr_policy_del) \
Pablo Camarillo1a5e3012017-11-16 16:02:50 +010054_(SR_STEERING_ADD_DEL, sr_steering_add_del) \
55_(SR_SET_ENCAP_SOURCE, sr_set_encap_source) \
Ignas Bačiuseeb5fb32019-10-03 17:15:38 +030056_(SR_SET_ENCAP_HOP_LIMIT, sr_set_encap_hop_limit) \
Pablo Camarillo3337bd22018-06-19 15:49:02 +020057_(SR_LOCALSIDS_DUMP, sr_localsids_dump) \
58_(SR_POLICIES_DUMP, sr_policies_dump) \
59_(SR_STEERING_POL_DUMP, sr_steering_pol_dump)
Pavel Kotucek0f971d82017-01-03 10:48:54 +010060
Pablo Camarillofb380952016-12-07 18:34:18 +010061static void vl_api_sr_localsid_add_del_t_handler
62 (vl_api_sr_localsid_add_del_t * mp)
Pavel Kotucek0f971d82017-01-03 10:48:54 +010063{
Pablo Camarillofb380952016-12-07 18:34:18 +010064 vl_api_sr_localsid_add_del_reply_t *rmp;
Pavel Kotucek0f971d82017-01-03 10:48:54 +010065 int rv = 0;
Jakub Grajciar0938eba2020-03-04 13:08:27 +010066 ip46_address_t prefix;
67 ip6_address_t localsid;
Pablo Camarillofb380952016-12-07 18:34:18 +010068/*
69 * int sr_cli_localsid (char is_del, ip6_address_t *localsid_addr,
70 * char end_psp, u8 behavior, u32 sw_if_index, u32 vlan_index, u32 fib_table,
71 * ip46_address_t *nh_addr, void *ls_plugin_mem)
72 */
Pablo Camarillo3337bd22018-06-19 15:49:02 +020073 if (mp->behavior == SR_BEHAVIOR_X ||
74 mp->behavior == SR_BEHAVIOR_DX6 ||
75 mp->behavior == SR_BEHAVIOR_DX4 || mp->behavior == SR_BEHAVIOR_DX2)
76 VALIDATE_SW_IF_INDEX (mp);
Chris Luke879ace32017-09-26 13:15:16 -040077
Jakub Grajciar0938eba2020-03-04 13:08:27 +010078 ip6_address_decode (mp->localsid, &localsid);
79 ip_address_decode (&mp->nh_addr, &prefix);
Chris Luke879ace32017-09-26 13:15:16 -040080
Pablo Camarillofb380952016-12-07 18:34:18 +010081 rv = sr_cli_localsid (mp->is_del,
Jakub Grajciar0938eba2020-03-04 13:08:27 +010082 &localsid, 128,
Pablo Camarillofb380952016-12-07 18:34:18 +010083 mp->end_psp,
84 mp->behavior,
85 ntohl (mp->sw_if_index),
86 ntohl (mp->vlan_index),
Tetsuya Murakamiec9cb962020-03-23 16:10:28 -070087 ntohl (mp->fib_table), &prefix, 0, NULL);
Pablo Camarillofb380952016-12-07 18:34:18 +010088
Chris Luke879ace32017-09-26 13:15:16 -040089 BAD_SW_IF_INDEX_LABEL;
Pablo Camarillofb380952016-12-07 18:34:18 +010090 REPLY_MACRO (VL_API_SR_LOCALSID_ADD_DEL_REPLY);
91}
92
93static void
94vl_api_sr_policy_add_t_handler (vl_api_sr_policy_add_t * mp)
95{
96 vl_api_sr_policy_add_reply_t *rmp;
Pavel Kotucek0f971d82017-01-03 10:48:54 +010097 ip6_address_t *segments = 0, *seg;
Jakub Grajciar0938eba2020-03-04 13:08:27 +010098 ip6_address_t bsid_addr;
Pablo Camarillofb380952016-12-07 18:34:18 +010099
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100100 int i;
Pablo Camarillo3337bd22018-06-19 15:49:02 +0200101 for (i = 0; i < mp->sids.num_sids; i++)
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100102 {
103 vec_add2 (segments, seg, 1);
Jakub Grajciar0938eba2020-03-04 13:08:27 +0100104 ip6_address_decode (mp->sids.sids[i], seg);
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100105 }
Pablo Camarillofb380952016-12-07 18:34:18 +0100106
Jakub Grajciar0938eba2020-03-04 13:08:27 +0100107 ip6_address_decode (mp->bsid_addr, &bsid_addr);
108
Pablo Camarillofb380952016-12-07 18:34:18 +0100109/*
110 * sr_policy_add (ip6_address_t *bsid, ip6_address_t *segments,
Tetsuya Murakami70d8ef82019-12-04 18:57:46 -0800111 * u32 weight, u8 behavior, u32 fib_table, u8 is_encap,
112 * u16 behavior, void *plugin_mem)
Pablo Camarillofb380952016-12-07 18:34:18 +0100113 */
114 int rv = 0;
Jakub Grajciar0938eba2020-03-04 13:08:27 +0100115 rv = sr_policy_add (&bsid_addr,
Pablo Camarillofb380952016-12-07 18:34:18 +0100116 segments,
Pablo Camarillo3337bd22018-06-19 15:49:02 +0200117 ntohl (mp->sids.weight),
Jakub Grajciar0938eba2020-03-04 13:08:27 +0100118 mp->is_spray, ntohl (mp->fib_table), mp->is_encap, 0,
119 NULL);
John Lod23d39c2018-09-13 15:08:08 -0400120 vec_free (segments);
Pablo Camarillofb380952016-12-07 18:34:18 +0100121
122 REPLY_MACRO (VL_API_SR_POLICY_ADD_REPLY);
123}
124
125static void
126vl_api_sr_policy_mod_t_handler (vl_api_sr_policy_mod_t * mp)
127{
128 vl_api_sr_policy_mod_reply_t *rmp;
Pablo Camarillofb380952016-12-07 18:34:18 +0100129 ip6_address_t *segments = 0, *seg;
Jakub Grajciar0938eba2020-03-04 13:08:27 +0100130 ip6_address_t bsid_addr;
Pablo Camarillofb380952016-12-07 18:34:18 +0100131
132 int i;
Pablo Camarillo3337bd22018-06-19 15:49:02 +0200133 for (i = 0; i < mp->sids.num_sids; i++)
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100134 {
Pablo Camarillofb380952016-12-07 18:34:18 +0100135 vec_add2 (segments, seg, 1);
Jakub Grajciar0938eba2020-03-04 13:08:27 +0100136 ip6_address_decode (mp->sids.sids[i], seg);
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100137 }
138
Jakub Grajciar0938eba2020-03-04 13:08:27 +0100139 ip6_address_decode (mp->bsid_addr, &bsid_addr);
140
Pablo Camarillofb380952016-12-07 18:34:18 +0100141 int rv = 0;
142/*
143 * int
144 * sr_policy_mod(ip6_address_t *bsid, u32 index, u32 fib_table,
145 * u8 operation, ip6_address_t *segments, u32 sl_index,
146 * u32 weight, u8 is_encap)
147 */
Jakub Grajciar0938eba2020-03-04 13:08:27 +0100148 rv = sr_policy_mod (&bsid_addr,
Pablo Camarillofb380952016-12-07 18:34:18 +0100149 ntohl (mp->sr_policy_index),
150 ntohl (mp->fib_table),
151 mp->operation,
Pablo Camarillo3337bd22018-06-19 15:49:02 +0200152 segments, ntohl (mp->sl_index),
153 ntohl (mp->sids.weight));
John Lod23d39c2018-09-13 15:08:08 -0400154 vec_free (segments);
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100155
Pablo Camarillofb380952016-12-07 18:34:18 +0100156 REPLY_MACRO (VL_API_SR_POLICY_MOD_REPLY);
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100157}
158
Pablo Camarillofb380952016-12-07 18:34:18 +0100159static void
160vl_api_sr_policy_del_t_handler (vl_api_sr_policy_del_t * mp)
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100161{
Pablo Camarillofb380952016-12-07 18:34:18 +0100162 vl_api_sr_policy_del_reply_t *rmp;
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100163 int rv = 0;
Jakub Grajciar0938eba2020-03-04 13:08:27 +0100164 ip6_address_t bsid_addr;
Pablo Camarillofb380952016-12-07 18:34:18 +0100165/*
166 * int
167 * sr_policy_del (ip6_address_t *bsid, u32 index)
168 */
Jakub Grajciar0938eba2020-03-04 13:08:27 +0100169 ip6_address_decode (mp->bsid_addr, &bsid_addr);
170 rv = sr_policy_del (&bsid_addr, ntohl (mp->sr_policy_index));
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100171
Pablo Camarillofb380952016-12-07 18:34:18 +0100172 REPLY_MACRO (VL_API_SR_POLICY_DEL_REPLY);
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100173}
174
Pablo Camarillo1a5e3012017-11-16 16:02:50 +0100175static void
176vl_api_sr_set_encap_source_t_handler (vl_api_sr_set_encap_source_t * mp)
177{
178 vl_api_sr_set_encap_source_reply_t *rmp;
179 int rv = 0;
Jakub Grajciar0938eba2020-03-04 13:08:27 +0100180 ip6_address_t encaps_source;
181
182 ip6_address_decode (mp->encaps_source, &encaps_source);
183 sr_set_source (&encaps_source);
Pablo Camarillo1a5e3012017-11-16 16:02:50 +0100184
Vratko Polak1096b462019-08-21 18:40:03 +0200185 REPLY_MACRO (VL_API_SR_SET_ENCAP_SOURCE_REPLY);
Pablo Camarillo1a5e3012017-11-16 16:02:50 +0100186}
187
Ignas Bačiuseeb5fb32019-10-03 17:15:38 +0300188static void
189vl_api_sr_set_encap_hop_limit_t_handler (vl_api_sr_set_encap_hop_limit_t * mp)
190{
191 vl_api_sr_set_encap_hop_limit_reply_t *rmp;
192 int rv = 0;
193
194 if (mp->hop_limit == 0)
195 rv = VNET_API_ERROR_INVALID_VALUE;
196 else
197 sr_set_hop_limit (mp->hop_limit);
198
199 REPLY_MACRO (VL_API_SR_SET_ENCAP_HOP_LIMIT_REPLY);
200}
201
Pablo Camarillofb380952016-12-07 18:34:18 +0100202static void vl_api_sr_steering_add_del_t_handler
203 (vl_api_sr_steering_add_del_t * mp)
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100204{
Pablo Camarillofb380952016-12-07 18:34:18 +0100205 vl_api_sr_steering_add_del_reply_t *rmp;
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100206 int rv = 0;
Jakub Grajciar0938eba2020-03-04 13:08:27 +0100207 ip6_address_t bsid_addr;
208 ip46_address_t prefix_addr;
Pablo Camarillofb380952016-12-07 18:34:18 +0100209/*
210 * int
211 * sr_steering_policy(int is_del, ip6_address_t *bsid, u32 sr_policy_index,
212 * u32 table_id, ip46_address_t *prefix, u32 mask_width, u32 sw_if_index,
213 * u8 traffic_type)
214 */
Jakub Grajciar0938eba2020-03-04 13:08:27 +0100215
216 ip6_address_decode (mp->bsid_addr, &bsid_addr);
217 ip_address_decode (&mp->prefix.address, &prefix_addr);
218
Pablo Camarillo3337bd22018-06-19 15:49:02 +0200219 if (mp->traffic_type == SR_STEER_L2)
220 VALIDATE_SW_IF_INDEX (mp);
Chris Luke879ace32017-09-26 13:15:16 -0400221
Pablo Camarillofb380952016-12-07 18:34:18 +0100222 rv = sr_steering_policy (mp->is_del,
Jakub Grajciar0938eba2020-03-04 13:08:27 +0100223 &bsid_addr,
Pablo Camarillofb380952016-12-07 18:34:18 +0100224 ntohl (mp->sr_policy_index),
225 ntohl (mp->table_id),
Jakub Grajciar0938eba2020-03-04 13:08:27 +0100226 &prefix_addr,
Ignas Bacius483a3d82020-04-06 16:31:27 +0300227 mp->prefix.len,
Pablo Camarillofb380952016-12-07 18:34:18 +0100228 ntohl (mp->sw_if_index), mp->traffic_type);
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100229
Chris Luke879ace32017-09-26 13:15:16 -0400230 BAD_SW_IF_INDEX_LABEL;
Pablo Camarillofb380952016-12-07 18:34:18 +0100231 REPLY_MACRO (VL_API_SR_STEERING_ADD_DEL_REPLY);
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100232}
233
Pablo Camarillo1a5e3012017-11-16 16:02:50 +0100234static void send_sr_localsid_details
Florin Coras6c4dae22018-01-09 06:39:23 -0800235 (ip6_sr_localsid_t * t, vl_api_registration_t * reg, u32 context)
Pablo Camarillo1a5e3012017-11-16 16:02:50 +0100236{
237 vl_api_sr_localsids_details_t *rmp;
238
239 rmp = vl_msg_api_alloc (sizeof (*rmp));
Dave Barachb7b92992018-10-17 10:38:51 -0400240 clib_memset (rmp, 0, sizeof (*rmp));
Pablo Camarillo1a5e3012017-11-16 16:02:50 +0100241 rmp->_vl_msg_id = ntohs (VL_API_SR_LOCALSIDS_DETAILS);
Jakub Grajciar0938eba2020-03-04 13:08:27 +0100242 ip6_address_encode (&t->localsid, rmp->addr);
Pablo Camarillo1a5e3012017-11-16 16:02:50 +0100243 rmp->end_psp = t->end_psp;
244 rmp->behavior = htons (t->behavior);
245 rmp->fib_table = htonl (t->fib_table);
Pablo Camarillo3337bd22018-06-19 15:49:02 +0200246 rmp->vlan_index = htonl (t->vlan_index);
Jakub Grajciar0938eba2020-03-04 13:08:27 +0100247 ip_address_encode (&t->next_hop, IP46_TYPE_ANY, &rmp->xconnect_nh_addr);
Ahmed Abdelsalam13e6fce2019-12-08 12:58:27 +0100248
249 if (t->behavior == SR_BEHAVIOR_T || t->behavior == SR_BEHAVIOR_DT6)
250 rmp->xconnect_iface_or_vrf_table =
251 htonl (fib_table_get_table_id (t->sw_if_index, FIB_PROTOCOL_IP6));
252 else if (t->behavior == SR_BEHAVIOR_DT4)
253 rmp->xconnect_iface_or_vrf_table =
254 htonl (fib_table_get_table_id (t->sw_if_index, FIB_PROTOCOL_IP4));
255 else
256 rmp->xconnect_iface_or_vrf_table = htonl (t->sw_if_index);
257
Pablo Camarillo1a5e3012017-11-16 16:02:50 +0100258 rmp->context = context;
259
Florin Coras6c4dae22018-01-09 06:39:23 -0800260 vl_api_send_msg (reg, (u8 *) rmp);
Pablo Camarillo1a5e3012017-11-16 16:02:50 +0100261}
262
263static void vl_api_sr_localsids_dump_t_handler
264 (vl_api_sr_localsids_dump_t * mp)
265{
Florin Coras6c4dae22018-01-09 06:39:23 -0800266 vl_api_registration_t *reg;
Pablo Camarillo1a5e3012017-11-16 16:02:50 +0100267 ip6_sr_main_t *sm = &sr_main;
268 ip6_sr_localsid_t *t;
269
Florin Coras6c4dae22018-01-09 06:39:23 -0800270 reg = vl_api_client_index_to_registration (mp->client_index);
271 if (!reg)
272 return;
Pablo Camarillo1a5e3012017-11-16 16:02:50 +0100273
274 /* *INDENT-OFF* */
275 pool_foreach (t, sm->localsids,
276 ({
Florin Coras6c4dae22018-01-09 06:39:23 -0800277 send_sr_localsid_details(t, reg, mp->context);
Pablo Camarillo1a5e3012017-11-16 16:02:50 +0100278 }));
279 /* *INDENT-ON* */
280}
281
Pablo Camarillo3337bd22018-06-19 15:49:02 +0200282static void send_sr_policies_details
283 (ip6_sr_policy_t * t, vl_api_registration_t * reg, u32 context)
284{
285 vl_api_sr_policies_details_t *rmp;
286 ip6_sr_main_t *sm = &sr_main;
287
Jakub Grajciar0938eba2020-03-04 13:08:27 +0100288 u32 *sl_index, slidx = 0;
Pablo Camarillo3337bd22018-06-19 15:49:02 +0200289 ip6_sr_sl_t *segment_list = 0;
Jakub Grajciar0938eba2020-03-04 13:08:27 +0100290 ip6_address_t *segment;
291 vl_api_srv6_sid_list_t *api_sid_list;
Pablo Camarillo3337bd22018-06-19 15:49:02 +0200292
293 rmp = vl_msg_api_alloc (sizeof (*rmp) +
294 vec_len (t->segments_lists) *
295 sizeof (vl_api_srv6_sid_list_t));
Dave Barachb7b92992018-10-17 10:38:51 -0400296 clib_memset (rmp, 0,
297 (sizeof (*rmp) +
298 vec_len (t->segments_lists) *
299 sizeof (vl_api_srv6_sid_list_t)));
Pablo Camarillo3337bd22018-06-19 15:49:02 +0200300
301 rmp->_vl_msg_id = ntohs (VL_API_SR_POLICIES_DETAILS);
Jakub Grajciar0938eba2020-03-04 13:08:27 +0100302 ip6_address_encode (&t->bsid, rmp->bsid);
Pablo Camarillo3337bd22018-06-19 15:49:02 +0200303 rmp->is_encap = t->is_encap;
Jakub Grajciar0938eba2020-03-04 13:08:27 +0100304 rmp->is_spray = t->type;
Pablo Camarillo3337bd22018-06-19 15:49:02 +0200305 rmp->fib_table = htonl (t->fib_table);
306 rmp->num_sid_lists = vec_len (t->segments_lists);
307
308 /* Fill in all the segments lists */
309 vec_foreach (sl_index, t->segments_lists)
310 {
311 segment_list = pool_elt_at_index (sm->sid_lists, *sl_index);
Jakub Grajciar0938eba2020-03-04 13:08:27 +0100312
313 api_sid_list = &rmp->sid_lists[sl_index - t->segments_lists];
314
315 api_sid_list->num_sids = vec_len (segment_list->segments);
316 api_sid_list->weight = htonl (segment_list->weight);
Chinmaya Agarwaledc2ea42020-06-23 12:38:23 +0000317 slidx = 0;
Jakub Grajciar0938eba2020-03-04 13:08:27 +0100318 vec_foreach (segment, segment_list->segments)
319 {
320 ip6_address_encode (segment, api_sid_list->sids[slidx++]);
321 }
Pablo Camarillo3337bd22018-06-19 15:49:02 +0200322 }
323
324 rmp->context = context;
325 vl_api_send_msg (reg, (u8 *) rmp);
326}
327
328static void
329vl_api_sr_policies_dump_t_handler (vl_api_sr_policies_dump_t * mp)
330{
331 vl_api_registration_t *reg;
332 ip6_sr_main_t *sm = &sr_main;
333 ip6_sr_policy_t *t;
334
335 reg = vl_api_client_index_to_registration (mp->client_index);
336 if (!reg)
337 return;
338
339 /* *INDENT-OFF* */
340 pool_foreach (t, sm->sr_policies,
341 ({
342 send_sr_policies_details(t, reg, mp->context);
343 }));
344 /* *INDENT-ON* */
345}
346
347static void send_sr_steering_pol_details
348 (ip6_sr_steering_policy_t * t, vl_api_registration_t * reg, u32 context)
349{
350 vl_api_sr_steering_pol_details_t *rmp;
351 ip6_sr_main_t *sm = &sr_main;
352
353 rmp = vl_msg_api_alloc (sizeof (*rmp));
Dave Barachb7b92992018-10-17 10:38:51 -0400354 clib_memset (rmp, 0, sizeof (*rmp));
Pablo Camarillo3337bd22018-06-19 15:49:02 +0200355 rmp->_vl_msg_id = ntohs (VL_API_SR_STEERING_POL_DETAILS);
356
357 //Get the SR policy BSID
358 ip6_sr_policy_t *p;
359 p = pool_elt_at_index (sm->sr_policies, t->sr_policy);
Jakub Grajciar0938eba2020-03-04 13:08:27 +0100360 ip6_address_encode (&p->bsid, rmp->bsid);
Pablo Camarillo3337bd22018-06-19 15:49:02 +0200361
362 //Get the steering
363 rmp->traffic_type = t->classify.traffic_type;
364 rmp->fib_table = htonl (t->classify.l3.fib_table);
Jakub Grajciar0938eba2020-03-04 13:08:27 +0100365 ip_address_encode (&t->classify.l3.prefix, IP46_TYPE_ANY,
366 &rmp->prefix.address);
Ignas Bacius483a3d82020-04-06 16:31:27 +0300367 rmp->prefix.len = t->classify.l3.mask_width;
Pablo Camarillo3337bd22018-06-19 15:49:02 +0200368
369 rmp->sw_if_index = htonl (t->classify.l2.sw_if_index);
370
371 rmp->context = context;
372 vl_api_send_msg (reg, (u8 *) rmp);
373}
374
375static void vl_api_sr_steering_pol_dump_t_handler
376 (vl_api_sr_policies_dump_t * mp)
377{
378 vl_api_registration_t *reg;
379 ip6_sr_main_t *sm = &sr_main;
380 ip6_sr_steering_policy_t *t;
381
382 reg = vl_api_client_index_to_registration (mp->client_index);
383 if (!reg)
384 return;
385
386 /* *INDENT-OFF* */
387 pool_foreach (t, sm->steer_policies,
388 ({
389 send_sr_steering_pol_details(t, reg, mp->context);
390 }));
391 /* *INDENT-ON* */
392}
Pablo Camarillo1a5e3012017-11-16 16:02:50 +0100393
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100394/*
395 * sr_api_hookup
396 * Add vpe's API message handlers to the table.
Jim Thompsonf324dec2019-04-08 03:22:21 -0500397 * vlib has already mapped shared memory and
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100398 * added the client registration handlers.
399 * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process()
400 */
401#define vl_msg_name_crc_list
402#include <vnet/vnet_all_api_h.h>
403#undef vl_msg_name_crc_list
404
405static void
406setup_message_id_table (api_main_t * am)
407{
408#define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
409 foreach_vl_msg_name_crc_sr;
410#undef _
411}
412
413static clib_error_t *
414sr_api_hookup (vlib_main_t * vm)
415{
Dave Barach39d69112019-11-27 11:42:13 -0500416 api_main_t *am = vlibapi_get_main ();
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100417
418#define _(N,n) \
419 vl_msg_api_set_handlers(VL_API_##N, #n, \
420 vl_api_##n##_t_handler, \
421 vl_noop_handler, \
422 vl_api_##n##_t_endian, \
423 vl_api_##n##_t_print, \
424 sizeof(vl_api_##n##_t), 1);
425 foreach_vpe_api_msg;
426#undef _
427
428 /*
Pavel Kotucek0f971d82017-01-03 10:48:54 +0100429 * Set up the (msg_name, crc, message-id) table
430 */
431 setup_message_id_table (am);
432
433 return 0;
434}
435
436VLIB_API_INIT_FUNCTION (sr_api_hookup);
437
438/*
439 * fd.io coding-style-patch-verification: ON
440 *
441 * Local Variables:
442 * eval: (c-set-style "gnu")
443 * End:
444 */