From 3006e19e416bde18e6000171c710281eef8fee1d Mon Sep 17 00:00:00 2001 From: Lon Hohberger Date: Wed, 6 Jul 2011 12:17:42 -0400 Subject: [PATCH] Make fence-virt requests endian clean Signed-off-by: Lon Hohberger --- client/serial.c | 3 +++ include/xvm.h | 34 ++++++++++++++++++++++++++++++++++ server/mcast.c | 2 ++ server/serial.c | 2 ++ 4 files changed, 41 insertions(+) diff --git a/client/serial.c b/client/serial.c index 52c57ee..9312048 100644 --- a/client/serial.c +++ b/client/serial.c @@ -267,6 +267,7 @@ serial_fence_virt(fence_virt_args_t *args) tv.tv_sec = 3; tv.tv_usec = 0; + swab_serial_req_t(&req); ret = _write_retry(fd, &req, sizeof(req), &tv); if (ret < sizeof(req)) { if (ret < 0) @@ -282,6 +283,8 @@ serial_fence_virt(fence_virt_args_t *args) sizeof(resp.magic), &tv) == 0) { ret = _read_retry(fd, &resp.response, sizeof(resp.response), &tv); } + + swab_serial_resp_t(&resp); } while(resp.magic != SERIAL_MAGIC && (tv.tv_sec || tv.tv_usec)); if (resp.magic != SERIAL_MAGIC) diff --git a/include/xvm.h b/include/xvm.h index e90f6d1..5b4cfe6 100644 --- a/include/xvm.h +++ b/include/xvm.h @@ -22,6 +22,8 @@ #include #include #include +#include +#include #define XVM_VERSION "1.9.0" @@ -85,6 +87,17 @@ typedef struct __attribute__ ((packed)) _fence_req { uint8_t hash[MAX_HASH_LENGTH]; /* Binary hash */ } fence_req_t; +#if __BYTE_ORDER == __BIG_ENDIAN +#define swab_fence_req_t(req) \ +do { \ + (req)->seqno = b_swap32((req)->seqno); \ + (req)->family = b_swap32((req)->family); \ + (req)->port = b_swap32((req)->port); \ +} while(0) +#else +#define swab_fence_req_t(req) +#endif + /* for host list */ typedef struct __attribute__ ((packed)) _host_info { @@ -108,11 +121,32 @@ typedef struct __attribute__((packed)) _serial_fence_req { uint32_t seqno; } serial_req_t; +#if __BYTE_ORDER == __BIG_ENDIAN +#define swab_serial_req_t(req) \ +do { \ + (req)->magic = b_swap32((req)->magic); \ + (req)->seqno = b_swap32((req)->seqno); \ +} while(0) +#else +#define swab_serial_req_t(req) +#endif + + typedef struct __attribute__((packed)) _serial_fense_resp { uint32_t magic; uint8_t response; } serial_resp_t; +#if __BYTE_ORDER == __BIG_ENDIAN +#define swab_serial_resp_t(req) \ +do { \ + (req)->magic = b_swap32((req)->magic); \ +} while(0) +#else +#define swab_serial_resp_t(req) +#endif + + #define RESP_SUCCESS 0 #define RESP_FAIL 1 #define RESP_OFF 2 diff --git a/server/mcast.c b/server/mcast.c index 6a5fa5a..dfd9ed9 100644 --- a/server/mcast.c +++ b/server/mcast.c @@ -364,6 +364,8 @@ mcast_dispatch(listener_context_t c, struct timeval *timeout) return len; } + swap_fence_req_t(&data); + if (!verify_request(&data, info->args.hash, info->key, info->key_len)) { printf("Key mismatch; dropping packet\n"); diff --git a/server/serial.c b/server/serial.c index 580a003..a750c88 100644 --- a/server/serial.c +++ b/server/serial.c @@ -230,6 +230,7 @@ do_fence_request(int fd, const char *src, serial_req_t *req, serial_info *info) resp.magic = SERIAL_MAGIC; resp.response = response; + swab_serial_resp_t(&resp); dbg_printf(3, "Sending response to caller...\n"); if (write(fd, &resp, sizeof(resp)) < 0) { @@ -289,6 +290,7 @@ serial_dispatch(listener_context_t c, struct timeval *timeout) else return 0; } else { + swab_serial_req_t(&data); break; } }