Commit 217be676 authored by Alessandro Rubini's avatar Alessandro Rubini

ptpdump: identify vlan header, and deal with it

This requires some change to the include files, to be able to
build for all architectures.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 1bcae4bb
......@@ -41,3 +41,14 @@ struct udphdr {
uint16_t len;
uint16_t check;
};
#ifndef __PPSI_PPSI_H__
/* from ppsi.h -- never defined elsewhere */
struct pp_vlanhdr {
uint8_t h_dest[6];
uint8_t h_source[6];
uint16_t h_tpid;
uint16_t h_tci;
uint16_t h_proto;
};
#endif /* __PPSI_PPSI_H__ */
......@@ -9,7 +9,8 @@ STRIP = $(CROSS_COMPILE)strip
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump
CFLAGS = -Wall -ggdb -I../include
include ../.config
CFLAGS = -Wall -ggdb -I../include -I../arch-$(CONFIG_ARCH)/include
PROGS = ptpdump adjtime jmptime chktime adjrate
LDFLAGS += -lrt
......
......@@ -51,15 +51,25 @@ static void dump_time(char *prefix, struct TimeInternal *ti)
}
#endif
static void dump_eth(char *prefix, struct ethhdr *eth)
/* Returns the header size, used by the caller to adjust the next pointer */
static int dump_eth(char *prefix, struct ethhdr *eth)
{
unsigned char *d = eth->h_dest;
unsigned char *s = eth->h_source;
int proto = ntohs(eth->h_proto);
struct pp_vlanhdr *vhdr = (void *)eth;
int ret = sizeof(*eth);
if (proto == 0x8100) {
ret = sizeof(*vhdr);
proto = ntohs(vhdr->h_proto);
printf("%sVLAN %i\n", prefix, ntohs(vhdr->h_tci) & 0xfff);
}
printf("%sETH: %04x (%02x:%02x:%02x:%02x:%02x:%02x -> "
"%02x:%02x:%02x:%02x:%02x:%02x)\n", prefix, ntohs(eth->h_proto),
"%02x:%02x:%02x:%02x:%02x:%02x)\n", prefix, proto,
s[0], s[1], s[2], s[3], s[4], s[5],
d[0], d[1], d[2], d[3], d[4], d[5]);
return ret;
}
static void dump_ip(char *prefix, struct iphdr *ip)
......@@ -256,16 +266,22 @@ static void dump_payload(char *prefix, void *pl, int len)
int dump_udppkt(char *prefix, void *buf, int len, struct TimeInternal *ti)
{
struct ethhdr *eth = buf;
struct iphdr *ip = buf + ETH_HLEN;
struct udphdr *udp = (void *)(ip + 1);
void *payload = (void *)(udp + 1);
struct iphdr *ip;
struct udphdr *udp;
void *payload;
if (ti)
dump_time(prefix, ti);
dump_eth(prefix, eth);
ip = buf + dump_eth(prefix, eth);
dump_ip(prefix, ip);
udp = (void *)(ip + 1);
dump_udp(prefix, udp);
payload = (void *)(udp + 1);
dump_payload(prefix, payload, len - (payload - buf));
return 0;
}
......@@ -282,11 +298,12 @@ int dump_payloadpkt(char *prefix, void *buf, int len, struct TimeInternal *ti)
int dump_1588pkt(char *prefix, void *buf, int len, struct TimeInternal *ti)
{
struct ethhdr *eth = buf;
void *payload = (void *)(eth + 1);
void *payload;
if (ti)
dump_time(prefix, ti);
dump_eth(prefix, eth);
payload = buf + dump_eth(prefix, eth);
dump_payload(prefix, payload, len - (payload - buf));
return 0;
}
#ifndef __PTPDUMP_H__
#define __PTPDUMP_H__
#include <ppsi/ppsi.h>
#if __STDC_HOSTED__
#include <time.h>
#include <sys/time.h>
......@@ -8,7 +9,6 @@
#include <netinet/udp.h> /* struct udphdr */
#include <linux/if_ether.h> /* struct ethhdr */
#else
#include <ppsi/ppsi.h>
#include "../lib/network_types.h"
#define printf pp_printf
#endif
......
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