40 #ifndef included_ethernet_h 41 #define included_ethernet_h 51 return (((
u64) a[0] << (
u64) (5 * 8))
52 | ((
u64) a[1] << (
u64) (4 * 8))
53 | ((
u64) a[2] << (
u64) (3 * 8))
54 | ((
u64) a[3] << (
u64) (2 * 8))
55 | ((
u64) a[4] << (
u64) (1 * 8)) | ((
u64) a[5] << (
u64) (0 * 8)));
61 return (a & (1ULL << (5 * 8))) != 0;
67 return ((*((
u32 *) mac) == 0) && (*((
u16 *) (mac + 4)) == 0));
70 #ifdef CLIB_HAVE_VEC128 71 static const u16x8 tagged_ethertypes = {
72 (
u16) ETHERNET_TYPE_VLAN,
73 (
u16) ETHERNET_TYPE_DOT1AD,
74 (
u16) ETHERNET_TYPE_VLAN_9100,
75 (
u16) ETHERNET_TYPE_VLAN_9200,
77 (
u16) ETHERNET_TYPE_VLAN_9200,
78 (
u16) ETHERNET_TYPE_VLAN_9200,
79 (
u16) ETHERNET_TYPE_VLAN_9200,
80 (
u16) ETHERNET_TYPE_VLAN_9200
87 #ifdef CLIB_HAVE_VEC128 88 return !u16x8_is_all_zero (tagged_ethertypes == u16x8_splat (type));
90 if ((type == ETHERNET_TYPE_VLAN) ||
91 (type == ETHERNET_TYPE_DOT1AD) ||
92 (type == ETHERNET_TYPE_VLAN_9100) || (type == ETHERNET_TYPE_VLAN_9200))
101 #ifdef CLIB_HAVE_VEC128 102 u16x8 r0 = (tagged_ethertypes == u16x8_splat (type0));
103 u16x8 r1 = (tagged_ethertypes == u16x8_splat (type1));
104 return !u16x8_is_all_zero (r0 | r1);
113 #ifdef CLIB_HAVE_VEC128 114 u16x8 r0 = (tagged_ethertypes == u16x8_splat (type0));
115 u16x8 r1 = (tagged_ethertypes == u16x8_splat (type1));
116 u16x8 r2 = (tagged_ethertypes == u16x8_splat (type2));
117 u16x8 r3 = (tagged_ethertypes == u16x8_splat (type3));
118 return !u16x8_is_all_zero (r0 | r1 | r2 | r3);
139 #define ETHERNET_MIN_PACKET_BYTES 64 140 #define ETHERNET_MAX_PACKET_BYTES 9216 147 #define ETHERNET_INTERFACE_FLAG_ACCEPT_ALL (1 << 0) 148 #define ETHERNET_INTERFACE_FLAG_CONFIG_PROMISC(flags) \ 149 (((flags) & ~ETHERNET_INTERFACE_FLAG_ACCEPT_ALL) == 0) 152 #define ETHERNET_INTERFACE_FLAG_MTU (1 << 1) 153 #define ETHERNET_INTERFACE_FLAG_CONFIG_MTU(flags) \ 154 ((flags) & ETHERNET_INTERFACE_FLAG_MTU) 184 #define ethernet_error(n,c,s) ETHERNET_ERROR_##n, 186 #undef ethernet_error 200 #define SUBINT_CONFIG_MATCH_0_TAG (1<<0) 201 #define SUBINT_CONFIG_MATCH_1_TAG (1<<1) 202 #define SUBINT_CONFIG_MATCH_2_TAG (1<<2) 203 #define SUBINT_CONFIG_MATCH_3_TAG (1<<3) 204 #define SUBINT_CONFIG_VALID (1<<4) 205 #define SUBINT_CONFIG_L2 (1<<5) 206 #define SUBINT_CONFIG_P2P (1<<6) 324 u32 * hw_if_index_return,
389 #define ethernet_buffer_get_vlan_count(b) ( \ 390 ((b)->flags & VNET_BUFFER_FLAGS_VLAN_BITS) >> VNET_BUFFER_F_LOG2_VLAN_1_DEEP \ 397 #define ethernet_buffer_set_vlan_count(b, v) ( \ 398 (b)->flags = ((b)->flags & ~VNET_BUFFER_FLAGS_VLAN_BITS) | \ 399 (((v) << VNET_BUFFER_F_LOG2_VLAN_1_DEEP) & VNET_BUFFER_FLAGS_VLAN_BITS) \ 403 #define ethernet_buffer_adjust_vlan_count(b, v) ( \ 404 ethernet_buffer_set_vlan_count(b, \ 405 (word)ethernet_buffer_get_vlan_count(b) + (word)(v)) \ 409 #define ethernet_buffer_adjust_vlan_count_by_bytes(b, v) ( \ 410 (b)->flags = ((b)->flags & ~VNET_BUFFER_FLAGS_VLAN_BITS) | (( \ 411 ((b)->flags & VNET_BUFFER_FLAGS_VLAN_BITS) + \ 412 ((v) << (VNET_BUFFER_F_LOG2_VLAN_1_DEEP - 2)) \ 413 ) & VNET_BUFFER_FLAGS_VLAN_BITS) \ 424 #define ethernet_buffer_header_size(b) ( \ 425 ethernet_buffer_get_vlan_count((b)) * sizeof(ethernet_vlan_header_t) + \ 426 sizeof(ethernet_header_t) \ 440 u32 ethertype,
u32 next_index);
443 u8 is_specified,
u32 user_instance);
453 u32 port_sw_if_index0,
475 vlan_table_id = (first_ethertype == ETHERNET_TYPE_DOT1AD) ?
476 (*main_intf)->dot1ad_vlans : (*main_intf)->dot1q_vlans;
478 *vlan_intf = &vlan_table->
vlans[outer_id];
481 *qinq_intf = &qinq_table->
vlans[inner_id];
496 u32 * new_sw_if_index,
u8 * error0,
u32 * is_l2)
504 subint = &qinq_intf->
subint;
505 if ((subint->
flags & match_flags) == match_flags)
510 if ((subint->
flags & match_flags) == match_flags)
515 if ((subint->
flags & match_flags) == match_flags)
520 if ((subint->
flags & match_flags) == match_flags)
525 if ((subint->
flags & match_flags) == match_flags)
529 *new_sw_if_index = ~0;
530 *error0 = ETHERNET_ERROR_UNKNOWN_VLAN;
544 return (*((
u32 *) (mac1 + 0)) == *((
u32 *) (mac2 + 0)) &&
545 *((
u32 *) (mac1 + 2)) == *((
u32 *) (mac2 + 2)));
567 uword data,
int is_add);
static_always_inline int ethernet_frame_is_any_tagged_x4(u16 type0, u16 type1, u16 type2, u16 type3)
uword unformat_ethernet_type_net_byte_order(unformat_input_t *input, va_list *args)
uword unformat_pg_ethernet_header(unformat_input_t *input, va_list *args)
void ethernet_delete_interface(vnet_main_t *vnm, u32 hw_if_index)
static vnet_hw_interface_t * vnet_get_sup_hw_interface(vnet_main_t *vnm, u32 sw_if_index)
ethernet_main_t * ethernet_get_main(vlib_main_t *vm)
int vnet_add_del_ip4_arp_change_event(vnet_main_t *vnm, void *data_callback, u32 pid, void *address_arg, uword node_index, uword type_opaque, uword data, int is_add)
subint_config_t inner_any_subint
vlib_node_registration_t ethernet_input_node
(constructor) VLIB_REGISTER_NODE (ethernet_input_node)
void ethernet_register_l3_redirect(vlib_main_t *vm, u32 node_index)
static u64 ethernet_mac_address_u64(u8 *a)
static pg_node_t * pg_get_node(uword node_index)
ethernet_main_t ethernet_main
#define static_always_inline
u8 * format_ethernet_address(u8 *s, va_list *args)
subint_config_t default_subint
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
void ethernet_sw_interface_set_l2_mode_noport(vnet_main_t *vnm, u32 sw_if_index, u32 l2)
u8 output_feature_arc_index
int format_ethernet_address_16bit
ethernet_flag_change_function_t * flag_change
const u8 * ethernet_ip6_mcast_dst_addr(void)
void ethernet_set_rx_redirect(vnet_main_t *vnm, vnet_hw_interface_t *hi, u32 enable)
void ethernet_update_adjacency(vnet_main_t *vnm, u32 sw_if_index, u32 ai)
static ethernet_header_t * ethernet_buffer_get_header(vlib_buffer_t *b)
void wc_arp_set_publisher_node(uword inode_index, uword event_type)
subint_config_t single_tag_subint
u32 * sparse_index_by_input_next_index
static ethernet_type_info_t * ethernet_get_type_info(ethernet_main_t *em, ethernet_type_t type)
format_function_t * format_buffer
void arp_update_adjacency(vnet_main_t *vnm, u32 sw_if_index, u32 ai)
vnet_hw_interface_class_t ethernet_hw_interface_class
u8 next_by_ethertype_register_called
subint_config_t untagged_subint
u8 * format_ethernet_type(u8 *s, va_list *args)
int vnet_create_loopback_interface(u32 *sw_if_indexp, u8 *mac_address, u8 is_specified, u32 user_instance)
u8 * format_ethernet_header_with_length(u8 *s, va_list *args)
#define SUBINT_CONFIG_VALID
clib_error_t * next_by_ethertype_register(next_by_ethertype_t *l3_next, u32 ethertype, u32 next_index)
void vnet_register_ip4_arp_resolution_event(vnet_main_t *vnm, void *address_arg, uword node_index, uword type_opaque, uword data)
qinq_intf_t vlans[ETHERNET_N_VLAN]
static int ethernet_mac_address_is_zero(u8 *mac)
int vnet_delete_sub_interface(u32 sw_if_index)
int vnet_delete_loopback_interface(u32 sw_if_index)
static u32 eth_create_valid_subint_match_flags(u32 num_tags)
void ethernet_register_l2_input(vlib_main_t *vm, u32 node_index)
unformat_function_t * unformat_buffer
unformat_function_t * unformat_edit
static void eth_vlan_table_lookups(ethernet_main_t *em, vnet_main_t *vnm, u32 port_sw_if_index0, u16 first_ethertype, u16 outer_id, u16 inner_id, vnet_hw_interface_t **hi, main_intf_t **main_intf, vlan_intf_t **vlan_intf, qinq_intf_t **qinq_intf)
static int ethernet_mac_address_is_multicast_u64(u64 a)
uword unformat_ethernet_address(unformat_input_t *input, va_list *args)
void ethernet_ndp_change_mac(u32 sw_if_index)
static u32 eth_identify_subint(vnet_hw_interface_t *hi, vlib_buffer_t *b0, u32 match_flags, main_intf_t *main_intf, vlan_intf_t *vlan_intf, qinq_intf_t *qinq_intf, u32 *new_sw_if_index, u8 *error0, u32 *is_l2)
u8 * format_ethernet_header(u8 *s, va_list *args)
enum vnet_link_t_ vnet_link_t
Link Type: A description of the protocol of packets on the link.
u32( ethernet_flag_change_function_t)(vnet_main_t *vnm, struct vnet_hw_interface_t *hi, u32 flags)
static_always_inline int ethernet_frame_is_tagged(u16 type)
clib_error_t * ethernet_register_interface(vnet_main_t *vnm, u32 dev_class_index, u32 dev_instance, u8 *address, u32 *hw_if_index_return, ethernet_flag_change_function_t flag_change)
vlan_intf_t vlans[ETHERNET_N_VLAN]
uword * bm_loopback_instances
void ethernet_arp_change_mac(u32 sw_if_index)
void ethernet_register_input_type(vlib_main_t *vm, ethernet_type_t type, u32 node_index)
uword unformat_ethernet_interface(unformat_input_t *input, va_list *args)
struct _vlib_node_registration vlib_node_registration_t
uword * type_info_by_type
ethernet_interface_t * ethernet_get_interface(ethernet_main_t *em, u32 hw_if_index)
void ethernet_sw_interface_set_l2_mode(vnet_main_t *vnm, u32 sw_if_index, u32 l2)
uword unformat_ethernet_type_host_byte_order(unformat_input_t *input, va_list *args)
struct _vnet_hw_interface_class vnet_hw_interface_class_t
u8 * format_ethernet_vlan_tci(u8 *s, va_list *va)
static_always_inline int ethernet_frame_is_any_tagged_x2(u16 type0, u16 type1)
struct ethernet_interface ethernet_interface_t
u8 * ethernet_build_rewrite(vnet_main_t *vnm, u32 sw_if_index, vnet_link_t link_type, const void *dst_address)
build a rewrite string to use for sending packets of type 'link_type' to 'dst_address' ...
clib_error_t * next_by_ethertype_init(next_by_ethertype_t *l3_next)
static ethernet_main_t * vnet_get_ethernet_main(void)
static u32 eth_mac_equal(u8 *mac1, u8 *mac2)
static vlib_node_t * vlib_get_node(vlib_main_t *vm, u32 i)
Get vlib node by index.
next_by_ethertype_t l3_next
ethernet_interface_t * interfaces
const u8 * ethernet_ip4_mcast_dst_addr(void)
static void ethernet_setup_node(vlib_main_t *vm, u32 node_index)
uword unformat_ethernet_header(unformat_input_t *input, va_list *args)
u32 ethernet_set_flags(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
ethernet_type_info_t * type_infos