Commit d924e8b0 authored by Alessandro Rubini's avatar Alessandro Rubini

arch-gnu-linux: network functions now dump if level is 2

If debug level for "frames" is 2 or more, net_ops->send and
net_ops->recv now dump the data to stdout. The format is the same
of tools/ptpdump, with "send:" and "recv:" in front. This is an example:

  send: TIME: (1363277414 - 0x5141f666) 17:10:14.748281
  send: VERSION: 2 (type 11, len 64, domain 0)
  send: FLAGS: 0x0002 (correction 0x00000000)
  send: PORT: 00-22-15-ff-fe-d7-c0-ef-00-01
  send: REST: seq 9, ctrl 5, log-interval 1
  send: MESSAGE: (G) ANNOUNCE
  send: MSG-ANNOUNCE: stamp 0.000000000
  send: MSG-ANNOUNCE: grandmaster-quality f8-fe-60f0
  send: MSG-ANNOUNCE: grandmaster-prio 248 248
  send: MSG-ANNOUNCE: grandmaster-id 00-22-15-ff-fe-d7-c0-ef
  send: DUMP: payload (size 64)
  send: DUMP: 8b 02 00 40  00 00 02 00  00 00 00 00  00 00 00 00
  send: DUMP: 00 00 00 00  00 22 15 ff  fe d7 c0 ef  00 01 00 09
  send: DUMP: 05 01 00 00  00 00 00 00  00 00 00 00  00 00 11 f8
  send: DUMP: f8 fe f0 60  f8 00 22 15  ff fe d7 c0  ef 00 00 a0
  diag-frames-1-eth0: SENT 64 bytes at 1363277414.748281517 (announce)

And this is the same frame in the other host:

  recv: TIME: (1363277414 - 0x5141f666) 17:10:14.691032
  recv: VERSION: 2 (type 11, len 64, domain 0)
  recv: FLAGS: 0x0002 (correction 0x00000000)
  recv: PORT: 00-22-15-ff-fe-d7-c0-ef-00-01
  recv: REST: seq 9, ctrl 5, log-interval 1
  recv: MESSAGE: (G) ANNOUNCE
  recv: MSG-ANNOUNCE: stamp 0.000000000
  recv: MSG-ANNOUNCE: grandmaster-quality f8-fe-60f0
  recv: MSG-ANNOUNCE: grandmaster-prio 248 248
  recv: MSG-ANNOUNCE: grandmaster-id 00-22-15-ff-fe-d7-c0-ef
  recv: DUMP: payload (size 64)
  recv: DUMP: 8b 02 00 40  00 00 02 00  00 00 00 00  00 00 00 00
  recv: DUMP: 00 00 00 00  00 22 15 ff  fe d7 c0 ef  00 01 00 09
  recv: DUMP: 05 01 00 00  00 00 00 00  00 00 00 00  00 00 11 f8
  recv: DUMP: f8 fe f0 60  f8 00 22 15  ff fe d7 c0  ef 00 00 a0
  diag-frames-1-eth0: RECV 64 bytes at 1363277414.691032726 (type b)

