From patchwork Thu Jul 25 09:23:49 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Perevalov X-Patchwork-Id: 261647 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 54AE62C00C9 for ; Thu, 25 Jul 2013 19:24:16 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755242Ab3GYJYN (ORCPT ); Thu, 25 Jul 2013 05:24:13 -0400 Received: from mailout4.w1.samsung.com ([210.118.77.14]:30812 "EHLO mailout4.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754912Ab3GYJYF (ORCPT ); Thu, 25 Jul 2013 05:24:05 -0400 Received: from eucpsbgm2.samsung.com (unknown [203.254.199.245]) by mailout4.w1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MQH00FKKJD6HO60@mailout4.w1.samsung.com>; Thu, 25 Jul 2013 10:24:03 +0100 (BST) X-AuditID: cbfec7f5-b7f376d000001ec6-1c-51f0eeb33a62 Received: from eusync1.samsung.com ( [203.254.199.211]) by eucpsbgm2.samsung.com (EUCPMTA) with SMTP id 36.7E.07878.3BEE0F15; Thu, 25 Jul 2013 10:24:03 +0100 (BST) Received: from aperevalov-ubuntu.rnd.samsung.ru ([106.109.9.222]) by eusync1.samsung.com (Oracle Communications Messaging Server 7u4-23.01(7.0.4.23.0) 64bit (built Aug 10 2011)) with ESMTPA id <0MQH000T9JFRKY20@eusync1.samsung.com>; Thu, 25 Jul 2013 10:24:03 +0100 (BST) From: Alexey Perevalov To: netfilter-devel@vger.kernel.org Cc: pablo@netfilter.org, netfilter@vger.kernel.org, Alexey Perevalov Subject: [PATCH 4/4] libiptc: Use DEBUGP macro from trace.h Date: Thu, 25 Jul 2013 13:23:49 +0400 Message-id: <1374744229-5427-5-git-send-email-a.perevalov@samsung.com> X-Mailer: git-send-email 1.7.9.5 In-reply-to: <1374744229-5427-1-git-send-email-a.perevalov@samsung.com> References: <1374744229-5427-1-git-send-email-a.perevalov@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrBJMWRmVeSWpSXmKPExsVy+t/xy7qb330INDh7QcNi7t3zLBYT1p1i sXixaR2bxfQ3V5kdWDze/j7B5NG3ZRWjx+dNcgHMUVw2Kak5mWWpRfp2CVwZ7W/usRWc9684 fSKwgXGNfRcjB4eEgIlE2+2ALkZOIFNM4sK99WwgtpDAUkaJ5su+XYxcQPY0JonF61cxgtSz CRhI7LtnC1IjIqAs8eZbLyOIzSyQIDFl2zsWEFtYwFriS/NcsDiLgKpE9/4FYDN5BdwkDl// xASxVkFiziQbkDCngLtEw/VNUGvdJGZsXcU2gZF3ASPDKkbR1NLkguKk9FwjveLE3OLSvHS9 5PzcTYyQ0Pi6g3HpMatDjAIcjEo8vCu+vw8UYk0sK67MPcQowcGsJMIbW/EhUIg3JbGyKrUo P76oNCe1+BAjEwenVANjSZuw0LepNZlWB/hXbt7Awb3oYn/Az07hrSncAb6b904pYIsSZG3g WVv1so0p/8kXmdAzD2oO2KiY9ii5BR9L1Xq2kYvh+pbHq3evtfbPF65S2G2yop5L1iRn8/Sl q3a62+faWR11aD+gmzTTZs6WiJr1m2dfmx72s/FsXbLHt3D3w7de+hgqsRRnJBpqMRcVJwIA udF95OsBAAA= Sender: netfilter-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netfilter-devel@vger.kernel.org Signed-off-by: Alexey Perevalov --- libiptc/libiptc.c | 90 ++++++++++++++++++++++------------------------------- 1 file changed, 37 insertions(+), 53 deletions(-) diff --git a/libiptc/libiptc.c b/libiptc/libiptc.c index f0f7815..bff89c3 100644 --- a/libiptc/libiptc.c +++ b/libiptc/libiptc.c @@ -38,23 +38,7 @@ #include #include "linux_list.h" - -//#define IPTC_DEBUG2 1 - -#ifdef IPTC_DEBUG2 -#include -#define DEBUGP(x, args...) fprintf(stderr, "%s: " x, __FUNCTION__, ## args) -#define DEBUGP_C(x, args...) fprintf(stderr, x, ## args) -#else -#define DEBUGP(x, args...) -#define DEBUGP_C(x, args...) -#endif - -#ifdef DEBUG -#define debug(x, args...) fprintf(stderr, x, ## args) -#else -#define debug(x, args...) -#endif +#include "trace.h" static void *iptc_fn = NULL; @@ -338,7 +322,7 @@ __iptcc_bsearch_chain_index(const char *name, unsigned int offset, /* Check for empty array, e.g. no user defined chains */ if (handle->chain_index_sz == 0) { - debug("WARNING: handle->chain_index_sz == 0\n"); + DEBUGP("WARNING: handle->chain_index_sz == 0\n"); return list_pos; } @@ -346,7 +330,7 @@ __iptcc_bsearch_chain_index(const char *name, unsigned int offset, end = handle->chain_index_sz; pos = end / 2; - debug("bsearch Find chain:%s (pos:%d end:%d) (offset:%d)\n", + DEBUGP("bsearch Find chain:%s (pos:%d end:%d) (offset:%d)\n", name, pos, end, offset); /* Loop */ @@ -356,7 +340,7 @@ __iptcc_bsearch_chain_index(const char *name, unsigned int offset, return &handle->chains; /* Be safe, return orig start pos */ } - debug("bsearch Index[%d] name:%s ", + DEBUGP("bsearch Index[%d] name:%s ", pos, handle->chain_index[pos]->name); /* Support for different compare functions */ @@ -365,7 +349,7 @@ __iptcc_bsearch_chain_index(const char *name, unsigned int offset, res = strcmp(name, handle->chain_index[pos]->name); break; case BSEARCH_OFFSET: - debug("head_offset:[%d] foot_offset:[%d] ", + DEBUGP("head_offset:[%d] foot_offset:[%d] ", handle->chain_index[pos]->head_offset, handle->chain_index[pos]->foot_offset); res = offset - handle->chain_index[pos]->head_offset; @@ -376,14 +360,14 @@ __iptcc_bsearch_chain_index(const char *name, unsigned int offset, abort(); break; } - debug("res:%d ", res); + DEBUGP("res:%d ", res); list_pos = &handle->chain_index[pos]->list; *idx = pos; if (res == 0) { /* Found element, by direct hit */ - debug("[found] Direct hit pos:%d end:%d\n", pos, end); + DEBUGP("[found] Direct hit pos:%d end:%d\n", pos, end); return list_pos; } else if (res < 0) { /* Too far, jump back */ end = pos; @@ -391,16 +375,16 @@ __iptcc_bsearch_chain_index(const char *name, unsigned int offset, /* Exit case: First element of array */ if (end == 0) { - debug("[found] Reached first array elem (end%d)\n",end); + DEBUGP("[found] Reached first array elem (end%d)\n",end); return list_pos; } - debug("jump back to pos:%d (end:%d)\n", pos, end); + DEBUGP("jump back to pos:%d (end:%d)\n", pos, end); goto loop; } else { /* res > 0; Not far enough, jump forward */ /* Exit case: Last element of array */ if (pos == handle->chain_index_sz-1) { - debug("[found] Last array elem (end:%d)\n", end); + DEBUGP("[found] Last array elem (end:%d)\n", end); return list_pos; } @@ -415,12 +399,12 @@ __iptcc_bsearch_chain_index(const char *name, unsigned int offset, } if (res < 0) { - debug("[found] closest list (end:%d)\n", end); + DEBUGP("[found] closest list (end:%d)\n", end); return list_pos; } pos = (pos+end)/2; - debug("jump forward to pos:%d (end:%d)\n", pos, end); + DEBUGP("jump forward to pos:%d (end:%d)\n", pos, end); goto loop; } } @@ -496,7 +480,7 @@ static int iptcc_chain_index_alloc(struct xtc_handle *h) (h->num_chains % list_length ? 1 : 0); array_mem = sizeof(h->chain_index) * array_elems; - debug("Alloc Chain index, elems:%d mem:%d bytes\n", + DEBUGP("Alloc Chain index, elems:%d mem:%d bytes\n", array_elems, array_mem); h->chain_index = malloc(array_mem); @@ -541,9 +525,9 @@ static int iptcc_chain_index_build(struct xtc_handle *h) struct chain_head *c; /* Build up the chain index array here */ - debug("Building chain index\n"); + DEBUGP("Building chain index\n"); - debug("Number of user defined chains:%d bucket_sz:%d array_sz:%d\n", + DEBUGP("Number of user defined chains:%d bucket_sz:%d array_sz:%d\n", h->num_chains, list_length, h->chain_index_sz); if (h->chain_index_sz == 0) @@ -563,21 +547,21 @@ static int iptcc_chain_index_build(struct xtc_handle *h) break; if ((chains % list_length)== 0) { - debug("\nIndex[%d] Chains:", cindex); + DEBUGP("\nIndex[%d] Chains:", cindex); h->chain_index[cindex] = c; } chains++; } - debug("%s, ", c->name); + DEBUGP("%s, ", c->name); } - debug("\n"); + DEBUGP("\n"); return 1; } static int iptcc_chain_index_rebuild(struct xtc_handle *h) { - debug("REBUILD chain index array\n"); + DEBUGP("REBUILD chain index array\n"); iptcc_chain_index_free(h); if ((iptcc_chain_index_alloc(h)) < 0) return -ENOMEM; @@ -605,7 +589,7 @@ static int iptcc_chain_index_delete_chain(struct chain_head *c, struct xtc_handl index_ptr = iptcc_bsearch_chain_index(c->name, &idx, h); - debug("Del chain[%s] c->list:%p index_ptr:%p\n", + DEBUGP("Del chain[%s] c->list:%p index_ptr:%p\n", c->name, &c->list, index_ptr); /* Save the next pointer */ @@ -625,7 +609,7 @@ static int iptcc_chain_index_delete_chain(struct chain_head *c, struct xtc_handl return iptcc_chain_index_rebuild(h); } else { /* Avoiding rebuild */ - debug("Update cindex[%d] with next ptr name:[%s]\n", + DEBUGP("Update cindex[%d] with next ptr name:[%s]\n", idx, c2->name); h->chain_index[idx]=c2; return 0; @@ -693,13 +677,13 @@ iptcc_find_chain_by_offset(struct xtc_handle *handle, unsigned int offset) * chains, but this function is only used for finding jump * targets, and a buildin chain is not a valid jump target */ - debug("Offset:[%u] starting search at index:[%u]\n", offset, i); + DEBUGP("Offset:[%u] starting search at index:[%u]\n", offset, i); // list_for_each(pos, &handle->chains) { list_for_each(pos, list_start_pos->prev) { struct chain_head *c = list_entry(pos, struct chain_head, list); - debug("."); + DEBUGP("."); if (offset >= c->head_offset && offset <= c->foot_offset) { - debug("Offset search found chain:[%s]\n", c->name); + DEBUGP("Offset search found chain:[%s]\n", c->name); return c; } } @@ -743,13 +727,13 @@ iptcc_find_label(const char *name, struct xtc_handle *handle) struct chain_head *test_c, *tmp_c; test_pos = iptcc_linearly_search_chain_index(name, handle); if (list_start_pos != test_pos) { - debug("BUG in chain_index search\n"); + DEBUGP("BUG in chain_index search\n"); test_c=list_entry(test_pos, struct chain_head,list); tmp_c =list_entry(list_start_pos,struct chain_head,list); - debug("Verify search found:\n"); - debug(" Chain:%s\n", test_c->name); - debug("BSearch found:\n"); - debug(" Chain:%s\n", tmp_c->name); + DEBUGP("Verify search found:\n"); + DEBUGP(" Chain:%s\n", test_c->name); + DEBUGP("BSearch found:\n"); + DEBUGP(" Chain:%s\n", tmp_c->name); exit(42); } } @@ -763,24 +747,24 @@ iptcc_find_label(const char *name, struct xtc_handle *handle) list_for_each(pos, list_start_pos->prev) { struct chain_head *c = list_entry(pos, struct chain_head, list); res = strcmp(c->name, name); - debug("List search name:%s == %s res:%d\n", name, c->name, res); + DEBUGP("List search name:%s == %s res:%d\n", name, c->name, res); if (res==0) return c; /* We can stop earlier as we know list is sorted */ if (res>0 && !iptcc_is_builtin(c)) { /* Walked too far*/ - debug(" Not in list, walked too far, sorted list\n"); + DEBUGP(" Not in list, walked too far, sorted list\n"); return NULL; } /* Stop on wrap around, if list head is reached */ if (pos == &handle->chains) { - debug("Stop, list head reached\n"); + DEBUGP("Stop, list head reached\n"); return NULL; } } - debug("List search NOT found name:%s\n", name); + DEBUGP("List search NOT found name:%s\n", name); return NULL; } @@ -853,7 +837,7 @@ static void iptc_insert_chain(struct xtc_handle *h, struct chain_head *c) if (i==0 && strcmp(c->name, h->chain_index[0]->name) <= 0) { h->chain_index[0] = c; /* Update chain index head */ list_start_pos = h->chains.next; - debug("Update chain_index[0] with %s\n", c->name); + DEBUGP("Update chain_index[0] with %s\n", c->name); } /* Handel if bsearch bails out early */ @@ -871,7 +855,7 @@ static void iptc_insert_chain(struct xtc_handle *h, struct chain_head *c) /* Stop if list head is reached */ if (&tmp->list == &h->chains) { - debug("Insert, list head reached add to tail\n"); + DEBUGP("Insert, list head reached add to tail\n"); break; } } @@ -916,7 +900,7 @@ static void __iptcc_p_add_chain(struct xtc_handle *h, struct chain_head *c, */ h->sorted_offsets = 0; - debug("NOTICE: chain:[%s] was NOT sorted(ctail:%s)\n", + DEBUGP("NOTICE: chain:[%s] was NOT sorted(ctail:%s)\n", c->name, ctail->name); } } @@ -2275,7 +2259,7 @@ TC_CREATE_CHAIN(const IPT_CHAINLABEL chain, struct xtc_handle *handle) capacity = handle->chain_index_sz * CHAIN_INDEX_BUCKET_LEN; exceeded = handle->num_chains - capacity; if (exceeded > CHAIN_INDEX_INSERT_MAX) { - debug("Capacity(%d) exceeded(%d) rebuild (chains:%d)\n", + DEBUGP("Capacity(%d) exceeded(%d) rebuild (chains:%d)\n", capacity, exceeded, handle->num_chains); iptcc_chain_index_rebuild(handle); }