|
From: | Alexandre Malo |
Subject: | Re: [lwip-users] memory leak when sending snmp trap |
Date: | Tue, 16 Jun 2009 10:39:57 -0400 |
Here is the function that could be use as
example
It is possible to have more than one
vSendTrapTaskDemo
private_trap only have the prototypes
What do you think?
#include "lwip/opt.h"
#if LWIP_SNMP
#include "lwip/inet.h"
#include "lwip/snmp_msg.h" #include "lwip/snmp_asn1.h" #include "lwip/tcpip.h" #include "Printf.h" #include "private_trap.h" #include "stdlib.h" #define NUM_PRIVATE_TRAP_LIST
5
static unsigned char SNMP_TRAP_0_FLAG =
1;
static struct ip_addr SNMP_TRAP_0_ADDR; extern struct snmp_msg_trap trap_msg;
struct trap_list
{ struct snmp_varbind_root vb_root; struct snmp_obj_id *ent_oid; s32_t spc_trap; u8_t in_use; }; struct trap_list
trap_list_bank[NUM_PRIVATE_TRAP_LIST];
xSemaphoreHandle getTrapListSema = NULL; void vSNMP_Trap_Init( )
{ /* Set SNMP Trap destination */ IP4_ADDR( &SNMP_TRAP_0_ADDR, 172, 27, 37, 70); snmp_trap_dst_ip_set(0,&SNMP_TRAP_0_ADDR); snmp_trap_dst_enable(0,SNMP_TRAP_0_FLAG); getTrapListSema = sys_sem_new(0); } struct trap_list *
getNextFreePrivateTrapList()
{ u8_t index; struct trap_list * result = NULL; xSemaphoreTake(getTrapListSema, (portTickType) 10); for(index = 0; index < NUM_PRIVATE_TRAP_LIST; index++) { if(!trap_list_bank[index].in_use) { trap_list_bank[index].in_use = 1; result = &trap_list_bank[index]; break; } } xSemaphoreGive(getTrapListSema); return result; } void freePrivateTrapList(struct trap_list *
list)
{ snmp_varbind_list_free(&list->vb_root); list->ent_oid = NULL; list->spc_trap = 0; list->in_use = 0; } void vSendTrapCallback( void * parameters
)
{ struct trap_list * param; if( parameters != NULL ) { param = (struct trap_list *) parameters; trap_msg.outvb = param->vb_root; snmp_send_trap(SNMP_GENTRAP_ENTERPRISESPC, param->ent_oid, param->spc_trap); freePrivateTrapList(param); } } void vSendTrapTaskDemo( void * pvParameters
)
{ portTickType xLastWakeTime; struct snmp_obj_id objid = {MY_SNMP_SYSOBJID_LEN, MY_SNMP_SYSOBJID}; static unsigned char msg[] = "Alexandre_Malo-mpbc_ca"; static unsigned char msg2[] = "salut simon, c'est mal"; static unsigned char msglen= 22; struct snmp_varbind *vb; struct trap_list *vb_list; (void) pvParameters; for ( ;; ) { xLastWakeTime = xTaskGetTickCount(); vb_list = getNextFreePrivateTrapList(); vb_list->ent_oid = &objid; vb_list->spc_trap = 12; vb = snmp_varbind_alloc(&objid, SNMP_ASN1_OPAQUE, msglen); if (vb != NULL) { memcpy (vb->value, &msg, msglen); snmp_varbind_tail_add(&vb_list->vb_root,vb); } vb = snmp_varbind_alloc(&objid, SNMP_ASN1_OPAQUE, msglen); if (vb != NULL) { memcpy (vb->value, &msg2, msglen); snmp_varbind_tail_add(&vb_list->vb_root,vb); } tcpip_callback(vSendTrapCallback, vb_list); // Wait for the next cycle. vTaskDelayUntil( &xLastWakeTime, 100); } } #endif//LWIP_SNMP
|
[Prev in Thread] | Current Thread | [Next in Thread] |