From 7cd468a3d7dee7d6c92f69a0bb7061ae208ec727 Mon Sep 17 00:00:00 2001 From: Damjan Marion Date: Mon, 19 Dec 2016 23:05:39 +0100 Subject: Reorganize source tree to use single autotools instance Change-Id: I7b51f88292e057c6443b12224486f2d0c9f8ae23 Signed-off-by: Damjan Marion --- src/vnet/l2/l2_vtr.c | 770 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 770 insertions(+) create mode 100644 src/vnet/l2/l2_vtr.c (limited to 'src/vnet/l2/l2_vtr.c') diff --git a/src/vnet/l2/l2_vtr.c b/src/vnet/l2/l2_vtr.c new file mode 100644 index 00000000..95a4f157 --- /dev/null +++ b/src/vnet/l2/l2_vtr.c @@ -0,0 +1,770 @@ +/* + * l2_vtr.c : layer 2 vlan tag rewrite configuration + * + * Copyright (c) 2013 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +/** + * @file + * @brief Ethernet VLAN Tag Rewrite. + * + * VLAN tag rewrite provides the ability to change the VLAN tags on a packet. + * Existing tags can be popped, new tags can be pushed, and existing tags can + * be swapped with new tags. The rewrite feature is attached to a subinterface + * as input and output operations. The input operation is explicitly configured. + * The output operation is the symmetric opposite and is automatically derived + * from the input operation. + */ + +/** Just a placeholder; ensures file is not eliminated by linker. */ +clib_error_t * +l2_vtr_init (vlib_main_t * vm) +{ + return 0; +} + +VLIB_INIT_FUNCTION (l2_vtr_init); + +u32 +l2pbb_configure (vlib_main_t * vlib_main, + vnet_main_t * vnet_main, u32 sw_if_index, u32 vtr_op, + u8 * b_dmac, u8 * b_smac, + u16 b_vlanid, u32 i_sid, u16 vlan_outer_tag) +{ + u32 error = 0; + u32 enable = 0; + + l2_output_config_t *config = 0; + vnet_hw_interface_t *hi; + hi = vnet_get_sup_hw_interface (vnet_main, sw_if_index); + + if (!hi) + { + error = VNET_API_ERROR_INVALID_INTERFACE; + goto done; + } + + // Config for this interface should be already initialized + ptr_config_t *in_config; + ptr_config_t *out_config; + config = vec_elt_at_index (l2output_main.configs, sw_if_index); + in_config = &(config->input_pbb_vtr); + out_config = &(config->output_pbb_vtr); + + in_config->pop_bytes = 0; + in_config->push_bytes = 0; + out_config->pop_bytes = 0; + out_config->push_bytes = 0; + enable = (vtr_op != L2_VTR_DISABLED); + + if (!enable) + goto done; + + if (vtr_op == L2_VTR_POP_2) + { + in_config->pop_bytes = sizeof (ethernet_pbb_header_packed_t); + } + else if (vtr_op == L2_VTR_PUSH_2) + { + clib_memcpy (in_config->macs_tags.b_dst_address, b_dmac, + sizeof (in_config->macs_tags.b_dst_address)); + clib_memcpy (in_config->macs_tags.b_src_address, b_smac, + sizeof (in_config->macs_tags.b_src_address)); + in_config->macs_tags.b_type = + clib_net_to_host_u16 (ETHERNET_TYPE_DOT1AD); + in_config->macs_tags.priority_dei_id = + clib_net_to_host_u16 (b_vlanid & 0xFFF); + in_config->macs_tags.i_type = + clib_net_to_host_u16 (ETHERNET_TYPE_DOT1AH); + in_config->macs_tags.priority_dei_uca_res_sid = + clib_net_to_host_u32 (i_sid & 0xFFFFF); + in_config->push_bytes = sizeof (ethernet_pbb_header_packed_t); + } + else if (vtr_op == L2_VTR_TRANSLATE_2_2) + { + /* TODO after PoC */ + } + + /* + * Construct the output tag-rewrite config + * + * The push/pop values are always reversed + */ + out_config->raw_data = in_config->raw_data; + out_config->pop_bytes = in_config->push_bytes; + out_config->push_bytes = in_config->pop_bytes; + +done: + l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_VTR, enable); + if (config) + config->out_vtr_flag = (u8) enable; + + /* output vtr enable is checked explicitly in l2_output */ + return error; +} + +/** + * Configure vtag tag rewrite on the given interface. + * Return 1 if there is an error, 0 if ok + */ +u32 +l2vtr_configure (vlib_main_t * vlib_main, vnet_main_t * vnet_main, u32 sw_if_index, u32 vtr_op, u32 push_dot1q, /* ethertype of first pushed tag is dot1q/dot1ad */ + u32 vtr_tag1, /* first pushed tag */ + u32 vtr_tag2) /* second pushed tag */ +{ + vnet_hw_interface_t *hi; + vnet_sw_interface_t *si; + u32 hw_no_tags; + u32 error = 0; + l2_output_config_t *config; + vtr_config_t *in_config; + vtr_config_t *out_config; + u32 enable; + u32 push_inner_et; + u32 push_outer_et; + u32 cfg_tags; + + hi = vnet_get_sup_hw_interface (vnet_main, sw_if_index); + if (!hi || (hi->hw_class_index != ethernet_hw_interface_class.index)) + { + error = VNET_API_ERROR_INVALID_INTERFACE; /* non-ethernet interface */ + goto done; + } + + /* Init the config for this interface */ + vec_validate (l2output_main.configs, sw_if_index); + config = vec_elt_at_index (l2output_main.configs, sw_if_index); + in_config = &(config->input_vtr); + out_config = &(config->output_vtr); + in_config->raw_tags = 0; + out_config->raw_tags = 0; + + /* Get the configured tags for the interface */ + si = vnet_get_sw_interface (vnet_main, sw_if_index); + hw_no_tags = (si->type == VNET_SW_INTERFACE_TYPE_HARDWARE); + + /* Construct the input tag-rewrite config */ + + push_outer_et = + clib_net_to_host_u16 (push_dot1q ? ETHERNET_TYPE_VLAN : + ETHERNET_TYPE_DOT1AD); + push_inner_et = clib_net_to_host_u16 (ETHERNET_TYPE_VLAN); + vtr_tag1 = clib_net_to_host_u16 (vtr_tag1); + vtr_tag2 = clib_net_to_host_u16 (vtr_tag2); + + /* Determine number of vlan tags with explictly configured values */ + cfg_tags = 0; + if (hw_no_tags || si->sub.eth.flags.no_tags) + { + cfg_tags = 0; + } + else if (si->sub.eth.flags.one_tag) + { + cfg_tags = 1; + if (si->sub.eth.flags.outer_vlan_id_any) + { + cfg_tags = 0; + } + } + else if (si->sub.eth.flags.two_tags) + { + cfg_tags = 2; + if (si->sub.eth.flags.inner_vlan_id_any) + { + cfg_tags = 1; + } + if (si->sub.eth.flags.outer_vlan_id_any) + { + cfg_tags = 0; + } + } + + switch (vtr_op) + { + case L2_VTR_DISABLED: + in_config->push_and_pop_bytes = 0; + break; + + case L2_VTR_POP_1: + if (cfg_tags < 1) + { + /* Need one or two tags */ + error = VNET_API_ERROR_INVALID_VLAN_TAG_COUNT; + goto done; + } + in_config->pop_bytes = 4; + in_config->push_bytes = 0; + break; + + case L2_VTR_POP_2: + if (cfg_tags < 2) + { + error = VNET_API_ERROR_INVALID_VLAN_TAG_COUNT; /* Need two tags */ + goto done; + } + in_config->pop_bytes = 8; + in_config->push_bytes = 0; + + out_config->push_bytes = in_config->pop_bytes; + out_config->pop_bytes = in_config->push_bytes; + break; + + case L2_VTR_PUSH_1: + in_config->pop_bytes = 0; + in_config->push_bytes = 4; + in_config->tags[1].priority_cfi_and_id = vtr_tag1; + in_config->tags[1].type = push_outer_et; + break; + + case L2_VTR_PUSH_2: + in_config->pop_bytes = 0; + in_config->push_bytes = 8; + in_config->tags[0].priority_cfi_and_id = vtr_tag1; + in_config->tags[0].type = push_outer_et; + in_config->tags[1].priority_cfi_and_id = vtr_tag2; + in_config->tags[1].type = push_inner_et; + break; + + case L2_VTR_TRANSLATE_1_1: + if (cfg_tags < 1) + { + error = VNET_API_ERROR_INVALID_VLAN_TAG_COUNT; /* Need one or two tags */ + goto done; + } + in_config->pop_bytes = 4; + in_config->push_bytes = 4; + in_config->tags[1].priority_cfi_and_id = vtr_tag1; + in_config->tags[1].type = push_outer_et; + break; + + case L2_VTR_TRANSLATE_1_2: + if (cfg_tags < 1) + { + error = VNET_API_ERROR_INVALID_VLAN_TAG_COUNT; /* Need one or two tags */ + goto done; + } + in_config->pop_bytes = 4; + in_config->push_bytes = 8; + in_config->tags[0].priority_cfi_and_id = vtr_tag1; + in_config->tags[0].type = push_outer_et; + in_config->tags[1].priority_cfi_and_id = vtr_tag2; + in_config->tags[1].type = push_inner_et; + break; + + case L2_VTR_TRANSLATE_2_1: + if (cfg_tags < 2) + { + error = VNET_API_ERROR_INVALID_VLAN_TAG_COUNT; /* Need two tags */ + goto done; + } + in_config->pop_bytes = 8; + in_config->push_bytes = 4; + in_config->tags[1].priority_cfi_and_id = vtr_tag1; + in_config->tags[1].type = push_outer_et; + break; + + case L2_VTR_TRANSLATE_2_2: + if (cfg_tags < 2) + { + error = VNET_API_ERROR_INVALID_VLAN_TAG_COUNT; /* Need two tags */ + goto done; + } + in_config->pop_bytes = 8; + in_config->push_bytes = 8; + in_config->tags[0].priority_cfi_and_id = vtr_tag1; + in_config->tags[0].type = push_outer_et; + in_config->tags[1].priority_cfi_and_id = vtr_tag2; + in_config->tags[1].type = push_inner_et; + break; + } + + /* + * Construct the output tag-rewrite config + * + * The push/pop values are always reversed + */ + out_config->push_bytes = in_config->pop_bytes; + out_config->pop_bytes = in_config->push_bytes; + + /* Any pushed tags are derived from the subinterface config */ + push_outer_et = + clib_net_to_host_u16 (si->sub.eth.flags.dot1ad ? ETHERNET_TYPE_DOT1AD : + ETHERNET_TYPE_VLAN); + push_inner_et = clib_net_to_host_u16 (ETHERNET_TYPE_VLAN); + vtr_tag1 = clib_net_to_host_u16 (si->sub.eth.outer_vlan_id); + vtr_tag2 = clib_net_to_host_u16 (si->sub.eth.inner_vlan_id); + + if (out_config->push_bytes == 4) + { + out_config->tags[1].priority_cfi_and_id = vtr_tag1; + out_config->tags[1].type = push_outer_et; + } + else if (out_config->push_bytes == 8) + { + out_config->tags[0].priority_cfi_and_id = vtr_tag1; + out_config->tags[0].type = push_outer_et; + out_config->tags[1].priority_cfi_and_id = vtr_tag2; + out_config->tags[1].type = push_inner_et; + } + + /* set the interface enable flags */ + enable = (vtr_op != L2_VTR_DISABLED); + config->out_vtr_flag = (u8) enable; + l2input_intf_bitmap_enable (sw_if_index, L2INPUT_FEAT_VTR, enable); + /* output vtr enable is checked explicitly in l2_output */ + +done: + return error; +} + +/** + * Get vtag tag rewrite on the given interface. + * Return 1 if there is an error, 0 if ok + */ +u32 +l2vtr_get (vlib_main_t * vlib_main, vnet_main_t * vnet_main, u32 sw_if_index, u32 * vtr_op, u32 * push_dot1q, /* ethertype of first pushed tag is dot1q/dot1ad */ + u32 * vtr_tag1, /* first pushed tag */ + u32 * vtr_tag2) /* second pushed tag */ +{ + vnet_hw_interface_t *hi; + u32 error = 0; + vtr_config_t *in_config; + + if (!vtr_op || !push_dot1q || !vtr_tag1 || !vtr_tag2) + { + clib_warning ("invalid arguments"); + error = VNET_API_ERROR_INVALID_ARGUMENT; + goto done; + } + + *vtr_op = L2_VTR_DISABLED; + *vtr_tag1 = 0; + *vtr_tag2 = 0; + *push_dot1q = 0; + + hi = vnet_get_sup_hw_interface (vnet_main, sw_if_index); + if (!hi || (hi->hw_class_index != ethernet_hw_interface_class.index)) + { + /* non-ethernet interface */ + goto done; + } + + if (sw_if_index >= vec_len (l2output_main.configs)) + { + /* no specific config (return disabled) */ + goto done; + } + + /* Get the config for this interface */ + in_config = + &(vec_elt_at_index (l2output_main.configs, sw_if_index)->input_vtr); + + /* DISABLED */ + if (in_config->push_and_pop_bytes == 0) + { + goto done; + } + + /* find out vtr_op */ + switch (in_config->pop_bytes) + { + case 0: + switch (in_config->push_bytes) + { + case 0: + /* DISABLED */ + goto done; + case 4: + *vtr_op = L2_VTR_PUSH_1; + *vtr_tag1 = + clib_host_to_net_u16 (in_config->tags[1].priority_cfi_and_id); + *push_dot1q = + (ETHERNET_TYPE_VLAN == + clib_host_to_net_u16 (in_config->tags[1].type)); + break; + case 8: + *vtr_op = L2_VTR_PUSH_2; + *vtr_tag1 = + clib_host_to_net_u16 (in_config->tags[0].priority_cfi_and_id); + *vtr_tag2 = + clib_host_to_net_u16 (in_config->tags[1].priority_cfi_and_id); + *push_dot1q = + (ETHERNET_TYPE_VLAN == + clib_host_to_net_u16 (in_config->tags[0].type)); + break; + default: + clib_warning ("invalid push_bytes count: %d", + in_config->push_bytes); + error = VNET_API_ERROR_UNEXPECTED_INTF_STATE; + goto done; + } + break; + + case 4: + switch (in_config->push_bytes) + { + case 0: + *vtr_op = L2_VTR_POP_1; + break; + case 4: + *vtr_op = L2_VTR_TRANSLATE_1_1; + *vtr_tag1 = + clib_host_to_net_u16 (in_config->tags[1].priority_cfi_and_id); + *push_dot1q = + (ETHERNET_TYPE_VLAN == + clib_host_to_net_u16 (in_config->tags[1].type)); + break; + case 8: + *vtr_op = L2_VTR_TRANSLATE_1_2; + *vtr_tag1 = + clib_host_to_net_u16 (in_config->tags[0].priority_cfi_and_id); + *vtr_tag2 = + clib_host_to_net_u16 (in_config->tags[1].priority_cfi_and_id); + *push_dot1q = + (ETHERNET_TYPE_VLAN == + clib_host_to_net_u16 (in_config->tags[0].type)); + break; + default: + clib_warning ("invalid push_bytes count: %d", + in_config->push_bytes); + error = VNET_API_ERROR_UNEXPECTED_INTF_STATE; + goto done; + } + break; + + case 8: + switch (in_config->push_bytes) + { + case 0: + *vtr_op = L2_VTR_POP_2; + break; + case 4: + *vtr_op = L2_VTR_TRANSLATE_2_1; + *vtr_tag1 = + clib_host_to_net_u16 (in_config->tags[1].priority_cfi_and_id); + *push_dot1q = + (ETHERNET_TYPE_VLAN == + clib_host_to_net_u16 (in_config->tags[1].type)); + break; + case 8: + *vtr_op = L2_VTR_TRANSLATE_2_2; + *vtr_tag1 = + clib_host_to_net_u16 (in_config->tags[0].priority_cfi_and_id); + *vtr_tag2 = + clib_host_to_net_u16 (in_config->tags[1].priority_cfi_and_id); + *push_dot1q = + (ETHERNET_TYPE_VLAN == + clib_host_to_net_u16 (in_config->tags[0].type)); + break; + default: + clib_warning ("invalid push_bytes count: %d", + in_config->push_bytes); + error = VNET_API_ERROR_UNEXPECTED_INTF_STATE; + goto done; + } + break; + + default: + clib_warning ("invalid pop_bytes count: %d", in_config->pop_bytes); + error = VNET_API_ERROR_UNEXPECTED_INTF_STATE; + goto done; + } + +done: + return error; +} + +/** + * Set subinterface vtr enable/disable. + * The CLI format is: + * set interface l2 tag-rewrite [disable | pop 1 | pop 2 | push {dot1q|dot1ad} []] + * + * "push" can also be replaced by "translate-{1|2}-{1|2}" + */ +static clib_error_t * +int_l2_vtr (vlib_main_t * vm, + unformat_input_t * input, vlib_cli_command_t * cmd) +{ + vnet_main_t *vnm = vnet_get_main (); + clib_error_t *error = 0; + u32 sw_if_index; + u32 vtr_op; + u32 push_dot1q = 0; + u32 tag1 = 0, tag2 = 0; + + if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index)) + { + error = clib_error_return (0, "unknown interface `%U'", + format_unformat_error, input); + goto done; + } + + vtr_op = L2_VTR_DISABLED; + + if (unformat (input, "disable")) + { + vtr_op = L2_VTR_DISABLED; + } + else if (unformat (input, "pop 1")) + { + vtr_op = L2_VTR_POP_1; + } + else if (unformat (input, "pop 2")) + { + vtr_op = L2_VTR_POP_2; + + } + else if (unformat (input, "push dot1q %d %d", &tag1, &tag2)) + { + vtr_op = L2_VTR_PUSH_2; + push_dot1q = 1; + } + else if (unformat (input, "push dot1ad %d %d", &tag1, &tag2)) + { + vtr_op = L2_VTR_PUSH_2; + + } + else if (unformat (input, "push dot1q %d", &tag1)) + { + vtr_op = L2_VTR_PUSH_1; + push_dot1q = 1; + } + else if (unformat (input, "push dot1ad %d", &tag1)) + { + vtr_op = L2_VTR_PUSH_1; + + } + else if (unformat (input, "translate 1-1 dot1q %d", &tag1)) + { + vtr_op = L2_VTR_TRANSLATE_1_1; + push_dot1q = 1; + } + else if (unformat (input, "translate 1-1 dot1ad %d", &tag1)) + { + vtr_op = L2_VTR_TRANSLATE_1_1; + + } + else if (unformat (input, "translate 2-1 dot1q %d", &tag1)) + { + vtr_op = L2_VTR_TRANSLATE_2_1; + push_dot1q = 1; + } + else if (unformat (input, "translate 2-1 dot1ad %d", &tag1)) + { + vtr_op = L2_VTR_TRANSLATE_2_1; + + } + else if (unformat (input, "translate 2-2 dot1q %d %d", &tag1, &tag2)) + { + vtr_op = L2_VTR_TRANSLATE_2_2; + push_dot1q = 1; + } + else if (unformat (input, "translate 2-2 dot1ad %d %d", &tag1, &tag2)) + { + vtr_op = L2_VTR_TRANSLATE_2_2; + + } + else if (unformat (input, "translate 1-2 dot1q %d %d", &tag1, &tag2)) + { + vtr_op = L2_VTR_TRANSLATE_1_2; + push_dot1q = 1; + } + else if (unformat (input, "translate 1-2 dot1ad %d %d", &tag1, &tag2)) + { + vtr_op = L2_VTR_TRANSLATE_1_2; + + } + else + { + error = + clib_error_return (0, + "expecting [disable | pop 1 | pop 2 | push {dot1q|dot1ah} []\n" + " | translate {1|2}-{1|2} {dot1q|dot1ah} []] but got `%U'", + format_unformat_error, input); + goto done; + } + + if (l2vtr_configure (vm, vnm, sw_if_index, vtr_op, push_dot1q, tag1, tag2)) + { + error = + clib_error_return (0, + "vlan tag rewrite is not compatible with interface"); + goto done; + } + +done: + return error; +} + +/*? + * VLAN tag rewrite provides the ability to change the VLAN tags on a packet. + * Existing tags can be popped, new tags can be pushed, and existing tags can + * be swapped with new tags. The rewrite feature is attached to a subinterface + * as input and output operations. The input operation is explicitly configured. + * The output operation is the symmetric opposite and is automatically derived + * from the input operation. + * + * POP: For pop operations, the subinterface encapsulation (the vlan + * tags specified when it was created) must have at least the number of popped + * tags. e.g. the \"pop 2\" operation would be rejected on a single-vlan interface. + * The output tag-rewrite operation for pops is to push the specified number of + * vlan tags onto the packet. The pushed tag values are the ones in the + * subinterface encapsulation. + * + * PUSH: For push operations, the ethertype is also specified. The + * output tag-rewrite operation for pushes is to pop the same number of tags + * off the packet. If the packet doesn't have enough tags it is dropped. + * + * + * @cliexpar + * @parblock + * By default a subinterface has no tag-rewrite. To return a subinterface to + * this state use: + * @cliexcmd{set interface l2 tag-rewrite GigabitEthernet0/8/0.200 disable} + * + * To pop vlan tags off packets received from a subinterface, use: + * @cliexcmd{set interface l2 tag-rewrite GigabitEthernet0/8/0.200 pop 1} + * @cliexcmd{set interface l2 tag-rewrite GigabitEthernet0/8/0.200 pop 2} + * + * To push one or two vlan tags onto packets received from an interface, use: + * @cliexcmd{set interface l2 tag-rewrite GigabitEthernet0/8/0.200 push dot1q 100} + * @cliexcmd{set interface l2 tag-rewrite GigabitEthernet0/8/0.200 push dot1ad 100 150} + * + * Tags can also be translated, which is basically a combination of a pop and push. + * @cliexcmd{set interface l2 tag-rewrite GigabitEthernet0/8/0.200 translate 1-1 dot1ad 100} + * @cliexcmd{set interface l2 tag-rewrite GigabitEthernet0/8/0.200 translate 2-2 dot1ad 100 150} + * @cliexcmd{set interface l2 tag-rewrite GigabitEthernet0/8/0.200 translate 1-2 dot1q 100} + * @cliexcmd{set interface l2 tag-rewrite GigabitEthernet0/8/0.200 translate 2-1 dot1q 100 150} + * + * To display the VLAN Tag settings, show the associate bridge-domain: + * @cliexstart{show bridge-domain 200 detail} + * ID Index Learning U-Forwrd UU-Flood Flooding ARP-Term BVI-Intf + * 200 1 on on on on off N/A + * + * Interface Index SHG BVI VLAN-Tag-Rewrite + * GigabitEthernet0/8/0.200 5 0 - trans-1-1 dot1ad 100 + * GigabitEthernet0/9/0.200 4 0 - none + * GigabitEthernet0/a/0.200 6 0 - none + * @cliexend + * @endparblock +?*/ +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (int_l2_vtr_cli, static) = { + .path = "set interface l2 tag-rewrite", + .short_help = "set interface l2 tag-rewrite [disable | pop {1|2} | push {dot1q|dot1ad} ]", + .function = int_l2_vtr, +}; +/* *INDENT-ON* */ + +/** + * Set subinterface pbb vtr enable/disable. + * The CLI format is: + * set interface l2 pbb-tag-rewrite [disable | pop | push | translate_pbb_stag dmac
smac
s_id [b_vlanid ]] + */ +static clib_error_t * +int_l2_pbb_vtr (vlib_main_t * vm, + unformat_input_t * input, vlib_cli_command_t * cmd) +{ + vnet_main_t *vnm = vnet_get_main (); + clib_error_t *error = 0; + u32 sw_if_index, tmp; + u32 vtr_op = L2_VTR_DISABLED; + u32 outer_tag = 0; + u8 dmac[6]; + u8 smac[6]; + u8 dmac_set = 0, smac_set = 0; + u16 b_vlanid = 0; + u32 s_id = ~0; + + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat_user + (input, unformat_vnet_sw_interface, vnm, &sw_if_index)) + ; + else if (unformat (input, "disable")) + vtr_op = L2_VTR_DISABLED; + else if (vtr_op == L2_VTR_DISABLED && unformat (input, "pop")) + vtr_op = L2_VTR_POP_2; + else if (vtr_op == L2_VTR_DISABLED && unformat (input, "push")) + vtr_op = L2_VTR_PUSH_2; + else if (vtr_op == L2_VTR_DISABLED + && unformat (input, "translate_pbb_stag %d", &outer_tag)) + vtr_op = L2_VTR_TRANSLATE_2_1; + else if (unformat (input, "dmac %U", unformat_ethernet_address, dmac)) + dmac_set = 1; + else if (unformat (input, "smac %U", unformat_ethernet_address, smac)) + smac_set = 1; + else if (unformat (input, "b_vlanid %d", &tmp)) + b_vlanid = tmp; + else if (unformat (input, "s_id %d", &s_id)) + ; + else + { + error = clib_error_return (0, + "expecting [disable | pop | push | translate_pbb_stag \n" + "dmac
smac
s_id [b_vlanid ]]"); + goto done; + } + } + + if ((vtr_op == L2_VTR_PUSH_2 || vtr_op == L2_VTR_TRANSLATE_2_1) + && (!dmac_set || !smac_set || s_id == ~0)) + { + error = clib_error_return (0, + "expecting dmac
smac
s_id [b_vlanid ]"); + goto done; + } + + if (l2pbb_configure + (vm, vnm, sw_if_index, vtr_op, dmac, smac, b_vlanid, s_id, outer_tag)) + { + error = + clib_error_return (0, + "pbb tag rewrite is not compatible with interface"); + goto done; + } + +done: + return error; +} + +/* *INDENT-OFF* */ +VLIB_CLI_COMMAND (int_l2_pbb_vtr_cli, static) = { + .path = "set interface l2 pbb-tag-rewrite", + .short_help = "set interface l2 pbb-tag-rewrite [disable | pop | push | translate_pbb_stag dmac
smac
s_id [b_vlanid ]]", + .function = int_l2_pbb_vtr, +}; +/* *INDENT-ON* */ + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ -- cgit 1.2.3-korg From 65e845785f21e6b43c026f092e982171eec1f641 Mon Sep 17 00:00:00 2001 From: Pavel Kotucek Date: Mon, 16 Jan 2017 17:01:56 +0100 Subject: VPP-540 : pbb tag rewrite details Extended sw_interface_dump to provide 802.1ah (pbb) tag rewrite info if present. Extended log "l2-output" to provide raw data to display result of prospetive pbb tag rewrite. Tracing is moved after l2output_vtr to show these changes. Change-Id: I8b7cb865dc67ce21afab402cc086dac35f7c0f07 Signed-off-by: Pavel Kotucek --- src/vat/api_format.c | 13 +++++ src/vnet/ethernet/format.c | 38 ++++----------- src/vnet/interface.api | 19 +++++++- src/vnet/interface_api.c | 20 ++++++++ src/vnet/l2/l2_output.c | 115 +++++++++++++++++++++++++-------------------- src/vnet/l2/l2_vtr.c | 66 ++++++++++++++++++++++++++ src/vnet/l2/l2_vtr.h | 11 +++++ 7 files changed, 200 insertions(+), 82 deletions(-) (limited to 'src/vnet/l2/l2_vtr.c') diff --git a/src/vat/api_format.c b/src/vat/api_format.c index e3d8ab48..0f035279 100644 --- a/src/vat/api_format.c +++ b/src/vat/api_format.c @@ -914,6 +914,19 @@ static void vl_api_sw_interface_details_t_handler_json ntohl (mp->vtr_push_dot1q)); vat_json_object_add_uint (node, "vtr_tag1", ntohl (mp->vtr_tag1)); vat_json_object_add_uint (node, "vtr_tag2", ntohl (mp->vtr_tag2)); + if (mp->sub_dot1ah) + { + vat_json_object_add_string_copy (node, "pbb_vtr_dmac", + format (0, "%U", + format_ethernet_address, + &mp->b_dmac)); + vat_json_object_add_string_copy (node, "pbb_vtr_smac", + format (0, "%U", + format_ethernet_address, + &mp->b_smac)); + vat_json_object_add_uint (node, "pbb_vtr_b_vlanid", mp->b_vlanid); + vat_json_object_add_uint (node, "pbb_vtr_i_sid", mp->i_sid); + } } static void vl_api_sw_interface_set_flags_t_handler diff --git a/src/vnet/ethernet/format.c b/src/vnet/ethernet/format.c index 4edef5ad..5b589998 100644 --- a/src/vnet/ethernet/format.c +++ b/src/vnet/ethernet/format.c @@ -87,30 +87,6 @@ format_ethernet_vlan_tci (u8 * s, va_list * va) return s; } -u8 * -format_ethernet_pbb (u8 * s, va_list * va) -{ - u32 b_tag = va_arg (*va, u32); - u32 i_tag = va_arg (*va, u32); - u32 vid = (b_tag & 0xfff); - u32 bdei = (b_tag >> 12) & 1; - u32 bpcp = (b_tag >> 13); - u32 sid = (i_tag & 0xffffff); - u8 ires = (i_tag >> 24) & 3; - u8 iuca = (i_tag >> 27) & 1; - u8 idei = (i_tag >> 28) & 1; - u8 ipcp = (i_tag >> 29); - - s = - format (s, "B_tag %04X (vid %d, dei %d, pcp %d), ", b_tag, vid, bdei, - bpcp); - s = - format (s, "I_tag %08X (sid %d, res %d, dei %d, pcp %d)", i_tag, sid, - ires, iuca, idei, ipcp); - - return s; -} - u8 * format_ethernet_header_with_length (u8 * s, va_list * args) { @@ -177,10 +153,16 @@ format_ethernet_header_with_length (u8 * s, va_list * args) } else { - s = format (s, "\n%UPBB header : %U", format_white_space, indent, - format_ethernet_pbb, - clib_net_to_host_u16 (ph->priority_dei_id), - clib_net_to_host_u32 (ph->priority_dei_uca_res_sid)); + s = + format (s, " %s b-tag %04X", + (clib_net_to_host_u16 (ph->b_type) == + ETHERNET_TYPE_DOT1AD) ? "802.1ad" : "", + clib_net_to_host_u16 (ph->priority_dei_id)); + s = + format (s, " %s i-tag %08X", + (clib_net_to_host_u16 (ph->i_type) == + ETHERNET_TYPE_DOT1AH) ? "802.1ah" : "", + clib_net_to_host_u32 (ph->priority_dei_uca_res_sid)); } return s; diff --git a/src/vnet/interface.api b/src/vnet/interface.api index 752e79c5..afa8bb5e 100644 --- a/src/vnet/interface.api +++ b/src/vnet/interface.api @@ -83,9 +83,10 @@ define want_interface_events_reply @param interface_name - name of the interface @param link_duplex - 1 if half duplex, 2 if full duplex @param link_speed - 1 = 10M, 2 = 100M, 4 = 1G, 8 = 10G, 16 = 40G, 32 = 100G - @param link_MTU - max. transmittion unit + @param link_MTU - max. transmittion unit @param sub_if_id - A number 0-N to uniquely identify this subif on super if - @param sub_dot1ad - 0 = dot1q, 1=dot1ad + @param sub_dot1ad - 0 = dot1q, 1 = dot1ad + @param sub_dot1ah - 1 = dot1ah, 0 = otherwise @param sub_number_of_tags - Number of tags (0 - 2) @param sub_outer_vlan_id @param sub_inner_vlan_id @@ -97,6 +98,11 @@ define want_interface_events_reply @param vtr_push_dot1q @param vtr_tag1 @param vtr_tag2 + @param pbb_outer_tag - translate pbb s-tag + @param pbb_b_dmac[6] - B-tag remote mac address + @param pbb_b_smac[6] - B-tag local mac address + @param pbb_b_vlanid - B-tag vlanid + @param pbb_i_sid - I-tag service id */ define sw_interface_details { @@ -132,6 +138,8 @@ define sw_interface_details /* 0 = dot1q, 1=dot1ad */ u8 sub_dot1ad; + /* 1 = dot1h, 1=otherwise */ + u8 sub_dot1ah; /* Number of tags 0-2 */ u8 sub_number_of_tags; @@ -148,6 +156,13 @@ define sw_interface_details u32 vtr_tag1; // first pushed tag u32 vtr_tag2; // second pushed tag u8 tag[64]; + + /* pbb tag rewrite info */ + u16 outer_tag; + u8 b_dmac[6]; + u8 b_smac[6]; + u16 b_vlanid; + u32 i_sid; }; /* works */ diff --git a/src/vnet/interface_api.c b/src/vnet/interface_api.c index 42fd14ee..63f7cad4 100644 --- a/src/vnet/interface_api.c +++ b/src/vnet/interface_api.c @@ -203,6 +203,26 @@ send_sw_interface_details (vpe_api_main_t * am, } } + /* pbb tag rewrite data */ + u32 vtr_op = L2_VTR_DISABLED; + u16 outer_tag = 0; + u8 b_dmac[6]; + u8 b_smac[6]; + u16 b_vlanid = 0; + u32 i_sid = 0; + memset (b_dmac, 0, sizeof (b_dmac)); + memset (b_smac, 0, sizeof (b_smac)); + + if (!l2pbb_get (am->vlib_main, am->vnet_main, swif->sw_if_index, + &vtr_op, &outer_tag, b_dmac, b_smac, &b_vlanid, &i_sid)) + { + mp->sub_dot1ah = 1; + clib_memcpy (mp->b_dmac, b_dmac, sizeof (b_dmac)); + clib_memcpy (mp->b_smac, b_smac, sizeof (b_smac)); + mp->b_vlanid = b_vlanid; + mp->i_sid = i_sid; + } + tag = vnet_get_sw_interface_tag (vnm, swif->sw_if_index); if (tag) strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1); diff --git a/src/vnet/l2/l2_output.c b/src/vnet/l2/l2_output.c index acfe3aba..00f22571 100644 --- a/src/vnet/l2/l2_output.c +++ b/src/vnet/l2/l2_output.c @@ -48,6 +48,7 @@ typedef struct u8 src[6]; u8 dst[6]; u32 sw_if_index; + u8 raw[12]; /* raw data */ } l2output_trace_t; /* packet trace format function */ @@ -58,10 +59,15 @@ format_l2output_trace (u8 * s, va_list * args) CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); l2output_trace_t *t = va_arg (*args, l2output_trace_t *); - s = format (s, "l2-output: sw_if_index %d dst %U src %U", + s = format (s, "l2-output: sw_if_index %d dst %U src %U data " + "%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x", t->sw_if_index, format_ethernet_address, t->dst, - format_ethernet_address, t->src); + format_ethernet_address, t->src, + t->raw[0], t->raw[1], t->raw[2], t->raw[3], t->raw[4], + t->raw[5], t->raw[6], t->raw[7], t->raw[8], t->raw[9], + t->raw[10], t->raw[11]); + return s; } @@ -214,46 +220,6 @@ l2output_node_inline (vlib_main_t * vm, vlib_node_runtime_t * node, sw_if_index2 = vnet_buffer (b2)->sw_if_index[VLIB_TX]; sw_if_index3 = vnet_buffer (b3)->sw_if_index[VLIB_TX]; - if (do_trace) - { - h0 = vlib_buffer_get_current (b0); - h1 = vlib_buffer_get_current (b1); - h2 = vlib_buffer_get_current (b2); - h3 = vlib_buffer_get_current (b3); - if (b0->flags & VLIB_BUFFER_IS_TRACED) - { - l2output_trace_t *t = - vlib_add_trace (vm, node, b0, sizeof (*t)); - t->sw_if_index = sw_if_index0; - clib_memcpy (t->src, h0->src_address, 6); - clib_memcpy (t->dst, h0->dst_address, 6); - } - if (b1->flags & VLIB_BUFFER_IS_TRACED) - { - l2output_trace_t *t = - vlib_add_trace (vm, node, b1, sizeof (*t)); - t->sw_if_index = sw_if_index1; - clib_memcpy (t->src, h1->src_address, 6); - clib_memcpy (t->dst, h1->dst_address, 6); - } - if (b2->flags & VLIB_BUFFER_IS_TRACED) - { - l2output_trace_t *t = - vlib_add_trace (vm, node, b2, sizeof (*t)); - t->sw_if_index = sw_if_index2; - clib_memcpy (t->src, h2->src_address, 6); - clib_memcpy (t->dst, h2->dst_address, 6); - } - if (b3->flags & VLIB_BUFFER_IS_TRACED) - { - l2output_trace_t *t = - vlib_add_trace (vm, node, b3, sizeof (*t)); - t->sw_if_index = sw_if_index3; - clib_memcpy (t->src, h3->src_address, 6); - clib_memcpy (t->dst, h3->dst_address, 6); - } - } - vlib_node_increment_counter (vm, l2output_node.index, L2OUTPUT_ERROR_L2OUTPUT, 4); @@ -314,6 +280,50 @@ l2output_node_inline (vlib_main_t * vm, vlib_node_runtime_t * node, l2output_vtr (node, config2, feature_bitmap2, b2, &next2); l2output_vtr (node, config3, feature_bitmap3, b3, &next3); + if (do_trace) + { + h0 = vlib_buffer_get_current (b0); + h1 = vlib_buffer_get_current (b1); + h2 = vlib_buffer_get_current (b2); + h3 = vlib_buffer_get_current (b3); + if (b0->flags & VLIB_BUFFER_IS_TRACED) + { + l2output_trace_t *t = + vlib_add_trace (vm, node, b0, sizeof (*t)); + t->sw_if_index = sw_if_index0; + clib_memcpy (t->src, h0->src_address, 6); + clib_memcpy (t->dst, h0->dst_address, 6); + clib_memcpy (t->raw, &h0->type, sizeof (t->raw)); + } + if (b1->flags & VLIB_BUFFER_IS_TRACED) + { + l2output_trace_t *t = + vlib_add_trace (vm, node, b1, sizeof (*t)); + t->sw_if_index = sw_if_index1; + clib_memcpy (t->src, h1->src_address, 6); + clib_memcpy (t->dst, h1->dst_address, 6); + clib_memcpy (t->raw, &h1->type, sizeof (t->raw)); + } + if (b2->flags & VLIB_BUFFER_IS_TRACED) + { + l2output_trace_t *t = + vlib_add_trace (vm, node, b2, sizeof (*t)); + t->sw_if_index = sw_if_index2; + clib_memcpy (t->src, h2->src_address, 6); + clib_memcpy (t->dst, h2->dst_address, 6); + clib_memcpy (t->raw, &h2->type, sizeof (t->raw)); + } + if (b3->flags & VLIB_BUFFER_IS_TRACED) + { + l2output_trace_t *t = + vlib_add_trace (vm, node, b3, sizeof (*t)); + t->sw_if_index = sw_if_index3; + clib_memcpy (t->src, h3->src_address, 6); + clib_memcpy (t->dst, h3->dst_address, 6); + clib_memcpy (t->raw, &h3->type, sizeof (t->raw)); + } + } + /* * Perform the split horizon check * The check can only fail for non-zero shg's @@ -378,16 +388,6 @@ l2output_node_inline (vlib_main_t * vm, vlib_node_runtime_t * node, sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_TX]; - if (do_trace && PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED)) - { - l2output_trace_t *t = - vlib_add_trace (vm, node, b0, sizeof (*t)); - t->sw_if_index = sw_if_index0; - h0 = vlib_buffer_get_current (b0); - clib_memcpy (t->src, h0->src_address, 6); - clib_memcpy (t->dst, h0->dst_address, 6); - } - vlib_node_increment_counter (vm, l2output_node.index, L2OUTPUT_ERROR_L2OUTPUT, 1); @@ -412,6 +412,17 @@ l2output_node_inline (vlib_main_t * vm, vlib_node_runtime_t * node, l2output_vtr (node, config0, feature_bitmap0, b0, &next0); + if (do_trace && PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED)) + { + l2output_trace_t *t = + vlib_add_trace (vm, node, b0, sizeof (*t)); + t->sw_if_index = sw_if_index0; + h0 = vlib_buffer_get_current (b0); + clib_memcpy (t->src, h0->src_address, 6); + clib_memcpy (t->dst, h0->dst_address, 6); + clib_memcpy (t->raw, &h0->type, sizeof (t->raw)); + } + /* Perform the split horizon check */ if (PREDICT_FALSE (split_horizon_violation diff --git a/src/vnet/l2/l2_vtr.c b/src/vnet/l2/l2_vtr.c index 95a4f157..e03a4880 100644 --- a/src/vnet/l2/l2_vtr.c +++ b/src/vnet/l2/l2_vtr.c @@ -681,6 +681,72 @@ VLIB_CLI_COMMAND (int_l2_vtr_cli, static) = { }; /* *INDENT-ON* */ +/** + * Get pbb tag rewrite on the given interface. + * Return 1 if there is an error, 0 if ok + */ +u32 +l2pbb_get (vlib_main_t * vlib_main, vnet_main_t * vnet_main, u32 sw_if_index, + u32 * vtr_op, u16 * outer_tag, u8 * b_dmac, u8 * b_smac, + u16 * b_vlanid, u32 * i_sid) +{ + u32 error = 1; + ptr_config_t *in_config; + + if (!vtr_op || !outer_tag || !b_vlanid || !i_sid) + { + clib_warning ("invalid arguments"); + error = VNET_API_ERROR_INVALID_ARGUMENT; + goto done; + } + + *vtr_op = L2_VTR_DISABLED; + *outer_tag = 0; + *b_dmac = 0; + *b_smac = 0; + *b_vlanid = 0; + *i_sid = 0; + + if (sw_if_index >= vec_len (l2output_main.configs)) + { + /* no specific config (return disabled) */ + goto done; + } + + /* Get the config for this interface */ + in_config = + &(vec_elt_at_index (l2output_main.configs, sw_if_index)->input_pbb_vtr); + + if (in_config->push_and_pop_bytes == 0) + { + /* DISABLED */ + goto done; + } + else + { + if (in_config->pop_bytes && in_config->push_bytes) + *vtr_op = L2_VTR_TRANSLATE_2_1; + else if (in_config->pop_bytes) + *vtr_op = L2_VTR_POP_2; + else if (in_config->push_bytes) + *vtr_op = L2_VTR_PUSH_2; + + clib_memcpy (b_dmac, in_config->macs_tags.b_dst_address, + sizeof (b_dmac)); + clib_memcpy (b_smac, in_config->macs_tags.b_src_address, + sizeof (b_smac)); + + *b_vlanid = + clib_host_to_net_u16 (in_config->macs_tags.priority_dei_id) & 0xFFF; + *i_sid = + clib_host_to_net_u32 (in_config-> + macs_tags.priority_dei_uca_res_sid) & 0xFFFFF; + error = 0; + } +done: + return error; +} + /** * Set subinterface pbb vtr enable/disable. * The CLI format is: diff --git a/src/vnet/l2/l2_vtr.h b/src/vnet/l2/l2_vtr.h index 893b2272..99aedc97 100644 --- a/src/vnet/l2/l2_vtr.h +++ b/src/vnet/l2/l2_vtr.h @@ -258,6 +258,17 @@ u32 l2vtr_get (vlib_main_t * vlib_main, u32 * vtr_op, u32 * push_dot1q, u32 * vtr_tag1, u32 * vtr_tag2); +/** + * Get pbb tag rewrite on the given interface. + * Return 1 if there is an error, 0 if ok + */ +u32 l2pbb_get (vlib_main_t * vlib_main, + vnet_main_t * vnet_main, + u32 sw_if_index, + u32 * vtr_op, + u16 * outer_tag, + u8 * b_dmac, u8 * b_smac, u16 * b_vlanid, u32 * i_sid); + #endif /* included_vnet_l2_vtr_h */ -- cgit 1.2.3-korg From f7f2a9feaa2cad8313afba53b53c32f1928f664c Mon Sep 17 00:00:00 2001 From: Gabriel Ganne Date: Mon, 6 Mar 2017 15:19:40 +0100 Subject: fix gcc 5.4 warning: argument to 'sizeof' in 'memcpy' call is the same expression as the destination warning translates as an invalid write : sizeof(u8* b_dmac) == 8 != sizeof(eth_hdr->dst_address) == 6 ~/vpp/build-data/../src/vnet/l2/l2_vtr.c: In function 'l2pbb_get': ~/vpp/build-data/../src/vnet/l2/l2_vtr.c:734:63: error: argument to 'sizeof' in 'memcpy' call is the same expression as the destination; did you mean to provide an explicit length? [-Werror=sizeof-pointer-memaccess] ~/vpp/build-data/../src/vnet/l2/l2_vtr.c:736:63: error: argument to 'sizeof' in 'memcpy' call is the same expression as the destination; did you mean to provide an explicit length? [-Werror=sizeof-pointer-memaccess] update l2pbb_get to take an ethernet header instead of two u8* pointers for source and dest mac addresses. Change-Id: Ifcf1319a9e22614d57682f940e10f0420dc6fb8c Signed-off-by: Gabriel Ganne --- src/vnet/interface_api.c | 14 +++++++------- src/vnet/l2/l2_vtr.c | 16 +++++++--------- src/vnet/l2/l2_vtr.h | 2 +- 3 files changed, 15 insertions(+), 17 deletions(-) (limited to 'src/vnet/l2/l2_vtr.c') diff --git a/src/vnet/interface_api.c b/src/vnet/interface_api.c index bfd2af31..2b6ff0c5 100644 --- a/src/vnet/interface_api.c +++ b/src/vnet/interface_api.c @@ -205,21 +205,21 @@ send_sw_interface_details (vpe_api_main_t * am, } /* pbb tag rewrite data */ + ethernet_header_t eth_hdr; u32 vtr_op = L2_VTR_DISABLED; u16 outer_tag = 0; - u8 b_dmac[6]; - u8 b_smac[6]; u16 b_vlanid = 0; u32 i_sid = 0; - memset (b_dmac, 0, sizeof (b_dmac)); - memset (b_smac, 0, sizeof (b_smac)); + memset (ð_hdr, 0, sizeof (eth_hdr)); if (!l2pbb_get (am->vlib_main, am->vnet_main, swif->sw_if_index, - &vtr_op, &outer_tag, b_dmac, b_smac, &b_vlanid, &i_sid)) + &vtr_op, &outer_tag, ð_hdr, &b_vlanid, &i_sid)) { mp->sub_dot1ah = 1; - clib_memcpy (mp->b_dmac, b_dmac, sizeof (b_dmac)); - clib_memcpy (mp->b_smac, b_smac, sizeof (b_smac)); + clib_memcpy (mp->b_dmac, eth_hdr.dst_address, + sizeof (eth_hdr.dst_address)); + clib_memcpy (mp->b_smac, eth_hdr.src_address, + sizeof (eth_hdr.src_address)); mp->b_vlanid = b_vlanid; mp->i_sid = i_sid; } diff --git a/src/vnet/l2/l2_vtr.c b/src/vnet/l2/l2_vtr.c index e03a4880..3c5365f9 100644 --- a/src/vnet/l2/l2_vtr.c +++ b/src/vnet/l2/l2_vtr.c @@ -687,7 +687,7 @@ VLIB_CLI_COMMAND (int_l2_vtr_cli, static) = { */ u32 l2pbb_get (vlib_main_t * vlib_main, vnet_main_t * vnet_main, u32 sw_if_index, - u32 * vtr_op, u16 * outer_tag, u8 * b_dmac, u8 * b_smac, + u32 * vtr_op, u16 * outer_tag, ethernet_header_t * eth_hdr, u16 * b_vlanid, u32 * i_sid) { u32 error = 1; @@ -702,8 +702,6 @@ l2pbb_get (vlib_main_t * vlib_main, vnet_main_t * vnet_main, u32 sw_if_index, *vtr_op = L2_VTR_DISABLED; *outer_tag = 0; - *b_dmac = 0; - *b_smac = 0; *b_vlanid = 0; *i_sid = 0; @@ -731,16 +729,16 @@ l2pbb_get (vlib_main_t * vlib_main, vnet_main_t * vnet_main, u32 sw_if_index, else if (in_config->push_bytes) *vtr_op = L2_VTR_PUSH_2; - clib_memcpy (b_dmac, in_config->macs_tags.b_dst_address, - sizeof (b_dmac)); - clib_memcpy (b_smac, in_config->macs_tags.b_src_address, - sizeof (b_smac)); + clib_memcpy (ð_hdr->dst_address, in_config->macs_tags.b_dst_address, + sizeof (eth_hdr->dst_address)); + clib_memcpy (ð_hdr->src_address, in_config->macs_tags.b_src_address, + sizeof (eth_hdr->src_address)); *b_vlanid = clib_host_to_net_u16 (in_config->macs_tags.priority_dei_id) & 0xFFF; *i_sid = - clib_host_to_net_u32 (in_config-> - macs_tags.priority_dei_uca_res_sid) & 0xFFFFF; + clib_host_to_net_u32 (in_config->macs_tags. + priority_dei_uca_res_sid) & 0xFFFFF; error = 0; } done: diff --git a/src/vnet/l2/l2_vtr.h b/src/vnet/l2/l2_vtr.h index 99aedc97..0aea618e 100644 --- a/src/vnet/l2/l2_vtr.h +++ b/src/vnet/l2/l2_vtr.h @@ -267,7 +267,7 @@ u32 l2pbb_get (vlib_main_t * vlib_main, u32 sw_if_index, u32 * vtr_op, u16 * outer_tag, - u8 * b_dmac, u8 * b_smac, u16 * b_vlanid, u32 * i_sid); + ethernet_header_t * eth_hdr, u16 * b_vlanid, u32 * i_sid); #endif /* included_vnet_l2_vtr_h */ -- cgit 1.2.3-korg From 6f7ebf900e6c65b73f8bb8f60ab5190cc2c893bc Mon Sep 17 00:00:00 2001 From: Eyal Bari Date: Tue, 13 Jun 2017 12:09:37 +0300 Subject: ETH:fix l2_len/vlan count mismatch for > 2 tags l2_len was not updated for the third tag as the ethernet node retracts by the vlan count after parse_header (using ethernet_buffer_header_size) it ends up pointing before the ethernet header + some minor cleanups Change-Id: I4ccaedd33928912e5d837376f146503b27071741 Signed-off-by: Eyal Bari --- src/vnet/ethernet/node.c | 5 ++++- src/vnet/l2/l2_input_vtr.c | 15 +++------------ src/vnet/l2/l2_vtr.c | 3 --- 3 files changed, 7 insertions(+), 16 deletions(-) (limited to 'src/vnet/l2/l2_vtr.c') diff --git a/src/vnet/ethernet/node.c b/src/vnet/ethernet/node.c index 8967cebe..4529ca6a 100755 --- a/src/vnet/ethernet/node.c +++ b/src/vnet/ethernet/node.c @@ -165,11 +165,12 @@ parse_header (ethernet_input_variant_t variant, vlib_buffer_advance (b0, sizeof (h0[0])); vlan_count = 2; - if (*type == ETHERNET_TYPE_VLAN) { // More than double tagged packet *match_flags = SUBINT_CONFIG_VALID | SUBINT_CONFIG_MATCH_3_TAG; + + vlib_buffer_advance (b0, sizeof (h0[0])); vlan_count = 3; // "unknown" number, aka, 3-or-more } } @@ -239,6 +240,8 @@ determine_next_node (ethernet_main_t * em, // record the L2 len and reset the buffer so the L2 header is preserved u32 eth_start = vnet_buffer (b0)->ethernet.start_of_ethernet_header; vnet_buffer (b0)->l2.l2_len = b0->current_data - eth_start; + ASSERT (vnet_buffer (b0)->l2.l2_len == + ethernet_buffer_header_size (b0)); vlib_buffer_advance (b0, -ethernet_buffer_header_size (b0)); // check for common IP/MPLS ethertypes diff --git a/src/vnet/l2/l2_input_vtr.c b/src/vnet/l2/l2_input_vtr.c index 60a39631..ded23095 100644 --- a/src/vnet/l2/l2_input_vtr.c +++ b/src/vnet/l2/l2_input_vtr.c @@ -188,10 +188,7 @@ l2_invtr_node_fn (vlib_main_t * vm, if (config0->output_vtr.push_and_pop_bytes) { /* perform the tag rewrite on two packets */ - if (l2_vtr_process - (b0, - &(vec_elt_at_index - (l2output_main.configs, sw_if_index0)->input_vtr))) + if (l2_vtr_process (b0, &config0->input_vtr)) { /* Drop packet */ next0 = L2_INVTR_NEXT_DROP; @@ -212,10 +209,7 @@ l2_invtr_node_fn (vlib_main_t * vm, { if (config1->output_vtr.push_and_pop_bytes) { - if (l2_vtr_process - (b1, - &(vec_elt_at_index - (l2output_main.configs, sw_if_index1)->input_vtr))) + if (l2_vtr_process (b1, &config1->input_vtr)) { /* Drop packet */ next1 = L2_INVTR_NEXT_DROP; @@ -305,10 +299,7 @@ l2_invtr_node_fn (vlib_main_t * vm, if (config0->output_vtr.push_and_pop_bytes) { /* perform the tag rewrite on one packet */ - if (l2_vtr_process - (b0, - &(vec_elt_at_index - (l2output_main.configs, sw_if_index0)->input_vtr))) + if (l2_vtr_process (b0, &config0->input_vtr)) { /* Drop packet */ next0 = L2_INVTR_NEXT_DROP; diff --git a/src/vnet/l2/l2_vtr.c b/src/vnet/l2/l2_vtr.c index 3c5365f9..02a68991 100644 --- a/src/vnet/l2/l2_vtr.c +++ b/src/vnet/l2/l2_vtr.c @@ -229,9 +229,6 @@ l2vtr_configure (vlib_main_t * vlib_main, vnet_main_t * vnet_main, u32 sw_if_ind } in_config->pop_bytes = 8; in_config->push_bytes = 0; - - out_config->push_bytes = in_config->pop_bytes; - out_config->pop_bytes = in_config->push_bytes; break; case L2_VTR_PUSH_1: -- cgit 1.2.3-korg