Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable neighbour acquisition #64

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions babeld.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ int resend_delay = -1;
int random_id = 0;
int do_daemonise = 0;
int skip_kernel_setup = 0;
int neighbour_acquisition = 1;
const char *logfile = NULL,
*pidfile = "/var/run/babeld.pid",
*state_file = "/var/lib/babel-state";
Expand Down
1 change: 1 addition & 0 deletions babeld.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ extern const char *logfile, *pidfile, *state_file;
extern int link_detect;
extern int all_wireless;
extern int has_ipv6_subtrees;
extern int neighbour_acquisition;

extern unsigned char myid[8];
extern int have_id;
Expand Down
16 changes: 16 additions & 0 deletions babeld.man
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,19 @@ source-specific routes. The default is 10.
.BI first-rule-priority " priority"
This specifies smallest (highest) rule priority used with source-specific
routes. The default is 100.
.TP
.BR neighbour-acquisition " {" true | false }
If this flag is set to
.BR false ,
no neighbour acquisition is done (e.g., via Multicast Hellos), and
neighbours must be added via an external mechanism. The default is
.BR true .
.TP
.BI neighbour " address ifname"
Add the neighbour with given
.I address
to the interface
.IR ifname .
.SS Interface configuration
An interface is configured by a line with the following format:
.IP
Expand Down Expand Up @@ -614,6 +627,9 @@ any configuration file directive, including
.IP \(bu
.BR "flush interface" ;
.IP \(bu
.B "flush neighbour"
.IR "address ifname" ;
.IP \(bu
.BR dump ;
.IP \(bu
.B monitor
Expand Down
70 changes: 69 additions & 1 deletion configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ THE SOFTWARE.
#include "babeld.h"
#include "util.h"
#include "interface.h"
#include "neighbour.h"
#include "route.h"
#include "kernel.h"
#include "configuration.h"
Expand Down Expand Up @@ -850,7 +851,8 @@ parse_option(int c, gnc_t gnc, void *closure, char *token)
strcmp(token, "daemonise") == 0 ||
strcmp(token, "skip-kernel-setup") == 0 ||
strcmp(token, "ipv6-subtrees") == 0 ||
strcmp(token, "reflect-kernel-metric") == 0) {
strcmp(token, "reflect-kernel-metric") == 0 ||
strcmp(token, "neighbour-acquisition") == 0) {
int b;
c = getbool(c, &b, gnc, closure);
if(c < -1)
Expand All @@ -868,6 +870,8 @@ parse_option(int c, gnc_t gnc, void *closure, char *token)
has_ipv6_subtrees = b;
else if(strcmp(token, "reflect-kernel-metric") == 0)
reflect_kernel_metric = b;
else if(strcmp(token, "neighbour-acquisition") == 0)
neighbour_acquisition = b;
else
abort();
} else if(strcmp(token, "protocol-group") == 0) {
Expand Down Expand Up @@ -969,6 +973,41 @@ parse_option(int c, gnc_t gnc, void *closure, char *token)

}

static int
parse_neighbour(int c, gnc_t gnc, void *closure,
unsigned char **address_return, struct interface **ifp_return)
{
char *ifname = NULL;
struct interface *ifp;
*address_return = NULL;
*ifp_return = NULL;

c = skip_whitespace(c, gnc, closure);
c = getip(c, address_return, NULL, gnc, closure);
if(c < -1)
return c;
c = getword(c, &ifname, gnc, closure);
c = skip_eol(c, gnc, closure);
if(c < -1) {
free(*address_return);
*address_return = NULL;
return c;
}

FOR_ALL_INTERFACES(ifp) {
if(strcmp(ifp->name, ifname) == 0)
break;
}
*ifp_return = ifp;
if(ifp == NULL) {
fprintf(stderr, "Couldn't find interface %s.\n", ifname);
free(*address_return);
*address_return = NULL;
}
free(ifname);
return c;
}

static int
parse_config_line(int c, gnc_t gnc, void *closure,
int *action_return, const char **message_return)
Expand Down Expand Up @@ -1068,6 +1107,19 @@ parse_config_line(int c, gnc_t gnc, void *closure,
if_conf, default_interface_conf);
free(if_conf);
}
} else if(strcmp(token, "neighbour") == 0) {
unsigned char *address;
struct interface *ifp;
struct neighbour *neigh;
c = parse_neighbour(c, gnc, closure, &address, &ifp);
if(c < -1 || address == NULL || ifp == NULL)
goto fail;
neigh = find_neighbour(address, ifp);
free(address);
if(neigh == NULL) {
fprintf(stderr, "Couldn't allocate neighbour.\n");
goto fail;
}
} else if(strcmp(token, "flush") == 0) {
char *token2;
c = skip_whitespace(c, gnc, closure);
Expand Down Expand Up @@ -1097,6 +1149,22 @@ parse_config_line(int c, gnc_t gnc, void *closure,
}
free(token2);
free(ifname);
} else if(strcmp(token2, "neighbour") == 0) {
unsigned char *address;
struct interface *ifp;
int rc;
free(token2);
c = parse_neighbour(c, gnc, closure, &address, &ifp);
if(c < -1 || address == NULL || ifp == NULL)
goto fail;
rc = flush_neighbour2(address, ifp);
if(rc) {
if(action_return)
*action_return = CONFIG_ACTION_NO;
if(message_return)
*message_return = "No such neighbour";
}
free(address);
} else {
free(token2);
goto fail;
Expand Down
19 changes: 14 additions & 5 deletions message.c
Original file line number Diff line number Diff line change
Expand Up @@ -495,10 +495,19 @@ parse_packet(const unsigned char *from, struct interface *ifp,
bodylen = packetlen - 4;
}

neigh = find_neighbour(from, ifp);
if(neigh == NULL) {
fprintf(stderr, "Couldn't allocate neighbour.\n");
return;
if(neighbour_acquisition) {
neigh = find_neighbour(from, ifp);
if(neigh == NULL) {
fprintf(stderr, "Couldn't allocate neighbour.\n");
return;
}
} else {
neigh = find_neighbour_nocreate(from, ifp);
if(neigh == NULL) {
fprintf(stderr, "Couldn't find neighbour %s on %s.\n",
format_address(from), ifp->name);
return;
}
}

i = 0;
Expand Down Expand Up @@ -1082,7 +1091,7 @@ buffer_hello(struct buffered *buf, struct interface *ifp,
void
send_multicast_hello(struct interface *ifp, unsigned interval, int force)
{
if(!if_up(ifp))
if(!neighbour_acquisition || !if_up(ifp))
return;

if(interval == 0 && (ifp->flags & IF_RFC6126) != 0)
Expand Down
23 changes: 22 additions & 1 deletion neighbour.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ THE SOFTWARE.

struct neighbour *neighs = NULL;

static struct neighbour *
struct neighbour *
find_neighbour_nocreate(const unsigned char *address, struct interface *ifp)
{
struct neighbour *neigh;
Expand Down Expand Up @@ -72,6 +72,27 @@ flush_neighbour(struct neighbour *neigh)
free(neigh);
}

int
flush_neighbour2(const unsigned char *address, const struct interface *ifp)
{
struct neighbour **neigh = &neighs, *flush;

while(*neigh != NULL &&
memcmp(address, (*neigh)->address, 16) != 0 &&
ifp != (*neigh)->ifp)
neigh = &(*neigh)->next;
flush = *neigh;
if(flush == NULL)
return -1;
*neigh = flush->next;
flush_neighbour_routes(flush);
flush_resends(flush);
local_notify_neighbour(flush, LOCAL_FLUSH);
free(flush->buf.buf);
free(flush);
return 0;
}

struct neighbour *
find_neighbour(const unsigned char *address, struct interface *ifp)
{
Expand Down
3 changes: 3 additions & 0 deletions neighbour.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ extern struct neighbour *neighs;
for(_neigh = neighs; _neigh; _neigh = _neigh->next)

void flush_neighbour(struct neighbour *neigh);
int flush_neighbour2(const unsigned char *address, const struct interface *ifp);
struct neighbour *find_neighbour_nocreate(const unsigned char *address,
struct interface *ifp);
struct neighbour *find_neighbour(const unsigned char *address,
struct interface *ifp);
int update_neighbour(struct neighbour *neigh, struct hello_history *hist,
Expand Down