X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvnet%2Fgre%2Finterface.c;h=2025838d9adeaf788bef1477ac3393476800f5ff;hb=5a8844bdb;hp=5b165c858d3e3289145cb9db214748cedb7949d8;hpb=25d417f28680c78a709792d997884dd80227bb70;p=vpp.git diff --git a/src/vnet/gre/interface.c b/src/vnet/gre/interface.c index 5b165c858d3..2025838d9ad 100644 --- a/src/vnet/gre/interface.c +++ b/src/vnet/gre/interface.c @@ -24,6 +24,7 @@ #include #include #include +#include static const char *gre_tunnel_type_names[] = GRE_TUNNEL_TYPE_NAMES; @@ -50,7 +51,7 @@ format_gre_tunnel (u8 * s, va_list * args) } static gre_tunnel_t * -gre_tunnel_db_find (const vnet_gre_add_del_tunnel_args_t * a, +gre_tunnel_db_find (const vnet_gre_tunnel_add_del_args_t * a, u32 outer_fib_index, gre_tunnel_key_t * key) { gre_main_t *gm = &gre_main; @@ -59,13 +60,13 @@ gre_tunnel_db_find (const vnet_gre_add_del_tunnel_args_t * a, if (!a->is_ipv6) { gre_mk_key4 (a->src.ip4, a->dst.ip4, outer_fib_index, - a->tunnel_type, a->session_id, &key->gtk_v4); + a->type, a->session_id, &key->gtk_v4); p = hash_get_mem (gm->tunnel_by_key4, &key->gtk_v4); } else { gre_mk_key6 (&a->src.ip6, &a->dst.ip6, outer_fib_index, - a->tunnel_type, a->session_id, &key->gtk_v6); + a->type, a->session_id, &key->gtk_v6); p = hash_get_mem (gm->tunnel_by_key6, &key->gtk_v6); } @@ -111,14 +112,6 @@ gre_tunnel_db_remove (gre_tunnel_t * t) t->key = NULL; } -static gre_tunnel_t * -gre_tunnel_from_fib_node (fib_node_t * node) -{ - ASSERT (FIB_NODE_TYPE_GRE_TUNNEL == node->fn_type); - return ((gre_tunnel_t *) (((char *) node) - - STRUCT_OFFSET_OF (gre_tunnel_t, node))); -} - /** * gre_tunnel_stack * @@ -135,7 +128,7 @@ gre_tunnel_stack (adj_index_t ai) adj = adj_get (ai); sw_if_index = adj->rewrite_header.sw_if_index; - if ((vec_len (gm->tunnel_index_by_sw_if_index) < sw_if_index) || + if ((vec_len (gm->tunnel_index_by_sw_if_index) <= sw_if_index) || (~0 == gm->tunnel_index_by_sw_if_index[sw_if_index])) return; @@ -145,45 +138,12 @@ gre_tunnel_stack (adj_index_t ai) if ((vnet_hw_interface_get_flags (vnet_get_main (), gt->hw_if_index) & VNET_HW_INTERFACE_FLAG_LINK_UP) == 0) { - adj_nbr_midchain_unstack (ai); - return; + adj_midchain_delegate_unstack (ai); } - - dpo_id_t tmp = DPO_INVALID; - fib_forward_chain_type_t fib_fwd = (FIB_PROTOCOL_IP6 == adj->ia_nh_proto) ? - FIB_FORW_CHAIN_TYPE_UNICAST_IP6 : FIB_FORW_CHAIN_TYPE_UNICAST_IP4; - - fib_entry_contribute_forwarding (gt->fib_entry_index, fib_fwd, &tmp); - if (DPO_LOAD_BALANCE == tmp.dpoi_type) + else { - /* - * post GRE rewrite we will load-balance. However, the GRE encap - * is always the same for this adjacency/tunnel and hence the IP/GRE - * src,dst hash is always the same result too. So we do that hash now and - * stack on the choice. - * If the choice is an incomplete adj then we will need a poke when - * it becomes complete. This happens since the adj update walk propagates - * as far a recursive paths. - */ - const dpo_id_t *choice; - load_balance_t *lb; - int hash; - - lb = load_balance_get (tmp.dpoi_index); - - if (fib_fwd == FIB_FORW_CHAIN_TYPE_UNICAST_IP4) - hash = ip4_compute_flow_hash ((ip4_header_t *) adj_get_rewrite (ai), - lb->lb_hash_config); - else - hash = ip6_compute_flow_hash ((ip6_header_t *) adj_get_rewrite (ai), - lb->lb_hash_config); - choice = - load_balance_get_bucket_i (lb, hash & lb->lb_n_buckets_minus_1); - dpo_copy (&tmp, choice); + adj_midchain_delegate_stack (ai, gt->outer_fib_index, >->tunnel_dst); } - - adj_nbr_midchain_stack (ai, &tmp); - dpo_reset (&tmp); } /** @@ -211,57 +171,8 @@ gre_tunnel_restack (gre_tunnel_t * gt) } } -/** - * Function definition to backwalk a FIB node - */ -static fib_node_back_walk_rc_t -gre_tunnel_back_walk (fib_node_t * node, fib_node_back_walk_ctx_t * ctx) -{ - gre_tunnel_restack (gre_tunnel_from_fib_node (node)); - - return (FIB_NODE_BACK_WALK_CONTINUE); -} - -/** - * Function definition to get a FIB node from its index - */ -static fib_node_t * -gre_tunnel_fib_node_get (fib_node_index_t index) -{ - gre_tunnel_t *gt; - gre_main_t *gm; - - gm = &gre_main; - gt = pool_elt_at_index (gm->tunnels, index); - - return (>->node); -} - -/** - * Function definition to inform the FIB node that its last lock has gone. - */ -static void -gre_tunnel_last_lock_gone (fib_node_t * node) -{ - /* - * The MPLS GRE tunnel is a root of the graph. As such - * it never has children and thus is never locked. - */ - ASSERT (0); -} - -/* - * Virtual function table registered by MPLS GRE tunnels - * for participation in the FIB object graph. - */ -const static fib_node_vft_t gre_vft = { - .fnv_get = gre_tunnel_fib_node_get, - .fnv_last_lock = gre_tunnel_last_lock_gone, - .fnv_back_walk = gre_tunnel_back_walk, -}; - static int -vnet_gre_tunnel_add (vnet_gre_add_del_tunnel_args_t * a, +vnet_gre_tunnel_add (vnet_gre_tunnel_add_del_args_t * a, u32 outer_fib_index, u32 * sw_if_indexp) { gre_main_t *gm = &gre_main; @@ -280,7 +191,7 @@ vnet_gre_tunnel_add (vnet_gre_add_del_tunnel_args_t * a, return VNET_API_ERROR_IF_ALREADY_EXISTS; pool_get_aligned (gm->tunnels, t, CLIB_CACHE_LINE_BYTES); - memset (t, 0, sizeof (*t)); + clib_memset (t, 0, sizeof (*t)); /* Reconcile the real dev_instance and a possible requested instance */ u32 t_idx = t - gm->tunnels; /* tunnel index (or instance) */ @@ -296,9 +207,8 @@ vnet_gre_tunnel_add (vnet_gre_add_del_tunnel_args_t * a, t->dev_instance = t_idx; /* actual */ t->user_instance = u_idx; /* name */ - fib_node_init (&t->node, FIB_NODE_TYPE_GRE_TUNNEL); - t->type = a->tunnel_type; + t->type = a->type; if (t->type == GRE_TUNNEL_TYPE_ERSPAN) t->session_id = a->session_id; @@ -348,11 +258,8 @@ vnet_gre_tunnel_add (vnet_gre_add_del_tunnel_args_t * a, 64 + sizeof (gre_header_t) + sizeof (ip6_header_t); } - hi->per_packet_overhead_bytes = - /* preamble */ 8 + /* inter frame gap */ 12; - /* Standard default gre MTU. */ - hi->max_l3_packet_bytes[VLIB_RX] = hi->max_l3_packet_bytes[VLIB_TX] = 9000; + vnet_sw_interface_set_mtu (vnm, sw_if_index, 9000); /* * source the FIB entry for the tunnel's destination @@ -389,11 +296,6 @@ vnet_gre_tunnel_add (vnet_gre_add_del_tunnel_args_t * a, } } - t->fib_entry_index = fib_table_entry_special_add - (outer_fib_index, &t->tunnel_dst, FIB_SOURCE_RR, FIB_ENTRY_FLAG_NONE); - t->sibling_index = fib_entry_child_add - (t->fib_entry_index, FIB_NODE_TYPE_GRE_TUNNEL, t_idx); - if (t->type != GRE_TUNNEL_TYPE_L3) { t->l2_adj_index = adj_nbr_add_or_lock @@ -408,7 +310,7 @@ vnet_gre_tunnel_add (vnet_gre_add_del_tunnel_args_t * a, } static int -vnet_gre_tunnel_delete (vnet_gre_add_del_tunnel_args_t * a, +vnet_gre_tunnel_delete (vnet_gre_tunnel_add_del_args_t * a, u32 outer_fib_index, u32 * sw_if_indexp) { gre_main_t *gm = &gre_main; @@ -425,7 +327,8 @@ 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); + set_int_l2_mode (gm->vlib_main, vnm, MODE_L3, sw_if_index, 0, + L2_BD_PORT_TYPE_NORMAL, 0, 0); gm->tunnel_index_by_sw_if_index[sw_if_index] = ~0; if (t->type == GRE_TUNNEL_TYPE_L3) @@ -434,10 +337,10 @@ vnet_gre_tunnel_delete (vnet_gre_add_del_tunnel_args_t * a, ethernet_delete_interface (vnm, t->hw_if_index); if (t->l2_adj_index != ADJ_INDEX_INVALID) - adj_unlock (t->l2_adj_index); - - fib_entry_child_remove (t->fib_entry_index, t->sibling_index); - fib_table_entry_delete_index (t->fib_entry_index, FIB_SOURCE_RR); + { + adj_midchain_delegate_unstack (t->l2_adj_index); + adj_unlock (t->l2_adj_index); + } ASSERT ((t->type != GRE_TUNNEL_TYPE_ERSPAN) || (t->gre_sn != NULL)); if ((t->type == GRE_TUNNEL_TYPE_ERSPAN) && (t->gre_sn->ref_count-- == 1)) @@ -450,7 +353,6 @@ vnet_gre_tunnel_delete (vnet_gre_add_del_tunnel_args_t * a, hash_unset (gm->instance_used, t->user_instance); gre_tunnel_db_remove (t); - fib_node_deinit (&t->node); pool_put (gm->tunnels, t); if (sw_if_indexp) @@ -460,7 +362,7 @@ vnet_gre_tunnel_delete (vnet_gre_add_del_tunnel_args_t * a, } int -vnet_gre_add_del_tunnel (vnet_gre_add_del_tunnel_args_t * a, +vnet_gre_tunnel_add_del (vnet_gre_tunnel_add_del_args_t * a, u32 * sw_if_indexp) { u32 outer_fib_index; @@ -521,7 +423,7 @@ create_gre_tunnel_command_fn (vlib_main_t * vm, vlib_cli_command_t * cmd) { unformat_input_t _line_input, *line_input = &_line_input; - vnet_gre_add_del_tunnel_args_t _a, *a = &_a; + vnet_gre_tunnel_add_del_args_t _a, *a = &_a; ip46_address_t src, dst; u32 instance = ~0; u32 outer_fib_id = 0; @@ -607,10 +509,10 @@ create_gre_tunnel_command_fn (vlib_main_t * vm, goto done; } - memset (a, 0, sizeof (*a)); + clib_memset (a, 0, sizeof (*a)); a->is_add = is_add; a->outer_fib_id = outer_fib_id; - a->tunnel_type = t_type; + a->type = t_type; a->session_id = session_id; a->is_ipv6 = ipv6_set; a->instance = instance; @@ -625,7 +527,7 @@ create_gre_tunnel_command_fn (vlib_main_t * vm, clib_memcpy (&a->dst.ip6, &dst.ip6, sizeof (dst.ip6)); } - rv = vnet_gre_add_del_tunnel (a, &sw_if_index); + rv = vnet_gre_tunnel_add_del (a, &sw_if_index); switch (rv) { @@ -652,7 +554,7 @@ create_gre_tunnel_command_fn (vlib_main_t * vm, goto done; default: error = - clib_error_return (0, "vnet_gre_add_del_tunnel returned %d", rv); + clib_error_return (0, "vnet_gre_tunnel_add_del returned %d", rv); goto done; } @@ -721,9 +623,7 @@ VLIB_CLI_COMMAND (show_gre_tunnel_command, static) = { clib_error_t * gre_interface_init (vlib_main_t * vm) { - fib_node_register_type (FIB_NODE_TYPE_GRE_TUNNEL, &gre_vft); - - return 0; + return (NULL); } VLIB_INIT_FUNCTION (gre_interface_init);