agent is not responding

Li Juen Hwang <[email protected]>
Newsgroups gmane.network.net-snmp.user
Message-ID <[email protected]>

Hi,

    I am using net-snmp-5.2.1 to buid an snmp agent.
    The source code of my agent was created by running mib2c on my MIB files
    with mib2c.scalar.conf and mib2c.iterate_access.conf.
    The binary code of my agent is linked with the snmp libraries of 
net-snmp-5.2.1.
    I placed snmpd.conf, snmp.conf under ~/.snmp and my MIB files under 
.snmp/mibs
    for root and for a normal user.
    Then as root (note: normal user would fail), i invoked my agent 
(darRecorder) which
    was listening on udp:161 and waiting for snmp requests in 
agent_check_and_process().

    When i (either as root or normal user)  tried "snmpget -v 2c -c 
public localhost darDeviceType.0",
    i got "Timeout: No Response from localhost." (darDeviceType is an 
integer)

    i turned on debugging in snmp.conf, i got a lot of messages and the 
following are the trailing
    statements.

dumpv_send:         Integer: 1 (0x01)
trace: _snmp_build(): snmp_api.c, 2924:
dumph_send: SNMPv2c Message
trace: netsnmp_udp_send(): snmpUDPDomain.c, 167:
netsnmp_udp: send 47 bytes from 0x818dde9 to UDP: [127.0.0.1]:161 on fd 3
trace: snmp_sess_select_info(): snmp_api.c, 5702:
sess_select: for all sessions: 3 (to in 1138071566.256498 sec)
verbose:sess_select: timer due in 0.999962 sec
verbose:sess_select: setting timer to 0.999962 sec, clear block (was 1)
trace: snmp_sess_select_info(): snmp_api.c, 5702:
sess_select: for all sessions: 3 (to in 1138071566.256498 sec)
verbose:sess_select: timer due *real* soon. 506 usec
verbose:sess_select: setting timer to 0.506 sec, clear block (was 1)
Timeout: No Response from localhost.

    It looked like application was sending the right stuff to the agent.
   When i turned on debugging on agent (-DALL),  it looked like
    the agent received the packet, but somehow "handle_darDeviceType()"
    did not get invoked. Did i miss something?
    Some of the debugging messages of agent follows. And
    darRecorder_subagent.c (created by mib2c -c subagent.m2c darRecorder)
    is attached.

    Thanks for your help very much.

    Li-Juen


dumph_recv:         Name
dumpx_recv:          06 0C 2B 06 01 04 01 49 17 02 02 02 01 00
 
dumpv_recv:            ObjID: DAR-COMMON::darDeviceType.0
trace: snmp_pdu_parse(): snmp_api.c, 4339:
dumph_recv:         Value
trace: init_agent_snmp_session(): snmp_agent.c, 1244:
snmp_agent: agent_sesion 0x9891828 created
trace: init_agent_snmp_session(): snmp_agent.c, 1259:
verbose:asp: asp 0x9891828 reqinfo 0x9891a20 created
trace: snmp_call_callbacks(): callback.c, 205:
callback: START calling callbacks for maj=1 min=5
trace: snmp_call_callbacks(): callback.c, 219:
callback: calling a callback for maj=1 min=5
trace: vacm_in_view(): mibgroup/mibII/vacm_conf.c, 708:
mibII/vacm_vars: vacm_in_view: ver=1, community=public
trace: netsnmp_udp_getSecName(): snmpUDPDomain.c, 1005:
netsnmp_udp_getSecName: no com2sec entries
trace: vacm_in_view(): mibgroup/mibII/vacm_conf.c, 806:
mibII/vacm_vars: vacm_in_view: No security name found
trace: snmp_call_callbacks(): callback.c, 231:
callback: END calling callbacks for maj=1 min=5 (1 called)
trace: netsnmp_send_traps(): agent_trap.c, 616:
trap: send_trap 4 0 NET-SNMP-MIB::netSnmpAgentOIDs.10trace: 
netsnmp_send_traps(): agent_trap.c, 618:
trap:
trace: snmp_call_callbacks(): callback.c, 205:
callback: START calling callbacks for maj=1 min=6
trace: snmp_call_callbacks(): callback.c, 231:
callback: END calling callbacks for maj=1 min=6 (0 called)
trace: snmp_call_callbacks(): callback.c, 205:
callback: START calling callbacks for maj=1 min=7
trace: snmp_call_callbacks(): callback.c, 231:
callback: END calling callbacks for maj=1 min=7 (0 called)
trace: netsnmp_remove_and_free_agent_snmp_session(): snmp_agent.c, 1657:
snmp_agent: REMOVE session == 0x9891828
darRecorder_subagent.c (text/x-c, 5.6 KB)
/*
 * Note: this file originally auto-generated by mbi2c using
 *       version : 1.5.2.1 $ of : subagent.m2c,v $ 
 */
/*
 * standard Net-SNMP includes 
 */
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>

/*
 * include our parent header 
 */
#include "darDevice.h"
#include "darRecorder.h"
#include "recPartitionTable.h"
#include "recMCAddressTable.h"

#include <signal.h>

static int      keep_running;

int32_t get_device_info()
{
	return 0;
}

int32_t set_device_info()
{
	return 0;
}

int32_t get_recorder_info()
{
	return 0;
}

void reset_recorder()
{
	return;
}

