diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5aeea93e..8a9bd2fc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,9 +2,9 @@ name: Clixon CI on: push: - branches: [ master, http-data ] + branches: [ master, snmp ] pull_request: - branches: [ master, http-data ] + branches: [ master, snmp ] jobs: build: diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d533e01..064f8b7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,11 @@ Planned: July 2022 ### New features +* Clixon SNMP frontend + * Support of SNMP for retreiving and setting values via netsnmp using a MIB-YANG mapping defined in RFC6643. + * For more details, see [SNMP section of user manual](https://clixon-docs.readthedocs.io/en/latest/snmp.html) + * Thanks Siklu for sponshoring + * YANG Action (RFC 7950 Section 7.15) * Register action callback with `action_callback_register()`, see main example * Remains: check list keys, validate output @@ -117,8 +122,6 @@ Developers may need to change their code The Clixon 5.7 release introduces (long overdue) NETCONF chunked framing as defined in RFC 6242. It also introduces a limited http data service and lots of bugfixes. -### New features - * Implementation of "chunked framing" according to RFC6242 for Netconf 1.1. * First hello is 1.0 EOM framing, then successing rpc is chunked framing * See diff --git a/apps/Makefile.in b/apps/Makefile.in index 4bf422c6..1e85dc81 100644 --- a/apps/Makefile.in +++ b/apps/Makefile.in @@ -36,6 +36,7 @@ VPATH = @srcdir@ srcdir = @srcdir@ top_srcdir = @top_srcdir@ with_restconf = @with_restconf@ +enable_netsnmp = @enable_netsnmp@ SHELL = /bin/sh @@ -47,6 +48,11 @@ SUBDIRS += netconf ifdef with_restconf SUBDIRS += restconf endif +ifdef enable_netsnmp +ifeq ($(enable_netsnmp),yes) +SUBDIRS += snmp +endif +endif .PHONY: all clean depend install $(SUBDIRS) diff --git a/apps/snmp/Makefile.in b/apps/snmp/Makefile.in new file mode 100644 index 00000000..9ceb6caf --- /dev/null +++ b/apps/snmp/Makefile.in @@ -0,0 +1,131 @@ +# +# ***** BEGIN LICENSE BLOCK ***** +# +# Copyright (C) 2022 Olof Hagsand and Kristofer Hallin +# +# This file is part of CLIXON +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Alternatively, the contents of this file may be used under the terms of +# the GNU General Public License Version 3 or later (the "GPL"), +# in which case the provisions of the GPL are applicable instead +# of those above. If you wish to allow use of your version of this file only +# under the terms of the GPL, and not to allow others to +# use your version of this file under the terms of Apache License version 2, +# indicate your decision by deleting the provisions above and replace them with +# the notice and other provisions required by the GPL. If you do not delete +# the provisions above, a recipient may use your version of this file under +# the terms of any one of the Apache License version 2 or the GPL. +# +# ***** END LICENSE BLOCK ***** +# +# +VPATH = @srcdir@ +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +CC = @CC@ +CFLAGS = @CFLAGS@ +LINKAGE = @LINKAGE@ +INSTALLFLAGS = @INSTALLFLAGS@ +LDFLAGS = @LDFLAGS@ + +prefix = @prefix@ +datarootdir = @datarootdir@ +exec_prefix = @exec_prefix@ +bindir = @bindir@ +libdir = @libdir@ +sbindir = @sbindir@ +mandir = @mandir@ +libexecdir = @libexecdir@ +localstatedir = @localstatedir@ +sysconfdir = @sysconfdir@ +includedir = @includedir@ +HOST_VENDOR = @host_vendor@ + +SH_SUFFIX = @SH_SUFFIX@ +LIBSTATIC_SUFFIX = @LIBSTATIC_SUFFIX@ +CLIXON_MAJOR = @CLIXON_VERSION_MAJOR@ +CLIXON_MINOR = @CLIXON_VERSION_MINOR@ + +# Use this clixon lib for linking +ifeq ($(LINKAGE),dynamic) + CLIXON_LIB = libclixon$(SH_SUFFIX).$(CLIXON_MAJOR).$(CLIXON_MINOR) +else + CLIXON_LIB = libclixon$(LIBSTATIC_SUFFIX) +endif + +# For dependency +LIBDEPS = $(top_srcdir)/lib/src/$(CLIXON_LIB) + +LIBS = -L$(top_srcdir)/lib/src $(top_srcdir)/lib/src/$(CLIXON_LIB) @LIBS@ + +CPPFLAGS = @CPPFLAGS@ + +ifeq ($(LINKAGE),dynamic) +CPPFLAGS += -fPIC +endif + +INCLUDES = -I. -I$(top_srcdir)/lib/src -I$(top_srcdir)/lib -I$(top_srcdir)/include -I$(top_srcdir) @INCLUDES@ + +# Application +APPL = clixon_snmp + +# Common source - not accessible from plugin - independent of restconf package (fcgi|native) +APPSRC = +APPSRC += snmp_main.c + +APPOBJ = $(APPSRC:.c=.o) + +all: $(APPL) + +# Dependency of clixon library (LIBDEPS) +$(top_srcdir)/lib/src/$(CLIXON_LIB): + (cd $(top_srcdir)/lib/src && $(MAKE) $(MFLAGS) $(CLIXON_LIB)) + +clean: + rm -f *.core $(APPL) $(APPOBJ) *.o + rm -f *.gcda *.gcno *.gcov # coverage + +distclean: clean + rm -f Makefile *~ .depend + +# Put daemon in bin +# Put other executables in libexec/ +install: $(APPL) + install -d -m 0755 $(DESTDIR)$(sbindir) + install -m 0755 $(INSTALLFLAGS) $(APPL) $(DESTDIR)$(sbindir) + +install-include: + +uninstall: + rm -f $(DESTDIR)$(sbindir)/$(APPL) + +.SUFFIXES: +.SUFFIXES: .c .o + +.c.o: + $(CC) $(INCLUDES) -D__PROGRAM__=\"clixon_snmp\" $(CPPFLAGS) $(CFLAGS) -c $< + +$(APPL) : $(APPOBJ) $(LIBDEPS) + echo $(APPOBJ) + echo $(LIBDEPS) + $(CC) $(LDFLAGS) $^ $(LIBS) -o $@ + +TAGS: + find . -name '*.[chyl]' -print | etags - + +depend: + $(CC) $(DEPENDFLAGS) @DEFS@ $(INCLUDES) $(CFLAGS) -MM $(APPFCGI) $(APPSRC) > .depend + +#include .depend diff --git a/apps/snmp/snmp_main.c b/apps/snmp/snmp_main.c new file mode 100644 index 00000000..cdb1bf76 --- /dev/null +++ b/apps/snmp/snmp_main.c @@ -0,0 +1,327 @@ +/* + * + ***** BEGIN LICENSE BLOCK ***** + + Copyright (C) 2022 Olof Hagsand and Kristofer Hallin + + This file is part of CLIXON. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + Alternatively, the contents of this file may be used under the terms of + the GNU General Public License Version 3 or later (the "GPL"), + in which case the provisions of the GPL are applicable instead + of those above. If you wish to allow use of your version of this file only + under the terms of the GPL, and not to allow others to + use your version of this file under the terms of Apache License version 2, + indicate your decision by deleting the provisions above and replace them with + the notice and other provisions required by the GPL. If you do not delete + the provisions above, a recipient may use your version of this file under + the terms of any one of the Apache License version 2 or the GPL. + + ***** END LICENSE BLOCK ***** + + */ + +#ifdef HAVE_CONFIG_H +#include "clixon_config.h" /* generated by config & autoconf */ +#endif + +#include +#include +#include +#include +#include +#include + +#include + +/* cligen */ +#include + +/* clicon */ +#include + +/* Command line options to be passed to getopt(3) */ +#define SNMP_OPTS "hD:f:l:o:" + +/*! XXX netsnmp API goes here + */ +static int +snmp_input_cb(int s, + void *arg) +{ + int retval = -1; + retval = 0; + // done: + return retval; +} + + +/*! Clean and close all state of netconf process (but dont exit). + * Cannot use h after this + * @param[in] h Clixon handle + */ +static int +snmp_terminate(clicon_handle h) +{ + yang_stmt *yspec; + cvec *nsctx; + cxobj *x; + + clicon_rpc_close_session(h); + if ((yspec = clicon_dbspec_yang(h)) != NULL) + ys_free(yspec); + if ((yspec = clicon_config_yang(h)) != NULL) + ys_free(yspec); + if ((nsctx = clicon_nsctx_global_get(h)) != NULL) + cvec_free(nsctx); + if ((x = clicon_conf_xml(h)) != NULL) + xml_free(x); + xpath_optimize_exit(); + clixon_event_exit(); + clicon_handle_exit(h); + clixon_err_exit(); + clicon_log_exit(); + return 0; +} + +/*! Setup signal handlers + */ +static int +snmp_signal_init (clicon_handle h) +{ + int retval = -1; + + if (set_signal(SIGPIPE, SIG_IGN, NULL) < 0){ + clicon_err(OE_UNIX, errno, "Setting DIGPIPE signal"); + goto done; + } + retval = 0; + done: + return retval; +} + +/*! Usage help routine + * @param[in] h Clixon handle + * @param[in] argv0 command line + */ +static void +usage(clicon_handle h, + char *argv0) +{ + fprintf(stderr, "usage:%s\n" + "where options are\n" + "\t-h\t\tHelp\n" + "\t-D \tDebug level\n" + "\t-f \tConfiguration file (mandatory)\n" + "\t-l (e|o|s|f) Log on std(e)rr, std(o)ut, (s)yslog(default), (f)ile\n" + "\t-o \"