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:
- A fix for the network coding component which has been added within the last
  pull request (so it is in linux-3.10). The problem has been spotted thanks to
  Fengguang Wu's automated daily checks on our tree.
- Implementation of the RTNL API for virtual interface creation/deletion and slave
  manipulation
- substitution of seq_printf with seq_puts when possible
- minor cleanups

Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David S. Miller committed Mar 28, 2013
2 parents 9631d79 + 0c81465 commit ea407f0
Show file tree
Hide file tree
Showing 13 changed files with 268 additions and 120 deletions.
2 changes: 1 addition & 1 deletion net/batman-adv/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (C) 2007-2012 B.A.T.M.A.N. contributors:
# Copyright (C) 2007-2013 B.A.T.M.A.N. contributors:
#
# Marek Lindner, Simon Wunderlich
#
Expand Down
2 changes: 1 addition & 1 deletion net/batman-adv/gateway_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ int batadv_gw_client_seq_print_text(struct seq_file *seq, void *offset)
rcu_read_unlock();

if (gw_count == 0)
seq_printf(seq, "No gateways in range ...\n");
seq_puts(seq, "No gateways in range ...\n");

out:
if (primary_if)
Expand Down
66 changes: 54 additions & 12 deletions net/batman-adv/hard-interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,35 @@ batadv_hardif_deactivate_interface(struct batadv_hard_iface *hard_iface)
batadv_update_min_mtu(hard_iface->soft_iface);
}

/**
* batadv_master_del_slave - remove hard_iface from the current master interface
* @slave: the interface enslaved in another master
* @master: the master from which slave has to be removed
*
* Invoke ndo_del_slave on master passing slave as argument. In this way slave
* is free'd and master can correctly change its internal state.
* Return 0 on success, a negative value representing the error otherwise
*/
static int batadv_master_del_slave(struct batadv_hard_iface *slave,
struct net_device *master)
{
int ret;

if (!master)
return 0;

ret = -EBUSY;
if (master->netdev_ops->ndo_del_slave)
ret = master->netdev_ops->ndo_del_slave(master, slave->net_dev);

return ret;
}

int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
const char *iface_name)
{
struct batadv_priv *bat_priv;
struct net_device *soft_iface;
struct net_device *soft_iface, *master;
__be16 ethertype = __constant_htons(ETH_P_BATMAN);
int ret;

Expand All @@ -321,11 +345,6 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
if (!atomic_inc_not_zero(&hard_iface->refcount))
goto out;

/* hard-interface is part of a bridge */
if (hard_iface->net_dev->priv_flags & IFF_BRIDGE_PORT)
pr_err("You are about to enable batman-adv on '%s' which already is part of a bridge. Unless you know exactly what you are doing this is probably wrong and won't work the way you think it would.\n",
hard_iface->net_dev->name);

soft_iface = dev_get_by_name(&init_net, iface_name);

if (!soft_iface) {
Expand All @@ -347,12 +366,24 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
goto err_dev;
}

/* check if the interface is enslaved in another virtual one and
* in that case unlink it first
*/
master = netdev_master_upper_dev_get(hard_iface->net_dev);
ret = batadv_master_del_slave(hard_iface, master);
if (ret)
goto err_dev;

hard_iface->soft_iface = soft_iface;
bat_priv = netdev_priv(hard_iface->soft_iface);

ret = netdev_master_upper_dev_link(hard_iface->net_dev, soft_iface);
if (ret)
goto err_dev;

ret = bat_priv->bat_algo_ops->bat_iface_enable(hard_iface);
if (ret < 0)
goto err_dev;
goto err_upper;

hard_iface->if_num = bat_priv->num_ifaces;
bat_priv->num_ifaces++;
Expand All @@ -362,7 +393,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
bat_priv->bat_algo_ops->bat_iface_disable(hard_iface);
bat_priv->num_ifaces--;
hard_iface->if_status = BATADV_IF_NOT_IN_USE;
goto err_dev;
goto err_upper;
}

hard_iface->batman_adv_ptype.type = ethertype;
Expand Down Expand Up @@ -401,14 +432,18 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
out:
return 0;

