introduce support for slave info data
Signed-off-by: Jiri Pirko <jiri@resnulli.us>
This commit is contained in:
parent
32ad31fba1
commit
fbea611564
|
|
@ -61,6 +61,8 @@ static inline int rtm_get_table(struct rtmsg *r, struct rtattr **tb)
|
||||||
|
|
||||||
extern struct rtnl_handle rth;
|
extern struct rtnl_handle rth;
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
struct link_util
|
struct link_util
|
||||||
{
|
{
|
||||||
struct link_util *next;
|
struct link_util *next;
|
||||||
|
|
@ -72,9 +74,11 @@ struct link_util
|
||||||
struct rtattr *[]);
|
struct rtattr *[]);
|
||||||
void (*print_xstats)(struct link_util *, FILE *,
|
void (*print_xstats)(struct link_util *, FILE *,
|
||||||
struct rtattr *);
|
struct rtattr *);
|
||||||
|
bool slave;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct link_util *get_link_kind(const char *kind);
|
struct link_util *get_link_kind(const char *kind);
|
||||||
|
struct link_util *get_link_slave_kind(const char *slave_kind);
|
||||||
int get_netns_fd(const char *name);
|
int get_netns_fd(const char *name);
|
||||||
|
|
||||||
#ifndef INFINITY_LIFE_TIME
|
#ifndef INFINITY_LIFE_TIME
|
||||||
|
|
|
||||||
|
|
@ -192,34 +192,52 @@ static void print_linktype(FILE *fp, struct rtattr *tb)
|
||||||
{
|
{
|
||||||
struct rtattr *linkinfo[IFLA_INFO_MAX+1];
|
struct rtattr *linkinfo[IFLA_INFO_MAX+1];
|
||||||
struct link_util *lu;
|
struct link_util *lu;
|
||||||
|
struct link_util *slave_lu;
|
||||||
char *kind;
|
char *kind;
|
||||||
|
char *slave_kind;
|
||||||
|
|
||||||
parse_rtattr_nested(linkinfo, IFLA_INFO_MAX, tb);
|
parse_rtattr_nested(linkinfo, IFLA_INFO_MAX, tb);
|
||||||
|
|
||||||
if (!linkinfo[IFLA_INFO_KIND])
|
if (linkinfo[IFLA_INFO_KIND]) {
|
||||||
return;
|
kind = RTA_DATA(linkinfo[IFLA_INFO_KIND]);
|
||||||
kind = RTA_DATA(linkinfo[IFLA_INFO_KIND]);
|
|
||||||
|
|
||||||
fprintf(fp, "%s", _SL_);
|
fprintf(fp, "%s", _SL_);
|
||||||
fprintf(fp, " %s ", kind);
|
fprintf(fp, " %s ", kind);
|
||||||
|
|
||||||
lu = get_link_kind(kind);
|
lu = get_link_kind(kind);
|
||||||
if (!lu || !lu->print_opt)
|
if (lu && lu->print_opt) {
|
||||||
return;
|
struct rtattr *attr[lu->maxattr+1], **data = NULL;
|
||||||
|
|
||||||
if (1) {
|
if (linkinfo[IFLA_INFO_DATA]) {
|
||||||
struct rtattr *attr[lu->maxattr+1], **data = NULL;
|
parse_rtattr_nested(attr, lu->maxattr,
|
||||||
|
linkinfo[IFLA_INFO_DATA]);
|
||||||
|
data = attr;
|
||||||
|
}
|
||||||
|
lu->print_opt(lu, fp, data);
|
||||||
|
|
||||||
if (linkinfo[IFLA_INFO_DATA]) {
|
if (linkinfo[IFLA_INFO_XSTATS] && show_stats &&
|
||||||
parse_rtattr_nested(attr, lu->maxattr,
|
lu->print_xstats)
|
||||||
linkinfo[IFLA_INFO_DATA]);
|
lu->print_xstats(lu, fp, linkinfo[IFLA_INFO_XSTATS]);
|
||||||
data = attr;
|
|
||||||
}
|
}
|
||||||
lu->print_opt(lu, fp, data);
|
}
|
||||||
|
|
||||||
if (linkinfo[IFLA_INFO_XSTATS] && show_stats &&
|
if (linkinfo[IFLA_INFO_SLAVE_KIND]) {
|
||||||
lu->print_xstats)
|
slave_kind = RTA_DATA(linkinfo[IFLA_INFO_SLAVE_KIND]);
|
||||||
lu->print_xstats(lu, fp, linkinfo[IFLA_INFO_XSTATS]);
|
|
||||||
|
fprintf(fp, "%s", _SL_);
|
||||||
|
fprintf(fp, " %s_slave ", slave_kind);
|
||||||
|
|
||||||
|
slave_lu = get_link_slave_kind(slave_kind);
|
||||||
|
if (slave_lu && slave_lu->print_opt) {
|
||||||
|
struct rtattr *attr[slave_lu->maxattr+1], **data = NULL;
|
||||||
|
|
||||||
|
if (linkinfo[IFLA_INFO_SLAVE_DATA]) {
|
||||||
|
parse_rtattr_nested(attr, slave_lu->maxattr,
|
||||||
|
linkinfo[IFLA_INFO_SLAVE_DATA]);
|
||||||
|
data = attr;
|
||||||
|
}
|
||||||
|
slave_lu->print_opt(slave_lu, fp, data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
21
ip/iplink.c
21
ip/iplink.c
|
|
@ -27,6 +27,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <linux/sockios.h>
|
#include <linux/sockios.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
#include "rt_names.h"
|
#include "rt_names.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
@ -105,14 +106,15 @@ static int on_off(const char *msg, const char *realval)
|
||||||
static void *BODY; /* cached dlopen(NULL) handle */
|
static void *BODY; /* cached dlopen(NULL) handle */
|
||||||
static struct link_util *linkutil_list;
|
static struct link_util *linkutil_list;
|
||||||
|
|
||||||
struct link_util *get_link_kind(const char *id)
|
static struct link_util *__get_link_kind(const char *id, bool slave)
|
||||||
{
|
{
|
||||||
void *dlh;
|
void *dlh;
|
||||||
char buf[256];
|
char buf[256];
|
||||||
struct link_util *l;
|
struct link_util *l;
|
||||||
|
|
||||||
for (l = linkutil_list; l; l = l->next)
|
for (l = linkutil_list; l; l = l->next)
|
||||||
if (strcmp(l->id, id) == 0)
|
if (strcmp(l->id, id) == 0 &&
|
||||||
|
l->slave == slave)
|
||||||
return l;
|
return l;
|
||||||
|
|
||||||
snprintf(buf, sizeof(buf), LIBDIR "/ip/link_%s.so", id);
|
snprintf(buf, sizeof(buf), LIBDIR "/ip/link_%s.so", id);
|
||||||
|
|
@ -127,7 +129,10 @@ struct link_util *get_link_kind(const char *id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(buf, sizeof(buf), "%s_link_util", id);
|
if (slave)
|
||||||
|
snprintf(buf, sizeof(buf), "%s_slave_link_util", id);
|
||||||
|
else
|
||||||
|
snprintf(buf, sizeof(buf), "%s_link_util", id);
|
||||||
l = dlsym(dlh, buf);
|
l = dlsym(dlh, buf);
|
||||||
if (l == NULL)
|
if (l == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
@ -137,6 +142,16 @@ struct link_util *get_link_kind(const char *id)
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct link_util *get_link_kind(const char *id)
|
||||||
|
{
|
||||||
|
return __get_link_kind(id, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct link_util *get_link_slave_kind(const char *id)
|
||||||
|
{
|
||||||
|
return __get_link_kind(id, true);
|
||||||
|
}
|
||||||
|
|
||||||
static int get_link_mode(const char *mode)
|
static int get_link_mode(const char *mode)
|
||||||
{
|
{
|
||||||
if (strcasecmp(mode, "default") == 0)
|
if (strcasecmp(mode, "default") == 0)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue