On Thu, Aug 10, 2017 at 04:10:49PM +0800, Hangbin Liu wrote: > 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:
No. > Or just let rtnl_link_status() return ts_iface index directly, like: > > ts_iface_index = rtnl_link_status(fd, NULL, NULL); Well, we need the return value to indicate errors. So for clock_create(), rtnl_link_info() can provide a special callback. First, pass in the desired index into rtnl_link_status() and initialize the slave index: int rtnl_link_status(int fd, int index, rtnl_callback cb, void *ctx) { int slave_index = -1; /* Don't forget this! */ ... for ( ; NLMSG_OK(nh, len); nh = NLMSG_NEXT(nh, len)) { if (nh->nlmsg_type != RTM_NEWLINK) { continue; } info = NLMSG_DATA(nh); if (index != info->ifi_index) { continue; } ... if (tb[IFLA_LINKINFO]) slave_index = rtnl_linkinfo_parse(tb[IFLA_LINKINFO]); if (cb) cb(ctx, link_up, slave_index); /* * cb doesn't need index! */ ... } } Then define a customized callback: static void rtnl_link_info_callback(void *ctx, int index, int lnk, int ts_index) { int *dst = ctx; *dst = ts_index; } int rtnl_link_info(struct interface *iface) { int fd, index, ts_index = -1; ... if (rtnl_link_status(fd, rtnl_link_info_callback, &ts_index)) goto no_info; /* * If we do not have a slave, then use our own interface name * as ts_iface */ if (ts_index < 0) { ... } else { ... } ... } Thanks, Richard ------------------------------------------------------------------------------ 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