From d8aa470192b53b7f1bd51c6d9481c64275f80a1a Mon Sep 17 00:00:00 2001 From: Davide Beatrici Date: Wed, 29 Jul 2020 20:00:46 +0200 Subject: [PATCH] Cedar: Improve IsPacketForMe()'s "data" argumment in PROTO_IMPL This allows a protocol implementation to implicitly cast the variable to the type it prefers. --- src/Cedar/Proto.h | 2 +- src/Cedar/Proto_OpenVPN.c | 15 ++++++++------- src/Cedar/Proto_OpenVPN.h | 4 +--- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/Cedar/Proto.h b/src/Cedar/Proto.h index 63f1b360..e0714cab 100644 --- a/src/Cedar/Proto.h +++ b/src/Cedar/Proto.h @@ -48,7 +48,7 @@ typedef struct PROTO_IMPL const PROTO_OPTION *(*Options)(); bool (*Init)(void **param, const LIST *options, CEDAR *cedar, INTERRUPT_MANAGER *im, SOCK_EVENT *se, const char *cipher, const char *hostname); void (*Free)(void *param); - bool (*IsPacketForMe)(const PROTO_MODE mode, const UCHAR *data, const UINT size); + bool (*IsPacketForMe)(const PROTO_MODE mode, const void *data, const UINT size); bool (*ProcessData)(void *param, TCP_RAW_DATA *in, FIFO *out); bool (*ProcessDatagrams)(void *param, LIST *in, LIST *out); } PROTO_IMPL; diff --git a/src/Cedar/Proto_OpenVPN.c b/src/Cedar/Proto_OpenVPN.c index a466a9c1..a801c4b1 100644 --- a/src/Cedar/Proto_OpenVPN.c +++ b/src/Cedar/Proto_OpenVPN.c @@ -69,16 +69,17 @@ void OvsFree(void *param) } // Check whether it's an OpenVPN packet -bool OvsIsPacketForMe(const PROTO_MODE mode, const UCHAR *data, const UINT size) +bool OvsIsPacketForMe(const PROTO_MODE mode, const void *data, const UINT size) { + if (data == NULL || size < 2) + { + return false; + } + if (mode == PROTO_MODE_TCP) { - if (data == NULL || size < 2) - { - return false; - } - - if (data[0] == 0x00 && data[1] == 0x0E) + const UCHAR *raw = data; + if (raw[0] == 0x00 && raw[1] == 0x0E) { return true; } diff --git a/src/Cedar/Proto_OpenVPN.h b/src/Cedar/Proto_OpenVPN.h index 8a5c111d..78204cc3 100644 --- a/src/Cedar/Proto_OpenVPN.h +++ b/src/Cedar/Proto_OpenVPN.h @@ -215,11 +215,9 @@ const char *OvsName(); const PROTO_OPTION *OvsOptions(); bool OvsInit(void **param, const LIST *options, CEDAR *cedar, INTERRUPT_MANAGER *im, SOCK_EVENT *se, const char *cipher, const char *hostname); void OvsFree(void *param); -bool OvsIsPacketForMe(const PROTO_MODE mode, const UCHAR *data, const UINT size); +bool OvsIsPacketForMe(const PROTO_MODE mode, const void *data, const UINT size); bool OvsProcessData(void *param, TCP_RAW_DATA *in, FIFO *out); bool OvsProcessDatagrams(void *param, LIST *in, LIST *out); -bool OvsIsOk(void *param); -UINT OvsEstablishedSessions(void *param); OPENVPN_SERVER *NewOpenVpnServer(const LIST *options, CEDAR *cedar, INTERRUPT_MANAGER *interrupt, SOCK_EVENT *sock_event); void FreeOpenVpnServer(OPENVPN_SERVER *s);