]> git.ipfire.org Git - thirdparty/squid.git/blob - include/snmp_api.h
Merged from parent (trunk r10600).
[thirdparty/squid.git] / include / snmp_api.h
1 #ifndef SQUID_SNMP_API_H
2 #define SQUID_SNMP_API_H
3
4 #include "config.h"
5
6 /***********************************************************
7 Copyright 1989 by Carnegie Mellon University
8
9 All Rights Reserved
10
11 Permission to use, copy, modify, and distribute this software and its
12 documentation for any purpose and without fee is hereby granted,
13 provided that the above copyright notice appear in all copies and that
14 both that copyright notice and this permission notice appear in
15 supporting documentation, and that the name of CMU not be
16 used in advertising or publicity pertaining to distribution of the
17 software without specific, written prior permission.
18
19 CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
20 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
21 CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
22 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
23 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
24 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
25 SOFTWARE.
26 ******************************************************************/
27
28 /*
29 * snmp_api.h - API for access to snmp.
30 */
31
32
33
34 /*
35 * Set fields in session and pdu to the following to get a default or unconfigured value.
36 */
37 #define SNMP_DEFAULT_COMMUNITY_LEN 0 /* to get a default community name */
38 #define SNMP_DEFAULT_RETRIES 3
39 #define SNMP_DEFAULT_TIMEOUT 1
40 #define SNMP_DEFAULT_REMPORT 0
41 #define SNMP_DEFAULT_PEERNAME NULL
42 #define SNMP_DEFAULT_ENTERPRISE_LENGTH 0
43 #define SNMP_DEFAULT_TIME 0
44 #define SNMP_DEFAULT_MAXREPETITIONS 5
45 #define SNMP_DEFAULT_MACREPEATERS 0
46
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50
51 /* Parse the buffer pointed to by arg3, of length arg4, into pdu arg2.
52 *
53 * Returns the community of the incoming PDU, or NULL
54 */
55 u_char *snmp_parse(struct snmp_session *, struct snmp_pdu *, u_char *, int);
56
57 /* Encode pdu arg2 into buffer arg3. arg4 contains the size of
58 * the buffer.
59 */
60 int snmp_build(struct snmp_session *, struct snmp_pdu *, u_char *, int *);
61
62 /*
63 * struct snmp_session *snmp_open(session)
64 * struct snmp_session *session;
65 *
66 * Sets up the session with the snmp_session information provided
67 * by the user. Then opens and binds the necessary UDP port.
68 * A handle to the created session is returned (this is different than
69 * the pointer passed to snmp_open()). On any error, NULL is returned
70 * and snmp_errno is set to the appropriate error code.
71 */
72 #if 0
73 struct snmp_session *snmp_open(struct snmp_session *);
74
75 /*
76 * int snmp_close(session)
77 * struct snmp_session *session;
78 *
79 * Close the input session. Frees all data allocated for the session,
80 * dequeues any pending requests, and closes any sockets allocated for
81 * the session. Returns 0 on error, 1 otherwise.
82 */
83 int snmp_close(struct snmp_session *);
84
85
86 /*
87 * int snmp_send(session, pdu)
88 * struct snmp_session *session;
89 * struct snmp_pdu *pdu;
90 *
91 * Sends the input pdu on the session after calling snmp_build to create
92 * a serialized packet. If necessary, set some of the pdu data from the
93 * session defaults. Add a request corresponding to this pdu to the list
94 * of outstanding requests on this session, then send the pdu.
95 * Returns the request id of the generated packet if applicable, otherwise 1.
96 * On any error, 0 is returned.
97 * The pdu is freed by snmp_send() unless a failure occured.
98 */
99 int snmp_send(struct snmp_session *, struct snmp_pdu *);
100
101 /*
102 * void snmp_read(fdset)
103 * fd_set *fdset;
104 *
105 * Checks to see if any of the fd's set in the fdset belong to
106 * snmp. Each socket with it's fd set has a packet read from it
107 * and snmp_parse is called on the packet received. The resulting pdu
108 * is passed to the callback routine for that session. If the callback
109 * routine returns successfully, the pdu and it's request are deleted.
110 */
111 void snmp_read(fd_set *);
112
113
114 /*
115 * int snmp_select_info(numfds, fdset, timeout, block)
116 * int *numfds;
117 * fd_set *fdset;
118 * struct timeval *timeout;
119 * int *block;
120 *
121 * Returns info about what snmp requires from a select statement.
122 * numfds is the number of fds in the list that are significant.
123 * All file descriptors opened for SNMP are OR'd into the fdset.
124 * If activity occurs on any of these file descriptors, snmp_read
125 * should be called with that file descriptor set.
126 *
127 * The timeout is the latest time that SNMP can wait for a timeout. The
128 * select should be done with the minimum time between timeout and any other
129 * timeouts necessary. This should be checked upon each invocation of select.
130 * If a timeout is received, snmp_timeout should be called to check if the
131 * timeout was for SNMP. (snmp_timeout is idempotent)
132 *
133 * Block is 1 if the select is requested to block indefinitely, rather than time out.
134 * If block is input as 1, the timeout value will be treated as undefined, but it must
135 * be available for setting in snmp_select_info. On return, if block is true, the value
136 * of timeout will be undefined.
137 *
138 * snmp_select_info returns the number of open sockets. (i.e. The number of sessions open)
139 */
140 int snmp_select_info(int *, fd_set *, struct timeval *, int *);
141
142 /*
143 * void snmp_timeout();
144 *
145 * snmp_timeout should be called whenever the timeout from snmp_select_info expires,
146 * but it is idempotent, so snmp_timeout can be polled (probably a cpu expensive
147 * proposition). snmp_timeout checks to see if any of the sessions have an
148 * outstanding request that has timed out. If it finds one (or more), and that
149 * pdu has more retries available, a new packet is formed from the pdu and is
150 * resent. If there are no more retries available, the callback for the session
151 * is used to alert the user of the timeout.
152 */
153 void snmp_timeout(void);
154
155
156 /*
157 * This routine must be supplied by the application:
158 *
159 * int callback(operation, session, reqid, pdu, magic)
160 * int operation;
161 * struct snmp_session *session; The session authenticated under.
162 * int reqid; The request id of this pdu (0 for TRAP)
163 * struct snmp_pdu *pdu; The pdu information.
164 * void *magic A link to the data for this routine.
165 *
166 * Returns 1 if request was successful, 0 if it should be kept pending.
167 * Any data in the pdu must be copied because it will be freed elsewhere.
168 * Operations are defined below:
169 */
170
171
172
173
174
175 void snmp_api_stats(void *);
176 #endif
177 #ifdef __cplusplus
178 }
179
180 #endif
181
182 #endif /* SQUID_SNMP_API_H */