From 1cecea641489a7b2575f4e552ed1fa7b9562ce89 Mon Sep 17 00:00:00 2001 From: Jason Larke Date: Tue, 10 Mar 2020 12:02:30 +0800 Subject: [PATCH 1/5] Updated NETCONF framing protocol detection to check both client & server capabilities This fixes an issue where the NetConfSession would expect the framing protocol to be used if ServerCapabilities contained 1.1, however the server would actually be using the legacy protocol as the client only advertises support for 1.0. --- src/Renci.SshNet/Netconf/NetConfSession.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Renci.SshNet/Netconf/NetConfSession.cs b/src/Renci.SshNet/Netconf/NetConfSession.cs index 14ba00a6e..360a965d0 100644 --- a/src/Renci.SshNet/Netconf/NetConfSession.cs +++ b/src/Renci.SshNet/Netconf/NetConfSession.cs @@ -131,7 +131,10 @@ protected override void OnDataReceived(byte[] data) var nsMgr = new XmlNamespaceManager(ServerCapabilities.NameTable); nsMgr.AddNamespace("nc", "urn:ietf:params:xml:ns:netconf:base:1.0"); - _usingFramingProtocol = (ServerCapabilities.SelectSingleNode("/nc:hello/nc:capabilities/nc:capability[text()='urn:ietf:params:netconf:base:1.1']", nsMgr) != null); + var xpath = "/nc:hello/nc:capabilities/nc:capability[text()='urn:ietf:params:netconf:base:1.1']"; + + _usingFramingProtocol = ServerCapabilities.SelectSingleNode(xpath, nsMgr) != null + && ClientCapabilities.SelectSingleNode(xpath, nsMgr) != null; _serverCapabilitiesConfirmed.Set(); } From 76c002e072f45fd5f035eeab4668a77df80f7ca6 Mon Sep 17 00:00:00 2001 From: Todd Schavey Date: Sat, 2 Apr 2022 21:29:20 -0400 Subject: [PATCH 2/5] fix NETCONF to comply with RFC6242 for framing protocol --- src/Renci.SshNet/Netconf/NetConfSession.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Renci.SshNet/Netconf/NetConfSession.cs b/src/Renci.SshNet/Netconf/NetConfSession.cs index 14ba00a6e..ef108e12d 100644 --- a/src/Renci.SshNet/Netconf/NetConfSession.cs +++ b/src/Renci.SshNet/Netconf/NetConfSession.cs @@ -128,10 +128,13 @@ protected override void OnDataReceived(byte[] data) throw new NetConfServerException("Server capabilities received are not well formed XML", e); } - var nsMgr = new XmlNamespaceManager(ServerCapabilities.NameTable); - nsMgr.AddNamespace("nc", "urn:ietf:params:xml:ns:netconf:base:1.0"); - - _usingFramingProtocol = (ServerCapabilities.SelectSingleNode("/nc:hello/nc:capabilities/nc:capability[text()='urn:ietf:params:netconf:base:1.1']", nsMgr) != null); + // Per RFC6242 section 4.1, If the :base:1.1 capability is advertised by both + // peers, the chunked transfer mechanism is used for the remainder of the NETCONF + // session. Otherwise, the old end-of-message based mechanism(see Section 4.3) is used. + // + // Because this client only support :base:1.0 capability and not :base:1.1, the + // the framing protocal is set to disabled/false. + _usingFramingProtocol = false; _serverCapabilitiesConfirmed.Set(); } From 7f7bed39b03030d6c51eb42488e2ab2c854ee07e Mon Sep 17 00:00:00 2001 From: Todd Schavey Date: Sat, 2 Apr 2022 21:30:17 -0400 Subject: [PATCH 3/5] netcconf client - fix null ptr exception on dispose --- src/Renci.SshNet/NetConfClient.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Renci.SshNet/NetConfClient.cs b/src/Renci.SshNet/NetConfClient.cs index b7ec82ec2..49857328c 100644 --- a/src/Renci.SshNet/NetConfClient.cs +++ b/src/Renci.SshNet/NetConfClient.cs @@ -241,7 +241,8 @@ protected override void OnDisconnecting() { base.OnDisconnecting(); - _netConfSession.Disconnect(); + if (_netConfSession != null) + _netConfSession.Disconnect(); } /// From 99ec4ab86238c45668529cc8ead65e086d9898d5 Mon Sep 17 00:00:00 2001 From: Todd Schavey Date: Sat, 2 Apr 2022 21:37:23 -0400 Subject: [PATCH 4/5] netcconf client - provide example usage in xml doc --- src/Renci.SshNet/NetConfClient.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Renci.SshNet/NetConfClient.cs b/src/Renci.SshNet/NetConfClient.cs index 49857328c..9765d192d 100644 --- a/src/Renci.SshNet/NetConfClient.cs +++ b/src/Renci.SshNet/NetConfClient.cs @@ -192,6 +192,11 @@ public XmlDocument ClientCapabilities /// /// Sends the receive RPC. /// + /// + /// var rpcXmlTemplate = "{0}"' + /// rpc.LoadXml(String.Format(rpcXmlTemplate, "")); + /// var rpcResponse = client.SendReceiveRpc(rpc); + /// /// The RPC. /// Reply message to RPC request /// Client is not connected. @@ -203,6 +208,10 @@ public XmlDocument SendReceiveRpc(XmlDocument rpc) /// /// Sends the receive RPC. /// + /// + /// var rpcXmlTemplate = "{0}"' + /// var rpcResponse = client.SendReceiveRpc(String.Format(rpcXmlTemplate, "")); + /// /// The XML. /// Reply message to RPC request public XmlDocument SendReceiveRpc(string xml) From 0157a2df6fbb2bcb9199cabc50c378965b246992 Mon Sep 17 00:00:00 2001 From: Rob Hague Date: Sun, 16 Jun 2024 10:54:14 +0200 Subject: [PATCH 5/5] add comment --- src/Renci.SshNet/Netconf/NetConfSession.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Renci.SshNet/Netconf/NetConfSession.cs b/src/Renci.SshNet/Netconf/NetConfSession.cs index 1e39ec252..b6da47799 100644 --- a/src/Renci.SshNet/Netconf/NetConfSession.cs +++ b/src/Renci.SshNet/Netconf/NetConfSession.cs @@ -152,6 +152,9 @@ protected override void OnDataReceived(byte[] data) const string xpath = "/nc:hello/nc:capabilities/nc:capability[text()='urn:ietf:params:netconf:base:1.1']"; + // This will currently evaluate to false since we (the client) do not advertise 1.1 capability. + // Despite some code existing for the 1.1 framing protocol, it is thought to be incorrect or + // incomplete. The NETCONF code is practically untested at the time of writing. _usingFramingProtocol = ServerCapabilities.SelectSingleNode(xpath, nsMgr) != null && ClientCapabilities.SelectSingleNode(xpath, nsMgr) != null;