Skip to content

Commit 8c8da5b

Browse files
committed
Merge branch 'Enhance-virtio-vsock-connection-semantics'
Sebastien Boeuf says: ==================== Enhance virtio-vsock connection semantics This series improves the semantics behind the way virtio-vsock server accepts connections coming from the client. Whenever the server receives a connection request from the client, if it is bound to the socket but not yet listening, it will answer with a RST packet. The point is to ensure each request from the client is quickly processed so that the client can decide about the strategy of retrying or not. The series includes along with the improvement patch a new test to ensure the behavior is consistent across all hypervisors drivers. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents ddb535a + 9de9f7d commit 8c8da5b

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

net/vmw_vsock/virtio_transport_common.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,6 +1153,7 @@ void virtio_transport_recv_pkt(struct virtio_transport *t,
11531153
virtio_transport_free_pkt(pkt);
11541154
break;
11551155
default:
1156+
(void)virtio_transport_reset_no_sock(t, pkt);
11561157
virtio_transport_free_pkt(pkt);
11571158
break;
11581159
}

tools/testing/vsock/vsock_test.c

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,78 @@ static void test_stream_connection_reset(const struct test_opts *opts)
5555
close(fd);
5656
}
5757

58+
static void test_stream_bind_only_client(const struct test_opts *opts)
59+
{
60+
union {
61+
struct sockaddr sa;
62+
struct sockaddr_vm svm;
63+
} addr = {
64+
.svm = {
65+
.svm_family = AF_VSOCK,
66+
.svm_port = 1234,
67+
.svm_cid = opts->peer_cid,
68+
},
69+
};
70+
int ret;
71+
int fd;
72+
73+
/* Wait for the server to be ready */
74+
control_expectln("BIND");
75+
76+
fd = socket(AF_VSOCK, SOCK_STREAM, 0);
77+
78+
timeout_begin(TIMEOUT);
79+
do {
80+
ret = connect(fd, &addr.sa, sizeof(addr.svm));
81+
timeout_check("connect");
82+
} while (ret < 0 && errno == EINTR);
83+
timeout_end();
84+
85+
if (ret != -1) {
86+
fprintf(stderr, "expected connect(2) failure, got %d\n", ret);
87+
exit(EXIT_FAILURE);
88+
}
89+
if (errno != ECONNRESET) {
90+
fprintf(stderr, "unexpected connect(2) errno %d\n", errno);
91+
exit(EXIT_FAILURE);
92+
}
93+
94+
/* Notify the server that the client has finished */
95+
control_writeln("DONE");
96+
97+
close(fd);
98+
}
99+
100+
static void test_stream_bind_only_server(const struct test_opts *opts)
101+
{
102+
union {
103+
struct sockaddr sa;
104+
struct sockaddr_vm svm;
105+
} addr = {
106+
.svm = {
107+
.svm_family = AF_VSOCK,
108+
.svm_port = 1234,
109+
.svm_cid = VMADDR_CID_ANY,
110+
},
111+
};
112+
int fd;
113+
114+
fd = socket(AF_VSOCK, SOCK_STREAM, 0);
115+
116+
if (bind(fd, &addr.sa, sizeof(addr.svm)) < 0) {
117+
perror("bind");
118+
exit(EXIT_FAILURE);
119+
}
120+
121+
/* Notify the client that the server is ready */
122+
control_writeln("BIND");
123+
124+
/* Wait for the client to finish */
125+
control_expectln("DONE");
126+
127+
close(fd);
128+
}
129+
58130
static void test_stream_client_close_client(const struct test_opts *opts)
59131
{
60132
int fd;
@@ -212,6 +284,11 @@ static struct test_case test_cases[] = {
212284
.name = "SOCK_STREAM connection reset",
213285
.run_client = test_stream_connection_reset,
214286
},
287+
{
288+
.name = "SOCK_STREAM bind only",
289+
.run_client = test_stream_bind_only_client,
290+
.run_server = test_stream_bind_only_server,
291+
},
215292
{
216293
.name = "SOCK_STREAM client close",
217294
.run_client = test_stream_client_close_client,

0 commit comments

Comments
 (0)