/*
  PIM for Quagga
  Copyright (C) 2008  Everton da Silva Marques

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful, but
  WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  General Public License for more details.
  
  You should have received a copy of the GNU General Public License
  along with this program; see the file COPYING; if not, write to the
  Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
  MA 02110-1301 USA
  
  $QuaggaId: $Format:%an, %ai, %h$ $
*/

#include <zebra.h>

#include "memory.h"

#include "pimd.h"
#include "pim_igmp.h"
#include "pim_igmpv3.h"
#include "pim_iface.h"
#include "pim_sock.h"
#include "pim_mroute.h"
#include "pim_str.h"
#include "pim_util.h"
#include "pim_time.h"
#include "pim_zebra.h"

#define IGMP_GRP_REC_TYPE_MODE_IS_INCLUDE        (1)
#define IGMP_GRP_REC_TYPE_MODE_IS_EXCLUDE        (2)
#define IGMP_GRP_REC_TYPE_CHANGE_TO_INCLUDE_MODE (3)
#define IGMP_GRP_REC_TYPE_CHANGE_TO_EXCLUDE_MODE (4)
#define IGMP_GRP_REC_TYPE_ALLOW_NEW_SOURCES      (5)
#define IGMP_GRP_REC_TYPE_BLOCK_OLD_SOURCES      (6)

static void group_timer_off(struct igmp_group *group);

static struct igmp_group *find_group_by_addr(struct igmp_sock *igmp,
					     struct in_addr group_addr);

static int igmp_sock_open(struct in_addr ifaddr, int ifindex, uint32_t pim_options)
{
  int fd;
  int join = 0;
  struct in_addr group;

  fd = pim_socket_mcast(IPPROTO_IGMP, ifaddr, 1 /* loop=true */);
  if (fd < 0)
    return -1;

  if (PIM_IF_TEST_IGMP_LISTEN_ALLROUTERS(pim_options)) {
    if (inet_aton(PIM_ALL_ROUTERS, &group)) {
      if (!pim_socket_join(fd, group, ifaddr, ifindex))
	++join;
    }
    else {
      zlog_warn("%s %s: IGMP socket fd=%d interface %s: could not solve %s to group address: errno=%d: %s",
		__FILE__, __PRETTY_FUNCTION__, fd, inet_ntoa(ifaddr),
		PIM_ALL_ROUTERS, errno, safe_strerror(errno));
    }
  }

  /*
    IGMP routers periodically send IGMP general queries to AllSystems=224.0.0.1
    IGMP routers must receive general queries for querier election.
  */
  if (inet_aton(PIM_ALL_SYSTEMS, &group)) {
    if (!pim_socket_join(fd, group, ifaddr, ifindex))
      ++join;
  }
  else {
    zlog_warn("%s %s: IGMP socket fd=%d interface %s: could not solve %s to group address: errno=%d: %s",
	      __FILE__, __PRETTY_FUNCTION__, fd, inet_ntoa(ifaddr),
	      PIM_ALL_SYSTEMS, errno, safe_strerror(errno));
  }

  if (inet_aton(PIM_ALL_IGMP_ROUTERS, &group)) {
    if (!pim_socket_join(fd, group, ifaddr, ifindex)) {
      ++join;
    }
  }
  else {
      zlog_warn("%s %s: IGMP socket fd=%d interface %s: could not solve %s to group address: errno=%d: %s",
		__FILE__, __PRETTY_FUNCTION__, fd, inet_ntoa(ifaddr),
		PIM_ALL_IGMP_ROUTERS, errno, safe_strerror(errno));
  }    

  if (!join) {
    zlog_err("IGMP socket fd=%d could not join any group on interface address %s",
	     fd, inet_ntoa(ifaddr));
    close(fd);
    fd = -1;
  }

  return fd;
}

#undef IGMP_SOCK_DUMP

#ifdef IGMP_SOCK_DUMP
static void igmp_sock_dump(array_t *igmp_sock_array)
{
  int size = array_size(igmp_sock_array);
  for (int i = 0; i < size; ++i) {
    
    struct igmp_sock *igmp = array_get(igmp_sock_array, i);
    
    zlog_debug("%s %s: [%d/%d] igmp_addr=%s fd=%d",
	       __FILE__, __PRETTY_FUNCTION__,
	       i, size,
	       inet_ntoa(igmp->ifaddr),
	       igmp->fd);
  }
}
#endif

struct igmp_sock *pim_igmp_sock_lookup_ifaddr(struct list *igmp_sock_list,
					      struct in_addr ifaddr)
{
  struct listnode  *sock_node;
  struct igmp_sock *igmp;

#ifdef IGMP_SOCK_DUMP
  igmp_sock_dump(igmp_sock_list);
#endif

  for (ALL_LIST_ELEMENTS_RO(igmp_sock_list, sock_node, igmp))
    if (ifaddr.s_addr == igmp->ifaddr.s_addr)
      return igmp;

  return 0;
}

struct igmp_sock *igmp_sock_lookup_by_fd(struct list *igmp_sock_list,
					 int fd)
{
  struct listnode  *sock_node;
  struct igmp_sock *igmp;

  for (ALL_LIST_ELEMENTS_RO(igmp_sock_list, sock_node, igmp))
    if (fd == igmp->fd)
      return igmp;

  return 0;
}

static int pim_igmp_other_querier_expire(struct thread *t)
{
  struct igmp_sock *igmp;

  zassert(t);
  igmp = THREAD_ARG(t);
  zassert(igmp);

  zassert(igmp->t_other_querier_timer);
  zassert(!igmp->t_igmp_query_timer);

  if (PIM_DEBUG_IGMP_TRACE) {
    char ifaddr_str[100];
    pim_inet4_dump("<ifaddr?>", igmp->ifaddr, ifaddr_str, sizeof(ifaddr_str));
    zlog_debug("%s: Querier %s resuming",
	       __PRETTY_FUNCTION__,
	       ifaddr_str);
  }

  igmp->t_other_querier_timer = 0;

  /*
    We are the current querier, then
    re-start sending general queries.
  */
  pim_igmp_general_query_on(igmp);

  return 0;
}

