X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvnet%2Fgre%2Finterface.c;h=bb0be865664a70ba9520b2640342c395bd75ca02;hb=4da8a63a9;hp=b9bfb79c172393a7d90df853e648a4fb9b30e017;hpb=521a8d7df423a0b5aaf259d49ca9230705bc25ee;p=vpp.git diff --git a/src/vnet/gre/interface.c b/src/vnet/gre/interface.c index b9bfb79c172..bb0be865664 100644 --- a/src/vnet/gre/interface.c +++ b/src/vnet/gre/interface.c @@ -16,17 +16,31 @@ */ #include -#include #include #include -#include -#include +#include #include #include #include #include +#include -static const char *gre_tunnel_type_names[] = GRE_TUNNEL_TYPE_NAMES; +u8 * +format_gre_tunnel_type (u8 * s, va_list * args) +{ + gre_tunnel_type_t type = va_arg (*args, int); + + switch (type) + { +#define _(n, v) case GRE_TUNNEL_TYPE_##n: \ + s = format (s, "%s", v); \ + break; + foreach_gre_tunnel_type +#undef _ + } + + return (s); +} static u8 * format_gre_tunnel (u8 * s, va_list * args) @@ -39,7 +53,8 @@ format_gre_tunnel (u8 * s, va_list * args) format_ip46_address, &t->tunnel_dst.fp_addr, IP46_TYPE_ANY, t->outer_fib_index, t->sw_if_index); - s = format (s, "payload %s ", gre_tunnel_type_names[t->type]); + s = format (s, "payload %U ", format_gre_tunnel_type, t->type); + s = format (s, "%U ", format_tunnel_mode, t->mode); if (t->type == GRE_TUNNEL_TYPE_ERSPAN) s = format (s, "session %d ", t->session_id); @@ -51,7 +66,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; @@ -60,13 +75,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->mode, 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->mode, a->session_id, &key->gtk_v6); p = hash_get_mem (gm->tunnel_by_key6, &key->gtk_v6); } @@ -81,43 +96,29 @@ gre_tunnel_db_add (gre_tunnel_t * t, gre_tunnel_key_t * key) { gre_main_t *gm = &gre_main; - t->key = clib_mem_alloc (sizeof (*t->key)); - clib_memcpy (t->key, key, sizeof (*key)); - if (t->tunnel_dst.fp_proto == FIB_PROTOCOL_IP6) { - hash_set_mem (gm->tunnel_by_key6, &t->key->gtk_v6, t->dev_instance); + hash_set_mem_alloc (&gm->tunnel_by_key6, &key->gtk_v6, t->dev_instance); } else { - hash_set_mem (gm->tunnel_by_key4, &t->key->gtk_v4, t->dev_instance); + hash_set_mem_alloc (&gm->tunnel_by_key4, &key->gtk_v4, t->dev_instance); } } static void -gre_tunnel_db_remove (gre_tunnel_t * t) +gre_tunnel_db_remove (gre_tunnel_t * t, gre_tunnel_key_t * key) { gre_main_t *gm = &gre_main; if (t->tunnel_dst.fp_proto == FIB_PROTOCOL_IP6) { - hash_unset_mem (gm->tunnel_by_key6, &t->key->gtk_v6); + hash_unset_mem_free (&gm->tunnel_by_key6, &key->gtk_v6); } else { - hash_unset_mem (gm->tunnel_by_key4, &t->key->gtk_v4); + hash_unset_mem_free (&gm->tunnel_by_key4, &key->gtk_v4); } - - clib_mem_free (t->key); - 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))); } /** @@ -146,14 +147,50 @@ 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); + adj_midchain_delegate_unstack (ai); } else { - adj_nbr_midchain_stack_on_fib_entry (ai, - gt->fib_entry_index, - fib_forw_chain_type_from_fib_proto - (gt->tunnel_dst.fp_proto)); + adj_midchain_delegate_stack (ai, gt->outer_fib_index, >->tunnel_dst); + } +} + +/** + * mgre_tunnel_stack + * + * 'stack' (resolve the recursion for) the tunnel's midchain adjacency + */ +static void +mgre_tunnel_stack (adj_index_t ai) +{ + gre_main_t *gm = &gre_main; + const ip_adjacency_t *adj; + const gre_tunnel_t *gt; + u32 sw_if_index; + + 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) || + (~0 == gm->tunnel_index_by_sw_if_index[sw_if_index])) + return; + + gt = pool_elt_at_index (gm->tunnels, + gm->tunnel_index_by_sw_if_index[sw_if_index]); + + if ((vnet_hw_interface_get_flags (vnet_get_main (), gt->hw_if_index) & + VNET_HW_INTERFACE_FLAG_LINK_UP) == 0) + { + adj_midchain_delegate_unstack (ai); + } + else + { + const teib_entry_t *ne; + + ne = teib_entry_find_46 (sw_if_index, adj->ia_nh_proto, + &adj->sub_type.nbr.next_hop); + if (NULL != ne) + teib_entry_adj_stack (ne, ai); } } @@ -167,6 +204,13 @@ gre_adj_walk_cb (adj_index_t ai, void *ctx) return (ADJ_WALK_RC_CONTINUE); } +static adj_walk_rc_t +mgre_adj_walk_cb (adj_index_t ai, void *ctx) +{ + mgre_tunnel_stack (ai); + + return (ADJ_WALK_RC_CONTINUE); +} static void gre_tunnel_restack (gre_tunnel_t * gt) @@ -178,71 +222,154 @@ gre_tunnel_restack (gre_tunnel_t * gt) */ FOR_EACH_FIB_IP_PROTOCOL (proto) { - adj_nbr_walk (gt->sw_if_index, proto, gre_adj_walk_cb, NULL); + switch (gt->mode) + { + case TUNNEL_MODE_P2P: + adj_nbr_walk (gt->sw_if_index, proto, gre_adj_walk_cb, NULL); + break; + case TUNNEL_MODE_MP: + adj_nbr_walk (gt->sw_if_index, proto, mgre_adj_walk_cb, NULL); + break; + } } } -/** - * 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) +static void +gre_teib_mk_key (const gre_tunnel_t * t, + const teib_entry_t * ne, gre_tunnel_key_t * key) { - gre_tunnel_restack (gre_tunnel_from_fib_node (node)); + const fib_prefix_t *nh; - return (FIB_NODE_BACK_WALK_CONTINUE); + nh = teib_entry_get_nh (ne); + + /* construct the key using mode P2P so it can be found in the DP */ + if (FIB_PROTOCOL_IP4 == nh->fp_proto) + gre_mk_key4 (t->tunnel_src.ip4, + nh->fp_addr.ip4, + teib_entry_get_fib_index (ne), + t->type, TUNNEL_MODE_P2P, 0, &key->gtk_v4); + else + gre_mk_key6 (&t->tunnel_src.ip6, + &nh->fp_addr.ip6, + teib_entry_get_fib_index (ne), + t->type, TUNNEL_MODE_P2P, 0, &key->gtk_v6); } /** - * Function definition to get a FIB node from its index + * An TEIB entry has been added */ -static fib_node_t * -gre_tunnel_fib_node_get (fib_node_index_t index) +static void +gre_teib_entry_added (const teib_entry_t * ne) { - gre_tunnel_t *gt; - gre_main_t *gm; + gre_main_t *gm = &gre_main; + const ip_address_t *nh; + gre_tunnel_key_t key; + gre_tunnel_t *t; + u32 sw_if_index; + u32 t_idx; + + sw_if_index = teib_entry_get_sw_if_index (ne); + if (vec_len (gm->tunnel_index_by_sw_if_index) < sw_if_index) + return; + + t_idx = gm->tunnel_index_by_sw_if_index[sw_if_index]; - gm = &gre_main; - gt = pool_elt_at_index (gm->tunnels, index); + if (INDEX_INVALID == t_idx) + return; + + /* entry has been added on an interface for which there is a GRE tunnel */ + t = pool_elt_at_index (gm->tunnels, t_idx); - return (>->node); + if (t->mode != TUNNEL_MODE_MP) + return; + + /* the next-hop (underlay) of the NHRP entry will form part of the key for + * ingress lookup to match packets to this interface */ + gre_teib_mk_key (t, ne, &key); + gre_tunnel_db_add (t, &key); + + /* update the rewrites for each of the adjacencies for this peer (overlay) + * using the next-hop (underlay) */ + mgre_walk_ctx_t ctx = { + .t = t, + .ne = ne + }; + nh = teib_entry_get_peer (ne); + adj_nbr_walk_nh (teib_entry_get_sw_if_index (ne), + (AF_IP4 == ip_addr_version (nh) ? + FIB_PROTOCOL_IP4 : + FIB_PROTOCOL_IP6), + &ip_addr_46 (nh), mgre_mk_complete_walk, &ctx); } -/** - * Function definition to inform the FIB node that its last lock has gone. - */ static void -gre_tunnel_last_lock_gone (fib_node_t * node) +gre_teib_entry_deleted (const teib_entry_t * ne) { - /* - * The MPLS GRE tunnel is a root of the graph. As such - * it never has children and thus is never locked. - */ - ASSERT (0); + gre_main_t *gm = &gre_main; + const ip_address_t *nh; + gre_tunnel_key_t key; + gre_tunnel_t *t; + u32 sw_if_index; + u32 t_idx; + + sw_if_index = teib_entry_get_sw_if_index (ne); + if (vec_len (gm->tunnel_index_by_sw_if_index) < sw_if_index) + return; + + t_idx = gm->tunnel_index_by_sw_if_index[sw_if_index]; + + if (INDEX_INVALID == t_idx) + return; + + t = pool_elt_at_index (gm->tunnels, t_idx); + + /* remove the next-hop as an ingress lookup key */ + gre_teib_mk_key (t, ne, &key); + gre_tunnel_db_remove (t, &key); + + nh = teib_entry_get_peer (ne); + + /* make all the adjacencies incomplete */ + adj_nbr_walk_nh (teib_entry_get_sw_if_index (ne), + (AF_IP4 == ip_addr_version (nh) ? + FIB_PROTOCOL_IP4 : + FIB_PROTOCOL_IP6), + &ip_addr_46 (nh), mgre_mk_incomplete_walk, t); } -/* - * 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 walk_rc_t +gre_tunnel_delete_teib_walk (index_t nei, void *ctx) +{ + gre_tunnel_t *t = ctx; + gre_tunnel_key_t key; + + gre_teib_mk_key (t, teib_entry_get (nei), &key); + gre_tunnel_db_remove (t, &key); + + return (WALK_CONTINUE); +} + +static walk_rc_t +gre_tunnel_add_teib_walk (index_t nei, void *ctx) +{ + gre_tunnel_t *t = ctx; + gre_tunnel_key_t key = {}; + + gre_teib_mk_key (t, teib_entry_get (nei), &key); + gre_tunnel_db_add (t, &key); + + return (WALK_CONTINUE); +} 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; vnet_main_t *vnm = gm->vnet_main; - ip4_main_t *im4 = &ip4_main; - ip6_main_t *im6 = &ip6_main; gre_tunnel_t *t; vnet_hw_interface_t *hi; u32 hw_if_index, sw_if_index; - clib_error_t *error; u8 is_ipv6 = a->is_ipv6; gre_tunnel_key_t key; @@ -267,33 +394,45 @@ 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; + t->mode = a->mode; + t->flags = a->flags; if (t->type == GRE_TUNNEL_TYPE_ERSPAN) t->session_id = a->session_id; if (t->type == GRE_TUNNEL_TYPE_L3) - hw_if_index = vnet_register_interface (vnm, gre_device_class.index, t_idx, - gre_hw_interface_class.index, - t_idx); + { + if (t->mode == TUNNEL_MODE_P2P) + hw_if_index = + vnet_register_interface (vnm, gre_device_class.index, t_idx, + gre_hw_interface_class.index, t_idx); + else + hw_if_index = + vnet_register_interface (vnm, gre_device_class.index, t_idx, + mgre_hw_interface_class.index, t_idx); + } else { + vnet_eth_interface_registration_t eir = {}; + /* Default MAC address (d00b:eed0:0000 + sw_if_index) */ u8 address[6] = { 0xd0, 0x0b, 0xee, 0xd0, (u8) (t_idx >> 8), (u8) t_idx }; - error = - ethernet_register_interface (vnm, gre_device_class.index, t_idx, - address, &hw_if_index, 0); - if (error) - { - clib_error_report (error); - return VNET_API_ERROR_INVALID_REGISTRATION; - } + + eir.dev_class_index = gre_device_class.index; + eir.dev_instance = t_idx; + eir.address = address; + hw_if_index = vnet_eth_register_interface (vnm, &eir); } /* Set GRE tunnel interface output node (not used for L3 payload) */ - vnet_set_interface_output_node (vnm, hw_if_index, gre_encap_node.index); + if (GRE_TUNNEL_TYPE_ERSPAN == t->type) + vnet_set_interface_output_node (vnm, hw_if_index, + gre_erspan_encap_node.index); + else + vnet_set_interface_output_node (vnm, hw_if_index, + gre_teb_encap_node.index); hi = vnet_get_hw_interface (vnm, hw_if_index); sw_if_index = hi->sw_if_index; @@ -308,15 +447,13 @@ vnet_gre_tunnel_add (vnet_gre_add_del_tunnel_args_t * a, if (!is_ipv6) { - vec_validate (im4->fib_index_by_sw_if_index, sw_if_index); - hi->min_packet_bytes = - 64 + sizeof (gre_header_t) + sizeof (ip4_header_t); + hi->frame_overhead = sizeof (gre_header_t) + sizeof (ip4_header_t); + hi->min_frame_size = hi->frame_overhead + 64; } else { - vec_validate (im6->fib_index_by_sw_if_index, sw_if_index); - hi->min_packet_bytes = - 64 + sizeof (gre_header_t) + sizeof (ip6_header_t); + hi->frame_overhead = sizeof (gre_header_t) + sizeof (ip6_header_t); + hi->min_frame_size = hi->frame_overhead + 64; } /* Standard default gre MTU. */ @@ -335,6 +472,10 @@ vnet_gre_tunnel_add (vnet_gre_add_del_tunnel_args_t * a, t->tunnel_dst.fp_addr = a->dst; gre_tunnel_db_add (t, &key); + + if (t->mode == TUNNEL_MODE_MP) + teib_walk_itf (t->sw_if_index, gre_tunnel_add_teib_walk, t); + if (t->type == GRE_TUNNEL_TYPE_ERSPAN) { gre_sn_key_t skey; @@ -357,26 +498,31 @@ 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 (t->tunnel_dst.fp_proto, VNET_LINK_ETHERNET, &zero_addr, sw_if_index); + vnet_set_interface_l3_output_node (gm->vlib_main, sw_if_index, + (u8 *) "tunnel-output-no-count"); gre_update_adj (vnm, t->sw_if_index, t->l2_adj_index); } - + else + { + vnet_set_interface_l3_output_node (gm->vlib_main, sw_if_index, + (u8 *) "tunnel-output"); + } if (sw_if_indexp) *sw_if_indexp = sw_if_index; + /* register gre46-input nodes */ + ip4_register_protocol (IP_PROTOCOL_GRE, gre4_input_node.index); + ip6_register_protocol (IP_PROTOCOL_GRE, gre6_input_node.index); + return 0; } 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; @@ -389,6 +535,9 @@ vnet_gre_tunnel_delete (vnet_gre_add_del_tunnel_args_t * a, if (NULL == t) return VNET_API_ERROR_NO_SUCH_ENTRY; + if (t->mode == TUNNEL_MODE_MP) + teib_walk_itf (t->sw_if_index, gre_tunnel_delete_teib_walk, t); + sw_if_index = t->sw_if_index; vnet_sw_interface_set_flags (vnm, sw_if_index, 0 /* down */ ); @@ -403,10 +552,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)) @@ -417,9 +566,9 @@ vnet_gre_tunnel_delete (vnet_gre_add_del_tunnel_args_t * a, clib_mem_free (t->gre_sn); } + vnet_reset_interface_l3_output_node (gm->vlib_main, sw_if_index); hash_unset (gm->instance_used, t->user_instance); - gre_tunnel_db_remove (t); - fib_node_deinit (&t->node); + gre_tunnel_db_remove (t, &key); pool_put (gm->tunnels, t); if (sw_if_indexp) @@ -429,15 +578,14 @@ 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; - if (!a->is_ipv6) - outer_fib_index = ip4_fib_index_from_table_id (a->outer_fib_id); - else - outer_fib_index = ip6_fib_index_from_table_id (a->outer_fib_id); + outer_fib_index = fib_table_find ((a->is_ipv6 ? + FIB_PROTOCOL_IP6 : + FIB_PROTOCOL_IP4), a->outer_table_id); if (~0 == outer_fib_index) return VNET_API_ERROR_NO_SUCH_FIB; @@ -445,6 +593,9 @@ vnet_gre_add_del_tunnel (vnet_gre_add_del_tunnel_args_t * a, if (a->session_id > GTK_SESSION_ID_MAX) return VNET_API_ERROR_INVALID_SESSION_ID; + if (a->mode == TUNNEL_MODE_MP && !ip46_address_is_zero (&a->dst)) + return (VNET_API_ERROR_INVALID_DST_ADDRESS); + if (a->is_add) return (vnet_gre_tunnel_add (a, outer_fib_index, sw_if_indexp)); else @@ -490,19 +641,19 @@ 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; - ip46_address_t src, dst; + vnet_gre_tunnel_add_del_args_t _a, *a = &_a; + ip46_address_t src = ip46_address_initializer, dst = + ip46_address_initializer; u32 instance = ~0; - u32 outer_fib_id = 0; + u32 outer_table_id = 0; gre_tunnel_type_t t_type = GRE_TUNNEL_TYPE_L3; + tunnel_mode_t t_mode = TUNNEL_MODE_P2P; + tunnel_encap_decap_flags_t flags = TUNNEL_ENCAP_DECAP_FLAG_NONE; u32 session_id = 0; int rv; - u32 num_m_args = 0; u8 is_add = 1; u32 sw_if_index; clib_error_t *error = NULL; - u8 ipv4_set = 0; - u8 ipv6_set = 0; /* Get a line of input. */ if (!unformat_user (input, unformat_line_input, line_input)) @@ -514,36 +665,23 @@ create_gre_tunnel_command_fn (vlib_main_t * vm, is_add = 0; else if (unformat (line_input, "instance %d", &instance)) ; - else - if (unformat (line_input, "src %U", unformat_ip4_address, &src.ip4)) - { - num_m_args++; - ipv4_set = 1; - } - else - if (unformat (line_input, "dst %U", unformat_ip4_address, &dst.ip4)) - { - num_m_args++; - ipv4_set = 1; - } - else - if (unformat (line_input, "src %U", unformat_ip6_address, &src.ip6)) - { - num_m_args++; - ipv6_set = 1; - } - else - if (unformat (line_input, "dst %U", unformat_ip6_address, &dst.ip6)) - { - num_m_args++; - ipv6_set = 1; - } - else if (unformat (line_input, "outer-fib-id %d", &outer_fib_id)) + else if (unformat (line_input, "src %U", unformat_ip46_address, &src)) + ; + else if (unformat (line_input, "dst %U", unformat_ip46_address, &dst)) + ; + else if (unformat (line_input, "outer-table-id %d", &outer_table_id)) ; + else if (unformat (line_input, "multipoint")) + t_mode = TUNNEL_MODE_MP; else if (unformat (line_input, "teb")) t_type = GRE_TUNNEL_TYPE_TEB; else if (unformat (line_input, "erspan %d", &session_id)) t_type = GRE_TUNNEL_TYPE_ERSPAN; + else + if (unformat + (line_input, "flags %U", unformat_tunnel_encap_decap_flags, + &flags)) + ; else { error = clib_error_return (0, "unknown input `%U'", @@ -552,49 +690,44 @@ create_gre_tunnel_command_fn (vlib_main_t * vm, } } - if (num_m_args < 2) + if (ip46_address_is_equal (&src, &dst)) { - error = clib_error_return (0, "mandatory argument(s) missing"); + error = clib_error_return (0, "src and dst are identical"); goto done; } - if ((ipv4_set && memcmp (&src.ip4, &dst.ip4, sizeof (src.ip4)) == 0) || - (ipv6_set && memcmp (&src.ip6, &dst.ip6, sizeof (src.ip6)) == 0)) + if (t_mode != TUNNEL_MODE_MP && ip46_address_is_zero (&dst)) { - error = clib_error_return (0, "src and dst are identical"); + error = clib_error_return (0, "destination address not specified"); goto done; } - if (ipv4_set && ipv6_set) - return clib_error_return (0, "both IPv4 and IPv6 addresses specified"); + if (ip46_address_is_zero (&src)) + { + error = clib_error_return (0, "source address not specified"); + goto done; + } - if ((ipv4_set && memcmp (&dst.ip4, &zero_addr.ip4, sizeof (dst.ip4)) == 0) - || (ipv6_set - && memcmp (&dst.ip6, &zero_addr.ip6, sizeof (dst.ip6)) == 0)) + if (ip46_address_is_ip4 (&src) != ip46_address_is_ip4 (&dst)) { - error = clib_error_return (0, "dst address cannot be zero"); + error = + clib_error_return (0, "src and dst address must be the same AF"); goto done; } clib_memset (a, 0, sizeof (*a)); a->is_add = is_add; - a->outer_fib_id = outer_fib_id; - a->tunnel_type = t_type; + a->outer_table_id = outer_table_id; + a->type = t_type; + a->mode = t_mode; a->session_id = session_id; - a->is_ipv6 = ipv6_set; + a->is_ipv6 = !ip46_address_is_ip4 (&src); a->instance = instance; - if (!ipv6_set) - { - clib_memcpy (&a->src.ip4, &src.ip4, sizeof (src.ip4)); - clib_memcpy (&a->dst.ip4, &dst.ip4, sizeof (dst.ip4)); - } - else - { - clib_memcpy (&a->src.ip6, &src.ip6, sizeof (src.ip6)); - clib_memcpy (&a->dst.ip6, &dst.ip6, sizeof (dst.ip6)); - } + a->flags = flags; + clib_memcpy (&a->src, &src, sizeof (a->src)); + clib_memcpy (&a->dst, &dst, sizeof (a->dst)); - rv = vnet_gre_add_del_tunnel (a, &sw_if_index); + rv = vnet_gre_tunnel_add_del (a, &sw_if_index); switch (rv) { @@ -606,8 +739,8 @@ create_gre_tunnel_command_fn (vlib_main_t * vm, error = clib_error_return (0, "GRE tunnel already exists..."); goto done; case VNET_API_ERROR_NO_SUCH_FIB: - error = clib_error_return (0, "outer fib ID %d doesn't exist\n", - outer_fib_id); + error = clib_error_return (0, "outer table ID %d doesn't exist\n", + outer_table_id); goto done; case VNET_API_ERROR_NO_SUCH_ENTRY: error = clib_error_return (0, "GRE tunnel doesn't exist"); @@ -621,7 +754,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; } @@ -635,7 +768,8 @@ done: VLIB_CLI_COMMAND (create_gre_tunnel_command, static) = { .path = "create gre tunnel", .short_help = "create gre tunnel src dst [instance ] " - "[outer-fib-id ] [teb | erspan ] [del]", + "[outer-fib-id ] [teb | erspan ] [del] " + "[multipoint]", .function = create_gre_tunnel_command_fn, }; /* *INDENT-ON* */ @@ -663,10 +797,10 @@ show_gre_tunnel_command_fn (vlib_main_t * vm, if (~0 == ti) { /* *INDENT-OFF* */ - pool_foreach (t, gm->tunnels, - ({ + pool_foreach (t, gm->tunnels) + { vlib_cli_output (vm, "%U", format_gre_tunnel, t); - })); + } /* *INDENT-ON* */ } else @@ -686,13 +820,18 @@ VLIB_CLI_COMMAND (show_gre_tunnel_command, static) = { }; /* *INDENT-ON* */ +const static teib_vft_t gre_teib_vft = { + .nv_added = gre_teib_entry_added, + .nv_deleted = gre_teib_entry_deleted, +}; + /* force inclusion from application's main.c */ clib_error_t * gre_interface_init (vlib_main_t * vm) { - fib_node_register_type (FIB_NODE_TYPE_GRE_TUNNEL, &gre_vft); + teib_register (&gre_teib_vft); - return 0; + return (NULL); } VLIB_INIT_FUNCTION (gre_interface_init);