mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-02-06 11:09:13 +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);
|
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 *tohex(char *dstHex, const unsigned char *srcBinary, size_t bytes)
|
||||||
{
|
{
|
||||||
char *p;
|
char *p;
|
||||||
|
@ -1074,8 +1074,11 @@ overlay_stuff_packet(struct outgoing_packet *packet, overlay_txqueue *queue, tim
|
|||||||
|
|
||||||
case REACHABLE_BROADCAST:
|
case REACHABLE_BROADCAST:
|
||||||
if (!frame->sendBroadcast){
|
if (!frame->sendBroadcast){
|
||||||
|
if (frame->ttl>2)
|
||||||
|
frame->ttl=2;
|
||||||
frame->sendBroadcast=1;
|
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;
|
int i;
|
||||||
for(i=0;i<OVERLAY_MAX_INTERFACES;i++)
|
for(i=0;i<OVERLAY_MAX_INTERFACES;i++)
|
||||||
frame->broadcast_sent_via[i]=0;
|
frame->broadcast_sent_via[i]=0;
|
||||||
|
@ -37,22 +37,10 @@ struct sched_ent mdp_named={
|
|||||||
};
|
};
|
||||||
|
|
||||||
// is the SID entirely 0xFF?
|
// is the SID entirely 0xFF?
|
||||||
static int is_broadcast(const unsigned char *sid){
|
#define is_broadcast(SID) is_all_matching(SID, SID_SIZE, 0xFF)
|
||||||
int i;
|
|
||||||
for (i=0;i<SID_SIZE;i++)
|
|
||||||
if (sid[i]!=0xFF)
|
|
||||||
return 0;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// is the SID entirely 0x00?
|
// is the SID entirely 0x00?
|
||||||
static int is_sid_any(unsigned char *sid){
|
#define is_sid_any(SID) is_all_matching(SID, SID_SIZE, 0)
|
||||||
int i;
|
|
||||||
for (i=0;i<SID_SIZE;i++)
|
|
||||||
if (sid[i])
|
|
||||||
return 0;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int overlay_mdp_setup_sockets()
|
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.
|
more prudent path.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (0)
|
if (debug & DEBUG_MDPREQUESTS)
|
||||||
WHYF("Received packet with listener (MDP ports: src=%s*:%d, dst=%d)",
|
DEBUGF("Received packet with listener (MDP ports: src=%s*:%d, dst=%d)",
|
||||||
alloca_tohex(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);
|
||||||
|
|
||||||
@ -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);
|
bcopy(&mdp->out.payload[0],&did[0],pll);
|
||||||
did[pll]=0;
|
did[pll]=0;
|
||||||
|
|
||||||
|
if (debug & DEBUG_MDPREQUESTS)
|
||||||
|
DEBUG("MDP_PORT_DNALOOKUP");
|
||||||
|
|
||||||
int results=0;
|
int results=0;
|
||||||
while(keyring_find_did(keyring,&cn,&in,&kp,did))
|
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);
|
int hexvalue(char c);
|
||||||
char *str_toupper_inplace(char *s);
|
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 str_is_subscriber_id(const char *sid);
|
||||||
int strn_is_subscriber_id(const char *sid, size_t *lenp);
|
int strn_is_subscriber_id(const char *sid, size_t *lenp);
|
||||||
int str_is_did(const char *did);
|
int str_is_did(const char *did);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user