void pim_igmp_other_querier_timer_on(struct igmp_sock *igmp)
{
  long other_querier_present_interval_msec;
  struct pim_interface *pim_ifp;

  zassert(igmp);
  zassert(igmp->interface);
  zassert(igmp->interface->info);

  pim_ifp = igmp->interface->info;

  if (igmp->t_other_querier_timer) {
    /*
      There is other querier present already,
      then reset the other-querier-present timer.
    */

    if (PIM_DEBUG_IGMP_TRACE) {
      char ifaddr_str[100];
      pim_inet4_dump("<ifaddr?>", igmp->ifaddr, ifaddr_str, sizeof(ifaddr_str));
      zlog_debug("Querier %s resetting TIMER event for Other-Querier-Present",
		 ifaddr_str);
    }

    THREAD_OFF(igmp->t_other_querier_timer);
    zassert(!igmp->t_other_querier_timer);
  }
  else {
    /*
      We are the current querier, then stop sending general queries:
      igmp->t_igmp_query_timer = 0;
    */
    pim_igmp_general_query_off(igmp);
  }

  /*
    Since this socket is starting the other-querier-present timer,
    there should not be periodic query timer for this socket.
   */
  zassert(!igmp->t_igmp_query_timer);

  /*
    RFC 3376: 8.5. Other Querier Present Interval

    The Other Querier Present Interval is the length of time that must
    pass before a multicast router decides that there is no longer
    another multicast router which should be the querier.  This value
    MUST be ((the Robustness Variable) times (the Query Interval)) plus
    (one half of one Query Response Interval).

    other_querier_present_interval_msec = \
      igmp->querier_robustness_variable * \
      1000 * igmp->querier_query_interval + \
      100 * (pim_ifp->query_max_response_time_dsec >> 1);
  */
  other_querier_present_interval_msec =
    PIM_IGMP_OQPI_MSEC(igmp->querier_robustness_variable,
		       igmp->querier_query_interval,
		       pim_ifp->igmp_query_max_response_time_dsec);
  
  if (PIM_DEBUG_IGMP_TRACE) {
    char ifaddr_str[100];
    pim_inet4_dump("<ifaddr?>", igmp->ifaddr, ifaddr_str, sizeof(ifaddr_str));
    zlog_debug("Querier %s scheduling %ld.%03ld sec TIMER event for Other-Querier-Present",
	       ifaddr_str,
	       other_querier_present_interval_msec / 1000,
	       other_querier_present_interval_msec % 1000);
  }
  
  THREAD_TIMER_MSEC_ON(master, igmp->t_other_querier_timer,
		       pim_igmp_other_querier_expire,
		       igmp, other_querier_present_interval_msec);
}

void pim_igmp_other_querier_timer_off(struct igmp_sock *igmp)
{
  zassert(igmp);

  if (PIM_DEBUG_IGMP_TRACE) {
    if (igmp->t_other_querier_timer) {
      char ifaddr_str[100];
      pim_inet4_dump("<ifaddr?>", igmp->ifaddr, ifaddr_str, sizeof(ifaddr_str));
      zlog_debug("IGMP querier %s fd=%d cancelling other-querier-present TIMER event on %s",
		 ifaddr_str, igmp->fd, igmp->interface->name);
    }
  }
  THREAD_OFF(igmp->t_other_querier_timer);
  zassert(!igmp->t_other_querier_timer);
}

static int recv_igmp_query(struct igmp_sock *igmp, int query_version,
			   int max_resp_code,
			   struct in_addr from, const char *from_str,
			   char *igmp_msg, int igmp_msg_len)
{
  struct interface     *ifp;
  struct pim_interface *pim_ifp;
  uint8_t               resv_s_qrv;
  uint8_t               s_flag;
  uint8_t               qrv;
  struct in_addr        group_addr;
  uint16_t              recv_checksum;
  uint16_t              checksum;

  group_addr = *(struct in_addr *)(igmp_msg + 4);

  ifp = igmp->interface;
  pim_ifp = ifp->info;

  recv_checksum = *(uint16_t *) (igmp_msg + IGMP_V3_CHECKSUM_OFFSET);

  /* for computing checksum */
  *(uint16_t *) (igmp_msg + IGMP_V3_CHECKSUM_OFFSET) = 0;

  checksum = pim_inet_checksum(igmp_msg, igmp_msg_len);
  if (checksum != recv_checksum) {
    zlog_warn("Recv IGMP query v%d from %s on %s: checksum mismatch: received=%x computed=%x",
	      query_version, from_str, ifp->name, recv_checksum, checksum);
    return -1;
  }

  if (PIM_DEBUG_IGMP_PACKETS) {
    char group_str[100];
    pim_inet4_dump("<group?>", group_addr, group_str, sizeof(group_str));
    zlog_debug("Recv IGMP query v%d from %s on %s: size=%d checksum=%x group=%s",
	       query_version, from_str, ifp->name,
	       igmp_msg_len, checksum, group_str);
  }

  /*
    RFC 3376: 6.6.2. Querier Election

    When a router receives a query with a lower IP address, it sets
    the Other-Querier-Present timer to Other Querier Present Interval
    and ceases to send queries on the network if it was the previously
    elected querier.
   */
  if (ntohl(from.s_addr) < ntohl(igmp->ifaddr.s_addr)) {
    
    if (PIM_DEBUG_IGMP_TRACE) {
      char ifaddr_str[100];
      pim_inet4_dump("<ifaddr?>", igmp->ifaddr, ifaddr_str, sizeof(ifaddr_str));
      zlog_debug("%s: local address %s (%u) lost querier election to %s (%u)",
		 ifp->name,
		 ifaddr_str, ntohl(igmp->ifaddr.s_addr),
		 from_str, ntohl(from.s_addr));
    }

    pim_igmp_other_querier_timer_on(igmp);
  }

  /*
    RFC 3376: 4.1.6. QRV (Querier's Robustness Variable)

    Routers adopt the QRV value from the most recently received Query
    as their own [Robustness Variable] value, unless that most
    recently received QRV was zero, in which case the receivers use
    the default [Robustness Variable] value specified in section 8.1
    or a statically configured value.
  */
  resv_s_qrv = igmp_msg[8];
  qrv = 7 & resv_s_qrv;
  igmp->querier_robustness_variable = qrv ? qrv : pim_ifp->igmp_default_robustness_variable;

  /*
    RFC 3376: 4.1.7. QQIC (Querier's Query Interval Code)

    Multicast routers that are not the current querier adopt the QQI
    value from the most recently received Query as their own [Query
    Interval] value, unless that most recently received QQI was zero,
    in which case the receiving routers use the default.
  */
  if (igmp->t_other_querier_timer) {
    /* other querier present */
    uint8_t  qqic;
    uint16_t qqi;
    qqic = igmp_msg[9];
    qqi = igmp_msg_decode8to16(qqic);
    igmp->querier_query_interval = qqi ? qqi : pim_ifp->igmp_default_query_interval;

    if (PIM_DEBUG_IGMP_TRACE) {
      char ifaddr_str[100];
      pim_inet4_dump("<ifaddr?>", igmp->ifaddr, ifaddr_str, sizeof(ifaddr_str));
      zlog_debug("Querier %s new query interval is %s QQI=%u sec (recv QQIC=%02x from %s)",
		 ifaddr_str,
		 qqi ? "recv-non-default" : "default",
		 igmp->querier_query_interval,
		 qqic,
		 from_str);
    }
  }

  /*
    RFC 3376: 6.6.1. Timer Updates

    When a router sends or receives a query with a clear Suppress
    Router-Side Processing flag, it must update its timers to reflect
    the correct timeout values for the group or sources being queried.

    General queries don't trigger timer update.
  */
  s_flag = (1 << 3) & resv_s_qrv;
  if (!s_flag) {
    /* s_flag is clear */

    if (PIM_INADDR_IS_ANY(group_addr)) {
      /* this is a general query */

      /* log that general query should have the s_flag set */
      zlog_warn("General IGMP query v%d from %s on %s: Router-Side Processing flag is clear",
		query_version, from_str, ifp->name);
    }
    else {
      struct igmp_group *group;

      /* this is a non-general query: perform timer updates */

      group = find_group_by_addr(igmp, group_addr);
      if (group) {
	int recv_num_sources = ntohs(*(uint16_t *)(igmp_msg + IGMP_V3_NUMSOURCES_OFFSET));

	/*
	  RFC 3376: 6.6.1. Timer Updates
	  Query Q(G,A): Source Timer for sources in A are lowered to LMQT
	  Query Q(G): Group Timer is lowered to LMQT
	*/
	if (recv_num_sources < 1) {
	  /* Query Q(G): Group Timer is lowered to LMQT */

	  igmp_group_timer_lower_to_lmqt(group);
	}
	else {
	  /* Query Q(G,A): Source Timer for sources in A are lowered to LMQT */

	  /* Scan sources in query and lower their timers to LMQT */
	  struct in_addr *sources = (struct in_addr *)(igmp_msg + IGMP_V3_SOURCES_OFFSET);
	  for (int i = 0; i < recv_num_sources; ++i) {
	    struct in_addr src_addr = sources[i];
	    struct igmp_source *src = igmp_find_source_by_addr(group, src_addr);
	    if (src) {
	      igmp_source_timer_lower_to_lmqt(src);
	    }
	  }
	}

      }
      else {
	char group_str[100];
	pim_inet4_dump("<group?>", group_addr, group_str, sizeof(group_str));
	zlog_warn("IGMP query v%d from %s on %s: could not find group %s for timer update",
		  query_version, from_str, ifp->name, group_str);
      }
    }
  } /* s_flag is clear: timer updates */
  
  return 0;
}

