Commit 5a159579 authored by Julien Muchembled's avatar Julien Muchembled Committed by Juliusz Chroboczek

Fix nodes incorrectly rejecting packets.

Nodes with default mac-verify would not accept packets from nodes with
non-default mac-verify.
Co-authored-by: default avatarJulien Muchembled <jm@jmuchemb.eu>
Co-authored-by: default avatarAntonin Décimo <antonin.decimo@gmail.com>
parent af02039b
...@@ -259,6 +259,7 @@ check_hmac(const unsigned char *packet, int packetlen, int bodylen, ...@@ -259,6 +259,7 @@ check_hmac(const unsigned char *packet, int packetlen, int bodylen,
{ {
int i = bodylen + 4; int i = bodylen + 4;
int len; int len;
int rc = -1;
debugf("check_hmac %s -> %s\n", debugf("check_hmac %s -> %s\n",
format_address(src), format_address(dst)); format_address(src), format_address(dst));
...@@ -278,8 +279,9 @@ check_hmac(const unsigned char *packet, int packetlen, int bodylen, ...@@ -278,8 +279,9 @@ check_hmac(const unsigned char *packet, int packetlen, int bodylen,
packet + i + 2, len, ifp->key); packet + i + 2, len, ifp->key);
if(ok) if(ok)
return 1; return 1;
rc = 0;
} }
i += len + 2; i += len + 2;
} }
return 0; return rc;
} }
...@@ -608,18 +608,23 @@ parse_packet(const unsigned char *from, struct interface *ifp, ...@@ -608,18 +608,23 @@ 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(ifp->key != NULL) {
if(check_hmac(packet, packetlen, bodylen, from, to, ifp) != 1) { switch(check_hmac(packet, packetlen, bodylen, from, to, ifp)) {
fprintf(stderr, "Received wrong hmac.\n"); case -1: /* no mac trailer */
if(ifp->flags & IF_NO_HMAC_VERIFY)
break;
/* fallthrough */
case 0:
fputs("Received wrong hmac.\n", stderr);
return; return;
} case 1:
neigh = preparse_packet(packet, bodylen, from, ifp); neigh = preparse_packet(packet, bodylen, from, ifp);
if(neigh == NULL) { if(neigh == NULL) {
fputs("Received wrong PC or failed the challenge.\n", stderr); fputs("Received wrong PC or failed the challenge.\n", stderr);
return; return;
} }
} }
}
neigh = neigh != NULL ? neigh : find_neighbour(from, ifp); neigh = neigh != NULL ? neigh : find_neighbour(from, ifp);
if(neigh == NULL) { if(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