OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [net/] [snmp/] [lib/] [v2_0/] [include/] [snmp_api.h] - Blame information for rev 174

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
//==========================================================================
2
//
3
//      ./lib/current/include/snmp_api.h
4
//
5
//
6
//==========================================================================
7
//####ECOSGPLCOPYRIGHTBEGIN####
8
// -------------------------------------------
9
// This file is part of eCos, the Embedded Configurable Operating System.
10
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
11
//
12
// eCos is free software; you can redistribute it and/or modify it under
13
// the terms of the GNU General Public License as published by the Free
14
// Software Foundation; either version 2 or (at your option) any later version.
15
//
16
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
17
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
18
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19
// for more details.
20
//
21
// You should have received a copy of the GNU General Public License along
22
// with eCos; if not, write to the Free Software Foundation, Inc.,
23
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
24
//
25
// As a special exception, if other files instantiate templates or use macros
26
// or inline functions from this file, or you compile this file and link it
27
// with other works to produce a work based on this file, this file does not
28
// by itself cause the resulting work to be covered by the GNU General Public
29
// License. However the source code for this file must still be made available
30
// in accordance with section (3) of the GNU General Public License.
31
//
32
// This exception does not invalidate any other reasons why a work based on
33
// this file might be covered by the GNU General Public License.
34
//
35
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
36
// at http://sources.redhat.com/ecos/ecos-license/
37
// -------------------------------------------
38
//####ECOSGPLCOPYRIGHTEND####
39
//####UCDSNMPCOPYRIGHTBEGIN####
40
//
41
// -------------------------------------------
42
//
43
// Portions of this software may have been derived from the UCD-SNMP
44
// project,  <http://ucd-snmp.ucdavis.edu/>  from the University of
45
// California at Davis, which was originally based on the Carnegie Mellon
46
// University SNMP implementation.  Portions of this software are therefore
47
// covered by the appropriate copyright disclaimers included herein.
48
//
49
// The release used was version 4.1.2 of May 2000.  "ucd-snmp-4.1.2"
50
// -------------------------------------------
51
//
52
//####UCDSNMPCOPYRIGHTEND####
53
//==========================================================================
54
//#####DESCRIPTIONBEGIN####
55
//
56
// Author(s):    hmt
57
// Contributors: hmt
58
// Date:         2000-05-30
59
// Purpose:      Port of UCD-SNMP distribution to eCos.
60
// Description:  
61
//              
62
//
63
//####DESCRIPTIONEND####
64
//
65
//==========================================================================
66
/********************************************************************
67
       Copyright 1989, 1991, 1992 by Carnegie Mellon University
68
 
69
                          Derivative Work -
70
Copyright 1996, 1998, 1999, 2000 The Regents of the University of California
71
 
72
                         All Rights Reserved
73
 
74
Permission to use, copy, modify and distribute this software and its
75
documentation for any purpose and without fee is hereby granted,
76
provided that the above copyright notice appears in all copies and
77
that both that copyright notice and this permission notice appear in
78
supporting documentation, and that the name of CMU and The Regents of
79
the University of California not be used in advertising or publicity
80
pertaining to distribution of the software without specific written
81
permission.
82
 
83
CMU AND THE REGENTS OF THE UNIVERSITY OF CALIFORNIA DISCLAIM ALL
84
WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
85
WARRANTIES OF MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL CMU OR
86
THE REGENTS OF THE UNIVERSITY OF CALIFORNIA BE LIABLE FOR ANY SPECIAL,
87
INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
88
FROM THE LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
89
CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
90
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
91
*********************************************************************/
92
#ifndef SNMP_API_H
93
#define SNMP_API_H
94
 
95
/*
96
 * snmp_api.h - API for access to snmp.
97
 *
98
 * Caution: when using this library in a multi-threaded application,
99
 * the values of global variables "snmp_errno" and "snmp_detail"
100
 * cannot be reliably determined.  Suggest using snmp_error()
101
 * to obtain the library error codes.
102
 */
103
 
104
#ifndef DONT_SHARE_ERROR_WITH_OTHER_THREADS
105
#define SET_SNMP_ERROR(x) snmp_errno=(x)
106
#else
107
#define SET_SNMP_ERROR(x) 
108
#endif
109
 
110
 
111
#ifdef __cplusplus
112
extern "C" {
113
#endif
114
 
115
/***********************************************************
116
        Copyright 1989 by Carnegie Mellon University
117
 
118
                      All Rights Reserved
119
 
120
Permission to use, copy, modify, and distribute this software and its
121
documentation for any purpose and without fee is hereby granted,
122
provided that the above copyright notice appear in all copies and that
123
both that copyright notice and this permission notice appear in
124
supporting documentation, and that the name of CMU not be
125
used in advertising or publicity pertaining to distribution of the
126
software without specific, written prior permission.
127
 
128
CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
129
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
130
CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
131
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
132
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
133
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
134
SOFTWARE.
135
******************************************************************/
136
 
137
 
138
struct variable_list;
139
struct timeval;
140
 
141
 
142
        /*
143
         * Mimic size and alignment of 'struct sockaddr_storage' (see RFC 2553)
144
         * But retain field names of traditional 'struct sockaddr'
145
         */
146
 
147
#define _UCD_SS_MAXSIZE   92            /* <= sizeof( sockaddr_un ) */
148
#define _UCD_SS_ALIGNSIZE (sizeof (long))
149
 
150
#define _UCD_SS_PAD1SIZE  (_UCD_SS_ALIGNSIZE - sizeof( unsigned short ))
151
#define _UCD_SS_PAD2SIZE  (_UCD_SS_MAXSIZE - \
152
                (sizeof( unsigned short ) + _UCD_SS_PAD1SIZE + _UCD_SS_ALIGNSIZE ))
153
 
154
typedef struct {
155
 
156
#ifdef STRUCT_SOCKADDR_HAS_SA_UNION_SA_GENERIC_SA_FAMILY2
157
        /*
158
         * Certain systems (notably Irix 6.x) have a non-traditional
159
         *   socket structure, and #define the traditional field names.
160
         * This local definition should reproduce this structure, and still
161
         *    be large enough to handle any necessary Unix domain addresses.
162
         */
163
  union {
164
   struct {
165
#ifdef _HAVE_SA_LEN
166
    unsigned char       sa_len2;
167
    unsigned char       sa_family2;
168
#else
169
    unsigned short      sa_family2;
170
#endif
171
    char                sa_data2[ _UCD_SS_PAD1SIZE ];
172
   } sa_generic;
173
    long                sa_align;
174
    char                sa_pad2[ _UCD_SS_PAD2SIZE ];
175
  } sa_union;
176
 
177
#else
178
 
179
#ifdef STRUCT_SOCKADDR_HAS_SA_LEN
180
    unsigned char       sa_len;
181
    unsigned char       sa_family;
182
#else
183
    unsigned short      sa_family;
184
#endif
185
    char                sa_data[ _UCD_SS_PAD1SIZE ];
186
    long                sa_align;
187
    char                sa_pad2[ _UCD_SS_PAD2SIZE ];
188
#endif
189
 
190
} snmp_ipaddr;
191
 
192
#define USM_AUTH_KU_LEN     32
193
#define USM_PRIV_KU_LEN     32
194
 
195
struct snmp_pdu {
196
 
197
        /*
198
         * Protocol-version independent fields
199
         */
200
    long    version;
201
    int     command;    /* Type of this PDU */
202
    long    reqid;      /* Request id - note: not incremented on retries */
203
    long    msgid;      /* Message id for V3 messages
204
                         * note: incremented for each retry */
205
    long    transid;    /* Unique ID for incoming transactions */
206
    long    sessid;     /* Session id for AgentX messages */
207
    long    errstat;    /* Error status (non_repeaters in GetBulk) */
208
    long    errindex;   /* Error index (max_repetitions in GetBulk) */
209
    u_long  time;       /* Uptime */
210
    u_long  flags;
211
 
212
    int     securityModel;
213
    int     securityLevel;  /* noAuthNoPriv, authNoPriv, authPriv */
214
    int     msgParseModel;
215
 
216
    snmp_ipaddr  address;       /* Address of peer or trap destination */
217
 
218
    struct variable_list *variables;
219
 
220
 
221
        /*
222
         * SNMPv1 & SNMPv2c fields
223
         */
224
    u_char  *community;         /* community for outgoing requests. */
225
    size_t  community_len;      /* Length of community name. */
226
 
227
        /*
228
         * Trap information
229
         */
230
    oid     *enterprise;        /* System OID */
231
    size_t  enterprise_length;
232
    long    trap_type;          /* trap type */
233
    long    specific_type;      /* specific type */
234
    snmp_ipaddr agent_addr;
235
 
236
        /*
237
         * SNMPv3 fields
238
         */
239
    u_char  *contextEngineID;   /* context snmpEngineID */
240
    size_t  contextEngineIDLen; /* Length of contextEngineID */
241
    char    *contextName;       /* authoritative contextName */
242
    size_t  contextNameLen;     /* Length of contextName */
243
    u_char  *securityEngineID;  /* authoritative snmpEngineID for security */
244
    size_t  securityEngineIDLen;/* Length of securityEngineID */
245
    char    *securityName;      /* on behalf of this principal */
246
    size_t  securityNameLen;    /* Length of securityName. */
247
 
248
        /*
249
         * AgentX fields
250
         *      (also uses SNMPv1 community field)
251
         */
252
    int     priority;
253
    int     range_subid;
254
 
255
    void * securityStateRef;
256
};
257
 
258
struct snmp_session;
259
typedef int (*snmp_callback) (int, struct snmp_session *, int, struct snmp_pdu *, void *);
260
 
