mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-01-30 08:03:49 +00:00
Simplify packet debug logging
This commit is contained in:
parent
2e6d3878e8
commit
f7bffbfabe
1
log.h
1
log.h
@ -107,7 +107,6 @@ void logConfigChanged();
|
|||||||
int logDump(int level, struct __sourceloc whence, char *name, const unsigned char *addr, size_t len);
|
int logDump(int level, struct __sourceloc whence, char *name, const unsigned char *addr, size_t len);
|
||||||
ssize_t get_self_executable_path(char *buf, size_t len);
|
ssize_t get_self_executable_path(char *buf, size_t len);
|
||||||
int log_backtrace(int level, struct __sourceloc whence);
|
int log_backtrace(int level, struct __sourceloc whence);
|
||||||
void logServalPacket(int level, struct __sourceloc __whence, const char *message, const unsigned char *packet, size_t len);
|
|
||||||
|
|
||||||
struct strbuf;
|
struct strbuf;
|
||||||
|
|
||||||
|
@ -51,8 +51,6 @@ static void overlay_interface_poll(struct sched_ent *alarm);
|
|||||||
static int re_init_socket(int interface_index);
|
static int re_init_socket(int interface_index);
|
||||||
static void write_stream_buffer(overlay_interface *interface);
|
static void write_stream_buffer(overlay_interface *interface);
|
||||||
|
|
||||||
#define DEBUG_packet_visualise(M,P,N) logServalPacket(LOG_LEVEL_DEBUG, __WHENCE__, (M), (P), (N))
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
overlay_interface_close(overlay_interface *interface){
|
overlay_interface_close(overlay_interface *interface){
|
||||||
link_interface_down(interface);
|
link_interface_down(interface);
|
||||||
@ -233,20 +231,7 @@ overlay_interface_read_any(struct sched_ent *alarm){
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We have a frame from this interface */
|
packetOkOverlay(interface, packet, plen, recvttl, &src_addr, addrlen);
|
||||||
if (config.debug.packetrx)
|
|
||||||
DEBUG_packet_visualise("Read from real interface", packet,plen);
|
|
||||||
if (config.debug.overlayinterfaces)
|
|
||||||
DEBUGF("Received %d bytes from %s on interface %s (ANY)",plen,
|
|
||||||
inet_ntoa(src),
|
|
||||||
interface->name);
|
|
||||||
|
|
||||||
if (packetOkOverlay(interface, packet, plen, recvttl, &src_addr, addrlen)<0) {
|
|
||||||
if (config.debug.rejecteddata) {
|
|
||||||
WHYF("Malformed packet (length = %d)",plen);
|
|
||||||
dump("the malformed packet",packet,plen);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (alarm->poll.revents & (POLLHUP | POLLERR)) {
|
if (alarm->poll.revents & (POLLHUP | POLLERR)) {
|
||||||
INFO("Closing broadcast socket due to error");
|
INFO("Closing broadcast socket due to error");
|
||||||
@ -552,21 +537,7 @@ static void interface_read_dgram(struct overlay_interface *interface){
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We have a frame from this interface */
|
packetOkOverlay(interface, packet, plen, recvttl, &src_addr, addrlen);
|
||||||
if (config.debug.packetrx)
|
|
||||||
DEBUG_packet_visualise("Read from real interface", packet,plen);
|
|
||||||
if (config.debug.overlayinterfaces) {
|
|
||||||
struct in_addr src = ((struct sockaddr_in *)&src_addr)->sin_addr; // avoid strict-alias warning on Solaris (gcc 4.4)
|
|
||||||
DEBUGF("Received %d bytes from %s on interface %s",plen,
|
|
||||||
inet_ntoa(src),
|
|
||||||
interface->name);
|
|
||||||
}
|
|
||||||
if (packetOkOverlay(interface, packet, plen, recvttl, &src_addr, addrlen)<0) {
|
|
||||||
if (config.debug.rejecteddata) {
|
|
||||||
WHYF("Malformed packet (length = %d)",plen);
|
|
||||||
dump("the malformed packet",packet,plen);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct file_packet{
|
struct file_packet{
|
||||||
@ -644,23 +615,13 @@ static void interface_read_file(struct overlay_interface *interface)
|
|||||||
|
|
||||||
if (nread == sizeof packet) {
|
if (nread == sizeof packet) {
|
||||||
interface->recv_offset += nread;
|
interface->recv_offset += nread;
|
||||||
|
|
||||||
if (config.debug.packetrx)
|
|
||||||
DEBUG_packet_visualise("Read from dummy interface", packet.payload, packet.payload_length);
|
|
||||||
|
|
||||||
if (should_drop(interface, packet.dst_addr) || (packet.pid == getpid() && !interface->local_echo)){
|
if (should_drop(interface, packet.dst_addr) || (packet.pid == getpid() && !interface->local_echo)){
|
||||||
if (config.debug.packetrx)
|
if (config.debug.packetrx)
|
||||||
DEBUGF("Ignoring packet from %d, addressed to %s:%d", packet.pid,
|
DEBUGF("Ignoring packet from %d, addressed to %s:%d", packet.pid,
|
||||||
inet_ntoa(packet.dst_addr.sin_addr), ntohs(packet.dst_addr.sin_port));
|
inet_ntoa(packet.dst_addr.sin_addr), ntohs(packet.dst_addr.sin_port));
|
||||||
}else{
|
}else{
|
||||||
if (packetOkOverlay(interface, packet.payload, packet.payload_length, -1,
|
packetOkOverlay(interface, packet.payload, packet.payload_length, -1,
|
||||||
(struct sockaddr*)&packet.src_addr, sizeof(packet.src_addr))<0) {
|
(struct sockaddr*)&packet.src_addr, sizeof(packet.src_addr));
|
||||||
if (config.debug.rejecteddata) {
|
|
||||||
WARN("Unsupported packet from dummy interface");
|
|
||||||
WHYF("Malformed packet (length = %d)",packet.payload_length);
|
|
||||||
dump("the malformed packet",packet.payload,packet.payload_length);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -694,13 +655,10 @@ static void interface_read_stream(struct overlay_interface *interface){
|
|||||||
OUT();
|
OUT();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (config.debug.packetradio)
|
||||||
|
dump("read bytes", buffer, nread);
|
||||||
struct slip_decode_state *state=&interface->slip_decode_state;
|
struct slip_decode_state *state=&interface->slip_decode_state;
|
||||||
|
|
||||||
if (config.debug.slip) {
|
|
||||||
dump("RX bytes", buffer, nread);
|
|
||||||
}
|
|
||||||
|
|
||||||
state->src=buffer;
|
state->src=buffer;
|
||||||
state->src_size=nread;
|
state->src_size=nread;
|
||||||
state->src_offset=0;
|
state->src_offset=0;
|
||||||
@ -708,12 +666,7 @@ static void interface_read_stream(struct overlay_interface *interface){
|
|||||||
while (state->src_offset < state->src_size) {
|
while (state->src_offset < state->src_size) {
|
||||||
int ret = slip_decode(state);
|
int ret = slip_decode(state);
|
||||||
if (ret==1){
|
if (ret==1){
|
||||||
if (packetOkOverlay(interface, state->dst, state->packet_length, -1, NULL, -1)<0) {
|
packetOkOverlay(interface, state->dst, state->packet_length, -1, NULL, -1);
|
||||||
if (config.debug.rejecteddata) {
|
|
||||||
WHYF("Malformed packet (length = %d)",state->packet_length);
|
|
||||||
dump("the malformed packet",state->dst,state->packet_length);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
state->dst_offset=0;
|
state->dst_offset=0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -378,6 +378,17 @@ int packetOkOverlay(struct overlay_interface *interface,unsigned char *packet, s
|
|||||||
the source having received the frame from elsewhere.
|
the source having received the frame from elsewhere.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
if (config.debug.packetrx || interface->debug) {
|
||||||
|
DEBUGF("Received on %s, len %d", interface->name, (int)len);
|
||||||
|
DEBUG_packet_visualise("Received packet",packet,len);
|
||||||
|
if (config.debug.interactive_io) {
|
||||||
|
fprintf(stderr,"Press ENTER to continue..."); fflush(stderr);
|
||||||
|
char buffer[80];
|
||||||
|
if (!fgets(buffer,80,stdin))
|
||||||
|
FATAL_perror("calling fgets");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (recvaddr&&recvaddr->sa_family!=AF_INET)
|
if (recvaddr&&recvaddr->sa_family!=AF_INET)
|
||||||
RETURN(WHYF("Unexpected protocol family %d",recvaddr->sa_family));
|
RETURN(WHYF("Unexpected protocol family %d",recvaddr->sa_family));
|
||||||
|
|
||||||
@ -396,9 +407,6 @@ int packetOkOverlay(struct overlay_interface *interface,unsigned char *packet, s
|
|||||||
else
|
else
|
||||||
bzero(&f.recvaddr, sizeof f.recvaddr);
|
bzero(&f.recvaddr, sizeof f.recvaddr);
|
||||||
|
|
||||||
if (interface->debug)
|
|
||||||
DEBUGF("Received on %s, len %d: %s", interface->name, (int)len, alloca_tohex(packet, len>64?64:len));
|
|
||||||
|
|
||||||
int ret=parseEnvelopeHeader(&context, interface, (struct sockaddr_in *)recvaddr, b);
|
int ret=parseEnvelopeHeader(&context, interface, (struct sockaddr_in *)recvaddr, b);
|
||||||
if (ret){
|
if (ret){
|
||||||
ob_free(b);
|
ob_free(b);
|
||||||
|
2
serval.h
2
serval.h
@ -590,6 +590,8 @@ int overlay_saw_mdp_containing_frame(struct overlay_frame *f, time_ms_t now);
|
|||||||
|
|
||||||
int serval_packetvisualise(const char *message, const unsigned char *packet, size_t len);
|
int serval_packetvisualise(const char *message, const unsigned char *packet, size_t len);
|
||||||
int serval_packetvisualise_xpf(XPRINTF xpf, const char *message, const unsigned char *packet, size_t len);
|
int serval_packetvisualise_xpf(XPRINTF xpf, const char *message, const unsigned char *packet, size_t len);
|
||||||
|
void logServalPacket(int level, struct __sourceloc __whence, const char *message, const unsigned char *packet, size_t len);
|
||||||
|
#define DEBUG_packet_visualise(M,P,N) logServalPacket(LOG_LEVEL_DEBUG, __WHENCE__, (M), (P), (N))
|
||||||
|
|
||||||
int rhizome_fetching_get_fds(struct pollfd *fds,int *fdcount,int fdmax);
|
int rhizome_fetching_get_fds(struct pollfd *fds,int *fdcount,int fdmax);
|
||||||
int rhizome_opendb();
|
int rhizome_opendb();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user