b.a.t.m.a.n.lists.open-mesh.org archive mirror
 help / color / mirror / Atom feed
From: Antonio Quartulli <ordex@autistici.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, b.a.t.m.a.n@lists.open-mesh.org,
	Simon Wunderlich <siwu@hrz.tu-chemnitz.de>
Subject: [B.A.T.M.A.N.] [PATCH 13/16] batman-adv: add broadcast duplicate check
Date: Thu,  5 Apr 2012 12:38:59 +0200	[thread overview]
Message-ID: <1333622342-6128-14-git-send-email-ordex@autistici.org> (raw)
In-Reply-To: <1333622342-6128-1-git-send-email-ordex@autistici.org>

From: Simon Wunderlich <simon.wunderlich@s2003.tu-chemnitz.de>

When multiple backbone gateways relay the same broadcast from the
backbone into the mesh, other nodes in the mesh may receive this
broadcast multiple times. To avoid this, the crc checksums of
received broadcasts are recorded and new broadcast packets with
the same content may be dropped if received by another gateway.

Signed-off-by: Simon Wunderlich <siwu@hrz.tu-chemnitz.de>
Signed-off-by: Antonio Quartulli <ordex@autistici.org>
---
 net/batman-adv/bridge_loop_avoidance.c |   73 ++++++++++++++++++++++++++++++++
 net/batman-adv/bridge_loop_avoidance.h |    2 +
 net/batman-adv/main.h                  |    3 ++
 net/batman-adv/routing.c               |    4 ++
 net/batman-adv/types.h                 |    7 +++
 5 files changed, 89 insertions(+)

diff --git a/net/batman-adv/bridge_loop_avoidance.c b/net/batman-adv/bridge_loop_avoidance.c
index 264ac65..ee9f912 100644
--- a/net/batman-adv/bridge_loop_avoidance.c
+++ b/net/batman-adv/bridge_loop_avoidance.c
@@ -1040,8 +1040,16 @@ out:
 /* initialize all bla structures */
 int bla_init(struct bat_priv *bat_priv)
 {
+	int i;
+
 	bat_dbg(DBG_BLA, bat_priv, "bla hash registering\n");
 
+	/* initialize the duplicate list */
+	for (i = 0; i < DUPLIST_SIZE; i++)
+		bat_priv->bcast_duplist[i].entrytime =
+			jiffies - msecs_to_jiffies(DUPLIST_TIMEOUT);
+	bat_priv->bcast_duplist_curr = 0;
+
 	if (bat_priv->claim_hash)
 		return 1;
 
@@ -1059,6 +1067,71 @@ int bla_init(struct bat_priv *bat_priv)
 
 /**
  * @bat_priv: the bat priv with all the soft interface information
+ * @bcast_packet: originator mac address
+ * @hdr_size: maximum length of the frame
+ *
+ * check if it is on our broadcast list. Another gateway might
+ * have sent the same packet because it is connected to the same backbone,
+ * so we have to remove this duplicate.
+ *
+ * This is performed by checking the CRC, which will tell us
+ * with a good chance that it is the same packet. If it is furthermore
+ * sent by another host, drop it. We allow equal packets from
+ * the same host however as this might be intended.
+ *
+ **/
+
+int bla_check_bcast_duplist(struct bat_priv *bat_priv,
+			    struct bcast_packet *bcast_packet,
+			    int hdr_size)
+{
+	int i, length, curr;
+	uint8_t *content;
+	uint16_t crc;
+	struct bcast_duplist_entry *entry;
+
+	length = hdr_size - sizeof(*bcast_packet);
+	content = (uint8_t *)bcast_packet;
+	content += sizeof(*bcast_packet);
+
+	/* calculate the crc ... */
+	crc = crc16(0, content, length);
+
+	for (i = 0 ; i < DUPLIST_SIZE; i++) {
+		curr = (bat_priv->bcast_duplist_curr + i) % DUPLIST_SIZE;
+		entry = &bat_priv->bcast_duplist[curr];
+
+		/* we can stop searching if the entry is too old ;
+		 * later entries will be even older */
+		if (has_timed_out(entry->entrytime, DUPLIST_TIMEOUT))
+			break;
+
+		if (entry->crc != crc)
+			continue;
+
+		if (compare_eth(entry->orig, bcast_packet->orig))
+			continue;
+
+		/* this entry seems to match: same crc, not too old,
+		 * and from another gw. therefore return 1 to forbid it. */
+		return 1;
+	}
+	/* not found, add a new entry (overwrite the oldest entry) */
+	curr = (bat_priv->bcast_duplist_curr + DUPLIST_SIZE - 1) % DUPLIST_SIZE;
+	entry = &bat_priv->bcast_duplist[curr];
+	entry->crc = crc;
+	entry->entrytime = jiffies;
+	memcpy(entry->orig, bcast_packet->orig, ETH_ALEN);
+	bat_priv->bcast_duplist_curr = curr;
+
+	/* allow it, its the first occurence. */
+	return 0;
+}
+
+
+
+/**
+ * @bat_priv: the bat priv with all the soft interface information
  * @orig: originator mac address
  *
  * check if the originator is a gateway for any VLAN ID.
diff --git a/net/batman-adv/bridge_loop_avoidance.h b/net/batman-adv/bridge_loop_avoidance.h
index b74940f..9468c24 100644
--- a/net/batman-adv/bridge_loop_avoidance.h
+++ b/net/batman-adv/bridge_loop_avoidance.h
@@ -28,6 +28,8 @@ int bla_is_backbone_gw(struct sk_buff *skb,
 		       struct orig_node *orig_node, int hdr_size);
 int bla_claim_table_seq_print_text(struct seq_file *seq, void *offset);
 int bla_is_backbone_gw_orig(struct bat_priv *bat_priv, uint8_t *orig);
+int bla_check_bcast_duplist(struct bat_priv *bat_priv,
+			    struct bcast_packet *bcast_packet, int hdr_size);
 void bla_update_orig_address(struct bat_priv *bat_priv,
 			     struct hard_iface *primary_if,
 			     struct hard_iface *oldif);
diff --git a/net/batman-adv/main.h b/net/batman-adv/main.h
index 82723b5..d9832ac 100644
--- a/net/batman-adv/main.h
+++ b/net/batman-adv/main.h
@@ -83,6 +83,9 @@
 #define BLA_PERIOD_LENGTH	10000	/* 10 seconds */
 #define BLA_BACKBONE_TIMEOUT	(BLA_PERIOD_LENGTH * 3)
 #define BLA_CLAIM_TIMEOUT	(BLA_PERIOD_LENGTH * 10)
+
+#define DUPLIST_SIZE		16
+#define DUPLIST_TIMEOUT		500	/* 500 ms */
 /* don't reset again within 30 seconds */
 #define RESET_PROTECTION_MS 30000
 #define EXPECTED_SEQNO_RANGE	65536
diff --git a/net/batman-adv/routing.c b/net/batman-adv/routing.c
index fb5e9f3..f1adef8 100644
--- a/net/batman-adv/routing.c
+++ b/net/batman-adv/routing.c
@@ -1075,6 +1075,10 @@ int recv_bcast_packet(struct sk_buff *skb, struct hard_iface *recv_if)
 
 	spin_unlock_bh(&orig_node->bcast_seqno_lock);
 
+	/* check whether this has been sent by another originator before */
+	if (bla_check_bcast_duplist(bat_priv, bcast_packet, hdr_size))
+		goto out;
+
 	/* rebroadcast packet */
 	add_bcast_packet_to_list(bat_priv, skb, 1);
 
diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
index 35cd831..ad97e87 100644
--- a/net/batman-adv/types.h
+++ b/net/batman-adv/types.h
@@ -140,6 +140,11 @@ struct neigh_node {
 	spinlock_t tq_lock;	/* protects: tq_recv, tq_index */
 };
 
+struct bcast_duplist_entry {
+	uint8_t orig[ETH_ALEN];
+	uint16_t crc;
+	unsigned long entrytime;
+};
 
 struct bat_priv {
 	atomic_t mesh_state;
@@ -186,6 +191,8 @@ struct bat_priv {
 	struct list_head tt_req_list; /* list of pending tt_requests */
 	struct list_head tt_roam_list;
 	struct hashtable_t *vis_hash;
+	struct bcast_duplist_entry bcast_duplist[DUPLIST_SIZE];
+	int bcast_duplist_curr;
 	spinlock_t forw_bat_list_lock; /* protects forw_bat_list */
 	spinlock_t forw_bcast_list_lock; /* protects  */
 	spinlock_t tt_changes_list_lock; /* protects tt_changes */
-- 
1.7.9.4


  parent reply	other threads:[~2012-04-05 10:38 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-05 10:38 [B.A.T.M.A.N.] pull request: batman-adv 2012-04-05 Antonio Quartulli
2012-04-05 10:38 ` [B.A.T.M.A.N.] [PATCH 01/16] MAINTAINERS: add additional maintainer for net/batman-adv Antonio Quartulli
2012-04-05 10:38 ` [B.A.T.M.A.N.] [PATCH 02/16] batman-adv: clean up Kconfig Antonio Quartulli
2012-04-05 10:38 ` [B.A.T.M.A.N.] [PATCH 03/16] batman-adv: use ETH_ALEN instead of hardcoded numeric constants Antonio Quartulli
2012-04-05 10:38 ` [B.A.T.M.A.N.] [PATCH 04/16] batman-adv: Replace bitarray operations with bitmap Antonio Quartulli
2012-04-05 10:38 ` [B.A.T.M.A.N.] [PATCH 05/16] batman-adv: Remove declaration of only locally used functions Antonio Quartulli
2012-04-05 10:38 ` [B.A.T.M.A.N.] [PATCH 06/16] batman-adv: encourage batman to take shorter routes by changing the default hop penalty Antonio Quartulli
2012-04-05 10:38 ` [B.A.T.M.A.N.] [PATCH 07/16] batman-adv: remove old bridge loop avoidance code Antonio Quartulli
2012-04-05 10:38 ` [B.A.T.M.A.N.] [PATCH 08/16] batman-adv: add basic " Antonio Quartulli
2012-04-05 10:38 ` [B.A.T.M.A.N.] [PATCH 09/16] batman-adv: make bridge loop avoidance switchable Antonio Quartulli
2012-04-05 10:38 ` [B.A.T.M.A.N.] [PATCH 10/16] batman-adv: export claim tables through debugfs Antonio Quartulli
2012-04-05 10:38 ` [B.A.T.M.A.N.] [PATCH 11/16] batman-adv: allow multiple entries in tt_global_entries Antonio Quartulli
2012-04-05 10:38 ` [B.A.T.M.A.N.] [PATCH 12/16] batman-adv: don't let backbone gateways exchange tt entries Antonio Quartulli
2012-04-05 10:38 ` Antonio Quartulli [this message]
2012-04-05 10:39 ` [B.A.T.M.A.N.] [PATCH 14/16] batman-adv: drop STP over batman Antonio Quartulli
2012-04-05 10:39 ` [B.A.T.M.A.N.] [PATCH 15/16] batman-adv: form groups in the bridge loop avoidance Antonio Quartulli
2012-04-05 10:39 ` [B.A.T.M.A.N.] [PATCH 16/16] batman-adv: add bridge loop avoidance compile option Antonio Quartulli
2012-04-05 23:15 ` [B.A.T.M.A.N.] pull request: batman-adv 2012-04-05 David Miller
2012-04-07 18:49 [B.A.T.M.A.N.] pull request: batman-adv 2012-04-07 Antonio Quartulli
2012-04-07 18:49 ` [B.A.T.M.A.N.] [PATCH 13/16] batman-adv: add broadcast duplicate check Antonio Quartulli
2012-04-11 12:50 [B.A.T.M.A.N.] pull request: batman-adv 2012-04-11 Antonio Quartulli
2012-04-11 12:50 ` [B.A.T.M.A.N.] [PATCH 13/16] batman-adv: add broadcast duplicate check Antonio Quartulli

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=1333622342-6128-14-git-send-email-ordex@autistici.org \
    --to=ordex@autistici.org \
    --cc=b.a.t.m.a.n@lists.open-mesh.org \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=siwu@hrz.tu-chemnitz.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).