b.a.t.m.a.n.lists.open-mesh.org archive mirror
 help / color / mirror / Atom feed
From: Marek Lindner <lindner_marek@yahoo.de>
To: b.a.t.m.a.n@lists.open-mesh.org
Cc: Marek Lindner <lindner_marek@yahoo.de>
Subject: [B.A.T.M.A.N.] [PATCH 3/8] batman-adv: move gateway selection class into its own sysfs file
Date: Thu,  4 Nov 2010 18:21:00 +0100	[thread overview]
Message-ID: <1288891265-16035-3-git-send-email-lindner_marek@yahoo.de> (raw)
In-Reply-To: <201011041820.44518.lindner_marek@yahoo.de>

The Linux kernel guidelines require each sysfs file to have a single
value / purpose, therefore it is necessary to split up the sysfs
gateway files.

Signed-off-by: Marek Lindner <lindner_marek@yahoo.de>
---
 batman-adv/bat_sysfs.c      |   10 ++++++++++
 batman-adv/gateway_client.c |    6 +++---
 batman-adv/gateway_common.c |    5 ++++-
 batman-adv/routing.c        |    5 ++++-
 batman-adv/soft-interface.c |    1 +
 batman-adv/types.h          |    1 +
 6 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/batman-adv/bat_sysfs.c b/batman-adv/bat_sysfs.c
