Skip to content

Commit

Permalink
Merge tag 'batman-adv-for-davem' of git://git.open-mesh.org/linux-merge
Browse files Browse the repository at this point in the history
Antonio Quartulli says:

====================
pull request: batman-adv 20160504

In this pull request you have:
- two changes to the MAINTAINERS file where one marks our mailing list
  as moderated and the other adds a missing documentation file
- kernel-doc fixes
- code refactoring and various cleanups
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David S. Miller committed May 4, 2016
2 parents e98a3aa + 64ae744 commit 5332174
Show file tree
Hide file tree
Showing 18 changed files with 277 additions and 232 deletions.
5 changes: 4 additions & 1 deletion MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -2203,10 +2203,13 @@ BATMAN ADVANCED
M: Marek Lindner <mareklindner@neomailbox.ch>
M: Simon Wunderlich <sw@simonwunderlich.de>
M: Antonio Quartulli <a@unstable.cc>
L: b.a.t.m.a.n@lists.open-mesh.org
L: b.a.t.m.a.n@lists.open-mesh.org (moderated for non-subscribers)
W: https://www.open-mesh.org/
Q: https://patchwork.open-mesh.org/project/batman/list/
S: Maintained
F: Documentation/ABI/testing/sysfs-class-net-batman-adv
F: Documentation/ABI/testing/sysfs-class-net-mesh
F: Documentation/networking/batman-adv.txt
F: net/batman-adv/

BAYCOM/HDLCDRV DRIVERS FOR AX.25
Expand Down
123 changes: 79 additions & 44 deletions net/batman-adv/bat_iv_ogm.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <linux/jiffies.h>
#include <linux/list.h>
#include <linux/kref.h>
#include <linux/lockdep.h>
#include <linux/netdevice.h>
#include <linux/pkt_sched.h>
#include <linux/printk.h>
Expand Down Expand Up @@ -175,71 +176,107 @@ static int batadv_iv_ogm_orig_add_if(struct batadv_orig_node *orig_node,
}

/**
* batadv_iv_ogm_orig_del_if - change the private structures of the orig_node to
* exclude the removed interface
* batadv_iv_ogm_drop_bcast_own_entry - drop section of bcast_own
* @orig_node: the orig_node that has to be changed
* @max_if_num: the current amount of interfaces
* @del_if_num: the index of the interface being removed
*
* Return: 0 on success, a negative error code otherwise.
*/
static int batadv_iv_ogm_orig_del_if(struct batadv_orig_node *orig_node,
int max_if_num, int del_if_num)
static void
batadv_iv_ogm_drop_bcast_own_entry(struct batadv_orig_node *orig_node,
int max_if_num, int del_if_num)
{
int ret = -ENOMEM;
size_t chunk_size, if_offset;
void *data_ptr = NULL;

spin_lock_bh(&orig_node->bat_iv.ogm_cnt_lock);
size_t chunk_size;
size_t if_offset;
void *data_ptr;

/* last interface was removed */
if (max_if_num == 0)
goto free_bcast_own;
lockdep_assert_held(&orig_node->bat_iv.ogm_cnt_lock);

chunk_size = sizeof(unsigned long) * BATADV_NUM_WORDS;
data_ptr = kmalloc_array(max_if_num, chunk_size, GFP_ATOMIC);
if (!data_ptr)
goto unlock;
/* use old buffer when new one could not be allocated */
data_ptr = orig_node->bat_iv.bcast_own;

/* copy first part */
memcpy(data_ptr, orig_node->bat_iv.bcast_own, del_if_num * chunk_size);
memmove(data_ptr, orig_node->bat_iv.bcast_own, del_if_num * chunk_size);

/* copy second part */
if_offset = (del_if_num + 1) * chunk_size;
memcpy((char *)data_ptr + del_if_num * chunk_size,
(uint8_t *)orig_node->bat_iv.bcast_own + if_offset,
(max_if_num - del_if_num) * chunk_size);
memmove((char *)data_ptr + del_if_num * chunk_size,
(uint8_t *)orig_node->bat_iv.bcast_own + if_offset,
(max_if_num - del_if_num) * chunk_size);

free_bcast_own:
kfree(orig_node->bat_iv.bcast_own);
orig_node->bat_iv.bcast_own = data_ptr;
/* bcast_own was shrunk down in new buffer; free old one */
if (orig_node->bat_iv.bcast_own != data_ptr) {
kfree(orig_node->bat_iv.bcast_own);
orig_node->bat_iv.bcast_own = data_ptr;
}
}