This is what I got for the same frame in a ptpdump running in the
master.

  TIME: (1363277414 - 0x5141f666) 17:10:14.748376
  ETH: 0800 (00:22:15:d7:c0:ef -> 01:00:5e:00:01:81)
  IP: 17 (192.168.16.1 -> 224.0.1.129) len 92
  UDP: (320 -> 320) len 72
  VERSION: 2 (type 11, len 64, domain 0)
  FLAGS: 0x0002 (correction 0x00000000)
  PORT: 00-22-15-ff-fe-d7-c0-ef-00-01
  REST: seq 9, ctrl 5, log-interval 1
  MESSAGE: (G) ANNOUNCE
  MSG-ANNOUNCE: stamp 0.000000000
  MSG-ANNOUNCE: grandmaster-quality f8-fe-60f0
  MSG-ANNOUNCE: grandmaster-prio 248 248
  MSG-ANNOUNCE: grandmaster-id 00-22-15-ff-fe-d7-c0-ef
  DUMP: payload (size 64)
  DUMP: 8b 02 00 40  00 00 02 00  00 00 00 00  00 00 00 00
  DUMP: 00 00 00 00  00 22 15 ff  fe d7 c0 ef  00 01 00 09
  DUMP: 05 01 00 00  00 00 00 00  00 00 00 00  00 00 11 f8
  DUMP: f8 fe f0 60  f8 00 22 15  ff fe d7 c0  ef 00 00 a0
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 64946111
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
# All files are under A (short for ARCH): I'm lazy # All files are under A (short for ARCH): I'm lazy
A := arch-$(ARCH) A := arch-$(ARCH)
CFLAGS += -DCONFIG_PPSI_RUNTIME_VERBOSITY CFLAGS += -DCONFIG_PPSI_RUNTIME_VERBOSITY -Itools
LIBARCH := $A/libarch.a LIBARCH := $A/libarch.a
...@@ -15,6 +15,7 @@ OBJ-libarch := $A/posix-startup.o \ ...@@ -15,6 +15,7 @@ OBJ-libarch := $A/posix-startup.o \
$A/posix-time.o \ $A/posix-time.o \
lib/cmdline.o \ lib/cmdline.o \
lib/libc-functions.o \ lib/libc-functions.o \
lib/dump-funcs.o \
lib/div64.o lib/div64.o
$(LIBARCH): $(OBJ-libarch) $(LIBARCH): $(OBJ-libarch)
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include <arpa/inet.h> #include <arpa/inet.h>
#include <ppsi/ppsi.h> #include <ppsi/ppsi.h>
#include "ptpdump.h"
#include "posix.h" #include "posix.h"
/* posix_recv_msg uses recvmsg for timestamp query */ /* posix_recv_msg uses recvmsg for timestamp query */
...@@ -93,11 +94,15 @@ static int posix_net_recv(struct pp_instance *ppi, void *pkt, int len, ...@@ -93,11 +94,15 @@ static int posix_net_recv(struct pp_instance *ppi, void *pkt, int len,
TimeInternal *t) TimeInternal *t)
{ {
struct pp_channel *ch1, *ch2; struct pp_channel *ch1, *ch2;
int ret;
if (OPTS(ppi)->ethernet_mode) { if (OPTS(ppi)->ethernet_mode) {
int fd = NP(ppi)->ch[PP_NP_GEN].fd; int fd = NP(ppi)->ch[PP_NP_GEN].fd;
return posix_recv_msg(ppi, fd, pkt, len, t); ret = posix_recv_msg(ppi, fd, pkt, len, t);
if (ret > 0 && pp_diag_allow(ppi, frames, 2))
dump_1588pkt("recv: ", pkt, ret, t);
return ret;
} }
/* else: UDP, we can return one frame only, so swap priority */ /* else: UDP, we can return one frame only, so swap priority */
...@@ -111,13 +116,15 @@ static int posix_net_recv(struct pp_instance *ppi, void *pkt, int len, ...@@ -111,13 +116,15 @@ static int posix_net_recv(struct pp_instance *ppi, void *pkt, int len,
POSIX_ARCH(ppi)->rcv_switch = !POSIX_ARCH(ppi)->rcv_switch; POSIX_ARCH(ppi)->rcv_switch = !POSIX_ARCH(ppi)->rcv_switch;
ret = -1;
if (ch1->pkt_present) if (ch1->pkt_present)
return posix_recv_msg(ppi, ch1->fd, pkt, len, t); ret = posix_recv_msg(ppi, ch1->fd, pkt, len, t);
else if (ch2->pkt_present)
if (ch2->pkt_present) ret = posix_recv_msg(ppi, ch2->fd, pkt, len, t);
return posix_recv_msg(ppi, ch2->fd, pkt, len, t);
return -1; if (ret > 0 && pp_diag_allow(ppi, frames, 2))
dump_payloadpkt("recv: ", pkt, ret, t);
return ret;
} }
static int posix_net_send(struct pp_instance *ppi, void *pkt, int len, static int posix_net_send(struct pp_instance *ppi, void *pkt, int len,
...@@ -125,6 +132,7 @@ static int posix_net_send(struct pp_instance *ppi, void *pkt, int len, ...@@ -125,6 +132,7 @@ static int posix_net_send(struct pp_instance *ppi, void *pkt, int len,
{ {
struct sockaddr_in addr; struct sockaddr_in addr;
struct ethhdr *hdr = pkt; struct ethhdr *hdr = pkt;
int ret;
if (OPTS(ppi)->ethernet_mode) { if (OPTS(ppi)->ethernet_mode) {
hdr->h_proto = htons(ETH_P_1588); hdr->h_proto = htons(ETH_P_1588);
...@@ -136,7 +144,10 @@ static int posix_net_send(struct pp_instance *ppi, void *pkt, int len, ...@@ -136,7 +144,10 @@ static int posix_net_send(struct pp_instance *ppi, void *pkt, int len,
if (t) if (t)
ppi->t_ops->get(ppi, t); ppi->t_ops->get(ppi, t);
return send(NP(ppi)->ch[PP_NP_GEN].fd, hdr, len, 0); ret = send(NP(ppi)->ch[PP_NP_GEN].fd, hdr, len, 0);
if (pp_diag_allow(ppi, frames, 2))
dump_1588pkt("send: ", pkt, len, t);
return ret;
} }
/* else: UDP */ /* else: UDP */
...@@ -148,10 +159,11 @@ static int posix_net_send(struct pp_instance *ppi, void *pkt, int len, ...@@ -148,10 +159,11 @@ static int posix_net_send(struct pp_instance *ppi, void *pkt, int len,
if (t) if (t)
ppi->t_ops->get(ppi, t); ppi->t_ops->get(ppi, t);
return sendto(NP(ppi)->ch[chtype].fd, pkt, len, 0, ret = sendto(NP(ppi)->ch[chtype].fd, pkt, len, 0,
(struct sockaddr *)&addr, sizeof(struct sockaddr_in)); (struct sockaddr *)&addr, sizeof(struct sockaddr_in));
if (pp_diag_allow(ppi, frames, 2))
return -1; dump_payloadpkt("send: ", pkt, len, t);
return ret;
} }
/* To open a channel we must bind to an interface and so on */ /* To open a channel we must bind to an interface and so on */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment