frr icon indicating copy to clipboard operation
frr copied to clipboard

northbound_sysrepo calls sysrepo exception

Open nic1225 opened this issue 6 years ago • 11 comments

hi, @rwestphal:

for the latest version of northbound_sysrepo, I have the following problems

2020/08/24 12:48:12 errors: BGP: [EC 100663349] sr_module_change_subscribe(): Operation not authorized

2020/08/25 15:49:26 errors: BGP: [EC 100663303] Can't create pid lock file /var/run/frr/bgpd.pid (Permission denied), exiting

I found the reason is that FRR is not run with root permission. When calling the API of sysrepo, the permission to perform some operations (such as Chmod) is not enough

[root@localhost modules]# ps aux | grep bgpd
frr       2950  0.0  0.1 237592  5736 ?        Ssl  09:34   0:00 /usr/lib/frr/bgpd -d -M sysrepo:/usr/lib64/frr/modules/ --log-level debugging

nic1225 avatar Aug 25 '20 01:08 nic1225

hi, Use the following command to solve the problem

./configure  --enable-multipath=1    --with-pkg-extra-version=-ctyun   --enable-sysrepo=yes  --enable-user=root --enable-group=root

nic1225 avatar Aug 25 '20 12:08 nic1225

I think we should talk about this

mjstapp avatar Aug 25 '20 12:08 mjstapp

@nic1225 recompiling doesn't look like a good solution... Have you tried running daemons with -u root -g root as temporary solution?

Other than that is sysrepo/sysrepo integration is expecting the wrong permissions? Or is your sysrepo client wanting root credentials? I have very little experience with this, but I don't recall needing this a while ago (I just ran it as test, nothing elaborated).

rzalamena avatar Aug 25 '20 12:08 rzalamena

In the new sysrepo version you need to set the owner of each YANG module after installing it. Example:

$ sysrepoctl --install /usr/local/share/yang/frr-isisd.yang
$ sysrepoctl -c frr-isisd --owner frr --group frr

More information here:

  • https://netopeer.liberouter.org/doc/sysrepo/master/index.html#access_control
  • https://netopeer.liberouter.org/doc/sysrepo/master/sysrepoctl.html

@nic1225 please try that and let us know if that fixes the problem for you. Documentation for the sysrepo and other northbound plugins should come within the next few weeks.

rwestphal avatar Aug 25 '20 13:08 rwestphal

hi, @rwestphal

Start the process after entering sysrepoctl --install /usr/local/share/yang/frr-isisd.yang ,the following exception occurred

2020/08/26 10:06:56 errors: BGP: [EC 100663349] sr_module_change_subscribe(): Operation not authorized

Continue with operation sysrepoctl -c frr-isisd --owner frr --group frr ,new problems arise

2020/08/26 10:07:39 errors: BGP: [EC 100663349] sr_module_change_subscribe(): System function call failed

Through GDB, the problem is found at sr_module_change_subscribe -> sr_subs_new -> mkfifo ,mkfifo 'errno is 13, In glibc, 13 means as follows

 #define	EACCES          _HURD_ERRNO (13)/* Permission denied */

So, I think sysrepo needs root privileges.

nic1225 avatar Aug 26 '20 02:08 nic1225

So, I think sysrepo needs root privileges.

I can confirm that's not the case, since I was able to use the sysrepo plugin without having to change the FRR user. You just need to use sysrepoctl to change the owner of each installed module as I explained before.

If that didn't work, there's a chance your sysrepo datastores might be corrupted. This is relatively easy to happen if you use gdb and quit while inside a Sysrepo function. This is because the new Sysrepo uses shared memory and some API calls need to perform some cleanup before exiting in order to keep things consistent. For more details please see this: https://netopeer.liberouter.org/doc/sysrepo/master/index.html#recovery

