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
included changes:
- some code cleanups and minor fixes (3 of them were reported by Coverity)
- 'struct hard_iface' re-shaping to improve multi-protocol support
- ECTP packets silent drop
- transfer the WIFI flag on clients in case of roaming
  • Loading branch information
David S. Miller committed Oct 31, 2012
2 parents 1627801 + 0aca86c commit 1570838
Show file tree
Hide file tree
Showing 16 changed files with 238 additions and 247 deletions.
43 changes: 24 additions & 19 deletions net/batman-adv/bat_iv_ogm.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,22 @@ batadv_iv_ogm_neigh_new(struct batadv_hard_iface *hard_iface,
static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
{
struct batadv_ogm_packet *batadv_ogm_packet;
unsigned char *ogm_buff;
uint32_t random_seqno;
int res = -ENOMEM;

/* randomize initial seqno to avoid collision */
get_random_bytes(&random_seqno, sizeof(random_seqno));
atomic_set(&hard_iface->seqno, random_seqno);
atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);

hard_iface->packet_len = BATADV_OGM_HLEN;
hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC);

if (!hard_iface->packet_buff)
hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
if (!ogm_buff)
goto out;

batadv_ogm_packet = (struct batadv_ogm_packet *)hard_iface->packet_buff;
hard_iface->bat_iv.ogm_buff = ogm_buff;

batadv_ogm_packet = (struct batadv_ogm_packet *)ogm_buff;
batadv_ogm_packet->header.packet_type = BATADV_IV_OGM;
batadv_ogm_packet->header.version = BATADV_COMPAT_VERSION;
batadv_ogm_packet->header.ttl = 2;
Expand All @@ -87,15 +89,16 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)

static void batadv_iv_ogm_iface_disable(struct batadv_hard_iface *hard_iface)
{
kfree(hard_iface->packet_buff);
hard_iface->packet_buff = NULL;
kfree(hard_iface->bat_iv.ogm_buff);
hard_iface->bat_iv.ogm_buff = NULL;
}

