From patchwork Tue Feb 20 12:43:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sabrina Dubroca X-Patchwork-Id: 875525 X-Patchwork-Delegate: dsahern@gmail.com Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3zm0fN6WxGz9ryy for ; Tue, 20 Feb 2018 23:43:40 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751725AbeBTMnh (ORCPT ); Tue, 20 Feb 2018 07:43:37 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:56228 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751610AbeBTMng (ORCPT ); Tue, 20 Feb 2018 07:43:36 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 74B227D85D; Tue, 20 Feb 2018 12:43:35 +0000 (UTC) Received: from localhost.localdomain (ovpn-204-72.brq.redhat.com [10.40.204.72]) by smtp.corp.redhat.com (Postfix) with ESMTP id 799D5AB599; Tue, 20 Feb 2018 12:43:34 +0000 (UTC) From: Sabrina Dubroca To: netdev@vger.kernel.org Cc: dsahern@gmail.com, sbrivio@redhat.com, serhe.popovych@gmail.com, Sabrina Dubroca Subject: [PATCH iproute2-next v2] ip link: add support to display extended tun attributes Date: Tue, 20 Feb 2018 13:43:22 +0100 Message-Id: <2ee799472ddf052722c5682506223244ce272606.1519124425.git.sd@queasysnail.net> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Tue, 20 Feb 2018 12:43:35 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Tue, 20 Feb 2018 12:43:35 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'sd@queasysnail.net' RCPT:'' Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Signed-off-by: Sabrina Dubroca Reviewed-by: Stefano Brivio --- 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, +};