* [PATCH iproute2 net-next-for-3.13 1/2] iplink: display slave information
@ 2014-02-10 8:11 Michal Kubecek
2014-02-10 13:34 ` Sergei Shtylyov
2014-02-10 17:09 ` Stephen Hemminger
0 siblings, 2 replies; 4+ messages in thread
From: Michal Kubecek @ 2014-02-10 8:11 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: netdev
Add print_slave_opt() callback and maxslattr value to struct
link_util. These are analogous to print_opt() and maxattr but
relate to slave info (IFLA_INFO_SLAVE_{KIND,DATA}).
Display the slave specific info in output of "ip -d link show".
Signed-off-by: Michal Kubecek <mkubecek@suse.cz>
---
ip/ip_common.h | 3 +++
ip/ipaddress.c | 27 +++++++++++++++++++++++++--
2 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/ip/ip_common.h b/ip/ip_common.h
index f9b4734..b1703a7 100644
--- a/ip/ip_common.h
+++ b/ip/ip_common.h
@@ -66,12 +66,15 @@ struct link_util
struct link_util *next;
const char *id;
int maxattr;
+ int maxslattr;
int (*parse_opt)(struct link_util *, int, char **,
struct nlmsghdr *);
void (*print_opt)(struct link_util *, FILE *,
struct rtattr *[]);
void (*print_xstats)(struct link_util *, FILE *,
struct rtattr *);
+ void (*print_slave_opt)(struct link_util *, FILE *,
+ struct rtattr *[]);
};
struct link_util *get_link_kind(const char *kind);
diff --git a/ip/ipaddress.c b/ip/ipaddress.c
index f794fa1..3cb7ee7 100644
--- a/ip/ipaddress.c
+++ b/ip/ipaddress.c
@@ -197,7 +197,7 @@ static void print_linktype(FILE *fp, struct rtattr *tb)
parse_rtattr_nested(linkinfo, IFLA_INFO_MAX, tb);
if (!linkinfo[IFLA_INFO_KIND])
- return;
+ goto no_info;
kind = RTA_DATA(linkinfo[IFLA_INFO_KIND]);
fprintf(fp, "%s", _SL_);
@@ -205,7 +205,7 @@ static void print_linktype(FILE *fp, struct rtattr *tb)
lu = get_link_kind(kind);
if (!lu || !lu->print_opt)
- return;
+ goto no_info;
if (1) {
struct rtattr *attr[lu->maxattr+1], **data = NULL;
@@ -221,6 +221,29 @@ static void print_linktype(FILE *fp, struct rtattr *tb)
lu->print_xstats)
lu->print_xstats(lu, fp, linkinfo[IFLA_INFO_XSTATS]);
}
+
+no_info:
+ if (!linkinfo[IFLA_INFO_SLAVE_KIND])
+ return;
+ kind = RTA_DATA(linkinfo[IFLA_INFO_SLAVE_KIND]);
+
+ fprintf(fp, "%s", _SL_);
+ fprintf(fp, " %s_slave ", kind);
+
+ lu = get_link_kind(kind);
+ if (!lu || !lu->print_slave_opt)
+ return;
+
+ if (1) {
+ struct rtattr *attr[lu->maxslattr+1], **data = NULL;
+
+ if (linkinfo[IFLA_INFO_SLAVE_DATA]) {
+ parse_rtattr_nested(attr, lu->maxslattr,
+ linkinfo[IFLA_INFO_SLAVE_DATA]);
+ data = attr;
+ }
+ lu->print_slave_opt(lu, fp, data);
+ }
}
static void print_vfinfo(FILE *fp, struct rtattr *vfinfo)
--
1.8.1.4
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH iproute2 net-next-for-3.13 1/2] iplink: display slave information
2014-02-10 8:11 [PATCH iproute2 net-next-for-3.13 1/2] iplink: display slave information Michal Kubecek
@ 2014-02-10 13:34 ` Sergei Shtylyov
2014-02-10 17:09 ` Stephen Hemminger
1 sibling, 0 replies; 4+ messages in thread
From: Sergei Shtylyov @ 2014-02-10 13:34 UTC (permalink / raw)
To: Michal Kubecek, Stephen Hemminger; +Cc: netdev
Hello.
On 10-02-2014 12:11, Michal Kubecek wrote:
> Add print_slave_opt() callback and maxslattr value to struct
> link_util. These are analogous to print_opt() and maxattr but
> relate to slave info (IFLA_INFO_SLAVE_{KIND,DATA}).
> Display the slave specific info in output of "ip -d link show".
> Signed-off-by: Michal Kubecek <mkubecek@suse.cz>
[...]
> diff --git a/ip/ipaddress.c b/ip/ipaddress.c
> index f794fa1..3cb7ee7 100644
> --- a/ip/ipaddress.c
> +++ b/ip/ipaddress.c
[...]
> @@ -221,6 +221,29 @@ static void print_linktype(FILE *fp, struct rtattr *tb)
> lu->print_xstats)
> lu->print_xstats(lu, fp, linkinfo[IFLA_INFO_XSTATS]);
> }
> +
> +no_info:
> + if (!linkinfo[IFLA_INFO_SLAVE_KIND])
> + return;
> + kind = RTA_DATA(linkinfo[IFLA_INFO_SLAVE_KIND]);
> +
> + fprintf(fp, "%s", _SL_);
> + fprintf(fp, " %s_slave ", kind);
> +
> + lu = get_link_kind(kind);
> + if (!lu || !lu->print_slave_opt)
> + return;
> +
> + if (1) {
Why is that?
> + struct rtattr *attr[lu->maxslattr+1], **data = NULL;
> +
> + if (linkinfo[IFLA_INFO_SLAVE_DATA]) {
> + parse_rtattr_nested(attr, lu->maxslattr,
> + linkinfo[IFLA_INFO_SLAVE_DATA]);
> + data = attr;
> + }
> + lu->print_slave_opt(lu, fp, data);
> + }
WBR, Sergei
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH iproute2 net-next-for-3.13 1/2] iplink: display slave information
2014-02-10 8:11 [PATCH iproute2 net-next-for-3.13 1/2] iplink: display slave information Michal Kubecek
2014-02-10 13:34 ` Sergei Shtylyov
@ 2014-02-10 17:09 ` Stephen Hemminger
2014-02-10 18:24 ` Michal Kubecek
1 sibling, 1 reply; 4+ messages in thread
From: Stephen Hemminger @ 2014-02-10 17:09 UTC (permalink / raw)
To: Michal Kubecek; +Cc: netdev
On Mon, 10 Feb 2014 09:11:46 +0100 (CET)
Michal Kubecek <mkubecek@suse.cz> wrote:
> + if (1) {
> + struct rtattr *attr[lu->maxslattr+1], **data = NULL;
> +
> + if (linkinfo[IFLA_INFO_SLAVE_DATA]) {
> + parse_rtattr_nested(attr, lu->maxslattr,
> + linkinfo[IFLA_INFO_SLAVE_DATA]);
> + data = attr;
> + }
> + lu->print_slave_opt(lu, fp, data);
> + }
> }
Ugly, please don't use if (1)
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH iproute2 net-next-for-3.13 1/2] iplink: display slave information
2014-02-10 17:09 ` Stephen Hemminger
@ 2014-02-10 18:24 ` Michal Kubecek
0 siblings, 0 replies; 4+ messages in thread
From: Michal Kubecek @ 2014-02-10 18:24 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: netdev
On Mon, Feb 10, 2014 at 09:09:16AM -0800, Stephen Hemminger wrote:
> On Mon, 10 Feb 2014 09:11:46 +0100 (CET)
> Michal Kubecek <mkubecek@suse.cz> wrote:
>
> > + if (1) {
> > + struct rtattr *attr[lu->maxslattr+1], **data = NULL;
> > +
> > + if (linkinfo[IFLA_INFO_SLAVE_DATA]) {
> > + parse_rtattr_nested(attr, lu->maxslattr,
> > + linkinfo[IFLA_INFO_SLAVE_DATA]);
> > + data = attr;
> > + }
> > + lu->print_slave_opt(lu, fp, data);
> > + }
> > }
>
> Ugly, please don't use if (1)
Normally I woudn't but it was already there this way in the original
code so I assumed there was a reason for that (even if I couldn't see
an obvious one).
Should I send a v2 or are you going to use the implementation submitted
by Jiri Pirko?
Michal Kubecek
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-02-10 18:25 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-10 8:11 [PATCH iproute2 net-next-for-3.13 1/2] iplink: display slave information Michal Kubecek
2014-02-10 13:34 ` Sergei Shtylyov
2014-02-10 17:09 ` Stephen Hemminger
2014-02-10 18:24 ` Michal Kubecek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).