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     /*
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 #define MODE_IS_GET(x)        ((x >= 128) && (x != -1)  && (x != SNMP_MSG_SET))
00122     /* #define MODE_IS_GET(x)        ((x == SNMP_MSG_GET) || (x == SNMP_MSG_GETNEXT) || (x == SNMP_MSG_GETBULK) || (x == SNMP_MSG_INTERNAL_GET_STASH)) */
00123 
00124 #define MODE_SET_BEGIN        SNMP_MSG_INTERNAL_SET_BEGIN
00125 #define MODE_SET_RESERVE1     SNMP_MSG_INTERNAL_SET_RESERVE1
00126 #define MODE_SET_RESERVE2     SNMP_MSG_INTERNAL_SET_RESERVE2
00127 #define MODE_SET_ACTION       SNMP_MSG_INTERNAL_SET_ACTION
00128 #define MODE_SET_COMMIT       SNMP_MSG_INTERNAL_SET_COMMIT
00129 #define MODE_SET_FREE         SNMP_MSG_INTERNAL_SET_FREE
00130 #define MODE_SET_UNDO         SNMP_MSG_INTERNAL_SET_UNDO
00131 #define MODE_IS_SET(x)         ((x < 128) || (x == -1) || (x == SNMP_MSG_SET))
00132     /* #define MODE_IS_SET(x)         (!MODE_IS_GET(x)) */
00133 
00134 #define MODE_BSTEP_PRE_REQUEST   SNMP_MSG_INTERNAL_PRE_REQUEST
00135 #define MODE_BSTEP_POST_REQUEST  SNMP_MSG_INTERNAL_POST_REQUEST
00136 
00137 #define MODE_BSTEP_OBJECT_LOOKUP       SNMP_MSG_INTERNAL_OBJECT_LOOKUP
00138 #define MODE_BSTEP_CHECK_VALUE         SNMP_MSG_INTERNAL_CHECK_VALUE
00139 #define MODE_BSTEP_ROW_CREATE          SNMP_MSG_INTERNAL_ROW_CREATE
00140 #define MODE_BSTEP_UNDO_SETUP          SNMP_MSG_INTERNAL_UNDO_SETUP
00141 #define MODE_BSTEP_SET_VALUE           SNMP_MSG_INTERNAL_SET_VALUE
00142 #define MODE_BSTEP_CHECK_CONSISTENCY   SNMP_MSG_INTERNAL_CHECK_CONSISTENCY
00143 #define MODE_BSTEP_UNDO_SET            SNMP_MSG_INTERNAL_UNDO_SET
00144 #define MODE_BSTEP_COMMIT              SNMP_MSG_INTERNAL_COMMIT
00145 #define MODE_BSTEP_UNDO_COMMIT         SNMP_MSG_INTERNAL_UNDO_COMMIT
00146 #define MODE_BSTEP_IRREVERSIBLE_COMMIT SNMP_MSG_INTERNAL_IRREVERSIBLE_COMMIT
00147 #define MODE_BSTEP_UNDO_CLEANUP        SNMP_MSG_INTERNAL_UNDO_CLEANUP
00148 
00149 
00158     typedef struct netsnmp_agent_request_info_s {
00159         int             mode;
00161 /*        netsnmp_pdu    *pdu;    */
00162         struct netsnmp_agent_session_s *asp;    /* may not be needed */
00163         /*
00164          * can be used to pass information on a per-pdu basis from a
00165          * helper to the later handlers 
00166          */
00167         netsnmp_data_list *agent_data;
00168     } netsnmp_agent_request_info;
00169 
00170     typedef struct netsnmp_cachemap_s {
00171         int             globalid;
00172         int             cacheid;
00173         struct netsnmp_cachemap_s *next;
00174     } netsnmp_cachemap;
00175 
00176     typedef struct netsnmp_agent_session_s {
00177         int             mode;
00178         netsnmp_session *session;
00179         netsnmp_pdu    *pdu;
00180         netsnmp_pdu    *orig_pdu;
00181         int             rw;
00182         int             exact;
00183         int             status;
00184         int             index;
00185         int             oldmode;
00186 
00187         struct netsnmp_agent_session_s *next;
00188 
00189         /*
00190          * new API pointers 
00191          */
00192         netsnmp_agent_request_info *reqinfo;
00193         netsnmp_request_info *requests;
00194         netsnmp_tree_cache *treecache;
00195         netsnmp_variable_list **bulkcache;
00196         int             treecache_len;  /* length of cache array */
00197         int             treecache_num;  /* number of current cache entries */
00198         netsnmp_cachemap *cache_store;
00199         int             vbcount;
00200     } netsnmp_agent_session;
00201 
00202     /*
00203      * Address cache handling functions.  
00204      */
00205 
00206     void            netsnmp_addrcache_initialise(void);
00207     void            netsnmp_addrcache_age(void);
00208 
00209 
00210     /*
00211      * config file parsing routines 
00212      */
00213     int             handle_snmp_packet(int, netsnmp_session *, int,
00214                                        netsnmp_pdu *, void *);
00215     void            snmp_agent_parse_config(char *, char *);
00216     netsnmp_agent_session *init_agent_snmp_session(netsnmp_session *,
00217                                                    netsnmp_pdu *);
00218     void            free_agent_snmp_session(netsnmp_agent_session *);
00219     void           
00220         netsnmp_remove_and_free_agent_snmp_session(netsnmp_agent_session
00221                                                    *asp);
00222 #ifdef SNMP_NEED_REQUEST_LIST
00223     void           
00224         netsnmp_free_agent_snmp_session_by_session(netsnmp_session * sess,
00225                                                    void (*free_request)
00226                                                    (netsnmp_request_list
00227                                                     *));
00228 #endif
00229     int             getNextSessID(void);
00230     void            dump_sess_list(void);
00231     int             init_master_agent(void);
00232     void            shutdown_master_agent(void);
00233     int             agent_check_and_process(int block);
00234     void            netsnmp_check_outstanding_agent_requests(void);
00235 
00236     int             netsnmp_request_set_error(netsnmp_request_info *request,
00237                                               int error_value);
00238     int             netsnmp_check_requests_error(netsnmp_request_info *reqs);
00239     int             netsnmp_check_all_requests_error(netsnmp_agent_session *asp,
00240                                                      int look_for_specific);
00241     int
00242         netsnmp_set_all_requests_error(netsnmp_agent_request_info *reqinfo,
00243                                        netsnmp_request_info *requests,
00244                                        int error_value);
00245     int netsnmp_request_set_error_idx(netsnmp_request_info *requests,
00246                                        int error_value, int idx);
00247     int
00248         netsnmp_request_set_error_all(netsnmp_request_info *requests,
00249                                        int error_value);
00250     
00252     int             netsnmp_set_request_error(netsnmp_agent_request_info
00253                                               *reqinfo,
00254                                               netsnmp_request_info
00255                                               *request, int error_value);
00257     int             netsnmp_set_mode_request_error(int mode,
00258                                                    netsnmp_request_info
00259                                                    *request,
00260                                                    int error_value);
00261 
00262     u_long          netsnmp_marker_uptime(marker_t pm);
00263     u_long          netsnmp_timeval_uptime(struct timeval *tv);
00264     u_long          netsnmp_get_agent_uptime(void);
00265     int             netsnmp_check_transaction_id(int transaction_id);
00266     int             netsnmp_agent_check_packet(netsnmp_session *,
00267                                                struct netsnmp_transport_s
00268                                                *, void *, int);
00269     int             netsnmp_agent_check_parse(netsnmp_session *,
00270                                               netsnmp_pdu *, int);
00271     int             netsnmp_allocate_globalcacheid(void);
00272 
00273     int netsnmp_remove_delegated_requests_for_session(netsnmp_session *sess);
00274 
00275     /*
00276      * Register and de-register agent NSAPs.  
00277      */
00278 
00279     struct netsnmp_transport_s;
00280 
00281     int             netsnmp_register_agent_nsap(struct netsnmp_transport_s
00282                                                 *t);
00283     void            netsnmp_deregister_agent_nsap(int handle);
00284 
00285     NETSNMP_INLINE void
00286         netsnmp_agent_add_list_data(netsnmp_agent_request_info *agent,
00287                                     netsnmp_data_list *node);
00288 
00289     NETSNMP_INLINE int
00290         netsnmp_agent_remove_list_data(netsnmp_agent_request_info *ari,
00291                                        const char * name);
00292 
00293     NETSNMP_INLINE void *
00294             netsnmp_agent_get_list_data(netsnmp_agent_request_info
00295                                         *agent, const char *name);
00296 
00297     NETSNMP_INLINE void
00298             netsnmp_free_agent_data_set(netsnmp_agent_request_info *agent);
00299 
00300     NETSNMP_INLINE void
00301            netsnmp_free_agent_data_sets(netsnmp_agent_request_info *agent);
00302     NETSNMP_INLINE void    
00303         netsnmp_free_agent_request_info(netsnmp_agent_request_info *ari);
00304 
00305 #ifdef __cplusplus
00306 }
00307 #endif
00308 #endif
00309