From 6933e0961cd07a79b2af6a9f113f1cd38c034aef Mon Sep 17 00:00:00 2001 From: schaveyt Date: Sun, 16 Jun 2024 05:41:41 -0400 Subject: [PATCH] Fix netconf framing protocol (#946) * 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. * fix NETCONF to comply with RFC6242 for framing protocol * netcconf client - fix null ptr exception on dispose * netcconf client - provide example usage in xml doc * add comment --------- Co-authored-by: Jason Larke Co-authored-by: Todd Schavey Co-authored-by: Robert Hague Co-authored-by: Rob Hague --- src/Renci.SshNet/NetConfClient.cs | 13 +++++++++++++ src/Renci.SshNet/Netconf/NetConfSession.cs | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/src/Renci.SshNet/NetConfClient.cs b/src/Renci.SshNet/NetConfClient.cs index e9ebace4..e4b66ad9 100644 --- a/src/Renci.SshNet/NetConfClient.cs +++ b/src/Renci.SshNet/NetConfClient.cs @@ -208,6 +208,13 @@ namespace Renci.SshNet /// /// Sends the receive RPC. /// + /// + /// + /// var rpcXmlTemplate = "{0}"' + /// rpc.LoadXml(String.Format(rpcXmlTemplate, "")); + /// var rpcResponse = client.SendReceiveRpc(rpc); + /// + /// /// The RPC. /// /// Reply message to RPC request. @@ -226,6 +233,12 @@ namespace Renci.SshNet /// /// Sends the receive RPC. /// + /// + /// + /// var rpcXmlTemplate = "{0}"' + /// var rpcResponse = client.SendReceiveRpc(String.Format(rpcXmlTemplate, "")); + /// + /// /// The XML. /// /// Reply message to RPC request. diff --git a/src/Renci.SshNet/Netconf/NetConfSession.cs b/src/Renci.SshNet/Netconf/NetConfSession.cs index b6da4779..d844a316 100644 --- a/src/Renci.SshNet/Netconf/NetConfSession.cs +++ b/src/Renci.SshNet/Netconf/NetConfSession.cs @@ -152,6 +152,10 @@ namespace Renci.SshNet.NetConf const string xpath = "/nc:hello/nc:capabilities/nc:capability[text()='urn:ietf:params:netconf:base:1.1']"; + // 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. + // 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.