net-snmp  5.4.1
snmp_agent.h
00001 /* Portions of this file are subject to the following copyright(s).  See
00002  * the Net-SNMP's COPYING file for more details and other copyrights
00003  * that may apply:
00004  */
00005 /*
00006  * Portions of this file are copyrighted by:
00007  * Copyright © 2003 Sun Microsystems, Inc. All rights reserved.
00008  * Use is subject to license terms specified in the COPYING file
00009  * distributed with the Net-SNMP package.
00010  */
00011 /*
00012  * @file snmp_agent.h
00013  *
00014  * @addtogroup agent
00015  * @addtogroup table
00016  * External definitions for functions and variables in snmp_agent.c.
00017  *
00018  * @{
00019  */
00020 
00021 #ifndef SNMP_AGENT_H
00022 #define SNMP_AGENT_H
00023 
00024 #ifdef __cplusplus
00025 extern          "C" {
00026 #endif
00027 
00028 #include <net-snmp/library/snmp_impl.h>
00029 #include <net-snmp/library/tools.h>
00030 #include <net-snmp/library/data_list.h>
00031 
00032 #define SNMP_MAX_PDU_SIZE 64000 /* local constraint on PDU size sent by agent
00033                                  * (see also SNMP_MAX_MSG_SIZE in snmp_api.h) */
00034 
00035 #define SNMP_AGENT_FLAGS_NONE                   0x0
00036 #define SNMP_AGENT_FLAGS_CANCEL_IN_PROGRESS     0x1
00037 
00038     /*
00039      * If non-zero, causes the addresses of peers to be logged when receptions
00040      * occur.  
00041      */
00042 
00043     extern int      log_addresses;
00044 
00045     /*
00046      * How many ticks since we last aged the address cache entries.  
00047      */
00048 
00049     extern int      lastAddrAge;
00050 
00057     typedef struct netsnmp_request_info_s {
00061         netsnmp_variable_list *requestvb;
00062 
00067         netsnmp_data_list *parent_data;
00068 
00069        /*
00070         * pointer to the agent_request_info for this request
00071         */
00072        struct netsnmp_agent_request_info_s *agent_req_info;
00073 
00075         oid            *range_end;
00076         size_t          range_end_len;
00077 
00078        /*
00079         * flags
00080         */
00081         int             delegated;
00082         int             processed;
00083         int             inclusive;
00084 
00085         int             status;
00087         int             index;
00088  
00090         int             repeat;
00091         int             orig_repeat;
00092         netsnmp_variable_list *requestvb_start;
00093 
00094        /* internal use */
00095         struct netsnmp_request_info_s *next;
00096         struct netsnmp_request_info_s *prev;
00097         struct netsnmp_subtree_s      *subtree;
00098     } netsnmp_request_info;
00099 
00100     typedef struct netsnmp_set_info_s {
00101         int             action;
00102         void           *stateRef;
00103 
00104         /*
00105          * don't use yet: 
00106          */
00107         void          **oldData;
00108         int             setCleanupFlags;
00109 #define AUTO_FREE_STATEREF 0x01 /* calls free(stateRef) */
00110 #define AUTO_FREE_OLDDATA  0x02 /* calls free(*oldData) */
00111 #define AUTO_UNDO          0x03 /* ... */
00112     } netsnmp_set_info;
00113 
00114     typedef struct netsnmp_tree_cache_s {
00115         struct netsnmp_subtree_s *subtree;
00116         netsnmp_request_info *requests_begin;
00117         netsnmp_request_info *requests_end;
00118     } netsnmp_tree_cache;
00119 
00120 #define MODE_GET              SNMP_MSG_GET
00121 #define MODE_GETNEXT          SNMP_MSG_GETNEXT
00122 #define MODE_GETBULK          SNMP_MSG_GETBULK
00123 #define MODE_GET_STASH        SNMP_MSG_INTERNAL_GET_STASH
00124 #define MODE_IS_GET(x)        ((x >= 128) && (x != -1)  && (x != SNMP_MSG_SET))
00125     /* #define MODE_IS_GET(x)        ((x == SNMP_MSG_GET) || (x == SNMP_MSG_GETNEXT) || (x == SNMP_MSG_GETBULK) || (x == SNMP_MSG_INTERNAL_GET_STASH)) */
00126 
00127 #define MODE_SET_BEGIN        SNMP_MSG_INTERNAL_SET_BEGIN
00128 #define MODE_SET_RESERVE1     SNMP_MSG_INTERNAL_SET_RESERVE1
00129 #define MODE_SET_RESERVE2     SNMP_MSG_INTERNAL_SET_RESERVE2
00130 #define MODE_SET_ACTION       SNMP_MSG_INTERNAL_SET_ACTION
00131 #define MODE_SET_COMMIT       SNMP_MSG_INTERNAL_SET_COMMIT
00132 #define MODE_SET_FREE         SNMP_MSG_INTERNAL_SET_FREE
00133 #define MODE_SET_UNDO         SNMP_MSG_INTERNAL_SET_UNDO
00134 #define MODE_IS_SET(x)         ((x < 128) || (x == -1) || (x == SNMP_MSG_SET))
00135     /* #define MODE_IS_SET(x)         (!MODE_IS_GET(x)) */
00136 
00137 #define MODE_BSTEP_PRE_REQUEST   SNMP_MSG_INTERNAL_PRE_REQUEST
00138 #define MODE_BSTEP_POST_REQUEST  SNMP_MSG_INTERNAL_POST_REQUEST
00139 
00140 #define MODE_BSTEP_OBJECT_LOOKUP       SNMP_MSG_INTERNAL_OBJECT_LOOKUP
00141 #define MODE_BSTEP_CHECK_VALUE         SNMP_MSG_INTERNAL_CHECK_VALUE
00142 #define MODE_BSTEP_ROW_CREATE          SNMP_MSG_INTERNAL_ROW_CREATE
00143 #define MODE_BSTEP_UNDO_SETUP          SNMP_MSG_INTERNAL_UNDO_SETUP
00144 #define MODE_BSTEP_SET_VALUE           SNMP_MSG_INTERNAL_SET_VALUE
00145 #define MODE_BSTEP_CHECK_CONSISTENCY   SNMP_MSG_INTERNAL_CHECK_CONSISTENCY
00146 #define MODE_BSTEP_UNDO_SET            SNMP_MSG_INTERNAL_UNDO_SET
00147 #define MODE_BSTEP_COMMIT              SNMP_MSG_INTERNAL_COMMIT
00148 #define MODE_BSTEP_UNDO_COMMIT         SNMP_MSG_INTERNAL_UNDO_COMMIT
00149 #define MODE_BSTEP_IRREVERSIBLE_COMMIT SNMP_MSG_INTERNAL_IRREVERSIBLE_COMMIT
00150 #define MODE_BSTEP_UNDO_CLEANUP        SNMP_MSG_INTERNAL_UNDO_CLEANUP
00151 
00152 
00161     typedef struct netsnmp_agent_request_info_s {
00162         int             mode;
00164 /*        netsnmp_pdu    *pdu;    */
00165         struct netsnmp_agent_session_s *asp;    /* may not be needed */
00166         /*
00167          * can be used to pass information on a per-pdu basis from a
00168          * helper to the later handlers 
00169          */
00170         netsnmp_data_list *agent_data;
00171     } netsnmp_agent_request_info;
00172 
00173     typedef struct netsnmp_cachemap_s {
00174         int             globalid;
00175         int             cacheid;
00176         struct netsnmp_cachemap_s *next;
00177     } netsnmp_cachemap;
00178 
00179     typedef struct netsnmp_agent_session_s {
00180         int             mode;
00181         netsnmp_session *session;
00182         netsnmp_pdu    *pdu;
00183         netsnmp_pdu    *orig_pdu;
00184         int             rw;
00185         int             exact;
00186         int             status;
00187         int             index;
00188         int             oldmode;
00189 
00190         struct netsnmp_agent_session_s *next;
00191 
00192         /*
00193          * new API pointers 
00194          */
00195         netsnmp_agent_request_info *reqinfo;
00196         netsnmp_request_info *requests;
00197         netsnmp_tree_cache *treecache;
00198         netsnmp_variable_list **bulkcache;
00199         int             treecache_len;  /* length of cache array */
00200         int             treecache_num;  /* number of current cache entries */
00201         netsnmp_cachemap *cache_store;
00202         int             vbcount;
00203         int             flags;
00204     } netsnmp_agent_session;
00205 
00206     /*
00207      * Address cache handling functions.  
00208      */
00209 
00210     void            netsnmp_addrcache_initialise(void);
00211     void            netsnmp_addrcache_age(void);
00212 
00213 
00214     /*
00215      * config file parsing routines 
00216      */
00217     int             handle_snmp_packet(int, netsnmp_session *, int,
00218                                        netsnmp_pdu *, void *);
00219     void            snmp_agent_parse_config(char *, char *);
00220     netsnmp_agent_session *init_agent_snmp_session(netsnmp_session *,
00221                                                    netsnmp_pdu *);
00222     void            free_agent_snmp_session(netsnmp_agent_session *);
00223     void           
00224         netsnmp_remove_and_free_agent_snmp_session(netsnmp_agent_session
00225                                                    *asp);
00226 #ifdef SNMP_NEED_REQUEST_LIST
00227     void           
00228         netsnmp_free_agent_snmp_session_by_session(netsnmp_session * sess,
00229                                                    void (*free_request)
00230                                                    (netsnmp_request_list
00231                                                     *));
00232 #endif
00233     int             getNextSessID(void);
00234     void            dump_sess_list(void);
00235     int             init_master_agent(void);
00236     void            shutdown_master_agent(void);
00237     int             agent_check_and_process(int block);
00238     void            netsnmp_check_delegated_requests(void);
00239     void            netsnmp_check_outstanding_agent_requests(void);
00240 
00241     int             netsnmp_request_set_error(netsnmp_request_info *request,
00242                                               int error_value);
00243     int             netsnmp_check_requests_error(netsnmp_request_info *reqs);
00244     int             netsnmp_check_all_requests_error(netsnmp_agent_session *asp,
00245                                                      int look_for_specific);
00246     int
00247         netsnmp_set_all_requests_error(netsnmp_agent_request_info *reqinfo,
00248                                        netsnmp_request_info *requests,
00249                                        int error_value);
00250     int netsnmp_request_set_error_idx(netsnmp_request_info *requests,
00251                                        int error_value, int idx);
00252     int
00253         netsnmp_request_set_error_all(netsnmp_request_info *requests,
00254                                        int error_value);
00255     
00257     int             netsnmp_set_request_error(netsnmp_agent_request_info
00258                                               *reqinfo,
00259                                               netsnmp_request_info
00260                                               *request, int error_value);
00262     int             netsnmp_set_mode_request_error(int mode,
00263                                                    netsnmp_request_info
00264                                                    *request,
00265                                                    int error_value);
00266 
00267     u_long          netsnmp_marker_uptime(marker_t pm);
00268     u_long          netsnmp_timeval_uptime(struct timeval *tv);
00269     u_long          netsnmp_get_agent_uptime(void);
00270     int             netsnmp_check_transaction_id(int transaction_id);
00271     int             netsnmp_agent_check_packet(netsnmp_session *,
00272                                                struct netsnmp_transport_s
00273                                                *, void *, int);
00274     int             netsnmp_agent_check_parse(netsnmp_session *,
00275                                               netsnmp_pdu *, int);
00276     int             netsnmp_allocate_globalcacheid(void);
00277 
00278     int netsnmp_remove_delegated_requests_for_session(netsnmp_session *sess);
00279 
00280     /*
00281      * Register and de-register agent NSAPs.  
00282      */
00283 
00284     struct netsnmp_transport_s;
00285 
00286     int             netsnmp_register_agent_nsap(struct netsnmp_transport_s
00287                                                 *t);
00288     void            netsnmp_deregister_agent_nsap(int handle);
00289 
00290     NETSNMP_INLINE void
00291         netsnmp_agent_add_list_data(netsnmp_agent_request_info *agent,
00292                                     netsnmp_data_list *node);
00293 
00294     NETSNMP_INLINE int
00295         netsnmp_agent_remove_list_data(netsnmp_agent_request_info *ari,
00296                                        const char * name);
00297 
00298     NETSNMP_INLINE void *
00299             netsnmp_agent_get_list_data(netsnmp_agent_request_info
00300                                         *agent, const char *name);
00301 
00302     NETSNMP_INLINE void
00303             netsnmp_free_agent_data_set(netsnmp_agent_request_info *agent);
00304 
00305     NETSNMP_INLINE void
00306            netsnmp_free_agent_data_sets(netsnmp_agent_request_info *agent);
00307     NETSNMP_INLINE void    
00308         netsnmp_free_agent_request_info(netsnmp_agent_request_info *ari);
00309 
00310 #ifdef __cplusplus
00311 }
00312 #endif
00313 #endif
00314