netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Vadim Kochan <vadim4j@gmail.com>
To: "netdev@vger.kernel.org" <netdev@vger.kernel.org>
Cc: Stephen Hemminger <stephen@networkplumber.org>
Subject: Re: [PATCH iproute2] ip link: Show devices by link type
Date: Wed, 3 Dec 2014 00:01:37 +0200	[thread overview]
Message-ID: <CAMw6YJJe_u1nL85J8mHR_71E_WY_aHJEC2fs9mynj4NuyQd1Sg@mail.gmail.com> (raw)
In-Reply-To: <1417370335-15772-1-git-send-email-vadim4j@gmail.com>

Hi,

The few things which were confused me a little:

#1 I think, I was not correct by calling it 'link type' in
descriptions, because it is rather the interface/device type than
link type ... so I can resend updated subject + man page in v2.

#2 Another think is that may be it would be better to consider the
ll_type_n2a too by the same 'ip link show type' or it is better to add
another option like 'ip link show link ether' and use ll_type_n2a to
filter devices by link type.

On Sun, Nov 30, 2014 at 7:58 PM, Vadim Kochan <vadim4j@gmail.com> wrote:
> Added new option 'type' to 'ip link show'
> command which allows to filter devices by
> link type name:
>
>     ip link show type bridge
>     ip link show type vlan
>
> Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
> ---
>  ip/ipaddress.c        | 24 ++++++++++++++++++++++++
>  ip/iplink.c           |  2 +-
>  man/man8/ip-link.8.in | 20 +++++++++++++++++++-
>  3 files changed, 44 insertions(+), 2 deletions(-)
>
> diff --git a/ip/ipaddress.c b/ip/ipaddress.c
> index 4d99324..a2f7a83 100644
> --- a/ip/ipaddress.c
> +++ b/ip/ipaddress.c
> @@ -57,6 +57,7 @@ static struct
>         int flushe;
>         int group;
>         int master;
> +       char *link_kind;
>  } filter;
>
>  static int do_link;
> @@ -189,6 +190,18 @@ static void print_linkmode(FILE *f, struct rtattr *tb)
>                 fprintf(f, "mode %s ", link_modes[mode]);
>  }
>
> +static char *parse_link_kind(struct rtattr *tb)
> +{
> +       struct rtattr *linkinfo[IFLA_INFO_MAX+1];
> +
> +       parse_rtattr_nested(linkinfo, IFLA_INFO_MAX, tb);
> +
> +       if (linkinfo[IFLA_INFO_KIND])
> +               return RTA_DATA(linkinfo[IFLA_INFO_KIND]);
> +
> +       return "";
> +}
> +
>  static void print_linktype(FILE *fp, struct rtattr *tb)
>  {
>         struct rtattr *linkinfo[IFLA_INFO_MAX+1];
> @@ -551,6 +564,14 @@ int print_linkinfo(const struct sockaddr_nl *who,
>         else if (filter.master > 0)
>                 return -1;
>
> +       if (filter.link_kind && tb[IFLA_LINKINFO]) {
> +               char *link_kind = parse_link_kind(tb[IFLA_LINKINFO]);
> +               if (strcmp(link_kind, filter.link_kind)) {
> +                       return -1;
> +               }
> +       } else if (filter.link_kind)
> +               return -1;
> +
>         if (n->nlmsg_type == RTM_DELLINK)
>                 fprintf(fp, "Deleted ");
>
> @@ -1293,6 +1314,9 @@ static int ipaddr_list_flush_or_save(int argc, char **argv, int action)
>                         if (!ifindex)
>                                 invarg("Device does not exist\n", *argv);
>                         filter.master = ifindex;
> +               } else if (do_link && strcmp(*argv, "type") == 0) {
> +                       NEXT_ARG();
> +                       filter.link_kind = *argv;
>                 } else {
>                         if (strcmp(*argv, "dev") == 0) {
>                                 NEXT_ARG();
> diff --git a/ip/iplink.c b/ip/iplink.c
> index ce6eb3e..f9a75d5 100644
> --- a/ip/iplink.c
> +++ b/ip/iplink.c
> @@ -82,7 +82,7 @@ void iplink_usage(void)
>         fprintf(stderr, "                         [ master DEVICE ]\n");
>         fprintf(stderr, "                         [ nomaster ]\n");
>         fprintf(stderr, "                         [ addrgenmode { eui64 | none } ]\n");
> -       fprintf(stderr, "       ip link show [ DEVICE | group GROUP ] [up] [master DEV]\n");
> +       fprintf(stderr, "       ip link show [ DEVICE | group GROUP ] [up] [master DEV] [type TYPE]\n");
>
>         if (iplink_have_newlink()) {
>                 fprintf(stderr, "       ip link help [ TYPE ]\n");
> diff --git a/man/man8/ip-link.8.in b/man/man8/ip-link.8.in
> index 9d4e3da..4233291 100644
> --- a/man/man8/ip-link.8.in
> +++ b/man/man8/ip-link.8.in
> @@ -148,7 +148,9 @@ ip-link \- network device configuration
>  .IR GROUP " | "
>  .BR up " | "
>  .B master
> -.IR DEVICE " ]"
> +.IR DEVICE " | "
> +.B type
> +.IR TYPE " ]"
>
>  .ti -8
>  .B ip link help
> @@ -688,6 +690,12 @@ only display running interfaces.
>  .I DEVICE
>  specifies the master device which enslaves devices to show.
>
> +.TP
> +.BI type " TYPE "
> +.I TYPE
> +specifies the link type of devices to show.
> +
> +.TP
>  The show command has additional formatting options:
>
>  .TP
> @@ -719,6 +727,16 @@ ip link show
>  Shows the state of all network interfaces on the system.
>  .RE
>  .PP
> +ip link show type bridge
> +.RS 4
> +Shows the bridge devices.
> +.RE
> +.PP
> +ip link show type vlan
> +.RS 4
> +Shows the vlan devices.
> +.RE
> +.PP
>  ip link set dev ppp0 mtu 1400
>  .RS 4
>  Change the MTU the ppp0 device.
> --
> 2.1.3
>

  reply	other threads:[~2014-12-02 22:01 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-30 17:58 [PATCH iproute2] ip link: Show devices by link type Vadim Kochan
2014-12-02 22:01 ` Vadim Kochan [this message]
2014-12-03  0:55 ` Roopa Prabhu
2014-12-03  1:13   ` vadim4j
2014-12-03 10:59     ` Vadim Kochan
2014-12-03 14:40     ` Roopa Prabhu
2014-12-03 14:47       ` Vadim Kochan
2014-12-03 15:08         ` Vadim Kochan

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=CAMw6YJJe_u1nL85J8mHR_71E_WY_aHJEC2fs9mynj4NuyQd1Sg@mail.gmail.com \
    --to=vadim4j@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=stephen@networkplumber.org \
    /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 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).