static void batadv_iv_ogm_iface_update_mac(struct batadv_hard_iface *hard_iface)
{
struct batadv_ogm_packet *batadv_ogm_packet;
unsigned char *ogm_buff = hard_iface->bat_iv.ogm_buff;

batadv_ogm_packet = (struct batadv_ogm_packet *)hard_iface->packet_buff;
batadv_ogm_packet = (struct batadv_ogm_packet *)ogm_buff;
memcpy(batadv_ogm_packet->orig,
hard_iface->net_dev->dev_addr, ETH_ALEN);
memcpy(batadv_ogm_packet->prev_sender,
Expand All @@ -106,8 +109,9 @@ static void
batadv_iv_ogm_primary_iface_set(struct batadv_hard_iface *hard_iface)
{
struct batadv_ogm_packet *batadv_ogm_packet;
unsigned char *ogm_buff = hard_iface->bat_iv.ogm_buff;

batadv_ogm_packet = (struct batadv_ogm_packet *)hard_iface->packet_buff;
batadv_ogm_packet = (struct batadv_ogm_packet *)ogm_buff;
batadv_ogm_packet->flags = BATADV_PRIMARIES_FIRST_HOP;
batadv_ogm_packet->header.ttl = BATADV_TTL;
}
Expand Down Expand Up @@ -590,8 +594,10 @@ static void batadv_iv_ogm_forward(struct batadv_orig_node *orig_node,
static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
{
struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
unsigned char **ogm_buff = &hard_iface->bat_iv.ogm_buff;
struct batadv_ogm_packet *batadv_ogm_packet;
struct batadv_hard_iface *primary_if;
int *ogm_buff_len = &hard_iface->bat_iv.ogm_buff_len;
int vis_server, tt_num_changes = 0;
uint32_t seqno;
uint8_t bandwidth;
Expand All @@ -600,17 +606,16 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
primary_if = batadv_primary_if_get_selected(bat_priv);

if (hard_iface == primary_if)
tt_num_changes = batadv_tt_append_diff(bat_priv,
&hard_iface->packet_buff,
&hard_iface->packet_len,
tt_num_changes = batadv_tt_append_diff(bat_priv, ogm_buff,
ogm_buff_len,
BATADV_OGM_HLEN);

batadv_ogm_packet = (struct batadv_ogm_packet *)hard_iface->packet_buff;
batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff);

/* change sequence number to network order */
seqno = (uint32_t)atomic_read(&hard_iface->seqno);
seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
batadv_ogm_packet->seqno = htonl(seqno);
atomic_inc(&hard_iface->seqno);
atomic_inc(&hard_iface->bat_iv.ogm_seqno);

batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
Expand All @@ -631,8 +636,8 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
}

batadv_slide_own_bcast_window(hard_iface);
batadv_iv_ogm_queue_add(bat_priv, hard_iface->packet_buff,
hard_iface->packet_len, hard_iface, 1,
batadv_iv_ogm_queue_add(bat_priv, hard_iface->bat_iv.ogm_buff,
hard_iface->bat_iv.ogm_buff_len, hard_iface, 1,
batadv_iv_ogm_emit_send_time(bat_priv));

if (primary_if)
Expand Down Expand Up @@ -1015,7 +1020,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
return;

/* could be changed by schedule_own_packet() */
if_incoming_seqno = atomic_read(&if_incoming->seqno);
if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);

if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
has_directlink_flag = 1;
Expand Down
23 changes: 10 additions & 13 deletions net/batman-adv/bitarray.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,17 @@ int batadv_bit_get_packet(void *priv, unsigned long *seq_bits,
* or the old packet got delayed somewhere in the network. The
* packet should be dropped without calling this function if the
* seqno window is protected.
*
* seq_num_diff <= -BATADV_TQ_LOCAL_WINDOW_SIZE
* or
* seq_num_diff >= BATADV_EXPECTED_SEQNO_RANGE
*/
if (seq_num_diff <= -BATADV_TQ_LOCAL_WINDOW_SIZE ||
seq_num_diff >= BATADV_EXPECTED_SEQNO_RANGE) {
batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
"Other host probably restarted!\n");

batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
"Other host probably restarted!\n");

bitmap_zero(seq_bits, BATADV_TQ_LOCAL_WINDOW_SIZE);
if (set_mark)
batadv_set_bit(seq_bits, 0);

return 1;
}
bitmap_zero(seq_bits, BATADV_TQ_LOCAL_WINDOW_SIZE);
if (set_mark)
batadv_set_bit(seq_bits, 0);

/* never reached */
return 0;
return 1;
}
36 changes: 6 additions & 30 deletions net/batman-adv/bridge_loop_avoidance.c
Original file line number Diff line number Diff line change
Expand Up @@ -1585,23 +1585,11 @@ int batadv_bla_claim_table_seq_print_text(struct seq_file *seq, void *offset)
struct hlist_head *head;
uint32_t i;
bool is_own;
int ret = 0;
uint8_t *primary_addr;

primary_if = batadv_primary_if_get_selected(bat_priv);
if (!primary_if) {
ret = seq_printf(seq,
"BATMAN mesh %s disabled - please specify interfaces to enable it\n",
net_dev->name);
goto out;
}

if (primary_if->if_status != BATADV_IF_ACTIVE) {
ret = seq_printf(seq,
"BATMAN mesh %s disabled - primary interface not active\n",
net_dev->name);
primary_if = batadv_seq_print_text_primary_if_get(seq);
if (!primary_if)
goto out;
}

primary_addr = primary_if->net_dev->dev_addr;
seq_printf(seq,
Expand All @@ -1628,7 +1616,7 @@ int batadv_bla_claim_table_seq_print_text(struct seq_file *seq, void *offset)
out:
if (primary_if)
batadv_hardif_free_ref(primary_if);
return ret;
return 0;
}

int batadv_bla_backbone_table_seq_print_text(struct seq_file *seq, void *offset)
Expand All @@ -1643,23 +1631,11 @@ int batadv_bla_backbone_table_seq_print_text(struct seq_file *seq, void *offset)
int secs, msecs;
uint32_t i;
bool is_own;
int ret = 0;
uint8_t *primary_addr;

primary_if = batadv_primary_if_get_selected(bat_priv);
if (!primary_if) {
ret = seq_printf(seq,
"BATMAN mesh %s disabled - please specify interfaces to enable it\n",
net_dev->name);
goto out;
}

if (primary_if->if_status != BATADV_IF_ACTIVE) {
ret = seq_printf(seq,
"BATMAN mesh %s disabled - primary interface not active\n",
net_dev->name);
primary_if = batadv_seq_print_text_primary_if_get(seq);
if (!primary_if)
goto out;
}

primary_addr = primary_if->net_dev->dev_addr;
seq_printf(seq,
Expand Down Expand Up @@ -1693,5 +1669,5 @@ int batadv_bla_backbone_table_seq_print_text(struct seq_file *seq, void *offset)
out:
if (primary_if)
batadv_hardif_free_ref(primary_if);
return ret;
return 0;
}
6 changes: 4 additions & 2 deletions net/batman-adv/debugfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,17 @@ int batadv_debug_log(struct batadv_priv *bat_priv, const char *fmt, ...)

static int batadv_log_open(struct inode *inode, struct file *file)
{
if (!try_module_get(THIS_MODULE))
return -EBUSY;

nonseekable_open(inode, file);
file->private_data = inode->i_private;
batadv_inc_module_count();
return 0;
}

static int batadv_log_release(struct inode *inode, struct file *file)
{
batadv_dec_module_count();
module_put(THIS_MODULE);
return 0;
}

Expand Down
19 changes: 4 additions & 15 deletions net/batman-adv/gateway_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -477,22 +477,11 @@ int batadv_gw_client_seq_print_text(struct seq_file *seq, void *offset)
struct batadv_hard_iface *primary_if;
struct batadv_gw_node *gw_node;
struct hlist_node *node;
int gw_count = 0, ret = 0;
int gw_count = 0;

primary_if = batadv_primary_if_get_selected(bat_priv);
if (!primary_if) {
ret = seq_printf(seq,
"BATMAN mesh %s disabled - please specify interfaces to enable it\n",
net_dev->name);
primary_if = batadv_seq_print_text_primary_if_get(seq);
if (!primary_if)
goto out;
}

if (primary_if->if_status != BATADV_IF_ACTIVE) {
ret = seq_printf(seq,
"BATMAN mesh %s disabled - primary interface not active\n",
net_dev->name);
goto out;
}

seq_printf(seq,
" %-12s (%s/%i) %17s [%10s]: gw_class ... [B.A.T.M.A.N. adv %s, MainIF/MAC: %s/%pM (%s)]\n",
Expand All @@ -519,7 +508,7 @@ int batadv_gw_client_seq_print_text(struct seq_file *seq, void *offset)
out:
if (primary_if)
batadv_hardif_free_ref(primary_if);
return ret;
return 0;
}

static bool batadv_is_type_dhcprequest(struct sk_buff *skb, int header_len)
Expand Down
4 changes: 2 additions & 2 deletions net/batman-adv/hard-interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,8 @@ batadv_hardif_add_interface(struct net_device *net_dev)
/* This can't be called via a bat_priv callback because
* we have no bat_priv yet.
*/
atomic_set(&hard_iface->seqno, 1);
hard_iface->packet_buff = NULL;
atomic_set(&hard_iface->bat_iv.ogm_seqno, 1);
hard_iface->bat_iv.ogm_buff = NULL;

return hard_iface;

Expand Down
12 changes: 8 additions & 4 deletions net/batman-adv/icmp_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,16 @@ static int batadv_socket_open(struct inode *inode, struct file *file)
unsigned int i;
struct batadv_socket_client *socket_client;

if (!try_module_get(THIS_MODULE))
return -EBUSY;

nonseekable_open(inode, file);

socket_client = kmalloc(sizeof(*socket_client), GFP_KERNEL);

if (!socket_client)
if (!socket_client) {
module_put(THIS_MODULE);
return -ENOMEM;
}

for (i = 0; i < ARRAY_SIZE(batadv_socket_client_hash); i++) {
if (!batadv_socket_client_hash[i]) {
Expand All @@ -59,6 +63,7 @@ static int batadv_socket_open(struct inode *inode, struct file *file)
if (i == ARRAY_SIZE(batadv_socket_client_hash)) {
pr_err("Error - can't add another packet client: maximum number of clients reached\n");
kfree(socket_client);
module_put(THIS_MODULE);
return -EXFULL;
}

Expand All @@ -71,7 +76,6 @@ static int batadv_socket_open(struct inode *inode, struct file *file)

file->private_data = socket_client;

batadv_inc_module_count();
return 0;
}

Expand All @@ -96,7 +100,7 @@ static int batadv_socket_release(struct inode *inode, struct file *file)
spin_unlock_bh(&socket_client->lock);

kfree(socket_client);
batadv_dec_module_count();
module_put(THIS_MODULE);

return 0;
}
Expand Down
46 changes: 36 additions & 10 deletions net/batman-adv/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,6 @@ void batadv_mesh_free(struct net_device *soft_iface)
atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
}

