From 1d0832b2f50d8f3a1a67f8cc5ba2390d8f1e7a63 Mon Sep 17 00:00:00 2001 From: Anders Selhammer Date: Tue, 21 Aug 2018 10:53:10 +0200 Subject: [PATCH] snmp4lptp: Added function for data collection from ptp4l program. General function to use for sending signals for data collection from ptp4l program. Signed-off-by: Anders Selhammer --- snmp4lptp.c | 37 +++++++++++++++++++++++++++++++++++++ snmp4lptp_mib.h | 30 ++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 snmp4lptp_mib.h diff --git a/snmp4lptp.c b/snmp4lptp.c index b32e4f6..e06f212 100644 --- a/snmp4lptp.c +++ b/snmp4lptp.c @@ -17,6 +17,9 @@ * 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 @@ -24,10 +27,44 @@ #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]; diff --git a/snmp4lptp_mib.h b/snmp4lptp_mib.h new file mode 100644 index 0000000..f135006 --- /dev/null +++ b/snmp4lptp_mib.h @@ -0,0 +1,30 @@ +/** + * @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 */