Commit 9a713ebc authored by Leonardo Lai's avatar Leonardo Lai

dump the content of non-ip packets for debug purposes

parent cd3adee2
......@@ -40,6 +40,7 @@ UDPDK_C= ${CC} -c $(DPDK_CFLAGS) $(UDPDK_CFLAGS) ${CFLAGS} ${WERROR} $<
UDPDK_CORE_SRCS+= \
udpdk_args.c \
udpdk_dump.c \
udpdk_globals.c \
udpdk_init.c \
udpdk_bind_table.c \
......
......@@ -8,3 +8,4 @@ udpdk_bind
udpdk_sendto
udpdk_recvfrom
udpdk_close
udpdk_dump_payload
//
// Created by leoll2 on 11/19/20.
// Copyright (c) 2020 Leonardo Lai. All rights reserved.
//
// The following code derives in part from netmap pkt-gen.c
//
#include <ctype.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <rte_mbuf.h>
#include "udpdk_dump.h"
/* Print the content of the packet in hex and ASCII */
void udpdk_dump_payload(const char *payload, int len)
{
char buf[128];
int i, j, i0;
const unsigned char *p = (const unsigned char *)payload;
printf("Dumping payload [len = %d]:\n", len);
/* hexdump routine */
for (i = 0; i < len; ) {
memset(buf, ' ', sizeof(buf));
sprintf(buf, "%5d: ", i);
i0 = i;
for (j = 0; j < 16 && i < len; i++, j++)
sprintf(buf + 7 + j*3, "%02x ", (uint8_t)(p[i]));
i = i0;
for (j = 0; j < 16 && i < len; i++, j++)
sprintf(buf + 7 + j + 48, "%c",
isprint(p[i]) ? p[i] : '.');
printf("%s\n", buf);
}
}
void udpdk_dump_mbuf(struct rte_mbuf *m)
{
udpdk_dump_payload(rte_pktmbuf_mtod(m, char *), rte_pktmbuf_data_len(m));
}
//
// Created by leoll2 on 11/19/20.
// Copyright (c) 2020 Leonardo Lai. All rights reserved.
//
// The following code derives in part from netmap pkt-gen.c
//
#ifndef UDPDK_DUMP_H
#define UDPDK_DUMP_H
void udpdk_dump_payload(const char *payload, int len);
void udpdk_dump_mbuf(struct rte_mbuf *m);
#endif // UDPDK_DUMP_H
......@@ -26,6 +26,7 @@
#include "udpdk_constants.h"
#include "udpdk_bind_table.h"
#include "udpdk_dump.h"
#include "udpdk_shmalloc.h"
#include "udpdk_sync.h"
#include "udpdk_types.h"
......@@ -359,7 +360,8 @@ static inline void reassemble(struct rte_mbuf *m, uint16_t portid, uint32_t queu
}
}
} else {
RTE_LOG(WARNING, POLLBODY, "Received non-IPv4 packet.\n");
RTE_LOG(WARNING, POLLBODY, "Received non-IPv4 packet, showing content below:\n");
udpdk_dump_mbuf(m);
return;
}
......
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