📄 ipsecloggerkernel.c
字号:
/* ipsecLoggerKernel.c - IKE task component of callback system *//* * Copyright (c) 2004-2005 Wind River Systems, Inc. * * The right to copy, distribute, modify or otherwise make use * of this software may be licensed only pursuant to the terms * of an applicable Wind River license agreement. *//*modification history--------------------01b,16mar06,djp Added msg initialization to callback code01a,04may05,djp Added NOMANUAL to internal operations (SPR 108231)*//*DESCRIPTIONThis module implements the kernel component of the IPsec logger callbackfunctionality. The callback facilities implemented bundle the callback dataand send the data via message passing using named vxWorks message queues. It's primarily for vxWorks 6.0 but will work on 5.5 via the named message queue emulation library. *//* includes */#ifdef INCLUDE_LOGGING_IPSEC#include <vxWorks.h>#include <msgQLib.h>#include <socket.h>#include <string.h>#include <wrn/ipsec/ipsecLogger.h>#include "ipsec_logger.h"#include "../msgCLib/msgCLib.h"/* get named-msgq emulation header file if needed */#if (_WRS_VXWORKS_MAJOR < 6)#include "../msgCLib/namedMsgQ.h"#endifLOCAL void ipsecLoggerKernelCallback(u_char saFamily, UCHAR* srcIPAddr, UCHAR* dstIPAddr, unsigned int srcPort, unsigned int dstPort, int protocol, int spi, void* eventData, IPSEC_LOG_EVENT_ID eventId, IPSEC_LOG_REASON reasonId);LOCAL IPSEC_LOGGER_INFO ipsecLoggerInfo = { NULL, NULL, FALSE, FALSE };BOOL eventLogTable[IPSEC_LOG_EVENT_ID_MAX + 1];/****************************************************************************** ipsecLoggerKernelInit - initialize IKE Task callback facilities* * This routine initializes the IKE Task / kernel component of the IKE * callback capabilities. The operation initializes the callback pointers* to specials callback functions that package up the arguments and send them* via message Q to another waiting task (which can be running in another RTP).** RETURNS: OK on success, or ERROR if the callback info structure is not* successfully initialized.** NOMANUAL*/void ipsecLoggerKernelInit ( void ) { int i; ipsecLoggerInfoInit(&ipsecLoggerInfo); ipsecLoggerInfoCallbackSet(&ipsecLoggerInfo, ipsecLoggerKernelCallback); /* Initialize the event log table with all events turned on */ for (i = UNKNOWN_EVENT; i <= IPSEC_LOG_EVENT_ID_MAX; i++) { eventLogTable[i] = TRUE; } }/****************************************************************************** ipsecLoggerInvokeCallback - invoke the logger callback* * This routine invokes the logger callback. It is typically called from the* IPsec/IKE code. The operation, verifies the callback is valid and then calls* the callback routine. The operation grabs the logger info mutex, retrieves* the callback function pointer and then invokes the callback.** NOMANUAL*/void ipsecLoggerInvokeCallback ( u_char saFamily, UCHAR* srcIPAddr, UCHAR* dstIPAddr, unsigned int srcPort, unsigned int dstPort, int protocol, int spi, void* eventData, IPSEC_LOG_EVENT_ID eventId, IPSEC_LOG_REASON reasonId ) { FP_IPSEC_LOGGER_GLOBAL_CALLBACK callback; semTake(ipsecLoggerInfo.callbackInfoMutex, WAIT_FOREVER); callback = ipsecLoggerInfo.fpIpsecLogger; if (callback != NULL) { callback(saFamily, srcIPAddr, dstIPAddr, srcPort, dstPort, protocol, spi, eventData, eventId, reasonId); } semGive(ipsecLoggerInfo.callbackInfoMutex); }/*************************************************************************** ipsecLoggerKernelCallback - kernel callback for logger events** This routine provides the kernel callback for logger events. * The operation serializes the parameters and forwards the message to the* callback queue.*/LOCAL void ipsecLoggerKernelCallback ( u_char saFamily, UCHAR* srcIPAddr, UCHAR* dstIPAddr, unsigned int srcPort, unsigned int dstPort, int protocol, int spi, void* eventData, IPSEC_LOG_EVENT_ID eventId, IPSEC_LOG_REASON reasonId ) { IPSEC_LOGGER_MSG callbackMsg; memset(&callbackMsg, 0, sizeof(IPSEC_LOGGER_MSG)); ipsecLoggerEventSerialize(&callbackMsg, saFamily, srcIPAddr, dstIPAddr, srcPort, dstPort, protocol, spi, eventData, eventId, reasonId); ipsecLoggerQueueCallback(&callbackMsg); }/****************************************************************************** ipsecLoggerKernelShutdown - Shutdown the IPsec logger callback facilities* * This routine terminates the kernel component of the IPsec logger* callback capabilities. The operation clears the callback pointers* and deletes the callback mutex.** RETURNS: OK on success, or ERROR if the callback info structure is not* successfully initialized.** NOMANUAL*/void ipsecLoggerKernelShutdown ( void ) { ipsecLoggerInfoCallbackClear(&ipsecLoggerInfo); ipsecLoggerInfoClear(&ipsecLoggerInfo); }/********************************************************************************* ipsecLoggerLogEventEnabledSetHandler - enable logging of the specified event type** This routine sets the enable mode for the specified event identifier to the specified mode.** RETURNS: OK if specified event identifier is valid, FALSE otherwise* * ERRNO: N/A** NOMANUAL*/STATUS ipsecLoggerLogEventEnabledSetHandler ( IPSEC_LOG_EVENT_ID eventId, /* event id to enable/disable for logging*/ BOOL enable /* enable mode for event id */ ) { STATUS retCode = ERROR; semTake(ipsecLoggerInfo.callbackInfoMutex, WAIT_FOREVER); if ((eventId >= UNKNOWN_EVENT) && (eventId <= IPSEC_LOG_EVENT_ID_MAX)) { if (enable != FALSE) { enable = TRUE; } eventLogTable[eventId] = enable; retCode = OK; } semGive(ipsecLoggerInfo.callbackInfoMutex); return retCode; }/********************************************************************************* ipsecLoggerIsLogEventEnabled - check whether or not logging is enabled for the specified event type** This routine checks whether or not logging is enabled for the specified event type.** RETURNS: TRUE if logging is enabled for the specified event type, FALSE otherwise. FALSE* is also returned if the specified event identifier is not valid.** ERRNO: N/A* NOMANUAL*/BOOL ipsecLoggerIsLogEventEnabled ( IPSEC_LOG_EVENT_ID eventId /* event id to check enable mode for */ ) { BOOL enabled = FALSE; semTake(ipsecLoggerInfo.callbackInfoMutex, WAIT_FOREVER); if (ipsecLoggerInfo.isLoggerEnabled) { if ((eventId >= UNKNOWN_EVENT) && (eventId <= IPSEC_LOG_EVENT_ID_MAX)) { enabled = eventLogTable[eventId]; } } semGive(ipsecLoggerInfo.callbackInfoMutex); return enabled; }#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -