/* * Copyright (c) 2015 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. */ /* * interface.h: VNET interfaces/sub-interfaces * * Copyright (c) 2008 Eliot Dresselhaus * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #ifndef included_vnet_interface_h #define included_vnet_interface_h #include #include #include #include struct vnet_main_t; struct vnet_hw_interface_t; struct vnet_sw_interface_t; union ip46_address_t_; typedef enum { VNET_HW_INTERFACE_RX_MODE_UNKNOWN, VNET_HW_INTERFACE_RX_MODE_POLLING, VNET_HW_INTERFACE_RX_MODE_INTERRUPT, VNET_HW_INTERFACE_RX_MODE_ADAPTIVE, VNET_HW_INTERFACE_RX_MODE_DEFAULT, VNET_HW_INTERFACE_NUM_RX_MODES, } vnet_hw_interface_rx_mode; /* Interface up/down callback. */ typedef clib_error_t *(vnet_interface_function_t) (struct vnet_main_t * vnm, u32 if_index, u32 flags); /* Sub-interface add/del callback. */ typedef clib_error_t *(vnet_subif_add_del_function_t) (struct vnet_main_t * vnm, u32 if_index, struct vnet_sw_interface_t * template, int is_add); /* Interface set mac address callback. */ typedef clib_error_t *(vnet_interface_set_mac_address_function_t) (struct vnet_hw_interface_t * hi, const u8 * old_address, const u8 * new_address); /* Interface add/del additional mac address callback */ typedef clib_error_t *(vnet_interface_add_del_mac_address_function_t) (struct vnet_hw_interface_t * hi, const u8 * address, u8 is_add); /* Interface set rx mode callback. */ typedef clib_error_t *(vnet_interface_set_rx_mode_function_t) (struct vnet_main_t * vnm, u32 if_index, u32 queue_id, vnet_hw_interface_rx_mode mode); /* Interface set l2 mode callback. */ typedef clib_error_t *(vnet_interface_set_l2_mode_function_t) (struct vnet_main_t * vnm, struct vnet_hw_interface_t * hi, i32 l2_if_adjust); typedef enum { VNET_FLOW_DEV_OP_ADD_FLOW, VNET_FLOW_DEV_OP_DEL_FLOW, VNET_FLOW_DEV_OP_GET_COUNTER, VNET_FLOW_DEV_OP_RESET_COUNTER, } vnet_flow_dev_op_t; /* Interface flow operations callback. */ typedef int (vnet_flow_dev_ops_function_t) (struct vnet_main_t * vnm, vnet_flow_dev_op_t op, u32 hw_if_index, u32 index, uword * private_data); typedef enum vnet_interface_function_priority_t_ { VNET_ITF_FUNC_PRIORITY_LOW, VNET_ITF_FUNC_PRIORITY_HIGH, } vnet_interface_function_priority_t; #define VNET_ITF_FUNC_N_PRIO ((vnet_interface_function_priority_t)VNET_ITF_FUNC_PRIORITY_HIGH+1) typedef struct _vnet_interface_function_list_elt { struct _vnet_interface_function_list_elt *next_interface_function; clib_error_t *(*fp) (struct vnet_main_t * vnm, u32 if_index, u32 flags); } _vnet_interface_function_list_elt_t; #ifndef CLIB_MARCH_VARIANT #define _VNET_INTERFACE_FUNCTION_DECL_PRIO(f,tag,p) \ \ static void __vnet_interface_function_init_##tag##_##f (void) \ __attribute__((__constructor__)) ; \ \ static void __vnet_interface_function_init_##tag##_##f (void) \ { \ vnet_main_t * vnm = vnet_get_main(); \ static _vnet_interface_function_list_elt_t init_function; \ init_function.next_interface_function = vnm->tag##_functions[p]; \ vnm->tag##_functions[p] = &init_function; \ init_function.fp = (void *) &f; \ } \ static void __vnet_interface_function_deinit_##tag##_##f (void) \ __attribute__((__destructor__)) ; \ \ static void __vnet_interface_function_deinit_##tag##_##f (void) \ { \ vnet_main_t * vnm = vnet_get_main(); \ _vnet_interface_function_list_elt_t *next; \ if (vnm->tag##_functions[p]->fp == f) \ { \ vnm->tag##_functions[p] = \ vnm->tag##_functions[p]->next_interface_function; \ return; \ }
/*
 * Copyright (c) 2016 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.
 */
