UDS transport is configured using pmc_common functions.
Signed-off-by: Anders Selhammer <[email protected]>
---
makefile | 3 +-
snmpd.c | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 102 insertions(+), 3 deletions(-)
diff --git a/makefile b/makefile
index ed5c554..fdf3747 100644
--- a/makefile
+++ b/makefile
@@ -52,7 +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
+snmpd: config.o hash.o msg.o pmc_common.o print.o raw.o sk.o \
+ snmpd.o tlv.o transport.o udp.o udp6.o uds.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
index 32237a5..1718b07 100644
--- a/snmpd.c
+++ b/snmpd.c
@@ -21,8 +21,26 @@
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
+#include "config.h"
+#include "pmc_common.h"
+#include "print.h"
#include "util.h"
+static struct pmc *pmc;
+
+static int open_pmc(struct config *cfg)
+{
+ char uds_local[MAX_IFNAME_SIZE + 1];
+ snprintf(uds_local, sizeof(uds_local), "/var/run/snmpd.%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();
@@ -35,23 +53,103 @@ static int open_snmp()
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[])
{
- int err = 0;
+ char *config = NULL, *progname;
+ int c, err = 0, index;
+ struct option *opts;
+ struct config *cfg;
if (handle_term_signals()) {
return -1;
}
- if (open_snmp()) {
+ 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;
}
--
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