CESNET / libyang

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

resolve_identref() interpret the xmlns prefix as module name #449

Closed darshana-jk closed 6 years ago

darshana-jk commented 6 years ago

Description

resolve_identref (..., ident_name="ianaift:fastdsl", ....) interpret the ianaift as a module eventhough its the namespace prefix.

Steps to Reproduce

  1. Build the latest devel branches of sysrepo, Netopeer2, libyang & libnetconf2. Below patch required to sysrepo: just to prevent interference by sysrepo examples.
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index e5916ca..30c3184 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -49,7 +49,3 @@ macro(INSTALL_EXAMPLE_YANG MODULE_NAME REVISION)
     EXEC_AT_INSTALL_TIME(${CMD})
 endmacro(INSTALL_EXAMPLE_YANG)

-INSTALL_EXAMPLE_YANG("turing-machine" "")
-INSTALL_EXAMPLE_YANG("iana-if-type" "")
-INSTALL_EXAMPLE_YANG("ietf-ip" "@2014-06-16")
-INSTALL_EXAMPLE_YANG("ietf-interfaces" "@2014-05-08")
diff --git a/examples/oper_data_example.c b/examples/oper_data_example.c
index 14bf62a..84c9aec 100644
--- a/examples/oper_data_example.c
+++ b/examples/oper_data_example.c
@@ -50,9 +50,6 @@ data_provider_cb(const char *xpath, sr_val_t **values, size_t *values_cnt, void
             return rc;
         }

-        sr_val_set_xpath(&v[0], "/ietf-interfaces:interfaces-state/interface[name='eth0']/type");
-        sr_val_set_str_data(&v[0], SR_IDENTITYREF_T, "ethernetCsmacd");
-
         sr_val_set_xpath(&v[1], "/ietf-interfaces:interfaces-state/interface[name='eth0']/oper-status");
         sr_val_set_str_data(&v[1], SR_ENUM_T, "down");
  1. Load modules and data: data.tar.gz load-data.sh to load yang files and data.
  2. Run the daemons, sysrepo/examples/oper_data_example, connect to Netopeer-2server. Run the RFC:
    
    <rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="5">
    <get>
    <filter type="subtree">
      <interfaces-state xmlns="urn:ietf:params:xml:ns:yang:ietf-interfaces">
        <interface>
          <type xmlns:ianaift="urn:ietf:params:xml:ns:yang:iana-if-type">ianaift:fastdsl</type>
          <name/>
          <admin-status/>
          <oper-status/>
        </interface>
      </interfaces-state>
    </filter>
    </get>
    </rpc>
**Expected behavior:**
get reply should come back with data.

**Actual behavior:**
Empty data:

### logs

[INF] (rp_dt_get_values_wrapper_with_opts:1351) Get items request running datastore, xpath: /ietf-interfaces:interfaces-state/interface[type='ianaift:fastdsl']/oper-status//., offset: 0, limit: 100 [DBG] (dm_get_data_info_internal:2689) Module ietf-interfaces already loaded [DBG] (dm_get_data_info_internal:2689) Module ietf-interfaces already loaded

[DBG] (dm_module_clb:421) CALLBACK FOR MODULE ianaift (null) [ERR] (md_get_module_info:1340) Module 'ianaift@' is not present in the dependency graph. [ERR] (dm_module_clb:437) Module 'ianaift' was not found

[DBG] (rp_dt_xpath_requests_state_data:754) State data in subtree /ietf-interfaces:interfaces-state requested. [DBG] (rp_dt_xpath_requests_state_data:762) 1 subtrees of state data will be attempted to load in order to resolve /ietf-interfaces:interfaces-state/interface[type='ianaift:fastdsl']/oper-status//. [DBG] (pm_module_data_version_changed:582) Module 'ietf-interfaces' persist file version matches with cached value (1520246875371969400). [DBG] (pm_get_subscriptions:1306) Returning 1 subscriptions from 'ietf-interfaces' persist file cache. [DBG] (rp_dt_find_subscription_covering_subtree:821) Found match for interfaces-state with depth 0 index 0 ...


gdb call trace:

(gdb) bt

