From patchwork Mon May 9 09:52:23 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Quartulli X-Patchwork-Id: 1014 Return-Path: Received: from confino.investici.org (investici.nine.ch [217.150.252.179]) by open-mesh.org (Postfix) with ESMTPS id 11647154241 for ; Mon, 9 May 2011 11:52:29 +0200 (CEST) Authentication-Results: open-mesh.org; dkim=pass (1024-bit key) header.i=@autistici.org; dkim-adsp=pass Received: from [217.150.252.179] (confino [217.150.252.179]) (Authenticated sender: ordex@autistici.org) by localhost (Postfix) with ESMTPSA id 76CFA84442; Mon, 9 May 2011 09:52:28 +0000 (UTC) X-DKIM: Sendmail DKIM Filter v2.8.2 confino.investici.org 76CFA84442 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org; s=stigmate; t=1304934748; bh=vS18BeyVPGd1nBvBmYvHTLAxedSPJBuQrAbJYUpz0h0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=hVmeO8sjQ+LxsTNH6bj9AzRqlKyw0iLFSVA2sMcd9lcYHU7haMgp2ZR950MxtIUy6 UvpumgPjiV73TlWVJ0KJjAs6ScwwBlJIMVB32/WLNCMsblcyR+Q2GV/ybyAG0HKTB4 CJ+c435uShXKu6botvN4tLaJ2wW/UQnG2AkztpAs= From: Antonio Quartulli To: "B.A.T.M.A.N" Date: Mon, 9 May 2011 11:52:23 +0200 Message-Id: <1304934744-6599-2-git-send-email-ordex@autistici.org> X-Mailer: git-send-email 1.7.3.4 In-Reply-To: <1304579589-5222-1-git-send-email-ordex@autistici.org> References: <1304579589-5222-1-git-send-email-ordex@autistici.org> Subject: [B.A.T.M.A.N.] [PATCHv2 2/3] batman-adv: throw uevent in userspace on gateway add/change/del event X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.13 Precedence: list Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 09 May 2011 09:52:29 -0000 In case of new default gw, changing the default gw or deleting the default gw a uevent is triggered with type=gw, action=add/change/del and data={GW_ORIG_ADDRESS} (if any). The gateway election mechanism has been a little revised. Now the gw_election is trigered by an atomic_t flag (gw_reselect) which is is set to 1 in case of election needed, avoding to set curr_gw to NULL. Signed-off-by: Antonio Quartulli --- gateway_client.c | 31 ++++++++++++++++++++++++------- main.c | 1 + types.h | 1 + 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/gateway_client.c b/gateway_client.c index 65f3953..8a7090c 100644 --- a/gateway_client.c +++ b/gateway_client.c @@ -20,6 +20,7 @@ */ #include "main.h" +#include "bat_sysfs.h" #include "gateway_client.h" #include "gateway_common.h" #include "hard-interface.h" @@ -105,17 +106,18 @@ static void gw_select(struct bat_priv *bat_priv, struct gw_node *new_gw_node) void gw_deselect(struct bat_priv *bat_priv) { - gw_select(bat_priv, NULL); + atomic_set(&bat_priv->gw_reselect, 1); } void gw_election(struct bat_priv *bat_priv) { struct hlist_node *node; struct gw_node *gw_node, *curr_gw = NULL, *curr_gw_tmp = NULL; - struct neigh_node *router; + struct neigh_node *router = NULL; uint8_t max_tq = 0; uint32_t max_gw_factor = 0, tmp_gw_factor = 0; int down, up; + char gw_addr[18] = { '\0' }; /** * The batman daemon checks here if we already passed a full originator @@ -127,7 +129,7 @@ void gw_election(struct bat_priv *bat_priv) return; curr_gw = gw_get_selected_gw_node(bat_priv); - if (curr_gw) + if (!atomic_dec_not_zero(&bat_priv->gw_reselect)) goto out; rcu_read_lock(); @@ -186,9 +188,8 @@ void gw_election(struct bat_priv *bat_priv) } if (curr_gw != curr_gw_tmp) { - router = orig_node_get_router(curr_gw_tmp->orig_node); - if (!router) - goto unlock; + if (curr_gw_tmp) + router = orig_node_get_router(curr_gw_tmp->orig_node); if ((curr_gw) && (!curr_gw_tmp)) bat_dbg(DBG_BATMAN, bat_priv, @@ -209,8 +210,24 @@ void gw_election(struct bat_priv *bat_priv) curr_gw_tmp->orig_node->gw_flags, router->tq_avg); - neigh_node_free_ref(router); + if (router) + neigh_node_free_ref(router); gw_select(bat_priv, curr_gw_tmp); + rcu_read_unlock(); + + /* Throw the gateway event to the userspace */ + if (!curr_gw_tmp) { + throw_uevent(bat_priv, UEV_GW, UEV_DEL, NULL); + goto out; + } + + sprintf(gw_addr, "%pM", curr_gw_tmp->orig_node->orig); + + if (curr_gw) + throw_uevent(bat_priv, UEV_GW, UEV_CHANGE, gw_addr); + else + throw_uevent(bat_priv, UEV_GW, UEV_ADD, gw_addr); + goto out; } unlock: diff --git a/main.c b/main.c index 0a7cee0..ca060a9 100644 --- a/main.c +++ b/main.c @@ -111,6 +111,7 @@ int mesh_init(struct net_device *soft_iface) if (vis_init(bat_priv) < 1) goto err; + atomic_set(&bat_priv->gw_reselect, 0); atomic_set(&bat_priv->mesh_state, MESH_ACTIVE); goto end; diff --git a/types.h b/types.h index fab70e8..87b890e 100644 --- a/types.h +++ b/types.h @@ -173,6 +173,7 @@ struct bat_priv { struct delayed_work orig_work; struct delayed_work vis_work; struct gw_node __rcu *curr_gw; /* rcu protected pointer */ + atomic_t gw_reselect; struct hard_iface __rcu *primary_if; /* rcu protected pointer */ struct vis_info *my_vis_info; };