261
struct snmp_session {
262
        /*
263
         * Protocol-version independent fields
264
         */
265
    long  version;
266
    int     retries;    /* Number of retries before timeout. */
267
    long    timeout;    /* Number of uS until first timeout, then exponential backoff */
268
    u_long  flags;
269
    struct  snmp_session *subsession;
270
    struct  snmp_session *next;
271
 
272
    char    *peername;  /* Domain name or dotted IP address of default peer */
273
    u_short remote_port;/* UDP port number of peer. */
274
    u_short local_port; /* My UDP port number, 0 for default, picked randomly */
275
    /* Authentication function or NULL if null authentication is used */
276
    u_char    *(*authenticator) (u_char *, size_t *, u_char *, size_t);
277
    snmp_callback callback; /* Function to interpret incoming data */
278
    /* Pointer to data that the callback function may consider important */
279
    void    *callback_magic;
280
 
281
    int     s_errno;        /* copy of system errno */
282
    int     s_snmp_errno;   /* copy of library errno */
283
    long    sessid;         /* Session id - AgentX only */
284
 
285
        /*
286
         * SNMPv1 & SNMPv2c fields
287
         */
288
    u_char  *community;         /* community for outgoing requests. */
289
    size_t  community_len;      /* Length of community name. */
290
 
291
        /*
292
         * SNMPv3 fields
293
         */
294
    u_char  *contextEngineID;   /* authoritative snmpEngineID */
295
    size_t  contextEngineIDLen; /* Length of contextEngineID */
296
    u_int   engineBoots;        /* initial engineBoots for remote engine */
297
    u_int   engineTime;         /* initial engineTime for remote engine */
298
    char    *contextName;       /* authoritative contextName */
299
    size_t  contextNameLen;     /* Length of contextName */
300
    u_char  *securityEngineID;  /* authoritative snmpEngineID */
301
    size_t  securityEngineIDLen;  /* Length of contextEngineID */
302
    char    *securityName;      /* on behalf of this principal */
303
    size_t  securityNameLen;    /* Length of securityName. */
304
    oid     *securityAuthProto; /* auth protocol oid */
305
    size_t  securityAuthProtoLen; /* Length of auth protocol oid */
306
    u_char  securityAuthKey[USM_AUTH_KU_LEN];  /* Ku for auth protocol XXX */
307
    size_t  securityAuthKeyLen; /* Length of Ku for auth protocol */
308
    oid     *securityPrivProto; /* priv protocol oid */
309
    size_t  securityPrivProtoLen; /* Length of priv protocol oid */
310
    u_char  securityPrivKey[USM_PRIV_KU_LEN];  /* Ku for privacy protocol XXX */
311
    size_t  securityPrivKeyLen; /* Length of Ku for priv protocol */
312
    int     securityModel;
313
    int     securityLevel;  /* noAuthNoPriv, authNoPriv, authPriv */
314
};
315
 
316
/*
317
 * A list of all the outstanding requests for a particular session.
318
 */
319
#ifdef SNMP_NEED_REQUEST_LIST
320
struct request_list {
321
    struct request_list *next_request;
322
    long  request_id;   /* request id */
323
    long  message_id;   /* message id */
324
    snmp_callback callback; /* user callback per request (NULL if unused) */
325
    void   *cb_data;   /* user callback data per request (NULL if unused) */
326
    int     retries;    /* Number of retries */
327
    u_long timeout;     /* length to wait for timeout */
328
    struct timeval time; /* Time this request was made */
329
    struct timeval expire;  /* time this request is due to expire */
330
    struct  snmp_session *session;
331
    struct snmp_pdu *pdu;   /* The pdu for this request
332
                               (saved so it can be retransmitted */
333
};
334
#endif /* SNMP_NEED_REQUEST_LIST */
335
 
336
/*
337
 * Set fields in session and pdu to the following to get a default or unconfigured value.
338
 */
339
#define SNMP_DEFAULT_COMMUNITY_LEN  0   /* to get a default community name */
340
#define SNMP_DEFAULT_RETRIES        -1
341
#define SNMP_DEFAULT_TIMEOUT        -1
342
#define SNMP_DEFAULT_REMPORT        0
343
#define SNMP_DEFAULT_REQID          -1
344
#define SNMP_DEFAULT_MSGID          -1
345
#define SNMP_DEFAULT_ERRSTAT        -1
346
#define SNMP_DEFAULT_ERRINDEX       -1
347
#define SNMP_DEFAULT_ADDRESS        0
348
#define SNMP_DEFAULT_PEERNAME       NULL
349
#define SNMP_DEFAULT_ENTERPRISE_LENGTH  0
350
#define SNMP_DEFAULT_TIME           0
351
#define SNMP_DEFAULT_VERSION        -1
352
#define SNMP_DEFAULT_CONTEXT        ""
353
#define SNMP_DEFAULT_AUTH_PROTO     usmHMACMD5AuthProtocol
354
#define SNMP_DEFAULT_AUTH_PROTOLEN  USM_LENGTH_OID_TRANSFORM
355
#define SNMP_DEFAULT_PRIV_PROTO     usmDESPrivProtocol
356
#define SNMP_DEFAULT_PRIV_PROTOLEN  USM_LENGTH_OID_TRANSFORM
357
 
