CESNET / libyang

YANG data modeling language library
BSD 3-Clause "New" or "Revised" License
368 stars 291 forks source link

get filter-subtree fails to match valid configured IPv6 address #953

Closed iffy50 closed 2 years ago

iffy50 commented 4 years ago

When I try and retrieve configuration for an IPv6 address on an interface, if the address supplied is not syntactically the same as the way the OS is representing the address:

Steps to recreate:

Address configured on an interface, represented as follows: inet6 2001:db8:c1:bff::509f:f045:0/128 scope global

nopeer2-cli, get --filter-subtree with the following filter:

<interfaces-state xmlns='urn:ietf:params:xml:ns:yang:ietf-interfaces'>
    <interface>
        <name>wan_4_</name>
        <ipv6 xmlns='urn:ietf:params:xml:ns:yang:ietf-ip'>
            <address>
                <ip>2001:db8:c1:bff:0:509f:f045:0</ip>
                <prefix-length></prefix-length>
                <ip/>
                <origin/>
                <status/>
            </address>
        </ipv6>
    </interface>
</interfaces-state>

returns:

DATA
<interfaces-state xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">
  <interface>
    <name>wan_4_</name>
  </interface>
</interfaces-state>

However, if the '0' is removed from the middle of the ip field (2001:db8:c1:bff::509f:f045:0 instead of 2001:db8:c1:bff:0:509f:f045:0) with the following filter:

<interfaces-state xmlns='urn:ietf:params:xml:ns:yang:ietf-interfaces'>
    <interface>
        <name>wan_4_</name>
        <ipv6 xmlns='urn:ietf:params:xml:ns:yang:ietf-ip'>
            <address>
                <ip>2001:db8:c1:bff::509f:f045:0</ip>
                <prefix-length></prefix-length>
                <ip/>
                <origin/>
                <status/>
            </address>
        </ipv6>
    </interface>
</interfaces-state>

The following is returned:

DATA
<interfaces-state xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">
  <interface>
    <name>wan_4_</name>
    <ipv6 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip">
      <address>
        <ip>2001:db8:c1:bff::509f:f045:0</ip>
        <prefix-length>128</prefix-length>
      </address>
    </ipv6>
  </interface>
</interfaces-state>

As in both examples, the same address is given using valid RFC5952 formats, the address in the filter should work correctly and match the configured address.

michalvasko commented 4 years ago

Hi, what exact libyang version have you installed? I think it may have been fixed fairly recently.

Regards, Michal

iffy50 commented 4 years ago

The filename is libyang.so.0.16.105. Is there a better way of getting the version?

michalvasko commented 4 years ago

Hi, that is fine. The SOVERSION version you should try is at least 1.2.11 or simply grab the latest master or devel. You should not have this problem with it.

Regards, Michal

iffy50 commented 4 years ago

Hi, What are the dependencies for this? Does it require the new sysrepo etc?

Thanks, Ian

michalvasko commented 4 years ago

Hi, no, just replace your installed libyang version with the updated one, nothing else is needed.

Regards, Michal

iffy50 commented 4 years ago

Hi, I have libyang working now, and have tested again. I am getting different results to before, but it is still not working as expected. If I use the following address in the filter

<ip>2001:db8:c1:bff::509f:f045:0</ip>

DATA
<interfaces-state xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">
  <interface>
    <name>wan_4_</name>
    <ipv6 xmlns="urn:ietf:params:xml:ns:yang:ietf-ip">
      <address>
        <ip>2001:db8:c1:bff::509f:f045:0</ip>
        <prefix-length>128</prefix-length>
      </address>
    </ipv6>
  </interface>
</interfaces-state>

But if I use:

<ip>2001:db8:c1:bff:0:509f:f045:0</ip>

> get --filter-subtree
DATA
<interfaces-state xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">
  <interface>
    <name>wan_4_</name>
  </interface>
</interfaces-state>

This is using libyang 1.4.1 (the compiled name built from v1.0-r5 release)

michalvasko commented 4 years ago

Hi, I have tried this and have not managed to reproduce it and I am quite sure the libyang version you are using has fixed the problem. The thing to notice here is that netopeer2 (libyang) always returns data in the canonical format. But the value

<ip>2001:db8:c1:bff::509f:f045:0</ip>

is not canonical (you cannot shorten just one 0 to ::). When I was testing it it was correctly printed with the 0. So, it seems you are not using libyang 1.4.1 or you are using an old ietf-inet-types plugin version. So, my suggestion would be to completely uninstall libyang on the target system so that there are no shared library and especially no plugins (default installed path is /usr/local/lib/libyang/user_types/) and reinstall libyang. It really should work then.

Regards, Michal

iffy50 commented 4 years ago

Interesting. It depends on which section of RFC5929 you believe! Section 2.2:

2.2.  Zero Compression
      ’A special syntax is available to compress the zeros.  The use of
      "::" indicates one or more groups of 16 bits of zeros.’

But section 4.2.2:

4.2.2.  Handling One 16-Bit 0 Field
   The symbol "::" MUST NOT be used to shorten just one 16-bit 0 field.
   For example, the representation 2001:db8:0:1:1:1:1:1 is correct, but
   2001:db8::1:1:1:1:1 is not correct.

There's errata on this, but it's not verified.

However, I've tested a few other address formats for the filter which definitely should work and these are not working either. e.g.:

<ip>2001:db8:00c1:0bff:0000:509f:f045:0000</ip>
<ip>2001:db8:00c1:bff:0:509f:f045:0</ip>
<ip>2001:db8:c1:bff:0000:509f:f045:0</ip>
michalvasko commented 4 years ago

Hi, okay, my main point was not what exactly the canonical format should be (current version uses inet_ntop(3) so that should definitely be correct) but rather that the canonical format you are seeing does not match the one I have seen when using the latest version. So, again, please make sure the server is really linked against the latest libyang version and this libyang uses the latest user_inet_types.so type plugin.

Regards, Michal

iffy50 commented 4 years ago

Hi. Ah, I missed the libyang directory (in the OpenWRT build, it's located in a hidden directory). I've now put all of the relevant libyang files into place and netopeer2-server/sysrepo won't start. This is mismatches in the versions. E,g. when I start netopeer2-cli:

netopeer2-cli
Error loading shared library libyang.so.0.16: No such file or directory (needed by /bin/netopeer2-cli)
Error loading shared library libyang.so.0.16: No such file or directory (needed by /usr/lib/libnetconf2.so.0.12)
...

So, I'm trying to build the lastest versions of the dependencies. However, libnetconf2-0.12-r2 build fails with:

[  7%] Building C object CMakeFiles/netconf2.dir/src/io.c.o
/home/dtadmin/test2/iopsyswrt/build_dir/target-arm_xscale_musl_eabi/libnetconf2-0.12-r2/src/io.c: In function 'nc_ssl_error_get_reasons':
/home/dtadmin/test2/iopsyswrt/build_dir/target-arm_xscale_musl_eabi/libnetconf2-0.12-r2/src/io.c:65:9: error: format not a string literal and no format arguments [-Werror=format-security]
         reason_len += sprintf(reasons + reason_len, ERR_reason_error_string(e));
         ^
cc1: some warnings

Any clues on how to fix this? Regards, Ian

michalvasko commented 4 years ago

Hi Ian, it seems you need this fix, which is not in 0.12-r2. Can you just use the latest master for now?

Regards, Michal