1 /* $OpenBSD: agentx_internal.h,v 1.2 2020/10/26 16:02:16 tb 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 struct ax *ax_ax; 42 TAILQ_HEAD(, agentx_session) ax_sessions; 43 TAILQ_HEAD(, agentx_get) ax_getreqs; 44 RB_HEAD(ax_requests, agentx_request) ax_requests; 45 }; 46 47 struct agentx_session { 48 struct agentx *axs_ax; 49 uint32_t axs_id; 50 uint32_t axs_timeout; 51 struct ax_oid axs_oid; 52 struct ax_ostring axs_descr; 53 enum agentx_cstate axs_cstate; 54 enum agentx_dstate axs_dstate; 55 uint32_t axs_packetid; 56 TAILQ_HEAD(, agentx_context) axs_contexts; 57 TAILQ_ENTRY(agentx_session) axs_ax_sessions; 58 }; 59 60 struct agentx_context { 61 struct agentx_session *axc_axs; 62 int axc_name_default; 63 struct ax_ostring axc_name; 64 uint32_t axc_sysuptime; 65 struct timespec axc_sysuptimespec; 66 enum agentx_cstate axc_cstate; 67 enum agentx_dstate axc_dstate; 68 TAILQ_HEAD(, agentx_agentcaps) axc_agentcaps; 69 TAILQ_HEAD(, agentx_region) axc_regions; 70 RB_HEAD(axc_objects, agentx_object) axc_objects; 71 TAILQ_ENTRY(agentx_context) axc_axs_contexts; 72 }; 73 74 struct agentx_get { 75 struct agentx_context *axg_axc; 76 int axg_fd; /* Only used for logging */ 77 uint32_t axg_sessionid; 78 uint32_t axg_transactionid; 79 uint32_t axg_packetid; 80 int axg_context_default; 81 struct ax_ostring axg_context; 82 enum ax_pdu_type axg_type; 83 uint16_t axg_nonrep; 84 uint16_t axg_maxrep; 85 size_t axg_nvarbind; 86 struct agentx_varbind *axg_varbind; 87 TAILQ_ENTRY(agentx_get) axg_ax_getreqs; 88 }; 89 90 __dead void agentx_log_ax_fatalx(struct agentx *, const char *, ...) 91 __attribute__((__format__ (printf, 2, 3))); 92 void agentx_log_ax_warn(struct agentx *, const char *, ...) 93 __attribute__((__format__ (printf, 2, 3))); 94 void agentx_log_ax_warnx(struct agentx *, const char *, ...) 95 __attribute__((__format__ (printf, 2, 3))); 96 void agentx_log_ax_info(struct agentx *, const char *, ...) 97 __attribute__((__format__ (printf, 2, 3))); 98 void agentx_log_ax_debug(struct agentx *, const char *, ...) 99 __attribute__((__format__ (printf, 2, 3))); 100 __dead void agentx_log_axs_fatalx(struct agentx_session *, const char *, 101 ...) __attribute__((__format__ (printf, 2, 3))); 102 void agentx_log_axs_warnx(struct agentx_session *, const char *, ...) 103 __attribute__((__format__ (printf, 2, 3))); 104 void agentx_log_axs_warn(struct agentx_session *, const char *, ...) 105 __attribute__((__format__ (printf, 2, 3))); 106 void agentx_log_axs_info(struct agentx_session *, const char *, ...) 107 __attribute__((__format__ (printf, 2, 3))); 108 __dead void agentx_log_axc_fatalx(struct agentx_context *, const char *, 109 ...) __attribute__((__format__ (printf, 2, 3))); 110 void agentx_log_axc_warnx(struct agentx_context *, const char *, ...) 111 __attribute__((__format__ (printf, 2, 3))); 112 void agentx_log_axc_warn(struct agentx_context *, const char *, ...) 113 __attribute__((__format__ (printf, 2, 3))); 114 void agentx_log_axc_info(struct agentx_context *, const char *, ...) 115 __attribute__((__format__ (printf, 2, 3))); 116 void agentx_log_axc_debug(struct agentx_context *, const char *, ...) 117 __attribute__((__format__ (printf, 2, 3))); 118 __dead void agentx_log_axg_fatalx(struct agentx_get *, const char *, 119 ...) __attribute__((__format__ (printf, 2, 3))); 120 void agentx_log_axg_warnx(struct agentx_get *, const char *, ...) 121 __attribute__((__format__ (printf, 2, 3))); 122 void agentx_log_axg_warn(struct agentx_get *, const char *, ...) 123 __attribute__((__format__ (printf, 2, 3))); 124 void agentx_log_axg_debug(struct agentx_get *, const char *, ...) 125 __attribute__((__format__ (printf, 2, 3))); 126