5.2   Configuring snmpIoLib

snmpIoLib contains routines which can be customized by an agent writer for specific needs. The following sections discuss routines which are present in the file $WIND_BASE/target/src/snmpv1/agent/. For more information on an individual routine, see its corresponding manual page entry in F. SNMP Reference.

snmpIoInit( ) - initialization routine for SNMP transport endpoint

This routine initializes the SNMP transport endpoint on the target.

The provided source code illustrates the initialization of a socket interface. Alter this routine to suit the transport needs of your environment.

snmpIoWrite( ) - write a packet to the transport

This routine writes a datagram to the transport mechanism initialized in snmpIoInit( ).

The provided source code utilizes a call to the VxWorks routine sendto( ) (see VxWorks Reference Manual) to send a packet through a socket. Alter this routine to suit the transport needs of your environment.

snmpIoClose( ) - close the transport endpoint

This routine deallocates the resources for the transport endpoint initialized in snmpIoInit( ). This routine is invoked from the task-deletion hook installed by the SNMP agent during initialization; it is invoked if the agent is deleted by accident or from another task.

The provided source code example deallocates a socket. Alter this routine to suit the transport needs of your environment.

snmpIoMain( ) - main SNMP I/O routine

This routine is invoked as a task by the SNMP agent initialization process after preliminary initializations have successfully completed. In this routine, the user is required to initialize the transport endpoint by calling snmpIoInit( ), to initialize the views by calling the routine snmpIoViewInit( ), to set up the data structures needed to send traps, and then to complete initialization of the agent by calling snmpdInitFinish( ). All user-defined initialization should be performed here.

Any hooks that are required by the user are to be passed to snmpdInitFinish( ). The transport endpoint must be initialized before snmpdInitFinish( ) is called.

The main loop, snmpIoBody( ), is then invoked. The agent begins listening on UDP port 161 for incoming SNMP requests.

snmpIoBody( ) - the top level loop of the SNMP agent

This routine listens to the transport endpoint that was initialized in snmpIoInit( ). When a packet is received, it is handed off to the received-packet manager, snmpdPktProcess( ). The provided source code example illustrates this process using a socket. Alter this routine to suit the transport needs of your environment.

snmpIoTrapSend( ) - send a trap

This routine sends a standard SNMP or MIB-II trap message (see 4.7 Traps) to the network. It is called by the SNMP agent at startup (to indicate a cold start) and when interface states change.

The provided source-code example illustrates this process using a socket interface. Alter this routine to suit the transport needs of your application.

snmpIoViewInit( ) - sample view-initialization routine

This routine creates the initial view table at agent-startup time. (For more information on view tables, see 4.9 View Tables.)

By default, the view is unrestricted. Alter this routine to provide restricted views of subsets of the MIB tree.

snmpIoCommunityValidate( ) - sample community validation

This routine is used to set up the view-index field in the SNMP packet.

By default, the priv community is allowed to set MIB variables (initiate SET request PDUs), and the pub community is allowed to retrieve variables with GET, GET NEXT, or GET BULK request PDUs. Alter this routine to provide a mechanism by which an incoming packet's community name can be validated and assigned a view-index for the corresponding request.