Support connecting to NETCONF clients via SSH
libnetconf doesn't have nice APIs for ssh connection, but allows users
to supply the connection by themselves. One way is to use libssh (which
libnetconf uses) and supply that. However, I found that using libssh to
implement an interactive CLI isn't very easy and I'd have to implement a
lot of functionality (like authentication) by myself, attempts were
made, but I was really only imitating the interface of OpenSSH.
Fortunately, libnetconf can also communicate over file descriptors, and
it is easy to get that from OpenSSH, so I fork it and use its
stdin/stdout. On top of that, OpenSSH is very clever and knows that I'm
using it like this, so it still allows entering passwords and accepting
host keys even though its stdin/stdout isn't a terminal.
Change-Id: I27816e038bed0a82a028c8e83c15455fd514c35e
diff --git a/src/netconf_access.hpp b/src/netconf_access.hpp
index 29dfd75..45973a6 100644
--- a/src/netconf_access.hpp
+++ b/src/netconf_access.hpp
@@ -7,6 +7,7 @@
#pragma once
+#include <libnetconf2/log.h>
#include <string>
#include "datastore_access.hpp"
@@ -27,6 +28,8 @@
class Schema;
class YangSchema;
+using LogCb = std::function<void(NC_VERB_LEVEL, const char*)>;
+
class NetconfAccess : public DatastoreAccess {
public:
NetconfAccess(const std::string& hostname, uint16_t port, const std::string& user, const std::string& pubKey, const std::string& privKey);
@@ -35,6 +38,9 @@
NetconfAccess(std::unique_ptr<libnetconf::client::Session>&& session);
~NetconfAccess() override;
[[nodiscard]] Tree getItems(const std::string& path) const override;
+
+ static void setNcLogLevel(NC_VERB_LEVEL level);
+ static void setNcLogCallback(const LogCb& callback);
void setLeaf(const std::string& path, leaf_data_ value) override;
void createItem(const std::string& path) override;
void deleteItem(const std::string& path) override;