diff options
author | Thanos Makatos <thanos.makatos@nutanix.com> | 2021-01-25 17:33:13 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-25 17:33:13 +0000 |
commit | 915a5b01f34a61cacef5ae5b50a215d13628b8b0 (patch) | |
tree | 6282c7f27790a44ed5787a5f288188e748f41a5e | |
parent | 5f2fa524cd587762bd63cfc6d1594dfd4a956272 (diff) | |
download | libvfio-user-915a5b01f34a61cacef5ae5b50a215d13628b8b0.zip libvfio-user-915a5b01f34a61cacef5ae5b50a215d13628b8b0.tar.gz libvfio-user-915a5b01f34a61cacef5ae5b50a215d13628b8b0.tar.bz2 |
don't assume specific message ID when negotiating (#248)
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
-rw-r--r-- | lib/tran_sock.c | 8 | ||||
-rw-r--r-- | samples/client.c | 7 |
2 files changed, 7 insertions, 8 deletions
diff --git a/lib/tran_sock.c b/lib/tran_sock.c index 3d3b1fc..e798cec 100644 --- a/lib/tran_sock.c +++ b/lib/tran_sock.c @@ -291,7 +291,7 @@ vfu_recv_fds(int sock, struct vfio_user_header *hdr, bool is_reply, } if (is_reply) { - if (hdr->msg_id != *msg_id) { + if (msg_id != NULL && hdr->msg_id != *msg_id) { return -EINVAL; } @@ -309,7 +309,9 @@ vfu_recv_fds(int sock, struct vfio_user_header *hdr, bool is_reply, if (hdr->flags.type != VFIO_USER_F_TYPE_COMMAND) { return -EINVAL; } - *msg_id = hdr->msg_id; + if (msg_id != NULL) { + *msg_id = hdr->msg_id; + } } if (len != NULL && *len > 0 && hdr->msg_size > sizeof *hdr) { @@ -664,7 +666,7 @@ static int negotiate(vfu_ctx_t *vfu_ctx, int sock) { struct vfio_user_version *client_version = NULL; - uint16_t msg_id = 1; + uint16_t msg_id = 0x0bad; int ret; ret = recv_version(vfu_ctx, sock, &msg_id, &client_version); diff --git a/samples/client.c b/samples/client.c index 60b245f..18558b8 100644 --- a/samples/client.c +++ b/samples/client.c @@ -130,12 +130,10 @@ recv_version(int sock, int *server_max_fds, size_t *pgsize) { struct vfio_user_version *sversion = NULL; struct vfio_user_header hdr; - uint16_t msg_id = 0; size_t vlen; int ret; - ret = vfu_recv_alloc(sock, &hdr, true, &msg_id, - (void **)&sversion, &vlen); + ret = vfu_recv_alloc(sock, &hdr, true, NULL, (void **)&sversion, &vlen); if (ret < 0) { errx(EXIT_FAILURE, "failed to receive version: %s", strerror(-ret)); @@ -150,8 +148,7 @@ recv_version(int sock, int *server_max_fds, size_t *pgsize) #endif if (vlen < sizeof (*sversion)) { - errx(EXIT_FAILURE, "msg%hx (VFIO_USER_VERSION): invalid size %lu", - msg_id, vlen); + errx(EXIT_FAILURE, "VFIO_USER_VERSION: invalid size %lu", vlen); } if (sversion->major != LIB_VFIO_USER_MAJOR) { |