358
extern const char *snmp_api_errstring (int);
359
extern void snmp_perror (const char *);
360
extern void snmp_set_detail (const char *);
361
 
362
#define SNMP_MAX_MSG_SIZE          1472 /* ethernet MTU minus IP/UDP header */
363
#define SNMP_MAX_ENG_SIZE          32
364
#define SNMP_MAX_SEC_NAME_SIZE     256
365
#define SNMP_MAX_SEC_NAME_SIZE     256
366
#define SNMP_MAX_CONTEXT_SIZE      256
367
#define SNMP_SEC_PARAM_BUF_SIZE     256
368
 
369
/* set to one to ignore unauthenticated Reports */
370
#define SNMPV3_IGNORE_UNAUTH_REPORTS 0
371
/* to determine type of Report from varbind_list */
372
#define REPORT_STATS_LEN 9
373
#define REPORT_snmpUnknownSecurityModels_NUM 1
374
#define REPORT_snmpInvalidMsgs_NUM 2
375
#define REPORT_usmStatsUnsupportedSecLevels_NUM 1
376
#define REPORT_usmStatsNotInTimeWindows_NUM 2
377
#define REPORT_usmStatsUnknownUserNames_NUM 3
378
#define REPORT_usmStatsUnknownEngineIDs_NUM 4 
379
#define REPORT_usmStatsWrongDigests_NUM 5
380
#define REPORT_usmStatsDecryptionErrors_NUM 6
381
 
382
#define SNMP_DETAIL_SIZE        512
383
 
384
#define SNMP_FLAGS_DONT_PROBE      0x100    /* don't probe for an engineID */
385
#define SNMP_FLAGS_STREAM_SOCKET   0x80
386
#define SNMP_FLAGS_LISTENING       0x40     /* Server stream sockets only */
387
#define SNMP_FLAGS_SUBSESSION      0x20
388
 
389
/*
390
 * Error return values.
391
 *
392
 * SNMPERR_SUCCESS is the non-PDU "success" code.
393
 *
394
 * XXX  These should be merged with SNMP_ERR_* defines and confined
395
 *      to values < 0.  ???
396
 */
397
#define SNMPERR_SUCCESS                 (0)  /* XXX  Non-PDU "success" code. */
398
#define SNMPERR_GENERR                  (-1)
399
#define SNMPERR_BAD_LOCPORT             (-2)
400
#define SNMPERR_BAD_ADDRESS             (-3)
401
#define SNMPERR_BAD_SESSION             (-4)
402
#define SNMPERR_TOO_LONG                (-5)
403
#define SNMPERR_NO_SOCKET               (-6)
404
#define SNMPERR_V2_IN_V1                (-7)
405
#define SNMPERR_V1_IN_V2                (-8)
406
#define SNMPERR_BAD_REPEATERS           (-9)
407
#define SNMPERR_BAD_REPETITIONS         (-10)
408
#define SNMPERR_BAD_ASN1_BUILD          (-11)
409
#define SNMPERR_BAD_SENDTO              (-12)
410
#define SNMPERR_BAD_PARSE               (-13)
411
#define SNMPERR_BAD_VERSION             (-14)
412
#define SNMPERR_BAD_SRC_PARTY           (-15)
413
#define SNMPERR_BAD_DST_PARTY           (-16)
414
#define SNMPERR_BAD_CONTEXT             (-17)
415
#define SNMPERR_BAD_COMMUNITY           (-18)
416
#define SNMPERR_NOAUTH_DESPRIV          (-19)
417
#define SNMPERR_BAD_ACL                 (-20)
418
#define SNMPERR_BAD_PARTY               (-21)
419
#define SNMPERR_ABORT                   (-22)
420
#define SNMPERR_UNKNOWN_PDU             (-23)
421
#define SNMPERR_TIMEOUT                 (-24)
422
#define SNMPERR_BAD_RECVFROM            (-25)
423
#define SNMPERR_BAD_ENG_ID              (-26)
424
#define SNMPERR_BAD_SEC_NAME            (-27)
425
#define SNMPERR_BAD_SEC_LEVEL           (-28)
426
#define SNMPERR_ASN_PARSE_ERR           (-29)
427
#define SNMPERR_UNKNOWN_SEC_MODEL       (-30)
428
#define SNMPERR_INVALID_MSG             (-31)
429
#define SNMPERR_UNKNOWN_ENG_ID          (-32)
430
#define SNMPERR_UNKNOWN_USER_NAME       (-33)
431
#define SNMPERR_UNSUPPORTED_SEC_LEVEL   (-34)
432
#define SNMPERR_AUTHENTICATION_FAILURE  (-35)
433
#define SNMPERR_NOT_IN_TIME_WINDOW      (-36)
434
#define SNMPERR_DECRYPTION_ERR          (-37)
435
#define SNMPERR_SC_GENERAL_FAILURE      (-38)
436
#define SNMPERR_SC_NOT_CONFIGURED       (-39)
437
#define SNMPERR_KT_NOT_AVAILABLE        (-40)
438
#define SNMPERR_UNKNOWN_REPORT          (-41)
439
#define SNMPERR_USM_GENERICERROR                (-42)
440
#define SNMPERR_USM_UNKNOWNSECURITYNAME         (-43)
441
#define SNMPERR_USM_UNSUPPORTEDSECURITYLEVEL    (-44)
442
#define SNMPERR_USM_ENCRYPTIONERROR             (-45)
443
#define SNMPERR_USM_AUTHENTICATIONFAILURE       (-46)
444
#define SNMPERR_USM_PARSEERROR                  (-47)
445
#define SNMPERR_USM_UNKNOWNENGINEID             (-48)
446
#define SNMPERR_USM_NOTINTIMEWINDOW             (-49)
447
#define SNMPERR_USM_DECRYPTIONERROR             (-50)
448
#define SNMPERR_NOMIB                   (-51)
449
#define SNMPERR_RANGE                   (-52)
450
#define SNMPERR_MAX_SUBID               (-53)
451
#define SNMPERR_BAD_SUBID               (-54)
452
#define SNMPERR_LONG_OID                (-55)
453
#define SNMPERR_BAD_NAME                (-56)
454
#define SNMPERR_VALUE                   (-57)
455
#define SNMPERR_UNKNOWN_OBJID           (-58)
456
#define SNMPERR_NULL_PDU                (-59)
457
#define SNMPERR_NO_VARS                 (-60)
458
#define SNMPERR_VAR_TYPE                (-61)
459
#define SNMPERR_MALLOC                  (-62)
460
 