static int igmp_v3_report(struct igmp_sock *igmp,
			  struct in_addr from, const char *from_str,
			  char *igmp_msg, int igmp_msg_len)
{
  uint16_t          recv_checksum;
  uint16_t          checksum;
  int               num_groups;
  uint8_t          *group_record;
  uint8_t          *report_pastend = (uint8_t *) igmp_msg + igmp_msg_len;
  struct interface *ifp = igmp->interface;

  if (igmp_msg_len < IGMP_V3_MSG_MIN_SIZE) {
    zlog_warn("Recv IGMP report v3 from %s on %s: size=%d shorter than minimum=%d",
	      from_str, ifp->name, igmp_msg_len, IGMP_V3_MSG_MIN_SIZE);
    return -1;
  }

  recv_checksum = *(uint16_t *) (igmp_msg + IGMP_V3_CHECKSUM_OFFSET);

  /* for computing checksum */
  *(uint16_t *) (igmp_msg + IGMP_V3_CHECKSUM_OFFSET) = 0;

  checksum = pim_inet_checksum(igmp_msg, igmp_msg_len);
  if (checksum != recv_checksum) {
    zlog_warn("Recv IGMP report v3 from %s on %s: checksum mismatch: received=%x computed=%x",
	      from_str, ifp->name, recv_checksum, checksum);
    return -1;
  }

  num_groups = ntohs(*(uint16_t *) (igmp_msg + IGMP_V3_REPORT_NUMGROUPS_OFFSET));
  if (num_groups < 1) {
    zlog_warn("Recv IGMP report v3 from %s on %s: missing group records",
	      from_str, ifp->name);
    return -1;
  }

  if (PIM_DEBUG_IGMP_PACKETS) {
    zlog_debug("Recv IGMP report v3 from %s on %s: size=%d checksum=%x groups=%d",
	       from_str, ifp->name, igmp_msg_len, checksum, num_groups);
  }

  group_record = (uint8_t *) igmp_msg + IGMP_V3_REPORT_GROUPPRECORD_OFFSET;

  /* Scan groups */
  for (int i = 0; i < num_groups; ++i) {
    struct in_addr  rec_group;
    uint8_t        *sources;
    uint8_t        *src;
    int             rec_type;
    int             rec_auxdatalen;
    int             rec_num_sources;
    int             j;

    if ((group_record + IGMP_V3_GROUP_RECORD_MIN_SIZE) > report_pastend) {
      zlog_warn("Recv IGMP report v3 from %s on %s: group record beyond report end",
		from_str, ifp->name);
      return -1;
    }

    rec_type        = group_record[IGMP_V3_GROUP_RECORD_TYPE_OFFSET];
    rec_auxdatalen  = group_record[IGMP_V3_GROUP_RECORD_AUXDATALEN_OFFSET];
    rec_num_sources = ntohs(* (uint16_t *) (group_record + IGMP_V3_GROUP_RECORD_NUMSOURCES_OFFSET));

    rec_group = *(struct in_addr *)(group_record + IGMP_V3_GROUP_RECORD_GROUP_OFFSET);

    if (PIM_DEBUG_IGMP_PACKETS) {
      zlog_debug("Recv IGMP report v3 from %s on %s: record=%d type=%d auxdatalen=%d sources=%d group=%s",
		 from_str, ifp->name, i, rec_type, rec_auxdatalen, rec_num_sources, inet_ntoa(rec_group));
    }

    /* Scan sources */
    
    sources = group_record + IGMP_V3_GROUP_RECORD_SOURCE_OFFSET;

    for (j = 0, src = sources; j < rec_num_sources; ++j, src += 4) {

      if ((src + 4) > report_pastend) {
	zlog_warn("Recv IGMP report v3 from %s on %s: group source beyond report end",
		  from_str, ifp->name);
	return -1;
      }

      if (PIM_DEBUG_IGMP_PACKETS) {
	char src_str[200];

	if (!inet_ntop(AF_INET, src, src_str , sizeof(src_str)))
	  sprintf(src_str, "<source?>");
	
	zlog_debug("Recv IGMP report v3 from %s on %s: record=%d group=%s source=%s",
		   from_str, ifp->name, i, inet_ntoa(rec_group), src_str);
      }
    } /* for (sources) */

    switch (rec_type) {
    case IGMP_GRP_REC_TYPE_MODE_IS_INCLUDE:
      igmpv3_report_isin(igmp, from, rec_group, rec_num_sources, (struct in_addr *) sources);
      break;
    case IGMP_GRP_REC_TYPE_MODE_IS_EXCLUDE:
      igmpv3_report_isex(igmp, from, rec_group, rec_num_sources, (struct in_addr *) sources);
      break;
    case IGMP_GRP_REC_TYPE_CHANGE_TO_INCLUDE_MODE:
      igmpv3_report_toin(igmp, from, rec_group, rec_num_sources, (struct in_addr *) sources);
      break;
    case IGMP_GRP_REC_TYPE_CHANGE_TO_EXCLUDE_MODE:
      igmpv3_report_toex(igmp, from, rec_group, rec_num_sources, (struct in_addr *) sources);
      break;
    case IGMP_GRP_REC_TYPE_ALLOW_NEW_SOURCES:
      igmpv3_report_allow(igmp, from, rec_group, rec_num_sources, (struct in_addr *) sources);
      break;
    case IGMP_GRP_REC_TYPE_BLOCK_OLD_SOURCES:
      igmpv3_report_block(igmp, from, rec_group, rec_num_sources, (struct in_addr *) sources);
      break;
    default:
      zlog_warn("Recv IGMP report v3 from %s on %s: unknown record type: type=%d",
		from_str, ifp->name, rec_type);
    }

    group_record += 8 + (rec_num_sources << 2) + (rec_auxdatalen << 2);

  } /* for (group records) */

  return 0;
}

