snmp4lptp: Added communication to ptp4l via the UDS port.
UDS transport is configured using pmc_common functions. Signed-off-by: Anders Selhammer <anders.selhammer@est.tech>master
parent
b2f2c9e02d
commit
68dcd10673
3
makefile
3
makefile
|
@ -68,7 +68,8 @@ 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
|
||||
snmp4lptp: config.o hash.o msg.o pmc_common.o print.o raw.o sk.o \
|
||||
snmp4lptp.o tlv.o transport.o udp.o udp6.o uds.o util.o
|
||||
$(CC) $^ $(LDFLAGS) $(LOADLIBES) $(LDLIBS) $(snmplib) -o $@
|
||||
|
||||
snmp4lptp.o: snmp4lptp.c
|
||||
|
|
102
snmp4lptp.c
102
snmp4lptp.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/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();
|
||||
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue