Improved packet tx and rx debugging and made it more logical.

This commit is contained in:
gardners 2012-04-14 06:38:11 +09:30
parent 2802a5c042
commit 283b29af6b
6 changed files with 37 additions and 32 deletions

View File

@ -53,10 +53,10 @@ int packetSendFollowup(struct in_addr destination,
r=sendto(sock,packet,packet_len,0,(struct sockaddr *)&peer_addr,sizeof(peer_addr));
if (r<packet_len) {
if (debug&DEBUG_PACKETXFER) fprintf(stderr,"Could not send to %s (r=%d, packet_len=%d)\n",inet_ntoa(destination),r,packet_len);
if (debug&DEBUG_PACKETTX) fprintf(stderr,"Could not send to %s (r=%d, packet_len=%d)\n",inet_ntoa(destination),r,packet_len);
perror("sendto(a)");
} else {
if (debug&DEBUG_PACKETXFER) fprintf(stderr,"Sent request to client %s\n",inet_ntoa(destination));
if (debug&DEBUG_PACKETTX) fprintf(stderr,"Sent request to client %s\n",inet_ntoa(destination));
}
return 0;
}
@ -94,11 +94,11 @@ int packetSendRequest(int method,unsigned char *packet,int packet_len,int batchP
else
r=sendto(sock,packet,packet_len,0,recvaddr,sizeof(struct sockaddr_in));
if (r<packet_len) {
if (debug&DEBUG_PACKETXFER) fprintf(stderr,"Could not send to client %s (packet=%p,len=%d,sock=%d)\n",
if (debug&DEBUG_PACKETTX) fprintf(stderr,"Could not send to client %s (packet=%p,len=%d,sock=%d)\n",
inet_ntoa(client_addr),packet,packet_len,sock);
perror("sendto(b)");
} else {
if (debug&DEBUG_PACKETXFER) fprintf(stderr,"Sent request to client %s\n",inet_ntoa(client_addr));
if (debug&DEBUG_PACKETTX) fprintf(stderr,"Sent request to client %s\n",inet_ntoa(client_addr));
}
return 0;
}
@ -401,7 +401,7 @@ int getReplyPackets(int method,int peer,int batchP,struct response_set *response
if (debug&DEBUG_DNARESPONSES) printf("Waiting for more packets, since called with policy %d\n",method);
}
} else {
if (debug&(DEBUG_PACKETXFER|DEBUG_DNARESPONSES)) setReason("Ignoring invalid packet");
if (debug&(DEBUG_PACKETRX|DEBUG_DNARESPONSES)) setReason("Ignoring invalid packet");
}
}
}
@ -549,7 +549,7 @@ int peerAddress(char *did,char *sid,int flags)
method=REQ_PARALLEL;
if (sid) method=REQ_FIRSTREPLY;
if (packetSendRequest(method,packet,packet_len,NONBATCH,transaction_id,NULL,&responses)) {
if (debug&DEBUG_PACKETXFER) fprintf(stderr,"peerAddress() failed because packetSendRequest() failed.\n");
if (debug&DEBUG_PACKETTX) fprintf(stderr,"peerAddress() failed because packetSendRequest() failed.\n");
return -1;
}
@ -631,7 +631,7 @@ int requestItem(char *did,char *sid,char *item,int instance,
method=REQ_PARALLEL;
if (sid) method=REQ_FIRSTREPLY;
if (packetSendRequest(method,packet,packet_len,(instance==-1)?BATCH:NONBATCH,transaction_id,NULL,&responses)) {
if (debug&DEBUG_PACKETXFER) fprintf(stderr,"requestItem() failed because packetSendRequest() failed.\n");
if (debug&DEBUG_PACKETTX) fprintf(stderr,"requestItem() failed because packetSendRequest() failed.\n");
return -1;
}

4
dna.c
View File

@ -474,8 +474,8 @@ int setVerbosity(char *optarg) {
long long old_debug=debug;
debug=strtoll(optarg,NULL,10);
if (strstr(optarg,"interfaces")) debug|=DEBUG_OVERLAYINTERFACES;
if (strstr(optarg,"packetxfer")) debug|=DEBUG_PACKETXFER;
if (strstr(optarg,"packettx")) debug|=DEBUG_PACKETTX;
if (strstr(optarg,"rx")) debug|=DEBUG_PACKETRX;
if (strstr(optarg,"tx")) debug|=DEBUG_PACKETTX;
if (strstr(optarg,"verbose")) debug|=DEBUG_VERBOSE;
if (strstr(optarg,"verbio")) debug|=DEBUG_VERBOSE_IO;
if (strstr(optarg,"peers")) debug|=DEBUG_PEERS;

View File

@ -201,12 +201,12 @@ int overlay_interface_init_socket(int interface,struct sockaddr_in src_addr,stru
/* XXX Is this right? Are we really setting the local side address?
I was in a plane when at the time, so couldn't Google it.
*/
if (debug&DEBUG_PACKETXFER) fprintf(stderr,"src_addr=%08x\n",(unsigned int)src_addr.sin_addr.s_addr);
if (debug&DEBUG_PACKETRX) fprintf(stderr,"src_addr=%08x\n",(unsigned int)src_addr.sin_addr.s_addr);
if(bind(I(fd),(struct sockaddr *)&src_addr,sizeof(src_addr))) {
perror("bind()");
return WHY("MP HLR server could not bind to requested UDP port (bind() failed)");
}
if (debug&(DEBUG_PACKETXFER|DEBUG_IO)) fprintf(stderr,"Bound to port 0x%04x\n",src_addr.sin_port);
if (debug&(DEBUG_PACKETRX|DEBUG_IO)) fprintf(stderr,"Bound to port 0x%04x\n",src_addr.sin_port);
int broadcastP=1;
if(setsockopt(I(fd), SOL_SOCKET, SO_BROADCAST, &broadcastP, sizeof(broadcastP)) < 0) {
@ -320,7 +320,7 @@ int overlay_rx_messages()
plen=2048-128;
plen=packet[110]+(packet[111]<<8);
if (plen>(2048-128)) plen=-1;
if (debug&DEBUG_PACKETXFER)
if (debug&DEBUG_PACKETRX)
serval_packetvisualise(stderr,
"Read from dummy interface",
&packet[128],plen);
@ -347,7 +347,7 @@ int overlay_rx_messages()
c[i]=0; count--;
} else {
/* We have a frame from this interface */
if (debug&DEBUG_PACKETXFER)
if (debug&DEBUG_PACKETRX)
serval_packetvisualise(stderr,"Read from real interface",
packet,plen);
if (debug&DEBUG_OVERLAYINTERFACES)fprintf(stderr,"Received %d bytes on interface #%d (%s)\n",plen,i,overlay_interfaces[i].name);
@ -401,7 +401,7 @@ int overlay_broadcast_ensemble(int interface_number,
else {
s = overlay_interfaces[interface_number].broadcast_address;
s.sin_family = AF_INET;
if (debug&DEBUG_PACKETXFER) fprintf(stderr,"Port=%d\n",overlay_interfaces[interface_number].port);
if (debug&DEBUG_PACKETTX) fprintf(stderr,"Port=%d\n",overlay_interfaces[interface_number].port);
s.sin_port = htons( overlay_interfaces[interface_number].port );
}
@ -464,7 +464,7 @@ int overlay_broadcast_ensemble(int interface_number,
interface they came in. */
int overlay_sendto(struct sockaddr_in *recipientaddr,unsigned char *bytes,int len)
{
if (debug&DEBUG_PACKETXFER) fprintf(stderr,"Sending %d bytes.\n",len);
if (debug&DEBUG_PACKETTX) fprintf(stderr,"Sending %d bytes.\n",len);
if(overlay_broadcast_ensemble(overlay_last_interface_number,recipientaddr,bytes,len))
return -1;
else
@ -637,11 +637,14 @@ int overlay_stuff_packet_from_queue(int i,overlay_buffer *e,int q,long long now,
WHY("bummer, I couldn't find an open route to that node");
}
} else if (!(*p)->broadcast_sent_via[i])
/* Broadcast frames are easy to work out if they go via this interface,
just make sure that they haven't been previously sent via this
interface. We then have some magic that only dequeues broadcast packets
once they have been sent via all open interfaces (or gone stale) */
dontSend=0;
{
/* Broadcast frames are easy to work out if they go via this interface,
just make sure that they haven't been previously sent via this
interface. We then have some magic that only dequeues broadcast packets
once they have been sent via all open interfaces (or gone stale) */
dontSend=0;
(*p)->broadcast_sent_via[i]=1;
}
if (dontSend==0) {
/* Try sending by this queue */
@ -776,7 +779,9 @@ int overlay_tick_interface(int i, long long now)
for(i=0;i<OVERLAY_MAX_INTERFACES;i++)
{
if (overlay_interfaces[i].observed>0)
if (!(*p)->broadcast_sent_via[i]) { workLeft=1; break; }
if (!(*p)->broadcast_sent_via[i])
{ fprintf(stderr,"Frame still needs to be send on interface #%d\n",i);
workLeft=1; break; }
}
if (!workLeft) {
WHY("Leaving broadcast payload on the queue for other interfaces");

View File

@ -201,17 +201,17 @@ int sendToPeers(unsigned char *packet,int packet_len,int method,int peerId,struc
{
peer_addr.sin_addr=peers[i];
if (debug&(DEBUG_PACKETXFER|DEBUG_PEERS)) fprintf(stderr,"Sending packet to peer #%d\n",i);
if (debug&(DEBUG_PACKETTX|DEBUG_PEERS)) fprintf(stderr,"Sending packet to peer #%d\n",i);
ret=sendto(sock,packet,packet_len,0,(struct sockaddr *)&peer_addr,sizeof(peer_addr));
if (ret<packet_len)
{
/* XXX something bad happened */
if (debug&(DEBUG_PACKETXFER|DEBUG_PEERS)) fprintf(stderr,"Could not send to peer %s\n",inet_ntoa(peer_addr.sin_addr));
if (debug&(DEBUG_PACKETTX|DEBUG_PEERS)) fprintf(stderr,"Could not send to peer %s\n",inet_ntoa(peer_addr.sin_addr));
}
else
{
if (debug&(DEBUG_PACKETXFER|DEBUG_PEERS)) fprintf(stderr,"Sent request to peer %s\n",inet_ntoa(peer_addr.sin_addr));
if (debug&(DEBUG_PACKETTX|DEBUG_PEERS)) fprintf(stderr,"Sent request to peer %s\n",inet_ntoa(peer_addr.sin_addr));
n++;
/* If sending to only one peer, return now */
if (method==i) break;

View File

@ -983,7 +983,7 @@ int overlay_saw_mdp_containing_frame(int interface,overlay_frame *f,long long no
#define DEBUG_OVERLAYINTERFACES 2
#define DEBUG_PACKETXFER 1
#define DEBUG_PACKETRX 1
#define DEBUG_VERBOSE 4
#define DEBUG_VERBOSE_IO 8
#define DEBUG_PEERS 16

View File

@ -61,7 +61,7 @@ int recvwithttl(int sock,unsigned char *buffer,int bufferlen,int *ttl,
int len = recvmsg(sock,&msg,0);
if (debug&DEBUG_PACKETXFER) {
if (0&&debug&DEBUG_PACKETRX) {
fprintf(stderr,"recvmsg returned %d bytes (flags=%d,msg_controllen=%d)\n",
len,msg.msg_flags,msg.msg_controllen);
dump("received data",buffer,len);
@ -77,16 +77,16 @@ int recvwithttl(int sock,unsigned char *buffer,int bufferlen,int *ttl,
if ((cmsg->cmsg_level == IPPROTO_IP) &&
((cmsg->cmsg_type == IP_RECVTTL) ||(cmsg->cmsg_type == IP_TTL))
&&(cmsg->cmsg_len) ){
if (debug&DEBUG_PACKETXFER)
if (debug&DEBUG_PACKETRX)
fprintf(stderr," TTL (%p) data location resolves to %p\n",
ttl,CMSG_DATA(cmsg));
if (CMSG_DATA(cmsg)) {
*ttl = *(unsigned char *) CMSG_DATA(cmsg);
if (debug&DEBUG_PACKETXFER)
if (debug&DEBUG_PACKETRX)
fprintf(stderr," TTL of packet is %d\n",*ttl);
}
} else {
if (debug&DEBUG_PACKETXFER)
if (debug&DEBUG_PACKETRX)
fprintf(stderr,"I didn't expect to see level=%02x, type=%02x\n",
cmsg->cmsg_level,cmsg->cmsg_type);
}
@ -571,8 +571,8 @@ int simpleServerMode()
client_addr=((struct sockaddr_in*)&recvaddr)->sin_addr;
if (debug&DEBUG_DNAREQUESTS) fprintf(stderr,"Received packet from %s:%d (len=%d).\n",inet_ntoa(client_addr),client_port,len);
if (debug&DEBUG_PACKETXFER) dump("recvaddr",(unsigned char *)&recvaddr,recvaddrlen);
if (debug&DEBUG_PACKETXFER) dump("packet",(unsigned char *)buffer,len);
if (debug&DEBUG_PACKETRX) dump("recvaddr",(unsigned char *)&recvaddr,recvaddrlen);
if (debug&DEBUG_PACKETRX) dump("packet",(unsigned char *)buffer,len);
if (dropPacketP(len)) {
if (debug&DEBUG_SIMULATION) fprintf(stderr,"Simulation mode: Dropped packet due to simulated link parameters.\n");
continue;
@ -581,7 +581,7 @@ int simpleServerMode()
if (packetOk(-1,buffer,len,NULL,ttl,&recvaddr,recvaddrlen,1)) {
if (debug&DEBUG_PACKETFORMATS) setReason("Ignoring invalid packet");
}
if (debug&DEBUG_PACKETXFER) fprintf(stderr,"Finished processing packet, waiting for next one.\n");
if (debug&DEBUG_PACKETRX) fprintf(stderr,"Finished processing packet, waiting for next one.\n");
}
}
return 0;