Cache helper doesn't work with cross-compiled net-snmp-5.7.2.1

2014-03-31 Thread Ekaterina Potachits
Hi All,

I built the last version of the net-snmp-5.7.2.1 using the
arm-linux-gcc compiler with the following flags:
CC=arm-linux-gcc ./configure --target=arm-linux --host=arm-linux --build=x86 \.
--program-prefix=/usr --prefix=/usr --exec-prefix=/usr --with-endianness=big \.
--enable-privacy --enable-des --enable-md5 --without-rpm --enable-shared \
--with-cflags="-O2 -fsigned-char -I$WORKSPACE/Build/target/usr/include" \
--with-persistent-directory=/var/net-snmp --with-copy-persistent-files="no" \
--with-out-mib-modules="ucd_snmp notification notification-log-mib
target utilities  disman/event disman/schedule host" \.
--sysconfdir=/conf  --with-openssl=internal  --disable-embedded-perl \.
--disable-perl-cc-checks --with-perl-modules=no
--with-sys-contact=root@localhost \
--disable-manuals --disable-scripts --disable-applications
--disable-mibs --disable-mib-loading \
--disable-deprecated --enable-ipv6 --with-default-snmp-version="3" \.
--with-sys-location="Unknown" --with-logfile=/var/log/snmpd.log
--with-security-modules="usm tsm"

The cross-compiled net-snmp libraries I use in my sub-agent implementation.
And it seems that the cache helper doesn't work in my case.
Before I decided to use the  net-snmp-5.7.2 I use the  net-snmp-5.4.3
and everything works fine.

My sub-agent uses the cache mechanism to update the particular MIB
table before the GET/GETNEXT request comes.
In my case the first calling of the cache load works fine but after
the cache timeout expires the sub-agents crashes with segmentation
fault and the snmpwalk command gets the message: "Error in packet.
Reason: (genError) A general failure occured Failed object:
iso.3.6.1.4.1.231.2.10.2.2.10.3.1."

I analysed the core dump of my application with gdb and it shows, that
sub-agent crashes in the _cache_load () when it tries to call the
_cache_free().

Maybe somebody can help me and explain what is wrong?

I have the following code:

  struct ManagementNodeTable_entry {
  long mnUnitId;
  long mnNodeNr;
  ...
};


#define MANAGEMENTNODETABLE_TIMEOUT  10


initialize_table_ManagementNodeTable(void)
{
  oid ManagementNodeTable_oid[] = { 1, 3, 6, 1, 4, 1, 231, 2, 10, 2,
2, 10, 3, 1 };
  size_t ManagementNodeTable_oid_len = OID_LENGTH(ManagementNodeTable_oid);
  netsnmp_tdata  *table_data = NULL;
  netsnmp_handler_registration *reg;
  netsnmp_table_registration_info *table_info;
  netsnmp_cache  *cache;
  reg = netsnmp_create_handler_registration("ManagementNodeTable",
ManagementNodeTable_handler,
ManagementNodeTable_oid,
ManagementNodeTable_oid_len,
HANDLER_CAN_RONLY);
  table_data = netsnmp_tdata_create_table("ManagementNodeTable", 0);
  if (NULL == table_data) {
snmp_log(LOG_ERR,
 "error creating tdata table for ManagementNodeTable\n");
return;
  }

  cache = netsnmp_cache_create(MANAGEMENTNODETABLE_TIMEOUT,
   ManagementNodeTable_load,
   ManagementNodeTable_free,
   ManagementNodeTable_oid,
   ManagementNodeTable_oid_len);
  if (NULL == cache) {
snmp_log(LOG_ERR,
 "error creating cache for ManagementNodeTable\n");
return;
  }
  else {
cache->magic = (void *) table_data;
cache->flags |= (NETSNMP_CACHE_DONT_FREE_BEFORE_LOAD |
NETSNMP_CACHE_DONT_FREE_EXPIRED | NETSNMP_CACHE_DONT_AUTO_RELEASE);
  }

  table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);
  if (NULL == table_info) {
snmp_log(LOG_ERR,
 "error creating table info for ManagementNodeTable\n");
return;
  }
  netsnmp_table_helper_add_indexes(table_info,
   ASN_INTEGER,   /* index: mnUnitId */
   ASN_INTEGER,   /* index: mnNodeNr */
   0);

  table_info->min_column = COLUMN_MNUNITID;
  table_info->max_column = COLUMN_UNITNODECONTROLLERFWVERSION;
  netsnmp_tdata_register(reg, table_data, table_info);

  if (cache) {
netsnmp_inject_handler (reg,
netsnmp_cache_handler_get(cache)
   );
  }
}


/** Create a new row in the table */
netsnmp_tdata_row *
ManagementNodeTable_createEntry (netsnmp_tdata *table_data,
 struct ManagementNodeTable_entry *srcEntry)
{
  struct ManagementNodeTable_entry *destEntry;
  netsnmp_tdata_row *row;

  destEntry = SNMP_MALLOC_TYPEDEF (struct ManagementNodeTable_entry);
  if (!destEntry)
return NULL;
  row = netsnmp_tdata_create_row();
  if (!row) {
SNMP_FREE (destEntry);
return NULL;
  }

  memcpy (destEntry, srcEntry, sizeof (struct ManagementNodeTable_entry));
  row->data = destEntry;

  netsnmp_tdata_row_add_index (row, ASN_INTEGER,
   &(destEntry->mnUnitId),
 

Re: Building net-snmp for HP-UX

2014-03-31 Thread Niels Baggesen
Den 31-03-2014 08:34, Niels Baggesen skrev:
> On Fri, Mar 28, 2014 at 02:02:08PM +0100, Joel Hansell wrote:
>> No luck there either, I'm afraid. Same old depressing output after
>> replacing that line and re-compiling.
>> (Used host name in the snmpTrapdAddr directive, this time, same result as
>> with ip address.)
>
> It was ua bit of a long shot :-) It might even be that it does not take
> that code path ...

OK, according to the config it should take that path 

Here is an extended patch, with some more debug. Could you try that?


diff --git a/snmplib/transports/snmpUDPBaseDomain.c 
b/snmplib/transports/snmpUDPBaseDomain.c
index 58b6fde..8618423 100644
--- a/snmplib/transports/snmpUDPBaseDomain.c
+++ b/snmplib/transports/snmpUDPBaseDomain.c
@@ -386,7 +386,7 @@ netsnmp_udpbase_recv(netsnmp_transport *t, void 
*buf, int size,
   void **opaque, int *olength)
  {
  int rc = -1;
-socklen_t   fromlen = sizeof(struct sockaddr);
+socklen_t   fromlen = sizeof(netsnmp_sockaddr_storage);
  netsnmp_indexed_addr_pair *addr_pair = NULL;
  struct sockaddr *from;

@@ -409,6 +409,12 @@ netsnmp_udpbase_recv(netsnmp_transport *t, void 
*buf, int size,
&local_addr_len, 
&(addr_pair->if_index));
  #else
  rc = recvfrom(t->sock, buf, size, MSG_DONTWAIT, from, 
&fromlen);
+   DEBUGMSGTL(("netsnmp_udp", "fromlen=%d->%d, af=%d\n",
+   sizeof(netsnmp_sockaddr_storage),
+   fromlen, from->sa_family));
+   DEBUGMSGTL(("netsnmp_udp", "port=%hu, addr=%08lx\n",
+   ntohs(((struct sockaddr_in *)from)->sin_port),
+   (long)((struct sockaddr_in *)from)->sin_addr.s_addr));
  #endif /* netsnmp_udpbase_recvfrom_sendto_defined */
 if (rc < 0 && errno != EINTR) {
 break;

(even if the patchis f***ed up in the mail, it should be simple enough 
to do by hand :-)

/Niels

-- 
Niels Baggesen - @home - Ã…rhus - Denmark - n...@users.sourceforge.net
The purpose of computing is insight, not numbers   ---   R W Hamming

--
___
Net-snmp-coders mailing list
Net-snmp-coders@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders