diff options
Diffstat (limited to 'drivers/staging/batman-adv/translation-table.c')
-rw-r--r-- | drivers/staging/batman-adv/translation-table.c | 92 |
1 files changed, 73 insertions, 19 deletions
diff --git a/drivers/staging/batman-adv/translation-table.c b/drivers/staging/batman-adv/translation-table.c index d56f6654de0d..e01ff2151f76 100644 --- a/drivers/staging/batman-adv/translation-table.c +++ b/drivers/staging/batman-adv/translation-table.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007-2009 B.A.T.M.A.N. contributors: + * Copyright (C) 2007-2010 B.A.T.M.A.N. contributors: * * Marek Lindner, Simon Wunderlich * @@ -77,11 +77,14 @@ void hna_local_add(uint8_t *addr) MAC-flooding. */ if ((num_hna + 1 > (ETH_DATA_LEN - BAT_PACKET_LEN) / ETH_ALEN) || (num_hna + 1 > 255)) { - bat_dbg(DBG_ROUTES, "Can't add new local hna entry (%pM): number of local hna entries exceeds packet size \n", addr); + bat_dbg(DBG_ROUTES, + "Can't add new local hna entry (%pM): " + "number of local hna entries exceeds packet size\n", + addr); return; } - bat_dbg(DBG_ROUTES, "Creating new local hna entry: %pM \n", + bat_dbg(DBG_ROUTES, "Creating new local hna entry: %pM\n", addr); hna_local_entry = kmalloc(sizeof(struct hna_local_entry), GFP_ATOMIC); @@ -108,7 +111,8 @@ void hna_local_add(uint8_t *addr) hna_local_hash->size * 2); if (swaphash == NULL) - printk(KERN_ERR "batman-adv:Couldn't resize local hna hash table \n"); + printk(KERN_ERR "batman-adv:" + "Couldn't resize local hna hash table\n"); else hna_local_hash = swaphash; } @@ -156,24 +160,49 @@ int hna_local_fill_buffer(unsigned char *buff, int buff_len) return i; } -int hna_local_fill_buffer_text(unsigned char *buff, int buff_len) +int hna_local_fill_buffer_text(struct net_device *net_dev, char *buff, + size_t count, loff_t off) { + struct bat_priv *bat_priv = netdev_priv(net_dev); struct hna_local_entry *hna_local_entry; HASHIT(hashit); int bytes_written = 0; unsigned long flags; + size_t hdr_len; + + if (!bat_priv->primary_if) { + if (off == 0) + return sprintf(buff, + "BATMAN mesh %s disabled - " + "please specify interfaces to enable it\n", + net_dev->name); + + return 0; + } + + hdr_len = sprintf(buff, + "Locally retrieved addresses (from %s) " + "announced via HNA:\n", + net_dev->name); + + if (off < hdr_len) + bytes_written = hdr_len; spin_lock_irqsave(&hna_local_hash_lock, flags); while (hash_iterate(hna_local_hash, &hashit)) { + hdr_len += 21; - if (buff_len < bytes_written + ETH_STR_LEN + 4) + if (count < bytes_written + 22) break; + if (off >= hdr_len) + continue; + hna_local_entry = hashit.bucket->data; - bytes_written += snprintf(buff + bytes_written, ETH_STR_LEN + 4, - " * %02x:%02x:%02x:%02x:%02x:%02x\n", + bytes_written += snprintf(buff + bytes_written, 22, + " * " MAC_FMT "\n", hna_local_entry->addr[0], hna_local_entry->addr[1], hna_local_entry->addr[2], @@ -183,7 +212,6 @@ int hna_local_fill_buffer_text(unsigned char *buff, int buff_len) } spin_unlock_irqrestore(&hna_local_hash_lock, flags); - return bytes_written; } @@ -197,7 +225,7 @@ static void _hna_local_del(void *data) static void hna_local_del(struct hna_local_entry *hna_local_entry, char *message) { - bat_dbg(DBG_ROUTES, "Deleting local hna entry (%pM): %s \n", + bat_dbg(DBG_ROUTES, "Deleting local hna entry (%pM): %s\n", hna_local_entry->addr, message); hash_remove(hna_local_hash, hna_local_entry->addr); @@ -295,7 +323,8 @@ void hna_global_add_orig(struct orig_node *orig_node, memcpy(hna_global_entry->addr, hna_ptr, ETH_ALEN); bat_dbg(DBG_ROUTES, - "Creating new global hna entry: %pM (via %pM)\n", + "Creating new global hna entry: " + "%pM (via %pM)\n", hna_global_entry->addr, orig_node->orig); spin_lock_irqsave(&hna_global_hash_lock, flags); @@ -340,7 +369,8 @@ void hna_global_add_orig(struct orig_node *orig_node, hna_global_hash->size * 2); if (swaphash == NULL) - printk(KERN_ERR "batman-adv:Couldn't resize global hna hash table \n"); + printk(KERN_ERR "batman-adv:" + "Couldn't resize global hna hash table\n"); else hna_global_hash = swaphash; } @@ -348,24 +378,49 @@ void hna_global_add_orig(struct orig_node *orig_node, spin_unlock_irqrestore(&hna_global_hash_lock, flags); } -int hna_global_fill_buffer_text(unsigned char *buff, int buff_len) +int hna_global_fill_buffer_text(struct net_device *net_dev, char *buff, + size_t count, loff_t off) { + struct bat_priv *bat_priv = netdev_priv(net_dev); struct hna_global_entry *hna_global_entry; HASHIT(hashit); int bytes_written = 0; unsigned long flags; + size_t hdr_len; + + if (!bat_priv->primary_if) { + if (off == 0) + return sprintf(buff, + "BATMAN mesh %s disabled - " + "please specify interfaces to enable it\n", + net_dev->name); + + return 0; + } + + hdr_len = sprintf(buff, + "Globally announced HNAs received via the mesh %s " + "(translation table):\n", + net_dev->name); + + if (off < hdr_len) + bytes_written = hdr_len; spin_lock_irqsave(&hna_global_hash_lock, flags); while (hash_iterate(hna_global_hash, &hashit)) { - if (buff_len < bytes_written + (2 * ETH_STR_LEN) + 10) + hdr_len += 43; + + if (count < bytes_written + 44) break; + if (off >= hdr_len) + continue; + hna_global_entry = hashit.bucket->data; - bytes_written += snprintf(buff + bytes_written, - (2 * ETH_STR_LEN) + 10, - " * %02x:%02x:%02x:%02x:%02x:%02x via %02x:%02x:%02x:%02x:%02x:%02x \n", + bytes_written += snprintf(buff + bytes_written, 44, + " * " MAC_FMT " via " MAC_FMT "\n", hna_global_entry->addr[0], hna_global_entry->addr[1], hna_global_entry->addr[2], @@ -381,14 +436,13 @@ int hna_global_fill_buffer_text(unsigned char *buff, int buff_len) } spin_unlock_irqrestore(&hna_global_hash_lock, flags); - return bytes_written; } void _hna_global_del_orig(struct hna_global_entry *hna_global_entry, char *message) { - bat_dbg(DBG_ROUTES, "Deleting global hna entry %pM (via %pM): %s \n", + bat_dbg(DBG_ROUTES, "Deleting global hna entry %pM (via %pM): %s\n", hna_global_entry->addr, hna_global_entry->orig_node->orig, message); |