461
#define SNMPERR_MAX                     (-62)
462
 
463
#define non_repeaters   errstat
464
#define max_repetitions errindex
465
 
466
 
467
struct variable_list {
468
    struct variable_list *next_variable;    /* NULL for last variable */
469
    oid     *name;  /* Object identifier of variable */
470
    size_t  name_length;    /* number of subid's in name */
471
    u_char  type;   /* ASN type of variable */
472
    union { /* value of variable */
473
        long    *integer;
474
        u_char  *string;
475
        oid     *objid;
476
        u_char  *bitstring;
477
        struct counter64 *counter64;
478
#ifdef OPAQUE_SPECIAL_TYPES
479
        float   *floatVal;
480
        double  *doubleVal;
481
/*      t_union *unionVal; */
482
#endif /* OPAQUE_SPECIAL_TYPES */
483
    } val;
484
    size_t          val_len;
485
    oid name_loc[MAX_OID_LEN];  /* 90 percentile < 24. */
486
    u_char buf[40];             /* 90 percentile < 40. */
487
};
488
 
489
 
490
 
491
/*
492
 * struct snmp_session *snmp_open(session)
493
 *      struct snmp_session *session;
494
 *
495
 * Sets up the session with the snmp_session information provided
496
 * by the user.  Then opens and binds the necessary UDP port.
497
 * A handle to the created session is returned (this is different than
498
 * the pointer passed to snmp_open()).  On any error, NULL is returned
499
 * and snmp_errno is set to the appropriate error code.
500
 */
501
struct snmp_session *snmp_open (struct snmp_session *);
502
 
503
/*
504
 * int snmp_close(session)
505
 *     struct snmp_session *session;
506
 *
507
 * Close the input session.  Frees all data allocated for the session,
508
 * dequeues any pending requests, and closes any sockets allocated for
509
 * the session.  Returns 0 on error, 1 otherwise.
510
 *
511
 * snmp_close_sessions() does the same thing for all open sessions
512
 */
513
int snmp_close (struct snmp_session *);
514
int snmp_close_sessions (void);
515
 
516
 
517
/*
518
 * int snmp_send(session, pdu)
519
 *     struct snmp_session *session;
520
 *     struct snmp_pdu  *pdu;
521
 *
522
 * Sends the input pdu on the session after calling snmp_build to create
523
 * a serialized packet.  If necessary, set some of the pdu data from the
524
 * session defaults.  Add a request corresponding to this pdu to the list
525
 * of outstanding requests on this session, then send the pdu.
526
 * Returns the request id of the generated packet if applicable, otherwise 1.
527
 * On any error, 0 is returned.
528
 * The pdu is freed by snmp_send() unless a failure occured.
529
 */
530
int snmp_send (struct snmp_session *, struct snmp_pdu *);
531
 
532
/*
533
 * int snmp_async_send(session, pdu, callback, cb_data)
534
 *     struct snmp_session *session;
535
 *     struct snmp_pdu  *pdu;
536
 *     snmp_callback callback;
537
 *     void   *cb_data;
538
 *
539
 * Sends the input pdu on the session after calling snmp_build to create
540
 * a serialized packet.  If necessary, set some of the pdu data from the
541
 * session defaults.  Add a request corresponding to this pdu to the list
542
 * of outstanding requests on this session and store callback and data,
543
 * then send the pdu.
544
 * Returns the request id of the generated packet if applicable, otherwise 1.
545
 * On any error, 0 is returned.
546
 * The pdu is freed by snmp_send() unless a failure occured.
547
 */
