Make fence-virt requests endian clean
Signed-off-by: Lon Hohberger <lon@users.sourceforge.net>
This commit is contained in:
parent
583ce1146a
commit
3006e19e41
@ -267,6 +267,7 @@ serial_fence_virt(fence_virt_args_t *args)
|
|||||||
|
|
||||||
tv.tv_sec = 3;
|
tv.tv_sec = 3;
|
||||||
tv.tv_usec = 0;
|
tv.tv_usec = 0;
|
||||||
|
swab_serial_req_t(&req);
|
||||||
ret = _write_retry(fd, &req, sizeof(req), &tv);
|
ret = _write_retry(fd, &req, sizeof(req), &tv);
|
||||||
if (ret < sizeof(req)) {
|
if (ret < sizeof(req)) {
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
@ -282,6 +283,8 @@ serial_fence_virt(fence_virt_args_t *args)
|
|||||||
sizeof(resp.magic), &tv) == 0) {
|
sizeof(resp.magic), &tv) == 0) {
|
||||||
ret = _read_retry(fd, &resp.response, sizeof(resp.response), &tv);
|
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));
|
} while(resp.magic != SERIAL_MAGIC && (tv.tv_sec || tv.tv_usec));
|
||||||
|
|
||||||
if (resp.magic != SERIAL_MAGIC)
|
if (resp.magic != SERIAL_MAGIC)
|
||||||
|
@ -22,6 +22,8 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <sechash.h>
|
#include <sechash.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
|
#include <byteswap.h>
|
||||||
|
#include <endian.h>
|
||||||
|
|
||||||
#define XVM_VERSION "1.9.0"
|
#define XVM_VERSION "1.9.0"
|
||||||
|
|
||||||
@ -85,6 +87,17 @@ typedef struct __attribute__ ((packed)) _fence_req {
|
|||||||
uint8_t hash[MAX_HASH_LENGTH]; /* Binary hash */
|
uint8_t hash[MAX_HASH_LENGTH]; /* Binary hash */
|
||||||
} fence_req_t;
|
} 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 */
|
/* for host list */
|
||||||
typedef struct __attribute__ ((packed)) _host_info {
|
typedef struct __attribute__ ((packed)) _host_info {
|
||||||
@ -108,11 +121,32 @@ typedef struct __attribute__((packed)) _serial_fence_req {
|
|||||||
uint32_t seqno;
|
uint32_t seqno;
|
||||||
} serial_req_t;
|
} 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 {
|
typedef struct __attribute__((packed)) _serial_fense_resp {
|
||||||
uint32_t magic;
|
uint32_t magic;
|
||||||
uint8_t response;
|
uint8_t response;
|
||||||
} serial_resp_t;
|
} 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_SUCCESS 0
|
||||||
#define RESP_FAIL 1
|
#define RESP_FAIL 1
|
||||||
#define RESP_OFF 2
|
#define RESP_OFF 2
|
||||||
|
@ -364,6 +364,8 @@ mcast_dispatch(listener_context_t c, struct timeval *timeout)
|
|||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
swap_fence_req_t(&data);
|
||||||
|
|
||||||
if (!verify_request(&data, info->args.hash, info->key,
|
if (!verify_request(&data, info->args.hash, info->key,
|
||||||
info->key_len)) {
|
info->key_len)) {
|
||||||
printf("Key mismatch; dropping packet\n");
|
printf("Key mismatch; dropping packet\n");
|
||||||
|
@ -230,6 +230,7 @@ do_fence_request(int fd, const char *src, serial_req_t *req, serial_info *info)
|
|||||||
|
|
||||||
resp.magic = SERIAL_MAGIC;
|
resp.magic = SERIAL_MAGIC;
|
||||||
resp.response = response;
|
resp.response = response;
|
||||||
|
swab_serial_resp_t(&resp);
|
||||||
|
|
||||||
dbg_printf(3, "Sending response to caller...\n");
|
dbg_printf(3, "Sending response to caller...\n");
|
||||||
if (write(fd, &resp, sizeof(resp)) < 0) {
|
if (write(fd, &resp, sizeof(resp)) < 0) {
|
||||||
@ -289,6 +290,7 @@ serial_dispatch(listener_context_t c, struct timeval *timeout)
|
|||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
|
swab_serial_req_t(&data);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user