void batadv_inc_module_count(void)
{
try_module_get(THIS_MODULE);
}

void batadv_dec_module_count(void)
{
module_put(THIS_MODULE);
}

int batadv_is_my_mac(const uint8_t *addr)
{
const struct batadv_hard_iface *hard_iface;
Expand All @@ -188,6 +178,42 @@ int batadv_is_my_mac(const uint8_t *addr)
return 0;
}

/**
* batadv_seq_print_text_primary_if_get - called from debugfs table printing
* function that requires the primary interface
* @seq: debugfs table seq_file struct
*
* Returns primary interface if found or NULL otherwise.
*/
struct batadv_hard_iface *
batadv_seq_print_text_primary_if_get(struct seq_file *seq)
{
struct net_device *net_dev = (struct net_device *)seq->private;
struct batadv_priv *bat_priv = netdev_priv(net_dev);
struct batadv_hard_iface *primary_if;

primary_if = batadv_primary_if_get_selected(bat_priv);

if (!primary_if) {
seq_printf(seq,
"BATMAN mesh %s disabled - please specify interfaces to enable it\n",
net_dev->name);
goto out;
}

if (primary_if->if_status == BATADV_IF_ACTIVE)
goto out;

seq_printf(seq,
"BATMAN mesh %s disabled - primary interface not active\n",
net_dev->name);
batadv_hardif_free_ref(primary_if);
primary_if = NULL;

out:
return primary_if;
}

static int batadv_recv_unhandled_packet(struct sk_buff *skb,
struct batadv_hard_iface *recv_if)
{
Expand Down
Loading

0 comments on commit 1570838

Please sign in to comment.