Skip to content

Commit

Permalink
Fix netconf framing protocol (#946)
Browse files Browse the repository at this point in the history
* 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 <jason.larke@curtin.edu.au>
Co-authored-by: Todd Schavey <todd.schavey@ge.com>
Co-authored-by: Robert Hague <rh@johnstreetcapital.com>
Co-authored-by: Rob Hague <rob.hague00@gmail.com>
  • Loading branch information
5 people authored Jun 16, 2024
1 parent 0effbd7 commit 6933e09
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Renci.SshNet/NetConfClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,13 @@ public XmlDocument ClientCapabilities
/// <summary>
/// Sends the receive RPC.
/// </summary>
/// <example>
/// <code>
/// var rpcXmlTemplate = "<rpc xmlns='urn:ietf:params:xml:ns:netconf:base:1.0' message-id='1'>{0}</rpc>"'
/// rpc.LoadXml(String.Format(rpcXmlTemplate, "<get-config><source><running/></source></get-config>"));
/// var rpcResponse = client.SendReceiveRpc(rpc);
/// </code>
/// </example>
/// <param name="rpc">The RPC.</param>
/// <returns>
/// Reply message to RPC request.
Expand All @@ -226,6 +233,12 @@ public XmlDocument SendReceiveRpc(XmlDocument rpc)
/// <summary>
/// Sends the receive RPC.
/// </summary>
/// <example>
/// <code>
/// var rpcXmlTemplate = "<rpc xmlns='urn:ietf:params:xml:ns:netconf:base:1.0' message-id='1'>{0}</rpc>"'
/// var rpcResponse = client.SendReceiveRpc(String.Format(rpcXmlTemplate, "<get-config><source><running/></source></get-config>"));
/// </code>
/// </example>
/// <param name="xml">The XML.</param>
/// <returns>
/// Reply message to RPC request.
Expand Down
4 changes: 4 additions & 0 deletions src/Renci.SshNet/Netconf/NetConfSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ protected override void OnDataReceived(byte[] data)

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.
Expand Down

0 comments on commit 6933e09

Please sign in to comment.