Skip to content

Commit

Permalink
interface/local: add remove_interface function
Browse files Browse the repository at this point in the history
Babeld can add interfaces dynamically. However, babeld is missing a
function to remove interfaces and stop meshing on them. Add a function
that can do it.

Signed-off-by: Nick Hainke <[email protected]>
  • Loading branch information
PolynomialDivision committed Feb 1, 2022
1 parent 91c44f8 commit 84cdb09
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
33 changes: 33 additions & 0 deletions interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,39 @@ add_interface(char *ifname, struct interface_conf *if_conf)
return ifp;
}

void
remove_interface(char *ifname)
{
struct interface *ifp = NULL;

if(interfaces == NULL)
return;

if(strcmp(interfaces->name, ifname) == 0) {
ifp = interfaces;
interface_updown(ifp, 0);
interfaces = interfaces->next;
free(ifp);
return;
}

FOR_ALL_INTERFACES(ifp) {
if(ifp->next == NULL)
break;
if(strcmp(ifp->next->name, ifname) == 0) {
break;
}
}

if(ifp->next == NULL)
return;

ifp = interfaces;
interface_updown(ifp, 0);
interfaces = ifp->next;
free(ifp);
}

int
flush_interface(char *ifname)
{
Expand Down
1 change: 1 addition & 0 deletions interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ if_up(struct interface *ifp)
}

struct interface *add_interface(char *ifname, struct interface_conf *if_conf);
void remove_interface(char *ifname);
int flush_interface(char *ifname);
unsigned jitter(struct buffered *buf, int urgent);
unsigned update_jitter(struct interface *ifp, int urgent);
Expand Down
1 change: 1 addition & 0 deletions local.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ struct xroute;
#define LOCAL_FLUSH 0
#define LOCAL_ADD 1
#define LOCAL_CHANGE 2
#define LOCAL_REMOVE 3

#ifndef MAX_LOCAL_SOCKETS
#define MAX_LOCAL_SOCKETS 4
Expand Down

0 comments on commit 84cdb09

Please sign in to comment.