548
int snmp_async_send (struct snmp_session *, struct snmp_pdu *,
549
                         snmp_callback, void *);
550
 
551
 
552
/*
553
 * void snmp_read(fdset)
554
 *     fd_set  *fdset;
555
 *
556
 * Checks to see if any of the fd's set in the fdset belong to
557
 * snmp.  Each socket with it's fd set has a packet read from it
558
 * and snmp_parse is called on the packet received.  The resulting pdu
559
 * is passed to the callback routine for that session.  If the callback
560
 * routine returns successfully, the pdu and it's request are deleted.
561
 */
562
void snmp_read (fd_set *);
563
 
564
 
565
 
566
/*
567
 * void
568
 * snmp_free_pdu(pdu)
569
 *     struct snmp_pdu *pdu;
570
 *
571
 * Frees the pdu and any malloc'd data associated with it.
572
 */
573
void snmp_free_pdu (struct snmp_pdu *);
574
 
575
void snmp_free_var (struct variable_list *);
576
 
577
void snmp_free_varbind(struct variable_list *var);
578
 
579
/*
580
 * int snmp_select_info(numfds, fdset, timeout, block)
581
 * int *numfds;
582
 * fd_set   *fdset;
583
 * struct timeval *timeout;
584
 * int *block;
585
 *
586
 * Returns info about what snmp requires from a select statement.
587
 * numfds is the number of fds in the list that are significant.
588
 * All file descriptors opened for SNMP are OR'd into the fdset.
589
 * If activity occurs on any of these file descriptors, snmp_read
590
 * should be called with that file descriptor set.
591
 *
592
 * The timeout is the latest time that SNMP can wait for a timeout.  The
593
 * select should be done with the minimum time between timeout and any other
594
 * timeouts necessary.  This should be checked upon each invocation of select.
595
 * If a timeout is received, snmp_timeout should be called to check if the
596
 * timeout was for SNMP.  (snmp_timeout is idempotent)
597
 *
598
 * Block is 1 if the select is requested to block indefinitely, rather than
599
 * time out.  If block is input as 1, the timeout value will be treated as
600
 * undefined, but it must be available for setting in snmp_select_info.  On
601
 * return, if block is true, the value of timeout will be undefined.
602
 *
603
 * snmp_select_info returns the number of open sockets.  (i.e. The number
604
 * of sessions open)
605
 */
606
int snmp_select_info (int *, fd_set *, struct timeval *, int *);
607
 
608
 
609
 
610
/*
611
 * void snmp_timeout();
612
 *
613
 * snmp_timeout should be called whenever the timeout from snmp_select_info
614
 * expires, but it is idempotent, so snmp_timeout can be polled (probably a
615
 * cpu expensive proposition).  snmp_timeout checks to see if any of the
616
 * sessions have an outstanding request that has timed out.  If it finds one
617
 * (or more), and that pdu has more retries available, a new packet is formed
618
 * from the pdu and is resent.  If there are no more retries available, the
619
 * callback for the session is used to alert the user of the timeout.
620
 */
621
 
622
void snmp_timeout (void);
623
 
624
 
625
/*
626
 * This routine must be supplied by the application:
627
 *
628
 * u_char *authenticator(pdu, length, community, community_len)
629
 * u_char *pdu;         The rest of the PDU to be authenticated
630
 * int *length;         The length of the PDU (updated by the authenticator)
631
 * u_char *community;   The community name to authenticate under.
632
 * int  community_len   The length of the community name.
633
 *
634
 * Returns the authenticated pdu, or NULL if authentication failed.
635
 * If null authentication is used, the authenticator in snmp_session can be
636
 * set to NULL(0).
637
 */
638
 
639
 
640
 
641
/*
642
 * This routine must be supplied by the application:
643
 *
644
 * int callback(operation, session, reqid, pdu, magic)
645
 * int operation;
646
 * struct snmp_session *session;    The session authenticated under.
647
 * int reqid;                       The request id of this pdu (0 for TRAP)
648
 * struct snmp_pdu *pdu;            The pdu information.
649
 * void *magic                      A link to the data for this routine.
650
 *
651
 * Returns 1 if request was successful, 0 if it should be kept pending.
652
 * Any data in the pdu must be copied because it will be freed elsewhere.
653
 * Operations are defined below:
654
 */
655
 
656
#define RECEIVED_MESSAGE   1
657
#define TIMED_OUT          2
658
 
