Microchip® Advanced Software Framework

mld6.c File Reference

Multicast listener discovery for IPv6.

Aims to be compliant with RFC 2710. No support for MLDv2.

#include "lwip/opt.h"
#include "lwip/mld6.h"
#include "lwip/icmp6.h"
#include "lwip/ip6.h"
#include "lwip/ip6_addr.h"
#include "lwip/ip.h"
#include "lwip/inet_chksum.h"
#include "lwip/pbuf.h"
#include "lwip/netif.h"
#include "lwip/memp.h"
#include "lwip/stats.h"
#include <string.h>

Macros

#define MLD6_GROUP_DELAYING_MEMBER   1
 
#define MLD6_GROUP_IDLE_MEMBER   2
 
#define MLD6_GROUP_NON_MEMBER   0
 
#define MLD6_HL   1
 
#define MLD6_JOIN_DELAYING_MEMBER_TMR_MS   (500)
 

Functions

static void mld6_delayed_report (struct mld_group *group, u16_t maxresp)
 Schedule a delayed membership report for a group. More...
 
static err_t mld6_free_group (struct mld_group *group)
 Remove a group in the mld_group_list and free. More...
 
void mld6_input (struct pbuf *p, struct netif *inp)
 Process an input MLD message. More...
 
err_t mld6_joingroup (ip6_addr_t *srcaddr, ip6_addr_t *groupaddr)
 Join a group on a network interface. More...
 
err_t mld6_leavegroup (ip6_addr_t *srcaddr, ip6_addr_t *groupaddr)
 Leave a group on a network interface. More...
 
struct mld_groupmld6_lookfor_group (struct netif *ifp, ip6_addr_t *addr)
 Search for a group that is joined on a netif. More...
 
static struct mld_groupmld6_new_group (struct netif *ifp, ip6_addr_t *addr)
 create a new group More...
 
void mld6_report_groups (struct netif *netif)
 Report MLD memberships for this interface. More...
 
static void mld6_send (struct mld_group *group, u8_t type)
 Send a MLD message (report or done). More...
 
err_t mld6_stop (struct netif *netif)
 Stop MLD processing on interface. More...
 
void mld6_tmr (void)
 Periodic timer for mld processing. More...
 

Variables

static struct mld_groupmld_group_list
 

#define MLD6_GROUP_DELAYING_MEMBER   1
#define MLD6_GROUP_IDLE_MEMBER   2
#define MLD6_GROUP_NON_MEMBER   0
#define MLD6_HL   1

Referenced by mld6_send().

#define MLD6_JOIN_DELAYING_MEMBER_TMR_MS   (500)

static void mld6_delayed_report ( struct mld_group group,
u16_t  maxresp 
)
static

Schedule a delayed membership report for a group.

Parameters
groupthe mld_group for which "delaying" membership report should be sent
maxrespthe max resp delay provided in the query

References mld_group::group_state, LWIP_RAND, MLD6_GROUP_DELAYING_MEMBER, MLD6_GROUP_IDLE_MEMBER, MLD6_TMR_INTERVAL, and mld_group::timer.

Referenced by mld6_input(), mld6_joingroup(), and mld6_report_groups().

static err_t mld6_free_group ( struct mld_group group)
static

Remove a group in the mld_group_list and free.

Parameters
groupthe group to remove
Returns
ERR_OK if group was removed from the list, an err_t otherwise

References ERR_ARG, ERR_OK, memp_free(), mld_group::next, and NULL.

Referenced by mld6_leavegroup().

void mld6_input ( struct pbuf p,
struct netif inp 
)
err_t mld6_joingroup ( ip6_addr_t srcaddr,
ip6_addr_t groupaddr 
)

Join a group on a network interface.

Parameters
srcaddripv6 address of the network interface which should join a new group. If IP6_ADDR_ANY, join on all netifs
groupaddrthe ipv6 address of the group to join
Returns
ERR_OK if group was joined on the netif(s), an err_t otherwise

References ERR_MEM, ERR_OK, ERR_VAL, ICMP6_TYPE_MLR, ip6_addr_cmp, ip6_addr_isany, MLD6_ADD_MAC_FILTER, mld6_delayed_report(), MLD6_JOIN_DELAYING_MEMBER_TMR_MS, mld6_lookfor_group(), mld6_new_group(), mld6_send(), MLD6_STATS_INC, netif::mld_mac_filter, netif_ip6_addr, netif_list, netif::next, NULL, and mld_group::use.

