Commit c2704e82 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Use hello_seqno to indicate invalid entries in the neighbour table.

Instead of neigh->id[0] = 0xFF.
parent ebaa1afd
...@@ -37,14 +37,20 @@ THE SOFTWARE. ...@@ -37,14 +37,20 @@ THE SOFTWARE.
struct neighbour neighs[MAXNEIGHBOURS]; struct neighbour neighs[MAXNEIGHBOURS];
int numneighs = 0; int numneighs = 0;
static int
neighbour_valid(struct neighbour *neigh)
{
return neigh->hello_seqno != -2;
}
void void
flush_neighbour(struct neighbour *neigh) flush_neighbour(struct neighbour *neigh)
{ {
flush_neighbour_routes(neigh); flush_neighbour_routes(neigh);
memset(neigh, 0, sizeof(*neigh)); memset(neigh, 0, sizeof(*neigh));
VALGRIND_MAKE_MEM_UNDEFINED(neigh, sizeof(*neigh)); VALGRIND_MAKE_MEM_UNDEFINED(neigh, sizeof(*neigh));
neigh->id[0] = 0xFF; neigh->hello_seqno = -2;
while(numneighs > 0 && neighs[numneighs - 1].id[0] == 0xFF) { while(numneighs > 0 && !neighbour_valid(&neighs[numneighs - 1])) {
numneighs--; numneighs--;
VALGRIND_MAKE_MEM_UNDEFINED(&neighs[numneighs], VALGRIND_MAKE_MEM_UNDEFINED(&neighs[numneighs],
sizeof(neighs[numneighs])); sizeof(neighs[numneighs]));
...@@ -56,7 +62,7 @@ find_neighbour(const unsigned char *address, struct network *net) ...@@ -56,7 +62,7 @@ find_neighbour(const unsigned char *address, struct network *net)
{ {
int i; int i;
for(i = 0; i < numneighs; i++) { for(i = 0; i < numneighs; i++) {
if(neighs[i].id[0] == 0xFF) if(!neighbour_valid(&neighs[i]))
continue; continue;
if(memcmp(address, neighs[i].address, 16) == 0 && if(memcmp(address, neighs[i].address, 16) == 0 &&
neighs[i].network == net) neighs[i].network == net)
...@@ -73,11 +79,6 @@ add_neighbour(const unsigned char *id, const unsigned char *address, ...@@ -73,11 +79,6 @@ add_neighbour(const unsigned char *id, const unsigned char *address,
const struct timeval zero = {0, 0}; const struct timeval zero = {0, 0};
int i; int i;
if(id[0] == 0xFF) {
fprintf(stderr, "Received neighbour announcement with id[0] = FF.\n");
return NULL;
}
neigh = find_neighbour(address, net); neigh = find_neighbour(address, net);
if(neigh) { if(neigh) {
if(memcmp(neigh->id, id, 16) == 0) { if(memcmp(neigh->id, id, 16) == 0) {
...@@ -92,7 +93,7 @@ add_neighbour(const unsigned char *id, const unsigned char *address, ...@@ -92,7 +93,7 @@ add_neighbour(const unsigned char *id, const unsigned char *address,
debugf("Creating neighbour %s (%s).\n", debugf("Creating neighbour %s (%s).\n",
format_address(id), format_address(address)); format_address(id), format_address(address));
for(i = 0; i < numneighs; i++) { for(i = 0; i < numneighs; i++) {
if(neighs[i].id[0] == 0xFF) if(!neighbour_valid(&neighs[i]))
neigh = &neighs[i]; neigh = &neighs[i];
} }
if(!neigh) { if(!neigh) {
...@@ -102,6 +103,7 @@ add_neighbour(const unsigned char *id, const unsigned char *address, ...@@ -102,6 +103,7 @@ add_neighbour(const unsigned char *id, const unsigned char *address,
} }
neigh = &neighs[numneighs++]; neigh = &neighs[numneighs++];
} }
neigh->hello_seqno = -1;
memcpy(neigh->id, id, 16); memcpy(neigh->id, id, 16);
memcpy(neigh->address, address, 16); memcpy(neigh->address, address, 16);
neigh->reach = 0; neigh->reach = 0;
...@@ -110,7 +112,6 @@ add_neighbour(const unsigned char *id, const unsigned char *address, ...@@ -110,7 +112,6 @@ add_neighbour(const unsigned char *id, const unsigned char *address,
neigh->hello_time = zero; neigh->hello_time = zero;
neigh->hello_interval = 0; neigh->hello_interval = 0;
neigh->ihu_interval = 0; neigh->ihu_interval = 0;
neigh->hello_seqno = -1;
neigh->network = net; neigh->network = net;
send_hello(net); send_hello(net);
return neigh; return neigh;
...@@ -220,7 +221,7 @@ check_neighbours() ...@@ -220,7 +221,7 @@ check_neighbours()
debugf("Checking neighbours.\n"); debugf("Checking neighbours.\n");
for(i = 0; i < numneighs; i++) { for(i = 0; i < numneighs; i++) {
if(neighs[i].id[0] == 0xFF) if(!neighbour_valid(&neighs[i]))
continue; continue;
changed = update_neighbour(&neighs[i], -1, 0); changed = update_neighbour(&neighs[i], -1, 0);
......
...@@ -21,12 +21,13 @@ THE SOFTWARE. ...@@ -21,12 +21,13 @@ THE SOFTWARE.
*/ */
struct neighbour { struct neighbour {
/* This is -1 when unknown, and -2 for an invalid neighbour,
so don't make it unsigned */
int hello_seqno;
unsigned char id[16]; unsigned char id[16];
unsigned char address[16]; unsigned char address[16];
unsigned short reach; unsigned short reach;
unsigned short txcost; unsigned short txcost;
/* This is -1 when unknown, so don't make it unsigned */
int hello_seqno;
struct timeval hello_time; struct timeval hello_time;
struct timeval ihu_time; struct timeval ihu_time;
unsigned short hello_interval; /* in centiseconds */ unsigned short hello_interval; /* in centiseconds */
......
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