From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail.avm.de (mail.avm.de [212.42.244.120]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 034C6318EC1; Fri, 12 Jun 2026 09:24:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.42.244.120 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781256286; cv=none; b=QdGzFZvOwEoYAGIKXb0Hb0nf2hJ4V0LLQVkki/EQQF7dndbfHKRDX2DyTi3fYe7jCxoeNOK3mQUEuAhbluDXKqpSeCxYYzjSrifBCErPBuiQNsWsgLuAikctwozUl6Xy7DnZniZTTdi4jxG+h+b9gvFbw1MOwxwq/fuTPaN25Go= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781256286; c=relaxed/simple; bh=oLJ9FE1uRY5QHAICJ1hqfCGxFI2speufjAwyc4aRbdE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mdCyJ68cQ/7IOjuKOJdC5ZEUZbBlyuB16+rrJ/yON+g/pveeR8gFFZQakcSQcrVNmXbjXHcFcMtno1dW7IsM07LYfE2YqVFbnu91qMqpuJpQA+XVX+hCeoDg1zUoNBHCxNd5ux7wlA7yCPpscufLEnTIUf4A4mYVsZtWFrr2PMs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=fritz.com; spf=pass smtp.mailfrom=fritz.com; arc=none smtp.client-ip=212.42.244.120 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=fritz.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fritz.com Received: from [212.42.244.71] (helo=mail.avm.de) by mail.avm.de with ESMTP (eXpurgate 4.56.1) (envelope-from ) id 6a2bd052-044e-7f0000032729-7f000001bafa-1 for ; Fri, 12 Jun 2026 11:24:34 +0200 Received: from mail-auth.avm.de (dovecot-mx-01.avm.de [212.42.244.71]) by mail.avm.de (Postfix) with ESMTPS; Fri, 12 Jun 2026 11:24:34 +0200 (CEST) From: Thomas Martitz To: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org (open list:NETWORKING DRIVERS), linux-kernel@vger.kernel.org (open list) Cc: Thomas Martitz , netdev@vger.kernel.org (open list:NETWORKING DRIVERS), linux-kernel@vger.kernel.org (open list) Subject: [PATCH RFC 1/1] macvlan: allow source mode devices along with passthru Date: Fri, 12 Jun 2026 11:23:44 +0200 Message-ID: <20260612092345.2352255-2-t.martitz@fritz.com> In-Reply-To: <20260612092345.2352255-1-t.martitz@fritz.com> References: <20260612092345.2352255-1-t.martitz@fritz.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-purgate-ID: 149429::1781256274-917F8962-B9A452D0/0/0 X-purgate-type: clean X-purgate-size: 3282 X-purgate: This mail is considered clean (visit https://www.eleven.de for further information) X-purgate: clean This allows for configurations where there are a few known senders in the system (e.g. multiple SoCs on the same board) along with unlimited external senders. The source mode devices represent the known senders while all external senders terminate on passthru device. Although you can still receive packets on the lower device without the need for the passthru vlan device, there are use cases where you need additional packet processing in the pipeline that hooks via rx_handler. With this the rx_handler can be attached to the passthru device while macvlan itself remains attached to the lower device. We use this to use the same physical link for inter-SoC networking and external networking. Some of our chips have no other viable link for inter-SoC traffic. Signed-off-by: Thomas Martitz --- drivers/net/macvlan.c | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c index c40fa331836bb..d28f9d905a84d 100644 --- a/drivers/net/macvlan.c +++ b/drivers/net/macvlan.c @@ -1502,15 +1502,6 @@ int macvlan_common_newlink(struct net_device *dev, } port = macvlan_port_get_rtnl(lowerdev); - /* Only 1 macvlan device can be created in passthru mode */ - if (macvlan_passthru(port)) { - /* The macvlan port must be not created this time, - * still goto destroy_macvlan_port for readability. - */ - err = -EINVAL; - goto destroy_macvlan_port; - } - vlan->lowerdev = lowerdev; vlan->dev = dev; vlan->port = port; @@ -1523,10 +1514,30 @@ int macvlan_common_newlink(struct net_device *dev, if (data && data[IFLA_MACVLAN_FLAGS]) vlan->flags = nla_get_u16(data[IFLA_MACVLAN_FLAGS]); + /* Only 1 macvlan device can be created in passthru mode. There may be + * additional source mode devices but nothing else at the moment. + * + * First check if adding a source mode device to an existing passthru vlan. + */ + if (macvlan_passthru(port) && vlan->mode != MACVLAN_MODE_SOURCE) { + /* The macvlan port must be not created this time, + * still goto destroy_macvlan_port for readability. + */ + err = -EINVAL; + goto destroy_macvlan_port; + } + + /* Now check if adding a passthru device to an existing set of source mode + * devices. + */ if (vlan->mode == MACVLAN_MODE_PASSTHRU) { - if (port->count) { - err = -EINVAL; - goto destroy_macvlan_port; + struct macvlan_dev *p; + + list_for_each_entry(p, &port->vlans, list) { + if (p->mode != MACVLAN_MODE_SOURCE) { + err = -EINVAL; + goto destroy_macvlan_port; + } } macvlan_set_passthru(port); eth_hw_addr_inherit(dev, lowerdev); @@ -1560,7 +1571,11 @@ int macvlan_common_newlink(struct net_device *dev, if (err) goto unregister_netdev; - list_add_tail_rcu(&vlan->list, &port->vlans); + /* macvlan_handle_frame expects the (one and only) passthru device first. */ + if (vlan->mode == MACVLAN_MODE_PASSTHRU) + list_add_rcu(&vlan->list, &port->vlans); + else + list_add_tail_rcu(&vlan->list, &port->vlans); update_port_bc_queue_len(vlan->port); netif_stacked_transfer_operstate(lowerdev, dev); linkwatch_fire_event(dev); -- 2.54.0