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