2 * SPDX-License-Identifier: (BSD-2-Clause AND Beerware)
4 * Copyright (c) 2005-2006 The FreeBSD Project
7 * Author: Victor Cruceru <soc-victor@freebsd.org>
9 * Redistribution of this software and documentation and use in source and
10 * binary forms, with or without modification, are permitted provided that
11 * the following conditions are met:
13 * 1. Redistributions of source code or documentation must retain the above
14 * copyright notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * This C file contains code developed by Poul-Henning Kamp under the
34 * FreeBSD: src/sbin/mdconfig/mdconfig.c,v 1.33.2.1 2004/09/14 03:32:21 jmg Exp
35 * ----------------------------------------------------------------------------
36 * "THE BEER-WARE LICENSE" (Revision 42):
37 * <phk@FreeBSD.ORG> wrote this file. As long as you retain this notice you
38 * can do whatever you want with this stuff. If we meet some day, and you think
39 * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
40 * ----------------------------------------------------------------------------
46 * Host Resources MIB implementation for bsnmpd.
55 #include "hostres_snmp.h"
56 #include "hostres_oid.h"
57 #include "hostres_tree.h"
59 /* Internal id got after we'll register this module with the agent */
60 static u_int host_registration_id = 0;
62 /* This our hostres module */
63 static struct lmodule *hostres_module;
65 /* See the generated file hostres_oid.h */
66 static const struct asn_oid oid_host = OIDX_host;
68 /* descriptor to access kernel memory */
72 * HOST RESOURCES mib module finalization hook.
73 * Returns 0 on success, < 0 on error
80 (void)kvm_close(hr_kd);
85 fini_disk_storage_tbl();
96 if (host_registration_id > 0)
97 or_unregister(host_registration_id);
104 * HOST RESOURCES mib module initialization hook.
105 * Returns 0 on success, < 0 on error
108 hostres_init(struct lmodule *mod, int argc __unused, char *argv[] __unused)
111 hostres_module = mod;
114 * NOTE: order of these calls is important here!
116 if ((hr_kd = kvm_open(NULL, _PATH_DEVNULL, NULL, O_RDONLY,
117 "kvm_open")) == NULL) {
118 syslog(LOG_ERR, "kvm_open failed: %m ");
123 * The order is relevant here, because some table depend on each other.
127 /* populates partition table too */
128 if (init_disk_storage_tbl()) {
132 init_processor_tbl();
136 * populate storage and FS tables. Must be done after device
137 * initialisation because the FS refresh code calls into the
138 * partition refresh code.
143 /* also the hrSWRunPerfTable's support is initialized here */
153 * HOST RESOURCES mib module start operation
160 host_registration_id = or_register(&oid_host,
161 "The MIB module for Host Resource MIB (RFC 2790).",
164 start_device_tbl(hostres_module);
165 start_processor_tbl(hostres_module);
171 /* this identifies the HOST RESOURCES mib module */
172 const struct snmp_module config = {
173 "This module implements the host resource mib (rfc 2790)",
176 NULL, /* idle function, do not use it */
180 NULL, /* proxy a PDU */
181 hostres_ctree, /* see the generated hostres_tree.h */
182 hostres_CTREE_SIZE, /* see the generated hostres_tree.h */
187 * Make an SNMP DateAndTime from a struct tm. This should be in the library.
190 make_date_time(u_char *str, const struct tm *tm, u_int decisecs)
193 str[0] = (u_char)((tm->tm_year + 1900) >> 8);
194 str[1] = (u_char)(tm->tm_year + 1900);
195 str[2] = tm->tm_mon + 1;
196 str[3] = tm->tm_mday;
197 str[4] = tm->tm_hour;
201 if (tm->tm_gmtoff < 0)
206 str[9] = (u_char)(labs(tm->tm_gmtoff) / 3600);
207 str[10] = (u_char)((labs(tm->tm_gmtoff) % 3600) / 60);