Skip to content

Commit

Permalink
Staging: batman-adv: adding gateway functionality
Browse files Browse the repository at this point in the history
Via the /sys filesystem you can change the gateway mode of a node using
gw_mode. Adjustments to it can be done using gw_bandwidth for server
mode and gw_sel_class for client mode.

Signed-off-by: Marek Lindner <lindner_marek@yahoo.de>
[sven.eckelmann@gmx.de: Rework on top of current version]
Signed-off-by: Sven Eckelmann <sven.eckelmann@gmx.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
  • Loading branch information
Marek Lindner authored and Greg Kroah-Hartman committed Nov 29, 2010
1 parent 7a18deb commit dfaf9dd
Show file tree
Hide file tree
Showing 15 changed files with 858 additions and 4 deletions.
19 changes: 18 additions & 1 deletion drivers/staging/batman-adv/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,21 @@
#

obj-$(CONFIG_BATMAN_ADV) += batman-adv.o
batman-adv-y := main.o bat_debugfs.o bat_sysfs.o send.o routing.o soft-interface.o icmp_socket.o translation-table.o bitarray.o hash.o ring_buffer.o vis.o hard-interface.o aggregation.o originator.o unicast.o
batman-adv-y += aggregation.o
batman-adv-y += bat_debugfs.o
batman-adv-y += bat_sysfs.o
batman-adv-y += bitarray.o
batman-adv-y += gateway_client.o
batman-adv-y += gateway_common.o
batman-adv-y += hard-interface.o
batman-adv-y += hash.o
batman-adv-y += icmp_socket.o
batman-adv-y += main.o
batman-adv-y += originator.o
batman-adv-y += ring_buffer.o
batman-adv-y += routing.o
batman-adv-y += send.o
batman-adv-y += soft-interface.o
batman-adv-y += translation-table.o
batman-adv-y += unicast.o
batman-adv-y += vis.o
10 changes: 10 additions & 0 deletions drivers/staging/batman-adv/bat_debugfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include "translation-table.h"
#include "originator.h"
#include "hard-interface.h"
#include "gateway_common.h"
#include "gateway_client.h"
#include "soft-interface.h"
#include "vis.h"
#include "icmp_socket.h"
Expand Down Expand Up @@ -226,6 +228,12 @@ static int originators_open(struct inode *inode, struct file *file)
return single_open(file, orig_seq_print_text, net_dev);
}

static int gateways_open(struct inode *inode, struct file *file)
{
struct net_device *net_dev = (struct net_device *)inode->i_private;
return single_open(file, gw_client_seq_print_text, net_dev);
}

static int softif_neigh_open(struct inode *inode, struct file *file)
{
struct net_device *net_dev = (struct net_device *)inode->i_private;
Expand Down Expand Up @@ -268,13 +276,15 @@ struct bat_debuginfo bat_debuginfo_##_name = { \
};

static BAT_DEBUGINFO(originators, S_IRUGO, originators_open);
static BAT_DEBUGINFO(gateways, S_IRUGO, gateways_open);
static BAT_DEBUGINFO(softif_neigh, S_IRUGO, softif_neigh_open);
static BAT_DEBUGINFO(transtable_global, S_IRUGO, transtable_global_open);
static BAT_DEBUGINFO(transtable_local, S_IRUGO, transtable_local_open);
static BAT_DEBUGINFO(vis_data, S_IRUGO, vis_data_open);