tcp_error (NONE, "no error")
tcp_error (WRONG_THREAD, "Wrong worker thread")
tcp_error (FILTERED, "Packets filtered")
tcp_error (LENGTH, "inconsistent ip/tcp lengths")
tcp_error (NO_LISTENER, "no listener for dst port")
tcp_error (LOOKUP_DROPS, "lookup drops")
tcp_error (DISPATCH, "Dispatch error")
tcp_error (ENQUEUED, "Packets pushed into rx fifo")
tcp_error (ENQUEUED_OOO, "OOO packets pushed into rx fifo")
tcp_error (FIFO_FULL, "Packets dropped for lack of rx fifo space")
tcp_error (PARTIALLY_ENQUEUED, "Packets partially pushed into rx fifo") 
tcp_error (SEGMENT_OLD, "Old segment")
tcp_error (SEGMENT_INVALID, "Invalid segments")
tcp_error (SYNS_RCVD, "SYNs received")
tcp_error (SYN_ACKS_RCVD, "SYN-ACKs received")
tcp_error (MSG_QUEUE_FULL, "Events not sent for lack of msg queue space") 
tcp_error (CREATE_SESSION_FAIL, "Sessions couldn't be allocated")
tcp_error (ACK_OK, "Pure ACKs received")
tcp_error (ACK_INVALID, "Invalid ACK")
tcp_error (ACK_DUP, "Duplicate ACK")
tcp_error (ACK_OLD, "Old ACK")
tcp_error (ACK_FUTURE, "Future ACK")
tcp_error (PKTS_SENT, "Packets sent")
tcp_error (FILTERED_DUPACKS, "Filtered duplicate ACKs")
tcp_error (RST_SENT, "Resets sent")
tcp_error (RST_RCVD, "Resets received")
tcp_error (INVALID_CONNECTION, "Invalid connection")
tcp_error (CONNECTION_CLOSED, "Connection closed")
tcp_error (CREATE_EXISTS, "Connection already exists")
tcp_error (PUNT, "Packets punted")
tcp_error (OPTIONS, "Could not parse options")
tcp_error (PAWS, "PAWS check failed")
tcp_error (RCV_WND, "Segment not in receive window")
tcp_error (FIN_RCVD, "FINs received")
tcp_error (LINK_LOCAL_RW, "No rewrite for link local connection")
el master is in the same L2 BD */ VNET_FLOOD_CLASS_TUNNEL_NORMAL, /* Never flood to this type */ VNET_FLOOD_CLASS_NO_FLOOD, } vnet_flood_class_t; /* Per protocol MTU */ typedef enum { VNET_MTU_L3, /* Default payload MTU (without L2 headers) */ VNET_MTU_IP4, /* Per-protocol MTUs overriding default */ VNET_MTU_IP6, VNET_MTU_MPLS, VNET_N_MTU } vnet_mtu_t; extern vnet_mtu_t vnet_link_to_mtu (vnet_link_t link); typedef enum vnet_sw_interface_flags_t_ { VNET_SW_INTERFACE_FLAG_NONE = 0, /* Interface is "up" meaning administratively up. Up in the sense of link state being up is maintained by hardware interface. */ VNET_SW_INTERFACE_FLAG_ADMIN_UP = (1 << 0), /* Interface is disabled for forwarding: punt all traffic to slow-path. */ VNET_SW_INTERFACE_FLAG_PUNT = (1 << 1), __VNET_SW_INTERFACE_FLAG_UNSUED = (1 << 2), VNET_SW_INTERFACE_FLAG_UNNUMBERED = (1 << 3), __VNET_SW_INTERFACE_FLAG_UNUSED2 = (1 << 4), /* Interface does not appear in CLI/API */ VNET_SW_INTERFACE_FLAG_HIDDEN = (1 << 5), /* Interface in ERROR state */ VNET_SW_INTERFACE_FLAG_ERROR = (1 << 6), /* Interface has IP configured directed broadcast */ VNET_SW_INTERFACE_FLAG_DIRECTED_BCAST = (1 << 7), } __attribute__ ((packed)) vnet_sw_interface_flags_t; /* Software-interface. This corresponds to a Ethernet VLAN, ATM vc, a tunnel, etc. Configuration (e.g. IP address) gets attached to software interface. */ typedef struct { vnet_sw_interface_type_t type:16; vnet_sw_interface_flags_t flags; /* Index for this interface. */ u32 sw_if_index; /* Software interface index of super-interface; equal to sw_if_index if this interface is not a sub-interface. */ u32 sup_sw_if_index; /* this swif is unnumbered, use addresses on unnumbered_sw_if_index... */ u32 unnumbered_sw_if_index; /* VNET_SW_INTERFACE_TYPE_HARDWARE. */ u32 hw_if_index; /* MTU for network layer (not including L2 headers) */ u32 mtu[VNET_N_MTU]; /* VNET_SW_INTERFACE_TYPE_SUB. */ vnet_sub_interface_t sub; /* VNET_SW_INTERFACE_TYPE_P2P. */ vnet_p2p_sub_interface_t p2p; vnet_flood_class_t flood_class; } vnet_sw_interface_t; typedef enum { /* Simple counters. */ VNET_INTERFACE_COUNTER_DROP = 0, VNET_INTERFACE_COUNTER_PUNT = 1, VNET_INTERFACE_COUNTER_IP4 = 2, VNET_INTERFACE_COUNTER_IP6 = 3, VNET_INTERFACE_COUNTER_RX_NO_BUF = 4, VNET_INTERFACE_COUNTER_RX_MISS = 5, VNET_INTERFACE_COUNTER_RX_ERROR = 6, VNET_INTERFACE_COUNTER_TX_ERROR = 7, VNET_INTERFACE_COUNTER_MPLS = 8, VNET_N_SIMPLE_INTERFACE_COUNTER = 9, /* Combined counters. */ VNET_INTERFACE_COUNTER_RX = 0, VNET_INTERFACE_COUNTER_RX_UNICAST = 1, VNET_INTERFACE_COUNTER_RX_MULTICAST = 2, VNET_INTERFACE_COUNTER_RX_BROADCAST = 3, VNET_INTERFACE_COUNTER_TX = 4, VNET_INTERFACE_COUNTER_TX_UNICAST = 5, VNET_INTERFACE_COUNTER_TX_MULTICAST = 6, VNET_INTERFACE_COUNTER_TX_BROADCAST = 7, VNET_N_COMBINED_INTERFACE_COUNTER = 8, } vnet_interface_counter_type_t; #define foreach_rx_combined_interface_counter(_x) \ for (_x = VNET_INTERFACE_COUNTER_RX; \ _x <= VNET_INTERFACE_COUNTER_RX_BROADCAST; \ _x++) #define foreach_tx_combined_interface_counter(_x) \ for (_x = VNET_INTERFACE_COUNTER_TX; \ _x <= VNET_INTERFACE_COUNTER_TX_BROADCAST; \ _x++) #define foreach_simple_interface_counter_name \ _(DROP, drops, if) \ _(PUNT, punt, if) \ _(IP4, ip4, if) \ _(IP6, ip6, if) \ _(RX_NO_BUF, rx-no-buf, if) \ _(RX_MISS, rx-miss, if) \ _(RX_ERROR, rx-error, if) \ _(TX_ERROR, tx-error, if) \ _(MPLS, mpls, if) #define foreach_combined_interface_counter_name \ _(RX, rx, if) \ _(RX_UNICAST, rx-unicast, if) \ _(RX_MULTICAST, rx-multicast, if) \ _(RX_BROADCAST, rx-broadcast, if) \ _(TX, tx, if) \ _(TX_UNICAST, tx-unicast, if) \ _(TX_MULTICAST, tx-multicast, if) \ _(TX_BROADCAST, tx-broadcast, if) typedef enum { COLLECT_SIMPLE_STATS = 0, COLLECT_DETAILED_STATS = 1, } vnet_interface_stats_collection_mode_e; extern int collect_detailed_interface_stats_flag; static inline int collect_detailed_interface_stats (void) { return collect_detailed_interface_stats_flag; } void collect_detailed_interface_stats_flag_set (void); void collect_detailed_interface_stats_flag_clear (void); typedef struct { u32 output_node_index; u32 tx_node_index; } vnet_hw_interface_nodes_t; typedef struct { CLIB_CACHE_LINE_ALIGN_MARK (cacheline0); u32 *split_buffers; } vnet_interface_per_thread_data_t; typedef u8 *(*vnet_buffer_opquae_formatter_t) (const vlib_buffer_t * b, u8 * s); typedef struct { /* Hardware interfaces. */ vnet_hw_interface_t *hw_interfaces; /* Hash table mapping HW interface name to index. */ uword *hw_interface_by_name; /* Vectors if hardware interface classes and device classes. */ vnet_hw_interface_class_t *hw_interface_classes; vnet_device_class_t *device_classes; /* Hash table mapping name to hw interface/device class. */ uword *hw_interface_class_by_name; uword *device_class_by_name; /* Software interfaces. */ vnet_sw_interface_t *sw_interfaces; /* Hash table mapping sub intfc sw_if_index by sup sw_if_index and sub id */ uword *sw_if_index_by_sup_and_sub; /* Software interface counters both simple and combined packet and byte counters. */ clib_spinlock_t sw_if_counter_lock; vlib_simple_counter_main_t *sw_if_counters; vlib_combined_counter_main_t *combined_sw_if_counters; vnet_hw_interface_nodes_t *deleted_hw_interface_nodes; /* * pcap drop tracing * Only the drop filter hash lives here. See ../src/vlib/main.h for * the rest of the variables. */ uword *pcap_drop_filter_hash; /* Buffer metadata format helper functions */ vnet_buffer_opquae_formatter_t *buffer_opaque_format_helpers; vnet_buffer_opquae_formatter_t *buffer_opaque2_format_helpers; /* per-thread data */ vnet_interface_per_thread_data_t *per_thread_data; /* enable GSO processing in packet path if this count is > 0 */ u32 gso_interface_count; /* feature_arc_index */ u8 output_feature_arc_index; } vnet_interface_main_t; static inline void vnet_interface_counter_lock (vnet_interface_main_t * im) { if (im->sw_if_counter_lock) clib_spinlock_lock (&im->sw_if_counter_lock); } static inline void vnet_interface_counter_unlock (vnet_interface_main_t * im) { if (im->sw_if_counter_lock) clib_spinlock_unlock (&im->sw_if_counter_lock); } void vnet_pcap_drop_trace_filter_add_del (u32 error_index, int is_add); int vnet_interface_name_renumber (u32 sw_if_index, u32 new_show_dev_instance); uword vnet_interface_output_node (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame); void vnet_register_format_buffer_opaque_helper (vnet_buffer_opquae_formatter_t fn); void vnet_register_format_buffer_opaque2_helper (vnet_buffer_opquae_formatter_t fn); typedef struct { u8 *filename; int enable; int status; u32 packets_to_capture; u32 max_bytes_per_pkt; u8 rx_enable; u8 tx_enable; u8 drop_enable; u32 sw_if_index; int filter; } vnet_pcap_dispatch_trace_args_t; int vnet_pcap_dispatch_trace_configure (vnet_pcap_dispatch_trace_args_t *); #endif /* included_vnet_interface_h */ /* * fd.io coding-style-patch-verification: ON * * Local Variables: * eval: (c-set-style "gnu") * End: */