Skip to content
Snippets Groups Projects
Commit 03bfca42 authored by Neal Cardwell's avatar Neal Cardwell
Browse files

net-test: packetdrill: fix packet_append_header() calculations for remote mode

Fix the packet header location calculations in packet_append_header()
forgot to account for the fact that there might be layer 2 headers.

Remote mode has been broken since the addition of encapsulation
support, partly due to this issue.

Change-Id: Idfb0670da8799e11fe1b72771ed13d52d8e991fe
parent 79b87276
No related branches found
No related tags found
No related merge requests found
...@@ -102,6 +102,7 @@ struct header *packet_append_header(struct packet *packet, ...@@ -102,6 +102,7 @@ struct header *packet_append_header(struct packet *packet,
{ {
struct header *header = NULL; struct header *header = NULL;
int num_headers = packet_header_count(packet); int num_headers = packet_header_count(packet);
int packet_bytes;
assert(num_headers <= PACKET_MAX_HEADERS); assert(num_headers <= PACKET_MAX_HEADERS);
if (num_headers == PACKET_MAX_HEADERS) if (num_headers == PACKET_MAX_HEADERS)
...@@ -111,7 +112,8 @@ struct header *packet_append_header(struct packet *packet, ...@@ -111,7 +112,8 @@ struct header *packet_append_header(struct packet *packet,
if (packet->ip_bytes + header_bytes > packet->buffer_bytes) if (packet->ip_bytes + header_bytes > packet->buffer_bytes)
return NULL; return NULL;
header->h.ptr = packet->buffer + packet->ip_bytes; packet_bytes = packet->l2_header_bytes + packet->ip_bytes;
header->h.ptr = packet->buffer + packet_bytes;
packet->ip_bytes += header_bytes; packet->ip_bytes += header_bytes;
header->type = header_type; header->type = header_type;
......
...@@ -69,7 +69,8 @@ static const int PACKET_READ_BYTES = 64 * 1024; ...@@ -69,7 +69,8 @@ static const int PACKET_READ_BYTES = 64 * 1024;
struct packet { struct packet {
u8 *buffer; /* data buffer: full contents of packet */ u8 *buffer; /* data buffer: full contents of packet */
u32 buffer_bytes; /* bytes of space in data buffer */ u32 buffer_bytes; /* bytes of space in data buffer */
u32 ip_bytes; /* bytes on wire: outermost IP hdrs/payload */ u32 l2_header_bytes; /* bytes in outer hardware/layer-2 header */
u32 ip_bytes; /* bytes in outermost IP hdrs/payload */
enum direction_t direction; /* direction packet is traveling */ enum direction_t direction; /* direction packet is traveling */
/* Metadata about all the headers in the packet, including all /* Metadata about all the headers in the packet, including all
......
...@@ -71,6 +71,7 @@ static int parse_layer2_packet(struct packet *packet, ...@@ -71,6 +71,7 @@ static int parse_layer2_packet(struct packet *packet,
} }
ether = (struct ether_header *)p; ether = (struct ether_header *)p;
p += sizeof(*ether); p += sizeof(*ether);
packet->l2_header_bytes = sizeof(*ether);
return parse_layer3_packet_by_proto(packet, ntohs(ether->ether_type), return parse_layer3_packet_by_proto(packet, ntohs(ether->ether_type),
p, packet_end, error); p, packet_end, error);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment