mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-18 12:52:44 +01:00
ng_netif: don't add duplicates
prevent ng_netif_add() from adding duplicates as described in https://github.com/RIOT-OS/RIOT/issues/2965
This commit is contained in:
parent
5b5ff5832c
commit
487064e51a
@ -44,22 +44,28 @@ void ng_netif_init(void)
|
||||
|
||||
int ng_netif_add(kernel_pid_t pid)
|
||||
{
|
||||
kernel_pid_t *free_entry = NULL;
|
||||
|
||||
for (int i = 0; i < NG_NETIF_NUMOF; i++) {
|
||||
if (ifs[i] == pid) { /* avoid duplicates */
|
||||
if (ifs[i] == pid) {
|
||||
return 0;
|
||||
}
|
||||
else if (ifs[i] == KERNEL_PID_UNDEF) {
|
||||
ifs[i] = pid;
|
||||
else if (ifs[i] == KERNEL_PID_UNDEF && !free_entry) {
|
||||
free_entry = &ifs[i];
|
||||
}
|
||||
}
|
||||
|
||||
if (!free_entry) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
*free_entry = pid;
|
||||
|
||||
for (int j = 0; if_handler[j].add != NULL; j++) {
|
||||
if_handler[j].add(pid);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
void ng_netif_remove(kernel_pid_t pid)
|
||||
|
Loading…
Reference in New Issue
Block a user