1 /* $OpenBSD: agentx.h,v 1.7 2022/10/14 15:26:58 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_MIN_LEN 2 40 #define AGENTX_OID_MAX_LEN 128 41 #define AGENTX_OID_INDEX_MAX_LEN 10 42 #define AGENTX_MIB2 1, 3, 6, 1, 2, 1 43 #define AGENTX_ENTERPRISES 1, 3, 6, 1, 4, 1 44 #define AGENTX_OID(...) (uint32_t []) { __VA_ARGS__ }, \ 45 (sizeof((uint32_t []) { __VA_ARGS__ }) / sizeof(uint32_t)) 46 47 extern void (*agentx_log_fatal)(const char *, ...) 48 __attribute__((__format__ (printf, 1, 2))); 49 extern void (*agentx_log_warn)(const char *, ...) 50 __attribute__((__format__ (printf, 1, 2))); 51 extern void (*agentx_log_info)(const char *, ...) 52 __attribute__((__format__ (printf, 1, 2))); 53 extern void (*agentx_log_debug)(const char *, ...) 54 __attribute__((__format__ (printf, 1, 2))); 55 56 struct agentx *agentx(void (*)(struct agentx *, void *, int), void *); 57 void agentx_connect(struct agentx *, int); 58 void agentx_retry(struct agentx *); 59 void agentx_read(struct agentx *); 60 void agentx_write(struct agentx *); 61 extern void (*agentx_wantwrite)(struct agentx *, int); 62 void agentx_free(struct agentx *); 63 struct agentx_session *agentx_session(struct agentx *, 64 uint32_t[], size_t, const char *, uint8_t); 65 void agentx_session_free(struct agentx_session *); 66 struct agentx_context *agentx_context(struct agentx_session *, 67 const char *); 68 struct agentx_object *agentx_context_object_find( 69 struct agentx_context *, const uint32_t[], size_t, int, int); 70 struct agentx_object *agentx_context_object_nfind( 71 struct agentx_context *, const uint32_t[], size_t, int, int); 72 uint32_t agentx_context_uptime(struct agentx_context *); 73 void agentx_context_free(struct agentx_context *); 74 struct agentx_agentcaps *agentx_agentcaps(struct agentx_context *, 75 uint32_t[], size_t, const char *); 76 void agentx_agentcaps_free(struct agentx_agentcaps *); 77 struct agentx_region *agentx_region(struct agentx_context *, 78 uint32_t[], size_t, uint8_t); 79 void agentx_region_free(struct agentx_region *); 80 struct agentx_index *agentx_index_integer_new(struct agentx_region *, 81 uint32_t[], size_t); 82 struct agentx_index *agentx_index_integer_any(struct agentx_region *, 83 uint32_t[], size_t); 84 struct agentx_index *agentx_index_integer_value(struct agentx_region *, 85 uint32_t[], size_t, int32_t); 86 struct agentx_index *agentx_index_integer_dynamic( 87 struct agentx_region *, uint32_t[], size_t); 88 struct agentx_index *agentx_index_string_dynamic( 89 struct agentx_region *, uint32_t[], size_t); 90 struct agentx_index *agentx_index_nstring_dynamic( 91 struct agentx_region *, uint32_t[], size_t, size_t); 92 struct agentx_index *agentx_index_oid_dynamic(struct agentx_region *, 93 uint32_t[], size_t); 94 struct agentx_index *agentx_index_noid_dynamic(struct agentx_region *, 95 uint32_t[], size_t, size_t); 96 struct agentx_index *agentx_index_ipaddress_dynamic( 97 struct agentx_region *, uint32_t[], size_t); 98 void agentx_index_free(struct agentx_index *); 99 struct agentx_object *agentx_object(struct agentx_region *, uint32_t[], 100 size_t, struct agentx_index *[], size_t, int, 101 void (*)(struct agentx_varbind *)); 102 void agentx_object_free(struct agentx_object *); 103 104 void agentx_varbind_integer(struct agentx_varbind *, int32_t); 105 void agentx_varbind_string(struct agentx_varbind *, const char *); 106 void agentx_varbind_nstring(struct agentx_varbind *, 107 const unsigned char *, size_t); 108 void agentx_varbind_printf(struct agentx_varbind *, const char *, ...) 109 __attribute__((__format__ (printf, 2, 3))); 110 void agentx_varbind_null(struct agentx_varbind *); 111 void agentx_varbind_oid(struct agentx_varbind *, const uint32_t[], 112 size_t); 113 void agentx_varbind_object(struct agentx_varbind *, 114 struct agentx_object *); 115 void agentx_varbind_index(struct agentx_varbind *, 116 struct agentx_index *); 117 void agentx_varbind_ipaddress(struct agentx_varbind *, 118 const struct in_addr *); 119 void agentx_varbind_counter32(struct agentx_varbind *, uint32_t); 120 void agentx_varbind_gauge32(struct agentx_varbind *, uint32_t); 121 void agentx_varbind_unsigned32(struct agentx_varbind *, uint32_t); 122 void agentx_varbind_timeticks(struct agentx_varbind *, uint32_t); 123 void agentx_varbind_opaque(struct agentx_varbind *, const char *, size_t); 124 void agentx_varbind_counter64(struct agentx_varbind *, uint64_t); 125 void agentx_varbind_notfound(struct agentx_varbind *); 126 void agentx_varbind_error(struct agentx_varbind *); 127 128 enum agentx_request_type agentx_varbind_request( 129 struct agentx_varbind *); 130 struct agentx_object * 131 agentx_varbind_get_object(struct agentx_varbind *); 132 int32_t agentx_varbind_get_index_integer(struct agentx_varbind *, 133 struct agentx_index *); 134 const unsigned char *agentx_varbind_get_index_string( 135 struct agentx_varbind *, struct agentx_index *, size_t *, int *); 136 const uint32_t *agentx_varbind_get_index_oid(struct agentx_varbind *, 137 struct agentx_index *, size_t *, int *); 138 const struct in_addr *agentx_varbind_get_index_ipaddress( 139 struct agentx_varbind *, struct agentx_index *); 140 void agentx_varbind_set_index_integer(struct agentx_varbind *, 141 struct agentx_index *, int32_t); 142 void agentx_varbind_set_index_string(struct agentx_varbind *, 143 struct agentx_index *, const char *); 144 void agentx_varbind_set_index_nstring(struct agentx_varbind *, 145 struct agentx_index *, const unsigned char *, size_t); 146 void agentx_varbind_set_index_oid(struct agentx_varbind *, 147 struct agentx_index *, const uint32_t *, size_t); 148 void agentx_varbind_set_index_object(struct agentx_varbind *, 149 struct agentx_index *, struct agentx_object *); 150 void agentx_varbind_set_index_ipaddress(struct agentx_varbind *, 151 struct agentx_index *, const struct in_addr *); 152