server header validation, handle ping message

This commit is contained in:
pantonshire committed 2026-03-08 08:50:40 +00:00
1 parent 001414baa4
commit 6f909a752b
2 files changed
+47 -26

No files matched your search

+23 -4
View File
@@ -10,9 +10,11 @@
#define OWD_DATA_LEN(HDR) (offsetof(__typeof__(HDR), _data_end))
enum owd_msg_type {
OWD_MSG_ERR,
OWD_MSG_SYNC_REQUEST,
OWD_MSG_SYNC_RESPONSE,
OWD_MSG_ERR = 0,
OWD_MSG_PING = 1,
OWD_MSG_PONG = 2,
OWD_MSG_SYNC_REQUEST = 3,
OWD_MSG_SYNC_RESPONSE = 4,
};
enum owd_error_code {
@@ -30,6 +32,7 @@ struct owdhdr {
uint8_t version;
uint8_t msg_type;
uint16_t length;
uint32_t tid;
};
struct owd_msg_err {
@@ -44,9 +47,25 @@ struct owd_msg_sync_response {
OWD_DECL_DATA_END;
};
static inline void owd_hdr_populate(struct owdhdr *hdr, uint8_t msg_type, uint16_t length) {
static inline void owd_hdr_populate(
struct owdhdr *hdr,
uint8_t msg_type,
uint16_t length,
uint32_t tid)
{
hdr->magic = htonl(OWD_MAGIC);
hdr->version = OWD_VERSION;
hdr->msg_type = msg_type;
hdr->length = htons(length);
hdr->tid = htonl(tid);
}
static inline int owd_hdr_validate(struct owdhdr *hdr, ssize_t len) {
if (len < sizeof(struct owdhdr))
return 1;
if (hdr->magic != ntohl(OWD_MAGIC))
return 1;
if (hdr->version != OWD_VERSION)
return 1;
return 0;
}