2 * l2_bvi.c : layer 2 Bridged Virtual Interface
4 * Copyright (c) 2013 Cisco and/or its affiliates.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 #include <vnet/l2/l2_bvi.h>
21 * send packets to l2-input.
23 VNET_DEVICE_CLASS_TX_FN (bvi_device_class) (vlib_main_t * vm,
24 vlib_node_runtime_t * node,
27 u32 sw_if_indices[VLIB_FRAME_SIZE], *sw_if_index;
28 vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b;
29 u16 nexts[VLIB_FRAME_SIZE];
32 n_left = frame->n_vectors;
33 from = vlib_frame_vector_args (frame);
35 vlib_get_buffers (vm, from, bufs, n_left);
38 sw_if_index = sw_if_indices;
40 /* It's all going to l2-input */
41 clib_memset_u16 (nexts, 0, VLIB_FRAME_SIZE);
45 * - fixup the L2 length of the packet
46 * - set the RX interface (which the bridge will use) to the
47 * TX interface (which routing has chosen)
48 * - Set the TX interface to the special ID so the DP knows this is a BVI
49 * Don't counts packets and bytes, that's done in the bviX-output node
53 /* Prefetch next iteration. */
54 if (PREDICT_TRUE (n_left >= 8))
56 /* LOAD pre-fetch since meta and packet data is read */
57 vlib_prefetch_buffer_header (b[4], LOAD);
58 vlib_prefetch_buffer_header (b[5], LOAD);
59 vlib_prefetch_buffer_header (b[6], LOAD);
60 vlib_prefetch_buffer_header (b[7], LOAD);
62 vlib_prefetch_buffer_data (b[4], LOAD);
63 vlib_prefetch_buffer_data (b[5], LOAD);
64 vlib_prefetch_buffer_data (b[6], LOAD);
65 vlib_prefetch_buffer_data (b[7], LOAD);
68 vnet_update_l2_len (b[0]);
69 vnet_update_l2_len (b[1]);
70 vnet_update_l2_len (b[2]);
71 vnet_update_l2_len (b[3]);
73 sw_if_index[0] = vnet_buffer (b[0])->sw_if_index[VLIB_TX];
74 sw_if_index[1] = vnet_buffer (b[1])->sw_if_index[VLIB_TX];
75 sw_if_index[2] = vnet_buffer (b[2])->sw_if_index[VLIB_TX];
76 sw_if_index[3] = vnet_buffer (b[3])->sw_if_index[VLIB_TX];
78 vnet_buffer (b[0])->sw_if_index[VLIB_TX] = L2INPUT_BVI;
79 vnet_buffer (b[1])->sw_if_index[VLIB_TX] = L2INPUT_BVI;
80 vnet_buffer (b[2])->sw_if_index[VLIB_TX] = L2INPUT_BVI;
81 vnet_buffer (b[3])->sw_if_index[VLIB_TX] = L2INPUT_BVI;
83 vnet_buffer (b[0])->sw_if_index[VLIB_RX] = sw_if_index[0];
84 vnet_buffer (b[1])->sw_if_index[VLIB_RX] = sw_if_index[1];
85 vnet_buffer (b[2])->sw_if_index[VLIB_RX] = sw_if_index[2];
86 vnet_buffer (b[3])->sw_if_index[VLIB_RX] = sw_if_index[3];
94 sw_if_index[0] = vnet_buffer (b[0])->sw_if_index[VLIB_TX];
95 vnet_buffer (b[0])->sw_if_index[VLIB_TX] = L2INPUT_BVI;
96 vnet_buffer (b[0])->sw_if_index[VLIB_RX] = sw_if_index[0];
98 vnet_update_l2_len (b[0]);
105 vlib_buffer_enqueue_to_next (vm, node, from, nexts, frame->n_vectors);
107 return frame->n_vectors;
111 * fd.io coding-style-patch-verification: ON
114 * eval: (c-set-style "gnu")