From: Stephen Hemminger Date: Mon, 11 Apr 2016 22:07:51 +0000 (+0000) Subject: ip: only display phys attributes with details option X-Git-Tag: v4.6.0~34 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=11522e7d02758653145f68bda7a6d123bdd0654b;p=thirdparty%2Fiproute2.git ip: only display phys attributes with details option Since output of ip commands are already cluttered, move the physical port details under a show_details option. --- diff --git a/ip/ipaddress.c b/ip/ipaddress.c index ca97907fe..f27d423ca 100644 --- a/ip/ipaddress.c +++ b/ip/ipaddress.c @@ -782,7 +782,7 @@ int print_linkinfo(const struct sockaddr_nl *who, fprintf(fp, "%d: ", ifi->ifi_index); color_fprintf(fp, COLOR_IFNAME, "%s", - tb[IFLA_IFNAME] ? rta_getattr_str(tb[IFLA_IFNAME]) : ""); + tb[IFLA_IFNAME] ? rta_getattr_str(tb[IFLA_IFNAME]) : ""); if (tb[IFLA_LINK]) { SPRINT_BUF(b1); @@ -813,26 +813,6 @@ int print_linkinfo(const struct sockaddr_nl *who, fprintf(fp, "master %s ", ll_idx_n2a(*(int *)RTA_DATA(tb[IFLA_MASTER]), b1)); } - if (tb[IFLA_PHYS_PORT_NAME]) - fprintf(fp, "portname %s ", - rta_getattr_str(tb[IFLA_PHYS_PORT_NAME])); - - if (tb[IFLA_PHYS_PORT_ID]) { - SPRINT_BUF(b1); - fprintf(fp, "portid %s ", - hexstring_n2a(RTA_DATA(tb[IFLA_PHYS_PORT_ID]), - RTA_PAYLOAD(tb[IFLA_PHYS_PORT_ID]), - b1, sizeof(b1))); - } - - if (tb[IFLA_PHYS_SWITCH_ID]) { - SPRINT_BUF(b1); - fprintf(fp, "switchid %s ", - hexstring_n2a(RTA_DATA(tb[IFLA_PHYS_SWITCH_ID]), - RTA_PAYLOAD(tb[IFLA_PHYS_SWITCH_ID]), - b1, sizeof(b1))); - } - if (tb[IFLA_OPERSTATE]) print_operstate(fp, rta_getattr_u8(tb[IFLA_OPERSTATE])); @@ -856,10 +836,10 @@ int print_linkinfo(const struct sockaddr_nl *who, if (tb[IFLA_ADDRESS]) { color_fprintf(fp, COLOR_MAC, "%s", - ll_addr_n2a(RTA_DATA(tb[IFLA_ADDRESS]), - RTA_PAYLOAD(tb[IFLA_ADDRESS]), - ifi->ifi_type, - b1, sizeof(b1))); + ll_addr_n2a(RTA_DATA(tb[IFLA_ADDRESS]), + RTA_PAYLOAD(tb[IFLA_ADDRESS]), + ifi->ifi_type, + b1, sizeof(b1))); } if (tb[IFLA_BROADCAST]) { if (ifi->ifi_flags&IFF_POINTOPOINT) @@ -867,10 +847,10 @@ int print_linkinfo(const struct sockaddr_nl *who, else fprintf(fp, " brd "); color_fprintf(fp, COLOR_MAC, "%s", - ll_addr_n2a(RTA_DATA(tb[IFLA_BROADCAST]), - RTA_PAYLOAD(tb[IFLA_BROADCAST]), - ifi->ifi_type, - b1, sizeof(b1))); + ll_addr_n2a(RTA_DATA(tb[IFLA_BROADCAST]), + RTA_PAYLOAD(tb[IFLA_BROADCAST]), + ifi->ifi_type, + b1, sizeof(b1))); } } @@ -888,21 +868,46 @@ int print_linkinfo(const struct sockaddr_nl *who, fprintf(fp, " protodown on "); } - if (tb[IFLA_PROMISCUITY] && show_details) - fprintf(fp, " promiscuity %u ", - *(int *)RTA_DATA(tb[IFLA_PROMISCUITY])); + if (show_details) { + if (tb[IFLA_PROMISCUITY]) + fprintf(fp, " promiscuity %u ", + *(int *)RTA_DATA(tb[IFLA_PROMISCUITY])); + + if (tb[IFLA_LINKINFO]) + print_linktype(fp, tb[IFLA_LINKINFO]); + + if (do_link && tb[IFLA_AF_SPEC]) + print_af_spec(fp, tb[IFLA_AF_SPEC]); + + if (tb[IFLA_NUM_TX_QUEUES]) + fprintf(fp, "numtxqueues %u ", + rta_getattr_u32(tb[IFLA_NUM_TX_QUEUES])); - if (tb[IFLA_LINKINFO] && show_details) - print_linktype(fp, tb[IFLA_LINKINFO]); + if (tb[IFLA_NUM_RX_QUEUES]) + fprintf(fp, "numrxqueues %u ", + rta_getattr_u32(tb[IFLA_NUM_RX_QUEUES])); - if (do_link && tb[IFLA_AF_SPEC] && show_details) - print_af_spec(fp, tb[IFLA_AF_SPEC]); + if (tb[IFLA_PHYS_PORT_NAME]) + fprintf(fp, "portname %s ", + rta_getattr_str(tb[IFLA_PHYS_PORT_NAME])); - if (tb[IFLA_NUM_TX_QUEUES] && show_details) - fprintf(fp, "numtxqueues %u ", rta_getattr_u32(tb[IFLA_NUM_TX_QUEUES])); + if (tb[IFLA_PHYS_PORT_ID]) { + SPRINT_BUF(b1); + fprintf(fp, "portid %s ", + hexstring_n2a(RTA_DATA(tb[IFLA_PHYS_PORT_ID]), + RTA_PAYLOAD(tb[IFLA_PHYS_PORT_ID]), + b1, sizeof(b1))); + } + + if (tb[IFLA_PHYS_SWITCH_ID]) { + SPRINT_BUF(b1); + fprintf(fp, "switchid %s ", + hexstring_n2a(RTA_DATA(tb[IFLA_PHYS_SWITCH_ID]), + RTA_PAYLOAD(tb[IFLA_PHYS_SWITCH_ID]), + b1, sizeof(b1))); + } + } - if (tb[IFLA_NUM_RX_QUEUES] && show_details) - fprintf(fp, "numrxqueues %u ", rta_getattr_u32(tb[IFLA_NUM_RX_QUEUES])); if ((do_link || show_details) && tb[IFLA_IFALIAS]) { fprintf(fp, "%s alias %s", _SL_,