index 8e3dbef..0f39213 100644
--- a/batman-adv/bat_sysfs.c
+++ b/batman-adv/bat_sysfs.c
@@ -251,6 +251,12 @@ 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)
 {
@@ -261,6 +267,7 @@ static ssize_t show_gw_mode(struct kobject *kobj, struct attribute *attr,
 
 	switch (gw_mode) {
 	case GW_MODE_CLIENT:
+		gw_class = atomic_read(&bat_priv->gw_sel_class);
 		bytes_written = sprintf(buff, "%s (gw_class: %i)\n",
 					GW_MODE_CLIENT_NAME, gw_class);
 		break;
@@ -298,6 +305,8 @@ 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);
 #ifdef CONFIG_BATMAN_ADV_DEBUG
 BAT_ATTR_UINT(log_level, S_IRUGO | S_IWUSR, 0, 3, NULL);
 #endif
@@ -310,6 +319,7 @@ static struct bat_attribute *mesh_attrs[] = {
 	&bat_attr_gw_mode,
 	&bat_attr_orig_interval,
 	&bat_attr_hop_penalty,
+	&bat_attr_gw_sel_class,
 #ifdef CONFIG_BATMAN_ADV_DEBUG
 	&bat_attr_log_level,
 #endif
diff --git a/batman-adv/gateway_client.c b/batman-adv/gateway_client.c
index 2e05dd4..56c52b0 100644
--- a/batman-adv/gateway_client.c
+++ b/batman-adv/gateway_client.c
@@ -116,7 +116,7 @@ void gw_election(struct bat_priv *bat_priv)
 		if (gw_node->deleted)
 			continue;
 
-		switch (atomic_read(&bat_priv->gw_class)) {
+		switch (atomic_read(&bat_priv->gw_sel_class)) {
 		case 1: /* fast connection */
 			gw_srv_class_to_kbit(gw_node->orig_node->gw_flags,
 					     &down, &up);
@@ -215,8 +215,8 @@ void gw_check_election(struct bat_priv *bat_priv, struct orig_node *orig_node)
 	 * if the routing class is greater than 3 the value tells us how much
 	 * greater the TQ value of the new gateway must be
 	 **/
-	if ((atomic_read(&bat_priv->gw_class) > 3) &&
-	    (orig_tq_avg - gw_tq_avg < atomic_read(&bat_priv->gw_class)))
+	if ((atomic_read(&bat_priv->gw_sel_class) > 3) &&
+	    (orig_tq_avg - gw_tq_avg < atomic_read(&bat_priv->gw_sel_class)))
 		return;
 
 	bat_dbg(DBG_BATMAN, bat_priv,
diff --git a/batman-adv/gateway_common.c b/batman-adv/gateway_common.c
index a88ce41..330167e 100644
--- a/batman-adv/gateway_common.c
+++ b/batman-adv/gateway_common.c
@@ -236,12 +236,15 @@ next:
 
 	switch (gw_mode_tmp) {
 	case GW_MODE_CLIENT:
+		gw_class_tmp = atomic_read(&bat_priv->gw_sel_class);
 		if ((gw_mode_tmp == GW_MODE_CLIENT) && (!gw_class_tmp))
 			gw_class_tmp = 20;
 
 		bat_info(net_dev, "Changing gateway mode from: '%s' to: '%s' "
-			 "(gw_class: %ld)\n",
+			 "(gw_sel_class: %ld)\n",
 			 gw_mode_curr_str, gw_mode_tmp_str, gw_class_tmp);
+
+		atomic_set(&bat_priv->gw_sel_class, gw_class_tmp);
 		break;
 	case GW_MODE_SERVER:
 		if (!down)
diff --git a/batman-adv/routing.c b/batman-adv/routing.c
index e75337d..9f31167 100644
--- a/batman-adv/routing.c
+++ b/batman-adv/routing.c
@@ -32,6 +32,7 @@
 #include "ring_buffer.h"
 #include "vis.h"
 #include "aggregation.h"
+#include "gateway_common.h"
 #include "gateway_client.h"
 #include "unicast.h"
 
@@ -330,7 +331,9 @@ update_gw:
 	orig_node->gw_flags = batman_packet->gw_flags;
 
 	/* restart gateway selection if fast or late switching was enabled */
-	if ((orig_node->gw_flags) && (atomic_read(&bat_priv->gw_class) > 2))
+	if ((orig_node->gw_flags) &&
+	    (atomic_read(&bat_priv->gw_mode) == GW_MODE_CLIENT) &&
+	    (atomic_read(&bat_priv->gw_sel_class) > 2))
 		gw_check_election(bat_priv, orig_node);
 }
 
diff --git a/batman-adv/soft-interface.c b/batman-adv/soft-interface.c
index 836c452..7b2673c 100644
--- a/batman-adv/soft-interface.c
+++ b/batman-adv/soft-interface.c
@@ -591,6 +591,7 @@ struct net_device *softif_create(char *name)
 	atomic_set(&bat_priv->bonding, 0);
 	atomic_set(&bat_priv->vis_mode, VIS_TYPE_CLIENT_UPDATE);
 	atomic_set(&bat_priv->gw_mode, GW_MODE_OFF);
+	atomic_set(&bat_priv->gw_sel_class, 0);
 	atomic_set(&bat_priv->gw_class, 0);
 	atomic_set(&bat_priv->orig_interval, 1000);
 	atomic_set(&bat_priv->hop_penalty, 10);
diff --git a/batman-adv/types.h b/batman-adv/types.h
index 2678ce1..b68add4 100644
--- a/batman-adv/types.h
+++ b/batman-adv/types.h
@@ -128,6 +128,7 @@ struct bat_priv {
 	atomic_t fragmentation;		/* boolean */
 	atomic_t vis_mode;		/* VIS_TYPE_* */
 	atomic_t gw_mode;		/* GW_MODE_* */
+	atomic_t gw_sel_class;		/* uint */
 	atomic_t gw_class;		/* uint */
 	atomic_t orig_interval;		/* uint */
 	atomic_t hop_penalty;		/* uint */
-- 
1.7.1


  parent reply	other threads:[~2010-11-04 17:21 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-04 17:20 [B.A.T.M.A.N.] batman-adv gateway handling [v2] Marek Lindner
2010-11-04 17:20 ` [B.A.T.M.A.N.] [PATCH 1/8] batman-adv: remove redundant gw_node_list_free() function Marek Lindner
2010-11-04 17:20 ` [B.A.T.M.A.N.] [PATCH 2/8] batman-adv: gateways silently drop DHCP requests Marek Lindner
2010-11-04 17:21 ` Marek Lindner [this message]
2010-11-04 17:21 ` [B.A.T.M.A.N.] [PATCH 4/8] batman-adv: move gateway bandwidth into its own sysfs file Marek Lindner
2010-11-04 17:21 ` [B.A.T.M.A.N.] [PATCH 5/8] batman-adv: cleanup gw mode sysfs file to only accept one value Marek Lindner
2010-11-04 17:21 ` [B.A.T.M.A.N.] [PATCH 6/8] batctl: support new gateway sysfs API Marek Lindner
2010-11-04 17:21 ` [B.A.T.M.A.N.] [PATCH 7/8] batman-adv: document gateway sysfs ABI Marek Lindner
2010-11-04 17:21 ` [B.A.T.M.A.N.] [PATCH 8/8] batman-adv: add gateway IPv6 support by filtering DHCPv6 messages Marek Lindner
2010-11-07 12:56 ` [B.A.T.M.A.N.] batman-adv gateway handling [v2] Marek Lindner
  -- strict thread matches above, loose matches on Subject: below --
2010-10-24  1:13 [B.A.T.M.A.N.] batman-adv gateway handling Marek Lindner
2010-10-24  1:14 ` [B.A.T.M.A.N.] [PATCH 3/8] batman-adv: move gateway selection class into its own sysfs file Marek Lindner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1288891265-16035-3-git-send-email-lindner_marek@yahoo.de \
    --to=lindner_marek@yahoo.de \
    --cc=b.a.t.m.a.n@lists.open-mesh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).