b.a.t.m.a.n.lists.open-mesh.org archive mirror
 help / color / mirror / Atom feed
From: "Linus Lüssing" <linus.luessing@ascom.ch>
To: b.a.t.m.a.n@lists.open-mesh.org
Cc: "Linus Lüssing" <linus.luessing@ascom.ch>
Subject: [B.A.T.M.A.N.] [PATCH 10/12] batman-adv: Adding unicast_safe packet reception
Date: Wed,  2 Mar 2011 18:18:39 +0100	[thread overview]
Message-ID: <1299086321-25116-11-git-send-email-linus.luessing@ascom.ch> (raw)
In-Reply-To: <1299086321-25116-1-git-send-email-linus.luessing@ascom.ch>

With this commit unicast_safe packets generated by a node in redundant
bonding mode will be processed on reception. It is being transformed
back to a normal unicast packet if the packet is for the node itself or
if redundant bonding mode is deactivated on this node. Otherwise it is
being passed on as is to the routing functions.

Signed-off-by: Linus Lüssing <linus.luessing@ascom.ch>
---
 hard-interface.c |    5 ++++
 routing.c        |   60 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 routing.h        |    1 +
 3 files changed, 62 insertions(+), 4 deletions(-)

diff --git a/hard-interface.c b/hard-interface.c
index b0105e9..7164b1f 100644
--- a/hard-interface.c
+++ b/hard-interface.c
@@ -624,6 +624,11 @@ static int batman_skb_recv(struct sk_buff *skb, struct net_device *dev,
 		ret = recv_ucast_frag_packet(skb, hard_iface);
 		break;
 
+		/* fragmented unicast packet */
+	case BAT_UNICAST_SAFE:
+		ret = recv_ucast_safe_packet(skb, hard_iface);
+		break;
+
 		/* broadcast packet */
 	case BAT_BCAST:
 		ret = recv_bcast_packet(skb, hard_iface);
diff --git a/routing.c b/routing.c
index f17834a..d31a7ad 100644
--- a/routing.c
+++ b/routing.c
@@ -1018,6 +1018,29 @@ out:
 	return ret;
 }
 
+static void unicast_safe_to_unicast(struct sk_buff *skb)
+{
+	struct unicast_packet_safe unicast_packet_safe;
+	struct unicast_packet *unicast_packet;
+
+	unicast_packet_safe = *((struct unicast_packet_safe *)skb->data);
+	unicast_packet = (struct unicast_packet *) skb_pull(skb,
+					sizeof(struct unicast_packet_safe) -
+					sizeof(struct unicast_packet));
+
+	unicast_packet->header = unicast_packet_safe.header;
+	unicast_packet->header.packet_type = BAT_UNICAST;
+	memcpy(unicast_packet->dest, unicast_packet_safe.dest, ETH_ALEN);
+}
+
+static void set_unicast_safe_options(struct bat_priv *bat_priv,
+				struct unicast_packet_safe *unicast_packet)
+{
+	memcpy(unicast_packet->orig, bat_priv->primary_if->net_dev->dev_addr,
+	       ETH_ALEN);
+	unicast_packet->seqno = htonl(atomic_inc_return(&bat_priv->dup_seqno));
+}
+
 static int unicast_to_unicast_safe(struct sk_buff *skb,
 				   struct bat_priv *bat_priv)
 {
@@ -1033,10 +1056,7 @@ static int unicast_to_unicast_safe(struct sk_buff *skb,
 	unicast_packet_safe->header = unicast_packet.header;
 	memcpy(unicast_packet_safe->dest, unicast_packet.dest, ETH_ALEN);
 	unicast_packet_safe->header.packet_type = BAT_UNICAST_SAFE;
-	memcpy(unicast_packet_safe->orig,
-	       bat_priv->primary_if->net_dev->dev_addr, ETH_ALEN);
-	unicast_packet_safe->seqno =
-				htonl(atomic_inc_return(&bat_priv->dup_seqno));
+	set_unicast_safe_options(bat_priv, unicast_packet_safe);
 
 	return 0;
 }
@@ -1384,6 +1404,38 @@ int recv_ucast_frag_packet(struct sk_buff *skb, struct hard_iface *recv_if)
 	return route_unicast_packet(bonding_mode, skb, recv_if, orig_node);
 }
 