static void on_trace(const char *label,
		     struct interface *ifp, struct in_addr from)
{
  if (PIM_DEBUG_IGMP_TRACE) {
    char from_str[100];
    pim_inet4_dump("<from?>", from, from_str, sizeof(from_str));
    zlog_debug("%s: from %s on %s",
	       label, from_str, ifp->name);
  }
}

static int igmp_v2_report(struct igmp_sock *igmp,
			  struct in_addr from, const char *from_str,
			  char *igmp_msg, int igmp_msg_len)
{
  struct interface *ifp = igmp->interface;
  struct igmp_group *group;
  struct in_addr group_addr;

  on_trace(__PRETTY_FUNCTION__, igmp->interface, from);

  if (igmp_msg_len != IGMP_V12_MSG_SIZE) {
    zlog_warn("Recv IGMP report v2 from %s on %s: size=%d other than correct=%d",
	      from_str, ifp->name, igmp_msg_len, IGMP_V12_MSG_SIZE);
    return -1;
  }

  if (PIM_DEBUG_IGMP_TRACE) {
    zlog_warn("%s %s: FIXME WRITEME",
	      __FILE__, __PRETTY_FUNCTION__);
  }

  group_addr = *(struct in_addr *)(igmp_msg + 4);

  /* non-existant group is created as INCLUDE {empty} */
  group = igmp_add_group_by_addr(igmp, group_addr, ifp->name);
  if (!group) {
    return -1;
  }

  group->last_igmp_v2_report_dsec = pim_time_monotonic_dsec();

  return 0;
}

static int igmp_v2_leave(struct igmp_sock *igmp,
			 struct in_addr from, const char *from_str,
			 char *igmp_msg, int igmp_msg_len)
{
  struct interface *ifp = igmp->interface;

  on_trace(__PRETTY_FUNCTION__, igmp->interface, from);

  if (igmp_msg_len != IGMP_V12_MSG_SIZE) {
    zlog_warn("Recv IGMP leave v2 from %s on %s: size=%d other than correct=%d",
	      from_str, ifp->name, igmp_msg_len, IGMP_V12_MSG_SIZE);
    return -1;
  }

  if (PIM_DEBUG_IGMP_TRACE) {
    zlog_warn("%s %s: FIXME WRITEME",
	      __FILE__, __PRETTY_FUNCTION__);
  }

  return 0;
}

static int igmp_v1_report(struct igmp_sock *igmp,
			  struct in_addr from, const char *from_str,
			  char *igmp_msg, int igmp_msg_len)
{
  struct interface *ifp = igmp->interface;
  struct igmp_group *group;
  struct in_addr group_addr;

  on_trace(__PRETTY_FUNCTION__, igmp->interface, from);

  if (igmp_msg_len != IGMP_V12_MSG_SIZE) {
    zlog_warn("Recv IGMP report v1 from %s on %s: size=%d other than correct=%d",
	      from_str, ifp->name, igmp_msg_len, IGMP_V12_MSG_SIZE);
    return -1;
  }

  if (PIM_DEBUG_IGMP_TRACE) {
    zlog_warn("%s %s: FIXME WRITEME",
	      __FILE__, __PRETTY_FUNCTION__);
  }

  group_addr = *(struct in_addr *)(igmp_msg + 4);

  /* non-existant group is created as INCLUDE {empty} */
  group = igmp_add_group_by_addr(igmp, group_addr, ifp->name);
  if (!group) {
    return -1;
  }

  group->last_igmp_v1_report_dsec = pim_time_monotonic_dsec();

  return 0;
}

