1 /* $OpenBSD: agentx_internal.h,v 1.3 2021/10/23 14:39:35 martijn Exp $ */ 2 /* 3 * Copyright (c) 2020 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 #include <sys/queue.h> 18 #include <sys/time.h> 19 #include <sys/tree.h> 20 21 #include "ax.h" 22 23 enum agentx_cstate { /* Current state */ 24 AX_CSTATE_CLOSE, /* Closed */ 25 AX_CSTATE_WAITOPEN, /* Connection requested */ 26 AX_CSTATE_OPEN, /* Open */ 27 AX_CSTATE_WAITCLOSE /* Close requested */ 28 }; 29 30 enum agentx_dstate { /* Desired state */ 31 AX_DSTATE_OPEN, /* Open */ 32 AX_DSTATE_CLOSE /* Close/free */ 33 }; 34 35 struct agentx { 36 void (*ax_nofd)(struct agentx *, void *, int); 37 void *ax_cookie; 38 int ax_fd; 39 enum agentx_cstate ax_cstate; 40 enum agentx_dstate ax_dstate; 41 int ax_free; /* Freeing already planned */ 42 struct ax *ax_ax; 43 TAILQ_HEAD(, agentx_session) ax_sessions; 44 TAILQ_HEAD(, agentx_get) ax_getreqs; 45 RB_HEAD(ax_requests, agentx_request) ax_requests; 46 }; 47 48 struct agentx_session { 49 struct agentx *axs_ax; 50 uint32_t axs_id; 51 uint32_t axs_timeout; 52 struct ax_oid axs_oid; 53 struct ax_ostring axs_descr; 54 enum agentx_cstate axs_cstate; 55 enum agentx_dstate axs_dstate; 56 uint32_t axs_packetid; 57 TAILQ_HEAD(, agentx_context) axs_contexts; 58 TAILQ_ENTRY(agentx_session) axs_ax_sessions; 59 }; 60 61 struct agentx_context { 62 struct agentx_session *axc_axs; 63 int axc_name_default; 64 struct ax_ostring axc_name; 65 uint32_t axc_sysuptime; 66 struct timespec axc_sysuptimespec; 67 enum agentx_cstate axc_cstate; 68 enum agentx_dstate axc_dstate; 69 TAILQ_HEAD(, agentx_agentcaps) axc_agentcaps; 70 TAILQ_HEAD(, agentx_region) axc_regions; 71 RB_HEAD(axc_objects, agentx_object) axc_objects; 72 TAILQ_ENTRY(agentx_context) axc_axs_contexts; 73 }; 74 75 struct agentx_get { 76 struct agentx_context *axg_axc; 77 int axg_fd; /* Only used for logging */ 78 uint32_t axg_sessionid; 79 uint32_t axg_transactionid; 80 uint32_t axg_packetid; 81 int axg_context_default; 82 struct ax_ostring axg_context; 83 enum ax_pdu_type axg_type; 84 uint16_t axg_nonrep; 85 uint16_t axg_maxrep; 86 size_t axg_nvarbind; 87 struct agentx_varbind *axg_varbind; 88 TAILQ_ENTRY(agentx_get) axg_ax_getreqs; 89 }; 90 91 __dead void agentx_log_ax_fatalx(struct agentx *, const char *, ...) 92 __attribute__((__format__ (printf, 2, 3))); 93 void agentx_log_ax_warn(struct agentx *, const char *, ...) 94 __attribute__((__format__ (printf, 2, 3))); 95 void agentx_log_ax_warnx(struct agentx *, const char *, ...) 96 __attribute__((__format__ (printf, 2, 3))); 97 void agentx_log_ax_info(struct agentx *, const char *, ...) 98 __attribute__((__format__ (printf, 2, 3))); 99 void agentx_log_ax_debug(struct agentx *, const char *, ...) 100 __attribute__((__format__ (printf, 2, 3))); 101 __dead void agentx_log_axs_fatalx(struct agentx_session *, const char *, 102 ...) __attribute__((__format__ (printf, 2, 3))); 103 void agentx_log_axs_warnx(struct agentx_session *, const char *, ...) 104 __attribute__((__format__ (printf, 2, 3))); 105 void agentx_log_axs_warn(struct agentx_session *, const char *, ...) 106 __attribute__((__format__ (printf, 2, 3))); 107 void agentx_log_axs_info(struct agentx_session *, const char *, ...) 108 __attribute__((__format__ (printf, 2, 3))); 109 __dead void agentx_log_axc_fatalx(struct agentx_context *, const char *, 110 ...) __attribute__((__format__ (printf, 2, 3))); 111 void agentx_log_axc_warnx(struct agentx_context *, const char *, ...) 112 __attribute__((__format__ (printf, 2, 3))); 113 void agentx_log_axc_warn(struct agentx_context *, const char *, ...) 114 __attribute__((__format__ (printf, 2, 3))); 115 void agentx_log_axc_info(struct agentx_context *, const char *, ...) 116 __attribute__((__format__ (printf, 2, 3))); 117 void agentx_log_axc_debug(struct agentx_context *, const char *, ...) 118 __attribute__((__format__ (printf, 2, 3))); 119 __dead void agentx_log_axg_fatalx(struct agentx_get *, const char *, 120 ...) __attribute__((__format__ (printf, 2, 3))); 121 void agentx_log_axg_warnx(struct agentx_get *, const char *, ...) 122 __attribute__((__format__ (printf, 2, 3))); 123 void agentx_log_axg_warn(struct agentx_get *, const char *, ...) 124 __attribute__((__format__ (printf, 2, 3))); 125 void agentx_log_axg_debug(struct agentx_get *, const char *, ...) 126 __attribute__((__format__ (printf, 2, 3))); 127