X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvnet%2Fethernet%2Fpacket.h;h=13d7dafabfcab5e0de47a726e6b5315d6dd92399;hb=57660d9df62756c5db1516be0dbb48505f996e82;hp=09f5e7f3d0b9b4739cc2ffbcbc27a5e08412ac1b;hpb=039cbfe254be998f7311bc4638bb262b44efac19;p=vpp.git diff --git a/src/vnet/ethernet/packet.h b/src/vnet/ethernet/packet.h index 09f5e7f3d0b..13d7dafabfc 100644 --- a/src/vnet/ethernet/packet.h +++ b/src/vnet/ethernet/packet.h @@ -40,6 +40,8 @@ #ifndef included_ethernet_packet_h #define included_ethernet_packet_h +#include + typedef enum { #define ethernet_type(n,s) ETHERNET_TYPE_##s = n, @@ -67,6 +69,13 @@ ethernet_address_cast (u8 * a) return (a[0] >> 0) & 1; } +always_inline int +ethernet_address_is_broadcast (u8 * a) +{ + return clib_mem_unaligned (a, u32) == 0xffffffff && + clib_mem_unaligned (a + 4, u16) == 0xffff; +} + always_inline uword ethernet_address_is_locally_administered (u8 * a) { @@ -79,6 +88,42 @@ ethernet_address_set_locally_administered (u8 * a) a[0] |= 1 << 1; } +always_inline int +eh_dst_addr_to_rx_ctype (ethernet_header_t * eh) +{ + if (PREDICT_TRUE (ethernet_address_cast (eh->dst_address) == + ETHERNET_ADDRESS_UNICAST)) + { + return VNET_INTERFACE_COUNTER_RX_UNICAST; + } + else if (ethernet_address_is_broadcast (eh->dst_address)) + { + return VNET_INTERFACE_COUNTER_RX_BROADCAST; + } + else + { + return VNET_INTERFACE_COUNTER_RX_MULTICAST; + } +} + +always_inline int +eh_dst_addr_to_tx_ctype (ethernet_header_t * eh) +{ + if (PREDICT_TRUE (ethernet_address_cast (eh->dst_address) == + ETHERNET_ADDRESS_UNICAST)) + { + return VNET_INTERFACE_COUNTER_TX_UNICAST; + } + else if (ethernet_address_is_broadcast (eh->dst_address)) + { + return VNET_INTERFACE_COUNTER_TX_BROADCAST; + } + else + { + return VNET_INTERFACE_COUNTER_TX_MULTICAST; + } +} + /* For VLAN ethernet type. */ typedef struct { @@ -97,8 +142,16 @@ ethernet_vlan_header_set_priority_net_order (ethernet_vlan_header_t * h, { u8 *bytes = (u8 *) (&h->priority_cfi_and_id); - bytes[0] &= 0x1f; - bytes[0] |= (prio & 0x7) << 5; + bytes[0] &= 0x0f; + bytes[0] |= (prio & 0xf) << 4; +} + +always_inline u8 +ethernet_vlan_header_get_priority_net_order (ethernet_vlan_header_t * h) +{ + u8 *bytes = (u8 *) (&h->priority_cfi_and_id); + + return (bytes[0] >> 4); } /* VLAN with ethertype first and vlan id second */