mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-01-29 15:43:56 +00:00
Reduce the potential for packet storms
This commit is contained in:
parent
dc8a453b7f
commit
0538e95be8
@ -57,6 +57,15 @@ int is_xstring(const char *text, int len)
|
||||
return _is_xstring(text, len);
|
||||
}
|
||||
|
||||
/* Does this whole buffer contain the same value? */
|
||||
int is_all_matching(unsigned char *ptr, int len, int value){
|
||||
int i;
|
||||
for (i=0;i<len;i++)
|
||||
if (ptr[i]!=value)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
char *tohex(char *dstHex, const unsigned char *srcBinary, size_t bytes)
|
||||
{
|
||||
char *p;
|
||||
|
@ -1074,8 +1074,11 @@ overlay_stuff_packet(struct outgoing_packet *packet, overlay_txqueue *queue, tim
|
||||
|
||||
case REACHABLE_BROADCAST:
|
||||
if (!frame->sendBroadcast){
|
||||
if (frame->ttl>2)
|
||||
frame->ttl=2;
|
||||
frame->sendBroadcast=1;
|
||||
overlay_broadcast_generate_address(&frame->broadcast_id);
|
||||
if (is_all_matching(frame->broadcast_id.id, BROADCAST_LEN, 0))
|
||||
overlay_broadcast_generate_address(&frame->broadcast_id);
|
||||
int i;
|
||||
for(i=0;i<OVERLAY_MAX_INTERFACES;i++)
|
||||
frame->broadcast_sent_via[i]=0;
|
||||
|
@ -37,22 +37,10 @@ struct sched_ent mdp_named={
|
||||
};
|
||||
|
||||
// is the SID entirely 0xFF?
|
||||
static int is_broadcast(const unsigned char *sid){
|
||||
int i;
|
||||
for (i=0;i<SID_SIZE;i++)
|
||||
if (sid[i]!=0xFF)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
#define is_broadcast(SID) is_all_matching(SID, SID_SIZE, 0xFF)
|
||||
|
||||
// is the SID entirely 0x00?
|
||||
static int is_sid_any(unsigned char *sid){
|
||||
int i;
|
||||
for (i=0;i<SID_SIZE;i++)
|
||||
if (sid[i])
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
#define is_sid_any(SID) is_all_matching(SID, SID_SIZE, 0)
|
||||
|
||||
int overlay_mdp_setup_sockets()
|
||||
{
|
||||
@ -431,8 +419,8 @@ int overlay_saw_mdp_frame(overlay_mdp_frame *mdp, time_ms_t now)
|
||||
more prudent path.
|
||||
*/
|
||||
|
||||
if (0)
|
||||
WHYF("Received packet with listener (MDP ports: src=%s*:%d, dst=%d)",
|
||||
if (debug & DEBUG_MDPREQUESTS)
|
||||
DEBUGF("Received packet with listener (MDP ports: src=%s*:%d, dst=%d)",
|
||||
alloca_tohex(mdp->out.src.sid, 7),
|
||||
mdp->out.src.port,mdp->out.dst.port);
|
||||
|
||||
@ -499,6 +487,9 @@ int overlay_saw_mdp_frame(overlay_mdp_frame *mdp, time_ms_t now)
|
||||
bcopy(&mdp->out.payload[0],&did[0],pll);
|
||||
did[pll]=0;
|
||||
|
||||
if (debug & DEBUG_MDPREQUESTS)
|
||||
DEBUG("MDP_PORT_DNALOOKUP");
|
||||
|
||||
int results=0;
|
||||
while(keyring_find_did(keyring,&cn,&in,&kp,did))
|
||||
{
|
||||
|
2
serval.h
2
serval.h
@ -456,6 +456,8 @@ int fromhexstr(unsigned char *dstBinary, const char *srcHex, size_t bytes);
|
||||
int hexvalue(char c);
|
||||
char *str_toupper_inplace(char *s);
|
||||
|
||||
int is_all_matching(unsigned char *ptr, int len, int value);
|
||||
|
||||
int str_is_subscriber_id(const char *sid);
|
||||
int strn_is_subscriber_id(const char *sid, size_t *lenp);
|
||||
int str_is_did(const char *did);
|
||||
|
Loading…
x
Reference in New Issue
Block a user