From patchwork Mon Jun 13 17:38:00 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Quartulli X-Patchwork-Id: 1170 Return-Path: Received: from contumacia.investici.org (contumacia.investici.org [178.255.144.35]) by open-mesh.org (Postfix) with ESMTPS id 11473154365 for ; Mon, 13 Jun 2011 19:38:09 +0200 (CEST) Authentication-Results: open-mesh.org; dkim=pass (1024-bit key) header.i=@autistici.org; dkim-adsp=pass Received: from [178.255.144.35] (contumacia [178.255.144.35]) (Authenticated sender: ordex@autistici.org) by localhost (Postfix) with ESMTPSA id 50EDFE80B6; Mon, 13 Jun 2011 17:38:08 +0000 (UTC) X-DKIM: Sendmail DKIM Filter v2.8.2 contumacia.investici.org 50EDFE80B6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org; s=stigmate; t=1307986688; bh=0MnOlZxdGXJzJSh/7zvbyjB1TuO+19xrYHJTpNHYUT0=; h=From:To:Cc:Subject:Date:Message-Id; b=DMgC/FBBViS7K5rmMj/w5QViVr4cOF6KqMoxqdZZdgXJsLvg3ZZGwK2mSBMJv/Xi5 ofruSrfhunE++CekJ6lY1WPhigDNQxauAUViq7RT2Vlm1XFlWxfYyVe9aeTssDNbAF mEwZau3RwYYzJwAh7X8pn9c0CBC1uNy3fvNKxrRA= From: Antonio Quartulli To: "B.A.T.M.A.N" Date: Mon, 13 Jun 2011 19:38:00 +0200 Message-Id: <1307986680-21113-1-git-send-email-ordex@autistici.org> X-Mailer: git-send-email 1.7.3.4 Subject: [B.A.T.M.A.N.] [PATCH] batman-adv: clean up the tt_query flags field 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, 13 Jun 2011 17:38:10 -0000 The tt_query subtype is represented by the two leading bits (lsb) of the tt_query->flags field. Therefore it cannot be handled by simple "flags" but by two bits wide integer. The TT_QUERY_TYPE_MASK is used to extract the relevant bits that can be compared to the related enum values (TT_RESPONSE, TT_REQUEST) Signed-off-by: Antonio Quartulli --- packet.h | 10 ++++++++-- routing.c | 30 ++++++++++++++++-------------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/packet.h b/packet.h index ef7476f..c5f081d 100644 --- a/packet.h +++ b/packet.h @@ -65,10 +65,16 @@ enum unicast_frag_flags { UNI_FRAG_LARGETAIL = 1 << 1 }; +/* TT_QUERY subtypes */ +#define TT_QUERY_TYPE_MASK 0x3 + +enum tt_query_packettype { + TT_REQUEST = 0, + TT_RESPONSE = 1 +}; + /* TT_QUERY flags */ enum tt_query_flags { - TT_RESPONSE = 1 << 0, - TT_REQUEST = 1 << 1, TT_FULL_TABLE = 1 << 2 }; diff --git a/routing.c b/routing.c index 7f458e9..027e988 100644 --- a/routing.c +++ b/routing.c @@ -1218,7 +1218,8 @@ int recv_tt_query(struct sk_buff *skb, struct hard_iface *recv_if) tt_query->tt_data = ntohs(tt_query->tt_data); - if (tt_query->flags & TT_REQUEST) { + switch (tt_query->flags & TT_QUERY_TYPE_MASK) { + case TT_REQUEST: /* If we cannot provide an answer the tt_request is * forwarded */ if (!send_tt_response(bat_priv, tt_query)) { @@ -1229,22 +1230,23 @@ int recv_tt_query(struct sk_buff *skb, struct hard_iface *recv_if) tt_query->tt_data = htons(tt_query->tt_data); return route_unicast_packet(skb, recv_if); } - ret = NET_RX_SUCCESS; - goto out; - } - /* packet needs to be linearised to access the TT changes records */ - if (skb_linearize(skb) < 0) - goto out; + break; + case TT_RESPONSE: + /* packet needs to be linearised to access the TT changes records */ + if (skb_linearize(skb) < 0) + goto out; - if (is_my_mac(tt_query->dst)) - handle_tt_response(bat_priv, tt_query); - else { - bat_dbg(DBG_TT, bat_priv, + if (is_my_mac(tt_query->dst)) + handle_tt_response(bat_priv, tt_query); + else { + bat_dbg(DBG_TT, bat_priv, "Routing TT_RESPONSE to %pM [%c]\n", tt_query->dst, (tt_query->flags & TT_FULL_TABLE ? 'F' : '.')); - tt_query->tt_data = htons(tt_query->tt_data); - return route_unicast_packet(skb, recv_if); + tt_query->tt_data = htons(tt_query->tt_data); + return route_unicast_packet(skb, recv_if); + } + break; } ret = NET_RX_SUCCESS;