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> |
Ahmed Abdelsalam | 13e6fce | 2019-12-08 12:58:27 +0100 | [diff] [blame] | 27 | #include <vnet/fib/fib_table.h> |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 28 | |
Jakub Grajciar | 0938eba | 2020-03-04 13:08:27 +0100 | [diff] [blame] | 29 | #include <vnet/ip/ip_types_api.h> |
| 30 | |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 31 | #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 Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 50 | _(SR_LOCALSID_ADD_DEL, sr_localsid_add_del) \ |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 51 | _(SR_POLICY_ADD, sr_policy_add) \ |
| 52 | _(SR_POLICY_MOD, sr_policy_mod) \ |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 53 | _(SR_POLICY_DEL, sr_policy_del) \ |
Pablo Camarillo | 1a5e301 | 2017-11-16 16:02:50 +0100 | [diff] [blame] | 54 | _(SR_STEERING_ADD_DEL, sr_steering_add_del) \ |
| 55 | _(SR_SET_ENCAP_SOURCE, sr_set_encap_source) \ |
Ignas Bačius | eeb5fb3 | 2019-10-03 17:15:38 +0300 | [diff] [blame] | 56 | _(SR_SET_ENCAP_HOP_LIMIT, sr_set_encap_hop_limit) \ |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 57 | _(SR_LOCALSIDS_DUMP, sr_localsids_dump) \ |
| 58 | _(SR_POLICIES_DUMP, sr_policies_dump) \ |
Chinmaya Agarwal | 30fa97d | 2020-07-13 22:34:12 +0530 | [diff] [blame] | 59 | _(SR_POLICIES_WITH_SL_INDEX_DUMP, sr_policies_with_sl_index_dump) \ |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 60 | _(SR_STEERING_POL_DUMP, sr_steering_pol_dump) |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 61 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 62 | static void vl_api_sr_localsid_add_del_t_handler |
| 63 | (vl_api_sr_localsid_add_del_t * mp) |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 64 | { |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 65 | vl_api_sr_localsid_add_del_reply_t *rmp; |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 66 | int rv = 0; |
Jakub Grajciar | 0938eba | 2020-03-04 13:08:27 +0100 | [diff] [blame] | 67 | ip46_address_t prefix; |
| 68 | ip6_address_t localsid; |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 69 | /* |
| 70 | * int sr_cli_localsid (char is_del, ip6_address_t *localsid_addr, |
| 71 | * char end_psp, u8 behavior, u32 sw_if_index, u32 vlan_index, u32 fib_table, |
| 72 | * ip46_address_t *nh_addr, void *ls_plugin_mem) |
| 73 | */ |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 74 | if (mp->behavior == SR_BEHAVIOR_X || |
| 75 | mp->behavior == SR_BEHAVIOR_DX6 || |
| 76 | mp->behavior == SR_BEHAVIOR_DX4 || mp->behavior == SR_BEHAVIOR_DX2) |
| 77 | VALIDATE_SW_IF_INDEX (mp); |
Chris Luke | 879ace3 | 2017-09-26 13:15:16 -0400 | [diff] [blame] | 78 | |
Jakub Grajciar | 0938eba | 2020-03-04 13:08:27 +0100 | [diff] [blame] | 79 | ip6_address_decode (mp->localsid, &localsid); |
| 80 | ip_address_decode (&mp->nh_addr, &prefix); |
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, |
Jakub Grajciar | 0938eba | 2020-03-04 13:08:27 +0100 | [diff] [blame] | 83 | &localsid, 128, |
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), |
Tetsuya Murakami | ec9cb96 | 2020-03-23 16:10:28 -0700 | [diff] [blame] | 88 | ntohl (mp->fib_table), &prefix, 0, 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; |
Jakub Grajciar | 0938eba | 2020-03-04 13:08:27 +0100 | [diff] [blame] | 99 | ip6_address_t bsid_addr; |
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); |
Jakub Grajciar | 0938eba | 2020-03-04 13:08:27 +0100 | [diff] [blame] | 105 | ip6_address_decode (mp->sids.sids[i], seg); |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 106 | } |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 107 | |
Jakub Grajciar | 0938eba | 2020-03-04 13:08:27 +0100 | [diff] [blame] | 108 | ip6_address_decode (mp->bsid_addr, &bsid_addr); |
| 109 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 110 | /* |
| 111 | * sr_policy_add (ip6_address_t *bsid, ip6_address_t *segments, |
Tetsuya Murakami | 70d8ef8 | 2019-12-04 18:57:46 -0800 | [diff] [blame] | 112 | * u32 weight, u8 behavior, u32 fib_table, u8 is_encap, |
| 113 | * u16 behavior, void *plugin_mem) |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 114 | */ |
| 115 | int rv = 0; |
Jakub Grajciar | 0938eba | 2020-03-04 13:08:27 +0100 | [diff] [blame] | 116 | rv = sr_policy_add (&bsid_addr, |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 117 | segments, |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 118 | ntohl (mp->sids.weight), |
Jakub Grajciar | 0938eba | 2020-03-04 13:08:27 +0100 | [diff] [blame] | 119 | mp->is_spray, ntohl (mp->fib_table), mp->is_encap, 0, |
| 120 | NULL); |
John Lo | d23d39c | 2018-09-13 15:08:08 -0400 | [diff] [blame] | 121 | vec_free (segments); |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 122 | |
| 123 | REPLY_MACRO (VL_API_SR_POLICY_ADD_REPLY); |
| 124 | } |
| 125 | |
| 126 | static void |
| 127 | vl_api_sr_policy_mod_t_handler (vl_api_sr_policy_mod_t * mp) |
| 128 | { |
| 129 | vl_api_sr_policy_mod_reply_t *rmp; |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 130 | ip6_address_t *segments = 0, *seg; |
Jakub Grajciar | 0938eba | 2020-03-04 13:08:27 +0100 | [diff] [blame] | 131 | ip6_address_t bsid_addr; |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 132 | |
| 133 | int i; |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 134 | for (i = 0; i < mp->sids.num_sids; i++) |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 135 | { |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 136 | vec_add2 (segments, seg, 1); |
Jakub Grajciar | 0938eba | 2020-03-04 13:08:27 +0100 | [diff] [blame] | 137 | ip6_address_decode (mp->sids.sids[i], seg); |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 138 | } |
| 139 | |
Jakub Grajciar | 0938eba | 2020-03-04 13:08:27 +0100 | [diff] [blame] | 140 | ip6_address_decode (mp->bsid_addr, &bsid_addr); |
| 141 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 142 | int rv = 0; |
| 143 | /* |
| 144 | * int |
| 145 | * sr_policy_mod(ip6_address_t *bsid, u32 index, u32 fib_table, |
| 146 | * u8 operation, ip6_address_t *segments, u32 sl_index, |
| 147 | * u32 weight, u8 is_encap) |
| 148 | */ |
Jakub Grajciar | 0938eba | 2020-03-04 13:08:27 +0100 | [diff] [blame] | 149 | rv = sr_policy_mod (&bsid_addr, |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 150 | ntohl (mp->sr_policy_index), |
| 151 | ntohl (mp->fib_table), |
| 152 | mp->operation, |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 153 | segments, ntohl (mp->sl_index), |
| 154 | ntohl (mp->sids.weight)); |
John Lo | d23d39c | 2018-09-13 15:08:08 -0400 | [diff] [blame] | 155 | vec_free (segments); |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 156 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 157 | REPLY_MACRO (VL_API_SR_POLICY_MOD_REPLY); |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 158 | } |
| 159 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 160 | static void |
| 161 | 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] | 162 | { |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 163 | vl_api_sr_policy_del_reply_t *rmp; |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 164 | int rv = 0; |
Jakub Grajciar | 0938eba | 2020-03-04 13:08:27 +0100 | [diff] [blame] | 165 | ip6_address_t bsid_addr; |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 166 | /* |
| 167 | * int |
| 168 | * sr_policy_del (ip6_address_t *bsid, u32 index) |
| 169 | */ |
Jakub Grajciar | 0938eba | 2020-03-04 13:08:27 +0100 | [diff] [blame] | 170 | ip6_address_decode (mp->bsid_addr, &bsid_addr); |
| 171 | rv = sr_policy_del (&bsid_addr, ntohl (mp->sr_policy_index)); |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 172 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 173 | REPLY_MACRO (VL_API_SR_POLICY_DEL_REPLY); |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 174 | } |
| 175 | |
Pablo Camarillo | 1a5e301 | 2017-11-16 16:02:50 +0100 | [diff] [blame] | 176 | static void |
| 177 | vl_api_sr_set_encap_source_t_handler (vl_api_sr_set_encap_source_t * mp) |
| 178 | { |
| 179 | vl_api_sr_set_encap_source_reply_t *rmp; |
| 180 | int rv = 0; |
Jakub Grajciar | 0938eba | 2020-03-04 13:08:27 +0100 | [diff] [blame] | 181 | ip6_address_t encaps_source; |
| 182 | |
| 183 | ip6_address_decode (mp->encaps_source, &encaps_source); |
| 184 | sr_set_source (&encaps_source); |
Pablo Camarillo | 1a5e301 | 2017-11-16 16:02:50 +0100 | [diff] [blame] | 185 | |
Vratko Polak | 1096b46 | 2019-08-21 18:40:03 +0200 | [diff] [blame] | 186 | REPLY_MACRO (VL_API_SR_SET_ENCAP_SOURCE_REPLY); |
Pablo Camarillo | 1a5e301 | 2017-11-16 16:02:50 +0100 | [diff] [blame] | 187 | } |
| 188 | |
Ignas Bačius | eeb5fb3 | 2019-10-03 17:15:38 +0300 | [diff] [blame] | 189 | static void |
| 190 | vl_api_sr_set_encap_hop_limit_t_handler (vl_api_sr_set_encap_hop_limit_t * mp) |
| 191 | { |
| 192 | vl_api_sr_set_encap_hop_limit_reply_t *rmp; |
| 193 | int rv = 0; |
| 194 | |
| 195 | if (mp->hop_limit == 0) |
| 196 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 197 | else |
| 198 | sr_set_hop_limit (mp->hop_limit); |
| 199 | |
| 200 | REPLY_MACRO (VL_API_SR_SET_ENCAP_HOP_LIMIT_REPLY); |
| 201 | } |
| 202 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 203 | static void vl_api_sr_steering_add_del_t_handler |
| 204 | (vl_api_sr_steering_add_del_t * mp) |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 205 | { |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 206 | vl_api_sr_steering_add_del_reply_t *rmp; |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 207 | int rv = 0; |
Jakub Grajciar | 0938eba | 2020-03-04 13:08:27 +0100 | [diff] [blame] | 208 | ip6_address_t bsid_addr; |
| 209 | ip46_address_t prefix_addr; |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 210 | /* |
| 211 | * int |
| 212 | * sr_steering_policy(int is_del, ip6_address_t *bsid, u32 sr_policy_index, |
| 213 | * u32 table_id, ip46_address_t *prefix, u32 mask_width, u32 sw_if_index, |
| 214 | * u8 traffic_type) |
| 215 | */ |
Jakub Grajciar | 0938eba | 2020-03-04 13:08:27 +0100 | [diff] [blame] | 216 | |
| 217 | ip6_address_decode (mp->bsid_addr, &bsid_addr); |
| 218 | ip_address_decode (&mp->prefix.address, &prefix_addr); |
| 219 | |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 220 | if (mp->traffic_type == SR_STEER_L2) |
| 221 | VALIDATE_SW_IF_INDEX (mp); |
Chris Luke | 879ace3 | 2017-09-26 13:15:16 -0400 | [diff] [blame] | 222 | |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 223 | rv = sr_steering_policy (mp->is_del, |
Jakub Grajciar | 0938eba | 2020-03-04 13:08:27 +0100 | [diff] [blame] | 224 | &bsid_addr, |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 225 | ntohl (mp->sr_policy_index), |
| 226 | ntohl (mp->table_id), |
Jakub Grajciar | 0938eba | 2020-03-04 13:08:27 +0100 | [diff] [blame] | 227 | &prefix_addr, |
Ignas Bacius | 483a3d8 | 2020-04-06 16:31:27 +0300 | [diff] [blame] | 228 | mp->prefix.len, |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 229 | ntohl (mp->sw_if_index), mp->traffic_type); |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 230 | |
Chris Luke | 879ace3 | 2017-09-26 13:15:16 -0400 | [diff] [blame] | 231 | BAD_SW_IF_INDEX_LABEL; |
Pablo Camarillo | fb38095 | 2016-12-07 18:34:18 +0100 | [diff] [blame] | 232 | REPLY_MACRO (VL_API_SR_STEERING_ADD_DEL_REPLY); |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 233 | } |
| 234 | |
Pablo Camarillo | 1a5e301 | 2017-11-16 16:02:50 +0100 | [diff] [blame] | 235 | static void send_sr_localsid_details |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 236 | (ip6_sr_localsid_t * t, vl_api_registration_t * reg, u32 context) |
Pablo Camarillo | 1a5e301 | 2017-11-16 16:02:50 +0100 | [diff] [blame] | 237 | { |
| 238 | vl_api_sr_localsids_details_t *rmp; |
| 239 | |
| 240 | rmp = vl_msg_api_alloc (sizeof (*rmp)); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 241 | clib_memset (rmp, 0, sizeof (*rmp)); |
Pablo Camarillo | 1a5e301 | 2017-11-16 16:02:50 +0100 | [diff] [blame] | 242 | rmp->_vl_msg_id = ntohs (VL_API_SR_LOCALSIDS_DETAILS); |
Jakub Grajciar | 0938eba | 2020-03-04 13:08:27 +0100 | [diff] [blame] | 243 | ip6_address_encode (&t->localsid, rmp->addr); |
Pablo Camarillo | 1a5e301 | 2017-11-16 16:02:50 +0100 | [diff] [blame] | 244 | rmp->end_psp = t->end_psp; |
| 245 | rmp->behavior = htons (t->behavior); |
| 246 | rmp->fib_table = htonl (t->fib_table); |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 247 | rmp->vlan_index = htonl (t->vlan_index); |
Jakub Grajciar | 0938eba | 2020-03-04 13:08:27 +0100 | [diff] [blame] | 248 | ip_address_encode (&t->next_hop, IP46_TYPE_ANY, &rmp->xconnect_nh_addr); |
Ahmed Abdelsalam | 13e6fce | 2019-12-08 12:58:27 +0100 | [diff] [blame] | 249 | |
| 250 | if (t->behavior == SR_BEHAVIOR_T || t->behavior == SR_BEHAVIOR_DT6) |
| 251 | rmp->xconnect_iface_or_vrf_table = |
| 252 | htonl (fib_table_get_table_id (t->sw_if_index, FIB_PROTOCOL_IP6)); |
| 253 | else if (t->behavior == SR_BEHAVIOR_DT4) |
| 254 | rmp->xconnect_iface_or_vrf_table = |
| 255 | htonl (fib_table_get_table_id (t->sw_if_index, FIB_PROTOCOL_IP4)); |
| 256 | else |
| 257 | rmp->xconnect_iface_or_vrf_table = htonl (t->sw_if_index); |
| 258 | |
Pablo Camarillo | 1a5e301 | 2017-11-16 16:02:50 +0100 | [diff] [blame] | 259 | rmp->context = context; |
| 260 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 261 | vl_api_send_msg (reg, (u8 *) rmp); |
Pablo Camarillo | 1a5e301 | 2017-11-16 16:02:50 +0100 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | static void vl_api_sr_localsids_dump_t_handler |
| 265 | (vl_api_sr_localsids_dump_t * mp) |
| 266 | { |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 267 | vl_api_registration_t *reg; |
Pablo Camarillo | 1a5e301 | 2017-11-16 16:02:50 +0100 | [diff] [blame] | 268 | ip6_sr_main_t *sm = &sr_main; |
| 269 | ip6_sr_localsid_t *t; |
| 270 | |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 271 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 272 | if (!reg) |
| 273 | return; |
Pablo Camarillo | 1a5e301 | 2017-11-16 16:02:50 +0100 | [diff] [blame] | 274 | |
| 275 | /* *INDENT-OFF* */ |
Damjan Marion | b2c31b6 | 2020-12-13 21:47:40 +0100 | [diff] [blame] | 276 | pool_foreach (t, sm->localsids) |
| 277 | { |
Florin Coras | 6c4dae2 | 2018-01-09 06:39:23 -0800 | [diff] [blame] | 278 | send_sr_localsid_details(t, reg, mp->context); |
Damjan Marion | b2c31b6 | 2020-12-13 21:47:40 +0100 | [diff] [blame] | 279 | } |
Pablo Camarillo | 1a5e301 | 2017-11-16 16:02:50 +0100 | [diff] [blame] | 280 | /* *INDENT-ON* */ |
| 281 | } |
| 282 | |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 283 | static void send_sr_policies_details |
| 284 | (ip6_sr_policy_t * t, vl_api_registration_t * reg, u32 context) |
| 285 | { |
| 286 | vl_api_sr_policies_details_t *rmp; |
| 287 | ip6_sr_main_t *sm = &sr_main; |
| 288 | |
Jakub Grajciar | 0938eba | 2020-03-04 13:08:27 +0100 | [diff] [blame] | 289 | u32 *sl_index, slidx = 0; |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 290 | ip6_sr_sl_t *segment_list = 0; |
Jakub Grajciar | 0938eba | 2020-03-04 13:08:27 +0100 | [diff] [blame] | 291 | ip6_address_t *segment; |
| 292 | vl_api_srv6_sid_list_t *api_sid_list; |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 293 | |
| 294 | rmp = vl_msg_api_alloc (sizeof (*rmp) + |
| 295 | vec_len (t->segments_lists) * |
| 296 | sizeof (vl_api_srv6_sid_list_t)); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 297 | clib_memset (rmp, 0, |
| 298 | (sizeof (*rmp) + |
| 299 | vec_len (t->segments_lists) * |
| 300 | sizeof (vl_api_srv6_sid_list_t))); |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 301 | |
| 302 | rmp->_vl_msg_id = ntohs (VL_API_SR_POLICIES_DETAILS); |
Jakub Grajciar | 0938eba | 2020-03-04 13:08:27 +0100 | [diff] [blame] | 303 | ip6_address_encode (&t->bsid, rmp->bsid); |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 304 | rmp->is_encap = t->is_encap; |
Jakub Grajciar | 0938eba | 2020-03-04 13:08:27 +0100 | [diff] [blame] | 305 | rmp->is_spray = t->type; |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 306 | rmp->fib_table = htonl (t->fib_table); |
| 307 | rmp->num_sid_lists = vec_len (t->segments_lists); |
| 308 | |
| 309 | /* Fill in all the segments lists */ |
| 310 | vec_foreach (sl_index, t->segments_lists) |
| 311 | { |
| 312 | segment_list = pool_elt_at_index (sm->sid_lists, *sl_index); |
Jakub Grajciar | 0938eba | 2020-03-04 13:08:27 +0100 | [diff] [blame] | 313 | |
| 314 | api_sid_list = &rmp->sid_lists[sl_index - t->segments_lists]; |
| 315 | |
| 316 | api_sid_list->num_sids = vec_len (segment_list->segments); |
| 317 | api_sid_list->weight = htonl (segment_list->weight); |
Chinmaya Agarwal | edc2ea4 | 2020-06-23 12:38:23 +0000 | [diff] [blame] | 318 | slidx = 0; |
Jakub Grajciar | 0938eba | 2020-03-04 13:08:27 +0100 | [diff] [blame] | 319 | vec_foreach (segment, segment_list->segments) |
| 320 | { |
| 321 | ip6_address_encode (segment, api_sid_list->sids[slidx++]); |
| 322 | } |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | rmp->context = context; |
| 326 | vl_api_send_msg (reg, (u8 *) rmp); |
| 327 | } |
| 328 | |
| 329 | static void |
| 330 | vl_api_sr_policies_dump_t_handler (vl_api_sr_policies_dump_t * mp) |
| 331 | { |
| 332 | vl_api_registration_t *reg; |
| 333 | ip6_sr_main_t *sm = &sr_main; |
| 334 | ip6_sr_policy_t *t; |
| 335 | |
| 336 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 337 | if (!reg) |
| 338 | return; |
| 339 | |
| 340 | /* *INDENT-OFF* */ |
Damjan Marion | b2c31b6 | 2020-12-13 21:47:40 +0100 | [diff] [blame] | 341 | pool_foreach (t, sm->sr_policies) |
| 342 | { |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 343 | send_sr_policies_details(t, reg, mp->context); |
Damjan Marion | b2c31b6 | 2020-12-13 21:47:40 +0100 | [diff] [blame] | 344 | } |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 345 | /* *INDENT-ON* */ |
| 346 | } |
| 347 | |
Chinmaya Agarwal | 30fa97d | 2020-07-13 22:34:12 +0530 | [diff] [blame] | 348 | |
| 349 | |
| 350 | static void send_sr_policies_details_with_sl_index |
| 351 | (ip6_sr_policy_t * t, vl_api_registration_t * reg, u32 context) |
| 352 | { |
| 353 | vl_api_sr_policies_with_sl_index_details_t *rmp; |
| 354 | ip6_sr_main_t *sm = &sr_main; |
| 355 | |
| 356 | u32 *sl_index, slidx = 0; |
| 357 | ip6_sr_sl_t *segment_list = 0; |
| 358 | ip6_address_t *segment; |
| 359 | vl_api_srv6_sid_list_with_sl_index_t *api_sid_list; |
| 360 | |
| 361 | rmp = vl_msg_api_alloc (sizeof (*rmp) + |
| 362 | vec_len (t->segments_lists) * |
| 363 | sizeof (vl_api_srv6_sid_list_with_sl_index_t)); |
| 364 | clib_memset (rmp, 0, |
| 365 | (sizeof (*rmp) + |
| 366 | vec_len (t->segments_lists) * |
| 367 | sizeof (vl_api_srv6_sid_list_with_sl_index_t))); |
| 368 | |
| 369 | rmp->_vl_msg_id = ntohs (VL_API_SR_POLICIES_WITH_SL_INDEX_DETAILS); |
| 370 | ip6_address_encode (&t->bsid, rmp->bsid); |
| 371 | rmp->is_encap = t->is_encap; |
| 372 | rmp->is_spray = t->type; |
| 373 | rmp->fib_table = htonl (t->fib_table); |
| 374 | rmp->num_sid_lists = vec_len (t->segments_lists); |
| 375 | |
| 376 | /* Fill in all the segments lists */ |
| 377 | vec_foreach (sl_index, t->segments_lists) |
| 378 | { |
| 379 | segment_list = pool_elt_at_index (sm->sid_lists, *sl_index); |
| 380 | |
| 381 | api_sid_list = &rmp->sid_lists[sl_index - t->segments_lists]; |
| 382 | api_sid_list->sl_index = htonl (*sl_index); |
| 383 | api_sid_list->num_sids = vec_len (segment_list->segments); |
| 384 | api_sid_list->weight = htonl (segment_list->weight); |
| 385 | slidx = 0; |
| 386 | vec_foreach (segment, segment_list->segments) |
| 387 | { |
| 388 | ip6_address_encode (segment, api_sid_list->sids[slidx++]); |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | rmp->context = context; |
| 393 | vl_api_send_msg (reg, (u8 *) rmp); |
| 394 | } |
| 395 | |
| 396 | static void |
| 397 | vl_api_sr_policies_with_sl_index_dump_t_handler |
| 398 | (vl_api_sr_policies_with_sl_index_dump_t * mp) |
| 399 | { |
| 400 | vl_api_registration_t *reg; |
| 401 | ip6_sr_main_t *sm = &sr_main; |
| 402 | ip6_sr_policy_t *t; |
| 403 | |
| 404 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 405 | if (!reg) |
| 406 | return; |
| 407 | |
| 408 | /* *INDENT-OFF* */ |
Damjan Marion | b2c31b6 | 2020-12-13 21:47:40 +0100 | [diff] [blame] | 409 | pool_foreach (t, sm->sr_policies) |
| 410 | { |
Chinmaya Agarwal | 30fa97d | 2020-07-13 22:34:12 +0530 | [diff] [blame] | 411 | send_sr_policies_details_with_sl_index(t, reg, mp->context); |
Damjan Marion | b2c31b6 | 2020-12-13 21:47:40 +0100 | [diff] [blame] | 412 | } |
Chinmaya Agarwal | 30fa97d | 2020-07-13 22:34:12 +0530 | [diff] [blame] | 413 | /* *INDENT-ON* */ |
| 414 | } |
| 415 | |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 416 | static void send_sr_steering_pol_details |
| 417 | (ip6_sr_steering_policy_t * t, vl_api_registration_t * reg, u32 context) |
| 418 | { |
| 419 | vl_api_sr_steering_pol_details_t *rmp; |
| 420 | ip6_sr_main_t *sm = &sr_main; |
| 421 | |
| 422 | rmp = vl_msg_api_alloc (sizeof (*rmp)); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 423 | clib_memset (rmp, 0, sizeof (*rmp)); |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 424 | rmp->_vl_msg_id = ntohs (VL_API_SR_STEERING_POL_DETAILS); |
| 425 | |
| 426 | //Get the SR policy BSID |
| 427 | ip6_sr_policy_t *p; |
| 428 | p = pool_elt_at_index (sm->sr_policies, t->sr_policy); |
Jakub Grajciar | 0938eba | 2020-03-04 13:08:27 +0100 | [diff] [blame] | 429 | ip6_address_encode (&p->bsid, rmp->bsid); |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 430 | |
| 431 | //Get the steering |
| 432 | rmp->traffic_type = t->classify.traffic_type; |
| 433 | rmp->fib_table = htonl (t->classify.l3.fib_table); |
Jakub Grajciar | 0938eba | 2020-03-04 13:08:27 +0100 | [diff] [blame] | 434 | ip_address_encode (&t->classify.l3.prefix, IP46_TYPE_ANY, |
| 435 | &rmp->prefix.address); |
Ignas Bacius | 483a3d8 | 2020-04-06 16:31:27 +0300 | [diff] [blame] | 436 | rmp->prefix.len = t->classify.l3.mask_width; |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 437 | |
| 438 | rmp->sw_if_index = htonl (t->classify.l2.sw_if_index); |
| 439 | |
| 440 | rmp->context = context; |
| 441 | vl_api_send_msg (reg, (u8 *) rmp); |
| 442 | } |
| 443 | |
| 444 | static void vl_api_sr_steering_pol_dump_t_handler |
| 445 | (vl_api_sr_policies_dump_t * mp) |
| 446 | { |
| 447 | vl_api_registration_t *reg; |
| 448 | ip6_sr_main_t *sm = &sr_main; |
| 449 | ip6_sr_steering_policy_t *t; |
| 450 | |
| 451 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 452 | if (!reg) |
| 453 | return; |
| 454 | |
| 455 | /* *INDENT-OFF* */ |
Damjan Marion | b2c31b6 | 2020-12-13 21:47:40 +0100 | [diff] [blame] | 456 | pool_foreach (t, sm->steer_policies) |
| 457 | { |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 458 | send_sr_steering_pol_details(t, reg, mp->context); |
Damjan Marion | b2c31b6 | 2020-12-13 21:47:40 +0100 | [diff] [blame] | 459 | } |
Pablo Camarillo | 3337bd2 | 2018-06-19 15:49:02 +0200 | [diff] [blame] | 460 | /* *INDENT-ON* */ |
| 461 | } |
Pablo Camarillo | 1a5e301 | 2017-11-16 16:02:50 +0100 | [diff] [blame] | 462 | |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 463 | /* |
| 464 | * sr_api_hookup |
| 465 | * Add vpe's API message handlers to the table. |
Jim Thompson | f324dec | 2019-04-08 03:22:21 -0500 | [diff] [blame] | 466 | * vlib has already mapped shared memory and |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 467 | * added the client registration handlers. |
| 468 | * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process() |
| 469 | */ |
| 470 | #define vl_msg_name_crc_list |
| 471 | #include <vnet/vnet_all_api_h.h> |
| 472 | #undef vl_msg_name_crc_list |
| 473 | |
| 474 | static void |
| 475 | setup_message_id_table (api_main_t * am) |
| 476 | { |
| 477 | #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id); |
| 478 | foreach_vl_msg_name_crc_sr; |
| 479 | #undef _ |
| 480 | } |
| 481 | |
| 482 | static clib_error_t * |
| 483 | sr_api_hookup (vlib_main_t * vm) |
| 484 | { |
Dave Barach | 39d6911 | 2019-11-27 11:42:13 -0500 | [diff] [blame] | 485 | api_main_t *am = vlibapi_get_main (); |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 486 | |
| 487 | #define _(N,n) \ |
| 488 | vl_msg_api_set_handlers(VL_API_##N, #n, \ |
| 489 | vl_api_##n##_t_handler, \ |
| 490 | vl_noop_handler, \ |
| 491 | vl_api_##n##_t_endian, \ |
| 492 | vl_api_##n##_t_print, \ |
| 493 | sizeof(vl_api_##n##_t), 1); |
| 494 | foreach_vpe_api_msg; |
| 495 | #undef _ |
| 496 | |
| 497 | /* |
Pavel Kotucek | 0f971d8 | 2017-01-03 10:48:54 +0100 | [diff] [blame] | 498 | * Set up the (msg_name, crc, message-id) table |
| 499 | */ |
| 500 | setup_message_id_table (am); |
| 501 | |
| 502 | return 0; |
| 503 | } |
| 504 | |
| 505 | VLIB_API_INIT_FUNCTION (sr_api_hookup); |
| 506 | |
| 507 | /* |
| 508 | * fd.io coding-style-patch-verification: ON |
| 509 | * |
| 510 | * Local Variables: |
| 511 | * eval: (c-set-style "gnu") |
| 512 | * End: |
| 513 | */ |