/**
* batadv_iv_ogm_drop_bcast_own_sum_entry - drop section of bcast_own_sum
* @orig_node: the orig_node that has to be changed
* @max_if_num: the current amount of interfaces
* @del_if_num: the index of the interface being removed
*/
static void
batadv_iv_ogm_drop_bcast_own_sum_entry(struct batadv_orig_node *orig_node,
int max_if_num, int del_if_num)
{
size_t if_offset;
void *data_ptr;

if (max_if_num == 0)
goto free_own_sum;
lockdep_assert_held(&orig_node->bat_iv.ogm_cnt_lock);

data_ptr = kmalloc_array(max_if_num, sizeof(u8), GFP_ATOMIC);
if (!data_ptr) {
kfree(orig_node->bat_iv.bcast_own);
goto unlock;
}
if (!data_ptr)
/* use old buffer when new one could not be allocated */
data_ptr = orig_node->bat_iv.bcast_own_sum;

memcpy(data_ptr, orig_node->bat_iv.bcast_own_sum,
del_if_num * sizeof(u8));
memmove(data_ptr, orig_node->bat_iv.bcast_own_sum,
del_if_num * sizeof(u8));

if_offset = (del_if_num + 1) * sizeof(u8);
memcpy((char *)data_ptr + del_if_num * sizeof(u8),
orig_node->bat_iv.bcast_own_sum + if_offset,
(max_if_num - del_if_num) * sizeof(u8));
memmove((char *)data_ptr + del_if_num * sizeof(u8),
orig_node->bat_iv.bcast_own_sum + if_offset,
(max_if_num - del_if_num) * sizeof(u8));

/* bcast_own_sum was shrunk down in new buffer; free old one */
if (orig_node->bat_iv.bcast_own_sum != data_ptr) {
kfree(orig_node->bat_iv.bcast_own_sum);
orig_node->bat_iv.bcast_own_sum = data_ptr;
}
}

free_own_sum:
kfree(orig_node->bat_iv.bcast_own_sum);
orig_node->bat_iv.bcast_own_sum = data_ptr;
/**
* batadv_iv_ogm_orig_del_if - change the private structures of the orig_node to
* exclude the removed interface
* @orig_node: the orig_node that has to be changed
* @max_if_num: the current amount of interfaces
* @del_if_num: the index of the interface being removed
*
* Return: 0 on success, a negative error code otherwise.
*/
static int batadv_iv_ogm_orig_del_if(struct batadv_orig_node *orig_node,
int max_if_num, int del_if_num)
{
spin_lock_bh(&orig_node->bat_iv.ogm_cnt_lock);

if (max_if_num == 0) {
kfree(orig_node->bat_iv.bcast_own);
kfree(orig_node->bat_iv.bcast_own_sum);
orig_node->bat_iv.bcast_own = NULL;
orig_node->bat_iv.bcast_own_sum = NULL;
} else {
batadv_iv_ogm_drop_bcast_own_entry(orig_node, max_if_num,
del_if_num);
batadv_iv_ogm_drop_bcast_own_sum_entry(orig_node, max_if_num,
del_if_num);
}

ret = 0;
unlock:
spin_unlock_bh(&orig_node->bat_iv.ogm_cnt_lock);

return ret;
return 0;
}

/**
Expand Down Expand Up @@ -1829,9 +1866,8 @@ static void batadv_iv_ogm_orig_print(struct batadv_priv *bat_priv,
int batman_count = 0;
u32 i;

seq_printf(seq, " %-15s %s (%s/%i) %17s [%10s]: %20s ...\n",
"Originator", "last-seen", "#", BATADV_TQ_MAX_VALUE,
"Nexthop", "outgoingIF", "Potential nexthops");
seq_puts(seq,
" Originator last-seen (#/255) Nexthop [outgoingIF]: Potential nexthops ...\n");

for (i = 0; i < hash->size; i++) {
head = &hash->table[i];
Expand Down Expand Up @@ -1911,8 +1947,7 @@ static void batadv_iv_neigh_print(struct batadv_priv *bat_priv,
struct batadv_hard_iface *hard_iface;
int batman_count = 0;

seq_printf(seq, " %10s %-13s %s\n",
"IF", "Neighbor", "last-seen");
seq_puts(seq, " IF Neighbor last-seen\n");

rcu_read_lock();
list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) {
Expand Down
9 changes: 4 additions & 5 deletions net/batman-adv/bat_v.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ static void batadv_v_neigh_print(struct batadv_priv *bat_priv,
struct batadv_hard_iface *hard_iface;
int batman_count = 0;

seq_printf(seq, " %-15s %s (%11s) [%10s]\n", "Neighbor",
"last-seen", "throughput", "IF");
seq_puts(seq,
" Neighbor last-seen ( throughput) [ IF]\n");

rcu_read_lock();
list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) {
Expand Down Expand Up @@ -202,9 +202,8 @@ static void batadv_v_orig_print(struct batadv_priv *bat_priv,
int batman_count = 0;
u32 i;

seq_printf(seq, " %-15s %s (%11s) %17s [%10s]: %20s ...\n",
"Originator", "last-seen", "throughput", "Nexthop",
"outgoingIF", "Potential nexthops");
seq_puts(seq,
" Originator last-seen ( throughput) Nexthop [outgoingIF]: Potential nexthops ...\n");

for (i = 0; i < hash->size; i++) {
head = &hash->table[i];
Expand Down
Loading

0 comments on commit 5332174

Please sign in to comment.