b.a.t.m.a.n.lists.open-mesh.org archive mirror
 help / color / mirror / Atom feed
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, Sven Eckelmann <sven@narfation.org>
Subject: [B.A.T.M.A.N.] [PATCH v2 12/26] batman-adv: iv_ogm_can_aggregate, code readability
Date: Fri, 26 Dec 2014 12:41:29 +0100	[thread overview]
Message-ID: <1419594103-10928-13-git-send-email-mpa@pengutronix.de> (raw)
In-Reply-To: <1419594103-10928-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 4801619c4da5..1f3880ac8376 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


  parent reply	other threads:[~2014-12-26 11:41 UTC|newest]

Thread overview: 67+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-26 11:41 [B.A.T.M.A.N.] [PATCH v2 00/26] batman-adv: Cleanups Markus Pargmann
2014-12-26 11:41 ` [B.A.T.M.A.N.] [PATCH v2 01/26] batman-adv: debugfs, avoid compiling for !DEBUG_FS Markus Pargmann
2015-01-11 10:32   ` Marek Lindner
2014-12-26 11:41 ` [B.A.T.M.A.N.] [PATCH v2 02/26] batman-adv: Separate logging header Markus Pargmann
2014-12-28  2:33   ` Marek Lindner
2014-12-28 11:08     ` Markus Pargmann
2014-12-26 11:41 ` [B.A.T.M.A.N.] [PATCH v2 03/26] batman-adv: iv_ogm, Reduce code duplication Markus Pargmann
2015-01-11 10:38   ` Marek Lindner
2014-12-26 11:41 ` [B.A.T.M.A.N.] [PATCH v2 04/26] batman-adv: iv_ogm, divide and round for ring buffer avg Markus Pargmann
2015-01-11 12:32   ` Marek Lindner
2015-01-11 12:42     ` Sven Eckelmann
2015-01-12 15:56   ` Simon Wunderlich
2014-12-26 11:41 ` [B.A.T.M.A.N.] [PATCH v2 05/26] batman-adv: init, Add some error handling Markus Pargmann
2015-01-11 12:38   ` Marek Lindner
2015-01-14 15:24     ` Markus Pargmann
2014-12-26 11:41 ` [B.A.T.M.A.N.] [PATCH v2 06/26] batman-adv: tvlv realloc, move error handling into if block Markus Pargmann
2015-01-11 12:40   ` Marek Lindner
2014-12-26 11:41 ` [B.A.T.M.A.N.] [PATCH v2 07/26] batman-adv: split tvlv into a seperate file Markus Pargmann
2014-12-26 11:41 ` [B.A.T.M.A.N.] [PATCH v2 08/26] batman-adv: Makefile, Sort alphabetically Markus Pargmann
2015-01-11 12:44   ` Marek Lindner
2014-12-26 11:41 ` [B.A.T.M.A.N.] [PATCH v2 09/26] batman-adv: iv_ogm_iface_enable, direct return values Markus Pargmann
2015-01-11 12:46   ` Marek Lindner
2014-12-26 11:41 ` [B.A.T.M.A.N.] [PATCH v2 10/26] batman-adv: iv_ogm_aggr_packet, bool return value Markus Pargmann
2015-01-11 12:48   ` Marek Lindner
2014-12-26 11:41 ` [B.A.T.M.A.N.] [PATCH v2 11/26] batman-adv: iv_ogm_send_to_if, declare char* as const Markus Pargmann
2015-02-18  9:14   ` Marek Lindner
2014-12-26 11:41 ` Markus Pargmann [this message]
2015-02-19 16:20   ` [B.A.T.M.A.N.] [PATCH v2 12/26] batman-adv: iv_ogm_can_aggregate, code readability Marek Lindner
2014-12-26 11:41 ` [B.A.T.M.A.N.] [PATCH v2 13/26] batman-adv: iv_ogm_orig_update, remove unnecessary brackets Markus Pargmann
2015-02-20 11:53   ` Marek Lindner
2014-12-26 11:41 ` [B.A.T.M.A.N.] [PATCH v2 14/26] batman-adv: iv_ogm_aggregate_new, simplify error handling Markus Pargmann
2015-02-23 16:50   ` Marek Lindner
2014-12-26 11:41 ` [B.A.T.M.A.N.] [PATCH v2 15/26] batman-adv: iv_ogm_queue_add, Simplify expressions Markus Pargmann
2015-02-24 21:20   ` Marek Lindner
2014-12-26 11:41 ` [B.A.T.M.A.N.] [PATCH v2 16/26] batman-adv: iv_ogm_orig_update, style, add missin brackets Markus Pargmann
2015-02-27 18:42   ` Marek Lindner
2014-12-26 11:41 ` [B.A.T.M.A.N.] [PATCH v2 17/26] batman-adv: iv_ogm, Fix dup_status comment Markus Pargmann
2015-02-27 18:43   ` Marek Lindner
2014-12-26 11:41 ` [B.A.T.M.A.N.] [PATCH v2 18/26] batman-adv: iv_ogm, fix coding style Markus Pargmann
2015-02-28 15:59   ` Marek Lindner
2014-12-26 11:41 ` [B.A.T.M.A.N.] [PATCH v2 19/26] batman-adv: iv_ogm, fix comment function name Markus Pargmann
2015-03-01  9:00   ` Marek Lindner
2014-12-26 11:41 ` [B.A.T.M.A.N.] [PATCH v2 20/26] batman-adv: types, Fix comment on bcast_own Markus Pargmann
2015-03-09  0:28   ` Marek Lindner
2014-12-26 11:41 ` [B.A.T.M.A.N.] [PATCH v2 21/26] batman-adv: main, Convert is_my_mac() to bool Markus Pargmann
2015-03-11  9:45   ` Marek Lindner
2014-12-26 11:41 ` [B.A.T.M.A.N.] [PATCH v2 22/26] batman-adv: main, batadv_compare_eth return bool Markus Pargmann
2015-03-11  9:48   ` Marek Lindner
2014-12-26 11:41 ` [B.A.T.M.A.N.] [PATCH v2 23/26] batman-adv: Remove unnecessary ret variable Markus Pargmann
2015-03-13  6:04   ` Marek Lindner
2014-12-26 11:41 ` [B.A.T.M.A.N.] [PATCH v2 24/26] batman-adv: Remove unnecessary ret variable in algo_register Markus Pargmann
2015-03-13  6:06   ` Marek Lindner
2014-12-26 11:41 ` [B.A.T.M.A.N.] [PATCH v2 25/26] batman-adv: packet.h, add some missing includes Markus Pargmann
2014-12-27 14:30   ` Antonio Quartulli
2014-12-27 17:03     ` Markus Pargmann
2014-12-31 17:55       ` Antonio Quartulli
2015-01-14 16:27         ` Markus Pargmann
2014-12-28  2:35   ` Marek Lindner
2014-12-28 11:11     ` Markus Pargmann
2015-03-21 22:36   ` Sven Eckelmann
2015-03-24 11:10     ` Markus Pargmann
2014-12-26 11:41 ` [B.A.T.M.A.N.] [PATCH v2 26/26] batman-adv: types.h, add missing include Markus Pargmann
2014-12-28  2:35   ` Marek Lindner
2015-03-22  0:52 ` [B.A.T.M.A.N.] [PATCH v2 00/26] batman-adv: Cleanups Sven Eckelmann
2015-03-22  1:34   ` Sven Eckelmann
2015-03-24 11:41     ` Markus Pargmann
2015-03-24 11:47       ` Sven Eckelmann

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=1419594103-10928-13-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=sven@narfation.org \
    --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).