mirror of
https://github.com/servalproject/serval-dna.git
synced 2024-12-21 06:03:12 +00:00
Replace overlay_render_sid_prefix() with alloca_tohex()
To eliminate timebomb bugs caused by rotor wraparound
This commit is contained in:
parent
d72e4d20ea
commit
72769e162b
10
keyring.c
10
keyring.c
@ -1132,7 +1132,7 @@ unsigned char *keyring_find_sas_private(keyring_file *k,unsigned char *sid,
|
|||||||
if (sas_public)
|
if (sas_public)
|
||||||
*sas_public=
|
*sas_public=
|
||||||
k->contexts[cn]->identities[in]->keypairs[kp]->public_key;
|
k->contexts[cn]->identities[in]->keypairs[kp]->public_key;
|
||||||
if (0) WHYF("Found SAS entry for %s*",overlay_render_sid_prefix(sid,7));
|
if (0) DEBUGF("Found SAS entry for %s*", alloca_tohex(sid, 7));
|
||||||
RETURN(k->contexts[cn]->identities[in]->keypairs[kp]->private_key);
|
RETURN(k->contexts[cn]->identities[in]->keypairs[kp]->private_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1289,10 +1289,10 @@ unsigned char *keyring_find_sas_public(keyring_file *k,unsigned char *sid)
|
|||||||
for(i=0;i<sid_sas_mapping_count;i++)
|
for(i=0;i<sid_sas_mapping_count;i++)
|
||||||
{
|
{
|
||||||
if (memcmp(sid,sid_sas_mappings[i].sid,SID_SIZE)) continue;
|
if (memcmp(sid,sid_sas_mappings[i].sid,SID_SIZE)) continue;
|
||||||
if (sid_sas_mappings[i].validP)
|
if (sid_sas_mappings[i].validP) {
|
||||||
{ if (0)
|
if (0) DEBUGF("Found SAS public entry for %s*", alloca_tohex(sid, 7));
|
||||||
WHYF("Found SAS public entry for %s*",overlay_render_sid_prefix(sid,7));
|
RETURN(sid_sas_mappings[i].sas_public);
|
||||||
RETURN(sid_sas_mappings[i].sas_public); }
|
}
|
||||||
/* Don't flood the network with mapping requests */
|
/* Don't flood the network with mapping requests */
|
||||||
if (((now-sid_sas_mappings[i].last_request_time_in_ms)<1000)
|
if (((now-sid_sas_mappings[i].last_request_time_in_ms)<1000)
|
||||||
&&((now-sid_sas_mappings[i].last_request_time_in_ms)>=0))
|
&&((now-sid_sas_mappings[i].last_request_time_in_ms)>=0))
|
||||||
|
@ -309,7 +309,7 @@ int overlay_frame_process(struct overlay_interface *interface,overlay_frame *f)
|
|||||||
if (overlay_get_nexthop(f->destination,f->nexthop,&len,
|
if (overlay_get_nexthop(f->destination,f->nexthop,&len,
|
||||||
&f->nexthop_interface))
|
&f->nexthop_interface))
|
||||||
WHYF("Could not find next hop for %s* - dropping frame",
|
WHYF("Could not find next hop for %s* - dropping frame",
|
||||||
overlay_render_sid_prefix(f->destination,7));
|
alloca_tohex(f->destination, 7));
|
||||||
dontForward=1;
|
dontForward=1;
|
||||||
}
|
}
|
||||||
f->ttl--;
|
f->ttl--;
|
||||||
|
@ -920,8 +920,8 @@ int overlay_tick_interface(int i, long long now)
|
|||||||
{
|
{
|
||||||
if (debug&DEBUG_QUEUES)
|
if (debug&DEBUG_QUEUES)
|
||||||
DEBUGF("dequeuing %s* -> %s* NOW (queue length=%d)",
|
DEBUGF("dequeuing %s* -> %s* NOW (queue length=%d)",
|
||||||
overlay_render_sid_prefix((*p)->source,7),
|
alloca_tohex((*p)->source, 7),
|
||||||
overlay_render_sid_prefix((*p)->destination,7),
|
alloca_tohex((*p)->destination, 7),
|
||||||
overlay_tx[q].length);
|
overlay_tx[q].length);
|
||||||
t=*p;
|
t=*p;
|
||||||
*p=t->next;
|
*p=t->next;
|
||||||
|
@ -422,7 +422,7 @@ int overlay_saw_mdp_frame(overlay_mdp_frame *mdp,long long now)
|
|||||||
|
|
||||||
if (0)
|
if (0)
|
||||||
WHYF("Received packet with listener (MDP ports: src=%s*:%d, dst=%d)",
|
WHYF("Received packet with listener (MDP ports: src=%s*:%d, dst=%d)",
|
||||||
overlay_render_sid_prefix(mdp->out.src.sid,7),
|
alloca_tohex(mdp->out.src.sid, 7),
|
||||||
mdp->out.src.port,mdp->out.dst.port);
|
mdp->out.src.port,mdp->out.dst.port);
|
||||||
|
|
||||||
|
|
||||||
|
@ -246,7 +246,7 @@ int overlay_payload_enqueue(int q,overlay_frame *p,int forceBroadcastP)
|
|||||||
*/
|
*/
|
||||||
if (0)
|
if (0)
|
||||||
WHYF("Enqueuing packet for %s* (q[%d]length = %d)",
|
WHYF("Enqueuing packet for %s* (q[%d]length = %d)",
|
||||||
overlay_render_sid_prefix(p->destination,7),
|
alloca_tohex(p->destination, 7),
|
||||||
q,overlay_tx[q].length);
|
q,overlay_tx[q].length);
|
||||||
if (q==OQ_ISOCHRONOUS_VOICE&&(!forceBroadcastP)) {
|
if (q==OQ_ISOCHRONOUS_VOICE&&(!forceBroadcastP)) {
|
||||||
/* Dispatch voice data immediately.
|
/* Dispatch voice data immediately.
|
||||||
|
@ -1008,23 +1008,6 @@ int overlay_route_recalc_neighbour_metrics(overlay_neighbour *n,long long now)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int ors_rotor=0;
|
|
||||||
char ors_out[4][SID_STRLEN+1];
|
|
||||||
|
|
||||||
char *overlay_render_sid_prefix(const unsigned char *sid,int l)
|
|
||||||
{
|
|
||||||
int zero=0;
|
|
||||||
|
|
||||||
if (l<0) l=0;
|
|
||||||
if (l>SID_STRLEN) l=SID_STRLEN;
|
|
||||||
ors_rotor++;
|
|
||||||
ors_rotor&=3;
|
|
||||||
extractSid(sid,&zero,ors_out[ors_rotor]);
|
|
||||||
ors_out[ors_rotor][l]=0;
|
|
||||||
return ors_out[ors_rotor];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Self-announcement acks bounce back to the self-announcer from immediate neighbours
|
Self-announcement acks bounce back to the self-announcer from immediate neighbours
|
||||||
who report the link score they have calculated based on listening to self-announces
|
who report the link score they have calculated based on listening to self-announces
|
||||||
@ -1112,8 +1095,7 @@ int overlay_route_record_link(long long now,unsigned char *to,
|
|||||||
}
|
}
|
||||||
|
|
||||||
DEBUGF("route_record_link(0x%llx,%s*,%s*,0x%08x-0x%08x,%d)",
|
DEBUGF("route_record_link(0x%llx,%s*,%s*,0x%08x-0x%08x,%d)",
|
||||||
now,overlay_render_sid_prefix(to,7),
|
now, alloca_tohex(to, 7), alloca_tohex(via, 7), s1, s2, score);
|
||||||
overlay_render_sid_prefix(via,7),s1,s2,score);
|
|
||||||
|
|
||||||
overlay_node *n=overlay_route_find_node(to,SID_SIZE,1 /* create node if missing */);
|
overlay_node *n=overlay_route_find_node(to,SID_SIZE,1 /* create node if missing */);
|
||||||
if (!n) return WHY("Could not find or create entry for node");
|
if (!n) return WHY("Could not find or create entry for node");
|
||||||
@ -1199,8 +1181,8 @@ int overlay_route_dump()
|
|||||||
if (overlay_neighbours[n].node)
|
if (overlay_neighbours[n].node)
|
||||||
{
|
{
|
||||||
strbuf_sprintf(b," %s* : %lldms ago :",
|
strbuf_sprintf(b," %s* : %lldms ago :",
|
||||||
overlay_render_sid_prefix(overlay_neighbours[n].node->sid,7),
|
alloca_tohex(overlay_neighbours[n].node->sid, 7),
|
||||||
(now-overlay_neighbours[n].last_observation_time_ms));
|
now - overlay_neighbours[n].last_observation_time_ms);
|
||||||
for(i=0;i<OVERLAY_MAX_INTERFACES;i++)
|
for(i=0;i<OVERLAY_MAX_INTERFACES;i++)
|
||||||
if (overlay_neighbours[n].scores[i])
|
if (overlay_neighbours[n].scores[i])
|
||||||
strbuf_sprintf(b," %d(via #%d)",
|
strbuf_sprintf(b," %d(via #%d)",
|
||||||
@ -1216,7 +1198,7 @@ int overlay_route_dump()
|
|||||||
{
|
{
|
||||||
if (!overlay_nodes[bin][slot].sid[0]) continue;
|
if (!overlay_nodes[bin][slot].sid[0]) continue;
|
||||||
|
|
||||||
strbuf_sprintf(b," %s* : %d :",overlay_render_sid_prefix(overlay_nodes[bin][slot].sid,7),
|
strbuf_sprintf(b," %s* : %d :", alloca_tohex(overlay_nodes[bin][slot].sid, 7),
|
||||||
overlay_nodes[bin][slot].best_link_score);
|
overlay_nodes[bin][slot].best_link_score);
|
||||||
for(o=0;o<OVERLAY_MAX_OBSERVATIONS;o++)
|
for(o=0;o<OVERLAY_MAX_OBSERVATIONS;o++)
|
||||||
{
|
{
|
||||||
@ -1226,7 +1208,7 @@ int overlay_route_dump()
|
|||||||
if (ob->corrected_score)
|
if (ob->corrected_score)
|
||||||
strbuf_sprintf(b," %d/%d via %s*",
|
strbuf_sprintf(b," %d/%d via %s*",
|
||||||
ob->corrected_score,ob->gateways_en_route,
|
ob->corrected_score,ob->gateways_en_route,
|
||||||
overlay_render_sid_prefix(ob->sender_prefix,7));
|
alloca_tohex(ob->sender_prefix, 7));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
strbuf_sprintf(b,"\n");
|
strbuf_sprintf(b,"\n");
|
||||||
@ -1358,8 +1340,7 @@ int overlay_route_node_info(overlay_mdp_frame *mdp,
|
|||||||
|
|
||||||
if (0)
|
if (0)
|
||||||
DEBUGF("Looking for node %s* (prefix len=0x%x)",
|
DEBUGF("Looking for node %s* (prefix len=0x%x)",
|
||||||
overlay_render_sid_prefix(mdp->nodeinfo.sid,
|
alloca_tohex(mdp->nodeinfo.sid, mdp->nodeinfo.sid_prefix_length),
|
||||||
mdp->nodeinfo.sid_prefix_length),
|
|
||||||
mdp->nodeinfo.sid_prefix_length
|
mdp->nodeinfo.sid_prefix_length
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -342,7 +342,7 @@ int rhizome_add_manifest(rhizome_manifest *m_in,int ttl)
|
|||||||
return WHY("rhizome_store_bundle() failed.");
|
return WHY("rhizome_store_bundle() failed.");
|
||||||
|
|
||||||
DEBUGF("Announcing arrival of manifest %s* version %lld",
|
DEBUGF("Announcing arrival of manifest %s* version %lld",
|
||||||
overlay_render_sid_prefix(m_in->cryptoSignPublic,8),m_in->version);
|
alloca_tohex(m_in->cryptoSignPublic, 8), m_in->version);
|
||||||
monitor_announce_bundle(m_in);
|
monitor_announce_bundle(m_in);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -238,7 +238,7 @@ int overlay_rhizome_add_advertisements(int interface_number,overlay_buffer *e)
|
|||||||
long long version = rhizome_manifest_get_ll(m, "version");
|
long long version = rhizome_manifest_get_ll(m, "version");
|
||||||
DEBUGF("Stop cramming %s advertisements: not enough space for %s*:v%lld (%d bytes, size limit=%d, used=%d)",
|
DEBUGF("Stop cramming %s advertisements: not enough space for %s*:v%lld (%d bytes, size limit=%d, used=%d)",
|
||||||
pass?"BARs":"manifests",
|
pass?"BARs":"manifests",
|
||||||
overlay_render_sid_prefix(m->cryptoSignPublic,8),
|
alloca_tohex(m->cryptoSignPublic, 8),
|
||||||
version,
|
version,
|
||||||
blob_bytes,e->sizeLimit,e->length);
|
blob_bytes,e->sizeLimit,e->length);
|
||||||
rhizome_manifest_free(m);
|
rhizome_manifest_free(m);
|
||||||
@ -277,7 +277,7 @@ int overlay_rhizome_add_advertisements(int interface_number,overlay_buffer *e)
|
|||||||
(m, (char *)&e->bytes[e->length+overhead], blob_bytes);
|
(m, (char *)&e->bytes[e->length+overhead], blob_bytes);
|
||||||
long long version = rhizome_manifest_get_ll(m, "version");
|
long long version = rhizome_manifest_get_ll(m, "version");
|
||||||
WHYF("Advertising manifest %s* version %lld",
|
WHYF("Advertising manifest %s* version %lld",
|
||||||
overlay_render_sid_prefix(m->cryptoSignPublic,8),
|
alloca_tohex(m->cryptoSignPublic, 8),
|
||||||
version);
|
version);
|
||||||
rhizome_manifest_free(m);
|
rhizome_manifest_free(m);
|
||||||
}
|
}
|
||||||
|
1
serval.h
1
serval.h
@ -1343,7 +1343,6 @@ int overlay_mdp_dispatch(overlay_mdp_frame *mdp,int userGeneratedFrameP,
|
|||||||
int ob_bcopy(overlay_buffer *b,int from, int to, int len);
|
int ob_bcopy(overlay_buffer *b,int from, int to, int len);
|
||||||
int ob_setbyte(overlay_buffer *b,int ofs,unsigned char value);
|
int ob_setbyte(overlay_buffer *b,int ofs,unsigned char value);
|
||||||
|
|
||||||
char *overlay_render_sid_prefix(const unsigned char *sid,int l);
|
|
||||||
int dump_payload(overlay_frame *p,char *message);
|
int dump_payload(overlay_frame *p,char *message);
|
||||||
|
|
||||||
int urandombytes(unsigned char *x,unsigned long long xlen);
|
int urandombytes(unsigned char *x,unsigned long long xlen);
|
||||||
|
4
vomp.c
4
vomp.c
@ -1198,8 +1198,8 @@ int app_vomp_status(int argc, const char *const *argv, struct command_line_optio
|
|||||||
mdp2.vompevent.call_session_token);
|
mdp2.vompevent.call_session_token);
|
||||||
else {
|
else {
|
||||||
fprintf(stderr,"%s* -> %s* (%s -> %s)",
|
fprintf(stderr,"%s* -> %s* (%s -> %s)",
|
||||||
overlay_render_sid_prefix(mdp2.vompevent.local_sid,6),
|
alloca_tohex(mdp2.vompevent.local_sid, 6),
|
||||||
overlay_render_sid_prefix(mdp2.vompevent.remote_sid,6),
|
alloca_tohex(mdp2.vompevent.remote_sid, 6),
|
||||||
strlen(mdp2.vompevent.local_did)
|
strlen(mdp2.vompevent.local_did)
|
||||||
?mdp2.vompevent.local_did:"<no local number>",
|
?mdp2.vompevent.local_did:"<no local number>",
|
||||||
strlen(mdp2.vompevent.remote_did)
|
strlen(mdp2.vompevent.remote_did)
|
||||||
|
Loading…
Reference in New Issue
Block a user