From 0ddd7de1bac5e6c2546b9c150f7aa7e838a7d36b Mon Sep 17 00:00:00 2001 From: sg Date: Fri, 6 Mar 2015 21:30:59 +0100 Subject: [PATCH] patch #8359 (Provide utility function to add an IPv6 address to an interface) --- CHANGELOG | 4 ++++ src/core/netif.c | 32 ++++++++++++++++++++++++++++++++ src/include/lwip/netif.h | 1 + 3 files changed, 37 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 3163d810..2debd2ff 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -6,6 +6,10 @@ HISTORY ++ 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 * 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) diff --git a/src/core/netif.c b/src/core/netif.c index 3dc8dc9b..bd6d56e2 100644 --- a/src/core/netif.c +++ b/src/core/netif.c @@ -916,6 +916,38 @@ netif_create_ip6_linklocal_address(struct netif * netif, u8_t from_mac_48bit) #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 netif_null_output_ip6(struct netif *netif, struct pbuf *p, const ip6_addr_t *ipaddr) { diff --git a/src/include/lwip/netif.h b/src/include/lwip/netif.h index fe71beb6..0b6afc23 100644 --- a/src/include/lwip/netif.h +++ b/src/include/lwip/netif.h @@ -375,6 +375,7 @@ void netif_poll_all(void); #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); 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 */ #if LWIP_NETIF_HWADDRHINT