Skip to content

Commit

Permalink
babeld: Add MBZ and Reserved field checking
Browse files Browse the repository at this point in the history
Signed-off-by: zmw12306 <[email protected]>
  • Loading branch information
zmw12306 committed Sep 3, 2024
1 parent 9b96394 commit 9731902
Showing 1 changed file with 59 additions and 5 deletions.
64 changes: 59 additions & 5 deletions babeld/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,12 @@ static bool parse_update_subtlv(const unsigned char *a, int alen,
"Received Mandatory bit set but this FRR version is not prepared to handle it at this point");
return true;
} else if (type == SUBTLV_PADN) {
/* Nothing. */
for (int j = 0; j < len; j++) {
if (a[i + j + 2] != 0) {
debugf(BABEL_DEBUG_COMMON,"Received pad%d with non zero MBZ field.",
len);
}
}
} else if (type == SUBTLV_DIVERSITY) {
if (len > DIVERSITY_HOPS) {
flog_err(
Expand Down Expand Up @@ -208,7 +213,12 @@ parse_hello_subtlv(const unsigned char *a, int alen,
"Received subtlv with Mandatory bit, this version of FRR is not prepared to handle this currently");
return -2;
} else if (type == SUBTLV_PADN) {
/* Nothing to do. */
for (int j = 0; j < len; j++) {
if (a[i + j + 2] != 0) {
debugf(BABEL_DEBUG_COMMON,"Received pad%d with non zero MBZ field.",
len);
}
}
} else if (type == SUBTLV_TIMESTAMP) {
if (len >= 4) {
DO_NTOHL(*hello_send_us, a + i + 2);
Expand Down Expand Up @@ -255,7 +265,12 @@ parse_ihu_subtlv(const unsigned char *a, int alen,
}

if(type == SUBTLV_PADN) {
/* Nothing to do. */
for (int j = 0; j < len; j++) {
if (a[i + j + 2] != 0) {
debugf(BABEL_DEBUG_COMMON,"Received pad%d with non zero MBZ field.",
len);
}
}
} else if(type == SUBTLV_TIMESTAMP) {
if(len >= 8) {
DO_NTOHL(*hello_send_us, a + i + 2);
Expand Down Expand Up @@ -392,12 +407,24 @@ parse_packet(const unsigned char *from, struct interface *ifp,
len = message[1];

if(type == MESSAGE_PADN) {
for (int i = 0; i < len; i++) {
if (message[i + 2] != 0) {
debugf(BABEL_DEBUG_COMMON,"Received pad%d with non zero MBZ field from %s on %s.",
len, format_address(from), ifp->name);
}
}
debugf(BABEL_DEBUG_COMMON,"Received pad%d from %s on %s.",
len, format_address(from), ifp->name);
} else if(type == MESSAGE_ACK_REQ) {
unsigned short nonce, interval;
unsigned short nonce, interval, Reserved;
DO_NTOHS(Reserved, message + 2);
DO_NTOHS(nonce, message + 4);
DO_NTOHS(interval, message + 6);
if (Reserved != 0) {
debugf(BABEL_DEBUG_COMMON,"Received ack-req (%04X %d) with non zero Reserved from %s on %s.",
nonce, interval, format_address(from), ifp->name);
goto done;
}
debugf(BABEL_DEBUG_COMMON,"Received ack-req (%04X %d) from %s on %s.",
nonce, interval, format_address(from), ifp->name);
send_ack(neigh, nonce, interval);
Expand Down Expand Up @@ -459,8 +486,15 @@ parse_packet(const unsigned char *from, struct interface *ifp,
}
} else if(type == MESSAGE_IHU) {
unsigned short txcost, interval;
unsigned char Reserved;
unsigned char address[16];
int rc;
Reserved = message[3];
if (Reserved != 0) {
debugf(BABEL_DEBUG_COMMON,"Received ihu with non zero Reserved from %s on %s.",
format_address(from), ifp->name);
goto done;
}
DO_NTOHS(txcost, message + 4);
DO_NTOHS(interval, message + 6);
rc = network_address(message[2], message + 8, len - 6, address);
Expand All @@ -484,12 +518,26 @@ parse_packet(const unsigned char *from, struct interface *ifp,
&hello_send_us, &hello_rtt_receive_time);
}
} else if(type == MESSAGE_ROUTER_ID) {
unsigned short Reserved;
DO_NTOHS(Reserved, message + 2);
if (Reserved != 0) {
debugf(BABEL_DEBUG_COMMON,"Received router-id with non zero Reserved from %s on %s.",
format_address(from), ifp->name);
goto done;
}
memcpy(router_id, message + 4, 8);
have_router_id = 1;
debugf(BABEL_DEBUG_COMMON,"Received router-id %s from %s on %s.",
format_eui64(router_id), format_address(from), ifp->name);
} else if(type == MESSAGE_NH) {
unsigned char nh[16];
unsigned char Reserved;
Reserved = message[3];
if (Reserved != 0) {
debugf(BABEL_DEBUG_COMMON,"Received nh with non zero Reserved from %s on %s.",
format_address(from), ifp->name);
goto done;
}
int rc;
rc = network_address(message[2], message + 4, len - 2,
nh);
Expand Down Expand Up @@ -638,8 +686,14 @@ parse_packet(const unsigned char *from, struct interface *ifp,
send_update(neigh->ifp, 0, prefix, plen);
}
} else if(type == MESSAGE_MH_REQUEST) {
unsigned char prefix[16], plen;
unsigned char prefix[16], plen, Reserved;
unsigned short seqno;
Reserved = message[7];
if (Reserved != 0) {
debugf(BABEL_DEBUG_COMMON,"Received request with non zero Reserved from %s on %s.",
format_address(from), ifp->name);
goto done;
}
int rc;
DO_NTOHS(seqno, message + 4);
rc = network_prefix(message[2], message[3], 0,
Expand Down

0 comments on commit 9731902

Please sign in to comment.