Commit 7de67155 authored by Etienne MARAIS's avatar Etienne MARAIS Committed by Juliusz Chroboczek

Create neighbour after checking HMAC.

parent ecd1f428
...@@ -546,7 +546,7 @@ parse_packet(const unsigned char *from, struct interface *ifp, ...@@ -546,7 +546,7 @@ parse_packet(const unsigned char *from, struct interface *ifp,
const unsigned char *message; const unsigned char *message;
unsigned char type, len; unsigned char type, len;
int bodylen; int bodylen;
struct neighbour *neigh; struct neighbour *neigh = NULL;
int have_router_id = 0, have_v4_prefix = 0, have_v6_prefix = 0, int have_router_id = 0, have_v4_prefix = 0, have_v6_prefix = 0,
have_v4_nh = 0, have_v6_nh = 0; have_v4_nh = 0, have_v6_nh = 0;
unsigned char router_id[8], v4_prefix[16], v6_prefix[16], unsigned char router_id[8], v4_prefix[16], v6_prefix[16],
...@@ -587,20 +587,28 @@ parse_packet(const unsigned char *from, struct interface *ifp, ...@@ -587,20 +587,28 @@ parse_packet(const unsigned char *from, struct interface *ifp,
bodylen = packetlen - 4; bodylen = packetlen - 4;
} }
if(ifp->key != NULL && !(ifp->flags & IF_NO_HMAC_VERIFY)) {
if(check_hmac(packet, packetlen, bodylen, from, to) != 1) {
fprintf(stderr, "Received wrong hmac.\n");
return;
}
neigh = find_neighbour(from, ifp); neigh = find_neighbour(from, ifp);
if(neigh == NULL) { if(neigh == NULL) {
fprintf(stderr, "Couldn't allocate neighbour.\n"); fprintf(stderr, "Couldn't allocate neighbour.\n");
return; return;
} }
if(ifp->key != NULL && !(ifp->flags & IF_NO_HMAC_VERIFY)) { if(preparse_packet(packet, bodylen, neigh, ifp) == 0) {
if(check_hmac(packet, packetlen, bodylen, neigh->address, to) != 1) { fprintf(stderr, "Received wrong PC or failed the challenge.\n");
fprintf(stderr, "Received wrong hmac.\n");
return; return;
} }
}
if(preparse_packet(packet, bodylen, neigh, ifp) == 0) { if(neigh == NULL) {
fprintf(stderr, "Received wrong PC or failed the challenge.\n"); neigh = find_neighbour(from, ifp);
if(neigh == NULL ) {
fprintf(stderr, "Couldn't allocate neighbour.\n");
return; return;
} }
} }
......
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