From patchwork Thu Aug 11 13:53:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Dedecker X-Patchwork-Id: 658230 X-Patchwork-Delegate: blogic@openwrt.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from arrakis.dune.hu (arrakis.dune.hu [78.24.191.176]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3s98fc5VLQz9sR9 for ; Thu, 11 Aug 2016 23:55:20 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=vUmmh3u5; dkim-atps=neutral Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 82738B91BF3; Thu, 11 Aug 2016 15:54:15 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on arrakis.dune.hu X-Spam-Level: X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,FREEMAIL_FROM, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.1 Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP; Thu, 11 Aug 2016 15:54:15 +0200 (CEST) Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 3B83CB91BD5 for ; Thu, 11 Aug 2016 15:54:07 +0200 (CEST) X-policyd-weight: using cached result; rate:hard: -7 Received: from mail-wm0-f66.google.com (mail-wm0-f66.google.com [74.125.82.66]) by arrakis.dune.hu (Postfix) with ESMTPS for ; Thu, 11 Aug 2016 15:54:06 +0200 (CEST) Received: by mail-wm0-f66.google.com with SMTP id q128so1558497wma.1 for ; Thu, 11 Aug 2016 06:54:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Ic5qgB9Y9a933UmJxWzORqabhMc2V2EerkO/PGHb5JM=; b=vUmmh3u5WU4Y7CUxVYt9QagHSgAZdtZeMSTNqxQYvHezSxyXGrBR0JIRtDwZr3ns2H I3BJVU/z/+TNDtnMQxnIbChaQ8SAPpWksupHkUI2OhWnNMuYpkksvuDg2sMVwB26H5wX nhacm2e9r913J3PLD6k/T1tuVwWwWCz9JFs7VV3ZkU+w0Px83qsmwYrnZxo+TV2UgbZ9 4ertljvPAg9uRFJjg2T3d9L0X0YKKs2KBKaNsbfjHNH/9PJtdm97+ZXZRGbUZlLsCeEh FQCyOV4n6iPvT6J5KSwqw9Fo2lmdnFs9uR4bwmZgCR7heuwHC8XGijbDlTUuXFb4CkJ7 GlzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Ic5qgB9Y9a933UmJxWzORqabhMc2V2EerkO/PGHb5JM=; b=H8w76DHbSjPWt4nXkjsbuZDJXt2TH5kPmnVIES3UjsbNfaik7uVzFrpJ+GHcSC8tMh kNtQme1btkeOi0/slEdGAkF8ZMUW616r8TlP4n832c9G3rvPZsOgA1cwGchD+tWuAjoU IbxcYscH/cMx5Tej27uJVlmGFz0uvqAs3+KgOexxff3nvX+CLyaUiHOTOtCNkjifjWwh ni1JQ+eVMct3GtEt7ZYw4v9wHNyPRgRGZHZJlS4qFfJXEbvhmrorNEpsVlryiYkQEUfp cW0PGV1MvIukWHPgv6JIOscHiD6HvHfY8AEYJeWQhRf6OlROq5olZgO2pNrJyFTwYW+T 1uBw== X-Gm-Message-State: AEkoouuJ6kfTipjkOl3HURVUGRsL/Zp+MPu1ICK8J9CQPGmWtN4Eg0h1Z/c9Sx0ZnD50Gw== X-Received: by 10.194.149.113 with SMTP id tz17mr11922579wjb.64.1470923646051; Thu, 11 Aug 2016 06:54:06 -0700 (PDT) Received: from cplx43.eu.thmulti.com ([141.11.62.7]) by smtp.gmail.com with ESMTPSA id 207sm238901wmb.7.2016.08.11.06.54.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 11 Aug 2016 06:54:05 -0700 (PDT) From: Hans Dedecker To: openwrt-devel@lists.openwrt.org, lede-dev@lists.infradead.org Date: Thu, 11 Aug 2016 15:53:29 +0200 Message-Id: <1470923609-24767-5-git-send-email-dedeckeh@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1470923609-24767-1-git-send-email-dedeckeh@gmail.com> References: <1470923609-24767-1-git-send-email-dedeckeh@gmail.com> Subject: [OpenWrt-Devel] [PATCH 5/5 netifd] utils: Move IP address validation to parse_addr function X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Hans Dedecker , steven@midlink.org MIME-Version: 1.0 Errors-To: openwrt-devel-bounces@lists.openwrt.org Sender: "openwrt-devel" Commit 7a51f23e adds IP address validation in the function parse_ip_and_netmask; however the added check is too restrictive as the function is used on several places resulting into the problem multicast routes cannot be added anymore via UCI. Therefore move the IP host address validation to the function parse_addr so experimantal/multicast addresses cannot be added as a host IP address while multicast routes can be added again. Signed-off-by: Hans Dedecker --- proto.c | 20 +++++++++++++++----- utils.c | 19 +------------------ 2 files changed, 16 insertions(+), 23 deletions(-) diff --git a/proto.c b/proto.c index 3b973d9..23304f3 100644 --- a/proto.c +++ b/proto.c @@ -123,17 +123,27 @@ parse_addr(struct interface *iface, const char *str, bool v6, int mask, return false; addr->mask = mask; - if (!parse_ip_and_netmask(af, str, &addr->addr, &addr->mask)) { - interface_add_error(iface, "proto", "INVALID_ADDRESS", &str, 1); - free(addr); - return false; - } + if (!parse_ip_and_netmask(af, str, &addr->addr, &addr->mask)) + goto error; + + if (!v6) { + if (IN_EXPERIMENTAL(ntohl(addr->addr.in.s_addr))) + goto error; + + } else if (IN6_IS_ADDR_MULTICAST(&addr->addr.in6)) + goto error; if (broadcast) addr->broadcast = broadcast; vlist_add(&iface->proto_ip.addr, &addr->node, &addr->flags); return true; + +error: + interface_add_error(iface, "proto", "INVALID_ADDRESS", &str, 1); + free(addr); + + return false; } static int diff --git a/utils.c b/utils.c index e01b633..ba26952 100644 --- a/utils.c +++ b/utils.c @@ -119,7 +119,6 @@ int parse_ip_and_netmask(int af, const char *str, void *addr, unsigned int *netmask) { char *astr = alloca(strlen(str) + 1); - int ret = 0; strcpy(astr, str); if (!split_netmask(astr, netmask, af == AF_INET6)) @@ -133,23 +132,7 @@ parse_ip_and_netmask(int af, const char *str, void *addr, unsigned int *netmask) return 0; } - ret = inet_pton(af, astr, addr); - if (ret > 0) { - if (af == AF_INET) { - struct in_addr *ip4_addr = (struct in_addr *)addr; - uint32_t host_addr = ntohl(ip4_addr->s_addr); - - if (IN_EXPERIMENTAL(host_addr)) { - return 0; - } - } - else if (af == AF_INET6) { - if (IN6_IS_ADDR_MULTICAST((struct in6_addr *)addr)) { - return 0; - } - } - } - return ret; + return inet_pton(af, astr, addr); } char *