net-snmp 5.7
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     /*
00036      * If non-zero, causes the addresses of peers to be logged when receptions
00037      * occur.  
00038      */
00039 
00040     extern int      log_addresses;
00041 
00042     /*
00043      * How many ticks since we last aged the address cache entries.  
00044      */
00045 
00046     extern int      lastAddrAge;
00047 
00054     typedef struct netsnmp_request_info_s {
00058         netsnmp_variable_list *requestvb;
00059 
00064         netsnmp_data_list *parent_data;
00065 
00066        /*
00067         * pointer to the agent_request_info for this request
00068         */
00069        struct netsnmp_agent_request_info_s *agent_req_info;
00070 
00072         oid            *range_end;
00073         size_t          range_end_len;
00074 
00075        /*
00076         * flags
00077         */
00078         int             delegated;
00079         int             processed;
00080         int             inclusive;
00081 
00082         int             status;
00084         int             index;
00085  
00087         int             repeat;
00088         int             orig_repeat;
00089         netsnmp_variable_list *requestvb_start;
00090 
00091        /* internal use */
00092         struct netsnmp_request_info_s *next;
00093         struct netsnmp_request_info_s *prev;
00094         struct netsnmp_subtree_s      *subtree;
00095     } netsnmp_request_info;
00096 
00097     typedef struct netsnmp_set_info_s {
00098         int             action;
00099         void           *stateRef;
00100 
00101         /*
00102          * don't use yet: 
00103          */
00104         void          **oldData;
00105         int             setCleanupFlags;
00106 #define AUTO_FREE_STATEREF 0x01 /* calls free(stateRef) */
00107 #define AUTO_FREE_OLDDATA  0x02 /* calls free(*oldData) */
00108 #define AUTO_UNDO          0x03 /* ... */
00109     } netsnmp_set_info;
00110 
00111     typedef struct netsnmp_tree_cache_s {
00112         struct netsnmp_subtree_s *subtree;
00113         netsnmp_request_info *requests_begin;
00114         netsnmp_request_info *requests_end;
00115     } netsnmp_tree_cache;
00116 
00117 #define MODE_GET              SNMP_MSG_GET
00118 #define MODE_GETNEXT          SNMP_MSG_GETNEXT
00119 #define MODE_GETBULK          SNMP_MSG_GETBULK
00120 #define MODE_GET_STASH        SNMP_MSG_INTERNAL_GET_STASH
00121 #ifndef NETSNMP_NO_WRITE_SUPPORT
00122 #define MODE_IS_GET(x)        ((x >= 128) && (x != -1)  && (x != SNMP_MSG_SET))
00123 #else /* NETSNMP_NO_WRITE_SUPPORT */
00124 #define MODE_IS_GET(x)        ((x >= 128) && (x != -1))
00125 #endif /* NETSNMP_NO_WRITE_SUPPORT */
00126 
00127     /* #define MODE_IS_GET(x)        ((x == SNMP_MSG_GET) || (x == SNMP_MSG_GETNEXT) || (x == SNMP_MSG_GETBULK) || (x == SNMP_MSG_INTERNAL_GET_STASH)) */
00128 
00129 #ifndef NETSNMP_NO_WRITE_SUPPORT
00130 #define MODE_SET_BEGIN        SNMP_MSG_INTERNAL_SET_BEGIN
00131 #define MODE_SET_RESERVE1     SNMP_MSG_INTERNAL_SET_RESERVE1
00132 #define MODE_SET_RESERVE2     SNMP_MSG_INTERNAL_SET_RESERVE2
00133 #define MODE_SET_ACTION       SNMP_MSG_INTERNAL_SET_ACTION
00134 #define MODE_SET_COMMIT       SNMP_MSG_INTERNAL_SET_COMMIT
00135 #define MODE_SET_FREE         SNMP_MSG_INTERNAL_SET_FREE
00136 #define MODE_SET_UNDO         SNMP_MSG_INTERNAL_SET_UNDO
00137 #define MODE_IS_SET(x)         ((x < 128) || (x == -1) || (x == SNMP_MSG_SET))
00138     /* #define MODE_IS_SET(x)         (!MODE_IS_GET(x)) */
00139 #endif /* NETSNMP_NO_WRITE_SUPPORT */
00140 
00141 #define MODE_BSTEP_PRE_REQUEST   SNMP_MSG_INTERNAL_PRE_REQUEST
00142 #define MODE_BSTEP_POST_REQUEST  SNMP_MSG_INTERNAL_POST_REQUEST
00143 
00144 #define MODE_BSTEP_OBJECT_LOOKUP       SNMP_MSG_INTERNAL_OBJECT_LOOKUP
00145 #ifndef NETSNMP_NO_WRITE_SUPPORT
00146 #define MODE_BSTEP_CHECK_VALUE         SNMP_MSG_INTERNAL_CHECK_VALUE
00147 #define MODE_BSTEP_ROW_CREATE          SNMP_MSG_INTERNAL_ROW_CREATE
00148 #define MODE_BSTEP_UNDO_SETUP          SNMP_MSG_INTERNAL_UNDO_SETUP
00149 #define MODE_BSTEP_SET_VALUE           SNMP_MSG_INTERNAL_SET_VALUE
00150 #define MODE_BSTEP_CHECK_CONSISTENCY   SNMP_MSG_INTERNAL_CHECK_CONSISTENCY
00151 #define MODE_BSTEP_UNDO_SET            SNMP_MSG_INTERNAL_UNDO_SET
00152 #define MODE_BSTEP_COMMIT              SNMP_MSG_INTERNAL_COMMIT
00153 #define MODE_BSTEP_UNDO_COMMIT         SNMP_MSG_INTERNAL_UNDO_COMMIT
00154 #define MODE_BSTEP_IRREVERSIBLE_COMMIT SNMP_MSG_INTERNAL_IRREVERSIBLE_COMMIT
00155 #define MODE_BSTEP_UNDO_CLEANUP        SNMP_MSG_INTERNAL_UNDO_CLEANUP
00156 #endif /* NETSNMP_NO_WRITE_SUPPORT */
00157 
00166     typedef struct netsnmp_agent_request_info_s {
00167         int             mode;
00169 /*        netsnmp_pdu    *pdu;    */
00170         struct netsnmp_agent_session_s *asp;    /* may not be needed */
00171         /*
00172          * can be used to pass information on a per-pdu basis from a
00173          * helper to the later handlers 
00174          */
00175         netsnmp_data_list *agent_data;
00176     } netsnmp_agent_request_info;
00177 
00178     typedef struct netsnmp_cachemap_s {
00179         int             globalid;
00180         int             cacheid;
00181         struct netsnmp_cachemap_s *next;
00182     } netsnmp_cachemap;
00183 
00184     typedef struct netsnmp_agent_session_s {
00185         int             mode;
00186         netsnmp_session *session;
00187         netsnmp_pdu    *pdu;
00188         netsnmp_pdu    *orig_pdu;
00189         int             rw;
00190         int             exact;
00191         int             status;
00192         int             index;
00193         int             oldmode;
00194 
00195         struct netsnmp_agent_session_s *next;
00196 
00197         /*
00198          * new API pointers 
00199          */
00200         netsnmp_agent_request_info *reqinfo;
00201         netsnmp_request_info *requests;
00202         netsnmp_tree_cache *treecache;
00203         netsnmp_variable_list **bulkcache;
00204         int             treecache_len;  /* length of cache array */
00205         int             treecache_num;  /* number of current cache entries */
00206         netsnmp_cachemap *cache_store;
00207         int             vbcount;
00208     } netsnmp_agent_session;
00209 
00210     /*
00211      * Address cache handling functions.  
00212      */
00213 
00214     void            netsnmp_addrcache_initialise(void);
00215     void            netsnmp_addrcache_destroy(void);
00216     void            netsnmp_addrcache_age(void);
00217 
00218 
00219     /*
00220      * config file parsing routines 
00221      */
00222     int             handle_snmp_packet(int, netsnmp_session *, int,
00223                                        netsnmp_pdu *, void *);
00224     void            snmp_agent_parse_config(char *, char *);
00225     netsnmp_agent_session *init_agent_snmp_session(netsnmp_session *,
00226                                                    netsnmp_pdu *);
00227     void            free_agent_snmp_session(netsnmp_agent_session *);
00228     void           
00229         netsnmp_remove_and_free_agent_snmp_session(netsnmp_agent_session
00230                                                    *asp);
00231 #ifdef SNMP_NEED_REQUEST_LIST
00232     void           
00233         netsnmp_free_agent_snmp_session_by_session(netsnmp_session * sess,
00234                                                    void (*free_request)
00235                                                    (netsnmp_request_list
00236                                                     *));
00237 #endif
00238     int             getNextSessID(void);
00239     void            dump_sess_list(void);
00240     int             init_master_agent(void);
00241     void            shutdown_master_agent(void);
00242     int             agent_check_and_process(int block);
00243     void            netsnmp_check_outstanding_agent_requests(void);
00244 
00245     int             netsnmp_request_set_error(netsnmp_request_info *request,
00246                                               int error_value);
00247     int             netsnmp_check_requests_error(netsnmp_request_info *reqs);
00248     int             netsnmp_check_all_requests_error(netsnmp_agent_session *asp,
00249                                                      int look_for_specific);
00250     int
00251         netsnmp_set_all_requests_error(netsnmp_agent_request_info *reqinfo,
00252                                        netsnmp_request_info *requests,
00253                                        int error_value);
00254     int netsnmp_request_set_error_idx(netsnmp_request_info *requests,
00255                                        int error_value, int idx);
00256     int
00257         netsnmp_request_set_error_all(netsnmp_request_info *requests,
00258                                        int error_value);
00259     
00261     int             netsnmp_set_request_error(netsnmp_agent_request_info
00262                                               *reqinfo,
00263                                               netsnmp_request_info
00264                                               *request, int error_value);
00266     int             netsnmp_set_mode_request_error(int mode,
00267                                                    netsnmp_request_info
00268                                                    *request,
00269                                                    int error_value);
00270 
00271     u_long          netsnmp_marker_uptime(marker_t pm);
00272     u_long          netsnmp_timeval_uptime(struct timeval *tv);
00273     const_marker_t  netsnmp_get_agent_starttime(void);
00274     void            netsnmp_set_agent_starttime(marker_t s);
00275     u_long          netsnmp_get_agent_uptime(void);
00276     void            netsnmp_set_agent_uptime(u_long hsec);
00277     int             netsnmp_check_transaction_id(int transaction_id);
00278     int             netsnmp_agent_check_packet(netsnmp_session *,
00279                                                struct netsnmp_transport_s
00280                                                *, void *, int);
00281     int             netsnmp_agent_check_parse(netsnmp_session *,
00282                                               netsnmp_pdu *, int);
00283     int             netsnmp_allocate_globalcacheid(void);
00284 
00285     int netsnmp_remove_delegated_requests_for_session(netsnmp_session *sess);
00286 
00287     /*
00288      * Register and de-register agent NSAPs.  
00289      */
00290 
00291     struct netsnmp_transport_s;
00292 
00293     int             netsnmp_register_agent_nsap(struct netsnmp_transport_s
00294                                                 *t);
00295     void            netsnmp_deregister_agent_nsap(int handle);
00296 
00297     void
00298         netsnmp_agent_add_list_data(netsnmp_agent_request_info *agent,
00299                                     netsnmp_data_list *node);
00300 
00301     int
00302         netsnmp_agent_remove_list_data(netsnmp_agent_request_info *ari,
00303                                        const char * name);
00304 
00305     void *
00306             netsnmp_agent_get_list_data(netsnmp_agent_request_info
00307                                         *agent, const char *name);
00308 
00309     void
00310             netsnmp_free_agent_data_set(netsnmp_agent_request_info *agent);
00311 
00312     void
00313            netsnmp_free_agent_data_sets(netsnmp_agent_request_info *agent);
00314     void
00315         netsnmp_free_agent_request_info(netsnmp_agent_request_info *ari);
00316 
00317 #ifdef __cplusplus
00318 }
00319 #endif
00320 #endif
00321