659
long snmp_get_next_msgid(void);
660
long snmp_get_next_reqid(void);
661
long snmp_get_next_sessid(void);
662
long snmp_get_next_transid(void);
663
/* provide for backwards compatibility */
664
void snmp_set_dump_packet(int);
665
int snmp_get_dump_packet(void);
666
void snmp_set_quick_print(int);
667
int snmp_get_quick_print(void);
668
void snmp_set_suffix_only(int);
669
int snmp_get_suffix_only(void);
670
void snmp_set_full_objid(int);
671
int snmp_get_full_objid(void);
672
void snmp_set_random_access(int);
673
int snmp_get_random_access(void);
674
 
675
int snmp_oid_compare (const oid *, size_t, const oid *, size_t);
676
void init_snmp (const char *);
677
u_char *snmp_pdu_build (struct snmp_pdu *, u_char *, size_t *);
678
int snmpv3_parse(struct snmp_pdu *, u_char *, size_t *, u_char  **);
679
int snmpv3_dparse(struct snmp_pdu *, u_char *, size_t *, u_char  **, int);
680
int snmpv3_packet_build(struct snmp_pdu *pdu, u_char *packet, size_t *out_length, u_char *pdu_data, size_t pdu_data_len);
681
int snmpv3_make_report(struct snmp_pdu *pdu, int error);
682
int snmpv3_get_report_type(struct snmp_pdu *pdu);
683
int snmp_pdu_parse(struct snmp_pdu *pdu, u_char *data, size_t *length);
684
int snmp_pdu_dparse(struct snmp_pdu *pdu, u_char *data, size_t *length, int);
685
u_char* snmpv3_scopedPDU_parse(struct snmp_pdu *pdu, u_char *cp, size_t *length);
686
u_char* snmpv3_scopedPDU_dparse(struct snmp_pdu *pdu, u_char *cp, size_t *length, int);
687
void snmp_shutdown(const char *type);
688
struct variable_list *snmp_pdu_add_variable (struct snmp_pdu *, oid *, size_t, u_char, u_char *, size_t);
689
struct variable_list *snmp_varlist_add_variable(struct variable_list **varlist,
690
        oid *name, size_t name_length, u_char type, u_char *value, size_t len);
691
int hex_to_binary (const char *, u_char *);
692
int ascii_to_binary (const char *, u_char *);
693
int snmp_add_var (struct snmp_pdu *, oid*, size_t, char, const char *);
694
oid  *snmp_duplicate_objid(oid *objToCopy, size_t);
695
u_int snmp_increment_statistic(int which);
696
u_int snmp_increment_statistic_by(int which, int count);
697
u_int snmp_get_statistic(int which);
698
void  snmp_init_statistics(void);
699
int create_user_from_session(struct snmp_session *session);
700
 
701
/* extended open */
702
struct snmp_session *snmp_open_ex (struct snmp_session *,
703
  int (*fpre_parse) (struct snmp_session *, snmp_ipaddr),
704
  int (*fparse) (struct snmp_session *, struct snmp_pdu *, u_char *, size_t),
705
  int (*fpost_parse) (struct snmp_session *, struct snmp_pdu *, int),
706
  int (*fbuild) (struct snmp_session *, struct snmp_pdu *, u_char *, size_t *),
707
  int (*fcheck) (u_char *, size_t)
708
);
709
 
710
/* provided for backwards compatability.  Don't use these functions.
711
   See snmp_debug.h and snmp_debug.c instead.
712
*/
713
#if HAVE_STDARG_H
714
void DEBUGP (const char *, ...);
715
#else
716
void DEBUGP (va_alist);
717
#endif
718
void DEBUGPOID(oid *, size_t);
719
void snmp_set_do_debugging (int);
720
int snmp_get_do_debugging (void);
721
 
722
#ifdef CMU_COMPATIBLE
723
extern int snmp_dump_packet;
724
extern int quick_print;
725
#endif
726
 
727
size_t snmp_socket_length   (int family);
728
 
729
/*
730
 * snmp_error - return error data
731
 * Inputs :  address of errno, address of snmp_errno, address of string
732
 * Caller must free the string returned after use.
733
 */
734
void snmp_error (struct snmp_session *, int *, int *, char **);
735
/*
736
 * single session API.
737
 *
738
 * These functions perform similar actions as snmp_XX functions,
739
 * but operate on a single session only.
740
 *
741
 * Synopsis:
742
 
743
        void * sessp;
744
        struct snmp_session session, *ss;
745
        struct snmp_pdu *pdu, *response;
746
 
747
        snmp_sess_init(&session);
748
        session.retries = ...
749
        session.remote_port = ...
750
        sessp = snmp_sess_open(&session);
751
        ss = snmp_sess_session(sessp);
752
        if (ss == NULL)
753
                exit(1);
754
        ...
755
        if (ss->community) free(ss->community);
756
        ss->community = strdup(gateway);
757
        ss->community_len = strlen(gateway);
758
        ...
759
        snmp_sess_synch_response(sessp, pdu, &response);
760
        ...
761
        snmp_sess_close(sessp);
762
 
763
 * See also:
764
 * snmp_sess_synch_response, in snmp_client.h.
765
 
766
 * Notes:
767
 *  1. Invoke snmp_sess_session after snmp_sess_open.
768
 *  2. snmp_sess_session return value is an opaque pointer.
769
 *  3. Do NOT free memory returned by snmp_sess_session.
770
 *  4. Replace snmp_send(ss,pdu) with snmp_sess_send(sessp,pdu)
771
 */
