From: Markus Pargmann <mpa@pengutronix.de>
To: Marek Lindner <mareklindner@neomailbox.ch>,
Simon Wunderlich <sw@simonwunderlich.de>,
Antonio Quartulli <antonio@meshcoding.com>
Cc: b.a.t.m.a.n@lists.open-mesh.org
Subject: [B.A.T.M.A.N.] [PATCH 17/31] batman-adv: iv_ogm_can_aggregate, code readability
Date: Tue, 2 Dec 2014 12:16:35 +0100 [thread overview]
Message-ID: <1417519009-20699-18-git-send-email-mpa@pengutronix.de> (raw)
In-Reply-To: <1417519009-20699-1-git-send-email-mpa@pengutronix.de>
This patch tries to increase code readability by negating the first if
block and rearranging some of the other conditional blocks. This way we
save an indentation level, we also save some allocation that is not
necessary for one of the conditions.
Signed-off-by: Markus Pargmann <mpa@pengutronix.de>
---
bat_iv_ogm.c | 98 +++++++++++++++++++++++++++++++-----------------------------
1 file changed, 50 insertions(+), 48 deletions(-)
diff --git a/bat_iv_ogm.c b/bat_iv_ogm.c
index 8ebbd2eb81ee..f8fd535dbdc9 100644
--- a/bat_iv_ogm.c
+++ b/bat_iv_ogm.c
@@ -546,58 +546,60 @@ batadv_iv_ogm_can_aggregate(const struct batadv_ogm_packet *new_bat_ogm_packet,
* - the send time is within our MAX_AGGREGATION_MS time
* - the resulting packet wont be bigger than
* MAX_AGGREGATION_BYTES
+ * otherwise aggregation is not possible
*/
- if (time_before(send_time, forw_packet->send_time) &&
- time_after_eq(aggregation_end_time, forw_packet->send_time) &&
- (aggregated_bytes <= BATADV_MAX_AGGREGATION_BYTES)) {
- /* check aggregation compatibility
- * -> direct link packets are broadcasted on
- * their interface only
- * -> aggregate packet if the current packet is
- * a "global" packet as well as the base
- * packet
- */
- primary_if = batadv_primary_if_get_selected(bat_priv);
- if (!primary_if)
- goto out;
+ if (!time_before(send_time, forw_packet->send_time) ||
+ !time_after_eq(aggregation_end_time, forw_packet->send_time) ||
+ aggregated_bytes > BATADV_MAX_AGGREGATION_BYTES)
+ return false;
- /* packet is not leaving on the same interface. */
- if (forw_packet->if_outgoing != if_outgoing)
- goto out;
+ /* packet is not leaving on the same interface. */
+ if (forw_packet->if_outgoing != if_outgoing)
+ return false;
- /* packets without direct link flag and high TTL
- * are flooded through the net
- */
- if ((!directlink) &&
- (!(batadv_ogm_packet->flags & BATADV_DIRECTLINK)) &&
- (batadv_ogm_packet->ttl != 1) &&
-
- /* own packets originating non-primary
- * interfaces leave only that interface
- */
- ((!forw_packet->own) ||
- (forw_packet->if_incoming == primary_if))) {
- res = true;
- goto out;
- }
+ /* check aggregation compatibility
+ * -> direct link packets are broadcasted on
+ * their interface only
+ * -> aggregate packet if the current packet is
+ * a "global" packet as well as the base
+ * packet
+ */
+ primary_if = batadv_primary_if_get_selected(bat_priv);
+ if (!primary_if)
+ return false;
- /* if the incoming packet is sent via this one
- * interface only - we still can aggregate
- */
- if ((directlink) &&
- (new_bat_ogm_packet->ttl == 1) &&
- (forw_packet->if_incoming == if_incoming) &&
-
- /* packets from direct neighbors or
- * own secondary interface packets
- * (= secondary interface packets in general)
- */
- (batadv_ogm_packet->flags & BATADV_DIRECTLINK ||
- (forw_packet->own &&
- forw_packet->if_incoming != primary_if))) {
- res = true;
- goto out;
- }
+ /* packets without direct link flag and high TTL
+ * are flooded through the net
+ */
+ if (!directlink &&
+ !(batadv_ogm_packet->flags & BATADV_DIRECTLINK) &&
+ batadv_ogm_packet->ttl != 1 &&
+
+ /* own packets originating non-primary
+ * interfaces leave only that interface
+ */
+ (!forw_packet->own ||
+ forw_packet->if_incoming == primary_if)) {
+ res = true;
+ goto out;
+ }
+
+ /* if the incoming packet is sent via this one
+ * interface only - we still can aggregate
+ */
+ if (directlink &&
+ new_bat_ogm_packet->ttl == 1 &&
+ forw_packet->if_incoming == if_incoming &&
+
+ /* packets from direct neighbors or
+ * own secondary interface packets
+ * (= secondary interface packets in general)
+ */
+ (batadv_ogm_packet->flags & BATADV_DIRECTLINK ||
+ (forw_packet->own &&
+ forw_packet->if_incoming != primary_if))) {
+ res = true;
+ goto out;
}
out:
--
2.1.3
next prev parent reply other threads:[~2014-12-02 11:16 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-02 11:16 [B.A.T.M.A.N.] [PATCH 00/31] batman-adv: Cleanups Markus Pargmann
2014-12-02 11:16 ` [B.A.T.M.A.N.] [PATCH 01/31] batman-adv: debugfs, avoid compiling for !DEBUG_FS Markus Pargmann
2014-12-02 11:16 ` [B.A.T.M.A.N.] [PATCH 02/31] batman-adv: Separate logging header Markus Pargmann
2014-12-02 15:59 ` Martin Hundebøll
2014-12-02 11:16 ` [B.A.T.M.A.N.] [PATCH 03/31] batman-adv: iv_ogm, Reduce code duplication Markus Pargmann
2014-12-02 11:16 ` [B.A.T.M.A.N.] [PATCH 04/31] batman-adv: iv_ogm, divide and round for ring buffer avg Markus Pargmann
2015-01-12 15:52 ` Simon Wunderlich
2014-12-02 11:16 ` [B.A.T.M.A.N.] [PATCH 05/31] batman-adv: init, Add some error handling Markus Pargmann
2014-12-02 11:16 ` [B.A.T.M.A.N.] [PATCH 06/31] batman-adv: tvlv realloc, move error handling into if block Markus Pargmann
2014-12-02 11:16 ` [B.A.T.M.A.N.] [PATCH 07/31] batman-adv: split tvlv into a seperate file Markus Pargmann
2014-12-02 11:16 ` [B.A.T.M.A.N.] [PATCH 08/31] batman-adv: hash, remove function implementations from header Markus Pargmann
2014-12-02 11:16 ` [B.A.T.M.A.N.] [PATCH 09/31] batman-adv: hash, Add helper functions Markus Pargmann
2014-12-02 11:16 ` [B.A.T.M.A.N.] [PATCH 10/31] batman-adv: hash, replace direct hash structure accesses Markus Pargmann
2014-12-02 11:16 ` [B.A.T.M.A.N.] [PATCH 11/31] batman-adv: hash, make struct hashtable private Markus Pargmann
2014-12-02 11:16 ` [B.A.T.M.A.N.] [PATCH 12/31] batman-adv: hash, add used linux headers Markus Pargmann
2014-12-02 11:16 ` [B.A.T.M.A.N.] [PATCH 13/31] batman-adv: Makefile, Sort alphabetically Markus Pargmann
2014-12-02 11:16 ` [B.A.T.M.A.N.] [PATCH 14/31] batman-adv: iv_ogm_iface_enable, direct return values Markus Pargmann
2014-12-02 11:16 ` [B.A.T.M.A.N.] [PATCH 15/31] batman-adv: iv_ogm_aggr_packet, bool return value Markus Pargmann
2014-12-02 11:16 ` [B.A.T.M.A.N.] [PATCH 16/31] batman-adv: iv_ogm_send_to_if, declare char* as const Markus Pargmann
2014-12-02 11:16 ` Markus Pargmann [this message]
2014-12-02 11:16 ` [B.A.T.M.A.N.] [PATCH 18/31] batman-adv: iv_ogm_orig_update, remove unnecessary brackets Markus Pargmann
2014-12-02 11:16 ` [B.A.T.M.A.N.] [PATCH 19/31] batman-adv: iv_ogm_aggregate_new, simplify error handling Markus Pargmann
2014-12-02 11:16 ` [B.A.T.M.A.N.] [PATCH 20/31] batman-adv: iv_ogm_queue_add, Simplify expressions Markus Pargmann
2014-12-02 11:16 ` [B.A.T.M.A.N.] [PATCH 21/31] batman-adv: iv_ogm_orig_update, style, add missin brackets Markus Pargmann
2014-12-02 11:16 ` [B.A.T.M.A.N.] [PATCH 22/31] batman-adv: iv_ogm, Fix dup_status comment Markus Pargmann
2014-12-02 11:16 ` [B.A.T.M.A.N.] [PATCH 23/31] batman-adv: iv_ogm, fix coding style Markus Pargmann
2014-12-02 11:16 ` [B.A.T.M.A.N.] [PATCH 24/31] batman-adv: iv_ogm, fix comment function name Markus Pargmann
2014-12-02 11:16 ` [B.A.T.M.A.N.] [PATCH 25/31] batman-adv: types, Fix comment on bcast_own Markus Pargmann
2014-12-02 11:16 ` [B.A.T.M.A.N.] [PATCH 26/31] batman-adv: main, Convert is_my_mac() to bool Markus Pargmann
2014-12-02 11:16 ` [B.A.T.M.A.N.] [PATCH 27/31] batman-adv: main, batadv_compare_eth return bool Markus Pargmann
2014-12-02 11:16 ` [B.A.T.M.A.N.] [PATCH 28/31] batman-adv: Remove unnecessary ret variable Markus Pargmann
2014-12-02 11:16 ` [B.A.T.M.A.N.] [PATCH 29/31] batman-adv: Remove unnecessary ret variable in algo_register Markus Pargmann
2014-12-02 11:16 ` [B.A.T.M.A.N.] [PATCH 30/31] batman-adv: packet.h, add some missing includes Markus Pargmann
2014-12-02 11:16 ` [B.A.T.M.A.N.] [PATCH 31/31] batman-adv: types.h, add missing include Markus Pargmann
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=1417519009-20699-18-git-send-email-mpa@pengutronix.de \
--to=mpa@pengutronix.de \
--cc=antonio@meshcoding.com \
--cc=b.a.t.m.a.n@lists.open-mesh.org \
--cc=mareklindner@neomailbox.ch \
--cc=sw@simonwunderlich.de \
/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).