0 dm_module_clb (ctx=0x7fffe8074860, name=0x7fffe815ffb0 "ianaift", ns=0x0, options=0, user_data=0x63ef20) at /WORK/PMA.new/sysrepo/src/data_manager.c:429

1 0x00007ffff68d0b7b in resolve_identref (type=0x7fffe8099d48, ident_name=0x7fffe815c780 "ianaift:fastdsl", node=0x7ffff5320670, mod=0x7fffe8086b10, dflt=0) at /WORK/PMA.new/libyang/src/resolve.c:5506

2 0x00007ffff68e329c in lyp_parsevalue (type=0x7fffe8099d48, value=0x7ffff53206a0, xml=0x0, leaf=0x7ffff5320670, attr=0x0, local_mod=0x7fffe8086b10, store=0, dflt=0) at /WORK/PMA.new/libyang/src/parser.c:1757

3 0x00007ffff69599c3 in lyd_validate_value (node=0x7fffe8099cd0, value=0x7fffe8175e70 "ianaift:fastdsl") at /WORK/PMA.new/libyang/src/tree_data.c:4454

4 0x00007ffff6968ff7 in warn_equality_value (ctx=0x7fffe8074860, exp=0x7fffe816fb30, set=0x7ffff5320b70, val_exp=7, equal_exp=5, last_equal_exp=7) at /WORK/PMA.new/libyang/src/xpath.c:2797

5 0x00007ffff6976e58 in eval_equality_expr (exp=0x7fffe816fb30, exp_idx=0x7ffff5320b0e, repeat=1, cur_node=0x7fffe8090ac0, local_mod=0x7fffe8086b10, set=0x7ffff5320b70, options=4) at /WORK/PMA.new/libyang/src/xpath.c:7766

6 0x00007ffff69779ff in eval_expr_select (exp=0x7fffe816fb30, exp_idx=0x7ffff5320b0e, etype=LYXP_EXPR_NONE, cur_node=0x7fffe8090ac0, local_mod=0x7fffe8086b10, set=0x7ffff5320b70, options=4) at /WORK/PMA.new/libyang/src/xpath.c:7988

7 0x00007ffff6972f7b in eval_predicate (exp=0x7fffe816fb30, exp_idx=0x7ffff5320b0e, cur_node=0x7fffe8090ac0, local_mod=0x7fffe8086b10, set=0x7ffff5320b70, options=4, parent_pos_pred=1) at /WORK/PMA.new/libyang/src/xpath.c:6704

8 0x00007ffff69736c0 in eval_relative_location_path (exp=0x7fffe816fb30, exp_idx=0x7ffff5320b0e, cur_node=0x7fffe8090ac0, local_mod=0x7fffe8086b10, all_desc=0, set=0x7ffff5320b70, options=4) at /WORK/PMA.new/libyang/src/xpath.c:6831

9 0x00007ffff6973934 in eval_absolute_location_path (exp=0x7fffe816fb30, exp_idx=0x7ffff5320b0e, cur_node=0x7fffe8090ac0, local_mod=0x7fffe8086b10, set=0x7ffff5320b70, options=4) at /WORK/PMA.new/libyang/src/xpath.c:6892

10 0x00007ffff697541d in eval_path_expr (exp=0x7fffe816fb30, exp_idx=0x7ffff5320b0e, cur_node=0x7fffe8090ac0, local_mod=0x7fffe8086b10, set=0x7ffff5320b70, options=4) at /WORK/PMA.new/libyang/src/xpath.c:7272

11 0x00007ffff6977b2c in eval_expr_select (exp=0x7fffe816fb30, exp_idx=0x7ffff5320b0e, etype=LYXP_EXPR_NONE, cur_node=0x7fffe8090ac0, local_mod=0x7fffe8086b10, set=0x7ffff5320b70, options=4) at /WORK/PMA.new/libyang/src/xpath.c:8006

12 0x00007ffff6978965 in lyxp_atomize (expr=0x7fffe816e230 "/ietf-interfaces:interfaces-state/interface[type='ianaift:fastdsl']/type//.", cur_snode=0x7fffe8090ac0, cur_snode_type=LYXP_NODE_ELEM, set=0x7ffff5320b70, options=4, ctx_snode=0x0) at /WORK/PMA.new/libyang/src/xpath.c:8390

