From patchwork Mon Apr 22 11:12:18 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: YourName X-Patchwork-Id: 2894 Return-Path: Received: from mail-we0-f176.google.com (mail-we0-f176.google.com [74.125.82.176]) by open-mesh.org (Postfix) with ESMTPS id C819C6019EB for ; Mon, 22 Apr 2013 13:13:19 +0200 (CEST) Received: by mail-we0-f176.google.com with SMTP id s10so1199900wey.21 for ; Mon, 22 Apr 2013 04:13:19 -0700 (PDT) X-Received: by 10.194.173.228 with SMTP id bn4mr51347146wjc.20.1366629199403; Mon, 22 Apr 2013 04:13:19 -0700 (PDT) Received: from cmihail-VirtualBox.labs.cs.pub.ro ([141.85.225.204]) by mx.google.com with ESMTPS id 8sm39916515eeg.15.2013.04.22.04.13.17 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 22 Apr 2013 04:13:18 -0700 (PDT) From: YourName To: b.a.t.m.a.n@lists.open-mesh.org Date: Mon, 22 Apr 2013 14:12:18 +0300 Message-Id: <1366629138-28627-1-git-send-email-mihail.costea2005@gmail.com> X-Mailer: git-send-email 1.7.10.4 X-Mailman-Approved-At: Mon, 22 Apr 2013 19:49:35 +0200 Subject: [B.A.T.M.A.N.] [PATCH] Added generic transformer to string function for DAT data X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 22 Apr 2013 11:13:20 -0000 Signed-off-by: Mihail Costea Signed-off-by: Stefan Popa Reviewed-by: Stefan Popa --- distributed-arp-table.c | 71 +++++++++++++++++++++++++++++++++++++++++------ types.h | 8 ++++++ 2 files changed, 70 insertions(+), 9 deletions(-) diff --git a/distributed-arp-table.c b/distributed-arp-table.c index 3a3e1d8..5df8f19 100644 --- a/distributed-arp-table.c +++ b/distributed-arp-table.c @@ -34,6 +34,36 @@ static void batadv_dat_purge(struct work_struct *work); /** + * batadv_dat_data_to_str: transforms DAT data to string + * @data: the DAT data + * @type: type of data + * + * Returns the string representation of data. This should be freed with kfree. + */ +static char *batadv_dat_data_to_str(void *data, uint8_t type) +{ + size_t buf_size; + char *buf, *format_type, ipv4[] = "%pI4"; + + switch (type) { + case BATADV_DAT_IPV4: + /* maximum length for an IPv4 string representation + NULL */ + buf_size = 16; + format_type = ipv4; + break; + default: + return NULL; + } + + buf = kmalloc(buf_size, GFP_ATOMIC); + if (!buf) + return NULL; + snprintf(buf, buf_size, format_type, data); + + return buf; +} + +/** * batadv_dat_start_timer - initialise the DAT periodic worker * @bat_priv: the bat priv with all the soft interface information */ @@ -272,6 +302,7 @@ static void batadv_dat_entry_add(struct batadv_priv *bat_priv, __be32 ip, { struct batadv_dat_entry *dat_entry; int hash_added; + char *dbg_data; dat_entry = batadv_dat_entry_hash_find(bat_priv, ip); /* if this entry is already known, just update it */ @@ -279,9 +310,15 @@ static void batadv_dat_entry_add(struct batadv_priv *bat_priv, __be32 ip, if (!batadv_compare_eth(dat_entry->mac_addr, mac_addr)) memcpy(dat_entry->mac_addr, mac_addr, ETH_ALEN); dat_entry->last_update = jiffies; - batadv_dbg(BATADV_DBG_DAT, bat_priv, - "Entry updated: %pI4 %pM\n", &dat_entry->ip, - dat_entry->mac_addr); + + dbg_data = batadv_dat_data_to_str(&dat_entry->ip, + BATADV_DAT_IPV4); + if (dbg_data) { + batadv_dbg(BATADV_DBG_DAT, bat_priv, + "Entry updated: %s %pM\n", dbg_data, + dat_entry->mac_addr); + kfree(dbg_data); + } goto out; } @@ -304,8 +341,13 @@ static void batadv_dat_entry_add(struct batadv_priv *bat_priv, __be32 ip, goto out; } - batadv_dbg(BATADV_DBG_DAT, bat_priv, "New entry added: %pI4 %pM\n", - &dat_entry->ip, dat_entry->mac_addr); + dbg_data = batadv_dat_data_to_str(&dat_entry->ip, BATADV_DAT_IPV4); + if (dbg_data) { + batadv_dbg(BATADV_DBG_DAT, bat_priv, + "New entry added: %s %pM\n", dbg_data, + dat_entry->mac_addr); + kfree(dbg_data); + } out: if (dat_entry) @@ -527,6 +569,7 @@ batadv_dat_select_candidates(struct batadv_priv *bat_priv, __be32 ip_dst) int select; batadv_dat_addr_t last_max = BATADV_DAT_ADDR_MAX, ip_key; struct batadv_dat_candidate *res; + char *dbg_data; if (!bat_priv->orig_hash) return NULL; @@ -538,9 +581,13 @@ batadv_dat_select_candidates(struct batadv_priv *bat_priv, __be32 ip_dst) ip_key = (batadv_dat_addr_t)batadv_hash_dat(&ip_dst, BATADV_DAT_ADDR_MAX); - batadv_dbg(BATADV_DBG_DAT, bat_priv, - "dat_select_candidates(): IP=%pI4 hash(IP)=%u\n", &ip_dst, - ip_key); + dbg_data = batadv_dat_data_to_str(&ip_dst, BATADV_DAT_IPV4); + if (dbg_data) { + batadv_dbg(BATADV_DBG_DAT, bat_priv, + "dat_select_candidates(): IP=%s hash(IP)=%u\n", + dbg_data, ip_key); + kfree(dbg_data); + } for (select = 0; select < BATADV_DAT_CANDIDATES_NUM; select++) batadv_choose_next_candidate(bat_priv, res, select, ip_key, @@ -572,12 +619,18 @@ static bool batadv_dat_send_data(struct batadv_priv *bat_priv, struct batadv_neigh_node *neigh_node = NULL; struct sk_buff *tmp_skb; struct batadv_dat_candidate *cand; + char *dbg_data; cand = batadv_dat_select_candidates(bat_priv, ip); if (!cand) goto out; - batadv_dbg(BATADV_DBG_DAT, bat_priv, "DHT_SEND for %pI4\n", &ip); + dbg_data = batadv_dat_data_to_str(&ip, BATADV_DAT_IPV4); + if (dbg_data) { + batadv_dbg(BATADV_DBG_DAT, bat_priv, + "DHT_SEND for %s\n", dbg_data); + kfree(dbg_data); + } for (i = 0; i < BATADV_DAT_CANDIDATES_NUM; i++) { if (cand[i].type == BATADV_DAT_CANDIDATE_NOT_FOUND) diff --git a/types.h b/types.h index b2c94e1..3488528 100644 --- a/types.h +++ b/types.h @@ -980,6 +980,14 @@ struct batadv_dat_entry { }; /** + * batadv_dat_types - types used in batadv_dat_entry for IP + * @BATADV_DAT_IPv4: IPv4 address type + */ +enum batadv_dat_types { + BATADV_DAT_IPV4, +}; + +/** * struct batadv_dat_candidate - candidate destination for DAT operations * @type: the type of the selected candidate. It can one of the following: * - BATADV_DAT_CANDIDATE_NOT_FOUND