From patchwork Mon May 24 13:35:48 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: 1483039 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=2607:7c80:54:e::133; helo=bombadil.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=bombadil.20210309 header.b=NGzKjghh; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=casper.20170209 header.b=VyxMmZfM; 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=OlK7HHAA; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (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 4Fpwxv6xB4z9s1l for ; Tue, 25 May 2021 11:10:59 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; 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=NvZUPSX9/tCD0WW5AXBsT3RF3l2P59xvcg2fM9z3Esg=; b=NGzKjghhALfvDh qZs0DyAhr3VIT2MRJ3dxLHAWntbLk/Ppf15+6Da1swO0G1obdjdCUc68pwAC2k3YKHAO9/esAUO10 ZT3U0THJxByafE+jVg+u4vOEUVgi71gN2lVl8jLgh6/ECY3jcAaW4kCTf6ugFxP5k2eysRveE1n9g e7OgfNdTbZI0+gOdAU9sCmRjVOsMc5xcDnwbg7uhVkccPKPESLVoaYT/UFMNS8VQnzfOqQKIs4ax+ Ynb6cIXldbbQTPcOTaExsk004M1PO+0IjcmIP9ZwZ/ABCbKeCICJyyBeEfXUF7wb7cCDVrTeZzA/W PFMe9nLwt3UJfwQVO5NA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1llLXD-002i3C-DR; Tue, 25 May 2021 01:07:04 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1llGrs-001mvT-3a for openwrt-devel@bombadil.infradead.org; Mon, 24 May 2021 20:08:04 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:Content-Type: MIME-Version:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:In-Reply-To:References; bh=c16XjbhDryMejXVmRlhrlDJt/t3h+hO2DtymkEH1GmU=; b=VyxMmZfMGglTorDkWNQ3VbPVld 8i9GPu/12kCxOLhMuYrDyPo00OHYY8GHw1n8T/CsXrwqB8XUHndMf+ItnUnYGbwNxP0kf//1oAg2J 72eTUH+6J+giFDvJ1cHS8IJDj13IQom14DwINW3zVumdc18AemWjvqIau22edkOPJXU4bLZYGZ6z9 WUc91VEiJoq9sUcwM3b6GrlNT1S4jgzR3u4oRlGjo2Esww0TX/t6qaHBPg3FXwfjDiuroD4GH/+gn i1VtFtu7DHCWb+LLKatyIsBMfIfhvOH6GUrJtO0i+1hGpicW08dbBgx19XV8M0S9/GV0qeheXVvet 5jXbM6Hw==; Received: from mail-lf1-x12e.google.com ([2a00:1450:4864:20::12e]) by casper.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1llAkR-002Pfj-W0 for openwrt-devel@lists.openwrt.org; Mon, 24 May 2021 13:36:17 +0000 Received: by mail-lf1-x12e.google.com with SMTP id a2so40673844lfc.9 for ; Mon, 24 May 2021 06:35:59 -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=c16XjbhDryMejXVmRlhrlDJt/t3h+hO2DtymkEH1GmU=; b=OlK7HHAAlt4saEEQMq23MtsjrliXHvwY35fnUvBHNJtpcT9hW2TiWmFjK74wdJ1F0y SPH/hJdGIcEz10oT5NZJjbRqCoIMn+LbuNhO9i/ZvCAjF1qBPO06uvflzVfDCB9srZkw xHZkFKwDtxe/TK7wlOggoRt+U/n/cElAi37rrQastdMSlThqvycxFHXYuJ7PqFRyStIe 4Jn9bWAJ9LYCs0sbJgEkMCjZutpLYvSq1ECl+nyJHWXrGIFtKyUMWiwGSVmUjzWHcl9X WHxaInBWtLyS7zZ+obO3rnay2A59JZHCVkfPXC11wFbNk6ddKdZEMktzKh3CjJhQnEPr YtiQ== 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=c16XjbhDryMejXVmRlhrlDJt/t3h+hO2DtymkEH1GmU=; b=SgxfDlywlthNKwtX5rk+E41mNKlbO3zzr6+1wy1Q2Q8Led3h4whbyQ6vkwOQMVMrBi QWiPTZ7LDLYgWYMlAps7SjpXKnHFsDxNloft4fajg6E6GMzBNuVQyeSTaPhLGj82GcSm 0S6O8pH3MEgDS9nqZGAHLQzL/ggWrPJ7zYr+/V4iwra8toimKdcdWiiWPAkqxfLckCws 0gllkwxabV3bdNkcPXArBYYJOGuBLBWUBJQPb1GJ1vp6jG/BR+yewGj0h6IMpNUP0+2L e/UiIlYxxTvMav6B2n3di4UQzLgVLQ5SdlGx1oXxQxhWdEOwtqctyG66N1khks4rWZzl zpXg== X-Gm-Message-State: AOAM5317HgHy7sK1MelzUl15V5vKWW3F15Kj3zFCCvKpuQq1N1ckQzwR qlCRcXbQiDODZDUZqgnVt2M= X-Google-Smtp-Source: ABdhPJyO6gBi5icBlH0v8Q6Jo1Vw/lGUIE5QT8IcS/2hvjkc1gajlAHZvE84K/fhc3lEijqF03JSXw== X-Received: by 2002:a19:6d12:: with SMTP id i18mr10220381lfc.249.1621863356816; Mon, 24 May 2021 06:35:56 -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 j5sm1430401lfb.101.2021.05.24.06.35.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 May 2021 06:35:56 -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 V2 netifd] interface: rename "ifname" attribute to "device" Date: Mon, 24 May 2021 15:35:48 +0200 Message-Id: <20210524133548.28188-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-20210524_143602_713017_10EECA8B X-CRM114-Status: GOOD ( 16.59 ) X-Spam-Score: -1.8 (-) X-Spam-Report: SpamAssassin version 3.4.6 on casper.infradead.org summary: Content analysis details: (-1.8 points, 5.0 required) 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:12e listed in] [list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit [zajec5[at]gmail.com] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [zajec5[at]gmail.com] -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's 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 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 Interfaces need to be assigned to devices. For that purpose a "device" option should be more accurate than "ifname" one. For backward compatibility add a temporary config translation. Config example: config device option name 'br-lan' option type 'bridge' list ports 'lan1' list ports 'lan2' config interface 'lan' option device 'br-lan' option proto 'static' Signed-off-by: Rafał Miłecki --- V2: Add translation in the "add_dynamic" ubus method handler --- config.c | 21 +++++++++++++++++++++ interface.c | 22 +++++++++++----------- interface.h | 2 +- ubus.c | 14 ++++++++++++++ 4 files changed, 47 insertions(+), 12 deletions(-) diff --git a/config.c b/config.c index d83ea9c..f6a1071 100644 --- a/config.c +++ b/config.c @@ -155,6 +155,25 @@ config_parse_bridge_interface(struct uci_section *s, struct device_type *devtype return 0; } +/** + * config_fixup_interface_device - translate deprecated "ifname" option + * + * Initially "interface" sections were using "ifname" for specifying device. + * That has been replaced by the "device" option. For backward compatibility + * translate it. + */ +static void config_fixup_interface_device(struct uci_section *s) +{ + const char *ifname; + + if (uci_lookup_option(uci_ctx, s, "device")) + return; + + ifname = uci_lookup_option_string(uci_ctx, s, "ifname"); + if (ifname) + config_fixup_bridge_var(s, "device", ifname); +} + static void config_parse_interface(struct uci_section *s, bool alias) { @@ -168,6 +187,8 @@ config_parse_interface(struct uci_section *s, bool alias) if (disabled && !strcmp(disabled, "1")) return; + config_fixup_interface_device(s); + blob_buf_init(&b, 0); if (!alias) diff --git a/interface.c b/interface.c index a91246a..c298355 100644 --- a/interface.c +++ b/interface.c @@ -30,7 +30,7 @@ struct vlist_tree interfaces; static LIST_HEAD(iface_all_users); enum { - IFACE_ATTR_IFNAME, + IFACE_ATTR_DEVICE, IFACE_ATTR_PROTO, IFACE_ATTR_AUTO, IFACE_ATTR_JAIL, @@ -55,8 +55,8 @@ enum { }; static const struct blobmsg_policy iface_attrs[IFACE_ATTR_MAX] = { + [IFACE_ATTR_DEVICE] = { .name = "device", .type = BLOBMSG_TYPE_STRING }, [IFACE_ATTR_PROTO] = { .name = "proto", .type = BLOBMSG_TYPE_STRING }, - [IFACE_ATTR_IFNAME] = { .name = "ifname", .type = BLOBMSG_TYPE_STRING }, [IFACE_ATTR_AUTO] = { .name = "auto", .type = BLOBMSG_TYPE_BOOL }, [IFACE_ATTR_JAIL] = { .name = "jail", .type = BLOBMSG_TYPE_STRING }, [IFACE_ATTR_JAIL_IFNAME] = { .name = "jail_ifname", .type = BLOBMSG_TYPE_STRING }, @@ -641,9 +641,9 @@ interface_claim_device(struct interface *iface) parent = vlist_find(&interfaces, iface->parent_ifname, parent, node); iface->parent_iface.cb = interface_alias_cb; interface_add_user(&iface->parent_iface, parent); - } else if (iface->ifname && + } else if (iface->device && !(iface->proto_handler->flags & PROTO_FLAG_NODEV)) { - dev = device_get(iface->ifname, true); + dev = device_get(iface->device, true); interface_set_device_config(iface, dev); } else { dev = iface->ext_dev.dev; @@ -939,8 +939,8 @@ static bool __interface_add(struct interface *iface, struct blob_attr *config, b if (!iface->parent_ifname) return false; } else { - if ((cur = tb[IFACE_ATTR_IFNAME])) - iface->ifname = blobmsg_data(cur); + if ((cur = tb[IFACE_ATTR_DEVICE])) + iface->device = blobmsg_data(cur); } if (iface->dynamic) { @@ -1216,7 +1216,7 @@ interface_start_jail(const char *jail, const pid_t netns_pid) * list, so we can mess with it :) */ if (iface->jail_ifname) - iface->ifname = iface->jail_ifname; + iface->device = iface->jail_ifname; interface_do_reload(iface); interface_set_up(iface); @@ -1257,9 +1257,9 @@ interface_stop_jail(const char *jail, const pid_t netns_pid) if (!iface->jail || strcmp(iface->jail, jail)) continue; - orig_ifname = iface->ifname; + orig_ifname = iface->device; if (iface->jail_ifname) - iface->ifname = iface->jail_ifname; + iface->device = iface->jail_ifname; interface_do_reload(iface); interface_set_down(iface); @@ -1352,7 +1352,7 @@ interface_change_config(struct interface *if_old, struct interface *if_new) if (!reload && interface_device_config_changed(if_old, if_new)) reload = true; - if (FIELD_CHANGED_STR(ifname) || + if (FIELD_CHANGED_STR(device) || if_old->proto_handler != if_new->proto_handler) reload = true; @@ -1391,7 +1391,7 @@ interface_change_config(struct interface *if_old, struct interface *if_new) if_old->jail_ifname = if_new->jail_ifname; - if_old->ifname = if_new->ifname; + if_old->device = if_new->device; if_old->parent_ifname = if_new->parent_ifname; if_old->dynamic = if_new->dynamic; if_old->proto_handler = if_new->proto_handler; diff --git a/interface.h b/interface.h index 9c136b6..1767bf1 100644 --- a/interface.h +++ b/interface.h @@ -107,7 +107,7 @@ struct interface { enum interface_event hotplug_ev; const char *name; - const char *ifname; + const char *device; char *jail; char *jail_ifname; int netns_fd; diff --git a/ubus.c b/ubus.c index be15062..814fd5d 100644 --- a/ubus.c +++ b/ubus.c @@ -126,9 +126,12 @@ netifd_add_dynamic(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) { + static struct blob_buf buf; struct blob_attr *tb[__DI_MAX]; struct interface *iface; struct blob_attr *config; + struct blob_attr *cur; + int rem; blobmsg_parse(dynamic_policy, __DI_MAX, tb, blob_data(msg), blob_len(msg)); @@ -141,6 +144,17 @@ netifd_add_dynamic(struct ubus_context *ctx, struct ubus_object *obj, if (!iface) return UBUS_STATUS_UNKNOWN_ERROR; + blob_buf_init(&buf, 0); + blob_for_each_attr(cur, msg, rem) { + /* Backward compatibility: s/ifname/device/ */ + if (!strcmp(blobmsg_name(cur), "ifname")) { + blobmsg_add_field(&buf, blobmsg_type(cur), "device", blobmsg_data(cur), blobmsg_data_len(cur)); + continue; + } + blobmsg_add_blob(&buf, cur); + } + msg = buf.head; + config = blob_memdup(msg); if (!config) goto error;