blob: ce5aefab2fd87729c3416dbce5540095dd01d359 [file] [log] [blame]
Steven9cd2d7a2017-12-20 12:43:01 -08001/*
2 *------------------------------------------------------------------
3 * Copyright (c) 2017 Cisco and/or its affiliates.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *------------------------------------------------------------------
16 */
17
18#define _GNU_SOURCE
19#include <stdint.h>
20#include <vnet/llc/llc.h>
21#include <vnet/snap/snap.h>
22#include <vnet/bonding/node.h>
23
Benoît Ganne47727c02019-02-12 13:35:08 +010024#ifndef CLIB_MARCH_VARIANT
Steven9cd2d7a2017-12-20 12:43:01 -080025bond_main_t bond_main;
Benoît Ganne47727c02019-02-12 13:35:08 +010026#endif /* CLIB_MARCH_VARIANT */
Steven9cd2d7a2017-12-20 12:43:01 -080027
28#define foreach_bond_input_error \
29 _(NONE, "no error") \
30 _(IF_DOWN, "interface down") \
Damjan Marion5e5adb32018-05-26 00:50:39 +020031 _(PASS_THRU, "pass through (CDP, LLDP, slow protocols)")
Steven9cd2d7a2017-12-20 12:43:01 -080032
33typedef enum
34{
35#define _(f,s) BOND_INPUT_ERROR_##f,
36 foreach_bond_input_error
37#undef _
38 BOND_INPUT_N_ERROR,
39} bond_input_error_t;
40
41static char *bond_input_error_strings[] = {
42#define _(n,s) s,
43 foreach_bond_input_error
44#undef _
45};
46
47static u8 *
48format_bond_input_trace (u8 * s, va_list * args)
49{
50 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
51 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
52 bond_packet_trace_t *t = va_arg (*args, bond_packet_trace_t *);
Steven9cd2d7a2017-12-20 12:43:01 -080053
Steven70488ab2018-03-28 17:59:00 -070054 s = format (s, "src %U, dst %U, %U -> %U",
Steven9cd2d7a2017-12-20 12:43:01 -080055 format_ethernet_address, t->ethernet.src_address,
56 format_ethernet_address, t->ethernet.dst_address,
Steven70488ab2018-03-28 17:59:00 -070057 format_vnet_sw_if_index_name, vnet_get_main (),
58 t->sw_if_index,
59 format_vnet_sw_if_index_name, vnet_get_main (),
60 t->bond_sw_if_index);
Steven9cd2d7a2017-12-20 12:43:01 -080061
62 return s;
63}
Damjan Marion5e5adb32018-05-26 00:50:39 +020064
65typedef enum
66{
67 BOND_INPUT_NEXT_DROP,
68 BOND_INPUT_N_NEXT,
Steven9f781d82018-06-05 11:09:32 -070069} bond_output_next_t;
Steven9cd2d7a2017-12-20 12:43:01 -080070
71static_always_inline u8
72packet_is_cdp (ethernet_header_t * eth)
73{
74 llc_header_t *llc;
75 snap_header_t *snap;
76
77 llc = (llc_header_t *) (eth + 1);
78 snap = (snap_header_t *) (llc + 1);
79
80 return ((eth->type == htons (ETHERNET_TYPE_CDP)) ||
81 ((llc->src_sap == 0xAA) && (llc->control == 0x03) &&
82 (snap->protocol == htons (0x2000)) &&
83 (snap->oui[0] == 0) && (snap->oui[1] == 0) &&
84 (snap->oui[2] == 0x0C)));
85}
86
Steven Luongc94afaa2019-07-24 21:16:09 -070087static inline void
Damjan Marion5e5adb32018-05-26 00:50:39 +020088bond_sw_if_idx_rewrite (vlib_main_t * vm, vlib_node_runtime_t * node,
Steven Luongc94afaa2019-07-24 21:16:09 -070089 vlib_buffer_t * b, u32 bond_sw_if_index,
90 u32 * n_rx_packets, u32 * n_rx_bytes)
Steven9cd2d7a2017-12-20 12:43:01 -080091{
Steven9cd2d7a2017-12-20 12:43:01 -080092 u16 *ethertype_p, ethertype;
93 ethernet_vlan_header_t *vlan;
Damjan Marion5e5adb32018-05-26 00:50:39 +020094 ethernet_header_t *eth = (ethernet_header_t *) vlib_buffer_get_current (b);
Steven9cd2d7a2017-12-20 12:43:01 -080095
Steven Luongc94afaa2019-07-24 21:16:09 -070096 (*n_rx_packets)++;
97 *n_rx_bytes += b->current_length;
Damjan Marion5e5adb32018-05-26 00:50:39 +020098 ethertype = clib_mem_unaligned (&eth->type, u16);
99 if (!ethernet_frame_is_tagged (ntohs (ethertype)))
Steven9cd2d7a2017-12-20 12:43:01 -0800100 {
Damjan Marion5e5adb32018-05-26 00:50:39 +0200101 // Let some layer2 packets pass through.
102 if (PREDICT_TRUE ((ethertype != htons (ETHERNET_TYPE_SLOW_PROTOCOLS))
103 && !packet_is_cdp (eth)
104 && (ethertype != htons (ETHERNET_TYPE_802_1_LLDP))))
Steven9cd2d7a2017-12-20 12:43:01 -0800105 {
Damjan Marion5e5adb32018-05-26 00:50:39 +0200106 /* Change the physical interface to bond interface */
107 vnet_buffer (b)->sw_if_index[VLIB_RX] = bond_sw_if_index;
Steven Luongc94afaa2019-07-24 21:16:09 -0700108 return;
Steven9cd2d7a2017-12-20 12:43:01 -0800109 }
110 }
111 else
112 {
Damjan Marion5e5adb32018-05-26 00:50:39 +0200113 vlan = (void *) (eth + 1);
114 ethertype_p = &vlan->type;
115 ethertype = clib_mem_unaligned (ethertype_p, u16);
116 if (ethertype == ntohs (ETHERNET_TYPE_VLAN))
117 {
118 vlan++;
119 ethertype_p = &vlan->type;
120 }
121 ethertype = clib_mem_unaligned (ethertype_p, u16);
122 if (PREDICT_TRUE ((ethertype != htons (ETHERNET_TYPE_SLOW_PROTOCOLS))
123 && (ethertype != htons (ETHERNET_TYPE_CDP))
124 && (ethertype != htons (ETHERNET_TYPE_802_1_LLDP))))
125 {
126 /* Change the physical interface to bond interface */
127 vnet_buffer (b)->sw_if_index[VLIB_RX] = bond_sw_if_index;
Steven Luongc94afaa2019-07-24 21:16:09 -0700128 return;
Damjan Marion5e5adb32018-05-26 00:50:39 +0200129 }
Steven9cd2d7a2017-12-20 12:43:01 -0800130 }
131
Damjan Marion5e5adb32018-05-26 00:50:39 +0200132 vlib_error_count (vm, node->node_index, BOND_INPUT_ERROR_PASS_THRU, 1);
Steven Luongc94afaa2019-07-24 21:16:09 -0700133 return;
Steven9cd2d7a2017-12-20 12:43:01 -0800134}
135
Damjan Marion5e5adb32018-05-26 00:50:39 +0200136static inline void
137bond_update_next (vlib_main_t * vm, vlib_node_runtime_t * node,
138 u32 * last_slave_sw_if_index, u32 slave_sw_if_index,
Damjan Marion5e5adb32018-05-26 00:50:39 +0200139 u32 * bond_sw_if_index, vlib_buffer_t * b,
140 u32 * next_index, vlib_error_t * error)
Steven9cd2d7a2017-12-20 12:43:01 -0800141{
Damjan Marion5e5adb32018-05-26 00:50:39 +0200142 slave_if_t *sif;
143 bond_if_t *bif;
144
145 if (PREDICT_TRUE (*last_slave_sw_if_index == slave_sw_if_index))
146 return;
147
Damjan Marion5e5adb32018-05-26 00:50:39 +0200148 *last_slave_sw_if_index = slave_sw_if_index;
149 *next_index = BOND_INPUT_NEXT_DROP;
150
151 sif = bond_get_slave_by_sw_if_index (slave_sw_if_index);
152 ASSERT (sif);
153
154 bif = bond_get_master_by_dev_instance (sif->bif_dev_instance);
155
156 ASSERT (bif);
157 ASSERT (vec_len (bif->slaves));
158
159 if (PREDICT_TRUE (bif->admin_up == 0))
160 {
161 *bond_sw_if_index = slave_sw_if_index;
162 *error = node->errors[BOND_INPUT_ERROR_IF_DOWN];
163 }
164
165 *bond_sw_if_index = bif->sw_if_index;
166 *error = 0;
Damjan Marion7d98a122018-07-19 20:42:08 +0200167 vnet_feature_next (next_index, b);
Damjan Marion5e5adb32018-05-26 00:50:39 +0200168}
169
Damjan Marion812b32d2018-05-28 21:26:47 +0200170VLIB_NODE_FN (bond_input_node) (vlib_main_t * vm,
171 vlib_node_runtime_t * node,
172 vlib_frame_t * frame)
Damjan Marion5e5adb32018-05-26 00:50:39 +0200173{
Damjan Marion067cd622018-07-11 12:47:43 +0200174 u16 thread_index = vm->thread_index;
Damjan Marion5e5adb32018-05-26 00:50:39 +0200175 u32 *from, n_left;
176 vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b;
177 u32 sw_if_indices[VLIB_FRAME_SIZE], *sw_if_index;
178 u16 nexts[VLIB_FRAME_SIZE], *next;
179 u32 last_slave_sw_if_index = ~0;
180 u32 bond_sw_if_index = 0;
181 vlib_error_t error = 0;
182 u32 next_index = 0;
Steven Luongc94afaa2019-07-24 21:16:09 -0700183 u32 n_rx_bytes = 0, n_rx_packets = 0;
Steven9cd2d7a2017-12-20 12:43:01 -0800184
185 /* Vector of buffer / pkt indices we're supposed to process */
186 from = vlib_frame_vector_args (frame);
187
188 /* Number of buffers / pkts */
Damjan Marion5e5adb32018-05-26 00:50:39 +0200189 n_left = frame->n_vectors;
Steven9cd2d7a2017-12-20 12:43:01 -0800190
Damjan Marion5e5adb32018-05-26 00:50:39 +0200191 vlib_get_buffers (vm, from, bufs, n_left);
Steven9cd2d7a2017-12-20 12:43:01 -0800192
Damjan Marion5e5adb32018-05-26 00:50:39 +0200193 b = bufs;
194 next = nexts;
195 sw_if_index = sw_if_indices;
196
197 while (n_left >= 4)
Steven9cd2d7a2017-12-20 12:43:01 -0800198 {
Damjan Marion5e5adb32018-05-26 00:50:39 +0200199 u32 x = 0;
200 /* Prefetch next iteration */
201 if (PREDICT_TRUE (n_left >= 16))
Steven9cd2d7a2017-12-20 12:43:01 -0800202 {
Damjan Mariond30bf012018-11-18 23:48:43 +0100203 vlib_prefetch_buffer_data (b[8], LOAD);
204 vlib_prefetch_buffer_data (b[9], LOAD);
205 vlib_prefetch_buffer_data (b[10], LOAD);
206 vlib_prefetch_buffer_data (b[11], LOAD);
Steven9cd2d7a2017-12-20 12:43:01 -0800207
Damjan Marion5e5adb32018-05-26 00:50:39 +0200208 vlib_prefetch_buffer_header (b[12], LOAD);
209 vlib_prefetch_buffer_header (b[13], LOAD);
210 vlib_prefetch_buffer_header (b[14], LOAD);
211 vlib_prefetch_buffer_header (b[15], LOAD);
Steven9cd2d7a2017-12-20 12:43:01 -0800212 }
213
Damjan Marion5e5adb32018-05-26 00:50:39 +0200214 sw_if_index[0] = vnet_buffer (b[0])->sw_if_index[VLIB_RX];
215 sw_if_index[1] = vnet_buffer (b[1])->sw_if_index[VLIB_RX];
216 sw_if_index[2] = vnet_buffer (b[2])->sw_if_index[VLIB_RX];
217 sw_if_index[3] = vnet_buffer (b[3])->sw_if_index[VLIB_RX];
218
219 x |= sw_if_index[0] ^ last_slave_sw_if_index;
220 x |= sw_if_index[1] ^ last_slave_sw_if_index;
221 x |= sw_if_index[2] ^ last_slave_sw_if_index;
222 x |= sw_if_index[3] ^ last_slave_sw_if_index;
223
224 if (PREDICT_TRUE (x == 0))
Steven9cd2d7a2017-12-20 12:43:01 -0800225 {
Damjan Marion5e5adb32018-05-26 00:50:39 +0200226 next[0] = next[1] = next[2] = next[3] = next_index;
227 if (next_index == BOND_INPUT_NEXT_DROP)
Steven9cd2d7a2017-12-20 12:43:01 -0800228 {
Damjan Marion5e5adb32018-05-26 00:50:39 +0200229 b[0]->error = error;
230 b[1]->error = error;
231 b[2]->error = error;
232 b[3]->error = error;
Steven9cd2d7a2017-12-20 12:43:01 -0800233 }
Damjan Marion5e5adb32018-05-26 00:50:39 +0200234 else
Steven70488ab2018-03-28 17:59:00 -0700235 {
Steven Luongc94afaa2019-07-24 21:16:09 -0700236 bond_sw_if_idx_rewrite (vm, node, b[0], bond_sw_if_index,
237 &n_rx_packets, &n_rx_bytes);
238 bond_sw_if_idx_rewrite (vm, node, b[1], bond_sw_if_index,
239 &n_rx_packets, &n_rx_bytes);
240 bond_sw_if_idx_rewrite (vm, node, b[2], bond_sw_if_index,
241 &n_rx_packets, &n_rx_bytes);
242 bond_sw_if_idx_rewrite (vm, node, b[3], bond_sw_if_index,
243 &n_rx_packets, &n_rx_bytes);
Steven70488ab2018-03-28 17:59:00 -0700244 }
Steven9cd2d7a2017-12-20 12:43:01 -0800245 }
Damjan Marion5e5adb32018-05-26 00:50:39 +0200246 else
247 {
Damjan Marion5e5adb32018-05-26 00:50:39 +0200248 bond_update_next (vm, node, &last_slave_sw_if_index, sw_if_index[0],
Steven Luongc94afaa2019-07-24 21:16:09 -0700249 &bond_sw_if_index, b[0], &next_index, &error);
Damjan Marion5e5adb32018-05-26 00:50:39 +0200250 next[0] = next_index;
251 if (next_index == BOND_INPUT_NEXT_DROP)
252 b[0]->error = error;
253 else
Steven Luongc94afaa2019-07-24 21:16:09 -0700254 bond_sw_if_idx_rewrite (vm, node, b[0], bond_sw_if_index,
255 &n_rx_packets, &n_rx_bytes);
Damjan Marion5e5adb32018-05-26 00:50:39 +0200256
257 bond_update_next (vm, node, &last_slave_sw_if_index, sw_if_index[1],
Steven Luongc94afaa2019-07-24 21:16:09 -0700258 &bond_sw_if_index, b[1], &next_index, &error);
Damjan Marion5e5adb32018-05-26 00:50:39 +0200259 next[1] = next_index;
260 if (next_index == BOND_INPUT_NEXT_DROP)
261 b[1]->error = error;
262 else
Steven Luongc94afaa2019-07-24 21:16:09 -0700263 bond_sw_if_idx_rewrite (vm, node, b[1], bond_sw_if_index,
264 &n_rx_packets, &n_rx_bytes);
Damjan Marion5e5adb32018-05-26 00:50:39 +0200265
266 bond_update_next (vm, node, &last_slave_sw_if_index, sw_if_index[2],
Steven Luongc94afaa2019-07-24 21:16:09 -0700267 &bond_sw_if_index, b[2], &next_index, &error);
Damjan Marion5e5adb32018-05-26 00:50:39 +0200268 next[2] = next_index;
269 if (next_index == BOND_INPUT_NEXT_DROP)
270 b[2]->error = error;
271 else
Steven Luongc94afaa2019-07-24 21:16:09 -0700272 bond_sw_if_idx_rewrite (vm, node, b[2], bond_sw_if_index,
273 &n_rx_packets, &n_rx_bytes);
Damjan Marion5e5adb32018-05-26 00:50:39 +0200274
275 bond_update_next (vm, node, &last_slave_sw_if_index, sw_if_index[3],
Steven Luongc94afaa2019-07-24 21:16:09 -0700276 &bond_sw_if_index, b[3], &next_index, &error);
Damjan Marion5e5adb32018-05-26 00:50:39 +0200277 next[3] = next_index;
278 if (next_index == BOND_INPUT_NEXT_DROP)
279 b[3]->error = error;
280 else
Steven Luongc94afaa2019-07-24 21:16:09 -0700281 bond_sw_if_idx_rewrite (vm, node, b[3], bond_sw_if_index,
282 &n_rx_packets, &n_rx_bytes);
Damjan Marion5e5adb32018-05-26 00:50:39 +0200283 }
284
285 VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b[0]);
286 VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b[1]);
287 VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b[2]);
288 VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b[3]);
289
290 /* next */
291 n_left -= 4;
292 b += 4;
293 sw_if_index += 4;
294 next += 4;
Steven9cd2d7a2017-12-20 12:43:01 -0800295 }
296
Damjan Marion5e5adb32018-05-26 00:50:39 +0200297 while (n_left)
298 {
299 sw_if_index[0] = vnet_buffer (b[0])->sw_if_index[VLIB_RX];
300 bond_update_next (vm, node, &last_slave_sw_if_index, sw_if_index[0],
Steven Luongc94afaa2019-07-24 21:16:09 -0700301 &bond_sw_if_index, b[0], &next_index, &error);
Damjan Marion5e5adb32018-05-26 00:50:39 +0200302 next[0] = next_index;
303 if (next_index == BOND_INPUT_NEXT_DROP)
304 b[0]->error = error;
305 else
Steven Luongc94afaa2019-07-24 21:16:09 -0700306 bond_sw_if_idx_rewrite (vm, node, b[0], bond_sw_if_index,
307 &n_rx_packets, &n_rx_bytes);
Damjan Marion5e5adb32018-05-26 00:50:39 +0200308
309 VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b[0]);
310
311 /* next */
312 n_left -= 1;
313 b += 1;
314 sw_if_index += 1;
315 next += 1;
316 }
317
318 if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)))
319 {
320 n_left = frame->n_vectors; /* number of packets to process */
321 b = bufs;
322 sw_if_index = sw_if_indices;
Damjan Marion5e5adb32018-05-26 00:50:39 +0200323 bond_packet_trace_t *t0;
Damjan Marion5e5adb32018-05-26 00:50:39 +0200324
Damjan Marionf264f082018-05-30 00:03:34 +0200325 while (n_left)
Damjan Marion5e5adb32018-05-26 00:50:39 +0200326 {
327 if (PREDICT_FALSE (b[0]->flags & VLIB_BUFFER_IS_TRACED))
328 {
Damjan Marion5e5adb32018-05-26 00:50:39 +0200329 t0 = vlib_add_trace (vm, node, b[0], sizeof (*t0));
330 t0->sw_if_index = sw_if_index[0];
Dave Barach178cf492018-11-13 16:34:13 -0500331 clib_memcpy_fast (&t0->ethernet, vlib_buffer_get_current (b[0]),
332 sizeof (ethernet_header_t));
Damjan Marion5e5adb32018-05-26 00:50:39 +0200333 t0->bond_sw_if_index = vnet_buffer (b[0])->sw_if_index[VLIB_RX];
334 }
335 /* next */
336 n_left--;
337 b++;
338 sw_if_index++;
Damjan Marion5e5adb32018-05-26 00:50:39 +0200339 }
340 }
341
342 /* increase rx counters */
Steven Luongc94afaa2019-07-24 21:16:09 -0700343 vlib_increment_combined_counter
344 (vnet_main.interface_main.combined_sw_if_counters +
345 VNET_INTERFACE_COUNTER_RX, thread_index, bond_sw_if_index, n_rx_packets,
346 n_rx_bytes);
Damjan Marion5e5adb32018-05-26 00:50:39 +0200347
348 vlib_buffer_enqueue_to_next (vm, node, from, nexts, frame->n_vectors);
Steven9cd2d7a2017-12-20 12:43:01 -0800349 vlib_node_increment_counter (vm, bond_input_node.index,
350 BOND_INPUT_ERROR_NONE, frame->n_vectors);
351
Steven9cd2d7a2017-12-20 12:43:01 -0800352 return frame->n_vectors;
353}
354
355static clib_error_t *
356bond_input_init (vlib_main_t * vm)
357{
358 return 0;
359}
360
361/* *INDENT-OFF* */
362VLIB_REGISTER_NODE (bond_input_node) = {
Steven9cd2d7a2017-12-20 12:43:01 -0800363 .name = "bond-input",
364 .vector_size = sizeof (u32),
365 .format_buffer = format_ethernet_header_with_length,
366 .format_trace = format_bond_input_trace,
367 .type = VLIB_NODE_TYPE_INTERNAL,
368 .n_errors = BOND_INPUT_N_ERROR,
369 .error_strings = bond_input_error_strings,
Damjan Marion5e5adb32018-05-26 00:50:39 +0200370 .n_next_nodes = BOND_INPUT_N_NEXT,
Steven9cd2d7a2017-12-20 12:43:01 -0800371 .next_nodes =
372 {
Damjan Marion5e5adb32018-05-26 00:50:39 +0200373 [BOND_INPUT_NEXT_DROP] = "error-drop"
Steven9cd2d7a2017-12-20 12:43:01 -0800374 }
375};
376
377VLIB_INIT_FUNCTION (bond_input_init);
378
379VNET_FEATURE_INIT (bond_input, static) =
380{
381 .arc_name = "device-input",
382 .node_name = "bond-input",
383 .runs_before = VNET_FEATURES ("ethernet-input"),
384};
Steven9cd2d7a2017-12-20 12:43:01 -0800385/* *INDENT-ON* */
386
387static clib_error_t *
388bond_sw_interface_up_down (vnet_main_t * vnm, u32 sw_if_index, u32 flags)
389{
390 bond_main_t *bm = &bond_main;
391 slave_if_t *sif;
392 vlib_main_t *vm = bm->vlib_main;
393
394 sif = bond_get_slave_by_sw_if_index (sw_if_index);
395 if (sif)
396 {
Stevene43278f2019-01-17 15:11:29 -0800397 if (sif->lacp_enabled)
398 return 0;
399
Steven Luongbac326c2019-08-05 09:47:58 -0700400 /* port_enabled is both admin up and hw link up */
401 sif->port_enabled = ((flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) &&
402 vnet_sw_interface_is_link_up (vnm, sw_if_index));
Steven9cd2d7a2017-12-20 12:43:01 -0800403 if (sif->port_enabled == 0)
Steven Luongbac326c2019-08-05 09:47:58 -0700404 bond_disable_collecting_distributing (vm, sif);
Steven9cd2d7a2017-12-20 12:43:01 -0800405 else
Steven Luongbac326c2019-08-05 09:47:58 -0700406 bond_enable_collecting_distributing (vm, sif);
Steven9cd2d7a2017-12-20 12:43:01 -0800407 }
408
409 return 0;
410}
411
412VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (bond_sw_interface_up_down);
413
414static clib_error_t *
415bond_hw_interface_up_down (vnet_main_t * vnm, u32 hw_if_index, u32 flags)
416{
417 bond_main_t *bm = &bond_main;
418 slave_if_t *sif;
419 vnet_sw_interface_t *sw;
420 vlib_main_t *vm = bm->vlib_main;
Steven9cd2d7a2017-12-20 12:43:01 -0800421
Stevence2db6a2018-04-23 17:06:24 -0700422 sw = vnet_get_hw_sw_interface (vnm, hw_if_index);
Steven9cd2d7a2017-12-20 12:43:01 -0800423 sif = bond_get_slave_by_sw_if_index (sw->sw_if_index);
424 if (sif)
425 {
Stevene43278f2019-01-17 15:11:29 -0800426 if (sif->lacp_enabled)
427 return 0;
428
Steven Luongbac326c2019-08-05 09:47:58 -0700429 /* port_enabled is both admin up and hw link up */
430 sif->port_enabled = ((flags & VNET_HW_INTERFACE_FLAG_LINK_UP) &&
431 vnet_sw_interface_is_admin_up (vnm,
432 sw->sw_if_index));
433 if (sif->port_enabled == 0)
434 bond_disable_collecting_distributing (vm, sif);
435 else
436 bond_enable_collecting_distributing (vm, sif);
Steven9cd2d7a2017-12-20 12:43:01 -0800437 }
438
439 return 0;
440}
441
442VNET_HW_INTERFACE_LINK_UP_DOWN_FUNCTION (bond_hw_interface_up_down);
Steven9cd2d7a2017-12-20 12:43:01 -0800443
444/*
445 * fd.io coding-style-patch-verification: ON
446 *
447 * Local Variables:
448 * eval: (c-set-style "gnu")
449 * End:
450 */