Commit 3551b45c authored by Antonin Décimo's avatar Antonin Décimo Committed by Juliusz Chroboczek

Simplify and fix preparse phase.

parent ba8f1168
...@@ -477,6 +477,10 @@ preparse_packet(const unsigned char *from, struct interface *ifp, ...@@ -477,6 +477,10 @@ preparse_packet(const unsigned char *from, struct interface *ifp,
} }
if(type == MESSAGE_PC) { if(type == MESSAGE_PC) {
unsigned int pcnat; unsigned int pcnat;
if(index != NULL)
goto done;
if(len < 4) { if(len < 4) {
fprintf(stderr, "Received truncated PC TLV.\n"); fprintf(stderr, "Received truncated PC TLV.\n");
break; break;
...@@ -485,8 +489,7 @@ preparse_packet(const unsigned char *from, struct interface *ifp, ...@@ -485,8 +489,7 @@ preparse_packet(const unsigned char *from, struct interface *ifp,
fprintf(stderr, "Overlong PC TLV.\n"); fprintf(stderr, "Overlong PC TLV.\n");
break; break;
} }
if(index != NULL)
goto done;
pc = message + 2; pc = message + 2;
index = message + 6; index = message + 6;
index_len = len - 4; index_len = len - 4;
...@@ -495,15 +498,25 @@ preparse_packet(const unsigned char *from, struct interface *ifp, ...@@ -495,15 +498,25 @@ preparse_packet(const unsigned char *from, struct interface *ifp,
debugf("Received PC %u from %s.\n", debugf("Received PC %u from %s.\n",
ntohl(pcnat), format_address(from)); ntohl(pcnat), format_address(from));
} else if(type == MESSAGE_CHALLENGE_REQUEST) { } else if(type == MESSAGE_CHALLENGE_REQUEST) {
debugf("Received challenge request from %s.\n",
format_address(from));
if(IN6_IS_ADDR_MULTICAST(to)) if(IN6_IS_ADDR_MULTICAST(to))
goto done; goto done;
if(len > 192) {
fprintf(stderr, "Overlong challenge request TLV.\n");
break;
}
nonce = message + 2; nonce = message + 2;
nonce_len = len; nonce_len = len;
debugf("Received challenge request from %s.\n",
format_address(from));
} else if(type == MESSAGE_CHALLENGE_REPLY) { } else if(type == MESSAGE_CHALLENGE_REPLY) {
if(len > 192) {
fprintf(stderr, "Overlong challenge reply TLV.\n");
break;
}
debugf("Received challenge reply from %s.\n", debugf("Received challenge reply from %s.\n",
format_address(from)); format_address(from));
...@@ -522,6 +535,7 @@ preparse_packet(const unsigned char *from, struct interface *ifp, ...@@ -522,6 +535,7 @@ preparse_packet(const unsigned char *from, struct interface *ifp,
const struct timeval zero = {0, 0}; const struct timeval zero = {0, 0};
challenge_success = 1; challenge_success = 1;
neigh->challenge_deadline = zero; neigh->challenge_deadline = zero;
debugf("Challenge succeeded!\n");
} else { } else {
debugf("Challenge failed.\n"); debugf("Challenge failed.\n");
} }
...@@ -532,43 +546,37 @@ preparse_packet(const unsigned char *from, struct interface *ifp, ...@@ -532,43 +546,37 @@ preparse_packet(const unsigned char *from, struct interface *ifp,
if(index == NULL) { if(index == NULL) {
debugf("No PC in packet.\n"); debugf("No PC in packet.\n");
goto maybe_send_challenge_reply; } else if(challenge_success) {
}
if(challenge_success) {
neigh->index_len = index_len; neigh->index_len = index_len;
memcpy(neigh->index, index, index_len); memcpy(neigh->index, index, index_len);
memcpy(neigh->pc, pc, 4); memcpy(neigh->pc, pc, 4);
accept_packet = 1; accept_packet = 1;
goto maybe_send_challenge_reply; } else {
}
if(neigh == NULL || neigh->index_len != index_len ||
memcmp(index, neigh->index, index_len) != 0) {
neigh = neigh != NULL ? neigh : find_neighbour(from, ifp); neigh = neigh != NULL ? neigh : find_neighbour(from, ifp);
if(neigh == NULL) if(neigh == NULL)
return NULL; return NULL;
rc = send_challenge_request(neigh); if(neigh->index_len == -1 ||
if(rc < -1) neigh->index_len != index_len ||
fputs("Could not send challenge request.\n", stderr); memcmp(index, neigh->index, index_len) != 0) {
goto maybe_send_challenge_reply; rc = send_challenge_request(neigh);
} if(rc < -1)
fputs("Could not send challenge request.\n", stderr);
if(memcmp(pc, neigh->pc, 4) <= 0) { } else if(memcmp(pc, neigh->pc, 4) <= 0) {
debugf("Out of order PC.\n"); debugf("Out of order PC.\n");
return NULL; nonce = NULL;
} else {
memcpy(neigh->pc, pc, 4);
accept_packet = 1;
}
} }
memcpy(neigh->pc, pc, 4);
return neigh;
maybe_send_challenge_reply:
if(nonce != NULL) { /* a challenge request was received */ if(nonce != NULL) { /* a challenge request was received */
neigh = neigh != NULL ? neigh : find_neighbour(from, ifp); neigh = neigh != NULL ? neigh : find_neighbour(from, ifp);
if(neigh == NULL) if(neigh == NULL)
return NULL; return NULL;
send_challenge_reply(neigh, nonce, nonce_len); send_challenge_reply(neigh, nonce, nonce_len);
} }
debugf("accept_packet: %d, neigh: %p.\n", accept_packet, (void*)neigh);
return accept_packet ? neigh : NULL; return accept_packet ? neigh : NULL;
} }
......
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