Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 1 | /* |
| 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 Camarillo | 5d73eec | 2017-04-24 17:51:56 +0200 | [diff] [blame] | 21 | #include <vnet/srv6/sr.h> |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 22 | #include <vlibmemory/api.h> |
| 23 | |
| 24 | #include <vnet/interface.h> |
| 25 | #include <vnet/api_errno.h> |
| 26 | #include <vnet/feature/feature.h> |
| 27 | |
| 28 | #include <vnet/vnet_msg_enum.h> |
| 29 | |
| 30 | #define vl_typedefs /* define message structures */ |
| 31 | #include <vnet/vnet_all_api_h.h> |
| 32 | #undef vl_typedefs |
| 33 | |
| 34 | #define vl_endianfun /* define message structures */ |
| 35 | #include <vnet/vnet_all_api_h.h> |
| 36 | #undef vl_endianfun |
| 37 | |
| 38 | /* instantiate all the print functions we know about */ |
| 39 | #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__) |
| 40 | #define vl_printfun |
| 41 | #include <vnet/vnet_all_api_h.h> |
| 42 | #undef vl_printfun |
| 43 | |
| 44 | #include <vlibapi/api_helper_macros.h> |
| 45 | |
| 46 | #define foreach_vpe_api_msg \ |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 47 | _(SR_LOCALSID_ADD_DEL, sr_localsid_add_del) \ |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 48 | _(SR_POLICY_ADD, sr_policy_add) \ |
| 49 | _(SR_POLICY_MOD, sr_policy_mod) \ |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 50 | _(SR_POLICY_DEL, sr_policy_del) \ |
Pablo Camarillo | 1a5e301 | 2017-11-16 16:02:50 +0100 | [diff] [blame] | 51 | _(SR_STEERING_ADD_DEL, sr_steering_add_del) \ |
| 52 | _(SR_SET_ENCAP_SOURCE, sr_set_encap_source) \ |
Ignas Bačius | eeb5fb3 | 2019-10-03 17:15:38 +0300 | [diff] [blame] | 53 | _(SR_SET_ENCAP_HOP_LIMIT, sr_set_encap_hop_limit) \ |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 54 | _(SR_LOCALSIDS_DUMP, sr_localsids_dump) \ |
| 55 | _(SR_POLICIES_DUMP, sr_policies_dump) \ |
| 56 | _(SR_STEERING_POL_DUMP, sr_steering_pol_dump) |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 57 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 58 | static void vl_api_sr_localsid_add_del_t_handler |
| 59 | (vl_api_sr_localsid_add_del_t * mp) |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 60 | { |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 61 | vl_api_sr_localsid_add_del_reply_t *rmp; |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 62 | int rv = 0; |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 63 | /* |
| 64 | * int sr_cli_localsid (char is_del, ip6_address_t *localsid_addr, |
| 65 | * char end_psp, u8 behavior, u32 sw_if_index, u32 vlan_index, u32 fib_table, |
| 66 | * ip46_address_t *nh_addr, void *ls_plugin_mem) |
| 67 | */ |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 68 | if (mp->behavior == SR_BEHAVIOR_X || |
| 69 | mp->behavior == SR_BEHAVIOR_DX6 || |
| 70 | mp->behavior == SR_BEHAVIOR_DX4 || mp->behavior == SR_BEHAVIOR_DX2) |
| 71 | VALIDATE_SW_IF_INDEX (mp); |
Chris Luke | 879ace3 | 2017-09-26 13:15:16 -0400 | [diff] [blame] | 72 | |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 73 | ip46_address_t prefix; |
| 74 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 75 | clib_memset (&prefix, 0, sizeof (ip46_address_t)); |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 76 | if ((mp->nh_addr4[0] | mp->nh_addr4[1] | mp-> |
| 77 | nh_addr4[2] | mp->nh_addr4[3]) != 0) |
| 78 | memcpy (&prefix.ip4, mp->nh_addr4, sizeof (prefix.ip4)); |
| 79 | else |
| 80 | memcpy (&prefix.ip6, mp->nh_addr6, sizeof (prefix.ip6)); |
Chris Luke | 879ace3 | 2017-09-26 13:15:16 -0400 | [diff] [blame] | 81 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 82 | rv = sr_cli_localsid (mp->is_del, |
Tetsuya Murakami | 1b81e6e | 2019-11-06 11:05:51 -0800 | [diff] [blame] | 83 | (ip6_address_t *) & mp->localsid, 0, |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 84 | mp->end_psp, |
| 85 | mp->behavior, |
| 86 | ntohl (mp->sw_if_index), |
| 87 | ntohl (mp->vlan_index), |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 88 | ntohl (mp->fib_table), &prefix, NULL); |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 89 | |
Chris Luke | 879ace3 | 2017-09-26 13:15:16 -0400 | [diff] [blame] | 90 | BAD_SW_IF_INDEX_LABEL; |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 91 | REPLY_MACRO (VL_API_SR_LOCALSID_ADD_DEL_REPLY); |
| 92 | } |
| 93 | |
| 94 | static void |
| 95 | vl_api_sr_policy_add_t_handler (vl_api_sr_policy_add_t * mp) |
| 96 | { |
| 97 | vl_api_sr_policy_add_reply_t *rmp; |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 98 | ip6_address_t *segments = 0, *seg; |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 99 | ip6_address_t *this_address = (ip6_address_t *) mp->sids.sids; |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 100 | |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 101 | int i; |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 102 | for (i = 0; i < mp->sids.num_sids; i++) |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 103 | { |
| 104 | vec_add2 (segments, seg, 1); |
| 105 | clib_memcpy (seg->as_u8, this_address->as_u8, sizeof (*this_address)); |
| 106 | this_address++; |
| 107 | } |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 108 | |
| 109 | /* |
| 110 | * sr_policy_add (ip6_address_t *bsid, ip6_address_t *segments, |
| 111 | * u32 weight, u8 behavior, u32 fib_table, u8 is_encap) |
| 112 | */ |
| 113 | int rv = 0; |
| 114 | rv = sr_policy_add ((ip6_address_t *) & mp->bsid_addr, |
| 115 | segments, |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 116 | ntohl (mp->sids.weight), |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 117 | mp->type, ntohl (mp->fib_table), mp->is_encap); |
John Lo | d23d39c | 2018-09-13 15:08:08 -0400 | [diff] [blame] | 118 | vec_free (segments); |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 119 | |
| 120 | REPLY_MACRO (VL_API_SR_POLICY_ADD_REPLY); |
| 121 | } |
| 122 | |
| 123 | static void |
| 124 | vl_api_sr_policy_mod_t_handler (vl_api_sr_policy_mod_t * mp) |
| 125 | { |
| 126 | vl_api_sr_policy_mod_reply_t *rmp; |
| 127 | |
| 128 | ip6_address_t *segments = 0, *seg; |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 129 | ip6_address_t *this_address = (ip6_address_t *) mp->sids.sids; |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 130 | |
| 131 | int i; |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 132 | for (i = 0; i < mp->sids.num_sids; i++) |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 133 | { |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 134 | vec_add2 (segments, seg, 1); |
| 135 | clib_memcpy (seg->as_u8, this_address->as_u8, sizeof (*this_address)); |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 136 | this_address++; |
| 137 | } |
| 138 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 139 | int rv = 0; |
| 140 | /* |
| 141 | * int |
| 142 | * sr_policy_mod(ip6_address_t *bsid, u32 index, u32 fib_table, |
| 143 | * u8 operation, ip6_address_t *segments, u32 sl_index, |
| 144 | * u32 weight, u8 is_encap) |
| 145 | */ |
| 146 | rv = sr_policy_mod ((ip6_address_t *) & mp->bsid_addr, |
| 147 | ntohl (mp->sr_policy_index), |
| 148 | ntohl (mp->fib_table), |
| 149 | mp->operation, |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 150 | segments, ntohl (mp->sl_index), |
| 151 | ntohl (mp->sids.weight)); |
John Lo | d23d39c | 2018-09-13 15:08:08 -0400 | [diff] [blame] | 152 | vec_free (segments); |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 153 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 154 | REPLY_MACRO (VL_API_SR_POLICY_MOD_REPLY); |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 155 | } |
| 156 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 157 | static void |
| 158 | vl_api_sr_policy_del_t_handler (vl_api_sr_policy_del_t * mp) |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 159 | { |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 160 | vl_api_sr_policy_del_reply_t *rmp; |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 161 | int rv = 0; |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 162 | /* |
| 163 | * int |
| 164 | * sr_policy_del (ip6_address_t *bsid, u32 index) |
| 165 | */ |
| 166 | rv = sr_policy_del ((ip6_address_t *) & mp->bsid_addr, |
| 167 | ntohl (mp->sr_policy_index)); |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 168 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 169 | REPLY_MACRO (VL_API_SR_POLICY_DEL_REPLY); |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 170 | } |
| 171 | |
Pablo Camarillo | 1a5e301 | 2017-11-16 16:02:50 +0100 | [diff] [blame] | 172 | static void |
| 173 | vl_api_sr_set_encap_source_t_handler (vl_api_sr_set_encap_source_t * mp) |
| 174 | { |
| 175 | vl_api_sr_set_encap_source_reply_t *rmp; |
| 176 | int rv = 0; |
| 177 | sr_set_source ((ip6_address_t *) & mp->encaps_source); |
| 178 | |
Vratko Polak | 1096b46 | 2019-08-21 18:40:03 +0200 | [diff] [blame] | 179 | REPLY_MACRO (VL_API_SR_SET_ENCAP_SOURCE_REPLY); |
Pablo Camarillo | 1a5e301 | 2017-11-16 16:02:50 +0100 | [diff] [blame] | 180 | } |
| 181 | |
Ignas Bačius | eeb5fb3 | 2019-10-03 17:15:38 +0300 | [diff] [blame] | 182 | static void |
| 183 | vl_api_sr_set_encap_hop_limit_t_handler (vl_api_sr_set_encap_hop_limit_t * mp) |
| 184 | { |
| 185 | vl_api_sr_set_encap_hop_limit_reply_t *rmp; |
| 186 | int rv = 0; |
| 187 | |
| 188 | if (mp->hop_limit == 0) |
| 189 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 190 | else |
| 191 | sr_set_hop_limit (mp->hop_limit); |
| 192 | |
| 193 | REPLY_MACRO (VL_API_SR_SET_ENCAP_HOP_LIMIT_REPLY); |
| 194 | } |
| 195 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 196 | static void vl_api_sr_steering_add_del_t_handler |
| 197 | (vl_api_sr_steering_add_del_t * mp) |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 198 | { |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 199 | vl_api_sr_steering_add_del_reply_t *rmp; |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 200 | int rv = 0; |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 201 | /* |
| 202 | * int |
| 203 | * sr_steering_policy(int is_del, ip6_address_t *bsid, u32 sr_policy_index, |
| 204 | * u32 table_id, ip46_address_t *prefix, u32 mask_width, u32 sw_if_index, |
| 205 | * u8 traffic_type) |
| 206 | */ |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 207 | if (mp->traffic_type == SR_STEER_L2) |
| 208 | VALIDATE_SW_IF_INDEX (mp); |
Chris Luke | 879ace3 | 2017-09-26 13:15:16 -0400 | [diff] [blame] | 209 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 210 | rv = sr_steering_policy (mp->is_del, |
| 211 | (ip6_address_t *) & mp->bsid_addr, |
| 212 | ntohl (mp->sr_policy_index), |
| 213 | ntohl (mp->table_id), |
| 214 | (ip46_address_t *) & mp->prefix_addr, |
| 215 | ntohl (mp->mask_width), |
| 216 | ntohl (mp->sw_if_index), mp->traffic_type); |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 217 | |
Chris Luke | 879ace3 | 2017-09-26 13:15:16 -0400 | [diff] [blame] | 218 | BAD_SW_IF_INDEX_LABEL; |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 219 | REPLY_MACRO (VL_API_SR_STEERING_ADD_DEL_REPLY); |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 220 | } |
| 221 | |
Pablo Camarillo | 1a5e301 | 2017-11-16 16:02:50 +0100 | [diff] [blame] | 222 | static void send_sr_localsid_details |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 223 | (ip6_sr_localsid_t * t, vl_api_registration_t * reg, u32 context) |
Pablo Camarillo | 1a5e301 | 2017-11-16 16:02:50 +0100 | [diff] [blame] | 224 | { |
| 225 | vl_api_sr_localsids_details_t *rmp; |
| 226 | |
| 227 | rmp = vl_msg_api_alloc (sizeof (*rmp)); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 228 | clib_memset (rmp, 0, sizeof (*rmp)); |
Pablo Camarillo | 1a5e301 | 2017-11-16 16:02:50 +0100 | [diff] [blame] | 229 | rmp->_vl_msg_id = ntohs (VL_API_SR_LOCALSIDS_DETAILS); |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 230 | clib_memcpy (rmp->addr.addr, &t->localsid, sizeof (ip6_address_t)); |
Pablo Camarillo | 1a5e301 | 2017-11-16 16:02:50 +0100 | [diff] [blame] | 231 | rmp->end_psp = t->end_psp; |
| 232 | rmp->behavior = htons (t->behavior); |
| 233 | rmp->fib_table = htonl (t->fib_table); |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 234 | rmp->vlan_index = htonl (t->vlan_index); |
| 235 | if (ip46_address_is_ip4 (&t->next_hop)) |
| 236 | clib_memcpy (rmp->xconnect_nh_addr4, &t->next_hop.ip4, |
| 237 | sizeof (ip4_address_t)); |
| 238 | else |
| 239 | clib_memcpy (rmp->xconnect_nh_addr6, &t->next_hop.ip6, |
| 240 | sizeof (ip6_address_t)); |
Pablo Camarillo | 1a5e301 | 2017-11-16 16:02:50 +0100 | [diff] [blame] | 241 | rmp->xconnect_iface_or_vrf_table = htonl (t->sw_if_index); |
| 242 | rmp->context = context; |
| 243 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 244 | vl_api_send_msg (reg, (u8 *) rmp); |
Pablo Camarillo | 1a5e301 | 2017-11-16 16:02:50 +0100 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | static void vl_api_sr_localsids_dump_t_handler |
| 248 | (vl_api_sr_localsids_dump_t * mp) |
| 249 | { |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 250 | vl_api_registration_t *reg; |
Pablo Camarillo | 1a5e301 | 2017-11-16 16:02:50 +0100 | [diff] [blame] | 251 | ip6_sr_main_t *sm = &sr_main; |
| 252 | ip6_sr_localsid_t *t; |
| 253 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 254 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 255 | if (!reg) |
| 256 | return; |
Pablo Camarillo | 1a5e301 | 2017-11-16 16:02:50 +0100 | [diff] [blame] | 257 | |
| 258 | /* *INDENT-OFF* */ |
| 259 | pool_foreach (t, sm->localsids, |
| 260 | ({ |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 261 | send_sr_localsid_details(t, reg, mp->context); |
Pablo Camarillo | 1a5e301 | 2017-11-16 16:02:50 +0100 | [diff] [blame] | 262 | })); |
| 263 | /* *INDENT-ON* */ |
| 264 | } |
| 265 | |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 266 | static void send_sr_policies_details |
| 267 | (ip6_sr_policy_t * t, vl_api_registration_t * reg, u32 context) |
| 268 | { |
| 269 | vl_api_sr_policies_details_t *rmp; |
| 270 | ip6_sr_main_t *sm = &sr_main; |
| 271 | |
| 272 | u32 *sl_index; |
| 273 | ip6_sr_sl_t *segment_list = 0; |
| 274 | vl_api_srv6_sid_list_t *write_sid_list; |
| 275 | |
| 276 | rmp = vl_msg_api_alloc (sizeof (*rmp) + |
| 277 | vec_len (t->segments_lists) * |
| 278 | sizeof (vl_api_srv6_sid_list_t)); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 279 | clib_memset (rmp, 0, |
| 280 | (sizeof (*rmp) + |
| 281 | vec_len (t->segments_lists) * |
| 282 | sizeof (vl_api_srv6_sid_list_t))); |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 283 | |
| 284 | rmp->_vl_msg_id = ntohs (VL_API_SR_POLICIES_DETAILS); |
| 285 | clib_memcpy (rmp->bsid.addr, &t->bsid, sizeof (ip6_address_t)); |
| 286 | rmp->is_encap = t->is_encap; |
| 287 | rmp->type = t->type; |
| 288 | rmp->fib_table = htonl (t->fib_table); |
| 289 | rmp->num_sid_lists = vec_len (t->segments_lists); |
| 290 | |
| 291 | /* Fill in all the segments lists */ |
| 292 | vec_foreach (sl_index, t->segments_lists) |
| 293 | { |
| 294 | segment_list = pool_elt_at_index (sm->sid_lists, *sl_index); |
| 295 | write_sid_list = &rmp->sid_lists[sl_index - t->segments_lists]; |
| 296 | write_sid_list->num_sids = vec_len (segment_list->segments); |
| 297 | write_sid_list->weight = htonl (segment_list->weight); |
| 298 | clib_memcpy (write_sid_list->sids, segment_list->segments, |
| 299 | vec_len (segment_list->segments) * sizeof (ip6_address_t)); |
| 300 | } |
| 301 | |
| 302 | rmp->context = context; |
| 303 | vl_api_send_msg (reg, (u8 *) rmp); |
| 304 | } |
| 305 | |
| 306 | static void |
| 307 | vl_api_sr_policies_dump_t_handler (vl_api_sr_policies_dump_t * mp) |
| 308 | { |
| 309 | vl_api_registration_t *reg; |
| 310 | ip6_sr_main_t *sm = &sr_main; |
| 311 | ip6_sr_policy_t *t; |
| 312 | |
| 313 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 314 | if (!reg) |
| 315 | return; |
| 316 | |
| 317 | /* *INDENT-OFF* */ |
| 318 | pool_foreach (t, sm->sr_policies, |
| 319 | ({ |
| 320 | send_sr_policies_details(t, reg, mp->context); |
| 321 | })); |
| 322 | /* *INDENT-ON* */ |
| 323 | } |
| 324 | |
| 325 | static void send_sr_steering_pol_details |
| 326 | (ip6_sr_steering_policy_t * t, vl_api_registration_t * reg, u32 context) |
| 327 | { |
| 328 | vl_api_sr_steering_pol_details_t *rmp; |
| 329 | ip6_sr_main_t *sm = &sr_main; |
| 330 | |
| 331 | rmp = vl_msg_api_alloc (sizeof (*rmp)); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 332 | clib_memset (rmp, 0, sizeof (*rmp)); |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 333 | rmp->_vl_msg_id = ntohs (VL_API_SR_STEERING_POL_DETAILS); |
| 334 | |
| 335 | //Get the SR policy BSID |
| 336 | ip6_sr_policy_t *p; |
| 337 | p = pool_elt_at_index (sm->sr_policies, t->sr_policy); |
| 338 | clib_memcpy (rmp->bsid.addr, &p->bsid, sizeof (ip6_address_t)); |
| 339 | |
| 340 | //Get the steering |
| 341 | rmp->traffic_type = t->classify.traffic_type; |
| 342 | rmp->fib_table = htonl (t->classify.l3.fib_table); |
| 343 | rmp->mask_width = htonl (t->classify.l3.mask_width); |
| 344 | if (ip46_address_is_ip4 (&t->classify.l3.prefix)) |
| 345 | clib_memcpy (rmp->prefix_addr, &t->classify.l3.prefix.ip4, |
| 346 | sizeof (ip4_address_t)); |
| 347 | else |
| 348 | clib_memcpy (rmp->prefix_addr, &t->classify.l3.prefix.ip6, |
| 349 | sizeof (ip6_address_t)); |
| 350 | |
| 351 | rmp->sw_if_index = htonl (t->classify.l2.sw_if_index); |
| 352 | |
| 353 | rmp->context = context; |
| 354 | vl_api_send_msg (reg, (u8 *) rmp); |
| 355 | } |
| 356 | |
| 357 | static void vl_api_sr_steering_pol_dump_t_handler |
| 358 | (vl_api_sr_policies_dump_t * mp) |
| 359 | { |
| 360 | vl_api_registration_t *reg; |
| 361 | ip6_sr_main_t *sm = &sr_main; |
| 362 | ip6_sr_steering_policy_t *t; |
| 363 | |
| 364 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 365 | if (!reg) |
| 366 | return; |
| 367 | |
| 368 | /* *INDENT-OFF* */ |
| 369 | pool_foreach (t, sm->steer_policies, |
| 370 | ({ |
| 371 | send_sr_steering_pol_details(t, reg, mp->context); |
| 372 | })); |
| 373 | /* *INDENT-ON* */ |
| 374 | } |
Pablo Camarillo | 1a5e301 | 2017-11-16 16:02:50 +0100 | [diff] [blame] | 375 | |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 376 | /* |
| 377 | * sr_api_hookup |
| 378 | * Add vpe's API message handlers to the table. |
Jim Thompson | f324dec | 2019-04-08 03:22:21 -0500 | [diff] [blame] | 379 | * vlib has already mapped shared memory and |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 380 | * added the client registration handlers. |
| 381 | * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process() |
| 382 | */ |
| 383 | #define vl_msg_name_crc_list |
| 384 | #include <vnet/vnet_all_api_h.h> |
| 385 | #undef vl_msg_name_crc_list |
| 386 | |
| 387 | static void |
| 388 | setup_message_id_table (api_main_t * am) |
| 389 | { |
| 390 | #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id); |
| 391 | foreach_vl_msg_name_crc_sr; |
| 392 | #undef _ |
| 393 | } |
| 394 | |
| 395 | static clib_error_t * |
| 396 | sr_api_hookup (vlib_main_t * vm) |
| 397 | { |
| 398 | api_main_t *am = &api_main; |
| 399 | |
| 400 | #define _(N,n) \ |
| 401 | vl_msg_api_set_handlers(VL_API_##N, #n, \ |
| 402 | vl_api_##n##_t_handler, \ |
| 403 | vl_noop_handler, \ |
| 404 | vl_api_##n##_t_endian, \ |
| 405 | vl_api_##n##_t_print, \ |
| 406 | sizeof(vl_api_##n##_t), 1); |
| 407 | foreach_vpe_api_msg; |
| 408 | #undef _ |
| 409 | |
| 410 | /* |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 411 | * Set up the (msg_name, crc, message-id) table |
| 412 | */ |
| 413 | setup_message_id_table (am); |
| 414 | |
| 415 | return 0; |
| 416 | } |
| 417 | |
| 418 | VLIB_API_INIT_FUNCTION (sr_api_hookup); |
| 419 | |
| 420 | /* |
| 421 | * fd.io coding-style-patch-verification: ON |
| 422 | * |
| 423 | * Local Variables: |
| 424 | * eval: (c-set-style "gnu") |
| 425 | * End: |
| 426 | */ |