+int recv_ucast_safe_packet(struct sk_buff *skb, struct hard_iface *recv_if)
+{
+	struct bat_priv *bat_priv = netdev_priv(recv_if->soft_iface);
+	struct unicast_packet_safe *unicast_packet;
+	struct orig_node *orig_node;
+	int hdr_size = sizeof(struct unicast_packet);
+	int bonding_mode;
+
+	if (check_unicast_packet(skb, hdr_size) < 0)
+		return NET_RX_DROP;
+
+	unicast_packet = (struct unicast_packet_safe *)skb->data;
+
+	/* packet for me */
+	if (is_my_mac(unicast_packet->dest)) {
+		unicast_safe_to_unicast(skb);
+
+		interface_rx(recv_if->soft_iface, skb, recv_if, hdr_size);
+		return NET_RX_SUCCESS;
+	}
+
+	bonding_mode = atomic_read(&bat_priv->bonding) <<
+			atomic_read(&bat_priv->red_bonding);
+
+	if (bonding_mode != REDUNDANT_BONDING)
+		unicast_safe_to_unicast(skb);
+	else
+		set_unicast_safe_options(bat_priv, unicast_packet);
+
+	orig_node = hash_find_orig(bat_priv, unicast_packet->dest);
+	return route_unicast_packet(bonding_mode, skb, recv_if, orig_node);
+}
 
 int recv_bcast_packet(struct sk_buff *skb, struct hard_iface *recv_if)
 {
diff --git a/routing.h b/routing.h
index 1530c6d..8608ac3 100644
--- a/routing.h
+++ b/routing.h
@@ -36,6 +36,7 @@ int route_unicast_packet(int bonding_mode, struct sk_buff *skb,
 int recv_icmp_packet(struct sk_buff *skb, struct hard_iface *recv_if);
 int recv_unicast_packet(struct sk_buff *skb, struct hard_iface *recv_if);
 int recv_ucast_frag_packet(struct sk_buff *skb, struct hard_iface *recv_if);
+int recv_ucast_safe_packet(struct sk_buff *skb, struct hard_iface *recv_if);
 int recv_bcast_packet(struct sk_buff *skb, struct hard_iface *recv_if);
 int recv_vis_packet(struct sk_buff *skb, struct hard_iface *recv_if);
 int recv_bat_packet(struct sk_buff *skb, struct hard_iface *recv_if);
-- 
1.7.2.3


  parent reply	other threads:[~2011-03-02 17:18 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-02 17:18 [B.A.T.M.A.N.] Redundancy bonding mode patches, v2 Linus Lüssing
2011-03-02 17:18 ` [B.A.T.M.A.N.] [PATCH 01/12] batman-adv: Remove unused hdr_size variable in route_unicast_packet() Linus Lüssing
2011-03-02 17:36   ` Marek Lindner
2011-03-02 17:18 ` [B.A.T.M.A.N.] [PATCH 02/12] batman-adv: Add explicit batman header structure Linus Lüssing
2011-03-02 17:18 ` [B.A.T.M.A.N.] [PATCH 03/12] batman-adv: Unify TTL handling Linus Lüssing
2011-03-02 17:18 ` [B.A.T.M.A.N.] [PATCH 04/12] batman-adv: Make route_unicast_packet() packet_type independent Linus Lüssing
2011-03-02 17:18 ` [B.A.T.M.A.N.] [PATCH 05/12] batman-adv: Use route_unicast_packet() for sending own unicast packets Linus Lüssing
2011-03-02 17:18 ` [B.A.T.M.A.N.] [PATCH 06/12] batman-adv: Avoid redundant hash_find() call for " Linus Lüssing
2011-03-02 17:18 ` [B.A.T.M.A.N.] [PATCH 07/12] batman-adv: Use packet lists for unicast packet sending Linus Lüssing
2011-03-03 13:17   ` Marek Lindner
2011-03-02 17:18 ` [B.A.T.M.A.N.] [PATCH 08/12] batman-adv: Add sysfs option for enabling redundant bonding mode Linus Lüssing
2011-03-03  2:01   ` Marek Lindner
2011-03-02 17:18 ` [B.A.T.M.A.N.] [PATCH 09/12] batman-adv: Adding redundant bonding mode transmission Linus Lüssing
2011-03-03 13:48   ` Marek Lindner
2011-03-02 17:18 ` Linus Lüssing [this message]
2011-03-02 17:18 ` [B.A.T.M.A.N.] [PATCH 11/12] batman-adv: Generic sequence number checking for data packets Linus Lüssing
2011-03-02 17:18 ` [B.A.T.M.A.N.] [PATCH 12/12] batman-adv: Add sequence number and duplicate checks for unicasts_safe Linus Lüssing

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=1299086321-25116-11-git-send-email-linus.luessing@ascom.ch \
    --to=linus.luessing@ascom.ch \
    --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).