Debian Codegraph @

contrib/mod_snmp/pdu.h

raw symbols SCIP
1 /*
2 * ProFTPD - mod_snmp PDU routines
3 * Copyright (c) 2008-2016 TJ Saunders
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
18 *
19 * As a special exemption, TJ Saunders and other respective copyright holders
20 * give permission to link this program with OpenSSL, and distribute the
21 * resulting executable, without including the source code for OpenSSL in the
22 * source distribution.
23 */
24
25 #ifndef MOD_SNMP_PDU_H
26 #define MOD_SNMP_PDU_H
27
28 #include "mod_snmp.h"
29 #include "asn1.h"
30 #include "smi.h"
31
32 /* RFC1905 SNMPv2 ResponsePDU error status codes */
33 #define SNMP_ERR_NO_ERROR 0
34 #define SNMP_ERR_TOO_BIG 1
35 #define SNMP_ERR_NO_SUCH_NAME 2
36 #define SNMP_ERR_BAD_VALUE 3
37 #define SNMP_ERR_READ_ONLY 4
38 #define SNMP_ERR_GENERIC 5
39 #define SNMP_ERR_NO_ACCESS 6
40 #define SNMP_ERR_WRONG_TYPE 7
41 #define SNMP_ERR_WRONG_LEN 8
42 #define SNMP_ERR_WRONG_ENCODING 9
43 #define SNMP_ERR_WRONG_VALUE 10
44 #define SNMP_ERR_NO_CREATE 11
45 #define SNMP_ERR_INCONSISTENT_VALUE 12
46 #define SNMP_ERR_RSRC_UNAVAIL 13
47 #define SNMP_ERR_COMMIT_FAILED 14
48 #define SNMP_ERR_UNDO_FAILED 15
49 #define SNMP_ERR_AUTHZ_FAILED 16
50 #define SNMP_ERR_CANT_WRITE 17
51 #define SNMP_ERR_INCONSISTENT_NAME 18
52
53 /* RFC1907 SNMPv2 Trap types */
54 #define SNMP_TRAP_TYPE_COLDSTART 0
55 #define SNMP_TRAP_TYPE_WARMSTART 1
56 #define SNMP_TRAP_TYPE_LINKDOWN 2
57 #define SNMP_TRAP_TYPE_LINKUP 3
58 #define SNMP_TRAP_TYPE_AUTH_FAILED 4
59 #define SNMP_TRAP_TYPE_EGP_NEIGHBOR_LOSS 5
60 #define SNMP_TRAP_TYPE_SPECIFIC 6
61
62 /* RFC1905 defines the operations for SNMPv2 requests.
63 *
64 * Note that 0x04 is obsolete and no longer used.
65 */
66 #define SNMP_PDU_GET (SNMP_ASN1_CLASS_CONTEXT|SNMP_ASN1_CONSTRUCT|0x0)
67 #define SNMP_PDU_GETNEXT (SNMP_ASN1_CLASS_CONTEXT|SNMP_ASN1_CONSTRUCT|0x1)
68 #define SNMP_PDU_RESPONSE (SNMP_ASN1_CLASS_CONTEXT|SNMP_ASN1_CONSTRUCT|0x2)
69 #define SNMP_PDU_SET (SNMP_ASN1_CLASS_CONTEXT|SNMP_ASN1_CONSTRUCT|0x3)
70 #define SNMP_PDU_TRAP_V1 (SNMP_ASN1_CLASS_CONTEXT|SNMP_ASN1_CONSTRUCT|0x4)
71 #define SNMP_PDU_GETBULK (SNMP_ASN1_CLASS_CONTEXT|SNMP_ASN1_CONSTRUCT|0x5)
72 #define SNMP_PDU_INFORM (SNMP_ASN1_CLASS_CONTEXT|SNMP_ASN1_CONSTRUCT|0x6)
73 #define SNMP_PDU_TRAP_V2 (SNMP_ASN1_CLASS_CONTEXT|SNMP_ASN1_CONSTRUCT|0x7)
74 #define SNMP_PDU_REPORT (SNMP_ASN1_CLASS_CONTEXT|SNMP_ASN1_CONSTRUCT|0x8)
75
76 #define SNMP_PDU_MAX_BINDINGS 2147483647
77
78 /* Used to hold both requests and response. */
79 struct snmp_pdu {
80 pool *pool;
81 pr_netaddr_t *peer_addr;
82
83 unsigned char request_type;
84 long request_id;
85
86 long err_code;
87 long err_idx;
88
89 /* For SNMPv2 bulk requests. RFC1905 says that these values can be
90 * negative (but if so, they are set to/treated as zero).
91 */
92 long non_repeaters;
93 long max_repetitions;
94
95 /* For responses. */
96 struct snmp_var *varlist;
97 unsigned int varlistlen;
98
99 /* For traps. */
100 oid_t *trap_oid;
101 unsigned int trap_oidlen;
102 pr_netaddr_t *trap_cause;
103 int trap_type;
104 unsigned int trap_systime;
105 };
106
107 const char *snmp_pdu_get_request_type_desc(unsigned char request_type);
108 struct snmp_pdu *snmp_pdu_create(pool *p, unsigned char request_type);
109 struct snmp_pdu *snmp_pdu_dup(pool *p, struct snmp_pdu *pdu);
110
111 /* XXX functions for fixing up a PDU, based on whether there was an err_code/
112 * err_idx value, etc.
113 */
114
115 int snmp_pdu_read(pool *p, unsigned char **buf, size_t *buflen,
116 struct snmp_pdu **pdu, long snmp_version);
117 int snmp_pdu_write(pool *p, unsigned char **buf, size_t *buflen,
118 struct snmp_pdu *pdu, long snmp_version);
119
120 #endif /* MOD_SNMP_PDU_H */