err_upper:
netdev_upper_dev_unlink(hard_iface->net_dev, soft_iface);
err_dev:
hard_iface->soft_iface = NULL;
dev_put(soft_iface);
err:
batadv_hardif_free_ref(hard_iface);
return ret;
}

void batadv_hardif_disable_interface(struct batadv_hard_iface *hard_iface)
void batadv_hardif_disable_interface(struct batadv_hard_iface *hard_iface,
enum batadv_hard_if_cleanup autodel)
{
struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
struct batadv_hard_iface *primary_if = NULL;
Expand Down Expand Up @@ -446,9 +481,10 @@ void batadv_hardif_disable_interface(struct batadv_hard_iface *hard_iface)
dev_put(hard_iface->soft_iface);

/* nobody uses this interface anymore */
if (!bat_priv->num_ifaces)
batadv_softif_destroy(hard_iface->soft_iface);
if (!bat_priv->num_ifaces && autodel == BATADV_IF_CLEANUP_AUTO)
batadv_softif_destroy_sysfs(hard_iface->soft_iface);

netdev_upper_dev_unlink(hard_iface->net_dev, hard_iface->soft_iface);
hard_iface->soft_iface = NULL;
batadv_hardif_free_ref(hard_iface);

Expand Down Expand Up @@ -533,7 +569,8 @@ static void batadv_hardif_remove_interface(struct batadv_hard_iface *hard_iface)

/* first deactivate interface */
if (hard_iface->if_status != BATADV_IF_NOT_IN_USE)
batadv_hardif_disable_interface(hard_iface);
batadv_hardif_disable_interface(hard_iface,
BATADV_IF_CLEANUP_AUTO);

if (hard_iface->if_status != BATADV_IF_NOT_IN_USE)
return;
Expand Down Expand Up @@ -563,6 +600,11 @@ static int batadv_hard_if_event(struct notifier_block *this,
struct batadv_hard_iface *primary_if = NULL;
struct batadv_priv *bat_priv;

if (batadv_softif_is_valid(net_dev) && event == NETDEV_REGISTER) {
batadv_sysfs_add_meshif(net_dev);
return NOTIFY_DONE;
}

hard_iface = batadv_hardif_get_by_netdev(net_dev);
if (!hard_iface && event == NETDEV_REGISTER)
hard_iface = batadv_hardif_add_interface(net_dev);
Expand Down
13 changes: 12 additions & 1 deletion net/batman-adv/hard-interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,24 @@ enum batadv_hard_if_state {
BATADV_IF_I_WANT_YOU,
};

/**
* enum batadv_hard_if_cleanup - Cleanup modi for soft_iface after slave removal
* @BATADV_IF_CLEANUP_KEEP: Don't automatically delete soft-interface
* @BATADV_IF_CLEANUP_AUTO: Delete soft-interface after last slave was removed
*/
enum batadv_hard_if_cleanup {
BATADV_IF_CLEANUP_KEEP,
BATADV_IF_CLEANUP_AUTO,
};

extern struct notifier_block batadv_hard_if_notifier;

struct batadv_hard_iface*
batadv_hardif_get_by_netdev(const struct net_device *net_dev);
int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
const char *iface_name);
void batadv_hardif_disable_interface(struct batadv_hard_iface *hard_iface);
void batadv_hardif_disable_interface(struct batadv_hard_iface *hard_iface,
enum batadv_hard_if_cleanup autodel);
void batadv_hardif_remove_interfaces(void);
int batadv_hardif_min_mtu(struct net_device *soft_iface);
void batadv_update_min_mtu(struct net_device *soft_iface);
Expand Down
4 changes: 3 additions & 1 deletion net/batman-adv/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ static int __init batadv_init(void)
batadv_debugfs_init();

register_netdevice_notifier(&batadv_hard_if_notifier);
rtnl_link_register(&batadv_link_ops);

pr_info("B.A.T.M.A.N. advanced %s (compatibility version %i) loaded\n",
BATADV_SOURCE_VERSION, BATADV_COMPAT_VERSION);
Expand All @@ -81,6 +82,7 @@ static int __init batadv_init(void)
static void __exit batadv_exit(void)
{
batadv_debugfs_destroy();
rtnl_link_unregister(&batadv_link_ops);
unregister_netdevice_notifier(&batadv_hard_if_notifier);
batadv_hardif_remove_interfaces();

Expand Down Expand Up @@ -417,7 +419,7 @@ int batadv_algo_seq_print_text(struct seq_file *seq, void *offset)
{
struct batadv_algo_ops *bat_algo_ops;

seq_printf(seq, "Available routing algorithms:\n");
seq_puts(seq, "Available routing algorithms:\n");

hlist_for_each_entry(bat_algo_ops, &batadv_algo_list, list) {
seq_printf(seq, "%s\n", bat_algo_ops->name);
Expand Down
3 changes: 2 additions & 1 deletion net/batman-adv/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#define BATADV_DRIVER_DEVICE "batman-adv"

#ifndef BATADV_SOURCE_VERSION
#define BATADV_SOURCE_VERSION "2013.1.0"
#define BATADV_SOURCE_VERSION "2013.2.0"
#endif

/* B.A.T.M.A.N. parameters */
Expand Down Expand Up @@ -152,6 +152,7 @@ enum batadv_uev_type {
#include <linux/percpu.h>
#include <linux/slab.h>
#include <net/sock.h> /* struct sock */
#include <net/rtnetlink.h>
#include <linux/jiffies.h>
#include <linux/seq_file.h>
#include "types.h"
Expand Down
10 changes: 5 additions & 5 deletions net/batman-adv/network-coding.c
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ static bool batadv_can_nc_with_orig(struct batadv_priv *bat_priv,
struct batadv_orig_node *orig_node,
struct batadv_ogm_packet *ogm_packet)
{
if (orig_node->last_real_seqno != ogm_packet->seqno)
if (orig_node->last_real_seqno != ntohl(ogm_packet->seqno))
return false;
if (orig_node->last_ttl != ogm_packet->header.ttl + 1)
return false;
Expand Down Expand Up @@ -1760,23 +1760,23 @@ int batadv_nc_nodes_seq_print_text(struct seq_file *seq, void *offset)
hlist_for_each_entry_rcu(orig_node, head, hash_entry) {
seq_printf(seq, "Node: %pM\n", orig_node->orig);

seq_printf(seq, " Ingoing: ");
seq_puts(seq, " Ingoing: ");
/* For each in_nc_node to this orig_node */
list_for_each_entry_rcu(nc_node,
&orig_node->in_coding_list,
list)
seq_printf(seq, "%pM ",
nc_node->addr);
seq_printf(seq, "\n");
seq_puts(seq, "\n");

seq_printf(seq, " Outgoing: ");
seq_puts(seq, " Outgoing: ");
/* For out_nc_node to this orig_node */
list_for_each_entry_rcu(nc_node,
&orig_node->out_coding_list,
list)
seq_printf(seq, "%pM ",
nc_node->addr);
seq_printf(seq, "\n\n");
seq_puts(seq, "\n\n");
}
rcu_read_unlock();
}
Expand Down
4 changes: 2 additions & 2 deletions net/batman-adv/originator.c
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ int batadv_orig_seq_print_text(struct seq_file *seq, void *offset)
neigh_node_tmp->tq_avg);
}

seq_printf(seq, "\n");
seq_puts(seq, "\n");
batman_count++;

next:
Expand All @@ -475,7 +475,7 @@ int batadv_orig_seq_print_text(struct seq_file *seq, void *offset)
}

if (batman_count == 0)
seq_printf(seq, "No batman nodes in range ...\n");
seq_puts(seq, "No batman nodes in range ...\n");

out:
if (primary_if)
Expand Down
2 changes: 1 addition & 1 deletion net/batman-adv/packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ struct batadv_coded_packet {
uint8_t second_source[ETH_ALEN];
uint8_t second_orig_dest[ETH_ALEN];
__be32 second_crc;
uint16_t coded_len;
__be16 coded_len;
};

#endif /* _NET_BATMAN_ADV_PACKET_H_ */
Loading

0 comments on commit ea407f0

Please sign in to comment.