FD.io VPP  v19.04.4-rc0-5-ge88582fac
Vector Packet Processing
bond_api.c
Go to the documentation of this file.
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>
26 
27 #include <vnet/vnet_msg_enum.h>
28 
29 #define vl_typedefs /* define message structures */
30 #include <vnet/vnet_all_api_h.h>
31 #undef vl_typedefs
32 
33 #define vl_endianfun /* define message structures */
34 #include <vnet/vnet_all_api_h.h>
35 #undef vl_endianfun
36 
37 /* instantiate all the print functions we know about */
38 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
39 #define vl_printfun
40 #include <vnet/vnet_all_api_h.h>
41 #undef vl_printfun
42 
44 #include <vnet/bonding/node.h>
45 
46 #define foreach_bond_api_msg \
47 _(BOND_CREATE, bond_create) \
48 _(BOND_DELETE, bond_delete) \
49 _(BOND_ENSLAVE, bond_enslave) \
50 _(BOND_DETACH_SLAVE, bond_detach_slave) \
51 _(SW_INTERFACE_BOND_DUMP, sw_interface_bond_dump)\
52 _(SW_INTERFACE_SLAVE_DUMP, sw_interface_slave_dump)
53 
54 static void
56 {
58  int rv;
59  vl_api_bond_delete_reply_t *rmp;
60  u32 sw_if_index = ntohl (mp->sw_if_index);
61 
62  rv = bond_delete_if (vm, sw_if_index);
63 
64  REPLY_MACRO (VL_API_BOND_DELETE_REPLY);
65 }
66 
67 static void
69 {
72  bond_create_if_args_t _a, *ap = &_a;
73 
74  clib_memset (ap, 0, sizeof (*ap));
75 
76  ap->id = ntohl (mp->id);
77 
78  if (mp->use_custom_mac)
79  {
80  clib_memcpy (ap->hw_addr, mp->mac_address, 6);
81  ap->hw_addr_set = 1;
82  }
83 
84  ap->mode = mp->mode;
85  ap->lb = mp->lb;
86  bond_create_if (vm, ap);
87 
88  int rv = ap->rv;
89 
90  /* *INDENT-OFF* */
91  REPLY_MACRO2(VL_API_BOND_CREATE_REPLY,
92  ({
93  rmp->sw_if_index = ntohl (ap->sw_if_index);
94  }));
95  /* *INDENT-ON* */
96 }
97 
98 static void
100 {
103  bond_enslave_args_t _a, *ap = &_a;
104  int rv = 0;
105 
106  clib_memset (ap, 0, sizeof (*ap));
107 
108  ap->group = ntohl (mp->bond_sw_if_index);
109  ap->slave = ntohl (mp->sw_if_index);
110  ap->is_passive = mp->is_passive;
112 
113  bond_enslave (vm, ap);
114 
115  REPLY_MACRO (VL_API_BOND_ENSLAVE_REPLY);
116 }
117 
118 static void
120 {
122  vl_api_bond_detach_slave_reply_t *rmp;
123  bond_detach_slave_args_t _a, *ap = &_a;
124  int rv = 0;
125 
126  clib_memset (ap, 0, sizeof (*ap));
127 
128  ap->slave = ntohl (mp->sw_if_index);
129  bond_detach_slave (vm, ap);
130 
131  REPLY_MACRO (VL_API_BOND_DETACH_SLAVE_REPLY);
132 }
133 
134 static void
136  vl_api_registration_t * reg,
137  bond_interface_details_t * bond_if,
138  u32 context)
139 {
141 
142  mp = vl_msg_api_alloc (sizeof (*mp));
143  clib_memset (mp, 0, sizeof (*mp));
144  mp->_vl_msg_id = htons (VL_API_SW_INTERFACE_BOND_DETAILS);
145  mp->sw_if_index = htonl (bond_if->sw_if_index);
146  mp->id = htonl (bond_if->id);
148  MIN (ARRAY_LEN (mp->interface_name) - 1,
149  strlen ((const char *) bond_if->interface_name)));
150  mp->mode = bond_if->mode;
151  mp->lb = bond_if->lb;
152  mp->active_slaves = htonl (bond_if->active_slaves);
153  mp->slaves = htonl (bond_if->slaves);
154 
155  mp->context = context;
156  vl_api_send_msg (reg, (u8 *) mp);
157 }
158 
159 static void
161 {
162  int rv;
165  bond_interface_details_t *bondifs = NULL;
166  bond_interface_details_t *bond_if = NULL;
167 
169  if (!reg)
170  return;
171 
172  rv = bond_dump_ifs (&bondifs);
173  if (rv)
174  return;
175 
176  vec_foreach (bond_if, bondifs)
177  {
178  bond_send_sw_interface_details (am, reg, bond_if, mp->context);
179  }
180 
181  vec_free (bondifs);
182 }
183 
184 static void
186  vl_api_registration_t * reg,
187  slave_interface_details_t * slave_if,
188  u32 context)
189 {
191 
192  mp = vl_msg_api_alloc (sizeof (*mp));
193  clib_memset (mp, 0, sizeof (*mp));
194  mp->_vl_msg_id = htons (VL_API_SW_INTERFACE_SLAVE_DETAILS);
195  mp->sw_if_index = htonl (slave_if->sw_if_index);
196  clib_memcpy (mp->interface_name, slave_if->interface_name,
197  MIN (ARRAY_LEN (mp->interface_name) - 1,
198  strlen ((const char *) slave_if->interface_name)));
199  mp->is_passive = slave_if->is_passive;
200  mp->is_long_timeout = slave_if->is_long_timeout;
201 
202  mp->context = context;
203  vl_api_send_msg (reg, (u8 *) mp);
204 }
205 
206 static void
208  mp)
209 {
210  int rv;
213  slave_interface_details_t *slaveifs = NULL;
214  slave_interface_details_t *slave_if = NULL;
215 
217  if (!reg)
218  return;
219 
220  rv = bond_dump_slave_ifs (&slaveifs, ntohl (mp->sw_if_index));
221  if (rv)
222  return;
223 
224  vec_foreach (slave_if, slaveifs)
225  {
226  bond_send_sw_interface_slave_details (am, reg, slave_if, mp->context);
227  }
228 
229  vec_free (slaveifs);
230 }
231 
232 #define vl_msg_name_crc_list
233 #include <vnet/vnet_all_api_h.h>
234 #undef vl_msg_name_crc_list
235 
236 static void
238 {
239 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
240  foreach_vl_msg_name_crc_bond;
241 #undef _
242 }
243 
244 static clib_error_t *
246 {
247  api_main_t *am = &api_main;
248 
249 #define _(N,n) \
250  vl_msg_api_set_handlers(VL_API_##N, #n, \
251  vl_api_##n##_t_handler, \
252  vl_noop_handler, \
253  vl_api_##n##_t_endian, \
254  vl_api_##n##_t_print, \
255  sizeof(vl_api_##n##_t), 1);
257 #undef _
258 
259  /*
260  * Set up the (msg_name, crc, message-id) table
261  */
263 
264  return 0;
265 }
266 
268 
269 /*
270  * fd.io coding-style-patch-verification: ON
271  *
272  * Local Variables:
273  * eval: (c-set-style "gnu")
274  * End:
275  */
u32 sw_if_index
Definition: ipsec_gre.api:37
static clib_error_t * bond_api_hookup(vlib_main_t *vm)
Definition: bond_api.c:245
int bond_delete_if(vlib_main_t *vm, u32 sw_if_index)
Definition: cli.c:199
static void vl_api_bond_detach_slave_t_handler(vl_api_bond_detach_slave_t *mp)
Definition: bond_api.c:119
#define foreach_bond_api_msg
Definition: bond_api.c:46
Reply for bond create reply.
Definition: bond.api:49
int bond_dump_ifs(bond_interface_details_t **out_bondifs)
Definition: cli.c:87
#define REPLY_MACRO2(t, body)
#define NULL
Definition: clib.h:58
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
u8 is_long_timeout
Definition: node.h:98
static void vl_api_send_msg(vl_api_registration_t *rp, u8 *elem)
Definition: api.h:34
static void vl_api_bond_create_t_handler(vl_api_bond_create_t *mp)
Definition: bond_api.c:68
static void vl_api_bond_delete_t_handler(vl_api_bond_delete_t *mp)
Definition: bond_api.c:55
void * vl_msg_api_alloc(int nbytes)
unsigned char u8
Definition: types.h:56
#define clib_memcpy(d, s, n)
Definition: string.h:180
static void vl_api_sw_interface_slave_dump_t_handler(vl_api_sw_interface_slave_dump_t *mp)
Definition: bond_api.c:207
static void vl_api_sw_interface_bond_dump_t_handler(vl_api_sw_interface_bond_dump_t *mp)
Definition: bond_api.c:160
void bond_enslave(vlib_main_t *vm, bond_enslave_args_t *args)
Definition: cli.c:441
Reply for bond enslave reply.
Definition: bond.api:90
unsigned int u32
Definition: types.h:88
#define MIN(x, y)
Definition: node.h:31
#define REPLY_MACRO(t)
VLIB_API_INIT_FUNCTION(bond_api_hookup)
static void bond_send_sw_interface_details(vpe_api_main_t *am, vl_api_registration_t *reg, bond_interface_details_t *bond_if, u32 context)
Definition: bond_api.c:135
Dump bond interfaces request.
Definition: bond.api:109
API main structure, used by both vpp and binary API clients.
Definition: api_common.h:202
void bond_detach_slave(vlib_main_t *vm, bond_detach_slave_args_t *args)
Definition: cli.c:630
Initialize a new bond interface with the given paramters.
Definition: bond.api:76
An API client registration, only in vpp/vlib.
Definition: api_common.h:45
vlib_main_t * vm
Definition: buffer.c:312
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:341
static void bond_send_sw_interface_slave_details(vpe_api_main_t *am, vl_api_registration_t *reg, slave_interface_details_t *slave_if, u32 context)
Definition: bond_api.c:185
Initialize a new bond interface with the given paramters.
Definition: bond.api:33
u32 context
Definition: ipsec_gre.api:33
#define ARRAY_LEN(x)
Definition: clib.h:62
static vl_api_registration_t * vl_api_client_index_to_registration(u32 index)
Definition: api.h:56
BOND interface details struct.
Definition: node.h:113
bond detach slave
Definition: bond.api:101
void bond_create_if(vlib_main_t *vm, bond_create_if_args_t *args)
Definition: cli.c:248
Reply for bond dump request.
Definition: bond.api:124
static void bond_setup_message_id_table(api_main_t *am)
Definition: bond_api.c:237
Delete bond interface.
Definition: bond.api:61
static void vl_api_bond_enslave_t_handler(vl_api_bond_enslave_t *mp)
Definition: bond_api.c:99
static vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:23
int bond_dump_slave_ifs(slave_interface_details_t **out_slaveifs, u32 bond_sw_if_index)
Definition: cli.c:119
slave interface details struct
Definition: node.h:125
Reply for slave dump request.
Definition: bond.api:154
#define vec_foreach(var, vec)
Vector iterator.
vpe_api_main_t vpe_api_main
Definition: interface_api.c:49
api_main_t api_main
Definition: api_shared.c:35