#include <vnet/devices/pipe/pipe.h>
#include <vppinfra/sparse_vec.h>
#include <vnet/l2/l2_bvi.h>
-#include <vnet/classify/trace_classify.h>
+#include <vnet/classify/pcap_classify.h>
#define foreach_ethernet_input_next \
_ (PUNT, "error-punt") \
{
ethernet_header_t *e0;
- e0 = (void *) (b0->data + b0->current_data);
+ e0 = vlib_buffer_get_current (b0);
vnet_buffer (b0)->l2_hdr_offset = b0->current_data;
b0->flags |= VNET_BUFFER_F_L2_HDR_OFFSET_VALID;
// here when prior node was LLC/SNAP processing
u16 *e0;
- e0 = (void *) (b0->data + b0->current_data);
+ e0 = vlib_buffer_get_current (b0);
vlib_buffer_advance (b0, sizeof (e0[0]));
*match_flags = SUBINT_CONFIG_VALID | SUBINT_CONFIG_MATCH_1_TAG;
- h0 = (void *) (b0->data + b0->current_data);
+ h0 = vlib_buffer_get_current (b0);
tag = clib_net_to_host_u16 (h0->priority_cfi_and_id);
// Double tagged packet
*match_flags = SUBINT_CONFIG_VALID | SUBINT_CONFIG_MATCH_2_TAG;
- h0 = (void *) (b0->data + b0->current_data);
+ h0 = vlib_buffer_get_current (b0);
tag = clib_net_to_host_u16 (h0->priority_cfi_and_id);
// vlan table lookups and vlan header parsing. Check the most specific
// matches first.
static_always_inline void
-identify_subint (vnet_hw_interface_t * hi,
+identify_subint (ethernet_main_t * em,
+ vnet_hw_interface_t * hi,
vlib_buffer_t * b0,
u32 match_flags,
main_intf_t * main_intf,
u32 * new_sw_if_index, u8 * error0, u32 * is_l2)
{
u32 matched;
+ ethernet_interface_t *ei = ethernet_get_interface (em, hi->hw_if_index);
matched = eth_identify_subint (hi, match_flags, main_intf, vlan_intf,
qinq_intf, new_sw_if_index, error0, is_l2);
if (matched)
{
// Perform L3 my-mac filter
- // A unicast packet arriving on an L3 interface must have a dmac matching the interface mac.
- // This is required for promiscuous mode, else we will forward packets we aren't supposed to.
- if (!(*is_l2))
+ // A unicast packet arriving on an L3 interface must have a dmac
+ // matching the interface mac. If interface has STATUS_L3 bit set
+ // mac filter is already done.
+ if ((!*is_l2) && ei &&
+ (!(ei->flags & ETHERNET_INTERFACE_FLAG_STATUS_L3)))
{
u64 dmacs[2];
u8 dmacs_bad[2];
ethernet_header_t *e0;
- ethernet_interface_t *ei0;
e0 = (void *) (b0->data + vnet_buffer (b0)->l2_hdr_offset);
dmacs[0] = *(u64 *) e0;
- ei0 = ethernet_get_interface (ðernet_main, hi->hw_if_index);
- if (ei0 && vec_len (ei0->secondary_addrs))
+ if (vec_len (ei->secondary_addrs))
ethernet_input_inline_dmac_check (hi, dmacs, dmacs_bad,
- 1 /* n_packets */ , ei0,
- 1 /* have_sec_dmac */ );
+ 1 /* n_packets */, ei,
+ 1 /* have_sec_dmac */);
else
ethernet_input_inline_dmac_check (hi, dmacs, dmacs_bad,
- 1 /* n_packets */ , ei0,
- 0 /* have_sec_dmac */ );
-
+ 1 /* n_packets */, ei,
+ 0 /* have_sec_dmac */);
if (dmacs_bad[0])
*error0 = ETHERNET_ERROR_L3_MAC_MISMATCH;
}
u32 n_packets, ethernet_interface_t * ei,
u8 have_sec_dmac)
{
- u64 hwaddr = (*(u64 *) hi->hw_address) & DMAC_MASK;
+ u64 hwaddr = ei->address.as_u64;
u8 bad = 0;
+ ASSERT (0 == ei->address.zero);
+
dmacs_bad[0] = is_dmac_bad (dmacs[0], hwaddr);
dmacs_bad[1] = ((n_packets > 1) & is_dmac_bad (dmacs[1], hwaddr));
if (PREDICT_FALSE (bad && have_sec_dmac))
{
- mac_address_t *sec_addr;
+ ethernet_interface_address_t *sec_addr;
vec_foreach (sec_addr, ei->secondary_addrs)
{
- hwaddr = (*(u64 *) sec_addr) & DMAC_MASK;
+ ASSERT (0 == sec_addr->zero);
+ hwaddr = sec_addr->as_u64;
bad = (eth_input_sec_dmac_check_x1 (hwaddr, dmacs, dmacs_bad) |
eth_input_sec_dmac_check_x1 (hwaddr, dmacs + 1,
u32 n_packets, ethernet_interface_t * ei,
u8 have_sec_dmac)
{
- u64 hwaddr = (*(u64 *) hi->hw_address) & DMAC_MASK;
+ u64 hwaddr = ei->address.as_u64;
u64 *dmac = dmacs;
u8 *dmac_bad = dmacs_bad;
u32 bad = 0;
i32 n_left = n_packets;
+ ASSERT (0 == ei->address.zero);
+
#ifdef CLIB_HAVE_VEC256
while (n_left > 0)
{
if (have_sec_dmac && bad)
{
- mac_address_t *addr;
+ ethernet_interface_address_t *addr;
vec_foreach (addr, ei->secondary_addrs)
{
- u64 hwaddr = ((u64 *) addr)[0] & DMAC_MASK;
+ u64 hwaddr = addr->as_u64;
i32 n_left = n_packets;
u64 *dmac = dmacs;
u8 *dmac_bad = dmacs_bad;
+ ASSERT (0 == addr->zero);
+
bad = 0;
while (n_left > 0)
u16 et_vlan = clib_host_to_net_u16 (ETHERNET_TYPE_VLAN);
u16 et_dot1ad = clib_host_to_net_u16 (ETHERNET_TYPE_DOT1AD);
i32 n_left = n_packets;
- vlib_buffer_t *b[20];
- u32 *from;
+ vlib_buffer_t *bufs[VLIB_FRAME_SIZE];
+ vlib_buffer_t **b = bufs;
ethernet_interface_t *ei = ethernet_get_interface (em, hi->hw_if_index);
- from = buffer_indices;
+ vlib_get_buffers (vm, buffer_indices, b, n_left);
while (n_left >= 20)
{
vlib_buffer_t **ph = b + 16, **pd = b + 8;
- vlib_get_buffers (vm, from, b, 4);
- vlib_get_buffers (vm, from + 8, pd, 4);
- vlib_get_buffers (vm, from + 16, ph, 4);
vlib_prefetch_buffer_header (ph[0], LOAD);
vlib_prefetch_buffer_data (pd[0], LOAD);
eth_input_adv_and_flags_x4 (b, main_is_l3);
/* next */
+ b += 4;
n_left -= 4;
etype += 4;
tag += 4;
dmac += 4;
- from += 4;
}
while (n_left >= 4)
{
- vlib_get_buffers (vm, from, b, 4);
eth_input_get_etype_and_tags (b, etype, tag, dmac, 0, dmac_check);
eth_input_get_etype_and_tags (b, etype, tag, dmac, 1, dmac_check);
eth_input_get_etype_and_tags (b, etype, tag, dmac, 2, dmac_check);
eth_input_adv_and_flags_x4 (b, main_is_l3);
/* next */
+ b += 4;
n_left -= 4;
etype += 4;
tag += 4;
dmac += 4;
- from += 4;
}
while (n_left)
{
- vlib_get_buffers (vm, from, b, 1);
eth_input_get_etype_and_tags (b, etype, tag, dmac, 0, dmac_check);
eth_input_adv_and_flags_x1 (b, main_is_l3);
/* next */
+ b += 1;
n_left -= 1;
etype += 1;
tag += 1;
- dmac += 4;
- from += 1;
+ dmac += 1;
}
if (dmac_check)
else
{
for (int j = 0; j < 16; j++)
- if (next[j] == 0)
- slowpath_indices[n_slowpath++] = i + j;
+ {
+ if (next[j] == 0)
+ slowpath_indices[n_slowpath++] = i + j;
+ else if (dmac_check && main_is_l3 && dmacs_bad[i + j])
+ {
+ next[j] = 0;
+ slowpath_indices[n_slowpath++] = i + j;
+ }
+ }
+ }
+ }
+ else
+ {
+ if (dmac_check && main_is_l3)
+ {
+ u8x16 dmac_bad = u8x16_load_unaligned (&dmacs_bad[i]);
+ if (!u8x16_is_all_zero (dmac_bad))
+ {
+ for (int j = 0; j < 16; j++)
+ if (dmacs_bad[i + j])
+ {
+ next[j] = 0;
+ slowpath_indices[n_slowpath++] = i + j;
+ }
+ }
}
}
continue;
}
#endif
- if (main_is_l3 && etype[0] == et_ip4)
+ if (dmac_check && main_is_l3 && dmacs_bad[i])
+ {
+ next[0] = 0;
+ slowpath_indices[n_slowpath++] = i;
+ }
+ else if (main_is_l3 && etype[0] == et_ip4)
next[0] = next_ip4;
else if (main_is_l3 && etype[0] == et_ip6)
next[0] = next_ip6;
}
else
{
- /* untagged packet with not well known etyertype */
+ /* untagged packet with not well known ethertype */
if (last_unknown_etype != etype)
{
last_unknown_etype = etype;
subint_config_t *subint0 = &intf0->untagged_subint;
int main_is_l3 = (subint0->flags & SUBINT_CONFIG_L2) == 0;
- int promisc = (ei->flags & ETHERNET_INTERFACE_FLAG_ACCEPT_ALL) != 0;
+ int int_is_l3 = ei->flags & ETHERNET_INTERFACE_FLAG_STATUS_L3;
if (main_is_l3)
{
- /* main interface is L3, we dont expect tagged packets and interface
- is not in promisc node, so we dont't need to check DMAC */
- int is_l3 = 1;
-
- if (promisc == 0)
- eth_input_process_frame (vm, node, hi, from, n_pkts, is_l3,
- ip4_cksum_ok, 0);
+ if (int_is_l3 || /* DMAC filter already done by NIC */
+ ((hi->l2_if_count != 0) && (hi->l3_if_count == 0)))
+ { /* All L2 usage - DMAC check not needed */
+ eth_input_process_frame (vm, node, hi, from, n_pkts,
+ /*is_l3 */ 1, ip4_cksum_ok, 0);
+ }
else
- /* subinterfaces and promisc mode so DMAC check is needed */
- eth_input_process_frame (vm, node, hi, from, n_pkts, is_l3,
- ip4_cksum_ok, 1);
+ { /* DMAC check needed for L3 */
+ eth_input_process_frame (vm, node, hi, from, n_pkts,
+ /*is_l3 */ 1, ip4_cksum_ok, 1);
+ }
return;
}
else
{
- /* untagged packets are treated as L2 */
- int is_l3 = 0;
- eth_input_process_frame (vm, node, hi, from, n_pkts, is_l3,
- ip4_cksum_ok, 1);
+ if (hi->l3_if_count == 0)
+ { /* All L2 usage - DMAC check not needed */
+ eth_input_process_frame (vm, node, hi, from, n_pkts,
+ /*is_l3 */ 0, ip4_cksum_ok, 0);
+ }
+ else
+ { /* DMAC check needed for L3 */
+ eth_input_process_frame (vm, node, hi, from, n_pkts,
+ /*is_l3 */ 0, ip4_cksum_ok, 1);
+ }
return;
}
}
ethernet_input_trace (vlib_main_t * vm, vlib_node_runtime_t * node,
vlib_frame_t * from_frame)
{
+ vnet_main_t *vnm = vnet_get_main ();
u32 *from, n_left;
if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)))
{
}
/* rx pcap capture if enabled */
- if (PREDICT_FALSE (vlib_global_main.pcap.pcap_rx_enable))
+ if (PREDICT_FALSE (vnm->pcap.pcap_rx_enable))
{
u32 bi0;
- vnet_pcap_t *pp = &vlib_global_main.pcap;
+ vnet_pcap_t *pp = &vnm->pcap;
from = vlib_frame_vector_args (from_frame);
n_left = from_frame->n_vectors;
while (n_left > 0)
{
- int classify_filter_result;
vlib_buffer_t *b0;
bi0 = from[0];
from++;
n_left--;
b0 = vlib_get_buffer (vm, bi0);
- if (pp->filter_classify_table_index != ~0)
- {
- classify_filter_result =
- vnet_is_packet_traced_inline
- (b0, pp->filter_classify_table_index, 0 /* full classify */ );
- if (classify_filter_result)
- pcap_add_buffer (&pp->pcap_main, vm, bi0,
- pp->max_bytes_per_pkt);
- continue;
- }
-
- if (pp->pcap_sw_if_index == 0 ||
- pp->pcap_sw_if_index == vnet_buffer (b0)->sw_if_index[VLIB_RX])
- {
- vnet_main_t *vnm = vnet_get_main ();
- vnet_hw_interface_t *hi =
- vnet_get_sup_hw_interface
- (vnm, vnet_buffer (b0)->sw_if_index[VLIB_RX]);
-
- /* Capture pkt if not filtered, or if filter hits */
- if (hi->trace_classify_table_index == ~0 ||
- vnet_is_packet_traced_inline
- (b0, hi->trace_classify_table_index,
- 0 /* full classify */ ))
- pcap_add_buffer (&pp->pcap_main, vm, bi0,
- pp->max_bytes_per_pkt);
- }
+ if (vnet_is_packet_pcaped (pp, b0, ~0))
+ pcap_add_buffer (&pp->pcap_main, vm, bi0, pp->max_bytes_per_pkt);
}
}
}
}
else
{
+ if (ei && (ei->flags & ETHERNET_INTERFACE_FLAG_STATUS_L3))
+ goto skip_dmac_check01;
+
dmacs[0] = *(u64 *) e0;
dmacs[1] = *(u64 *) e1;
if (dmacs_bad[1])
error1 = ETHERNET_ERROR_L3_MAC_MISMATCH;
+ skip_dmac_check01:
vlib_buffer_advance (b0, sizeof (ethernet_header_t));
determine_next_node (em, variant, 0, type0, b0,
&error0, &next0);
&hi1,
&main_intf1, &vlan_intf1, &qinq_intf1);
- identify_subint (hi0,
+ identify_subint (em,
+ hi0,
b0,
match_flags0,
main_intf0,
vlan_intf0,
qinq_intf0, &new_sw_if_index0, &error0, &is_l20);
- identify_subint (hi1,
+ identify_subint (em,
+ hi1,
b1,
match_flags1,
main_intf1,
if (n_left_from > 1)
{
vlib_prefetch_buffer_header (b[1], STORE);
- CLIB_PREFETCH (b[1]->data, CLIB_CACHE_LINE_BYTES, LOAD);
+ clib_prefetch_load (b[1]->data);
}
bi0 = from[0];
}
else
{
- dmacs[0] = *(u64 *) e0;
+ if (ei && ei->flags & ETHERNET_INTERFACE_FLAG_STATUS_L3)
+ goto skip_dmac_check0;
- if (ei && vec_len (ei->secondary_addrs))
- ethernet_input_inline_dmac_check (hi, dmacs,
- dmacs_bad,
- 1 /* n_packets */ ,
- ei,
- 1 /* have_sec_dmac */ );
- else
- ethernet_input_inline_dmac_check (hi, dmacs,
- dmacs_bad,
- 1 /* n_packets */ ,
- ei,
- 0 /* have_sec_dmac */ );
+ dmacs[0] = *(u64 *) e0;
- if (dmacs_bad[0])
- error0 = ETHERNET_ERROR_L3_MAC_MISMATCH;
+ if (ei)
+ {
+ if (vec_len (ei->secondary_addrs))
+ ethernet_input_inline_dmac_check (
+ hi, dmacs, dmacs_bad, 1 /* n_packets */, ei,
+ 1 /* have_sec_dmac */);
+ else
+ ethernet_input_inline_dmac_check (
+ hi, dmacs, dmacs_bad, 1 /* n_packets */, ei,
+ 0 /* have_sec_dmac */);
+
+ if (dmacs_bad[0])
+ error0 = ETHERNET_ERROR_L3_MAC_MISMATCH;
+ }
+ skip_dmac_check0:
vlib_buffer_advance (b0, sizeof (ethernet_header_t));
determine_next_node (em, variant, 0, type0, b0,
&error0, &next0);
&hi0,
&main_intf0, &vlan_intf0, &qinq_intf0);
- identify_subint (hi0,
+ identify_subint (em,
+ hi0,
b0,
match_flags0,
main_intf0,
}
else
{
- // a specific outer + specifc innner vlan id, a common case
+ // a specific outer + specific innner vlan id, a common case
// get the qinq table
if (vlan_table->vlans[si->sub.eth.outer_vlan_id].qinqs == 0)
ethernet_sw_interface_up_down (vnet_main_t * vnm, u32 sw_if_index, u32 flags)
{
subint_config_t *subint;
- u32 dummy_flags;
- u32 dummy_unsup;
+ u32 placeholder_flags;
+ u32 placeholder_unsup;
clib_error_t *error = 0;
// Find the config for this subinterface
subint =
- ethernet_sw_interface_get_config (vnm, sw_if_index, &dummy_flags,
- &dummy_unsup);
+ ethernet_sw_interface_get_config (vnm, sw_if_index, &placeholder_flags,
+ &placeholder_unsup);
if (subint == 0)
{
ethernet_sw_interface_set_l2_mode (vnet_main_t * vnm, u32 sw_if_index, u32 l2)
{
subint_config_t *subint;
- u32 dummy_flags;
- u32 dummy_unsup;
+ u32 placeholder_flags;
+ u32 placeholder_unsup;
int is_port;
vnet_sw_interface_t *sw = vnet_get_sw_interface (vnm, sw_if_index);
// Find the config for this subinterface
subint =
- ethernet_sw_interface_get_config (vnm, sw_if_index, &dummy_flags,
- &dummy_unsup);
+ ethernet_sw_interface_get_config (vnm, sw_if_index, &placeholder_flags,
+ &placeholder_unsup);
if (subint == 0)
{
u32 sw_if_index, u32 l2)
{
subint_config_t *subint;
- u32 dummy_flags;
- u32 dummy_unsup;
+ u32 placeholder_flags;
+ u32 placeholder_unsup;
/* Find the config for this subinterface */
subint =
- ethernet_sw_interface_get_config (vnm, sw_if_index, &dummy_flags,
- &dummy_unsup);
+ ethernet_sw_interface_get_config (vnm, sw_if_index, &placeholder_flags,
+ &placeholder_unsup);
if (subint == 0)
{
#undef ethernet_error
};
-/* *INDENT-OFF* */
VLIB_REGISTER_NODE (ethernet_input_node) = {
.name = "ethernet-input",
/* Takes a vector of packets. */
#undef _
},
};
-/* *INDENT-ON* */
#ifndef CLIB_MARCH_VARIANT
void
return 0;
}
+void
+ethernet_setup_node (vlib_main_t *vm, u32 node_index)
+{
+ vlib_node_t *n = vlib_get_node (vm, node_index);
+ pg_node_t *pn = pg_get_node (node_index);
+
+ n->format_buffer = format_ethernet_header_with_length;
+ n->unformat_buffer = unformat_ethernet_header;
+ pn->unformat_edit = unformat_pg_ethernet_header;
+}
+
void
ethernet_input_init (vlib_main_t * vm, ethernet_main_t * em)
{