From patchwork Tue May 11 17:14:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= X-Patchwork-Id: 1477253 X-Patchwork-Delegate: zajec5@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.openwrt.org (client-ip=2001:8b0:10b:1:d65d:64ff:fe57:4e05; helo=desiato.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) 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=desiato.20200630 header.b=X0RnlSJa; 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=Rm/OQgd+; dkim-atps=neutral Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) (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 4Ffl2V2V20z9sWk for ; Wed, 12 May 2021 03:16:34 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc: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=jpKiQ7PX6P16MZoiPWHez02rj9GeKy02aWmJ7XOYUcg=; b=X0RnlSJaCHA97PmM/XlR4H20cH oYC/D4vMBn4Tg6Coxgws8bOJ19sBw0pSuJRirrrqMVegHWjQ0Xkse4e4urx4b3HIBC+SkbJDRPzMI HJWKT/X8hFbKU5JD1iY7rqcKp+oJwF3jekTEissL6+6j9F5DhyJOTddcyydnrciF7yx/IJ6bdeRjR Y/+M87Ek+nsxPISL6boiC+vpwJBWQOvy00V5UDF1q4GFwDarnazZgJjDPSb8O8QSpCOxqn8t78Plh qNI7tI+3efgsxYeF1GBcBZWAXE7Ei0Hc/jGrbwoS7k3ylwsJB3biia3win0L7hqCix+L1aJ3NjH1q csWRYNdg==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lgVxh-000t6h-O9; Tue, 11 May 2021 17:14:25 +0000 Received: from mail-lf1-x12e.google.com ([2a00:1450:4864:20::12e]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lgVxd-000t5M-9c for openwrt-devel@lists.openwrt.org; Tue, 11 May 2021 17:14:23 +0000 Received: by mail-lf1-x12e.google.com with SMTP id t11so29661920lfl.11 for ; Tue, 11 May 2021 10:14:19 -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=02TYeesBqW0BS+nTXVakZ1H8L6gQWXt+iQ4H1psQ2jY=; b=Rm/OQgd+9XacpeazsOL9iTFG367x4oDtdgXCzMYlpJkpaxq0J04sYj8IDOcGC2Wnnu Z1Snn7c+G1uKyOqP+4/oLBciQqqaJR1rpttzXxwxLY02tR2qGmomv4y+d0K4zo2bsy8s B/AWDeQTJn0pWs0h1AFXw6E39jccm9H6Ot3botLbDh6uHDUMtCWFJ3qYEZbf1YJy7BPi 5MumurN0SN7M01lLhkDQs5A3Mq017N9y8wKM1DyddHIO8Yqd4zSPlxMJYwF6hTP33Ysn BkvamBv2X/kW5dPezOMQl0jIobi2ZaOupo7GPwF49ANMDvqcn1I0mcqWjpzy8thnYlJe ZbrQ== 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=02TYeesBqW0BS+nTXVakZ1H8L6gQWXt+iQ4H1psQ2jY=; b=IAugjyo/GaAtdx4RhyQtbZiYVESVKAHduWZh8ixL6uR5VTpuxPkklQTMqIS4vS+81K 7d0bUlVa9xoz6z1anqHcEn7eKqExTcG5j+wNyYQ6OeJLIU2baR7WgPbtutXRtMJ3l66S Q2wcr9p38FF6rAp9mmpgSv6JI3aCFpPD28TqnqsoVyOIa+MVmgL1Ftphm+VW6kBfYoa9 zQeRLcOkgc4muDIWWBgt1VFgyCXO6qSYBQZkveqzDioxA7j889DHiQDTc/JIT0vAoGlM a/GtL2KLUJFMXb3T91cAbKG0FOdk7ssgsM3xAZdoLN76m+zqP7nsm0EOsusL0LYJ9KfC qXqA== X-Gm-Message-State: AOAM530abJQaeZSrnkkhTqIW1nQ3HpY4+OtyKt8S1Ef+gSPMJ1CCMqLp 1K//1Uk7ukwrMuvTS5R0XAQ= X-Google-Smtp-Source: ABdhPJx8bsBo5/lQfRYPMeFrnH/SLaQDkcNeHI8xM7JfVDTJMEiaDiMw+TOPXm9DRy+aNoWMI60AxA== X-Received: by 2002:ac2:52a9:: with SMTP id r9mr22223756lfm.308.1620753258403; Tue, 11 May 2021 10:14:18 -0700 (PDT) Received: from localhost.lan (ip-194-187-74-233.konfederacka.maverick.com.pl. [194.187.74.233]) by smtp.gmail.com with ESMTPSA id h13sm3707503lji.102.2021.05.11.10.14.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 May 2021 10:14:17 -0700 (PDT) From: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= To: Jo-Philipp Wich , Hans Dedecker , John Crispin , Felix Fietkau , openwrt-devel@lists.openwrt.org Cc: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= Subject: [PATCH netifd] config: support bridge designed UCI section Date: Tue, 11 May 2021 19:14:07 +0200 Message-Id: <20210511171407.17078-1-zajec5@gmail.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210511_181421_437132_DBFAE19A X-CRM114-Status: GOOD ( 15.70 ) X-Spam-Score: 0.1 (/) X-Spam-Report: =?unknown-8bit?q?Spam_detection_software=2C_running_on_the_sy?= =?unknown-8bit?q?stem_=22desiato=2Einfradead=2Eorg=22=2C?= =?unknown-8bit?q?_has_NOT_identified_this_incoming_email_as_spam=2E__The_ori?= =?unknown-8bit?q?ginal?= =?unknown-8bit?q?_message_has_been_attached_to_this_so_you_can_view_it_or_la?= =?unknown-8bit?q?bel?= =?unknown-8bit?q?_similar_future_email=2E__If_you_have_any_questions=2C_see?= =?unknown-8bit?q?_the_administrator_of_that_system_for_details=2E?= =?unknown-8bit?q?_?= =?unknown-8bit?q?_Content_preview=3A__From=3A_Rafa=C5=82_Mi=C5=82ecki_Networ?= =?unknown-8bit?q?k_layer_2_devices_should_have?= =?unknown-8bit?q?_their_own_UCI_section_types=2E_They_differ_so_much_that_ea?= =?unknown-8bit?q?ch_device_type_requires?= =?unknown-8bit?q?_a_custom_handling_anyway=2E_Currently_there_is_=22type=22_?= =?unknown-8bit?q?option_used_to_distinguish?= =?unknown-8bit?b?IHRoZW0gWy4uLl0g?= =?unknown-8bit?q?_?= =?unknown-8bit?q?_Content_analysis_details=3A___=280=2E1_points=2C_5=2E0_req?= =?unknown-8bit?q?uired=29?= =?unknown-8bit?q?_?= =?unknown-8bit?q?_pts_rule_name______________description?= =?unknown-8bit?q?_----_----------------------_------------------------------?= =?unknown-8bit?q?--------------------?= =?unknown-8bit?q?_-0=2E0_SPF=5FPASS_______________SPF=3A_sender_matches_SPF_?= =?unknown-8bit?q?record?= =?unknown-8bit?q?_0=2E0_SPF=5FHELO=5FNONE__________SPF=3A_HELO_does_not_publ?= =?unknown-8bit?q?ish_an_SPF_Record?= =?unknown-8bit?q?_0=2E2_FREEMAIL=5FENVFROM=5FEND=5FDIGIT_Envelope-from_freem?= =?unknown-8bit?q?ail_username_ends?= =?unknown-8bit?q?_in_digit?= =?unknown-8bit?q?_=5Bzajec5=5Bat=5Dgmail=2Ecom=5D?= =?unknown-8bit?q?_0=2E0_FREEMAIL=5FFROM__________Sender_email_is_commonly_ab?= =?unknown-8bit?q?used_enduser_mail?= =?unknown-8bit?q?_provider?= =?unknown-8bit?q?_=5Bzajec5=5Bat=5Dgmail=2Ecom=5D?= =?unknown-8bit?q?_-0=2E0_RCVD=5FIN=5FDNSWL=5FNONE_____RBL=3A_Sender_listed_a?= =?unknown-8bit?q?t_https=3A//www=2Ednswl=2Eorg/=2C?= =?unknown-8bit?q?_no_trust?= =?unknown-8bit?b?IFsyYTAwOjE0NTA6NDg2NDoyMDowOjA6MDoxMmUgbGlzdGVkIGluXQ==?= =?unknown-8bit?b?IFtsaXN0LmRuc3dsLm9yZ10=?= =?unknown-8bit?q?_-0=2E1_DKIM=5FVALID_____________Message_has_at_least_one_v?= =?unknown-8bit?q?alid_DKIM_or_DK_signature?= =?unknown-8bit?q?_-0=2E1_DKIM=5FVALID=5FAU__________Message_has_a_valid_DKIM?= =?unknown-8bit?q?_or_DK_signature_from?= =?unknown-8bit?q?_author=27s_domain?= =?unknown-8bit?q?_-0=2E1_DKIM=5FVALID=5FEF__________Message_has_a_valid_DKIM?= =?unknown-8bit?q?_or_DK_signature_from?= =?unknown-8bit?q?_envelope-from_domain?= =?unknown-8bit?q?_0=2E1_DKIM=5FSIGNED____________Message_has_a_DKIM_or_DK_si?= =?unknown-8bit?q?gnature=2C_not_necessarily?= =?unknown-8bit?q?_valid?= X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org From: Rafał Miłecki Network layer 2 devices should have their own UCI section types. They differ so much that each device type requires a custom handling anyway. Currently there is "type" option used to distinguish them while UCI supports different section types right for that purpose. This change will result in cleaner UCI and UI code. Example UCI section: config bridge option name 'foo' list ports 'lan1' list ports 'lan2' While introducing this new bridge section a new option was added for storing bridge port names: "ports". It's clearer than previously used "ifname". A simple validation code is present to make sure "ports" is used and contains a list of ports. Signed-off-by: Rafał Miłecki Acked-by: Hans Dedecker --- bridge.c | 14 +++++++++----- config.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 5 deletions(-) diff --git a/bridge.c b/bridge.c index 099dfe4..ce49a74 100644 --- a/bridge.c +++ b/bridge.c @@ -23,7 +23,8 @@ #include "system.h" enum { - BRIDGE_ATTR_IFNAME, + BRIDGE_ATTR_PORTS, + BRIDGE_ATTR_IFNAME, /* Deprecated */ BRIDGE_ATTR_STP, BRIDGE_ATTR_FORWARD_DELAY, BRIDGE_ATTR_PRIORITY, @@ -44,6 +45,7 @@ enum { }; static const struct blobmsg_policy bridge_attrs[__BRIDGE_ATTR_MAX] = { + [BRIDGE_ATTR_PORTS] = { "ports", BLOBMSG_TYPE_ARRAY }, [BRIDGE_ATTR_IFNAME] = { "ifname", BLOBMSG_TYPE_ARRAY }, [BRIDGE_ATTR_STP] = { "stp", BLOBMSG_TYPE_BOOL }, [BRIDGE_ATTR_FORWARD_DELAY] = { "forward_delay", BLOBMSG_TYPE_INT32 }, @@ -104,7 +106,7 @@ struct bridge_state { struct blob_attr *config_data; struct bridge_config config; - struct blob_attr *ifnames; + struct blob_attr *ports; bool active; bool force_active; bool has_vlans; @@ -853,8 +855,8 @@ bridge_config_init(struct device *dev) bst->n_failed = 0; vlist_update(&bst->members); - if (bst->ifnames) { - blobmsg_for_each_attr(cur, bst->ifnames, rem) { + if (bst->ports) { + blobmsg_for_each_attr(cur, bst->ports, rem) { bridge_add_member(bst, blobmsg_data(cur)); } } @@ -970,7 +972,9 @@ bridge_reload(struct device *dev, struct blob_attr *attr) if (tb_dev[DEV_ATTR_MACADDR]) bst->primary_port = NULL; - bst->ifnames = tb_br[BRIDGE_ATTR_IFNAME]; + bst->ports = tb_br[BRIDGE_ATTR_PORTS]; + if (!bst->ports) + bst->ports = tb_br[BRIDGE_ATTR_IFNAME]; device_init_settings(dev, tb_dev); bridge_apply_settings(bst, tb_br); diff --git a/config.c b/config.c index fa7cbe4..4cc5a61 100644 --- a/config.c +++ b/config.c @@ -223,6 +223,57 @@ config_parse_rule(struct uci_section *s, bool v6) iprule_add(blob_data(b.head), v6); } +/** + * config_init_bridges - create bridges for new syntax UCI sections + * + * The new syntax uses dedicated UCI "bridge" sections for describing bridges. + * They use "ports" list instead of "ifname" for specifying bridge ports. + */ +static void config_init_bridges() +{ + struct uci_element *e; + + uci_foreach_element(&uci_network->sections, e) { + struct uci_section *s = uci_to_section(e); + struct device_type *devtype; + struct uci_option *o; + struct device *dev; + const char *name; + + if (strcmp(s->type, "bridge")) + continue; + + name = uci_lookup_option_string(uci_ctx, s, "name"); + if (!name) + continue; + + devtype = device_type_get("bridge"); + if (!devtype) + continue; + + config_fixup_bridge_vlan_filtering(s, name); + o = uci_lookup_option(uci_ctx, s, "ifname"); + if (o) { + netifd_log_message(L_WARNING, "Unsupported \"ifname\" bridge option\n"); + continue; + } + o = uci_lookup_option(uci_ctx, s, "ports"); + if (o && o->type != UCI_TYPE_LIST) { + netifd_log_message(L_WARNING, "Invalid \"ports\" option format\n"); + continue; + } + + blob_buf_init(&b, 0); + uci_to_blob(&b, s, devtype->config_params); + + dev = device_create(name, devtype, b.head); + if (!dev) + continue; + + dev->default_config = false; + } +} + static void config_init_devices(bool bridge) { @@ -737,6 +788,7 @@ config_init_all(void) device_lock(); device_reset_config(); + config_init_bridges(); config_init_devices(true); config_init_vlans(); config_init_devices(false);