mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2025-02-21 18:40:12 +00:00
Add functions to join/leave v6 multicast group by netif
Existing functions are based on IP address, but the address is used only to look up which netif to act on. The netif-based core code is extracted to new exported functions. If you have a netif handle, this makes it easier to join/leave groups, without the need to convert to IP address first only for the mld6 code to convert back to netif.
This commit is contained in:
parent
3dd0977635
commit
6cdea62638
@ -327,7 +327,6 @@ err_t
|
|||||||
mld6_joingroup(const ip6_addr_t *srcaddr, const ip6_addr_t *groupaddr)
|
mld6_joingroup(const ip6_addr_t *srcaddr, const ip6_addr_t *groupaddr)
|
||||||
{
|
{
|
||||||
err_t err = ERR_VAL; /* no matching interface */
|
err_t err = ERR_VAL; /* no matching interface */
|
||||||
struct mld_group *group;
|
|
||||||
struct netif *netif;
|
struct netif *netif;
|
||||||
u8_t match;
|
u8_t match;
|
||||||
u8_t i;
|
u8_t i;
|
||||||
@ -350,6 +349,31 @@ mld6_joingroup(const ip6_addr_t *srcaddr, const ip6_addr_t *groupaddr)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (match) {
|
if (match) {
|
||||||
|
err = mld6_joingroup_netif(netif, groupaddr);
|
||||||
|
if (err != ERR_OK) {
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* proceed to next network interface */
|
||||||
|
netif = netif->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Join a group on a network interface.
|
||||||
|
*
|
||||||
|
* @param netif the network interface which should join a new group.
|
||||||
|
* @param groupaddr the ipv6 address of the group to join
|
||||||
|
* @return ERR_OK if group was joined on the netif, an err_t otherwise
|
||||||
|
*/
|
||||||
|
err_t
|
||||||
|
mld6_joingroup_netif(struct netif *netif, const ip6_addr_t *groupaddr)
|
||||||
|
{
|
||||||
|
struct mld_group *group;
|
||||||
|
|
||||||
/* find group or create a new one if not found */
|
/* find group or create a new one if not found */
|
||||||
group = mld6_lookfor_group(netif, groupaddr);
|
group = mld6_lookfor_group(netif, groupaddr);
|
||||||
|
|
||||||
@ -373,14 +397,7 @@ mld6_joingroup(const ip6_addr_t *srcaddr, const ip6_addr_t *groupaddr)
|
|||||||
|
|
||||||
/* Increment group use */
|
/* Increment group use */
|
||||||
group->use++;
|
group->use++;
|
||||||
err = ERR_OK;
|
return ERR_OK;
|
||||||
}
|
|
||||||
|
|
||||||
/* proceed to next network interface */
|
|
||||||
netif = netif->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -395,7 +412,6 @@ err_t
|
|||||||
mld6_leavegroup(const ip6_addr_t *srcaddr, const ip6_addr_t *groupaddr)
|
mld6_leavegroup(const ip6_addr_t *srcaddr, const ip6_addr_t *groupaddr)
|
||||||
{
|
{
|
||||||
err_t err = ERR_VAL; /* no matching interface */
|
err_t err = ERR_VAL; /* no matching interface */
|
||||||
struct mld_group *group;
|
|
||||||
struct netif *netif;
|
struct netif *netif;
|
||||||
u8_t match;
|
u8_t match;
|
||||||
u8_t i;
|
u8_t i;
|
||||||
@ -418,6 +434,31 @@ mld6_leavegroup(const ip6_addr_t *srcaddr, const ip6_addr_t *groupaddr)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (match) {
|
if (match) {
|
||||||
|
err_t res = mld6_leavegroup_netif(netif, groupaddr);
|
||||||
|
if (err != ERR_OK) {
|
||||||
|
/* Store this result if we have not yet gotten a success */
|
||||||
|
err = res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* proceed to next network interface */
|
||||||
|
netif = netif->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Leave a group on a network interface.
|
||||||
|
*
|
||||||
|
* @param netif the network interface which should leave the group.
|
||||||
|
* @param groupaddr the ipv6 address of the group to leave
|
||||||
|
* @return ERR_OK if group was left on the netif, an err_t otherwise
|
||||||
|
*/
|
||||||
|
err_t
|
||||||
|
mld6_leavegroup_netif(struct netif *netif, const ip6_addr_t *groupaddr)
|
||||||
|
{
|
||||||
|
struct mld_group *group;
|
||||||
|
|
||||||
/* find group */
|
/* find group */
|
||||||
group = mld6_lookfor_group(netif, groupaddr);
|
group = mld6_lookfor_group(netif, groupaddr);
|
||||||
|
|
||||||
@ -441,15 +482,13 @@ mld6_leavegroup(const ip6_addr_t *srcaddr, const ip6_addr_t *groupaddr)
|
|||||||
/* Decrement group use */
|
/* Decrement group use */
|
||||||
group->use--;
|
group->use--;
|
||||||
}
|
}
|
||||||
/* Leave on this interface */
|
|
||||||
err = ERR_OK;
|
/* Left group */
|
||||||
}
|
return ERR_OK;
|
||||||
}
|
|
||||||
/* proceed to next network interface */
|
|
||||||
netif = netif->next;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return err;
|
/* Group not found */
|
||||||
|
return ERR_VAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -105,7 +105,9 @@ void mld6_tmr(void);
|
|||||||
struct mld_group *mld6_lookfor_group(struct netif *ifp, const ip6_addr_t *addr);
|
struct mld_group *mld6_lookfor_group(struct netif *ifp, const ip6_addr_t *addr);
|
||||||
void mld6_input(struct pbuf *p, struct netif *inp);
|
void mld6_input(struct pbuf *p, struct netif *inp);
|
||||||
err_t mld6_joingroup(const ip6_addr_t *srcaddr, const ip6_addr_t *groupaddr);
|
err_t mld6_joingroup(const ip6_addr_t *srcaddr, const ip6_addr_t *groupaddr);
|
||||||
|
err_t mld6_joingroup_netif(struct netif *netif, const ip6_addr_t *groupaddr);
|
||||||
err_t mld6_leavegroup(const ip6_addr_t *srcaddr, const ip6_addr_t *groupaddr);
|
err_t mld6_leavegroup(const ip6_addr_t *srcaddr, const ip6_addr_t *groupaddr);
|
||||||
|
err_t mld6_leavegroup_netif(struct netif *netif, const ip6_addr_t *groupaddr);
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
Loading…
x
Reference in New Issue
Block a user