From: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
To: Andy Roulin <aroulin@cumulusnetworks.com>, netdev@vger.kernel.org
Cc: dsahern@gmail.com, roopa@cumulusnetworks.com,
j.vosburgh@gmail.com, vfalico@gmail.com, andy@greyhouse.net
Subject: Re: [PATCH iproute2-next 3/3] iplink: bond: print 3ad actor/partner oper states as strings
Date: Sun, 27 Oct 2019 11:41:46 +0200 [thread overview]
Message-ID: <cd73c11e-e8bd-615d-0513-bb3e3797f342@cumulusnetworks.com> (raw)
In-Reply-To: <1572132594-2006-4-git-send-email-aroulin@cumulusnetworks.com>
On 27/10/2019 02:29, Andy Roulin wrote:
> The 802.3ad actor/partner operating states are only printed as
> numbers, e.g,
>
> ad_actor_oper_port_state 15
>
> Add an additional output in ip link show that prints a string describing
> the individual 3ad bit meanings in the following way:
>
> ad_actor_oper_port_state_str <active,short_timeout,aggregating,in_sync>
>
> JSON output is also supported, the field becomes a json array:
>
> "ad_actor_oper_port_state_str":
> ["active","short_timeout","aggregating","in_sync"]
>
> Signed-off-by: Andy Roulin <aroulin@cumulusnetworks.com>
> Acked-by: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
> Acked-by: Roopa Prabhu <roopa@cumulusnetworks.com>
> ---
> ip/iplink_bond_slave.c | 38 ++++++++++++++++++++++++++++++++++----
> 1 file changed, 34 insertions(+), 4 deletions(-)
>
> diff --git a/ip/iplink_bond_slave.c b/ip/iplink_bond_slave.c
> index 4eaf72b8..99beeca1 100644
> --- a/ip/iplink_bond_slave.c
> +++ b/ip/iplink_bond_slave.c
> @@ -68,6 +68,28 @@ static void print_slave_mii_status(FILE *f, struct rtattr *tb)
> slave_mii_status[status]);
> }
>
> +static void print_slave_oper_state(FILE *fp, const char *name, __u16 state)
> +{
> +
extra new line here
> + open_json_array(PRINT_ANY, name);
> + if (!is_json_context())
> + fprintf(fp, " <");
> +#define _PF(s, str) if (state&AD_STATE_##s) { \
> + state &= ~AD_STATE_##s; \
> + print_string(PRINT_ANY, NULL, \
> + state ? "%s," : "%s", str); }
> + _PF(LACP_ACTIVITY, "active");
> + _PF(LACP_TIMEOUT, "short_timeout");
> + _PF(AGGREGATION, "aggregating");
> + _PF(SYNCHRONIZATION, "in_sync");
> + _PF(COLLECTING, "collecting");
> + _PF(DISTRIBUTING, "distributing");
> + _PF(DEFAULTED, "defaulted");
> + _PF(EXPIRED, "expired");
> +#undef _PF
> + close_json_array(PRINT_ANY, "> ");
> +}
> +
> static void bond_slave_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
> {
> SPRINT_BUF(b1);
> @@ -106,17 +128,25 @@ static void bond_slave_print_opt(struct link_util *lu, FILE *f, struct rtattr *t
> "ad_aggregator_id %d ",
> rta_getattr_u16(tb[IFLA_BOND_SLAVE_AD_AGGREGATOR_ID]));
>
> - if (tb[IFLA_BOND_SLAVE_AD_ACTOR_OPER_PORT_STATE])
> + if (tb[IFLA_BOND_SLAVE_AD_ACTOR_OPER_PORT_STATE]) {
> + __u8 state = rta_getattr_u8(tb[IFLA_BOND_SLAVE_AD_ACTOR_OPER_PORT_STATE]);
> +
> print_int(PRINT_ANY,
> "ad_actor_oper_port_state",
> "ad_actor_oper_port_state %d ",
> - rta_getattr_u8(tb[IFLA_BOND_SLAVE_AD_ACTOR_OPER_PORT_STATE]));
> + state);
> + print_slave_oper_state(f, "ad_actor_oper_port_state_str", state);
> + }
> +
> + if (tb[IFLA_BOND_SLAVE_AD_PARTNER_OPER_PORT_STATE]) {
> + __u16 state = rta_getattr_u8(tb[IFLA_BOND_SLAVE_AD_PARTNER_OPER_PORT_STATE]);
>
> - if (tb[IFLA_BOND_SLAVE_AD_PARTNER_OPER_PORT_STATE])
> print_int(PRINT_ANY,
> "ad_partner_oper_port_state",
> "ad_partner_oper_port_state %d ",
> - rta_getattr_u16(tb[IFLA_BOND_SLAVE_AD_PARTNER_OPER_PORT_STATE]));
> + state);
> + print_slave_oper_state(f, "ad_partner_oper_port_state_str", state);
> + }
> }
>
> static int bond_slave_parse_opt(struct link_util *lu, int argc, char **argv,
>
next prev parent reply other threads:[~2019-10-27 9:41 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-26 23:29 [PATCH iproute2-net-next 0/3] pretty-print 802.3ad slave state Andy Roulin
2019-10-26 23:29 ` [PATCH net-next 1/3] bonding: move 3ad port state defs to include/uapi Andy Roulin
2019-10-26 23:29 ` [PATCH iproute2-next 2/3] include/uapi: update bonding kernel header Andy Roulin
2019-10-26 23:29 ` [PATCH iproute2-next 3/3] iplink: bond: print 3ad actor/partner oper states as strings Andy Roulin
2019-10-27 9:41 ` Nikolay Aleksandrov [this message]
2019-10-28 16:58 ` Stephen Hemminger
2019-10-27 1:31 ` [PATCH iproute2-net-next 0/3] pretty-print 802.3ad slave state David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=cd73c11e-e8bd-615d-0513-bb3e3797f342@cumulusnetworks.com \
--to=nikolay@cumulusnetworks.com \
--cc=andy@greyhouse.net \
--cc=aroulin@cumulusnetworks.com \
--cc=dsahern@gmail.com \
--cc=j.vosburgh@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=roopa@cumulusnetworks.com \
--cc=vfalico@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.