mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-04-14 22:26:44 +00:00
Fix TTL out-of-range bug
Was causing two routing tests to fail since the TTL decrement logic was fixed in a8b88a46 The default TTL of 64 overflowed the 5-bit unsigned int in the MDP packet header
This commit is contained in:
parent
121ae2d609
commit
8771a50b14
@ -100,6 +100,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
#define PAYLOAD_FLAG_CIPHERED (1<<4)
|
||||
#define PAYLOAD_FLAG_SIGNED (1<<5)
|
||||
|
||||
/* Time-to-live is a 'uint5_t'.
|
||||
*/
|
||||
#define PAYLOAD_TTL_MAX (31)
|
||||
#define PAYLOAD_TTL_DEFAULT (31)
|
||||
|
||||
// return codes for parsing mdp packet headers
|
||||
#define HEADER_PROCESS 1
|
||||
#define HEADER_FORWARD 2
|
||||
|
@ -362,7 +362,7 @@ int send_please_explain(struct decode_context *context, struct subscriber *sourc
|
||||
frame->destination = destination;
|
||||
|
||||
if (destination && (destination->reachable & REACHABLE)){
|
||||
frame->ttl=64;
|
||||
frame->ttl = PAYLOAD_TTL_DEFAULT; // MAX?
|
||||
}else{
|
||||
frame->ttl=1;// how will this work with olsr??
|
||||
overlay_broadcast_generate_address(&frame->broadcast_id);
|
||||
|
@ -626,9 +626,15 @@ int overlay_mdp_dispatch(overlay_mdp_frame *mdp,int userGeneratedFrameP,
|
||||
frame->destination = find_subscriber(mdp->out.dst.sid, SID_SIZE, 1);
|
||||
}
|
||||
|
||||
frame->ttl=mdp->out.ttl;
|
||||
if (frame->ttl==0)
|
||||
frame->ttl=64; /* default TTL */
|
||||
frame->ttl = mdp->out.ttl;
|
||||
if (frame->ttl == 0)
|
||||
frame->ttl = PAYLOAD_TTL_DEFAULT;
|
||||
else if (frame->ttl > PAYLOAD_TTL_MAX) {
|
||||
op_free(frame);
|
||||
RETURN(overlay_mdp_reply_error(mdp_named.poll.fd,
|
||||
recvaddr,recvaddrlen,9,
|
||||
"TTL out of range"));
|
||||
}
|
||||
|
||||
if (!frame->destination || frame->destination->reachable == REACHABLE_SELF)
|
||||
{
|
||||
|
@ -143,7 +143,8 @@ int overlay_forward_payload(struct overlay_frame *f){
|
||||
// Parse the mdp envelope header
|
||||
// may return (HEADER_PROCESS|HEADER_FORWARD) || -1
|
||||
int parseMdpPacketHeader(struct decode_context *context, struct overlay_frame *frame,
|
||||
struct overlay_buffer *buffer, struct subscriber **nexthop){
|
||||
struct overlay_buffer *buffer, struct subscriber **nexthop)
|
||||
{
|
||||
IN();
|
||||
int process=1;
|
||||
int forward=2;
|
||||
@ -203,21 +204,22 @@ int parseMdpPacketHeader(struct decode_context *context, struct overlay_frame *f
|
||||
}
|
||||
}
|
||||
|
||||
if (flags & PAYLOAD_FLAG_ONE_HOP){
|
||||
if (flags & PAYLOAD_FLAG_ONE_HOP) {
|
||||
frame->ttl=1;
|
||||
}else{
|
||||
} else {
|
||||
int ttl_qos = ob_get(buffer);
|
||||
if (ttl_qos<0)
|
||||
RETURN(WHY("Unable to read ttl"));
|
||||
frame->ttl = ttl_qos & 0x1F;
|
||||
frame->queue = (ttl_qos >> 5) & 3;
|
||||
}
|
||||
if (frame->ttl == 0){
|
||||
if (frame->ttl)
|
||||
--frame->ttl;
|
||||
if (frame->ttl == 0) {
|
||||
forward = 0;
|
||||
if (config.debug.overlayframes)
|
||||
DEBUGF("Don't forward when TTL expired");
|
||||
} else
|
||||
--frame->ttl;
|
||||
}
|
||||
|
||||
if (flags & PAYLOAD_FLAG_LEGACY_TYPE){
|
||||
int ftype = ob_get(buffer);
|
||||
|
@ -26,8 +26,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
int overlay_frame_build_header(struct decode_context *context, struct overlay_buffer *buff,
|
||||
int queue, int type, int modifiers, int ttl,
|
||||
struct broadcast *broadcast, struct subscriber *next_hop,
|
||||
struct subscriber *destination, struct subscriber *source){
|
||||
|
||||
struct subscriber *destination, struct subscriber *source)
|
||||
{
|
||||
if (ttl < 0 || ttl > PAYLOAD_TTL_MAX)
|
||||
return WHYF("invalid ttl=%d", ttl);
|
||||
|
||||
int flags = modifiers & (PAYLOAD_FLAG_CIPHERED | PAYLOAD_FLAG_SIGNED);
|
||||
|
||||
if (ttl==1 && !broadcast)
|
||||
|
Loading…
x
Reference in New Issue
Block a user