Squashed commit of the following:
net/mld: The MLD logic now compiles and is much less toxic. It still is not a proper MLD implementation: (1) It is basically a port of IGMP, tweaked to work with IPv6 and ICMPv6 MLD messages, (2) it needs a proper analysis and comparison with RFC 3810, and (3) it is completely untested. For this reason, it will remain EXPERIMENTAL for some time. net/mld: Add some missing macros, more fixes related to IPv6 vs IPv4 types, net/mld: More compilation cleaning. Most fixups for IPv6 vs IPv4 types. net/mld: Hook crudely converted .c files into build system and resolve a few of the many, many compilation/design problems. net/mld: Add support for MLD statistics. net/mld: Hook in MLD poll and packet transmission logic. net/mld: Change references to IPv4 definitions to IPv6 definitions; Remove mld_input() since MLD piggybacks on ICMPv6 input. Add functions to catch MLD messages dispatched by ICMPv6 input logic. net/mld: As a starting point, copy all net/igmp/*.c files to net/mld/. and change all occurrences of igmp (or IGMP) to mld (or MLD). net/mld: More compilation cleaning. Most fixups for IPv6 vs IPv4 types. net/mld: Hook crudely converted .c files into build system and resolve a few of the many, many compilation/design problems. net/mld: Add support for MLD statistics. net/mld: Hook in MLD poll and packet transmission logic. net/mld: Change references to IPv4 definitions to IPv6 definitions; Remove mld_input() since MLD piggybacks on ICMPv6 input. Add functions to catch MLD messages dispatched by ICMPv6 input logic. net/mld: As a starting point, copy all net/igmp/*.c files to net/mld/. and change all occurrences of igmp (or IGMP) to mld (or MLD).
This commit is contained in:
parent
260d29a187
commit
5b7ef856a0
23 changed files with 2442 additions and 21 deletions
|
@ -1,7 +1,6 @@
|
|||
/************************************************************************************************************
|
||||
* include/nuttx/net/ipopt.h
|
||||
*
|
||||
* Defines values for the IP header options
|
||||
* Defines values for the IPv4 header options
|
||||
*
|
||||
* Copyright (C) 2010, 2014 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
|
@ -65,7 +64,7 @@
|
|||
* Pointer: 8-bits:
|
||||
* Option Data: (depends on Length)
|
||||
*
|
||||
* The IP Option Type byte consists of the following subfields:
|
||||
* The IPv4 Option Type byte consists of the following subfields:
|
||||
*/
|
||||
|
||||
#define IPOPT_TYPE_OPTION_SHIFT (0) /* Bits 0-5: Option number*/
|
||||
|
|
|
@ -201,7 +201,7 @@ struct mld_mcast_listen_query_s
|
|||
uint16_t chksum; /* Checksum of ICMP header and data */
|
||||
uint16_t mrc; /* Maximum response code */
|
||||
uint16_t reserved2; /* Reserved, must be zero on transmission */
|
||||
net_ipv6addr_t mcast; /* 128-bit IPv6 multicast address */
|
||||
net_ipv6addr_t grpaddr; /* 128-bit IPv6 multicast group address */
|
||||
uint8_t flags; /* See S and QRV flag definitions */
|
||||
uint8_t qqic; /* Querier's Query Interval Cod */
|
||||
uint16_t nsources; /* Number of sources that follow */
|
||||
|
@ -219,12 +219,12 @@ struct mld_mcast_listen_query_s
|
|||
* routers) the current multicast listening state, or changes in the
|
||||
* multicast listening state, of their interfaces.
|
||||
*
|
||||
* Version 1 Multicast Listener Reports (RFC 2710)
|
||||
* Version 1 Multicast Listener Report (RFC 2710)
|
||||
*/
|
||||
|
||||
struct mld_mcast_listen_report_v1_s
|
||||
{
|
||||
uint8_t type; /* Message Type: ICMPV6_MCAST_LISTEN_REPORT */
|
||||
uint8_t type; /* Message Type: ICMPV6_MCAST_LISTEN_REPORT_V1 */
|
||||
uint8_t reserved1; /* Reserved, must be zero on transmission */
|
||||
uint16_t chksum; /* Checksum of ICMP header and data */
|
||||
uint16_t reserved2; /* Reserved, must be zero on transmission */
|
||||
|
@ -232,7 +232,7 @@ struct mld_mcast_listen_report_v1_s
|
|||
net_ipv6addr_t mcastaddr; /* Multicast address */
|
||||
};
|
||||
|
||||
/* Version 2 Multicast Listener Reports (RFC 3810). */
|
||||
/* Version 2 Multicast Listener Report (RFC 3810). */
|
||||
/* This is the form of the address record used in the listener report */
|
||||
|
||||
struct mld_mcast_addrec_v2_s
|
||||
|
@ -282,7 +282,7 @@ struct mld_mcast_listen_report_v2_s
|
|||
|
||||
struct mld_mcast_listen_done_v1_s
|
||||
{
|
||||
uint8_t type; /* Message Type: ICMPV6_MCAST_LISTEN_DONE */
|
||||
uint8_t type; /* Message Type: ICMPV6_MCAST_LISTEN_DONE_V1 */
|
||||
uint8_t reserved1; /* Reserved, must be zero on transmission */
|
||||
uint16_t chksum; /* Checksum of ICMP header and data */
|
||||
uint16_t reserved2; /* Reserved, must be zero on transmission */
|
||||
|
@ -290,6 +290,31 @@ struct mld_mcast_listen_done_v1_s
|
|||
net_ipv6addr_t mcastaddr; /* Multicast address */
|
||||
};
|
||||
|
||||
#ifdef CONFIG_NET_STATISTICS
|
||||
/* MLD statistic counters */
|
||||
|
||||
struct mld_stats_s
|
||||
{
|
||||
net_stats_t joins; /* Requests to join a group */
|
||||
net_stats_t leaves; /* Requests to leave a group */
|
||||
net_stats_t report_sched; /* Version 1 REPORT packets scheduled */
|
||||
net_stats_t done_sched; /* Version 1 DONE packets scheduled */
|
||||
net_stats_t report_sent; /* Version 1 REPORT packets sent */
|
||||
net_stats_t done_sent; /* Version 1 DONE packets sent */
|
||||
net_stats_t gmq_query_received; /* General multicast QUERY received */
|
||||
net_stats_t mas_query_received; /* Multicast Address Specific QUERY received */
|
||||
net_stats_t massq_query_received; /* Multicast Address and Source Specific QUERY received */
|
||||
net_stats_t ucast_query_received; /* Unicast query received */
|
||||
net_stats_t v1report_received; /* Version 1 REPORT packets received */
|
||||
net_stats_t v2report_received; /* Version 2 REPORT packets received */
|
||||
net_stats_t done_received; /* DONE packets received */
|
||||
};
|
||||
|
||||
# define MLD_STATINCR(p) ((p)++)
|
||||
#else
|
||||
# define MLD_STATINCR(p)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
|
|
@ -51,8 +51,12 @@
|
|||
|
||||
#include <sys/ioctl.h>
|
||||
#include <stdint.h>
|
||||
#include <net/if.h>
|
||||
|
||||
#ifdef CONFIG_NET_MCASTGROUP
|
||||
# include <queue.h>
|
||||
#endif
|
||||
|
||||
#include <net/if.h>
|
||||
#include <net/ethernet.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
|
|
|
@ -66,6 +66,9 @@
|
|||
#ifdef CONFIG_NET_IGMP
|
||||
# include <nuttx/net/igmp.h>
|
||||
#endif
|
||||
#ifdef CONFIG_NET_MLD
|
||||
# include <nuttx/net/mld.h>
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NET_STATISTICS
|
||||
|
||||
|
@ -103,6 +106,10 @@ struct net_stats_s
|
|||
struct igmp_stats_s igmp; /* IGMP statistics */
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NET_IGMP
|
||||
struct mld_stats_s mld; /* MLD statistics */
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NET_TCP
|
||||
struct tcp_stats_s tcp; /* TCP statistics */
|
||||
#endif
|
||||
|
|
|
@ -57,8 +57,9 @@
|
|||
#include "bluetooth/bluetooth.h"
|
||||
#include "ieee802154/ieee802154.h"
|
||||
#include "icmp/icmp.h"
|
||||
#include "icmpv6/icmpv6.h"
|
||||
#include "igmp/igmp.h"
|
||||
#include "icmpv6/icmpv6.h"
|
||||
#include "mld/mld.h"
|
||||
#include "ipforward/ipforward.h"
|
||||
#include "sixlowpan/sixlowpan.h"
|
||||
|
||||
|
@ -421,6 +422,36 @@ static inline int devif_poll_igmp(FAR struct net_driver_s *dev,
|
|||
}
|
||||
#endif /* CONFIG_NET_IGMP */
|
||||
|
||||
/****************************************************************************
|
||||
* Name: devif_poll_mld
|
||||
*
|
||||
* Description:
|
||||
* Poll all MLD connections for available packets to send.
|
||||
*
|
||||
* Assumptions:
|
||||
* This function is called from the MAC device driver with the network
|
||||
* locked.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NET_MLD
|
||||
static inline int devif_poll_mld(FAR struct net_driver_s *dev,
|
||||
devif_poll_callback_t callback)
|
||||
{
|
||||
/* Perform the MLD TX poll */
|
||||
|
||||
mld_poll(dev);
|
||||
|
||||
/* Perform any necessary conversions on outgoing ICMPv6 packets */
|
||||
|
||||
devif_packet_conversion(dev, DEVIF_ICMP6);
|
||||
|
||||
/* Call back into the driver */
|
||||
|
||||
return callback(dev);
|
||||
}
|
||||
#endif /* CONFIG_NET_MLD */
|
||||
|
||||
/****************************************************************************
|
||||
* Name: devif_poll_udp_connections
|
||||
*
|
||||
|
@ -626,6 +657,15 @@ int devif_poll(FAR struct net_driver_s *dev, devif_poll_callback_t callback)
|
|||
|
||||
if (!bstop)
|
||||
#endif
|
||||
#ifdef CONFIG_NET_MLD
|
||||
{
|
||||
/* Check for pending MLD messages */
|
||||
|
||||
bstop = devif_poll_mld(dev, callback);
|
||||
}
|
||||
|
||||
if (!bstop)
|
||||
#endif
|
||||
#ifdef NET_TCP_HAVE_STACK
|
||||
{
|
||||
/* Traverse all of the active TCP connections and perform the poll
|
||||
|
|
|
@ -498,7 +498,7 @@ void icmpv6_input(FAR struct net_driver_s *dev)
|
|||
FAR struct mld_mcast_listen_query_s *query = MLDQUERY;
|
||||
int ret;
|
||||
|
||||
ret = mld_query_input(dev, query);
|
||||
ret = mld_query(dev, query);
|
||||
if (ret < 0)
|
||||
{
|
||||
goto icmpv6_drop_packet;
|
||||
|
|
|
@ -93,12 +93,29 @@ EXTERN uint16_t g_ipid;
|
|||
#ifdef CONFIG_NET_IPv6
|
||||
EXTERN const net_ipv6addr_t g_ipv6_unspecaddr; /* An address of all zeroes */
|
||||
EXTERN const net_ipv6addr_t g_ipv6_allnodes; /* All link local nodes */
|
||||
#if defined(CONFIG_NET_ICMPv6_AUTOCONF) || defined(CONFIG_NET_ICMPv6_ROUTER)
|
||||
|
||||
#if defined(CONFIG_NET_ICMPv6_AUTOCONF) || defined(CONFIG_NET_ICMPv6_ROUTER) || \
|
||||
defined(CONFIG_NET_MLD)
|
||||
/* IPv6 Multi-cast IP addresses. See RFC 2375 */
|
||||
|
||||
EXTERN const net_ipv6addr_t g_ipv6_allrouters; /* All link local routers */
|
||||
#ifdef CONFIG_NET_ICMPv6_AUTOCONF
|
||||
EXTERN const net_ipv6addr_t g_ipv6_llnetmask; /* Netmask for local link address */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NET_ETHERNET
|
||||
/* IPv6 Multi-cast Ethernet addresses. Formed from the 16-bit prefix:
|
||||
*
|
||||
* 0x33:0x33:xx:xx:xx:xx:
|
||||
*
|
||||
* and the last 32-bits of the IPv6 IP address
|
||||
*/
|
||||
|
||||
EXTERN const struct ether_addr g_ipv6_ethallnodes; /* All link local nodes */
|
||||
EXTERN const struct ether_addr g_ipv6_ethallrouters; /* All link local routers */
|
||||
|
||||
#endif /* CONFIG_NET_ETHERNET */
|
||||
#endif /* CONFIG_NET_ICMPv6_AUTOCONF || CONFIG_NET_ICMPv6_ROUTER || CONFIG_NET_MLD */
|
||||
#endif /* CONFIG_NET_IPv6 */
|
||||
|
||||
/****************************************************************************
|
||||
|
|
|
@ -77,7 +77,8 @@ const net_ipv6addr_t g_ipv6_allnodes = /* All link local nodes */
|
|||
HTONS(0x0001)
|
||||
};
|
||||
|
||||
#if defined(CONFIG_NET_ICMPv6_AUTOCONF) || defined(CONFIG_NET_ICMPv6_ROUTER)
|
||||
#if defined(CONFIG_NET_ICMPv6_AUTOCONF) || defined(CONFIG_NET_ICMPv6_ROUTER) || \
|
||||
defined(CONFIG_NET_MLD)
|
||||
const net_ipv6addr_t g_ipv6_allrouters = /* All link local routers */
|
||||
{
|
||||
HTONS(0xff02),
|
||||
|
@ -117,7 +118,7 @@ const struct ether_addr g_ipv6_ethallrouters = /* All link local routers */
|
|||
};
|
||||
|
||||
#endif /* CONFIG_NET_ETHERNET */
|
||||
#endif /* CONFIG_NET_ICMPv6_AUTOCONF || CONFIG_NET_ICMPv6_ROUTER */
|
||||
#endif /* CONFIG_NET_ICMPv6_AUTOCONF || CONFIG_NET_ICMPv6_ROUTER || CONFIG_NET_MLD */
|
||||
#endif /* CONFIG_NET_IPv6 */
|
||||
|
||||
/****************************************************************************
|
||||
|
|
|
@ -37,8 +37,9 @@
|
|||
|
||||
ifeq ($(CONFIG_NET_MLD),y)
|
||||
|
||||
SOCK_CSRCS +=
|
||||
NET_CSRCS +=
|
||||
NET_CSRCS += mld_done.c mld_initialize.c mld_leave.c mld_msg.c mld_query.c
|
||||
NET_CSRCS += mld_send.c mld_group.c mld_join.c mld_mcastmac.c mld_poll.c
|
||||
NET_CSRCS += mld_report.c mld_timer.c
|
||||
|
||||
# Include MLD build support
|
||||
|
||||
|
|
301
net/mld/mld.h
301
net/mld/mld.h
|
@ -34,6 +34,69 @@
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
/* State transition diagram for a router in Querier state (RFC 2710):
|
||||
* ________________
|
||||
* | |
|
||||
* | |timer expired
|
||||
* timer expired| |(notify routing -,
|
||||
* (notify routing -)| No Listeners |clear rxmt tmr)
|
||||
* ------->| Present |<---------
|
||||
* | | | |
|
||||
* | | | |
|
||||
* | |________________| | ---------------
|
||||
* | | | | rexmt timer |
|
||||
* | report received| | | expired |
|
||||
* | (notify routing +,| | | (send m-a-s |
|
||||
* | start timer)| | | query, |
|
||||
* __________|______ | ________|_|______ st rxmt |
|
||||
* | |<------------ | | tmr) |
|
||||
* | | | |<-------
|
||||
* | | report received | |
|
||||
* | | (start timer, | |
|
||||
* | | clear rxmt tmr) | |
|
||||
* | Listeners |<-------------------| Checking |
|
||||
* | Present | done received | Listeners |
|
||||
* | | (start timer*, | |
|
||||
* | | start rxmt timer, | |
|
||||
* | | send m-a-s query) | |
|
||||
* --->| |------------------->| |
|
||||
* | |_________________| |_________________|
|
||||
* | report received |
|
||||
* | (start timer) |
|
||||
* -----------------
|
||||
*
|
||||
* State transition diagram for a router in Non-Querier state is
|
||||
* similar, but non-Queriers do not send any messages and are only
|
||||
* driven by message reception.
|
||||
*
|
||||
* ________________
|
||||
* | |
|
||||
* | |
|
||||
* timer expired| |timer expired
|
||||
* (notify routing -)| No Listeners |(notify routing -)
|
||||
* --------->| Present |<---------
|
||||
* | | | |
|
||||
* | | | |
|
||||
* | | | |
|
||||
* | |________________| |
|
||||
* | | |
|
||||
* | |report received |
|
||||
* | |(notify routing +,|
|
||||
* | | start timer) |
|
||||
* ________|________ | ________|________
|
||||
* | |<--------- | |
|
||||
* | | report received | |
|
||||
* | | (start timer) | |
|
||||
* | Listeners |<-------------------| Checking |
|
||||
* | Present | m-a-s query rec'd | Listeners |
|
||||
* | | (start timer*) | |
|
||||
* ---->| |------------------->| |
|
||||
* | |_________________| |_________________|
|
||||
* | report received |
|
||||
* | (start timer) |
|
||||
* -----------------
|
||||
*/
|
||||
|
||||
#ifndef __NET_NETLINK_MLD_H
|
||||
#define __NET_NETLINK_MLD_H
|
||||
|
||||
|
@ -47,6 +110,8 @@
|
|||
#include <queue.h>
|
||||
#include <semaphore.h>
|
||||
|
||||
#include <nuttx/net/ip.h>
|
||||
|
||||
#include "devif/devif.h"
|
||||
#include "socket/socket.h"
|
||||
|
||||
|
@ -56,10 +121,55 @@
|
|||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Group flags */
|
||||
|
||||
#define MLD_PREALLOCATED (1 << 0)
|
||||
#define MLD_LASTREPORT (1 << 1)
|
||||
#define MLD_IDLEMEMBER (1 << 2)
|
||||
#define MLD_SCHEDMSG (1 << 3)
|
||||
#define MLD_WAITMSG (1 << 4)
|
||||
|
||||
#define SET_MLD_PREALLOCATED(f) do { (f) |= MLD_PREALLOCATED; } while (0)
|
||||
#define SET_MLD_LASTREPORT(f) do { (f) |= MLD_LASTREPORT; } while (0)
|
||||
#define SET_MLD_IDLEMEMBER(f) do { (f) |= MLD_IDLEMEMBER; } while (0)
|
||||
#define SET_MLD_SCHEDMSG(f) do { (f) |= MLD_SCHEDMSG; } while (0)
|
||||
#define SET_MLD_WAITMSG(f) do { (f) |= MLD_WAITMSG; } while (0)
|
||||
|
||||
#define CLR_MLD_PREALLOCATED(f) do { (f) &= ~MLD_PREALLOCATED; } while (0)
|
||||
#define CLR_MLD_LASTREPORT(f) do { (f) &= ~MLD_LASTREPORT; } while (0)
|
||||
#define CLR_MLD_IDLEMEMBER(f) do { (f) &= ~MLD_IDLEMEMBER; } while (0)
|
||||
#define CLR_MLD_SCHEDMSG(f) do { (f) &= ~MLD_SCHEDMSG; } while (0)
|
||||
#define CLR_MLD_WAITMSG(f) do { (f) &= ~MLD_WAITMSG; } while (0)
|
||||
|
||||
#define IS_MLD_PREALLOCATED(f) (((f) & MLD_PREALLOCATED) != 0)
|
||||
#define IS_MLD_LASTREPORT(f) (((f) & MLD_LASTREPORT) != 0)
|
||||
#define IS_MLD_IDLEMEMBER(f) (((f) & MLD_IDLEMEMBER) != 0)
|
||||
#define IS_MLD_SCHEDMSG(f) (((f) & MLD_SCHEDMSG) != 0)
|
||||
#define IS_MLD_WAITMSG(f) (((f) & MLD_WAITMSG) != 0)
|
||||
|
||||
/****************************************************************************
|
||||
* Public Type Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* This structure represents one group member. There is a list of groups
|
||||
* for each device interface structure.
|
||||
*
|
||||
* There will be a group for the all systems group address but this
|
||||
* will not run the state machine as it is used to kick off reports
|
||||
* from all the other groups
|
||||
*/
|
||||
|
||||
typedef FAR struct wdog_s *WDOG_ID;
|
||||
struct mld_group_s
|
||||
{
|
||||
struct mld_group_s *next; /* Implements a singly-linked list */
|
||||
net_ipv6addr_t grpaddr; /* Group IPv6 address */
|
||||
WDOG_ID wdog; /* WDOG used to detect timeouts */
|
||||
sem_t sem; /* Used to wait for message transmission */
|
||||
volatile uint8_t flags; /* See MLD_ flags definitions */
|
||||
uint8_t msgid; /* Pending message ID (if non-zero) */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
@ -93,6 +203,17 @@ struct mld_mcast_listen_done_v1_s; /* Forward reference */
|
|||
|
||||
void mld_initialize(void);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: mld_devinit
|
||||
*
|
||||
* Description:
|
||||
* Called when a new network device is registered to configure that device
|
||||
* for MLD support.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void mld_devinit(FAR struct net_driver_s *dev);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: mld_query
|
||||
*
|
||||
|
@ -101,8 +222,8 @@ void mld_initialize(void);
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
int mld_query_input(FAR struct net_driver_s *dev,
|
||||
FAR const struct mld_mcast_listen_query_s *query);
|
||||
int mld_query(FAR struct net_driver_s *dev,
|
||||
FAR const struct mld_mcast_listen_query_s *query);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: mld_report_v1
|
||||
|
@ -120,7 +241,7 @@ int mld_report_v1(FAR struct net_driver_s *dev,
|
|||
* Name: mld_report_v2
|
||||
*
|
||||
* Description:
|
||||
* Called from icmpv6_input() when a Version 2 Multicast Listener Report is
|
||||
* Called from icmpv6_input() when a Version 2 Multicast Listener Report is
|
||||
* received.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
@ -140,6 +261,180 @@ int mld_report_v2(FAR struct net_driver_s *dev,
|
|||
int mld_done_v1(FAR struct net_driver_s *dev,
|
||||
FAR const struct mld_mcast_listen_done_v1_s *done);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: mld_grpalloc
|
||||
*
|
||||
* Description:
|
||||
* Allocate a new group from heap memory.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR struct mld_group_s *mld_grpalloc(FAR struct net_driver_s *dev,
|
||||
FAR const net_ipv6addr_t addr);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: mld_grpfind
|
||||
*
|
||||
* Description:
|
||||
* Find an existing group.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR struct mld_group_s *mld_grpfind(FAR struct net_driver_s *dev,
|
||||
FAR const net_ipv6addr_t addr);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: mld_grpallocfind
|
||||
*
|
||||
* Description:
|
||||
* Find an existing group. If not found, create a new group for the
|
||||
* address.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR struct mld_group_s *mld_grpallocfind(FAR struct net_driver_s *dev,
|
||||
FAR const net_ipv6addr_t addr);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: mld_grpfree
|
||||
*
|
||||
* Description:
|
||||
* Release a previously allocated group.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void mld_grpfree(FAR struct net_driver_s *dev,
|
||||
FAR struct mld_group_s *group);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: mld_schedmsg
|
||||
*
|
||||
* Description:
|
||||
* Schedule a message to be send at the next driver polling interval.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void mld_schedmsg(FAR struct mld_group_s *group, uint8_t msgid);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: mld_waitmsg
|
||||
*
|
||||
* Description:
|
||||
* Schedule a message to be send at the next driver polling interval and
|
||||
* block, waiting for the message to be sent.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void mld_waitmsg(FAR struct mld_group_s *group, uint8_t msgid);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: mld_poll
|
||||
*
|
||||
* Description:
|
||||
* Poll the groups associated with the device to see if any MLD messages
|
||||
* are pending transfer.
|
||||
*
|
||||
* Returned Value:
|
||||
* Returns a non-zero value if a IGP message is sent.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void mld_poll(FAR struct net_driver_s *dev);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: mld_send
|
||||
*
|
||||
* Description:
|
||||
* Sends an MLD IP packet on a network interface. This function constructs
|
||||
* the IP header and calculates the IP header checksum.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev - The device driver structure to use in the send operation.
|
||||
* group - Describes the multicast group member and identifies the
|
||||
* message to be sent.
|
||||
* destipaddr - The IP address of the recipient of the message
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
* Assumptions:
|
||||
* The network is locked.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void mld_send(FAR struct net_driver_s *dev, FAR struct mld_group_s *group,
|
||||
FAR const net_ipv6addr_t dest);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: mld_joingroup
|
||||
*
|
||||
* Description:
|
||||
* Add the specified group address to the group.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int mld_joingroup(FAR struct net_driver_s *dev,
|
||||
FAR const struct in6_addr *grpaddr);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: mld_leavegroup
|
||||
*
|
||||
* Description:
|
||||
* Remove the specified group address to the group.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int mld_leavegroup(FAR struct net_driver_s *dev,
|
||||
FAR const struct in6_addr *grpaddr);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: mld_startticks and mld_starttimer
|
||||
*
|
||||
* Description:
|
||||
* Start the MLD timer with differing time units (ticks or deciseconds).
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void mld_startticks(FAR struct mld_group_s *group, unsigned int ticks);
|
||||
void mld_starttimer(FAR struct mld_group_s *group, uint8_t decisecs);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: mld_cmptimer
|
||||
*
|
||||
* Description:
|
||||
* Compare the timer remaining on the watching timer to the deci-second
|
||||
* value. If maxticks > ticks-remaining, then (1) cancel the timer (to
|
||||
* avoid race conditions) and return true.
|
||||
*
|
||||
* If true is returned then the caller must call mld_startticks() to
|
||||
* restart the timer
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
bool mld_cmptimer(FAR struct mld_group_s *group, int maxticks);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: mld_addmcastmac
|
||||
*
|
||||
* Description:
|
||||
* Add an MLD MAC address to the device's MAC filter table.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void mld_addmcastmac(FAR struct net_driver_s *dev,
|
||||
FAR const net_ipv6addr_t ipaddr);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: mld_removemcastmac
|
||||
*
|
||||
* Description:
|
||||
* Remove an MLD MAC address from the device's MAC filter table.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void mld_removemcastmac(FAR struct net_driver_s *dev,
|
||||
FAR const net_ipv6addr_t ipaddr);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
68
net/mld/mld_done.c
Normal file
68
net/mld/mld_done.c
Normal file
|
@ -0,0 +1,68 @@
|
|||
/****************************************************************************
|
||||
* net/mld/mld_done.c
|
||||
*
|
||||
* Copyright (C) 2018 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of CITEL Technologies Ltd nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY CITEL TECHNOLOGIES AND CONTRIBUTORS ``AS IS''
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL CITEL TECHNOLOGIES OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/net/netstats.h>
|
||||
#include <nuttx/net/mld.h>
|
||||
|
||||
#include "devif/devif.h"
|
||||
#include "mld/mld.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: mld_done_v1
|
||||
*
|
||||
* Description:
|
||||
* Called from icmpv6_input() when a Version 1 Multicast Listener Done is
|
||||
* received.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int mld_done_v1(FAR struct net_driver_s *dev,
|
||||
FAR const struct mld_mcast_listen_done_v1_s *done)
|
||||
{
|
||||
MLD_STATINCR(g_netstats.mld.done_received);
|
||||
#warning Missing logic
|
||||
return -ENOSYS;
|
||||
}
|
248
net/mld/mld_group.c
Normal file
248
net/mld/mld_group.c
Normal file
|
@ -0,0 +1,248 @@
|
|||
/****************************************************************************
|
||||
* net/mld/mld_group.c
|
||||
* MLD group data structure management logic
|
||||
*
|
||||
* Copyright (C) 2018 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of CITEL Technologies Ltd nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY CITEL TECHNOLOGIES AND CONTRIBUTORS ``AS IS''
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL CITEL TECHNOLOGIES OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/compiler.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <queue.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <arch/irq.h>
|
||||
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/wdog.h>
|
||||
#include <nuttx/kmalloc.h>
|
||||
#include <nuttx/semaphore.h>
|
||||
#include <nuttx/net/net.h>
|
||||
#include <nuttx/net/netdev.h>
|
||||
#include <nuttx/net/ip.h>
|
||||
#include <nuttx/net/mld.h>
|
||||
|
||||
#include "devif/devif.h"
|
||||
#include "mld/mld.h"
|
||||
|
||||
#ifdef CONFIG_NET_MLD
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Debug ********************************************************************/
|
||||
|
||||
#undef MLD_GRPDEBUG /* Define to enable detailed MLD group debug */
|
||||
|
||||
#ifndef CONFIG_NET_MLD
|
||||
# undef MLD_GRPDEBUG
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_CPP_HAVE_VARARGS
|
||||
# ifdef MLD_GRPDEBUG
|
||||
# define grperr(format, ...) nerr(format, ##__VA_ARGS__)
|
||||
# define grpinfo(format, ...) ninfo(format, ##__VA_ARGS__)
|
||||
# else
|
||||
# define grperr(x...)
|
||||
# define grpinfo(x...)
|
||||
# endif
|
||||
#else
|
||||
# ifdef MLD_GRPDEBUG
|
||||
# define grperr nerr
|
||||
# define grpinfo ninfo
|
||||
# else
|
||||
# define grperr (void)
|
||||
# define grpinfo (void)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: mld_grpalloc
|
||||
*
|
||||
* Description:
|
||||
* Allocate a new group from heap memory.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR struct mld_group_s *mld_grpalloc(FAR struct net_driver_s *dev,
|
||||
FAR const net_ipv6addr_t addr)
|
||||
{
|
||||
FAR struct mld_group_s *group;
|
||||
|
||||
ninfo("addr: %08x dev: %p\n", *addr, dev);
|
||||
group = (FAR struct mld_group_s *)kmm_zalloc(sizeof(struct mld_group_s));
|
||||
|
||||
grpinfo("group: %p\n", group);
|
||||
|
||||
/* Check if we successfully allocated a group structure */
|
||||
|
||||
if (group != NULL)
|
||||
{
|
||||
/* Initialize the non-zero elements of the group structure */
|
||||
|
||||
net_ipv6addr_copy(group->grpaddr, addr);
|
||||
|
||||
/* This semaphore is used for signaling and, hence, should not have
|
||||
* priority inheritance enabled.
|
||||
*/
|
||||
|
||||
nxsem_init(&group->sem, 0, 0);
|
||||
nxsem_setprotocol(&group->sem, SEM_PRIO_NONE);
|
||||
|
||||
/* Initialize the group timer (but don't start it yet) */
|
||||
|
||||
group->wdog = wd_create();
|
||||
DEBUGASSERT(group->wdog);
|
||||
|
||||
/* Interrupts must be disabled in order to modify the group list */
|
||||
|
||||
net_lock();
|
||||
|
||||
/* Add the group structure to the list in the device structure */
|
||||
|
||||
sq_addfirst((FAR sq_entry_t *)group, &dev->grplist);
|
||||
net_unlock();
|
||||
}
|
||||
|
||||
return group;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: mld_grpfind
|
||||
*
|
||||
* Description:
|
||||
* Find an existing group.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR struct mld_group_s *mld_grpfind(FAR struct net_driver_s *dev,
|
||||
FAR const net_ipv6addr_t addr)
|
||||
{
|
||||
FAR struct mld_group_s *group;
|
||||
|
||||
grpinfo("Searching for addr %08x\n", (int)*addr);
|
||||
|
||||
net_lock();
|
||||
for (group = (FAR struct mld_group_s *)dev->grplist.head;
|
||||
group;
|
||||
group = group->next)
|
||||
{
|
||||
grpinfo("Compare: %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n",
|
||||
group->grpaddr[0], group->grpaddr[1], group->grpaddr[2],
|
||||
group->grpaddr[3], group->grpaddr[4], group->grpaddr[5],
|
||||
group->grpaddr[6], group->grpaddr[7]);
|
||||
grpinfo("Versus: %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n",
|
||||
addr[0], addr[1], addr[2], addr[3],
|
||||
addr[4], addr[5], addr[6], addr[7]);
|
||||
|
||||
if (net_ipv6addr_cmp(group->grpaddr, addr))
|
||||
{
|
||||
grpinfo("Match!\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
net_unlock();
|
||||
return group;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: mld_grpallocfind
|
||||
*
|
||||
* Description:
|
||||
* Find an existing group. If not found, create a new group for the
|
||||
* address.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR struct mld_group_s *mld_grpallocfind(FAR struct net_driver_s *dev,
|
||||
FAR const net_ipv6addr_t addr)
|
||||
{
|
||||
FAR struct mld_group_s *group = mld_grpfind(dev, addr);
|
||||
|
||||
grpinfo("group: %p addr: %08x\n", group, (int)*addr);
|
||||
if (!group)
|
||||
{
|
||||
group = mld_grpalloc(dev, addr);
|
||||
}
|
||||
|
||||
grpinfo("group: %p\n", group);
|
||||
return group;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: mld_grpfree
|
||||
*
|
||||
* Description:
|
||||
* Release a previously allocated group.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void mld_grpfree(FAR struct net_driver_s *dev, FAR struct mld_group_s *group)
|
||||
{
|
||||
grpinfo("Free: %p flags: %02x\n", group, group->flags);
|
||||
|
||||
/* Cancel the wdog */
|
||||
|
||||
net_lock();
|
||||
wd_cancel(group->wdog);
|
||||
|
||||
/* Remove the group structure from the group list in the device structure */
|
||||
|
||||
sq_rem((FAR sq_entry_t *)group, &dev->grplist);
|
||||
|
||||
/* Destroy the wait semaphore */
|
||||
|
||||
(void)nxsem_destroy(&group->sem);
|
||||
|
||||
/* Destroy the wdog */
|
||||
|
||||
wd_delete(group->wdog);
|
||||
|
||||
/* Then release the group structure resources. */
|
||||
|
||||
net_unlock();
|
||||
grpinfo("Call sched_kfree()\n");
|
||||
sched_kfree(group);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NET_MLD */
|
||||
|
90
net/mld/mld_initialize.c
Normal file
90
net/mld/mld_initialize.c
Normal file
|
@ -0,0 +1,90 @@
|
|||
/****************************************************************************
|
||||
* net/mld/mld_init.c
|
||||
* MLD initialization logic
|
||||
*
|
||||
* Copyright (C) 2018 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of CITEL Technologies Ltd nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY CITEL TECHNOLOGIES AND CONTRIBUTORS ``AS IS''
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL CITEL TECHNOLOGIES OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/net/netdev.h>
|
||||
#include <nuttx/net/ip.h>
|
||||
#include <nuttx/net/mld.h>
|
||||
|
||||
#include "devif/devif.h"
|
||||
#include "inet/inet.h"
|
||||
#include "mld/mld.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: mld_initialize
|
||||
*
|
||||
* Description:
|
||||
* Perform one-time MLD initialization.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void mld_initialize(void)
|
||||
{
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: mld_devinit
|
||||
*
|
||||
* Description:
|
||||
* Called when a new network device is registered to configure that device
|
||||
* for MLD support.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void mld_devinit(struct net_driver_s *dev)
|
||||
{
|
||||
ninfo("MLD initializing dev %p\n", dev);
|
||||
DEBUGASSERT(dev->grplist.head == NULL);
|
||||
|
||||
/* Add the all nodes address to the group */
|
||||
|
||||
(void)mld_grpalloc(dev, g_ipv6_allnodes);
|
||||
|
||||
/* Allow the MLD messages at the MAC level */
|
||||
|
||||
mld_addmcastmac(dev, g_ipv6_allrouters);
|
||||
mld_addmcastmac(dev, g_ipv6_allnodes);
|
||||
}
|
176
net/mld/mld_join.c
Normal file
176
net/mld/mld_join.c
Normal file
|
@ -0,0 +1,176 @@
|
|||
/****************************************************************************
|
||||
* net/mld/mld_join.c
|
||||
*
|
||||
* Copyright (C) 2018 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of CITEL Technologies Ltd nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY CITEL TECHNOLOGIES AND CONTRIBUTORS ``AS IS''
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL CITEL TECHNOLOGIES OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <nuttx/net/netconfig.h>
|
||||
#include <nuttx/net/netstats.h>
|
||||
#include <nuttx/net/ip.h>
|
||||
#include <nuttx/net/mld.h>
|
||||
|
||||
#include "devif/devif.h"
|
||||
#include "mld/mld.h"
|
||||
|
||||
#ifdef CONFIG_NET_MLD
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: mld_joingroup
|
||||
*
|
||||
* Description:
|
||||
* Add the specified group address to the group.
|
||||
*
|
||||
* State transition diagram for a router in Querier state (RFC 2710):
|
||||
* ________________
|
||||
* | |
|
||||
* | |timer expired
|
||||
* timer expired| |(notify routing -,
|
||||
* (notify routing -)| No Listeners |clear rxmt tmr)
|
||||
* ------->| Present |<---------
|
||||
* | | | |
|
||||
* | | | |
|
||||
* | |________________| | ---------------
|
||||
* | | | | rexmt timer |
|
||||
* | report received| | | expired |
|
||||
* | (notify routing +,| | | (send m-a-s |
|
||||
* | start timer)| | | query, |
|
||||
* __________|______ | ________|_|______ st rxmt |
|
||||
* | |<------------ | | tmr) |
|
||||
* | | | |<-------
|
||||
* | | report received | |
|
||||
* | | (start timer, | |
|
||||
* | | clear rxmt tmr) | |
|
||||
* | Listeners |<-------------------| Checking |
|
||||
* | Present | done received | Listeners |
|
||||
* | | (start timer*, | |
|
||||
* | | start rxmt timer, | |
|
||||
* | | send m-a-s query) | |
|
||||
* --->| |------------------->| |
|
||||
* | |_________________| |_________________|
|
||||
* | report received |
|
||||
* | (start timer) |
|
||||
* -----------------
|
||||
*
|
||||
* State transition diagram for a router in Non-Querier state is
|
||||
* similar, but non-Queriers do not send any messages and are only
|
||||
* driven by message reception.
|
||||
*
|
||||
* ________________
|
||||
* | |
|
||||
* | |
|
||||
* timer expired| |timer expired
|
||||
* (notify routing -)| No Listeners |(notify routing -)
|
||||
* --------->| Present |<---------
|
||||
* | | | |
|
||||
* | | | |
|
||||
* | | | |
|
||||
* | |________________| |
|
||||
* | | |
|
||||
* | |report received |
|
||||
* | |(notify routing +,|
|
||||
* | | start timer) |
|
||||
* ________|________ | ________|________
|
||||
* | |<--------- | |
|
||||
* | | report received | |
|
||||
* | | (start timer) | |
|
||||
* | Listeners |<-------------------| Checking |
|
||||
* | Present | m-a-s query rec'd | Listeners |
|
||||
* | | (start timer*) | |
|
||||
* ---->| |------------------->| |
|
||||
* | |_________________| |_________________|
|
||||
* | report received |
|
||||
* | (start timer) |
|
||||
* -----------------
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int mld_joingroup(struct net_driver_s *dev, FAR const struct in6_addr *grpaddr)
|
||||
{
|
||||
struct mld_group_s *group;
|
||||
|
||||
DEBUGASSERT(dev != NULL && grpaddr != NULL);
|
||||
|
||||
/* Check if a this address is already in the group */
|
||||
|
||||
group = mld_grpfind(dev, grpaddr->s6_addr16);
|
||||
if (group == NULL)
|
||||
{
|
||||
/* No... allocate a new entry */
|
||||
|
||||
ninfo("Join to new group: %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n",
|
||||
grpaddr->s6_addr16[0], grpaddr->s6_addr16[1],
|
||||
grpaddr->s6_addr16[2], grpaddr->s6_addr16[3],
|
||||
grpaddr->s6_addr16[4], grpaddr->s6_addr16[5],
|
||||
grpaddr->s6_addr16[5], grpaddr->s6_addr16[7);
|
||||
|
||||
group = mld_grpalloc(dev, grpaddr->s6_addr16);
|
||||
if (group == NULL)
|
||||
{
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
MLD_STATINCR(g_netstats.mld.joins);
|
||||
|
||||
/* Send the Version 1 Multicast Listener Report */
|
||||
|
||||
MLD_STATINCR(g_netstats.mld.report_sched);
|
||||
mld_waitmsg(group, ICMPV6_MCAST_LISTEN_REPORT_V1);
|
||||
|
||||
/* And start the timer at 10*100 msec */
|
||||
|
||||
mld_starttimer(group, 10);
|
||||
|
||||
/* Add the group (MAC) address to the ether drivers MAC filter list */
|
||||
|
||||
mld_addmcastmac(dev, grpaddr->s6_addr16);
|
||||
return OK;
|
||||
}
|
||||
|
||||
/* Return EEXIST if the address is already a member of the group */
|
||||
|
||||
return -EEXIST;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NET_MLD */
|
185
net/mld/mld_leave.c
Normal file
185
net/mld/mld_leave.c
Normal file
|
@ -0,0 +1,185 @@
|
|||
/****************************************************************************
|
||||
* net/mld/mld_leave.c
|
||||
*
|
||||
* Copyright (C) 2018 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of CITEL Technologies Ltd nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY CITEL TECHNOLOGIES AND CONTRIBUTORS ``AS IS''
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL CITEL TECHNOLOGIES OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <nuttx/wdog.h>
|
||||
#include <nuttx/net/netconfig.h>
|
||||
#include <nuttx/net/net.h>
|
||||
#include <nuttx/net/netstats.h>
|
||||
#include <nuttx/net/ip.h>
|
||||
#include <nuttx/net/mld.h>
|
||||
|
||||
#include "devif/devif.h"
|
||||
#include "mld/mld.h"
|
||||
|
||||
#ifdef CONFIG_NET_MLD
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: mld_leavegroup
|
||||
*
|
||||
* Description:
|
||||
* Remove the specified group address to the group.
|
||||
*
|
||||
* State transition diagram for a router in Querier state (RFC 2710):
|
||||
* ________________
|
||||
* | |
|
||||
* | |timer expired
|
||||
* timer expired| |(notify routing -,
|
||||
* (notify routing -)| No Listeners |clear rxmt tmr)
|
||||
* ------->| Present |<---------
|
||||
* | | | |
|
||||
* | | | |
|
||||
* | |________________| | ---------------
|
||||
* | | | | rexmt timer |
|
||||
* | report received| | | expired |
|
||||
* | (notify routing +,| | | (send m-a-s |
|
||||
* | start timer)| | | query, |
|
||||
* __________|______ | ________|_|______ st rxmt |
|
||||
* | |<------------ | | tmr) |
|
||||
* | | | |<-------
|
||||
* | | report received | |
|
||||
* | | (start timer, | |
|
||||
* | | clear rxmt tmr) | |
|
||||
* | Listeners |<-------------------| Checking |
|
||||
* | Present | done received | Listeners |
|
||||
* | | (start timer*, | |
|
||||
* | | start rxmt timer, | |
|
||||
* | | send m-a-s query) | |
|
||||
* --->| |------------------->| |
|
||||
* | |_________________| |_________________|
|
||||
* | report received |
|
||||
* | (start timer) |
|
||||
* -----------------
|
||||
*
|
||||
* State transition diagram for a router in Non-Querier state is
|
||||
* similar, but non-Queriers do not send any messages and are only
|
||||
* driven by message reception.
|
||||
*
|
||||
* ________________
|
||||
* | |
|
||||
* | |
|
||||
* timer expired| |timer expired
|
||||
* (notify routing -)| No Listeners |(notify routing -)
|
||||
* --------->| Present |<---------
|
||||
* | | | |
|
||||
* | | | |
|
||||
* | | | |
|
||||
* | |________________| |
|
||||
* | | |
|
||||
* | |report received |
|
||||
* | |(notify routing +,|
|
||||
* | | start timer) |
|
||||
* ________|________ | ________|________
|
||||
* | |<--------- | |
|
||||
* | | report received | |
|
||||
* | | (start timer) | |
|
||||
* | Listeners |<-------------------| Checking |
|
||||
* | Present | m-a-s query rec'd | Listeners |
|
||||
* | | (start timer*) | |
|
||||
* ---->| |------------------->| |
|
||||
* | |_________________| |_________________|
|
||||
* | report received |
|
||||
* | (start timer) |
|
||||
* -----------------
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int mld_leavegroup(struct net_driver_s *dev, FAR const struct in6_addr *grpaddr)
|
||||
{
|
||||
struct mld_group_s *group;
|
||||
|
||||
DEBUGASSERT(dev != NULL && grpaddr != NULL);
|
||||
|
||||
/* Find the entry corresponding to the address leaving the group */
|
||||
|
||||
group = mld_grpfind(dev, grpaddr->s6_addr16);
|
||||
|
||||
ninfo("Leaving group: %p\n", group);
|
||||
|
||||
if (group != NULL)
|
||||
{
|
||||
/* Cancel the timer and discard any queued Reports. Canceling the
|
||||
* timer will prevent any new Reports from being sent; clearing the
|
||||
* flags will discard any pending Reports that could interfere with
|
||||
* leaving the group.
|
||||
*/
|
||||
|
||||
net_lock();
|
||||
wd_cancel(group->wdog);
|
||||
CLR_MLD_SCHEDMSG(group->flags);
|
||||
CLR_MLD_WAITMSG(group->flags);
|
||||
net_unlock();
|
||||
|
||||
MLD_STATINCR(g_netstats.mld.leaves);
|
||||
|
||||
/* Send a leave if the flag is set according to the state diagram */
|
||||
|
||||
if (IS_MLD_LASTREPORT(group->flags))
|
||||
{
|
||||
ninfo("Schedule Leave Group message\n");
|
||||
|
||||
MLD_STATINCR(g_netstats.mld.done_sched);
|
||||
mld_waitmsg(group, ICMPV6_MCAST_LISTEN_DONE_V1);
|
||||
}
|
||||
|
||||
/* Free the group structure */
|
||||
|
||||
mld_grpfree(dev, group);
|
||||
|
||||
/* And remove the group address from the ethernet drivers MAC filter set */
|
||||
|
||||
mld_removemcastmac(dev, grpaddr->s6_addr16);
|
||||
return OK;
|
||||
}
|
||||
|
||||
/* Return ENOENT if the address is not a member of the group */
|
||||
|
||||
ninfo("Return -ENOENT\n");
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NET_MLD */
|
139
net/mld/mld_mcastmac.c
Normal file
139
net/mld/mld_mcastmac.c
Normal file
|
@ -0,0 +1,139 @@
|
|||
/****************************************************************************
|
||||
* net/mld/mld_mcastmac.c
|
||||
*
|
||||
* Copyright (C) 2018 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of CITEL Technologies Ltd nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY CITEL TECHNOLOGIES AND CONTRIBUTORS ``AS IS''
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL CITEL TECHNOLOGIES OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/net/netconfig.h>
|
||||
#include <nuttx/net/netdev.h>
|
||||
#include <nuttx/net/ip.h>
|
||||
#include <nuttx/net/mld.h>
|
||||
|
||||
#include "devif/devif.h"
|
||||
#include "mld/mld.h"
|
||||
|
||||
#ifdef CONFIG_NET_MLD
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: mld_mcastmac
|
||||
*
|
||||
* Description:
|
||||
* Given an IP address (in network order), create a MLD multicast MAC
|
||||
* address.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void mld_mcastmac(FAR const net_ipv6addr_t ipaddr, FAR uint8_t *mac)
|
||||
{
|
||||
FAR uint8_t *ipaddr8 = (FAR uint8_t *)ipaddr;
|
||||
|
||||
ninfo("Mcast IP: %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n",
|
||||
ipaddr[0], ipaddr[1], ipaddr[2], ipaddr[3],
|
||||
ipaddr[4], ipaddr[5], ipaddr[6], ipaddr[7]);
|
||||
ninfo("IP: 0")
|
||||
|
||||
/* For the MAC address by insert the low 32 Bits of the multicast IPv6
|
||||
* Address into the Ethernet Address . This mapping is from the IETF
|
||||
* RFC 7042.
|
||||
*/
|
||||
|
||||
mac[0] = 0x33;
|
||||
mac[1] = 0x33;
|
||||
mac[2] = ipaddr8[12]; /* Bits: 96-103 */
|
||||
mac[2] = ipaddr8[13]; /* Bits: 104-111 */
|
||||
mac[2] = ipaddr8[14]; /* Bits: 112-119 */
|
||||
mac[2] = ipaddr8[15]; /* Bits: 120-127 */
|
||||
|
||||
ninfo("Mcast MAC: %02x:%02x:%02x:%02x:%02x:%02x\n",
|
||||
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: mld_addmcastmac
|
||||
*
|
||||
* Description:
|
||||
* Add an MLD MAC address to the device's MAC filter table.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void mld_addmcastmac(FAR struct net_driver_s *dev,
|
||||
FAR const net_ipv6addr_t ipaddr)
|
||||
{
|
||||
uint8_t mcastmac[6];
|
||||
|
||||
ninfo("Adding MAC address filter\n");
|
||||
|
||||
if (dev->d_addmac != NULL)
|
||||
{
|
||||
mld_mcastmac(ipaddr, mcastmac);
|
||||
dev->d_addmac(dev, mcastmac);
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: mld_removemcastmac
|
||||
*
|
||||
* Description:
|
||||
* Remove an MLD MAC address from the device's MAC filter table.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void mld_removemcastmac(FAR struct net_driver_s *dev,
|
||||
FAR const net_ipv6addr_t ipaddr)
|
||||
{
|
||||
uint8_t mcastmac[6];
|
||||
|
||||
ninfo("Removing MAC address filter\n");
|
||||
|
||||
if (dev->d_rmmac != NULL)
|
||||
{
|
||||
mld_mcastmac(ipaddr, mcastmac);
|
||||
dev->d_rmmac(dev, mcastmac);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NET_MLD */
|
122
net/mld/mld_msg.c
Normal file
122
net/mld/mld_msg.c
Normal file
|
@ -0,0 +1,122 @@
|
|||
/****************************************************************************
|
||||
* net/mld/mld_msg.c
|
||||
*
|
||||
* Copyright (C) 2018 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of CITEL Technologies Ltd nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY CITEL TECHNOLOGIES AND CONTRIBUTORS ``AS IS''
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL CITEL TECHNOLOGIES OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/net/netconfig.h>
|
||||
#include <nuttx/net/net.h>
|
||||
#include <nuttx/net/mld.h>
|
||||
|
||||
#include "devif/devif.h"
|
||||
#include "mld/mld.h"
|
||||
|
||||
#ifdef CONFIG_NET_MLD
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: mld_schedmsg
|
||||
*
|
||||
* Description:
|
||||
* Schedule a message to be send at the next driver polling interval.
|
||||
*
|
||||
* Assumptions:
|
||||
* This function may be called in most any context.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void mld_schedmsg(FAR struct mld_group_s *group, uint8_t msgid)
|
||||
{
|
||||
/* The following should be atomic */
|
||||
|
||||
net_lock();
|
||||
DEBUGASSERT(!IS_MLD_SCHEDMSG(group->flags));
|
||||
group->msgid = msgid;
|
||||
SET_MLD_SCHEDMSG(group->flags);
|
||||
net_unlock();
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: mld_waitmsg
|
||||
*
|
||||
* Description:
|
||||
* Schedule a message to be send at the next driver polling interval and
|
||||
* block, waiting for the message to be sent.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void mld_waitmsg(FAR struct mld_group_s *group, uint8_t msgid)
|
||||
{
|
||||
int ret;
|
||||
|
||||
/* Schedule to send the message */
|
||||
|
||||
net_lock();
|
||||
DEBUGASSERT(!IS_MLD_WAITMSG(group->flags));
|
||||
SET_MLD_WAITMSG(group->flags);
|
||||
mld_schedmsg(group, msgid);
|
||||
|
||||
/* Then wait for the message to be sent */
|
||||
|
||||
while (IS_MLD_SCHEDMSG(group->flags))
|
||||
{
|
||||
/* Wait for the semaphore to be posted */
|
||||
|
||||
while ((ret = net_lockedwait(&group->sem)) < 0)
|
||||
{
|
||||
/* The only error that should occur from net_lockedwait() is if
|
||||
* the wait is awakened by a signal.
|
||||
*/
|
||||
|
||||
DEBUGASSERT(ret == -EINTR || ret == -ECANCELED);
|
||||
}
|
||||
|
||||
UNUSED(ret);
|
||||
}
|
||||
|
||||
/* The message has been sent and we are no longer waiting */
|
||||
|
||||
CLR_MLD_WAITMSG(group->flags);
|
||||
net_unlock();
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NET_MLD */
|
177
net/mld/mld_poll.c
Normal file
177
net/mld/mld_poll.c
Normal file
|
@ -0,0 +1,177 @@
|
|||
/****************************************************************************
|
||||
* net/mld/mld_poll.c
|
||||
*
|
||||
* Copyright (C) 2018 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of CITEL Technologies Ltd nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY CITEL TECHNOLOGIES AND CONTRIBUTORS ``AS IS''
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL CITEL TECHNOLOGIES OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/semaphore.h>
|
||||
#include <nuttx/net/netconfig.h>
|
||||
#include <nuttx/net/netdev.h>
|
||||
#include <nuttx/net/netstats.h>
|
||||
#include <nuttx/net/ip.h>
|
||||
|
||||
#include "devif/devif.h"
|
||||
#include "inet/inet.h"
|
||||
#include "mld/mld.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: mld_sched_send
|
||||
*
|
||||
* Description:
|
||||
* Construct and send the MLD message.
|
||||
*
|
||||
* Returned Value:
|
||||
* Returns a non-zero value if an MLD message is sent.
|
||||
*
|
||||
* Assumptions:
|
||||
* This function ust be called with the network locked.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static inline void mld_sched_send(FAR struct net_driver_s *dev,
|
||||
FAR struct mld_group_s *group)
|
||||
{
|
||||
const net_ipv6addr_t *dest;
|
||||
|
||||
/* Check what kind of message we need to send. There are only two
|
||||
* possibilities:
|
||||
*/
|
||||
|
||||
if (group->msgid == ICMPV6_MCAST_LISTEN_REPORT_V1)
|
||||
{
|
||||
dest = &group->grpaddr;
|
||||
|
||||
ninfo("Send ICMPV6_MCAST_LISTEN_REPORT_V1, flags=%02x\n", group->flags);
|
||||
ninfo("destipaddr: %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n",
|
||||
ipv6->destipaddr[0], ipv6->destipaddr[1], ipv6->destipaddr[2],
|
||||
ipv6->destipaddr[3], ipv6->destipaddr[4], ipv6->destipaddr[5],
|
||||
ipv6->destipaddr[6], ipv6->destipaddr[7]);
|
||||
|
||||
MLD_STATINCR(g_netstats.mld.report_sched);
|
||||
SET_MLD_LASTREPORT(group->flags); /* Remember we were the last to report */
|
||||
}
|
||||
else
|
||||
{
|
||||
DEBUGASSERT(group->msgid == ICMPV6_MCAST_LISTEN_DONE_V1);
|
||||
|
||||
dest = &g_ipv6_allrouters;
|
||||
|
||||
ninfo("Send ICMPV6_MCAST_LISTEN_DONE_V1, flags=%02x\n", group->flags);
|
||||
ninfo("destipaddr: %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n",
|
||||
ipv6->destipaddr[0], ipv6->destipaddr[1], ipv6->destipaddr[2],
|
||||
ipv6->destipaddr[3], ipv6->destipaddr[4], ipv6->destipaddr[5],
|
||||
ipv6->destipaddr[6], ipv6->destipaddr[7]);
|
||||
|
||||
MLD_STATINCR(g_netstats.mld.done_sched);
|
||||
}
|
||||
|
||||
/* Send the message */
|
||||
|
||||
mld_send(dev, group, *dest);
|
||||
|
||||
/* Indicate that the message has been sent */
|
||||
|
||||
CLR_MLD_SCHEDMSG(group->flags);
|
||||
group->msgid = 0;
|
||||
|
||||
/* If there is a thread waiting fore the message to be sent, wake it up */
|
||||
|
||||
if (IS_MLD_WAITMSG(group->flags))
|
||||
{
|
||||
ninfo("Awakening waiter\n");
|
||||
nxsem_post(&group->sem);
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: mld_poll
|
||||
*
|
||||
* Description:
|
||||
* Poll the groups associated with the device to see if any MLD messages
|
||||
* are pending transfer.
|
||||
*
|
||||
* Returned Value:
|
||||
* Returns a non-zero value if a IGP message is sent.
|
||||
*
|
||||
* Assumptions:
|
||||
* This function must be called with the network locked.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void mld_poll(FAR struct net_driver_s *dev)
|
||||
{
|
||||
FAR struct mld_group_s *group;
|
||||
|
||||
ninfo("Entry\n");
|
||||
|
||||
/* Setup the poll operation */
|
||||
|
||||
dev->d_appdata = &dev->d_buf[NET_LL_HDRLEN(dev) + IPv6_HDRLEN];
|
||||
dev->d_len = 0;
|
||||
dev->d_sndlen = 0;
|
||||
|
||||
/* Check each member of the group */
|
||||
|
||||
for (group = (FAR struct mld_group_s *)dev->grplist.head;
|
||||
group;
|
||||
group = group->next)
|
||||
{
|
||||
/* Does this member have a pending outgoing message? */
|
||||
|
||||
if (IS_MLD_SCHEDMSG(group->flags))
|
||||
{
|
||||
/* Yes, create the MLD message in the driver buffer */
|
||||
|
||||
mld_sched_send(dev, group);
|
||||
|
||||
/* Mark the message as sent and break out */
|
||||
|
||||
CLR_MLD_SCHEDMSG(group->flags);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
199
net/mld/mld_query.c
Normal file
199
net/mld/mld_query.c
Normal file
|
@ -0,0 +1,199 @@
|
|||
/****************************************************************************
|
||||
* net/mld/mld_query.c
|
||||
*
|
||||
* Copyright (C) 2018 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of CITEL Technologies Ltd nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY CITEL TECHNOLOGIES AND CONTRIBUTORS ``AS IS''
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL CITEL TECHNOLOGIES OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/wdog.h>
|
||||
#include <nuttx/net/netconfig.h>
|
||||
#include <nuttx/net/netstats.h>
|
||||
#include <nuttx/net/ip.h>
|
||||
#include <nuttx/net/mld.h>
|
||||
|
||||
#include "devif/devif.h"
|
||||
#include "inet/inet.h"
|
||||
#include "mld/mld.h"
|
||||
#include "utils/utils.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define IPv6BUF ((FAR struct ipv6_hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: mld_query
|
||||
*
|
||||
* Description:
|
||||
* Called from icmpv6_input() when a Multicast Listener Query is received.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int mld_query(FAR struct net_driver_s *dev,
|
||||
FAR const struct mld_mcast_listen_query_s *query)
|
||||
{
|
||||
FAR struct ipv6_hdr_s *ipv6 = IPv6BUF;
|
||||
FAR struct mld_group_s *group;
|
||||
unsigned int ticks;
|
||||
bool unspec;
|
||||
|
||||
ninfo("Multicast Listener Query\n");
|
||||
ninfo("destipaddr: %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n",
|
||||
ipv6->destipaddr[0], ipv6->destipaddr[1], ipv6->destipaddr[2],
|
||||
ipv6->destipaddr[3], ipv6->destipaddr[4], ipv6->destipaddr[5],
|
||||
ipv6->destipaddr[6], ipv6->destipaddr[7]);
|
||||
|
||||
/* Find the group (or create a new one) using the incoming IP address */
|
||||
|
||||
group = mld_grpallocfind(dev, ipv6->destipaddr);
|
||||
if (group == NULL)
|
||||
{
|
||||
nerr("ERROR: Failed to allocate/find group\n");
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
/* Max Response Time. The Max Response Time field is meaningful only in
|
||||
* Query messages, and specifies the maximum allowed time before sending
|
||||
* a responding report in units of 1/10 second. In all other messages,
|
||||
* it is set to zero by the sender and ignored by receivers.
|
||||
*/
|
||||
|
||||
/* Check if the query was sent to all systems */
|
||||
|
||||
unspec = net_ipv6addr_cmp(query->grpaddr, g_ipv6_unspecaddr);
|
||||
|
||||
if (net_ipv6addr_cmp(ipv6->destipaddr, g_ipv6_allnodes))
|
||||
{
|
||||
/* There are three variants of the Query message (RFC 3810):
|
||||
*
|
||||
* 1. A "General Query" is sent by the Querier to learn which
|
||||
* multicast addresses have listeners on an attached link. In a
|
||||
* General Query, both the Multicast Address field and the Number
|
||||
* of Sources (N) field are zero.
|
||||
* 2. A "Multicast Address Specific Query" is sent by the Querier to
|
||||
* learn if a particular multicast address has any listeners on an
|
||||
* attached link. In a Multicast Address Specific Query, the
|
||||
* Multicast Address field contains the multicast address of
|
||||
* interest, while the Number of Sources (N) field is set to zero.
|
||||
* 3. A "Multicast Address and Source Specific Query" is sent by the
|
||||
* Querier to learn if any of the sources from the specified list for
|
||||
* the particular multicast address has any listeners on an attached
|
||||
* link or not. In a Multicast Address and Source Specific Query the
|
||||
* Multicast Address field contains the multicast address of
|
||||
* interest, while the Source Address [i] field(s) contain(s) the
|
||||
* source address(es) of interest.
|
||||
*/
|
||||
|
||||
if (unspec && query->nsources == 0)
|
||||
{
|
||||
FAR struct mld_group_s *member;
|
||||
|
||||
/* This is the general query */
|
||||
|
||||
ninfo("General multicast query\n");
|
||||
MLD_STATINCR(g_netstats.mld.gmq_query_received);
|
||||
|
||||
for (member = (FAR struct mld_group_s *)dev->grplist.head;
|
||||
member;
|
||||
member = member->next)
|
||||
{
|
||||
/* Skip over the all systems group entry */
|
||||
|
||||
if (!net_ipv6addr_cmp(member->grpaddr, g_ipv6_allnodes))
|
||||
{
|
||||
ticks = net_dsec2tick((int)query->mrc);
|
||||
if (IS_MLD_IDLEMEMBER(member->flags) ||
|
||||
mld_cmptimer(member, ticks))
|
||||
{
|
||||
mld_startticks(member, ticks);
|
||||
CLR_MLD_IDLEMEMBER(member->flags);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (!unspec && query->nsources == 0)
|
||||
{
|
||||
ninfo("Multicast Address Specific Query\n");
|
||||
|
||||
/* We first need to re-lookup the group since we used dest last time.
|
||||
* Use the incoming IPaddress!
|
||||
*/
|
||||
|
||||
MLD_STATINCR(g_netstats.mld.mas_query_received);
|
||||
|
||||
group = mld_grpallocfind(dev, query->grpaddr);
|
||||
ticks = net_dsec2tick((int)query->mrc);
|
||||
|
||||
if (IS_MLD_IDLEMEMBER(group->flags) || mld_cmptimer(group, ticks))
|
||||
{
|
||||
mld_startticks(group, ticks);
|
||||
CLR_MLD_IDLEMEMBER(group->flags);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ninfo("Multicast Address and Source Specific Query\n");
|
||||
MLD_STATINCR(g_netstats.mld.massq_query_received);
|
||||
#warning Missing logic
|
||||
}
|
||||
}
|
||||
|
||||
/* Not sent to all systems -- Unicast query */
|
||||
|
||||
else if (!unspec)
|
||||
{
|
||||
ninfo("Unicast query\n");
|
||||
MLD_STATINCR(g_netstats.mld.ucast_query_received);
|
||||
|
||||
ninfo("Query to a specific group with the group address as destination\n");
|
||||
|
||||
ticks = net_dsec2tick((int)query->mrc);
|
||||
if (IS_MLD_IDLEMEMBER(group->flags) || mld_cmptimer(group, ticks))
|
||||
{
|
||||
mld_startticks(group, ticks);
|
||||
CLR_MLD_IDLEMEMBER(group->flags);
|
||||
}
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
147
net/mld/mld_report.c
Normal file
147
net/mld/mld_report.c
Normal file
|
@ -0,0 +1,147 @@
|
|||
/****************************************************************************
|
||||
* net/mld/mld_report.c
|
||||
*
|
||||
* Copyright (C) 2018 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of CITEL Technologies Ltd nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY CITEL TECHNOLOGIES AND CONTRIBUTORS ``AS IS''
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL CITEL TECHNOLOGIES OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/wdog.h>
|
||||
#include <nuttx/net/netstats.h>
|
||||
#include <nuttx/net/ip.h>
|
||||
#include <nuttx/net/mld.h>
|
||||
|
||||
#include "devif/devif.h"
|
||||
#include "mld/mld.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define IPv6BUF ((FAR struct ipv6_hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: mld_report_v1
|
||||
*
|
||||
* Description:
|
||||
* Called from icmpv6_input() when a Version 1 or Version 2 Multicast
|
||||
* Listener Report is received.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int mld_report_v1(FAR struct net_driver_s *dev,
|
||||
FAR const struct mld_mcast_listen_report_v1_s *report)
|
||||
{
|
||||
FAR struct ipv6_hdr_s *ipv6 = IPv6BUF;
|
||||
FAR struct mld_group_s *group;
|
||||
|
||||
ninfo("Version 1 Multicast Listener Report\n");
|
||||
ninfo("destipaddr: %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n",
|
||||
ipv6->destipaddr[0], ipv6->destipaddr[1], ipv6->destipaddr[2],
|
||||
ipv6->destipaddr[3], ipv6->destipaddr[4], ipv6->destipaddr[5],
|
||||
ipv6->destipaddr[6], ipv6->destipaddr[7]);
|
||||
|
||||
MLD_STATINCR(g_netstats.mld.v1report_received);
|
||||
|
||||
/* Find the group (or create a new one) using the incoming IP address */
|
||||
|
||||
group = mld_grpallocfind(dev, ipv6->destipaddr);
|
||||
if (group == NULL)
|
||||
{
|
||||
nerr("ERROR: Failed to allocate/find group\n");
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
if (!IS_MLD_IDLEMEMBER(group->flags))
|
||||
{
|
||||
/* This is on a specific group we have already looked up */
|
||||
|
||||
wd_cancel(group->wdog);
|
||||
SET_MLD_IDLEMEMBER(group->flags);
|
||||
CLR_MLD_LASTREPORT(group->flags);
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: mld_report_v2
|
||||
*
|
||||
* Description:
|
||||
* Called from icmpv6_input() when a Version 2 Multicast Listener Report is
|
||||
* received.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int mld_report_v2(FAR struct net_driver_s *dev,
|
||||
FAR const struct mld_mcast_listen_report_v2_s *report)
|
||||
{
|
||||
FAR struct ipv6_hdr_s *ipv6 = IPv6BUF;
|
||||
FAR struct mld_group_s *group;
|
||||
|
||||
ninfo("Version 2 Multicast Listener Report\n");
|
||||
ninfo("destipaddr: %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n",
|
||||
ipv6->destipaddr[0], ipv6->destipaddr[1], ipv6->destipaddr[2],
|
||||
ipv6->destipaddr[3], ipv6->destipaddr[4], ipv6->destipaddr[5],
|
||||
ipv6->destipaddr[6], ipv6->destipaddr[7]);
|
||||
|
||||
MLD_STATINCR(g_netstats.mld.v2report_received);
|
||||
|
||||
/* Find the group (or create a new one) using the incoming IP address */
|
||||
|
||||
group = mld_grpallocfind(dev, ipv6->destipaddr);
|
||||
if (group == NULL)
|
||||
{
|
||||
nerr("ERROR: Failed to allocate/find group\n");
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
if (!IS_MLD_IDLEMEMBER(group->flags))
|
||||
{
|
||||
/* This is on a specific group we have already looked up */
|
||||
|
||||
wd_cancel(group->wdog);
|
||||
SET_MLD_IDLEMEMBER(group->flags);
|
||||
CLR_MLD_LASTREPORT(group->flags);
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
250
net/mld/mld_send.c
Normal file
250
net/mld/mld_send.c
Normal file
|
@ -0,0 +1,250 @@
|
|||
/****************************************************************************
|
||||
* net/mld/mld_send.c
|
||||
*
|
||||
* Copyright (C) 2018 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <debug.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include <nuttx/net/netconfig.h>
|
||||
#include <nuttx/net/netdev.h>
|
||||
#include <nuttx/net/netstats.h>
|
||||
#include <nuttx/net/ip.h>
|
||||
#include <nuttx/net/ipopt.h>
|
||||
#include <nuttx/net/tcp.h>
|
||||
#include <nuttx/net/mld.h>
|
||||
|
||||
#include "devif/devif.h"
|
||||
#include "inet/inet.h"
|
||||
#include "utils/utils.h"
|
||||
#include "mld/mld.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Debug */
|
||||
|
||||
#undef MLD_DUMPPKT /* Define to enable packet dump */
|
||||
|
||||
#ifndef CONFIG_DEBUG_NET
|
||||
# undef MLD_DUMPPKT
|
||||
#endif
|
||||
|
||||
#ifdef MLD_DUMPPKT
|
||||
# define mld_dumppkt(b,n) lib_dumpbuffer("MLD", (FAR const uint8_t*)(b), (n))
|
||||
#else
|
||||
# define mld_dumppkt(b,n)
|
||||
#endif
|
||||
|
||||
/* Buffer layout */
|
||||
|
||||
#define IPv6BUF ((FAR struct ipv6_hdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
|
||||
#define RABUF ((FAR uint8_t *)&dev->d_buf[NET_LL_HDRLEN(dev)] + \
|
||||
IPv6_HDRLEN)
|
||||
#define RASIZE (4 * sizeof(uint16_t))
|
||||
#define REPORTBUF ((FAR struct mld_mcast_listen_report_v1_s *) \
|
||||
&dev->d_buf[NET_LL_HDRLEN(dev)] + IPv6_HDRLEN + RASIZE)
|
||||
#define DONEBUF ((FAR struct mld_mcast_listen_done_v1_s *) \
|
||||
&dev->d_buf[NET_LL_HDRLEN(dev)] + IPv6_HDRLEN + RASIZE)
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: mld_send
|
||||
*
|
||||
* Description:
|
||||
* Sends an MLD IP packet on a network interface. This function constructs
|
||||
* the IP header and calculates the IP header checksum.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev - The device driver structure to use in the send operation.
|
||||
* group - Describes the multicast group member and identifies the
|
||||
* message to be sent.
|
||||
* destipaddr - The IP address of the recipient of the message
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
* Assumptions:
|
||||
* The network is locked.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void mld_send(FAR struct net_driver_s *dev, FAR struct mld_group_s *group,
|
||||
FAR const net_ipv6addr_t destipaddr)
|
||||
{
|
||||
FAR struct ipv6_hdr_s *ipv6;
|
||||
FAR uint8_t *ra;
|
||||
unsigned int mldsize;
|
||||
|
||||
ninfo("msgid: %02x \n", group->msgid);
|
||||
ninfo("destipaddr: %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n",
|
||||
destipaddr[0], destipaddr[1], destipaddr[2], destipaddr[3],
|
||||
destipaddr[4], destipaddr[5], destipaddr[6], destipaddr[7]);
|
||||
|
||||
/* Select IPv6 */
|
||||
|
||||
IFF_SET_IPv6(dev->d_flags);
|
||||
|
||||
/* What is the size of the ICMPv6 payload? Currently only Version 1
|
||||
* REPORT and DONE packets are sent (these are actually the same size).
|
||||
* This will change.
|
||||
*/
|
||||
|
||||
switch (group->msgid)
|
||||
{
|
||||
case ICMPV6_MCAST_LISTEN_REPORT_V1:
|
||||
mldsize = sizeof(struct mld_mcast_listen_report_v1_s);
|
||||
break;
|
||||
|
||||
case ICMPV6_MCAST_LISTEN_DONE_V1:
|
||||
mldsize = sizeof(struct mld_mcast_listen_done_v1_s);
|
||||
break;
|
||||
|
||||
/* Not yet supported */
|
||||
|
||||
case ICMPV6_MCAST_LISTEN_QUERY:
|
||||
case ICMPV6_MCAST_LISTEN_REPORT_V2:
|
||||
default:
|
||||
DEBUGPANIC();
|
||||
return;
|
||||
}
|
||||
|
||||
/* The total length to send is the size of the IPv6 header, 4 bytes for the
|
||||
* ROUTER ALERT, and the MLD ICMPv6 payload (and, eventually, the Ethernet
|
||||
* header length)
|
||||
*/
|
||||
|
||||
dev->d_len = IPv6_HDRLEN + RASIZE + mldsize;
|
||||
|
||||
/* The total size of the data is the size of the ICMPv6 payload */
|
||||
|
||||
dev->d_sndlen = mldsize;
|
||||
|
||||
/* Set up the IPv6 header */
|
||||
|
||||
ipv6 = IPv6BUF;
|
||||
ipv6->vtc = 0x60; /* Version/traffic class (MS) */
|
||||
ipv6->tcf = 0; /* Traffic class(LS)/Flow label(MS) */
|
||||
ipv6->flow = 0; /* Flow label (LS) */
|
||||
ipv6->len[0] = (dev->d_sndlen >> 8); /* Length excludes the IPv6 header */
|
||||
ipv6->len[1] = (dev->d_sndlen & 0xff);
|
||||
ipv6->proto = IP_PROTO_ICMP6; /* ICMPv6 payload */
|
||||
ipv6->ttl = MLD_TTL; /* MLD Time-to-live */
|
||||
|
||||
net_ipv6addr_hdrcopy(ipv6->srcipaddr, dev->d_ipv6addr);
|
||||
net_ipv6addr_hdrcopy(ipv6->destipaddr, destipaddr);
|
||||
|
||||
/* Add the router alert IP header option.
|
||||
*
|
||||
* The IPv6 router alert option (type 5) is defined in RFC 2711.
|
||||
* REVISIT: This should go into a new header file ipv6opt.h
|
||||
*/
|
||||
|
||||
ra = RABUF;
|
||||
ra[0] = 5; /* Option type */
|
||||
ra[1] = 2; /* Option length */
|
||||
ra[2] = 0; /* Router alert value */
|
||||
ra[3] = 0;
|
||||
|
||||
/* Format the MLD ICMPv6 payload into place after the IPv6 header (with
|
||||
* router alert)
|
||||
*/
|
||||
|
||||
switch (group->msgid)
|
||||
{
|
||||
case ICMPV6_MCAST_LISTEN_REPORT_V1:
|
||||
{
|
||||
FAR struct mld_mcast_listen_report_v1_s *report = REPORTBUF;
|
||||
|
||||
/* Initializer the Report payload */
|
||||
|
||||
memset(report, 0, sizeof(struct mld_mcast_listen_report_v1_s));
|
||||
report->type = ICMPV6_MCAST_LISTEN_REPORT_V1;
|
||||
net_ipv6addr_hdrcopy(report->mcastaddr, &group->grpaddr);
|
||||
|
||||
/* Calculate the ICMPv6 checksum. */
|
||||
|
||||
report->chksum = 0;
|
||||
report->chksum = ~icmpv6_chksum(dev);
|
||||
|
||||
MLD_STATINCR(g_netstats.mld.report_sent);
|
||||
}
|
||||
break;
|
||||
|
||||
case ICMPV6_MCAST_LISTEN_DONE_V1:
|
||||
{
|
||||
FAR struct mld_mcast_listen_done_v1_s *done = DONEBUF;
|
||||
|
||||
/* Initializer the Done payload */
|
||||
|
||||
memset(done, 0, sizeof(struct mld_mcast_listen_done_v1_s));
|
||||
done->type = ICMPV6_MCAST_LISTEN_DONE_V1;
|
||||
net_ipv6addr_hdrcopy(done->mcastaddr, &group->grpaddr);
|
||||
|
||||
/* Calculate the ICMPv6 checksum. */
|
||||
|
||||
done->chksum = 0;
|
||||
done->chksum = ~icmpv6_chksum(dev);
|
||||
|
||||
MLD_STATINCR(g_netstats.mld.done_sent);
|
||||
}
|
||||
break;
|
||||
|
||||
/* Not yet supported */
|
||||
|
||||
case ICMPV6_MCAST_LISTEN_QUERY:
|
||||
case ICMPV6_MCAST_LISTEN_REPORT_V2:
|
||||
default:
|
||||
DEBUGPANIC();
|
||||
return;
|
||||
}
|
||||
|
||||
MLD_STATINCR(g_netstats.icmpv6.sent);
|
||||
MLD_STATINCR(g_netstats.ipv6.sent);
|
||||
|
||||
ninfo("Outgoing ICMPv6 MLD packet length: %d (%d)\n",
|
||||
dev->d_len, (ipv6->len[0] << 8) | ipv6->len[1]);
|
||||
|
||||
mld_dumppkt(RA, IPMLD_HDRLEN + RASIZE);
|
||||
}
|
229
net/mld/mld_timer.c
Normal file
229
net/mld/mld_timer.c
Normal file
|
@ -0,0 +1,229 @@
|
|||
/****************************************************************************
|
||||
* net/mld/mld_timer.c
|
||||
*
|
||||
* Copyright (C) 2018 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of CITEL Technologies Ltd nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY CITEL TECHNOLOGIES AND CONTRIBUTORS ``AS IS''
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL CITEL TECHNOLOGIES OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/compiler.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/wdog.h>
|
||||
#include <nuttx/irq.h>
|
||||
#include <nuttx/net/netconfig.h>
|
||||
#include <nuttx/net/net.h>
|
||||
#include <nuttx/net/netstats.h>
|
||||
#include <nuttx/net/mld.h>
|
||||
|
||||
#include "devif/devif.h"
|
||||
#include "mld/mld.h"
|
||||
#include "utils/utils.h"
|
||||
|
||||
#ifdef CONFIG_NET_MLD
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Debug ********************************************************************/
|
||||
|
||||
#undef MLD_GTMRDEBUG /* Define to enable detailed MLD group debug */
|
||||
|
||||
#ifndef CONFIG_NET_MLD
|
||||
# undef MLD_GTMRDEBUG
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_CPP_HAVE_VARARGS
|
||||
# ifdef MLD_GTMRDEBUG
|
||||
# define gtmrerr(format, ...) nerr(format, ##__VA_ARGS__)
|
||||
# define gtmrinfo(format, ...) ninfo(format, ##__VA_ARGS__)
|
||||
# else
|
||||
# define gtmrerr(x...)
|
||||
# define gtmrinfo(x...)
|
||||
# endif
|
||||
#else
|
||||
# ifdef MLD_GTMRDEBUG
|
||||
# define gtmrerr nerr
|
||||
# define gtmrinfo ninfo
|
||||
# else
|
||||
# define gtmrerr (void)
|
||||
# define gtmrinfo (void)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: mld_timeout
|
||||
*
|
||||
* Description:
|
||||
* Timeout watchdog handler.
|
||||
*
|
||||
* Assumptions:
|
||||
* This function is called from the wdog timer handler which runs in the
|
||||
* context of the timer interrupt handler.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void mld_timeout(int argc, uint32_t arg, ...)
|
||||
{
|
||||
FAR struct mld_group_s *group;
|
||||
|
||||
/* If the state is DELAYING_MEMBER then we send a report for this group */
|
||||
|
||||
ninfo("Timeout!\n");
|
||||
group = (FAR struct mld_group_s *)arg;
|
||||
DEBUGASSERT(argc == 1 && group);
|
||||
|
||||
/* If the group exists and is no an IDLE MEMBER, then it must be a DELAYING
|
||||
* member. Race conditions are avoided because (1) the timer is not started
|
||||
* until after the first MLDv2_MEMBERSHIP_REPORT during the join, and (2)
|
||||
* the timer is canceled before sending the ICMPV6_MCAST_LISTEN_DONE_V1
|
||||
* during a leave.
|
||||
*/
|
||||
|
||||
if (!IS_MLD_IDLEMEMBER(group->flags))
|
||||
{
|
||||
/* Schedule (and forget) the Report. NOTE: Since we are executing
|
||||
* from a timer interrupt, we cannot wait for the message to be sent.
|
||||
*/
|
||||
|
||||
MLD_STATINCR(g_netstats.mld.report_sched);
|
||||
mld_schedmsg(group, ICMPV6_MCAST_LISTEN_REPORT_V1);
|
||||
|
||||
/* Also note: The Report is sent at most two times because the timer
|
||||
* is not reset here. Hmm.. does this mean that the group is stranded
|
||||
* if both reports were lost? This is consistent with the
|
||||
* RFC that states: "To cover the possibility of the initial Report
|
||||
* being lost or damaged, it is recommended that it be repeated once
|
||||
* or twice after short delays [Unsolicited Report Interval]...."
|
||||
* (RFC 2710).
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: mld_startticks and mld_starttimer
|
||||
*
|
||||
* Description:
|
||||
* Start the MLD timer with differing time units (ticks or deciseconds).
|
||||
*
|
||||
* Assumptions:
|
||||
* This function may be called from most any context.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void mld_startticks(FAR struct mld_group_s *group, unsigned int ticks)
|
||||
{
|
||||
int ret;
|
||||
|
||||
/* Start the timer */
|
||||
|
||||
gtmrinfo("ticks: %d\n", ticks);
|
||||
|
||||
ret = wd_start(group->wdog, ticks, mld_timeout, 1, (uint32_t)group);
|
||||
|
||||
DEBUGASSERT(ret == OK);
|
||||
UNUSED(ret);
|
||||
}
|
||||
|
||||
void mld_starttimer(FAR struct mld_group_s *group, uint8_t decisecs)
|
||||
{
|
||||
/* Convert the decisec value to system clock ticks and start the timer.
|
||||
* Important!! this should be a random timer from 0 to decisecs
|
||||
*/
|
||||
|
||||
gtmrinfo("decisecs: %d\n", decisecs);
|
||||
mld_startticks(group, net_dsec2tick(decisecs));
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: mld_cmptimer
|
||||
*
|
||||
* Description:
|
||||
* Compare the timer remaining on the watching timer to the deci-second
|
||||
* value. If maxticks > ticks-remaining, then (1) cancel the timer (to
|
||||
* avoid race conditions) and return true.
|
||||
*
|
||||
* Assumptions:
|
||||
* This function may be called from most any context. If true is returned
|
||||
* then the caller must call mld_startticks() to restart the timer
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
bool mld_cmptimer(FAR struct mld_group_s *group, int maxticks)
|
||||
{
|
||||
irqstate_t flags;
|
||||
int remaining;
|
||||
|
||||
/* Disable interrupts so that there is no race condition with the actual
|
||||
* timer expiration.
|
||||
*/
|
||||
|
||||
flags = enter_critical_section();
|
||||
|
||||
/* Get the timer remaining on the watchdog. A time of <= zero means that
|
||||
* the watchdog was never started.
|
||||
*/
|
||||
|
||||
remaining = wd_gettime(group->wdog);
|
||||
|
||||
/* A remaining time of zero means that the watchdog was never started
|
||||
* or has already expired. That case should be covered in the following
|
||||
* test as well.
|
||||
*/
|
||||
|
||||
gtmrinfo("maxticks: %d remaining: %d\n", maxticks, remaining);
|
||||
if (maxticks > remaining)
|
||||
{
|
||||
/* Cancel the watchdog timer and return true */
|
||||
|
||||
wd_cancel(group->wdog);
|
||||
leave_critical_section(flags);
|
||||
return true;
|
||||
}
|
||||
|
||||
leave_critical_section(flags);
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NET_MLD */
|
|
@ -57,6 +57,7 @@
|
|||
|
||||
#include "utils/utils.h"
|
||||
#include "igmp/igmp.h"
|
||||
#include "mld/mld.h"
|
||||
#include "netdev/netdev.h"
|
||||
|
||||
#if defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0
|
||||
|
@ -418,7 +419,8 @@ int netdev_register(FAR struct net_driver_s *dev, enum net_lltype_e lltype)
|
|||
|
||||
#ifdef CONFIG_NET_MLD
|
||||
/* Configure the device for MLD support */
|
||||
#warning Missing Logic
|
||||
|
||||
mld_devinit(dev);
|
||||
#endif
|
||||
|
||||
net_unlock();
|
||||
|
|
Loading…
Reference in a new issue