mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-01-29 15:43:56 +00:00
Add length of link record for forward compatibility
This commit is contained in:
parent
85b885dde2
commit
d7caaf4973
@ -282,7 +282,6 @@ int ob_append_rfs(struct overlay_buffer *b,int l)
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
Functions that read / write data within the existing length limit
|
||||
*/
|
||||
@ -379,6 +378,14 @@ int ob_set_ui16(struct overlay_buffer *b, int offset, uint16_t v)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ob_set(struct overlay_buffer *b, int ofs, unsigned char byte)
|
||||
{
|
||||
if (test_offset(b, ofs, 1))
|
||||
return -1;
|
||||
b->bytes[ofs] = byte;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ob_patch_rfs(struct overlay_buffer *b){
|
||||
return ob_set_ui16(b,b->var_length_offset,b->position - (b->var_length_offset + 2));
|
||||
}
|
||||
|
@ -52,6 +52,7 @@ int ob_rewind(struct overlay_buffer *b);
|
||||
int ob_limitsize(struct overlay_buffer *b,int bytes);
|
||||
int ob_unlimitsize(struct overlay_buffer *b);
|
||||
int ob_makespace(struct overlay_buffer *b,int bytes);
|
||||
int ob_set(struct overlay_buffer *b, int ofs, unsigned char byte);
|
||||
int ob_append_byte(struct overlay_buffer *b,unsigned char byte);
|
||||
int ob_append_bytes(struct overlay_buffer *b,unsigned char *bytes,int count);
|
||||
int ob_append_buffer(struct overlay_buffer *b,struct overlay_buffer *s);
|
||||
|
21
route_link.c
21
route_link.c
@ -242,6 +242,10 @@ static int append_link_state(struct overlay_buffer *payload, char flags, struct
|
||||
if (!transmitter)
|
||||
flags|=FLAG_NO_PATH;
|
||||
|
||||
int length_pos = ob_position(payload);
|
||||
if (ob_append_byte(payload, 0))
|
||||
return -1;
|
||||
|
||||
if (ob_append_byte(payload, flags))
|
||||
return -1;
|
||||
|
||||
@ -259,6 +263,14 @@ static int append_link_state(struct overlay_buffer *payload, char flags, struct
|
||||
if (ob_append_byte(payload, interface))
|
||||
return -1;
|
||||
|
||||
// TODO insert future fields here
|
||||
|
||||
|
||||
// patch the record length
|
||||
int end_pos = ob_position(payload);
|
||||
if (ob_set(payload, length_pos, end_pos - length_pos))
|
||||
return -1;
|
||||
|
||||
ob_checkpoint(payload);
|
||||
return 0;
|
||||
}
|
||||
@ -419,6 +431,12 @@ int link_receive(overlay_mdp_frame *mdp)
|
||||
context.invalid_addresses=0;
|
||||
|
||||
struct subscriber *receiver=NULL, *transmitter=NULL;
|
||||
|
||||
int start_pos = ob_position(payload);
|
||||
int length = ob_get(payload);
|
||||
if (length <=0)
|
||||
break;
|
||||
|
||||
int flags = ob_get(payload);
|
||||
if (flags<0)
|
||||
break;
|
||||
@ -438,6 +456,9 @@ int link_receive(overlay_mdp_frame *mdp)
|
||||
break;
|
||||
}
|
||||
|
||||
// jump to the position of the next record, even if there's more data we don't understand
|
||||
payload->position = start_pos + length;
|
||||
|
||||
if (context.invalid_addresses)
|
||||
continue;
|
||||
|
||||
|
@ -43,6 +43,7 @@ start_routing_instance() {
|
||||
set log.console.show_pid on \
|
||||
set log.console.show_time on \
|
||||
set debug.mdprequests yes \
|
||||
set debug.linkstate yes \
|
||||
set debug.verbose yes \
|
||||
set rhizome.enable no
|
||||
start_servald_server
|
||||
|
Loading…
x
Reference in New Issue
Block a user