static struct bat_debuginfo *mesh_debuginfos[] = {
&bat_debuginfo_originators,
&bat_debuginfo_gateways,
&bat_debuginfo_softif_neigh,
&bat_debuginfo_transtable_global,
&bat_debuginfo_transtable_local,
Expand Down
115 changes: 115 additions & 0 deletions drivers/staging/batman-adv/bat_sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include "translation-table.h"
#include "originator.h"
#include "hard-interface.h"
#include "gateway_common.h"
#include "gateway_client.h"
#include "vis.h"

#define to_dev(obj) container_of(obj, struct device, kobj)
Expand Down Expand Up @@ -249,12 +251,122 @@ static ssize_t store_vis_mode(struct kobject *kobj, struct attribute *attr,
return count;
}

static void post_gw_deselect(struct net_device *net_dev)
{
struct bat_priv *bat_priv = netdev_priv(net_dev);
gw_deselect(bat_priv);
}

static ssize_t show_gw_mode(struct kobject *kobj, struct attribute *attr,
char *buff)
{
struct bat_priv *bat_priv = kobj_to_batpriv(kobj);
int bytes_written;

switch (atomic_read(&bat_priv->gw_mode)) {
case GW_MODE_CLIENT:
bytes_written = sprintf(buff, "%s\n", GW_MODE_CLIENT_NAME);
break;
case GW_MODE_SERVER:
bytes_written = sprintf(buff, "%s\n", GW_MODE_SERVER_NAME);
break;
default:
bytes_written = sprintf(buff, "%s\n", GW_MODE_OFF_NAME);
break;
}

return bytes_written;
}

static ssize_t store_gw_mode(struct kobject *kobj, struct attribute *attr,
char *buff, size_t count)
{
struct net_device *net_dev = kobj_to_netdev(kobj);
struct bat_priv *bat_priv = netdev_priv(net_dev);
char *curr_gw_mode_str;
int gw_mode_tmp = -1;

if (buff[count - 1] == '\n')
buff[count - 1] = '\0';

if (strncmp(buff, GW_MODE_OFF_NAME, strlen(GW_MODE_OFF_NAME)) == 0)
gw_mode_tmp = GW_MODE_OFF;

if (strncmp(buff, GW_MODE_CLIENT_NAME,
strlen(GW_MODE_CLIENT_NAME)) == 0)
gw_mode_tmp = GW_MODE_CLIENT;

if (strncmp(buff, GW_MODE_SERVER_NAME,
strlen(GW_MODE_SERVER_NAME)) == 0)
gw_mode_tmp = GW_MODE_SERVER;

if (gw_mode_tmp < 0) {
bat_info(net_dev,
"Invalid parameter for 'gw mode' setting received: "
"%s\n", buff);
return -EINVAL;
}

if (atomic_read(&bat_priv->gw_mode) == gw_mode_tmp)
return count;

switch (atomic_read(&bat_priv->gw_mode)) {
case GW_MODE_CLIENT:
curr_gw_mode_str = GW_MODE_CLIENT_NAME;
break;
case GW_MODE_SERVER:
curr_gw_mode_str = GW_MODE_SERVER_NAME;
break;
default:
curr_gw_mode_str = GW_MODE_OFF_NAME;
break;
}

bat_info(net_dev, "Changing gw mode from: %s to: %s\n",
curr_gw_mode_str, buff);

gw_deselect(bat_priv);
atomic_set(&bat_priv->gw_mode, (unsigned)gw_mode_tmp);
return count;
}

static ssize_t show_gw_bwidth(struct kobject *kobj, struct attribute *attr,
char *buff)
{
struct bat_priv *bat_priv = kobj_to_batpriv(kobj);
int down, up;
int gw_bandwidth = atomic_read(&bat_priv->gw_bandwidth);

gw_bandwidth_to_kbit(gw_bandwidth, &down, &up);
return sprintf(buff, "%i%s/%i%s\n",
(down > 2048 ? down / 1024 : down),
(down > 2048 ? "MBit" : "KBit"),
(up > 2048 ? up / 1024 : up),
(up > 2048 ? "MBit" : "KBit"));
}

static ssize_t store_gw_bwidth(struct kobject *kobj, struct attribute *attr,
char *buff, size_t count)
{
struct net_device *net_dev = kobj_to_netdev(kobj);

if (buff[count - 1] == '\n')
buff[count - 1] = '\0';

return gw_bandwidth_set(net_dev, buff, count);
}

BAT_ATTR_BOOL(aggregated_ogms, S_IRUGO | S_IWUSR, NULL);
BAT_ATTR_BOOL(bonding, S_IRUGO | S_IWUSR, NULL);
BAT_ATTR_BOOL(fragmentation, S_IRUGO | S_IWUSR, update_min_mtu);
static BAT_ATTR(vis_mode, S_IRUGO | S_IWUSR, show_vis_mode, store_vis_mode);
static BAT_ATTR(gw_mode, S_IRUGO | S_IWUSR, show_gw_mode, store_gw_mode);
BAT_ATTR_UINT(orig_interval, S_IRUGO | S_IWUSR, 2 * JITTER, INT_MAX, NULL);
BAT_ATTR_UINT(hop_penalty, S_IRUGO | S_IWUSR, 0, TQ_MAX_VALUE, NULL);
BAT_ATTR_UINT(gw_sel_class, S_IRUGO | S_IWUSR, 1, TQ_MAX_VALUE,
post_gw_deselect);
static BAT_ATTR(gw_bandwidth, S_IRUGO | S_IWUSR, show_gw_bwidth,
store_gw_bwidth);
#ifdef CONFIG_BATMAN_ADV_DEBUG
BAT_ATTR_UINT(log_level, S_IRUGO | S_IWUSR, 0, 3, NULL);
#endif
Expand All @@ -264,8 +376,11 @@ static struct bat_attribute *mesh_attrs[] = {
&bat_attr_bonding,
&bat_attr_fragmentation,
&bat_attr_vis_mode,
&bat_attr_gw_mode,
&bat_attr_orig_interval,
&bat_attr_hop_penalty,
&bat_attr_gw_sel_class,
&bat_attr_gw_bandwidth,
#ifdef CONFIG_BATMAN_ADV_DEBUG
&bat_attr_log_level,
#endif
Expand Down
Loading

0 comments on commit dfaf9dd

Please sign in to comment.