snmp.h (133212) | snmp.h (216294) |
---|---|
1/* 2 * Copyright (c) 2001-2003 3 * Fraunhofer Institute for Open Communication Systems (FhG Fokus). 4 * All rights reserved. 5 * 6 * Author: Harti Brandt <harti@freebsd.org> 7 * | 1/* 2 * Copyright (c) 2001-2003 3 * Fraunhofer Institute for Open Communication Systems (FhG Fokus). 4 * All rights reserved. 5 * 6 * Author: Harti Brandt <harti@freebsd.org> 7 * |
8 * Copyright (c) 2010 The FreeBSD Foundation 9 * All rights reserved. 10 * 11 * Portions of this software were developed by Shteryana Sotirova Shopova 12 * under sponsorship from the FreeBSD Foundation. 13 * 14 * |
|
8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. --- 14 unchanged lines hidden (view full) --- 30 * 31 * Header file for SNMP functions. 32 */ 33#ifndef snmp_h_ 34#define snmp_h_ 35 36#include <sys/types.h> 37 | 15 * Redistribution and use in source and binary forms, with or without 16 * modification, are permitted provided that the following conditions 17 * are met: 18 * 1. Redistributions of source code must retain the above copyright 19 * notice, this list of conditions and the following disclaimer. 20 * 2. Redistributions in binary form must reproduce the above copyright 21 * notice, this list of conditions and the following disclaimer in the 22 * documentation and/or other materials provided with the distribution. --- 14 unchanged lines hidden (view full) --- 37 * 38 * Header file for SNMP functions. 39 */ 40#ifndef snmp_h_ 41#define snmp_h_ 42 43#include <sys/types.h> 44 |
38#define SNMP_COMMUNITY_MAXLEN 128 39#define SNMP_MAX_BINDINGS 100 | 45#define SNMP_COMMUNITY_MAXLEN 128 46#define SNMP_MAX_BINDINGS 100 47#define SNMP_CONTEXT_NAME_SIZ (32 + 1) 48#define SNMP_ENGINE_ID_SIZ 32 49#define SNMP_TIME_WINDOW 150 |
40 41enum snmp_syntax { 42 SNMP_SYNTAX_NULL = 0, 43 SNMP_SYNTAX_INTEGER, /* == INTEGER32 */ 44 SNMP_SYNTAX_OCTETSTRING, 45 SNMP_SYNTAX_OID, 46 SNMP_SYNTAX_IPADDRESS, 47 SNMP_SYNTAX_COUNTER, --- 22 unchanged lines hidden (view full) --- 70 unsigned32, timeticks */ 71 uint64_t counter64; 72 } v; 73}; 74 75enum snmp_version { 76 SNMP_Verr = 0, 77 SNMP_V1 = 1, | 50 51enum snmp_syntax { 52 SNMP_SYNTAX_NULL = 0, 53 SNMP_SYNTAX_INTEGER, /* == INTEGER32 */ 54 SNMP_SYNTAX_OCTETSTRING, 55 SNMP_SYNTAX_OID, 56 SNMP_SYNTAX_IPADDRESS, 57 SNMP_SYNTAX_COUNTER, --- 22 unchanged lines hidden (view full) --- 80 unsigned32, timeticks */ 81 uint64_t counter64; 82 } v; 83}; 84 85enum snmp_version { 86 SNMP_Verr = 0, 87 SNMP_V1 = 1, |
78 SNMP_V2c, | 88 SNMP_V2c = 2, 89 SNMP_V3, |
79}; 80 | 90}; 91 |
92#define SNMP_ADM_STR32_SIZ (32 + 1) 93#define SNMP_AUTH_KEY_SIZ 40 94#define SNMP_PRIV_KEY_SIZ 32 95#define SNMP_USM_AUTH_SIZE 12 96#define SNMP_USM_PRIV_SIZE 8 97#define SNMP_AUTH_HMACMD5_KEY_SIZ 16 98#define SNMP_AUTH_HMACSHA_KEY_SIZ 20 99#define SNMP_PRIV_AES_KEY_SIZ 16 100#define SNMP_PRIV_DES_KEY_SIZ 8 101 102 103enum snmp_secmodel { 104 SNMP_SECMODEL_ANY = 0, 105 SNMP_SECMODEL_SNMPv1 = 1, 106 SNMP_SECMODEL_SNMPv2c = 2, 107 SNMP_SECMODEL_USM = 3, 108 SNMP_SECMODEL_UNKNOWN 109}; 110 111enum snmp_usm_level { 112 SNMP_noAuthNoPriv = 1, 113 SNMP_authNoPriv = 2, 114 SNMP_authPriv = 3 115}; 116 117enum snmp_authentication { 118 SNMP_AUTH_NOAUTH = 0, 119 SNMP_AUTH_HMAC_MD5, 120 SNMP_AUTH_HMAC_SHA 121}; 122 123enum snmp_privacy { 124 SNMP_PRIV_NOPRIV = 0, 125 SNMP_PRIV_DES = 1, 126 SNMP_PRIV_AES 127}; 128 129struct snmp_engine { 130 uint8_t engine_id[SNMP_ENGINE_ID_SIZ]; 131 uint32_t engine_len; 132 int32_t engine_boots; 133 int32_t engine_time; 134 int32_t max_msg_size; 135}; 136 137struct snmp_user { 138 char sec_name[SNMP_ADM_STR32_SIZ]; 139 enum snmp_authentication auth_proto; 140 enum snmp_privacy priv_proto; 141 uint8_t auth_key[SNMP_AUTH_KEY_SIZ]; 142 uint8_t priv_key[SNMP_PRIV_KEY_SIZ]; 143}; 144 |
|
81struct snmp_pdu { | 145struct snmp_pdu { |
82 char community[SNMP_COMMUNITY_MAXLEN + 1]; 83 enum snmp_version version; 84 u_int type; | 146 char community[SNMP_COMMUNITY_MAXLEN + 1]; 147 enum snmp_version version; 148 u_int type; |
85 | 149 |
150 /* SNMPv3 PDU header fields */ 151 int32_t identifier; 152 uint8_t flags; 153 int32_t security_model; 154 struct snmp_engine engine; 155 156 /* Associated USM user parameters */ 157 struct snmp_user user; 158 uint8_t msg_digest[SNMP_USM_AUTH_SIZE]; 159 uint8_t msg_salt[SNMP_USM_PRIV_SIZE]; 160 161 /* View-based Access Model */ 162 /* XXX: put in separate structure - conflicts with struct snmp_context */ 163 uint32_t context_engine_len; 164 uint8_t context_engine[SNMP_ENGINE_ID_SIZ]; 165 char context_name[SNMP_CONTEXT_NAME_SIZ]; 166 |
|
86 /* trap only */ | 167 /* trap only */ |
87 struct asn_oid enterprise; 88 u_char agent_addr[4]; 89 int32_t generic_trap; 90 int32_t specific_trap; 91 uint32_t time_stamp; | 168 struct asn_oid enterprise; 169 u_char agent_addr[4]; 170 int32_t generic_trap; 171 int32_t specific_trap; 172 uint32_t time_stamp; |
92 93 /* others */ | 173 174 /* others */ |
94 int32_t request_id; 95 int32_t error_status; 96 int32_t error_index; | 175 int32_t request_id; 176 int32_t error_status; 177 int32_t error_index; |
97 98 /* fixes for encoding */ | 178 179 /* fixes for encoding */ |
99 u_char *outer_ptr; 100 u_char *pdu_ptr; 101 u_char *vars_ptr; | 180 size_t outer_len; 181 size_t scoped_len; 182 u_char *outer_ptr; 183 u_char *digest_ptr; 184 u_char *encrypted_ptr; 185 u_char *scoped_ptr; 186 u_char *pdu_ptr; 187 u_char *vars_ptr; |
102 | 188 |
103 struct snmp_value bindings[SNMP_MAX_BINDINGS]; 104 u_int nbindings; | 189 190 struct snmp_value bindings[SNMP_MAX_BINDINGS]; 191 u_int nbindings; |
105}; 106#define snmp_v1_pdu snmp_pdu 107 108#define SNMP_PDU_GET 0 109#define SNMP_PDU_GETNEXT 1 110#define SNMP_PDU_RESPONSE 2 111#define SNMP_PDU_SET 3 112#define SNMP_PDU_TRAP 4 /* v1 */ --- 32 unchanged lines hidden (view full) --- 145 146enum snmp_code { 147 SNMP_CODE_OK = 0, 148 SNMP_CODE_FAILED, 149 SNMP_CODE_BADVERS, 150 SNMP_CODE_BADLEN, 151 SNMP_CODE_BADENC, 152 SNMP_CODE_OORANGE, | 192}; 193#define snmp_v1_pdu snmp_pdu 194 195#define SNMP_PDU_GET 0 196#define SNMP_PDU_GETNEXT 1 197#define SNMP_PDU_RESPONSE 2 198#define SNMP_PDU_SET 3 199#define SNMP_PDU_TRAP 4 /* v1 */ --- 32 unchanged lines hidden (view full) --- 232 233enum snmp_code { 234 SNMP_CODE_OK = 0, 235 SNMP_CODE_FAILED, 236 SNMP_CODE_BADVERS, 237 SNMP_CODE_BADLEN, 238 SNMP_CODE_BADENC, 239 SNMP_CODE_OORANGE, |
240 SNMP_CODE_BADSECLEVEL, 241 SNMP_CODE_NOTINTIME, 242 SNMP_CODE_BADUSER, 243 SNMP_CODE_BADENGINE, 244 SNMP_CODE_BADDIGEST, 245 SNMP_CODE_EDECRYPT |
|
153}; 154 | 246}; 247 |
248#define SNMP_MSG_AUTH_FLAG 0x1 249#define SNMP_MSG_PRIV_FLAG 0x2 250#define SNMP_MSG_REPORT_FLAG 0x4 251#define SNMP_MSG_AUTODISCOVER 0x80 252 |
|
155void snmp_value_free(struct snmp_value *); 156int snmp_value_parse(const char *, enum snmp_syntax, union snmp_values *); 157int snmp_value_copy(struct snmp_value *, const struct snmp_value *); 158 159void snmp_pdu_free(struct snmp_pdu *); 160enum snmp_code snmp_pdu_decode(struct asn_buf *b, struct snmp_pdu *pdu, int32_t *); | 253void snmp_value_free(struct snmp_value *); 254int snmp_value_parse(const char *, enum snmp_syntax, union snmp_values *); 255int snmp_value_copy(struct snmp_value *, const struct snmp_value *); 256 257void snmp_pdu_free(struct snmp_pdu *); 258enum snmp_code snmp_pdu_decode(struct asn_buf *b, struct snmp_pdu *pdu, int32_t *); |
161enum snmp_code snmp_pdu_encode(struct snmp_pdu *pdu, struct asn_buf *resp_b); | 259enum snmp_code snmp_pdu_decode_header(struct asn_buf *, struct snmp_pdu *); 260enum snmp_code snmp_pdu_decode_scoped(struct asn_buf *, struct snmp_pdu *, int32_t *); 261enum snmp_code snmp_pdu_encode(struct snmp_pdu *, struct asn_buf *); 262enum snmp_code snmp_pdu_decode_secmode(struct asn_buf *, struct snmp_pdu *); |
162 163int snmp_pdu_snoop(const struct asn_buf *); 164 165void snmp_pdu_dump(const struct snmp_pdu *pdu); 166 | 263 264int snmp_pdu_snoop(const struct asn_buf *); 265 266void snmp_pdu_dump(const struct snmp_pdu *pdu); 267 |
268enum snmp_code snmp_passwd_to_keys(struct snmp_user *, char *); 269enum snmp_code snmp_get_local_keys(struct snmp_user *, uint8_t *, uint32_t); 270enum snmp_code snmp_calc_keychange(struct snmp_user *, uint8_t *); 271 |
|
167extern void (*snmp_error)(const char *, ...); 168extern void (*snmp_printf)(const char *, ...); 169 170#define TRUTH_MK(F) ((F) ? 1 : 2) 171#define TRUTH_GET(T) (((T) == 1) ? 1 : 0) 172#define TRUTH_OK(T) ((T) == 1 || (T) == 2) 173 174#endif | 272extern void (*snmp_error)(const char *, ...); 273extern void (*snmp_printf)(const char *, ...); 274 275#define TRUTH_MK(F) ((F) ? 1 : 2) 276#define TRUTH_GET(T) (((T) == 1) ? 1 : 0) 277#define TRUTH_OK(T) ((T) == 1 || (T) == 2) 278 279#endif |