added files
[bcm963xx.git] / userapps / opensource / net-snmp / include / net-snmp / agent / snmp_agent.h
1 /*
2  * snmp_agent.h
3  *
4  * External definitions for functions and variables in snmp_agent.c.
5  */
6
7 #ifndef SNMP_AGENT_H
8 #define SNMP_AGENT_H
9
10 #ifdef __cplusplus
11 extern          "C" {
12 #endif
13
14 #include <net-snmp/library/snmp_impl.h>
15 #include <net-snmp/library/tools.h>
16 #include <net-snmp/library/data_list.h>
17
18 #define SNMP_MAX_PDU_SIZE 64000 /* local constraint on PDU size sent by agent
19                                  * (see also SNMP_MAX_MSG_SIZE in snmp_api.h) */
20
21     /*
22      * If non-zero, causes the addresses of peers to be logged when receptions
23      * occur.  
24      */
25
26     extern int      log_addresses;
27
28     /*
29      * How many ticks since we last aged the address cache entries.  
30      */
31
32     extern int      lastAddrAge;
33
34     typedef struct netsnmp_request_info_s {
35         netsnmp_variable_list *requestvb;
36
37         /*
38          * can be used to pass information on a per-request basis from a
39          * helper to the later handlers 
40          */
41         netsnmp_data_list *parent_data;
42
43         oid            *range_end;      /* don't free, reference to (struct tree)->end */
44         size_t          range_end_len;
45         int             delegated;
46         int             processed;
47         int             inclusive;
48         int             status;
49         int             index; /* index in original pdu */
50         int             repeat; /* get-bulk */
51
52         struct netsnmp_request_info_s *next;
53         struct netsnmp_request_info_s *prev;
54         struct netsnmp_subtree_s      *subtree;
55     } netsnmp_request_info;
56
57     typedef struct netsnmp_set_info_s {
58         int             action;
59         void           *stateRef;
60
61         /*
62          * don't use yet: 
63          */
64         void          **oldData;
65         int             setCleanupFlags;
66 #define AUTO_FREE_STATEREF 0x01 /* calls free(stateRef) */
67 #define AUTO_FREE_OLDDATA  0x02 /* calls free(*oldData) */
68 #define AUTO_UNDO          0x03 /* ... */
69     } netsnmp_set_info;
70
71     typedef struct netsnmp_tree_cache_s {
72         struct netsnmp_subtree_s *subtree;
73         netsnmp_request_info *requests_begin;
74         netsnmp_request_info *requests_end;
75     } netsnmp_tree_cache;
76
77 #define MODE_GET              SNMP_MSG_GET
78 #define MODE_GETNEXT          SNMP_MSG_GETNEXT
79 #define MODE_GETBULK          SNMP_MSG_GETBULK
80 #define MODE_IS_GET(x)        (x == SNMP_MSG_GET || x == SNMP_MSG_GETNEXT || x == SNMP_MSG_GETBULK)
81
82 #define MODE_SET_BEGIN        SNMP_MSG_INTERNAL_SET_BEGIN
83 #define MODE_SET_RESERVE1     SNMP_MSG_INTERNAL_SET_RESERVE1
84 #define MODE_SET_RESERVE2     SNMP_MSG_INTERNAL_SET_RESERVE2
85 #define MODE_SET_ACTION       SNMP_MSG_INTERNAL_SET_ACTION
86 #define MODE_SET_COMMIT       SNMP_MSG_INTERNAL_SET_COMMIT
87 #define MODE_SET_FREE         SNMP_MSG_INTERNAL_SET_FREE
88 #define MODE_SET_UNDO         SNMP_MSG_INTERNAL_SET_UNDO
89 #define MODE_IS_SET(x)         (!MODE_IS_GET(x))
90
91     typedef struct netsnmp_agent_request_info_s {
92         int             mode;
93         netsnmp_pdu    *pdu;    /* pdu contains authinfo, eg */
94         struct netsnmp_agent_session_s *asp;    /* may not be needed */
95         /*
96          * can be used to pass information on a per-pdu basis from a
97          * helper to the later handlers 
98          */
99         netsnmp_data_list *agent_data;
100         /*
101          * ... 
102          */
103     } netsnmp_agent_request_info;
104
105     typedef struct netsnmp_cachemap_s {
106         int             globalid;
107         int             cacheid;
108         struct netsnmp_cachemap_s *next;
109     } netsnmp_cachemap;
110
111     typedef struct netsnmp_agent_session_s {
112         int             mode;
113         netsnmp_session *session;
114         netsnmp_pdu    *pdu;
115         netsnmp_pdu    *orig_pdu;
116         int             rw;
117         int             exact;
118         int             status;
119         int             index;
120         int             oldmode;
121
122         struct netsnmp_agent_session_s *next;
123
124         /*
125          * new API pointers 
126          */
127         netsnmp_agent_request_info *reqinfo;
128         netsnmp_request_info *requests;
129         netsnmp_tree_cache *treecache;
130         netsnmp_variable_list **bulkcache;
131         int             treecache_len;  /* length of cache array */
132         int             treecache_num;  /* number of current cache entries */
133         netsnmp_cachemap *cache_store;
134         int             vbcount;
135     } netsnmp_agent_session;
136
137     /*
138      * Address cache handling functions.  
139      */
140
141     void            netsnmp_addrcache_initialise(void);
142     void            netsnmp_addrcache_age(void);
143
144
145     /*
146      * config file parsing routines 
147      */
148     int             handle_snmp_packet(int, netsnmp_session *, int,
149                                        netsnmp_pdu *, void *);
150     void            snmp_agent_parse_config(char *, char *);
151     netsnmp_agent_session *init_agent_snmp_session(netsnmp_session *,
152                                                    netsnmp_pdu *);
153     void            free_agent_snmp_session(netsnmp_agent_session *);
154     void           
155         netsnmp_remove_and_free_agent_snmp_session(netsnmp_agent_session
156                                                    *asp);
157 #ifdef SNMP_NEED_REQUEST_LIST
158     void           
159         netsnmp_free_agent_snmp_session_by_session(netsnmp_session * sess,
160                                                    void (*free_request)
161                                                    (netsnmp_request_list
162                                                     *));
163 #endif
164     int             getNextSessID(void);
165     void            dump_sess_list(void);
166     int             init_master_agent(void);
167     int             agent_check_and_process(int block);
168     void            netsnmp_check_outstanding_agent_requests(void);
169     int             netsnmp_set_mode_request_error(int mode,
170                                                    netsnmp_request_info
171                                                    *request,
172                                                    int error_value);
173     int             netsnmp_set_request_error(netsnmp_agent_request_info
174                                               *reqinfo,
175                                               netsnmp_request_info
176                                               *request, int error_value);
177     int            
178         netsnmp_set_all_requests_error(netsnmp_agent_request_info *reqinfo,
179                                        netsnmp_request_info *requests,
180                                        int error_value);
181     u_long          netsnmp_marker_uptime(marker_t pm);
182     u_long          netsnmp_timeval_uptime(struct timeval *tv);
183     u_long          netsnmp_get_agent_uptime(void);
184     int             netsnmp_check_transaction_id(int transaction_id);
185     int             netsnmp_agent_check_packet(netsnmp_session *,
186                                                struct netsnmp_transport_s
187                                                *, void *, int);
188     int             netsnmp_agent_check_parse(netsnmp_session *,
189                                               netsnmp_pdu *, int);
190     int             netsnmp_allocate_globalcacheid(void);
191
192     int netsnmp_remove_delegated_requests_for_session(netsnmp_session *sess);
193
194     /*
195      * Register and de-register agent NSAPs.  
196      */
197
198     struct netsnmp_transport_s;
199
200     int             netsnmp_register_agent_nsap(struct netsnmp_transport_s
201                                                 *t);
202     void            netsnmp_deregister_agent_nsap(int handle);
203
204     NETSNMP_INLINE void
205         netsnmp_agent_add_list_data(netsnmp_agent_request_info *agent,
206                                     netsnmp_data_list *node);
207
208     NETSNMP_INLINE void    *netsnmp_agent_get_list_data(netsnmp_agent_request_info
209                                                 *agent, const char *name);
210
211     NETSNMP_INLINE void
212             netsnmp_free_agent_data_set(netsnmp_agent_request_info *agent);
213
214     NETSNMP_INLINE void
215            netsnmp_free_agent_data_sets(netsnmp_agent_request_info *agent);
216     NETSNMP_INLINE void    
217         netsnmp_free_agent_request_info(netsnmp_agent_request_info *ari);
218
219 #ifdef __cplusplus
220 }
221 #endif
222 #endif