mirror of
https://github.com/kernelkit/infix.git
synced 2026-07-30 04:33:00 +02:00
confd: add support for factory-default rpc
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
committed by
Tobias Waldekranz
parent
8302ad9735
commit
123317ce35
@@ -9,5 +9,5 @@ confd_plugin_la_LIBADD = $(augeas_LIBS) $(jansson_LIBS) $(libite_LIBS) $(
|
||||
confd_plugin_la_LDFLAGS = -module -avoid-version -shared
|
||||
confd_plugin_la_SOURCES = core.c core.h ../lib/helpers.c ../lib/helpers.h srx_val.c srx_val.h \
|
||||
ietf-system.c ietf-interfaces.c systemv.c systemv.h ../lib/lyx.c ../lib/lyx.h dagger.c dagger.h \
|
||||
infix-dhcp.c ../lib/srx_module.c ../lib/srx_module.h \
|
||||
infix-dhcp.c infix-factory.c ../lib/srx_module.c ../lib/srx_module.h \
|
||||
../lib/common.h
|
||||
|
||||
@@ -75,6 +75,7 @@ int sr_plugin_init_cb(sr_session_ctx_t *session, void **priv)
|
||||
confd.session = session;
|
||||
confd.conn = sr_session_get_connection(session);
|
||||
confd.sub = NULL;
|
||||
confd.fsub = NULL;
|
||||
|
||||
if (!confd.conn)
|
||||
goto err;
|
||||
@@ -100,6 +101,9 @@ int sr_plugin_init_cb(sr_session_ctx_t *session, void **priv)
|
||||
if (rc)
|
||||
goto err;
|
||||
rc = infix_dhcp_init(&confd);
|
||||
if (rc)
|
||||
goto err;
|
||||
rc = infix_factory_init(&confd);
|
||||
if (rc)
|
||||
goto err;
|
||||
|
||||
@@ -109,12 +113,16 @@ int sr_plugin_init_cb(sr_session_ctx_t *session, void **priv)
|
||||
err:
|
||||
ERROR("init failed: %s", sr_strerror(rc));
|
||||
sr_unsubscribe(confd.sub);
|
||||
sr_unsubscribe(confd.fsub);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
void sr_plugin_cleanup_cb(sr_session_ctx_t *session, void *priv)
|
||||
{
|
||||
sr_unsubscribe((sr_subscription_ctx_t *)priv);
|
||||
struct confd *confd = (struct confd *)priv;
|
||||
|
||||
sr_unsubscribe(confd->sub);
|
||||
sr_unsubscribe(confd->fsub);
|
||||
closelog();
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include <libite/queue.h>
|
||||
#include <libyang/libyang.h>
|
||||
#include <sysrepo.h>
|
||||
#include <sysrepo/error_format.h>
|
||||
#include <sysrepo/values.h>
|
||||
#include <sysrepo/xpath.h>
|
||||
|
||||
@@ -56,6 +57,7 @@ struct confd {
|
||||
sr_session_ctx_t *cand; /* candidate datastore */
|
||||
sr_conn_ctx_t *conn;
|
||||
sr_subscription_ctx_t *sub;
|
||||
sr_subscription_ctx_t *fsub; /* factory-default sub */
|
||||
|
||||
augeas *aug;
|
||||
struct dagger netdag;
|
||||
@@ -129,4 +131,7 @@ int ietf_system_init(struct confd *confd);
|
||||
/* infix-dhcp.c */
|
||||
int infix_dhcp_init(struct confd *confd);
|
||||
|
||||
/* infix-factory.c */
|
||||
int infix_factory_init(struct confd *confd);
|
||||
|
||||
#endif /* CONFD_CORE_H_ */
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
/* SPDX-License-Identifier: BSD-3-Clause */
|
||||
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <pwd.h>
|
||||
#include <sched.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <sys/sysinfo.h>
|
||||
#include <sys/types.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" },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
static int rpc(sr_session_ctx_t *session, uint32_t sub_id, const char *xpath,
|
||||
const sr_val_t *input, const size_t input_cnt, sr_event_t event,
|
||||
unsigned request_id, sr_val_t **output, size_t *output_cnt, void *priv)
|
||||
{
|
||||
int rc;
|
||||
|
||||
DEBUG("%s", xpath);
|
||||
|
||||
sr_session_switch_ds(session, SR_DS_RUNNING);
|
||||
rc = sr_copy_config(session, NULL, SR_DS_FACTORY_DEFAULT, 60000);
|
||||
if (rc) {
|
||||
sr_session_set_netconf_error(session, "application", "operation-failed",
|
||||
NULL, xpath, sr_strerror(rc), 0);
|
||||
rc = SR_ERR_OPERATION_FAILED;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
int infix_factory_init(struct confd *confd)
|
||||
{
|
||||
int rc;
|
||||
|
||||
rc = srx_require_modules(confd->conn, reqs);
|
||||
if (rc)
|
||||
goto fail;
|
||||
|
||||
REGISTER_RPC(confd->session, "/infix-factory-default:factory-default", rpc, NULL, &confd->fsub);
|
||||
return SR_ERR_OK;
|
||||
fail:
|
||||
ERROR("failed: %s", sr_strerror(rc));
|
||||
return rc;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
module infix-factory-default {
|
||||
yang-version 1.1;
|
||||
namespace "urn:infix:factory-default:ns:yang:1.0";
|
||||
prefix infix-fd;
|
||||
|
||||
import ietf-netconf-acm {
|
||||
prefix nacm;
|
||||
}
|
||||
|
||||
organization "KernelKit";
|
||||
contact "kernelkit@googlegroups.com";
|
||||
description "Infix factory default model.";
|
||||
|
||||
revision 2023-06-28 {
|
||||
description "Initial revision.";
|
||||
reference "internal";
|
||||
}
|
||||
|
||||
rpc factory-default {
|
||||
nacm:default-deny-all;
|
||||
description "Reset the running-config datastore to factory defaults.";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user