[3/3] batman-adv: allowing changing the routing algorithm via sysfs

Message ID 1323078985-1116-4-git-send-email-lindner_marek@yahoo.de
State Superseded, archived
Headers

Commit Message

Marek Lindner Dec. 5, 2011, 9:56 a.m. UTC
  Signed-off-by: Marek Lindner <lindner_marek@yahoo.de>
---
 bat_sysfs.c          |   35 +++++++++++++++++++++++++++++++++++
 sysfs-class-net-mesh |    7 +++++++
 2 files changed, 42 insertions(+), 0 deletions(-)
  

Patch

diff --git a/bat_sysfs.c b/bat_sysfs.c
index c25492f..af8dd58 100644
--- a/bat_sysfs.c
+++ b/bat_sysfs.c
@@ -272,6 +272,39 @@  static ssize_t store_vis_mode(struct kobject *kobj, struct attribute *attr,
 	return count;
 }
 
+static ssize_t show_bat_algo(struct kobject *kobj, struct attribute *attr,
+			    char *buff)
+{
+	struct bat_priv *bat_priv = kobj_to_batpriv(kobj);
+	return sprintf(buff, "%s\n", bat_priv->bat_algo_ops->name);
+}
+
+static ssize_t store_bat_algo(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);
+	int ret;
+
+	if (buff[count - 1] == '\n')
+		buff[count - 1] = '\0';
+	else
+		buff[count] = '\0';
+
+	if (strcmp(bat_priv->bat_algo_ops->name, buff) == 0)
+		return count;
+
+	ret = bat_algo_select(bat_priv, buff);
+	if (ret < 0)
+		bat_info(net_dev,
+			 "Invalid parameter for 'routing algorithm' setting "
+			 "received: %s\n", buff);
+	else
+		bat_info(net_dev, "Changing routing algorithm to: %s\n", buff);
+
+	return count;
+}
+
 static void post_gw_deselect(struct net_device *net_dev)
 {
 	struct bat_priv *bat_priv = netdev_priv(net_dev);
@@ -382,6 +415,7 @@  BAT_ATTR_BOOL(bonding, S_IRUGO | S_IWUSR, NULL);
 BAT_ATTR_BOOL(fragmentation, S_IRUGO | S_IWUSR, update_min_mtu);
 BAT_ATTR_BOOL(ap_isolation, S_IRUGO | S_IWUSR, NULL);
 static BAT_ATTR(vis_mode, S_IRUGO | S_IWUSR, show_vis_mode, store_vis_mode);
+static BAT_ATTR(routing_algo, S_IRUGO | S_IWUSR, show_bat_algo, store_bat_algo);
 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);
@@ -399,6 +433,7 @@  static struct bat_attribute *mesh_attrs[] = {
 	&bat_attr_fragmentation,
 	&bat_attr_ap_isolation,
 	&bat_attr_vis_mode,
+	&bat_attr_routing_algo,
 	&bat_attr_gw_mode,
 	&bat_attr_orig_interval,
 	&bat_attr_hop_penalty,
diff --git a/sysfs-class-net-mesh b/sysfs-class-net-mesh
index b020014..b218e0f 100644
--- a/sysfs-class-net-mesh
+++ b/sysfs-class-net-mesh
@@ -65,6 +65,13 @@  Description:
 		Defines the penalty which will be applied to an
 		originator message's tq-field on every hop.
 
+What:		/sys/class/net/<mesh_iface>/mesh/routing_algo
+Date:		Dec 2011
+Contact:	Marek Lindner <lindner_marek@yahoo.de>
+Description:
+		Defines the routing procotol this mesh instance
+		uses to find the optimal paths through the mesh.
+
 What:           /sys/class/net/<mesh_iface>/mesh/vis_mode
 Date:           May 2010
 Contact:        Marek Lindner <lindner_marek@yahoo.de>