Skip to content

Commit c0b9f43

Browse files
committed
net-test: packetdrill: for wire mode have client send WIRE_LIVE_REMOTE_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
1 parent 7f29a38 commit c0b9f43

File tree

4 files changed

+48
-0
lines changed

4 files changed

+48
-0
lines changed

gtests/net/packetdrill/wire_client.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,18 @@ static void wire_client_send_live_local_ip(struct wire_client *wire_client,
151151
"error sending WIRE_LIVE_LOCAL_IP");
152152
}
153153

154+
/* Send the IP live_remote address from which the server should send packets. */
155+
static void wire_client_send_live_remote_ip(struct wire_client *wire_client,
156+
const struct config *config)
157+
{
158+
if (wire_conn_write(wire_client->wire_conn,
159+
WIRE_LIVE_REMOTE_IP,
160+
config->live_remote_ip_string,
161+
strlen(config->live_remote_ip_string)))
162+
wire_client_die(wire_client,
163+
"error sending WIRE_LIVE_REMOTE_IP");
164+
}
165+
154166
/* Receive server's message that the server is ready to execute the script. */
155167
static void wire_client_receive_server_ready(struct wire_client *wire_client)
156168
{
@@ -279,6 +291,8 @@ int wire_client_init(struct wire_client *wire_client,
279291

280292
wire_client_send_live_local_ip(wire_client, config);
281293

294+
wire_client_send_live_remote_ip(wire_client, config);
295+
282296
wire_client_receive_server_ready(wire_client);
283297

284298
return STATUS_OK;

gtests/net/packetdrill/wire_protocol.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const char *wire_op_to_string(enum wire_op_t op)
3737
case WIRE_SCRIPT: return "WIRE_SCRIPT";
3838
case WIRE_HARDWARE_ADDR: return "WIRE_HARDWARE_ADDR";
3939
case WIRE_LIVE_LOCAL_IP: return "WIRE_LIVE_LOCAL_IP";
40+
case WIRE_LIVE_REMOTE_IP: return "WIRE_LIVE_REMOTE_IP";
4041
case WIRE_SERVER_READY: return "WIRE_SERVER_READY";
4142
case WIRE_CLIENT_STARTING: return "WIRE_CLIENT_STARTING";
4243
case WIRE_PACKETS_START: return "WIRE_PACKETS_START";

gtests/net/packetdrill/wire_protocol.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ enum wire_op_t {
3535
WIRE_SCRIPT, /* "here's the script we're going to start" */
3636
WIRE_HARDWARE_ADDR, /* "here's my ethernet MAC address" */
3737
WIRE_LIVE_LOCAL_IP, /* "here's the client live_local_ip_string */
38+
WIRE_LIVE_REMOTE_IP, /* "here's the live_remote_ip_string to use */
3839
WIRE_SERVER_READY, /* "server ready to start script execution" */
3940
WIRE_CLIENT_STARTING, /* "i'm starting script execution... now!" */
4041
WIRE_PACKETS_START, /* "please start handling packet events" */

gtests/net/packetdrill/wire_server.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,35 @@ static int wire_server_receive_live_local_ip(struct wire_server *wire_server)
236236
return STATUS_OK;
237237
}
238238

239+
/* Receive the live_remote IP from which the server should send packets. */
240+
static int wire_server_receive_live_remote_ip(struct wire_server *wire_server)
241+
{
242+
enum wire_op_t op = WIRE_INVALID;
243+
void *buf = NULL;
244+
int buf_len = -1;
245+
struct config *config = &wire_server->config;
246+
247+
if (wire_conn_read(wire_server->wire_conn, &op, &buf, &buf_len))
248+
return STATUS_ERR;
249+
if (op != WIRE_LIVE_REMOTE_IP) {
250+
fprintf(stderr,
251+
"bad wire client: expected WIRE_LIVE_REMOTE_IP\n");
252+
return STATUS_ERR;
253+
}
254+
if (buf_len + 1 > sizeof(config->live_remote_ip_string)) {
255+
fprintf(stderr,
256+
"bad wire client: ip address too long\n");
257+
return STATUS_ERR;
258+
}
259+
260+
memcpy(config->live_remote_ip_string, buf, buf_len);
261+
config->live_remote_ip_string[buf_len] = '\0'; /* NULL-terminate str */
262+
DEBUGP("got WIRE_LIVE_REMOTE_IP: [%s]\n",
263+
config->live_remote_ip_string);
264+
265+
return STATUS_OK;
266+
}
267+
239268
/* Send a message to tell the client we're ready to excecute the script. */
240269
static int wire_server_send_server_ready(struct wire_server *wire_server)
241270
{
@@ -488,6 +517,9 @@ static void *wire_server_thread(void *arg)
488517
if (wire_server_receive_live_local_ip(wire_server))
489518
goto error_done;
490519

520+
if (wire_server_receive_live_remote_ip(wire_server))
521+
goto error_done;
522+
491523
if (parse_script_and_set_config(wire_server->argc,
492524
wire_server->argv,
493525
&wire_server->config,

0 commit comments

Comments
 (0)