Skip to content

Commit 3de673c

Browse files
Geliang Tangintel-lab-lkp
authored andcommitted
selftests: mptcp: sockopt: add protocol arguments
Add -t and -r options to specify tx/rx protocols (TCP/MPTCP). This increases testing flexibility by allowing explicit protocol selection for both transmission and reception paths. These codes are from mptcp_inq.c. Signed-off-by: Geliang Tang <[email protected]>
1 parent ca7f153 commit 3de673c

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

tools/testing/selftests/net/mptcp/mptcp_sockopt.c

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
#include <linux/tcp.h>
2929

3030
static int pf = AF_INET;
31+
static int proto_tx = IPPROTO_MPTCP;
32+
static int proto_rx = IPPROTO_MPTCP;
3133

3234
#ifndef IPPROTO_MPTCP
3335
#define IPPROTO_MPTCP 262
@@ -136,7 +138,7 @@ static void die_perror(const char *msg)
136138

137139
static void die_usage(int r)
138140
{
139-
fprintf(stderr, "Usage: mptcp_sockopt [-6]\n");
141+
fprintf(stderr, "Usage: mptcp_sockopt [-6] [ -t tcp|mptcp ] [ -r tcp|mptcp]\n");
140142
exit(r);
141143
}
142144

@@ -202,7 +204,7 @@ static int sock_listen_mptcp(const char * const listenaddr,
202204
hints.ai_family = pf;
203205

204206
for (a = addr; a; a = a->ai_next) {
205-
sock = socket(a->ai_family, a->ai_socktype, IPPROTO_MPTCP);
207+
sock = socket(a->ai_family, a->ai_socktype, proto_rx);
206208
if (sock < 0)
207209
continue;
208210

@@ -260,18 +262,35 @@ static int sock_connect_mptcp(const char * const remoteaddr,
260262
return sock;
261263
}
262264

265+
static int protostr_to_num(const char *s)
266+
{
267+
if (strcasecmp(s, "tcp") == 0)
268+
return IPPROTO_TCP;
269+
if (strcasecmp(s, "mptcp") == 0)
270+
return IPPROTO_MPTCP;
271+
272+
die_usage(1);
273+
return 0;
274+
}
275+
263276
static void parse_opts(int argc, char **argv)
264277
{
265278
int c;
266279

267-
while ((c = getopt(argc, argv, "h6")) != -1) {
280+
while ((c = getopt(argc, argv, "h6t:r:")) != -1) {
268281
switch (c) {
269282
case 'h':
270283
die_usage(0);
271284
break;
272285
case '6':
273286
pf = AF_INET6;
274287
break;
288+
case 't':
289+
proto_tx = protostr_to_num(optarg);
290+
break;
291+
case 'r':
292+
proto_rx = protostr_to_num(optarg);
293+
break;
275294
default:
276295
die_usage(1);
277296
break;
@@ -772,10 +791,10 @@ static int client(int pipefd)
772791

773792
switch (pf) {
774793
case AF_INET:
775-
fd = sock_connect_mptcp("127.0.0.1", "15432", IPPROTO_MPTCP);
794+
fd = sock_connect_mptcp("127.0.0.1", "15432", proto_tx);
776795
break;
777796
case AF_INET6:
778-
fd = sock_connect_mptcp("::1", "15432", IPPROTO_MPTCP);
797+
fd = sock_connect_mptcp("::1", "15432", proto_tx);
779798
break;
780799
default:
781800
xerror("Unknown pf %d\n", pf);

0 commit comments

Comments
 (0)