The sub agent use net-snmp library and AgentX protocol for the communication towards the snmp master agent. snmpd.c should only include general setup needed for handling snmp. Supported MIBs should be implemented in separate files. Makefile will include snmpd if libsnmp is available during compilation. configs/snmpd.conf should be placed in /etc/snmp/
Signed-off-by: Anders Selhammer <anders.selham...@est.tech> --- configs/snmpd.conf | 26 +++++++++++++++++++++++++ incdefs.sh | 13 ++++++++++++- ldlibs.sh | 33 +++++++++++++++++++++++++++++++ makefile | 11 ++++++++--- optprg.sh | 33 +++++++++++++++++++++++++++++++ snmpd.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 169 insertions(+), 4 deletions(-) create mode 100644 configs/snmpd.conf create mode 100755 ldlibs.sh create mode 100755 optprg.sh create mode 100644 snmpd.c diff --git a/configs/snmpd.conf b/configs/snmpd.conf new file mode 100644 index 0000000..8a0d929 --- /dev/null +++ b/configs/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 diff --git a/incdefs.sh b/incdefs.sh index 19e620e..d8ae7d5 100755 --- a/incdefs.sh +++ b/incdefs.sh @@ -88,5 +88,16 @@ kernel_flags() fi } -flags="$(user_flags)$(kernel_flags)" +# +# Look for libsnmp presence. +# +snmp_flags() +{ + libsnmp=/usr/include/net-snmp/ + if [ -d ${libsnmp} ]; then + printf " -I. `net-snmp-config --cflags`" + fi +} + +flags="$(user_flags)$(kernel_flags)$(snmp_flags)" echo "$flags" diff --git a/ldlibs.sh b/ldlibs.sh new file mode 100755 index 0000000..82d9000 --- /dev/null +++ b/ldlibs.sh @@ -0,0 +1,33 @@ +#!/bin/sh +# +# Discover the LDLIBS to use during compilation. +# +# Copyright (C) 2018 Anders Selhammer <anders.selham...@est.tech> +# +# 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. + +# +# Look for libsnmp presence. +# +snmp_libs() +{ + libsnmp=/usr/include/net-snmp/ + if [ -d ${libsnmp} ]; then + printf " `net-snmp-config --agent-libs`" + fi +} + +libs="$(snmp_libs)" +echo "$libs" diff --git a/makefile b/makefile index fafacbe..ed5c554 100644 --- a/makefile +++ b/makefile @@ -21,19 +21,22 @@ 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 +LDLIBS = -lm -lrt $(ldlibs) $(EXTRA_LDFLAGS) +PRG = ptp4l hwstamp_ctl nsm phc2sys phc_ctl pmc timemaster \ + $(filter-out %.o,$(optprg)) 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 + sysoff.o timemaster.o $(filter %.o,$(optprg)) SRC = $(OBJECTS:.o=.c) DEPEND = $(OBJECTS:.o=.d) srcdir := $(dir $(lastword $(MAKEFILE_LIST))) +optprg := $(shell $(srcdir)/optprg.sh) incdefs := $(shell $(srcdir)/incdefs.sh) +ldlibs := $(shell $(srcdir)/ldlibs.sh) version := $(shell $(srcdir)/version.sh $(srcdir)) VPATH = $(srcdir) @@ -49,6 +52,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/optprg.sh b/optprg.sh new file mode 100755 index 0000000..dda04dc --- /dev/null +++ b/optprg.sh @@ -0,0 +1,33 @@ +#!/bin/sh +# +# Discover the optional programs to use during compilation. +# +# Copyright (C) 2018 Anders Selhammer <anders.selham...@est.tech> +# +# 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. + +# +# Look for libsnmp presence. +# +snmp_files() +{ + libsnmp=/usr/include/net-snmp/ + if [ -d ${libsnmp} ]; then + printf " snmpd snmpd.o" + fi +} + +files="$(snmp_files)" +echo "$files" 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 <anders.selham...@est.tech> + * + * 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; +} -- 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 Linuxptp-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linuxptp-devel