b.a.t.m.a.n.lists.open-mesh.org archive mirror
 help / color / mirror / Atom feed
From: "Linus Lüssing" <linus.luessing@c0d3.blue>
To: b.a.t.m.a.n@lists.open-mesh.org
Subject: [B.A.T.M.A.N.] [PATCH v3 2/5] batman-adv: Allow TVLVs greater than 128 bytes
Date: Tue, 25 Apr 2017 02:02:15 +0200	[thread overview]
Message-ID: <20170425000218.23721-3-linus.luessing@c0d3.blue> (raw)
In-Reply-To: <20170425000218.23721-1-linus.luessing@c0d3.blue>

The upcoming aggregation TVLVs will need to be able to hold larger
broadcast packets too.

For one thing this patch increases the according stack buffer to
256 bytes to be able to handle the most common broadcast packet cases
quickly.

For larger TVLVs, this patch will try to linearize skb data up to
and including the TVLV within the received packet.

Signed-off-by: Linus Lüssing <linus.luessing@c0d3.blue>
---
 net/batman-adv/bat_iv_ogm.c |  4 ++--
 net/batman-adv/bat_v_ogm.c  |  4 ++--
 net/batman-adv/tvlv.c       | 20 +++++++++++---------
 net/batman-adv/tvlv.h       |  4 ++--
 4 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