13 0x00007ffff694abd1 in lys_xpath_atomize (ctx_node=0x7fffe8090ac0, ctx_node_type=LYXP_NODE_ELEM, expr=0x7fffe816e230 "/ietf-interfaces:interfaces-state/interface[type='ianaift:fastdsl']/type//.", options=4) at /WORK/PMA.new/libyang/src/tree_schema.c:3918

14 0x00007ffff7a9a892 in rp_dt_xpath_atomize (schema_info=0x7fffe806eaf0, xpath=0x7fffe816e230 "/ietf-interfaces:interfaces-state/interface[type='ianaift:fastdsl']/type//.", atoms=0x7ffff5320c70) at /WORK/PMA.new/sysrepo/src/rp_dt_get.c:569

15 0x00007ffff7a9bc86 in rp_dt_xpath_requests_state_data (rp_ctx=0x604870, session=0x674d00, schema_info=0x7fffe806eaf0, xpath=0x675330 "/ietf-interfaces:interfaces-state/interface[type='ianaift:fastdsl']/type//.", api_variant=SR_API_VALUES, tree_depth_limit=0, state_data_ctx=0x674e18) at /WORK/PMA.new/sysrepo/src/rp_dt_get.c:702

16 0x00007ffff7aa091b in rp_dt_prepare_data (rp_ctx=0x604870, rp_session=0x674d00, xpath=0x675330 "/ietf-interfaces:interfaces-state/interface[type='ianaift:fastdsl']/type//.", api_variant=SR_API_VALUES, tree_depth_limit=0, data_tree=0x7ffff5320d88) at /WORK/PMA.new/sysrepo/src/rp_dt_get.c:1231

17 0x00007ffff7aa2ebb in rp_dt_get_values_wrapper_with_opts (rp_ctx=0x604870, rp_session=0x674d00, get_items_ctx=0x674d60, sr_mem=0x0, xpath=0x675330 "/ietf-interfaces:interfaces-state/interface[type='ianaift:fastdsl']/type//.", offset=0, limit=100, values=0x7ffff5320df8, count=0x7ffff5320e00) at /WORK/PMA.new/sysrepo/src/rp_dt_get.c:1363

18 0x00007ffff7a6dbc6 in rp_get_items_req_process (rp_ctx=0x604870, session=0x674d00, msg=0x675b40, skip_msg_cleanup=0x7ffff5320ee3) at /WORK/PMA.new/sysrepo/src/request_processor.c:821

19 0x00007ffff7a897a2 in rp_req_dispatch (rp_ctx=0x604870, session=0x674d00, msg=0x675b40, skip_msg_cleanup=0x7ffff5320ee3) at /WORK/PMA.new/sysrepo/src/request_processor.c:3390

20 0x00007ffff7a8ad28 in rp_msg_dispatch (rp_ctx=0x604870, session=0x674d00, msg=0x675b40) at /WORK/PMA.new/sysrepo/src/request_processor.c:3603

21 0x00007ffff7a8b6c7 in rp_worker_thread_execute (rp_ctx_p=0x604870) at /WORK/PMA.new/sysrepo/src/request_processor.c:3704

22 0x00007ffff77ca6ba in start_thread (arg=0x7ffff5321700) at pthread_create.c:333

23 0x00007ffff75003dd in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:109


The back trace shows that the resolve_identref() calls dm_module_clb(...name=0x7fffe815ffb0 "ianaift"...), which is not correct in this case (as it is the xmlns prefix). This is because libyang interpret it as "modulename:value".
Referring to [RFC 6020 section 9.10.5](https://tools.ietf.org/html/rfc6020#section-9.10.5) I think an identity-ref should be 'ns pefix : value' instead of 'modulename:value' format.

Thanks!
Darshana.
michalvasko commented 6 years ago

Hi Darshana, with the most recent devel libyang and netopeer2-server it should work.

Regards, Michal

darshana-jk commented 6 years ago

Thanks for the fix Michal. Unfortunately I'm stuck in an old libyang version (0.14.45) the reason is in the latest version some of the YANG deviations we use is broken (I will add an issue with more information). If possible, I will try to get the fix ported to our old libyang version.

Thanks again, Darshana.