From patchwork Mon Oct 30 20:57:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mahesh Bandewar X-Patchwork-Id: 832166 X-Patchwork-Delegate: shemminger@vyatta.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=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bandewar-net.20150623.gappssmtp.com header.i=@bandewar-net.20150623.gappssmtp.com header.b="Pp+gK4jc"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3yQmyx5sD0z9sPm for ; Tue, 31 Oct 2017 07:58:01 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933148AbdJ3U57 (ORCPT ); Mon, 30 Oct 2017 16:57:59 -0400 Received: from mail-io0-f195.google.com ([209.85.223.195]:54936 "EHLO mail-io0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932821AbdJ3U55 (ORCPT ); Mon, 30 Oct 2017 16:57:57 -0400 Received: by mail-io0-f195.google.com with SMTP id e89so30275347ioi.11 for ; Mon, 30 Oct 2017 13:57:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bandewar-net.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=AYmsNi4zkmZJZMovcQ8rKULltn0PDQQFs+R4tetw24g=; b=Pp+gK4jcBWc+b54/Jg5pcG2BrMw3e2LFHwN+S3fWw76+Tw2a7r9/dcYdQY1+z2wyHQ G9pWrqXX5rBMr9brf8nAE/gZgYiyZLirIFuxsd35T24qRmPTpamVSOFNzskRyDNA+UYE UEtZA7MDjl0yoau/jkpdJYk5cBzVo77cBiG4Re4WJ1YRMqTmDwyPS/WjYpqNvG9trcZV DLKrn/gp1KESQhWmJX2hf3ts6KSHNqQGDym/gJVOqZ0qZxsH4IhUTgPDmELn3FhB0m/l lBWiuaT4zWzKrdYwkX6ljRZ+uQjJr8PxeunpRKlSkVZpqmjCUPv6bjPPXMr/vdUj9rj/ gt7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=AYmsNi4zkmZJZMovcQ8rKULltn0PDQQFs+R4tetw24g=; b=s+7Wz4kjP7SiYO4o0QcH/zbGhUCoePKg+ti/Zgmw4X7+W3LvH3qWgXI1s2JAQkK9/x XaejieOSJuW7zCSxxgdYNzCw2xaC/lTLzuq2p38uI0rlflvoq6C3rwGNB1osuqQzBEgn aaWxkp2jDWuzcV53yg0lAX/yK6P5688tT1t1XE7FL+6Z7JxVbQ8+uwSMzze6xUnbWp4K K9RFArY2JsUapmHdGb56uuv2CCaXkNbyHrjo+4kFij/965ZwYujb0LA3usnmDrDs374s k7k6ay9eqjoSUxEo/VdtdFTylN8BJ+SaW+/vRuNM6GUni5yc0MZyN4dJjUvxgb1YWJOT V4rA== X-Gm-Message-State: AMCzsaVP6Rz9nUCPLi9pH+FV3w0jHdmzX9o3NP8qN+cpENth/CNb+tLA NYww1sA6u6ZnD1OnckSbKiLY8k1Gftc= X-Google-Smtp-Source: ABhQp+RYrGtNdZI4BEDYyQQSC1aeKNOsRFw8X19X3UR3vwFg/l79rynluIK6WsNDHmUT6e+W6mhfgQ== X-Received: by 10.107.185.6 with SMTP id j6mr12770742iof.221.1509397076231; Mon, 30 Oct 2017 13:57:56 -0700 (PDT) Received: from localhost ([2620:15c:2c4:201:8b4:b83a:a2ec:9abe]) by smtp.gmail.com with ESMTPSA id d129sm6563881ioe.1.2017.10.30.13.57.55 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Mon, 30 Oct 2017 13:57:55 -0700 (PDT) From: Mahesh Bandewar To: Netdev , Stephen Hemminger Cc: Eric Dumazet , David Miller , Changgong Li , Mahesh Bandewar , Mahesh Bandewar Subject: [PATCH] ip/ipvlan: enhance ability to add mode flags to existing modes Date: Mon, 30 Oct 2017 13:57:51 -0700 Message-Id: <20171030205751.8280-1-mahesh@bandewar.net> X-Mailer: git-send-email 2.15.0.rc2.357.g7e34df9404-goog Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Mahesh Bandewar IPvlan supported bridge-only functionality prior to commits a190d04db937 ('ipvlan: introduce 'private' attribute for all existing modes.') and fe89aa6b250c ('ipvlan: implement VEPA mode'). These two commits allow to configure the VEPA and private modes now. This patch adds those options in ip command. e.g. bash:~# ip link add link eth0 name ipvl0 type ipvlan mode l2 private -or- bash:~# ip link add link eth0 type ipvl0 type ipvlan mode l2 vepa Also the output will reflect the mode and the mode-flag accordingly. e.g. bash:~# ip -details link show ipvl0 4: ipvl0@eth0: mtu 1500 qdisc ... link/ether 00:1a:11:44:a5:3e brd ff:ff:ff:ff:ff:ff promiscuity 0 ipvlan mode l2 private addrgenmode eui64 numtxqueues 1 ... Signed-off-by: Mahesh Bandewar --- include/uapi/linux/if_link.h | 4 ++++ ip/iplink_ipvlan.c | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h index dafe0a6e0421..35bc598566e0 100644 --- a/include/uapi/linux/if_link.h +++ b/include/uapi/linux/if_link.h @@ -463,6 +463,7 @@ enum macsec_validation_type { enum { IFLA_IPVLAN_UNSPEC, IFLA_IPVLAN_MODE, + IFLA_IPVLAN_FLAGS, __IFLA_IPVLAN_MAX }; @@ -475,6 +476,9 @@ enum ipvlan_mode { IPVLAN_MODE_MAX }; +#define IPVLAN_F_PRIVATE 0x01 +#define IPVLAN_F_VEPA 0x02 + /* VXLAN section */ enum { IFLA_VXLAN_UNSPEC, diff --git a/ip/iplink_ipvlan.c b/ip/iplink_ipvlan.c index 9f48309ee030..8889808508fe 100644 --- a/ip/iplink_ipvlan.c +++ b/ip/iplink_ipvlan.c @@ -20,12 +20,21 @@ static void ipvlan_explain(FILE *f) { - fprintf(f, "Usage: ... ipvlan [ mode { l2 | l3 | l3s } ]\n"); + fprintf(f, + "Usage: ... ipvlan [ mode MODE ] [ FLAGS ]\n" + "\n" + "MODE: l3 | l3s | l2\n" + "FLAGS: bridge | private | vepa\n" + "(first values are the defaults if nothing is specified).\n" + ); } static int ipvlan_parse_opt(struct link_util *lu, int argc, char **argv, struct nlmsghdr *n) { + __u16 flags = 0; + bool mflag_given = false; + while (argc > 0) { if (matches(*argv, "mode") == 0) { __u16 mode = 0; @@ -43,6 +52,14 @@ static int ipvlan_parse_opt(struct link_util *lu, int argc, char **argv, return -1; } addattr16(n, 1024, IFLA_IPVLAN_MODE, mode); + } else if (matches(*argv, "private") == 0 && !mflag_given) { + flags |= IPVLAN_F_PRIVATE; + mflag_given = true; + } else if (matches(*argv, "vepa") == 0 && !mflag_given) { + flags |= IPVLAN_F_VEPA; + mflag_given = true; + } else if (matches(*argv, "bridge") == 0 && !mflag_given) { + mflag_given = true; } else if (matches(*argv, "help") == 0) { ipvlan_explain(stderr); return -1; @@ -55,6 +72,7 @@ static int ipvlan_parse_opt(struct link_util *lu, int argc, char **argv, argc--; argv++; } + addattr16(n, 1024, IFLA_IPVLAN_FLAGS, flags); return 0; } @@ -75,6 +93,21 @@ static void ipvlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) print_string(PRINT_ANY, "mode", " mode %s ", mode_str); } } + if (tb[IFLA_IPVLAN_FLAGS]) { + if (RTA_PAYLOAD(tb[IFLA_IPVLAN_FLAGS]) == sizeof(__u16)) { + __u16 flags = rta_getattr_u16(tb[IFLA_IPVLAN_FLAGS]); + + if (flags & IPVLAN_F_PRIVATE) + print_bool(PRINT_ANY, "private", "private ", + true); + else if (flags & IPVLAN_F_VEPA) + print_bool(PRINT_ANY, "vepa", "vepa ", + true); + else + print_bool(PRINT_ANY, "bridge", "bridge ", + true); + } + } } static void ipvlan_print_help(struct link_util *lu, int argc, char **argv,