net-snmp 5.7
|
00001 #ifndef _SNMP_TRANSPORT_H 00002 #define _SNMP_TRANSPORT_H 00003 00004 #include <sys/types.h> 00005 00006 #if HAVE_SYS_SOCKET_H 00007 #ifdef solaris2 00008 #define _XPG4_2 00009 #endif 00010 00011 #include <sys/socket.h> 00012 00013 #ifdef solaris2 00014 # ifndef CMSG_SPACE 00015 # define CMSG_SPACE(l) \ 00016 ((unsigned int)_CMSG_HDR_ALIGN(sizeof (struct cmsghdr) + (l))) 00017 # define CMSG_LEN(l) (_CMSG_HDR_ALIGN(sizeof(struct cmsghdr)) + (l)) 00018 # endif 00019 #endif 00020 #endif /* HAVE_SYS_SOCKET_H */ 00021 00022 #ifdef HAVE_NETINET_IN_H 00023 #include <netinet/in.h> 00024 #endif 00025 00026 #include <net-snmp/library/asn1.h> 00027 00028 #ifdef __cplusplus 00029 extern "C" { 00030 #endif 00031 00032 /* Some transport-type constants. */ 00033 00034 #ifndef NETSNMP_STREAM_QUEUE_LEN 00035 #define NETSNMP_STREAM_QUEUE_LEN 5 00036 #endif 00037 00038 /* Some transport-type flags. */ 00039 00040 #define NETSNMP_TRANSPORT_FLAG_STREAM 0x01 00041 #define NETSNMP_TRANSPORT_FLAG_LISTEN 0x02 00042 #define NETSNMP_TRANSPORT_FLAG_TUNNELED 0x04 00043 #define NETSNMP_TRANSPORT_FLAG_TMSTATE 0x08 /* indicates opaque is a 00044 TSM tmStateReference */ 00045 #define NETSNMP_TRANSPORT_FLAG_EMPTY_PKT 0x10 00046 #define NETSNMP_TRANSPORT_FLAG_OPENED 0x20 /* f_open called */ 00047 #define NETSNMP_TRANSPORT_FLAG_HOSTNAME 0x80 /* for fmtaddr hook */ 00048 00049 /* The standard SNMP domains. */ 00050 00051 NETSNMP_IMPORT oid netsnmpUDPDomain[]; /* = { 1, 3, 6, 1, 6, 1, 1 }; */ 00052 NETSNMP_IMPORT oid netsnmpCLNSDomain[]; /* = { 1, 3, 6, 1, 6, 1, 2 }; */ 00053 NETSNMP_IMPORT oid netsnmpCONSDomain[]; /* = { 1, 3, 6, 1, 6, 1, 3 }; */ 00054 NETSNMP_IMPORT oid netsnmpDDPDomain[]; /* = { 1, 3, 6, 1, 6, 1, 4 }; */ 00055 NETSNMP_IMPORT oid netsnmpIPXDomain[]; /* = { 1, 3, 6, 1, 6, 1, 5 }; */ 00056 NETSNMP_IMPORT size_t netsnmpUDPDomain_len; 00057 NETSNMP_IMPORT size_t netsnmpCLNSDomain_len; 00058 NETSNMP_IMPORT size_t netsnmpCONSDomain_len; 00059 NETSNMP_IMPORT size_t netsnmpDDPDomain_len; 00060 NETSNMP_IMPORT size_t netsnmpIPXDomain_len; 00061 00062 /* Structure which stores transport security model specific parameters */ 00063 /* isms-secshell-11 section 4.1 */ 00064 00065 /* contents documented in draft-ietf-isms-transport-security-model 00066 Section 3.2 */ 00067 /* note: VACM only allows <= 32 so this is overkill till another ACM comes */ 00068 #define NETSNMP_TM_MAX_SECNAME 256 00069 00070 typedef union netsnmp_sockaddr_storage_u { 00071 struct sockaddr sa; 00072 struct sockaddr_in sin; 00073 #ifdef NETSNMP_ENABLE_IPV6 00074 struct sockaddr_in6 sin6; 00075 #endif 00076 } netsnmp_sockaddr_storage; 00077 00078 typedef struct netsnmp_addr_pair_s { 00079 netsnmp_sockaddr_storage remote_addr; 00080 netsnmp_sockaddr_storage local_addr; 00081 } netsnmp_addr_pair; 00082 00083 typedef struct netsnmp_indexed_addr_pair_s { 00084 netsnmp_sockaddr_storage remote_addr; 00085 netsnmp_sockaddr_storage local_addr; 00086 int if_index; 00087 } netsnmp_indexed_addr_pair; 00088 00089 typedef struct netsnmp_tmStateReference_s { 00090 oid transportDomain[MAX_OID_LEN]; 00091 size_t transportDomainLen; 00092 char securityName[NETSNMP_TM_MAX_SECNAME]; 00093 size_t securityNameLen; 00094 int requestedSecurityLevel; 00095 int transportSecurityLevel; 00096 char sameSecurity; 00097 char sessionID[8]; 00098 00099 char have_addresses; 00100 netsnmp_indexed_addr_pair addresses; 00101 00102 void *otherTransportOpaque; /* XXX: May have mem leak issues */ 00103 } netsnmp_tmStateReference; 00104 00105 /* Structure which defines the transport-independent API. */ 00106 00107 struct snmp_session; 00108 00109 typedef struct netsnmp_transport_s { 00110 /* The transport domain object identifier. */ 00111 00112 const oid *domain; 00113 int domain_length; /* In sub-IDs, not octets. */ 00114 00115 /* Local transport address (in relevant SNMP-style encoding). */ 00116 00117 unsigned char *local; 00118 int local_length; /* In octets. */ 00119 00120 /* Remote transport address (in relevant SNMP-style encoding). */ 00121 00122 unsigned char *remote; 00123 int remote_length; /* In octets. */ 00124 00125 /* The actual socket. */ 00126 00127 int sock; 00128 00129 /* Flags (see #definitions above). */ 00130 00131 unsigned int flags; 00132 00133 /* Protocol-specific opaque data pointer. */ 00134 00135 void *data; 00136 int data_length; 00137 00138 /* Maximum size of PDU that can be sent/received by this transport. */ 00139 00140 size_t msgMaxSize; 00141 00142 #ifdef FOR_STANDARDS_COMPLIANCE_OR_FUTURE_USE 00143 /* TM state reference per ISMS WG solution */ 00144 netsnmp_tmStateReference *tmStateRef; 00145 #endif 00146 00147 /* tunneled transports */ 00148 struct netsnmp_transport_s * base_transport; 00149 00150 /* Callbacks. Arguments are: 00151 * 00152 * "this" pointer, fd, buf, size, *opaque, *opaque_length 00153 */ 00154 00155 int (*f_recv) (struct netsnmp_transport_s *, void *, 00156 int, void **, int *); 00157 int (*f_send) (struct netsnmp_transport_s *, void *, 00158 int, void **, int *); 00159 int (*f_close) (struct netsnmp_transport_s *); 00160 00161 /* Optional: opening can occur during creation if more appropriate */ 00162 struct netsnmp_transport_s * (*f_open) (struct netsnmp_transport_s *); 00163 00164 /* This callback is only necessary for stream-oriented transports. */ 00165 00166 int (*f_accept) (struct netsnmp_transport_s *); 00167 00168 /* Optional callback to format a transport address. */ 00169 00170 char *(*f_fmtaddr)(struct netsnmp_transport_s *, void *, int); 00171 00172 /* Optional callback to support extra configuration token/value pairs */ 00173 /* return non-zero on error */ 00174 int (*f_config)(struct netsnmp_transport_s *, const char *, 00175 const char *); 00176 00177 /* Optional callback that is called after the first transport is 00178 cloned to the second */ 00179 int (*f_copy)(struct netsnmp_transport_s *, 00180 struct netsnmp_transport_s *); 00181 00182 /* Setup initial session config if special things are needed */ 00183 int (*f_setup_session)(struct netsnmp_transport_s *, 00184 struct snmp_session *); 00185 00186 /* allocated host name identifier; used by configuration system 00187 to load localhost.conf for host-specific configuration */ 00188 u_char *identifier; /* udp:localhost:161 -> "localhost" */ 00189 } netsnmp_transport; 00190 00191 typedef struct netsnmp_transport_list_s { 00192 netsnmp_transport *transport; 00193 struct netsnmp_transport_list_s *next; 00194 } netsnmp_transport_list; 00195 00196 typedef struct netsnmp_tdomain_s { 00197 const oid *name; 00198 size_t name_length; 00199 const char **prefix; 00200 00201 /* 00202 * The f_create_from_tstring field is deprecated, please do not use it 00203 * for new code and try to migrate old code away from using it. 00204 */ 00205 netsnmp_transport *(*f_create_from_tstring) (const char *, int); 00206 00207 netsnmp_transport *(*f_create_from_ostring) (const u_char *, size_t, int); 00208 00209 struct netsnmp_tdomain_s *next; 00210 00211 netsnmp_transport *(*f_create_from_tstring_new) (const char *, int, 00212 const char*); 00213 00214 } netsnmp_tdomain; 00215 00216 void init_snmp_transport(void); 00217 00218 /* Some utility functions. */ 00219 00220 char *netsnmp_transport_peer_string(netsnmp_transport *t, void *data, int len); 00221 00222 int netsnmp_transport_send(netsnmp_transport *t, void *data, int len, 00223 void **opaque, int *olength); 00224 int netsnmp_transport_recv(netsnmp_transport *t, void *data, int len, 00225 void **opaque, int *olength); 00226 00227 int netsnmp_transport_add_to_list(netsnmp_transport_list **transport_list, 00228 netsnmp_transport *transport); 00229 int netsnmp_transport_remove_from_list(netsnmp_transport_list **transport_list, 00230 netsnmp_transport *transport); 00231 int netsnmp_sockaddr_size(struct sockaddr *sa); 00232 00233 00234 /* 00235 * Return an exact (deep) copy of t, or NULL if there is a memory allocation 00236 * problem (for instance). 00237 */ 00238 00239 netsnmp_transport *netsnmp_transport_copy(netsnmp_transport *t); 00240 00241 00242 /* Free an netsnmp_transport. */ 00243 00244 NETSNMP_IMPORT 00245 void netsnmp_transport_free(netsnmp_transport *t); 00246 00247 00248 /* 00249 * If the passed oid (in_oid, in_len) corresponds to a supported transport 00250 * domain, return 1; if not return 0. If out_oid is not NULL and out_len is 00251 * not NULL, then the "internal" oid which should be used to identify this 00252 * domain (e.g. in pdu->tDomain etc.) is written to *out_oid and its length to 00253 * *out_len. 00254 */ 00255 00256 NETSNMP_IMPORT 00257 int netsnmp_tdomain_support(const oid *in_oid, size_t in_len, 00258 const oid **out_oid, size_t *out_len); 00259 00260 int netsnmp_tdomain_register(netsnmp_tdomain *domain); 00261 00262 int netsnmp_tdomain_unregister(netsnmp_tdomain *domain); 00263 00264 NETSNMP_IMPORT 00265 void netsnmp_clear_tdomain_list(void); 00266 00267 void netsnmp_tdomain_init(void); 00268 00269 NETSNMP_IMPORT 00270 netsnmp_transport *netsnmp_tdomain_transport(const char *str, 00271 int local, 00272 const char *default_domain); 00273 00274 NETSNMP_IMPORT 00275 netsnmp_transport *netsnmp_tdomain_transport_full(const char *application, 00276 const char *str, 00277 int local, 00278 const char *default_domain, 00279 const char *default_target); 00280 00281 NETSNMP_IMPORT 00282 netsnmp_transport *netsnmp_tdomain_transport_oid(const oid * dom, 00283 size_t dom_len, 00284 const u_char * o, 00285 size_t o_len, 00286 int local); 00287 00288 NETSNMP_IMPORT 00289 netsnmp_transport* 00290 netsnmp_transport_open_client(const char* application, const char* str); 00291 00292 NETSNMP_IMPORT 00293 netsnmp_transport* 00294 netsnmp_transport_open_server(const char* application, const char* str); 00295 00296 netsnmp_transport* 00297 netsnmp_transport_open(const char* application, const char* str, int local); 00298 00299 typedef struct netsnmp_transport_config_s { 00300 char *key; 00301 char *value; 00302 } netsnmp_transport_config; 00303 00304 NETSNMP_IMPORT 00305 int netsnmp_transport_config_compare(netsnmp_transport_config *left, 00306 netsnmp_transport_config *right); 00307 NETSNMP_IMPORT 00308 netsnmp_transport_config *netsnmp_transport_create_config(char *key, 00309 char *value); 00310 #ifdef __cplusplus 00311 } 00312 #endif 00313 #endif/*_SNMP_TRANSPORT_H*/