Make fence-virt requests endian clean

Signed-off-by: Lon Hohberger <lon@users.sourceforge.net>
This commit is contained in:
Lon Hohberger 2011-07-06 12:17:42 -04:00
parent 583ce1146a
commit 3006e19e41
4 changed files with 41 additions and 0 deletions

View File

@ -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)

View File

@ -22,6 +22,8 @@
#include <stdint.h>
#include <sechash.h>
#include <netinet/in.h>
#include <byteswap.h>
#include <endian.h>
#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

View File

@ -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");

View File

@ -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;
}
}