Refactor, break out a libsrx from confd, shared with statd

Everything (!) potentially shared with other sysrepo plugins/daemons and
helper functions (not yet in libite) that can be used by other daemons
have been relocated to libsrx.

Fix #116

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2023-08-30 10:37:43 +02:00
committed by Tobias Waldekranz
parent 72c8aaef0c
commit a38e5582ac
41 changed files with 199 additions and 92 deletions
+1
View File
@@ -8,6 +8,7 @@ source "$BR2_EXTERNAL_INFIX_PATH/package/ifupdown-ng/Config.in"
source "$BR2_EXTERNAL_INFIX_PATH/package/klish-plugin-infix/Config.in"
source "$BR2_EXTERNAL_INFIX_PATH/package/klish/Config.in"
source "$BR2_EXTERNAL_INFIX_PATH/package/klish-plugin-sysrepo/Config.in"
source "$BR2_EXTERNAL_INFIX_PATH/package/libsrx/Config.in"
source "$BR2_EXTERNAL_INFIX_PATH/package/lowdown/Config.in"
source "$BR2_EXTERNAL_INFIX_PATH/package/mdnsd/Config.in"
source "$BR2_EXTERNAL_INFIX_PATH/package/net/Config.in"
+1
View File
@@ -5,6 +5,7 @@ config BR2_PACKAGE_CONFD
select BR2_PACKAGE_LIBITE
select BR2_PACKAGE_NETOPEER2
select BR2_PACKAGE_SYSREPO
select BR2_PACKAGE_LIBSRX
help
A plugin to sysrepo that provides the core YANG models used to
manage an Infix based system. Configuration can be done using
+1 -1
View File
@@ -10,7 +10,7 @@ CONFD_SITE_METHOD = local
CONFD_SITE = $(BR2_EXTERNAL_INFIX_PATH)/src/confd
CONFD_LICENSE = BSD-3
CONFD_LICENSE_FILES = LICENSE
CONFD_DEPENDENCIES = augeas jansson libite sysrepo
CONFD_DEPENDENCIES = augeas jansson libite sysrepo libsrx
CONFD_AUTORECONF = YES
define CONFD_INSTALL_EXTRA
+7
View File
@@ -0,0 +1,7 @@
config BR2_PACKAGE_LIBSRX
bool "libsrx"
select BR2_PACKAGE_SYSREPO
help
Extensions and helper APIs for sysrepo plugins.
https://github.com/kernelkit/infix
+16
View File
@@ -0,0 +1,16 @@
################################################################################
#
# libsrx
#
################################################################################
LIBSRX_VERSION = 1.0.0
LIBSRX_SITE_METHOD = local
LIBSRX_SITE = $(BR2_EXTERNAL_INFIX_PATH)/src/libsrx
LIBSRX_LICENSE = BSD-3-Clause
LIBSRX_LICENSE_FILES = LICENSE
LIBSRX_INSTALL_STAGING = YES
LIBSRX_DEPENDENCIES = sysrepo
LIBSRX_AUTORECONF = YES
$(eval $(autotools-package))
+1
View File
@@ -3,6 +3,7 @@ config BR2_PACKAGE_STATD
select BR2_PACKAGE_JANSSON
select BR2_PACKAGE_LIBEV
select BR2_PACKAGE_SYSREPO
select BR2_PACKAGE_LIBSRX
help
Operational Status Daemon. Responsible for handling sysrepo
operational run-time info. Such as interface state and address.
+2 -1
View File
@@ -3,11 +3,12 @@
# statd
#
################################################################################
STATD_VERSION = 1.0
STATD_LICENSE = MIT
STATD_SITE_METHOD = local
STATD_SITE = $(BR2_EXTERNAL_INFIX_PATH)/src/statd
STATD_DEPENDENCIES = sysrepo libev jansson
STATD_DEPENDENCIES = sysrepo libev libsrx jansson
define STATD_BUILD_CMDS
$(TARGET_MAKE_ENV) $(TARGET_CONFIGURE_OPTS) $(MAKE) -C $(@D) \
-1
View File
@@ -26,4 +26,3 @@ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+3 -4
View File
@@ -1,11 +1,8 @@
AC_PREREQ(2.61)
AC_INIT([confd], [1.0.0],
[https://github.com/kernelkit/infix/issues])
AC_INIT([confd], [1.0.0], [https://github.com/kernelkit/infix/issues])
AM_INIT_AUTOMAKE(1.11 foreign subdir-objects)
AM_SILENT_RULES(yes)
LT_INIT
AC_CONFIG_FILES([
Makefile
src/Makefile
@@ -15,6 +12,7 @@ AC_CONFIG_FILES([
AC_PROG_CC
AC_PROG_INSTALL
LT_INIT
AC_CONFIG_LIBOBJ_DIR(lib)
AC_REPLACE_FUNCS(vasprintf)
@@ -38,6 +36,7 @@ PKG_CHECK_MODULES([glib], [glib-2.0 >= 2.50 gio-2.0 gio-unix-2.0])
PKG_CHECK_MODULES([jansson], [jansson >= 2.0.0])
PKG_CHECK_MODULES([libite], [libite >= 2.5.0])
PKG_CHECK_MODULES([sysrepo], [sysrepo >= 2.2.36])
PKG_CHECK_MODULES([libsrx], [libsrx >= 1.0.0])
# Plugin installation path for sysrepo-plugind
PKG_CHECK_VAR([srpdplugindir], [sysrepo], [SRPD_PLUGINS_PATH])
+27 -33
View File
@@ -6,20 +6,22 @@ plugin_LTLIBRARIES = confd-plugin.la
confd_plugin_la_LDFLAGS = -module -avoid-version -shared
confd_plugin_la_CFLAGS = \
$(augeas_CFLAGS) \
$(glib_CFLAGS) \
$(jansson_CFLAGS) \
$(libite_CFLAGS) \
$(sysrepo_CFLAGS) \
confd_plugin_la_CFLAGS = \
$(augeas_CFLAGS) \
$(glib_CFLAGS) \
$(jansson_CFLAGS) \
$(libite_CFLAGS) \
$(sysrepo_CFLAGS) \
$(libsrx_CFLAGS) \
$(CFLAGS)
confd_plugin_la_LIBADD = \
$(augeas_LIBS) \
$(glib_LIBS) \
$(jansson_LIBS) \
$(libite_LIBS) \
$(sysrepo_LIBS)
confd_plugin_la_LIBADD = \
$(augeas_LIBS) \
$(glib_LIBS) \
$(jansson_LIBS) \
$(libite_LIBS) \
$(sysrepo_LIBS) \
$(libsrx_LIBS)
rauc_installer_sources = \
rauc-installer.c \
@@ -29,29 +31,21 @@ BUILT_SOURCES = $(rauc_installer_sources)
EXTRA_DIST = ../lib/de.pengutronix.rauc.Installer.xml
$(rauc_installer_sources): ../lib/de.pengutronix.rauc.Installer.xml
$(AM_V_GEN) gdbus-codegen \
--generate-c-code rauc-installer \
--c-generate-autocleanup all \
--c-namespace Rauc \
--interface-prefix de.pengutronix.rauc. \
$(AM_V_GEN) gdbus-codegen \
--generate-c-code rauc-installer \
--c-generate-autocleanup all \
--c-namespace Rauc \
--interface-prefix de.pengutronix.rauc. \
$<
nodist_confd_plugin_la_SOURCES = \
$(rauc_installer_sources)
confd_plugin_la_SOURCES = \
ietf-interfaces.c \
ietf-system.c \
infix-dhcp.c \
infix-factory.c \
infix-system-software.c \
\
../lib/common.h \
../lib/helpers.c ../lib/helpers.h \
../lib/lyx.c ../lib/lyx.h \
../lib/srx_module.c ../lib/srx_module.h \
\
core.c core.h \
dagger.c dagger.h \
srx_val.c srx_val.h \
systemv.c systemv.h
confd_plugin_la_SOURCES = \
ietf-interfaces.c \
ietf-system.c \
infix-dhcp.c \
infix-factory.c \
infix-system-software.c \
core.c core.h \
dagger.c dagger.h
+3 -2
View File
@@ -1,8 +1,9 @@
/* SPDX-License-Identifier: BSD-3-Clause */
#include <srx/srx_module.h>
#include <srx/common.h>
#include "core.h"
#include "../lib/srx_module.h"
#include "../lib/common.h"
static struct confd confd;
+4 -3
View File
@@ -21,10 +21,11 @@
#include <sysrepo/values.h>
#include <sysrepo/xpath.h>
#include "../lib/common.h"
#include <srx/common.h>
#include <srx/helpers.h>
#include <srx/systemv.h>
#include "dagger.h"
#include "../lib/helpers.h"
#include "systemv.h"
#define CB_PRIO_PRIMARY 65535
#define CB_PRIO_PASSIVE 65000
+3 -1
View File
@@ -1,8 +1,10 @@
/* SPDX-License-Identifier: BSD-3-Clause */
#include <libite/lite.h>
#include <srx/common.h>
#include "core.h"
#include "dagger.h"
#include "../lib/common.h"
#define PATH_ACTION_ "%s/%d/action/%s/%s"
+5 -3
View File
@@ -1,5 +1,7 @@
#ifndef _CONFD_DAGGER_H
#define _CONFD_DAGGER_H
/* SPDX-License-Identifier: BSD-3-Clause */
#ifndef CONFD_DAGGER_H_
#define CONFD_DAGGER_H_
#include <limits.h>
#include <stdio.h>
@@ -31,4 +33,4 @@ int dagger_should_skip_current(struct dagger *d, const char *ifname);
int dagger_claim(struct dagger *d, const char *path);
#endif /* _CONFD_DAGGER_H */
#endif /* CONFD_DAGGER_H_ */
+5 -4
View File
@@ -6,12 +6,13 @@
#include <arpa/inet.h>
#include <net/if.h>
#include <srx/common.h>
#include <srx/lyx.h>
#include <srx/srx_module.h>
#include <srx/srx_val.h>
#include "core.h"
#include "dagger.h"
#include "../lib/common.h"
#include "../lib/lyx.h"
#include "../lib/srx_module.h"
#include "srx_val.h"
#define ERR_IFACE(_iface, _err, _fmt, ...) \
({ \
+5 -4
View File
@@ -8,11 +8,12 @@
#include <sys/sysinfo.h>
#include <sys/types.h>
#include <srx/common.h>
#include <srx/lyx.h>
#include <srx/srx_module.h>
#include <srx/srx_val.h>
#include "core.h"
#include "../lib/common.h"
#include "../lib/lyx.h"
#include "../lib/srx_module.h"
#include "srx_val.h"
#define XPATH_BASE_ "/ietf-system:system"
#define XPATH_AUTH_ XPATH_BASE_"/authentication"
+6 -4
View File
@@ -7,11 +7,13 @@
#include <sys/sysinfo.h>
#include <sys/types.h>
#include <srx/common.h>
#include <srx/lyx.h>
#include <srx/srx_module.h>
#include <srx/srx_val.h>
#include "core.h"
#include "../lib/common.h"
#include "../lib/lyx.h"
#include "../lib/srx_module.h"
#include "srx_val.h"
static const struct srx_module_requirement infix_dhcp_reqs[] = {
{ .dir = YANG_PATH_, .name = "infix-dhcp-client", .rev = "2023-05-22" },
+5 -4
View File
@@ -8,11 +8,12 @@
#include <sys/sysinfo.h>
#include <sys/types.h>
#include <srx/common.h>
#include <srx/lyx.h>
#include <srx/srx_module.h>
#include <srx/srx_val.h>
#include "core.h"
#include "../lib/common.h"
#include "../lib/lyx.h"
#include "../lib/srx_module.h"
#include "srx_val.h"
static const struct srx_module_requirement reqs[] = {
{ .dir = YANG_PATH_, .name = "infix-factory-default", .rev = "2023-06-28" },
+4 -4
View File
@@ -1,12 +1,12 @@
/* SPDX-License-Identifier: BSD-3-Clause */
#include <sysrepo/error_format.h>
#include <srx/common.h>
#include <srx/lyx.h>
#include "core.h"
#include "../lib/common.h"
#include "../lib/lyx.h"
#include "rauc-installer.h"
#include <sysrepo/error_format.h>
#define SW_STATE_PATH_ "/ietf-system:system-state/infix-system:software"
static const struct lys_module *infix_system;
+27
View File
@@ -0,0 +1,27 @@
Copyright (c) 2023 The KernelKit Authors
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of copyright holders nor the names of
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+3
View File
@@ -0,0 +1,3 @@
SUBDIRS = src
dist_doc_DATA = README.md LICENSE
ACLOCAL_AMFLAGS = -I m4
+6
View File
@@ -0,0 +1,6 @@
sysepo extensions
=================
This library contains extensions and helper APIs for sysrepo plugins.
It is currently used by confd and statd in Infix.
+3
View File
@@ -0,0 +1,3 @@
#!/bin/sh
autoreconf -W portability -visfm
+16
View File
@@ -0,0 +1,16 @@
AC_INIT(libsrx, 1.0.0, https://github.com/kernelkit/infix/issues)
AC_CONFIG_AUX_DIR(aux)
AM_INIT_AUTOMAKE([1.11 foreign])
AM_SILENT_RULES([yes])
AC_CONFIG_SRCDIR(src/lyx.h)
AC_CONFIG_HEADERS(config.h)
AC_CONFIG_FILES([Makefile src/Makefile src/libsrx.pc])
AC_CONFIG_MACRO_DIR([m4])
AC_PROG_CC
AC_PROG_INSTALL
AM_PROG_AR
LT_INIT
AC_OUTPUT
+17
View File
@@ -0,0 +1,17 @@
lib_LTLIBRARIES = libsrx.la
libsrx_la_CPPFLAGS = -D_DEFAULT_SOURCE -D_XOPEN_SOURCE -D_GNU_SOURCE
libsrx_la_CFLAGS = -W -Wall -Wextra -std=gnu11
libsrx_la_LDFLAGS = $(AM_LDFLAGS) -version-info 0:0:0
libsrx_la_SOURCES = common.c common.h \
helpers.c helpers.h \
lyx.c lyx.h \
srx_module.c srx_module.h \
srx_val.c srx_val.h \
systemv.c systemv.h
pkgincludedir = $(includedir)/srx
pkginclude_HEADERS = common.h helpers.h lyx.h srx_module.h srx_val.h systemv.h
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = libsrx.pc
View File
+12
View File
@@ -0,0 +1,12 @@
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
Name: @PACKAGE@
Description: Extensions and helper APIs for sysrepo plugins
Version: @VERSION@
Requires:
Libs: -L${libdir} -lsrx
Cflags: -I${includedir}
@@ -1,8 +1,9 @@
/* SPDX-License-Identifier: BSD-3-Clause */
#include <errno.h>
#include <stdarg.h>
#include "core.h"
#include "../lib/common.h"
#include <sysrepo/values.h>
#include "common.h"
sr_error_t srx_get_diff(sr_session_ctx_t *session, struct lyd_node **treep)
{
+6 -14
View File
@@ -1,21 +1,13 @@
# TODO: Libs are included fron confd. They should be broken out of confd and
# shared between statd and confd in some nice way.
CONFD_LIB = $(BASE_DIR)/../src/confd/lib/
CONFD_SRC_LIB = $(BASE_DIR)/../src/confd/src/lib
CFLAGS += -Wall -Wextra -Werror
LDLIBS += -lsysrepo -lev -lyang -ljansson -lite -lsrx
CFLAGS += -Wall -Wextra -Werror
LDLIBS += -lsysrepo -lev -lyang -ljansson -lite
CPPFLAGS := -I$(CONFD_SRC_LIB)
TARGET = statd
SRC = statd.c
LIB_SRC = $(CONFD_SRC_LIB)/helpers.c $(CONFD_SRC_LIB)/lyx.c $(CONFD_LIB)/vasprintf.c
LIB_HDR = $(CONFD_SRC_LIB)/helpers.h $(CONFD_SRC_LIB)/lyx.h $(CONFD_SRC_LIB)/common.h
TARGET = statd
SRC = statd.c
all: $(TARGET)
$(TARGET): $(SRC) $(LIB_SRC) $(LIB_HDR)
$(CC) $(CPPFLAGS) $(LDLIBS) $(CFLAGS) -o $(TARGET) $(SRC) $(LIB_SRC)
$(TARGET): $(SRC)
$(CC) $(CPPFLAGS) $(LDLIBS) $(CFLAGS) -o $(TARGET) $(SRC)
clean:
-rm statd
+3 -3
View File
@@ -3,9 +3,9 @@
#include <jansson.h>
#include <stdio.h>
#include <ctype.h>
#include "../lib/common.h"
#include "../lib/helpers.h"
#include "../lib/lyx.h"
#include <srx/common.h>
#include <srx/helpers.h>
#include <srx/lyx.h>
/* TODO: break out and find a reasonable value */
#define XPATH_MAX PATH_MAX
+3 -3
View File
@@ -16,9 +16,9 @@
#include <linux/if.h>
#include <sys/queue.h>
#include "common.h"
#include "helpers.h"
#include "lyx.h"
#include <srx/common.h>
#include <srx/helpers.h>
#include <srx/lyx.h>
#define XPATH_MAX PATH_MAX
#define XPATH_IFACE_BASE "/ietf-interfaces:interfaces"