Add hop count to mdp ping

- Allow mdp client to specify ttl
- Copy ttl into and out of overlay frame
This commit is contained in:
Jeremy Lakeman 2012-10-10 16:22:31 +10:30
parent 4658251ebe
commit b22e3f1964
7 changed files with 40 additions and 5 deletions

View File

@ -833,9 +833,13 @@ int app_mdp_ping(int argc, const char *const *argv, struct command_line_option *
{
int *rxseq=(int *)&mdp.in.payload;
long long *txtime=(long long *)&mdp.in.payload[4];
int hop_count = 64 - mdp.in.ttl;
time_ms_t delay = gettime_ms() - *txtime;
printf("%s: seq=%d time=%lld ms%s%s\n",
alloca_tohex_sid(mdp.in.src.sid),(*rxseq)-firstSeq+1,delay,
printf("%s: seq=%d time=%lld hops=%d ms%s%s\n",
alloca_tohex_sid(mdp.in.src.sid),
(*rxseq)-firstSeq+1,
delay,
hop_count,
mdp.packetTypeAndFlags&MDP_NOCRYPT?"":" ENCRYPTED",
mdp.packetTypeAndFlags&MDP_NOSIGN?"":" SIGNED");
// TODO Put duplicate pong detection here so that stats work properly.

View File

@ -1224,6 +1224,7 @@ int keyring_mapping_request(keyring_file *k, overlay_mdp_frame *req)
/* and record the full length of this */
req->out.payload_length = 1 + SAS_SIZE + slen;
overlay_mdp_swap_src_dst(req);
req->out.ttl=0;
req->packetTypeAndFlags=MDP_TX; /* crypt and sign */
if (debug & DEBUG_KEYRING)
DEBUGF("Sending SID:SAS mapping, %d bytes, %s:0x%X -> %s:0x%X",

View File

@ -372,6 +372,7 @@ int overlay_saw_mdp_containing_frame(struct overlay_frame *f, time_ms_t now)
bzero(&mdp, sizeof(overlay_mdp_frame));
mdp.in.queue = f->queue;
mdp.in.ttl = f->ttl;
/* Get source and destination addresses */
if (f->destination)
@ -530,7 +531,8 @@ int overlay_saw_mdp_frame(overlay_mdp_frame *mdp, time_ms_t now)
/* Swap addresses */
overlay_mdp_swap_src_dst(mdp);
mdp->out.ttl=0;
/* Prevent echo:echo connections and the resulting denial of service from triggering endless pongs. */
if (mdp->out.dst.port==MDP_PORT_ECHO) {
RETURN(WHY("echo loop averted"));
@ -710,7 +712,10 @@ int overlay_mdp_dispatch(overlay_mdp_frame *mdp,int userGeneratedFrameP,
}else{
frame->destination = find_subscriber(mdp->out.dst.sid, SID_SIZE, 1);
}
frame->ttl=64; /* normal TTL (XXX allow setting this would be a good idea) */
frame->ttl=mdp->out.ttl;
if (frame->ttl==0)
frame->ttl=64; /* default TTL */
if (!frame->destination || frame->destination->reachable == REACHABLE_SELF)
{

View File

@ -72,7 +72,6 @@ int process_incoming_frame(time_ms_t now, struct overlay_interface *interface, s
// duplicate the frame and queue it
int overlay_forward_payload(struct overlay_frame *f){
f->ttl--;
if (f->ttl<=0)
return 0;
@ -226,6 +225,7 @@ int packetOkOverlay(struct overlay_interface *interface,unsigned char *packet, s
/* Get time to live */
f.ttl=ob_get(b);
f.ttl--;
/* Decode length of remainder of frame */
int payload_len=rfs_decode(b->bytes, &b->position);

View File

@ -87,6 +87,8 @@ int overlay_frame_append_payload(overlay_interface *interface, struct overlay_fr
goto cleanup;
/* Write out TTL */
if (p->ttl>64)
p->ttl=64;
if (ob_append_byte(headers,p->ttl))
goto cleanup;

View File

@ -700,6 +700,7 @@ typedef struct overlay_mdp_data_frame {
// temporary hack to improve reliability before implementing per-packet nack's
int send_copies;
int queue;
int ttl;
unsigned char payload[MDP_MTU-100];
} overlay_mdp_data_frame;

View File

@ -81,4 +81,26 @@ test_multihop_linear() {
tfw_cat --stdout --stderr
}
setup_crowded_mess() {
setup_servald
assert_no_servald_processes
# BCDE & DEFG form squares, ABC & FGH form triangles
foreach_instance +A +B +C +D +E +F +G +H create_single_identity
foreach_instance +A +B +C add_interface dummy1
foreach_instance +B +D add_interface dummy2
foreach_instance +C +E add_interface dummy3
foreach_instance +D +E add_interface dummy4
foreach_instance +D +F add_interface dummy5
foreach_instance +E +G add_interface dummy6
foreach_instance +F +G +H add_interface dummy7
foreach_instance +A +B +C +D +E +F +G +H start_routing_instance
}
doc_crowded_mess="Multiple possible paths"
test_crowded_mess() {
set_instance +A
executeOk_servald mdp ping $SIDH 5
tfw_cat --stdout --stderr
}
runTests "$@"