Skip to content

Commit

Permalink
Expire Index and challenge timer.
Browse files Browse the repository at this point in the history
  • Loading branch information
MisterDA authored and jech committed May 30, 2021
1 parent d66a4d2 commit ceda3a0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
13 changes: 9 additions & 4 deletions message.c
Original file line number Diff line number Diff line change
Expand Up @@ -508,10 +508,16 @@ preparse_packet(const unsigned char *from, struct interface *ifp,
goto done;

gettime(&now);
if(timeval_compare(&now, &neigh->challenge_deadline) > 0) {
debugf("No pending challenge.\n");
goto done;
}

if(len == sizeof(neigh->nonce) &&
memcmp(neigh->nonce, message + 2, len) == 0 &&
timeval_compare(&now, &neigh->challenge_deadline) <= 0) {
memcmp(neigh->nonce, message + 2, len) == 0) {
const struct timeval zero = {0, 0};
challenge_success = 1;
neigh->challenge_deadline = zero;
} else {
debugf("Challenge failed.\n");
}
Expand All @@ -529,12 +535,11 @@ preparse_packet(const unsigned char *from, struct interface *ifp,
neigh->index_len = index_len;
memcpy(neigh->index, index, index_len);
memcpy(neigh->pc, pc, 4);
neigh->have_index = 1;
accept_packet = 1;
goto maybe_send_challenge_reply;
}

if(neigh == NULL || !neigh->have_index || neigh->index_len != index_len ||
if(neigh == NULL || neigh->index_len != index_len ||
memcmp(index, neigh->index, index_len) != 0) {
neigh = neigh != NULL ? neigh : find_neighbour(from, ifp);
if(neigh == NULL)
Expand Down
3 changes: 2 additions & 1 deletion neighbour.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ find_neighbour(const unsigned char *address, struct interface *ifp)
neigh->hello_rtt_receive_time = zero;
neigh->echo_receive_time = zero;
neigh->rtt_time = zero;
neigh->challenge_deadline = now;
neigh->index_len = -1;
neigh->challenge_deadline = zero;
neigh->ifp = ifp;
neigh->buf.buf = buf;
neigh->buf.size = ifp->buf.size;
Expand Down
3 changes: 1 addition & 2 deletions neighbour.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ struct neighbour {
struct timeval echo_receive_time;
unsigned int rtt;
struct timeval rtt_time;
int have_index;
int index_len;
unsigned char pc[4];
int index_len; /* This is -1 when index is undefined */
unsigned char index[32];
unsigned char nonce[NONCE_LEN];
struct timeval challenge_deadline;
Expand Down

0 comments on commit ceda3a0

Please sign in to comment.