772
 
773
void   snmp_sess_init       (struct snmp_session *);
774
void * snmp_sess_open       (struct snmp_session *);
775
struct snmp_session * snmp_sess_session    (void *);
776
 
777
/* use return value from snmp_sess_open as void * parameter */
778
 
779
int    snmp_sess_send       (void *, struct snmp_pdu *);
780
int    snmp_sess_async_send (void *, struct snmp_pdu *,
781
                                         snmp_callback, void *);
782
int    snmp_sess_select_info (void *, int *, fd_set *,
783
                                         struct timeval *, int *);
784
int    snmp_sess_read       (void *, fd_set *);
785
void   snmp_sess_timeout    (void *);
786
int    snmp_sess_close      (void *);
787
 
788
void   snmp_sess_error      (void *, int *, int *, char **);
789
void   snmp_sess_perror     (const char *prog_string, struct snmp_session *ss);
790
 
791
/* end single session API */
792
 
793
/* generic statistic counters */
794
 
795
/* snmpv3 statistics */
796
 
797
/* mpd stats */
798
#define   STAT_SNMPUNKNOWNSECURITYMODELS     0
799
#define   STAT_SNMPINVALIDMSGS               1
800
#define   STAT_SNMPUNKNOWNPDUHANDLERS        2
801
#define   STAT_MPD_STATS_START               STAT_SNMPUNKNOWNSECURITYMODELS
802
#define   STAT_MPD_STATS_END                 STAT_SNMPUNKNOWNPDUHANDLERS
803
 
804
/* usm stats */
805
#define   STAT_USMSTATSUNSUPPORTEDSECLEVELS  3
806
#define   STAT_USMSTATSNOTINTIMEWINDOWS      4
807
#define   STAT_USMSTATSUNKNOWNUSERNAMES      5
808
#define   STAT_USMSTATSUNKNOWNENGINEIDS      6
809
#define   STAT_USMSTATSWRONGDIGESTS          7
810
#define   STAT_USMSTATSDECRYPTIONERRORS      8
811
#define   STAT_USM_STATS_START               STAT_USMSTATSUNSUPPORTEDSECLEVELS
812
#define   STAT_USM_STATS_END                 STAT_USMSTATSDECRYPTIONERRORS
813
 
814
/* snmp counters */
815
#define  STAT_SNMPINPKTS                     9
816
#define  STAT_SNMPOUTPKTS                    10
817
#define  STAT_SNMPINBADVERSIONS              11
818
#define  STAT_SNMPINBADCOMMUNITYNAMES        12
819
#define  STAT_SNMPINBADCOMMUNITYUSES         13
820
#define  STAT_SNMPINASNPARSEERRS             14
821
/* #define  STAT_SNMPINBADTYPES              15 */
822
#define  STAT_SNMPINTOOBIGS                  16
823
#define  STAT_SNMPINNOSUCHNAMES              17
824
#define  STAT_SNMPINBADVALUES                18
825
#define  STAT_SNMPINREADONLYS                19
826
#define  STAT_SNMPINGENERRS                  20
827
#define  STAT_SNMPINTOTALREQVARS             21
828
#define  STAT_SNMPINTOTALSETVARS             22
829
#define  STAT_SNMPINGETREQUESTS              23
830
#define  STAT_SNMPINGETNEXTS                 24
831
#define  STAT_SNMPINSETREQUESTS              25
832
#define  STAT_SNMPINGETRESPONSES             26
833
#define  STAT_SNMPINTRAPS                    27
834
#define  STAT_SNMPOUTTOOBIGS                 28
835
#define  STAT_SNMPOUTNOSUCHNAMES             29
836
#define  STAT_SNMPOUTBADVALUES               30
837
/* #define  STAT_SNMPOUTREADONLYS            31 */
838
#define  STAT_SNMPOUTGENERRS                 32
839
#define  STAT_SNMPOUTGETREQUESTS             33
840
#define  STAT_SNMPOUTGETNEXTS                34
841
#define  STAT_SNMPOUTSETREQUESTS             35
842
#define  STAT_SNMPOUTGETRESPONSES            36
843
#define  STAT_SNMPOUTTRAPS                   37
844
/* AUTHTRAPENABLE                            38 */
845
#define  STAT_SNMPSILENTDROPS                39
846
#define  STAT_SNMPPROXYDROPS                 40
847
#define  STAT_SNMP_STATS_START               STAT_SNMPINPKTS
848
#define  STAT_SNMP_STATS_END                 STAT_SNMPOUTTRAPS
849
 
850
#define  MAX_STATS                           41
851
 
852
#ifdef __cplusplus
853
}
854
#endif
855
 
856
#endif /* SNMP_API_H */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.