From patchwork Wed Oct 21 03:08:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yousong Zhou X-Patchwork-Id: 1385307 X-Patchwork-Delegate: yszhou4tech@gmail.com 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=KulTQ+fW; 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=fkPI4Zqe; 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 4CGFr21bbTz9sTK for ; Wed, 21 Oct 2020 14:10:57 +1100 (AEDT) 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:References:In-Reply-To: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:List-Owner; bh=7mnL1khhDDN/mMreRtpNP6IQNjwu1Rjs8L7sPAIB1BU=; b=KulTQ+fWaUVjz33lLDqQCEgzy JNhtupqJAMkZWErj5LpoLpZUKK3cr7iJss705maOSUTowSJPZJUvJyXQR6nnQXsYZnEkn5gQWdMDP qOtvz8J8IpjLOzEPmMx22IgW7rmV19itpUNq0Ao3TZRZAgCQg725pREb8UfLeHuZXtuPOVLvpHCrN R7+LjA6oeKXvro7URg7Z2fr2o7VKwAMuareIWN9TinP1BFr+7RC7tM+OshaevyNjNQagwklbgGgxP v8RAK9WvI8B2XP3sdlFJbI5GC3r7WkQZT3e/Kk2NE2hE5KS4psy6uGeug0NsImj926BOkW5XpVXtj BVsHO+Nfg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kV4Ud-0006li-FT; Wed, 21 Oct 2020 03:08:51 +0000 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kV4Ua-0006kj-Hv for openwrt-devel@lists.openwrt.org; Wed, 21 Oct 2020 03:08:49 +0000 Received: by mail-pg1-x542.google.com with SMTP id t14so607717pgg.1 for ; Tue, 20 Oct 2020 20:08:48 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=9H7wjoLcAPXYkY9+elDVBKQhzBPwhRKOPAxKAZqWqTA=; b=fkPI4Zqe071Bp3BmfDt/ZCCOh2sQ3fEvKmbUj5lS805eQqrLVXPoFLupYllG7HgX2d CCZ2iTcOm9xvNAs55VZ0/w8PcwDb2f3JpMx4rUsBtCdjp7okdfKVllhauZbkLrzwHbSh L432qVBFlxHOyMirR1CCm/3lr/Iz2YV941haUdo86VFD7Et80MJ92v3Vn7JDCcVAL40V k5TnvkvPc85h+r4rNWL+8imGH5K+B7m9yn/UUyIYRZwuF3pNfnBdQWC0pBbQQQHyk6k5 wQ5AOaq6k30q3eMHamOJfueq8FyZ3nEaPCsD7QH49T/FecMVSpu05Xok0seluO0LsBt6 GlJA== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=9H7wjoLcAPXYkY9+elDVBKQhzBPwhRKOPAxKAZqWqTA=; b=N9OLvxzpvEfzRm77AlwWMoXaSXhr+L7ynzFdHQY8MQaZtaN5bEdASt78KGbxetIZWJ Xy914GXAU0uZk65BCDje+O3yPqXRoJeV3hjuBm2OWiplooRlRoOd75B8LeGSBKkD7Eq1 BsKwsCNpwNYtAXgKOJNTBWN4xmB/RDiPTC9J/eP9g/RpLDz3/1RCVDOrz65g+2TlJlh8 S8Xge/2qjT9Rj6lwb/qlVDjJR8AfC04C8jfErVR8bVV7scqfeKuUuP6k2vpgisLaTpjg 9/eddXL05WeOa0/AsZ9YwBzRBOrL8h/HW1LwpR3TUyzcRiMDA1vc6awkBM4qWv9U5azX C8Yw== X-Gm-Message-State: AOAM530Om6earoOH+nc6QYAn16A7907FmL5+EQcD1Y3VQOIA3JqVOycT 5dT2rJTVMuRFrFXGh57VCq8= X-Google-Smtp-Source: ABdhPJyUHXj2RIfXfZJrzcgVeUrGf2C9+8tKHcg6bWItmBVNYO6kkCFx/YfIATbgToJaTgKW2RJ4Xg== X-Received: by 2002:a63:120b:: with SMTP id h11mr1180698pgl.291.1603249726602; Tue, 20 Oct 2020 20:08:46 -0700 (PDT) Received: from titan.office.yunion.io ([103.119.177.162]) by smtp.gmail.com with ESMTPSA id f7sm376393pfd.111.2020.10.20.20.08.44 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 20 Oct 2020 20:08:45 -0700 (PDT) From: Yousong Zhou To: Felix Fietkau , Hans Dedecker Subject: [PATCH netifd 2/4] proto: rework parse_addr to return struct device_addr Date: Wed, 21 Oct 2020 11:08:23 +0800 Message-Id: <20201021030825.93626-3-yszhou4tech@gmail.com> In-Reply-To: <20201021030825.93626-1-yszhou4tech@gmail.com> References: <20201021030825.93626-1-yszhou4tech@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201020_230848_630403_D04BB82B X-CRM114-Status: GOOD ( 13.77 ) 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 [2607:f8b0:4864:20:0:0:0:542 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 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 [yszhou4tech[at]gmail.com] -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: Yousong Zhou , openwrt-devel@lists.openwrt.org Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org This is a preparation for the next commit to record address index for the returned device_addr struct Signed-off-by: Yousong Zhou Acked-by: Hans Dedecker --- proto.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/proto.c b/proto.c index cbc92b1..d80cae0 100644 --- a/proto.c +++ b/proto.c @@ -116,16 +116,16 @@ alloc_device_addr(bool v6, bool ext) return addr; } -static bool -parse_addr(struct interface *iface, const char *str, bool v6, int mask, - bool ext, uint32_t broadcast, uint32_t ptp, bool deprecated) +static struct device_addr * +parse_addr(const char *str, bool v6, int mask, bool ext, uint32_t broadcast, + uint32_t ptp, bool deprecated) { struct device_addr *addr; int af = v6 ? AF_INET6 : AF_INET; addr = alloc_device_addr(v6, ext); if (!addr) - return false; + return NULL; addr->mask = mask; if (!parse_ip_and_netmask(af, str, &addr->addr, &addr->mask)) @@ -143,14 +143,12 @@ parse_addr(struct interface *iface, const char *str, bool v6, int mask, if (deprecated) addr->preferred_until = system_get_rtime(); - vlist_add(&iface->proto_ip.addr, &addr->node, &addr->flags); - return true; + return addr; error: - interface_add_error(iface, "proto", "INVALID_ADDRESS", &str, 1); free(addr); - return false; + return NULL; } static int @@ -159,6 +157,8 @@ parse_static_address_option(struct interface *iface, struct blob_attr *attr, uint32_t ptp, bool deprecated) { struct blob_attr *cur; + struct device_addr *addr; + const char *str; int n_addr = 0; int rem; @@ -166,10 +166,14 @@ parse_static_address_option(struct interface *iface, struct blob_attr *attr, if (blobmsg_type(cur) != BLOBMSG_TYPE_STRING) return -1; - n_addr++; - if (!parse_addr(iface, blobmsg_data(cur), v6, netmask, ext, - broadcast, ptp, deprecated)) + str = blobmsg_data(cur); + addr = parse_addr(str, v6, netmask, ext, broadcast, ptp, deprecated); + if (addr == NULL) { + interface_add_error(iface, "proto", "INVALID_ADDRESS", &str, 1); return -1; + } + n_addr++; + vlist_add(&iface->proto_ip.addr, &addr->node, &addr->flags); } return n_addr;