summaryrefslogtreecommitdiffstats
path: root/src/vnet/vxlan-gbp/vxlan_gbp.api
blob: 685666970003b808c895b9a0e102a295f57622ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/* Hey Emacs use -*- mode: C -*- */
/*
 * Copyright (c) 2018 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.
 */

option version = "1.1.1";
import "vnet/ip/ip_types.api";
import "vnet/interface_types.api";

enum vxlan_gbp_api_tunnel_mode
{
  VXLAN_GBP_API_TUNNEL_MODE_L2,
  VXLAN_GBP_API_TUNNEL_MODE_L3,
};

/** \brief Definition of a VXLAN GBP tunnel
    @param instance - optional unique custom device instance, else ~0.
    @param src - Source IP address
    @param dst - Destination IP address, can be multicast
    @param mcast_sw_if_index - Interface for multicast destination
    @param encap_table_id - Encap route table
    @param vni - The VXLAN Network Identifier, uint24
    @param sw_ifindex - Ignored in add message, set in details
*/
typedef vxlan_gbp_tunnel
{
  u32 instance;
  vl_api_address_t src;
  vl_api_address_t dst;
  vl_api_interface_index_t mcast_sw_if_index;
  u32 encap_table_id;
  u32 vni;
  vl_api_interface_index_t sw_if_index;
  vl_api_vxlan_gbp_api_tunnel_mode_t mode;
};

/** \brief Create or delete a VXLAN-GBP tunnel
    @param client_index - opaque cookie to identify the sender
    @param context - sender context, to match reply w/ request
    @param is_add - Use 1 to create the tunnel, 0 to remove it
*/
define vxlan_gbp_tunnel_add_del
{
  u32 client_index;
  u32 context;
  bool is_add [default=true];
  vl_api_vxlan_gbp_tunnel_t tunnel;
  option in_progress;
};

define vxlan_gbp_tunnel_add_del_reply
{
  u32 context;
  i32 retval;
  vl_api_interface_index_t sw_if_index;
  option in_progress;
};

define vxlan_gbp_tunnel_dump
{
  u32 client_index;
  u32 context;
  vl_api_interface_index_t sw_if_index [default=0xffffffff];
  option in_progress;
};

define vxlan_gbp_tunnel_details
{
  u32 context;
  vl_api_vxlan_gbp_tunnel_t tunnel;
  option in_progress;
};

