From patchwork Thu Jul 9 12:04:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kristian Evensen X-Patchwork-Id: 1325920 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.openwrt.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=qVVfNEQQ; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=ELplk/rQ; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4B2Zfc0nSXz9sSn for ; Thu, 9 Jul 2020 22:07:03 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=61yC78Gl6+6sGOt29hZD4DTs9STzrhzhzFSZlvtuvIU=; b=qVVfNEQQ6gvQTJs/1TjngNwJp3 qdc6Q4J3tQ3nq0JE78vqzEFG8DjLNWeiIfDbwILV+mfaYc6+Yt25iHIG+MiWIV+olYnp3CdzD3QKh /WQpMsKTJrqU0k6xqZIDn5noJ9e0jps4vgOpKiCXPkSC5x9skwJY5TRyenynUVT++aruLTXVyGGfQ dyVEglZ4Q0ojxJn70kyt5CUMQoxWZn7TTcpJvLFcCdAkie3hii+5yGULo87mGHls5Yh6BKa+RsKl5 aU9TAZXS6cRX7yB/GmyWdlCV93Z0sW6fzJ4lMtBg/NtIXvBK0Pj16ohHLZESDq+ml/HdEx2B8PXdg FHsgd2JA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jtVIF-0002ei-KY; Thu, 09 Jul 2020 12:04:47 +0000 Received: from mail-ed1-x541.google.com ([2a00:1450:4864:20::541]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jtVIC-0002dr-Ec for openwrt-devel@lists.openwrt.org; Thu, 09 Jul 2020 12:04:45 +0000 Received: by mail-ed1-x541.google.com with SMTP id b15so1577716edy.7 for ; Thu, 09 Jul 2020 05:04:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=xij/GkJT//naJaZNxG4vHISWOjFMaEmIswY4LpNPHs0=; b=ELplk/rQzo/gPml41xC1lpJN4wWq4lM1wR3qMqguQY30dyNYaV7L0RCpSLt61C8DvG TPhsSzqMDP3D2uEpHf1Vp2ytdLYw+mva/8yrILa0l6hUsQYbG0Amlymkx1O3mzgkN9hC R6f2oY+ASg99hgQzpxi9npEy1fQsu6pNHpR1lkPBPMjpINwT2sRbyuuV5HZMjuw8B6O4 +gf+g7YrkpGvdhFHTOtju5Rz8N+QyL+Sf+wT7IUZmZSWiybjfeq60X4v+xl5wJV4OWzn VJ75ix+wWGmCuHko6oMIuLGZw6e1nOCBbA9+bYjH0nxpIIVRHqCfWILk9EeySsSRxjpT JWtg== 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:mime-version :content-transfer-encoding; bh=xij/GkJT//naJaZNxG4vHISWOjFMaEmIswY4LpNPHs0=; b=HF5qnPfq69PJcIGLklpg7/ERMRsLu7WEPynKFJMtvbu+8BxBZsg5QrEzqwMgzZQeNb 7QJDYGACDyY6e79KCmHUBrnYbENy3Pyc9YXmRYtITYH/7eAn0OnD1BsdRKAy7bc6n0ep OA0ZbZ7yeaNT1v465e+IlFoLb1Dx/TIIe6JKoGp8x1XURxPE2qaMGqrZrrIz7HwN1MF7 RsqGfSwlGQS9nbiV4XF9KlP+Wqa16LJKT83P1A3yY7a1LOoeszKgGQlK3E2PNCGZFRtc ORdvCp+rtI/GT28nAowmrPAHYfyHOGLrSWAEi4do2tp9XvuWNRzmlGi5NDDdNMqI5M0g azMg== X-Gm-Message-State: AOAM530/2Xbw+eI60AjDjvv6wiwlqdneUoe9eDCYr8P7rvM/Mqj+ZS5t 0JRQRoOA3qZVTTICw/qpT1Y9crrx X-Google-Smtp-Source: ABdhPJyHTo3y9FaBknKBmsC9JebWW5aoXKgjdQwGNqRJzsKAmmjuZ75ku46xLTJ4gRlDo8mZO1ONVg== X-Received: by 2002:a05:6402:134e:: with SMTP id y14mr72341388edw.4.1594296281096; Thu, 09 Jul 2020 05:04:41 -0700 (PDT) Received: from kristrev-XPS-15-9570.lan ([193.213.155.210]) by smtp.gmail.com with ESMTPSA id v24sm1673700eja.29.2020.07.09.05.04.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jul 2020 05:04:40 -0700 (PDT) From: Kristian Evensen To: openwrt-devel@lists.openwrt.org Subject: [PATCH] netifd: Ensure custom MTU is respected for bridges Date: Thu, 9 Jul 2020 14:04:39 +0200 Message-Id: <20200709120439.10537-1-kristian.evensen@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200709_080444_508781_8FF93961 X-CRM114-Status: GOOD ( 17.75 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:541 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [kristian.evensen[at]gmail.com] -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kristian Evensen Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org When an interface is added or removed from a bridge, the kernel updates the MTU to ETH_DATA_LEN or the minimum MTU of the ports (see br_min_mtu() in net/bridge/br_if.c). netifd already works around this behavior by updating the MTU when an interface is added to a bridge. However, remove is not handled. This commit introduces a new callback in the device-struct named update_mtu. If the callback is set, it is called from cb_rtnl_event for devices with a custom MTU. The bridge code has been extended to make use of this callback. If the MTU received from the kernel differs from the custom MTU, the MTU of the bridge device is update. The callback covers both the case when a device is added and removed (NEWLINK events are received in both cases), so the old work-around is removed. Signed-off-by: Kristian Evensen --- bridge.c | 22 +++++++++++++--------- device.h | 2 ++ system-linux.c | 3 +++ 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/bridge.c b/bridge.c index c1f4ffa..8421366 100644 --- a/bridge.c +++ b/bridge.c @@ -304,15 +304,9 @@ bridge_member_cb(struct device_user *dev, enum device_event ev) if (bst->n_present == 1) device_set_present(&bst->dev, true); - if (bst->dev.active && !bridge_enable_member(bm)) { - /* - * Adding a bridge member can overwrite the bridge mtu - * in the kernel, apply the bridge settings in case the - * bridge mtu is set - */ - system_if_apply_settings(&bst->dev, &bst->dev.settings, - DEV_OPT_MTU | DEV_OPT_MTU6); - } + + if (bst->dev.active) + bridge_enable_member(bm); break; case DEV_EVENT_REMOVE: @@ -710,6 +704,14 @@ bridge_retry_members(struct uloop_timeout *timeout) } } +static void +bridge_update_mtu(struct device *dev, uint32_t mtu) +{ + if (dev->settings.mtu != mtu || dev->settings.mtu6 != mtu) + system_if_apply_settings(dev, &dev->settings, DEV_OPT_MTU | + DEV_OPT_MTU6); +} + static struct device * bridge_create(const char *name, struct device_type *devtype, struct blob_attr *attr) @@ -735,6 +737,8 @@ bridge_create(const char *name, struct device_type *devtype, bst->set_state = dev->set_state; dev->set_state = bridge_set_state; + dev->update_mtu = bridge_update_mtu; + dev->hotplug_ops = &bridge_ops; vlist_init(&bst->members, avl_strcmp, bridge_member_update); diff --git a/device.h b/device.h index 5f3fae2..382af81 100644 --- a/device.h +++ b/device.h @@ -25,6 +25,7 @@ struct device_hotplug_ops; struct interface; typedef int (*device_state_cb)(struct device *, bool up); +typedef void (*device_mtu_cb)(struct device *, uint32_t mtu); enum { DEV_ATTR_TYPE, @@ -213,6 +214,7 @@ struct device { /* set interface up or down */ device_state_cb set_state; + device_mtu_cb update_mtu; const struct device_hotplug_ops *hotplug_ops; diff --git a/system-linux.c b/system-linux.c index 3b09bbb..54a35d0 100644 --- a/system-linux.c +++ b/system-linux.c @@ -597,6 +597,9 @@ static int cb_rtnl_event(struct nl_msg *msg, void *arg) device_set_link(dev, link_state ? true : false); + if (nla[IFLA_MTU] && (dev->settings.flags & DEV_OPT_MTU) && + dev->update_mtu) + dev->update_mtu(dev, nla_get_u32(nla[IFLA_MTU])); out: return 0; }