int pim_igmp_packet(struct igmp_sock *igmp, char *buf, size_t len)
{
  struct ip *ip_hdr;
  size_t ip_hlen; /* ip header length in bytes */
  char *igmp_msg;
  int igmp_msg_len;
  int msg_type;
  char from_str[100];
  char to_str[100];
    
  if (len < sizeof(*ip_hdr)) {
    zlog_warn("IGMP packet size=%d shorter than minimum=%d",
	      len, sizeof(*ip_hdr));
    return -1;
  }

  ip_hdr = (struct ip *) buf;

  pim_inet4_dump("<src?>", ip_hdr->ip_src, from_str , sizeof(from_str));
  pim_inet4_dump("<dst?>", ip_hdr->ip_dst, to_str , sizeof(to_str));

  ip_hlen = ip_hdr->ip_hl << 2; /* ip_hl gives length in 4-byte words */

  if (PIM_DEBUG_IGMP_PACKETS) {
    zlog_debug("Recv IP packet from %s to %s on %s: size=%d ip_header_size=%d ip_proto=%d",
	       from_str, to_str, igmp->interface->name, len, ip_hlen, ip_hdr->ip_p);
  }

  if (ip_hdr->ip_p != PIM_IP_PROTO_IGMP) {
    zlog_warn("IP packet protocol=%d is not IGMP=%d",
	      ip_hdr->ip_p, PIM_IP_PROTO_IGMP);
    return -1;
  }

  if (ip_hlen < PIM_IP_HEADER_MIN_LEN) {
    zlog_warn("IP packet header size=%d shorter than minimum=%d",
	      ip_hlen, PIM_IP_HEADER_MIN_LEN);
    return -1;
  }
  if (ip_hlen > PIM_IP_HEADER_MAX_LEN) {
    zlog_warn("IP packet header size=%d greater than maximum=%d",
	      ip_hlen, PIM_IP_HEADER_MAX_LEN);
    return -1;
  }

  igmp_msg = buf + ip_hlen;
  msg_type = *igmp_msg;
  igmp_msg_len = len - ip_hlen;

  if (PIM_DEBUG_IGMP_PACKETS) {
    zlog_debug("Recv IGMP packet from %s to %s on %s: ttl=%d msg_type=%d msg_size=%d",
	       from_str, to_str, igmp->interface->name, ip_hdr->ip_ttl, msg_type,
	       igmp_msg_len);
  }

  if (igmp_msg_len < PIM_IGMP_MIN_LEN) {
    zlog_warn("IGMP message size=%d shorter than minimum=%d",
	      igmp_msg_len, PIM_IGMP_MIN_LEN);
    return -1;
  }

  switch (msg_type) {
  case PIM_IGMP_MEMBERSHIP_QUERY:
    {
      int max_resp_code = igmp_msg[1];
      int query_version;

      /*
	RFC 3376: 7.1. Query Version Distinctions
	IGMPv1 Query: length = 8 octets AND Max Resp Code field is zero
	IGMPv2 Query: length = 8 octets AND Max Resp Code field is non-zero
	IGMPv3 Query: length >= 12 octets
      */

      if (igmp_msg_len == 8) {
	query_version = max_resp_code ? 2 : 1;
      }
      else if (igmp_msg_len >= 12) {
	query_version = 3;
      }
      else {
	zlog_warn("Unknown IGMP query version");
	return -1;
      }

      return recv_igmp_query(igmp, query_version, max_resp_code,
			     ip_hdr->ip_src, from_str,
			     igmp_msg, igmp_msg_len);
    }

  case PIM_IGMP_V3_MEMBERSHIP_REPORT:
    return igmp_v3_report(igmp, ip_hdr->ip_src, from_str,
			  igmp_msg, igmp_msg_len);

  case PIM_IGMP_V2_MEMBERSHIP_REPORT:
    return igmp_v2_report(igmp, ip_hdr->ip_src, from_str,
			  igmp_msg, igmp_msg_len);

  case PIM_IGMP_V1_MEMBERSHIP_REPORT:
    return igmp_v1_report(igmp, ip_hdr->ip_src, from_str,
			  igmp_msg, igmp_msg_len);

  case PIM_IGMP_V2_LEAVE_GROUP:
    return igmp_v2_leave(igmp, ip_hdr->ip_src, from_str,
			 igmp_msg, igmp_msg_len);
  }

  zlog_warn("Ignoring unsupported IGMP message type: %d", msg_type);

  return -1;
}

static int pim_igmp_general_query(struct thread *t);

void pim_igmp_general_query_on(struct igmp_sock *igmp)
{
  struct pim_interface *pim_ifp;
  int startup_mode;
  int query_interval;

  zassert(igmp);
  zassert(igmp->interface);

  /*
    Since this socket is starting as querier,
    there should not exist a timer for other-querier-present.
   */
  zassert(!igmp->t_other_querier_timer);
  pim_ifp = igmp->interface->info;
  zassert(pim_ifp);

  /*
    RFC 3376: 8.6. Startup Query Interval

    The Startup Query Interval is the interval between General Queries
    sent by a Querier on startup.  Default: 1/4 the Query Interval.
  */
  startup_mode = igmp->startup_query_count > 0;
  if (startup_mode) {
    --igmp->startup_query_count;

    /* query_interval = pim_ifp->igmp_default_query_interval >> 2; */
    query_interval = PIM_IGMP_SQI(pim_ifp->igmp_default_query_interval);
  }
  else {
    query_interval = igmp->querier_query_interval;
  }

  if (PIM_DEBUG_IGMP_TRACE) {
    char ifaddr_str[100];
    pim_inet4_dump("<ifaddr?>", igmp->ifaddr, ifaddr_str, sizeof(ifaddr_str));
    zlog_debug("Querier %s scheduling %d-second (%s) TIMER event for IGMP query on fd=%d",
	       ifaddr_str,
	       query_interval,
	       startup_mode ? "startup" : "non-startup",
	       igmp->fd);
  }
  igmp->t_igmp_query_timer = 0;
  zassert(!igmp->t_igmp_query_timer);
  THREAD_TIMER_ON(master, igmp->t_igmp_query_timer,
		  pim_igmp_general_query,
		  igmp, query_interval);
}

void pim_igmp_general_query_off(struct igmp_sock *igmp)
{
  zassert(igmp);

  if (PIM_DEBUG_IGMP_TRACE) {
    if (igmp->t_igmp_query_timer) {
      char ifaddr_str[100];
      pim_inet4_dump("<ifaddr?>", igmp->ifaddr, ifaddr_str, sizeof(ifaddr_str));
      zlog_debug("IGMP querier %s fd=%d cancelling query TIMER event on %s",
		 ifaddr_str, igmp->fd, igmp->interface->name);
    }
  }
  THREAD_OFF(igmp->t_igmp_query_timer);
  zassert(!igmp->t_igmp_query_timer);
}

