Skip to content

Commit

Permalink
babeld: Add interval and router-id 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 077c9ad
Showing 1 changed file with 42 additions and 4 deletions.
46 changes: 42 additions & 4 deletions babeld/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,13 @@ parse_packet(const unsigned char *from, struct interface *ifp,
DO_NTOHS(interval, message + 6);
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);
if (interval > 0) {
send_ack(neigh, nonce, interval);
} else {
debugf(BABEL_DEBUG_COMMON,"Received ack-req (%04X %d) with zero interval from %s on %s.",
nonce, interval, format_address(from), ifp->name);
goto done;
}
} else if(type == MESSAGE_ACK) {
debugf(BABEL_DEBUG_COMMON,"Received ack from %s on %s.",
format_address(from), ifp->name);
Expand Down Expand Up @@ -475,16 +481,43 @@ parse_packet(const unsigned char *from, struct interface *ifp,
neigh->ihu_time = babel_now;
neigh->ihu_interval = interval;
update_neighbour_metric(neigh, changed);
if(interval > 0)
if(interval > 0){
/* Multiply by 3/2 to allow neighbours to expire. */
schedule_neighbours_check(interval * 45, 0);
} else {
debugf(BABEL_DEBUG_COMMON, "Received ihu %d (%d) with zero interval from %s on %s for %s.",
txcost, interval,
format_address(from), ifp->name,
format_address(address));
goto done;
}

/* RTT sub-TLV. */
if(len > 10 + rc)
parse_ihu_subtlv(message + 8 + rc, len - 6 - rc,
&hello_send_us, &hello_rtt_receive_time);
}
} else if(type == MESSAGE_ROUTER_ID) {
if (len < 10) {
have_router_id = 0;
goto fail;
}
memcpy(router_id, message + 4, 8);
// Check if the Router-Id is all zeroes or all ones
bool is_all_zeroes = true;
bool is_all_ones = true;
for (int i = 0; i < 8; i++) {
if (router_id[i] != 0x00) {
is_all_zeroes = false;
}
if (router_id[i] != 0xFF) {
is_all_ones = false;
}
}
if (is_all_zeroes || is_all_ones) {
debugf(BABEL_DEBUG_COMMON, "Invalid Router-Id detected. Ignoring TLV.");
goto done;
}
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);
Expand Down Expand Up @@ -607,10 +640,15 @@ parse_packet(const unsigned char *from, struct interface *ifp,
len - parsed_len, channels);
}

if (!ignore_update)
update_route(router_id, prefix, plen, seqno, metric,
if (!ignore_update) {
if(interval > 0) {
update_route(router_id, prefix, plen, seqno, metric,
interval, neigh, nh, channels,
channels_len(channels));
} else {
debugf(BABEL_DEBUG_COMMON, "Received update with zero interval.");
}
}
} else if(type == MESSAGE_REQUEST) {
unsigned char prefix[16], plen;
int rc;
Expand Down

0 comments on commit 077c9ad

Please sign in to comment.