From patchwork Sat Sep 5 23:53:25 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Pfaff X-Patchwork-Id: 514859 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from archives.nicira.com (unknown [IPv6:2600:3c00::f03c:91ff:fe6e:bdf7]) by ozlabs.org (Postfix) with ESMTP id B0B3A1401F0 for ; Sun, 6 Sep 2015 09:53:32 +1000 (AEST) Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id C5D1410871; Sat, 5 Sep 2015 16:53:30 -0700 (PDT) X-Original-To: dev@openvswitch.org Delivered-To: dev@openvswitch.org Received: from mx1e4.cudamail.com (mx1.cudamail.com [69.90.118.67]) by archives.nicira.com (Postfix) with ESMTPS id 5C3B71086E for ; Sat, 5 Sep 2015 16:53:29 -0700 (PDT) Received: from bar2.cudamail.com (unknown [192.168.21.12]) by mx1e4.cudamail.com (Postfix) with ESMTPS id B354F1E0205 for ; Sat, 5 Sep 2015 17:53:28 -0600 (MDT) X-ASG-Debug-ID: 1441497207-03dc5311eb07d00001-byXFYA Received: from mx1-pf1.cudamail.com ([192.168.24.1]) by bar2.cudamail.com with ESMTP id wldvepky0S5cvRhc (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Sat, 05 Sep 2015 17:53:28 -0600 (MDT) X-Barracuda-Envelope-From: blp@nicira.com X-Barracuda-RBL-Trusted-Forwarder: 192.168.24.1 Received: from unknown (HELO mail-pa0-f47.google.com) (209.85.220.47) by mx1-pf1.cudamail.com with ESMTPS (RC4-SHA encrypted); 5 Sep 2015 23:53:27 -0000 Received-SPF: unknown (mx1-pf1.cudamail.com: Multiple SPF records returned) X-Barracuda-RBL-Trusted-Forwarder: 209.85.220.47 Received: by padhy16 with SMTP id hy16so56510322pad.1 for ; Sat, 05 Sep 2015 16:53:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-type:content-disposition:in-reply-to :user-agent; bh=o1nXqNo6pMi2cjeHuJly5AFocLK8dCRaG2pLR+ubbeA=; b=Uvbywxx/lorYinsj22x3eAYUtf0tVgWgTU+eU9icZ+9MtGexYwsbaE+Jw/mkxE6SEc wHvxrQdbpWB8UevKsVV/rgyLMzDuHgF29HroUKAX6UG0gineUjtx6yqWJxMfi9SpeUgQ k+qsY3rRstccC4Jye6KMHRIoJO0hntjfECImfOedxLUU1zCdT+LnhEweSGEd51OL9lAf ZyQDr2L+6/Tj9RPI4YRkBzM9EqSUKIikhV5QxeoKcqNzBDzYkuAHeko0OvAaeIHfYI5x ultj7xeobjjrM3cMvATBjnG05Zscydq9eubaL+RRi+6PQpZZeC+dlnNTC5DaIzn0uiz6 UeWQ== X-Gm-Message-State: ALoCoQmvkdxVbpiA8A71/HUZxNRaLlV87SZCMycLWbZ+/4CQZ5BhjJrfS7dy+qfW7Ng3HC7aoyVy X-Received: by 10.68.99.197 with SMTP id es5mr26566279pbb.112.1441497206765; Sat, 05 Sep 2015 16:53:26 -0700 (PDT) Received: from nicira.com (173-228-112-165.dsl.dynamic.fusionbroadband.com. [173.228.112.165]) by smtp.gmail.com with ESMTPSA id pi9sm6990261pbb.96.2015.09.05.16.53.24 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 05 Sep 2015 16:53:25 -0700 (PDT) Date: Sat, 5 Sep 2015 16:53:25 -0700 X-Barracuda-Apparent-Source-IP: 173.228.112.165 X-CudaMail-Envelope-Sender: blp@nicira.com From: Ben Pfaff To: Justin Pettit X-CudaMail-Whitelist-To: dev@openvswitch.org X-CudaMail-MID: CM-E1-904027304 X-CudaMail-DTE: 090515 X-CudaMail-Originating-IP: 209.85.220.47 Message-ID: <20150905235325.GB23703@nicira.com> X-ASG-Orig-Subj: [##CM-E1-904027304##]Re: [ovs-dev] [PATCH 2/2] ovn-nbctl: Add ACL commands. References: <1441413542-92140-1-git-send-email-jpettit@nicira.com> <1441413542-92140-2-git-send-email-jpettit@nicira.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1441413542-92140-2-git-send-email-jpettit@nicira.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-Barracuda-Connect: UNKNOWN[192.168.24.1] X-Barracuda-Start-Time: 1441497208 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://web.cudamail.com:443/cgi-mod/mark.cgi X-ASG-Whitelist: Header =?UTF-8?B?eFwtY3VkYW1haWxcLXdoaXRlbGlzdFwtdG8=?= X-Virus-Scanned: by bsmtpd at cudamail.com X-Barracuda-BRTS-Status: 1 Cc: dev@openvswitch.org Subject: Re: [ovs-dev] [PATCH 2/2] ovn-nbctl: Add ACL commands. 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: , Errors-To: dev-bounces@openvswitch.org Sender: "dev" On Fri, Sep 04, 2015 at 05:39:02PM -0700, Justin Pettit wrote: > Signed-off-by: Justin Pettit I came really close to duplicating your work here on Thursday when I was writing tests. I'm glad that didn't happen. The printf() specifier is wrong here: Acked-by: Ben Pfaff diff --git a/ovn/utilities/ovn-nbctl.c b/ovn/utilities/ovn-nbctl.c index 0b19521..26a4735 100644 --- a/ovn/utilities/ovn-nbctl.c +++ b/ovn/utilities/ovn-nbctl.c @@ -824,7 +824,7 @@ do_acl_list(struct ovs_cmdl_context *ctx) for (i = 0; i < lswitch->n_acls; i++) { const struct nbrec_acl *acl = acls[i]; - printf("%10s %5ld (%s) %s%s\n", acl->direction, acl->priority, + printf("%10s %5"PRId64" (%s) %s%s\n", acl->direction, acl->priority, acl->match, acl->action, acl->log ? " log" : ""); } I'd prefer to avoid casts in acl_cmp(), also the macro there doesn't seem to help much: diff --git a/ovn/utilities/ovn-nbctl.c b/ovn/utilities/ovn-nbctl.c index 0b19521..384bc7b 100644 --- a/ovn/utilities/ovn-nbctl.c +++ b/ovn/utilities/ovn-nbctl.c @@ -775,31 +775,20 @@ dir_encode(const char *dir) static int acl_cmp(const void *acl1_, const void *acl2_) { - const struct nbrec_acl *acl1, *acl2; - - acl1 = *((struct nbrec_acl **) acl1_); - acl2 = *((struct nbrec_acl **) acl2_); + const struct nbrec_acl *const *acl1p = acl1_; + const struct nbrec_acl *const *acl2p = acl2_; + const struct nbrec_acl *acl1 = *acl1p; + const struct nbrec_acl *acl2 = *acl2p; int dir1 = dir_encode(acl1->direction); int dir2 = dir_encode(acl2->direction); - -#define CMP(expr) \ - do { \ - int res; \ - res = (expr); \ - if (res) { \ - return res; \ - } \ - } while (0) - - CMP(dir1 - dir2); - CMP(acl1->priority > acl2->priority ? -1 : - (acl1->priority < acl2->priority ? 1 : 0)); - CMP(strcmp(acl1->match, acl2->match)); - -#undef CMP - - return 0; + if (dir1 != dir2) { + return dir1 > dir2 ? -1 : 1; + } else if (acl1->priority != acl2->priority) { + return acl1->priority > acl2->priority ? -1 : 1; + } else { + return strcmp(acl1->match, acl2->match); + } } static void