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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [net/] [snmp/] [lib/] [current/] [include/] [snmp_api.h] - Blame information for rev 844

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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