368 lines
11 KiB
C
368 lines
11 KiB
C
|
|
/*
|
|
******************************************************************************
|
|
* INTERPEAK SOURCE FILE
|
|
*
|
|
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: ipmip_log.c,v $ $Revision: 1.5 $
|
|
* $Source: /home/interpeak/CVSRoot/ipmip/src/ipmip_log.c,v $
|
|
* $Author: jhorteli $
|
|
* $State: Exp $ $Locker: $
|
|
*
|
|
* INTERPEAK_COPYRIGHT_STRING
|
|
* Design and implementation by Joel Hortelius <joel.hortelis@interpeak.se>
|
|
******************************************************************************
|
|
*/
|
|
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 1 DESCRIPTION
|
|
****************************************************************************
|
|
*/
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 2 CONFIGURATION
|
|
****************************************************************************
|
|
*/
|
|
|
|
#include "ipmip_config.h"
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 3 INCLUDE FILES
|
|
****************************************************************************
|
|
*/
|
|
#define IPCOM_USE_CLIB_PROTO
|
|
#include <ipcom_clib.h>
|
|
#include <ipcom_drv_eth_filter.h>
|
|
#include <ipcom_err.h>
|
|
#include <ipcom_hash.h>
|
|
#include <ipcom_inet.h>
|
|
#include <ipcom_ipd.h>
|
|
#include <ipcom_list.h>
|
|
#include <ipcom_os.h>
|
|
#include <ipcom_sock.h>
|
|
#include <ipcom_sock2.h>
|
|
#include <ipcom_sysctl.h>
|
|
#include <ipcom_syslog.h>
|
|
#include <ipcom_netif.h>
|
|
#include <ipcom_sysvar.h>
|
|
|
|
#include <ipmip.h>
|
|
#include <private/ipmip_context.h>
|
|
#include <private/ipmip_ntop.h>
|
|
#include <private/ipmip_cli.h>
|
|
#include <private/ipmip_util.h>
|
|
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 4 DEFINES
|
|
****************************************************************************
|
|
*/
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 5 TYPES
|
|
****************************************************************************
|
|
*/
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 6 EXTERN PROTOTYPES
|
|
****************************************************************************
|
|
*/
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 7 LOCAL PROTOTYPES
|
|
****************************************************************************
|
|
*/
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 8 DATA
|
|
****************************************************************************
|
|
*/
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 9 STATIC FUNCTIONS
|
|
****************************************************************************
|
|
*/
|
|
IP_STATIC void
|
|
ipmip_log_event_delete_locked(Ipmip_context_t *ctx)
|
|
{
|
|
Ipmip_log_event_t *ev = IPCOM_LIST_LAST(&ctx->log.events);
|
|
|
|
if (ev)
|
|
{
|
|
ipcom_list_remove(&ev->next);
|
|
if (ev->event)
|
|
ipcom_free(ev->event);
|
|
ipcom_free(ev);
|
|
}
|
|
}
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 10 GLOBAL FUNCTIONS
|
|
****************************************************************************
|
|
*/
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipmip_log_event_add
|
|
*===========================================================================
|
|
* Description:
|
|
* Parameters:
|
|
* Returns:
|
|
*
|
|
*/
|
|
IP_GLOBAL void
|
|
ipmip_log_event_add(Ipmip_context_t *ctx,
|
|
Ipmip_proc_t *proc,
|
|
const char *format,
|
|
...)
|
|
{
|
|
va_list ap;
|
|
va_start(ap, format);
|
|
ipmip_log_event_vadd(ctx, proc, format, ap);
|
|
va_end(ap);
|
|
}
|
|
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipmip_log_event_vadd
|
|
*===========================================================================
|
|
* Description:
|
|
* Parameters:
|
|
* Returns:
|
|
*
|
|
*/
|
|
IP_GLOBAL void
|
|
ipmip_log_event_vadd(Ipmip_context_t *ctx,
|
|
Ipmip_proc_t *proc,
|
|
const char *format,
|
|
va_list ap)
|
|
{
|
|
if (ctx->log.events_max > 0)
|
|
{
|
|
Ip_u32 loglevel = IPCOM_LOG_PRI(proc->args.arg32);
|
|
if (loglevel <= ctx->log.loglevel)
|
|
{
|
|
Ipmip_log_event_t *ev = ipcom_calloc(1, sizeof(*ev));
|
|
if (ev)
|
|
{
|
|
ev->event = ipmip_util_vstrdup(format, ap);
|
|
|
|
if (ev->event == IP_NULL)
|
|
{
|
|
ipcom_free(ev);
|
|
return;
|
|
}
|
|
|
|
ev->when = ipmip_util_time();
|
|
ev->level = loglevel;
|
|
|
|
ipcom_mutex_lock(ctx->log.events_lock);
|
|
ipcom_list_insert_first(&ctx->log.events, &ev->next);
|
|
if (ctx->log.events.size > ctx->log.events_max)
|
|
ipmip_log_event_delete_locked(ctx);
|
|
|
|
ipcom_syslog(proc->args.arg32, "%s#%d: %s", ctx->name, ctx->vr, ev->event);
|
|
ipcom_mutex_unlock(ctx->log.events_lock);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipmip_log_event_delete
|
|
*===========================================================================
|
|
* Description: Delete an error from the system
|
|
* Parameters:
|
|
* Returns:
|
|
*
|
|
*/
|
|
IP_GLOBAL void
|
|
ipmip_log_event_delete(Ipmip_context_t *ctx,
|
|
Ipmip_proc_t *proc)
|
|
{
|
|
IPMIP_UNUSED_PARAMETER(proc);
|
|
ipcom_mutex_lock(ctx->log.events_lock);
|
|
ipmip_log_event_delete_locked(ctx);
|
|
ipcom_mutex_unlock(ctx->log.events_lock);
|
|
}
|
|
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipmip_log_event_flush
|
|
*===========================================================================
|
|
* Description: Flush all events from the system
|
|
* Parameters:
|
|
* Returns:
|
|
*
|
|
*/
|
|
IP_GLOBAL void
|
|
ipmip_log_event_flush(Ipmip_context_t *ctx,
|
|
Ipmip_proc_t *proc)
|
|
{
|
|
IPMIP_UNUSED_PARAMETER(proc);
|
|
ipcom_mutex_lock(ctx->log.events_lock);
|
|
while (ctx->log.events.size > 0)
|
|
ipmip_log_event_delete_locked(ctx);
|
|
ipcom_mutex_unlock(ctx->log.events_lock);
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipmip_log_attr_request_events
|
|
*===========================================================================
|
|
* Description:
|
|
* Parameters:
|
|
* Returns:
|
|
*
|
|
*/
|
|
IP_GLOBAL Ip_size_t
|
|
ipmip_log_attr_request_events(Ipmip_context_t *ctx,
|
|
Ipmip_proc_t *proc,
|
|
struct Ipmip_cli_message *request)
|
|
{
|
|
struct Ipmip_attr_header *hdr = (struct Ipmip_attr_header *)IPMIP_BUFFER_DATA(&request->request);
|
|
Ip_size_t rhdr;
|
|
Ipmip_log_event_t *ev;
|
|
|
|
IPMIP_UNUSED_PARAMETER(proc);
|
|
|
|
rhdr = ipmip_attr_hdr_ack(&request->message, hdr);
|
|
|
|
ipcom_mutex_lock(ctx->log.events_lock);
|
|
/**/
|
|
for (ev = IPCOM_LIST_LAST(&ctx->log.events); ev != IP_NULL; ev = IPCOM_LIST_PREV(&ev->next))
|
|
{
|
|
Ip_size_t rta = ipmip_attr_begin(&request->message, IPMIP_CLI_ITEM_EVENT);
|
|
ipmip_attr_put_time_t(&request->message, IPMIP_CLI_ITEM_EVENT_TIME, ev->when);
|
|
ipmip_attr_put_u32(&request->message, IPMIP_CLI_ITEM_EVENT_LEVEL, ev->level);
|
|
ipmip_attr_put_str(&request->message, IPMIP_CLI_ITEM_EVENT_MESSAGE, ev->event);
|
|
ipmip_attr_end(&request->message, rta);
|
|
}
|
|
ipcom_mutex_unlock(ctx->log.events_lock);
|
|
|
|
return rhdr;
|
|
|
|
}
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipmip_log_attr_request_history
|
|
*===========================================================================
|
|
* Description:
|
|
* Parameters:
|
|
* Returns:
|
|
*
|
|
*/
|
|
IP_GLOBAL Ip_size_t
|
|
ipmip_log_attr_request_history(Ipmip_context_t *ctx,
|
|
Ipmip_proc_t *proc,
|
|
struct Ipmip_cli_message *request)
|
|
{
|
|
struct Ipmip_attr_header *hdr = (struct Ipmip_attr_header *)IPMIP_BUFFER_DATA(&request->request);
|
|
Ip_size_t rhdr;
|
|
|
|
IPMIP_UNUSED_PARAMETER(proc);
|
|
|
|
rhdr = ipmip_attr_hdr_ack(&request->message, hdr);
|
|
ipmip_attr_put_u32(&request->message, IPMIP_CLI_ITEM_SIZE, ctx->log.events_max);
|
|
|
|
return rhdr;
|
|
}
|
|
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipmip_log_attr_request_loglevel
|
|
*===========================================================================
|
|
* Description:
|
|
* Parameters:
|
|
* Returns:
|
|
*
|
|
*/
|
|
IP_GLOBAL Ip_size_t
|
|
ipmip_log_attr_request_loglevel(Ipmip_context_t *ctx,
|
|
Ipmip_proc_t *proc,
|
|
struct Ipmip_cli_message *request)
|
|
{
|
|
struct Ipmip_attr_header *hdr = (struct Ipmip_attr_header *)IPMIP_BUFFER_DATA(&request->request);
|
|
Ip_size_t rhdr;
|
|
|
|
IPMIP_UNUSED_PARAMETER(proc);
|
|
|
|
rhdr = ipmip_attr_hdr_ack(&request->message, hdr);
|
|
ipmip_attr_put_u32(&request->message, IPMIP_CLI_ITEM_SIZE, ctx->log.loglevel);
|
|
|
|
return rhdr;
|
|
}
|
|
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipmip_log_event_backlog
|
|
*===========================================================================
|
|
* Description:
|
|
* Parameters:
|
|
* Returns:
|
|
*
|
|
*/
|
|
IP_GLOBAL void
|
|
ipmip_log_event_backlog(Ipmip_context_t *ctx,
|
|
Ipmip_proc_t *proc,
|
|
Ip_u32 backlog)
|
|
{
|
|
IPMIP_UNUSED_PARAMETER(proc);
|
|
|
|
ipcom_mutex_lock(ctx->log.events_lock);
|
|
while (ctx->log.events.size > backlog)
|
|
ipmip_log_event_delete_locked(ctx);
|
|
ctx->log.events_max = backlog;
|
|
ipcom_mutex_unlock(ctx->log.events_lock);
|
|
}
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipmip_log_event_backlog
|
|
*===========================================================================
|
|
* Description:
|
|
* Parameters:
|
|
* Returns:
|
|
*
|
|
*/
|
|
IP_GLOBAL void
|
|
ipmip_log_loglevel(Ipmip_context_t *ctx,
|
|
Ipmip_proc_t *proc,
|
|
Ip_u32 loglevel)
|
|
{
|
|
IPMIP_UNUSED_PARAMETER(proc);
|
|
ctx->log.loglevel = loglevel;
|
|
}
|
|
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 11 PUBLIC FUNCTIONS
|
|
****************************************************************************
|
|
*/
|
|
|
|
/*
|
|
****************************************************************************
|
|
* END OF FILE
|
|
****************************************************************************
|
|
*/
|