Referenced by lwip_netconn_do_join_leave_group(), and nd6_tmr().

err_t mld6_leavegroup ( ip6_addr_t srcaddr,
ip6_addr_t groupaddr 
)

Leave a group on a network interface.

Parameters
srcaddripv6 address of the network interface which should leave the group. If IP6_ISANY, leave on all netifs
groupaddrthe ipv6 address of the group to leave
Returns
ERR_OK if group was left on the netif(s), an err_t otherwise

References ERR_OK, ERR_VAL, ICMP6_TYPE_MLD, ip6_addr_cmp, ip6_addr_isany, mld_group::last_reporter_flag, MLD6_DEL_MAC_FILTER, mld6_free_group(), mld6_lookfor_group(), mld6_send(), MLD6_STATS_INC, netif::mld_mac_filter, netif_ip6_addr, netif_list, netif::next, NULL, and mld_group::use.

Referenced by lwip_netconn_do_join_leave_group(), and nd6_input().

struct mld_group* mld6_lookfor_group ( struct netif ifp,
ip6_addr_t addr 
)

Search for a group that is joined on a netif.

Parameters
ifpthe network interface for which to look
addrthe group ipv6 address to search for
Returns
a struct mld_group* if the group has been found, NULL if the group wasn't found.

References mld_group::group_address, ip6_addr_cmp, mld_group_list, mld_group::netif, mld_group::next, and NULL.

Referenced by ip6_input(), mld6_input(), mld6_joingroup(), and mld6_leavegroup().

static struct mld_group * mld6_new_group ( struct netif ifp,
ip6_addr_t addr 
)
static

create a new group

Parameters
ifpthe network interface for which to create
addrthe new group ipv6
Returns
a struct mld_group*, NULL on memory error.

References mld_group::group_address, mld_group::group_state, ip6_addr_set, mld_group::last_reporter_flag, memp_malloc(), MLD6_GROUP_IDLE_MEMBER, mld_group_list, mld_group::netif, mld_group::next, NULL, mld_group::timer, and mld_group::use.

Referenced by mld6_joingroup().

void mld6_report_groups ( struct netif netif)

Report MLD memberships for this interface.

Parameters
netifnetwork interface on which report MLD memberships

References mld6_delayed_report(), MLD6_JOIN_DELAYING_MEMBER_TMR_MS, mld_group_list, mld_group::netif, mld_group::next, and NULL.

Referenced by netif_set_link_up(), and netif_set_up().

static void mld6_send ( struct mld_group group,
u8_t  type 
)
static

Send a MLD message (report or done).

An IPv6 hop-by-hop options header with a router alert option is prepended.

Parameters
groupthe group to report or quit
typeICMP6_TYPE_MLR (report) or ICMP6_TYPE_MLD (done)

References mld_group::group_address, IP6_ADDR_ANY, ip6_addr_isany, ip6_addr_isvalid, ip6_addr_set, ip6_chksum_pseudo(), IP6_HBH_HLEN, IP6_NEXTH_HOPBYHOP, IP6_NEXTH_ICMP6, ip6_options_add_hbh_ra(), ip6_output_if(), IP6_ROUTER_ALERT_VALUE_MLD, pbuf::len, MLD6_HL, MLD6_STATS_INC, mld_group::netif, netif_ip6_addr, netif_ip6_addr_state, NULL, pbuf::payload, pbuf_alloc(), pbuf_free(), pbuf_header(), PBUF_IP, and PBUF_RAM.

Referenced by mld6_joingroup(), mld6_leavegroup(), and mld6_tmr().

err_t mld6_stop ( struct netif netif)

Stop MLD processing on interface.

Parameters
netifnetwork interface on which stop MLD processing

References ERR_OK, mld_group::group_address, memp_free(), MLD6_DEL_MAC_FILTER, mld_group_list, netif::mld_mac_filter, mld_group::netif, mld_group::next, next, and NULL.

Referenced by netif_remove().

void mld6_tmr ( void  )

Periodic timer for mld processing.

Must be called every MLD6_TMR_INTERVAL milliseconds (100).

When a delaying member expires, a membership report is sent.

References mld_group::group_state, ICMP6_TYPE_MLR, MLD6_GROUP_DELAYING_MEMBER, MLD6_GROUP_IDLE_MEMBER, mld6_send(), MLD6_STATS_INC, mld_group_list, mld_group::next, NULL, and mld_group::timer.

Referenced by mld6_timer().