-static void vl_api_gre_add_del_tunnel_t_handler
- (vl_api_gre_add_del_tunnel_t * mp)
-{
- vl_api_gre_add_del_tunnel_reply_t *rmp;
- int rv = 0;
- vnet_gre_add_del_tunnel_args_t _a, *a = &_a;
- u32 outer_fib_id;
- uword *p;
- ip4_main_t *im = &ip4_main;
- u32 sw_if_index = ~0;
-
- p = hash_get (im->fib_index_by_table_id, ntohl (mp->outer_fib_id));
- if (!p)
- {
- rv = VNET_API_ERROR_NO_SUCH_FIB;
- goto out;
- }
- outer_fib_id = p[0];
-
- /* Check src & dst are different */
- if ((mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 16) == 0) ||
- (!mp->is_ipv6 && memcmp (mp->src_address, mp->dst_address, 4) == 0))
- {
- rv = VNET_API_ERROR_SAME_SRC_DST;
- goto out;
- }
- memset (a, 0, sizeof (*a));
-
- a->is_add = mp->is_add;
- a->teb = mp->teb;
-
- /* ip addresses sent in network byte order */
- clib_memcpy (&(a->src), mp->src_address, 4);
- clib_memcpy (&(a->dst), mp->dst_address, 4);
-
- a->outer_fib_id = outer_fib_id;
- rv = vnet_gre_add_del_tunnel (a, &sw_if_index);
-
-out:
- /* *INDENT-OFF* */
- REPLY_MACRO2(VL_API_GRE_ADD_DEL_TUNNEL_REPLY,
- ({
- rmp->sw_if_index = ntohl (sw_if_index);
- }));
- /* *INDENT-ON* */
-}
-
-static void send_gre_tunnel_details
- (gre_tunnel_t * t, unix_shared_memory_queue_t * q, u32 context)
-{
- vl_api_gre_tunnel_details_t *rmp;
- ip4_main_t *im = &ip4_main;
-
- rmp = vl_msg_api_alloc (sizeof (*rmp));
- memset (rmp, 0, sizeof (*rmp));
- rmp->_vl_msg_id = ntohs (VL_API_GRE_TUNNEL_DETAILS);
- clib_memcpy (rmp->src_address, &(t->tunnel_src), 4);
- clib_memcpy (rmp->dst_address, &(t->tunnel_dst), 4);
- rmp->outer_fib_id = htonl (im->fibs[t->outer_fib_index].ft_table_id);
- rmp->teb = (GRE_TUNNEL_TYPE_TEB == t->type);
- rmp->sw_if_index = htonl (t->sw_if_index);
- rmp->context = context;
-
- vl_msg_api_send_shmem (q, (u8 *) & rmp);
-}
-
-static void
-vl_api_gre_tunnel_dump_t_handler (vl_api_gre_tunnel_dump_t * mp)
-{
- unix_shared_memory_queue_t *q;
- gre_main_t *gm = &gre_main;
- gre_tunnel_t *t;
- u32 sw_if_index;
-
- q = vl_api_client_index_to_input_queue (mp->client_index);
- if (q == 0)
- {
- return;
- }
-
- sw_if_index = ntohl (mp->sw_if_index);
-
- if (~0 == sw_if_index)
- {
- /* *INDENT-OFF* */
- pool_foreach (t, gm->tunnels,
- ({
- send_gre_tunnel_details(t, q, mp->context);
- }));
- /* *INDENT-ON* */
- }
- else
- {
- if ((sw_if_index >= vec_len (gm->tunnel_index_by_sw_if_index)) ||
- (~0 == gm->tunnel_index_by_sw_if_index[sw_if_index]))
- {
- return;
- }
- t = &gm->tunnels[gm->tunnel_index_by_sw_if_index[sw_if_index]];
- send_gre_tunnel_details (t, q, mp->context);
- }
-}
-