/** \brief Interface set vxlan-bypass request
    @param client_index - opaque cookie to identify the sender
    @param context - sender context, to match reply w/ request
    @param sw_if_index - interface used to reach neighbor
    @param is_ipv6 - if non-zero, enable ipv6-vxlan-bypass, else ipv4-vxlan-bypass
    @param enable - if non-zero enable, else disable
*/
autoreply define sw_interface_set_vxlan_gbp_bypass
{
  u32 client_index;
  u32 context;
  vl_api_interface_index_t sw_if_index;
  bool is_ipv6;
  bool enable [default=true];
  option in_progress;
};
6d9ef } /* Keyword.Type */ .highlight .ld { color: #e6db74 } /* Literal.Date */ .highlight .m { color: #ae81ff } /* Literal.Number */ .highlight .s { color: #e6db74 } /* Literal.String */ .highlight .na { color: #a6e22e } /* Name.Attribute */ .highlight .nb { color: #f8f8f2 } /* Name.Builtin */ .highlight .nc { color: #a6e22e } /* Name.Class */ .highlight .no { color: #66d9ef } /* Name.Constant */ .highlight .nd { color: #a6e22e } /* Name.Decorator */ .highlight .ni { color: #f8f8f2 } /* Name.Entity */ .highlight .ne { color: #a6e22e } /* Name.Exception */ .highlight .nf { color: #a6e22e } /* Name.Function */ .highlight .nl { color: #f8f8f2 } /* Name.Label */ .highlight .nn { color: #f8f8f2 } /* Name.Namespace */ .highlight .nx { color: #a6e22e } /* Name.Other */ .highlight .py { color: #f8f8f2 } /* Name.Property */ .highlight .nt { color: #f92672 } /* Name.Tag */ .highlight .nv { color: #f8f8f2 } /* Name.Variable */ .highlight .ow { color: #f92672 } /* Operator.Word */ .highlight .w { color: #f8f8f2 } /* Text.Whitespace */ .highlight .mb { color: #ae81ff } /* Literal.Number.Bin */ .highlight .mf { color: #ae81ff } /* Literal.Number.Float */ .highlight .mh { color: #ae81ff } /* Literal.Number.Hex */ .highlight .mi { color: #ae81ff } /* Literal.Number.Integer */ .highlight .mo { color: #ae81ff } /* Literal.Number.Oct */ .highlight .sa { color: #e6db74 } /* Literal.String.Affix */ .highlight .sb { color: #e6db74 } /* Literal.String.Backtick */ .highlight .sc { color: #e6db74 } /* Literal.String.Char */ .highlight .dl { color: #e6db74 } /* Literal.String.Delimiter */ .highlight .sd { color: #e6db74 } /* Literal.String.Doc */ .highlight .s2 { color: #e6db74 } /* Literal.String.Double */ .highlight .se { color: #ae81ff } /* Literal.String.Escape */ .highlight .sh { color: #e6db74 } /* Literal.String.Heredoc */ .highlight .si { color: #e6db74 } /* Literal.String.Interpol */ .highlight .sx { color: #e6db74 } /* Literal.String.Other */ .highlight .sr { color: #e6db74 } /* Literal.String.Regex */ .highlight .s1 { color: #e6db74 } /* Literal.String.Single */ .highlight .ss { color: #e6db74 } /* Literal.String.Symbol */ .highlight .bp { color: #f8f8f2 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #a6e22e } /* Name.Function.Magic */ .highlight .vc { color: #f8f8f2 } /* Name.Variable.Class */ .highlight .vg { color: #f8f8f2 } /* Name.Variable.Global */ .highlight .vi { color: #f8f8f2 } /* Name.Variable.Instance */ .highlight .vm { color: #f8f8f2 } /* Name.Variable.Magic */ .highlight .il { color: #ae81ff } /* Literal.Number.Integer.Long */ } @media (prefers-color-scheme: light) { .highlight .hll { background-color: #ffffcc } .highlight .c { color: #888888 } /* Comment */ .highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */ .highlight .k { color: #008800; font-weight: bold } /* Keyword */ .highlight .ch { color: #888888 } /* Comment.Hashbang */ .highlight .cm { color: #888888 } /* Comment.Multiline */ .highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */ .highlight .cpf { color: #888888 } /* Comment.PreprocFile */ .highlight .c1 { color: #888888 } /* Comment.Single */ .highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */ .highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .gr { color: #aa0000 } /* Generic.Error */ .highlight .gh { color: #333333 } /* Generic.Heading */ .highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */ .highlight .go { color: #888888 } /* Generic.Output */ .highlight .gp { color: #555555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */ }
/*
 *------------------------------------------------------------------
 * Copyright (c) 2017 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.
 *------------------------------------------------------------------
 */

#include <igmp/igmp.h>

#include <vlibapi/api.h>
#include <vlibmemory/api.h>
#include <vnet/ip/ip_types_api.h>
#include <igmp/igmp_ssm_range.h>

/* define message IDs */
#include <igmp/igmp.api_enum.h>
#include <igmp/igmp.api_types.h>
#include <vnet/format_fns.h>

#include <vlibapi/api_helper_macros.h>

#define IGMP_MSG_ID(_id) (_id + igmp_main.msg_id_base)

static void
vl_api_igmp_listen_t_handler (vl_api_igmp_listen_t * mp)
{
  vlib_main_t *vm = vlib_get_main ();
  vnet_main_t *vnm = vnet_get_main ();
  vl_api_igmp_listen_reply_t *rmp;
  int ii, rv = 0;
  ip46_address_t gaddr, *saddrs = NULL;

  VALIDATE_SW_IF_INDEX (&mp->group);

  if ((vnet_sw_interface_get_flags (vnm, ntohl (mp->group.sw_if_index)) &&
       VNET_SW_INTERFACE_FLAG_ADMIN_UP) == 0)
    {
      // FIXME - don't we clear this state on interface down ...
      rv = VNET_API_ERROR_UNEXPECTED_INTF_STATE;
      goto done;
    }

  clib_memset (&gaddr, 0, sizeof (gaddr));
  clib_memcpy (&gaddr.ip4, &mp->group.gaddr, sizeof (ip4_address_t));

  vec_validate (saddrs, mp->group.n_srcs - 1);

  vec_foreach_index (ii, saddrs)
  {
    clib_memcpy (&saddrs[ii].ip4,
		 &mp->group.saddrs[ii], sizeof (ip4_address_t));
  }

  rv = igmp_listen (vm,
		    (mp->group.filter ?
		     IGMP_FILTER_MODE_INCLUDE :
		     IGMP_FILTER_MODE_EXCLUDE),
		    ntohl (mp->group.sw_if_index), saddrs, &gaddr);

  vec_free (saddrs);

  BAD_SW_IF_INDEX_LABEL;
done:;
  REPLY_MACRO (IGMP_MSG_ID (VL_API_IGMP_LISTEN_REPLY));
}

static void
vl_api_igmp_enable_disable_t_handler (vl_api_igmp_enable_disable_t * mp)
{
  vl_api_igmp_enable_disable_reply_t *rmp;
  int rv = 0;

  VALIDATE_SW_IF_INDEX (mp);

  rv = igmp_enable_disable (ntohl (mp->sw_if_index),
			    mp->enable,
			    (mp->mode ? IGMP_MODE_HOST : IGMP_MODE_ROUTER));

  BAD_SW_IF_INDEX_LABEL;

  REPLY_MACRO (IGMP_MSG_ID (VL_API_IGMP_ENABLE_DISABLE_REPLY));
}

static void
vl_api_igmp_proxy_device_add_del_t_handler (vl_api_igmp_proxy_device_add_del_t
					    * mp)
{
  vl_api_igmp_proxy_device_add_del_reply_t *rmp;
  int rv = 0;

  VALIDATE_SW_IF_INDEX (mp);

  rv =
    igmp_proxy_device_add_del (ntohl (mp->vrf_id), ntohl (mp->sw_if_index),
			       mp->add);

  BAD_SW_IF_INDEX_LABEL;

  REPLY_MACRO (IGMP_MSG_ID (VL_API_IGMP_PROXY_DEVICE_ADD_DEL_REPLY));
}

static void
  vl_api_igmp_proxy_device_add_del_interface_t_handler
  (vl_api_igmp_proxy_device_add_del_interface_t * mp)
{
  vl_api_igmp_proxy_device_add_del_interface_reply_t *rmp;
  int rv = 0;

  VALIDATE_SW_IF_INDEX (mp);

  rv =
    igmp_proxy_device_add_del_interface (ntohl (mp->vrf_id),
					 ntohl (mp->sw_if_index), mp->add);

  BAD_SW_IF_INDEX_LABEL;

  REPLY_MACRO (IGMP_MSG_ID
	       (VL_API_IGMP_PROXY_DEVICE_ADD_DEL_INTERFACE_REPLY));
}

static void
send_igmp_details (vl_api_registration_t * rp, igmp_main_t * im,
		   igmp_config_t * config, igmp_group_t * group,
		   igmp_src_t * src, u32 context)
{
  vl_api_igmp_details_t *mp;

  mp = vl_msg_api_alloc (sizeof (*mp));
  clib_memset (mp, 0, sizeof (*mp));

  mp->_vl_msg_id = htons (IGMP_MSG_ID (VL_API_IGMP_DETAILS));
  mp->context = context;
  mp->sw_if_index = htonl (config->sw_if_index);
  clib_memcpy (&mp->saddr, &src->key->ip4, sizeof (src->key->ip4));
  clib_memcpy (&mp->gaddr, &group->key->ip4, sizeof (group->key->ip4));

  vl_api_send_msg (rp, (u8 *) mp);
}

static void
igmp_config_dump (igmp_main_t * im,
		  vl_api_registration_t * rp,
		  u32 context, igmp_config_t * config)
{
  igmp_group_t *group;
  igmp_src_t *src;

  /* *INDENT-OFF* */
  FOR_EACH_GROUP (group, config,
    ({
      FOR_EACH_SRC (src, group, IGMP_FILTER_MODE_INCLUDE,
        ({
          send_igmp_details (rp, im, config, group, src, context);
        }));
    }));
  /* *INDENT-ON* */
}

static void
vl_api_igmp_dump_t_handler (vl_api_igmp_dump_t * mp)
{
  igmp_main_t *im = &igmp_main;
  igmp_config_t *config;
  u32 sw_if_index;
  vl_api_registration_t *rp;

  rp = vl_api_client_index_to_registration (mp->client_index);
  if (rp == 0)
    return;

  sw_if_index = ntohl (mp->sw_if_index);
  if (~0 == sw_if_index)
    {
      /* *INDENT-OFF* */
      pool_foreach (config, im->configs,
        ({
          igmp_config_dump(im, rp, mp->context, config);
        }));
      /* *INDENT-ON* */
    }
  else
    {
      config = igmp_config_lookup (sw_if_index);
      if (config)
	{
	  igmp_config_dump (im, rp, mp->context, config);
	}
    }
}

static void
vl_api_igmp_clear_interface_t_handler (vl_api_igmp_clear_interface_t * mp)
{
  vl_api_igmp_clear_interface_reply_t *rmp;
  igmp_config_t *config;
  int rv = 0;

  config = igmp_config_lookup (ntohl (mp->sw_if_index));
  if (config)
    igmp_clear_config (config);

  REPLY_MACRO (IGMP_MSG_ID (VL_API_IGMP_CLEAR_INTERFACE_REPLY));
}

static vl_api_group_prefix_type_t
igmp_group_type_int_to_api (igmp_group_prefix_type_t t)
{
  switch (t)
    {
    case IGMP_GROUP_PREFIX_TYPE_ASM:
      return (htonl (ASM));
    case IGMP_GROUP_PREFIX_TYPE_SSM:
      return (htonl (SSM));
    }

  return (SSM);
}

static igmp_group_prefix_type_t
igmp_group_type_api_to_int (vl_api_group_prefix_type_t t)
{
  switch (htonl (t))
    {
    case ASM:
      return (IGMP_GROUP_PREFIX_TYPE_ASM);
    case SSM:
      return (IGMP_GROUP_PREFIX_TYPE_SSM);
    }

  return (IGMP_GROUP_PREFIX_TYPE_SSM);
}

static void
vl_api_igmp_group_prefix_set_t_handler (vl_api_igmp_group_prefix_set_t * mp)
{
  vl_api_igmp_group_prefix_set_reply_t *rmp;
  fib_prefix_t pfx;
  int rv = 0;

  ip_prefix_decode (&mp->gp.prefix, &pfx);
  igmp_group_prefix_set (&pfx, igmp_group_type_api_to_int (mp->gp.type));

  REPLY_MACRO (IGMP_MSG_ID (VL_API_IGMP_GROUP_PREFIX_SET_REPLY));
}

typedef struct igmp_ssm_range_walk_ctx_t_
{
  vl_api_registration_t *rp;
  u32 context;
} igmp_ssm_range_walk_ctx_t;

static walk_rc_t
igmp_ssm_range_walk_dump (const fib_prefix_t * pfx,
			  igmp_group_prefix_type_t type, void *args)
{
  igmp_ssm_range_walk_ctx_t *ctx = args;
  vl_api_igmp_group_prefix_details_t *mp;

  mp = vl_msg_api_alloc (sizeof (*mp));
  clib_memset (mp, 0, sizeof (*mp));

  mp->_vl_msg_id = htons (IGMP_MSG_ID (VL_API_IGMP_DETAILS));
  mp->context = ctx->context;
  mp->gp.type = igmp_group_type_int_to_api (type);
  ip_prefix_encode (pfx, &mp->gp.prefix);

  vl_api_send_msg (ctx->rp, (u8 *) mp);

  return (WALK_CONTINUE);
}

static void
vl_api_igmp_group_prefix_dump_t_handler (vl_api_igmp_dump_t * mp)
{
  vl_api_registration_t *rp;

  rp = vl_api_client_index_to_registration (mp->client_index);
  if (rp == 0)
    return;

  igmp_ssm_range_walk_ctx_t ctx = {
    .rp = rp,
    .context = mp->context,
  };

  igmp_ssm_range_walk (igmp_ssm_range_walk_dump, &ctx);
}

static vpe_client_registration_t *
igmp_api_client_lookup (igmp_main_t * im, u32 client_index)
{
  uword *p;
  vpe_client_registration_t *api_client = NULL;

  p = hash_get (im->igmp_api_client_by_client_index, client_index);
  if (p)
    api_client = vec_elt_at_index (im->api_clients, p[0]);

  return api_client;
}

static void
vl_api_want_igmp_events_t_handler (vl_api_want_igmp_events_t * mp)
{
  igmp_main_t *im = &igmp_main;
  vpe_client_registration_t *api_client;
  vl_api_want_igmp_events_reply_t *rmp;
  int rv = 0;

  api_client = igmp_api_client_lookup (im, mp->client_index);
  if (api_client)
    {
      if (mp->enable)
	{
	  rv = VNET_API_ERROR_INVALID_REGISTRATION;
	  goto done;
	}
      hash_unset (im->igmp_api_client_by_client_index,
		  api_client->client_index);
      pool_put (im->api_clients, api_client);
      goto done;
    }
  if (mp->enable)
    {
      pool_get (im->api_clients, api_client);
      clib_memset (api_client, 0, sizeof (vpe_client_registration_t));
      api_client->client_index = mp->client_index;
      api_client->client_pid = mp->pid;
      hash_set (im->igmp_api_client_by_client_index,
		mp->client_index, api_client - im->api_clients);
      goto done;
    }
  rv = VNET_API_ERROR_INVALID_REGISTRATION;

done:
  REPLY_MACRO (VL_API_WANT_IGMP_EVENTS_REPLY + im->msg_id_base);
}

static clib_error_t *
want_igmp_events_reaper (u32 client_index)
{
  igmp_main_t *im = &igmp_main;
  vpe_client_registration_t *api_client;
  uword *p;

  p = hash_get (im->igmp_api_client_by_client_index, client_index);

  if (p)
    {
      api_client = pool_elt_at_index (im->api_clients, p[0]);
      pool_put (im->api_clients, api_client);
      hash_unset (im->igmp_api_client_by_client_index, client_index);
    }
  return (NULL);
}

VL_MSG_API_REAPER_FUNCTION (want_igmp_events_reaper);

void
send_igmp_event (vl_api_registration_t * rp,
		 igmp_filter_mode_t filter,
		 u32 sw_if_index,
		 const ip46_address_t * saddr, const ip46_address_t * gaddr)
{
  vl_api_igmp_event_t *mp = vl_msg_api_alloc (sizeof (*mp));
  clib_memset (mp, 0, sizeof (*mp));

  mp->_vl_msg_id = ntohs ((VL_API_IGMP_EVENT) + igmp_main.msg_id_base);
  mp->sw_if_index = htonl (sw_if_index);
  mp->filter = htonl (filter);
  clib_memcpy (&mp->saddr, &saddr->ip4, sizeof (ip4_address_t));
  clib_memcpy (&mp->gaddr, &gaddr->ip4, sizeof (ip4_address_t));

  vl_api_send_msg (rp, (u8 *) mp);
}

void
igmp_event (igmp_filter_mode_t filter,
	    u32 sw_if_index,
	    const ip46_address_t * saddr, const ip46_address_t * gaddr)
{
  vpe_client_registration_t *api_client;
  vl_api_registration_t *rp;
  igmp_main_t *im;

  im = &igmp_main;

  IGMP_DBG ("event: (%U, %U) %U %U",
	    format_ip46_address, saddr, IP46_TYPE_ANY,
	    format_ip46_address, saddr, IP46_TYPE_ANY,
	    format_vnet_sw_if_index_name,
	    vnet_get_main (), sw_if_index, format_igmp_filter_mode, filter);


  /* *INDENT-OFF* */
  pool_foreach (api_client, im->api_clients,
    ({
      rp = vl_api_client_index_to_registration (api_client->client_index);
      if (rp)
        send_igmp_event (rp, filter, sw_if_index, saddr, gaddr);
    }));
  /* *INDENT-ON* */
}

/* Set up the API message handling tables */
#include <igmp/igmp.api.c>
static clib_error_t *
igmp_plugin_api_hookup (vlib_main_t * vm)
{
  igmp_main_t *im = &igmp_main;

  /* Ask for a correctly-sized block of API message decode slots */
  im->msg_id_base = setup_message_id_table ();

  return 0;
}

VLIB_API_INIT_FUNCTION (igmp_plugin_api_hookup);

/*
 * fd.io coding-style-patch-verification: ON
 *
 * Local Variables:
 * eval: (c-set-style "gnu")
 * End:
 */