lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Tue, 13 May 2014 19:24:03 +0200
From:	Phoebe Buckheister <phoebe.buckheister@...m.fraunhofer.de>
To:	netdev@...r.kernel.org
Cc:	linux-zigbee-devel@...ts.sourceforge.net, davem@...emloft.net,
	Phoebe Buckheister <phoebe.buckheister@...m.fraunhofer.de>
Subject: [PATCH net-next 2/5] 6lowpan: simplify/fix payload length calculation

Instead of accounting for all fields of a packet we can think about,
simply peek the header of a packet we're building and ask ieee802154 how
many bytes of payload space we have. This also accounts for security
headers, which were ignored previously.

Signed-off-by: Phoebe Buckheister <phoebe.buckheister@...m.fraunhofer.de>
---
 net/ieee802154/6lowpan_rtnl.c |   24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/net/ieee802154/6lowpan_rtnl.c b/net/ieee802154/6lowpan_rtnl.c
index 0f5a69e..3e11b46 100644
--- a/net/ieee802154/6lowpan_rtnl.c
+++ b/net/ieee802154/6lowpan_rtnl.c
@@ -256,6 +256,19 @@ lowpan_fragment_xmit(struct sk_buff *skb, u8 *head,
 	return dev_queue_xmit(frag);
 }
 
+static int lowpan_fragment_plen(struct sk_buff *skb, int extra)
+{
+	struct ieee802154_hdr hdr;
+
+	ieee802154_hdr_peek(skb, &hdr);
+
+	/* calc the nearest payload length(divided to 8) for a fragment with
+	 * a given 802.15.4 hdr and additional lowpan headers which fits into
+	 * IEEE802154_MTU
+	 */
+	return round_down(ieee802154_max_payload(&hdr) - extra, 8);
+}
+
 static int
 lowpan_skb_fragmentation(struct sk_buff *skb, struct net_device *dev)
 {
@@ -277,12 +290,8 @@ lowpan_skb_fragmentation(struct sk_buff *skb, struct net_device *dev)
 	head[1] = dgram_size & 0xff;
 	memcpy(head + 2, &tag, sizeof(tag));
 
-	/* calc the nearest payload length(divided to 8) for first fragment
-	 * which fits into a IEEE802154_MTU
-	 */
-	frag_plen = round_down(IEEE802154_MTU - header_length -
-			       LOWPAN_FRAG1_HEAD_SIZE - lowpan_size -
-			       IEEE802154_MFR_SIZE, 8);
+	frag_plen = lowpan_fragment_plen(skb, LOWPAN_FRAG1_HEAD_SIZE +
+					 lowpan_size);
 
 	err = lowpan_fragment_xmit(skb, head, header_length,
 				   frag_plen + lowpan_size, 0,
@@ -300,8 +309,7 @@ lowpan_skb_fragmentation(struct sk_buff *skb, struct net_device *dev)
 	head[0] &= ~LOWPAN_DISPATCH_FRAG1;
 	head[0] |= LOWPAN_DISPATCH_FRAGN;
 
-	frag_plen = round_down(IEEE802154_MTU - header_length -
-			       LOWPAN_FRAGN_HEAD_SIZE - IEEE802154_MFR_SIZE, 8);
+	frag_plen = lowpan_fragment_plen(skb, LOWPAN_FRAGN_HEAD_SIZE);
 
 	while (payload_length - offset > 0) {
 		int len = frag_plen;
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