├── .gitignore ├── LICENSE ├── Makefile.am ├── README.md ├── TODO ├── ar-lib ├── conf ├── Makefile.am ├── snmpd.conf.in └── snmpd.in ├── configure.ac ├── doc ├── Makefile.am ├── README.md ├── example-tree ├── message-format.asn1 ├── mib │ ├── BATTERY-MIB.mib │ ├── DNS-RESOLVER-MIB.mib │ ├── DNS-SERVER-MIB.mib │ ├── ENTITY-MIB.mib │ ├── ENTITY-SENSORS-MIB.mib │ ├── HOST-RESOURCES-MIB.mib │ ├── HOST-RESOURCES-TYPES.mib │ ├── IANA-ENTITY-MIB.mib │ ├── IANAifType-MIB.mib │ ├── IF-INVERTED-STACK-MIB.mib │ ├── IF-MIB.mib │ ├── INET-ADDRESS-MIB.mib │ ├── IP-MIB.mib │ ├── IPV6-FLOW-LABEL-MIB.mib │ ├── NETWORK-SERVICES-MIB.mib │ ├── NOTIFICATION-LOG-MIB.mib │ ├── RFC-1155.mib │ ├── RFC-1212.mib │ ├── RFC-1213.mib │ ├── SCTP-MIB.mib │ ├── SNMP-FRAMEWORK-MIB.mib │ ├── SNMP-MPD-MIB.mib │ ├── SNMP-NOTIFICATION-MIB.mib │ ├── SNMP-TARGET-MIB.mib │ ├── SNMP-USER-BASED-SM-MIB.mib │ ├── SNMP-USM-AES-MIB.mib │ ├── SNMP-USM-DH-OBJECTS-MIB.mib │ ├── SNMP-USM-HMAC-SHA2-MIB.mib │ ├── SNMP-VIEW-BASED-ACM-MIB.mib │ ├── SNMPv2-CONF.mib │ ├── SNMPv2-MIB.mib │ ├── SNMPv2-SMI.mib │ ├── SNMPv2-TC.mib │ ├── TCP-MIB.mib │ ├── TUNNEL-MIB.mib │ ├── UCD-SNMP-MIB.mib │ ├── UDP-MIB.mib │ ├── UPS-MIB.mib │ └── UUID-TC-MIB.mib └── snmpd.8.in ├── m4 └── config │ ├── as-ac-expand.m4 │ ├── libtool.m4 │ ├── ltoptions.m4 │ ├── ltsugar.m4 │ ├── ltversion.m4 │ └── lt~obsolete.m4 └── src ├── Makefile.am ├── snmp-agent ├── agent-cache.c ├── agent-cache.h ├── agent-config.c ├── agent-config.h ├── agent-ctl.c ├── agent-ctl.h ├── agent-incoming.c ├── agent-incoming.h ├── agent-notification-builder.c ├── agent-notification-builder.h ├── agent-notification-log.c ├── agent-notification-log.h ├── agent-notification.c ├── agent-notification.h ├── mib-tree.c ├── mib-tree.h ├── snmpd.c └── snmpd.h ├── snmp-core ├── snmp-core.h ├── snmp-crypto.c ├── snmp-crypto.h ├── snmp-date-time.c ├── snmp-date-time.h ├── snmp-pdu.c ├── snmp-pdu.h ├── snmp-types.c ├── snmp-types.h ├── tinyber.c ├── tinyber.h ├── utils.c └── utils.h ├── snmp-mib ├── Makefile.am ├── agent │ ├── Makefile.am │ ├── activator.c │ ├── framework-module.c │ ├── framework-module.h │ ├── mpd-stats-module.c │ ├── mpd-stats-module.h │ ├── notification-log-config-module.c │ ├── notification-log-module.c │ ├── notification-log-stats-module.c │ ├── notification-module.c │ ├── notification-module.h │ ├── snmp-agent-descriptor.c │ ├── snmp-agent-descriptor.h │ ├── snmp-stats-module.c │ ├── snmp-stats-module.h │ ├── snmpv2-module.c │ ├── snmpv2-module.h │ ├── target-module.c │ ├── target-module.h │ ├── ucd-version-module.c │ ├── ucd-version-module.h │ ├── usm-dh-module.c │ ├── usm-dh-module.h │ ├── usm-stats-module.c │ ├── usm-stats-module.h │ ├── usm-users-module.c │ ├── usm-users-module.h │ ├── vacm-access-module.c │ ├── vacm-access-module.h │ ├── vacm-context-module.c │ ├── vacm-context-module.h │ ├── vacm-security-group-module.c │ ├── vacm-security-group-module.h │ ├── vacm-views-module.c │ └── vacm-views-module.h ├── ip │ ├── Makefile.am │ ├── activator.c │ ├── dns-resolver-module.c │ ├── dns-resolver-module.h │ ├── icmp-module.c │ ├── icmp-module.h │ ├── if-cache.c │ ├── if-cache.h │ ├── if-inverted-module.c │ ├── if-inverted-module.h │ ├── if-module.c │ ├── if-module.h │ ├── ifx-module.c │ ├── ifx-module.h │ ├── ip-address-cache.c │ ├── ip-address-cache.h │ ├── ip-cache.c │ ├── ip-cache.h │ ├── ip-module.c │ ├── ip-module.h │ ├── ip-traffic-stats.c │ ├── ip-traffic-stats.h │ ├── ip-traps.c │ ├── ip-traps.h │ ├── sctp-assoc-local-module.c │ ├── sctp-assoc-module.c │ ├── sctp-assoc-remote-module.c │ ├── sctp-hostname-module.c │ ├── sctp-local-port-module.c │ ├── sctp-module.h │ ├── sctp-params-module.c │ ├── sctp-remote-ip-module.c │ ├── sctp-remote-port-module.c │ ├── sctp-remote-prim-ip-module.c │ ├── sctp-stats-module.c │ ├── socket-cache.c │ ├── socket-cache.h │ ├── tcp-module.c │ ├── tcp-module.h │ ├── udp-module.c │ └── udp-module.h ├── java-subagent │ ├── Makefile.am │ ├── activator.c │ ├── java-subagent.c │ └── java-subagent.h ├── mib-module.h ├── mib-utils.c ├── mib-utils.h ├── power │ ├── Makefile.am │ ├── activator.c │ ├── battery-module.c │ ├── battery-module.h │ ├── battery-traps.c │ ├── battery-traps.h │ ├── power-cache.c │ ├── power-cache.h │ ├── ups-alarm-module.c │ ├── ups-battery-module.c │ ├── ups-bypass-module.c │ ├── ups-config-module.c │ ├── ups-control-module.c │ ├── ups-ident-module.c │ ├── ups-input-module.c │ ├── ups-module.h │ ├── ups-output-module.c │ └── ups-test-module.c ├── sensors │ ├── Makefile.am │ ├── activator.c │ ├── entity-sensors-module.c │ ├── entity-sensors-module.h │ ├── sensor-cache.c │ └── sensor-cache.h ├── single-level-module.c ├── single-level-module.h ├── single-table-module.c ├── single-table-module.h └── system │ ├── Makefile.am │ ├── activator.c │ ├── application-module.c │ ├── application-module.h │ ├── cpu-cache.c │ ├── cpu-cache.h │ ├── device-cache.c │ ├── device-cache.h │ ├── hr-device-module.c │ ├── hr-device-module.h │ ├── hr-storage-module.c │ ├── hr-storage-module.h │ ├── hr-sw-installed-module.c │ ├── hr-sw-installed-module.h │ ├── hr-sw-perf-module.c │ ├── hr-sw-perf-module.h │ ├── hr-sw-run-module.c │ ├── hr-sw-run-module.h │ ├── hr-system-module.c │ ├── hr-system-module.h │ ├── mem-cache.c │ ├── mem-cache.h │ ├── proc-cache.c │ ├── proc-cache.h │ ├── storage-cache.c │ ├── storage-cache.h │ ├── system-module.c │ ├── system-module.h │ ├── ucd-load-module.c │ ├── ucd-memory-module.c │ ├── ucd-module.h │ └── ucd-vmstat-module.c └── tests ├── Makefile.am ├── ctl-tests.c ├── event-tests.c ├── java-subagent ├── .classpath ├── .gitignore ├── pom.xml └── src │ └── pm │ └── x25 │ └── osnmpd │ └── test │ ├── LibC.java │ └── TestSubAgent.java └── pdu-tests.c /.gitignore: -------------------------------------------------------------------------------- 1 | .cproject 2 | .settings 3 | .project 4 | Makefile 5 | Makefile.in 6 | aclocal.m4 7 | autom4te.cache 8 | compile 9 | config.guess 10 | config.sub 11 | configure 12 | config.h.in 13 | config.h 14 | stamp-h1 15 | depcomp 16 | install-sh 17 | ltmain.sh 18 | missing 19 | ylwrap 20 | .libs 21 | .deps 22 | config.log 23 | config.status 24 | libtool 25 | .dirstamp 26 | *.l[ao] 27 | *.[ao] 28 | *.exe 29 | y.tab.[ch] 30 | lex.yy.c 31 | *keywords.c 32 | Doxyfile 33 | apidoc/ 34 | *~ 35 | *.orig 36 | *.patch 37 | *.diff 38 | *.tar.bz2 39 | *.tar.gz 40 | .DS_Store 41 | coverage/ 42 | *.gcno 43 | *.gcda 44 | *.gcov 45 | .cproject 46 | .project 47 | .metadata/ 48 | .settings/ 49 | test-driver 50 | Debug/ 51 | src/snmpd 52 | src/tests/pdu-tests 53 | src/tests/event-tests 54 | src/tests/ctl-tests 55 | dh.param 56 | conf/snmpd 57 | conf/snmpd.conf 58 | doc/snmpd.8 59 | TODO.local 60 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (C) 2016 Olivier Verriest 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = src conf doc 2 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | - determine max PDU size dynamically 2 | - don't block on DNS resolving 3 | - do some proper unit testing 4 | - do some fuzzing 5 | - expose file system statistics somehow 6 | - expose wifi statistics somehow 7 | - add ENTITY-MIB 8 | - add TUNNEL-MIB 9 | - add IP-FORWARD-MIB 10 | - add SCTP-MIB 11 | - add NTP-MIB 12 | - add BRIDGE-MIB 13 | - add EtherMIB 14 | - add DNS-SERVER-MIB/DNS-RESOLVER-MIB 15 | - add DHCP-SERVER-MIB 16 | 17 | -------------------------------------------------------------------------------- /conf/Makefile.am: -------------------------------------------------------------------------------- 1 | SUFFIXES = .in 2 | 3 | .in: 4 | @sed \ 5 | -e 's|@SNMP_VERSION[@]|$(agent_version)|g' \ 6 | -e 's|@SNMP_CONF[@]|$(confdir)|g' \ 7 | -e 's|@SNMP_PLUGIN[@]|$(plugindir)|g' \ 8 | -e 's|@SNMP_RUN[@]|$(rundir)|g' \ 9 | -e 's|@SNMP_BIN[@]|$(bindir)|g' \ 10 | -e 's|@SNMP_CACHE[@]|$(cachedir)|g' \ 11 | < $< > $@ 12 | 13 | EXTRA_DIST = \ 14 | snmpd.conf.in \ 15 | snmpd.in 16 | 17 | CLEANFILES = \ 18 | snmpd.conf \ 19 | snmpd 20 | 21 | conf_DATA = ./snmpd.conf 22 | init_ddir = $(sysconfdir)/init.d 23 | init_d_SCRIPTS = ./snmpd 24 | 25 | -------------------------------------------------------------------------------- /conf/snmpd.conf.in: -------------------------------------------------------------------------------- 1 | #---------------------------- 2 | # SNMP agent configuration 3 | #--------------------------- 4 | 5 | agent: 6 | { 7 | uid = "snmp-usr"; 8 | gid = "snmp-grp"; 9 | port = 161; 10 | interfaces = [ "eth0", "eth1", "ppp0" ]; 11 | cache-dir = "@SNMP_CACHE@"; 12 | 13 | trap: 14 | { 15 | enabled = true; 16 | confirmed = false; 17 | user = "READ_ONLY"; 18 | destination = "::1"; 19 | port = 162; 20 | retries = 3; 21 | timeout = 10; 22 | }; 23 | 24 | users = ( 25 | { 26 | slot = "PUBLIC"; 27 | enabled = true; 28 | name = "public"; 29 | security-model = "USM"; 30 | security-level = "noAuthnoPriv"; 31 | }, 32 | { 33 | slot = "READ_ONLY"; 34 | enabled = true; 35 | name = "read-only"; 36 | security-model = "USM"; 37 | security-level = "authPriv"; 38 | auth-password = "hunter2"; 39 | priv-password = "hunter2"; 40 | }, 41 | { 42 | slot = "READ_WRITE"; 43 | enabled = false; 44 | name = "read-write"; 45 | security-model = "USM"; 46 | security-level = "authPriv"; 47 | }, 48 | { 49 | slot = "ADMIN"; 50 | enabled = false; 51 | name = "admin"; 52 | security-model = "USM"; 53 | security-level = "authPriv"; 54 | } 55 | ); 56 | 57 | }; 58 | -------------------------------------------------------------------------------- /conf/snmpd.in: -------------------------------------------------------------------------------- 1 | #!/sbin/openrc-run 2 | # Copyright 1999-2017 Gentoo Foundation 3 | # Distributed under the terms of the GNU General Public License v2 4 | # $Id$ 5 | 6 | name="SNMP agent" 7 | pidfile="@SNMP_RUN@/snmpd.pid" 8 | command="@SNMP_BIN@/snmpd" 9 | command_args="${EXTRA_OPTS}" 10 | start_stop_daemon_args="--pidfile ${pidfile}" 11 | 12 | depend() { 13 | need localmount net 14 | use logger 15 | } 16 | 17 | -------------------------------------------------------------------------------- /doc/Makefile.am: -------------------------------------------------------------------------------- 1 | osnmp_mibs_dir = $(datadir)/snmp/mibs 2 | osnmp_mibs__DATA = $(top_srcdir)/doc/mib/* 3 | 4 | SUFFIXES = .in 5 | 6 | .in: 7 | @sed \ 8 | -e 's|@SNMP_VERSION[@]|$(VERSION)|g' \ 9 | -e 's|@SNMP_CONF[@]|$(confdir)|g' \ 10 | -e 's|@SNMP_PLUGIN[@]|$(plugindir)|g' \ 11 | -e 's|@SNMP_RUN[@]|$(rundir)|g' \ 12 | -e 's|@SNMP_BIN[@]|$(bindir)|g' \ 13 | -e 's|@SNMP_CACHE[@]|$(cachedir)|g' \ 14 | < $< > $@ 15 | 16 | man8_MANS = snmpd.8 17 | 18 | EXTRA_DIST = \ 19 | mib/* \ 20 | snmpd.8.in 21 | 22 | CLEANFILES = \ 23 | snmpd.8 24 | 25 | -------------------------------------------------------------------------------- /doc/mib/IPV6-FLOW-LABEL-MIB.mib: -------------------------------------------------------------------------------- 1 | IPV6-FLOW-LABEL-MIB DEFINITIONS ::= BEGIN 2 | 3 | IMPORTS 4 | 5 | MODULE-IDENTITY, mib-2, Integer32 FROM SNMPv2-SMI 6 | TEXTUAL-CONVENTION FROM SNMPv2-TC; 7 | 8 | ipv6FlowLabelMIB MODULE-IDENTITY 9 | 10 | LAST-UPDATED "200308280000Z" -- 28 August 2003 11 | ORGANIZATION "IETF Operations and Management Area" 12 | CONTACT-INFO "Bert Wijnen (Editor) 13 | Lucent Technologies 14 | Schagen 33 15 | 3461 GL Linschoten 16 | Netherlands 17 | 18 | Phone: +31 348-407-775 19 | EMail: bwijnen@lucent.com 20 | 21 | Send comments to . 22 | " 23 | DESCRIPTION "This MIB module provides commonly used textual 24 | conventions for IPv6 Flow Labels. 25 | 26 | Copyright (C) The Internet Society (2003). This 27 | version of this MIB module is part of RFC 3595, 28 | see the RFC itself for full legal notices. 29 | " 30 | -- Revision History 31 | 32 | REVISION "200308280000Z" -- 28 August 2003 33 | DESCRIPTION "Initial version, published as RFC 3595." 34 | ::= { mib-2 103 } 35 | 36 | IPv6FlowLabel ::= TEXTUAL-CONVENTION 37 | DISPLAY-HINT "d" 38 | STATUS current 39 | DESCRIPTION "The flow identifier or Flow Label in an IPv6 40 | packet header that may be used to discriminate 41 | traffic flows. 42 | " 43 | REFERENCE "Internet Protocol, Version 6 (IPv6) specification, 44 | section 6. RFC 2460. 45 | " 46 | SYNTAX Integer32 (0..1048575) 47 | 48 | IPv6FlowLabelOrAny ::= TEXTUAL-CONVENTION 49 | DISPLAY-HINT "d" 50 | STATUS current 51 | DESCRIPTION "The flow identifier or Flow Label in an IPv6 52 | packet header that may be used to discriminate 53 | traffic flows. The value of -1 is used to 54 | indicate a wildcard, i.e. any value. 55 | " 56 | SYNTAX Integer32 (-1 | 0..1048575) 57 | 58 | END 59 | -------------------------------------------------------------------------------- /doc/mib/RFC-1155.mib: -------------------------------------------------------------------------------- 1 | RFC1155-SMI DEFINITIONS ::= BEGIN 2 | 3 | EXPORTS -- EVERYTHING 4 | internet, directory, mgmt, 5 | experimental, private, enterprises, 6 | OBJECT-TYPE, ObjectName, ObjectSyntax, SimpleSyntax, 7 | ApplicationSyntax, NetworkAddress, IpAddress, 8 | Counter, Gauge, TimeTicks, Opaque; 9 | 10 | -- the path to the root 11 | 12 | internet OBJECT IDENTIFIER ::= { iso org(3) dod(6) 1 } 13 | 14 | directory OBJECT IDENTIFIER ::= { internet 1 } 15 | 16 | mgmt OBJECT IDENTIFIER ::= { internet 2 } 17 | 18 | experimental OBJECT IDENTIFIER ::= { internet 3 } 19 | 20 | private OBJECT IDENTIFIER ::= { internet 4 } 21 | enterprises OBJECT IDENTIFIER ::= { private 1 } 22 | 23 | -- definition of object types 24 | 25 | OBJECT-TYPE MACRO ::= 26 | BEGIN 27 | TYPE NOTATION ::= "SYNTAX" type (TYPE ObjectSyntax) 28 | "ACCESS" Access 29 | "STATUS" Status 30 | VALUE NOTATION ::= value (VALUE ObjectName) 31 | 32 | Access ::= "read-only" 33 | | "read-write" 34 | | "write-only" 35 | | "not-accessible" 36 | Status ::= "mandatory" 37 | | "optional" 38 | | "obsolete" 39 | END 40 | 41 | -- names of objects in the MIB 42 | 43 | ObjectName ::= 44 | OBJECT IDENTIFIER 45 | 46 | -- syntax of objects in the MIB 47 | 48 | ObjectSyntax ::= 49 | CHOICE { 50 | simple 51 | SimpleSyntax, 52 | -- note that simple SEQUENCEs are not directly 53 | -- mentioned here to keep things simple (i.e., 54 | -- prevent mis-use). However, application-wide 55 | -- types which are IMPLICITly encoded simple 56 | -- SEQUENCEs may appear in the following CHOICE 57 | 58 | application-wide 59 | ApplicationSyntax 60 | } 61 | 62 | SimpleSyntax ::= 63 | CHOICE { 64 | number 65 | INTEGER, 66 | string 67 | OCTET STRING, 68 | object 69 | OBJECT IDENTIFIER, 70 | empty 71 | NULL 72 | } 73 | 74 | ApplicationSyntax ::= 75 | CHOICE { 76 | address 77 | NetworkAddress, 78 | counter 79 | Counter, 80 | gauge 81 | Gauge, 82 | ticks 83 | TimeTicks, 84 | arbitrary 85 | Opaque 86 | 87 | -- other application-wide types, as they are 88 | -- defined, will be added here 89 | } 90 | 91 | -- application-wide types 92 | 93 | NetworkAddress ::= 94 | CHOICE { 95 | internet 96 | IpAddress 97 | } 98 | 99 | IpAddress ::= 100 | [APPLICATION 0] -- in network-byte order 101 | IMPLICIT OCTET STRING (SIZE (4)) 102 | 103 | Counter ::= 104 | [APPLICATION 1] 105 | IMPLICIT INTEGER (0..4294967295) 106 | 107 | Gauge ::= 108 | [APPLICATION 2] 109 | IMPLICIT INTEGER (0..4294967295) 110 | 111 | TimeTicks ::= 112 | [APPLICATION 3] 113 | IMPLICIT INTEGER (0..4294967295) 114 | 115 | Opaque ::= 116 | [APPLICATION 4] -- arbitrary ASN.1 value, 117 | IMPLICIT OCTET STRING -- "double-wrapped" 118 | 119 | END 120 | -------------------------------------------------------------------------------- /doc/mib/RFC-1212.mib: -------------------------------------------------------------------------------- 1 | RFC-1212 DEFINITIONS ::= BEGIN 2 | 3 | IMPORTS 4 | ObjectName 5 | FROM RFC1155-SMI; 6 | -- DisplayString 7 | -- FROM RFC1158-MIB; 8 | 9 | OBJECT-TYPE MACRO ::= 10 | BEGIN 11 | TYPE NOTATION ::= 12 | -- must conform to 13 | -- RFC1155's ObjectSyntax 14 | "SYNTAX" type(ObjectSyntax) 15 | "ACCESS" Access 16 | "STATUS" Status 17 | DescrPart 18 | ReferPart 19 | IndexPart 20 | DefValPart 21 | VALUE NOTATION ::= value (VALUE ObjectName) 22 | 23 | Access ::= "read-only" 24 | | "read-write" 25 | | "write-only" 26 | | "not-accessible" 27 | Status ::= "mandatory" 28 | | "optional" 29 | | "obsolete" 30 | | "deprecated" 31 | 32 | DescrPart ::= 33 | "DESCRIPTION" value (description 34 | DisplayString) 35 | | empty 36 | 37 | ReferPart ::= 38 | "REFERENCE" value (reference DisplayString) 39 | | empty 40 | 41 | IndexPart ::= 42 | "INDEX" "{" IndexTypes "}" 43 | | empty 44 | IndexTypes ::= 45 | IndexType | IndexTypes "," IndexType 46 | IndexType ::= 47 | -- if indexobject, use the SYNTAX 48 | -- value of the correspondent 49 | -- OBJECT-TYPE invocation 50 | value (indexobject ObjectName) 51 | -- otherwise use named SMI type 52 | -- must conform to IndexSyntax below 53 | | type (indextype) 54 | 55 | DefValPart ::= 56 | "DEFVAL" "{" value (defvalue ObjectSyntax) 57 | "}" 58 | | empty 59 | 60 | END 61 | 62 | IndexSyntax ::= 63 | CHOICE { 64 | number 65 | INTEGER (0..MAX), 66 | string 67 | OCTET STRING, 68 | object 69 | OBJECT IDENTIFIER, 70 | address 71 | NetworkAddress, 72 | ipAddress 73 | IpAddress 74 | } 75 | 76 | END 77 | -------------------------------------------------------------------------------- /doc/mib/SNMP-USM-AES-MIB.mib: -------------------------------------------------------------------------------- 1 | SNMP-USM-AES-MIB DEFINITIONS ::= BEGIN 2 | IMPORTS 3 | MODULE-IDENTITY, OBJECT-IDENTITY, 4 | snmpModules FROM SNMPv2-SMI -- [RFC2578] 5 | snmpPrivProtocols FROM SNMP-FRAMEWORK-MIB; -- [RFC3411] 6 | 7 | snmpUsmAesMIB MODULE-IDENTITY 8 | LAST-UPDATED "200406140000Z" 9 | ORGANIZATION "IETF" 10 | CONTACT-INFO "Uri Blumenthal 11 | Lucent Technologies / Bell Labs 12 | 67 Whippany Rd. 13 | 14D-318 14 | Whippany, NJ 07981, USA 15 | 973-386-2163 16 | uri@bell-labs.com 17 | 18 | Fabio Maino 19 | Andiamo Systems, Inc. 20 | 375 East Tasman Drive 21 | San Jose, CA 95134, USA 22 | 408-853-7530 23 | fmaino@andiamo.com 24 | 25 | Keith McCloghrie 26 | Cisco Systems, Inc. 27 | 170 West Tasman Drive 28 | San Jose, CA 95134-1706, USA 29 | 30 | 408-526-5260 31 | kzm@cisco.com" 32 | DESCRIPTION "Definitions of Object Identities needed for 33 | the use of AES by SNMP's User-based Security 34 | Model. 35 | 36 | Copyright (C) The Internet Society (2004). 37 | 38 | This version of this MIB module is part of RFC 3826; 39 | see the RFC itself for full legal notices. 40 | Supplementary information may be available on 41 | http://www.ietf.org/copyrights/ianamib.html." 42 | 43 | REVISION "200406140000Z" 44 | DESCRIPTION "Initial version, published as RFC3826" 45 | ::= { snmpModules 20 } 46 | 47 | usmAesCfb128Protocol OBJECT-IDENTITY 48 | STATUS current 49 | DESCRIPTION "The CFB128-AES-128 Privacy Protocol." 50 | REFERENCE "- Specification for the ADVANCED ENCRYPTION 51 | STANDARD. Federal Information Processing 52 | Standard (FIPS) Publication 197. 53 | (November 2001). 54 | 55 | - Dworkin, M., NIST Recommendation for Block 56 | Cipher Modes of Operation, Methods and 57 | Techniques. NIST Special Publication 800-38A 58 | (December 2001). 59 | " 60 | ::= { snmpPrivProtocols 4 } 61 | 62 | END 63 | -------------------------------------------------------------------------------- /doc/mib/UUID-TC-MIB.mib: -------------------------------------------------------------------------------- 1 | UUID-TC-MIB DEFINITIONS ::= BEGIN 2 | 3 | IMPORTS 4 | MODULE-IDENTITY, mib-2 5 | FROM SNMPv2-SMI -- RFC 2578 6 | TEXTUAL-CONVENTION 7 | FROM SNMPv2-TC -- RFC 2579 8 | ; 9 | 10 | uuidTCMIB MODULE-IDENTITY 11 | 12 | 13 | LAST-UPDATED "201304050000Z" -- April 5, 2013 14 | ORGANIZATION "IETF Energy Management Working Group" 15 | CONTACT-INFO "WG Email: eman@ietf.org 16 | Mailing list subscription info: 17 | http://www.ietf.org/mailman/listinfo/eman 18 | 19 | Dan Romascanu 20 | Avaya 21 | Park Atidim, Bldg. #3 22 | Tel Aviv, 61581 23 | Israel 24 | Phone: +972-3-6458414 25 | Email: dromasca@avaya.com 26 | 27 | Juergen Quittek 28 | NEC Europe Ltd. 29 | Network Research Division 30 | Kurfuersten-Anlage 36 31 | Heidelberg 69115 32 | Germany 33 | Phone: +49 6221 4342-115 34 | Email: quittek@neclab.eu 35 | 36 | Mouli Chandramouli 37 | Cisco Systems, Inc. 38 | Sarjapur Outer Ring Road 39 | Bangalore 560103 40 | India 41 | Phone: +91 80 4429 2409 42 | Email: moulchan@cisco.com" 43 | 44 | DESCRIPTION 45 | "This MIB module defines TEXTUAL-CONVENTIONs 46 | representing Universally Unique IDentifiers 47 | (UUIDs). 48 | 49 | Copyright (c) 2013 IETF Trust and the persons 50 | identified as authors of the code. All rights 51 | reserved. 52 | 53 | Redistribution and use in source and binary forms, 54 | with or without modification, is permitted 55 | pursuant to, and subject to the license terms 56 | contained in, the Simplified BSD License set forth 57 | in Section 4.c of the IETF Trust's Legal 58 | Provisions Relating to IETF Documents 59 | (http://trustee.ietf.org/license-info)." 60 | 61 | 62 | 63 | REVISION "201304050000Z" -- April 5, 2013 64 | DESCRIPTION "Initial version of this MIB as published in 65 | RFC 6933." 66 | 67 | ::= { mib-2 217 } 68 | 69 | -- Textual Conventions 70 | 71 | UUID ::= TEXTUAL-CONVENTION 72 | DISPLAY-HINT "4x-2x-2x-1x1x-6x" 73 | STATUS current 74 | DESCRIPTION 75 | "Universally Unique Identifier information. The syntax must 76 | conform to RFC 4122, Section 4.1." 77 | 78 | SYNTAX OCTET STRING (SIZE (16)) 79 | 80 | UUIDorZero ::= TEXTUAL-CONVENTION 81 | DISPLAY-HINT "4x-2x-2x-1x1x-6x" 82 | STATUS current 83 | DESCRIPTION 84 | "Universally Unique Identifier information. The syntax must 85 | conform to RFC 4122, Section 4.1. 86 | 87 | The semantics of the value zero-length OCTET STRING are 88 | object-specific and must therefore be defined as part of 89 | the description of any object that uses this syntax." 90 | 91 | SYNTAX OCTET STRING (SIZE (0|16)) 92 | 93 | END 94 | -------------------------------------------------------------------------------- /doc/snmpd.8.in: -------------------------------------------------------------------------------- 1 | .TH OSNMPD 8 "February 22, 2016" "Version @SNMP_VERSION@" "osnmpd manual" 2 | 3 | .SH NAME 4 | osnmpd - SNMPv3 daemon responding on incoming SNMP requests. 5 | 6 | .SH SYNOPSIS 7 | .B osnmpd 8 | .RI [ options ] 9 | 10 | .SH DESCRIPTION 11 | .BI osnmpd 12 | is a minimal SNMP agent implementation, to be used for basic system monitoring. The agent process binds on a predefined UDP port and listens for incoming requests. In addition to that, unsolicited trap/inform events can be dispatched from any process within the system to a predefined monitoring process. Only a minimal set of MIB attributes are present by default; additional attributes can be exported through means of shared objects. 13 | 14 | .SH OPTIONS 15 | .TP 16 | .B \-c\fR 17 | Use configuration file at the specified location instead of the default file. 18 | .TP 19 | .B \-d 20 | Enable debug logging. 21 | .TP 22 | .B \-f 23 | Run the server in the foreground (i.e. do not daemonize). 24 | .TP 25 | .B \-p\fR 26 | Load MIB plugins from the specified directory instead of the default location. 27 | .TP 28 | .B \-q 29 | This suppresses non-essential logging. 30 | .TP 31 | .B \-v 32 | This prints the name and version of the application. 33 | 34 | .SH FILES 35 | .PP 36 | @SNMP_CONF@/snmpd.conf 37 | .RS 4 38 | The default configuration file\&. 39 | .RE 40 | .PP 41 | @SNMP_PLUGIN@ 42 | .RS 4 43 | The default location for MIB modules\&. 44 | .RE 45 | .PP 46 | @SNMP_RUN@/osnmpd-ctl 47 | .RS 4 48 | Path to the control socket\&. 49 | .RE 50 | 51 | .SH SEE ALSO 52 | .PP 53 | RFC 3411, 54 | RFC 3412, 55 | RFC 3413, 56 | RFC 3414 57 | 58 | .SH AUTHOR 59 | .PP 60 | \fBosnmpd\fR was written by Olivier Verriest . Bug reports or other contributions are welcome\&. 61 | -------------------------------------------------------------------------------- /m4/config/as-ac-expand.m4: -------------------------------------------------------------------------------- 1 | dnl as-ac-expand.m4 0.2.1 2 | dnl autostars m4 macro for expanding directories using configure's prefix 3 | dnl thomas@apestaart.org 4 | 5 | dnl AS_AC_EXPAND(VAR, CONFIGURE_VAR) 6 | dnl example 7 | dnl AS_AC_EXPAND(SYSCONFDIR, $sysconfdir) 8 | dnl will set SYSCONFDIR to /usr/local/etc if prefix=/usr/local 9 | dnl Note: when using $prefix or $exec_prefix, avoid it expanding to NONE 10 | dnl by calling it like this: 11 | dnl AS_AC_EXPAND(PYTHONLIBDIR, "\${exec_prefix}/lib/python$PYVER/site-packages") 12 | 13 | AC_DEFUN([AS_AC_EXPAND], 14 | [ 15 | EXP_VAR=[$1] 16 | FROM_VAR=[$2] 17 | 18 | dnl echo DEBUG: expand FROM_VAR $FROM_VAR 19 | 20 | dnl first expand prefix and exec_prefix if necessary 21 | prefix_save=$prefix 22 | exec_prefix_save=$exec_prefix 23 | 24 | dnl if no prefix given, then use /usr/local, the default prefix 25 | if test "x$prefix" = "xNONE"; then 26 | prefix="$ac_default_prefix" 27 | fi 28 | dnl if no exec_prefix given, then use prefix 29 | if test "x$exec_prefix" = "xNONE"; then 30 | exec_prefix=$prefix 31 | fi 32 | 33 | full_var="$FROM_VAR" 34 | dnl loop until it doesn't change anymore 35 | while true; do 36 | dnl echo DEBUG: full_var: $full_var 37 | new_full_var="`eval echo $full_var`" 38 | if test "x$new_full_var" = "x$full_var"; then break; fi 39 | full_var=$new_full_var 40 | done 41 | 42 | dnl clean up 43 | full_var=$new_full_var 44 | AC_SUBST([$1], "$full_var") 45 | 46 | dnl restore prefix and exec_prefix 47 | prefix=$prefix_save 48 | exec_prefix=$exec_prefix_save 49 | ]) 50 | -------------------------------------------------------------------------------- /m4/config/ltversion.m4: -------------------------------------------------------------------------------- 1 | # ltversion.m4 -- version numbers -*- Autoconf -*- 2 | # 3 | # Copyright (C) 2004, 2011-2015 Free Software Foundation, Inc. 4 | # Written by Scott James Remnant, 2004 5 | # 6 | # This file is free software; the Free Software Foundation gives 7 | # unlimited permission to copy and/or distribute it, with or without 8 | # modifications, as long as this notice is preserved. 9 | 10 | # @configure_input@ 11 | 12 | # serial 4179 ltversion.m4 13 | # This file is part of GNU Libtool 14 | 15 | m4_define([LT_PACKAGE_VERSION], [2.4.6]) 16 | m4_define([LT_PACKAGE_REVISION], [2.4.6]) 17 | 18 | AC_DEFUN([LTVERSION_VERSION], 19 | [macro_version='2.4.6' 20 | macro_revision='2.4.6' 21 | _LT_DECL(, macro_version, 0, [Which release of libtool.m4 was used?]) 22 | _LT_DECL(, macro_revision, 0) 23 | ]) 24 | -------------------------------------------------------------------------------- /src/Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = snmp-mib 2 | 3 | bin_PROGRAMS = snmpd 4 | 5 | snmpd_SOURCES = \ 6 | snmp-core/snmp-core.h snmp-core/snmp-types.c \ 7 | snmp-core/snmp-types.h snmp-core/snmp-crypto.c \ 8 | snmp-core/snmp-crypto.h snmp-core/snmp-pdu.c \ 9 | snmp-core/snmp-pdu.h snmp-core/snmp-date-time.h \ 10 | snmp-core/snmp-date-time.c snmp-core/tinyber.c \ 11 | snmp-core/tinyber.h snmp-core/utils.c snmp-core/utils.h \ 12 | snmp-agent/agent-cache.c snmp-agent/agent-cache.h \ 13 | snmp-agent/agent-config.c snmp-agent/agent-config.h \ 14 | snmp-agent/agent-ctl.c snmp-agent/agent-ctl.h \ 15 | snmp-agent/agent-incoming.c snmp-agent/agent-incoming.h \ 16 | snmp-agent/agent-notification-builder.c \ 17 | snmp-agent/agent-notification-builder.h \ 18 | snmp-agent/agent-notification-log.c snmp-agent/agent-notification-log.h \ 19 | snmp-agent/agent-notification.c snmp-agent/agent-notification.h \ 20 | snmp-agent/mib-tree.c snmp-agent/mib-tree.h \ 21 | snmp-agent/snmpd.c snmp-agent/snmpd.h \ 22 | snmp-mib/single-level-module.c snmp-mib/single-level-module.h \ 23 | snmp-mib/single-table-module.c snmp-mib/single-table-module.h \ 24 | snmp-mib/mib-utils.h snmp-mib/mib-utils.c 25 | snmpd_CFLAGS= \ 26 | -fPIC -fvisibility=hidden 27 | snmpd_LDADD = \ 28 | -lrt -lz -lcrypto 29 | #ifdef LINUX 30 | snmpd_LDADD += -ldl 31 | #endif 32 | snmpd_LDFLAGS = \ 33 | -fvisibility=hidden \ 34 | -Wl,-export-dynamic \ 35 | -Wl,--gc-sections 36 | 37 | AM_CPPFLAGS = \ 38 | -I$(top_srcdir)/src \ 39 | -I$(top_srcdir)/src/snmp-core \ 40 | -I$(top_srcdir)/src/snmp-agent \ 41 | -I$(top_srcdir)/src/snmp-mib 42 | 43 | install-exec-hook: 44 | find $(DESTDIR)$(plugindir) -type f -name \*.la -delete 45 | -------------------------------------------------------------------------------- /src/snmp-agent/agent-ctl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #ifndef AGENT_AGENT_CTL_H_ 25 | #define AGENT_AGENT_CTL_H_ 26 | 27 | #include 28 | 29 | /** 30 | * init_ctl_handler - initialize the control channel. 31 | * 32 | * @param poll_descriptor IN/OUT - poll file descriptor on which to register 33 | * for incoming events 34 | * @return 0 on success or -1 on any error 35 | */ 36 | int init_ctl_handler(struct pollfd *poll_descriptor); 37 | 38 | /** 39 | * finish_ctl_handler - finish the control channel. 40 | * 41 | * @return 0 on success or -1 on any error 42 | */ 43 | int finish_ctl_handler(void); 44 | 45 | /** 46 | * handle_ctl_request - handle an incoming control request. 47 | */ 48 | void handle_ctl_request(void); 49 | 50 | #endif /* AGENT_AGENT_CTL_H_ */ 51 | -------------------------------------------------------------------------------- /src/snmp-agent/agent-incoming.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #ifndef SRC_SNMP_AGENT_AGENT_INCOMING_H_ 25 | #define SRC_SNMP_AGENT_AGENT_INCOMING_H_ 26 | 27 | #include 28 | 29 | /** 30 | * init_incoming_handler - initialize the handler for incoming user requests. 31 | * 32 | * @param poll_descriptor IN/OUT - poll file descriptor on which to register 33 | * for incoming events 34 | * @return 0 on success or -1 on any error 35 | */ 36 | int init_incoming_handler(struct pollfd *poll_descriptor); 37 | 38 | /** 39 | * finish_incoming_handler - finish the handler for incoming user requests. 40 | * 41 | * @return 0 on success or -1 on any error 42 | */ 43 | int finish_incoming_handler(void); 44 | 45 | /** 46 | * handle_request - handle an incoming SNMP request. 47 | */ 48 | void handle_request(void); 49 | 50 | /** 51 | * update_incoming_keyset - invalidate the USM keysets currently in use. 52 | */ 53 | __attribute__((visibility("default"))) 54 | void update_incoming_keyset(void); 55 | 56 | #endif /* SRC_SNMP_AGENT_AGENT_INCOMING_H_ */ 57 | -------------------------------------------------------------------------------- /src/snmp-agent/agent-notification-builder.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #ifndef SRC_SNMP_AGENT_AGENT_NOTIFICATION_BUILDER_H_ 25 | #define SRC_SNMP_AGENT_AGENT_NOTIFICATION_BUILDER_H_ 26 | 27 | #include "snmp-core/snmp-pdu.h" 28 | 29 | #define NOTIFICATION_VERSION 0x00 30 | 31 | #define CHECK_TRAP_ENC_RESULT(x,y) do { \ 32 | int retval = (x); \ 33 | if (retval != 0) { \ 34 | syslog(LOG_WARNING, "failed to encode %s. (return code %d)", y, retval); \ 35 | return -1; \ 36 | } \ 37 | } while (0) 38 | 39 | #define CHECK_TRAP_DEC_RESULT(x,y) do { \ 40 | int retval = (x); \ 41 | if (retval != 0) { \ 42 | syslog(LOG_WARNING, "notification decode error: %s. (return code %d)", \ 43 | y, retval); \ 44 | return -1; \ 45 | } \ 46 | } while (0) 47 | 48 | /* notification type */ 49 | typedef struct agent_notification { 50 | 51 | /* trap IDs identifying the notification type */ 52 | uint16_t code_1; 53 | uint16_t code_2; 54 | 55 | /* associated OID */ 56 | const SubOID *oid; 57 | size_t oid_len; 58 | 59 | /* argument handling (NULL if no arguments required) */ 60 | int (*add_arguments)(const struct agent_notification *notification, 61 | buf_t *input_buf, SnmpScopedPDU *output_pdu); 62 | 63 | } agent_notification; 64 | 65 | /** 66 | * init_notification_builder - initialise the notification builder. 67 | * 68 | * @return 0 on success, negative number on failure 69 | */ 70 | int init_notification_builder(void); 71 | 72 | /** 73 | * add_notification_type - add new notification type. 74 | * 75 | * type IN - notification to be added. 76 | * 77 | * @return 0 on success, negative number on failure 78 | */ 79 | __attribute__((visibility("default"))) 80 | int add_notification_type(const agent_notification *type); 81 | 82 | /** 83 | * build_authentication_failure_notification - build new authorization exception 84 | * notification. 85 | * 86 | * @param source IN - source of authorization failure 87 | * @param buf OUT - output buffer for resulting notification 88 | * 89 | * @return returns 0 on success, negative value on failure. 90 | */ 91 | int build_authentication_failure_notification(const char *source, buf_t *buf); 92 | 93 | /** 94 | * build_snmp_notification_scoped_pdu - build new trap/inform PDU from 95 | * received notification. 96 | * 97 | * @param source IN - buffer containing received event 98 | * @param scoped_pdu OUT - resulting PDU 99 | * 100 | * @return returns 0 on success, negative value on failure. 101 | */ 102 | int build_snmp_notification_scoped_pdu(buf_t *source, SnmpScopedPDU *scoped_pdu); 103 | 104 | #endif /* SRC_SNMP_AGENT_AGENT_NOTIFICATION_BUILDER_H_ */ 105 | -------------------------------------------------------------------------------- /src/snmp-agent/agent-notification-log.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #ifndef SRC_SNMP_AGENT_AGENT_NOTIFICATION_LOG_H_ 25 | #define SRC_SNMP_AGENT_AGENT_NOTIFICATION_LOG_H_ 26 | 27 | #include "snmp-agent/agent-notification.h" 28 | #include "snmp-core/snmp-pdu.h" 29 | 30 | typedef struct { 31 | 32 | /* index in log */ 33 | uint32_t index; 34 | 35 | /* time of notification (uptime in seconds, timestamp in millis) */ 36 | uint32_t uptime; 37 | uint64_t timestamp; 38 | 39 | /* trap identifier */ 40 | OID trap_type; 41 | 42 | /* associated variable bindings */ 43 | SnmpVariableBinding vars[MAX_SNMP_VAR_BINDINGS]; 44 | size_t num_of_vars; 45 | 46 | } LoggedTrapEntry; 47 | 48 | /** 49 | * init_trap_log - Opens the trap log. 50 | * 51 | * @return 0 on success, -1 on storage error. 52 | */ 53 | int init_trap_log(void); 54 | 55 | /** 56 | * finish_trap_log - Closes the trap log. 57 | * 58 | * @return 0 on success, -1 on storage error. 59 | */ 60 | int finish_trap_log(void); 61 | 62 | /** 63 | * store_new_log_entry - Stores a new trap to the log. 64 | * 65 | * @param scoped_pdu IN - Scoped PDU of the generated trap. 66 | * 67 | * @return 0 on success, -1 on storage error. 68 | */ 69 | int store_new_log_entry(const SnmpScopedPDU *const scoped_pdu); 70 | 71 | /** 72 | * get_trap_entry - Retrieves the first logged trap matching the given parameters. 73 | * 74 | * @param index IN - Minimum index in log. 75 | * @param var_filter IN - Variable binding type which should be included in the trap. 76 | * @param dst OUT - destination output. 77 | * 78 | * @return 0 on success, -1 when no results were found. 79 | */ 80 | __attribute__((visibility("default"))) 81 | int get_trap_entry(uint32_t index, SMIType var_filter, LoggedTrapEntry *dst); 82 | 83 | /** 84 | * get_num_log_entries - Returns the number of logged traps. 85 | * 86 | * @return amount of logged traps. 87 | */ 88 | __attribute__((visibility("default"))) 89 | uint32_t get_num_log_entries(void); 90 | 91 | /** 92 | * get_max_log_entries - Returns the maximum number of logged traps. 93 | * 94 | * @return Maximum number of logged traps. 95 | */ 96 | __attribute__((visibility("default"))) 97 | uint32_t get_max_log_entries(void); 98 | 99 | /** 100 | * get_num_log_discarded - Returns the number of discarded notifications 101 | * since the last agent restart. 102 | * 103 | * @return amount of discarded notifications since the last agent restart. 104 | */ 105 | __attribute__((visibility("default"))) 106 | uint32_t get_num_log_discarded(void); 107 | 108 | #endif /* SRC_SNMP_AGENT_AGENT_NOTIFICATION_LOG_H_ */ 109 | -------------------------------------------------------------------------------- /src/snmp-agent/agent-notification.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #ifndef SRC_SNMP_AGENT_AGENT_NOTIFICATION_H_ 25 | #define SRC_SNMP_AGENT_AGENT_NOTIFICATION_H_ 26 | 27 | #include 28 | 29 | #define MAX_SNMP_NOTIFICATION_SIZE 1024 30 | 31 | /** 32 | * init_notification_handler - initialise the notification handler. 33 | * 34 | * @param poll_descriptor OUT - poll file descriptor on which to register 35 | * for incoming notifications 36 | * @param timeout OUT - timeout on poll 37 | * @return 0 on success or -1 on any error 38 | */ 39 | int init_notification_handler(struct pollfd *poll_descriptor, int *timeout); 40 | 41 | /** 42 | * finish_notification_handler - finish the notification handler. 43 | * 44 | * @return 0 on success or -1 on any error 45 | */ 46 | int finish_notification_handler(void); 47 | 48 | /** 49 | * handle_incoming_notification - handle an incoming SNMP notification. 50 | */ 51 | void handle_incoming_notification(void); 52 | 53 | /** 54 | * dispatch_auth_failed_notification - dispatch an authentication failure trap. 55 | * 56 | * @param source IN - source of the authentication failure 57 | */ 58 | void dispatch_auth_failed_notification(const char *source); 59 | 60 | /** 61 | * refresh_notification_handler_state - reload the notification handler 62 | * state from config. 63 | * 64 | * @return 0 on success or -1 on any error 65 | */ 66 | __attribute__((visibility("default"))) 67 | int refresh_notification_handler_state(void); 68 | 69 | #endif /* SRC_SNMP_AGENT_AGENT_NOTIFICATION_H_ */ 70 | -------------------------------------------------------------------------------- /src/snmp-agent/snmpd.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #ifndef SRC_SNMPD_H_ 25 | #define SRC_SNMPD_H_ 26 | 27 | #define SNMPD_RUN_PATH "/var/run/snmp/" 28 | 29 | /* user profiles available on the agent */ 30 | typedef enum { 31 | USER_PUBLIC = 0, 32 | USER_READ_ONLY = 1, 33 | USER_READ_WRITE = 2, 34 | USER_ADMIN = 3, 35 | NUMBER_OF_USER_SLOTS = 4 36 | } SnmpUserSlot; 37 | 38 | /** 39 | * set_debug_logging - enables/disables the debug logging 40 | * 41 | * @param enabled IN - new debug logging state 42 | */ 43 | __attribute__((visibility("default"))) 44 | void set_debug_logging(int enabled); 45 | 46 | /** 47 | * debug_logging_enabled - returns the debug logging state. 48 | * 49 | * @return 0 when disabled, 1 when enabled. 50 | */ 51 | __attribute__((visibility("default"))) 52 | int debug_logging_enabled(void); 53 | 54 | #endif /* SRC_SNMPD_H_ */ 55 | -------------------------------------------------------------------------------- /src/snmp-core/snmp-core.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #ifndef SRC_SNMP_CORE_SNMP_CORE_H_ 25 | #define SRC_SNMP_CORE_SNMP_CORE_H_ 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include "config.h" 33 | 34 | #endif /* SRC_SNMP_CORE_SNMP_CORE_H_ */ 35 | -------------------------------------------------------------------------------- /src/snmp-core/snmp-date-time.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #ifndef SRC_SNMP_CORE_SNMP_DATE_TIME_H_ 25 | #define SRC_SNMP_CORE_SNMP_DATE_TIME_H_ 26 | 27 | #include 28 | #include "snmp-core/snmp-types.h" 29 | 30 | /* 31 | * SMI encoding of date/time fields according to the textual convention of RFC 2579 32 | * 33 | * DateAndTime ::= TEXTUAL-CONVENTION 34 | * DISPLAY-HINT "2d-1d-1d,1d:1d:1d.1d,1a1d:1d" 35 | * STATUS current 36 | * DESCRIPTION 37 | * "A date-time specification. 38 | * 39 | * field octets contents range 40 | * ----- ------ -------- ----- 41 | * 1 1-2 year* 0..65536 42 | * 2 3 month 1..12 43 | * 3 4 day 1..31 44 | * 4 5 hour 0..23 45 | * 5 6 minutes 0..59 46 | * 6 7 seconds 0..60 47 | * (use 60 for leap-second) 48 | * 7 8 deci-seconds 0..9 49 | * 8 9 direction from UTC '+' / '-' 50 | * 9 10 hours from UTC* 0..13 51 | * 10 11 minutes from UTC 0..59 52 | * 53 | * * Notes: 54 | * - the value of year is in network-byte order 55 | * - daylight saving time in New Zealand is +13 56 | * 57 | * For example, Tuesday May 26, 1992 at 1:30:15 PM EDT would be 58 | * displayed as: 59 | * 60 | * 61 | * Note that if only local time is known, then timezone 62 | * information (fields 8-10) is not present." 63 | * SYNTAX OCTET STRING (SIZE (8 | 11)) 64 | */ 65 | 66 | #define SMI_DATE_AND_TIME_LEN 8 67 | #define SMI_DATE_AND_TIME_LEN_EX 11 68 | 69 | /** 70 | * decode_timestamp - Extracts a millis timestamp from the given variable binding. 71 | * 72 | * @param timestamp OUT - output buffer. 73 | * @param binding IN - input variable binding. 74 | * 75 | * @return 0 on success, -1 on error. 76 | */ 77 | __attribute__((visibility("default"))) 78 | int decode_timestamp(uint64_t *timestamp, SnmpVariableBinding *binding); 79 | 80 | /** 81 | * encode_date_time - Encodes the given millis timestamp to a DateAndTime field. 82 | * 83 | * @param timestamp IN - input timestamp (millis). 84 | * @param binding OUT - output variable binding. 85 | * 86 | * @return 0 on success, -1 on error. 87 | */ 88 | __attribute__((visibility("default"))) 89 | int encode_date_time(uint64_t timestamp, SnmpVariableBinding *binding); 90 | 91 | #endif /* SRC_SNMP_CORE_SNMP_DATE_TIME_H_ */ 92 | -------------------------------------------------------------------------------- /src/snmp-core/tinyber.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Sam Rushing 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not 5 | * use this file except in compliance with the License. You may obtain a copy of 6 | * the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations under 14 | * the License. 15 | */ 16 | 17 | #ifndef _TINYBER_H_ 18 | #define _TINYBER_H_ 19 | 20 | #include 21 | 22 | typedef int64_t asn1int_t; 23 | typedef uint8_t asn1bool_t; 24 | 25 | typedef enum { 26 | FLAG_UNIVERSAL = 0x00, 27 | FLAG_STRUCTURED = 0x20, 28 | FLAG_APPLICATION = 0x40, 29 | FLAG_CONTEXT = 0x80, 30 | } asn1flag; 31 | 32 | typedef enum { 33 | TAG_BOOLEAN = 0x01, 34 | TAG_INTEGER = 0x02, 35 | TAG_BITSTRING = 0x03, 36 | TAG_OCTETSTRING = 0x04, 37 | TAG_NULLTAG = 0x05, 38 | TAG_OID = 0x06, 39 | TAG_ENUMERATED = 0x0A, 40 | TAG_UTF8STRING = 0x0C, 41 | TAG_SEQUENCE = 0x10, 42 | TAG_SET = 0x11, 43 | TAG_SMI_IP_ADDRESS = 0x40, 44 | TAG_SMI_COUNTER32 = 0x41, 45 | TAG_SMI_COUNTER64 = 0x46, 46 | TAG_SMI_GAUGE32 = 0x42, 47 | TAG_SMI_TIME_TICKS = 0x43, 48 | TAG_SMI_OPAQUE = 0x44 49 | } asn1type; 50 | 51 | typedef struct { 52 | uint32_t type; 53 | uint8_t flags; 54 | unsigned int length; 55 | uint8_t * value; 56 | } asn1raw_t; 57 | 58 | typedef struct { 59 | uint8_t * buffer; 60 | unsigned int pos; 61 | unsigned int size; 62 | } buf_t; 63 | 64 | // buffer interface 65 | 66 | static inline void init_obuf (buf_t * self, uint8_t * buffer, unsigned int size) 67 | { 68 | self->buffer = buffer; 69 | self->pos = size; 70 | self->size = size; 71 | } 72 | 73 | static inline void init_ibuf (buf_t * self, uint8_t * buffer, unsigned int size) 74 | { 75 | self->buffer = buffer; 76 | self->pos = 0; 77 | self->size = size; 78 | } 79 | 80 | // decoder 81 | __attribute__((visibility("default"))) 82 | int decode_BOOLEAN (asn1raw_t * src); 83 | __attribute__((visibility("default"))) 84 | asn1int_t decode_INTEGER (asn1raw_t * src); 85 | __attribute__((visibility("default"))) 86 | uint8_t decode_BITSTRING (asn1raw_t * src); 87 | __attribute__((visibility("default"))) 88 | int decode_TLV (asn1raw_t * dst, buf_t * src); 89 | __attribute__((visibility("default"))) 90 | int decode_length (buf_t * src, uint32_t * length); 91 | 92 | // encoder 93 | __attribute__((visibility("default"))) 94 | int encode_TLV (buf_t * o, unsigned int mark, uint32_t tag, uint8_t flags); 95 | __attribute__((visibility("default"))) 96 | int encode_BITSTRING (buf_t * o, const uint8_t * n); 97 | __attribute__((visibility("default"))) 98 | int encode_INTEGER (buf_t * o, const asn1int_t * n, uint32_t tag, uint8_t flags); 99 | __attribute__((visibility("default"))) 100 | int encode_UNSIGNED64 (buf_t *o, uint64_t n, uint32_t tag, uint8_t flags); 101 | __attribute__((visibility("default"))) 102 | int encode_BOOLEAN (buf_t * o, const asn1bool_t * value); 103 | __attribute__((visibility("default"))) 104 | int encode_OCTET_STRING (buf_t * o, const uint8_t * src, int src_len); 105 | __attribute__((visibility("default"))) 106 | int encode_NULL (buf_t * o); 107 | 108 | #define TYB_FAILIF(x) do { if (x) { return -1; } } while(0) 109 | #define TYB_CHECK(x) TYB_FAILIF(-1 == (x)) 110 | 111 | #endif // _TINYBER_H_ 112 | -------------------------------------------------------------------------------- /src/snmp-mib/Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = agent ip java-subagent power sensors system 2 | -------------------------------------------------------------------------------- /src/snmp-mib/agent/Makefile.am: -------------------------------------------------------------------------------- 1 | if ENABLE_MIB_AGENT 2 | 3 | plugin_LTLIBRARIES = libsnmp-mib-agent.la 4 | 5 | libsnmp_mib_agent_la_SOURCES = \ 6 | activator.c framework-module.h framework-module.c \ 7 | mpd-stats-module.h mpd-stats-module.c \ 8 | usm-stats-module.h usm-stats-module.c \ 9 | usm-users-module.h usm-users-module.c \ 10 | usm-dh-module.h usm-dh-module.c \ 11 | snmpv2-module.h snmpv2-module.c \ 12 | snmp-stats-module.h snmp-stats-module.c \ 13 | notification-module.h notification-module.c \ 14 | notification-log-module.c notification-log-config-module.c \ 15 | notification-log-stats-module.c target-module.h target-module.c \ 16 | snmp-agent-descriptor.h snmp-agent-descriptor.c \ 17 | ucd-version-module.h ucd-version-module.c \ 18 | vacm-access-module.h vacm-access-module.c \ 19 | vacm-context-module.h vacm-context-module.c \ 20 | vacm-security-group-module.h vacm-security-group-module.c \ 21 | vacm-views-module.h vacm-views-module.c 22 | libsnmp_mib_agent_la_CFLAGS= \ 23 | -fPIC -fvisibility=hidden 24 | libsnmp_mib_agent_la_LDFLAGS = \ 25 | -no-undefined -avoid-version -shared -fPIC 26 | 27 | AM_CPPFLAGS = \ 28 | -I$(top_srcdir)/src \ 29 | -I$(top_srcdir)/src/snmp-core \ 30 | -I$(top_srcdir)/src/snmp-agent \ 31 | -I$(top_srcdir)/src/snmp-mib 32 | 33 | endif 34 | -------------------------------------------------------------------------------- /src/snmp-mib/agent/activator.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #include "snmp-agent/mib-tree.h" 25 | #include "snmp-mib/agent/framework-module.h" 26 | #include "snmp-mib/agent/mpd-stats-module.h" 27 | #include "snmp-mib/agent/notification-module.h" 28 | #include "snmp-mib/agent/snmp-agent-descriptor.h" 29 | #include "snmp-mib/agent/snmp-stats-module.h" 30 | #include "snmp-mib/agent/snmpv2-module.h" 31 | #include "snmp-mib/agent/target-module.h" 32 | #include "snmp-mib/agent/usm-dh-module.h" 33 | #include "snmp-mib/agent/usm-stats-module.h" 34 | #include "snmp-mib/agent/usm-users-module.h" 35 | #include "snmp-mib/agent/ucd-version-module.h" 36 | #include "snmp-mib/agent/vacm-access-module.h" 37 | #include "snmp-mib/agent/vacm-context-module.h" 38 | #include "snmp-mib/agent/vacm-security-group-module.h" 39 | #include "snmp-mib/agent/vacm-views-module.h" 40 | 41 | __attribute__((constructor)) 42 | static void load_plugin(void) 43 | { 44 | add_module(init_framework_module, "snmpFrameworkMIB"); 45 | add_module(init_mpd_stats_module, "snmpMPDMIB"); 46 | add_module(init_usm_stats_module, "usmStats"); 47 | add_module(init_usm_users_module, "usmUser"); 48 | add_module(init_usm_dh_module, "usmDH"); 49 | add_module(init_snmpv2_set_module, "snmpSet"); 50 | add_module(init_snmp_stats_module, "snmpGroup"); 51 | add_module(init_notification_module, "snmpNotification"); 52 | add_module(init_notification_log_module, "snmpNotificationLog"); 53 | add_module(init_notification_log_config_module, "snmpNotificationLogConfig"); 54 | add_module(init_notification_log_stats_module, "snmpNotificationLogStats"); 55 | add_module(init_target_module, "snmpTarget"); 56 | add_module(init_ucd_version_module, "UCD version"); 57 | add_module(init_vacm_access_module, "vacmAccessTable"); 58 | add_module(init_vacm_context_module, "vacmContextTable"); 59 | add_module(init_vacm_security_group_module, "vacmSecurityToGroupTable"); 60 | add_module(init_vacm_views_module, "vacmMIBViews"); 61 | add_app_module(get_snmp_agent_app_module()); 62 | 63 | #ifdef DEBUG 64 | dump_mib_tree(); 65 | #endif 66 | } 67 | -------------------------------------------------------------------------------- /src/snmp-mib/agent/framework-module.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #ifndef SRC_SNMP_MIB_AGENT_FRAMEWORK_MODULE_H_ 25 | #define SRC_SNMP_MIB_AGENT_FRAMEWORK_MODULE_H_ 26 | 27 | /** 28 | * Engine group of the SNMP-FRAMEWORK-MIB (RFC 3411) at 1.3.6.1.6.3.10.2.1 29 | * 30 | * Contains general SNMP engine parameters. 31 | */ 32 | 33 | /** 34 | * init_framework_module - creates and initialises a new framework module. 35 | * 36 | * @return pointer to new module on success, NULL on error. 37 | */ 38 | MibModule *init_framework_module(void); 39 | 40 | #endif /* SRC_SNMP_MIB_AGENT_FRAMEWORK_MODULE_H_ */ 41 | -------------------------------------------------------------------------------- /src/snmp-mib/agent/mpd-stats-module.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #include 25 | #include 26 | 27 | #include "snmp-agent/agent-cache.h" 28 | #include "snmp-agent/mib-tree.h" 29 | #include "snmp-core/utils.h" 30 | #include "snmp-core/snmp-types.h" 31 | #include "snmp-mib/single-level-module.h" 32 | #include "snmp-mib/agent/mpd-stats-module.h" 33 | 34 | #define MPD_STATS_COMPLIANCE_OID SNMP_OID_MPD_STATS_MIB,3,1,1 35 | 36 | static SysOREntry mib_stats_or_entry = { 37 | .or_id = { 38 | .subid = { MPD_STATS_COMPLIANCE_OID }, 39 | .len = OID_SEQ_LENGTH(MPD_STATS_COMPLIANCE_OID) 40 | }, 41 | .or_descr = "SNMP-MPD-MIB - the MIB for message processing and dispatching", 42 | .next = NULL 43 | }; 44 | 45 | enum MPDStatsMIBObjects { 46 | SNMP_UNKNOWN_SECURITY_MODELS = 1, 47 | SNMP_INVALID_MSGS = 2, 48 | SNMP_UNKNOWN_PDU_HANDLERS = 3 49 | }; 50 | 51 | DEF_METHOD(get_scalar, SnmpErrorStatus, SingleLevelMibModule, 52 | SingleLevelMibModule, int id, SnmpVariableBinding *binding) 53 | { 54 | switch (id) { 55 | case SNMP_UNKNOWN_SECURITY_MODELS: { 56 | SET_UNSIGNED_BIND(binding, get_statistics()->snmp_unknown_security_models); 57 | break; 58 | } 59 | 60 | case SNMP_INVALID_MSGS: { 61 | SET_UNSIGNED_BIND(binding, get_statistics()->snmp_invalid_msgs); 62 | break; 63 | } 64 | 65 | case SNMP_UNKNOWN_PDU_HANDLERS: { 66 | SET_UNSIGNED_BIND(binding, get_statistics()->snmp_unknown_pdu_handlers); 67 | break; 68 | } 69 | } 70 | 71 | return NO_ERROR; 72 | } 73 | 74 | DEF_METHOD(set_scalar, SnmpErrorStatus, SingleLevelMibModule, 75 | SingleLevelMibModule, int id, SnmpVariableBinding *binding, int dry_run) 76 | { 77 | return NOT_WRITABLE; 78 | } 79 | 80 | DEF_METHOD(finish_module, void, MibModule, SingleLevelMibModule) 81 | { 82 | finish_single_level_module(this); 83 | } 84 | 85 | MibModule *init_mpd_stats_module(void) 86 | { 87 | SingleLevelMibModule *module = malloc(sizeof(SingleLevelMibModule)); 88 | if (module == NULL) { 89 | return NULL; 90 | } else if (init_single_level_module(module, SNMP_UNKNOWN_SECURITY_MODELS, 91 | SNMP_UNKNOWN_PDU_HANDLERS - SNMP_UNKNOWN_SECURITY_MODELS + 1, 92 | LEAF_SCALAR, LEAF_SCALAR, LEAF_SCALAR)) { 93 | free(module); 94 | return NULL; 95 | } 96 | 97 | SET_PREFIX(module, SNMP_OID_MPD_STATS_MIB,2,1); 98 | SET_OR_ENTRY(module, &mib_stats_or_entry); 99 | SET_METHOD(module, MibModule, finish_module); 100 | SET_METHOD(module, SingleLevelMibModule, get_scalar); 101 | SET_METHOD(module, SingleLevelMibModule, set_scalar); 102 | return &module->public; 103 | } 104 | 105 | -------------------------------------------------------------------------------- /src/snmp-mib/agent/mpd-stats-module.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #ifndef SRC_SNMP_MIB_AGENT_MPD_STATS_MODULE_H_ 25 | #define SRC_SNMP_MIB_AGENT_MPD_STATS_MODULE_H_ 26 | 27 | #include "snmp-mib/mib-module.h" 28 | 29 | /* 30 | * Message Processing and Dispatching statistics ("snmpMPDStats") 31 | * of the SNMP-MPD-MIB (RFC 3412). 32 | */ 33 | 34 | /** 35 | * init_mpd_stats_module - creates and initialises a new mpd stats module. 36 | * 37 | * @return pointer to new module on success, NULL on error. 38 | */ 39 | MibModule *init_mpd_stats_module(void); 40 | 41 | #endif /* SRC_SNMP_MIB_AGENT_MPD_STATS_MODULE_H_ */ 42 | -------------------------------------------------------------------------------- /src/snmp-mib/agent/notification-module.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #ifndef SRC_SNMP_MIB_AGENT_NOTIFICATION_MODULE_H_ 25 | #define SRC_SNMP_MIB_AGENT_NOTIFICATION_MODULE_H_ 26 | 27 | #include "snmp-mib/mib-module.h" 28 | 29 | /** 30 | * SNMP-NOTIFICATION-MIB (RFC 2573), NOTIFICATION-LOG-MIB (RFC 3014) 31 | * Contains notification related configuration and logging. 32 | */ 33 | 34 | #define NOTIFICATION_LOG_MIB_OID SNMP_OID_MIB2,92 35 | 36 | extern const char *const notification_log_name; 37 | extern const char *const notification_filter_name; 38 | 39 | /** 40 | * init_notification_module - creates and initialises a new notification module. 41 | * 42 | * @return pointer to new module on success, NULL on error. 43 | */ 44 | MibModule *init_notification_module(void); 45 | 46 | /** 47 | * init_notification_log_module - creates and initialises a new 48 | * notification log module. 49 | * 50 | * @return pointer to new module on success, NULL on error. 51 | */ 52 | MibModule *init_notification_log_module(void); 53 | 54 | /** 55 | * init_notification_log_config_module - creates and initialises a new 56 | * notification log configuration module. 57 | * 58 | * @return pointer to new module on success, NULL on error. 59 | */ 60 | MibModule *init_notification_log_config_module(void); 61 | 62 | /** 63 | * init_notification_log_stats_module - creates and initialises a new 64 | * notification log statistics module. 65 | * 66 | * @return pointer to new module on success, NULL on error. 67 | */ 68 | MibModule *init_notification_log_stats_module(void); 69 | 70 | #endif /* SRC_SNMP_MIB_AGENT_NOTIFICATION_MODULE_H_ */ 71 | -------------------------------------------------------------------------------- /src/snmp-mib/agent/snmp-agent-descriptor.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #include "config.h" 25 | #include "snmp-agent/agent-cache.h" 26 | #include "snmp-agent/mib-tree.h" 27 | #include "snmp-mib/agent/snmp-agent-descriptor.h" 28 | 29 | #define AGENT_DESCRIPTION "SNMPv3 agent" 30 | 31 | static char *get_name(void); 32 | static char *get_version(void); 33 | static char *get_description(void); 34 | static ApplicationOperStatus get_oper_state(void); 35 | static uint32_t get_last_inbound(void); 36 | static uint32_t get_last_outbound(void); 37 | static uint32_t get_inbound_assoc(void); 38 | static uint32_t get_acc_inbound_assoc(void); 39 | static uint32_t get_acc_failed_inbound_assoc(void); 40 | static uint32_t get_outbound_assoc(void); 41 | static uint32_t get_acc_outbound_assoc(void); 42 | static uint32_t get_acc_failed_outbound_assoc(void); 43 | 44 | static MibApplicationModule app_module = { 45 | .get_name = get_name, 46 | .get_version = get_version, 47 | .get_description = get_description, 48 | .get_oper_state = get_oper_state, 49 | .get_uptime = get_uptime, 50 | .get_last_change = get_uptime, 51 | .get_last_inbound = get_last_inbound, 52 | .get_last_outbound = get_last_outbound, 53 | .get_inbound_assoc = get_inbound_assoc, 54 | .get_acc_inbound_assoc = get_acc_inbound_assoc, 55 | .get_acc_failed_inbound_assoc = get_acc_failed_inbound_assoc, 56 | .get_outbound_assoc = get_outbound_assoc, 57 | .get_acc_outbound_assoc = get_acc_outbound_assoc, 58 | .get_acc_failed_outbound_assoc = get_acc_failed_outbound_assoc, 59 | .next = NULL 60 | }; 61 | 62 | MibApplicationModule *get_snmp_agent_app_module(void) 63 | { 64 | return &app_module; 65 | } 66 | 67 | static char *get_name(void) 68 | { 69 | return PACKAGE_NAME; 70 | } 71 | 72 | static char *get_version(void) 73 | { 74 | return VERSION; 75 | } 76 | 77 | static char *get_description(void) 78 | { 79 | return AGENT_DESCRIPTION; 80 | } 81 | 82 | static ApplicationOperStatus get_oper_state(void) 83 | { 84 | return NET_APP_UP; 85 | } 86 | 87 | static uint32_t get_last_inbound(void) 88 | { 89 | return 0; 90 | 91 | } 92 | 93 | static uint32_t get_last_outbound(void) 94 | { 95 | return get_statistics()->last_outbound_timestamp; 96 | } 97 | 98 | static uint32_t get_inbound_assoc(void) 99 | { 100 | return 0; 101 | } 102 | 103 | static uint32_t get_acc_inbound_assoc(void) 104 | { 105 | return 0; 106 | } 107 | 108 | static uint32_t get_acc_failed_inbound_assoc(void) 109 | { 110 | return 0; 111 | } 112 | 113 | static uint32_t get_outbound_assoc(void) 114 | { 115 | return 0; 116 | } 117 | 118 | static uint32_t get_acc_outbound_assoc(void) 119 | { 120 | return 0; 121 | } 122 | 123 | static uint32_t get_acc_failed_outbound_assoc(void) 124 | { 125 | return 0; 126 | } 127 | -------------------------------------------------------------------------------- /src/snmp-mib/agent/snmp-agent-descriptor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #ifndef SRC_SNMP_AGENT_AGENT_DESCRIPTOR_H_ 25 | #define SRC_SNMP_AGENT_AGENT_DESCRIPTOR_H_ 26 | 27 | #include "snmp-agent/mib-tree.h" 28 | 29 | /** 30 | * get_snmp_agent_app_module - returns the network application 31 | * module descriptor for the SNMP agent. 32 | * 33 | * @return pointer to the SNMP agent app module 34 | */ 35 | MibApplicationModule *get_snmp_agent_app_module(void); 36 | 37 | #endif /* SRC_SNMP_AGENT_AGENT_DESCRIPTOR_H_ */ 38 | -------------------------------------------------------------------------------- /src/snmp-mib/agent/snmp-stats-module.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #ifndef SRC_SNMP_MIB_AGENT_SNMP_STATS_MODULE_H_ 25 | #define SRC_SNMP_MIB_AGENT_SNMP_STATS_MODULE_H_ 26 | 27 | #include "snmp-mib/mib-module.h" 28 | 29 | /** 30 | * SNMP group of MIB-2 at 1.3.6.1.2.1.11 (RFC 1213) 31 | * 32 | * The SNMP group is mandatory for all systems which support an SNMP protocol entity. 33 | * Some of the objects deinfed below will be zero-valued in those SNMP implementations 34 | * that are optimized to support only those functions specific to either a management 35 | * agent or a management stations. In particular, it should be observed that the objects 36 | * below refer to an SNMP entity, and there may be several SNMP entities residing on a managed node. 37 | */ 38 | 39 | /** 40 | * init_snmp_stats_module - creates and initialises a new SNMP statistics module. 41 | * 42 | * @return pointer to new module on success, NULL on error. 43 | */ 44 | MibModule *init_snmp_stats_module(void); 45 | 46 | #endif /* SRC_SNMP_MIB_AGENT_SNMP_STATS_MODULE_H_ */ 47 | -------------------------------------------------------------------------------- /src/snmp-mib/agent/snmpv2-module.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #include 25 | #include 26 | 27 | #include "snmp-agent/mib-tree.h" 28 | #include "snmp-core/utils.h" 29 | #include "snmp-core/snmp-types.h" 30 | #include "snmp-mib/single-level-module.h" 31 | #include "snmp-mib/agent/snmpv2-module.h" 32 | 33 | enum SNMPv2SetMIBObjects { 34 | SNMP_SET_SERIAL_NO = 1 35 | }; 36 | 37 | DEF_METHOD(get_scalar, SnmpErrorStatus, SingleLevelMibModule, 38 | SingleLevelMibModule, int id, SnmpVariableBinding *binding) 39 | { 40 | SET_INTEGER_BIND(binding, 0); 41 | return NO_ERROR; 42 | } 43 | 44 | DEF_METHOD(set_scalar, SnmpErrorStatus, SingleLevelMibModule, 45 | SingleLevelMibModule, int id, SnmpVariableBinding *binding, int dry_run) 46 | { 47 | return NOT_WRITABLE; 48 | } 49 | 50 | DEF_METHOD(finish_module, void, MibModule, SingleLevelMibModule) 51 | { 52 | finish_single_level_module(this); 53 | } 54 | 55 | MibModule *init_snmpv2_set_module(void) 56 | { 57 | SingleLevelMibModule *module = malloc(sizeof(SingleLevelMibModule)); 58 | if (module == NULL) { 59 | return NULL; 60 | } else if (init_single_level_module(module, SNMP_SET_SERIAL_NO, 1, LEAF_SCALAR)) { 61 | free(module); 62 | return NULL; 63 | } 64 | 65 | SET_PREFIX(module, SNMP_OID_SNMPMODULES,1,1,6); 66 | SET_OR_ENTRY(module, NULL); 67 | SET_METHOD(module, MibModule, finish_module); 68 | SET_METHOD(module, SingleLevelMibModule, get_scalar); 69 | SET_METHOD(module, SingleLevelMibModule, set_scalar); 70 | return &module->public; 71 | } 72 | -------------------------------------------------------------------------------- /src/snmp-mib/agent/snmpv2-module.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #ifndef SRC_SNMP_MIB_AGENT_SNMPV2_MODULE_H_ 25 | #define SRC_SNMP_MIB_AGENT_SNMPV2_MODULE_H_ 26 | 27 | #include "snmp-mib/mib-module.h" 28 | 29 | /* 30 | * SNMPv2-MIB snmpSet (RFC 3418). 31 | */ 32 | 33 | /** 34 | * init_snmpv2_set_module - creates and initialises a new SNMPv2 set module. 35 | * 36 | * @return pointer to new module on success, NULL on error. 37 | */ 38 | MibModule *init_snmpv2_set_module(void); 39 | 40 | #endif /* SRC_SNMP_MIB_AGENT_SNMPV2_MODULE_H_ */ 41 | -------------------------------------------------------------------------------- /src/snmp-mib/agent/target-module.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #ifndef SRC_SNMP_MIB_AGENT_TARGET_MODULE_H_ 25 | #define SRC_SNMP_MIB_AGENT_TARGET_MODULE_H_ 26 | 27 | #include "snmp-mib/mib-module.h" 28 | 29 | /** 30 | * Read-only SNMP-TARGET-MIB module (RFC 2573). 31 | * Contains information on upstream destinations for notifications. 32 | */ 33 | 34 | extern SubOID target_table_idx[]; 35 | extern size_t target_table_idx_len; 36 | 37 | /** 38 | * init_target_module - creates and initialises a new target module. 39 | * 40 | * @return pointer to new module on success, NULL on error. 41 | */ 42 | MibModule *init_target_module(void); 43 | 44 | #endif /* SRC_SNMP_MIB_AGENT_TARGET_MODULE_H_ */ 45 | -------------------------------------------------------------------------------- /src/snmp-mib/agent/ucd-version-module.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #ifndef SRC_SNMP_MIB_SYSTEM_UCD_MODULE_H_ 25 | #define SRC_SNMP_MIB_SYSTEM_UCD_MODULE_H_ 26 | 27 | #include "snmp-mib/mib-module.h" 28 | 29 | /* version group of the ucdavis UCD-SNMP-MIB at .1.3.6.1.4.1.2021.100 */ 30 | #define SNMP_OID_UCD_VERSION SNMP_OID_ENTERPRISES,2021,100 31 | 32 | /** 33 | * init_ucd_version_module - creates and initialises a new UCD version module. 34 | * 35 | * @return pointer to new module on success, NULL on error. 36 | */ 37 | MibModule *init_ucd_version_module(void); 38 | 39 | #endif /* SRC_SNMP_MIB_SYSTEM_UCD_MODULE_H_ */ 40 | -------------------------------------------------------------------------------- /src/snmp-mib/agent/usm-dh-module.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #ifndef SRC_SNMP_MIB_AGENT_USM_DH_MODULE_H_ 25 | #define SRC_SNMP_MIB_AGENT_USM_DH_MODULE_H_ 26 | 27 | #include "snmp-mib/mib-module.h" 28 | 29 | /** 30 | * SNMP-USM-DH-OBJECTS-MIB (RFC 2786) 31 | * Contains objects required for USM key exchange using a Diffie-Hellman 32 | * key exchange. This procedure is common in DOCSIS CM and CMTS equipment. 33 | */ 34 | 35 | /** 36 | * init_usm_dh_module - creates and initialises a new D-H USM module. 37 | * 38 | * @return pointer to new module on success, NULL on error. 39 | */ 40 | MibModule *init_usm_dh_module(void); 41 | 42 | #endif /* SRC_SNMP_MIB_AGENT_USM_DH_MODULE_H_ */ 43 | -------------------------------------------------------------------------------- /src/snmp-mib/agent/usm-stats-module.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #ifndef SRC_SNMP_MIB_AGENT_USM_STATS_MODULE_H_ 25 | #define SRC_SNMP_MIB_AGENT_USM_STATS_MODULE_H_ 26 | 27 | #include "snmp-mib/mib-module.h" 28 | 29 | /* 30 | * USM statistics ("usmStats") of the SNMP-USER-BASED-SM-MIB (RFC 3414). 31 | */ 32 | 33 | /** 34 | * init_usm_stats_module - creates and initialises a new USM stats module. 35 | * 36 | * @return pointer to new module on success, NULL on error. 37 | */ 38 | MibModule *init_usm_stats_module(void); 39 | 40 | #endif /* SRC_SNMP_MIB_AGENT_USM_STATS_MODULE_H_ */ 41 | -------------------------------------------------------------------------------- /src/snmp-mib/agent/usm-users-module.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #ifndef SRC_SNMP_MIB_AGENT_USM_USERS_MODULE_H_ 25 | #define SRC_SNMP_MIB_AGENT_USM_USERS_MODULE_H_ 26 | 27 | #include "snmp-agent/agent-config.h" 28 | #include "snmp-mib/mib-module.h" 29 | 30 | /* 31 | * USM statistics ("usmUser") of the SNMP-USER-BASED-SM-MIB (RFC 3414). 32 | */ 33 | 34 | /** 35 | * get_user_row - returns user belonging to the given row identifier 36 | * 37 | * @row IN - row identifier 38 | * @row_len IN - length of row identifier 39 | * @next_row IN - return row following the given row identifier 40 | * @return row index, or -1 if no match found. 41 | */ 42 | UserConfiguration *get_user_row(SubOID *row, size_t row_len, int next_row); 43 | 44 | /** 45 | * init_usm_users_module - creates and initialises a new USM users module. 46 | * 47 | * @return pointer to new module on success, NULL on error. 48 | */ 49 | MibModule *init_usm_users_module(void); 50 | 51 | #endif /* SRC_SNMP_MIB_AGENT_USM_USERS_MODULE_H_ */ 52 | -------------------------------------------------------------------------------- /src/snmp-mib/agent/vacm-access-module.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #ifndef SRC_SNMP_MIB_AGENT_VACM_ACCESS_MODULE_H_ 25 | #define SRC_SNMP_MIB_AGENT_VACM_ACCESS_MODULE_H_ 26 | 27 | #include "snmp-mib/mib-module.h" 28 | 29 | /* 30 | * Contains information about the access table ("vacmAccessTable"). 31 | * Part of the SNMP-VIEW-BASED-ACM-MIB as described in RFC 3415. 32 | */ 33 | 34 | /** 35 | * init_vacm_access_module - creates and initialises a new VACM access module. 36 | * 37 | * @return pointer to new module on success, NULL on error. 38 | */ 39 | MibModule *init_vacm_access_module(void); 40 | 41 | #endif /* SRC_SNMP_MIB_AGENT_VACM_ACCESS_MODULE_H_ */ 42 | -------------------------------------------------------------------------------- /src/snmp-mib/agent/vacm-context-module.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | #include "config.h" 29 | #include "snmp-agent/mib-tree.h" 30 | #include "snmp-agent/agent-config.h" 31 | #include "snmp-core/utils.h" 32 | #include "snmp-core/snmp-types.h" 33 | #include "snmp-mib/single-table-module.h" 34 | #include "snmp-mib/agent/vacm-context-module.h" 35 | 36 | #define VACM_CONTEXT_TABLE 1 37 | #define VACM_CONTEXT_ENTRY 1 38 | 39 | enum VacmContextTableColumns { 40 | VACM_CONTEXT_NAME = 1 41 | }; 42 | 43 | DEF_METHOD(get_column, SnmpErrorStatus, SingleTableMibModule, SingleTableMibModule, 44 | int column, SubOID *row, size_t row_len, SnmpVariableBinding *binding, int next_row) 45 | { 46 | /* single empty context entry */ 47 | if (next_row && row_len > 0) { 48 | binding->type = SMI_EXCEPT_END_OF_MIB_VIEW; 49 | } else if (!next_row && (row_len != 1 || row[0] != 0)) { 50 | binding->type = SMI_EXCEPT_NO_SUCH_INSTANCE; 51 | } else { 52 | SET_OID(binding->oid, SNMP_OID_VACM, 1, VACM_CONTEXT_TABLE, 53 | VACM_CONTEXT_ENTRY, VACM_CONTEXT_NAME, 0); 54 | SET_OCTET_STRING_BIND(binding, NULL, 0); 55 | } 56 | 57 | return NO_ERROR; 58 | } 59 | 60 | DEF_METHOD(set_column, SnmpErrorStatus, SingleTableMibModule, SingleTableMibModule, 61 | int column, SubOID *index, size_t index_len, SnmpVariableBinding *binding, int dry_run) 62 | { 63 | return NOT_WRITABLE; 64 | } 65 | 66 | DEF_METHOD(finish_module, void, MibModule, SingleTableMibModule) 67 | { 68 | finish_single_table_module(this); 69 | } 70 | 71 | MibModule *init_vacm_context_module(void) 72 | { 73 | SingleTableMibModule *module = malloc(sizeof(SingleTableMibModule)); 74 | if (module == NULL) { 75 | return NULL; 76 | } else if (init_single_table_module(module, VACM_CONTEXT_NAME, VACM_CONTEXT_NAME)) { 77 | free(module); 78 | return NULL; 79 | } 80 | 81 | SET_PREFIX(module, SNMP_OID_VACM, 1, VACM_CONTEXT_TABLE, VACM_CONTEXT_ENTRY); 82 | SET_OR_ENTRY(module, NULL); 83 | SET_METHOD(module, MibModule, finish_module); 84 | SET_METHOD(module, SingleTableMibModule, get_column); 85 | SET_METHOD(module, SingleTableMibModule, set_column); 86 | return &module->public; 87 | } 88 | -------------------------------------------------------------------------------- /src/snmp-mib/agent/vacm-context-module.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #ifndef SRC_SNMP_MIB_AGENT_VACM_CONTEXT_MODULE_H_ 25 | #define SRC_SNMP_MIB_AGENT_VACM_CONTEXT_MODULE_H_ 26 | 27 | #include "snmp-mib/mib-module.h" 28 | 29 | /* 30 | * Contains information about context names ("vacmContextTable"). 31 | * Part of the SNMP-VIEW-BASED-ACM-MIB as described in RFC 3415. 32 | * 33 | * @note Only the default (empty) contextName is in use. 34 | */ 35 | 36 | /** 37 | * init_vacm_context_module - creates and initialises a new VACM context module. 38 | * 39 | * @return pointer to new module on success, NULL on error. 40 | */ 41 | MibModule *init_vacm_context_module(void); 42 | 43 | #endif /* SRC_SNMP_MIB_AGENT_VACM_CONTEXT_MODULE_H_ */ 44 | -------------------------------------------------------------------------------- /src/snmp-mib/agent/vacm-security-group-module.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #ifndef SRC_SNMP_MIB_VACM_SECURITY_GROUP_MODULE_H_ 25 | #define SRC_SNMP_MIB_VACM_SECURITY_GROUP_MODULE_H_ 26 | 27 | #include "snmp-mib/mib-module.h" 28 | 29 | /* 30 | * Contains information about the security name to group mapping 31 | * ("vacmSecurityToGroupTable"). 32 | * Part of the SNMP-VIEW-BASED-ACM-MIB as described in RFC 3415. 33 | */ 34 | 35 | /** 36 | * init_vacm_security_group_module - creates and initialises a new 37 | * VACM security to group module. 38 | * 39 | * @return pointer to new module on success, NULL on error. 40 | */ 41 | MibModule *init_vacm_security_group_module(void); 42 | 43 | #endif /* SRC_SNMP_MIB_VACM_SECURITY_GROUP_MODULE_H_ */ 44 | -------------------------------------------------------------------------------- /src/snmp-mib/agent/vacm-views-module.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #ifndef SRC_SNMP_MIB_AGENT_VACM_VIEWS_MODULE_H_ 25 | #define SRC_SNMP_MIB_AGENT_VACM_VIEWS_MODULE_H_ 26 | 27 | #include "snmp-mib/mib-module.h" 28 | 29 | /* 30 | * Contains information about the VACM views ("vacmMIBViews"). 31 | * Part of the SNMP-VIEW-BASED-ACM-MIB as described in RFC 3415. 32 | */ 33 | 34 | /** 35 | * init_vacm_views_module - creates and initialises a new VACM views module. 36 | * 37 | * @return pointer to new module on success, NULL on error. 38 | */ 39 | MibModule *init_vacm_views_module(void); 40 | 41 | #endif /* SRC_SNMP_MIB_AGENT_VACM_VIEWS_MODULE_H_ */ 42 | -------------------------------------------------------------------------------- /src/snmp-mib/ip/Makefile.am: -------------------------------------------------------------------------------- 1 | if ENABLE_MIB_IP 2 | 3 | plugin_LTLIBRARIES = libsnmp-mib-ip.la 4 | 5 | libsnmp_mib_ip_la_SOURCES = \ 6 | activator.c ip-cache.h ip-cache.c \ 7 | ip-traps.h ip-traps.c ip-module.h ip-module.c \ 8 | icmp-module.h icmp-module.c tcp-module.h tcp-module.c \ 9 | udp-module.h udp-module.c sctp-module.h sctp-assoc-local-module.c \ 10 | sctp-assoc-module.c sctp-assoc-remote-module.c \ 11 | sctp-hostname-module.c sctp-local-port-module.c \ 12 | sctp-params-module.c sctp-remote-ip-module.c \ 13 | sctp-remote-port-module.c sctp-remote-prim-ip-module.c \ 14 | sctp-stats-module.c ip-address-cache.h ip-address-cache.c \ 15 | ip-traffic-stats.h ip-traffic-stats.c \ 16 | if-module.h if-module.c ifx-module.h ifx-module.c \ 17 | if-inverted-module.h if-inverted-module.c \ 18 | if-cache.h if-cache.c socket-cache.h socket-cache.c \ 19 | dns-resolver-module.h dns-resolver-module.c 20 | libsnmp_mib_ip_la_CFLAGS= \ 21 | -fPIC -fvisibility=hidden 22 | libsnmp_mib_ip_la_LDFLAGS = \ 23 | -no-undefined -avoid-version -shared -fPIC 24 | 25 | AM_CPPFLAGS = \ 26 | -I$(top_srcdir)/src \ 27 | -I$(top_srcdir)/src/snmp-core \ 28 | -I$(top_srcdir)/src/snmp-agent \ 29 | -I$(top_srcdir)/src/snmp-mib 30 | 31 | endif 32 | -------------------------------------------------------------------------------- /src/snmp-mib/ip/activator.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #include "snmp-agent/mib-tree.h" 25 | #include "snmp-agent/agent-notification-builder.h" 26 | #include "snmp-mib/ip/if-module.h" 27 | #include "snmp-mib/ip/ifx-module.h" 28 | #include "snmp-mib/ip/if-inverted-module.h" 29 | #include "snmp-mib/ip/ip-cache.h" 30 | #include "snmp-mib/ip/ip-traps.h" 31 | #include "snmp-mib/ip/ip-module.h" 32 | #include "snmp-mib/ip/icmp-module.h" 33 | #include "snmp-mib/ip/tcp-module.h" 34 | #include "snmp-mib/ip/udp-module.h" 35 | #include "snmp-mib/ip/sctp-module.h" 36 | #include "snmp-mib/ip/dns-resolver-module.h" 37 | 38 | __attribute__((constructor)) 39 | static void load_plugin(void) 40 | { 41 | init_ip_statistics(); 42 | 43 | add_notification_type(&trap_link_up); 44 | add_notification_type(&trap_link_down); 45 | 46 | add_module(init_ip_module, "ip"); 47 | add_module(init_icmp_module, "icmp"); 48 | add_module(init_tcp_module, "tcp"); 49 | add_module(init_udp_module, "udp"); 50 | add_module(init_sctp_stats_module, "sctp statistics"); 51 | add_module(init_sctp_params_module, "sctp parameters"); 52 | add_module(init_sctp_assoc_module, "sctp associations"); 53 | add_module(init_sctp_assoc_local_module, "sctp local assoc"); 54 | add_module(init_sctp_assoc_remote_module, "sctp remote assoc"); 55 | add_module(init_sctp_local_port_module, "sctp local port"); 56 | add_module(init_sctp_remote_port_module, "sctp remote port"); 57 | add_module(init_sctp_hostname_module, "sctp hostname"); 58 | add_module(init_sctp_primary_ip_module, "sctp primary ip"); 59 | add_module(init_sctp_remote_ip_module, "sctp remote ip"); 60 | add_module(init_iface_module, "iface"); 61 | add_module(init_ifacex_module, "ifaceX"); 62 | add_module(init_inverted_iface_module, "inverted stack"); 63 | add_module(init_dns_resolver_module, "dns resolve"); 64 | } 65 | -------------------------------------------------------------------------------- /src/snmp-mib/ip/dns-resolver-module.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #ifndef SRC_SNMP_MIB_IP_DNS_RESOLVE_MODULE_H_ 25 | #define SRC_SNMP_MIB_IP_DNS_RESOLVE_MODULE_H_ 26 | 27 | #include "snmp-agent/mib-tree.h" 28 | #include "snmp-mib/mib-module.h" 29 | 30 | /* ICMP group of the IP-MIB at 1.3.6.1.2.1.32 (RFC 1612) */ 31 | #define SNMP_OID_DNS_RESOLVER_CONFIG SNMP_OID_MIB2,32,2,1,1 32 | 33 | /** 34 | * @internal 35 | * init_dns_resolver_module - creates and initialises a new DNS resolver module. 36 | * 37 | * @return pointer to new module on success, NULL on error. 38 | */ 39 | MibModule *init_dns_resolver_module(void); 40 | 41 | #endif /* SRC_SNMP_MIB_IP_DNS_RESOLVE_MODULE_H_ */ 42 | -------------------------------------------------------------------------------- /src/snmp-mib/ip/icmp-module.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #ifndef SRC_SNMP_MIB_IP_ICMP_MODULE_H_ 25 | #define SRC_SNMP_MIB_IP_ICMP_MODULE_H_ 26 | 27 | #include "snmp-agent/mib-tree.h" 28 | #include "snmp-mib/mib-module.h" 29 | 30 | /* ICMP group of the IP-MIB at 1.3.6.1.2.1.5 (RFC 4293) */ 31 | #define SNMP_OID_ICMP SNMP_OID_MIB2,5 32 | 33 | /** 34 | * @internal 35 | * init_icmp_module - creates and initialises a new ICMP module. 36 | * 37 | * @return pointer to new module on success, NULL on error. 38 | */ 39 | MibModule *init_icmp_module(void); 40 | 41 | #endif /* SRC_SNMP_MIB_IP_ICMP_MODULE_H_ */ 42 | -------------------------------------------------------------------------------- /src/snmp-mib/ip/if-inverted-module.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #ifndef SRC_SNMP_MIB_IP_IF_INVERTED_MODULE_H_ 25 | #define SRC_SNMP_MIB_IP_IF_INVERTED_MODULE_H_ 26 | 27 | #include "snmp-agent/mib-tree.h" 28 | #include "snmp-mib/mib-module.h" 29 | 30 | /* IF-INVERTED-STACK-MIB at 1.3.6.1.2.1.77.1 (RFC 2864) */ 31 | #define SNMP_OID_IF_INVERTED SNMP_OID_MIB2,77,1 32 | 33 | /** 34 | * @internal 35 | * init_inverted_iface_module - creates and initialises a new 36 | * inverted interface stack module. 37 | * 38 | * @return pointer to new module on success, NULL on error. 39 | */ 40 | MibModule *init_inverted_iface_module(void); 41 | 42 | #endif /* SRC_SNMP_MIB_IP_IF_INVERTED_MODULE_H_ */ 43 | -------------------------------------------------------------------------------- /src/snmp-mib/ip/if-module.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #ifndef SRC_SNMP_MIB_IP_IF_MODULE_H_ 25 | #define SRC_SNMP_MIB_IP_IF_MODULE_H_ 26 | 27 | #include "snmp-agent/mib-tree.h" 28 | #include "snmp-mib/mib-module.h" 29 | 30 | /* IF-MIB at 1.3.6.1.2.1.2 (RFC 2863) */ 31 | #define SNMP_OID_IF SNMP_OID_MIB2,2 32 | 33 | /** 34 | * @internal 35 | * init_iface_module - creates and initialises a new interface module. 36 | * 37 | * @return pointer to new module on success, NULL on error. 38 | */ 39 | MibModule *init_iface_module(void); 40 | 41 | #endif /* SRC_SNMP_MIB_IP_IF_MODULE_H_ */ 42 | -------------------------------------------------------------------------------- /src/snmp-mib/ip/ifx-module.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #ifndef SRC_SNMP_MIB_IP_IFX_MODULE_H_ 25 | #define SRC_SNMP_MIB_IP_IFX_MODULE_H_ 26 | 27 | #include "snmp-agent/mib-tree.h" 28 | #include "snmp-mib/mib-module.h" 29 | 30 | /* IF-MIB at 1.3.6.1.2.1.31.1 (RFC 2863) */ 31 | #define SNMP_OID_IFX SNMP_OID_MIB2,31,1 32 | 33 | /** 34 | * @internal 35 | * init_ifacex_module - creates and initialises a new interfaceX module. 36 | * 37 | * @return pointer to new module on success, NULL on error. 38 | */ 39 | MibModule *init_ifacex_module(void); 40 | 41 | #endif /* SRC_SNMP_MIB_IP_IFX_MODULE_H_ */ 42 | -------------------------------------------------------------------------------- /src/snmp-mib/ip/ip-cache.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #ifndef SRC_SNMP_MIB_IP_IP_CACHE_H_ 25 | #define SRC_SNMP_MIB_IP_IP_CACHE_H_ 26 | 27 | #define IP_CACHE_UPDATE_INTERVAL 8 28 | 29 | #define MAX_ICMP_TYPES 256 30 | 31 | #define LOWER_HALF(x) (0xffffffff & (x)) 32 | 33 | typedef struct { 34 | uint32_t forwarding; 35 | uint32_t default_ttl; 36 | uint64_t in_octets; 37 | uint64_t out_octets; 38 | uint64_t in_receives; 39 | uint64_t in_hdr_errors; 40 | uint64_t reasm_reqds; 41 | uint64_t reasm_timeout; 42 | uint64_t reasm_oks; 43 | uint64_t reasm_fails; 44 | uint64_t out_frag_oks; 45 | uint64_t out_frag_fails; 46 | uint64_t out_frag_creates; 47 | uint64_t out_requests; 48 | uint64_t out_discards; 49 | uint64_t out_no_routes; 50 | uint64_t out_forw_datagrams; 51 | uint64_t out_transmit; 52 | uint64_t out_routing_discards; 53 | uint64_t in_discards; 54 | uint64_t in_delivers; 55 | uint64_t in_no_routes; 56 | uint64_t in_addr_errors; 57 | uint64_t in_unknown_protos; 58 | uint64_t in_truncated_pkts; 59 | uint64_t in_forw_datagrams; 60 | uint64_t in_mcast_pkts; 61 | uint64_t out_mcast_pkts; 62 | uint64_t in_mcast_octets; 63 | uint64_t out_mcast_octets; 64 | uint64_t in_bcast_pkts; 65 | uint64_t out_bcast_pkts; 66 | } IpGeneralStatistics; 67 | 68 | typedef struct { 69 | uint64_t in_msg; 70 | uint64_t in_err; 71 | uint64_t out_msg; 72 | uint64_t out_err; 73 | } IcmpStatsTableEntry; 74 | 75 | typedef struct { 76 | uint64_t in_pkts; 77 | uint64_t out_pkts; 78 | } IcmpMsgStatsTableEntry; 79 | 80 | typedef struct { 81 | IpGeneralStatistics ip4; 82 | IpGeneralStatistics ip6; 83 | IcmpStatsTableEntry icmp4; 84 | IcmpStatsTableEntry icmp6; 85 | IcmpMsgStatsTableEntry icmp4_msg[MAX_ICMP_TYPES]; 86 | IcmpMsgStatsTableEntry icmp6_msg[MAX_ICMP_TYPES]; 87 | } IpStatistics; 88 | 89 | /** 90 | * @internal 91 | * init_cache - initialise the ip statistics cache 92 | */ 93 | void init_ip_statistics(void); 94 | 95 | /** 96 | * @internal 97 | * finish_ip_statistics - finalise the ip statistics cache 98 | */ 99 | void finish_ip_statistics(void); 100 | 101 | /** 102 | * @internal 103 | * get_ip_statistics - returns the current IP statistics 104 | * 105 | * @return ip statistics, NULL on error 106 | */ 107 | IpStatistics *get_ip_statistics(void); 108 | 109 | #endif /* SRC_SNMP_MIB_IP_IP_CACHE_H_ */ 110 | -------------------------------------------------------------------------------- /src/snmp-mib/ip/ip-module.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #ifndef SRC_SNMP_MIB_IP_IP_MODULE_H_ 25 | #define SRC_SNMP_MIB_IP_IP_MODULE_H_ 26 | 27 | #include "snmp-agent/mib-tree.h" 28 | #include "snmp-mib/mib-module.h" 29 | 30 | /* IP group of the IP-MIB at 1.3.6.1.2.1.4 (RFC 4293) */ 31 | #define SNMP_OID_IP SNMP_OID_MIB2,4 32 | 33 | /** 34 | * @internal 35 | * init_ip_module - creates and initialises a new IP module. 36 | * 37 | * @return pointer to new module on success, NULL on error. 38 | */ 39 | MibModule *init_ip_module(void); 40 | 41 | #endif /* SRC_SNMP_MIB_IP_IP_MODULE_H_ */ 42 | -------------------------------------------------------------------------------- /src/snmp-mib/ip/ip-traffic-stats.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #ifndef SRC_SNMP_MIB_IP_IP_TRAFFIC_STATS_H_ 25 | #define SRC_SNMP_MIB_IP_IP_TRAFFIC_STATS_H_ 26 | 27 | #define SNMP_OID_IP_TRAFFIC_STATS SNMP_OID_IP,31 28 | 29 | /** 30 | * @internal 31 | * init_ip_traffic_stats_module - creates and 32 | * initialises a new IP traffic statistics module. 33 | * 34 | * @return pointer to new module on success, NULL on error. 35 | */ 36 | MibModule *init_ip_traffic_stats_module(void); 37 | 38 | #endif /* SRC_SNMP_MIB_IP_IP_TRAFFIC_STATS_H_ */ 39 | -------------------------------------------------------------------------------- /src/snmp-mib/ip/ip-traps.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #ifndef SRC_SNMP_MIB_IP_IP_TRAPS_H_ 25 | #define SRC_SNMP_MIB_IP_IP_TRAPS_H_ 26 | 27 | #include "snmp-agent/agent-notification-builder.h" 28 | 29 | extern agent_notification trap_link_up; 30 | extern agent_notification trap_link_down; 31 | 32 | #endif /* SRC_SNMP_MIB_IP_IP_TRAPS_H_ */ 33 | -------------------------------------------------------------------------------- /src/snmp-mib/ip/sctp-module.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #ifndef SRC_SNMP_MIB_IP_SCTP_H_ 25 | #define SRC_SNMP_MIB_IP_SCTP_H_ 26 | 27 | /* SCTP-MIB at 1.3.6.1.2.1.104 (RFC 3873) */ 28 | #define SNMP_OID_SCTP SNMP_OID_MIB2,104 29 | #define SNMP_OID_SCTP_OBJECTS SNMP_OID_SCTP,1 30 | 31 | /** 32 | * @internal 33 | * init_sctp_stats_module - creates and initialises 34 | * a new SCTP statistics module. 35 | * 36 | * @return pointer to new module on success, NULL on error. 37 | */ 38 | MibModule *init_sctp_stats_module(void); 39 | 40 | /** 41 | * @internal 42 | * init_sctp_params_module - creates and initialises 43 | * a new SCTP parameters module. 44 | * 45 | * @return pointer to new module on success, NULL on error. 46 | */ 47 | MibModule *init_sctp_params_module(void); 48 | 49 | /** 50 | * @internal 51 | * init_sctp_assoc_module - creates and initialises 52 | * a new association SCTP module. 53 | * 54 | * @return pointer to new module on success, NULL on error. 55 | */ 56 | MibModule *init_sctp_assoc_module(void); 57 | 58 | /** 59 | * @internal 60 | * init_sctp_assoc_local_module - creates and initialises 61 | * a new local association SCTP module. 62 | * 63 | * @return pointer to new module on success, NULL on error. 64 | */ 65 | MibModule *init_sctp_assoc_local_module(void); 66 | 67 | /** 68 | * @internal 69 | * init_sctp_assoc_remote_module - creates and initialises 70 | * a new remote association SCTP module. 71 | * 72 | * @return pointer to new module on success, NULL on error. 73 | */ 74 | MibModule *init_sctp_assoc_remote_module(void); 75 | 76 | /** 77 | * @internal 78 | * init_sctp_local_port_module - creates and initialises 79 | * a new local port SCTP module. 80 | * 81 | * @return pointer to new module on success, NULL on error. 82 | */ 83 | MibModule *init_sctp_local_port_module(void); 84 | 85 | /** 86 | * @internal 87 | * init_sctp_remote_port_module - creates and initialises 88 | * a new remote port SCTP module. 89 | * 90 | * @return pointer to new module on success, NULL on error. 91 | */ 92 | MibModule *init_sctp_remote_port_module(void); 93 | 94 | /** 95 | * @internal 96 | * init_sctp_hostname_module - creates and initialises 97 | * a new hostname SCTP module. 98 | * 99 | * @return pointer to new module on success, NULL on error. 100 | */ 101 | MibModule *init_sctp_hostname_module(void); 102 | 103 | /** 104 | * @internal 105 | * init_sctp_primary_ip_module - creates and initialises 106 | * a new primary IP SCTP module. 107 | * 108 | * @return pointer to new module on success, NULL on error. 109 | */ 110 | MibModule *init_sctp_primary_ip_module(void); 111 | 112 | /** 113 | * @internal 114 | * init_sctp_remote_ip_module - creates and initialises 115 | * a new SCTP remote ip module. 116 | * 117 | * @return pointer to new module on success, NULL on error. 118 | */ 119 | MibModule *init_sctp_remote_ip_module(void); 120 | 121 | #endif /* SRC_SNMP_MIB_IP_SCTP_H_ */ 122 | -------------------------------------------------------------------------------- /src/snmp-mib/ip/tcp-module.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #ifndef SRC_SNMP_MIB_IP_TCP_MODULE_H_ 25 | #define SRC_SNMP_MIB_IP_TCP_MODULE_H_ 26 | 27 | #include "snmp-agent/mib-tree.h" 28 | #include "snmp-mib/mib-module.h" 29 | 30 | /* TCP group of the IP-MIB at 1.3.6.1.2.1.6 (RFC 4022) */ 31 | #define SNMP_OID_TCP SNMP_OID_MIB2,6 32 | 33 | /** 34 | * @internal 35 | * init_tcp_module - creates and initialises a new TCP module. 36 | * 37 | * @return pointer to new module on success, NULL on error. 38 | */ 39 | MibModule *init_tcp_module(void); 40 | 41 | #endif /* SRC_SNMP_MIB_IP_TCP_MODULE_H_ */ 42 | -------------------------------------------------------------------------------- /src/snmp-mib/ip/udp-module.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #ifndef SRC_SNMP_MIB_IP_UDP_MODULE_H_ 25 | #define SRC_SNMP_MIB_IP_UDP_MODULE_H_ 26 | 27 | #include "snmp-agent/mib-tree.h" 28 | #include "snmp-mib/mib-module.h" 29 | 30 | /* UDP group of the IP-MIB at 1.3.6.1.2.1.7 (RFC 8096) */ 31 | #define SNMP_OID_UDP SNMP_OID_MIB2,7 32 | 33 | /** 34 | * @internal 35 | * init_udp_module - creates and initialises a new UDP module. 36 | * 37 | * @return pointer to new module on success, NULL on error. 38 | */ 39 | MibModule *init_udp_module(void); 40 | 41 | #endif /* SRC_SNMP_MIB_IP_UDP_MODULE_H_ */ 42 | -------------------------------------------------------------------------------- /src/snmp-mib/java-subagent/Makefile.am: -------------------------------------------------------------------------------- 1 | if ENABLE_MIB_JAVA_SUBAGENT 2 | 3 | plugin_LTLIBRARIES = libsnmp-mib-java-sub-agent.la 4 | 5 | libsnmp_mib_java_sub_agent_la_SOURCES = \ 6 | activator.c java-subagent.h java-subagent.c 7 | libsnmp_mib_java_sub_agent_la_CFLAGS= \ 8 | -fPIC -fvisibility=hidden 9 | libsnmp_mib_java_sub_agent_la_LDFLAGS = \ 10 | -no-undefined -avoid-version -shared -fPIC 11 | 12 | AM_CPPFLAGS = \ 13 | -I$(top_srcdir)/src \ 14 | -I$(top_srcdir)/src/snmp-core \ 15 | -I$(top_srcdir)/src/snmp-agent \ 16 | -I$(top_srcdir)/src/snmp-mib 17 | 18 | endif 19 | -------------------------------------------------------------------------------- /src/snmp-mib/java-subagent/activator.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #include "snmp-agent/mib-tree.h" 25 | #include "snmp-mib/java-subagent/java-subagent.h" 26 | 27 | __attribute__((constructor)) 28 | static void load_plugin(void) 29 | { 30 | add_module(init_java_subagent_module, "java-sub-agent"); 31 | 32 | #ifdef DEBUG 33 | dump_mib_tree(); 34 | #endif 35 | } 36 | -------------------------------------------------------------------------------- /src/snmp-mib/java-subagent/java-subagent.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #ifndef SRC_SNMP_MIB_JAVA_SUBAGENT_JAVA_SUBAGENT_H_ 25 | #define SRC_SNMP_MIB_JAVA_SUBAGENT_JAVA_SUBAGENT_H_ 26 | 27 | #include "snmp-mib/mib-module.h" 28 | 29 | /** 30 | * Java subagent. Module which delegates requests to java process. 31 | */ 32 | 33 | /** 34 | * @internal 35 | * init_java_subagent_module - creates and initialises 36 | * a new java subagent module. 37 | * 38 | * @return pointer to new module on success, NULL on error. 39 | */ 40 | MibModule *init_java_subagent_module(void); 41 | 42 | #endif /* SRC_SNMP_MIB_JAVA_SUBAGENT_JAVA_SUBAGENT_H_ */ 43 | -------------------------------------------------------------------------------- /src/snmp-mib/mib-module.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #ifndef SRC_MIB_MODULE_MIB_MODULE_H_ 25 | #define SRC_MIB_MODULE_MIB_MODULE_H_ 26 | 27 | #include "snmp-core/snmp-types.h" 28 | 29 | #define SET_PREFIX(module, ...) SET_OID(((MibModule *) module)->prefix, __VA_ARGS__) 30 | #define SET_OR_ENTRY(module, entry) ((MibModule *) module)->or_entry = entry 31 | #define SET_METHOD(module, type, method) ((type *) module)->method = _##method 32 | #define DEF_METHOD(name, ret, super, type, ...) \ 33 | static ret name(union {super *public; type *this;} \ 34 | __attribute__((transparent_union)), ##__VA_ARGS__); \ 35 | static typeof(name) *_##name = (typeof(name)*)name; \ 36 | static ret name(type *this, ##__VA_ARGS__) 37 | 38 | /* sysOR table entry */ 39 | typedef struct SysOREntry { 40 | 41 | /* authoritative identification of a capabilities statement */ 42 | OID or_id; 43 | 44 | /* textual description of the module's capabilities */ 45 | char *or_descr; 46 | 47 | /* next entry in list */ 48 | struct SysOREntry *next; 49 | 50 | } SysOREntry; 51 | 52 | /* Collection of MIB entries grouped under a common OID prefix */ 53 | typedef struct MibModule { 54 | 55 | /* OID prefix and descriptor managed by this module */ 56 | OID prefix; 57 | SysOREntry *or_entry; 58 | 59 | /* SNMP actions on subtree */ 60 | SnmpErrorStatus (*get_var)(struct MibModule *mod, SnmpVariableBinding *binding); 61 | SnmpErrorStatus (*get_next_var)(struct MibModule *mod, SnmpVariableBinding *binding); 62 | SnmpErrorStatus (*set_var)(struct MibModule *mod, 63 | SnmpVariableBinding *binding, int dry_run); 64 | 65 | /* destroy the module */ 66 | void (*finish_module)(struct MibModule *mod); 67 | 68 | } MibModule; 69 | 70 | typedef enum ApplicationOperStatus { 71 | NET_APP_UP = 1, 72 | NET_APP_DOWN = 2, 73 | NET_APP_HALTED = 3, 74 | NET_APP_CONGESTED = 4, 75 | NET_APP_RESTARTING = 5 76 | } ApplicationOperStatus; 77 | 78 | /* Network application registered on the SNMP agent */ 79 | typedef struct MibApplicationModule { 80 | 81 | /* application descriptors */ 82 | char *(*get_name)(void); 83 | char *(*get_version)(void); 84 | char *(*get_description)(void); 85 | 86 | /* application state */ 87 | ApplicationOperStatus (*get_oper_state)(void); 88 | 89 | /* timestamps (relative to system boot, in seconds) */ 90 | uint32_t (*get_uptime)(void); 91 | uint32_t (*get_last_change)(void); 92 | uint32_t (*get_last_inbound)(void); 93 | uint32_t (*get_last_outbound)(void); 94 | 95 | /* counters */ 96 | uint32_t (*get_inbound_assoc)(void); 97 | uint32_t (*get_acc_inbound_assoc)(void); 98 | uint32_t (*get_acc_failed_inbound_assoc)(void); 99 | uint32_t (*get_outbound_assoc)(void); 100 | uint32_t (*get_acc_outbound_assoc)(void); 101 | uint32_t (*get_acc_failed_outbound_assoc)(void); 102 | 103 | /* next entry in list */ 104 | struct MibApplicationModule *next; 105 | 106 | } MibApplicationModule; 107 | 108 | #endif /* SRC_MIB_MODULE_MIB_MODULE_H_ */ 109 | -------------------------------------------------------------------------------- /src/snmp-mib/power/Makefile.am: -------------------------------------------------------------------------------- 1 | if ENABLE_MIB_POWER 2 | 3 | plugin_LTLIBRARIES = libsnmp-mib-power.la 4 | 5 | libsnmp_mib_power_la_SOURCES = \ 6 | activator.c battery-traps.h battery-traps.c battery-module.h \ 7 | battery-module.c ups-module.h ups-ident-module.c ups-battery-module.c \ 8 | ups-input-module.c ups-output-module.c ups-bypass-module.c \ 9 | ups-alarm-module.c ups-test-module.c ups-control-module.c \ 10 | ups-config-module.c power-cache.h power-cache.c 11 | libsnmp_mib_power_la_CFLAGS= \ 12 | -fPIC -fvisibility=hidden 13 | libsnmp_mib_power_la_LDFLAGS = \ 14 | -no-undefined -avoid-version -shared -fPIC 15 | 16 | AM_CPPFLAGS = \ 17 | -I$(top_srcdir)/src \ 18 | -I$(top_srcdir)/src/snmp-core \ 19 | -I$(top_srcdir)/src/snmp-agent \ 20 | -I$(top_srcdir)/src/snmp-mib 21 | 22 | endif 23 | -------------------------------------------------------------------------------- /src/snmp-mib/power/activator.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #include "snmp-agent/mib-tree.h" 25 | #include "snmp-agent/agent-notification-builder.h" 26 | #include "snmp-mib/power/battery-module.h" 27 | #include "snmp-mib/power/battery-traps.h" 28 | #include "snmp-mib/power/ups-module.h" 29 | 30 | __attribute__((constructor)) 31 | static void load_plugin(void) 32 | { 33 | add_notification_type(&battery_low_voltage); 34 | add_notification_type(&battery_replace); 35 | add_notification_type(&battery_charge_start); 36 | add_notification_type(&battery_charge_stop); 37 | 38 | add_module(init_battery_module, "battery"); 39 | add_module(init_ups_ident_module, "UPS ident"); 40 | add_module(init_ups_battery_module, "UPS battery"); 41 | add_module(init_ups_input_module, "UPS input"); 42 | add_module(init_ups_output_module, "UPS output"); 43 | add_module(init_ups_bypass_module, "UPS bypass"); 44 | add_module(init_ups_alarm_module, "UPS alarm"); 45 | add_module(init_ups_test_module, "UPS test"); 46 | add_module(init_ups_control_module, "UPS control"); 47 | add_module(init_ups_config_module, "UPS config"); 48 | } 49 | -------------------------------------------------------------------------------- /src/snmp-mib/power/battery-module.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #ifndef SRC_SNMP_MIB_SYSTEM_BATTERY_MODULE_H_ 25 | #define SRC_SNMP_MIB_SYSTEM_BATTERY_MODULE_H_ 26 | 27 | #include "snmp-agent/mib-tree.h" 28 | #include "snmp-mib/mib-module.h" 29 | 30 | /* objects group of the BATTERY-MIB at 1.3.6.1.2.1.233.1 (RFC 7577) */ 31 | #define SNMP_OID_BATTERY_OBJECTS SNMP_OID_BATTERY_MIB,1 32 | 33 | /** 34 | * @internal 35 | * init_battery_module - creates and initialises a new battery module. 36 | * 37 | * @return pointer to new module on success, NULL on error. 38 | */ 39 | MibModule *init_battery_module(void); 40 | 41 | #endif /* SRC_SNMP_MIB_SYSTEM_BATTERY_MODULE_H_ */ 42 | -------------------------------------------------------------------------------- /src/snmp-mib/power/battery-traps.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #ifndef SRC_SNMP_MIB_POWER_BATTERY_TRAPS_H_ 25 | #define SRC_SNMP_MIB_POWER_BATTERY_TRAPS_H_ 26 | 27 | #include "snmp-agent/agent-notification-builder.h" 28 | 29 | extern agent_notification battery_low_voltage; 30 | extern agent_notification battery_replace; 31 | extern agent_notification battery_charge_start; 32 | extern agent_notification battery_charge_stop; 33 | 34 | #endif /* SRC_SNMP_MIB_POWER_BATTERY_TRAPS_H_ */ 35 | -------------------------------------------------------------------------------- /src/snmp-mib/power/ups-alarm-module.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include "config.h" 33 | #include "snmp-agent/mib-tree.h" 34 | #include "snmp-core/utils.h" 35 | #include "snmp-core/snmp-types.h" 36 | #include "snmp-core/snmp-date-time.h" 37 | #include "snmp-mib/single-level-module.h" 38 | #include "snmp-mib/power/ups-module.h" 39 | #include "snmp-mib/power/power-cache.h" 40 | 41 | enum UPSAlarmsObjects { 42 | UPS_ALARMS_PRESENT = 1 43 | }; 44 | 45 | DEF_METHOD(get_scalar, SnmpErrorStatus, SingleLevelMibModule, 46 | SingleLevelMibModule, int id, SnmpVariableBinding *binding) 47 | { 48 | SET_INTEGER_BIND(binding, 0); 49 | return NO_ERROR; 50 | } 51 | 52 | DEF_METHOD(set_scalar, SnmpErrorStatus, SingleLevelMibModule, 53 | SingleLevelMibModule, int id, SnmpVariableBinding *binding, int dry_run) 54 | { 55 | return NOT_WRITABLE; 56 | } 57 | 58 | DEF_METHOD(finish_module, void, MibModule, SingleLevelMibModule) 59 | { 60 | finish_single_level_module(this); 61 | } 62 | 63 | MibModule *init_ups_alarm_module(void) 64 | { 65 | SingleLevelMibModule *module = malloc(sizeof(SingleLevelMibModule)); 66 | if (module == NULL) { 67 | return NULL; 68 | } else if (init_single_level_module(module, UPS_ALARMS_PRESENT, 1, LEAF_SCALAR)) { 69 | free(module); 70 | return NULL; 71 | } 72 | 73 | SET_PREFIX(module, SNMP_OID_UPS_ALARM_OBJECTS); 74 | SET_OR_ENTRY(module, NULL); 75 | SET_METHOD(module, MibModule, finish_module); 76 | SET_METHOD(module, SingleLevelMibModule, get_scalar); 77 | SET_METHOD(module, SingleLevelMibModule, set_scalar); 78 | return &module->public; 79 | } 80 | -------------------------------------------------------------------------------- /src/snmp-mib/power/ups-control-module.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include "config.h" 33 | #include "snmp-agent/mib-tree.h" 34 | #include "snmp-core/utils.h" 35 | #include "snmp-core/snmp-types.h" 36 | #include "snmp-core/snmp-date-time.h" 37 | #include "snmp-mib/single-level-module.h" 38 | #include "snmp-mib/power/ups-module.h" 39 | #include "snmp-mib/power/power-cache.h" 40 | 41 | enum UPSControlObjects { 42 | UPS_SHUTDOWN_TYPE = 1, 43 | UPS_SHUTDOWN_AFTER_DELAY = 2, 44 | UPS_STARTUP_AFTER_DELAY = 3, 45 | UPS_REBOOT_WITH_DURATION = 4, 46 | UPS_AUTO_RESTART = 5 47 | }; 48 | 49 | DEF_METHOD(get_scalar, SnmpErrorStatus, SingleLevelMibModule, 50 | SingleLevelMibModule, int id, SnmpVariableBinding *binding) 51 | { 52 | UPSEntry *ups = get_ups_info(); 53 | 54 | switch (id) { 55 | case UPS_SHUTDOWN_TYPE: { 56 | SET_INTEGER_BIND(binding, 2); /* system */ 57 | break; 58 | } 59 | 60 | case UPS_SHUTDOWN_AFTER_DELAY: { 61 | SET_INTEGER_BIND(binding, ups == NULL ? 0 : ups->shutdown_delay); 62 | break; 63 | } 64 | 65 | case UPS_STARTUP_AFTER_DELAY: { 66 | SET_INTEGER_BIND(binding, ups == NULL ? 0 : ups->startup_delay); 67 | break; 68 | } 69 | 70 | case UPS_REBOOT_WITH_DURATION: { 71 | SET_INTEGER_BIND(binding, ups == NULL ? 0 : ups->reboot_duration); 72 | break; 73 | } 74 | 75 | case UPS_AUTO_RESTART: { 76 | SET_INTEGER_BIND(binding, ups == NULL ? 0 : ups->auto_restart); 77 | break; 78 | } 79 | } 80 | 81 | return NO_ERROR; 82 | } 83 | 84 | DEF_METHOD(set_scalar, SnmpErrorStatus, SingleLevelMibModule, 85 | SingleLevelMibModule, int id, SnmpVariableBinding *binding, int dry_run) 86 | { 87 | return NOT_WRITABLE; 88 | } 89 | 90 | DEF_METHOD(finish_module, void, MibModule, SingleLevelMibModule) 91 | { 92 | finish_single_level_module(this); 93 | } 94 | 95 | MibModule *init_ups_control_module(void) 96 | { 97 | SingleLevelMibModule *module = malloc(sizeof(SingleLevelMibModule)); 98 | if (module == NULL) { 99 | return NULL; 100 | } else if (init_single_level_module(module, UPS_SHUTDOWN_TYPE, 101 | UPS_AUTO_RESTART - UPS_SHUTDOWN_TYPE + 1, 102 | LEAF_SCALAR, LEAF_SCALAR, LEAF_SCALAR, LEAF_SCALAR, LEAF_SCALAR)) { 103 | free(module); 104 | return NULL; 105 | } 106 | 107 | SET_PREFIX(module, SNMP_OID_UPS_CONTROL_OBJECTS); 108 | SET_OR_ENTRY(module, NULL); 109 | SET_METHOD(module, MibModule, finish_module); 110 | SET_METHOD(module, SingleLevelMibModule, get_scalar); 111 | SET_METHOD(module, SingleLevelMibModule, set_scalar); 112 | return &module->public; 113 | } 114 | -------------------------------------------------------------------------------- /src/snmp-mib/sensors/Makefile.am: -------------------------------------------------------------------------------- 1 | if ENABLE_MIB_SENSORS 2 | 3 | plugin_LTLIBRARIES = libsnmp-mib-sensors.la 4 | 5 | libsnmp_mib_sensors_la_SOURCES = \ 6 | activator.c entity-sensors-module.h entity-sensors-module.c \ 7 | sensor-cache.h sensor-cache.c 8 | libsnmp_mib_sensors_la_CFLAGS= \ 9 | -fPIC -fvisibility=hidden 10 | libsnmp_mib_sensors_la_LDFLAGS = \ 11 | -no-undefined -avoid-version -shared -fPIC -lsensors 12 | 13 | AM_CPPFLAGS = \ 14 | -I$(top_srcdir)/src \ 15 | -I$(top_srcdir)/src/snmp-core \ 16 | -I$(top_srcdir)/src/snmp-agent \ 17 | -I$(top_srcdir)/src/snmp-mib 18 | 19 | endif 20 | -------------------------------------------------------------------------------- /src/snmp-mib/sensors/activator.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #include "snmp-agent/mib-tree.h" 25 | #include "snmp-mib/sensors/entity-sensors-module.h" 26 | 27 | __attribute__((constructor)) 28 | static void load_plugin(void) 29 | { 30 | add_module(init_entity_sensors_module, "entity sensors"); 31 | } 32 | -------------------------------------------------------------------------------- /src/snmp-mib/sensors/entity-sensors-module.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #ifndef SRC_SNMP_MIB_SENSORS_ENTITY_SENSORS_MODULE_H_ 25 | #define SRC_SNMP_MIB_SENSORS_ENTITY_SENSORS_MODULE_H_ 26 | 27 | #include "snmp-agent/mib-tree.h" 28 | #include "snmp-mib/mib-module.h" 29 | 30 | /* objects group of the ENTITY-SENSORS-MIB at 1.3.6.1.2.1.99.1 (RFC 3433) */ 31 | #define SNMP_OID_SENSORS_OBJECTS SNMP_OID_MIB2,99,1 32 | 33 | /** 34 | * @internal 35 | * init_entity_sensors_module - creates and initialises a new sensors module. 36 | * 37 | * @return pointer to new module on success, NULL on error. 38 | */ 39 | MibModule *init_entity_sensors_module(void); 40 | 41 | #endif /* SRC_SNMP_MIB_SENSORS_ENTITY_SENSORS_MODULE_H_ */ 42 | -------------------------------------------------------------------------------- /src/snmp-mib/sensors/sensor-cache.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #ifndef SRC_SNMP_MIB_SENSORS_SENSOR_CACHE_H_ 25 | #define SRC_SNMP_MIB_SENSORS_SENSOR_CACHE_H_ 26 | 27 | #include 28 | 29 | enum EntitySensorDataType { 30 | SENSOR_DATA_TYPE_OTHER = 1, 31 | SENSOR_DATA_TYPE_UNKNOWN = 2, 32 | SENSOR_DATA_TYPE_VOLTS_AC = 3, 33 | SENSOR_DATA_TYPE_VOLTS_DC = 4, 34 | SENSOR_DATA_TYPE_AMPERES = 5, 35 | SENSOR_DATA_TYPE_WATTS = 6, 36 | SENSOR_DATA_TYPE_HERTZ = 7, 37 | SENSOR_DATA_TYPE_CELSIUS = 8, 38 | SENSOR_DATA_TYPE_PERCENT_RH = 9, 39 | SENSOR_DATA_TYPE_RPM = 10, 40 | SENSOR_DATA_TYPE_CMM = 11, 41 | SENSOR_DATA_TYPE_TRUTH_VALUE = 12 42 | }; 43 | 44 | enum EntitySensorStatus { 45 | SENSOR_STATUS_OK = 1, 46 | SENSOR_STATUS_UNAVAILABLE = 2, 47 | SENSOR_STATUS_NON_OPERATIONAL = 3 48 | }; 49 | 50 | typedef struct { 51 | uint32_t entity_index; 52 | uint32_t value; 53 | uint32_t scale; 54 | uint32_t precision; 55 | enum EntitySensorDataType data_type; 56 | enum EntitySensorStatus status; 57 | char description[64]; 58 | } EntitySensor; 59 | 60 | typedef struct { 61 | EntitySensor **list; 62 | size_t len; 63 | } EntitySensorList; 64 | 65 | /** 66 | * @internal 67 | * init_sensor_cache - initialise the sensor cache 68 | * 69 | * @return 0 on success, -1 on error. 70 | */ 71 | int init_sensor_cache(void); 72 | 73 | /** 74 | * @internal 75 | * finish_sensor_cache - finalise the sensor cache 76 | * 77 | * @return 0 on success, -1 on error. 78 | */ 79 | int finish_sensor_cache(void); 80 | 81 | /** 82 | * @internal 83 | * get_sensor_cache - returns list of sensor entries 84 | * 85 | * @return list of sensor entries, or NULL if not available. 86 | */ 87 | EntitySensorList *get_sensor_cache(void); 88 | 89 | /** 90 | * @internal 91 | * update_sensor - update sensor value for given entry. 92 | * 93 | * @param sensor IN/OUT - sensor to be updated. 94 | * 95 | * @return 0 on success, -1 on error. 96 | */ 97 | int update_sensor(EntitySensor *sensor); 98 | 99 | #endif /* SRC_SNMP_MIB_SENSORS_SENSOR_CACHE_H_ */ 100 | -------------------------------------------------------------------------------- /src/snmp-mib/single-table-module.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #ifndef SRC_SNMP_MIB_SINGLE_TABLE_MODULE_H_ 25 | #define SRC_SNMP_MIB_SINGLE_TABLE_MODULE_H_ 26 | 27 | #include "snmp-core/snmp-pdu.h" 28 | #include "snmp-mib/mib-module.h" 29 | 30 | /* MIB group consisting of a single tabular object */ 31 | typedef struct SingleTableMibModule { 32 | 33 | /* public MIB module methods */ 34 | MibModule public; 35 | 36 | /* private variables */ 37 | int col_offset; 38 | int col_limit; 39 | 40 | /** 41 | * @internal 42 | * get_tabular - fetches the value associated with a cell of the tabular object 43 | * 44 | * @param module IN - this pointer 45 | * @param column IN - column to be fetched 46 | * @param row IN - row to be fetched 47 | * @param row_len IN - length of row identifier 48 | * @param dst OUT - destination variable binding 49 | * @param next_row IN - 0 if given row should be returned, 50 | * 1 if row following the given row should be returned; in the latter case, 51 | * this function should update the OID of the dst variable binding. 52 | * 53 | * @return SNMP error code on error, 0 on success 54 | */ 55 | SnmpErrorStatus (*get_column)(struct SingleTableMibModule *mod, int column, 56 | SubOID *row, size_t row_len, SnmpVariableBinding *dst, int next_row); 57 | 58 | /** 59 | * @internal 60 | * set_tabular - updates/creates a value associated with a cell 61 | * of the tabular object 62 | * 63 | * @param module IN - this pointer 64 | * @param column IN - column to be updated 65 | * @param row IN - row to be updated 66 | * @param row_len IN - length of row identifier 67 | * @param src IN - variable binding containing new value 68 | * @param dry_run IN - 0 if set action is to be performed, 69 | * 1 if set should be validated without executing 70 | * 71 | * @return SNMP error code on error, 0 on success 72 | */ 73 | SnmpErrorStatus (*set_column)(struct SingleTableMibModule *mod, int column, 74 | SubOID *row, size_t row_len, SnmpVariableBinding *src, int dry_run); 75 | 76 | } SingleTableMibModule; 77 | 78 | /** 79 | * init_single_table_module - initialise new single-level module. 80 | * 81 | * @param module OUT - module to be initialised 82 | * @param offset IN - column offset 83 | * @param limit IN - column limit 84 | * 85 | * @return 0 on success or -1 on any error 86 | */ 87 | __attribute__((visibility("default"))) 88 | int init_single_table_module(SingleTableMibModule *module, int offset, int limit); 89 | 90 | /** 91 | * finish_single_table_module - finalise a single-level module. 92 | * 93 | * @param module IN - module to be finalised 94 | */ 95 | __attribute__((visibility("default"))) 96 | void finish_single_table_module(SingleTableMibModule *module); 97 | 98 | #endif /* SRC_SNMP_MIB_SINGLE_TABLE_MODULE_H_ */ 99 | -------------------------------------------------------------------------------- /src/snmp-mib/system/Makefile.am: -------------------------------------------------------------------------------- 1 | if ENABLE_MIB_SYSTEM 2 | 3 | plugin_LTLIBRARIES = libsnmp-mib-system.la 4 | 5 | libsnmp_mib_system_la_SOURCES = \ 6 | activator.c system-module.h system-module.c \ 7 | hr-system-module.h hr-system-module.c \ 8 | hr-device-module.h hr-device-module.c \ 9 | hr-storage-module.h hr-storage-module.c \ 10 | hr-sw-run-module.h hr-sw-run-module.c \ 11 | hr-sw-perf-module.h hr-sw-perf-module.c \ 12 | hr-sw-installed-module.h hr-sw-installed-module.c \ 13 | ucd-module.h ucd-memory-module.c \ 14 | ucd-load-module.c ucd-vmstat-module.c \ 15 | application-module.h application-module.c \ 16 | cpu-cache.h cpu-cache.c \ 17 | device-cache.h device-cache.c \ 18 | proc-cache.h proc-cache.c \ 19 | mem-cache.h mem-cache.c \ 20 | storage-cache.h storage-cache.c 21 | libsnmp_mib_system_la_CFLAGS= \ 22 | -fPIC -fvisibility=hidden 23 | libsnmp_mib_system_la_LDFLAGS = \ 24 | -no-undefined -avoid-version -shared -fPIC 25 | 26 | AM_CPPFLAGS = \ 27 | -I$(top_srcdir)/src \ 28 | -I$(top_srcdir)/src/snmp-core \ 29 | -I$(top_srcdir)/src/snmp-agent \ 30 | -I$(top_srcdir)/src/snmp-mib 31 | 32 | endif 33 | 34 | -------------------------------------------------------------------------------- /src/snmp-mib/system/activator.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #include "snmp-agent/mib-tree.h" 25 | #include "snmp-mib/system/application-module.h" 26 | #include "snmp-mib/system/system-module.h" 27 | #include "snmp-mib/system/hr-system-module.h" 28 | #include "snmp-mib/system/hr-storage-module.h" 29 | #include "snmp-mib/system/hr-device-module.h" 30 | #include "snmp-mib/system/hr-sw-run-module.h" 31 | #include "snmp-mib/system/hr-sw-perf-module.h" 32 | #include "snmp-mib/system/hr-sw-installed-module.h" 33 | #include "snmp-mib/system/ucd-module.h" 34 | 35 | __attribute__((constructor)) 36 | static void load_plugin(void) 37 | { 38 | add_module(init_system_module, "system"); 39 | add_module(init_hr_system_module, "host system"); 40 | add_module(init_hr_storage_module, "storage"); 41 | add_module(init_hr_device_module, "device"); 42 | add_module(init_hr_sw_run_module, "running software"); 43 | add_module(init_hr_sw_perf_module, "software performance"); 44 | add_module(init_hr_sw_installed_module, "installed software"); 45 | add_module(init_ucd_memory_module, "memory"); 46 | add_module(init_ucd_load_module, "system load"); 47 | add_module(init_ucd_vmstat_module, "vmstat"); 48 | add_module(init_application_module, "applTable"); 49 | } 50 | -------------------------------------------------------------------------------- /src/snmp-mib/system/application-module.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #ifndef SRC_SNMP_MIB_BASE_APPLICATION_MODULE_H_ 25 | #define SRC_SNMP_MIB_BASE_APPLICATION_MODULE_H_ 26 | 27 | /** 28 | * APPLICATION-MIB (RFC 2788). Contains general statistics 29 | * on network services available on this device. 30 | */ 31 | 32 | /** 33 | * @internal 34 | * init_application_module - creates and initialises a new application module. 35 | * 36 | * @return pointer to new module on success, NULL on error. 37 | */ 38 | MibModule *init_application_module(void); 39 | 40 | #endif /* SRC_SNMP_MIB_BASE_APPLICATION_MODULE_H_ */ 41 | -------------------------------------------------------------------------------- /src/snmp-mib/system/cpu-cache.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #ifndef SRC_SNMP_MIB_SYSTEM_CPU_CACHE_H_ 25 | #define SRC_SNMP_MIB_SYSTEM_CPU_CACHE_H_ 26 | 27 | typedef struct { 28 | 29 | /* average amount of memory swapped in */ 30 | uint32_t swap_in; 31 | 32 | /* average amount of memory swapped out */ 33 | uint32_t swap_out; 34 | 35 | /* average amount of data written to external I/O device */ 36 | uint32_t io_sent; 37 | 38 | /* average amount of data read from external I/O device */ 39 | uint32_t io_received; 40 | 41 | /* average rate of interrupts processed */ 42 | uint32_t interrupts; 43 | 44 | /* average rate of context switches */ 45 | uint32_t context_switch; 46 | 47 | /* CPU time spent in user-level code */ 48 | uint32_t cpu_user; 49 | 50 | /* CPU time spent in system-level code */ 51 | uint32_t cpu_system; 52 | 53 | /* CPU idle time */ 54 | uint32_t cpu_idle; 55 | 56 | } CpuInfo; 57 | 58 | /** 59 | * @internal 60 | * get_cpu_info - returns CPU statistics 61 | * 62 | * @return CPU statistics, or NULL if not available. 63 | */ 64 | CpuInfo *get_cpu_info(void); 65 | 66 | #endif /* SRC_SNMP_MIB_SYSTEM_CPU_CACHE_H_ */ 67 | -------------------------------------------------------------------------------- /src/snmp-mib/system/device-cache.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #ifndef SRC_SNMP_MIB_SYSTEM_DEVICE_CACHE_H_ 25 | #define SRC_SNMP_MIB_SYSTEM_DEVICE_CACHE_H_ 26 | 27 | #define DEVICE_ID_PREFIX_CPU 0x00000000 28 | #define DEVICE_ID_PREFIX_NETWORK 0x00A00000 29 | #define DEVICE_ID_PREFIX_PRINTER 0x00B00000 30 | #define DEVICE_ID_PREFIX_STORAGE 0x00C00000 31 | 32 | enum DeviceType { 33 | DEVICE_TYPE_PROCESSOR = 3, 34 | DEVICE_TYPE_NETWORK = 4, 35 | DEVICE_TYPE_PRINTER = 5, 36 | DEVICE_TYPE_STORAGE = 6 37 | }; 38 | 39 | enum DeviceStatus { 40 | DEVICE_STATUS_UNKNOWN = 1, 41 | DEVICE_STATUS_RUNNING = 2, 42 | DEVICE_STATUS_WARNING = 3, 43 | DEVICE_STATUS_TESTING = 4, 44 | DEVICE_STATUS_DOWN = 5 45 | }; 46 | 47 | enum DeviceStorageAccess { 48 | DEVICE_STORAGE_READ_WRITE = 1, 49 | DEVICE_STORAGE_READ_ONLY = 2 50 | }; 51 | 52 | enum DeviceStorageMedia { 53 | DEVICE_STORAGE_MEDIA_OTHER = 1, 54 | DEVICE_STORAGE_MEDIA_UNKNOWN = 2, 55 | DEVICE_STORAGE_MEDIA_HARD_DISK = 3, 56 | DEVICE_STORAGE_MEDIA_FLOPPY_DISK = 4, 57 | DEVICE_STORAGE_MEDIA_OPTICAL_DISK_ROM = 5, 58 | DEVICE_STORAGE_MEDIA_OPTICAL_DISK_WORM = 6, 59 | DEVICE_STORAGE_MEDIA_OPTICAL_DISK_RW = 7, 60 | DEVICE_STORAGE_MEDIA_RAM_DISK = 8 61 | }; 62 | 63 | typedef struct PartitionEntry { 64 | uint32_t device_id; 65 | uint32_t partition_id; 66 | char label[64]; 67 | char uuid[64]; 68 | uint32_t size; 69 | struct PartitionEntry *next; 70 | } PartitionEntry; 71 | 72 | typedef struct { 73 | uint32_t id; 74 | enum DeviceType type; 75 | char descr[64]; 76 | enum DeviceStatus status; 77 | uint32_t errors; 78 | } DeviceEntry; 79 | 80 | typedef struct { 81 | DeviceEntry device; 82 | uint32_t load; 83 | } DeviceProcessorEntry; 84 | 85 | typedef struct { 86 | DeviceEntry device; 87 | uint32_t iface_id; 88 | } DeviceIfaceEntry; 89 | 90 | typedef struct { 91 | DeviceEntry device; 92 | enum DeviceStorageAccess access; 93 | enum DeviceStorageMedia media; 94 | int removable; 95 | uint32_t capacity; 96 | PartitionEntry *partitions; 97 | } DeviceStorageEntry; 98 | 99 | typedef struct { 100 | size_t len; 101 | size_t max_len; 102 | DeviceEntry **arr; 103 | } DeviceList; 104 | 105 | /** 106 | * @internal 107 | * get_device_list - returns list of available devices 108 | * 109 | * @return list of devices, or NULL if not available. 110 | */ 111 | DeviceList *get_device_list(void); 112 | 113 | #endif /* SRC_SNMP_MIB_SYSTEM_DEVICE_CACHE_H_ */ 114 | -------------------------------------------------------------------------------- /src/snmp-mib/system/hr-device-module.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #ifndef SRC_SNMP_MIB_SYSTEM_HR_DEVICE_MODULE_H_ 25 | #define SRC_SNMP_MIB_SYSTEM_HR_DEVICE_MODULE_H_ 26 | 27 | #include "snmp-agent/mib-tree.h" 28 | #include "snmp-mib/mib-module.h" 29 | 30 | /* device group of HOST-RESOURCES-MIB at .1.3.6.1.2.1.25.3 (RFC 2790) */ 31 | #define SNMP_OID_HR_DEVICE SNMP_OID_MIB2,25,3 32 | 33 | /** 34 | * @internal 35 | * init_hr_device_module - creates and initialises a new device module. 36 | * 37 | * @return pointer to new module on success, NULL on error. 38 | */ 39 | MibModule *init_hr_device_module(void); 40 | 41 | #endif /* SRC_SNMP_MIB_SYSTEM_HR_DEVICE_MODULE_H_ */ 42 | -------------------------------------------------------------------------------- /src/snmp-mib/system/hr-storage-module.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #ifndef SRC_SNMP_MIB_SYSTEM_HR_STORAGE_MODULE_H_ 25 | #define SRC_SNMP_MIB_SYSTEM_HR_STORAGE_MODULE_H_ 26 | 27 | #include "snmp-agent/mib-tree.h" 28 | #include "snmp-mib/mib-module.h" 29 | 30 | /* storage group of HOST-RESOURCES-MIB at .1.3.6.1.2.1.25.2 (RFC 2790) */ 31 | #define SNMP_OID_HR_STORAGE SNMP_OID_MIB2,25,2 32 | 33 | /** 34 | * @internal 35 | * init_hr_storage_module - creates and initialises a new storage module. 36 | * 37 | * @return pointer to new module on success, NULL on error. 38 | */ 39 | MibModule *init_hr_storage_module(void); 40 | 41 | #endif /* SRC_SNMP_MIB_SYSTEM_HR_STORAGE_MODULE_H_ */ 42 | -------------------------------------------------------------------------------- /src/snmp-mib/system/hr-sw-installed-module.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | #include "snmp-agent/mib-tree.h" 29 | #include "snmp-core/snmp-types.h" 30 | #include "snmp-mib/single-level-module.h" 31 | #include "snmp-mib/system/hr-sw-installed-module.h" 32 | 33 | enum HRSWInstalledMIBObjects { 34 | HR_SW_INSTALLED_LAST_CHANGE = 1, 35 | HR_SW_INSTALLED_LAST_UPDATE_TIME = 2, 36 | HR_SW_INSTALLED_TABLE = 3 37 | }; 38 | 39 | enum HRSWInstalledTableColumns { 40 | HR_SW_INSTALLED_INDEX = 1, 41 | HR_SW_INSTALLED_NAME = 2, 42 | HR_SW_INSTALLED_ID = 3, 43 | HR_SW_INSTALLED_TYPE = 4, 44 | HR_SW_INSTALLED_DATE = 5 45 | }; 46 | 47 | DEF_METHOD(get_scalar, SnmpErrorStatus, SingleLevelMibModule, 48 | SingleLevelMibModule, int id, SnmpVariableBinding *binding) 49 | { 50 | SET_TIME_TICKS_BIND(binding, 0); 51 | return NO_ERROR; 52 | } 53 | 54 | DEF_METHOD(set_scalar, SnmpErrorStatus, SingleLevelMibModule, 55 | SingleLevelMibModule, int id, SnmpVariableBinding *binding, int dry_run) 56 | { 57 | return NOT_WRITABLE; 58 | } 59 | 60 | DEF_METHOD(get_tabular, SnmpErrorStatus, SingleLevelMibModule, 61 | SingleLevelMibModule, int id, int column, SubOID *row, size_t row_len, 62 | SnmpVariableBinding *binding, int next_row) 63 | { 64 | binding->type = next_row ? SMI_EXCEPT_END_OF_MIB_VIEW : 65 | SMI_EXCEPT_NO_SUCH_INSTANCE; 66 | return NO_ERROR; 67 | } 68 | 69 | DEF_METHOD(set_tabular, SnmpErrorStatus, SingleLevelMibModule, 70 | SingleLevelMibModule, int id, int column, SubOID *index, size_t index_len, 71 | SnmpVariableBinding *binding, int dry_run) 72 | { 73 | return NOT_WRITABLE; 74 | } 75 | 76 | DEF_METHOD(finish_module, void, MibModule, SingleLevelMibModule) 77 | { 78 | finish_single_level_module(this); 79 | } 80 | 81 | MibModule *init_hr_sw_installed_module(void) 82 | { 83 | SingleLevelMibModule *module = malloc(sizeof(SingleLevelMibModule)); 84 | if (module == NULL) { 85 | return NULL; 86 | } else if (init_single_level_module(module, HR_SW_INSTALLED_LAST_CHANGE, 87 | HR_SW_INSTALLED_TABLE - HR_SW_INSTALLED_LAST_CHANGE + 1, 88 | LEAF_SCALAR, LEAF_SCALAR, HR_SW_INSTALLED_DATE)) { 89 | free(module); 90 | return NULL; 91 | } 92 | 93 | SET_PREFIX(module, SNMP_OID_HR_SW_INSTALLED); 94 | SET_OR_ENTRY(module, NULL); 95 | SET_METHOD(module, MibModule, finish_module); 96 | SET_METHOD(module, SingleLevelMibModule, get_scalar); 97 | SET_METHOD(module, SingleLevelMibModule, set_scalar); 98 | SET_METHOD(module, SingleLevelMibModule, get_tabular); 99 | SET_METHOD(module, SingleLevelMibModule, set_tabular); 100 | return &module->public; 101 | } 102 | -------------------------------------------------------------------------------- /src/snmp-mib/system/hr-sw-installed-module.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #ifndef SRC_SNMP_MIB_SYSTEM_HR_SW_INSTALLED_MODULE_H_ 25 | #define SRC_SNMP_MIB_SYSTEM_HR_SW_INSTALLED_MODULE_H_ 26 | 27 | #include "snmp-agent/mib-tree.h" 28 | #include "snmp-mib/mib-module.h" 29 | 30 | /* installed SW group of HOST-RESOURCES-MIB at .1.3.6.1.2.1.25.6 (RFC 2790) */ 31 | #define SNMP_OID_HR_SW_INSTALLED SNMP_OID_MIB2,25,6 32 | 33 | /** 34 | * @internal 35 | * init_hr_sw_installed_module - creates and initialises 36 | * a new installed software module. 37 | * 38 | * @return pointer to new module on success, NULL on error. 39 | */ 40 | MibModule *init_hr_sw_installed_module(void); 41 | 42 | #endif /* SRC_SNMP_MIB_SYSTEM_HR_SW_INSTALLED_MODULE_H_ */ 43 | -------------------------------------------------------------------------------- /src/snmp-mib/system/hr-sw-perf-module.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #ifndef SRC_SNMP_MIB_SYSTEM_HR_SW_PERF_MODULE_H_ 25 | #define SRC_SNMP_MIB_SYSTEM_HR_SW_PERF_MODULE_H_ 26 | 27 | #include "snmp-agent/mib-tree.h" 28 | #include "snmp-mib/mib-module.h" 29 | 30 | /* SW run performance group of HOST-RESOURCES-MIB at .1.3.6.1.2.1.25.5 (RFC 2790) */ 31 | #define SNMP_OID_HR_SW_PERF SNMP_OID_MIB2,25,5 32 | 33 | /** 34 | * @internal 35 | * init_hr_sw_pef_module - creates and initialises a new 36 | * running software performance module. 37 | * 38 | * @return pointer to new module on success, NULL on error. 39 | */ 40 | MibModule *init_hr_sw_perf_module(void); 41 | 42 | #endif /* SRC_SNMP_MIB_SYSTEM_HR_SW_PERF_MODULE_H_ */ 43 | -------------------------------------------------------------------------------- /src/snmp-mib/system/hr-sw-run-module.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #ifndef SRC_SNMP_MIB_SYSTEM_HR_SW_RUN_MODULE_H_ 25 | #define SRC_SNMP_MIB_SYSTEM_HR_SW_RUN_MODULE_H_ 26 | 27 | #include "snmp-agent/mib-tree.h" 28 | #include "snmp-mib/mib-module.h" 29 | 30 | /* SW run group of HOST-RESOURCES-MIB at .1.3.6.1.2.1.25.4 (RFC 2790) */ 31 | #define SNMP_OID_HR_SW_RUN SNMP_OID_MIB2,25,4 32 | 33 | /** 34 | * @internal 35 | * init_hr_sw_run_module - creates and initialises a new running software module. 36 | * 37 | * @return pointer to new module on success, NULL on error. 38 | */ 39 | MibModule *init_hr_sw_run_module(void); 40 | 41 | #endif /* SRC_SNMP_MIB_SYSTEM_HR_SW_RUN_MODULE_H_ */ 42 | -------------------------------------------------------------------------------- /src/snmp-mib/system/hr-system-module.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #ifndef SRC_SNMP_MIB_SYSTEM_HR_SYSTEM_MODULE_H_ 25 | #define SRC_SNMP_MIB_SYSTEM_HR_SYSTEM_MODULE_H_ 26 | 27 | #include "snmp-agent/mib-tree.h" 28 | #include "snmp-mib/mib-module.h" 29 | 30 | /* system group of HOST-RESOURCES-MIB at .1.3.6.1.2.1.25.1 (RFC 2790) */ 31 | #define SNMP_OID_HR_SYSTEM SNMP_OID_MIB2,25,1 32 | 33 | /** 34 | * @internal 35 | * init_hr_system_module - creates and initialises a new host system module. 36 | * 37 | * @return pointer to new module on success, NULL on error. 38 | */ 39 | MibModule *init_hr_system_module(void); 40 | 41 | #endif /* SRC_SNMP_MIB_SYSTEM_HR_SYSTEM_MODULE_H_ */ 42 | -------------------------------------------------------------------------------- /src/snmp-mib/system/mem-cache.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include "snmp-agent/agent-cache.h" 32 | #include "snmp-core/utils.h" 33 | #include "snmp-mib/mib-utils.h" 34 | #include "snmp-mib/system/mem-cache.h" 35 | 36 | #define UPDATE_INTERVAL 8 37 | #define PATH_MEM_INFO "/proc/meminfo" 38 | #define MEM_INFO_LINE_BUF 256 39 | 40 | static void *fetch_memory_info(void); 41 | static int scan_val(FILE *, char *, uint32_t *); 42 | 43 | MemoryInfo *get_memory_info(void) 44 | { 45 | return get_mib_cache(fetch_memory_info, free, UPDATE_INTERVAL); 46 | } 47 | 48 | static void *fetch_memory_info(void) 49 | { 50 | FILE *f = NULL; 51 | MemoryInfo *info = malloc(sizeof(MemoryInfo)); 52 | if (info == NULL) 53 | goto err; 54 | if ((f = fopen(PATH_MEM_INFO, "r")) == NULL) 55 | goto err; 56 | if (scan_val(f, "MemTotal", &info->mem_total)) 57 | goto err; 58 | if (scan_val(f, "MemFree", &info->mem_free)) 59 | goto err; 60 | if (scan_val(f, "Buffers", &info->mem_buffers)) 61 | goto err; 62 | if (scan_val(f, "Cached", &info->mem_cached)) 63 | goto err; 64 | if (scan_val(f, "SwapTotal", &info->swap_total)) 65 | goto err; 66 | if (scan_val(f, "SwapFree", &info->swap_free)) 67 | goto err; 68 | if (scan_val(f, "Shmem", &info->mem_shared)) 69 | goto err; 70 | info->swap_min = 0; 71 | fclose(f); 72 | return info; 73 | err: 74 | if (f != NULL) 75 | fclose(f); 76 | free(info); 77 | return NULL; 78 | } 79 | 80 | static int scan_val(FILE *file, char *prefix, uint32_t *dst) 81 | { 82 | char line[MEM_INFO_LINE_BUF]; 83 | 84 | while (line == fgets(line, sizeof(line), file)) { 85 | if (strncmp(line, prefix, strlen(prefix))) 86 | continue; 87 | line[MEM_INFO_LINE_BUF - 1] = '\0'; 88 | if (sscanf(line + strlen(prefix) + 2, "%"PRIu32, dst) != 1) 89 | return -1; 90 | return 0; 91 | } 92 | 93 | return -1; 94 | } 95 | -------------------------------------------------------------------------------- /src/snmp-mib/system/mem-cache.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #ifndef SRC_SNMP_MIB_SYSTEM_MEM_CACHE_H_ 25 | #define SRC_SNMP_MIB_SYSTEM_MEM_CACHE_H_ 26 | 27 | typedef struct { 28 | uint32_t swap_total; 29 | uint32_t swap_free; 30 | uint32_t swap_min; 31 | uint32_t mem_total; 32 | uint32_t mem_free; 33 | uint32_t mem_shared; 34 | uint32_t mem_buffers; 35 | uint32_t mem_cached; 36 | } MemoryInfo; 37 | 38 | /** 39 | * @internal 40 | * get_memory_info - returns memory statistics 41 | * 42 | * @return memory statistics, or NULL if not available. 43 | */ 44 | MemoryInfo *get_memory_info(void); 45 | 46 | #endif /* SRC_SNMP_MIB_SYSTEM_MEM_CACHE_H_ */ 47 | -------------------------------------------------------------------------------- /src/snmp-mib/system/proc-cache.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | #include "snmp-agent/agent-cache.h" 34 | #include "snmp-core/utils.h" 35 | #include "snmp-mib/mib-utils.h" 36 | #include "snmp-mib/system/proc-cache.h" 37 | 38 | #define UPDATE_INTERVAL 4 39 | 40 | static void *fetch_pid_list(void); 41 | static void free_pid_list(void *); 42 | static int pid_cmp(const void *, const void *); 43 | 44 | int pid_exists(const uint32_t pid) 45 | { 46 | char buf[64]; 47 | snprintf(buf, sizeof(buf), LINUX_PROC"/%"PRIu32, pid); 48 | return access(buf, F_OK) == -1 ? -1 : 0; 49 | } 50 | 51 | uint32_t get_next_pid(const uint32_t prev) 52 | { 53 | PIDList *list = get_pid_list(); 54 | 55 | if (list == NULL) { 56 | return -1; 57 | } 58 | 59 | int index = bsearch_next(&prev, list->arr, list->len, sizeof(uint32_t), pid_cmp); 60 | if (index == -1) { 61 | return -1; 62 | } 63 | return list->arr[index]; 64 | } 65 | 66 | PIDList *get_pid_list(void) 67 | { 68 | return get_mib_cache(fetch_pid_list, free_pid_list, UPDATE_INTERVAL); 69 | } 70 | 71 | static void *fetch_pid_list(void) 72 | { 73 | PIDList *list = malloc(sizeof(PIDList)); 74 | if (list == NULL) { 75 | return NULL; 76 | } 77 | 78 | list->len = 0; 79 | list->arr = NULL; 80 | 81 | DIR *dir = opendir(LINUX_PROC); 82 | if (dir == NULL) { 83 | goto err; 84 | } 85 | 86 | int i = 0; 87 | struct dirent *entry; 88 | while ((entry = readdir(dir)) != NULL) { 89 | if (!isdigit(entry->d_name[0])) { 90 | continue; 91 | } 92 | 93 | if (i >= list->len) { 94 | size_t new_len = list->len < 255 ? 255 : (list->len << 1); 95 | uint32_t *tmp = malloc(new_len * sizeof(uint32_t)); 96 | if (tmp == NULL) { 97 | goto err; 98 | } 99 | 100 | memcpy(tmp, list->arr, list->len * sizeof(uint32_t)); 101 | free(list->arr); 102 | list->arr = tmp; 103 | list->len = new_len; 104 | } 105 | 106 | list->arr[i++] = strtol(entry->d_name, (char **)NULL, 10); 107 | } 108 | list->len = i; 109 | qsort(list->arr, list->len, sizeof(uint32_t), pid_cmp); 110 | err: 111 | closedir(dir); 112 | return list; 113 | } 114 | 115 | static void free_pid_list(void *list) 116 | { 117 | free(((PIDList *) list)->arr); 118 | free(list); 119 | } 120 | 121 | static int pid_cmp(const void *pid1, const void *pid2) 122 | { 123 | if (*(uint32_t *) pid1 > *(uint32_t *) pid2) { 124 | return 1; 125 | } else if (*(uint32_t *) pid1 < *(uint32_t *) pid2) { 126 | return -1; 127 | } else { 128 | return 0; 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /src/snmp-mib/system/proc-cache.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #ifndef SRC_SNMP_MIB_SYSTEM_PROC_CACHE_H_ 25 | #define SRC_SNMP_MIB_SYSTEM_PROC_CACHE_H_ 26 | 27 | #define LINUX_PROC "/proc" 28 | #define LINUX_PROC_CMDLINE "/proc/%d/cmdline" 29 | #define LINUX_PROC_EXE "/proc/%d/exe" 30 | #define LINUX_PROC_STAT "/proc/%d/stat" 31 | #define LINUX_PROC_STATM "/proc/%d/statm" 32 | 33 | typedef struct { 34 | size_t len; 35 | uint32_t *arr; 36 | } PIDList; 37 | 38 | /** 39 | * @internal 40 | * get_pid_list - returns list of running processes 41 | * 42 | * @return list of processes, or NULL if not available. 43 | */ 44 | PIDList *get_pid_list(void); 45 | 46 | /** 47 | * @internal 48 | * pid_exists - checks if given process identifier exists 49 | * 50 | * @param pid IN - process identifier to be validated. 51 | * 52 | * @return 0 if pid exists, -1 otherwise. 53 | */ 54 | int pid_exists(uint32_t pid); 55 | 56 | /** 57 | * @internal 58 | * get_next_pid - returns the smallest pid following the given process identifier 59 | * 60 | * @param prev IN - preceding process identifier 61 | * 62 | * @return following process identifier, or -1 if no match found. 63 | */ 64 | uint32_t get_next_pid(uint32_t prev); 65 | 66 | #endif /* SRC_SNMP_MIB_SYSTEM_PROC_CACHE_H_ */ 67 | -------------------------------------------------------------------------------- /src/snmp-mib/system/storage-cache.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | #include "snmp-agent/agent-cache.h" 35 | #include "snmp-core/utils.h" 36 | #include "snmp-mib/mib-utils.h" 37 | #include "snmp-mib/system/storage-cache.h" 38 | 39 | #define UPDATE_INTERVAL 8 40 | #define MOUNTED_FILE_SYSTEMS "/proc/mounts" 41 | 42 | static void *fetch_storage_list(void); 43 | static void free_storage_list(void *); 44 | 45 | StorageEntry *get_storage_list(void) 46 | { 47 | return get_mib_cache(fetch_storage_list, free_storage_list, UPDATE_INTERVAL); 48 | } 49 | 50 | static void *fetch_storage_list(void) 51 | { 52 | StorageEntry *head = NULL; 53 | StorageEntry *tail = NULL; 54 | 55 | FILE *mount_table = setmntent(MOUNTED_FILE_SYSTEMS, "r"); 56 | if (mount_table == NULL) { 57 | return NULL; 58 | } 59 | 60 | struct mntent *e; 61 | int i = 1; 62 | while ((e = getmntent(mount_table)) != NULL) { 63 | struct statfs stat; 64 | if (statfs(e->mnt_dir, &stat) != 0) 65 | continue; 66 | if (stat.f_blocks == 0) 67 | continue; 68 | 69 | StorageEntry *entry = malloc(sizeof(StorageEntry)); 70 | if (entry == NULL) 71 | goto err; 72 | 73 | entry->index = i++; 74 | snprintf(entry->descr, sizeof(entry->descr), "%s mounted on %s", 75 | e->mnt_type, e->mnt_dir); 76 | entry->allocation_units = stat.f_bsize ? stat.f_bsize : 1; 77 | entry->size = stat.f_blocks; 78 | entry->used = stat.f_blocks - stat.f_bfree; 79 | entry->next = NULL; 80 | 81 | if (head == NULL) { 82 | head = entry; 83 | tail = entry; 84 | } else { 85 | tail->next = entry; 86 | tail = entry; 87 | } 88 | } 89 | err: 90 | endmntent(mount_table); 91 | return head; 92 | } 93 | 94 | static void free_storage_list(void *list) 95 | { 96 | StorageEntry *e = list; 97 | 98 | while (e != NULL) { 99 | StorageEntry *tmp = e->next; 100 | free(e); 101 | e = tmp; 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /src/snmp-mib/system/storage-cache.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #ifndef SRC_SNMP_MIB_SYSTEM_STORAGE_CACHE_H_ 25 | #define SRC_SNMP_MIB_SYSTEM_STORAGE_CACHE_H_ 26 | 27 | typedef struct StorageEntry { 28 | uint32_t index; 29 | OID type; 30 | char descr[64]; 31 | uint32_t allocation_units; 32 | uint32_t size; 33 | uint32_t used; 34 | struct StorageEntry *next; 35 | } StorageEntry; 36 | 37 | /** 38 | * @internal 39 | * get_storage_list - returns list of storage entries 40 | * 41 | * @return list of storage entries, or NULL if not available. 42 | */ 43 | StorageEntry *get_storage_list(void); 44 | 45 | #endif /* SRC_SNMP_MIB_SYSTEM_STORAGE_CACHE_H_ */ 46 | -------------------------------------------------------------------------------- /src/snmp-mib/system/system-module.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #ifndef SRC_SNMP_MIB_BASE_SYSTEM_MODULE_H_ 25 | #define SRC_SNMP_MIB_BASE_SYSTEM_MODULE_H_ 26 | 27 | #include "snmp-mib/mib-module.h" 28 | 29 | /* 30 | * System group of MIB-2 at 1.3.6.1.2.1.1 (RFC 3418) 31 | * 32 | * The system group includes information about the system on which the entity 33 | * resides. Objects in this group are useful for fault management 34 | * and configuration management. 35 | */ 36 | 37 | /** 38 | * @internal 39 | * init_system_module - creates and initialises a new system module. 40 | * 41 | * @return pointer to new module on success, NULL on error. 42 | */ 43 | MibModule *init_system_module(void); 44 | 45 | #endif /* SRC_SNMP_MIB_BASE_SYSTEM_MODULE_H_ */ 46 | -------------------------------------------------------------------------------- /src/snmp-mib/system/ucd-module.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 3 | * Copyright (C) 2016 Olivier Verriest 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy 6 | * of this software and associated documentation files (the "Software"), to deal 7 | * in the Software without restriction, including without limitation the rights 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | * copies of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | * SOFTWARE. 22 | */ 23 | 24 | #ifndef SRC_SNMP_MIB_SYSTEM_UCD_MODULE_H_ 25 | #define SRC_SNMP_MIB_SYSTEM_UCD_MODULE_H_ 26 | 27 | #include "snmp-mib/mib-module.h" 28 | 29 | /* 30 | * modules relating to the ucdavis UCD-SNMP-MIB at .1.3.6.1.4.1.2021 31 | * only selective parts of this MIB are available. 32 | */ 33 | #define SNMP_OID_UCD SNMP_OID_ENTERPRISES,2021 34 | #define SNMP_OID_UCD_MEM SNMP_OID_UCD,4 35 | #define SNMP_OID_UCD_LOAD_TABLE 10 36 | #define SNMP_OID_UCD_LOAD SNMP_OID_UCD,SNMP_OID_UCD_LOAD_TABLE 37 | #define SNMP_OID_UCD_CPU SNMP_OID_UCD,11 38 | 39 | /** 40 | * @internal 41 | * init_ucd_memory_module - creates and initialises a new UCD memory module. 42 | * 43 | * @return pointer to new module on success, NULL on error. 44 | */ 45 | MibModule *init_ucd_memory_module(void); 46 | 47 | /** 48 | * @internal 49 | * init_ucd_load_module - creates and initialises a new UCD load module. 50 | * 51 | * @return pointer to new module on success, NULL on error. 52 | */ 53 | MibModule *init_ucd_load_module(void); 54 | 55 | /** 56 | * @internal 57 | * init_ucd_vmstat_module - creates and initialises a new UCD VM statistics module. 58 | * 59 | * @return pointer to new module on success, NULL on error. 60 | */ 61 | MibModule *init_ucd_vmstat_module(void); 62 | 63 | #endif /* SRC_SNMP_MIB_SYSTEM_UCD_MODULE_H_ */ 64 | -------------------------------------------------------------------------------- /src/tests/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_PROGRAMS = pdu-tests event-tests ctl-tests 2 | 3 | pdu_tests_SOURCES = pdu-tests.c \ 4 | ../snmp-core/snmp-core.h ../snmp-core/snmp-types.c \ 5 | ../snmp-core/snmp-types.h ../snmp-core/snmp-crypto.c \ 6 | ../snmp-core/snmp-crypto.h ../snmp-core/snmp-pdu.c \ 7 | ../snmp-core/snmp-pdu.h ../snmp-core/snmp-date-time.h \ 8 | ../snmp-core/snmp-date-time.c ../snmp-core/tinyber.c \ 9 | ../snmp-core/tinyber.h ../snmp-core/utils.c ../snmp-core/utils.h 10 | 11 | pdu_tests_LDADD = $(OPENSSL_LIB) 12 | 13 | event_tests_SOURCES = event-tests.c \ 14 | ../snmp-agent/agent-notification-builder.h ../snmp-core/tinyber.c \ 15 | ../snmp-core/tinyber.h ../snmp-core/utils.c ../snmp-core/utils.h 16 | 17 | event_tests_LDADD = -lrt 18 | 19 | ctl_tests_SOURCES = ctl-tests.c \ 20 | ../snmp-core/tinyber.h ../snmp-core/tinyber.c \ 21 | ../snmp-core/utils.c ../snmp-core/utils.h 22 | 23 | ctl_tests_LDADD = -lrt 24 | 25 | AM_CPPFLAGS = -I$(top_srcdir)/src/snmp-core 26 | -------------------------------------------------------------------------------- /src/tests/java-subagent/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/tests/java-subagent/.gitignore: -------------------------------------------------------------------------------- 1 | /bin/ 2 | /target/ 3 | -------------------------------------------------------------------------------- /src/tests/java-subagent/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | osnmpd 5 | test-java-subagent 6 | 0.0.1 7 | 8 | 9 | 10 | net.java.dev.jna 11 | jna 12 | 4.1.0 13 | 14 | 15 | 16 | 17 | src 18 | 19 | 20 | maven-compiler-plugin 21 | 3.3 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /src/tests/java-subagent/src/pm/x25/osnmpd/test/LibC.java: -------------------------------------------------------------------------------- 1 | package pm.x25.osnmpd.test; 2 | 3 | import java.nio.ByteBuffer; 4 | import java.nio.charset.StandardCharsets; 5 | import java.util.Arrays; 6 | import java.util.List; 7 | 8 | import com.sun.jna.IntegerType; 9 | import com.sun.jna.Library; 10 | import com.sun.jna.Native; 11 | import com.sun.jna.NativeLong; 12 | import com.sun.jna.Pointer; 13 | import com.sun.jna.Structure; 14 | 15 | /** 16 | * This file is part of the osnmpd project (https://github.com/verrio/osnmpd). 17 | * Copyright (C) 2016 Olivier Verriest 18 | * 19 | * Permission is hereby granted, free of charge, to any person obtaining a copy 20 | * of this software and associated documentation files (the "Software"), to deal 21 | * in the Software without restriction, including without limitation the rights 22 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 23 | * copies of the Software, and to permit persons to whom the Software is 24 | * furnished to do so, subject to the following conditions: 25 | * 26 | * The above copyright notice and this permission notice shall be included in all 27 | * copies or substantial portions of the Software. 28 | * 29 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 30 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 31 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 32 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 33 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 34 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 35 | * SOFTWARE. 36 | */ 37 | public interface LibC extends Library { 38 | 39 | public static class SizeT extends IntegerType { 40 | 41 | public SizeT() { 42 | this(0); 43 | } 44 | 45 | public SizeT(final long value) { 46 | super(Native.SIZE_T_SIZE, value); 47 | } 48 | } 49 | 50 | public static class TimeVal extends Structure { 51 | public NativeLong tv_sec; 52 | public NativeLong tv_usec; 53 | 54 | public TimeVal(int sec, int usec) { 55 | super(); 56 | this.tv_sec = new NativeLong(sec); 57 | this.tv_usec = new NativeLong(usec); 58 | } 59 | 60 | protected List getFieldOrder() { 61 | return Arrays.asList("tv_sec", "tv_usec"); 62 | } 63 | } 64 | 65 | public static class UnixSockAddress extends Structure { 66 | public final static int SUN_PATH_SIZE = 108; 67 | public short sun_family; 68 | public byte[] sun_path = new byte[SUN_PATH_SIZE]; 69 | 70 | public UnixSockAddress(final String path) { 71 | this.sun_family = AF_UNIX; 72 | final byte[] pathEncoded = path.getBytes(StandardCharsets.UTF_8); 73 | System.arraycopy(pathEncoded, 0, this.sun_path, 0, pathEncoded.length); 74 | System.arraycopy(new byte[] {0x00}, 0, this.sun_path, pathEncoded.length, 1); 75 | } 76 | 77 | protected List getFieldOrder() { 78 | return Arrays.asList("sun_family", "sun_path"); 79 | } 80 | } 81 | 82 | LibC INSTANCE = (LibC)Native.loadLibrary("c", LibC.class); 83 | 84 | int AF_UNIX = 1; 85 | int SOCK_STREAM = 1; 86 | int SOL_SOCKET = 0x01; 87 | int SO_RCVTIMEO = 0x14; 88 | int SO_SNDTIMEO = 0x15; 89 | 90 | int socket(int domain, int type, int protocol); 91 | int setsockopt(int fd, int level, int option_name, Pointer option_value, int option_len); 92 | int connect(int fd, UnixSockAddress sockaddr, int length); 93 | int bind(int fd, UnixSockAddress sockaddr, int length); 94 | int listen(int sockfd, int backlog); 95 | int accept(int sockfd, Pointer address, SizeT addrlen); 96 | int recv(int fd, ByteBuffer buf, int len, int flags); 97 | SizeT write(final int fd, final ByteBuffer buffer, SizeT length); 98 | int close(final int fd); 99 | int umask (int mask); 100 | String strerror(int errno); 101 | 102 | } 103 | --------------------------------------------------------------------------------