From f023c1e8ff4e143638ef385164af7692cdecadc0 Mon Sep 17 00:00:00 2001 From: Neal Cardwell <ncardwell@google.com> Date: Mon, 4 Nov 2013 10:08:13 -0500 Subject: [PATCH] net-test: packetdrill encap support: free unknown sniffed packets When we sniff an unknown packet, free it and allocate another packet at the top of the sniffing loop. Previously we were not clearing state after parsing an unknown packet, so state from the unkbown packet could linger on, co-mingling with state from the next sniffed packet. Change-Id: Ia9a330766969b114fd6084a087ff3f0d6b11d9d4 --- gtests/net/packetdrill/netdev.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/gtests/net/packetdrill/netdev.c b/gtests/net/packetdrill/netdev.c index 64ac611e..37399b21 100644 --- a/gtests/net/packetdrill/netdev.c +++ b/gtests/net/packetdrill/netdev.c @@ -380,28 +380,31 @@ int netdev_receive_loop(struct packet_socket *psock, char **error) { assert(*packet == NULL); /* should be no packet yet */ - *packet = packet_new(PACKET_READ_BYTES); while (1) { int in_bytes = 0; enum packet_parse_result_t result; + *packet = packet_new(PACKET_READ_BYTES); + /* Sniff the next outbound packet from the kernel under test. */ if (packet_socket_receive(psock, DIRECTION_OUTBOUND, *packet, &in_bytes)) continue; result = parse_packet(*packet, in_bytes, layer, error); - if (result == PACKET_OK) { + + if (result == PACKET_OK) return STATUS_OK; - } else if (result == PACKET_BAD) { - packet_free(*packet); - *packet = NULL; + + packet_free(*packet); + *packet = NULL; + + if (result == PACKET_BAD) return STATUS_ERR; - } else { - DEBUGP("parse_result:%d; error parsing packet: %s\n", - result, *error); - } + + DEBUGP("parse_result:%d; error parsing packet: %s\n", + result, *error); } assert(!"should not be reached"); -- GitLab