Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp2744723pxy; Sun, 25 Apr 2021 02:52:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzpcoTTdKwaHbbzhQwoD8plLVh1s4WvatR+3bnO2VyWvACwxWP04Pw9bzZwDoDo8e+fxUIK X-Received: by 2002:aa7:9f8f:0:b029:274:21e:fe0c with SMTP id z15-20020aa79f8f0000b0290274021efe0cmr3694460pfr.8.1619344339391; Sun, 25 Apr 2021 02:52:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619344339; cv=none; d=google.com; s=arc-20160816; b=SAPdIKTXmA0nSMgLmkXMkQGapWgLStCZx4wsfY08mSrhOJ6wF7Yrs6akfWDRWaURVr dVmYhQHNfrRwo48THodc6FHz5Gb+aIWch8FFs46m7VEgzfXtWuU7AnmUhgvwPReFwtXd Pwh3KE9KonPtDNn9MKBONanXT29nLEapk3jfhM82edLYoqSD9XFE5PzV7/1p4rsuc7kN Uto7FDaChwzrn+Afd9PRWxXL+B7WmAplzS9AaTK2mMZehp4fqMOZ8iYJiYYOd3mcSn4n HkL5OF7uZnHl5Amj00/moi3iPJsRO52rodU7I3olmaKxlmcRzk/t7wuUsnNUde/BpNqG LB5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:content-transfer-encoding :content-language:mime-version:user-agent:date:message-id:to:from :dkim-signature; bh=nC1EmQC2aDc1D3V92LRuQ9iWwJu2uRPFq4IPsbVeQ9w=; b=E1uEQXSAz64mZfJLYrzDnpNu5yUQzBGZJQQhvBiyjv3bKqxWQjngpBkOHjajrdggcg +lkdhApAyecW6ZUuACbZAgpZtPJLkurCdX9fGNGr10F+b0vO0KFtFfGctEYaektErscy 3TR9CoV6VEIvby0ow6DD/5c3FSI7CfGY5j28O71f2wwAO3/4orux4ewgDGquL5LO1Euo KVJDbZiUEO91+RYAV39ENwUED9fPTv0cZIKDz2jTnWNA2ugEjiLgLUSUzD0sZD8YoaIS Hpq/fUo5i4XnL3D39GlVJ1mxF5nk3w7ZNvXezTGqM7qFdwA1cUuzuF4Fcc0mzTeem36e 0VMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@jbeekman.nl header.s=main header.b=C3l80p5U; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i8si13558480pgp.235.2021.04.25.02.52.06; Sun, 25 Apr 2021 02:52:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@jbeekman.nl header.s=main header.b=C3l80p5U; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229688AbhDYJwR (ORCPT + 99 others); Sun, 25 Apr 2021 05:52:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229551AbhDYJwQ (ORCPT ); Sun, 25 Apr 2021 05:52:16 -0400 X-Greylist: delayed 1769 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Sun, 25 Apr 2021 02:51:37 PDT Received: from daxilon.jbeekman.nl (jbeekman.nl [IPv6:2a01:7c8:aab4:5fb::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36525C061574 for ; Sun, 25 Apr 2021 02:51:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=jbeekman.nl ; s=main; h=Subject:Content-Transfer-Encoding:Content-Type:MIME-Version:Date: Message-ID:To:From:Sender:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=nC1EmQC2aDc1D3V92LRuQ9iWwJu2uRPFq4IPsbVeQ9w=; b=C3l80p5UG0fJAIhj3wPPvbAjt3 EAFDh9RULZ56TdGy1+cEu0kTZj3heEeEL9IxjV7YZ3/6DnveYkV6z2BG7KSyt8o0D7f+ocYBui15Z G0A9iBhJdhtpEdQAZo7BEwyLquY5QKecBAxZ8sQfHggYuxQAeqmXPL+TtFFeDNtWq22oVxATND0BJ VWSY/kNtcXvdtbQFExOIz2/tJxwINVTV+hipzG0qkUJn0IadWZdK77YqP4UeFhXU7Qc9rZnabiBGm 0zs4+T1A+L1NUDe+uYJ5TNnEEoavAzq16egmJoUEx9GFSboo7H9/m0nL9A2W9oeBPZ+akNAeikHmT bh9ewALQ==; Received: from ip-213-127-124-30.ip.prioritytelecom.net ([213.127.124.30] helo=[192.168.3.100]) by daxilon.jbeekman.nl with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1laaxo-0001uQ-3S; Sun, 25 Apr 2021 11:22:04 +0200 From: Jethro Beekman To: "David S. Miller" , Jakub Kicinski , netdev@vger.kernel.org, open list Message-ID: <2afc4d46-aa9b-a7db-d872-d02163b1f29c@jbeekman.nl> Date: Sun, 25 Apr 2021 11:22:03 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.9.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-SA-Exim-Connect-IP: 213.127.124.30 X-SA-Exim-Mail-From: kernel@jbeekman.nl X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on daxilon.jbeekman.nl X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Report: Content analysis details: (-2.9 points, 5.0 required) pts rule name description --- ---------------------- -------------------------------------------------- -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP 0.0 URIBL_BLOCKED ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [URIs: jbeekman.nl] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Subject: [PATCH v2 net-next] macvlan: Add nodst option to macvlan type source Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The default behavior for source MACVLAN is to duplicate packets to appropriate type source devices, and then do the normal destination MACVLAN flow. This patch adds an option to skip destination MACVLAN processing if any matching source MACVLAN device has the option set. This allows setting up a "catch all" device for source MACVLAN: create one or more devices with type source nodst, and one device with e.g. type vepa, and incoming traffic will be received on exactly one device. v2: netdev wants non-standard line length Signed-off-by: Jethro Beekman --- drivers/net/macvlan.c | 19 ++++++++++++++----- include/uapi/linux/if_link.h | 1 + 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c index 9a9a5cf36a4b..7427b989607e 100644 --- a/drivers/net/macvlan.c +++ b/drivers/net/macvlan.c @@ -423,18 +423,24 @@ static void macvlan_forward_source_one(struct sk_buff *skb, macvlan_count_rx(vlan, len, ret == NET_RX_SUCCESS, false); } -static void macvlan_forward_source(struct sk_buff *skb, +static bool macvlan_forward_source(struct sk_buff *skb, struct macvlan_port *port, const unsigned char *addr) { struct macvlan_source_entry *entry; u32 idx = macvlan_eth_hash(addr); struct hlist_head *h = &port->vlan_source_hash[idx]; + bool consume = false; hlist_for_each_entry_rcu(entry, h, hlist) { - if (ether_addr_equal_64bits(entry->addr, addr)) + if (ether_addr_equal_64bits(entry->addr, addr)) { + if (entry->vlan->flags & MACVLAN_FLAG_NODST) + consume = true; macvlan_forward_source_one(skb, entry->vlan); + } } + + return consume; } /* called under rcu_read_lock() from netif_receive_skb */ @@ -463,7 +469,8 @@ static rx_handler_result_t macvlan_handle_frame(struct sk_buff **pskb) return RX_HANDLER_CONSUMED; *pskb = skb; eth = eth_hdr(skb); - macvlan_forward_source(skb, port, eth->h_source); + if (macvlan_forward_source(skb, port, eth->h_source)) + return RX_HANDLER_CONSUMED; src = macvlan_hash_lookup(port, eth->h_source); if (src && src->mode != MACVLAN_MODE_VEPA && src->mode != MACVLAN_MODE_BRIDGE) { @@ -482,7 +489,8 @@ static rx_handler_result_t macvlan_handle_frame(struct sk_buff **pskb) return RX_HANDLER_PASS; } - macvlan_forward_source(skb, port, eth->h_source); + if (macvlan_forward_source(skb, port, eth->h_source)) + return RX_HANDLER_CONSUMED; if (macvlan_passthru(port)) vlan = list_first_or_null_rcu(&port->vlans, struct macvlan_dev, list); @@ -1286,7 +1294,8 @@ static int macvlan_validate(struct nlattr *tb[], struct nlattr *data[], return 0; if (data[IFLA_MACVLAN_FLAGS] && - nla_get_u16(data[IFLA_MACVLAN_FLAGS]) & ~MACVLAN_FLAG_NOPROMISC) + nla_get_u16(data[IFLA_MACVLAN_FLAGS]) & ~(MACVLAN_FLAG_NOPROMISC | + MACVLAN_FLAG_NODST)) return -EINVAL; if (data[IFLA_MACVLAN_MODE]) { diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h index 91c8dda6d95d..cd5b382a4138 100644 --- a/include/uapi/linux/if_link.h +++ b/include/uapi/linux/if_link.h @@ -614,6 +614,7 @@ enum macvlan_macaddr_mode { }; #define MACVLAN_FLAG_NOPROMISC 1 +#define MACVLAN_FLAG_NODST 2 /* skip dst macvlan if matching src macvlan */ /* VRF section */ enum { -- 2.31.1