diff --git a/board/common/rootfs/etc/pam.d/netopeer2.conf b/board/common/rootfs/etc/pam.d/netopeer2.conf new file mode 100644 index 0000000000..ca894fe8c4 --- /dev/null +++ b/board/common/rootfs/etc/pam.d/netopeer2.conf @@ -0,0 +1,20 @@ +#%PAM-1.0 +auth requisite pam_nologin.so +auth [success=1 default=ignore] pam_unix.so nullok +auth requisite pam_deny.so +auth required pam_permit.so + +account requisite pam_nologin.so +account [success=1 default=ignore] pam_unix.so +account requisite pam_deny.so +account required pam_permit.so + +password [success=1 default=ignore] pam_unix.so +password requisite pam_deny.so +password required pam_permit.so + +session required pam_loginuid.so +session include common-session +session optional pam_keyinit.so force revoke +session optional pam_lastlog.so showfailed +session optional pam_motd.so diff --git a/buildroot b/buildroot index 1d96daca15..9dcd908bd1 160000 --- a/buildroot +++ b/buildroot @@ -1 +1 @@ -Subproject commit 1d96daca1516cbd74546c58d82da965628987c10 +Subproject commit 9dcd908bd1f82f62a1d8c807d1701deb9c9afe23 diff --git a/doc/ChangeLog.md b/doc/ChangeLog.md index 35785726e6..8eb82d2bf1 100644 --- a/doc/ChangeLog.md +++ b/doc/ChangeLog.md @@ -6,6 +6,7 @@ All notable changes to the project are documented in this file. [v24.05.0][UNRELEASED] ---------------------- +> **Note:** After upgrade a factory reset is needed ### Changes - Default web landing page refactored into a Buildroot package to make @@ -22,6 +23,12 @@ All notable changes to the project are documented in this file. - Update documentation for use of VETH pairs in containers - Issue #454: create bridges in `factory-config` with IGMP/MLD snooping enabled by default +- The following YANG models have been updated to newer draft versions: + `ietf-crypto-types`, `ietf-keystore`, `ietf-netconf-server`, `ietf-ssh-common`, + `ietf-ssh-server`, `ietf-tcp-client`, `ietf-tcp-common`, `ietf-tcp-server`, + `ietf-tcp-server`, `ietf-tcp-server`, `ietf-tcp-server`. + In these there are a lot of breaking changes, most likely + you will need to redo your configuration from `factory-config`. ### Fixes - Add missing LICENSE hash for factory reset tool diff --git a/package/confd/confd.mk b/package/confd/confd.mk index 7a9ed05837..5cdbb72b8b 100644 --- a/package/confd/confd.mk +++ b/package/confd/confd.mk @@ -11,8 +11,11 @@ CONFD_SITE = $(BR2_EXTERNAL_INFIX_PATH)/src/confd CONFD_LICENSE = BSD-3-Clause CONFD_LICENSE_FILES = LICENSE CONFD_REDISTRIBUTE = NO -CONFD_DEPENDENCIES = augeas jansson libite sysrepo libsrx libglib2 +CONFD_DEPENDENCIES = host-sysrepo sysrepo netopeer2 augeas jansson libite sysrepo libsrx libglib2 CONFD_AUTORECONF = YES + +CONFD_SYSREPO_SHM_PREFIX = sr_buildroot$(subst /,_,$(CONFIG_DIR))_confd + define CONFD_CONF_ENV CFLAGS="$(INFIX_CFLAGS)" endef @@ -30,6 +33,19 @@ define CONFD_INSTALL_EXTRA mkdir -p $(TARGET_DIR)/etc/avahi/services cp $(CONFD_PKGDIR)/avahi.service $(TARGET_DIR)/etc/avahi/services/netconf.service endef -CONFD_POST_INSTALL_TARGET_HOOKS += CONFD_INSTALL_EXTRA +define CONFD_INSTALL_YANG_MODULES + USE_CONTAINERS=$(BR2_PACKAGE_PODMAN) SYSREPO_SHM_PREFIX=$(CONFD_SYSREPO_SHM_PREFIX) SYSREPOCTL_EXECUTABLE="$(HOST_DIR)/bin/sysrepoctl" SYSREPOCFG_EXECUTABLE="$(HOST_DIR)/bin/sysrepocfg" SEARCH_PATH="$(TARGET_DIR)/usr/share/yang/modules/confd/" $(@D)/scripts/setup.sh +endef +define CONFD_PERMISSIONS +/etc/sysrepo/data/ r 660 root wheel - - - - - +/etc/sysrepo/data d 770 root wheel - - - - - +endef +define CONFD_CLEANUP + rm -f /dev/shm/$(CONFD_SYSREPO_SHM_PREFIX)* +endef +CONFD_PRE_INSTALL_TARGET_HOOKS += CONFD_CLEANUP +CONFD_POST_INSTALL_TARGET_HOOKS += CONFD_INSTALL_EXTRA +CONFD_POST_INSTALL_TARGET_HOOKS += CONFD_INSTALL_YANG_MODULES +CONFD_POST_INSTALL_TARGET_HOOKS += CONFD_CLEANUP $(eval $(autotools-package)) diff --git a/patches/frr/8.5.4/0001-libyang-compat.patch b/patches/frr/8.5.4/0001-libyang-compat.patch new file mode 100644 index 0000000000..7b6093e4ce --- /dev/null +++ b/patches/frr/8.5.4/0001-libyang-compat.patch @@ -0,0 +1,22 @@ +diff --git a/lib/yang.c b/lib/yang.c +index ef1cf898a..c780b8e8c 100644 +--- a/lib/yang.c ++++ b/lib/yang.c +@@ -647,7 +647,7 @@ struct yang_data *yang_data_list_find(const struct list *list, + } + + /* Make libyang log its errors using FRR logging infrastructure. */ +-static void ly_log_cb(LY_LOG_LEVEL level, const char *msg, const char *path) ++static void ly_log_cb(LY_LOG_LEVEL level, const char *msg, const char *path, uint64_t line) + { + int priority = LOG_ERR; + +@@ -742,7 +742,7 @@ struct ly_ctx *yang_ctx_new_setup(bool embedded_modules, bool explicit_compile) + void yang_init(bool embedded_modules, bool defer_compile) + { + /* Initialize libyang global parameters that affect all containers. */ +- ly_set_log_clb(ly_log_cb, 1); ++ ly_set_log_clb(ly_log_cb); + ly_log_options(LY_LOLOG | LY_LOSTORE); + + /* Initialize libyang container for native models. */ diff --git a/patches/libnetconf2/3.0.17/0001-Add-support-for-system-authentication-as-fallback.patch b/patches/libnetconf2/3.0.17/0001-Add-support-for-system-authentication-as-fallback.patch new file mode 100644 index 0000000000..83dcbaa77c --- /dev/null +++ b/patches/libnetconf2/3.0.17/0001-Add-support-for-system-authentication-as-fallback.patch @@ -0,0 +1,59 @@ +From 2b3e1c379bf9b9404452b7aa1a66a6ce6d1301e3 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Mattias=20Walstr=C3=B6m?= +Date: Fri, 17 May 2024 13:33:53 +0200 +Subject: [PATCH] Add support for system authentication as fallback + +First check if the user is configurured in ietf-netconf-server YANG, +if found in YANG go with the user found. Else, if using shadow or pam, +just continue, try to auth anyway. PAM will block the login later if +incorrect. +--- + src/session_server_ssh.c | 17 +++++++++++++++-- + 1 file changed, 15 insertions(+), 2 deletions(-) + +diff --git a/src/session_server_ssh.c b/src/session_server_ssh.c +index c8386bc..86d5bb1 100644 +--- a/src/session_server_ssh.c ++++ b/src/session_server_ssh.c +@@ -1415,6 +1415,7 @@ nc_session_ssh_msg(struct nc_session *session, struct nc_server_ssh_opts *opts, + * process known messages + */ + if (type == SSH_REQUEST_AUTH) { ++ int username_allocated = 0; + if (session->flags & NC_SESSION_SSH_AUTHENTICATED) { + ERR(session, "User \"%s\" authenticated, but requested another authentication.", session->username); + ssh_message_reply_default(msg); +@@ -1439,6 +1440,15 @@ nc_session_ssh_msg(struct nc_session *session, struct nc_server_ssh_opts *opts, + } + } + ++#if defined(HAVE_LIBPAM) || defined(HAVE_SHADOW) ++ if (!auth_client) { ++ username_allocated = 1; ++ auth_client = malloc(sizeof(*auth_client)); /* Get freed when closing session. */ ++ memset(auth_client, 0, sizeof(*auth_client)); ++ auth_client->username = strdup(username); ++ auth_client->kb_int_enabled = 1; ++ } ++#else + if (!auth_client) { + if (opts->referenced_endpt_name) { + /* client not known by the endpt, but it references another one so try it */ +@@ -1457,9 +1467,12 @@ nc_session_ssh_msg(struct nc_session *session, struct nc_server_ssh_opts *opts, + ssh_message_reply_default(msg); + return 0; + } +- ++#endif + if (!session->username) { +- session->username = strdup(username); ++ if (username_allocated) ++ session->username = auth_client->username; ++ else ++ session->username = strdup(username); + + /* configure and count accepted auth methods */ + if (auth_client->store == NC_STORE_LOCAL) { +-- +2.34.1 + diff --git a/patches/libyang/2.2.8/UPSTREAM-Fix-netopeer2-segfault.patch b/patches/libyang/2.2.8/UPSTREAM-Fix-netopeer2-segfault.patch new file mode 100644 index 0000000000..f104136cb2 --- /dev/null +++ b/patches/libyang/2.2.8/UPSTREAM-Fix-netopeer2-segfault.patch @@ -0,0 +1,73 @@ +From 1544e0adb44a18d95e1bb23d2881a73a89fa5631 Mon Sep 17 00:00:00 2001 +From: Michal Vasko +Date: Mon, 22 Apr 2024 14:12:24 +0200 +Subject: [PATCH] plugins BUGFIX safe retrieval of canonical value + +Fixes cesnet/netopeer2#1562 +--- + src/plugins_types/binary.c | 6 +++--- + src/plugins_types/instanceid.c | 2 +- + src/plugins_types/string.c | 6 +++--- + 3 files changed, 7 insertions(+), 7 deletions(-) + +diff --git a/src/plugins_types/binary.c b/src/plugins_types/binary.c +index c2655119d..c70b4a008 100644 +--- a/src/plugins_types/binary.c ++++ b/src/plugins_types/binary.c +@@ -338,7 +338,7 @@ lyplg_type_store_binary(const struct ly_ctx *ctx, const struct lysc_type *type, + * @brief Implementation of ::lyplg_type_validate_clb for the binary type. + */ + static LY_ERR +-lyplg_type_validate_binary(const struct ly_ctx *UNUSED(ctx), const struct lysc_type *type, const struct lyd_node *UNUSED(ctx_node), ++lyplg_type_validate_binary(const struct ly_ctx *ctx, const struct lysc_type *type, const struct lyd_node *UNUSED(ctx_node), + const struct lyd_node *UNUSED(tree), struct lyd_value *storage, struct ly_err_item **err) + { + struct lysc_type_bin *type_bin = (struct lysc_type_bin *)type; +@@ -349,8 +349,8 @@ lyplg_type_validate_binary(const struct ly_ctx *UNUSED(ctx), const struct lysc_t + LY_CHECK_ARG_RET(NULL, type, storage, err, LY_EINVAL); + + val = LYPLG_TYPE_VAL_IS_DYN(val) ? (struct lyd_value_binary *)(storage->dyn_mem) : (struct lyd_value_binary *)(storage->fixed_mem); +- value = storage->_canonical; +- value_len = strlen(storage->_canonical); ++ value = lyd_value_get_canonical(ctx, storage); ++ value_len = strlen(value); + *err = NULL; + + /* length restriction of the binary value */ +diff --git a/src/plugins_types/instanceid.c b/src/plugins_types/instanceid.c +index 84e92b698..00ad45a98 100644 +--- a/src/plugins_types/instanceid.c ++++ b/src/plugins_types/instanceid.c +@@ -244,7 +244,7 @@ lyplg_type_validate_instanceid(const struct ly_ctx *ctx, const struct lysc_type + + /* find the target in data */ + if ((ret = ly_path_eval(storage->target, tree, NULL, NULL))) { +- value = lyplg_type_print_instanceid(ctx, storage, LY_VALUE_CANON, NULL, NULL, NULL); ++ value = lyd_value_get_canonical(ctx, storage); + path = lyd_path(ctx_node, LYD_PATH_STD, NULL, 0); + return ly_err_new(err, ret, LYVE_DATA, path, strdup("instance-required"), LY_ERRMSG_NOINST, value); + } +diff --git a/src/plugins_types/string.c b/src/plugins_types/string.c +index e4c1cb986..2ad003551 100644 +--- a/src/plugins_types/string.c ++++ b/src/plugins_types/string.c +@@ -112,7 +112,7 @@ lyplg_type_store_string(const struct ly_ctx *ctx, const struct lysc_type *type, + * @brief Implementation of ::lyplg_type_validate_clb for the string type. + */ + static LY_ERR +-lyplg_type_validate_string(const struct ly_ctx *UNUSED(ctx), const struct lysc_type *type, const struct lyd_node *UNUSED(ctx_node), ++lyplg_type_validate_string(const struct ly_ctx *ctx, const struct lysc_type *type, const struct lyd_node *UNUSED(ctx_node), + const struct lyd_node *UNUSED(tree), struct lyd_value *storage, struct ly_err_item **err) + { + LY_ERR ret; +@@ -121,8 +121,8 @@ lyplg_type_validate_string(const struct ly_ctx *UNUSED(ctx), const struct lysc_t + size_t value_len; + + LY_CHECK_ARG_RET(NULL, type, storage, err, LY_EINVAL); +- value = storage->_canonical; +- value_len = strlen(storage->_canonical); ++ value = lyd_value_get_canonical(ctx, storage); ++ value_len = strlen(value); + *err = NULL; + + /* length restriction of the string */ diff --git a/patches/sysrepo/2.2.170/0001-sysrepo-plugind-add-support-for-running-in-foregroun.patch b/patches/sysrepo/2.2.170/0001-sysrepo-plugind-add-support-for-running-in-foregroun.patch new file mode 100644 index 0000000000..6d3fda2160 --- /dev/null +++ b/patches/sysrepo/2.2.170/0001-sysrepo-plugind-add-support-for-running-in-foregroun.patch @@ -0,0 +1,70 @@ +From 2b284c1addeecb767bcd7dc280b27411c81cbb74 Mon Sep 17 00:00:00 2001 +From: Joachim Wiberg +Date: Tue, 28 Mar 2023 10:37:53 +0200 +Subject: [PATCH 1/4] sysrepo-plugind: add support for running in foreground + with syslog + +Signed-off-by: Joachim Wiberg +--- + src/executables/sysrepo-plugind.c | 10 +++++++++- + 1 file changed, 9 insertions(+), 1 deletion(-) + +diff --git a/src/executables/sysrepo-plugind.c b/src/executables/sysrepo-plugind.c +index a6a817cc..5baebec3 100644 +--- a/src/executables/sysrepo-plugind.c ++++ b/src/executables/sysrepo-plugind.c +@@ -98,6 +98,7 @@ help_print(void) + " Change verbosity to a level (none, error, warning, info, debug) or\n" + " number (0, 1, 2, 3, 4).\n" + " -d, --debug Debug mode - is not daemonized and logs to stderr instead of syslog.\n" ++ " -n, --foreground Run in foreground and log to syslog.\n" + " -P, --plugin-install \n" + " Install a sysrepo-plugind plugin. The plugin is simply copied\n" + " to the designated plugin directory.\n" +@@ -201,6 +202,8 @@ daemon_init(int debug, sr_log_level_t log_level) + + if (debug) { + handle_signals(); ++ if (debug < 0) ++ goto done; + sr_log_stderr(log_level); + return; + } +@@ -241,6 +244,7 @@ daemon_init(int debug, sr_log_level_t log_level) + close(fd); + } + ++done: + /* set verbosity */ + sr_log_syslog("sysrepo-plugind", log_level); + } +@@ -466,6 +470,7 @@ main(int argc, char **argv) + {"version", no_argument, NULL, 'V'}, + {"verbosity", required_argument, NULL, 'v'}, + {"debug", no_argument, NULL, 'd'}, ++ {"foreground", no_argument, NULL, 'n'}, + {"plugin-install", required_argument, NULL, 'P'}, + {"pid-file", required_argument, NULL, 'p'}, + {"fatal-plugin-fail", no_argument, NULL, 'f'}, +@@ -474,7 +479,7 @@ main(int argc, char **argv) + + /* process options */ + opterr = 0; +- while ((opt = getopt_long(argc, argv, "hVv:dP:p:f", options, NULL)) != -1) { ++ while ((opt = getopt_long(argc, argv, "hVv:dnP:p:f", options, NULL)) != -1) { + switch (opt) { + case 'h': + version_print(); +@@ -506,6 +511,9 @@ main(int argc, char **argv) + case 'd': + debug = 1; + break; ++ case 'n': ++ debug = -1; ++ break; + case 'P': + /* plugin-install */ + if (get_plugins_dir(&plugins_dir)) { +-- +2.34.1 + diff --git a/patches/sysrepo/2.2.170/0002-Allow-SR_EV_DONE-to-return-any-error-to-sysrepocfg.patch b/patches/sysrepo/2.2.170/0002-Allow-SR_EV_DONE-to-return-any-error-to-sysrepocfg.patch new file mode 100644 index 0000000000..306474c1da --- /dev/null +++ b/patches/sysrepo/2.2.170/0002-Allow-SR_EV_DONE-to-return-any-error-to-sysrepocfg.patch @@ -0,0 +1,151 @@ +From 4861639df0ce14178dbcec4d9ba93f502a1d122d Mon Sep 17 00:00:00 2001 +From: Joachim Wiberg +Date: Tue, 7 May 2024 15:41:53 +0200 +Subject: [PATCH 2/4] Allow SR_EV_DONE to return any error to sysrepocfg + +Importing a system configuration with sysrepocfg the model callbacks do +their best to validate the configuration and prepare the transaction in +SR_EV_CHANGE. In cases when dealing with a complex system, like adding +a route, address, or other change using iproute2, we may still get into +trouble when actually sending off the transaction in SR_EV_DONE. + +If something does go wrong we'd like to know this by the exit code of +sysrepocfg, not by inspecting logs or expected system state. + +This patch is a clumsy way of forcing the (first) error to bubble up to +the surface and cause a non-zero exit code from sysrepocfg. + +Signed-off-by: Joachim Wiberg +--- + src/shm_sub.c | 36 ++++++++++++++++++++++++++++-------- + src/shm_sub.h | 2 +- + src/sysrepo.c | 2 +- + 3 files changed, 30 insertions(+), 10 deletions(-) + +diff --git a/src/shm_sub.c b/src/shm_sub.c +index 63a55056..e243a2c5 100644 +--- a/src/shm_sub.c ++++ b/src/shm_sub.c +@@ -1694,7 +1694,7 @@ cleanup: + + sr_error_info_t * + sr_shmsub_change_notify_change_done(struct sr_mod_info_s *mod_info, const char *orig_name, const void *orig_data, +- uint32_t timeout_ms) ++ uint32_t timeout_ms, sr_error_info_t **cb_err_info) + { + sr_error_info_t *err_info = NULL; + struct sr_mod_info_mod_s *mod = NULL; +@@ -1826,12 +1826,19 @@ sr_shmsub_change_notify_change_done(struct sr_mod_info_s *mod_info, const char * + sr_rwunlock(&nsub->sub_shm->lock, 0, SR_LOCK_WRITE, cid, __func__); + nsub->lock = SR_LOCK_NONE; + +- /* we do not care about an error */ +- sr_errinfo_free(&nsub->cb_err_info); +- + SR_LOG_INF("EV ORIGIN: \"%s\" \"%s\" ID %" PRIu32 " priority %" PRIu32 " succeeded.", + nsub->mod->ly_mod->name, sr_ev2str(SR_SUB_EV_DONE), nsub->mod->request_id, nsub->cur_priority); + ++ /* ++ * unexpected critical error, merge and cleanup, let ++ * sysrepocfg caller handle undefined system state. ++ */ ++ if (nsub->cb_err_info) { ++ sr_errinfo_merge(cb_err_info, nsub->cb_err_info); ++ nsub->cb_err_info = NULL; ++ goto cleanup; ++ } ++ + nsub->pending_event = 0; + } + } while (1); +@@ -3301,7 +3308,7 @@ sr_shmsub_change_listen_check_update_edit(sr_session_ctx_t *ev_sess, const char + sr_error_info_t * + sr_shmsub_change_listen_process_module_events(struct modsub_change_s *change_subs, sr_conn_ctx_t *conn) + { +- sr_error_info_t *err_info = NULL; ++ sr_error_info_t *err_info = NULL, *err_tmp; + uint32_t i, data_len = 0, valid_subscr_count; + char *data = NULL, *shm_data_ptr; + int ret = SR_ERR_OK, filter_valid; +@@ -3429,6 +3436,11 @@ process_event: + } + break; + } ++ } else if (sub_info.event == SR_SUB_EV_DONE) { ++ if (ret && err_code == SR_ERR_OK) { ++ /* unexpected, callback actually failed, save for later. */ ++ err_code = ret; ++ } + } + + /* subscription processed this event */ +@@ -3470,6 +3482,11 @@ process_event: + } + break; + case SR_SUB_EV_DONE: ++ if (err_code) { ++ /* prepare unexepected error from session to be written to SHM */ ++ sr_errinfo_new(&err_info, err_code, "Oups, error detected in SR_EV_DONE"); ++ } ++ break; + case SR_SUB_EV_ABORT: + /* nothing to do */ + break; +@@ -3489,14 +3506,17 @@ process_event: + + /* SUB WRITE URGE LOCK */ + if (sr_shmsub_change_listen_relock(multi_sub_shm, SR_LOCK_WRITE_URGE, &sub_info, change_sub, change_subs->module_name, +- ret, filter_valid, ev_sess, &err_info)) { ++ ret, filter_valid, ev_sess, &err_tmp)) { ++ if (err_tmp) ++ err_info = err_tmp; + goto cleanup; + } + sub_lock = SR_LOCK_WRITE_URGE; + + /* finish event */ +- if ((err_info = sr_shmsub_multi_listen_write_event(multi_sub_shm, valid_subscr_count, err_code, &shm_data_sub, data, ++ if ((err_tmp = sr_shmsub_multi_listen_write_event(multi_sub_shm, valid_subscr_count, err_code, &shm_data_sub, data, + data_len, change_subs->module_name, err_code ? "fail" : "success"))) { ++ err_info = err_tmp; + goto cleanup; + } + +@@ -4025,7 +4045,7 @@ finish_iter: + sr_errinfo_free(&cb_err_info); + + /* publish "done" event */ +- if ((err_info = sr_shmsub_change_notify_change_done(&mod_info, NULL, NULL, SR_CHANGE_CB_TIMEOUT))) { ++ if ((err_info = sr_shmsub_change_notify_change_done(&mod_info, NULL, NULL, SR_CHANGE_CB_TIMEOUT, &cb_err_info))) { + goto cleanup_unlock; + } + +diff --git a/src/shm_sub.h b/src/shm_sub.h +index 3056e4c5..460ad927 100644 +--- a/src/shm_sub.h ++++ b/src/shm_sub.h +@@ -144,7 +144,7 @@ sr_error_info_t *sr_shmsub_change_notify_change(struct sr_mod_info_s *mod_info, + * @return err_info, NULL on success. + */ + sr_error_info_t *sr_shmsub_change_notify_change_done(struct sr_mod_info_s *mod_info, const char *orig_name, +- const void *orig_data, uint32_t timeout_ms); ++ const void *orig_data, uint32_t timeout_ms, sr_error_info_t **cb_err_info); + + /** + * @brief Notify about (generate) a change "abort" event. +diff --git a/src/sysrepo.c b/src/sysrepo.c +index 460a8c2f..6d0bf76d 100644 +--- a/src/sysrepo.c ++++ b/src/sysrepo.c +@@ -3874,7 +3874,7 @@ store: + } + + /* publish "done" event, all changes were applied */ +- if ((err_info = sr_shmsub_change_notify_change_done(mod_info, orig_name, orig_data, timeout_ms))) { ++ if ((err_info = sr_shmsub_change_notify_change_done(mod_info, orig_name, orig_data, timeout_ms, cb_err_info))) { + goto cleanup; + } + +-- +2.34.1 + diff --git a/patches/sysrepo/2.2.170/0003-Allow-to-copy-from-factory-default.patch b/patches/sysrepo/2.2.170/0003-Allow-to-copy-from-factory-default.patch new file mode 100644 index 0000000000..bd76995cb6 --- /dev/null +++ b/patches/sysrepo/2.2.170/0003-Allow-to-copy-from-factory-default.patch @@ -0,0 +1,25 @@ +From ff0e3f4197fabaf3de5e013b065a6d9765dfdb07 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Mattias=20Walstr=C3=B6m?= +Date: Wed, 8 May 2024 17:00:50 +0200 +Subject: [PATCH 3/4] Allow to copy from factory default + +--- + src/sysrepo.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/sysrepo.c b/src/sysrepo.c +index 6d0bf76d..2eac2858 100644 +--- a/src/sysrepo.c ++++ b/src/sysrepo.c +@@ -4122,7 +4122,7 @@ sr_copy_config(sr_session_ctx_t *session, const char *module_name, sr_datastore_ + struct sr_mod_info_s mod_info; + const struct lys_module *ly_mod = NULL; + +- SR_CHECK_ARG_APIRET(!session || !SR_IS_CONVENTIONAL_DS(src_datastore) || !SR_IS_CONVENTIONAL_DS(session->ds), ++ SR_CHECK_ARG_APIRET(!session || (!SR_IS_CONVENTIONAL_DS(src_datastore) && (src_datastore != SR_DS_FACTORY_DEFAULT)) || !SR_IS_CONVENTIONAL_DS(session->ds), + session, err_info); + + if (src_datastore == session->ds) { +-- +2.34.1 + diff --git a/patches/sysrepo/2.2.170/0004-Add-z-switch-to-sysrepoctl-to-install-factory-config.patch b/patches/sysrepo/2.2.170/0004-Add-z-switch-to-sysrepoctl-to-install-factory-config.patch new file mode 100644 index 0000000000..04acc03b12 --- /dev/null +++ b/patches/sysrepo/2.2.170/0004-Add-z-switch-to-sysrepoctl-to-install-factory-config.patch @@ -0,0 +1,158 @@ +From a047f4b535f363cd97f02e80e2c5aec36f1cc081 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Mattias=20Walstr=C3=B6m?= +Date: Mon, 6 May 2024 14:49:32 +0200 +Subject: [PATCH 4/4] Add -z switch to sysrepoctl to install factory config + from a json file + +This to be able to load the yang modules during build time instead on boot. +--- + src/executables/sysrepoctl.c | 20 +++++++++++++-- + src/sysrepo.c | 49 ++++++++++++++++++++++++++++++++++++ + src/sysrepo.h | 10 +++++++- + 3 files changed, 76 insertions(+), 3 deletions(-) + +diff --git a/src/executables/sysrepoctl.c b/src/executables/sysrepoctl.c +index b9680551..4cdba6a0 100644 +--- a/src/executables/sysrepoctl.c ++++ b/src/executables/sysrepoctl.c +@@ -647,6 +647,7 @@ main(int argc, char **argv) + {"uninstall", required_argument, NULL, 'u'}, + {"change", required_argument, NULL, 'c'}, + {"update", required_argument, NULL, 'U'}, ++ {"factory-install", no_argument, NULL, 'z'}, + {"plugin-list", no_argument, NULL, 'L'}, + {"plugin-install", required_argument, NULL, 'P'}, + {"search-dirs", required_argument, NULL, 's'}, +@@ -671,7 +672,7 @@ main(int argc, char **argv) + + /* process options */ + opterr = 0; +- while ((opt = getopt_long(argc, argv, "hVli:u:c:U:LP:s:e:d:r:o:g:p:D:m:I:fv:", options, NULL)) != -1) { ++ while ((opt = getopt_long(argc, argv, "hVli:u:c:U:LP:s:e:d:r:o:g:p:D:m:I:fv:z:", options, NULL)) != -1) { + switch (opt) { + case 'h': + /* help */ +@@ -863,6 +864,15 @@ main(int argc, char **argv) + goto cleanup; + } + break; ++ case 'z': ++ if (operation) { ++ error_print(0, "Operation already specified"); ++ goto cleanup; ++ } ++ /* init-data */ ++ operation = 'z'; ++ data_path = optarg; ++ break; + case 'I': + /* init-data */ + if (operation == 'i') { +@@ -922,9 +932,15 @@ main(int argc, char **argv) + goto cleanup; + } + } +- + /* perform the operation */ + switch (operation) { ++ case 'z': ++ /* Install factory config for built-in modules */ ++ if ((r = sr_install_factory_config(conn, data_path))) { ++ error_print(r, "Failed to install factory config"); ++ goto cleanup; ++ } ++ break; + case 'l': + /* list */ + if ((r = srctl_list(conn))) { +diff --git a/src/sysrepo.c b/src/sysrepo.c +index 2eac2858..ce2fa822 100644 +--- a/src/sysrepo.c ++++ b/src/sysrepo.c +@@ -1569,6 +1569,55 @@ cleanup: + return sr_api_ret(NULL, err_info); + } + ++API int ++sr_install_factory_config(sr_conn_ctx_t *conn, const char *factory_file) { ++ sr_error_info_t *err_info = NULL; ++ struct ly_ctx *new_ctx = NULL; ++ struct lyd_node *sr_mods = NULL; ++ int initialized = 0; ++ struct lyd_node *mod_data = NULL; ++ struct sr_data_update_s data_info = {0}; ++ ++ /* create new temporary context */ ++ if ((err_info = sr_ly_ctx_init(conn, &new_ctx))) { ++ goto cleanup; ++ } ++ ++ /* use temporary context to load current modules */ ++ if ((err_info = sr_shmmod_ctx_load_modules(SR_CONN_MOD_SHM(conn), new_ctx, NULL))) { ++ goto cleanup; ++ } ++ ++ if ((err_info = sr_lyd_parse_data(new_ctx, NULL, factory_file, LYD_JSON, LYD_PARSE_ONLY | LYD_PARSE_STRICT, 0, &mod_data))) { ++ goto cleanup; ++ } ++ if ((err_info = sr_lyd_dup(mod_data, NULL, LYD_DUP_RECURSIVE, 1, &data_info.new.start))) { ++ goto cleanup; ++ } ++ if ((err_info = sr_lyd_dup(mod_data, NULL, LYD_DUP_RECURSIVE, 1, &data_info.new.run))) { ++ goto cleanup; ++ } ++ /* parse SR mods */ ++ if ((err_info = sr_lydmods_parse(new_ctx, conn, &initialized, &sr_mods))) { ++ goto cleanup; ++ } ++ data_info.new.fdflt = mod_data; ++ mod_data = NULL; ++ if ((err_info = sr_lycc_store_data_if_differ(conn, new_ctx, sr_mods, &data_info))) { ++ goto cleanup; ++ } ++ ++ /* update content ID and safely switch the context */ ++ SR_CONN_MAIN_SHM(conn)->content_id = ly_ctx_get_modules_hash(new_ctx); ++ sr_conn_ctx_switch(conn, &new_ctx, NULL); ++cleanup: ++ ly_ctx_destroy(new_ctx); ++ sr_lycc_update_data_clear(&data_info); ++ lyd_free_siblings(sr_mods); ++ lyd_free_siblings(mod_data); ++ return sr_api_ret(NULL, err_info); ++} ++ + API int + sr_install_module(sr_conn_ctx_t *conn, const char *schema_path, const char *search_dirs, const char **features) + { +diff --git a/src/sysrepo.h b/src/sysrepo.h +index 0dcaedc4..46c8317e 100644 +--- a/src/sysrepo.h ++++ b/src/sysrepo.h +@@ -34,7 +34,6 @@ extern "C" { + //////////////////////////////////////////////////////////////////////////////// + // Logging API + //////////////////////////////////////////////////////////////////////////////// +- + /** + * @defgroup log_api Logging API + * @{ +@@ -706,6 +705,15 @@ int sr_get_module_info(sr_conn_ctx_t *conn, sr_data_t **sysrepo_data); + */ + int sr_is_module_internal(const struct lys_module *ly_mod); + ++/** ++ * @brief Install factory config for built-in modules from a JSON file ++ * ++ * @param[in] conn Connection to use. ++ * @param[in] conn File containing factory default data in JSON format ++ * @return Error code (::SR_ERR_OK on success). ++ */ ++int sr_install_factory_config(sr_conn_ctx_t *conn, const char *factory_file); ++ + /** @} schema */ + + //////////////////////////////////////////////////////////////////////////////// +-- +2.34.1 + diff --git a/src/confd/bin/bootstrap b/src/confd/bin/bootstrap index 3aa453b5a3..aa710349e3 100755 --- a/src/confd/bin/bootstrap +++ b/src/confd/bin/bootstrap @@ -148,111 +148,23 @@ if [ -n "$TESTING" ]; then exit 0 fi -# Drop all pre-initialized data from netopeer2 install, then re-create -# with required netopeer2 models, sysrepo implicitly installs its own, -# and then we initialize it all with our factory defaults. -rm -rf /etc/sysrepo/* /dev/shm/sr_* mkdir -p /etc/sysrepo/ if [ -f "$FACTORY_CFG" ]; then cp "$FACTORY_CFG" "$INIT_DATA" else cp "$FAILURE_CFG" "$INIT_DATA" fi +rc=$? -sysrepoctl -s $SEARCH \ - -i ietf-system@2014-08-06.yang -g wheel -p 0660 \ - -e authentication \ - -e local-users \ - -e ntp \ - -e ntp-udp-port \ - -e timezone-name \ - -i iana-timezones@2013-11-19.yang -g wheel -p 0660 \ - -i nc-notifications@2008-07-14.yang -g wheel -p 0660 \ - -i notifications@2008-07-14.yang -g wheel -p 0660 \ - -i ietf-keystore@2019-07-02.yang -g wheel -p 0660 \ - -e keystore-supported \ - -e local-definitions-supported \ - -e key-generation \ - -i ietf-truststore@2019-07-02.yang -g wheel -p 0660 \ - -e truststore-supported \ - -e x509-certificates \ - -i ietf-tcp-common@2019-07-02.yang -g wheel -p 0660 \ - -e keepalives-supported \ - -i ietf-ssh-server@2019-07-02.yang -g wheel -p 0660 \ - -e local-client-auth-supported \ - -i ietf-tls-server@2019-07-02.yang -g wheel -p 0660 \ - -e local-client-auth-supported \ - -i ietf-netconf-server@2019-07-02.yang -g wheel -p 0660 \ - -e ssh-listen \ - -e tls-listen \ - -e ssh-call-home \ - -e tls-call-home \ - -i ietf-interfaces@2018-02-20.yang -g wheel -p 0660 \ - -e if-mib \ - -i ietf-ip@2018-02-22.yang -g wheel -p 0660 \ - -e ipv6-privacy-autoconf \ - -i ietf-network-instance@2019-01-21.yang -g wheel -p 0660 \ - -i ietf-netconf-monitoring@2010-10-04.yang -g wheel -p 0660 \ - -i ietf-netconf-nmda@2019-01-07.yang -g wheel -p 0660 \ - -e origin \ - -e with-defaults \ - -i ietf-subscribed-notifications@2019-09-09.yang \ - -g wheel -p 0660 \ - -e encode-xml \ - -e replay \ - -e subtree \ - -e xpath \ - -i ietf-yang-push@2019-09-09.yang -g wheel -p 0660 \ - -e on-change \ - -i ietf-routing@2018-03-13.yang -g wheel -p 0660 \ - -i ietf-ipv6-unicast-routing@2018-03-13.yang -g wheel -p 0660 \ - -i ietf-ipv4-unicast-routing@2018-03-13.yang -g wheel -p 0660 \ - -i ietf-ospf@2022-10-19.yang -g wheel -p 0660 \ - -e bfd \ - -e explicit-router-id \ - -i iana-if-type@2023-01-26.yang -g wheel -p 0660 \ - -i iana-hardware@2018-03-13.yang -g wheel -p 0660 \ - -i ietf-hardware@2018-03-13.yang -g wheel -p 0660 \ - -e hardware-state \ - -i infix-hardware@2024-04-25.yang -g wheel -p 0660 \ - -i ieee802-dot1q-types@2022-10-29.yang -g wheel -p 0660 \ - -i infix-ip@2023-09-14.yang -g wheel -p 0660 \ - -i infix-if-type@2024-01-29.yang -g wheel -p 0660 \ - -i infix-routing@2024-03-06.yang -g wheel -p 0660 \ - -i infix-interfaces@2024-01-15.yang -g wheel -p 0660 \ - -e vlan-filtering \ - -i ieee802-dot1ab-lldp@2022-03-15.yang -g wheel -p 0660 \ - -i infix-lldp@2023-08-23.yang -g wheel -p 0660 \ - -i infix-dhcp-client@2024-04-12.yang -g wheel -p 0660 \ - -i infix-shell-type@2023-08-21.yang -g wheel -p 0660 \ - -i infix-system@2024-04-12.yang -g wheel -p 0660 \ - -i infix-services@2024-04-08.yang -g wheel -p 0660 \ - -i ieee802-ethernet-interface@2019-06-21.yang -g wheel -p 0660 \ - -i infix-ethernet-interface@2024-02-27.yang -g wheel -p 0660 \ - -I "${INIT_DATA}" +sysrepoctl -z $INIT_DATA +rc=$? +sudo -u root -g wheel sysrepocfg -f json -I"$INIT_DATA" -d running rc=$? -# Unlike `sysrepoctl -i` the `-c` command requires separate invocations. -# NOTE: we ignore any errors from these at bootstrap since sysrepo may -# already enable some of these feature, resulting in error here. -# Enable features required by netopeer2 -sysrepoctl -c ietf-netconf -g wheel -p 0660 \ - -e writable-running \ - -e candidate \ - -e rollback-on-error \ - -e validate \ - -e startup \ - -e url \ - -e xpath \ - -e confirmed-commit -# Allow wheel group users (admin) to modify NACM and do factory reset -sysrepoctl -c ietf-netconf-acm -g wheel -p 0660 -sysrepoctl -c ietf-factory-default -g wheel -p 0660 -sysrepoctl -c sysrepo-plugind -g wheel -p 0660 - -# On first boot, install factory-config as startup-config. Due to a -# limitation in sysrepo we cannot initialize ietf-netconf-acm, so we -# cheat, see sysrepo#3079 + +#rm $INIT_DATA + +# On first boot, install factory-config as startup-config. chgrp wheel /cfg chmod g+w /cfg if [ ! -f "$STARTUP_CFG" ]; then @@ -260,7 +172,8 @@ if [ ! -f "$STARTUP_CFG" ]; then fi # Clear running-config so we can load startup in the next step -echo "{}" > "$INIT_DATA" -sysrepocfg -f json -I"$INIT_DATA" -d running +temp=$(mktemp) +echo "{}" > $temp +sysrepocfg -f json -I$temp -d running exit $rc diff --git a/src/confd/bin/gen-hostkeys b/src/confd/bin/gen-hostkeys index d7639adfe3..7c42169bed 100755 --- a/src/confd/bin/gen-hostkeys +++ b/src/confd/bin/gen-hostkeys @@ -1,15 +1,14 @@ #!/bin/sh +KEYNAME=$(mktemp -u) + +ssh-keygen -f ${KEYNAME} -t rsa -N "" > /dev/null + +PUBKEY=$(awk '{print $2}' "${KEYNAME}.pub") -# generate a new key PRIVPEM=$(openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -outform PEM 2>/dev/null) # remove header/footer and newlines PRIVKEY=$(echo "$PRIVPEM" | grep -v -- "-----" | tr -d "\n") -# get public key -PUBPEM=$(echo "$PRIVPEM" | openssl rsa -pubout 2>/dev/null) -# remove header/footer and newlines -PUBKEY=$(echo "$PUBPEM" | grep -v -- "-----" | tr -d "\n") - # generate edit config cat < #include #include "core.h" diff --git a/src/confd/src/ietf-hardware.c b/src/confd/src/ietf-hardware.c index 53b20328eb..3714395494 100644 --- a/src/confd/src/ietf-hardware.c +++ b/src/confd/src/ietf-hardware.c @@ -3,7 +3,6 @@ #include #include -#include #include #include #include diff --git a/src/confd/src/ietf-interfaces.c b/src/confd/src/ietf-interfaces.c index 25b3b29460..fce1c2d2b7 100644 --- a/src/confd/src/ietf-interfaces.c +++ b/src/confd/src/ietf-interfaces.c @@ -8,7 +8,6 @@ #include #include -#include #include #include "core.h" @@ -1749,11 +1748,6 @@ static int ifchange(sr_session_ctx_t *session, uint32_t sub_id, const char *modu int ietf_interfaces_init(struct confd *confd) { int rc = 0; - -#ifdef CONTAINERS - sr_enable_module_feature(confd->conn, "infix-interfaces", "containers"); -#endif - REGISTER_CHANGE(confd->session, "ietf-interfaces", "/ietf-interfaces:interfaces//.", 0, ifchange, confd, &confd->sub); REGISTER_CHANGE(confd->cand, "ietf-interfaces", "/ietf-interfaces:interfaces//.", diff --git a/src/confd/src/ietf-routing.c b/src/confd/src/ietf-routing.c index 4b5b7edbed..ecf28eb0d6 100644 --- a/src/confd/src/ietf-routing.c +++ b/src/confd/src/ietf-routing.c @@ -2,7 +2,6 @@ #include #include -#include #include #include "core.h" @@ -104,13 +103,14 @@ int parse_ospf_areas(sr_session_ctx_t *session, struct lyd_node *areas, FILE *fp area_type = lydx_get_cattr(area, "area-type"); default_cost = lydx_get_cattr(area, "default-cost"); summary = lydx_get_bool(area, "summary"); + if (area_type) { int stub_or_nssa = 0; - if (!strcmp(area_type, "nssa-area")) { + if (!strcmp(area_type, "ietf-ospf:nssa-area")) { stub_or_nssa = 1; fprintf(fp, " area %s nssa %s\n", area_id, !summary ? "no-summary" : ""); - } else if (!strcmp(area_type, "stub-area")) { + } else if (!strcmp(area_type, "ietf-ospf:stub-area")) { stub_or_nssa = 1; fprintf(fp, " area %s stub %s\n", area_id, !summary ? "no-summary" : ""); } @@ -358,7 +358,7 @@ static int change_control_plane_protocols(sr_session_ctx_t *session, uint32_t su const char *type; type = lydx_get_cattr(cplane, "type"); - if (!strcmp(type, "static")) { + if (!strcmp(type, "ietf-routing:static")) { staticd_enabled = parse_static_routes(session, lydx_get_child(cplane, "static-routes"), fp); } else if (!strcmp(type, "ietf-ospf:ospfv2")) { parse_ospf(session, lydx_get_child(cplane, "ospf")); diff --git a/src/confd/src/ietf-system.c b/src/confd/src/ietf-system.c index f7a20e932f..7fa0e66baf 100644 --- a/src/confd/src/ietf-system.c +++ b/src/confd/src/ietf-system.c @@ -12,7 +12,7 @@ #include #include -#include + #include #include "base64.h" diff --git a/src/confd/src/infix-containers.c b/src/confd/src/infix-containers.c index 8cb22b4abb..415dff3c9c 100644 --- a/src/confd/src/infix-containers.c +++ b/src/confd/src/infix-containers.c @@ -10,7 +10,6 @@ #include #include -#include #include #include "core.h" @@ -22,11 +21,6 @@ #define ACTIVE_QUEUE "/var/lib/containers/active" #define LOGGER "logger -t container -p local1.notice" -static const struct srx_module_requirement reqs[] = { - { .dir = YANG_PATH_, .name = MODULE, .rev = "2024-03-27" }, - { NULL } -}; - static int add(const char *name, struct lyd_node *cif) { const char *image = lydx_get_cattr(cif, "image"); @@ -438,10 +432,6 @@ int infix_containers_init(struct confd *confd) { int rc; - rc = srx_require_modules(confd->conn, reqs); - if (rc) - goto fail; - REGISTER_CHANGE(confd->session, MODULE, CFG_XPATH, 0, change, confd, &confd->sub); REGISTER_RPC(confd->session, CFG_XPATH "/container/start", action, NULL, &confd->sub); REGISTER_RPC(confd->session, CFG_XPATH "/container/stop", action, NULL, &confd->sub); diff --git a/src/confd/src/infix-dhcp.c b/src/confd/src/infix-dhcp.c index 43d63e2bd0..431a468c84 100644 --- a/src/confd/src/infix-dhcp.c +++ b/src/confd/src/infix-dhcp.c @@ -9,7 +9,6 @@ #include #include -#include #include #include "core.h" @@ -18,12 +17,6 @@ #define XPATH "/infix-dhcp-client:dhcp-client" #define CACHE_TEMPLATE "/var/lib/misc/%s.cache" -static const struct srx_module_requirement reqs[] = { - { .dir = YANG_PATH_, .name = MODULE, .rev = "2024-01-30" }, - { NULL } -}; - - static char *ip_cache(const char *ifname, char *str, size_t len) { @@ -407,10 +400,6 @@ int infix_dhcp_init(struct confd *confd) { int rc; - rc = srx_require_modules(confd->conn, reqs); - if (rc) - goto fail; - REGISTER_CHANGE(confd->session, MODULE, XPATH, 0, change, confd, &confd->sub); REGISTER_CHANGE(confd->cand, MODULE, XPATH"//.", SR_SUBSCR_UPDATE, cand, confd, &confd->sub); diff --git a/src/confd/src/infix-factory.c b/src/confd/src/infix-factory.c index be2396023e..c793a71f6c 100644 --- a/src/confd/src/infix-factory.c +++ b/src/confd/src/infix-factory.c @@ -10,16 +10,10 @@ #include #include -#include #include #include "core.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) @@ -42,11 +36,6 @@ static int rpc(sr_session_ctx_t *session, uint32_t sub_id, const char *xpath, 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: diff --git a/src/confd/src/infix-services.c b/src/confd/src/infix-services.c index 70ff6039ae..356766ca08 100644 --- a/src/confd/src/infix-services.c +++ b/src/confd/src/infix-services.c @@ -10,7 +10,6 @@ #include #include -#include #include #include "core.h" @@ -51,13 +50,6 @@ struct mdns_svc { { ssh, "ssh", "_ssh._tcp", 22, "Secure shell command line interface (CLI)", NULL }, }; -static const struct srx_module_requirement reqs[] = { - { .dir = YANG_PATH_, .name = "infix-services", .rev = "2024-04-08" }, - { .dir = YANG_PATH_, .name = "ieee802-dot1ab-lldp", .rev = "2022-03-15" }, - { .dir = YANG_PATH_, .name = "infix-lldp", .rev = "2023-08-23" }, - { NULL } -}; - /* * On hostname changes we need to update the mDNS records, in particular * the ones advertising an adminurl (standarized by Apple), because they @@ -295,10 +287,6 @@ int infix_services_init(struct confd *confd) { int rc; - rc = srx_require_modules(confd->conn, reqs); - if (rc) - goto fail; - REGISTER_CHANGE(confd->session, "infix-services", "/infix-services:mdns", 0, mdns_change, confd, &confd->sub); REGISTER_MONITOR(confd->session, "ietf-system", "/ietf-system:system/hostname", diff --git a/src/confd/yang/ietf-netconf-acm@2018-02-14.yang b/src/confd/yang/ietf-netconf-acm@2018-02-14.yang deleted file mode 100644 index bf4855faf0..0000000000 --- a/src/confd/yang/ietf-netconf-acm@2018-02-14.yang +++ /dev/null @@ -1,464 +0,0 @@ -module ietf-netconf-acm { - - namespace "urn:ietf:params:xml:ns:yang:ietf-netconf-acm"; - - prefix nacm; - - import ietf-yang-types { - prefix yang; - } - - organization - "IETF NETCONF (Network Configuration) Working Group"; - - contact - "WG Web: - WG List: - - Author: Andy Bierman - - - Author: Martin Bjorklund - "; - - description - "Network Configuration Access Control Model. - - Copyright (c) 2012 - 2018 IETF Trust and the persons - identified as authors of the code. All rights reserved. - - Redistribution and use in source and binary forms, with or - without modification, is permitted pursuant to, and subject - to the license terms contained in, the Simplified BSD - License set forth in Section 4.c of the IETF Trust's - Legal Provisions Relating to IETF Documents - (https://trustee.ietf.org/license-info). - - This version of this YANG module is part of RFC 8341; see - the RFC itself for full legal notices."; - - revision "2018-02-14" { - description - "Added support for YANG 1.1 actions and notifications tied to - data nodes. Clarified how NACM extensions can be used by - other data models."; - reference - "RFC 8341: Network Configuration Access Control Model"; - } - - revision "2012-02-22" { - description - "Initial version."; - reference - "RFC 6536: Network Configuration Protocol (NETCONF) - Access Control Model"; - } - - /* - * Extension statements - */ - - extension default-deny-write { - description - "Used to indicate that the data model node - represents a sensitive security system parameter. - - If present, the NETCONF server will only allow the designated - 'recovery session' to have write access to the node. An - explicit access control rule is required for all other users. - - If the NACM module is used, then it must be enabled (i.e., - /nacm/enable-nacm object equals 'true'), or this extension - is ignored. - - The 'default-deny-write' extension MAY appear within a data - definition statement. It is ignored otherwise."; - } - - extension default-deny-all { - description - "Used to indicate that the data model node - controls a very sensitive security system parameter. - - If present, the NETCONF server will only allow the designated - 'recovery session' to have read, write, or execute access to - the node. An explicit access control rule is required for all - other users. - - If the NACM module is used, then it must be enabled (i.e., - /nacm/enable-nacm object equals 'true'), or this extension - is ignored. - - The 'default-deny-all' extension MAY appear within a data - definition statement, 'rpc' statement, or 'notification' - statement. It is ignored otherwise."; - } - - /* - * Derived types - */ - - typedef user-name-type { - type string { - length "1..max"; - } - description - "General-purpose username string."; - } - - typedef matchall-string-type { - type string { - pattern '\*'; - } - description - "The string containing a single asterisk '*' is used - to conceptually represent all possible values - for the particular leaf using this data type."; - } - - typedef access-operations-type { - type bits { - bit create { - description - "Any protocol operation that creates a - new data node."; - } - bit read { - description - "Any protocol operation or notification that - returns the value of a data node."; - } - bit update { - description - "Any protocol operation that alters an existing - data node."; - } - bit delete { - description - "Any protocol operation that removes a data node."; - } - bit exec { - description - "Execution access to the specified protocol operation."; - } - } - description - "Access operation."; - } - - typedef group-name-type { - type string { - length "1..max"; - pattern '[^\*].*'; - } - description - "Name of administrative group to which - users can be assigned."; - } - - typedef action-type { - type enumeration { - enum permit { - description - "Requested action is permitted."; - } - enum deny { - description - "Requested action is denied."; - } - } - description - "Action taken by the server when a particular - rule matches."; - } - - typedef node-instance-identifier { - type yang:xpath1.0; - description - "Path expression used to represent a special - data node, action, or notification instance-identifier - string. - - A node-instance-identifier value is an - unrestricted YANG instance-identifier expression. - All the same rules as an instance-identifier apply, - except that predicates for keys are optional. If a key - predicate is missing, then the node-instance-identifier - represents all possible server instances for that key. - - This XML Path Language (XPath) expression is evaluated in the - following context: - - o The set of namespace declarations are those in scope on - the leaf element where this type is used. - - o The set of variable bindings contains one variable, - 'USER', which contains the name of the user of the - current session. - - o The function library is the core function library, but - note that due to the syntax restrictions of an - instance-identifier, no functions are allowed. - - o The context node is the root node in the data tree. - - The accessible tree includes actions and notifications tied - to data nodes."; - } - - /* - * Data definition statements - */ - - container nacm { - nacm:default-deny-all; - - description - "Parameters for NETCONF access control model."; - - leaf enable-nacm { - type boolean; - default "true"; - description - "Enables or disables all NETCONF access control - enforcement. If 'true', then enforcement - is enabled. If 'false', then enforcement - is disabled."; - } - - leaf read-default { - type action-type; - default "permit"; - description - "Controls whether read access is granted if - no appropriate rule is found for a - particular read request."; - } - - leaf write-default { - type action-type; - default "deny"; - description - "Controls whether create, update, or delete access - is granted if no appropriate rule is found for a - particular write request."; - } - - leaf exec-default { - type action-type; - default "permit"; - description - "Controls whether exec access is granted if no appropriate - rule is found for a particular protocol operation request."; - } - - leaf enable-external-groups { - type boolean; - default "true"; - description - "Controls whether the server uses the groups reported by the - NETCONF transport layer when it assigns the user to a set of - NACM groups. If this leaf has the value 'false', any group - names reported by the transport layer are ignored by the - server."; - } - - leaf denied-operations { - type yang:zero-based-counter32; - config false; - mandatory true; - description - "Number of times since the server last restarted that a - protocol operation request was denied."; - } - - leaf denied-data-writes { - type yang:zero-based-counter32; - config false; - mandatory true; - description - "Number of times since the server last restarted that a - protocol operation request to alter - a configuration datastore was denied."; - } - - leaf denied-notifications { - type yang:zero-based-counter32; - config false; - mandatory true; - description - "Number of times since the server last restarted that - a notification was dropped for a subscription because - access to the event type was denied."; - } - - container groups { - description - "NETCONF access control groups."; - - list group { - key name; - - description - "One NACM group entry. This list will only contain - configured entries, not any entries learned from - any transport protocols."; - - leaf name { - type group-name-type; - description - "Group name associated with this entry."; - } - - leaf-list user-name { - type user-name-type; - description - "Each entry identifies the username of - a member of the group associated with - this entry."; - } - } - } - - list rule-list { - key name; - ordered-by user; - description - "An ordered collection of access control rules."; - - leaf name { - type string { - length "1..max"; - } - description - "Arbitrary name assigned to the rule-list."; - } - leaf-list group { - type union { - type matchall-string-type; - type group-name-type; - } - description - "List of administrative groups that will be - assigned the associated access rights - defined by the 'rule' list. - - The string '*' indicates that all groups apply to the - entry."; - } - - list rule { - key name; - ordered-by user; - description - "One access control rule. - - Rules are processed in user-defined order until a match is - found. A rule matches if 'module-name', 'rule-type', and - 'access-operations' match the request. If a rule - matches, the 'action' leaf determines whether or not - access is granted."; - - leaf name { - type string { - length "1..max"; - } - description - "Arbitrary name assigned to the rule."; - } - - leaf module-name { - type union { - type matchall-string-type; - type string; - } - default "*"; - description - "Name of the module associated with this rule. - - This leaf matches if it has the value '*' or if the - object being accessed is defined in the module with the - specified module name."; - } - choice rule-type { - description - "This choice matches if all leafs present in the rule - match the request. If no leafs are present, the - choice matches all requests."; - case protocol-operation { - leaf rpc-name { - type union { - type matchall-string-type; - type string; - } - description - "This leaf matches if it has the value '*' or if - its value equals the requested protocol operation - name."; - } - } - case notification { - leaf notification-name { - type union { - type matchall-string-type; - type string; - } - description - "This leaf matches if it has the value '*' or if its - value equals the requested notification name."; - } - } - - case data-node { - leaf path { - type node-instance-identifier; - mandatory true; - description - "Data node instance-identifier associated with the - data node, action, or notification controlled by - this rule. - - Configuration data or state data - instance-identifiers start with a top-level - data node. A complete instance-identifier is - required for this type of path value. - - The special value '/' refers to all possible - datastore contents."; - } - } - } - - leaf access-operations { - type union { - type matchall-string-type; - type access-operations-type; - } - default "*"; - description - "Access operations associated with this rule. - - This leaf matches if it has the value '*' or if the - bit corresponding to the requested operation is set."; - } - - leaf action { - type action-type; - mandatory true; - description - "The access control action associated with the - rule. If a rule has been determined to match a - particular request, then this object is used - to determine whether to permit or deny the - request."; - } - - leaf comment { - type string; - description - "A textual description of the access rule."; - } - } - } - } -} diff --git a/src/klish-plugin-infix/src/infix.c b/src/klish-plugin-infix/src/infix.c index 1c523bcf18..f2d9265f2c 100644 --- a/src/klish-plugin-infix/src/infix.c +++ b/src/klish-plugin-infix/src/infix.c @@ -43,7 +43,7 @@ struct infix_ds infix_config[] = { { "running-config", "running", SR_DS_RUNNING, 1, NULL }, { "candidate-config", "candidate", SR_DS_CANDIDATE, 1, NULL }, { "operational-config", "operational", SR_DS_OPERATIONAL, 1, NULL }, - { "factory-config", NULL, SR_DS_FACTORY_DEFAULT, 0, "/etc/factory-config.cfg" }, + { "factory-config", "factory-default", SR_DS_FACTORY_DEFAULT, 0, NULL } }; static void cd_home(kcontext_t *ctx) diff --git a/src/libsrx/src/Makefile.am b/src/libsrx/src/Makefile.am index 1b9b1cc3fe..b92a5153ce 100644 --- a/src/libsrx/src/Makefile.am +++ b/src/libsrx/src/Makefile.am @@ -6,12 +6,11 @@ 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 +pkginclude_HEADERS = common.h helpers.h lyx.h srx_val.h systemv.h pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = libsrx.pc diff --git a/src/libsrx/src/common.h b/src/libsrx/src/common.h index cda9a5b909..426b7ab6f0 100644 --- a/src/libsrx/src/common.h +++ b/src/libsrx/src/common.h @@ -6,7 +6,7 @@ #include #include #include -#include "srx_module.h" + #include "common.h" extern int debug; diff --git a/src/libsrx/src/srx_module.c b/src/libsrx/src/srx_module.c deleted file mode 100644 index 94631ce2b7..0000000000 --- a/src/libsrx/src/srx_module.c +++ /dev/null @@ -1,48 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ - -#include -#include - -#include "common.h" -#include "srx_module.h" - -sr_error_t srx_require_module(sr_conn_ctx_t *conn, const struct srx_module_requirement *mr) -{ - sr_error_t err = SR_ERR_OK; - char *path; - int len; - - len = asprintf(&path, "%s%s%s.yang", mr->name, mr->rev ? "@" : "", mr->rev ? : ""); - if (len == -1) { - ERROR("failed asprintf(): %s", strerror(errno)); - return SR_ERR_SYS; - } - - err = sr_install_module2(conn, path, mr->dir, mr->features, NULL, - "root", "wheel", 0660, NULL, NULL, 0); - free(path); - if (err == SR_ERR_EXISTS) { - /* Probably loaded as a dependency */ - err = 0; - - /* Ensure all requested features are enabled */ - for (int i = 0; mr->features[i]; i++) { - err = sr_enable_module_feature(conn, mr->name, mr->features[i]); - if (err) { - ERROR("failed enabling %s:%s, error %d", mr->name, mr->features[i], err); - } - } - } - - return err; -} - -sr_error_t srx_require_modules(sr_conn_ctx_t *conn, const struct srx_module_requirement *mrs) -{ - sr_error_t err = SR_ERR_OK; - - for (; mrs->name && !err; mrs++) - err = srx_require_module(conn, mrs); - - return err; -} diff --git a/src/libsrx/src/srx_module.h b/src/libsrx/src/srx_module.h deleted file mode 100644 index a544e209de..0000000000 --- a/src/libsrx/src/srx_module.h +++ /dev/null @@ -1,20 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ - -#ifndef CONFD_SR_EXT_H_ -#define CONFD_SR_EXT_H_ - -#include - -struct srx_module_requirement { - const char *dir; - const char *name; - const char *rev; - const char **features; -}; - -sr_error_t srx_require_module(sr_conn_ctx_t *conn, - const struct srx_module_requirement *mr); -sr_error_t srx_require_modules(sr_conn_ctx_t *conn, - const struct srx_module_requirement *mrs); - -#endif /* CONFD_SR_EXT_H_ */ diff --git a/src/statd/python/ospf_status/ospf_status.py b/src/statd/python/ospf_status/ospf_status.py index 07bf843f2a..101975117e 100755 --- a/src/statd/python/ospf_status/ospf_status.py +++ b/src/statd/python/ospf_status/ospf_status.py @@ -13,9 +13,12 @@ def main(): iface_out=subprocess.check_output("vtysh -c 'show ip ospf interface json'", shell=True) ospf_out=subprocess.check_output("vtysh -c 'show ip ospf json'", shell=True) neighbor_out=subprocess.check_output("vtysh -c 'show ip ospf neighbor detail json'", shell=True) - interfaces=json.loads(iface_out) - ospf=json.loads(ospf_out) - neighbors=json.loads(neighbor_out) + try: + interfaces=json.loads(iface_out) + ospf=json.loads(ospf_out) + neighbors=json.loads(neighbor_out) + except json.JSONDecodeError: + return {} # OSPFD is most likely not running for ifname,iface in interfaces["interfaces"].items(): iface["name"] = ifname diff --git a/src/statd/python/yanger/yanger.py b/src/statd/python/yanger/yanger.py index 2d03cb3522..c3d7680ac3 100755 --- a/src/statd/python/yanger/yanger.py +++ b/src/statd/python/yanger/yanger.py @@ -325,17 +325,27 @@ def add_ospf_routes(ospf): insert(ospf, "ietf-ospf:local-rib", "ietf-ospf:route", routes) -def add_ospf(ospf): +def add_ospf(control_protocols): """Populate OSPF status""" cmd = ['/usr/libexec/statd/ospf-status'] data = run_json_cmd(cmd, "") - ospf["ietf-ospf:router-id"] = data["routerId"] - ospf["ietf-ospf:address-family"] = "ipv4" + if data == {}: + return # No OSPF data available + + control_protocol={} + control_protocol["type"] = "ietf-ospf:ospfv2" + control_protocol["name"] = "default" + control_protocol["ietf-ospf:ospf"] = {} + control_protocol["ietf-ospf:ospf"]["ietf-ospf:areas"] = {} + + + control_protocol["ietf-ospf:ospf"]["ietf-ospf:router-id"] = data.get("routerId") + control_protocol["ietf-ospf:ospf"]["ietf-ospf:address-family"] = "ipv4" areas=[] - for area_id,values in data["areas"].items(): + for area_id,values in data.get("areas", {}).items(): area={} area["ietf-ospf:area-id"] = area_id area["ietf-ospf:interfaces"] = {} @@ -401,8 +411,9 @@ def add_ospf(ospf): area["ietf-ospf:interfaces"]["ietf-ospf:interface"] = interfaces areas.append(area) - insert(ospf, "ietf-ospf:areas", "area", areas) - add_ospf_routes(ospf) + add_ospf_routes(control_protocol["ietf-ospf:ospf"]); + control_protocol["ietf-ospf:ospf"]["ietf-ospf:areas"]["ietf-ospf:area"] = areas + insert(control_protocols, "control-plane-protocol", [control_protocol]) def get_bridge_port_pvid(ifname): data = run_json_cmd(['bridge', '-j', 'vlan', 'show', 'dev', ifname], @@ -856,20 +867,10 @@ def main(): yang_data = { "ietf-routing:routing": { "control-plane-protocols": { - "control-plane-protocol": [ - { - "type": "ietf-ospf:ospfv2", - "name": "default", - "ietf-ospf:ospf": { - "ietf-ospf:areas": - { - } - } - }] } } } - add_ospf(yang_data['ietf-routing:routing']['control-plane-protocols']['control-plane-protocol'][0]["ietf-ospf:ospf"]) + add_ospf(yang_data['ietf-routing:routing']['control-plane-protocols']) elif args.model == 'ietf-hardware': yang_data = { diff --git a/test/case/ietf_interfaces/ipv4_address.py b/test/case/ietf_interfaces/ipv4_address.py index c897507bc2..f28992171f 100755 --- a/test/case/ietf_interfaces/ipv4_address.py +++ b/test/case/ietf_interfaces/ipv4_address.py @@ -1,70 +1,15 @@ #!/usr/bin/env python3 import copy - import infamy +import infamy.iface as iface + +from infamy.util import until #Set of parameters needed to add/remove IPv4 addresses from interface new_ip_address = "10.10.10.20" new_prefix_length = 24 -def print_ip_addresses(target): - running = target.get_config_dict("/ietf-interfaces:interfaces") - interfaces = running.get("interfaces", {}).get("interface", []) - - for interface in interfaces: - name = interface["name"] - - if "ipv4" in interface: - ipv4_addresses = interface["ipv4"].get("address", []) - for ipv4_address in ipv4_addresses: - address = ipv4_address.get("ip") - prefix_length = ipv4_address.get("prefix-length") - print(f"Interface: {name}, IPv4 Address: {address}/{prefix_length}") - else: - print(f"Interface: {name}, No IPv4 Address") - - if "ipv6" in interface: - ipv6_addresses = interface["ipv6"].get("address", []) - for ipv6_address in ipv6_addresses: - address = ipv6_address.get("ip") - prefix_length = ipv6_address.get("prefix-length") - print(f"Interface: {name}, IPv6 Address: {address}/{prefix_length}") - else: - print(f"Interface: {name}, No IPv6 Address") - -def assert_ipv4_address_in_interface(target, ip_address, interface_name, prefix_length): - running = target.get_config_dict("/ietf-interfaces:interfaces") - interfaces = running.get("interfaces", {}).get("interface", []) - - found = False - - for interface in interfaces: - name = interface["name"] - - if name == interface_name: - if "ipv4" in interface: - ipv4_addresses = interface["ipv4"].get("address", []) - for ipv4_address in ipv4_addresses: - address = ipv4_address.get("ip") - length = ipv4_address.get("prefix-length") - if address == ip_address and length == prefix_length: - found = True - break - - assert found, f"IP address {ip_address}/{prefix_length} not found for interface {interface_name}" - -def assert_ipv4_removed(target, interface_name): - running = target.get_config_dict("/ietf-interfaces:interfaces") - interfaces = running.get("interfaces", {}).get("interface", []) - - for interface in interfaces: - name = interface["name"] - if name == interface_name: - assert "ipv4" not in interface, f"IPv4 address not removed from interface {interface_name}" - return - print(f"No interface with the name {interface_name}") - with infamy.Test() as test: with test.step("Setup"): env = infamy.Env(infamy.std_topology("1x1")) @@ -72,7 +17,7 @@ def assert_ipv4_removed(target, interface_name): _, interface_name = env.ltop.xlate("target", "mgmt") with test.step("Get initial IP addresses"): - print_ip_addresses(target) + print(iface.get_ipv4_address(target, interface_name)) with test.step("Configure IP address"): config = { @@ -92,23 +37,21 @@ def assert_ipv4_removed(target, interface_name): target.put_config_dict("ietf-interfaces", config) with test.step("Get updated IP addresses"): - print_ip_addresses(target) - assert_ipv4_address_in_interface(target, new_ip_address, interface_name, new_prefix_length) + until(lambda: iface.address_exist(target, interface_name, new_ip_address, proto='static')) with test.step(f"Remove IPv4 addresses from {interface_name}"): # Get current interface configuration running = target.get_config_dict("/ietf-interfaces:interfaces") new = copy.deepcopy(running) - for iface in new["interfaces"]["interface"]: - if iface["name"] == interface_name and "ipv4" in iface: - del iface["ipv4"] + for i in new["interfaces"]["interface"]: + if i["name"] == interface_name and "ipv4" in i: + del i["ipv4"] break target.put_diff_dicts("ietf-interfaces", running, new) with test.step("Get updated IP addresses"): - print_ip_addresses(target) - assert_ipv4_removed(target, interface_name) + until(lambda: iface.address_exist(target, interface_name, new_ip_address) == False) test.succeed() diff --git a/test/case/infix_interfaces/ipv4_autoconf.py b/test/case/infix_interfaces/ipv4_autoconf.py index 1ae2163932..4acf539be3 100755 --- a/test/case/infix_interfaces/ipv4_autoconf.py +++ b/test/case/infix_interfaces/ipv4_autoconf.py @@ -43,6 +43,6 @@ def has_linklocal(target, iface): }) with test.step("Wait for linklocal address on interface"): - until(lambda: has_linklocal(target, tport), attempts=10) + until(lambda: has_linklocal(target, tport), attempts=30) test.succeed() diff --git a/test/infamy/iface.py b/test/infamy/iface.py index 18e1bb6407..d9012a9d74 100644 --- a/test/infamy/iface.py +++ b/test/infamy/iface.py @@ -34,13 +34,13 @@ def interface_exist(target, iface): """Verify that the target interface exists""" return _iface_get_param(target, iface, "name") is not None -def address_exist(target, iface, address, proto="dhcp"): +def address_exist(target, iface, address, prefix_length = 24, proto="dhcp"): """Check if 'address' is set on iface""" addrs = get_ipv4_address(target, iface) if not addrs: return False for addr in addrs: - if addr['origin'] == proto and addr['ip'] == address: + if addr['origin'] == proto and addr['ip'] == address and addr['prefix-length'] == prefix_length: return True def get_ipv4_address(target, iface): diff --git a/test/infamy/route.py b/test/infamy/route.py index f2373850b0..a981b5e432 100644 --- a/test/infamy/route.py +++ b/test/infamy/route.py @@ -40,8 +40,8 @@ def ipv6_route_exist(target, prefix, nexthop=None,source_protocol=None): def _get_ospf_status(target): - xpath="/ietf-routing:routing/control-plane-protocols/control-plane-protocol/ietf-ospf:ospf" - rib = target.get_data(xpath)["routing"]["control-plane-protocols"]["control-plane-protocol"] + xpath="/ietf-routing:routing/control-plane-protocols" + rib = target.get_data(xpath)["routing"]["control-plane-protocols"].get("control-plane-protocol", {}) for p in rib: if p["type"] == "ietf-ospf:ospfv2": return p["ospf"]