Skip to content

Commit 8bc65a9

Browse files
committed
gnrc_ipv6_netif: remove existing interfaces on INIT
1 parent 2f9f99e commit 8bc65a9

File tree

1 file changed

+25
-24
lines changed

1 file changed

+25
-24
lines changed

sys/net/gnrc/network_layer/ipv6/netif/gnrc_ipv6_netif.c

+25-24
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,34 @@ static void _reset_addr_from_entry(gnrc_ipv6_netif_t *entry)
167167
memset(entry->addrs, 0, sizeof(entry->addrs));
168168
}
169169

170+
static void _ipv6_netif_remove(gnrc_ipv6_netif_t *entry)
171+
{
172+
if (entry == NULL) {
173+
return;
174+
}
175+
176+
#ifdef MODULE_GNRC_NDP
177+
gnrc_ndp_netif_remove(entry);
178+
#endif
179+
180+
mutex_lock(&entry->mutex);
181+
xtimer_remove(&entry->rtr_sol_timer);
182+
#ifdef MODULE_GNRC_NDP_ROUTER
183+
xtimer_remove(&entry->rtr_adv_timer);
184+
#endif
185+
_reset_addr_from_entry(entry);
186+
DEBUG("ipv6 netif: Remove IPv6 interface %" PRIkernel_pid "\n", entry->pid);
187+
entry->pid = KERNEL_PID_UNDEF;
188+
entry->flags = 0;
189+
190+
mutex_unlock(&entry->mutex);
191+
}
192+
170193
void gnrc_ipv6_netif_init(void)
171194
{
172195
for (int i = 0; i < GNRC_NETIF_NUMOF; i++) {
173196
mutex_init(&(ipv6_ifs[i].mutex));
174-
mutex_lock(&(ipv6_ifs[i].mutex));
175-
_reset_addr_from_entry(&ipv6_ifs[i]);
176-
ipv6_ifs[i].pid = KERNEL_PID_UNDEF;
177-
mutex_unlock(&(ipv6_ifs[i].mutex));
197+
_ipv6_netif_remove(&ipv6_ifs[i]);
178198
}
179199
}
180200

@@ -228,26 +248,7 @@ void gnrc_ipv6_netif_add(kernel_pid_t pid)
228248
void gnrc_ipv6_netif_remove(kernel_pid_t pid)
229249
{
230250
gnrc_ipv6_netif_t *entry = gnrc_ipv6_netif_get(pid);
231-
232-
if (entry == NULL) {
233-
return;
234-
}
235-
236-
#ifdef MODULE_GNRC_NDP
237-
gnrc_ndp_netif_remove(entry);
238-
#endif
239-
240-
mutex_lock(&entry->mutex);
241-
xtimer_remove(&entry->rtr_sol_timer);
242-
#ifdef MODULE_GNRC_NDP_ROUTER
243-
xtimer_remove(&entry->rtr_adv_timer);
244-
#endif
245-
_reset_addr_from_entry(entry);
246-
DEBUG("ipv6 netif: Remove IPv6 interface %" PRIkernel_pid "\n", pid);
247-
entry->pid = KERNEL_PID_UNDEF;
248-
entry->flags = 0;
249-
250-
mutex_unlock(&entry->mutex);
251+
_ipv6_netif_remove(entry);
251252
}
252253

253254
gnrc_ipv6_netif_t *gnrc_ipv6_netif_get(kernel_pid_t pid)

0 commit comments

Comments
 (0)