On Thu, Aug 10, 2017 at 11:22:56AM +0200, Richard Cochran wrote: > > 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.
Ah, yes, this would make the code more clear. Thanks a lot for the help. > > First, pass in the desired index into rtnl_link_status() and > initialize the slave index: Would it be better to pass a device name? If we pass the index number. Then we need to convert both iface->name and port->name to index in rtnl_link_info() and port_event(). And if pass a device name. We can convert the name to index in rtnl_link_status() unified. > > 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); OK, check the index in rtnl_link_status(), not in port_link_status(). No problem. > /* > * 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) I guess we do not need this 'int index' now. as above. > { > 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)) iface_index = if_nametoindex(iface->name); if (rtnl_link_status(fd, iface_index, rtnl_link_info_callback, &ts_index)) or pass dev name to rtnl_link_status() if (rtnl_link_status(fd, iface->name, 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 > */ we have moved this check to clock.c. So no need to ensure it here, right? Just if (ts_index > 0 && if_indextoname(ts_index, iface->ts_label)) err = 0; should be OK. Thanks Hangbin > 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