aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMattias Nissler <122288598+mnissler-rivos@users.noreply.github.com>2023-08-30 17:19:50 +0200
committerGitHub <noreply@github.com>2023-08-30 16:19:50 +0100
commitf981913abd9a5926d38a48c6ba9b1ba7dacb1c11 (patch)
treefd987030168cc14095322664e86feaefaa362582 /lib
parent149aa845b11bd13fca41dcf65b51283f83ac5520 (diff)
downloadlibvfio-user-f981913abd9a5926d38a48c6ba9b1ba7dacb1c11.zip
libvfio-user-f981913abd9a5926d38a48c6ba9b1ba7dacb1c11.tar.gz
libvfio-user-f981913abd9a5926d38a48c6ba9b1ba7dacb1c11.tar.bz2
Replace protocol header flags bit field with mask (#773)
It turns out that the bit field will not yield the desired / specified bit layout on big-endian systems, see issue #768 for details. Thus, replace the bit field with constants for the individual fields and use bit masking when accessing the flags field. Signed-off-by: Mattias Nissler <mnissler@rivosinc.com> Reviewed-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/libvfio-user.c4
-rw-r--r--lib/tran_pipe.c12
-rw-r--r--lib/tran_sock.c12
3 files changed, 14 insertions, 14 deletions
diff --git a/lib/libvfio-user.c b/lib/libvfio-user.c
index 48013c2..271a269 100644
--- a/lib/libvfio-user.c
+++ b/lib/libvfio-user.c
@@ -1127,7 +1127,7 @@ do_reply(vfu_ctx_t *vfu_ctx, vfu_msg_t *msg, int reply_errno)
assert(vfu_ctx != NULL);
assert(msg != NULL);
- if (msg->hdr.flags.no_reply) {
+ if (msg->hdr.flags & VFIO_USER_F_NO_REPLY) {
/*
* A failed client request is not a failure of handle_request() itself.
*/
@@ -1283,7 +1283,7 @@ get_request_header(vfu_ctx_t *vfu_ctx, vfu_msg_t **msgp)
static bool
is_valid_header(vfu_ctx_t *vfu_ctx, vfu_msg_t *msg)
{
- if (msg->hdr.flags.type != VFIO_USER_F_TYPE_COMMAND) {
+ if ((msg->hdr.flags & VFIO_USER_F_TYPE_MASK) != VFIO_USER_F_TYPE_COMMAND) {
vfu_log(vfu_ctx, LOG_ERR, "msg%#hx: not a command req",
msg->hdr.msg_id);
return false;
diff --git a/lib/tran_pipe.c b/lib/tran_pipe.c
index d1428ab..e7aa84d 100644
--- a/lib/tran_pipe.c
+++ b/lib/tran_pipe.c
@@ -57,15 +57,15 @@ tran_pipe_send_iovec(int fd, uint16_t msg_id, bool is_reply,
}
if (is_reply) {
- hdr.flags.type = VFIO_USER_F_TYPE_REPLY;
+ hdr.flags |= VFIO_USER_F_TYPE_REPLY;
hdr.cmd = cmd;
if (err != 0) {
- hdr.flags.error = 1U;
+ hdr.flags |= VFIO_USER_F_ERROR;
hdr.error_no = err;
}
} else {
hdr.cmd = cmd;
- hdr.flags.type = VFIO_USER_F_TYPE_COMMAND;
+ hdr.flags |= VFIO_USER_F_TYPE_COMMAND;
}
iovecs[0].iov_base = &hdr;
@@ -131,18 +131,18 @@ tran_pipe_recv(int fd, struct vfio_user_header *hdr, bool is_reply,
return ERROR_INT(EPROTO);
}
- if (hdr->flags.type != VFIO_USER_F_TYPE_REPLY) {
+ if ((hdr->flags & VFIO_USER_F_TYPE_MASK) != VFIO_USER_F_TYPE_REPLY) {
return ERROR_INT(EINVAL);
}
- if (hdr->flags.error == 1U) {
+ if (hdr->flags & VFIO_USER_F_ERROR) {
if (hdr->error_no <= 0) {
hdr->error_no = EINVAL;
}
return ERROR_INT(hdr->error_no);
}
} else {
- if (hdr->flags.type != VFIO_USER_F_TYPE_COMMAND) {
+ if ((hdr->flags & VFIO_USER_F_TYPE_MASK) != VFIO_USER_F_TYPE_COMMAND) {
return ERROR_INT(EINVAL);
}
if (msg_id != NULL) {
diff --git a/lib/tran_sock.c b/lib/tran_sock.c
index fb0ccbb..3f4c8c3 100644
--- a/lib/tran_sock.c
+++ b/lib/tran_sock.c
@@ -69,15 +69,15 @@ tran_sock_send_iovec(int sock, uint16_t msg_id, bool is_reply,
memset(&msg, 0, sizeof(msg));
if (is_reply) {
- hdr.flags.type = VFIO_USER_F_TYPE_REPLY;
+ hdr.flags |= VFIO_USER_F_TYPE_REPLY;
hdr.cmd = cmd;
if (err != 0) {
- hdr.flags.error = 1U;
+ hdr.flags |= VFIO_USER_F_ERROR;
hdr.error_no = err;
}
} else {
hdr.cmd = cmd;
- hdr.flags.type = VFIO_USER_F_TYPE_COMMAND;
+ hdr.flags |= VFIO_USER_F_TYPE_COMMAND;
}
iovecs[0].iov_base = &hdr;
@@ -211,18 +211,18 @@ tran_sock_recv_fds(int sock, struct vfio_user_header *hdr, bool is_reply,
return ERROR_INT(EPROTO);
}
- if (hdr->flags.type != VFIO_USER_F_TYPE_REPLY) {
+ if ((hdr->flags & VFIO_USER_F_TYPE_MASK) != VFIO_USER_F_TYPE_REPLY) {
return ERROR_INT(EINVAL);
}
- if (hdr->flags.error == 1U) {
+ if (hdr->flags & VFIO_USER_F_ERROR) {
if (hdr->error_no <= 0) {
hdr->error_no = EINVAL;
}
return ERROR_INT(hdr->error_no);
}
} else {
- if (hdr->flags.type != VFIO_USER_F_TYPE_COMMAND) {
+ if ((hdr->flags & VFIO_USER_F_TYPE_MASK) != VFIO_USER_F_TYPE_COMMAND) {
return ERROR_INT(EINVAL);
}
if (msg_id != NULL) {