libyang icon indicating copy to clipboard operation
libyang copied to clipboard

List instance is missing its key error while parse

Open sicongPang opened this issue 2 years ago • 10 comments

hi When I try to use libyang 2.1.30 to parse the rpc message, the error message "List instance is missing its key "OCSAddr" is displayed. My message is in XML format. By analyzing the code, he reported an error in the lydxml_subtree_r->lyd_parse_check_keys function.

Here's the modeling information I've provided:

container OCSStatuss {
      list OCSStatus {
        key "HostName ResourceUnit LocAddr SubLocAddr OCSAddr";
        config false;
        description
          "OCS Status";
        leaf RecId {
          type uint32 {
            range "0..4294967295";
          }
          mandatory false;
          description
            "Record ID";
          mo:indexAssignMode "INC";
        }
        leaf HostName {
          type string {
            length "0..127";
          }
          mandatory false;
          description
            "OCS Host Name";
          mo:indexAssignMode "MIN";
        }
        leaf SpuGrp {
          type uint32 {
            range "1";
          }
          mandatory false;
          description
            "SPU Group ID";
          mo:indexAssignMode "MIN";
        }
        leaf ResourceUnit {
          type string {
            length "0..63";
          }
          mandatory false;
          description
            "RU Name";
          mo:indexAssignMode "MIN";
        }
        leaf LocAddr {
          type string {
            length "0..63";
          }
           mandatory false;
           description
             "Local Address";
           mo:indexAssignMode "MIN";
         }
         leaf SubLocAddr {
           type string {
             length "0..63";
           }
           mandatory false;
           description
             "Local Sub-Address";
           mo:indexAssignMode "MIN";
         }
         leaf OCSAddr {
           type string {
             length "0..63";
           }
           mandatory false;
           description
             "Peer Address";
           mo:indexAssignMode "MIN";
         }
         leaf LocalHostName {
           type string {
             length "0..127";
           }
           mandatory false;
           description
             "Local Host Name";
           mo:indexAssignMode "MIN";
         }
       }
    }

This is the get request message I sent: image

According to the node parameter of the lyd_parse_check_keys function, the key field OCSAddr is behind a non-key. As a result, the function reports an error. image

sicongPang avatar Nov 27 '23 12:11 sicongPang

What netopeer2-server version are you using? It worked fine using the current devel version.

michalvasko avatar Nov 27 '23 14:11 michalvasko

The libnetconf2 2.1.28 version is used.

I reconstructed another model, and it worked fine, as shown in the following figure. image

But once I used the above mentioned model "OCSStatuss", the problem revealed that none of my other behaviors changed, which I was puzzled by. image

sicongPang avatar Nov 27 '23 14:11 sicongPang

I have tested your exact module and could not reproduce it.

michalvasko avatar Nov 27 '23 15:11 michalvasko

I tried to verify the problem with different versions and found that the problem was fixed between 2.1.111 and 2.1.128. Have you fixed this problem between the two versions? If there is a similar commit record for my reference, I would appreciate it. image

sicongPang avatar Nov 28 '23 13:11 sicongPang

You are free to go commit-by-commit and find the one that fixed it, but it is not part of the support we provide.

michalvasko avatar Nov 28 '23 13:11 michalvasko

Hello, this problem recurs when I trigger the same operation above with the new yang model, and I am using libyang version 2.1.128:

