From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf0-f67.google.com ([209.85.215.67]:37611 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932116AbeBSWTf (ORCPT ); Mon, 19 Feb 2018 17:19:35 -0500 Received: by mail-lf0-f67.google.com with SMTP id y19so1521883lfd.4 for ; Mon, 19 Feb 2018 14:19:35 -0800 (PST) Subject: Re: [PATCH iproute2-next] ip link: add support to display extended tun attributes To: Sabrina Dubroca , netdev@vger.kernel.org References: <8bea9df2ab3ee8202f6696fdbea331abacdbb8b5.1518775084.git.sd@queasysnail.net> Cc: David Ahern , sbrivio@redhat.com From: Serhey Popovych Message-ID: <73c75acb-4607-d405-8a0d-71b2904e1f64@gmail.com> Date: Tue, 20 Feb 2018 00:19:25 +0200 MIME-Version: 1.0 In-Reply-To: <8bea9df2ab3ee8202f6696fdbea331abacdbb8b5.1518775084.git.sd@queasysnail.net> Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="SZ3EEZvyptM0iabAI6XfPoXQ6anSiiTO8" Sender: netdev-owner@vger.kernel.org List-ID: This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --SZ3EEZvyptM0iabAI6XfPoXQ6anSiiTO8 Content-Type: multipart/mixed; boundary="RmipeMQMz4uFHINf5QN0bWF42r6OyorQb"; protected-headers="v1" From: Serhey Popovych To: Sabrina Dubroca , netdev@vger.kernel.org Cc: David Ahern , sbrivio@redhat.com Message-ID: <73c75acb-4607-d405-8a0d-71b2904e1f64@gmail.com> Subject: Re: [PATCH iproute2-next] ip link: add support to display extended tun attributes References: <8bea9df2ab3ee8202f6696fdbea331abacdbb8b5.1518775084.git.sd@queasysnail.net> In-Reply-To: <8bea9df2ab3ee8202f6696fdbea331abacdbb8b5.1518775084.git.sd@queasysnail.net> --RmipeMQMz4uFHINf5QN0bWF42r6OyorQb Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Sabrina Dubroca wrote: > Signed-off-by: Sabrina Dubroca > Reviewed-by: Stefano Brivio > --- >=20 > I included the uapi changes from the kernel patch. Let me know if I > need to resend without the header changes. >=20 > include/uapi/linux/if_link.h | 18 ++++++++++ > ip/iptuntap.c | 85 ++++++++++++++++++++++++++++++++++++= ++++++++ > 2 files changed, 103 insertions(+) >=20 > diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.= h > index 1726e49fbc6b..e2af6588b50d 100644 > --- a/include/uapi/linux/if_link.h > +++ b/include/uapi/linux/if_link.h > @@ -936,4 +936,22 @@ enum { > IFLA_EVENT_BONDING_OPTIONS, /* change in bonding options */ > }; > =20 > +/* tun section */ > + > +enum { > + IFLA_TUN_UNSPEC, > + IFLA_TUN_OWNER, > + IFLA_TUN_GROUP, > + IFLA_TUN_TYPE, > + IFLA_TUN_PI, > + IFLA_TUN_VNET_HDR, > + IFLA_TUN_PERSIST, > + IFLA_TUN_MULTI_QUEUE, > + IFLA_TUN_NUM_QUEUES, > + IFLA_TUN_NUM_DISABLED_QUEUES, > + __IFLA_TUN_MAX, > +}; > + > +#define IFLA_TUN_MAX (__IFLA_TUN_MAX - 1) > + > #endif /* _LINUX_IF_LINK_H */ > diff --git a/ip/iptuntap.c b/ip/iptuntap.c > index 4628db2832b4..520244c31b89 100644 > --- a/ip/iptuntap.c > +++ b/ip/iptuntap.c > @@ -469,3 +469,88 @@ int do_iptuntap(int argc, char **argv) > *argv); > exit(-1); > } > + > +static void print_owner(FILE *f, uid_t uid) > +{ > + struct passwd *pw =3D 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 =3D 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]) { > + __u8 mq =3D rta_getattr_u8(tb[IFLA_TUN_MULTI_QUEUE]); > + if (!mq) > + return; > + fprintf(f, "multi_queue "); > + } > + > + if (tb[IFLA_TUN_NUM_QUEUES]) { > + __u32 numq =3D rta_getattr_u32(tb[IFLA_TUN_NUM_QUEUES]); > + fprintf(f, "numqueues %u ", numq); > + } > + > + if (tb[IFLA_TUN_NUM_DISABLED_QUEUES]) { > + __u32 numq =3D rta_getattr_u32(tb[IFLA_TUN_NUM_DISABLED_QUEUES]); > + fprintf(f, "numdisabled %u ", numq); > + } > +} > + > +static void tun_print_opt(struct link_util *lu, FILE *f, struct rtattr= *tb[]) > +{ > + if (!tb) > + return; > + > + if (tb[IFLA_TUN_TYPE]) { > + __u8 type =3D rta_getattr_u8(tb[IFLA_TUN_TYPE]); > + if (type =3D=3D IFF_TUN) > + fprintf(f, "type tun "); > + else if (type =3D=3D IFF_TAP) > + fprintf(f, "type tap "); > + else > + fprintf(f, "type UNKNOWN:%hhu ", type); > + } > + > + if (tb[IFLA_TUN_PI]) { > + __u8 pi =3D rta_getattr_u8(tb[IFLA_TUN_PI]); > + fprintf(f, "pi %s ", pi ? "on" : "off"); > + } > + > + if (tb[IFLA_TUN_VNET_HDR]) { > + __u8 vnet =3D rta_getattr_u8(tb[IFLA_TUN_VNET_HDR]); > + fprintf(f, "vnet_hdr %s ", vnet ? "on" : "off"); > + } > + > + print_mq(f, tb); > + > + if (tb[IFLA_TUN_PERSIST]) { > + __u8 persist =3D rta_getattr_u8(tb[IFLA_TUN_PERSIST]); > + fprintf(f, "persist %s ", persist ? "on" : "off"); > + } > + > + 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 =3D { > + .id =3D "tun", > + .maxattr =3D IFLA_TUN_MAX, > + .print_opt =3D tun_print_opt, > +}; >=20 I get following checkpatch.pl warnings: WARNING: Missing a blank line after declarations #73: FILE: ip/iptuntap.c:497: + __u8 mq =3D rta_getattr_u8(tb[IFLA_TUN_MULTI_QUEUE]); + if (!mq) WARNING: Missing a blank line after declarations #80: FILE: ip/iptuntap.c:504: + __u32 numq =3D rta_getattr_u32(tb[IFLA_TUN_NUM_QUEUES]); + fprintf(f, "numqueues %u ", numq); WARNING: Missing a blank line after declarations #85: FILE: ip/iptuntap.c:509: + __u32 numq =3D rta_getattr_u32(tb[IFLA_TUN_NUM_DISABLED_QUEUES]); + fprintf(f, "numdisabled %u ", numq); maybe they should be fixed before accepting? I wonder if we can use tun_print_opt() and it's infrastructure in print_tuntap(). Now they use read_prop() to read same information from sysfs while netlink provides it. --RmipeMQMz4uFHINf5QN0bWF42r6OyorQb-- --SZ3EEZvyptM0iabAI6XfPoXQ6anSiiTO8 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) iQEcBAEBAgAGBQJai01zAAoJEBTawMmQ61bBXaEH/jJeLGbi0luJgWOEsWxf83H6 xnItO5RGR/rll9/YMYuhjy2yUdvJJV1R3MrGg8Q/I83Kx/WF+SJDoXSuLEldB7ns a/S43ATkOzvrWb4lAecN2QqxQXpgTSPcwW3Ejq0+JdFzI/gY98SlfMJavuz2OZ55 veLvHsl7QKTD3y6dKfin6FsbUjow2uFBgtdnl9LRxgEkyRlsy8l9GbkPLTsDNWNi mr9pKU+FMYu3hAoqEzmq+1O43p/+LZl0mPzBtO4bFOwtJnHvO55Komkqp6EpyWH8 r0RSyvu2pxv3Ame3iR8iMIrxKcjoErJTUUEsBnMlX1eyjzk4fIFY3S+i2jFO7rA= =rMmw -----END PGP SIGNATURE----- --SZ3EEZvyptM0iabAI6XfPoXQ6anSiiTO8--