Signed-off-by: Hangbin Liu <liuhang...@gmail.com> --- rtnl.c | 31 +++++++++++++++++++++++++++++++ rtnl.h | 8 ++++++++ 2 files changed, 39 insertions(+)
diff --git a/rtnl.c b/rtnl.c index b695edd..c292a77 100644 --- a/rtnl.c +++ b/rtnl.c @@ -237,3 +237,34 @@ int rtnl_open(void) } return fd; } + +static void rtnl_get_ts_label_callback(void *ctx, int linkup, int ts_index) +{ + int *dst = ctx; + *dst = ts_index; +} + +int rtnl_get_ts_label(struct interface *iface) +{ + int err, fd; + int ts_index = -1; + + fd = rtnl_open(); + if (fd < 0) + return fd; + + err = rtnl_link_query(fd, iface->name); + if (err) { + goto no_info; + } + + rtnl_link_status(fd, iface->name, rtnl_get_ts_label_callback, &ts_index); + if (ts_index > 0 && if_indextoname(ts_index, iface->ts_label)) + err = 0; + else + err = -1; + +no_info: + rtnl_close(fd); + return err; +} diff --git a/rtnl.h b/rtnl.h index 20f1491..d335c40 100644 --- a/rtnl.h +++ b/rtnl.h @@ -20,6 +20,8 @@ #ifndef HAVE_RTNL_H #define HAVE_RTNL_H +#include "config.h" + typedef void (*rtnl_callback)(void *ctx, int linkup, int ts_index); /** @@ -53,4 +55,10 @@ int rtnl_link_status(int fd, char *device, rtnl_callback cb, void *ctx); */ int rtnl_open(void); +/** + * Get interface ts_label information + * @param iface struct interface. + * @return Zero on success, or -1 on error. + */ +int rtnl_get_ts_label(struct interface *iface); #endif -- 2.5.5 ------------------------------------------------------------------------------ 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