1 /* $OpenBSD: agentx.h,v 1.5 2020/10/27 18:24:01 martijn Exp $ */ 2 /* 3 * Copyright (c) 2019 Martijn van Duren <martijn@openbsd.org> 4 * 5 * Permission to use, copy, modify, and distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice and this permission notice appear in all copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 */ 17 18 #include <netinet/in.h> 19 20 #include <stdint.h> 21 #include <stddef.h> 22 23 struct agentx; 24 struct agentx_session; 25 struct agentx_context; 26 struct agentx_agentcaps; 27 struct agentx_region; 28 struct agentx_index; 29 struct agentx_object; 30 struct agentx_varbind; 31 32 enum agentx_request_type { 33 AGENTX_REQUEST_TYPE_GET, 34 AGENTX_REQUEST_TYPE_GETNEXT, 35 AGENTX_REQUEST_TYPE_GETNEXTINCLUSIVE 36 }; 37 38 #define AGENTX_MASTER_PATH "/var/agentx/master" 39 #define AGENTX_OID_MAX_LEN 128 40 #define AGENTX_OID_INDEX_MAX_LEN 10 41 #define AGENTX_MIB2 1, 3, 6, 1, 2, 1 42 #define AGENTX_ENTERPRISES 1, 3, 6, 1, 4, 1 43 #define AGENTX_OID(...) (uint32_t []) { __VA_ARGS__ }, \ 44 (sizeof((uint32_t []) { __VA_ARGS__ }) / sizeof(uint32_t)) 45 46 extern void (*agentx_log_fatal)(const char *, ...) 47 __attribute__((__format__ (printf, 1, 2))); 48 extern void (*agentx_log_warn)(const char *, ...) 49 __attribute__((__format__ (printf, 1, 2))); 50 extern void (*agentx_log_info)(const char *, ...) 51 __attribute__((__format__ (printf, 1, 2))); 52 extern void (*agentx_log_debug)(const char *, ...) 53 __attribute__((__format__ (printf, 1, 2))); 54 55 struct agentx *agentx(void (*)(struct agentx *, void *, int), void *); 56 void agentx_connect(struct agentx *, int); 57 void agentx_read(struct agentx *); 58 void agentx_write(struct agentx *); 59 extern void (*agentx_wantwrite)(struct agentx *, int); 60 void agentx_free(struct agentx *); 61 struct agentx_session *agentx_session(struct agentx *, 62 uint32_t[], size_t, const char *, uint8_t); 63 void agentx_session_free(struct agentx_session *); 64 struct agentx_context *agentx_context(struct agentx_session *, 65 const char *); 66 struct agentx_object *agentx_context_object_find( 67 struct agentx_context *, const uint32_t[], size_t, int, int); 68 struct agentx_object *agentx_context_object_nfind( 69 struct agentx_context *, const uint32_t[], size_t, int, int); 70 uint32_t agentx_context_uptime(struct agentx_context *); 71 void agentx_context_free(struct agentx_context *); 72 struct agentx_agentcaps *agentx_agentcaps(struct agentx_context *, 73 uint32_t[], size_t, const char *); 74 void agentx_agentcaps_free(struct agentx_agentcaps *); 75 struct agentx_region *agentx_region(struct agentx_context *, 76 uint32_t[], size_t, uint8_t); 77 void agentx_region_free(struct agentx_region *); 78 struct agentx_index *agentx_index_integer_new(struct agentx_region *, 79 uint32_t[], size_t); 80 struct agentx_index *agentx_index_integer_any(struct agentx_region *, 81 uint32_t[], size_t); 82 struct agentx_index *agentx_index_integer_value(struct agentx_region *, 83 uint32_t[], size_t, int32_t); 84 struct agentx_index *agentx_index_integer_dynamic( 85 struct agentx_region *, uint32_t[], size_t); 86 struct agentx_index *agentx_index_string_dynamic( 87 struct agentx_region *, uint32_t[], size_t); 88 struct agentx_index *agentx_index_nstring_dynamic( 89 struct agentx_region *, uint32_t[], size_t, size_t); 90 struct agentx_index *agentx_index_oid_dynamic(struct agentx_region *, 91 uint32_t[], size_t); 92 struct agentx_index *agentx_index_noid_dynamic(struct agentx_region *, 93 uint32_t[], size_t, size_t); 94 struct agentx_index *agentx_index_ipaddress_dynamic( 95 struct agentx_region *, uint32_t[], size_t); 96 void agentx_index_free(struct agentx_index *); 97 struct agentx_object *agentx_object(struct agentx_region *, uint32_t[], 98 size_t, struct agentx_index *[], size_t, int, 99 void (*)(struct agentx_varbind *)); 100 void agentx_object_free(struct agentx_object *); 101 102 void agentx_varbind_integer(struct agentx_varbind *, int32_t); 103 void agentx_varbind_string(struct agentx_varbind *, const char *); 104 void agentx_varbind_nstring(struct agentx_varbind *, 105 const unsigned char *, size_t); 106 void agentx_varbind_printf(struct agentx_varbind *, const char *, ...) 107 __attribute__((__format__ (printf, 2, 3))); 108 void agentx_varbind_null(struct agentx_varbind *); 109 void agentx_varbind_oid(struct agentx_varbind *, const uint32_t[], 110 size_t); 111 void agentx_varbind_object(struct agentx_varbind *, 112 struct agentx_object *); 113 void agentx_varbind_index(struct agentx_varbind *, 114 struct agentx_index *); 115 void agentx_varbind_ipaddress(struct agentx_varbind *, 116 const struct in_addr *); 117 void agentx_varbind_counter32(struct agentx_varbind *, uint32_t); 118 void agentx_varbind_gauge32(struct agentx_varbind *, uint32_t); 119 void agentx_varbind_unsigned32(struct agentx_varbind *, uint32_t); 120 void agentx_varbind_timeticks(struct agentx_varbind *, uint32_t); 121 void agentx_varbind_opaque(struct agentx_varbind *, const char *, size_t); 122 void agentx_varbind_counter64(struct agentx_varbind *, uint64_t); 123 void agentx_varbind_notfound(struct agentx_varbind *); 124 void agentx_varbind_error(struct agentx_varbind *); 125 126 enum agentx_request_type agentx_varbind_request( 127 struct agentx_varbind *); 128 struct agentx_object * 129 agentx_varbind_get_object(struct agentx_varbind *); 130 int32_t agentx_varbind_get_index_integer(struct agentx_varbind *, 131 struct agentx_index *); 132 const unsigned char *agentx_varbind_get_index_string( 133 struct agentx_varbind *, struct agentx_index *, size_t *, int *); 134 const uint32_t *agentx_varbind_get_index_oid(struct agentx_varbind *, 135 struct agentx_index *, size_t *, int *); 136 const struct in_addr *agentx_varbind_get_index_ipaddress( 137 struct agentx_varbind *, struct agentx_index *); 138 void agentx_varbind_set_index_integer(struct agentx_varbind *, 139 struct agentx_index *, int32_t); 140 void agentx_varbind_set_index_string(struct agentx_varbind *, 141 struct agentx_index *, const char *); 142 void agentx_varbind_set_index_nstring(struct agentx_varbind *, 143 struct agentx_index *, const unsigned char *, size_t); 144 void agentx_varbind_set_index_oid(struct agentx_varbind *, 145 struct agentx_index *, const uint32_t *, size_t); 146 void agentx_varbind_set_index_object(struct agentx_varbind *, 147 struct agentx_index *, struct agentx_object *); 148 void agentx_varbind_set_index_ipaddress(struct agentx_varbind *, 149 struct agentx_index *, const struct in_addr *); 150