diff options
Diffstat (limited to 'vnet')
-rw-r--r-- | vnet/vnet/adj/adj.c | 10 | ||||
-rw-r--r-- | vnet/vnet/adj/adj_internal.h | 3 | ||||
-rw-r--r-- | vnet/vnet/adj/adj_nbr.c | 4 | ||||
-rw-r--r-- | vnet/vnet/ethernet/arp.c | 2 | ||||
-rw-r--r-- | vnet/vnet/gre/gre.c | 43 | ||||
-rw-r--r-- | vnet/vnet/gre/gre.h | 77 | ||||
-rw-r--r-- | vnet/vnet/gre/interface.c | 51 | ||||
-rw-r--r-- | vnet/vnet/gre/node.c | 21 | ||||
-rw-r--r-- | vnet/vnet/interface_output.c | 29 | ||||
-rw-r--r-- | vnet/vnet/ip/ip6_forward.c | 2 | ||||
-rw-r--r-- | vnet/vnet/ip/ip6_neighbor.c | 2 |
11 files changed, 174 insertions, 70 deletions
diff --git a/vnet/vnet/adj/adj.c b/vnet/vnet/adj/adj.c index 24f7662d943..2741c885cee 100644 --- a/vnet/vnet/adj/adj.c +++ b/vnet/vnet/adj/adj.c @@ -61,6 +61,7 @@ adj_alloc (fib_protocol_t proto) adj->mcast_group_index = ~0; adj->saved_lookup_next_index = 0; adj->n_adj = 1; + adj->lookup_next_index = 0; fib_node_init(&adj->ia_node, FIB_NODE_TYPE_ADJ); @@ -163,7 +164,8 @@ adj_last_lock_gone (ip_adjacency_t *adj) /* * complete and incomplete nbr adjs */ - adj_nbr_remove(adj->ia_nh_proto, + adj_nbr_remove(adj_get_index(adj), + adj->ia_nh_proto, adj->ia_link, &adj->sub_type.nbr.next_hop, adj->rewrite_header.sw_if_index); @@ -376,6 +378,12 @@ adj_show (vlib_main_t * vm, if (ADJ_INDEX_INVALID != ai) { + if (pool_is_free_index(adj_pool, ai)) + { + vlib_cli_output (vm, "adjacency %d invalid", ai); + return 0; + } + vlib_cli_output (vm, "[@%d] %U", ai, format_ip_adjacency, ai, diff --git a/vnet/vnet/adj/adj_internal.h b/vnet/vnet/adj/adj_internal.h index e3e0e04c99a..833bc7c9e01 100644 --- a/vnet/vnet/adj/adj_internal.h +++ b/vnet/vnet/adj/adj_internal.h @@ -93,7 +93,8 @@ extern void adj_nbr_update_rewrite_internal (ip_adjacency_t *adj, extern ip_adjacency_t * adj_alloc(fib_protocol_t proto); -extern void adj_nbr_remove(fib_protocol_t nh_proto, +extern void adj_nbr_remove(adj_index_t ai, + fib_protocol_t nh_proto, vnet_link_t link_type, const ip46_address_t *nh_addr, u32 sw_if_index); diff --git a/vnet/vnet/adj/adj_nbr.c b/vnet/vnet/adj/adj_nbr.c index 1a78ecbc49f..003e18e8d66 100644 --- a/vnet/vnet/adj/adj_nbr.c +++ b/vnet/vnet/adj/adj_nbr.c @@ -76,7 +76,8 @@ adj_nbr_insert (fib_protocol_t nh_proto, } void -adj_nbr_remove (fib_protocol_t nh_proto, +adj_nbr_remove (adj_index_t ai, + fib_protocol_t nh_proto, vnet_link_t link_type, const ip46_address_t *nh_addr, u32 sw_if_index) @@ -87,6 +88,7 @@ adj_nbr_remove (fib_protocol_t nh_proto, return; ADJ_NBR_SET_KEY(kv, link_type, nh_addr); + kv.value = ai; BV(clib_bihash_add_del) (adj_nbr_tables[nh_proto][sw_if_index], &kv, 0); } diff --git a/vnet/vnet/ethernet/arp.c b/vnet/vnet/ethernet/arp.c index eeaac4d3808..c6dbbc689b2 100644 --- a/vnet/vnet/ethernet/arp.c +++ b/vnet/vnet/ethernet/arp.c @@ -1509,7 +1509,7 @@ arp_add_del_interface_address (ip4_main_t * im, ethernet_arp_main_t *am = ðernet_arp_main; ethernet_arp_ip4_entry_t *e; - if (vec_len (am->ethernet_arp_by_sw_if_index) < sw_if_index) + if (vec_len (am->ethernet_arp_by_sw_if_index) <= sw_if_index) return; if (is_del) diff --git a/vnet/vnet/gre/gre.c b/vnet/vnet/gre/gre.c index a4b3f9fc228..0faed13eb29 100644 --- a/vnet/vnet/gre/gre.c +++ b/vnet/vnet/gre/gre.c @@ -250,9 +250,9 @@ gre_update_adj (vnet_main_t * vnm, * @brief TX function. Only called L2. L3 traffic uses the adj-midchains */ static uword -gre_interface_tx (vlib_main_t * vm, - vlib_node_runtime_t * node, - vlib_frame_t * frame) +gre_interface_tx_inline (vlib_main_t * vm, + vlib_node_runtime_t * node, + vlib_frame_t * frame) { gre_main_t * gm = &gre_main; u32 next_index; @@ -318,12 +318,34 @@ gre_interface_tx (vlib_main_t * vm, return frame->n_vectors; } +static uword +gre_interface_tx (vlib_main_t * vm, + vlib_node_runtime_t * node, + vlib_frame_t * frame) +{ + return (gre_interface_tx_inline (vm, node, frame)); +} + +static uword +gre_teb_interface_tx (vlib_main_t * vm, + vlib_node_runtime_t * node, + vlib_frame_t * frame) +{ + return (gre_interface_tx_inline (vm, node, frame)); +} + static u8 * format_gre_tunnel_name (u8 * s, va_list * args) { u32 dev_instance = va_arg (*args, u32); return format (s, "gre%d", dev_instance); } +static u8 * format_gre_tunnel_teb_name (u8 * s, va_list * args) +{ + u32 dev_instance = va_arg (*args, u32); + return format (s, "teb-gre%d", dev_instance); +} + static u8 * format_gre_device (u8 * s, va_list * args) { u32 dev_instance = va_arg (*args, u32); @@ -348,6 +370,21 @@ VNET_DEVICE_CLASS (gre_device_class) = { VLIB_DEVICE_TX_FUNCTION_MULTIARCH (gre_device_class, gre_interface_tx) +VNET_DEVICE_CLASS (gre_device_teb_class) = { + .name = "GRE TEB tunnel device", + .format_device_name = format_gre_tunnel_teb_name, + .format_device = format_gre_device, + .format_tx_trace = format_gre_tx_trace, + .tx_function = gre_teb_interface_tx, + .admin_up_down_function = gre_interface_admin_up_down, +#ifdef SOON + .clear counter = 0; +#endif +}; + +VLIB_DEVICE_TX_FUNCTION_MULTIARCH (gre_device_teb_class, + gre_teb_interface_tx) + VNET_HW_INTERFACE_CLASS (gre_hw_interface_class) = { .name = "GRE", .format_header = format_gre_header_with_length, diff --git a/vnet/vnet/gre/gre.h b/vnet/vnet/gre/gre.h index a0ee9ad263b..b6544b9b737 100644 --- a/vnet/vnet/gre/gre.h +++ b/vnet/vnet/gre/gre.h @@ -36,20 +36,48 @@ typedef enum { GRE_N_ERROR, } gre_error_t; +/** + * A GRE payload protocol registration + */ typedef struct { - /* Name (a c string). */ + /** Name (a c string). */ char * name; - /* GRE protocol type in host byte order. */ + /** GRE protocol type in host byte order. */ gre_protocol_t protocol; - /* Node which handles this type. */ + /** Node which handles this type. */ u32 node_index; - /* Next index for this type. */ + /** Next index for this type. */ u32 next_index; } gre_protocol_info_t; +/** + * @brief The GRE tunnel type + */ +typedef enum gre_tunnel_tyoe_t_ +{ + /** + * L3 GRE (i.e. this tunnel is in L3 mode) + */ + GRE_TUNNEL_TYPE_L3, + /** + * Transparent Ethernet Bridging - the tunnel is in L2 mode + */ + GRE_TUNNEL_TYPE_TEB, +} gre_tunnel_type_t; + +#define GRE_TUNNEL_TYPE_NAMES { \ + [GRE_TUNNEL_TYPE_L3] = "L3", \ + [GRE_TUNNEL_TYPE_TEB] = "TEB", \ +} + +#define GRE_TUNNEL_N_TYPES ((gre_tunnel_type_t)GRE_TUNNEL_TYPE_TEB+1) + +/** + * @brief A representation of a GRE tunnel + */ typedef struct { /** * Linkage into the FIB object graph @@ -70,7 +98,7 @@ typedef struct { u32 outer_fib_index; u32 hw_if_index; u32 sw_if_index; - u8 teb; + gre_tunnel_type_t type; /** * The FIB entry sourced by the tunnel for its destination prefix @@ -96,21 +124,39 @@ typedef struct { adj_index_t l2_adj_index; } gre_tunnel_t; +/** + * @brief GRE related global data + */ typedef struct { - /* pool of tunnel instances */ + /** + * pool of tunnel instances + */ gre_tunnel_t *tunnels; + /** + * GRE payload protocol registrations + */ gre_protocol_info_t * protocol_infos; - /* Hash tables mapping name/protocol to protocol info index. */ + /** + * Hash tables mapping name/protocol to protocol info index. + */ uword * protocol_info_by_name, * protocol_info_by_protocol; - /* Hash mapping src/dst addr pair to tunnel */ + /** + * Hash mapping src/dst addr pair to tunnel + */ uword * tunnel_by_key; - /* Free vlib hw_if_indices */ - u32 * free_gre_tunnel_hw_if_indices; + /** + * Free vlib hw_if_indices. + * A free list per-tunnel type since the interfaces ctreated are fo different + * types and we cannot change the type. + */ + u32 * free_gre_tunnel_hw_if_indices[GRE_TUNNEL_N_TYPES]; - /* Mapping from sw_if_index to tunnel index */ + /** + * Mapping from sw_if_index to tunnel index + */ u32 * tunnel_index_by_sw_if_index; /* convenience */ @@ -120,8 +166,7 @@ typedef struct { /** * @brief IPv4 and GRE header. - * -*/ + */ typedef CLIB_PACKED (struct { ip4_header_t ip4; gre_header_t gre; @@ -148,8 +193,8 @@ extern clib_error_t * gre_interface_admin_up_down (vnet_main_t * vnm, extern void gre_tunnel_stack (adj_index_t ai); extern void gre_update_adj (vnet_main_t * vnm, - u32 sw_if_index, - adj_index_t ai); + u32 sw_if_index, + adj_index_t ai); format_function_t format_gre_protocol; format_function_t format_gre_header; @@ -157,7 +202,7 @@ format_function_t format_gre_header_with_length; extern vlib_node_registration_t gre_input_node; extern vnet_device_class_t gre_device_class; -extern vnet_device_class_t gre_l2_device_class; +extern vnet_device_class_t gre_device_teb_class; /* Parse gre protocol as 0xXXXX or protocol name. In either host or network byte order. */ diff --git a/vnet/vnet/gre/interface.c b/vnet/vnet/gre/interface.c index 3234de09858..7adc5268446 100644 --- a/vnet/vnet/gre/interface.c +++ b/vnet/vnet/gre/interface.c @@ -24,6 +24,8 @@ #include <vnet/adj/adj_nbr.h> #include <vnet/mpls/mpls.h> +static const char *gre_tunnel_type_names[] = GRE_TUNNEL_TYPE_NAMES; + static inline u64 gre_mk_key (const ip4_address_t *src, const ip4_address_t *dst, @@ -34,17 +36,25 @@ gre_mk_key (const ip4_address_t *src, } static u8 * +format_gre_tunnel_type (u8 * s, va_list * args) +{ + gre_tunnel_type_t type = va_arg (*args, gre_tunnel_type_t); + + return (format(s, "%s", gre_tunnel_type_names[type])); +} + +static u8 * format_gre_tunnel (u8 * s, va_list * args) { gre_tunnel_t * t = va_arg (*args, gre_tunnel_t *); gre_main_t * gm = &gre_main; s = format (s, - "[%d] %U (src) %U (dst) payload %s outer_fib_index %d", + "[%d] %U (src) %U (dst) payload %U outer_fib_index %d", t - gm->tunnels, format_ip4_address, &t->tunnel_src, format_ip4_address, &t->tunnel_dst, - (t->teb ? "teb" : "ip"), + format_gre_tunnel_type, t->type, t->outer_fib_index); return s; @@ -248,12 +258,17 @@ vnet_gre_tunnel_add (vnet_gre_add_del_tunnel_args_t *a, memset (t, 0, sizeof (*t)); fib_node_init(&t->node, FIB_NODE_TYPE_GRE_TUNNEL); - if (vec_len (gm->free_gre_tunnel_hw_if_indices) > 0) { + if (a->teb) + t->type = GRE_TUNNEL_TYPE_TEB; + else + t->type = GRE_TUNNEL_TYPE_L3; + + if (vec_len (gm->free_gre_tunnel_hw_if_indices[t->type]) > 0) { vnet_interface_main_t * im = &vnm->interface_main; - hw_if_index = gm->free_gre_tunnel_hw_if_indices - [vec_len (gm->free_gre_tunnel_hw_if_indices)-1]; - _vec_len (gm->free_gre_tunnel_hw_if_indices) -= 1; + hw_if_index = gm->free_gre_tunnel_hw_if_indices[t->type] + [vec_len (gm->free_gre_tunnel_hw_if_indices[t->type])-1]; + _vec_len (gm->free_gre_tunnel_hw_if_indices[t->type]) -= 1; hi = vnet_get_hw_interface (vnm, hw_if_index); hi->dev_instance = t - gm->tunnels; @@ -269,14 +284,14 @@ vnet_gre_tunnel_add (vnet_gre_add_del_tunnel_args_t *a, vlib_zero_simple_counter (&im->sw_if_counters[VNET_INTERFACE_COUNTER_DROP], sw_if_index); vnet_interface_counter_unlock(im); - if (a->teb) + if (GRE_TUNNEL_TYPE_TEB == t->type) { - t->l2_tx_arc = vlib_node_add_named_next(vlib_get_main(), - hi->tx_node_index, - "adj-l2-midchain"); + t->l2_tx_arc = vlib_node_add_named_next(vlib_get_main(), + hi->tx_node_index, + "adj-l2-midchain"); } } else { - if (a->teb) + if (GRE_TUNNEL_TYPE_TEB == t->type) { /* Default MAC address (d00b:eed0:0000 + sw_if_index) */ memset (address, 0, sizeof (address)); @@ -287,7 +302,7 @@ vnet_gre_tunnel_add (vnet_gre_add_del_tunnel_args_t *a, address[4] = t - gm->tunnels; error = ethernet_register_interface(vnm, - gre_device_class.index, + gre_device_teb_class.index, t - gm->tunnels, address, &hw_if_index, 0); @@ -316,14 +331,11 @@ vnet_gre_tunnel_add (vnet_gre_add_del_tunnel_args_t *a, t->hw_if_index = hw_if_index; t->outer_fib_index = outer_fib_index; t->sw_if_index = sw_if_index; - t->teb = a->teb; vec_validate_init_empty (gm->tunnel_index_by_sw_if_index, sw_if_index, ~0); gm->tunnel_index_by_sw_if_index[sw_if_index] = t - gm->tunnels; vec_validate (im->fib_index_by_sw_if_index, sw_if_index); - im->fib_index_by_sw_if_index[sw_if_index] = t->outer_fib_index; - ip4_sw_interface_enable_disable(sw_if_index, 1); hi->min_packet_bytes = 64 + sizeof (gre_header_t) + sizeof (ip4_header_t); hi->per_packet_overhead_bytes = @@ -365,13 +377,12 @@ vnet_gre_tunnel_add (vnet_gre_add_del_tunnel_args_t *a, clib_memcpy (&t->tunnel_src, &a->src, sizeof (t->tunnel_src)); clib_memcpy (&t->tunnel_dst, &a->dst, sizeof (t->tunnel_dst)); - if (t->teb) + if (GRE_TUNNEL_TYPE_TEB == t->type) { t->l2_adj_index = adj_nbr_add_or_lock(FIB_PROTOCOL_IP4, VNET_LINK_ETHERNET, &zero_addr, sw_if_index); - gre_update_adj(vnm, t->sw_if_index, t->l2_adj_index); } @@ -399,9 +410,11 @@ vnet_gre_tunnel_delete (vnet_gre_add_del_tunnel_args_t *a, vnet_sw_interface_set_flags (vnm, sw_if_index, 0 /* down */); /* make sure tunnel is removed from l2 bd or xconnect */ set_int_l2_mode(gm->vlib_main, vnm, MODE_L3, sw_if_index, 0, 0, 0, 0); - vec_add1 (gm->free_gre_tunnel_hw_if_indices, t->hw_if_index); + vec_add1 (gm->free_gre_tunnel_hw_if_indices[t->type], t->hw_if_index); gm->tunnel_index_by_sw_if_index[sw_if_index] = ~0; - ip4_sw_interface_enable_disable(sw_if_index, 0); + + if (GRE_TUNNEL_TYPE_TEB == t->type) + adj_unlock(t->l2_adj_index); fib_entry_child_remove(t->fib_entry_index, t->sibling_index); diff --git a/vnet/vnet/gre/node.c b/vnet/vnet/gre/node.c index 556f1a81837..86f7a6eeea4 100644 --- a/vnet/vnet/gre/node.c +++ b/vnet/vnet/gre/node.c @@ -68,12 +68,10 @@ gre_input (vlib_main_t * vm, vlib_frame_t * from_frame) { gre_main_t * gm = &gre_main; - ip4_main_t * ip4m = &ip4_main; gre_input_runtime_t * rt = (void *) node->runtime_data; __attribute__((unused)) u32 n_left_from, next_index, * from, * to_next; u64 cached_tunnel_key = (u64) ~0; u32 cached_tunnel_sw_if_index = 0, tunnel_sw_if_index = 0; - u32 cached_tunnel_fib_index = 0, tunnel_fib_index; u32 cpu_index = os_get_cpu_number(); u32 len; @@ -193,16 +191,12 @@ gre_input (vlib_main_t * vm, hi = vnet_get_hw_interface (gm->vnet_main, t->hw_if_index); tunnel_sw_if_index = hi->sw_if_index; - tunnel_fib_index = vec_elt (ip4m->fib_index_by_sw_if_index, - tunnel_sw_if_index); cached_tunnel_sw_if_index = tunnel_sw_if_index; - cached_tunnel_fib_index = tunnel_fib_index; } else { tunnel_sw_if_index = cached_tunnel_sw_if_index; - tunnel_fib_index = cached_tunnel_fib_index; } } else @@ -218,7 +212,6 @@ gre_input (vlib_main_t * vm, 1 /* packets */, len /* bytes */); - vnet_buffer(b0)->sw_if_index[VLIB_TX] = tunnel_fib_index; vnet_buffer(b0)->sw_if_index[VLIB_RX] = tunnel_sw_if_index; drop0: @@ -247,16 +240,12 @@ drop0: hi = vnet_get_hw_interface (gm->vnet_main, t->hw_if_index); tunnel_sw_if_index = hi->sw_if_index; - tunnel_fib_index = vec_elt (ip4m->fib_index_by_sw_if_index, - tunnel_sw_if_index); cached_tunnel_sw_if_index = tunnel_sw_if_index; - cached_tunnel_fib_index = tunnel_fib_index; } else { tunnel_sw_if_index = cached_tunnel_sw_if_index; - tunnel_fib_index = cached_tunnel_fib_index; } } else @@ -272,7 +261,6 @@ drop0: 1 /* packets */, len /* bytes */); - vnet_buffer(b1)->sw_if_index[VLIB_TX] = tunnel_fib_index; vnet_buffer(b1)->sw_if_index[VLIB_RX] = tunnel_sw_if_index; drop1: @@ -280,7 +268,7 @@ drop1: { gre_rx_trace_t *tr = vlib_add_trace (vm, node, b0, sizeof (*tr)); - tr->tunnel_id = ~0; + tr->tunnel_id = tunnel_sw_if_index; tr->length = ip0->length; tr->src.as_u32 = ip0->src_address.as_u32; tr->dst.as_u32 = ip0->dst_address.as_u32; @@ -290,7 +278,7 @@ drop1: { gre_rx_trace_t *tr = vlib_add_trace (vm, node, b1, sizeof (*tr)); - tr->tunnel_id = ~0; + tr->tunnel_id = tunnel_sw_if_index; tr->length = ip1->length; tr->src.as_u32 = ip1->src_address.as_u32; tr->dst.as_u32 = ip1->dst_address.as_u32; @@ -374,16 +362,12 @@ drop1: hi = vnet_get_hw_interface (gm->vnet_main, t->hw_if_index); tunnel_sw_if_index = hi->sw_if_index; - tunnel_fib_index = vec_elt (ip4m->fib_index_by_sw_if_index, - tunnel_sw_if_index); cached_tunnel_sw_if_index = tunnel_sw_if_index; - cached_tunnel_fib_index = tunnel_fib_index; } else { tunnel_sw_if_index = cached_tunnel_sw_if_index; - tunnel_fib_index = cached_tunnel_fib_index; } } else @@ -399,7 +383,6 @@ drop1: 1 /* packets */, len /* bytes */); - vnet_buffer(b0)->sw_if_index[VLIB_TX] = tunnel_fib_index; vnet_buffer(b0)->sw_if_index[VLIB_RX] = tunnel_sw_if_index; drop: diff --git a/vnet/vnet/interface_output.c b/vnet/vnet/interface_output.c index 1d1546f6ebe..46e8a98c75d 100644 --- a/vnet/vnet/interface_output.c +++ b/vnet/vnet/interface_output.c @@ -58,15 +58,30 @@ format_vnet_interface_output_trace (u8 * s, va_list * va) if (t->sw_if_index != (u32) ~ 0) { - si = vnet_get_sw_interface (vnm, t->sw_if_index); indent = format_get_indent (s); - s = format (s, "%U\n%U%U", - format_vnet_sw_interface_name, vnm, si, - format_white_space, indent, - node->format_buffer ? node-> - format_buffer : format_hex_bytes, t->data, - sizeof (t->data)); + if (pool_is_free_index + (vnm->interface_main.sw_interfaces, t->sw_if_index)) + { + /* the interface may have been deleted by the time the trace is printed */ + s = format (s, "sw_if_index: %d\n%U%U", + t->sw_if_index, + format_white_space, indent, + node->format_buffer ? node-> + format_buffer : format_hex_bytes, t->data, + sizeof (t->data)); + } + else + { + si = vnet_get_sw_interface (vnm, t->sw_if_index); + + s = format (s, "%U\n%U%U", + format_vnet_sw_interface_name, vnm, si, + format_white_space, indent, + node->format_buffer ? node-> + format_buffer : format_hex_bytes, t->data, + sizeof (t->data)); + } } return s; } diff --git a/vnet/vnet/ip/ip6_forward.c b/vnet/vnet/ip/ip6_forward.c index bc346786283..14dd9dfbdf0 100644 --- a/vnet/vnet/ip/ip6_forward.c +++ b/vnet/vnet/ip/ip6_forward.c @@ -498,6 +498,8 @@ ip6_add_del_interface_address (vlib_main_t * vm, goto done; } + ip6_sw_interface_enable_disable(sw_if_index, !is_del); + if (is_del) ip6_del_interface_routes (im, ip6_af.fib_index, address, address_length); diff --git a/vnet/vnet/ip/ip6_neighbor.c b/vnet/vnet/ip/ip6_neighbor.c index cebe09a9557..af852a2be86 100644 --- a/vnet/vnet/ip/ip6_neighbor.c +++ b/vnet/vnet/ip/ip6_neighbor.c @@ -1849,7 +1849,6 @@ ip6_neighbor_sw_interface_add_del (vnet_main_t * vnm, pool_put (nm->if_radv_pool, a); nm->if_radv_pool_index_by_sw_if_index[sw_if_index] = ~0; ri = ~0; - ip6_sw_interface_enable_disable(sw_if_index, 0); } } else @@ -1858,7 +1857,6 @@ ip6_neighbor_sw_interface_add_del (vnet_main_t * vnm, { vnet_hw_interface_t * hw_if0; - ip6_sw_interface_enable_disable(sw_if_index, 1); hw_if0 = vnet_get_sup_hw_interface (vnm, sw_if_index); pool_get (nm->if_radv_pool, a); |