patch #8359 (Provide utility function to add an IPv6 address to an interface)

This commit is contained in:
sg 2015-03-06 21:30:59 +01:00
parent f385193a89
commit 0ddd7de1ba
3 changed files with 37 additions and 0 deletions

View File

@ -6,6 +6,10 @@ HISTORY
++ New features: ++ New features:
2015-03-06: Philip Gladstone
* netif.h/.c: patch #8359 (Provide utility function to add an IPv6 address to
an interface)
2015-03-05: Simon Goldschmidt 2015-03-05: Simon Goldschmidt
* netif.c, ip4.c, dhcp.c, autoip.c: fixed bug #37068 (netif up/down handling * netif.c, ip4.c, dhcp.c, autoip.c: fixed bug #37068 (netif up/down handling
is unclear): correclty separated administrative status of a netif (up/down) is unclear): correclty separated administrative status of a netif (up/down)

View File

@ -916,6 +916,38 @@ netif_create_ip6_linklocal_address(struct netif * netif, u8_t from_mac_48bit)
#endif /* LWIP_IPV6_AUTOCONFIG */ #endif /* LWIP_IPV6_AUTOCONFIG */
} }
err_t
netif_add_ip6_address(struct netif *netif, ip6_addr_t * ip6addr, s8_t *chosen_idx)
{
s8_t i;
i = netif_get_ip6_addr_match(netif, ip6addr);
if (i >= 0) {
/* Address already added */
if (chosen_idx != NULL) {
*chosen_idx = i;
}
return ERR_OK;
}
/* Find a free slot -- musn't be the first one (reserved for link local) */
for (i = 1; i < LWIP_IPV6_NUM_ADDRESSES; i++) {
if (!ip6_addr_isvalid(netif->ip6_addr_state[i])) {
ip6_addr_copy(netif->ip6_addr[i], *ip6addr);
netif_ip6_addr_set_state(netif, i, IP6_ADDR_TENTATIVE);
if (chosen_idx != NULL) {
*chosen_idx = i;
}
return ERR_OK;
}
}
if (chosen_idx != NULL) {
*chosen_idx = -1;
}
return ERR_VAL;
}
static err_t static err_t
netif_null_output_ip6(struct netif *netif, struct pbuf *p, const ip6_addr_t *ipaddr) netif_null_output_ip6(struct netif *netif, struct pbuf *p, const ip6_addr_t *ipaddr)
{ {

View File

@ -375,6 +375,7 @@ void netif_poll_all(void);
#define netif_ip6_addr_set_state(netif, i, state) ((netif)->ip6_addr_state[(i)] = (state)) #define netif_ip6_addr_set_state(netif, i, state) ((netif)->ip6_addr_state[(i)] = (state))
s8_t netif_get_ip6_addr_match(struct netif * netif, ip6_addr_t * ip6addr); s8_t netif_get_ip6_addr_match(struct netif * netif, ip6_addr_t * ip6addr);
void netif_create_ip6_linklocal_address(struct netif * netif, u8_t from_mac_48bit); void netif_create_ip6_linklocal_address(struct netif * netif, u8_t from_mac_48bit);
err_t netif_add_ip6_address(struct netif *netif, ip6_addr_t *ip6addr, s8_t *chosen_idx);
#endif /* LWIP_IPV6 */ #endif /* LWIP_IPV6 */
#if LWIP_NETIF_HWADDRHINT #if LWIP_NETIF_HWADDRHINT