Skip to content

Commit 548aac3

Browse files
committed
netopeer2 UPDATE support for new ln2 version
1 parent 57b14c6 commit 548aac3

File tree

3 files changed

+140
-46
lines changed

3 files changed

+140
-46
lines changed

scripts/common.sh

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,25 @@ NP2_MODULES=(
1818
)
1919

2020
LN2_MODULES=(
21-
"iana-ssh-encryption-algs@2022-06-16.yang"
22-
"iana-ssh-key-exchange-algs@2022-06-16.yang"
23-
"iana-ssh-mac-algs@2022-06-16.yang"
24-
"iana-ssh-public-key-algs@2022-06-16.yang"
25-
"iana-tls-cipher-suite-algs@2022-06-16.yang"
21+
"iana-ssh-encryption-algs@2024-10-16.yang"
22+
"iana-ssh-key-exchange-algs@2024-10-16.yang"
23+
"iana-ssh-mac-algs@2024-10-16.yang"
24+
"iana-ssh-public-key-algs@2024-10-16.yang"
25+
"iana-tls-cipher-suite-algs@2024-10-16.yang"
2626
2727
"[email protected] -e crypt-hash-md5 -e crypt-hash-sha-256 -e crypt-hash-sha-512"
28-
"ietf-crypto-types@2023-12-28.yang -e cleartext-passwords -e cleartext-private-keys"
29-
"ietf-keystore@2023-12-28.yang -e central-keystore-supported -e inline-definitions-supported -e asymmetric-keys"
30-
"ietf-truststore@2023-12-28.yang -e central-truststore-supported -e inline-definitions-supported -e certificates -e public-keys"
31-
"ietf-tcp-common@2023-12-28.yang -e keepalives-supported"
32-
"ietf-tcp-server@2023-12-28.yang -e tcp-server-keepalives"
33-
"ietf-tcp-client@2023-12-28.yang -e local-binding-supported -e tcp-client-keepalives"
34-
"ietf-ssh-common@2023-12-28.yang -e transport-params"
35-
"ietf-ssh-server@2023-12-28.yang -e local-users-supported -e local-user-auth-publickey -e local-user-auth-password -e local-user-auth-none"
36-
"ietf-tls-common@2023-12-28.yang -e tls10 -e tls11 -e tls12 -e tls13 -e hello-params"
37-
"ietf-tls-server@2023-12-28.yang -e server-ident-x509-cert -e client-auth-supported -e client-auth-x509-cert"
38-
"ietf-netconf-server@2023-12-28.yang -e ssh-listen -e tls-listen -e ssh-call-home -e tls-call-home -e central-netconf-server-supported"
39-
"libnetconf2-netconf-server@2025-08-01.yang"
28+
"ietf-crypto-types@2024-10-10.yang -e cleartext-passwords -e cleartext-private-keys"
29+
"ietf-keystore@2024-10-10.yang -e central-keystore-supported -e inline-definitions-supported -e asymmetric-keys"
30+
"ietf-truststore@2024-10-10.yang -e central-truststore-supported -e inline-definitions-supported -e certificates -e public-keys"
31+
"ietf-tcp-common@2024-10-10.yang -e keepalives-supported"
32+
"ietf-tcp-server@2024-10-10.yang -e tcp-server-keepalives"
33+
"ietf-tcp-client@2024-10-10.yang -e local-binding-supported -e tcp-client-keepalives"
34+
"ietf-ssh-common@2024-10-10.yang -e algorithm-discovery -e transport-params"
35+
"ietf-ssh-server@2024-10-10.yang -e local-users-supported -e local-user-auth-publickey -e local-user-auth-password -e local-user-auth-none"
36+
"ietf-tls-common@2024-10-10.yang -e algorithm-discovery -e tls12 -e tls13 -e hello-params"
37+
"ietf-tls-server@2024-10-10.yang -e server-ident-x509-cert -e client-auth-supported -e client-auth-x509-cert"
38+
"ietf-netconf-server@2025-04-24.yang -e ssh-listen -e tls-listen -e ssh-call-home -e tls-call-home -e central-netconf-server-supported"
39+
"libnetconf2-netconf-server@2025-11-11.yang"
4040
)
4141

4242
# get path to the sysrepocfg executable

scripts/merge_config.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ CONFIG="<netconf-server xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-server\
8383
<name>default-ssh</name>
8484
<ssh>
8585
<tcp-server-parameters>
86-
<local-address>0.0.0.0</local-address>
86+
<local-bind>
87+
<local-address>0.0.0.0</local-address>
88+
</local-bind>
8789
</tcp-server-parameters>
8890
<ssh-server-parameters>
8991
<server-identity>

src/main.c