void set_recorder_enable()
{
	return;
}

int32_t set_recorder_info()
{
	reset_recorder();
	set_recorder_enable();
	return 0;
}

/*
get_next_mcaddr_index_str()
{
}
*/

int32_t get_multicast_data()
{
	return 0;
}

int32_t get_partition_data()
{
	return 0;
}

static          RETSIGTYPE
stop_server(int a)
{
    keep_running = 0;
}

static void
usage(void)
{
    printf
        ("usage: darRecorder [-D<tokens>] [-f] [-L] [-M] [-H] [LISTENING ADDRESSES]\n"
          "\t-f\tDon't fork().\n"
          "\t-DTOKEN[,TOKEN,..]\n"
          "\t\tTurn on debug for TOKEN(s).\n"
          "\t\tWithout any token specified, it prints all tokens\n"
          "\t\t(i.e. using 'ALL' for verbose output.).\n"
          "\t\tNote: don't put a space between -D and TOKENs.\n"
          "\t-H\tDisplay a list of config file directives\n"
          "\t\tknown by the agent and then exit.\n"
          "\t-M\tRun as a normal SNMP Agent, not an AgentX sub-agent.\n"
          "\t-L\tNo log file; print msgs to stderr.\n");
    exit(0);
}

int
main(int argc, char **argv)
{
    int             agentx_subagent = 0; /* SNMP master agent */
    /*
     * Defs for arg-handling code: handles setting of policy-related variables 
     */
    int             ch;
    extern char    *optarg;
    int             dont_fork = 0, use_syslog = 0;

    while ((ch = getopt(argc, argv, "D:fHLM")) != EOF)
        switch (ch) {
        case 'D':
            debug_register_tokens(optarg);
            snmp_set_do_debugging(1);
            break;
        case 'f':
            dont_fork = 1;
            break;
        case 'H':
            netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID,
                                   NETSNMP_DS_AGENT_NO_ROOT_ACCESS, 1);
            init_agent("darRecorder");  /* register our .conf handlers */
            init_darRecorder();
            init_snmp("darRecorder");
            fprintf(stderr, "Configuration directives understood:\n");
            read_config_print_usage("  ");
            exit(0);
        case 'M':
            agentx_subagent = 0;
            break;
        case 'L':
            use_syslog = 0;     /* use stderr */
            break;
        default:
            fprintf(stderr, "unknown option %c\n", ch);
            usage();
        }

    if (optind < argc) {
        int             i;
        /*
         * There are optional transport addresses on the command line.  
         */
        DEBUGMSGTL(("snmpd/main", "optind %d, argc %d\n", optind, argc));
        for (i = optind; i < argc; i++) {
            char           *c, *astring;
            if ((c = netsnmp_ds_get_string(NETSNMP_DS_APPLICATION_ID,
                                           NETSNMP_DS_AGENT_PORTS))) {
                astring = malloc(strlen(c) + 2 + strlen(argv[i]));
                if (astring == NULL) {
                    fprintf(stderr, "malloc failure processing argv[%d]\n",
                            i);
                    exit(1);
                }
                sprintf(astring, "%s,%s", c, argv[i]);
                netsnmp_ds_set_string(NETSNMP_DS_APPLICATION_ID,
                                      NETSNMP_DS_AGENT_PORTS, astring);
                SNMP_FREE(astring);
            } else {
                netsnmp_ds_set_string(NETSNMP_DS_APPLICATION_ID,
                                      NETSNMP_DS_AGENT_PORTS, argv[i]);
            }
        }
        DEBUGMSGTL(("snmpd/main", "port spec: %s\n",
                    netsnmp_ds_get_string(NETSNMP_DS_APPLICATION_ID,
                                          NETSNMP_DS_AGENT_PORTS)));
    }

    /*
     * we're an agentx subagent? 
     */
    if (agentx_subagent) {
        /*
         * make us a agentx client. 
         */
        netsnmp_enable_subagent();
    }

    snmp_disable_log();
    if (use_syslog)
        snmp_enable_calllog();
    else
        snmp_enable_stderrlog();

    /*
     * daemonize 
     */
    if (!dont_fork) {
        int             rc = netsnmp_daemonize(1, !use_syslog);
        if (rc)
            exit(-1);
    }

    /*
     * initialize the agent library 
     */
    init_agent("darRecorder");

    /*
     * init darRecorder mib code 
     */
	init_darDevice();
    init_darRecorder();
	init_recPartitionTable();
	init_recMCAddressTable();
    /*
     * read darRecorder.conf files. 
     */
    init_snmp("darRecorder");

    /*
     * If we're going to be a snmp master agent, initial the ports 
     */
    if (!agentx_subagent)
        init_master_agent();    /* open the port to listen on (defaults to udp:161) */

    /*
     * In case we recevie a request to stop (kill -TERM or kill -INT) 
     */
    keep_running = 1;
    signal(SIGTERM, stop_server);
    signal(SIGINT, stop_server);

    /*
     * you're main loop here... 
     */
    while (keep_running) {
        /*
         * if you use select(), see snmp_select_info() in snmp_api(3) 
         */
        /*
         * --- OR ---  
         */
        agent_check_and_process(1);     /* 0 == don't block */
    }

    /*
     * at shutdown time 
     */
    snmp_shutdown("darRecorder");

    exit(0);
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.