/* Issue IGMP general query */
static int pim_igmp_general_query(struct thread *t)
{
  char   query_buf[PIM_IGMP_BUFSIZE_WRITE];
  struct igmp_sock *igmp;
  struct in_addr dst_addr;
  struct in_addr group_addr;
  struct pim_interface *pim_ifp;

  zassert(t);

  igmp = THREAD_ARG(t);

  zassert(igmp);
  zassert(igmp->interface);
  zassert(igmp->interface->info);

  pim_ifp = igmp->interface->info;

  /*
    RFC3376: 4.1.12. IP Destination Addresses for Queries

    In IGMPv3, General Queries are sent with an IP destination address
    of 224.0.0.1, the all-systems multicast address.  Group-Specific
    and Group-and-Source-Specific Queries are sent with an IP
    destination address equal to the multicast address of interest.
  */

  dst_addr.s_addr   = htonl(INADDR_ALLHOSTS_GROUP);
  group_addr.s_addr = PIM_NET_INADDR_ANY;

  if (PIM_DEBUG_IGMP_TRACE) {
    char querier_str[100];
    char dst_str[100];
    pim_inet4_dump("<querier?>", igmp->ifaddr, querier_str,
		   sizeof(querier_str));
    pim_inet4_dump("<dst?>", dst_addr, dst_str, sizeof(dst_str));
    zlog_debug("Querier %s issuing IGMP general query to %s on %s",
	       querier_str, dst_str, igmp->interface->name);
  }

  pim_igmp_send_membership_query(0 /* igmp_group */,
				 igmp->fd,
				 igmp->interface->name,
				 query_buf,
				 sizeof(query_buf),
				 0 /* num_sources */,
				 dst_addr,
				 group_addr,
				 pim_ifp->igmp_query_max_response_time_dsec,
				 1 /* s_flag: always set for general queries */,
				 igmp->querier_robustness_variable,
				 igmp->querier_query_interval);

  pim_igmp_general_query_on(igmp);

  return 0;
}

static int pim_igmp_read(struct thread *t);

static void igmp_read_on(struct igmp_sock *igmp)
{
  zassert(igmp);

  if (PIM_DEBUG_IGMP_TRACE) {
    zlog_debug("Scheduling READ event on IGMP socket fd=%d",
	       igmp->fd);
  }
  igmp->t_igmp_read = 0;
  zassert(!igmp->t_igmp_read);
  THREAD_READ_ON(master, igmp->t_igmp_read, pim_igmp_read, igmp, igmp->fd);
}

static int pim_igmp_read(struct thread *t)
{
  struct igmp_sock *igmp;
  int fd;
  struct sockaddr_in from;
  struct sockaddr_in to;
  socklen_t fromlen = sizeof(from);
  socklen_t tolen = sizeof(to);
  char buf[PIM_IGMP_BUFSIZE_READ];
  int len;
  int ifindex = -1;
  int result = -1; /* defaults to bad */

  zassert(t);

  igmp = THREAD_ARG(t);

  zassert(igmp);

  fd = THREAD_FD(t);

  zassert(fd == igmp->fd);

  len = pim_socket_recvfromto(fd, buf, sizeof(buf),
			      &from, &fromlen,
			      &to, &tolen,
			      &ifindex);
  if (len < 0) {
    zlog_warn("Failure receiving IP IGMP packet on fd=%d: errno=%d: %s",
	      fd, errno, safe_strerror(errno));
    goto done;
  }

  if (PIM_DEBUG_IGMP_PACKETS) {
    char from_str[100];
    char to_str[100];
    
    if (!inet_ntop(AF_INET, &from.sin_addr, from_str, sizeof(from_str)))
      sprintf(from_str, "<from?>");
    if (!inet_ntop(AF_INET, &to.sin_addr, to_str, sizeof(to_str)))
      sprintf(to_str, "<to?>");
    
    zlog_debug("Recv IP IGMP pkt size=%d from %s to %s on fd=%d on ifindex=%d (sock_ifindex=%d)",
	       len, from_str, to_str, fd, ifindex, igmp->interface->ifindex);
  }

#ifdef PIM_CHECK_RECV_IFINDEX_SANITY
  /* ifindex sanity check */
  if (ifindex != (int) igmp->interface->ifindex) {
    char from_str[100];
    char to_str[100];
    struct interface *ifp;

    if (!inet_ntop(AF_INET, &from.sin_addr, from_str , sizeof(from_str)))
      sprintf(from_str, "<from?>");
    if (!inet_ntop(AF_INET, &to.sin_addr, to_str , sizeof(to_str)))
      sprintf(to_str, "<to?>");

    ifp = if_lookup_by_index(ifindex);
    if (ifp) {
      zassert(ifindex == (int) ifp->ifindex);
    }

#ifdef PIM_REPORT_RECV_IFINDEX_MISMATCH
    zlog_warn("Interface mismatch: recv IGMP pkt from %s to %s on fd=%d: recv_ifindex=%d (%s) sock_ifindex=%d (%s)",
	      from_str, to_str, fd,
	      ifindex, ifp ? ifp->name : "<if-notfound>",
	      igmp->interface->ifindex, igmp->interface->name);
#endif
    goto done;
  }
#endif

  if (pim_igmp_packet(igmp, buf, len)) {
    goto done;
  }

  result = 0; /* good */

 done:
  igmp_read_on(igmp);

  return result;
}

static void sock_close(struct igmp_sock *igmp)
{
  pim_igmp_other_querier_timer_off(igmp);
  pim_igmp_general_query_off(igmp);

  if (PIM_DEBUG_IGMP_TRACE) {
    if (igmp->t_igmp_read) {
      zlog_debug("Cancelling READ event on IGMP socket %s fd=%d on interface %s",
		 inet_ntoa(igmp->ifaddr), igmp->fd,
		 igmp->interface->name);
    }
  }
  THREAD_OFF(igmp->t_igmp_read);
  zassert(!igmp->t_igmp_read);
  
  if (close(igmp->fd)) {
    zlog_err("Failure closing IGMP socket %s fd=%d on interface %s: errno=%d: %s",
	     inet_ntoa(igmp->ifaddr), igmp->fd, igmp->interface->name,
	     errno, safe_strerror(errno));
  }
  
  if (PIM_DEBUG_IGMP_TRACE) {
    zlog_debug("Deleted IGMP socket %s fd=%d on interface %s",
	       inet_ntoa(igmp->ifaddr), igmp->fd, igmp->interface->name);
  }
}

void igmp_startup_mode_on(struct igmp_sock *igmp)
{
  struct pim_interface *pim_ifp;

  pim_ifp = igmp->interface->info;

  /*
    RFC 3376: 8.7. Startup Query Count

    The Startup Query Count is the number of Queries sent out on
    startup, separated by the Startup Query Interval.  Default: the
    Robustness Variable.
  */
  igmp->startup_query_count = igmp->querier_robustness_variable;

  /*
    Since we're (re)starting, reset QQI to default Query Interval
  */
  igmp->querier_query_interval = pim_ifp->igmp_default_query_interval;
}

static void igmp_group_free(struct igmp_group *group)
{
  zassert(!group->t_group_query_retransmit_timer);
  zassert(!group->t_group_timer);
  zassert(group->group_source_list);
  zassert(!listcount(group->group_source_list));

  list_free(group->group_source_list);

  XFREE(MTYPE_PIM_IGMP_GROUP, group);
}

static void igmp_group_delete(struct igmp_group *group)
{
  struct listnode *src_node;
  struct listnode *src_nextnode;
  struct igmp_source *src;

  if (PIM_DEBUG_IGMP_TRACE) {
    char group_str[100];
    pim_inet4_dump("<group?>", group->group_addr, group_str, sizeof(group_str));
    zlog_debug("Deleting IGMP group %s from socket %d interface %s",
	       group_str,
	       group->group_igmp_sock->fd,
	       group->group_igmp_sock->interface->name);
  }

  for (ALL_LIST_ELEMENTS(group->group_source_list, src_node, src_nextnode, src)) {
    igmp_source_delete(src);
  }

  if (group->t_group_query_retransmit_timer) {
    THREAD_OFF(group->t_group_query_retransmit_timer);
    zassert(!group->t_group_query_retransmit_timer);
  }

  group_timer_off(group);
  listnode_delete(group->group_igmp_sock->igmp_group_list, group);
  igmp_group_free(group);
}

void igmp_group_delete_empty_include(struct igmp_group *group)
{
  zassert(!group->group_filtermode_isexcl);
  zassert(!listcount(group->group_source_list));

  igmp_group_delete(group);
}

void igmp_sock_free(struct igmp_sock *igmp)
{
  zassert(!igmp->t_igmp_read);
  zassert(!igmp->t_igmp_query_timer);
  zassert(!igmp->t_other_querier_timer);
  zassert(igmp->igmp_group_list);
  zassert(!listcount(igmp->igmp_group_list));

  list_free(igmp->igmp_group_list);

  XFREE(MTYPE_PIM_IGMP_SOCKET, igmp);
}

void igmp_sock_delete(struct igmp_sock *igmp)
{
  struct pim_interface *pim_ifp;
  struct listnode      *grp_node;
  struct listnode      *grp_nextnode;
  struct igmp_group    *grp;

  for (ALL_LIST_ELEMENTS(igmp->igmp_group_list, grp_node, grp_nextnode, grp)) {
    igmp_group_delete(grp);
  }

  sock_close(igmp);

  pim_ifp = igmp->interface->info;

  listnode_delete(pim_ifp->igmp_socket_list, igmp);

  igmp_sock_free(igmp);
}

static struct igmp_sock *igmp_sock_new(int fd,
				       struct in_addr ifaddr,
				       struct interface *ifp)
{
  struct pim_interface *pim_ifp;
  struct igmp_sock *igmp;

  pim_ifp = ifp->info;

  if (PIM_DEBUG_IGMP_TRACE) {
    zlog_debug("Creating IGMP socket fd=%d for address %s on interface %s",
	       fd, inet_ntoa(ifaddr), ifp->name);
  }

  igmp = XMALLOC(MTYPE_PIM_IGMP_SOCKET, sizeof(*igmp));
  if (!igmp) {
    zlog_warn("%s %s: XMALLOC() failure",
              __FILE__, __PRETTY_FUNCTION__);
    return 0;
  }

  igmp->igmp_group_list = list_new();
  if (!igmp->igmp_group_list) {
    zlog_err("%s %s: failure: igmp_group_list = list_new()",
	     __FILE__, __PRETTY_FUNCTION__);
    return 0;
  }
  igmp->igmp_group_list->del = (void (*)(void *)) igmp_group_free;

  igmp->fd                          = fd;
  igmp->interface                   = ifp;
  igmp->ifaddr                      = ifaddr;
  igmp->t_igmp_read                 = 0;
  igmp->t_igmp_query_timer          = 0;
  igmp->t_other_querier_timer       = 0; /* no other querier present */
  igmp->querier_robustness_variable = pim_ifp->igmp_default_robustness_variable;
  igmp->sock_creation               = pim_time_monotonic_sec();

  /*
    igmp_startup_mode_on() will reset QQI:

    igmp->querier_query_interval = pim_ifp->igmp_default_query_interval;
  */
  igmp_startup_mode_on(igmp);

  igmp_read_on(igmp);
  pim_igmp_general_query_on(igmp);

  return igmp;
}

struct igmp_sock *pim_igmp_sock_add(struct list *igmp_sock_list,
				    struct in_addr ifaddr,
				    struct interface *ifp)
{
  struct pim_interface *pim_ifp;
  struct igmp_sock *igmp;
  int fd;

  pim_ifp = ifp->info;

  fd = igmp_sock_open(ifaddr, ifp->ifindex, pim_ifp->options);
  if (fd < 0) {
    zlog_warn("Could not open IGMP socket for %s on %s",
	      inet_ntoa(ifaddr), ifp->name);
    return 0;
  }

  igmp = igmp_sock_new(fd, ifaddr, ifp);
  if (!igmp) {
    zlog_err("%s %s: igmp_sock_new() failure",
	     __FILE__, __PRETTY_FUNCTION__);
    close(fd);
    return 0;
  }

  listnode_add(igmp_sock_list, igmp);

#ifdef IGMP_SOCK_DUMP
  igmp_sock_dump(igmp_sock_array);
#endif

  return igmp;
}

