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

net-test: packetdrill encap support: test GRE encap parsing

Add simple coverage of IP/GRE encapsulation parsing.

Change-Id: I5938edc521a387e0c72bbf547d2862077f6af204
parent 460c15db
No related branches found
No related tags found
No related merge requests found
...@@ -206,11 +206,90 @@ static void test_parse_udp_ipv6_packet(void) ...@@ -206,11 +206,90 @@ static void test_parse_udp_ipv6_packet(void)
packet_free(packet); packet_free(packet);
} }
static void test_parse_ipv4_gre_ipv4_tcp_packet(void)
{
u8 *p = NULL;
int i = 0;
/* An IPv4/GRE/IPv4/TCP packet. */
u8 data[] = {
/* IP 2.2.2.2 > 1.1.1.1: GREv0, length 48:
IP 192.0.2.1.47078 > 192.168.0.1.8080:
. 2:6(4) ack 1 win 123 */
0x45, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x00,
0xff, 0x2f, 0xb5, 0x85, 0x02, 0x02, 0x02, 0x02,
0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x08, 0x00,
0x45, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x00,
0xff, 0x06, 0x39, 0x21, 0xc0, 0x00, 0x02, 0x01,
0xc0, 0xa8, 0x00, 0x01, 0xb7, 0xe6, 0x1f, 0x90,
0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01,
0x50, 0x10, 0x00, 0x7b, 0x55, 0x31, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00
};
struct packet *packet = packet_new(sizeof(data));
/* Populate and parse a packet */
memcpy(packet->buffer, data, sizeof(data));
char *error = NULL;
enum packet_parse_result_t result =
parse_packet(packet, sizeof(data), PACKET_LAYER_3_IP,
&error);
assert(result == PACKET_OK);
assert(error == NULL);
p = packet->buffer;
i = 0; /* outer most layer, 0 */
assert(packet->headers[i].type == HEADER_IPV4);
assert(packet->headers[i].h.ptr == p);
assert(packet->headers[i].header_bytes == sizeof(struct ipv4));
p += packet->headers[i].header_bytes;
i++;
assert(packet->headers[i].type == HEADER_GRE);
assert(packet->headers[i].h.ptr == p);
assert(packet->headers[i].header_bytes == sizeof(struct gre));
p += packet->headers[i].header_bytes;
i++;
struct ipv4 *expected_inner_ipv4 = (struct ipv4 *)p;
assert(packet->headers[i].type == HEADER_IPV4);
assert(packet->headers[i].h.ptr == p);
assert(packet->headers[i].header_bytes == sizeof(struct ipv4));
p += packet->headers[i].header_bytes;
i++;
struct tcp *expected_tcp = (struct tcp *)p;
assert(packet->headers[i].type == HEADER_TCP);
assert(packet->headers[i].h.ptr == p);
assert(packet->headers[i].header_bytes == sizeof(struct tcp));
p += packet->headers[i].header_bytes;
i++;
assert(packet->headers[i].type == HEADER_NONE);
assert(packet->ip_bytes == sizeof(data));
assert(packet->ipv4 == expected_inner_ipv4);
assert(packet->ipv6 == NULL);
assert(packet->tcp == expected_tcp);
assert(packet->udp == NULL);
assert(packet->icmpv4 == NULL);
assert(packet->icmpv6 == NULL);
assert(packet->time_usecs == 0);
assert(packet->flags == 0);
assert(packet->ecn == 0);
packet_free(packet);
}
int main(void) int main(void)
{ {
test_parse_tcp_ipv4_packet(); test_parse_tcp_ipv4_packet();
test_parse_tcp_ipv6_packet(); test_parse_tcp_ipv6_packet();
test_parse_udp_ipv4_packet(); test_parse_udp_ipv4_packet();
test_parse_udp_ipv6_packet(); test_parse_udp_ipv6_packet();
test_parse_ipv4_gre_ipv4_tcp_packet();
return 0; return 0;
} }
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