From: kostas <> Date: Fri, 21 Nov 1997 07:34:06 +0000 (+0000) Subject: Include files for snmp support X-Git-Tag: SQUID_3_0_PRE1~4504 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8bde32eac8de2d9cc73e577235acb1e867a74341;p=thirdparty%2Fsquid.git Include files for snmp support --- diff --git a/include/asn1.h b/include/asn1.h new file mode 100644 index 0000000000..979c39b3ae --- /dev/null +++ b/include/asn1.h @@ -0,0 +1,199 @@ +/* + * Definitions for Abstract Syntax Notation One, ASN.1 + * As defined in ISO/IS 8824 and ISO/IS 8825 + * + * + */ +/*********************************************************** + Copyright 1988, 1989 by Carnegie Mellon University + + All Rights Reserved + +Permission to use, copy, modify, and distribute this software and its +documentation for any purpose and without fee is hereby granted, +provided that the above copyright notice appear in all copies and that +both that copyright notice and this permission notice appear in +supporting documentation, and that the name of CMU not be +used in advertising or publicity pertaining to distribution of the +software without specific, written prior permission. + +CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING +ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL +CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR +ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, +WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS +SOFTWARE. +******************************************************************/ + +#ifndef ASN1_H +#define ASN1_H + + +#undef _ANSI_ARGS_ +#if (defined(__STDC__) && ! defined(NO_PROTOTYPE)) || defined(USE_PROTOTYPE) +# define _ANSI_ARGS_(x) x +#else +# define _ANSI_ARGS_(x) () +#endif + +#include + +#ifndef EIGHTBIT_SUBIDS +typedef u_long oid; +#define MAX_SUBID 0xFFFFFFFF +#else +typedef u_char oid; +#define MAX_SUBID 0xFF +#endif + +#define MAX_OID_LEN 64 /* max subid's in an oid */ + +#define ASN_BOOLEAN (0x01) +#define ASN_INTEGER (0x02) +#define ASN_BIT_STR (0x03) +#define ASN_OCTET_STR (0x04) +#define ASN_NULL (0x05) +#define ASN_OBJECT_ID (0x06) +#define ASN_SEQUENCE (0x10) +#define ASN_SET (0x11) + +#define ASN_UNIVERSAL (0x00) +#define ASN_APPLICATION (0x40) +#define ASN_CONTEXT (0x80) +#define ASN_PRIVATE (0xC0) + +#define ASN_PRIMITIVE (0x00) +#define ASN_CONSTRUCTOR (0x20) + +#define ASN_LONG_LEN (0x80) +#define ASN_EXTENSION_ID (0x1F) +#define ASN_BIT8 (0x80) + +#define IS_CONSTRUCTOR(byte) ((byte) & ASN_CONSTRUCTOR) +#define IS_EXTENSION_ID(byte) (((byte) & ASN_EXTENSION_ID) == ASN_EXTENSION_ID) + +/* + * support for 64 bit linux platform. + * instead of a rewrite, which is obviously neccessary, + * we replace `long' by `int32' + */ +#if defined(__alpha) +typedef unsigned int u_int32; +typedef int int32; +#else +typedef unsigned long u_int32; +typedef long int32; +#endif + +/* + * internal 64 bit representation: + */ +struct counter64 { + u_int32 high; + u_int32 low; + }; + + +extern u_char *asn_parse_int _ANSI_ARGS_((u_char *data, + int *datalength, + u_char *type, + long *intp, + int intsize)); + +extern u_char *asn_build_int _ANSI_ARGS_((u_char *data, + int *datalength, + u_char type, + long *intp, + int intsize)); + +extern u_char *asn_parse_unsigned_int _ANSI_ARGS_((u_char *data, + int *datalength, + u_char *type, + u_long *intp, + int intsize)); + +extern u_char *asn_build_unsigned_int _ANSI_ARGS_((u_char *data, + int *datalength, + u_char type, + u_long *intp, + int intsize)); + +extern u_char *asn_parse_string _ANSI_ARGS_((u_char *data, + int *datalength, + u_char *type, + u_char *string, + int *len)); + +extern u_char *asn_build_string _ANSI_ARGS_((u_char *data, + int *datalength, + u_char type, + u_char *str, + int len)); + +extern u_char *asn_parse_header _ANSI_ARGS_((u_char *data, + int *datalength, + u_char *type)); + +extern u_char *asn_build_header _ANSI_ARGS_((u_char *data, + int *datalength, + u_char type, + int len)); + +extern u_char *asn_build_sequence _ANSI_ARGS_((u_char *data, + int *datalength, + u_char type, + int len)); + +extern u_char *asn_parse_length _ANSI_ARGS_((u_char *data, + u_long *eln)); + +extern u_char *asn_build_length _ANSI_ARGS_((u_char *data, + int *datalength, + int len)); + +extern u_char *asn_parse_objid _ANSI_ARGS_(( + u_char *data, + int *datalength, + u_char *type, + oid *objid, + int *objidlength)); + +extern u_char *asn_build_objid _ANSI_ARGS_((u_char *data, + int *datalength, + u_char type, + oid *objid, + int objidlength)); + +extern u_char *asn_parse_null _ANSI_ARGS_((u_char *data, + int *datalength, + u_char *type)); + +extern u_char *asn_build_null _ANSI_ARGS_((u_char *data, + int *datalength, + u_char type)); +extern u_char *asn_parse_bitstring _ANSI_ARGS_((u_char *data, + int *datalength, + u_char *type, + u_char *str, + int *len)); + +extern u_char *asn_build_bitstring _ANSI_ARGS_((u_char *data, + int *datalength, + u_char type, + u_char *str, + int len)); + +extern u_char *asn_parse_unsigned_int64 _ANSI_ARGS_((u_char *data, + int *datalength, + u_char *type, + struct counter64 *cp, + int cp_size)); + +extern u_char *asn_build_unsigned_int64 _ANSI_ARGS_((u_char *data, + int *datalength, + u_char type, + struct counter64 *cp, + int cp_size)); + +#endif diff --git a/include/md5.h b/include/md5.h new file mode 100644 index 0000000000..37d1d34539 --- /dev/null +++ b/include/md5.h @@ -0,0 +1,70 @@ +/* taken from RFC-1321/Appendices A.1/A.2 */ + +/* GLOBAL.H - RSAREF types and constants + */ + +/* PROTOTYPES should be set to one if and only if the compiler supports + function argument prototyping. +The following makes PROTOTYPES default to 0 if it has not already + been defined with C compiler flags. + */ +#ifndef PROTOTYPES +#define PROTOTYPES 0 +#endif + +/* POINTER defines a generic pointer type */ +typedef unsigned char *POINTER; + +/* UINT2 defines a two byte word */ +typedef unsigned short int UINT2; + +/* UINT4 defines a four byte word */ +typedef unsigned long int UINT4; + +/* PROTO_LIST is defined depending on how PROTOTYPES is defined above. +If using PROTOTYPES, then PROTO_LIST returns the list, otherwise it + returns an empty list. + */ +#if PROTOTYPES +#define PROTO_LIST(list) list +#else +#define PROTO_LIST(list) () +#endif + +/* MD5.H - header file for MD5C.C + */ + +/* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All +rights reserved. + +License to copy and use this software is granted provided that it +is identified as the "RSA Data Security, Inc. MD5 Message-Digest +Algorithm" in all material mentioning or referencing this software +or this function. + +License is also granted to make and use derivative works provided +that such works are identified as "derived from the RSA Data +Security, Inc. MD5 Message-Digest Algorithm" in all material +mentioning or referencing the derived work. + +RSA Data Security, Inc. makes no representations concerning either +the merchantability of this software or the suitability of this +software for any particular purpose. It is provided "as is" +without express or implied warranty of any kind. + +These notices must be retained in any copies of any part of this +documentation and/or software. + */ + +/* MD5 context. */ +typedef struct { + UINT4 state[4]; /* state (ABCD) */ + UINT4 count[2]; /* number of bits, modulo 2^64 (lsb first) */ + unsigned char buffer[64]; /* input buffer */ +} MD5_CTX; + +void MD5Init PROTO_LIST ((MD5_CTX *)); +void MD5Update PROTO_LIST + ((MD5_CTX *, unsigned char *, unsigned int)); +void MD5Final PROTO_LIST ((unsigned char [16], MD5_CTX *)); + diff --git a/include/snmp.h b/include/snmp.h new file mode 100644 index 0000000000..d3b47c38ea --- /dev/null +++ b/include/snmp.h @@ -0,0 +1,147 @@ +/* + * Definitions for the Simple Network Management Protocol (RFC 1067). + * + * + */ +/*********************************************************** + Copyright 1988, 1989 by Carnegie Mellon University + + All Rights Reserved + +Permission to use, copy, modify, and distribute this software and its +documentation for any purpose and without fee is hereby granted, +provided that the above copyright notice appear in all copies and that +both that copyright notice and this permission notice appear in +supporting documentation, and that the name of CMU not be +used in advertising or publicity pertaining to distribution of the +software without specific, written prior permission. + +CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING +ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL +CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR +ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, +WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS +SOFTWARE. +******************************************************************/ + +#ifndef SNMP_H +#define SNMP_H + +#include "snmp_api.h" + + +#define SNMP_PORT 161 +#define SNMP_TRAP_PORT 162 + +#define SNMP_MAX_LEN 1450 + +#define SNMP_MESSAGE_LIFETIME 150 + +#define SNMP_VERSION_1 0 +#define SNMP_VERSION_2C 1 +#define SNMP_VERSION_2 2 + +#define SNMP_USEC_MODEL 1 + +#define GET_REQ_MSG (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x0) +#define GETNEXT_REQ_MSG (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x1) +#define GET_RSP_MSG (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x2) +#define SET_REQ_MSG (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x3) +#define TRP_REQ_MSG (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x4) + +#define GETBULK_REQ_MSG (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x5) +#define INFORM_REQ_MSG (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x6) +#define TRP2_REQ_MSG (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x7) +#define REPORT_MSG (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x8) + +#define SNMP_NOSUCHOBJECT (ASN_CONTEXT | ASN_PRIMITIVE | 0x0) +#define SNMP_NOSUCHINSTANCE (ASN_CONTEXT | ASN_PRIMITIVE | 0x1) +#define SNMP_ENDOFMIBVIEW (ASN_CONTEXT | ASN_PRIMITIVE | 0x2) + +#define SNMP_ERR_NOERROR (0) +#define SNMP_ERR_TOOBIG (1) +#define SNMP_ERR_NOSUCHNAME (2) +#define SNMP_ERR_BADVALUE (3) +#define SNMP_ERR_READONLY (4) +#define SNMP_ERR_GENERR (5) + +#define SNMP_ERR_NOACCESS (6) +#define SNMP_ERR_WRONGTYPE (7) +#define SNMP_ERR_WRONGLENGTH (8) +#define SNMP_ERR_WRONGENCODING (9) +#define SNMP_ERR_WRONGVALUE (10) +#define SNMP_ERR_NOCREATION (11) +#define SNMP_ERR_INCONSISTENTVALUE (12) +#define SNMP_ERR_RESOURCEUNAVAILABLE (13) +#define SNMP_ERR_COMMITFAILED (14) +#define SNMP_ERR_UNDOFAILED (15) +#define SNMP_ERR_AUTHORIZATIONERROR (16) +#define SNMP_ERR_NOTWRITABLE (17) +#define SNMP_ERR_INCONSISTENTNAME (18) + +#define SNMP_TRAP_COLDSTART (0x0) +#define SNMP_TRAP_WARMSTART (0x1) +#define SNMP_TRAP_LINKDOWN (0x2) +#define SNMP_TRAP_LINKUP (0x3) +#define SNMP_TRAP_AUTHFAIL (0x4) +#define SNMP_TRAP_EGPNEIGHBORLOSS (0x5) +#define SNMP_TRAP_ENTERPRISESPECIFIC (0x6) + +#define USEC_QOS_AUTH (0x01) +#define USEC_QOS_PRIV (0x02) +#define USEC_QOS_AUTHPRIV (0x03) +#define USEC_QOS_GENREPORT (0x04) +#define USEC_QOS_NOAUTH_NOPRIV (0) + +#define SNMP_STAT_PACKETS 0 +#define SNMP_STAT_ENCODING_ERRORS 1 +#define USEC_STAT_UNSUPPORTED_QOS 2 +#define USEC_STAT_NOT_IN_WINDOWS 3 +#define USEC_STAT_UNKNOWN_USERNAMES 4 +#define USEC_STAT_WRONG_DIGEST_VALUES 5 +#define USEC_STAT_UNKNOWN_CONTEXT_SELECTORS 6 +#define USEC_STAT_BAD_PARAMETERS 7 +#define USEC_STAT_UNAUTHORIZED_OPERATIONS 8 +#define SNMP_STAT_BAD_OPERATIONS 9 +#define SNMP_STAT_PROXY_DROPS 10 +#define SNMP_STAT_SILENT_DROPS 11 +#define SNMP_STAT_V1_BAD_COMMUNITY_NAMES 12 +#define SNMP_STAT_V1_BAD_COMMUNITY_USES 13 + +#define SNMP_LAST_STAT SNMP_STAT_V1_BAD_COMMUNITY_USES + + +typedef struct _conf_if_list { + char *name; + int type; + int speed; + struct _conf_if_list *next; +} conf_if_list; + +extern conf_if_list *if_list; + +#ifndef SQUID_SNMP +/*extern void init_snmp();*/ + +extern int read_objid (char *input, + oid *output, + int *out_len); + +extern void sprint_objid (char *buf,oid *id,int idlen); +extern void print_objid (oid *id, + int idlen); +void snmp_add_null_var (struct snmp_pdu *, + oid *, + int); +extern void xdump (u_char *cp, + int length, + char *prefix); + +extern void snmp_synch_setup (struct snmp_session *session); + +extern int snmp_synch_response (struct snmp_session *ss, + struct snmp_pdu *pdu, + struct snmp_pdu **response); +#endif +#endif diff --git a/include/snmp_api.h b/include/snmp_api.h new file mode 100644 index 0000000000..336aa5cf6b --- /dev/null +++ b/include/snmp_api.h @@ -0,0 +1,325 @@ +/*********************************************************** + Copyright 1989 by Carnegie Mellon University + + All Rights Reserved + +Permission to use, copy, modify, and distribute this software and its +documentation for any purpose and without fee is hereby granted, +provided that the above copyright notice appear in all copies and that +both that copyright notice and this permission notice appear in +supporting documentation, and that the name of CMU not be +used in advertising or publicity pertaining to distribution of the +software without specific, written prior permission. + +CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING +ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL +CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR +ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, +WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS +SOFTWARE. +******************************************************************/ + +/* + * snmp_api.h - API for access to snmp. + */ + +#ifndef _SNMP_API_H +#define _SNMP_API_H + + +#undef _ANSI_ARGS_ +#if (defined(__STDC__) && ! defined(NO_PROTOTYPE)) || defined(USE_PROTOTYPE) +# define _ANSI_ARGS_(x) x +#else +# define _ANSI_ARGS_(x) () +#endif + + +#include +#include +#include + +#if defined(sun) && !defined(__svr4__) +typedef int ssize_t; +#endif + +#include "asn1.h" + + +typedef struct sockaddr_in ipaddr; + +typedef struct { + u_char securityModel; + u_char qoS; + u_char agentID[12]; + u_long agentBoots; + int agentTime; + int MMS; + int userLen; + u_char userName[16]; + int authLen; + u_char authDigest[16]; + u_char *authDigestPtr; + int contextLen; + u_char contextSelector[40]; +} Parameters; + +struct snmp_session { + int retries; /* Number of retries before timeout. */ + long timeout; /* Number of uS until first timeout, then exponential backoff */ + char *peername; /* Domain name or dotted IP address of default peer */ + u_short remote_port; /* UDP port number of peer. */ + u_short local_port; /* My UDP port number, 0 for default, picked randomly */ + + /* Authentication function or NULL if null authentication is used */ + int (*authenticator)(); + int (*callback)(); /* Function to interpret incoming data */ + + /* Pointer to data that the callback function may consider important */ + void *callback_magic; + + int version; /* SNMP version number */ + + /* fields to support SNMPv1 community model */ + int community_len; + u_char *community; + + /* the private keys to use for user-based security */ + u_char authKey[16]; + u_char privKey[16]; + + /* fields to support user-based security model in SNMPv2 */ + Parameters params; + + u_char qoS; + u_char agentID[16]; + u_long agentBoots; + int agentTime; /* the agentTime value */ + int agentClock; /* the running agentClock */ + int userLen; + u_char userName[32]; + int MMS; + int contextLen; + u_char contextSelector[64]; + + /* misc stuff */ + int readView; + int writeView; +}; + +/* + * Set fields in session and pdu to the following to get a default or unconfigured value. + */ +#define SNMP_DEFAULT_COMMUNITY_LEN 0 /* to get a default community name */ +#define SNMP_DEFAULT_RETRIES -1 +#define SNMP_DEFAULT_TIMEOUT -1 +#define SNMP_DEFAULT_REMPORT 0 +#define SNMP_DEFAULT_REQID 0 +#define SNMP_DEFAULT_ERRSTAT -1 +#define SNMP_DEFAULT_ERRINDEX -1 +#define SNMP_DEFAULT_ADDRESS 0 +#define SNMP_DEFAULT_PEERNAME NULL +#define SNMP_DEFAULT_ENTERPRISE_LENGTH 0 +#define SNMP_DEFAULT_TIME 0 + +/* + * default initial timeout ans default retries; + * the timeout is doubled for every retry: + * 0.3 + 0.6 + 1.2 + 2.4 + 4.8 = 9.3 + */ +#define SNMP_API_DEFAULT_RETRIES 6 +#define SNMP_API_DEFAULT_TIMEOUT 300000L + +extern int snmp_errno; +/* Error return values */ +#define SNMPERR_GENERR -1 +#define SNMPERR_BAD_LOCPORT -2 /* local port was already in use */ +#define SNMPERR_BAD_ADDRESS -3 +#define SNMPERR_BAD_SESSION -4 +#define SNMPERR_TOO_LONG -5 + + +struct snmp_pdu { + ipaddr address; /* Address of peer */ + + int command; /* Type of this PDU */ + + Parameters params; + + u_long reqid; /* Request id */ + u_long errstat; /* Error status */ + u_long errindex; /* Error index */ + + /* Trap information */ + oid *enterprise;/* System OID */ + int enterprise_length; + ipaddr agent_addr; /* address of object generating trap */ + int trap_type; /* trap type */ + int specific_type; /* specific type */ + u_long time; /* Uptime */ + + struct variable_list *variables; +}; + + +struct variable_list { + struct variable_list *next_variable; /* NULL for last variable */ + oid *name; /* Object identifier of variable */ + int name_length; /* number of subid's in name */ + u_char type; /* ASN type of variable */ + union { /* value of variable */ + long *integer; + u_char *string; + oid *objid; + u_char *bitstring; + struct counter64 *counter64; + + } val; + int val_len; +}; + +#ifndef SQUID_SNMP +/* + * struct snmp_session *snmp_open(session) + * struct snmp_session *session; + * + * Sets up the session with the snmp_session information provided + * by the user. Then opens and binds the necessary UDP port. + * A handle to the created session is returned (this is different than + * the pointer passed to snmp_open()). On any error, NULL is returned + * and snmp_errno is set to the appropriate error code. + */ +struct snmp_session *snmp_open _ANSI_ARGS_((struct snmp_session *session)); + +/* + * int snmp_close(session) + * struct snmp_session *session; + * + * Close the input session. Frees all data allocated for the session, + * dequeues any pending requests, and closes any sockets allocated for + * the session. Returns 0 on error, 1 otherwise. + */ +int snmp_close _ANSI_ARGS_((struct snmp_session *session)); + + +/* + * int snmp_send(session, pdu) + * struct snmp_session *session; + * struct snmp_pdu *pdu; + * + * Sends the input pdu on the session after calling snmp_build to create + * a serialized packet. If necessary, set some of the pdu data from the + * session defaults. Add a request corresponding to this pdu to the list + * of outstanding requests on this session, then send the pdu. + * Returns the request id of the generated packet if applicable, otherwise 1. + * On any error, 0 is returned. + * The pdu is freed by snmp_send() unless a failure occured. + */ +int snmp_send _ANSI_ARGS_((struct snmp_session *session, + struct snmp_pdu *pdu)); + + +/* + * void snmp_read(fdset) + * fd_set *fdset; + * + * Checks to see if any of the fd's set in the fdset belong to + * snmp. Each socket with it's fd set has a packet read from it + * and snmp_parse is called on the packet received. The resulting pdu + * is passed to the callback routine for that session. If the callback + * routine returns successfully, the pdu and it's request are deleted. + */ +void snmp_read (fd_set *fdset); + + +/* + * void + * snmp_free_pdu(pdu) + * struct snmp_pdu *pdu; + * + * Frees the pdu and any malloc'd data associated with it. + */ +void snmp_free_pdu (struct snmp_pdu *pdu); + +/* + * int snmp_select_info(numfds, fdset, timeout, block) + * int *numfds; + * fd_set *fdset; + * struct timeval *timeout; + * int *block; + * + * Returns info about what snmp requires from a select statement. + * numfds is the number of fds in the list that are significant. + * All file descriptors opened for SNMP are OR'd into the fdset. + * If activity occurs on any of these file descriptors, snmp_read + * should be called with that file descriptor set. + * + * The timeout is the latest time that SNMP can wait for a timeout. The + * select should be done with the minimum time between timeout and any other + * timeouts necessary. This should be checked upon each invocation of select. + * If a timeout is received, snmp_timeout should be called to check if the + * timeout was for SNMP. (snmp_timeout is idempotent) + * + * Block is 1 if the select is requested to block indefinitely, rather than time out. + * If block is input as 1, the timeout value will be treated as undefined, but it must + * be available for setting in snmp_select_info. On return, if block is true, the value + * of timeout will be undefined. + * + * snmp_select_info returns the number of open sockets. (i.e. The number of sessions open) + */ +int snmp_select_info _ANSI_ARGS_((int *numfds, + fd_set *fdset, + struct timeval *timeout, + int *block)); + +/* + * void snmp_timeout(); + * + * snmp_timeout should be called whenever the timeout from snmp_select_info expires, + * but it is idempotent, so snmp_timeout can be polled (probably a cpu expensive + * proposition). snmp_timeout checks to see if any of the sessions have an + * outstanding request that has timed out. If it finds one (or more), and that + * pdu has more retries available, a new packet is formed from the pdu and is + * resent. If there are no more retries available, the callback for the session + * is used to alert the user of the timeout. + */ +void snmp_timeout _ANSI_ARGS_((void)); + + +/* + * This routine must be supplied by the application: + * + * u_char *authenticator(pdu, length, community, community_len) + * u_char *pdu; The rest of the PDU to be authenticated + * int *length; The length of the PDU (updated by the authenticator) + * u_char *community; The community name to authenticate under. + * int community_len The length of the community name. + * + * Returns the authenticated pdu, or NULL if authentication failed. + * If null authentication is used, the authenticator in snmp_session can be + * set to NULL(0). + */ + +/* + * This routine must be supplied by the application: + * + * int callback(operation, session, reqid, pdu, magic) + * int operation; + * struct snmp_session *session; The session authenticated under. + * int reqid; The request id of this pdu (0 for TRAP) + * struct snmp_pdu *pdu; The pdu information. + * void *magic A link to the data for this routine. + * + * Returns 1 if request was successful, 0 if it should be kept pending. + * Any data in the pdu must be copied because it will be freed elsewhere. + * Operations are defined below: + */ +#endif + +#define RECEIVED_MESSAGE 1 +#define TIMED_OUT 2 + +extern int snmp_dump_packet; + +#endif diff --git a/include/snmp_client.h b/include/snmp_client.h new file mode 100644 index 0000000000..b1b9249e23 --- /dev/null +++ b/include/snmp_client.h @@ -0,0 +1,58 @@ +/* + * snmp_client.h + */ + +/*********************************************************** + Copyright 1988, 1989 by Carnegie Mellon University + + All Rights Reserved + +Permission to use, copy, modify, and distribute this software and its +documentation for any purpose and without fee is hereby granted, +provided that the above copyright notice appear in all copies and that +both that copyright notice and this permission notice appear in +supporting documentation, and that the name of CMU not be +used in advertising or publicity pertaining to distribution of the +software without specific, written prior permission. + +CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING +ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL +CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR +ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, +WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS +SOFTWARE. +******************************************************************/ + +#ifndef SNMP_CLIENT_H +#define SNMP_CLIENT_H + +#undef _ANSI_ARGS_ +#if (defined(__STDC__) && ! defined(NO_PROTOTYPE)) || defined(USE_PROTOTYPE) +# define _ANSI_ARGS_(x) x +#else +# define _ANSI_ARGS_(x) () +#endif + + + +struct synch_state { + int waiting; + int status; +/* status codes */ +#define STAT_SUCCESS 0 +#define STAT_ERROR 1 +#define STAT_TIMEOUT 2 + int reqid; + struct snmp_pdu *pdu; +}; + +extern struct synch_state snmp_synch_state; + +extern struct snmp_pdu *snmp_pdu_create _ANSI_ARGS_((int cmd)); + +extern struct snmp_pdu *snmp_fix_pdu _ANSI_ARGS_((struct snmp_pdu *pdu, + int cmd)); +extern char *snmp_errstring _ANSI_ARGS_((int errstat)); + +#endif diff --git a/include/snmp_impl.h b/include/snmp_impl.h new file mode 100644 index 0000000000..46a96c7d2e --- /dev/null +++ b/include/snmp_impl.h @@ -0,0 +1,137 @@ +/* + * Definitions for SNMP (RFC 1067) implementation. + * + * + */ +/*********************************************************** + Copyright 1988, 1989 by Carnegie Mellon University + + All Rights Reserved + +Permission to use, copy, modify, and distribute this software and its +documentation for any purpose and without fee is hereby granted, +provided that the above copyright notice appear in all copies and that +both that copyright notice and this permission notice appear in +supporting documentation, and that the name of CMU not be +used in advertising or publicity pertaining to distribution of the +software without specific, written prior permission. + +CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING +ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL +CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR +ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, +WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS +SOFTWARE. +******************************************************************/ + +#ifndef SNMP_IMPL_H +#define SNMP_IMPL_H + + +#undef _ANSI_ARGS_ +#if (defined(__STDC__) && ! defined(NO_PROTOTYPE)) || defined(USE_PROTOTYPE) +# define _ANSI_ARGS_(x) x +#else +# define _ANSI_ARGS_(x) () +#endif + + +#if (defined vax) || (defined (mips)) +/* + * This is a fairly bogus thing to do, but there seems to be no better way for + * compilers that don't understand void pointers. + */ +#define void char +#endif + +/* + * Error codes: + */ +/* + * These must not clash with SNMP error codes (all positive). + */ +#define PARSE_ERROR -1 +#define BUILD_ERROR -2 + +#define SID_MAX_LEN 200 +#define MAX_NAME_LEN 64 /* number of subid's in a objid */ + +#ifndef NULL +#define NULL 0 +#endif + +#ifndef TRUE +#define TRUE 1 +#endif +#ifndef FALSE +#define FALSE 0 +#endif + +#define READ 1 +#define WRITE 0 + +#define RESERVE1 0 +#define RESERVE2 1 +#define COMMIT 2 +#define ACTION 3 +#define FREE 4 + +#define RONLY 0xAAAA /* read access for everyone */ +#define RWRITE 0xAABA /* add write access for community private */ +#define NOACCESS 0x0000 /* no access for anybody */ + +#define INTEGER ASN_INTEGER +#define STRING ASN_OCTET_STR +#define OBJID ASN_OBJECT_ID +#define NULLOBJ ASN_NULL + +/* defined types (from the SMI, RFC 1065) */ +#define IPADDRESS (ASN_APPLICATION | 0) +#define COUNTER (ASN_APPLICATION | 1) +#define GAUGE (ASN_APPLICATION | 2) +#define TIMETICKS (ASN_APPLICATION | 3) +#define OPAQUE (ASN_APPLICATION | 4) + +#define NSAP (ASN_APPLICATION | 5) +#define COUNTER64 (ASN_APPLICATION | 6) +#define UINTEGER (ASN_APPLICATION | 7) +#define DEBUG +#ifdef DEBUG +#define ERROR(string) fprintf(stderr,"%s(%d): %s\n",__FILE__, __LINE__, string); +#else +#define ERROR(string) +#endif + +/* from snmp.c*/ +extern u_char sid[]; /* size SID_MAX_LEN */ + +extern u_char *snmp_parse_var_op _ANSI_ARGS_((u_char *data, + oid *var_name, + int *var_name_len, + u_char *var_val_type, + int *var_val_len, + u_char **var_val, + int *listlength)); + +extern u_char *snmp_build_var_op _ANSI_ARGS_((u_char *data, + oid *var_name, + int *var_name_len, + u_char var_val_type, + int var_val_len, + u_char *var_val, + int *listlength)); + +extern u_char *snmp_auth_parse _ANSI_ARGS_((u_char *data, + int *length, + u_char *sid, + int *slen, + long *version)); + +extern u_char *snmp_auth_build _ANSI_ARGS_((u_char *data, + int *length, + struct snmp_session *session, + int is_agent, + int messagelen)); + +#endif diff --git a/include/snmp_util.h b/include/snmp_util.h new file mode 100644 index 0000000000..d9be9146ff --- /dev/null +++ b/include/snmp_util.h @@ -0,0 +1,90 @@ +#ifndef SNMP_UTIL_H +#define SNMP_UTIL_H + + +#undef _ANSI_ARGS_ +#if (defined(__STDC__) && ! defined(NO_PROTOTYPE)) || defined(USE_PROTOTYPE) +# define _ANSI_ARGS_(x) x +#else +# define _ANSI_ARGS_(x) () +#endif + + +/* + * call a function at regular intervals (in seconds): + */ +extern void snmp_alarm _ANSI_ARGS_((int ival, void (*handler) (void))); + + +/* + * service for filedescriptors: + */ + +extern void fd_add _ANSI_ARGS_((int fd, void (*func)(int fd))); +extern void fd_service _ANSI_ARGS_((void)); + + +/* ---------------------------------------------------------------------- */ + +/* +** SNMP Agent extension for Spacer-Controler Management +** +** Copyright (c) 1997 FT/CNET/DES/GRL Olivier Montanuy +** +*/ +/* +** Function to safely copy a string, and ensure the last +** character is always '\0'. +*/ +void +strcpy_safe _ANSI_ARGS_((char *str, int str_len, char *val)); + + +/* +** Function to get IP address of this agent +** WARNING: this scans all interfaces (slow) +*/ +u_long +Util_local_ip_address _ANSI_ARGS_((void)); + +/* +** Function to get the current time in seconds +*/ +long +Util_time_now _ANSI_ARGS_((void)); + +/* +** Function to determine how long the agent has been running +* (WARNING: this seems rather slow) +*/ +long +Util_time_running(); + +/* +** Read data from file +*/ +int +Util_file_read _ANSI_ARGS_((char *file, int offset, char *data, int dataSz)); + +/* +** Write data into file +*/ +int +Util_file_write _ANSI_ARGS_((char *file, int offset, char *data, int dataSz)); + + +/* ---------------------------------------------------------------------- */ + + + + + + + + + + + + + +#endif diff --git a/include/snmp_vars.h b/include/snmp_vars.h new file mode 100644 index 0000000000..9a468907ca --- /dev/null +++ b/include/snmp_vars.h @@ -0,0 +1,288 @@ +/* + * Definitions for SNMP (RFC 1067) agent variable finder. + * and more. + */ +/*********************************************************** + Copyright 1988, 1989 by Carnegie Mellon University + Copyright 1989 TGV, Incorporated + + All Rights Reserved + +Permission to use, copy, modify, and distribute this software and its +documentation for any purpose and without fee is hereby granted, +provided that the above copyright notice appear in all copies and that +both that copyright notice and this permission notice appear in +supporting documentation, and that the name of CMU and TGV not be used +in advertising or publicity pertaining to distribution of the software +without specific, written prior permission. + +CMU AND TGV DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO +EVENT SHALL CMU OR TGV BE LIABLE FOR ANY SPECIAL, INDIRECT OR +CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF +USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +PERFORMANCE OF THIS SOFTWARE. +******************************************************************/ + +#ifndef SNMPLIB_H +#define SNMPLIB_H + + +#undef _ANSI_ARGS_ +#if (defined(__STDC__) && ! defined(NO_PROTOTYPE)) || defined(USE_PROTOTYPE) +# define _ANSI_ARGS_(x) x +#else +# define _ANSI_ARGS_(x) () +#endif + + +u_char *var_system(); +u_char *var_ifEntry(); +u_char *var_atEntry(); +u_char *var_ip(); +u_char *var_ipAddrEntry(); +u_char *var_ipRouteEntry(); +u_char *var_icmp(); +u_char *var_tcp(); +u_char *var_udp(); +#ifdef linux +u_char *var_snmp(); +u_char *var_id(); +#endif +u_char *var_process(); +u_char *var_event(); +u_char *var_capture(); +u_char *var_demo(); +u_char *var_snmpStats(); +u_char *var_usecStats(); +u_char *var_usecAgent(); +u_char *var_orEntry(); +u_char *var_rwstats(); +u_char *getStatPtr(); + +extern long long_return; +extern u_char return_buf[]; + +#define INST 0xFFFFFFFF /* used to fill out the instance field of the variables table */ + +/* + * These are unit magic numbers for each variable. + */ + +#define VERSION_DESCR 0 +#define VERSION_ID 1 +#define IFNUMBER 2 +#define UPTIME 3 +#define SYSCONTACT 4 +#define SYSYSNAME 5 +#define SYSLOCATION 6 +#define SYSSERVICES 7 +#define SYSORLASTCHANGE 8 + +#define IFINDEX 1 +#define IFDESCR 2 +#define IFTYPE 3 +#define IFMTU 4 +#define IFSPEED 5 +#define IFPHYSADDRESS 6 +#define IFADMINSTATUS 7 +#define IFOPERSTATUS 8 +#define IFLASTCHANGE 9 +#define IFINOCTETS 10 +#define IFINUCASTPKTS 11 +#define IFINNUCASTPKTS 12 +#define IFINDISCARDS 13 +#define IFINERRORS 14 +#define IFINUNKNOWNPROTOS 15 +#define IFOUTOCTETS 16 +#define IFOUTUCASTPKTS 17 +#define IFOUTNUCASTPKTS 18 +#define IFOUTDISCARDS 19 +#define IFOUTERRORS 20 +#define IFOUTQLEN 21 +#define IFSPECIFIC 22 + +#define ATIFINDEX 0 +#define ATPHYSADDRESS 1 +#define ATNETADDRESS 2 + +#define IPFORWARDING 0 +#define IPDEFAULTTTL 1 +#define IPINRECEIVES 2 +#define IPINHDRERRORS 3 +#define IPINADDRERRORS 4 +#define IPFORWDATAGRAMS 5 +#define IPINUNKNOWNPROTOS 6 +#define IPINDISCARDS 7 +#define IPINDELIVERS 8 +#define IPOUTREQUESTS 9 +#define IPOUTDISCARDS 10 +#define IPOUTNOROUTES 11 +#define IPREASMTIMEOUT 12 +#define IPREASMREQDS 13 +#define IPREASMOKS 14 +#define IPREASMFAILS 15 +#define IPFRAGOKS 16 +#define IPFRAGFAILS 17 +#define IPFRAGCREATES 18 + +#define IPADADDR 1 +#define IPADIFINDEX 2 +#define IPADNETMASK 3 +#define IPADBCASTADDR 4 +#define IPADENTREASMMAXSIZE 5 + +#ifndef linux +#define IPROUTEDEST 0 +#define IPROUTEIFINDEX 1 +#define IPROUTEMETRIC1 2 +#define IPROUTEMETRIC2 3 +#define IPROUTEMETRIC3 4 +#define IPROUTEMETRIC4 5 +#define IPROUTENEXTHOP 6 +#define IPROUTETYPE 7 +#define IPROUTEPROTO 8 +#define IPROUTEAGE 9 +#else +/* XXX */ +#define IPROUTEDEST 1 +#define IPROUTEIFINDEX 2 +#define IPROUTEMETRIC1 3 +#define IPROUTEMETRIC2 4 +#define IPROUTEMETRIC3 5 +#define IPROUTEMETRIC4 6 +#define IPROUTENEXTHOP 7 +#define IPROUTETYPE 8 +#define IPROUTEPROTO 9 +#define IPROUTEAGE 10 +#define IPROUTEMASK 11 +#define IPROUTEMETRIC5 12 +#define IPROUTEINFO 13 +#endif + +#define IPNETTOMEDIAIFINDEX 1 +#define IPNETTOMEDIAPHYSADDR 2 +#define IPNETTOMEDIANETADDR 3 +#define IPNETTOMEDIATYPE 4 + +#define ICMPINMSGS 0 +#define ICMPINERRORS 1 +#define ICMPINDESTUNREACHS 2 +#define ICMPINTIMEEXCDS 3 +#define ICMPINPARMPROBS 4 +#define ICMPINSRCQUENCHS 5 +#define ICMPINREDIRECTS 6 +#define ICMPINECHOS 7 +#define ICMPINECHOREPS 8 +#define ICMPINTIMESTAMPS 9 +#define ICMPINTIMESTAMPREPS 10 +#define ICMPINADDRMASKS 11 +#define ICMPINADDRMASKREPS 12 +#define ICMPOUTMSGS 13 +#define ICMPOUTERRORS 14 +#define ICMPOUTDESTUNREACHS 15 +#define ICMPOUTTIMEEXCDS 16 +#define ICMPOUTPARMPROBS 17 +#define ICMPOUTSRCQUENCHS 18 +#define ICMPOUTREDIRECTS 19 +#define ICMPOUTECHOS 20 +#define ICMPOUTECHOREPS 21 +#define ICMPOUTTIMESTAMPS 22 +#define ICMPOUTTIMESTAMPREPS 23 +#define ICMPOUTADDRMASKS 24 +#define ICMPOUTADDRMASKREPS 25 + +#define TCPRTOALGORITHM 1 +#define TCPRTOMIN 2 +#define TCPRTOMAX 3 +#define TCPMAXCONN 4 +#define TCPACTIVEOPENS 5 +#define TCPPASSIVEOPENS 6 +#define TCPATTEMPTFAILS 7 +#define TCPESTABRESETS 8 +#define TCPCURRESTAB 9 +#define TCPINSEGS 10 +#define TCPOUTSEGS 11 +#define TCPRETRANSSEGS 12 +#define TCPCONNSTATE 13 +#define TCPCONNLOCALADDRESS 14 +#define TCPCONNLOCALPORT 15 +#define TCPCONNREMADDRESS 16 +#define TCPCONNREMPORT 17 + +#define UDPINDATAGRAMS 0 +#define UDPNOPORTS 1 +#define UDPINERRORS 2 +#define UDPOUTDATAGRAMS 3 +#ifdef linux +#define UDPLOCALADDRESS 4 +#define UDPLOCALPORT 5 +#endif /* linux */ + +#define SNMPINPKTS 1 +#define SNMPOUTPKTS 2 +#define SNMPINBADVERSIONS 3 +#define SNMPINBADCOMMUNITYNAMES 4 +#define SNMPINBADCOMMUNITYUSES 5 +#define SNMPINASNPARSEERRORS 6 +#define SNMPINTOOBIGS 8 +#define SNMPINNOSUCHNAMES 9 +#define SNMPINBADVALUES 10 +#define SNMPINREADONLYS 11 +#define SNMPINGENERRS 12 +#define SNMPINTOTALREQVARS 13 +#define SNMPINTOTALSETVARS 14 +#define SNMPINGETREQUESTS 15 +#define SNMPINGETNEXTS 16 +#define SNMPINSETREQUESTS 17 +#define SNMPINGETRESPONSES 18 +#define SNMPINTRAPS 19 +#define SNMPOUTTOOBIGS 20 +#define SNMPOUTNOSUCHNAMES 21 +#define SNMPOUTBADVALUES 22 +#define SNMPOUTGENERRS 24 +#define SNMPOUTGETREQUESTS 25 +#define SNMPOUTGETNEXTS 26 +#define SNMPOUTSETREQUESTS 27 +#define SNMPOUTGETRESPONSES 28 +#define SNMPOUTTRAPS 29 +#define SNMPENABLEAUTHENTRAPS 30 + + +/* + * for tcp-connection list access: + */ +#include + +#ifdef linux +struct inpcb { + struct inpcb *inp_next; /* pointers to other pcb's */ + struct in_addr inp_faddr; /* foreign host table entry */ + u_short inp_fport; /* foreign port */ + struct in_addr inp_laddr; /* local host table entry */ + u_short inp_lport; /* local port */ + int inp_state; + int uid; /* owner of the connection */ +}; +#endif + +extern void TCP_Scan_Init (); +extern int TCP_Scan_Next (); + + +struct variable { + u_char magic; /* passed to function as a hint */ + char type; /* type of variable */ +/* See important comment in snmp_vars.c relating to acl */ + u_short acl; /* access control list for variable */ + u_char *(*findVar)(); /* function that finds variable */ + u_char namelen; /* length of above */ + oid name[32]; /* object identifier of variable */ +}; + +extern int compare (); +extern void Interface_Scan_Init (); +extern int Interface_Scan_Next (); + +#endif