| 1 |
/* |
| 2 |
* Portions of this file are subject to the following copyright(s). See |
| 3 |
* the Net-SNMP's COPYING file for more details and other copyrights |
| 4 |
* that may apply: |
| 5 |
* |
| 6 |
* Portions of this file are copyrighted by: |
| 7 |
* Copyright (c) 2016 VMware, Inc. All rights reserved. |
| 8 |
* Use is subject to license terms specified in the COPYING file |
| 9 |
* distributed with the Net-SNMP package. |
| 10 |
*/ |
| 11 |
|
| 12 |
#ifndef NET_SNMP_TYPES_H |
| 13 |
#define NET_SNMP_TYPES_H |
| 14 |
|
| 15 |
/** |
| 16 |
* Definitions of data structures, used within the library API. |
| 17 |
*/ |
| 18 |
|
| 19 |
#include <stdio.h> |
| 20 |
|
| 21 |
#ifndef NET_SNMP_CONFIG_H |
| 22 |
#error "Please include <net-snmp/net-snmp-config.h> before this file" |
| 23 |
#endif |
| 24 |
|
| 25 |
#include <sys/types.h> |
| 26 |
#if defined(HAVE_SYS_SELECT_H) |
| 27 |
#include <sys/select.h> |
| 28 |
#endif |
| 29 |
|
| 30 |
#if defined(WIN32) && !defined(cygwin) |
| 31 |
typedef HANDLE netsnmp_pid_t; |
| 32 |
#define NETSNMP_NO_SUCH_PROCESS INVALID_HANDLE_VALUE |
| 33 |
#else |
| 34 |
/* |
| 35 |
* Note: on POSIX-compliant systems, pid_t is defined in <sys/types.h>. |
| 36 |
* And if pid_t has not been defined in <sys/types.h>, AC_TYPE_PID_T ensures |
| 37 |
* that a pid_t definition is present in net-snmp-config.h. |
| 38 |
*/ |
| 39 |
typedef pid_t netsnmp_pid_t; |
| 40 |
#define NETSNMP_NO_SUCH_PROCESS -1 |
| 41 |
#endif |
| 42 |
|
| 43 |
#include <net-snmp/library/oid.h> |
| 44 |
|
| 45 |
#ifdef __cplusplus |
| 46 |
extern "C" { |
| 47 |
#endif |
| 48 |
|
| 49 |
#ifndef HAVE_SOCKLEN_T |
| 50 |
#ifdef WIN32 |
| 51 |
typedef int socklen_t; |
| 52 |
#else |
| 53 |
typedef u_int socklen_t; |
| 54 |
#endif |
| 55 |
#endif |
| 56 |
|
| 57 |
#ifndef HAVE_SSIZE_T |
| 58 |
#if defined(__INT_MAX__) && __INT_MAX__ == 2147483647 |
| 59 |
typedef int ssize_t; |
| 60 |
#else |
| 61 |
typedef long ssize_t; |
| 62 |
#endif |
| 63 |
#endif |
| 64 |
|
| 65 |
#ifndef HAVE_NFDS_T |
| 66 |
typedef unsigned long int nfds_t; |
| 67 |
#endif |
| 68 |
|
| 69 |
#ifdef HAVE_PCRE_H |
| 70 |
/* |
| 71 |
* Abstract the pcre typedef such that not all *.c files have to include |
| 72 |
* <pcre.h>. |
| 73 |
*/ |
| 74 |
typedef struct { |
| 75 |
void *regex_ptr; |
| 76 |
} netsnmp_regex_ptr; |
| 77 |
#endif |
| 78 |
|
| 79 |
/* |
| 80 |
* For the initial release, this will just refer to the |
| 81 |
* relevant UCD header files. |
| 82 |
* In due course, the types and structures relevant to the |
| 83 |
* Net-SNMP API will be identified, and defined here directly. |
| 84 |
* |
| 85 |
* But for the time being, this header file is primarily a placeholder, |
| 86 |
* to allow application writers to adopt the new header file names. |
| 87 |
*/ |
| 88 |
|
| 89 |
typedef union { |
| 90 |
long *integer; |
| 91 |
u_char *string; |
| 92 |
oid *objid; |
| 93 |
u_char *bitstring; |
| 94 |
struct counter64 *counter64; |
| 95 |
#ifdef NETSNMP_WITH_OPAQUE_SPECIAL_TYPES |
| 96 |
float *floatVal; |
| 97 |
double *doubleVal; |
| 98 |
/* |
| 99 |
* t_union *unionVal; |
| 100 |
*/ |
| 101 |
#endif /* NETSNMP_WITH_OPAQUE_SPECIAL_TYPES */ |
| 102 |
} netsnmp_vardata; |
| 103 |
|
| 104 |
|
| 105 |
#define MAX_OID_LEN 128 /* max subid's in an oid */ |
| 106 |
|
| 107 |
/** @typedef struct variable_list netsnmp_variable_list |
| 108 |
* Typedefs the variable_list struct into netsnmp_variable_list */ |
| 109 |
/** @struct variable_list |
| 110 |
* The netsnmp variable list binding structure, it's typedef'd to |
| 111 |
* netsnmp_variable_list. |
| 112 |
*/ |
| 113 |
typedef struct variable_list { |
| 114 |
/** NULL for last variable */ |
| 115 |
struct variable_list *next_variable; |
| 116 |
/** Object identifier of variable */ |
| 117 |
oid *name; |
| 118 |
/** number of subid's in name */ |
| 119 |
size_t name_length; |
| 120 |
/** ASN type of variable */ |
| 121 |
u_char type; |
| 122 |
/** value of variable */ |
| 123 |
netsnmp_vardata val; |
| 124 |
/** the length of the value to be copied into buf */ |
| 125 |
size_t val_len; |
| 126 |
/** buffer to hold the OID */ |
| 127 |
oid name_loc[MAX_OID_LEN]; |
| 128 |
/** 90 percentile < 40. */ |
| 129 |
u_char buf[40]; |
| 130 |
/** (Opaque) hook for additional data */ |
| 131 |
void *data; |
| 132 |
/** callback to free above */ |
| 133 |
void (*dataFreeHook)(void *); |
| 134 |
int index; |
| 135 |
} netsnmp_variable_list; |
| 136 |
|
| 137 |
|
| 138 |
/** @typedef struct snmp_pdu to netsnmp_pdu |
| 139 |
* Typedefs the snmp_pdu struct into netsnmp_pdu */ |
| 140 |
/** @struct snmp_pdu |
| 141 |
* The snmp protocol data unit. |
| 142 |
*/ |
| 143 |
typedef struct snmp_pdu { |
| 144 |
|
| 145 |
#define non_repeaters errstat |
| 146 |
#define max_repetitions errindex |
| 147 |
|
| 148 |
/* |
| 149 |
* Protocol-version independent fields |
| 150 |
*/ |
| 151 |
/** snmp version */ |
| 152 |
long version; |
| 153 |
/** Type of this PDU */ |
| 154 |
int command; |
| 155 |
/** Request id - note: incremented for each retry */ |
| 156 |
long reqid; |
| 157 |
/** Message id for V3 messages note: incremented for each retry */ |
| 158 |
long msgid; |
| 159 |
/** Unique ID for incoming transactions */ |
| 160 |
long transid; |
| 161 |
/** Session id for AgentX messages */ |
| 162 |
long sessid; |
| 163 |
/** Error status (non_repeaters in GetBulk) */ |
| 164 |
long errstat; |
| 165 |
/** Error index (max_repetitions in GetBulk) */ |
| 166 |
long errindex; |
| 167 |
/** Uptime */ |
| 168 |
u_long time; |
| 169 |
u_long flags; |
| 170 |
|
| 171 |
int securityModel; |
| 172 |
/** noAuthNoPriv, authNoPriv, authPriv */ |
| 173 |
int securityLevel; |
| 174 |
int msgParseModel; |
| 175 |
|
| 176 |
/** smallest of max for transport, v3 msgMaxSize and local cfg. */ |
| 177 |
long msgMaxSize; |
| 178 |
|
| 179 |
/** |
| 180 |
* Transport-specific opaque data. This replaces the IP-centric address |
| 181 |
* field. |
| 182 |
*/ |
| 183 |
|
| 184 |
void *transport_data; |
| 185 |
int transport_data_length; |
| 186 |
|
| 187 |
/** |
| 188 |
* The actual transport domain. This SHOULD NOT BE FREE()D. |
| 189 |
*/ |
| 190 |
|
| 191 |
const oid *tDomain; |
| 192 |
size_t tDomainLen; |
| 193 |
|
| 194 |
netsnmp_variable_list *variables; |
| 195 |
|
| 196 |
|
| 197 |
/* |
| 198 |
* SNMPv1 & SNMPv2c fields |
| 199 |
*/ |
| 200 |
/** community for outgoing requests. */ |
| 201 |
u_char *community; |
| 202 |
/** length of community name. */ |
| 203 |
size_t community_len; |
| 204 |
|
| 205 |
/* |
| 206 |
* Trap information |
| 207 |
*/ |
| 208 |
/** System OID */ |
| 209 |
oid *enterprise; |
| 210 |
size_t enterprise_length; |
| 211 |
/** trap type */ |
| 212 |
long trap_type; |
| 213 |
/** specific type */ |
| 214 |
long specific_type; |
| 215 |
/** This is ONLY used for v1 TRAPs */ |
| 216 |
unsigned char agent_addr[4]; |
| 217 |
|
| 218 |
/* |
| 219 |
* SNMPv3 fields |
| 220 |
*/ |
| 221 |
/** context snmpEngineID */ |
| 222 |
u_char *contextEngineID; |
| 223 |
/** Length of contextEngineID */ |
| 224 |
size_t contextEngineIDLen; |
| 225 |
/** authoritative contextName */ |
| 226 |
char *contextName; |
| 227 |
/** Length of contextName */ |
| 228 |
size_t contextNameLen; |
| 229 |
/** authoritative snmpEngineID for security */ |
| 230 |
u_char *securityEngineID; |
| 231 |
/** Length of securityEngineID */ |
| 232 |
size_t securityEngineIDLen; |
| 233 |
/** on behalf of this principal */ |
| 234 |
char *securityName; |
| 235 |
/** Length of securityName. */ |
| 236 |
size_t securityNameLen; |
| 237 |
|
| 238 |
/* |
| 239 |
* AgentX fields |
| 240 |
* (also uses SNMPv1 community field) |
| 241 |
*/ |
| 242 |
int priority; |
| 243 |
int range_subid; |
| 244 |
|
| 245 |
void *securityStateRef; |
| 246 |
} netsnmp_pdu; |
| 247 |
|
| 248 |
|
| 249 |
/** |
| 250 |
* @typedef struct snmp_session netsnmp_session |
| 251 |
* Typedefs the snmp_session struct into netsnmp_session. |
| 252 |
*/ |
| 253 |
typedef struct snmp_session netsnmp_session; |
| 254 |
|
| 255 |
/** for openssl this should match up with EVP_MAX_MD_SIZE */ |
| 256 |
#define USM_AUTH_KU_LEN 64 |
| 257 |
#define USM_PRIV_KU_LEN 64 |
| 258 |
|
| 259 |
typedef int (*snmp_callback) (int, netsnmp_session *, int, |
| 260 |
netsnmp_pdu *, void *); |
| 261 |
typedef int (*netsnmp_callback) (int, netsnmp_session *, int, |
| 262 |
netsnmp_pdu *, void *); |
| 263 |
|
| 264 |
struct netsnmp_container_s; |
| 265 |
|
| 266 |
#ifndef NETSNMP_NO_TRAP_STATS |
| 267 |
/* |
| 268 |
* trap/inform statistics. |
| 269 |
* |
| 270 |
* all times are sysuptime |
| 271 |
*/ |
| 272 |
typedef struct netsnmp_trap_stats_s { |
| 273 |
u_long sent_count; |
| 274 |
u_long sent_last_sent; |
| 275 |
|
| 276 |
u_long sent_fail_count; |
| 277 |
u_long sent_last_fail; |
| 278 |
|
| 279 |
u_long ack_count; |
| 280 |
u_long ack_last_rcvd; |
| 281 |
|
| 282 |
u_long sec_err_count; |
| 283 |
u_long sec_err_last; |
| 284 |
|
| 285 |
u_long timeouts; |
| 286 |
u_long sent_last_timeout; |
| 287 |
} netsnmp_trap_stats; |
| 288 |
#endif /* NETSNMP_NO_TRAP_STATS */ |
| 289 |
|
| 290 |
/** @struct snmp_session |
| 291 |
* The snmp session structure. |
| 292 |
*/ |
| 293 |
struct snmp_session { |
| 294 |
/* |
| 295 |
* Protocol-version independent fields |
| 296 |
*/ |
| 297 |
/** snmp version */ |
| 298 |
long version; |
| 299 |
/** Number of retries before timeout. */ |
| 300 |
int retries; |
| 301 |
/** Message timeout in μs before first retry and between retries */ |
| 302 |
long timeout; |
| 303 |
u_long flags; |
| 304 |
struct snmp_session *subsession; |
| 305 |
struct snmp_session *next; |
| 306 |
|
| 307 |
/** name or address of default peer (may include transport specifier and/or port number) */ |
| 308 |
char *peername; |
| 309 |
/** UDP port number of peer. (NO LONGER USED - USE peername INSTEAD) */ |
| 310 |
u_short remote_port NETSNMP_ATTRIBUTE_DEPRECATED; |
| 311 |
/** My Domain name or dotted IP address, 0 for default */ |
| 312 |
char *localname; |
| 313 |
/** My UDP port number, 0 for default, picked randomly */ |
| 314 |
u_short local_port; |
| 315 |
/** |
| 316 |
* Authentication function or NULL if null authentication is used |
| 317 |
*/ |
| 318 |
u_char *(*authenticator) (u_char *, size_t *, u_char *, size_t); |
| 319 |
/** Function to interpret incoming data */ |
| 320 |
netsnmp_callback callback; |
| 321 |
/** |
| 322 |
* Pointer to data that the callback function may consider important |
| 323 |
*/ |
| 324 |
void *callback_magic; |
| 325 |
/** copy of system errno */ |
| 326 |
int s_errno; |
| 327 |
/** copy of library errno */ |
| 328 |
int s_snmp_errno; |
| 329 |
/** Session id - AgentX only */ |
| 330 |
long sessid; |
| 331 |
|
| 332 |
/* |
| 333 |
* SNMPv1 & SNMPv2c fields |
| 334 |
*/ |
| 335 |
/** community for outgoing requests. */ |
| 336 |
u_char *community; |
| 337 |
/** Length of community name. */ |
| 338 |
size_t community_len; |
| 339 |
/** Largest message to try to receive. */ |
| 340 |
size_t rcvMsgMaxSize; |
| 341 |
/** Largest message to try to send. */ |
| 342 |
size_t sndMsgMaxSize; |
| 343 |
|
| 344 |
/* |
| 345 |
* SNMPv3 fields |
| 346 |
*/ |
| 347 |
/** are we the authoritative engine? */ |
| 348 |
u_char isAuthoritative; |
| 349 |
/** authoritative snmpEngineID */ |
| 350 |
u_char *contextEngineID; |
| 351 |
/** Length of contextEngineID */ |
| 352 |
size_t contextEngineIDLen; |
| 353 |
/** initial engineBoots for remote engine */ |
| 354 |
u_int engineBoots; |
| 355 |
/** initial engineTime for remote engine */ |
| 356 |
u_int engineTime; |
| 357 |
/** authoritative contextName */ |
| 358 |
char *contextName; |
| 359 |
/** Length of contextName */ |
| 360 |
size_t contextNameLen; |
| 361 |
/** authoritative snmpEngineID */ |
| 362 |
u_char *securityEngineID; |
| 363 |
/** Length of contextEngineID */ |
| 364 |
size_t securityEngineIDLen; |
| 365 |
/** on behalf of this principal */ |
| 366 |
char *securityName; |
| 367 |
/** Length of securityName. */ |
| 368 |
size_t securityNameLen; |
| 369 |
|
| 370 |
/** auth protocol oid */ |
| 371 |
oid *securityAuthProto; |
| 372 |
/** Length of auth protocol oid */ |
| 373 |
size_t securityAuthProtoLen; |
| 374 |
/** Ku for auth protocol XXX */ |
| 375 |
u_char securityAuthKey[USM_AUTH_KU_LEN]; |
| 376 |
/** Length of Ku for auth protocol */ |
| 377 |
size_t securityAuthKeyLen; |
| 378 |
/** Kul for auth protocol */ |
| 379 |
u_char *securityAuthLocalKey; |
| 380 |
/** Length of Kul for auth protocol XXX */ |
| 381 |
size_t securityAuthLocalKeyLen; |
| 382 |
|
| 383 |
/** priv protocol oid */ |
| 384 |
oid *securityPrivProto; |
| 385 |
/** Length of priv protocol oid */ |
| 386 |
size_t securityPrivProtoLen; |
| 387 |
/** Ku for privacy protocol XXX */ |
| 388 |
u_char securityPrivKey[USM_PRIV_KU_LEN]; |
| 389 |
/** Length of Ku for priv protocol */ |
| 390 |
size_t securityPrivKeyLen; |
| 391 |
/** Kul for priv protocol */ |
| 392 |
u_char *securityPrivLocalKey; |
| 393 |
/** Length of Kul for priv protocol XXX */ |
| 394 |
size_t securityPrivLocalKeyLen; |
| 395 |
|
| 396 |
/** snmp security model, v1, v2c, usm */ |
| 397 |
int securityModel; |
| 398 |
/** noAuthNoPriv, authNoPriv, authPriv */ |
| 399 |
int securityLevel; |
| 400 |
/** target param name */ |
| 401 |
char *paramName; |
| 402 |
#ifndef NETSNMP_NO_TRAP_STATS |
| 403 |
netsnmp_trap_stats *trap_stats; |
| 404 |
#endif /* NETSNMP_NO_TRAP_STATS */ |
| 405 |
|
| 406 |
/** |
| 407 |
* security module specific |
| 408 |
*/ |
| 409 |
void *securityInfo; |
| 410 |
|
| 411 |
/** |
| 412 |
* transport specific configuration |
| 413 |
*/ |
| 414 |
struct netsnmp_container_s *transport_configuration; |
| 415 |
|
| 416 |
/** |
| 417 |
* use as you want data |
| 418 |
* |
| 419 |
* used by 'SNMP_FLAGS_RESP_CALLBACK' handling in the agent |
| 420 |
* XXX: or should we add a new field into this structure? |
| 421 |
*/ |
| 422 |
void *myvoid; |
| 423 |
|
| 424 |
/** |
| 425 |
* session specific user |
| 426 |
*/ |
| 427 |
struct usmUser *sessUser; |
| 428 |
}; |
| 429 |
|
| 430 |
|
| 431 |
#include <net-snmp/library/types.h> |
| 432 |
#include <net-snmp/definitions.h> |
| 433 |
#include <net-snmp/library/snmp_api.h> |
| 434 |
|
| 435 |
#ifdef __cplusplus |
| 436 |
} |
| 437 |
#endif |
| 438 |
|
| 439 |
#endif /* NET_SNMP_TYPES_H */ |