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