Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 1 | /* |
| 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 Ganne | 47727c0 | 2019-02-12 13:35:08 +0100 | [diff] [blame] | 24 | #ifndef CLIB_MARCH_VARIANT |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 25 | bond_main_t bond_main; |
Benoît Ganne | 47727c0 | 2019-02-12 13:35:08 +0100 | [diff] [blame] | 26 | #endif /* CLIB_MARCH_VARIANT */ |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 27 | |
| 28 | #define foreach_bond_input_error \ |
| 29 | _(NONE, "no error") \ |
| 30 | _(IF_DOWN, "interface down") \ |
Steven Luong | 6dfd378 | 2019-12-06 21:12:41 -0800 | [diff] [blame] | 31 | _(PASSIVE_IF, "traffic received on passive interface") \ |
Damjan Marion | 5e5adb3 | 2018-05-26 00:50:39 +0200 | [diff] [blame] | 32 | _(PASS_THRU, "pass through (CDP, LLDP, slow protocols)") |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 33 | |
| 34 | typedef enum |
| 35 | { |
| 36 | #define _(f,s) BOND_INPUT_ERROR_##f, |
| 37 | foreach_bond_input_error |
| 38 | #undef _ |
| 39 | BOND_INPUT_N_ERROR, |
| 40 | } bond_input_error_t; |
| 41 | |
| 42 | static char *bond_input_error_strings[] = { |
| 43 | #define _(n,s) s, |
| 44 | foreach_bond_input_error |
| 45 | #undef _ |
| 46 | }; |
| 47 | |
| 48 | static u8 * |
| 49 | format_bond_input_trace (u8 * s, va_list * args) |
| 50 | { |
| 51 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 52 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); |
| 53 | bond_packet_trace_t *t = va_arg (*args, bond_packet_trace_t *); |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 54 | |
Steven | 70488ab | 2018-03-28 17:59:00 -0700 | [diff] [blame] | 55 | s = format (s, "src %U, dst %U, %U -> %U", |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 56 | format_ethernet_address, t->ethernet.src_address, |
| 57 | format_ethernet_address, t->ethernet.dst_address, |
Steven | 70488ab | 2018-03-28 17:59:00 -0700 | [diff] [blame] | 58 | format_vnet_sw_if_index_name, vnet_get_main (), |
| 59 | t->sw_if_index, |
| 60 | format_vnet_sw_if_index_name, vnet_get_main (), |
| 61 | t->bond_sw_if_index); |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 62 | |
| 63 | return s; |
| 64 | } |
Damjan Marion | 5e5adb3 | 2018-05-26 00:50:39 +0200 | [diff] [blame] | 65 | |
| 66 | typedef enum |
| 67 | { |
| 68 | BOND_INPUT_NEXT_DROP, |
| 69 | BOND_INPUT_N_NEXT, |
Steven | 9f781d8 | 2018-06-05 11:09:32 -0700 | [diff] [blame] | 70 | } bond_output_next_t; |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 71 | |
| 72 | static_always_inline u8 |
| 73 | packet_is_cdp (ethernet_header_t * eth) |
| 74 | { |
| 75 | llc_header_t *llc; |
| 76 | snap_header_t *snap; |
| 77 | |
| 78 | llc = (llc_header_t *) (eth + 1); |
| 79 | snap = (snap_header_t *) (llc + 1); |
| 80 | |
| 81 | return ((eth->type == htons (ETHERNET_TYPE_CDP)) || |
| 82 | ((llc->src_sap == 0xAA) && (llc->control == 0x03) && |
| 83 | (snap->protocol == htons (0x2000)) && |
| 84 | (snap->oui[0] == 0) && (snap->oui[1] == 0) && |
| 85 | (snap->oui[2] == 0x0C))); |
| 86 | } |
| 87 | |
Steven Luong | c94afaa | 2019-07-24 21:16:09 -0700 | [diff] [blame] | 88 | static inline void |
Damjan Marion | 5e5adb3 | 2018-05-26 00:50:39 +0200 | [diff] [blame] | 89 | bond_sw_if_idx_rewrite (vlib_main_t * vm, vlib_node_runtime_t * node, |
Steven Luong | c94afaa | 2019-07-24 21:16:09 -0700 | [diff] [blame] | 90 | vlib_buffer_t * b, u32 bond_sw_if_index, |
| 91 | u32 * n_rx_packets, u32 * n_rx_bytes) |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 92 | { |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 93 | u16 *ethertype_p, ethertype; |
| 94 | ethernet_vlan_header_t *vlan; |
Damjan Marion | 5e5adb3 | 2018-05-26 00:50:39 +0200 | [diff] [blame] | 95 | ethernet_header_t *eth = (ethernet_header_t *) vlib_buffer_get_current (b); |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 96 | |
Steven Luong | c94afaa | 2019-07-24 21:16:09 -0700 | [diff] [blame] | 97 | (*n_rx_packets)++; |
| 98 | *n_rx_bytes += b->current_length; |
Damjan Marion | 5e5adb3 | 2018-05-26 00:50:39 +0200 | [diff] [blame] | 99 | ethertype = clib_mem_unaligned (ð->type, u16); |
| 100 | if (!ethernet_frame_is_tagged (ntohs (ethertype))) |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 101 | { |
Damjan Marion | 5e5adb3 | 2018-05-26 00:50:39 +0200 | [diff] [blame] | 102 | // Let some layer2 packets pass through. |
| 103 | if (PREDICT_TRUE ((ethertype != htons (ETHERNET_TYPE_SLOW_PROTOCOLS)) |
| 104 | && !packet_is_cdp (eth) |
| 105 | && (ethertype != htons (ETHERNET_TYPE_802_1_LLDP)))) |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 106 | { |
Damjan Marion | 5e5adb3 | 2018-05-26 00:50:39 +0200 | [diff] [blame] | 107 | /* Change the physical interface to bond interface */ |
| 108 | vnet_buffer (b)->sw_if_index[VLIB_RX] = bond_sw_if_index; |
Steven Luong | c94afaa | 2019-07-24 21:16:09 -0700 | [diff] [blame] | 109 | return; |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 110 | } |
| 111 | } |
| 112 | else |
| 113 | { |
Damjan Marion | 5e5adb3 | 2018-05-26 00:50:39 +0200 | [diff] [blame] | 114 | vlan = (void *) (eth + 1); |
| 115 | ethertype_p = &vlan->type; |
| 116 | ethertype = clib_mem_unaligned (ethertype_p, u16); |
| 117 | if (ethertype == ntohs (ETHERNET_TYPE_VLAN)) |
| 118 | { |
| 119 | vlan++; |
| 120 | ethertype_p = &vlan->type; |
| 121 | } |
| 122 | ethertype = clib_mem_unaligned (ethertype_p, u16); |
| 123 | if (PREDICT_TRUE ((ethertype != htons (ETHERNET_TYPE_SLOW_PROTOCOLS)) |
| 124 | && (ethertype != htons (ETHERNET_TYPE_CDP)) |
| 125 | && (ethertype != htons (ETHERNET_TYPE_802_1_LLDP)))) |
| 126 | { |
| 127 | /* Change the physical interface to bond interface */ |
| 128 | vnet_buffer (b)->sw_if_index[VLIB_RX] = bond_sw_if_index; |
Steven Luong | c94afaa | 2019-07-24 21:16:09 -0700 | [diff] [blame] | 129 | return; |
Damjan Marion | 5e5adb3 | 2018-05-26 00:50:39 +0200 | [diff] [blame] | 130 | } |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 131 | } |
| 132 | |
Damjan Marion | 5e5adb3 | 2018-05-26 00:50:39 +0200 | [diff] [blame] | 133 | vlib_error_count (vm, node->node_index, BOND_INPUT_ERROR_PASS_THRU, 1); |
Steven Luong | c94afaa | 2019-07-24 21:16:09 -0700 | [diff] [blame] | 134 | return; |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 135 | } |
| 136 | |
Damjan Marion | 5e5adb3 | 2018-05-26 00:50:39 +0200 | [diff] [blame] | 137 | static inline void |
| 138 | bond_update_next (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 139 | u32 * last_slave_sw_if_index, u32 slave_sw_if_index, |
Damjan Marion | 5e5adb3 | 2018-05-26 00:50:39 +0200 | [diff] [blame] | 140 | u32 * bond_sw_if_index, vlib_buffer_t * b, |
| 141 | u32 * next_index, vlib_error_t * error) |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 142 | { |
Damjan Marion | 5e5adb3 | 2018-05-26 00:50:39 +0200 | [diff] [blame] | 143 | slave_if_t *sif; |
| 144 | bond_if_t *bif; |
| 145 | |
Steven Luong | 71e5b47 | 2019-10-10 11:36:41 -0700 | [diff] [blame] | 146 | *next_index = BOND_INPUT_NEXT_DROP; |
| 147 | *error = 0; |
| 148 | |
Damjan Marion | 5e5adb3 | 2018-05-26 00:50:39 +0200 | [diff] [blame] | 149 | if (PREDICT_TRUE (*last_slave_sw_if_index == slave_sw_if_index)) |
Steven Luong | 71e5b47 | 2019-10-10 11:36:41 -0700 | [diff] [blame] | 150 | goto next; |
Damjan Marion | 5e5adb3 | 2018-05-26 00:50:39 +0200 | [diff] [blame] | 151 | |
Damjan Marion | 5e5adb3 | 2018-05-26 00:50:39 +0200 | [diff] [blame] | 152 | *last_slave_sw_if_index = slave_sw_if_index; |
Damjan Marion | 5e5adb3 | 2018-05-26 00:50:39 +0200 | [diff] [blame] | 153 | |
| 154 | sif = bond_get_slave_by_sw_if_index (slave_sw_if_index); |
Dave Barach | ffd1546 | 2020-02-18 10:12:23 -0500 | [diff] [blame] | 155 | ALWAYS_ASSERT (sif); |
Damjan Marion | 5e5adb3 | 2018-05-26 00:50:39 +0200 | [diff] [blame] | 156 | |
| 157 | bif = bond_get_master_by_dev_instance (sif->bif_dev_instance); |
| 158 | |
Dave Barach | ffd1546 | 2020-02-18 10:12:23 -0500 | [diff] [blame] | 159 | ALWAYS_ASSERT (bif); |
Damjan Marion | 5e5adb3 | 2018-05-26 00:50:39 +0200 | [diff] [blame] | 160 | ASSERT (vec_len (bif->slaves)); |
| 161 | |
Steven Luong | 6dfd378 | 2019-12-06 21:12:41 -0800 | [diff] [blame] | 162 | if (PREDICT_FALSE (bif->admin_up == 0)) |
Damjan Marion | 5e5adb3 | 2018-05-26 00:50:39 +0200 | [diff] [blame] | 163 | { |
| 164 | *bond_sw_if_index = slave_sw_if_index; |
| 165 | *error = node->errors[BOND_INPUT_ERROR_IF_DOWN]; |
Steven Luong | 6dfd378 | 2019-12-06 21:12:41 -0800 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | if (PREDICT_FALSE ((bif->mode == BOND_MODE_ACTIVE_BACKUP) && |
| 169 | vec_len (bif->active_slaves) && |
| 170 | (slave_sw_if_index != bif->active_slaves[0]))) |
| 171 | { |
| 172 | *bond_sw_if_index = slave_sw_if_index; |
| 173 | *error = node->errors[BOND_INPUT_ERROR_PASSIVE_IF]; |
| 174 | return; |
Damjan Marion | 5e5adb3 | 2018-05-26 00:50:39 +0200 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | *bond_sw_if_index = bif->sw_if_index; |
Steven Luong | 71e5b47 | 2019-10-10 11:36:41 -0700 | [diff] [blame] | 178 | |
| 179 | next: |
Damjan Marion | 7d98a12 | 2018-07-19 20:42:08 +0200 | [diff] [blame] | 180 | vnet_feature_next (next_index, b); |
Damjan Marion | 5e5adb3 | 2018-05-26 00:50:39 +0200 | [diff] [blame] | 181 | } |
| 182 | |
Steven Luong | 71e5b47 | 2019-10-10 11:36:41 -0700 | [diff] [blame] | 183 | static_always_inline void |
| 184 | bond_update_next_x4 (vlib_buffer_t * b0, vlib_buffer_t * b1, |
| 185 | vlib_buffer_t * b2, vlib_buffer_t * b3) |
| 186 | { |
| 187 | u32 tmp0, tmp1, tmp2, tmp3; |
| 188 | |
| 189 | tmp0 = tmp1 = tmp2 = tmp3 = BOND_INPUT_NEXT_DROP; |
| 190 | vnet_feature_next (&tmp0, b0); |
| 191 | vnet_feature_next (&tmp1, b1); |
| 192 | vnet_feature_next (&tmp2, b2); |
| 193 | vnet_feature_next (&tmp3, b3); |
| 194 | } |
| 195 | |
Damjan Marion | 812b32d | 2018-05-28 21:26:47 +0200 | [diff] [blame] | 196 | VLIB_NODE_FN (bond_input_node) (vlib_main_t * vm, |
| 197 | vlib_node_runtime_t * node, |
| 198 | vlib_frame_t * frame) |
Damjan Marion | 5e5adb3 | 2018-05-26 00:50:39 +0200 | [diff] [blame] | 199 | { |
Damjan Marion | 067cd62 | 2018-07-11 12:47:43 +0200 | [diff] [blame] | 200 | u16 thread_index = vm->thread_index; |
Damjan Marion | 5e5adb3 | 2018-05-26 00:50:39 +0200 | [diff] [blame] | 201 | u32 *from, n_left; |
| 202 | vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b; |
| 203 | u32 sw_if_indices[VLIB_FRAME_SIZE], *sw_if_index; |
| 204 | u16 nexts[VLIB_FRAME_SIZE], *next; |
| 205 | u32 last_slave_sw_if_index = ~0; |
| 206 | u32 bond_sw_if_index = 0; |
| 207 | vlib_error_t error = 0; |
| 208 | u32 next_index = 0; |
Steven Luong | c94afaa | 2019-07-24 21:16:09 -0700 | [diff] [blame] | 209 | u32 n_rx_bytes = 0, n_rx_packets = 0; |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 210 | |
| 211 | /* Vector of buffer / pkt indices we're supposed to process */ |
| 212 | from = vlib_frame_vector_args (frame); |
| 213 | |
| 214 | /* Number of buffers / pkts */ |
Damjan Marion | 5e5adb3 | 2018-05-26 00:50:39 +0200 | [diff] [blame] | 215 | n_left = frame->n_vectors; |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 216 | |
Damjan Marion | 5e5adb3 | 2018-05-26 00:50:39 +0200 | [diff] [blame] | 217 | vlib_get_buffers (vm, from, bufs, n_left); |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 218 | |
Damjan Marion | 5e5adb3 | 2018-05-26 00:50:39 +0200 | [diff] [blame] | 219 | b = bufs; |
| 220 | next = nexts; |
| 221 | sw_if_index = sw_if_indices; |
| 222 | |
| 223 | while (n_left >= 4) |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 224 | { |
Damjan Marion | 5e5adb3 | 2018-05-26 00:50:39 +0200 | [diff] [blame] | 225 | u32 x = 0; |
| 226 | /* Prefetch next iteration */ |
| 227 | if (PREDICT_TRUE (n_left >= 16)) |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 228 | { |
Damjan Marion | d30bf01 | 2018-11-18 23:48:43 +0100 | [diff] [blame] | 229 | vlib_prefetch_buffer_data (b[8], LOAD); |
| 230 | vlib_prefetch_buffer_data (b[9], LOAD); |
| 231 | vlib_prefetch_buffer_data (b[10], LOAD); |
| 232 | vlib_prefetch_buffer_data (b[11], LOAD); |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 233 | |
Damjan Marion | 5e5adb3 | 2018-05-26 00:50:39 +0200 | [diff] [blame] | 234 | vlib_prefetch_buffer_header (b[12], LOAD); |
| 235 | vlib_prefetch_buffer_header (b[13], LOAD); |
| 236 | vlib_prefetch_buffer_header (b[14], LOAD); |
| 237 | vlib_prefetch_buffer_header (b[15], LOAD); |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 238 | } |
| 239 | |
Damjan Marion | 5e5adb3 | 2018-05-26 00:50:39 +0200 | [diff] [blame] | 240 | sw_if_index[0] = vnet_buffer (b[0])->sw_if_index[VLIB_RX]; |
| 241 | sw_if_index[1] = vnet_buffer (b[1])->sw_if_index[VLIB_RX]; |
| 242 | sw_if_index[2] = vnet_buffer (b[2])->sw_if_index[VLIB_RX]; |
| 243 | sw_if_index[3] = vnet_buffer (b[3])->sw_if_index[VLIB_RX]; |
| 244 | |
| 245 | x |= sw_if_index[0] ^ last_slave_sw_if_index; |
| 246 | x |= sw_if_index[1] ^ last_slave_sw_if_index; |
| 247 | x |= sw_if_index[2] ^ last_slave_sw_if_index; |
| 248 | x |= sw_if_index[3] ^ last_slave_sw_if_index; |
| 249 | |
| 250 | if (PREDICT_TRUE (x == 0)) |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 251 | { |
Steven Luong | 71e5b47 | 2019-10-10 11:36:41 -0700 | [diff] [blame] | 252 | /* |
| 253 | * Optimize to call update_next only if there is a feature arc |
| 254 | * after bond-input. Test feature count greater than 1 because |
| 255 | * bond-input itself is a feature arc for this slave interface. |
| 256 | */ |
| 257 | ASSERT ((vnet_buffer (b[0])->feature_arc_index == |
| 258 | vnet_buffer (b[1])->feature_arc_index) && |
| 259 | (vnet_buffer (b[0])->feature_arc_index == |
| 260 | vnet_buffer (b[2])->feature_arc_index) && |
| 261 | (vnet_buffer (b[0])->feature_arc_index == |
| 262 | vnet_buffer (b[3])->feature_arc_index)); |
| 263 | if (PREDICT_FALSE (vnet_get_feature_count |
| 264 | (vnet_buffer (b[0])->feature_arc_index, |
| 265 | last_slave_sw_if_index) > 1)) |
| 266 | bond_update_next_x4 (b[0], b[1], b[2], b[3]); |
| 267 | |
Damjan Marion | 5e5adb3 | 2018-05-26 00:50:39 +0200 | [diff] [blame] | 268 | next[0] = next[1] = next[2] = next[3] = next_index; |
| 269 | if (next_index == BOND_INPUT_NEXT_DROP) |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 270 | { |
Damjan Marion | 5e5adb3 | 2018-05-26 00:50:39 +0200 | [diff] [blame] | 271 | b[0]->error = error; |
| 272 | b[1]->error = error; |
| 273 | b[2]->error = error; |
| 274 | b[3]->error = error; |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 275 | } |
Damjan Marion | 5e5adb3 | 2018-05-26 00:50:39 +0200 | [diff] [blame] | 276 | else |
Steven | 70488ab | 2018-03-28 17:59:00 -0700 | [diff] [blame] | 277 | { |
Steven Luong | c94afaa | 2019-07-24 21:16:09 -0700 | [diff] [blame] | 278 | bond_sw_if_idx_rewrite (vm, node, b[0], bond_sw_if_index, |
| 279 | &n_rx_packets, &n_rx_bytes); |
| 280 | bond_sw_if_idx_rewrite (vm, node, b[1], bond_sw_if_index, |
| 281 | &n_rx_packets, &n_rx_bytes); |
| 282 | bond_sw_if_idx_rewrite (vm, node, b[2], bond_sw_if_index, |
| 283 | &n_rx_packets, &n_rx_bytes); |
| 284 | bond_sw_if_idx_rewrite (vm, node, b[3], bond_sw_if_index, |
| 285 | &n_rx_packets, &n_rx_bytes); |
Steven | 70488ab | 2018-03-28 17:59:00 -0700 | [diff] [blame] | 286 | } |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 287 | } |
Damjan Marion | 5e5adb3 | 2018-05-26 00:50:39 +0200 | [diff] [blame] | 288 | else |
| 289 | { |
Damjan Marion | 5e5adb3 | 2018-05-26 00:50:39 +0200 | [diff] [blame] | 290 | bond_update_next (vm, node, &last_slave_sw_if_index, sw_if_index[0], |
Steven Luong | c94afaa | 2019-07-24 21:16:09 -0700 | [diff] [blame] | 291 | &bond_sw_if_index, b[0], &next_index, &error); |
Damjan Marion | 5e5adb3 | 2018-05-26 00:50:39 +0200 | [diff] [blame] | 292 | next[0] = next_index; |
| 293 | if (next_index == BOND_INPUT_NEXT_DROP) |
| 294 | b[0]->error = error; |
| 295 | else |
Steven Luong | c94afaa | 2019-07-24 21:16:09 -0700 | [diff] [blame] | 296 | bond_sw_if_idx_rewrite (vm, node, b[0], bond_sw_if_index, |
| 297 | &n_rx_packets, &n_rx_bytes); |
Damjan Marion | 5e5adb3 | 2018-05-26 00:50:39 +0200 | [diff] [blame] | 298 | |
| 299 | bond_update_next (vm, node, &last_slave_sw_if_index, sw_if_index[1], |
Steven Luong | c94afaa | 2019-07-24 21:16:09 -0700 | [diff] [blame] | 300 | &bond_sw_if_index, b[1], &next_index, &error); |
Damjan Marion | 5e5adb3 | 2018-05-26 00:50:39 +0200 | [diff] [blame] | 301 | next[1] = next_index; |
| 302 | if (next_index == BOND_INPUT_NEXT_DROP) |
| 303 | b[1]->error = error; |
| 304 | else |
Steven Luong | c94afaa | 2019-07-24 21:16:09 -0700 | [diff] [blame] | 305 | bond_sw_if_idx_rewrite (vm, node, b[1], bond_sw_if_index, |
| 306 | &n_rx_packets, &n_rx_bytes); |
Damjan Marion | 5e5adb3 | 2018-05-26 00:50:39 +0200 | [diff] [blame] | 307 | |
| 308 | bond_update_next (vm, node, &last_slave_sw_if_index, sw_if_index[2], |
Steven Luong | c94afaa | 2019-07-24 21:16:09 -0700 | [diff] [blame] | 309 | &bond_sw_if_index, b[2], &next_index, &error); |
Damjan Marion | 5e5adb3 | 2018-05-26 00:50:39 +0200 | [diff] [blame] | 310 | next[2] = next_index; |
| 311 | if (next_index == BOND_INPUT_NEXT_DROP) |
| 312 | b[2]->error = error; |
| 313 | else |
Steven Luong | c94afaa | 2019-07-24 21:16:09 -0700 | [diff] [blame] | 314 | bond_sw_if_idx_rewrite (vm, node, b[2], bond_sw_if_index, |
| 315 | &n_rx_packets, &n_rx_bytes); |
Damjan Marion | 5e5adb3 | 2018-05-26 00:50:39 +0200 | [diff] [blame] | 316 | |
| 317 | bond_update_next (vm, node, &last_slave_sw_if_index, sw_if_index[3], |
Steven Luong | c94afaa | 2019-07-24 21:16:09 -0700 | [diff] [blame] | 318 | &bond_sw_if_index, b[3], &next_index, &error); |
Damjan Marion | 5e5adb3 | 2018-05-26 00:50:39 +0200 | [diff] [blame] | 319 | next[3] = next_index; |
| 320 | if (next_index == BOND_INPUT_NEXT_DROP) |
| 321 | b[3]->error = error; |
| 322 | else |
Steven Luong | c94afaa | 2019-07-24 21:16:09 -0700 | [diff] [blame] | 323 | bond_sw_if_idx_rewrite (vm, node, b[3], bond_sw_if_index, |
| 324 | &n_rx_packets, &n_rx_bytes); |
Damjan Marion | 5e5adb3 | 2018-05-26 00:50:39 +0200 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b[0]); |
| 328 | VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b[1]); |
| 329 | VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b[2]); |
| 330 | VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b[3]); |
| 331 | |
| 332 | /* next */ |
| 333 | n_left -= 4; |
| 334 | b += 4; |
| 335 | sw_if_index += 4; |
| 336 | next += 4; |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 337 | } |
| 338 | |
Damjan Marion | 5e5adb3 | 2018-05-26 00:50:39 +0200 | [diff] [blame] | 339 | while (n_left) |
| 340 | { |
| 341 | sw_if_index[0] = vnet_buffer (b[0])->sw_if_index[VLIB_RX]; |
| 342 | bond_update_next (vm, node, &last_slave_sw_if_index, sw_if_index[0], |
Steven Luong | c94afaa | 2019-07-24 21:16:09 -0700 | [diff] [blame] | 343 | &bond_sw_if_index, b[0], &next_index, &error); |
Damjan Marion | 5e5adb3 | 2018-05-26 00:50:39 +0200 | [diff] [blame] | 344 | next[0] = next_index; |
| 345 | if (next_index == BOND_INPUT_NEXT_DROP) |
| 346 | b[0]->error = error; |
| 347 | else |
Steven Luong | c94afaa | 2019-07-24 21:16:09 -0700 | [diff] [blame] | 348 | bond_sw_if_idx_rewrite (vm, node, b[0], bond_sw_if_index, |
| 349 | &n_rx_packets, &n_rx_bytes); |
Damjan Marion | 5e5adb3 | 2018-05-26 00:50:39 +0200 | [diff] [blame] | 350 | |
| 351 | VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b[0]); |
| 352 | |
| 353 | /* next */ |
| 354 | n_left -= 1; |
| 355 | b += 1; |
| 356 | sw_if_index += 1; |
| 357 | next += 1; |
| 358 | } |
| 359 | |
| 360 | if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE))) |
| 361 | { |
| 362 | n_left = frame->n_vectors; /* number of packets to process */ |
| 363 | b = bufs; |
| 364 | sw_if_index = sw_if_indices; |
Damjan Marion | 5e5adb3 | 2018-05-26 00:50:39 +0200 | [diff] [blame] | 365 | bond_packet_trace_t *t0; |
Damjan Marion | 5e5adb3 | 2018-05-26 00:50:39 +0200 | [diff] [blame] | 366 | |
Damjan Marion | f264f08 | 2018-05-30 00:03:34 +0200 | [diff] [blame] | 367 | while (n_left) |
Damjan Marion | 5e5adb3 | 2018-05-26 00:50:39 +0200 | [diff] [blame] | 368 | { |
| 369 | if (PREDICT_FALSE (b[0]->flags & VLIB_BUFFER_IS_TRACED)) |
| 370 | { |
Damjan Marion | 5e5adb3 | 2018-05-26 00:50:39 +0200 | [diff] [blame] | 371 | t0 = vlib_add_trace (vm, node, b[0], sizeof (*t0)); |
| 372 | t0->sw_if_index = sw_if_index[0]; |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 373 | clib_memcpy_fast (&t0->ethernet, vlib_buffer_get_current (b[0]), |
| 374 | sizeof (ethernet_header_t)); |
Damjan Marion | 5e5adb3 | 2018-05-26 00:50:39 +0200 | [diff] [blame] | 375 | t0->bond_sw_if_index = vnet_buffer (b[0])->sw_if_index[VLIB_RX]; |
| 376 | } |
| 377 | /* next */ |
| 378 | n_left--; |
| 379 | b++; |
| 380 | sw_if_index++; |
Damjan Marion | 5e5adb3 | 2018-05-26 00:50:39 +0200 | [diff] [blame] | 381 | } |
| 382 | } |
| 383 | |
| 384 | /* increase rx counters */ |
Steven Luong | c94afaa | 2019-07-24 21:16:09 -0700 | [diff] [blame] | 385 | vlib_increment_combined_counter |
| 386 | (vnet_main.interface_main.combined_sw_if_counters + |
| 387 | VNET_INTERFACE_COUNTER_RX, thread_index, bond_sw_if_index, n_rx_packets, |
| 388 | n_rx_bytes); |
Damjan Marion | 5e5adb3 | 2018-05-26 00:50:39 +0200 | [diff] [blame] | 389 | |
| 390 | vlib_buffer_enqueue_to_next (vm, node, from, nexts, frame->n_vectors); |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 391 | vlib_node_increment_counter (vm, bond_input_node.index, |
| 392 | BOND_INPUT_ERROR_NONE, frame->n_vectors); |
| 393 | |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 394 | return frame->n_vectors; |
| 395 | } |
| 396 | |
| 397 | static clib_error_t * |
| 398 | bond_input_init (vlib_main_t * vm) |
| 399 | { |
| 400 | return 0; |
| 401 | } |
| 402 | |
| 403 | /* *INDENT-OFF* */ |
| 404 | VLIB_REGISTER_NODE (bond_input_node) = { |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 405 | .name = "bond-input", |
| 406 | .vector_size = sizeof (u32), |
| 407 | .format_buffer = format_ethernet_header_with_length, |
| 408 | .format_trace = format_bond_input_trace, |
| 409 | .type = VLIB_NODE_TYPE_INTERNAL, |
| 410 | .n_errors = BOND_INPUT_N_ERROR, |
| 411 | .error_strings = bond_input_error_strings, |
Damjan Marion | 5e5adb3 | 2018-05-26 00:50:39 +0200 | [diff] [blame] | 412 | .n_next_nodes = BOND_INPUT_N_NEXT, |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 413 | .next_nodes = |
| 414 | { |
Damjan Marion | 5e5adb3 | 2018-05-26 00:50:39 +0200 | [diff] [blame] | 415 | [BOND_INPUT_NEXT_DROP] = "error-drop" |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 416 | } |
| 417 | }; |
| 418 | |
| 419 | VLIB_INIT_FUNCTION (bond_input_init); |
| 420 | |
| 421 | VNET_FEATURE_INIT (bond_input, static) = |
| 422 | { |
| 423 | .arc_name = "device-input", |
| 424 | .node_name = "bond-input", |
| 425 | .runs_before = VNET_FEATURES ("ethernet-input"), |
| 426 | }; |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 427 | /* *INDENT-ON* */ |
| 428 | |
| 429 | static clib_error_t * |
| 430 | bond_sw_interface_up_down (vnet_main_t * vnm, u32 sw_if_index, u32 flags) |
| 431 | { |
| 432 | bond_main_t *bm = &bond_main; |
| 433 | slave_if_t *sif; |
| 434 | vlib_main_t *vm = bm->vlib_main; |
| 435 | |
| 436 | sif = bond_get_slave_by_sw_if_index (sw_if_index); |
| 437 | if (sif) |
| 438 | { |
Steven | e43278f | 2019-01-17 15:11:29 -0800 | [diff] [blame] | 439 | if (sif->lacp_enabled) |
| 440 | return 0; |
| 441 | |
Steven Luong | bac326c | 2019-08-05 09:47:58 -0700 | [diff] [blame] | 442 | /* port_enabled is both admin up and hw link up */ |
| 443 | sif->port_enabled = ((flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) && |
| 444 | vnet_sw_interface_is_link_up (vnm, sw_if_index)); |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 445 | if (sif->port_enabled == 0) |
Steven Luong | bac326c | 2019-08-05 09:47:58 -0700 | [diff] [blame] | 446 | bond_disable_collecting_distributing (vm, sif); |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 447 | else |
Steven Luong | bac326c | 2019-08-05 09:47:58 -0700 | [diff] [blame] | 448 | bond_enable_collecting_distributing (vm, sif); |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | return 0; |
| 452 | } |
| 453 | |
| 454 | VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (bond_sw_interface_up_down); |
| 455 | |
| 456 | static clib_error_t * |
| 457 | bond_hw_interface_up_down (vnet_main_t * vnm, u32 hw_if_index, u32 flags) |
| 458 | { |
| 459 | bond_main_t *bm = &bond_main; |
| 460 | slave_if_t *sif; |
| 461 | vnet_sw_interface_t *sw; |
| 462 | vlib_main_t *vm = bm->vlib_main; |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 463 | |
Steven | ce2db6a | 2018-04-23 17:06:24 -0700 | [diff] [blame] | 464 | sw = vnet_get_hw_sw_interface (vnm, hw_if_index); |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 465 | sif = bond_get_slave_by_sw_if_index (sw->sw_if_index); |
| 466 | if (sif) |
| 467 | { |
Steven | e43278f | 2019-01-17 15:11:29 -0800 | [diff] [blame] | 468 | if (sif->lacp_enabled) |
| 469 | return 0; |
| 470 | |
Steven Luong | bac326c | 2019-08-05 09:47:58 -0700 | [diff] [blame] | 471 | /* port_enabled is both admin up and hw link up */ |
| 472 | sif->port_enabled = ((flags & VNET_HW_INTERFACE_FLAG_LINK_UP) && |
| 473 | vnet_sw_interface_is_admin_up (vnm, |
| 474 | sw->sw_if_index)); |
| 475 | if (sif->port_enabled == 0) |
| 476 | bond_disable_collecting_distributing (vm, sif); |
| 477 | else |
| 478 | bond_enable_collecting_distributing (vm, sif); |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | return 0; |
| 482 | } |
| 483 | |
| 484 | VNET_HW_INTERFACE_LINK_UP_DOWN_FUNCTION (bond_hw_interface_up_down); |
Steven | 9cd2d7a | 2017-12-20 12:43:01 -0800 | [diff] [blame] | 485 | |
| 486 | /* |
| 487 | * fd.io coding-style-patch-verification: ON |
| 488 | * |
| 489 | * Local Variables: |
| 490 | * eval: (c-set-style "gnu") |
| 491 | * End: |
| 492 | */ |