typedef SUBSINFO_TYPE {
      type enumeration {
        enum "LOCAL_AGGR_EVT" {
          description
            "Local Aggregation Event";
          value 4;
        }
        enum "LOCAL_FLT_EVT" {
          description
            "Local Filter Event";
          value 3;
        }
        enum "LOCAL_RPT_EVT" {
          description
            "Local RPT Event";
          value 2;
        }
        enum "LOCAL_TOPN_EVT" {
          description
            "Local Topn Event";
          value 5;
        }
        enum "SUBS_CONFIG" {
          description
            "Subscription configuration";
          value 1;
        }
        enum "SUBS_POLICY" {
          description
            "Subscription Policy";
          value 0;
        }
      }
    }

    typedef SUBS_CONFIG_TYPE {
      type enumeration {
        enum "CONFIG_TYPE_FILTERGROUP" {
          description
            "Config Filter Group";
          value 1;
        }
        enum "CONFIG_TYPE_HIGHBAND" {
          description
            "High-bandwidth User Rule";
          value 3;
        }
        enum "CONFIG_TYPE_QOSMONITOR" {
          description
            "Qos Monitor Rule";
          value 2;
        }
        enum "CONFIG_TYPE_REALRPT" {
          description
            "Real Report";
          value 0;
        }
        enum "CONFIG_TYPE_USRTATS" {
          description
            "UserStats";
          value 5;
        }
        enum "CONFIG_TYPE_VVIP" {
          description
            "VVIP";
          value 4;
        }
        enum "CONFIG_TYPE_CCO_ABRVIDEO" {
          description
            "CCO ABR Video Rule";
          value 7;
        }
        enum "CONFIG_TYPE_CCO_CELLLEVEL" {
          description
            "CCO Cell Level Rule";
          value 8;
        }
        enum "CONFIG_TYPE_CCO_CELLSPEC" {
          description
            "CCO Cell Spec Rule";
          value 6;
        }
        enum "CONFIG_TYPE_CCO_CTRL" {
          description
            "CCO Ctrl Rule";
          value 9;
        }
      }
    }
container RptSubsInfos {
      list RptSubsInfo {
        key "Result";
        config false;
        description
          "Display Report Subscribe Information";
        leaf Type {
          type SUBSINFO_TYPE;
          mandatory false;
          description
            "Type";
          mo:indexAssignMode "MIN";
        }
        leaf SubsPolicyId {
          type uint32 {
            range "0..4294967295";
          }
          mandatory false;
          description
            "Subscribe Policy ID";
          mo:indexAssignMode "MIN";
        }
        leaf Result {
          type string {
            length "0..29000";
          }
          mandatory false;
          description
            "Result";
          mo:indexAssignMode "MIN";
        }
        leaf SubsConfigType {
          type SUBS_CONFIG_TYPE;
          mandatory false;
          description
            "Subscription Configuration Type";
          mo:indexAssignMode "MIN";
        }
      }
    }

I triggered this with the following netconf get request:

<?xml version="1.0" encoding="UTF8"?>
<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="1" pid="1766902592">
  <get>
    <filter type="subtree">
      <RptSubsInfos xmlns="test:test-rfc6241">
        <RptSubsInfo>
          <Type>SUBS_CONFIG</Type>
          <SubsPolicyId/>
          <Result/>
          <SubsConfigType>CONFIG_TYPE_FILTERGROUP</SubsConfigType>
        </RptSubsInfo>
      </RptSubsInfos>
    </filter>
  </get>
</rpc>

Here are my test results: image

sicongPang avatar Dec 08 '23 08:12 sicongPang

By printing the content in the lyd_insert_node function, I found that when the key is inserted into the third node or later, first_sibling->prev equals first_sibling->next. As a result, the key cannot be inserted into the first node. image image

The above part comes from the commit record: https://github.com/CESNET/libyang/commit/6a0bb25952429185c42974d6dab31bbf39083925 Finally, the lyd_parse_check_keys function fails. The information about the node parameter is as follows: image

sicongPang avatar Dec 08 '23 10:12 sicongPang

Thanks for the example, it should be fixed in the latest libyang, test added into netopeer2.

michalvasko avatar Dec 14 '23 09:12 michalvasko

@michalvasko @sicongPang I've had the same problem, but I don't think it's a bug. According to RFC7950 7.8.5: The rest of the list’s child nodes are encoded as subelements to the list element, after the keys.

NextLitete avatar Feb 23 '24 03:02 NextLitete

Fair enough, I suppose it can be considered to be a minor extension but it is generally accepted that this should be supported in practice.

michalvasko avatar Feb 23 '24 09:02 michalvasko