/*
  RFC 3376: 6.5. Switching Router Filter-Modes

  When a router's filter-mode for a group is EXCLUDE and the group
  timer expires, the router filter-mode for the group transitions to
  INCLUDE.

  A router uses source records with running source timers as its state
  for the switch to a filter-mode of INCLUDE.  If there are any source
  records with source timers greater than zero (i.e., requested to be
  forwarded), a router switches to filter-mode of INCLUDE using those
  source records.  Source records whose timers are zero (from the
  previous EXCLUDE mode) are deleted.
 */
static int igmp_group_timer(struct thread *t)
{
  struct igmp_group *group;

  zassert(t);
  group = THREAD_ARG(t);
  zassert(group);

  if (PIM_DEBUG_IGMP_TRACE) {
    char group_str[100];
    pim_inet4_dump("<group?>", group->group_addr, group_str, sizeof(group_str));
    zlog_debug("%s: Timer for group %s on interface %s",
	       __PRETTY_FUNCTION__,
	       group_str, group->group_igmp_sock->interface->name);
  }

  zassert(group->group_filtermode_isexcl);

  group->t_group_timer = 0;
  group->group_filtermode_isexcl = 0;

  /* Any source (*,G) is forwarded only if mode is EXCLUDE {empty} */
  igmp_anysource_forward_stop(group);

  igmp_source_delete_expired(group->group_source_list);

  zassert(!group->t_group_timer);
  zassert(!group->group_filtermode_isexcl);

  /*
    RFC 3376: 6.2.2. Definition of Group Timers

    If there are no more source records for the group, delete group
    record.
  */
  if (listcount(group->group_source_list) < 1) {
    igmp_group_delete_empty_include(group);
  }

  return 0;
}

static void group_timer_off(struct igmp_group *group)
{
  if (!group->t_group_timer)
    return;

  if (PIM_DEBUG_IGMP_TRACE) {
    char group_str[100];
    pim_inet4_dump("<group?>", group->group_addr, group_str, sizeof(group_str));
    zlog_debug("Cancelling TIMER event for group %s on %s",
	       group_str, group->group_igmp_sock->interface->name);
  }
    
  THREAD_OFF(group->t_group_timer);
  zassert(!group->t_group_timer);
}

void igmp_group_timer_on(struct igmp_group *group,
			 long interval_msec, const char *ifname)
{
  group_timer_off(group);

  if (PIM_DEBUG_IGMP_EVENTS) {
    char group_str[100];
    pim_inet4_dump("<group?>", group->group_addr, group_str, sizeof(group_str));
    zlog_debug("Scheduling %ld.%03ld sec TIMER event for group %s on %s",
	       interval_msec / 1000,
	       interval_msec % 1000,
	       group_str, ifname);
  }

  /*
    RFC 3376: 6.2.2. Definition of Group Timers

    The group timer is only used when a group is in EXCLUDE mode and
    it represents the time for the *filter-mode* of the group to
    expire and switch to INCLUDE mode.
  */
  zassert(group->group_filtermode_isexcl);

  THREAD_TIMER_MSEC_ON(master, group->t_group_timer,
		       igmp_group_timer,
		       group, interval_msec);
}

static struct igmp_group *find_group_by_addr(struct igmp_sock *igmp,
					     struct in_addr group_addr)
{
  struct igmp_group *group;
  struct listnode   *node;

  for (ALL_LIST_ELEMENTS_RO(igmp->igmp_group_list, node, group))
    if (group_addr.s_addr == group->group_addr.s_addr)
      return group;

  return 0;
}

struct igmp_group *igmp_add_group_by_addr(struct igmp_sock *igmp,
					  struct in_addr group_addr,
					  const char *ifname)
{
  struct igmp_group *group;

  group = find_group_by_addr(igmp, group_addr);
  if (group) {
    return group;
  }

  /*
    Non-existant group is created as INCLUDE {empty}:

    RFC 3376 - 5.1. Action on Change of Interface State

    If no interface state existed for that multicast address before
    the change (i.e., the change consisted of creating a new
    per-interface record), or if no state exists after the change
    (i.e., the change consisted of deleting a per-interface record),
    then the "non-existent" state is considered to have a filter mode
    of INCLUDE and an empty source list.
  */

  group = XMALLOC(MTYPE_PIM_IGMP_GROUP, sizeof(*group));
  if (!group) {
    zlog_warn("%s %s: XMALLOC() failure",
	      __FILE__, __PRETTY_FUNCTION__);
    return 0; /* error, not found, could not create */
  }

  group->group_source_list = list_new();
  if (!group->group_source_list) {
    zlog_warn("%s %s: list_new() failure",
	      __FILE__, __PRETTY_FUNCTION__);
    XFREE(MTYPE_PIM_IGMP_GROUP, group); /* discard group */
    return 0; /* error, not found, could not initialize */
  }
  group->group_source_list->del = (void (*)(void *)) igmp_source_free;

  group->t_group_timer                         = 0;
  group->t_group_query_retransmit_timer        = 0;
  group->group_specific_query_retransmit_count = 0;
  group->group_addr                            = group_addr;
  group->group_igmp_sock                       = igmp;
  group->last_igmp_v1_report_dsec              = -1;
  group->last_igmp_v2_report_dsec              = -1;
  group->group_creation                        = pim_time_monotonic_sec();

  /* initialize new group as INCLUDE {empty} */
  group->group_filtermode_isexcl = 0; /* 0=INCLUDE, 1=EXCLUDE */

  listnode_add(igmp->igmp_group_list, group);

  if (PIM_DEBUG_IGMP_TRACE) {
    char group_str[100];
    pim_inet4_dump("<group?>", group->group_addr, group_str, sizeof(group_str));
    zlog_debug("Creating new IGMP group %s on socket %d interface %s",
	       group_str, group->group_igmp_sock->fd, ifname);
  }

  /*
    RFC 3376: 6.2.2. Definition of Group Timers

    The group timer is only used when a group is in EXCLUDE mode and
    it represents the time for the *filter-mode* of the group to
    expire and switch to INCLUDE mode.
  */
  zassert(!group->group_filtermode_isexcl); /* INCLUDE mode */
  zassert(!group->t_group_timer); /* group timer == 0 */

  /* Any source (*,G) is forwarded only if mode is EXCLUDE {empty} */
  igmp_anysource_forward_stop(group);

  return group;
}
