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