From patchwork Wed Oct 5 11:20:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: nickcooper-zhangtonghao X-Patchwork-Id: 678387 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from archives.nicira.com (archives.nicira.com [96.126.127.54]) by ozlabs.org (Postfix) with ESMTP id 3sptdL0CKFz9s3s for ; Wed, 5 Oct 2016 22:21:09 +1100 (AEDT) Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id 0B46510655; Wed, 5 Oct 2016 04:21:09 -0700 (PDT) X-Original-To: dev@openvswitch.org Delivered-To: dev@openvswitch.org Received: from mx1e3.cudamail.com (mx1.cudamail.com [69.90.118.67]) by archives.nicira.com (Postfix) with ESMTPS id 9141F1064B for ; Wed, 5 Oct 2016 04:21:07 -0700 (PDT) Received: from bar5.cudamail.com (localhost [127.0.0.1]) by mx1e3.cudamail.com (Postfix) with ESMTPS id 2301E420696 for ; Wed, 5 Oct 2016 05:21:07 -0600 (MDT) X-ASG-Debug-ID: 1475666466-09eadd4e19dea40001-byXFYA Received: from mx1-pf1.cudamail.com ([192.168.24.1]) by bar5.cudamail.com with ESMTP id 0SQen7sySYCmpsFF (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Wed, 05 Oct 2016 05:21:06 -0600 (MDT) X-Barracuda-Envelope-From: nickcooper-zhangtonghao@opencloud.tech X-Barracuda-RBL-Trusted-Forwarder: 192.168.24.1 Received: from unknown (HELO smtpbgsg2.qq.com) (54.254.200.128) by mx1-pf1.cudamail.com with ESMTPS (DHE-RSA-AES256-SHA encrypted); 5 Oct 2016 11:21:05 -0000 Received-SPF: none (mx1-pf1.cudamail.com: domain at opencloud.tech does not designate permitted sender hosts) X-Barracuda-Apparent-Source-IP: 54.254.200.128 X-Barracuda-RBL-IP: 54.254.200.128 X-QQ-mid: bizesmtp5t1475666460t58hlpx3a Received: from local.opencloud.tech.localdomai (unknown [117.100.145.25]) by esmtp4.qq.com (ESMTP) with id ; Wed, 05 Oct 2016 19:20:59 +0800 (CST) X-QQ-SSF: 01100000002000F0FFF0B00A0000000 X-QQ-FEAT: R6TcVykn+7/k+7nL7SvGVFsx6AgZnig9O/zaWRz8sMrwuzJy3IXSOW/LY1tbm jLl3rG6yY1gHeC1C/vBW9+u8K3ZMMMDZgnNtt7VmVtu6iyhXjwNfLQXPm0MXQgw6Vkk76qJ TTZwp9b4ehVm6XP9QDeDnjtUBNT4RQj5QrRTT3I0b3Tfx+v1xK847FdZAubZrZiyAoG0Clj AWfmjUjUFIME8IN2BY7JDtjNvmV8ctiB0tTamtHmwNLJ6FaSKdG8un2ECUz0udEc= X-QQ-GoodBg: 0 X-CudaMail-Envelope-Sender: nickcooper-zhangtonghao@opencloud.tech From: nickcooper-zhangtonghao To: dev@openvswitch.org X-CudaMail-MID: CM-E1-1004007357 X-CudaMail-DTE: 100516 X-CudaMail-Originating-IP: 54.254.200.128 Date: Wed, 5 Oct 2016 04:20:43 -0700 X-ASG-Orig-Subj: [##CM-E1-1004007357##][PATCH 2/4] ovn-nbctl: Check the length of MAC address Message-Id: <1475666445-90772-2-git-send-email-nickcooper-zhangtonghao@opencloud.tech> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1475666445-90772-1-git-send-email-nickcooper-zhangtonghao@opencloud.tech> References: <1475666445-90772-1-git-send-email-nickcooper-zhangtonghao@opencloud.tech> X-QQ-SENDSIZE: 520 X-QQ-Bgrelay: 1 X-Barracuda-Connect: UNKNOWN[192.168.24.1] X-Barracuda-Start-Time: 1475666466 X-Barracuda-Encrypted: ECDHE-RSA-AES256-GCM-SHA384 X-Barracuda-URL: https://web.cudamail.com:443/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at cudamail.com X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 1.10 X-Barracuda-Spam-Status: No, SCORE=1.10 using global scores of TAG_LEVEL=3.5 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=4.0 tests=BSF_SC0_MV0713, BSF_SC5_MJ1963, RDNS_NONE X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.33489 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- 0.10 RDNS_NONE Delivered to trusted network by a host with no rDNS 0.50 BSF_SC0_MV0713 Custom rule MV0713 0.50 BSF_SC5_MJ1963 Custom Rule MJ1963 Cc: nickcooper-zhangtonghao Subject: [ovs-dev] [PATCH 2/4] ovn-nbctl: Check the length of MAC address X-BeenThere: dev@openvswitch.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dev-bounces@openvswitch.org Sender: "dev" The command "ovn-nbctl lrp-add" should not set the MAC address which length is invalid to logical router port. This patch updates the eth_addr_from_string() to check trailing characters. We should use the ovs_scan() to check the "addresses" owned by the logical port, instead of eth_addr_from_string(). This patch also updates the ovn-nbctl tests. Signed-off-by: nickcooper-zhangtonghao --- lib/packets.c | 15 +++++++++------ ovn/northd/ovn-northd.c | 11 +++++++---- ovn/utilities/ovn-nbctl.c | 2 +- tests/ovn-nbctl.at | 7 +++++++ 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/lib/packets.c b/lib/packets.c index 11bb587..f661c34 100644 --- a/lib/packets.c +++ b/lib/packets.c @@ -142,16 +142,19 @@ eth_addr_is_reserved(const struct eth_addr ea) /* Attempts to parse 's' as an Ethernet address. If successful, stores the * address in 'ea' and returns true, otherwise zeros 'ea' and returns - * false. */ + * false. This function checks trailing characters. */ bool eth_addr_from_string(const char *s, struct eth_addr *ea) { - if (ovs_scan(s, ETH_ADDR_SCAN_FMT, ETH_ADDR_SCAN_ARGS(*ea))) { - return true; - } else { - *ea = eth_addr_zero; - return false; + int n = 0; + if (ovs_scan_len(s, &n, ETH_ADDR_SCAN_FMT, ETH_ADDR_SCAN_ARGS(*ea))) { + if (!s[n]) { + return true; + } } + + *ea = eth_addr_zero; + return false; } /* Fills 'b' with a Reverse ARP packet with Ethernet source address 'eth_src'. diff --git a/ovn/northd/ovn-northd.c b/ovn/northd/ovn-northd.c index eeeb41d..42b5423 100644 --- a/ovn/northd/ovn-northd.c +++ b/ovn/northd/ovn-northd.c @@ -2912,9 +2912,12 @@ build_lswitch_flows(struct hmap *datapaths, struct hmap *ports, } for (size_t i = 0; i < op->nbsp->n_addresses; i++) { + /* Addresses are owned by the logical port. + * Ethernet address followed by zero or more IPv4 + * or IPv6 addresses (or both). */ struct eth_addr mac; - - if (eth_addr_from_string(op->nbsp->addresses[i], &mac)) { + if (ovs_scan(op->nbsp->addresses[i], + ETH_ADDR_SCAN_FMT, ETH_ADDR_SCAN_ARGS(mac))) { ds_clear(&match); ds_put_format(&match, "eth.dst == "ETH_ADDR_FMT, ETH_ADDR_ARGS(mac)); @@ -2930,8 +2933,8 @@ build_lswitch_flows(struct hmap *datapaths, struct hmap *ports, } } else if (!strcmp(op->nbsp->addresses[i], "dynamic")) { if (!op->nbsp->dynamic_addresses - || !eth_addr_from_string(op->nbsp->dynamic_addresses, - &mac)) { + || !ovs_scan(op->nbsp->dynamic_addresses, + ETH_ADDR_SCAN_FMT, ETH_ADDR_SCAN_ARGS(mac))) { continue; } ds_clear(&match); diff --git a/ovn/utilities/ovn-nbctl.c b/ovn/utilities/ovn-nbctl.c index 7643241..453ff72 100644 --- a/ovn/utilities/ovn-nbctl.c +++ b/ovn/utilities/ovn-nbctl.c @@ -2299,7 +2299,7 @@ nbctl_lrp_add(struct ctl_context *ctx) } struct eth_addr ea; - if (!ovs_scan(mac, ETH_ADDR_SCAN_FMT, ETH_ADDR_SCAN_ARGS(ea))) { + if (!eth_addr_from_string(mac, &ea)) { ctl_fatal("%s: invalid mac address %s", lrp_name, mac); } diff --git a/tests/ovn-nbctl.at b/tests/ovn-nbctl.at index d8331f8..115d781 100644 --- a/tests/ovn-nbctl.at +++ b/tests/ovn-nbctl.at @@ -530,6 +530,13 @@ AT_SETUP([ovn-nbctl - basic logical router port commands]) OVN_NBCTL_TEST_START AT_CHECK([ovn-nbctl lr-add lr0]) +AT_CHECK([ovn-nbctl lrp-add lr0 lrp0 00:00:00:01:02 192.168.1.1/24], [1], [], + [ovn-nbctl: lrp0: invalid mac address 00:00:00:01:02 +]) +AT_CHECK([ovn-nbctl lrp-add lr0 lrp0 00:00:00:01:02:03:04 192.168.1.1/24], [1], [], + [ovn-nbctl: lrp0: invalid mac address 00:00:00:01:02:03:04 +]) + AT_CHECK([ovn-nbctl lrp-add lr0 lrp0 00:00:00:01:02:03 192.168.1.1/24]) AT_CHECK([ovn-nbctl show lr0 | ${PERL} $srcdir/uuidfilt.pl], [0], [dnl