index 95dfc5c..e27a23f 100644
--- a/net/batman-adv/bat_iv_ogm.c
+++ b/net/batman-adv/bat_iv_ogm.c
@@ -1410,7 +1410,7 @@ batadv_iv_ogm_update_seqnos(const struct ethhdr *ethhdr,
  * @if_outgoing: the interface for which the packet should be considered
  */
 static void
-batadv_iv_ogm_process_per_outif(const struct sk_buff *skb, int ogm_offset,
+batadv_iv_ogm_process_per_outif(struct sk_buff *skb, int ogm_offset,
 				struct batadv_orig_node *orig_node,
 				struct batadv_hard_iface *if_incoming,
 				struct batadv_hard_iface *if_outgoing)
@@ -1614,7 +1614,7 @@ batadv_iv_ogm_process_per_outif(const struct sk_buff *skb, int ogm_offset,
  * @ogm_offset: offset to the OGM which should be processed (for aggregates)
  * @if_incoming: the interface where this packet was receved
  */
-static void batadv_iv_ogm_process(const struct sk_buff *skb, int ogm_offset,
+static void batadv_iv_ogm_process(struct sk_buff *skb, int ogm_offset,
 				  struct batadv_hard_iface *if_incoming)
 {
 	struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
diff --git a/net/batman-adv/bat_v_ogm.c b/net/batman-adv/bat_v_ogm.c
index cfc9228..fad96c9 100644
--- a/net/batman-adv/bat_v_ogm.c
+++ b/net/batman-adv/bat_v_ogm.c
@@ -603,7 +603,7 @@ static bool batadv_v_ogm_route_update(struct batadv_priv *bat_priv,
  */
 static void
 batadv_v_ogm_process_per_outif(struct batadv_priv *bat_priv,
-			       const struct sk_buff *skb,
+			       struct sk_buff *skb,
 			       const struct batadv_ogm2_packet *ogm2,
 			       struct batadv_orig_node *orig_node,
 			       struct batadv_neigh_node *neigh_node,
@@ -673,7 +673,7 @@ static bool batadv_v_ogm_aggr_packet(int buff_pos, int packet_len,
  * @ogm_offset: offset to the OGM which should be processed (for aggregates)
  * @if_incoming: the interface where this packet was receved
  */
-static void batadv_v_ogm_process(const struct sk_buff *skb, int ogm_offset,
+static void batadv_v_ogm_process(struct sk_buff *skb, int ogm_offset,
 				 struct batadv_hard_iface *if_incoming)
 {
 	struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
diff --git a/net/batman-adv/tvlv.c b/net/batman-adv/tvlv.c
index 7dbda3a..9179e87 100644
--- a/net/batman-adv/tvlv.c
+++ b/net/batman-adv/tvlv.c
@@ -497,12 +497,12 @@ static void batadv_tvlv_call_unfound_handlers(struct batadv_priv *bat_priv,
  * any TVLV handler called successfully. Returns NET_RX_DROP otherwise.
  */
 int batadv_tvlv_containers_process2(struct batadv_priv *bat_priv,
-				    const struct sk_buff *skb, u8 packet_type,
+				    struct sk_buff *skb, u8 packet_type,
 				    unsigned int tvlv_offset,
 				    u16 tvlv_value_len, void *ctx)
 {
 	struct batadv_tvlv_hdr *tvlv_hdr, tvlv_hdr_buff;
-	u8 *tvlv_value, tvlv_value_buff[128];
+	u8 *tvlv_value, tvlv_value_buff[256];
 	u16 tvlv_value_cont_len;
 	int ret = NET_RX_SUCCESS;
 
@@ -517,14 +517,16 @@ int batadv_tvlv_containers_process2(struct batadv_priv *bat_priv,
 		tvlv_offset += sizeof(*tvlv_hdr);
 		tvlv_value_len -= sizeof(*tvlv_hdr);
 
-		if (tvlv_value_cont_len > sizeof(tvlv_value_buff)) {
-			pr_warn_once("batman-adv: TVLVs greater than 128 bytes unsupported for now, ignoring\n");
-			goto skip_handler_call;
-		}
-
 		if (tvlv_value_cont_len > tvlv_value_len)
 			return NET_RX_DROP;
 
+		/* check for sufficient space either in stack buffer or
+		 * in skb's linear data buffer
+		 */
+		if (tvlv_value_cont_len > sizeof(tvlv_value_buff) &&
+		    !pskb_may_pull(skb, tvlv_offset + tvlv_value_cont_len))
+			return NET_RX_DROP;
+
 		tvlv_value = skb_header_pointer(skb, tvlv_offset,
 						tvlv_value_cont_len,
 						tvlv_value_buff);
@@ -535,7 +537,7 @@ int batadv_tvlv_containers_process2(struct batadv_priv *bat_priv,
 						 tvlv_hdr->type,
 						 tvlv_hdr->version, tvlv_value,
 						 tvlv_value_cont_len, ctx);
-skip_handler_call:
+
 		tvlv_offset += tvlv_value_cont_len;
 		tvlv_value_len -= tvlv_value_cont_len;
 	}
@@ -626,7 +628,7 @@ int batadv_tvlv_containers_process(struct batadv_priv *bat_priv,
  * OGM header.
  */
 void batadv_tvlv_ogm_receive(struct batadv_priv *bat_priv,
-			     const struct sk_buff *skb,
+			     struct sk_buff *skb,
 			     struct batadv_orig_node *orig_node)
 {
 	struct batadv_ogm_packet *ogm_packet;
diff --git a/net/batman-adv/tvlv.h b/net/batman-adv/tvlv.h
index 3496f36..feae0ea 100644
--- a/net/batman-adv/tvlv.h
+++ b/net/batman-adv/tvlv.h
@@ -31,7 +31,7 @@ u16 batadv_tvlv_container_ogm_append(struct batadv_priv *bat_priv,
 				     unsigned char **packet_buff,
 				     int *packet_buff_len, int packet_min_len);
 void batadv_tvlv_ogm_receive(struct batadv_priv *bat_priv,
-			     const struct sk_buff *skb,
+			     struct sk_buff *skb,
 			     struct batadv_orig_node *orig_node);
 void batadv_tvlv_container_unregister(struct batadv_priv *bat_priv,
 				      u8 type, u8 version);
@@ -65,7 +65,7 @@ int batadv_tvlv_containers_process(struct batadv_priv *bat_priv,
 				   u8 *src, u8 *dst,
 				   void *tvlv_buff, u16 tvlv_buff_len);
 int batadv_tvlv_containers_process2(struct batadv_priv *bat_priv,
-				    const struct sk_buff *skb, u8 packet_type,
+				    struct sk_buff *skb, u8 packet_type,
 				    unsigned int tvlv_offset,
 				    u16 tvlv_value_len, void *ctx);
 void batadv_tvlv_unicast_send(struct batadv_priv *bat_priv, u8 *src,
-- 
2.1.4


  parent reply	other threads:[~2017-04-25  0:02 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-25  0:02 [B.A.T.M.A.N.] (no subject) Linus Lüssing
2017-04-25  0:02 ` [B.A.T.M.A.N.] [PATCH v3 1/5] batman-adv: Introduce packet type independent TVLV handler API Linus Lüssing
2017-04-25  0:02 ` Linus Lüssing [this message]
2017-04-25  0:02 ` [B.A.T.M.A.N.] [PATCH v3 3/5] batman-adv: aggregation packet reception Linus Lüssing
2017-04-25  0:02 ` [B.A.T.M.A.N.] [PATCH v3 4/5] batman-adv: aggregation packet queueing and transmission Linus Lüssing
2017-04-25  0:02 ` [B.A.T.M.A.N.] [PATCH v3 5/5] batman-adv: do not aggregate rebroadcasts in the same packet Linus Lüssing
2017-04-25  0:56 ` [B.A.T.M.A.N.] [PATCH v3 0/5] batman-adv: broadcast packet aggregation 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=20170425000218.23721-3-linus.luessing@c0d3.blue \
    --to=linus.luessing@c0d3.blue \
    --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).