Lines changed: 120 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,40 +1041,131 @@ np2srv_ssh_algs_oper_cb(sr_session_ctx_t *session, uint32_t UNUSED(sub_id), cons
10411041
const char *UNUSED(request_xpath), uint32_t UNUSED(request_id), struct lyd_node **parent,
10421042
void *UNUSED(private_data))
10431043
{
1044-
int ret = 0;
10451044
const struct ly_ctx *ly_ctx;
10461045

1047-
(void) path;
1048-
10491046
/* context is locked by the callback anyway */
10501047
ly_ctx = sr_session_acquire_context(session);
10511048
sr_session_release_context(session);
10521049

10531050
/* get oper data based on the module */
1054-
if (!strcmp(module_name, "iana-ssh-public-key-algs")) {
1055-
assert(!strcmp(path, "/iana-ssh-public-key-algs:supported-algorithms"));
1056-
ret = nc_server_config_oper_get_hostkey_algs(ly_ctx, parent);
1057-
} else if (!strcmp(module_name, "iana-ssh-key-exchange-algs")) {
1058-
assert(!strcmp(path, "/iana-ssh-key-exchange-algs:supported-algorithms"));
1059-
ret = nc_server_config_oper_get_kex_algs(ly_ctx, parent);
1060-
} else if (!strcmp(module_name, "iana-ssh-encryption-algs")) {
1061-
assert(!strcmp(path, "/iana-ssh-encryption-algs:supported-algorithms"));
1062-
ret = nc_server_config_oper_get_encryption_algs(ly_ctx, parent);
1063-
} else if (!strcmp(module_name, "iana-ssh-mac-algs")) {
1064-
assert(!strcmp(path, "/iana-ssh-mac-algs:supported-algorithms"));
1065-
ret = nc_server_config_oper_get_mac_algs(ly_ctx, parent);
1051+
if (!strcmp(module_name, "ietf-ssh-common") && !strcmp(path, "/ietf-ssh-common:supported-algorithms")) {
1052+
if (nc_server_config_oper_get_supported_ssh_algs(ly_ctx, parent)) {
1053+
return SR_ERR_INTERNAL;
1054+
}
10661055
} else {
1067-
ERR("Unable to get supported SSH algorithms (module %s not supported).", module_name);
1056+
ERR("Unable to get supported SSH algorithms for unknown module \"%s\" and path \"%s\".", module_name, path);
10681057
return SR_ERR_INTERNAL;
10691058
}
1070-
if (ret) {
1071-
ERR("Getting supported SSH algorithms failed.");
1059+
1060+
return SR_ERR_OK;
1061+
}
1062+
1063+
/**
1064+
* @brief Callback for providing TLS cipher suites operational data.
1065+
*/
1066+
static int
1067+
np2srv_tls_algs_oper_cb(sr_session_ctx_t *session, uint32_t UNUSED(sub_id), const char *module_name, const char *path,
1068+
const char *UNUSED(request_xpath), uint32_t UNUSED(request_id), struct lyd_node **parent,
1069+
void *UNUSED(private_data))
1070+
{
1071+
const struct ly_ctx *ly_ctx;
1072+
1073+
/* context is locked by the callback anyway */
1074+
ly_ctx = sr_session_acquire_context(session);
1075+
sr_session_release_context(session);
1076+
1077+
/* get oper data based on the module */
1078+
if (!strcmp(module_name, "ietf-tls-common") && !strcmp(path, "/ietf-tls-common:supported-algorithms")) {
1079+
if (nc_server_config_oper_get_supported_tls_algs(ly_ctx, parent)) {
1080+
return SR_ERR_INTERNAL;
1081+
}
1082+
} else {
1083+
ERR("Unable to get supported TLS cipher suites for unknown module \"%s\" and path \"%s\".", module_name, path);
10721084
return SR_ERR_INTERNAL;
10731085
}
10741086

10751087
return SR_ERR_OK;
10761088
}
10771089

1090+
/**
1091+
* @brief Callback for providing password last-modified operational data.
1092+
*/
1093+
static int
1094+
np2srv_password_last_modified_oper_cb(sr_session_ctx_t *session, uint32_t UNUSED(sub_id),
1095+
const char *module_name, const char *UNUSED(path), const char *UNUSED(request_xpath),
1096+
uint32_t UNUSED(request_id), struct lyd_node **parent, void *UNUSED(private_data))
1097+
{
1098+
int rc = SR_ERR_OK, r;
1099+
char *path = NULL, *time_str = NULL;
1100+
const struct ly_ctx *ly_ctx;
1101+
const char *ch_client = NULL, *endpoint = NULL, *username = NULL;
1102+
struct lyd_node *tree;
1103+
time_t last_modified;
1104+
1105+
/* context is locked by the callback anyway */
1106+
ly_ctx = sr_session_acquire_context(session);
1107+
sr_session_release_context(session);
1108+
1109+
if (strcmp(module_name, "ietf-netconf-server")) {
1110+
ERR("Unable to get password last-modified for unknown module \"%s\".", module_name);
1111+
return SR_ERR_INTERNAL;
1112+
}
1113+
1114+
/* extract keys from the parent */
1115+
tree = *parent;
1116+
while (tree->parent) {
1117+
if (!strcmp(LYD_NAME(tree), "call-home")) {
1118+
ch_client = lyd_get_value(lyd_child(tree));
1119+
} else if (!strcmp(LYD_NAME(tree), "endpoint")) {
1120+
endpoint = lyd_get_value(lyd_child(tree));
1121+
} else if (!strcmp(LYD_NAME(tree), "user")) {
1122+
username = lyd_get_value(lyd_child(tree));
1123+
}
1124+
tree = lyd_parent(tree);
1125+
}
1126+
1127+
if (!endpoint || !username) {
1128+
ERR("Not enough information to get password last-modified.");
1129+
return SR_ERR_INTERNAL;
1130+
}
1131+
1132+
/* get the last modified time */
1133+
if (nc_server_config_oper_get_user_password_last_modified(ch_client, endpoint, username, &last_modified)) {
1134+
return SR_ERR_INTERNAL;
1135+
}
1136+
1137+
/* format the time */
1138+
if (ly_time_time2str(last_modified, NULL, &time_str)) {
1139+
return SR_ERR_INTERNAL;
1140+
}
1141+
1142+
/* create the path to the last-modified node */
1143+
if (ch_client) {
1144+
r = asprintf(&path, "/ietf-netconf-server:netconf-server/call-home/netconf-client[name='%s']/endpoints/"
1145+
"endpoint[name='%s']/ssh/ssh-server-parameters/client-authentication/users/user[name='%s']/password/"
1146+
"last-modified", ch_client, endpoint, username);
1147+
} else {
1148+
r = asprintf(&path, "/ietf-netconf-server:netconf-server/listen/endpoints/endpoint[name='%s']/ssh/"
1149+
"ssh-server-parameters/client-authentication/users/user[name='%s']/password/last-modified",
1150+
endpoint, username);
1151+
}
1152+
if (r == -1) {
1153+
rc = SR_ERR_INTERNAL;
1154+
goto cleanup;
1155+
}
1156+
1157+
/* create the last-modified node */
1158+
if (lyd_new_path(NULL, ly_ctx, path, time_str, 0, parent)) {
1159+
rc = SR_ERR_INTERNAL;
1160+
goto cleanup;
1161+
}
1162+
1163+
cleanup:
1164+
free(path);
1165+
free(time_str);
1166+
return rc;
1167+
}
1168+
10781169
#endif /* NC_ENABLED_SSH_TLS */
10791170

10801171
/**
@@ -1126,18 +1217,19 @@ server_data_subscribe(void)
11261217
}
11271218

11281219
#ifdef NC_ENABLED_SSH_TLS
1129-
/* set callbacks for supported algorithms oper data */
1130-
mod_name = "iana-ssh-public-key-algs";
1131-
SR_OPER_SUBSCR(mod_name, "/iana-ssh-public-key-algs:supported-algorithms", np2srv_ssh_algs_oper_cb);
1132-
1133-
mod_name = "iana-ssh-key-exchange-algs";
1134-
SR_OPER_SUBSCR(mod_name, "/iana-ssh-key-exchange-algs:supported-algorithms", np2srv_ssh_algs_oper_cb);
1220+
/* set callbacks for supported SSH algorithms and TLS cipher suites oper data */
1221+
mod_name = "ietf-ssh-common";
1222+
SR_OPER_SUBSCR(mod_name, "/ietf-ssh-common:supported-algorithms", np2srv_ssh_algs_oper_cb);
11351223

1136-
mod_name = "iana-ssh-encryption-algs";
1137-
SR_OPER_SUBSCR(mod_name, "/iana-ssh-encryption-algs:supported-algorithms", np2srv_ssh_algs_oper_cb);
1224+
mod_name = "ietf-tls-common";
1225+
SR_OPER_SUBSCR(mod_name, "/ietf-tls-common:supported-algorithms", np2srv_tls_algs_oper_cb);
11381226

1139-
mod_name = "iana-ssh-mac-algs";
1140-
SR_OPER_SUBSCR(mod_name, "/iana-ssh-mac-algs:supported-algorithms", np2srv_ssh_algs_oper_cb);
1227+
/* password last modified oper data for both listen + call-home SSH users */
1228+
mod_name = "ietf-netconf-server";
1229+
SR_OPER_SUBSCR(mod_name, "/ietf-netconf-server:netconf-server/listen/endpoints/endpoint/ssh/"
1230+
"ssh-server-parameters/client-authentication/users/user/password/last-modified", np2srv_password_last_modified_oper_cb);
1231+
SR_OPER_SUBSCR(mod_name, "/ietf-netconf-server:netconf-server/call-home/netconf-client/endpoints/endpoint/ssh/"
1232+
"ssh-server-parameters/client-authentication/users/user/password/last-modified", np2srv_password_last_modified_oper_cb);
11411233
#endif /* NC_ENABLED_SSH_TLS */
11421234

11431235
/* subscriptions to running DS */

0 commit comments

Comments
 (0)