Skip to content

Netopeer2-cli seg fault for schema-mount #1775

@ankit7gup

Description

@ankit7gup

Hi @michalvasko,

I have been using yang schema mount defined using the below yang models and populating the operational data using the below commands. While the data fetch via sysrepocfg command is successful, the netopeer2-cli on doing a get for the parent module gives seg-fault. Can you please suggest if something is wrong here? I also tried to configure the ietf-yang-library still facing same segfault. Thanks in advance!

CORE

#0  0x0000562e5fc8d0dd in cli_send_recv (rpc=0x562e8a5f1250, output=0x7f0964d606a0 <_IO_2_1_stdout_>, wd_mode=NC_WD_UNKNOWN, timeout_s=5) at /home/ankgupta/tools/netopeer2/cli/commands.c:410
410	    } else if (!strcmp(LYD_NAME(lyd_child(envp)), "ok")) {
(gdb) 
#0  0x0000562e5fc8d0dd in cli_send_recv (rpc=0x562e8a5f1250, output=0x7f0964d606a0 <_IO_2_1_stdout_>, wd_mode=NC_WD_UNKNOWN, timeout_s=5) at /home/ankgupta/tools/netopeer2/cli/commands.c:410
410	    } else if (!strcmp(LYD_NAME(lyd_child(envp)), "ok")) {
(gdb) 
#0  0x0000562e5fc8d0dd in cli_send_recv (rpc=0x562e8a5f1250, output=0x7f0964d606a0 <_IO_2_1_stdout_>, wd_mode=NC_WD_UNKNOWN, timeout_s=5) at /home/ankgupta/tools/netopeer2/cli/commands.c:410
410	    } else if (!strcmp(LYD_NAME(lyd_child(envp)), "ok")) {
(gdb) 
#0  0x0000562e5fc8d0dd in cli_send_recv (rpc=0x562e8a5f1250, output=0x7f0964d606a0 <_IO_2_1_stdout_>, wd_mode=NC_WD_UNKNOWN, timeout_s=5) at /home/ankgupta/tools/netopeer2/cli/commands.c:410
410	    } else if (!strcmp(LYD_NAME(lyd_child(envp)), "ok")) {
(gdb) p *output
$1 = {_flags = -72537468, _IO_read_ptr = 0x562e8a477bd0 "\noG\212.V", _IO_read_end = 0x562e8a477bd0 "\noG\212.V", _IO_read_base = 0x562e8a477bd0 "\noG\212.V", 
  _IO_write_base = 0x562e8a477bd0 "\noG\212.V", _IO_write_ptr = 0x562e8a477bd0 "\noG\212.V", _IO_write_end = 0x562e8a477bd0 "\noG\212.V", _IO_buf_base = 0x562e8a477bd0 "\noG\212.V", 
  _IO_buf_end = 0x562e8a477fd0 " \004", _IO_save_base = 0x0, _IO_backup_base = 0x0, _IO_save_end = 0x0, _markers = 0x0, _chain = 0x7f0964d5f980 <_IO_2_1_stdin_>, _fileno = 1, _flags2 = 0, 
  _old_offset = -1, _cur_column = 0, _vtable_offset = 0 '\000', _shortbuf = "", _lock = 0x7f0964d617e0 <_IO_stdfile_1_lock>, _offset = -1, _codecvt = 0x0, _wide_data = 0x7f0964d5f880 <_IO_wide_data_1>, 
  _freeres_list = 0x0, _freeres_buf = 0x0, __pad5 = 0, _mode = -1, _unused2 = '\000' <repeats 19 times>}

device-config.yang:

module device-config {
  yang-version 1.1;
  namespace "urn:example:device-config";
  prefix dc;

  revision 2025-01-01 {
    description
      "test device-config";
   }

  container system {
    leaf hostname {
      type string;
    }

    leaf enabled {
      type boolean;
      default true;
    }
  }
}

parent.yang

module parent {
  yang-version 1.1;
  namespace "urn:example:parent";
  prefix p;

  import ietf-yang-schema-mount {
    prefix yangmnt;
  }

  import ietf-yang-library {
    prefix yanglib;
  }


  revision 2025-01-01 {
    description
      "test schema mount";
    }


  container devices {
    list device {
      key "name";

      leaf name {
        type string;
      }

      /*
       * Schema mount point
       */
      container config {
        yangmnt:mount-point "device-schema";
      }
    }
  }
}

device_data1.xml

<devices xmlns="urn:example:parent">
<device>
<name>router1</name>
<config>
<system xmlns="urn:example:device-config">
<hostname>r1</hostname>
<enabled>true</enabled>
</system>
</config>
</device>
</devices>

device_data2.xml

<devices xmlns="urn:example:parent">
<device>
<name>router2</name>
<config>
<system xmlns="urn:example:device-config">
<hostname>r2</hostname>
<enabled>false</enabled>
</system>
</config>
</device>
</devices>

Commands to push and check data

sysrepocfg -I device_data1.xml -d running -f xml -m parent
sysrepocfg -E device_data2.xml -d running -f xml -m parent

sysrepocfg --export -d running -f xml -m parent
<devices xmlns="urn:example:parent">
  <device>
    <name>router1</name>
    <config>
      <system xmlns="urn:example:device-config">
        <hostname>r1</hostname>
        <enabled>true</enabled>
      </system>
    </config>
  </device>
  <device>
    <name>router2</name>
    <config>
      <system xmlns="urn:example:device-config">
        <hostname>r2</hostname>
        <enabled>false</enabled>
      </system>
    </config>
  </device>
</devices>

Yang schema mount operational data

#include <stdio.h>
#include <sysrepo.h>

int main() {
    sr_conn_ctx_t *conn = NULL;
    sr_session_ctx_t *sess = NULL;

    // 1. Connect to sysrepo and start a session for the OPERATIONAL datastore
    sr_connect(0, &conn);
    sr_session_start(conn, SR_DS_OPERATIONAL, &sess);


    sr_set_item_str(sess,
    "/ietf-yang-schema-mount:schema-mounts/mount-point[module='parent'][label='device-schema']",
    NULL, NULL, 0);

    // Path: /module:container/mount-point-label/shared-schema
    sr_set_item_str(sess, 
        "/ietf-yang-schema-mount:schema-mounts/mount-point[module='parent'][label='device-schema']/shared-schema", 
        NULL, NULL, 0);
    sr_set_item_str(sess, 
        "/ietf-yang-schema-mount:schema-mounts/mount-point[module='parent'][label='device-schema']/config", 
        "true", NULL, 0);


    
    /* module-set */
    sr_set_item_str(sess,
        "/ietf-yang-schema-mount:schema-mounts/mount-point[module='parent'][label='device-schema']/yang-library/module-set[name='device-schema-set']",
        NULL, NULL, 0);
    
    /* module */
    sr_set_item_str(sess,
        "/ietf-yang-schema-mount:schema-mounts/mount-point[module='parent'][label='device-schema']/yang-library/module-set[name='device-schema-set']/module[name='device-config']/namespace",
        "urn:example:device-config", NULL, 0);
    
    /* schema (leafref to module-set) */
    sr_set_item_str(sess,
        "/ietf-yang-schema-mount:schema-mounts/mount-point[module='parent'][label='device-schema']/yang-library/schema[name='device-schema']/module-set",
        "device-schema-set", NULL, 0);
    
    /* datastore (leafref to schema) */
    sr_set_item_str(sess,
        "/ietf-yang-schema-mount:schema-mounts/mount-point[module='parent'][label='device-schema']/yang-library/datastore[name='running']/schema",
        "device-schema", NULL, 0);
    

#if 0
 char xpath[512];


    /* 1. Define the YANG Library container under the device's mount point */
    snprintf(xpath, sizeof(xpath), "/parent:devices/device[name='%s']/config/ietf-yang-library:yang-library/module-set[name='device-schema-set']", "router1");
    sr_set_item_str(sess, xpath, NULL, NULL, SR_EDIT_DEFAULT);

    /* 2. List modules available inside this specific device's mount point */
    // Example: Adding device-config to dev1
    snprintf(xpath, sizeof(xpath), "/parent:devices/device[name='%s']/config/ietf-yang-library:yang-library/module-set[name='device-schema-set']/module[name='device-config']", "router1");
    sr_set_item_str(sess, xpath, NULL, NULL, SR_EDIT_DEFAULT);
    
    snprintf(xpath, sizeof(xpath), "/parent:devices/device[name='%s']/config/ietf-yang-library:yang-library/module-set[name='device-schema-set']/module[name='device-config']/revision", "router1");
    sr_set_item_str(sess, xpath, "2025-01-01", NULL, SR_EDIT_DEFAULT);

    /* 1. Define the YANG Library container under the device's mount point */
    snprintf(xpath, sizeof(xpath), "/parent:devices/device[name='%s']/config/ietf-yang-library:yang-library/module-set[name='device-schema-set']", "router2");
    sr_set_item_str(sess, xpath, NULL, NULL, SR_EDIT_DEFAULT);

    /* 2. List modules available inside this specific device's mount point */
    // Example: Adding device-config to dev1
    snprintf(xpath, sizeof(xpath), "/parent:devices/device[name='%s']/config/ietf-yang-library:yang-library/module-set[name='device-schema-set']/module[name='device-config']", "router2");
    sr_set_item_str(sess, xpath, NULL, NULL, SR_EDIT_DEFAULT);
    
    snprintf(xpath, sizeof(xpath), "/parent:devices/device[name='%s']/config/ietf-yang-library:yang-library/module-set[name='device-schema-set']/module[name='device-config']/revision", "router2");
    sr_set_item_str(sess, xpath, "2025-01-01", NULL, SR_EDIT_DEFAULT);


    #endif
    
    
    // 5. Apply the changes to the Operational Datastore
    if (sr_apply_changes(sess, 0) != SR_ERR_OK) {
        printf("Failed to apply schema-mount mapping. Check if features are enabled.\n");
        sr_disconnect(conn);
        return 1;
    }

    printf("Runtime Schema Mount mapping has been applied to Operational DS.\n");


    while(1);

    return 0;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions