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.
53 #include "hostres_snmp.h"
54 #include "hostres_oid.h"
55 #include "hostres_tree.h"
57 /* Internal id got after we'll register this module with the agent */
58 static u_int host_registration_id = 0;
60 /* This our hostres module */
61 static struct lmodule *hostres_module;
63 /* See the generated file hostres_oid.h */
64 static const struct asn_oid oid_host = OIDX_host;
66 /* descriptor to access kernel memory */
70 * HOST RESOURCES mib module finalization hook.
71 * Returns 0 on success, < 0 on error
78 (void)kvm_close(hr_kd);
83 fini_disk_storage_tbl();
94 if (host_registration_id > 0)
95 or_unregister(host_registration_id);
102 * HOST RESOURCES mib module initialization hook.
103 * Returns 0 on success, < 0 on error
106 hostres_init(struct lmodule *mod, int argc __unused, char *argv[] __unused)
109 hostres_module = mod;
112 * NOTE: order of these calls is important here!
114 if ((hr_kd = kvm_open(NULL, _PATH_DEVNULL, NULL, O_RDONLY,
115 "kvm_open")) == NULL) {
116 syslog(LOG_ERR, "kvm_open failed: %m ");
121 * The order is relevant here, because some table depend on each other.
125 /* populates partition table too */
126 if (init_disk_storage_tbl()) {
130 init_processor_tbl();
134 * populate storage and FS tables. Must be done after device
135 * initialisation because the FS refresh code calls into the
136 * partition refresh code.
141 /* also the hrSWRunPerfTable's support is initialized here */
151 * HOST RESOURCES mib module start operation
158 host_registration_id = or_register(&oid_host,
159 "The MIB module for Host Resource MIB (RFC 2790).",
162 start_device_tbl(hostres_module);
163 start_processor_tbl(hostres_module);
169 /* this identifies the HOST RESOURCES mib module */
170 const struct snmp_module config = {
171 "This module implements the host resource mib (rfc 2790)",
174 NULL, /* idle function, do not use it */
178 NULL, /* proxy a PDU */
179 hostres_ctree, /* see the generated hostres_tree.h */
180 hostres_CTREE_SIZE, /* see the generated hostres_tree.h */
185 * Make an SNMP DateAndTime from a struct tm. This should be in the library.
188 make_date_time(u_char *str, const struct tm *tm, u_int decisecs)
191 str[0] = (u_char)((tm->tm_year + 1900) >> 8);
192 str[1] = (u_char)(tm->tm_year + 1900);
193 str[2] = tm->tm_mon + 1;
194 str[3] = tm->tm_mday;
195 str[4] = tm->tm_hour;
199 if (tm->tm_gmtoff < 0)
204 str[9] = (u_char)(abs(tm->tm_gmtoff) / 3600);
205 str[10] = (u_char)((abs(tm->tm_gmtoff) % 3600) / 60);