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:
Andrew Bettison 2013-04-23 16:02:39 +09:30
parent 121ae2d609
commit 8771a50b14
5 changed files with 28 additions and 12 deletions

View File

@ -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

View File

@ -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);

View File

@ -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)
{

View File

@ -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);

View File

@ -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)