diff --git a/makefile b/makefile index e1dd3fa..a23945a 100644 --- a/makefile +++ b/makefile @@ -38,16 +38,9 @@ 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 @@ -71,13 +64,6 @@ 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: config.o hash.o interface.o msg.o phc.o pmc_common.o print.o sk.o \ - snmp4lptp.o tlv.o $(TRANSP) util.o - $(CC) $^ $(LDFLAGS) $(LOADLIBES) $(LDLIBS) $(snmplib) -o $@ - -snmp4lptp.o: snmp4lptp.c - $(CC) $(CPPFLAGS) $(CFLAGS) $(snmpflg) -c $< - timemaster: phc.o print.o rtnl.o sk.o timemaster.o util.o version.o version.o: .version version.sh $(filter-out version.d,$(DEPEND)) diff --git a/snmp4lptp.8 b/snmp4lptp.8 deleted file mode 100644 index 7dda4d0..0000000 --- a/snmp4lptp.8 +++ /dev/null @@ -1,119 +0,0 @@ -.TH SNMP4LPTP 8 "September 2018" "linuxptp" -.SH NAME -snmp4lptp - SNMP sub agent - -.SH SYNOPSIS -.B snmp4lptp -[ -.BI \-f " config-file" -] [ -.B \-m -] [ -.B \-q -] [ -.I long-options -] - -.SH DESCRIPTION -.B snmp4lptp -is an implementation of a sub agent for handling SNMP requests on -the device running ptp4l. Via the UDS port, the sub agent retrieves -management information from ptp4l and translates the information to -or from an SNMP-specific form. - -.SH OPTIONS -.TP -.BI \-f " file" -Specify the path to the \fBsnmp4lptp\fR configuration file. -.TP -.B \-h -Display a help message. -.TP -.B \-m -Print messages to the standard output. -.TP -.B \-q -Don't send messages to the system logger. - -.SH LONG OPTIONS - -Each and every configuration file option (see below in sections -.BR PROGRAM\ OPTIONS -and -.BR PORT\ OPTIONS ) -may also appear -as a "long" style command line argument. For example, the transportSpecific -option may be set using either of these two forms: - -.RS -\f(CW\-\-transportSpecific 1 \-\-transportSpecific=1\fP -.RE - -Option values given on the command line override values in the global -section of the configuration file (which, in turn, overrides default -values). - -.SH CONFIGURATION FILE - -The configuration file is divided into sections. Each section starts with a -line containing its name enclosed in brackets and it follows with settings. -Each setting is placed on a separate line, it contains the name of the -option and the value separated by whitespace characters. Empty lines and lines -starting with # are ignored. - -The global section (indicated as -.BR [global] ) -sets the global program options as well as the default port specific options. -Other sections are port specific sections and they override the default port -options. The name of the section is the name of the configured port (e.g. -.BR [eth0] -). Currently no port specific options other than default are considered. - -.SH PROGRAM OPTIONS -.TP -.B domainNumber -The domain attribute of the local clock. -The default is 0. -.TP -.B logging_level -The maximum logging level of messages which should be printed. -The default is 6 (LOG_INFO). -.TP -.B message_tag -The tag which is added to all messages printed to the standard output or system -log. -The default is an empty string (which cannot be set in the configuration file -as the option requires an argument). -.TP -.B use_syslog -Print messages to the system log if enabled. -The default is 1 (enabled). -.TP -.B verbose -Print messages to the standard output if enabled. -The default is 0 (disabled). -.TP -.B uds_address -Specifies the address of the server's UNIX domain socket. -The default is /var/run/ptp4l. - -.SH PORT OPTIONS -.TP -.B transportSpecific -The transport specific field. Must be in the range 0 to 255. -The default is 0. - -.SH WARNING - -Be cautious when the same configuration file is used for both ptp4l -and snmp4lptp. Keep in mind that values specified in the configuration -file take precedence over their default values. If a certain option which -is common to ptp4l and snmp4lptp is specified to a non-default value in -the configuration file (e.g. for ptp4l), then this non-default value -applies also for snmp4lptp. This might be not what is expected. - -To avoid securely these unexpected behaviour, different configuration files -for ptp4l and snmp4lptp are recommended. - -.SH SEE ALSO -.BR ptp4l (8) diff --git a/snmp4lptp.c b/snmp4lptp.c deleted file mode 100644 index e06f212..0000000 --- a/snmp4lptp.c +++ /dev/null @@ -1,192 +0,0 @@ -/** - * @file snmp4lptp.c - * @brief Implements SNMP sub agent program for linuxptp - * @note Copyright (C) 2018 Anders Selhammer - * - * 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 -#include - -#include -#include -#include - -#include "config.h" -#include "pmc_common.h" -#include "print.h" -#include "snmp4lptp_mib.h" -#include "util.h" - -#define SNMP_NFD 1 -static struct pmc *pmc; - -struct ptp_message* snmp4lptp_run_pmc(char *cmd) -{ - struct pollfd pollfd[SNMP_NFD]; - int cnt, tmo = 100; - - pollfd[0].fd = pmc_get_transport_fd(pmc); - pollfd[0].events = POLLIN | POLLPRI; - - if (cmd && pmc_do_command(pmc, cmd)) { - pr_err("bad command: %s", cmd); - } - - while (is_running()) { - cnt = poll(pollfd, SNMP_NFD, tmo); - if (cnt < 0) { - if (EINTR == errno) { - continue; - } else { - pr_emerg("poll failed"); - break; - } - } else if (!cnt) { - break; - } - - if (pollfd[0].revents & (POLLIN|POLLPRI)) { - return pmc_recv(pmc); - } - } - return NULL; -} - -static int open_pmc(struct config *cfg) -{ - char uds_local[MAX_IFNAME_SIZE + 1]; - snprintf(uds_local, sizeof(uds_local), "/var/run/snmp4lptp.%d", getpid()); - - pmc = pmc_create(cfg, TRANS_UDS, uds_local, 0, - config_get_int(cfg, NULL, "domainNumber"), - config_get_int(cfg, NULL, "transportSpecific") << 4, - 1); - - return pmc ? 0 : -1; -} - -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; -} - -static void usage(char *progname) -{ - fprintf(stderr, - "\nusage: %s [options]\n\n" - " -f [file] read configuration from 'file'\n" - " -h prints this message and exits\n" - " -m print messages to stdout\n" - " -q do not print messages to the syslog\n" - "\n", - progname); -} - -int main(int argc, char *argv[]) -{ - char *config = NULL, *progname; - int c, err = 0, index; - struct option *opts; - struct config *cfg; - - if (handle_term_signals()) { - return -1; - } - - cfg = config_create(); - if (!cfg) { - return -1; - } - - opts = config_long_options(cfg); - print_set_verbose(1); - print_set_syslog(0); - - /* Process the command line arguments. */ - progname = strrchr(argv[0], '/'); - progname = progname ? 1+progname : argv[0]; - while (EOF != (c = getopt_long(argc, argv, "f:hmq", opts, &index))) { - switch (c) { - case 0: - if (config_parse_option(cfg, opts[index].name, optarg)) { - config_destroy(cfg); - return -1; - } - break; - case 'f': - config = optarg; - break; - case 'h': - usage(progname); - err = -1; - goto out; - case 'm': - config_set_int(cfg, "verbose", 1); - break; - case 'q': - config_set_int(cfg, "use_syslog", 0); - break; - case '?': - default: - usage(progname); - err = -1; - goto out; - } - } - - if (config && (err = config_read(config, cfg))) { - err = -1; - goto out; - } - - print_set_progname(progname); - print_set_tag(config_get_string(cfg, NULL, "message_tag")); - print_set_verbose(config_get_int(cfg, NULL, "verbose")); - print_set_syslog(config_get_int(cfg, NULL, "use_syslog")); - print_set_level(config_get_int(cfg, NULL, "logging_level")); - - - if (open_pmc(cfg)) { - err = -1; - goto pmc_out; - } - - if (open_snmp()) { - err = -1; - goto snmp_out; - } - - while (is_running()) { - agent_check_and_process(1); - } - - snmp_shutdown("linuxptpAgent"); - -snmp_out: - pmc_destroy(pmc); - msg_cleanup(); -pmc_out: -out: - config_destroy(cfg); - return err; -} diff --git a/snmp4lptp_mib.h b/snmp4lptp_mib.h deleted file mode 100644 index f135006..0000000 --- a/snmp4lptp_mib.h +++ /dev/null @@ -1,30 +0,0 @@ -/** - * @file snmp4lptp_mib.h - * @brief Common header file for all supported mibs in linuxptp - * @note Copyright (C) 2018 Anders Selhammer - * - * 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. - */ -#ifndef HAVE_SNMP4LPTP_MIB_H -#define HAVE_SNMP4LPTP_MIB_H - -#include "msg.h" - -/* - * function declarations - */ -struct ptp_message* snmp4lptp_run_pmc(char *cmd); - -#endif /* HAVE_SNMP4LPTP_MIB_H */ diff --git a/snmpflg.sh b/snmpflg.sh deleted file mode 100755 index 3c58bcb..0000000 --- a/snmpflg.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/sh -# -# Discover the SNMP CFLAGS to use during compilation. -# -# Copyright (C) 2018 Anders Selhammer -# -# 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)"