Commit 096aa18e authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Remove id field from neighbour, rename add_neighbour to find_neighbour.

The old find_neighbour is now an internal function (f_n_no_create).
parent 978bfd37
......@@ -37,8 +37,8 @@ THE SOFTWARE.
struct neighbour *neighs = NULL;
struct neighbour *
find_neighbour(const unsigned char *address, struct network *net)
static struct neighbour *
find_neighbour_nocreate(const unsigned char *address, struct network *net)
{
struct neighbour *neigh;
FOR_ALL_NEIGHBOURS(neigh) {
......@@ -49,17 +49,6 @@ find_neighbour(const unsigned char *address, struct network *net)
return NULL;
}
struct neighbour *
find_neighbour_by_id(const unsigned char *id, struct network *net)
{
struct neighbour *neigh;
FOR_ALL_NEIGHBOURS(neigh) {
if(memcmp(id, neigh->id, 16) == 0 && neigh->network == net)
return neigh;
}
return NULL;
}
void
flush_neighbour(struct neighbour *neigh)
{
......@@ -80,41 +69,17 @@ flush_neighbour(struct neighbour *neigh)
}
struct neighbour *
add_neighbour(const unsigned char *id, const unsigned char *address,
struct network *net)
find_neighbour(const unsigned char *address, struct network *net)
{
struct neighbour *neigh;
const struct timeval zero = {0, 0};
neigh = find_neighbour(address, net);
if(neigh) {
if(memcmp(neigh->id, id, 16) == 0) {
return neigh;
} else {
fprintf(stderr, "Neighbour changed id (%s -> %s)!\n",
format_address(neigh->id), format_address(id));
flush_neighbour(neigh);
neigh = NULL;
}
}
neigh = find_neighbour_by_id(id, net);
if(neigh) {
if((neigh->reach & 0xE000) == 0) {
/* The other neighbour is probably obsolete. */
flush_neighbour(neigh);
neigh = NULL;
} else {
fprintf(stderr, "Duplicate neighbour %s (%s and %s)!\n",
format_address(id),
format_address(neigh->address),
format_address(address));
return NULL;
}
}
neigh = find_neighbour_nocreate(address, net);
if(neigh)
return neigh;
debugf("Creating neighbour %s (%s).\n",
format_address(id), format_address(address));
debugf("Creating neighbour %s on %s.\n",
format_address(address), net->ifname);
neigh = malloc(sizeof(struct neighbour));
if(neigh == NULL) {
......@@ -123,7 +88,6 @@ add_neighbour(const unsigned char *id, const unsigned char *address,
}
neigh->hello_seqno = -1;
memcpy(neigh->id, id, 16);
memcpy(neigh->address, address, 16);
neigh->reach = 0;
neigh->txcost = INFINITY;
......@@ -219,15 +183,10 @@ update_neighbour(struct neighbour *neigh, int hello, int hello_interval)
}
if((neigh->reach & 0xFC00) == 0xC000) {
/* This is a newish neighbour. If we don't have another route to it,
request a full route dump. This assumes that the neighbour's id
is also its IP address and that it is exporting a route to itself. */
struct route *route = NULL;
/* This is a newish neighbour. Let's request a full route dump. */
send_ihu(neigh, NULL);
if(!martian_prefix(neigh->id, 128))
route = find_installed_route(neigh->id, 128);
if(!route || route->metric >= INFINITY || route->neigh == neigh)
send_unicast_request(neigh, NULL, 0, 0, 0, 0);
/* We ought to avoid this when the network is dense */
send_unicast_request(neigh, NULL, 0);
}
if(rc)
local_notify_neighbour(neigh, LOCAL_CHANGE);
......
......@@ -24,7 +24,6 @@ struct neighbour {
struct neighbour *next;
/* This is -1 when unknown, so don't make it unsigned */
int hello_seqno;
unsigned char id[16];
unsigned char address[16];
unsigned short reach;
unsigned short txcost;
......@@ -44,11 +43,6 @@ int neighbour_valid(struct neighbour *neigh);
void flush_neighbour(struct neighbour *neigh);
struct neighbour *find_neighbour(const unsigned char *address,
struct network *net);
struct neighbour *find_neighbour_by_id(const unsigned char *id,
struct network *net);
struct neighbour *add_neighbour(const unsigned char *id,
const unsigned char *address,
struct network *net);
int update_neighbour(struct neighbour *neigh, int hello, int hello_interval);
unsigned check_neighbours(void);
unsigned neighbour_txcost(struct neighbour *neigh);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment