On Wed, Aug 09, 2017 at 08:49:34AM +0200, Richard Cochran wrote:
> On Tue, Aug 08, 2017 at 06:16:37PM +0800, Hangbin Liu wrote:
> > The goal of this call path is to call port_link_status() whenever link 
> > status
> > changed. And the call path should like
> > 
> > 1. port_event() -> rtnl_link_status() -> port_link_status()
> > 
> > > 2. clock_create() -> rtnl_link_info() -> rtnl_link_status()
> > 
> > This one only want to get the bond slave info when add iface at the 
> > begining.
> 
> Right.
> 
> > What do you think? any other good ideas?
> 
> Yes, I have an idea.  Pass an interface index (instead of a string) to
> port_link_status(), and then you can remove the ugly code.
> 
>       if (cb)
>               device = calloc(1, sizeof(MAX_IFNAME_SIZE + 1));
>       else
>               device = (char *)ctx;

Yes, that would be more clear, especially the call path 1. Then how about

2. clock_create() -> rtnl_link_info() -> rtnl_link_status()


Should we get the ts_iface inside rtnl_link_status() like:

err = rtnl_link_status(fd, iface->ts_label, NULL, NULL);

int rtnl_link_status(int fd, char *slave, rtnl_callback cb, void *ctx)
{
        ...
        if (tb[IFLA_LINKINFO])
                slave_index = rtnl_linkinfo_parse(tb[IFLA_LINKINFO]);

        if (cb)
                cb(ctx, index, link_up, slave_index);

        if (slave)
                if_indextoname(slave_index, slave);
        ...
}


Or just let rtnl_link_status() return ts_iface index directly, like:

ts_iface_index = rtnl_link_status(fd, NULL, NULL);

int rtnl_link_status(int fd, rtnl_callback cb, void *ctx)
{
        ...
        if (tb[IFLA_LINKINFO])
                slave_index = rtnl_linkinfo_parse(tb[IFLA_LINKINFO]);

        if (cb)
                cb(ctx, index, link_up, slave_index);
        ...

        return slave_index;
}

Thanks
Hangbin

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to