Skip to content

Commit e1dbf76

Browse files
committed
udp gso/gro: move policy to client; send explicit params; server accepts and applies locally
Client remains the source of truth for UDP GSO/GRO policy (including --no-gsro). During parameter exchange, the client now sends GSO/GRO flags and sizes in JSON, and the server simply consumes those values without recomputing. Kernel capability gating stays local and authoritative: each endpoint attempts to enable GSO/GRO on its own sockets via setsockopt, and if the kernel rejects it, we log and flip the local flag off. This handles the case where only one side supports the feature (GSO for the sender, GRO for the receiver). Backward compatibility: if talking to an older client that doesn’t send GSO fields, the server derives gso_dg_size from blksize and adjusts gso_bf_size, falling back to DEFAULT_UDP_BLKSIZE if zero. This preserves previous behavior without overriding explicit client intent. Behavior details: - --no-gsro on the client sends gso=0 and gro=0, so the server won’t try to enable them. - If -l/--length is provided, blksize (and therefore gso_dg_size when enabled) follows that value; otherwise default logic applies. Files: src/iperf_api.c (send_parameters adds gso/gro fields; get_parameters reads them and removes server-side recompute unless needed for compatibility).
1 parent b679f78 commit e1dbf76

1 file changed

Lines changed: 34 additions & 3 deletions

File tree

src/iperf_api.c

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2487,6 +2487,22 @@ send_parameters(struct iperf_test *test)
24872487
cJSON_AddNumberToObject(j, "pacing_timer", test->settings->pacing_timer);
24882488
if (test->settings->burst)
24892489
cJSON_AddNumberToObject(j, "burst", test->settings->burst);
2490+
2491+
#ifdef HAVE_UDP_SEGMENT
2492+
/* Send UDP GSO settings from client to server */
2493+
if (test->protocol->id == Pudp) {
2494+
cJSON_AddNumberToObject(j, "gso", test->settings->gso);
2495+
cJSON_AddNumberToObject(j, "gso_dg_size", test->settings->gso_dg_size);
2496+
cJSON_AddNumberToObject(j, "gso_bf_size", test->settings->gso_bf_size);
2497+
}
2498+
#endif
2499+
#ifdef HAVE_UDP_GRO
2500+
/* Send UDP GRO settings from client to server */
2501+
if (test->protocol->id == Pudp) {
2502+
cJSON_AddNumberToObject(j, "gro", test->settings->gro);
2503+
cJSON_AddNumberToObject(j, "gro_bf_size", test->settings->gro_bf_size);
2504+
}
2505+
#endif
24902506
if (test->settings->tos)
24912507
cJSON_AddNumberToObject(j, "TOS", test->settings->tos);
24922508
if (test->settings->flowlabel)
@@ -2610,17 +2626,32 @@ get_parameters(struct iperf_test *test)
26102626
test->settings->socket_bufsize = j_p->valueint;
26112627
if ((j_p = iperf_cJSON_GetObjectItemType(j, "len", cJSON_Number)) != NULL)
26122628
test->settings->blksize = j_p->valueint;
2629+
26132630
#ifdef HAVE_UDP_SEGMENT
2614-
if (test->protocol->id == Pudp && test->settings->gso == 1) {
2631+
/* Accept UDP GSO settings provided by the client */
2632+
if ((j_p = iperf_cJSON_GetObjectItemType(j, "gso", cJSON_Number)) != NULL)
2633+
test->settings->gso = j_p->valueint;
2634+
if ((j_p = iperf_cJSON_GetObjectItemType(j, "gso_dg_size", cJSON_Number)) != NULL)
2635+
test->settings->gso_dg_size = j_p->valueint;
2636+
if ((j_p = iperf_cJSON_GetObjectItemType(j, "gso_bf_size", cJSON_Number)) != NULL)
2637+
test->settings->gso_bf_size = j_p->valueint;
2638+
2639+
/* Backward-compatibility: If client didn't send GSO params, derive from blksize. */
2640+
if (test->protocol->id == Pudp && test->settings->gso == 1 && test->settings->gso_dg_size == 0) {
26152641
test->settings->gso_dg_size = test->settings->blksize;
2616-
/* use the multiple of datagram size for the best efficiency. */
26172642
if (test->settings->gso_dg_size > 0) {
26182643
test->settings->gso_bf_size = (test->settings->gso_bf_size / test->settings->gso_dg_size) * test->settings->gso_dg_size;
26192644
} else {
2620-
/* If gso_dg_size is 0 (unlimited bandwidth), use default UDP datagram size */
26212645
test->settings->gso_dg_size = DEFAULT_UDP_BLKSIZE;
26222646
}
26232647
}
2648+
#endif
2649+
#ifdef HAVE_UDP_GRO
2650+
/* Accept UDP GRO settings provided by the client */
2651+
if ((j_p = iperf_cJSON_GetObjectItemType(j, "gro", cJSON_Number)) != NULL)
2652+
test->settings->gro = j_p->valueint;
2653+
if ((j_p = iperf_cJSON_GetObjectItemType(j, "gro_bf_size", cJSON_Number)) != NULL)
2654+
test->settings->gro_bf_size = j_p->valueint;
26242655
#endif
26252656
if ((j_p = iperf_cJSON_GetObjectItemType(j, "bandwidth", cJSON_Number)) != NULL)
26262657
test->settings->rate = j_p->valueint;

0 commit comments

Comments
 (0)