Skip to content

Commit

Permalink
net-test: packetdrill: for wire mode have client send WIRE_LIVE_REMOT…
Browse files Browse the repository at this point in the history
…E_IP to server

For wire mode have the client send WIRE_LIVE_REMOTE_IP to server.

This fixes a significant bug from the May 2023 wire mode patch series.
That bug caused the wire server to inject packets with a source IP of
the DEFAULT_V4_LIVE_REMOTE_IP_STRING (192.0.2.1) instead of a source
IP of the wire server machine. That bug prevented wire mode from
working properly.

This fixes behavior so that the following simple usage works as
intended for remote/wire-server mode:

server_machine# ./packetdrill --wire_server
client_machine# ./packetdrill --wire_server_at=10.240.0.42 test.pkt

This method of configuring the client and server now works properly
because:

+ set_wire_client_defaults() will set live_remote_ip_string from
  wire_server_ip

+ the client will communicate this live_remote_ip_string value to the
  server

+ the server will use this live_remote_ip_string as the source IP for
  injected packets

Signed-off-by: Neal Cardwell <[email protected]>
Change-Id: Icda2f8040b3d69a1c23813e9d94e94cc3be88a36
  • Loading branch information
nealcardwell committed Mar 10, 2025
1 parent 7f29a38 commit c0b9f43
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
14 changes: 14 additions & 0 deletions gtests/net/packetdrill/wire_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,18 @@ static void wire_client_send_live_local_ip(struct wire_client *wire_client,
"error sending WIRE_LIVE_LOCAL_IP");
}

/* Send the IP live_remote address from which the server should send packets. */
static void wire_client_send_live_remote_ip(struct wire_client *wire_client,
const struct config *config)
{
if (wire_conn_write(wire_client->wire_conn,
WIRE_LIVE_REMOTE_IP,
config->live_remote_ip_string,
strlen(config->live_remote_ip_string)))
wire_client_die(wire_client,
"error sending WIRE_LIVE_REMOTE_IP");
}

/* Receive server's message that the server is ready to execute the script. */
static void wire_client_receive_server_ready(struct wire_client *wire_client)
{
Expand Down Expand Up @@ -279,6 +291,8 @@ int wire_client_init(struct wire_client *wire_client,

wire_client_send_live_local_ip(wire_client, config);

wire_client_send_live_remote_ip(wire_client, config);

wire_client_receive_server_ready(wire_client);

return STATUS_OK;
Expand Down
1 change: 1 addition & 0 deletions gtests/net/packetdrill/wire_protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const char *wire_op_to_string(enum wire_op_t op)
case WIRE_SCRIPT: return "WIRE_SCRIPT";
case WIRE_HARDWARE_ADDR: return "WIRE_HARDWARE_ADDR";
case WIRE_LIVE_LOCAL_IP: return "WIRE_LIVE_LOCAL_IP";
case WIRE_LIVE_REMOTE_IP: return "WIRE_LIVE_REMOTE_IP";
case WIRE_SERVER_READY: return "WIRE_SERVER_READY";
case WIRE_CLIENT_STARTING: return "WIRE_CLIENT_STARTING";
case WIRE_PACKETS_START: return "WIRE_PACKETS_START";
Expand Down
1 change: 1 addition & 0 deletions gtests/net/packetdrill/wire_protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ enum wire_op_t {
WIRE_SCRIPT, /* "here's the script we're going to start" */
WIRE_HARDWARE_ADDR, /* "here's my ethernet MAC address" */
WIRE_LIVE_LOCAL_IP, /* "here's the client live_local_ip_string */
WIRE_LIVE_REMOTE_IP, /* "here's the live_remote_ip_string to use */
WIRE_SERVER_READY, /* "server ready to start script execution" */
WIRE_CLIENT_STARTING, /* "i'm starting script execution... now!" */
WIRE_PACKETS_START, /* "please start handling packet events" */
Expand Down
32 changes: 32 additions & 0 deletions gtests/net/packetdrill/wire_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,35 @@ static int wire_server_receive_live_local_ip(struct wire_server *wire_server)
return STATUS_OK;
}

/* Receive the live_remote IP from which the server should send packets. */
static int wire_server_receive_live_remote_ip(struct wire_server *wire_server)
{
enum wire_op_t op = WIRE_INVALID;
void *buf = NULL;
int buf_len = -1;
struct config *config = &wire_server->config;

if (wire_conn_read(wire_server->wire_conn, &op, &buf, &buf_len))
return STATUS_ERR;
if (op != WIRE_LIVE_REMOTE_IP) {
fprintf(stderr,
"bad wire client: expected WIRE_LIVE_REMOTE_IP\n");
return STATUS_ERR;
}
if (buf_len + 1 > sizeof(config->live_remote_ip_string)) {
fprintf(stderr,
"bad wire client: ip address too long\n");
return STATUS_ERR;
}

memcpy(config->live_remote_ip_string, buf, buf_len);
config->live_remote_ip_string[buf_len] = '\0'; /* NULL-terminate str */
DEBUGP("got WIRE_LIVE_REMOTE_IP: [%s]\n",
config->live_remote_ip_string);

return STATUS_OK;
}

/* Send a message to tell the client we're ready to excecute the script. */
static int wire_server_send_server_ready(struct wire_server *wire_server)
{
Expand Down Expand Up @@ -488,6 +517,9 @@ static void *wire_server_thread(void *arg)
if (wire_server_receive_live_local_ip(wire_server))
goto error_done;

if (wire_server_receive_live_remote_ip(wire_server))
goto error_done;

if (parse_script_and_set_config(wire_server->argc,
wire_server->argv,
&wire_server->config,
Expand Down

0 comments on commit c0b9f43

Please sign in to comment.