From: "Linus Lüssing" <linus.luessing@saxnet.de>
To: b.a.t.m.a.n@lists.open-mesh.org
Cc: "Linus Lüssing" <linus.luessing@saxnet.de>
Subject: [B.A.T.M.A.N.] [PATCH 04/20] batman-adv: Attach local MCAs to OGMs
Date: Tue, 7 Dec 2010 23:32:14 +0100 [thread overview]
Message-ID: <1291761150-29818-4-git-send-email-linus.luessing@saxnet.de> (raw)
In-Reply-To: <20101207221351.GA19474@Sellars>
This patch introduces multicast announcements - MCA for short - which
are now being attached to an OGM if an optimized multicast mode needing
MCAs has been selected (i.e. proactive_tracking).
MCA entries are multicast mac addresses used by a multicast receiver in
the mesh cloud. Currently MCAs are only fetched locally from the
according batman interface itself, bridged-in hosts will not yet get
announced and will need a more complex patch for supporting IGMP/MLD
snooping. However, the local fetching also allows to have multicast
optimizations on layer 2 already for batman nodes, not depending on
IP at all.
Signed-off-by: Linus Lüssing <linus.luessing@saxnet.de>
---
aggregation.c | 12 +++++++-
aggregation.h | 6 +++-
main.h | 2 +
send.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++++-------
4 files changed, 87 insertions(+), 15 deletions(-)
diff --git a/aggregation.c b/aggregation.c
index 0c92e3b..d4de296 100644
--- a/aggregation.c
+++ b/aggregation.c
@@ -30,6 +30,12 @@ static int hna_len(struct batman_packet *batman_packet)
return batman_packet->num_hna * ETH_ALEN;
}
+/* calculate the size of the mca information for a given packet */
+static int mca_len(struct batman_packet *batman_packet)
+{
+ return batman_packet->num_mca * ETH_ALEN;
+}
+
/* return true if new_packet can be aggregated with forw_packet */
static bool can_aggregate_with(struct batman_packet *new_batman_packet,
int packet_len,
@@ -265,9 +271,11 @@ void receive_aggr_bat_packet(struct ethhdr *ethhdr, unsigned char *packet_buff,
hna_buff, hna_len(batman_packet),
if_incoming);
- buff_pos += BAT_PACKET_LEN + hna_len(batman_packet);
+ buff_pos += BAT_PACKET_LEN + hna_len(batman_packet) +
+ mca_len(batman_packet);
batman_packet = (struct batman_packet *)
(packet_buff + buff_pos);
} while (aggregated_packet(buff_pos, packet_len,
- batman_packet->num_hna));
+ batman_packet->num_hna,
+ batman_packet->num_mca));
}
diff --git a/aggregation.h b/aggregation.h
index 71a91b3..93f2496 100644
--- a/aggregation.h
+++ b/aggregation.h
@@ -25,9 +25,11 @@
#include "main.h"
/* is there another aggregated packet here? */
-static inline int aggregated_packet(int buff_pos, int packet_len, int num_hna)
+static inline int aggregated_packet(int buff_pos, int packet_len, int num_hna,
+ int num_mca)
{
- int next_buff_pos = buff_pos + BAT_PACKET_LEN + (num_hna * ETH_ALEN);
+ int next_buff_pos = buff_pos + BAT_PACKET_LEN + (num_hna * ETH_ALEN) +
+ (num_mca * ETH_ALEN);
return (next_buff_pos <= packet_len) &&
(next_buff_pos <= MAX_AGGREGATION_BYTES);
diff --git a/main.h b/main.h
index a362433..772d621 100644
--- a/main.h
+++ b/main.h
@@ -105,6 +105,8 @@
/* #define VIS_SUBCLUSTERS_DISABLED */
+#define UINT8_MAX 255
+
/*
* Kernel headers
*/
diff --git a/send.c b/send.c
index b89b9f7..ba7ebfe 100644
--- a/send.c
+++ b/send.c
@@ -122,7 +122,8 @@ static void send_packet_to_if(struct forw_packet *forw_packet,
/* adjust all flags and log packets */
while (aggregated_packet(buff_pos,
forw_packet->packet_len,
- batman_packet->num_hna)) {
+ batman_packet->num_hna,
+ batman_packet->num_mca)) {
/* we might have aggregated direct link packets with an
* ordinary base packet */
@@ -214,18 +215,71 @@ static void send_packet(struct forw_packet *forw_packet)
rcu_read_unlock();
}
+static void add_own_MCA(struct batman_packet *batman_packet, int num_mca,
+ struct net_device *soft_iface)
+{
+ MC_LIST *mc_list_entry;
+ int num_mca_done = 0;
+ unsigned long flags;
+ char *mca_entry = (char *)(batman_packet + 1);
+
+ if (num_mca == 0)
+ goto out;
+
+ if (num_mca > UINT8_MAX) {
+ pr_warning("Too many multicast announcements here, "
+ "just adding %i\n", UINT8_MAX);
+ num_mca = UINT8_MAX;
+ }
+
+ mca_entry = mca_entry + batman_packet->num_hna * ETH_ALEN;
+
+ MC_LIST_LOCK(soft_iface, flags);
+ netdev_for_each_mc_addr(mc_list_entry, soft_iface) {
+ memcpy(mca_entry, &mc_list_entry->MC_LIST_ADDR, ETH_ALEN);
+ mca_entry += ETH_ALEN;
+
+ /* A multicast address might just have been added,
+ * avoid writing outside of buffer */
+ if(++num_mca_done == num_mca)
+ break;
+ }
+ MC_LIST_UNLOCK(soft_iface, flags);
+
+out:
+ batman_packet->num_mca = num_mca_done;
+}
+
static void rebuild_batman_packet(struct bat_priv *bat_priv,
struct batman_if *batman_if)
{
- int new_len;
- unsigned char *new_buff;
+ int new_len, mcast_mode, num_mca = 0;
+ unsigned long flags;
+ unsigned char *new_buff = NULL;
struct batman_packet *batman_packet;
- new_len = sizeof(struct batman_packet) +
- (bat_priv->num_local_hna * ETH_ALEN);
- new_buff = kmalloc(new_len, GFP_ATOMIC);
+ batman_packet = (struct batman_packet *)batman_if->packet_buff;
+ mcast_mode = atomic_read(&bat_priv->mcast_mode);
+
+ /* Avoid attaching MCAs, if multicast optimization is disabled */
+ if (mcast_mode == MCAST_MODE_PROACT_TRACKING) {
+ MC_LIST_LOCK(batman_if->soft_iface, flags);
+ num_mca = netdev_mc_count(batman_if->soft_iface);
+ MC_LIST_UNLOCK(batman_if->soft_iface, flags);
+ }
- /* keep old buffer if kmalloc should fail */
+ if (atomic_read(&bat_priv->hna_local_changed) ||
+ num_mca != batman_packet->num_mca) {
+ new_len = sizeof(struct batman_packet) +
+ (bat_priv->num_local_hna * ETH_ALEN) +
+ num_mca * ETH_ALEN;
+ new_buff = kmalloc(new_len, GFP_ATOMIC);
+ }
+
+ /*
+ * if local hna or mca has changed but kmalloc failed
+ * then just keep the old buffer
+ */
if (new_buff) {
memcpy(new_buff, batman_if->packet_buff,
sizeof(struct batman_packet));
@@ -239,6 +293,13 @@ static void rebuild_batman_packet(struct bat_priv *bat_priv,
batman_if->packet_buff = new_buff;
batman_if->packet_len = new_len;
}
+
+ /**
+ * always copy mca entries (if there are any) - we have to
+ * traverse the list anyway, so we can just do a memcpy instead of memcmp
+ * for the sake of simplicity
+ */
+ add_own_MCA(batman_packet, num_mca, batman_if->soft_iface);
}
void schedule_own_packet(struct batman_if *batman_if)
@@ -264,9 +325,7 @@ void schedule_own_packet(struct batman_if *batman_if)
if (batman_if->if_status == IF_TO_BE_ACTIVATED)
batman_if->if_status = IF_ACTIVE;
- /* if local hna has changed and interface is a primary interface */
- if ((atomic_read(&bat_priv->hna_local_changed)) &&
- (batman_if == bat_priv->primary_if))
+ if (batman_if == bat_priv->primary_if)
rebuild_batman_packet(bat_priv, batman_if);
/**
@@ -359,7 +418,8 @@ void schedule_forward_packet(struct orig_node *orig_node,
send_time = forward_send_time(bat_priv);
add_bat_packet_to_list(bat_priv,
(unsigned char *)batman_packet,
- sizeof(struct batman_packet) + hna_buff_len,
+ sizeof(struct batman_packet) + hna_buff_len
+ + batman_packet->num_mca * ETH_ALEN,
if_incoming, 0, send_time);
}
--
1.7.1
next prev parent reply other threads:[~2010-12-07 22:32 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-07 22:13 [B.A.T.M.A.N.] B.A.T.M.A.N.-Advanced Multicast Optimizations Linus Lüssing
2010-12-07 22:32 ` [B.A.T.M.A.N.] [PATCH 01/20] batman-adv: Add packet structures for multicast optimizations Linus Lüssing
2010-12-08 8:18 ` Andrew Lunn
2010-12-07 22:32 ` [B.A.T.M.A.N.] [PATCH 02/20] batman-adv: Adding configurable variables " Linus Lüssing
2010-12-07 22:32 ` [B.A.T.M.A.N.] [PATCH 03/20] batman-adv: compat macros/defines for local multicast group fetching Linus Lüssing
2010-12-07 22:32 ` Linus Lüssing [this message]
2010-12-07 22:32 ` [B.A.T.M.A.N.] [PATCH 05/20] batman-adv: Add periodic multicast tracker timer Linus Lüssing
2010-12-07 22:32 ` [B.A.T.M.A.N.] [PATCH 06/20] batman-adv: Buffer other originator's received MCA entries Linus Lüssing
2010-12-07 22:32 ` [B.A.T.M.A.N.] [PATCH 07/20] batman-adv: Prepare and send own multicast tracker packets Linus Lüssing
2010-12-08 9:06 ` Andrew Lunn
2010-12-07 22:32 ` [B.A.T.M.A.N.] [PATCH 08/20] batman-adv: Add length check for (received) " Linus Lüssing
2010-12-07 22:32 ` [B.A.T.M.A.N.] [PATCH 09/20] batman-adv: Route multicast " Linus Lüssing
2010-12-07 22:32 ` [B.A.T.M.A.N.] [PATCH 10/20] batman-adv: Add/refresh entries to/in mcast forwarding table Linus Lüssing
2010-12-07 22:32 ` [B.A.T.M.A.N.] [PATCH 11/20] batman-adv: Output mcast forw table in debugfs Linus Lüssing
2010-12-07 22:32 ` [B.A.T.M.A.N.] [PATCH 12/20] batman-adv: Purge timeouted entries in mcast forw table Linus Lüssing
2010-12-08 18:08 ` Andrew Lunn
2010-12-07 22:32 ` [B.A.T.M.A.N.] [PATCH 13/20] batman-adv: Send own BAT_MCAST packets in proact_tracking multicast mode Linus Lüssing
2010-12-08 18:12 ` Andrew Lunn
2010-12-07 22:32 ` [B.A.T.M.A.N.] [PATCH 14/20] batman-adv: Export broadcast packet ethernet header checks Linus Lüssing
2010-12-07 22:32 ` [B.A.T.M.A.N.] [PATCH 15/20] batman-adv: Receive multicast data packets BAT_MCAST Linus Lüssing
2010-12-07 22:32 ` [B.A.T.M.A.N.] [PATCH 16/20] batman-adv: Forward multicast data in proact_tracking mode Linus Lüssing
2010-12-07 22:32 ` [B.A.T.M.A.N.] [PATCH 17/20] batman-adv: Add duplicate checks for multicast data Linus Lüssing
2010-12-07 22:32 ` [B.A.T.M.A.N.] [PATCH 18/20] batman-adv: Still flood multicast packets we are not a receiver of Linus Lüssing
2010-12-10 13:07 ` Andrew Lunn
2010-12-07 22:32 ` [B.A.T.M.A.N.] [PATCH 19/20] batman-adv: Make number of (re)broadcasts configurable via sysfs Linus Lüssing
2010-12-07 22:32 ` [B.A.T.M.A.N.] [PATCH 20/20] batman-adv: Do not disable irqs for spinlocks in multicast specific code Linus Lüssing
2010-12-08 7:29 ` [B.A.T.M.A.N.] B.A.T.M.A.N.-Advanced Multicast Optimizations Andrew Lunn
2010-12-09 21:02 ` Simon Wunderlich
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=1291761150-29818-4-git-send-email-linus.luessing@saxnet.de \
--to=linus.luessing@saxnet.de \
--cc=b.a.t.m.a.n@lists.open-mesh.org \
/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).