snmp4lptp: Add snmp sub agent for linuxptp
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.selhammer@est.tech>master
parent
059269d0cc
commit
b2f2c9e02d
|
@ -7,4 +7,5 @@
|
|||
/pmc
|
||||
/ptp4l
|
||||
/phc_ctl
|
||||
/snmp4lptp
|
||||
/timemaster
|
||||
|
|
|
@ -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
|
13
makefile
13
makefile
|
@ -35,9 +35,16 @@ SRC = $(OBJECTS:.o=.c)
|
|||
DEPEND = $(OBJECTS:.o=.d)
|
||||
srcdir := $(dir $(lastword $(MAKEFILE_LIST)))
|
||||
incdefs := $(shell $(srcdir)/incdefs.sh)
|
||||
snmpflg := $(shell $(srcdir)/snmpflg.sh)
|
||||
version := $(shell $(srcdir)/version.sh $(srcdir))
|
||||
VPATH = $(srcdir)
|
||||
|
||||
ifneq (,$(findstring -DHAVE_NET_SNMP,$(snmpflg)))
|
||||
PRG += snmp4lptp
|
||||
OBJECTS += snmp4lptp.o
|
||||
snmplib := $(shell net-snmp-config --netsnmp-agent-libs)
|
||||
endif
|
||||
|
||||
prefix = /usr/local
|
||||
sbindir = $(prefix)/sbin
|
||||
mandir = $(prefix)/man
|
||||
|
@ -61,6 +68,12 @@ hwstamp_ctl: hwstamp_ctl.o version.o
|
|||
|
||||
phc_ctl: phc_ctl.o phc.o sk.o util.o clockadj.o sysoff.o print.o version.o
|
||||
|
||||
snmp4lptp: print.o sk.o snmp4lptp.o util.o
|
||||
$(CC) $^ $(LDFLAGS) $(LOADLIBES) $(LDLIBS) $(snmplib) -o $@
|
||||
|
||||
snmp4lptp.o: snmp4lptp.c
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) $(snmpflg) -c $<
|
||||
|
||||
timemaster: print.o rtnl.o sk.o timemaster.o util.o version.o
|
||||
|
||||
version.o: .version version.sh $(filter-out version.d,$(DEPEND))
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
/**
|
||||
* @file snmp4lptp.c
|
||||
* @brief Implements SNMP sub agent program for linuxptp
|
||||
* @note Copyright (C) 2018 Anders Selhammer <anders.selhammer@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;
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# Discover the SNMP CFLAGS to use during compilation.
|
||||
#
|
||||
# Copyright (C) 2018 Anders Selhammer <anders.selhammer@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. When cross compiling, the user will
|
||||
# specify the include path in EXTRA_CFLAGS.
|
||||
#
|
||||
snmp_flags()
|
||||
{
|
||||
# Get list of directories searched for header files.
|
||||
dirs=$(echo "" | ${CROSS_COMPILE}cpp ${EXTRA_CFLAGS} -Wp,-v 2>&1 >/dev/null | grep ^" /")
|
||||
|
||||
# Look for libsnmp presence
|
||||
for d in $dirs; do
|
||||
files=$(find $d -type f -name net-snmp-agent-includes.h)
|
||||
for f in $files; do
|
||||
if grep -q NET_SNMP_AGENT_INCLUDES_H $f; then
|
||||
printf " -DHAVE_NET_SNMP `net-snmp-config --cflags`"
|
||||
break 2
|
||||
fi
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
echo "$(snmp_flags)"
|
Loading…
Reference in New Issue