rtnl: add function rtnl_get_ts_label to get interface ts_label info
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>master
parent
80bc4d4c2f
commit
6d1e2a62bd
31
rtnl.c
31
rtnl.c
|
@ -43,6 +43,37 @@ int rtnl_close(int fd)
|
||||||
return close(fd);
|
return close(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;
|
||||||
|
}
|
||||||
|
|
||||||
int rtnl_link_query(int fd, char *device)
|
int rtnl_link_query(int fd, char *device)
|
||||||
{
|
{
|
||||||
struct sockaddr_nl sa;
|
struct sockaddr_nl sa;
|
||||||
|
|
9
rtnl.h
9
rtnl.h
|
@ -20,6 +20,8 @@
|
||||||
#ifndef HAVE_RTNL_H
|
#ifndef HAVE_RTNL_H
|
||||||
#define HAVE_RTNL_H
|
#define HAVE_RTNL_H
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
typedef void (*rtnl_callback)(void *ctx, int linkup, int ts_index);
|
typedef void (*rtnl_callback)(void *ctx, int linkup, int ts_index);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -29,6 +31,13 @@ typedef void (*rtnl_callback)(void *ctx, int linkup, int ts_index);
|
||||||
*/
|
*/
|
||||||
int rtnl_close(int fd);
|
int rtnl_close(int fd);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request the link status from the kernel.
|
* Request the link status from the kernel.
|
||||||
* @param fd A socket obtained via rtnl_open().
|
* @param fd A socket obtained via rtnl_open().
|
||||||
|
|
Loading…
Reference in New Issue