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