To recover from that, you can remove the /etc/sysrepo directory and install Sysrepo (and all FRR modules) again. After that, you might also need to do this: sysrepocfg --format=json --import=/tmp/empty.json --datastore=running (where /tmp/empty.json is a file containing only {}). This last step was required for me in order to get things working (for reasons I don't understand) so you might need to do that as well.

Finally, beware our Sysrepo plugin is mostly experimental at this point, and not particularly useful since most FRR daemons weren't converted to YANG yet. In any case, any feedback or bug reports would be appreciated!

rwestphal avatar Aug 26 '20 14:08 rwestphal

hi, @rwestphal thanks for reply,I will try frr user later. currently, there is a problem that sysrepo database changes but no callback function is called. I used command sysrepocfg --edit=vi --lock -d running -f xml -m frr-route-map to issue configuration to frr-route-map module, and the callback function frr_sr_config_change_cb was not called

<lib xmlns="http://frrouting.org/yang/route-map">
    <route-map>
	  <name>med100</name>
      <entry>
        <sequence>100</sequence>
        <action>permit</action>
      </entry>    
	</route-map>  
</lib>

After the above configuration is completed, the newly created event variable(/etc/sysrepo/sr_evpipe4) will disappear,Even without the above operation, it will disappear in about a minute

by netopeer2-cli , I can see that the configuration is successfully distributed, but there is no display in vtysh. GDB also did not stop at the preset breakpoint.

I added log information in function frr_sr_read_cb, but I haven't received relevant log since gbpd was started.

/usr/lib/frr/bgpd -d -M sysrepo:/usr/lib64/frr/modules/  --log-level debugging

thanks Nick

nic1225 avatar Aug 27 '20 02:08 nic1225

Hi @nic1225,

I've no idea why bgpd isn't receiving the configuration changes committed to Sysrepo. It might be a corruption issue in your configuration datastores as I explained before. My suggestion for you would be to reinstall Sysrepo following my steps as that is a sure way to make things work.

Regarding log information, you can use the debug northbound command if you want to get more details about the configuration changes being committed to FRR.

Also, using -M sysrepo should be enough to load the sysrepo plugin in any daemon. There's no need to pass a directory as a parameter as far as I'm aware of.

rwestphal avatar Aug 27 '20 18:08 rwestphal

hi, @rwestphal

I added an idle thread at the end of initialization (although it should not be), and then when operating the sysrepo database, the callback failed, but pipe sr_evpipe always exists. Therefore, I speculate that after the initialization of module northbound_sysrepo is completed and exited, the subscription will also stop, so that pipe sr_evpipe will disappear.

static void * worker_thread(void *arg)
{
    while (true) {
        sleep(1);
    }
    
    return NULL;
}

static int frr_sr_module_late_init(struct thread_master *tm)
{
    master = tm;
    pthread_t tid;
        
    if (frr_sr_init() < 0) {
        flog_err(EC_LIB_SYSREPO_INIT,
			 "failed to initialize the Sysrepo module");
        return -1;
    }

    hook_register(frr_fini, frr_sr_finish);
    frr_sr_cli_init();

    pthread_create((pthread_t *)&tid, NULL, worker_thread, 0);
    pthread_join(tid, NULL);

    return 0;
}

In addition, have you tested whether the configuration can be successfully distributed through sysrspo 1.4.xx?

thanks Nick

nic1225 avatar Sep 01 '20 07:09 nic1225

hi, @rwestphal Using strace,I discovery, when configuring sysrepo, it needs to check whether the thread creating the subscription is still there. If not, the pipe sr_evpipe will be deleted. However, we do not generate threads in northbound_sysrepo, and all subsequent callbacks will fail.

1565  01:51:29.188460 kill(1171, 0)     = 0
1565  01:51:29.188487 kill(1548, 0)     = -1 ESRCH (No such process)
1565  01:51:29.188554 open("/dev/shm/sr_ctcc-bgpd.operational", O_RDONLY|O_NOFOLLOW|O_CLOEXEC) = 6
1565  01:51:29.188591 fstat(6, {st_mode=S_IFREG|0666, st_size=7, ...}) = 0
1565  01:51:29.188622 mmap(NULL, 8, PROT_READ|PROT_WRITE, MAP_PRIVATE, 6, 0) = 0x7f0c58f5f000
1565  01:51:29.188683 munmap(0x7f0c58f5f000, 8) = 0
1565  01:51:29.188719 close(6)          = 0
1565  01:51:29.188752 unlink("/dev/shm/srsub_ctcc-bgpd.running") = 0
1565  01:51:29.188792 unlink("/etc/sysrepo/sr_evpipe2") = 0

As mentioned above, I think northbound_sysrepo should be put into the bgpd process.

thanks Nick

nic1225 avatar Sep 03 '20 07:09 nic1225

hi, @rwestphal According to the previous reply, the problem can be solved

thanks Nick

nic1225 avatar Sep 04 '20 02:09 nic1225