* [PATCH iproute2-next v2] ip link: add support to display extended tun attributes
@ 2018-02-20 12:43 Sabrina Dubroca
2018-02-20 16:34 ` David Ahern
0 siblings, 1 reply; 5+ messages in thread
From: Sabrina Dubroca @ 2018-02-20 12:43 UTC (permalink / raw)
To: netdev; +Cc: dsahern, sbrivio, serhe.popovych, Sabrina Dubroca
Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
Reviewed-by: Stefano Brivio <sbrivio@redhat.com>
---
v2: define print_onoff to print flags, fix checkpatch warnings, drop
header changes
ip/iptuntap.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 86 insertions(+)
diff --git a/ip/iptuntap.c b/ip/iptuntap.c
index 4628db2832b4..07253870472f 100644
--- a/ip/iptuntap.c
+++ b/ip/iptuntap.c
@@ -469,3 +469,89 @@ int do_iptuntap(int argc, char **argv)
*argv);
exit(-1);
}
+
+static void print_owner(FILE *f, uid_t uid)
+{
+ struct passwd *pw = getpwuid(uid);
+
+ if (pw)
+ fprintf(f, "user %s ", pw->pw_name);
+ else
+ fprintf(f, "user %u ", uid);
+}
+
+static void print_group(FILE *f, gid_t gid)
+{
+ struct group *group = getgrgid(gid);
+
+ if (group)
+ fprintf(f, "group %s ", group->gr_name);
+ else
+ fprintf(f, "group %u ", gid);
+}
+
+static void print_mq(FILE *f, struct rtattr *tb[])
+{
+ if (!tb[IFLA_TUN_MULTI_QUEUE] ||
+ !rta_getattr_u8(tb[IFLA_TUN_MULTI_QUEUE]))
+ return;
+
+ fprintf(f, "multi_queue ");
+
+ if (tb[IFLA_TUN_NUM_QUEUES]) {
+ fprintf(f, "numqueues %u ",
+ rta_getattr_u32(tb[IFLA_TUN_NUM_QUEUES]));
+ }
+
+ if (tb[IFLA_TUN_NUM_DISABLED_QUEUES]) {
+ fprintf(f, "numdisabled %u ",
+ rta_getattr_u32(tb[IFLA_TUN_NUM_DISABLED_QUEUES]));
+ }
+}
+
+static void print_onoff(FILE *f, const char *flag, __u8 val)
+{
+ fprintf(f, "%s %s ", flag, val ? "on" : "off");
+}
+
+static void tun_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
+{
+ if (!tb)
+ return;
+
+ if (tb[IFLA_TUN_TYPE]) {
+ __u8 type = rta_getattr_u8(tb[IFLA_TUN_TYPE]);
+
+ if (type == IFF_TUN)
+ fprintf(f, "type tun ");
+ else if (type == IFF_TAP)
+ fprintf(f, "type tap ");
+ else
+ fprintf(f, "type UNKNOWN:%hhu ", type);
+ }
+
+ if (tb[IFLA_TUN_PI])
+ print_onoff(f, "pi", rta_getattr_u8(tb[IFLA_TUN_PI]));
+
+ if (tb[IFLA_TUN_VNET_HDR]) {
+ print_onoff(f, "vnet_hdr",
+ rta_getattr_u8(tb[IFLA_TUN_VNET_HDR]));
+ }
+
+ print_mq(f, tb);
+
+ if (tb[IFLA_TUN_PERSIST])
+ print_onoff(f, "persist", rta_getattr_u8(tb[IFLA_TUN_PERSIST]));
+
+ if (tb[IFLA_TUN_OWNER])
+ print_owner(f, rta_getattr_u32(tb[IFLA_TUN_OWNER]));
+
+ if (tb[IFLA_TUN_GROUP])
+ print_group(f, rta_getattr_u32(tb[IFLA_TUN_GROUP]));
+}
+
+struct link_util tun_link_util = {
+ .id = "tun",
+ .maxattr = IFLA_TUN_MAX,
+ .print_opt = tun_print_opt,
+};
--
2.16.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH iproute2-next v2] ip link: add support to display extended tun attributes
2018-02-20 12:43 [PATCH iproute2-next v2] ip link: add support to display extended tun attributes Sabrina Dubroca
@ 2018-02-20 16:34 ` David Ahern
2018-02-20 17:18 ` Sabrina Dubroca
2018-02-20 18:40 ` Stephen Hemminger
0 siblings, 2 replies; 5+ messages in thread
From: David Ahern @ 2018-02-20 16:34 UTC (permalink / raw)
To: Sabrina Dubroca, netdev; +Cc: sbrivio, serhe.popovych
On 2/20/18 5:43 AM, Sabrina Dubroca wrote:
> Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
> Reviewed-by: Stefano Brivio <sbrivio@redhat.com>
> ---
> v2: define print_onoff to print flags, fix checkpatch warnings, drop
> header changes
>
> ip/iptuntap.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 86 insertions(+)
applied to iproute2-next.
>
> diff --git a/ip/iptuntap.c b/ip/iptuntap.c
> index 4628db2832b4..07253870472f 100644
> --- a/ip/iptuntap.c
> +++ b/ip/iptuntap.c
> @@ -469,3 +469,89 @@ int do_iptuntap(int argc, char **argv)
> *argv);
> exit(-1);
> }
> +
> +static void print_owner(FILE *f, uid_t uid)
> +{
> + struct passwd *pw = getpwuid(uid);
> +
> + if (pw)
> + fprintf(f, "user %s ", pw->pw_name);
> + else
> + fprintf(f, "user %u ", uid);
> +}
> +
> +static void print_group(FILE *f, gid_t gid)
> +{
> + struct group *group = getgrgid(gid);
> +
> + if (group)
> + fprintf(f, "group %s ", group->gr_name);
> + else
> + fprintf(f, "group %u ", gid);
> +}
> +
Those helpers can be re-used to make 'ip tuntap show' better too.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH iproute2-next v2] ip link: add support to display extended tun attributes
2018-02-20 16:34 ` David Ahern
@ 2018-02-20 17:18 ` Sabrina Dubroca
2018-02-20 18:40 ` Stephen Hemminger
1 sibling, 0 replies; 5+ messages in thread
From: Sabrina Dubroca @ 2018-02-20 17:18 UTC (permalink / raw)
To: David Ahern; +Cc: netdev, sbrivio, serhe.popovych
2018-02-20, 09:34:15 -0700, David Ahern wrote:
> On 2/20/18 5:43 AM, Sabrina Dubroca wrote:
> > Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
> > Reviewed-by: Stefano Brivio <sbrivio@redhat.com>
> > ---
> > v2: define print_onoff to print flags, fix checkpatch warnings, drop
> > header changes
> >
> > ip/iptuntap.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> > 1 file changed, 86 insertions(+)
>
> applied to iproute2-next.
Thanks!
> >
> > diff --git a/ip/iptuntap.c b/ip/iptuntap.c
> > index 4628db2832b4..07253870472f 100644
> > --- a/ip/iptuntap.c
> > +++ b/ip/iptuntap.c
> > @@ -469,3 +469,89 @@ int do_iptuntap(int argc, char **argv)
> > *argv);
> > exit(-1);
> > }
> > +
> > +static void print_owner(FILE *f, uid_t uid)
> > +{
> > + struct passwd *pw = getpwuid(uid);
> > +
> > + if (pw)
> > + fprintf(f, "user %s ", pw->pw_name);
> > + else
> > + fprintf(f, "user %u ", uid);
> > +}
> > +
> > +static void print_group(FILE *f, gid_t gid)
> > +{
> > + struct group *group = getgrgid(gid);
> > +
> > + if (group)
> > + fprintf(f, "group %s ", group->gr_name);
> > + else
> > + fprintf(f, "group %u ", gid);
> > +}
> > +
>
>
> Those helpers can be re-used to make 'ip tuntap show' better too.
Actually, I didn't want to do that, because that command currently
always prints a numeric value, and I don't want to change the output
format (in case someone is parsing it and expects the raw uid/gid).
--
Sabrina
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH iproute2-next v2] ip link: add support to display extended tun attributes
2018-02-20 16:34 ` David Ahern
2018-02-20 17:18 ` Sabrina Dubroca
@ 2018-02-20 18:40 ` Stephen Hemminger
2018-02-20 20:19 ` David Ahern
1 sibling, 1 reply; 5+ messages in thread
From: Stephen Hemminger @ 2018-02-20 18:40 UTC (permalink / raw)
To: David Ahern; +Cc: Sabrina Dubroca, netdev, sbrivio, serhe.popovych
On Tue, 20 Feb 2018 09:34:15 -0700
David Ahern <dsahern@gmail.com> wrote:
> On 2/20/18 5:43 AM, Sabrina Dubroca wrote:
> > Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
> > Reviewed-by: Stefano Brivio <sbrivio@redhat.com>
> > ---
> > v2: define print_onoff to print flags, fix checkpatch warnings, drop
> > header changes
> >
> > ip/iptuntap.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> > 1 file changed, 86 insertions(+)
>
> applied to iproute2-next.
>
> >
> > diff --git a/ip/iptuntap.c b/ip/iptuntap.c
> > index 4628db2832b4..07253870472f 100644
> > --- a/ip/iptuntap.c
> > +++ b/ip/iptuntap.c
> > @@ -469,3 +469,89 @@ int do_iptuntap(int argc, char **argv)
> > *argv);
> > exit(-1);
> > }
> > +
> > +static void print_owner(FILE *f, uid_t uid)
> > +{
> > + struct passwd *pw = getpwuid(uid);
> > +
> > + if (pw)
> > + fprintf(f, "user %s ", pw->pw_name);
> > + else
> > + fprintf(f, "user %u ", uid);
> > +}
> > +
> > +static void print_group(FILE *f, gid_t gid)
> > +{
> > + struct group *group = getgrgid(gid);
> > +
> > + if (group)
> > + fprintf(f, "group %s ", group->gr_name);
> > + else
> > + fprintf(f, "group %u ", gid);
> > +}
> > +
>
>
> Those helpers can be re-used to make 'ip tuntap show' better too.
These should support JSON output.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH iproute2-next v2] ip link: add support to display extended tun attributes
2018-02-20 18:40 ` Stephen Hemminger
@ 2018-02-20 20:19 ` David Ahern
0 siblings, 0 replies; 5+ messages in thread
From: David Ahern @ 2018-02-20 20:19 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: Sabrina Dubroca, netdev, sbrivio, serhe.popovych
On 2/20/18 11:40 AM, Stephen Hemminger wrote:
>>> diff --git a/ip/iptuntap.c b/ip/iptuntap.c
>>> index 4628db2832b4..07253870472f 100644
>>> --- a/ip/iptuntap.c
>>> +++ b/ip/iptuntap.c
>>> @@ -469,3 +469,89 @@ int do_iptuntap(int argc, char **argv)
>>> *argv);
>>> exit(-1);
>>> }
>>> +
>>> +static void print_owner(FILE *f, uid_t uid)
>>> +{
>>> + struct passwd *pw = getpwuid(uid);
>>> +
>>> + if (pw)
>>> + fprintf(f, "user %s ", pw->pw_name);
>>> + else
>>> + fprintf(f, "user %u ", uid);
>>> +}
>>> +
>>> +static void print_group(FILE *f, gid_t gid)
>>> +{
>>> + struct group *group = getgrgid(gid);
>>> +
>>> + if (group)
>>> + fprintf(f, "group %s ", group->gr_name);
>>> + else
>>> + fprintf(f, "group %u ", gid);
>>> +}
>>> +
>>
>>
>> Those helpers can be re-used to make 'ip tuntap show' better too.
>
> These should support JSON output.
>
Good point. Missed that detail. Sabrina: Please send a patch to fix the
json output.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2018-02-20 20:19 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-02-20 12:43 [PATCH iproute2-next v2] ip link: add support to display extended tun attributes Sabrina Dubroca
2018-02-20 16:34 ` David Ahern
2018-02-20 17:18 ` Sabrina Dubroca
2018-02-20 18:40 ` Stephen Hemminger
2018-02-20 20:19 ` David Ahern
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).