Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 1 | /* |
| 2 | *------------------------------------------------------------------ |
| 3 | * bond_api.c - vnet bonding device driver API support |
| 4 | * |
| 5 | * Copyright (c) 2017 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> |
| 21 | #include <vlibmemory/api.h> |
| 22 | |
| 23 | #include <vnet/interface.h> |
| 24 | #include <vnet/api_errno.h> |
| 25 | #include <vnet/ethernet/ethernet.h> |
Jakub Grajciar | 3d1ef87 | 2019-08-26 12:55:15 +0200 | [diff] [blame] | 26 | #include <vnet/ethernet/ethernet_types_api.h> |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 27 | #include <vnet/bonding/node.h> |
| 28 | |
Filip Tehlar | 116a1e5 | 2021-06-22 09:24:06 +0000 | [diff] [blame] | 29 | #include <vnet/format_fns.h> |
| 30 | #include <vnet/bonding/bond.api_enum.h> |
| 31 | #include <vnet/bonding/bond.api_types.h> |
| 32 | |
| 33 | #define REPLY_MSG_ID_BASE msg_id_base |
| 34 | #include <vlibapi/api_helper_macros.h> |
| 35 | |
| 36 | static u16 msg_id_base; |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 37 | |
| 38 | static void |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 39 | vl_api_bond_delete_t_handler (vl_api_bond_delete_t * mp) |
| 40 | { |
| 41 | vlib_main_t *vm = vlib_get_main (); |
| 42 | int rv; |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 43 | vl_api_bond_delete_reply_t *rmp; |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 44 | u32 sw_if_index = ntohl (mp->sw_if_index); |
| 45 | |
Stanislav Zaikin | 9c6fd89 | 2023-10-13 17:48:53 +0200 | [diff] [blame] | 46 | VALIDATE_SW_IF_INDEX (mp); |
| 47 | |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 48 | rv = bond_delete_if (vm, sw_if_index); |
| 49 | |
Stanislav Zaikin | 9c6fd89 | 2023-10-13 17:48:53 +0200 | [diff] [blame] | 50 | BAD_SW_IF_INDEX_LABEL; |
Ole Troan | 2e1c896 | 2019-04-10 09:44:23 +0200 | [diff] [blame] | 51 | REPLY_MACRO (VL_API_BOND_DELETE_REPLY); |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | static void |
| 55 | vl_api_bond_create_t_handler (vl_api_bond_create_t * mp) |
| 56 | { |
| 57 | vlib_main_t *vm = vlib_get_main (); |
| 58 | vl_api_bond_create_reply_t *rmp; |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 59 | bond_create_if_args_t _a, *ap = &_a; |
| 60 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 61 | clib_memset (ap, 0, sizeof (*ap)); |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 62 | |
Alexander Chernavin | ad9d528 | 2018-12-13 09:08:09 -0500 | [diff] [blame] | 63 | ap->id = ntohl (mp->id); |
| 64 | |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 65 | if (mp->use_custom_mac) |
| 66 | { |
Jakub Grajciar | 3d1ef87 | 2019-08-26 12:55:15 +0200 | [diff] [blame] | 67 | mac_address_decode (mp->mac_address, (mac_address_t *) ap->hw_addr); |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 68 | ap->hw_addr_set = 1; |
| 69 | } |
| 70 | |
Jakub Grajciar | 3d1ef87 | 2019-08-26 12:55:15 +0200 | [diff] [blame] | 71 | ap->mode = ntohl (mp->mode); |
| 72 | ap->lb = ntohl (mp->lb); |
Zhiyong Yang | 751e3f3 | 2019-06-26 05:49:14 -0400 | [diff] [blame] | 73 | ap->numa_only = mp->numa_only; |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 74 | bond_create_if (vm, ap); |
| 75 | |
Ole Troan | 2e1c896 | 2019-04-10 09:44:23 +0200 | [diff] [blame] | 76 | int rv = ap->rv; |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 77 | |
Ole Troan | 2e1c896 | 2019-04-10 09:44:23 +0200 | [diff] [blame] | 78 | /* *INDENT-OFF* */ |
| 79 | REPLY_MACRO2(VL_API_BOND_CREATE_REPLY, |
| 80 | ({ |
| 81 | rmp->sw_if_index = ntohl (ap->sw_if_index); |
| 82 | })); |
| 83 | /* *INDENT-ON* */ |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | static void |
Steven Luong | ea71786 | 2020-07-30 07:31:40 -0700 | [diff] [blame] | 87 | vl_api_bond_create2_t_handler (vl_api_bond_create2_t * mp) |
| 88 | { |
| 89 | vlib_main_t *vm = vlib_get_main (); |
| 90 | vl_api_bond_create2_reply_t *rmp; |
| 91 | bond_create_if_args_t _a, *ap = &_a; |
| 92 | |
| 93 | clib_memset (ap, 0, sizeof (*ap)); |
| 94 | |
| 95 | ap->id = ntohl (mp->id); |
| 96 | |
| 97 | if (mp->use_custom_mac) |
| 98 | { |
| 99 | mac_address_decode (mp->mac_address, (mac_address_t *) ap->hw_addr); |
| 100 | ap->hw_addr_set = 1; |
| 101 | } |
| 102 | |
| 103 | ap->mode = ntohl (mp->mode); |
| 104 | ap->lb = ntohl (mp->lb); |
| 105 | ap->numa_only = mp->numa_only; |
| 106 | ap->gso = mp->enable_gso; |
| 107 | bond_create_if (vm, ap); |
| 108 | |
| 109 | int rv = ap->rv; |
| 110 | |
| 111 | /* *INDENT-OFF* */ |
| 112 | REPLY_MACRO2(VL_API_BOND_CREATE2_REPLY, |
| 113 | ({ |
| 114 | rmp->sw_if_index = ntohl (ap->sw_if_index); |
| 115 | })); |
| 116 | /* *INDENT-ON* */ |
| 117 | } |
| 118 | |
| 119 | static void |
Steven Luong | 4c4223e | 2020-07-15 08:44:54 -0700 | [diff] [blame] | 120 | vl_api_bond_add_member_t_handler (vl_api_bond_add_member_t * mp) |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 121 | { |
| 122 | vlib_main_t *vm = vlib_get_main (); |
Steven Luong | 4c4223e | 2020-07-15 08:44:54 -0700 | [diff] [blame] | 123 | vl_api_bond_add_member_reply_t *rmp; |
| 124 | bond_add_member_args_t _a, *ap = &_a; |
Ole Troan | 2e1c896 | 2019-04-10 09:44:23 +0200 | [diff] [blame] | 125 | int rv = 0; |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 126 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 127 | clib_memset (ap, 0, sizeof (*ap)); |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 128 | |
| 129 | ap->group = ntohl (mp->bond_sw_if_index); |
Steven Luong | 3f54d96 | 2020-08-10 09:34:07 -0700 | [diff] [blame] | 130 | VALIDATE_SW_IF_INDEX (mp); |
Steven Luong | 4c4223e | 2020-07-15 08:44:54 -0700 | [diff] [blame] | 131 | ap->member = ntohl (mp->sw_if_index); |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 132 | ap->is_passive = mp->is_passive; |
| 133 | ap->is_long_timeout = mp->is_long_timeout; |
| 134 | |
Steven Luong | 4c4223e | 2020-07-15 08:44:54 -0700 | [diff] [blame] | 135 | bond_add_member (vm, ap); |
Steven Luong | 3f54d96 | 2020-08-10 09:34:07 -0700 | [diff] [blame] | 136 | rv = ap->rv; |
Steven Luong | 4c4223e | 2020-07-15 08:44:54 -0700 | [diff] [blame] | 137 | |
Steven Luong | 3f54d96 | 2020-08-10 09:34:07 -0700 | [diff] [blame] | 138 | BAD_SW_IF_INDEX_LABEL; |
Steven Luong | 4c4223e | 2020-07-15 08:44:54 -0700 | [diff] [blame] | 139 | REPLY_MACRO (VL_API_BOND_ADD_MEMBER_REPLY); |
| 140 | } |
| 141 | |
| 142 | static void |
| 143 | vl_api_bond_enslave_t_handler (vl_api_bond_enslave_t * mp) |
| 144 | { |
| 145 | vlib_main_t *vm = vlib_get_main (); |
| 146 | vl_api_bond_enslave_reply_t *rmp; |
| 147 | bond_add_member_args_t _a, *ap = &_a; |
| 148 | int rv = 0; |
| 149 | |
| 150 | clib_memset (ap, 0, sizeof (*ap)); |
| 151 | |
| 152 | ap->group = ntohl (mp->bond_sw_if_index); |
Steven Luong | 3f54d96 | 2020-08-10 09:34:07 -0700 | [diff] [blame] | 153 | VALIDATE_SW_IF_INDEX (mp); |
Steven Luong | 4c4223e | 2020-07-15 08:44:54 -0700 | [diff] [blame] | 154 | ap->member = ntohl (mp->sw_if_index); |
| 155 | ap->is_passive = mp->is_passive; |
| 156 | ap->is_long_timeout = mp->is_long_timeout; |
| 157 | |
| 158 | bond_add_member (vm, ap); |
Steven Luong | 3f54d96 | 2020-08-10 09:34:07 -0700 | [diff] [blame] | 159 | rv = ap->rv; |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 160 | |
Steven Luong | 3f54d96 | 2020-08-10 09:34:07 -0700 | [diff] [blame] | 161 | BAD_SW_IF_INDEX_LABEL; |
Ole Troan | 2e1c896 | 2019-04-10 09:44:23 +0200 | [diff] [blame] | 162 | REPLY_MACRO (VL_API_BOND_ENSLAVE_REPLY); |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | static void |
Steven Luong | a1876b8 | 2019-08-20 16:58:00 -0700 | [diff] [blame] | 166 | vl_api_sw_interface_set_bond_weight_t_handler |
| 167 | (vl_api_sw_interface_set_bond_weight_t * mp) |
| 168 | { |
| 169 | vlib_main_t *vm = vlib_get_main (); |
| 170 | bond_set_intf_weight_args_t _a, *ap = &_a; |
| 171 | vl_api_sw_interface_set_bond_weight_reply_t *rmp; |
| 172 | int rv = 0; |
| 173 | |
Stanislav Zaikin | 9c6fd89 | 2023-10-13 17:48:53 +0200 | [diff] [blame] | 174 | VALIDATE_SW_IF_INDEX (mp); |
| 175 | |
Steven Luong | a1876b8 | 2019-08-20 16:58:00 -0700 | [diff] [blame] | 176 | clib_memset (ap, 0, sizeof (*ap)); |
| 177 | |
| 178 | ap->sw_if_index = ntohl (mp->sw_if_index); |
| 179 | ap->weight = ntohl (mp->weight); |
| 180 | |
| 181 | bond_set_intf_weight (vm, ap); |
Steven Luong | 3f54d96 | 2020-08-10 09:34:07 -0700 | [diff] [blame] | 182 | rv = ap->rv; |
Steven Luong | a1876b8 | 2019-08-20 16:58:00 -0700 | [diff] [blame] | 183 | |
Stanislav Zaikin | 9c6fd89 | 2023-10-13 17:48:53 +0200 | [diff] [blame] | 184 | BAD_SW_IF_INDEX_LABEL; |
Steven Luong | a1876b8 | 2019-08-20 16:58:00 -0700 | [diff] [blame] | 185 | REPLY_MACRO (VL_API_SW_INTERFACE_SET_BOND_WEIGHT_REPLY); |
| 186 | } |
| 187 | |
| 188 | static void |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 189 | vl_api_bond_detach_slave_t_handler (vl_api_bond_detach_slave_t * mp) |
| 190 | { |
| 191 | vlib_main_t *vm = vlib_get_main (); |
| 192 | vl_api_bond_detach_slave_reply_t *rmp; |
Steven Luong | 4c4223e | 2020-07-15 08:44:54 -0700 | [diff] [blame] | 193 | bond_detach_member_args_t _a, *ap = &_a; |
Ole Troan | 2e1c896 | 2019-04-10 09:44:23 +0200 | [diff] [blame] | 194 | int rv = 0; |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 195 | |
Stanislav Zaikin | 9c6fd89 | 2023-10-13 17:48:53 +0200 | [diff] [blame] | 196 | VALIDATE_SW_IF_INDEX (mp); |
| 197 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 198 | clib_memset (ap, 0, sizeof (*ap)); |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 199 | |
Steven Luong | 4c4223e | 2020-07-15 08:44:54 -0700 | [diff] [blame] | 200 | ap->member = ntohl (mp->sw_if_index); |
| 201 | bond_detach_member (vm, ap); |
Steven Luong | 3f54d96 | 2020-08-10 09:34:07 -0700 | [diff] [blame] | 202 | rv = ap->rv; |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 203 | |
Stanislav Zaikin | 9c6fd89 | 2023-10-13 17:48:53 +0200 | [diff] [blame] | 204 | BAD_SW_IF_INDEX_LABEL; |
Ole Troan | 2e1c896 | 2019-04-10 09:44:23 +0200 | [diff] [blame] | 205 | REPLY_MACRO (VL_API_BOND_DETACH_SLAVE_REPLY); |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | static void |
Steven Luong | 4c4223e | 2020-07-15 08:44:54 -0700 | [diff] [blame] | 209 | vl_api_bond_detach_member_t_handler (vl_api_bond_detach_member_t * mp) |
| 210 | { |
| 211 | vlib_main_t *vm = vlib_get_main (); |
| 212 | vl_api_bond_detach_member_reply_t *rmp; |
| 213 | bond_detach_member_args_t _a, *ap = &_a; |
| 214 | int rv = 0; |
| 215 | |
Stanislav Zaikin | 9c6fd89 | 2023-10-13 17:48:53 +0200 | [diff] [blame] | 216 | VALIDATE_SW_IF_INDEX (mp); |
| 217 | |
Steven Luong | 4c4223e | 2020-07-15 08:44:54 -0700 | [diff] [blame] | 218 | clib_memset (ap, 0, sizeof (*ap)); |
| 219 | |
| 220 | ap->member = ntohl (mp->sw_if_index); |
| 221 | bond_detach_member (vm, ap); |
Steven Luong | 3f54d96 | 2020-08-10 09:34:07 -0700 | [diff] [blame] | 222 | rv = ap->rv; |
Steven Luong | 4c4223e | 2020-07-15 08:44:54 -0700 | [diff] [blame] | 223 | |
Stanislav Zaikin | 9c6fd89 | 2023-10-13 17:48:53 +0200 | [diff] [blame] | 224 | BAD_SW_IF_INDEX_LABEL; |
Steven Luong | 4c4223e | 2020-07-15 08:44:54 -0700 | [diff] [blame] | 225 | REPLY_MACRO (VL_API_BOND_DETACH_MEMBER_REPLY); |
| 226 | } |
| 227 | |
| 228 | static void |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 229 | bond_send_sw_interface_details (vpe_api_main_t * am, |
| 230 | vl_api_registration_t * reg, |
| 231 | bond_interface_details_t * bond_if, |
| 232 | u32 context) |
| 233 | { |
| 234 | vl_api_sw_interface_bond_details_t *mp; |
| 235 | |
| 236 | mp = vl_msg_api_alloc (sizeof (*mp)); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 237 | clib_memset (mp, 0, sizeof (*mp)); |
Filip Tehlar | 116a1e5 | 2021-06-22 09:24:06 +0000 | [diff] [blame] | 238 | mp->_vl_msg_id = |
| 239 | htons (REPLY_MSG_ID_BASE + VL_API_SW_INTERFACE_BOND_DETAILS); |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 240 | mp->sw_if_index = htonl (bond_if->sw_if_index); |
Alexander Chernavin | ad9d528 | 2018-12-13 09:08:09 -0500 | [diff] [blame] | 241 | mp->id = htonl (bond_if->id); |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 242 | clib_memcpy (mp->interface_name, bond_if->interface_name, |
| 243 | MIN (ARRAY_LEN (mp->interface_name) - 1, |
| 244 | strlen ((const char *) bond_if->interface_name))); |
Jakub Grajciar | 3d1ef87 | 2019-08-26 12:55:15 +0200 | [diff] [blame] | 245 | mp->mode = htonl (bond_if->mode); |
| 246 | mp->lb = htonl (bond_if->lb); |
Zhiyong Yang | 751e3f3 | 2019-06-26 05:49:14 -0400 | [diff] [blame] | 247 | mp->numa_only = bond_if->numa_only; |
Steven Luong | 4c4223e | 2020-07-15 08:44:54 -0700 | [diff] [blame] | 248 | mp->active_slaves = htonl (bond_if->active_members); |
| 249 | mp->slaves = htonl (bond_if->members); |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 250 | |
| 251 | mp->context = context; |
| 252 | vl_api_send_msg (reg, (u8 *) mp); |
| 253 | } |
| 254 | |
| 255 | static void |
| 256 | vl_api_sw_interface_bond_dump_t_handler (vl_api_sw_interface_bond_dump_t * mp) |
| 257 | { |
| 258 | int rv; |
| 259 | vpe_api_main_t *am = &vpe_api_main; |
| 260 | vl_api_registration_t *reg; |
| 261 | bond_interface_details_t *bondifs = NULL; |
| 262 | bond_interface_details_t *bond_if = NULL; |
| 263 | |
| 264 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 265 | if (!reg) |
| 266 | return; |
| 267 | |
| 268 | rv = bond_dump_ifs (&bondifs); |
| 269 | if (rv) |
| 270 | return; |
| 271 | |
| 272 | vec_foreach (bond_if, bondifs) |
| 273 | { |
| 274 | bond_send_sw_interface_details (am, reg, bond_if, mp->context); |
| 275 | } |
| 276 | |
| 277 | vec_free (bondifs); |
| 278 | } |
| 279 | |
| 280 | static void |
Steven Luong | 4c4223e | 2020-07-15 08:44:54 -0700 | [diff] [blame] | 281 | bond_send_sw_bond_interface_details (vpe_api_main_t * am, |
| 282 | vl_api_registration_t * reg, |
| 283 | bond_interface_details_t * bond_if, |
| 284 | u32 context) |
| 285 | { |
| 286 | vl_api_sw_bond_interface_details_t *mp; |
| 287 | |
| 288 | mp = vl_msg_api_alloc (sizeof (*mp)); |
| 289 | clib_memset (mp, 0, sizeof (*mp)); |
Filip Tehlar | 116a1e5 | 2021-06-22 09:24:06 +0000 | [diff] [blame] | 290 | mp->_vl_msg_id = |
| 291 | htons (REPLY_MSG_ID_BASE + VL_API_SW_BOND_INTERFACE_DETAILS); |
Steven Luong | 4c4223e | 2020-07-15 08:44:54 -0700 | [diff] [blame] | 292 | mp->sw_if_index = htonl (bond_if->sw_if_index); |
| 293 | mp->id = htonl (bond_if->id); |
| 294 | clib_memcpy (mp->interface_name, bond_if->interface_name, |
| 295 | MIN (ARRAY_LEN (mp->interface_name) - 1, |
| 296 | strlen ((const char *) bond_if->interface_name))); |
| 297 | mp->mode = htonl (bond_if->mode); |
| 298 | mp->lb = htonl (bond_if->lb); |
| 299 | mp->numa_only = bond_if->numa_only; |
| 300 | mp->active_members = htonl (bond_if->active_members); |
| 301 | mp->members = htonl (bond_if->members); |
| 302 | |
| 303 | mp->context = context; |
| 304 | vl_api_send_msg (reg, (u8 *) mp); |
| 305 | } |
| 306 | |
| 307 | static void |
| 308 | vl_api_sw_bond_interface_dump_t_handler (vl_api_sw_bond_interface_dump_t * mp) |
| 309 | { |
| 310 | int rv; |
| 311 | vpe_api_main_t *am = &vpe_api_main; |
| 312 | vl_api_registration_t *reg; |
| 313 | bond_interface_details_t *bondifs = NULL; |
| 314 | bond_interface_details_t *bond_if = NULL; |
| 315 | u32 filter_sw_if_index; |
| 316 | |
| 317 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 318 | if (!reg) |
| 319 | return; |
| 320 | |
| 321 | filter_sw_if_index = htonl (mp->sw_if_index); |
| 322 | if (filter_sw_if_index != ~0) |
| 323 | VALIDATE_SW_IF_INDEX (mp); |
| 324 | |
| 325 | rv = bond_dump_ifs (&bondifs); |
| 326 | if (rv) |
| 327 | return; |
| 328 | |
| 329 | vec_foreach (bond_if, bondifs) |
| 330 | { |
| 331 | if ((filter_sw_if_index == ~0) || |
| 332 | (bond_if->sw_if_index == filter_sw_if_index)) |
| 333 | bond_send_sw_bond_interface_details (am, reg, bond_if, mp->context); |
| 334 | } |
| 335 | |
| 336 | BAD_SW_IF_INDEX_LABEL; |
| 337 | vec_free (bondifs); |
| 338 | } |
| 339 | |
| 340 | static void |
| 341 | bond_send_sw_member_interface_details (vpe_api_main_t * am, |
| 342 | vl_api_registration_t * reg, |
| 343 | member_interface_details_t * member_if, |
| 344 | u32 context) |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 345 | { |
| 346 | vl_api_sw_interface_slave_details_t *mp; |
| 347 | |
| 348 | mp = vl_msg_api_alloc (sizeof (*mp)); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 349 | clib_memset (mp, 0, sizeof (*mp)); |
Filip Tehlar | 116a1e5 | 2021-06-22 09:24:06 +0000 | [diff] [blame] | 350 | mp->_vl_msg_id = |
| 351 | htons (REPLY_MSG_ID_BASE + VL_API_SW_INTERFACE_SLAVE_DETAILS); |
Steven Luong | 4c4223e | 2020-07-15 08:44:54 -0700 | [diff] [blame] | 352 | mp->sw_if_index = htonl (member_if->sw_if_index); |
| 353 | clib_memcpy (mp->interface_name, member_if->interface_name, |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 354 | MIN (ARRAY_LEN (mp->interface_name) - 1, |
Steven Luong | 4c4223e | 2020-07-15 08:44:54 -0700 | [diff] [blame] | 355 | strlen ((const char *) member_if->interface_name))); |
| 356 | mp->is_passive = member_if->is_passive; |
| 357 | mp->is_long_timeout = member_if->is_long_timeout; |
| 358 | mp->is_local_numa = member_if->is_local_numa; |
| 359 | mp->weight = htonl (member_if->weight); |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 360 | |
| 361 | mp->context = context; |
| 362 | vl_api_send_msg (reg, (u8 *) mp); |
| 363 | } |
| 364 | |
| 365 | static void |
| 366 | vl_api_sw_interface_slave_dump_t_handler (vl_api_sw_interface_slave_dump_t * |
| 367 | mp) |
| 368 | { |
| 369 | int rv; |
| 370 | vpe_api_main_t *am = &vpe_api_main; |
| 371 | vl_api_registration_t *reg; |
Steven Luong | 4c4223e | 2020-07-15 08:44:54 -0700 | [diff] [blame] | 372 | member_interface_details_t *memberifs = NULL; |
| 373 | member_interface_details_t *member_if = NULL; |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 374 | |
| 375 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 376 | if (!reg) |
| 377 | return; |
| 378 | |
Steven Luong | 4c4223e | 2020-07-15 08:44:54 -0700 | [diff] [blame] | 379 | rv = bond_dump_member_ifs (&memberifs, ntohl (mp->sw_if_index)); |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 380 | if (rv) |
| 381 | return; |
| 382 | |
Steven Luong | 4c4223e | 2020-07-15 08:44:54 -0700 | [diff] [blame] | 383 | vec_foreach (member_if, memberifs) |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 384 | { |
Steven Luong | 4c4223e | 2020-07-15 08:44:54 -0700 | [diff] [blame] | 385 | bond_send_sw_member_interface_details (am, reg, member_if, mp->context); |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 386 | } |
| 387 | |
Steven Luong | 4c4223e | 2020-07-15 08:44:54 -0700 | [diff] [blame] | 388 | vec_free (memberifs); |
| 389 | } |
| 390 | |
| 391 | static void |
| 392 | bond_send_member_interface_details (vpe_api_main_t * am, |
| 393 | vl_api_registration_t * reg, |
| 394 | member_interface_details_t * member_if, |
| 395 | u32 context) |
| 396 | { |
| 397 | vl_api_sw_member_interface_details_t *mp; |
| 398 | |
| 399 | mp = vl_msg_api_alloc (sizeof (*mp)); |
| 400 | clib_memset (mp, 0, sizeof (*mp)); |
Filip Tehlar | 116a1e5 | 2021-06-22 09:24:06 +0000 | [diff] [blame] | 401 | mp->_vl_msg_id = |
| 402 | htons (REPLY_MSG_ID_BASE + VL_API_SW_MEMBER_INTERFACE_DETAILS); |
Steven Luong | 4c4223e | 2020-07-15 08:44:54 -0700 | [diff] [blame] | 403 | mp->sw_if_index = htonl (member_if->sw_if_index); |
| 404 | clib_memcpy (mp->interface_name, member_if->interface_name, |
| 405 | MIN (ARRAY_LEN (mp->interface_name) - 1, |
| 406 | strlen ((const char *) member_if->interface_name))); |
| 407 | mp->is_passive = member_if->is_passive; |
| 408 | mp->is_long_timeout = member_if->is_long_timeout; |
| 409 | mp->is_local_numa = member_if->is_local_numa; |
| 410 | mp->weight = htonl (member_if->weight); |
| 411 | |
| 412 | mp->context = context; |
| 413 | vl_api_send_msg (reg, (u8 *) mp); |
| 414 | } |
| 415 | |
| 416 | static void |
| 417 | vl_api_sw_member_interface_dump_t_handler (vl_api_sw_member_interface_dump_t * |
| 418 | mp) |
| 419 | { |
| 420 | int rv; |
| 421 | vpe_api_main_t *am = &vpe_api_main; |
| 422 | vl_api_registration_t *reg; |
| 423 | member_interface_details_t *memberifs = NULL; |
| 424 | member_interface_details_t *member_if = NULL; |
| 425 | |
| 426 | reg = vl_api_client_index_to_registration (mp->client_index); |
| 427 | if (!reg) |
| 428 | return; |
| 429 | |
| 430 | rv = bond_dump_member_ifs (&memberifs, ntohl (mp->sw_if_index)); |
| 431 | if (rv) |
| 432 | return; |
| 433 | |
| 434 | vec_foreach (member_if, memberifs) |
| 435 | { |
| 436 | bond_send_member_interface_details (am, reg, member_if, mp->context); |
| 437 | } |
| 438 | |
| 439 | vec_free (memberifs); |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 440 | } |
| 441 | |
Filip Tehlar | 116a1e5 | 2021-06-22 09:24:06 +0000 | [diff] [blame] | 442 | #include <vnet/bonding/bond.api.c> |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 443 | static clib_error_t * |
| 444 | bond_api_hookup (vlib_main_t * vm) |
| 445 | { |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 446 | /* |
| 447 | * Set up the (msg_name, crc, message-id) table |
| 448 | */ |
Filip Tehlar | 116a1e5 | 2021-06-22 09:24:06 +0000 | [diff] [blame] | 449 | REPLY_MSG_ID_BASE = setup_message_id_table (); |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 450 | |
| 451 | return 0; |
| 452 | } |
| 453 | |
| 454 | VLIB_API_INIT_FUNCTION (bond_api_hookup); |
| 455 | |
| 456 | /* |
| 457 | * fd.io coding-style-patch-verification: ON |
| 458 | * |
| 459 | * Local Variables: |
| 460 | * eval: (c-set-style "gnu") |
| 461 | * End: |
| 462 | */ |