The sub agent use net-snmp library and AgentX protocol for the communication towards the snmp master agent.
Signed-off-by: Anders Selhammer <[email protected]> --- makefile | 12 ++++++++---- snmpd.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ snmpd.conf | 26 ++++++++++++++++++++++++++ 3 files changed, 91 insertions(+), 4 deletions(-) create mode 100644 snmpd.c create mode 100644 snmpd.conf diff --git a/makefile b/makefile index fafacbe..6981ba5 100644 --- a/makefile +++ b/makefile @@ -20,22 +20,24 @@ KBUILD_OUTPUT = DEBUG = CC = $(CROSS_COMPILE)gcc VER = -DVER=$(version) -CFLAGS = -Wall $(VER) $(incdefs) $(DEBUG) $(EXTRA_CFLAGS) -LDLIBS = -lm -lrt $(EXTRA_LDFLAGS) -PRG = ptp4l hwstamp_ctl nsm phc2sys phc_ctl pmc timemaster +CFLAGS = -Wall $(VER) $(incdefs) $(DEBUG) $(EXTRA_CFLAGS) $(SNMPCFLAGS) +LDLIBS = -lm -lrt $(EXTRA_LDFLAGS) $(SNMPAGENTLIBS) +PRG = ptp4l hwstamp_ctl nsm phc2sys phc_ctl pmc snmpd timemaster OBJ = bmc.o clock.o clockadj.o clockcheck.o config.o e2e_tc.o fault.o \ filter.o fsm.o hash.o linreg.o mave.o mmedian.o msg.o ntpshm.o nullf.o phc.o \ pi.o port.o print.o ptp4l.o p2p_tc.o raw.o rtnl.o servo.o sk.o stats.o tc.o \ telecom.o tlv.o transport.o tsproc.o udp.o udp6.o uds.o util.o version.o OBJECTS = $(OBJ) hwstamp_ctl.o nsm.o phc2sys.o phc_ctl.o pmc.o pmc_common.o \ - sysoff.o timemaster.o + snmpd.o sysoff.o timemaster.o SRC = $(OBJECTS:.o=.c) DEPEND = $(OBJECTS:.o=.d) srcdir := $(dir $(lastword $(MAKEFILE_LIST))) incdefs := $(shell $(srcdir)/incdefs.sh) version := $(shell $(srcdir)/version.sh $(srcdir)) VPATH = $(srcdir) +SNMPCFLAGS = -I. `net-snmp-config --cflags` +SNMPAGENTLIBS = `net-snmp-config --agent-libs` prefix = /usr/local sbindir = $(prefix)/sbin @@ -49,6 +51,8 @@ ptp4l: $(OBJ) nsm: config.o filter.o hash.o mave.o mmedian.o msg.o nsm.o print.o raw.o \ rtnl.o sk.o transport.o tlv.o tsproc.o udp.o udp6.o uds.o util.o version.o +snmpd: print.o sk.o snmpd.o util.o + pmc: config.o hash.o msg.o pmc.o pmc_common.o print.o raw.o sk.o tlv.o \ transport.o udp.o udp6.o uds.o util.o version.o diff --git a/snmpd.c b/snmpd.c new file mode 100644 index 0000000..32237a5 --- /dev/null +++ b/snmpd.c @@ -0,0 +1,57 @@ +/** + * @file snmpd.c + * @brief Implements linuxptp SNMP sub agent program + * @note Copyright (C) 2018 Anders Selhammer <[email protected]> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ +#include <net-snmp/net-snmp-config.h> +#include <net-snmp/net-snmp-includes.h> +#include <net-snmp/agent/net-snmp-agent-includes.h> + +#include "util.h" + +static int open_snmp() +{ + snmp_enable_calllog(); + netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID, + NETSNMP_DS_AGENT_ROLE, 1); + init_agent("linuxptpAgent"); + + init_snmp("linuxptpAgent"); + + return 0; +} + +int main(int argc, char *argv[]) +{ + int err = 0; + + if (handle_term_signals()) { + return -1; + } + + if (open_snmp()) { + return -1; + } + + while (is_running()) { + agent_check_and_process(1); + } + + snmp_shutdown("linuxptpAgent"); + + return err; +} diff --git a/snmpd.conf b/snmpd.conf new file mode 100644 index 0000000..8a0d929 --- /dev/null +++ b/snmpd.conf @@ -0,0 +1,26 @@ +# Map 'linuxptp' community to the 'LinuxPtpUser' +# Map 'public' community to the 'AllUser' +# sec.name source community +com2sec LinuxPtpUser default linuxptp +com2sec AllUser default public + +# Map 'LinuxPtpUser' to 'LinuxPtpGroup' for SNMP Version 2c +# Map 'AllUser' to 'AllGroup' for SNMP Version 2c +# sec.model sec.name +group LinuxPtpGroup v2c LinuxPtpUser +group AllGroup v2c AllUser + +# Define 'SystemView', which includes everything under .1.3.6.1.2.1.241 +# Define 'AllView', which includes everything under .1 +# incl/excl subtree +view SystemView included .1.3.6.1.2.1.241 +view AllView included .1 + +# Give 'ConfigGroup' read access to objects in the view 'SystemView' +# Give 'AllGroup' read access to objects in the view 'AllView' +# context model level prefix read write notify +access LinuxPtpGroup "" any noauth exact SystemView none none +access AllGroup "" any noauth exact AllView none none + +# turn on the AgentX master agent support +master agentx -- 1.8.3.1 --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ Linuxptp-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linuxptp-devel
