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