From 0573742776d9855684bcd5ffc5ae50affcb2126b Mon Sep 17 00:00:00 2001
From: Neal Cardwell <ncardwell@google.com>
Date: Fri, 17 Jan 2014 12:29:33 -0500
Subject: [PATCH] net-test: packetdrill: fix bug in remote mode packet sniffing
 direction

Fix wire_server_netdev_receive() to reflect the fact that in remote
mode the server is sniffing packets that are inbound (whereas in local
mode we are sniffing *outbound* packets).

This was a bug introduced in "net-test: packetdrill encap
support: refactor packet receive loops into one loop".

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

Change-Id: Ia92f70f48ae90cb2e089ee51d728473a12c63595
---
 gtests/net/packetdrill/netdev.c             | 6 +++---
 gtests/net/packetdrill/netdev.h             | 1 +
 gtests/net/packetdrill/wire_server_netdev.c | 2 +-
 3 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/gtests/net/packetdrill/netdev.c b/gtests/net/packetdrill/netdev.c
index 8cee434d..1d92da4d 100644
--- a/gtests/net/packetdrill/netdev.c
+++ b/gtests/net/packetdrill/netdev.c
@@ -371,11 +371,12 @@ static int local_netdev_receive(struct netdev *a_netdev,
 	DEBUGP("local_netdev_receive\n");
 
 	return netdev_receive_loop(netdev->psock, PACKET_LAYER_3_IP,
-				   packet, error);
+				   DIRECTION_OUTBOUND, packet, error);
 }
 
 int netdev_receive_loop(struct packet_socket *psock,
 			enum packet_layer_t layer,
+			enum direction_t direction,
 			struct packet **packet,
 			char **error)
 {
@@ -388,8 +389,7 @@ int netdev_receive_loop(struct packet_socket *psock,
 		*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))
+		if (packet_socket_receive(psock, direction, *packet, &in_bytes))
 			continue;
 
 		result = parse_packet(*packet, in_bytes, layer, error);
diff --git a/gtests/net/packetdrill/netdev.h b/gtests/net/packetdrill/netdev.h
index 84e87a0a..d7444a86 100644
--- a/gtests/net/packetdrill/netdev.h
+++ b/gtests/net/packetdrill/netdev.h
@@ -88,6 +88,7 @@ static inline int netdev_receive(struct netdev *netdev,
  */
 extern int netdev_receive_loop(struct packet_socket *psock,
 			       enum packet_layer_t layer,
+			       enum direction_t direction,
 			       struct packet **packet,
 			       char **error);
 
diff --git a/gtests/net/packetdrill/wire_server_netdev.c b/gtests/net/packetdrill/wire_server_netdev.c
index 066566f2..219f86c3 100644
--- a/gtests/net/packetdrill/wire_server_netdev.c
+++ b/gtests/net/packetdrill/wire_server_netdev.c
@@ -192,7 +192,7 @@ static int wire_server_netdev_receive(struct netdev *a_netdev,
 	DEBUGP("wire_server_netdev_receive\n");
 
 	return netdev_receive_loop(netdev->psock, PACKET_LAYER_2_ETHERNET,
-				   packet, error);
+				   DIRECTION_INBOUND, packet, error);
 }
 
 struct netdev_ops wire_server_netdev_ops = {
-- 
GitLab