libnl icon indicating copy to clipboard operation
libnl copied to clipboard

rtnl_link_is_bridge not working

Open mordae opened this issue 11 years ago • 3 comments

Hi, I am wrapping libnl3 for use with Racket at https://github.com/Mordae/racket-rtnl and it seems as if rtnl_link_is_bridge fails on newly obtained bridge link objects. For example:

-> (let ((virbr0 (rtnl-link-get/kernel socket -1 "virbr0")))
     (rtnl-link-is-bridge? virbr0))
#f

However, if I properly modify the link object, it seems to work fine:

-> (let ((virbr0 (rtnl-link-get/kernel socket -1 "virbr0")))
     (rtnl-link-set-family! virbr0 'bridge)
     (rtnl-link-is-bridge? virbr0))
#t

Is this to be expected? I mean, with VLAN interfaces I can confirm their type right away.

-> (let ((em1.123 (rtnl-link-get/kernel socket -1 "em1.123")))
     (rtnl-link-is-vlan? em1.123))
#t

mordae avatar Jun 04 '13 23:06 mordae

Hmm, another example:

-> (rtnl-link-is-bridge? (rtnl-link-bridge-alloc))
#f

vs.

-> (rtnl-link-is-vlan? (rtnl-link-vlan-alloc))
#t

mordae avatar Jun 05 '13 09:06 mordae

On Wed 05 Jun 2013 11:07:38 AM CEST, Jan Dvořák wrote:

Hmm, another example:

-> (rtnl-link-is-bridge? (rtnl-link-bridge-alloc)) #f

vs.

-> (rtnl-link-is-vlan? (rtnl-link-vlan-alloc)) #t

rtnl_link_is_bridge() currently only returns true if the family is set to AF_BRIDGE is not true for bridge objects that have not been created based on kernel responses. This is obviously a bug. Fix in progress.

tgraf avatar Jun 06 '13 12:06 tgraf

Hello,

I have tried to create bridge using sk = nl_socket_alloc(); if ((err = nl_connect(sk, NETLINK_ROUTE)) < 0) { nl_perror(err, "Unable to connect socket"); return err; }

     link1 = rtnl_link_alloc();


 if ((err = rtnl_link_set_type(link1, "bridge")) < 0) {
            nl_perror(err, "Unable to set link info type");
            return err;
    }
    rtnl_link_set_name(link1, "br0");
    //rtnl_link_set_link(link, master_index);


if ((err = rtnl_link_add(sk, link1, NLM_F_CREATE)) < 0) {
            nl_perror(err, "Unable to add link");
            return err;
    }
rtnl_link_put(link1);

    nl_close(sk);

It works fine but when I access the link from link_cache and trying to set BRIDGE PRIORITY or check rtnl_link_is_bridge(link)...It does not work.

if ((err = rtnl_link_alloc_cache(sk, AF_UNSPEC, &link_cache)) < 0) { nl_perror(err, "Unable to allocate cache"); return err; }

link1=rtnl_link_get_by_name(link_cache, "br0");

    int k = rtnl_link_is_bridge(link1);
    printf("\nsuccess %d\n",k );
    k = rtnl_link_bridge_set_priority(link1,300);
    printf("\nsuccess %d\n",k );

It shows Assertion '0' failed and no changes in bridge configuration...it could not able to detect AF_BRIDGE...

my kernel version is 3.5.0-23-generic ....

please help me out..

Thanks

subhajitchatu avatar Jul 11 '13 06:07 subhajitchatu