Skip to contentSkip to conversation

ieee802154: llsec fix and get AF_PACKET working

PATCH In review Alexander Aring 2 participants 7 messages Sep 18, 2015 – Sep 21, 2015

Subsystems (3)
lore
Share & tools
lore

Alexander Aring

author maintainer
#0 lore raw

cover ieee802154: llsec fix and get AF_PACKET working

Hi,

this patch series contains at first a little fix for llsec which I currently working on (nl802154 support). The second patch fixes push header if we don't set the fc address modes.

Patch 3 and 4 contains fixes to get AF_PACKET for wpan intefaces working and cleanup the headroom/tailroom hard_header_len fields. This was broken "somehow" before, don't know if I can crash the kernel with that. I tried to figure out what we need to have some AF_PACKET use-case.

AF_PACKET:

AF_PACKET is very generic socket interface and provided RAW and DGRAM sockets.

For RAW sockets:
You need at least 3 bytes frame and it's also possible to send frames above 125, which we usually doesn't support. It will be dropped now at xmit callback. To fix it right we need special handling in AF_PACKET and right FCS extra_len arguments. This will be a new TODO.

For DGRAM sockets:

The semantic scheme for AF_PACKET DGRAM is set some maximum 8 byte destination address and send out the frame. Currently it's broken because we always assume "struct ieee802154_addr" there which is also above 8 bytes. The new "create" callback which is used by AF_PACKET DGRAM sockets assumes now always an extended_addr and doing intra_pan dataframe afterwards, fc fields like ackreq, security is set with fallback defaults.

For what's it's good for?

I think the RAW socket is useful to have and we should replace it with AF802154 RAW sockets. The AF_PACKET mode is usually known and AF802154 RAW sockets should to the same like AF_PACKET RAW sockets. (And I know AF802154 RAW sockets are somehow broken currently.)

The DGRAM sockets has a small use-case if somebody wants to send "somehow" a frame, if you need another destination address or short address then you need AF802154 (or the successor of this socket family). Nevertheless I implement now the create/parse address for extended address only to have something there which works. Not sure if we should really support DGRAM sockets for AF_PACKET because the UAPI has limitations which doesn't fit to 802.15.4 address space.

In general a nice to have is now to create "AF_PACKET RAW sockets" and generate some 6LoWPAN frames in userspace in combination with the fakelb driver. I think we can do a nice testing framework with that. Also in Python, I tested to send out AF_PACKET raw over python. (DGRAM sockets are not supported by python, don't know why).

The tailroom, headroom, hard_header_len values has a new semantic what we mean with that and I hope the core network stack means the same then.

- needed_headroom:
The needed_headroom means we need for callbacks like dev_hard_header at minimum a before allocated headroom which is this size. This is usually the WORST-CASE scenario by calling skb_push, which moves headroom into dataspace (start of buffer). This room is also available inside the xmit callback.

- needed_tailroom:
Same like headroom but for the tail where the FCS is placed.

- hard_header_len:
skb->len, where skb_mac_header is placed should be more than hard_header_len. I saw this for AF_PACKET RAW sockets and this is the minimum lengths which need to be there before calling xmit callback. At our case this is 3 bytes, which is an ACK frame and contains fc fields, already there are also drivers which checks on fc field in driver layer. For lowpan interface we need at least ipv6hdr to uncompress it.

What this patch series does now is to move hard_header_len length (which is maximum size of mac header) to needed_headroom. The hard_header_len is now the minimum size for a mac header. I lookup 802.15.4 upper-layer protocols and changed at points like lowpan hard_header_len to needed_headroom. At AF802154 they use LL_RESERVED_SPACE which does some "needed_headroom + hard_header_len" calculation, so it should be fine.

- Alex

Alexander Aring (5):
mac802154: llsec: fix device deletion from list
ieee802154: header_ops: fix frame control setting
ieee802154: introduce wpan_dev_header_ops
ieee802154: change needed headroom/tailroom
mac802154: tx: add warning if MTU exceeds

 include/linux/ieee802154.h      |  11 ++++
 include/net/6lowpan.h           |   8 +++
 include/net/cfg802154.h         |  33 ++++++++++++
 include/net/ieee802154_netdev.h |  11 +---
 include/net/mac802154.h         |   8 ---
 net/6lowpan/nhc.h               |   2 -
 net/ieee802154/6lowpan/core.c   |  14 ++++--
 net/ieee802154/6lowpan/tx.c     |  20 +++++---
 net/ieee802154/header_ops.c     |  20 ++++----
 net/ieee802154/socket.c         |   4 +-
 net/mac802154/iface.c           | 108 ++++++++++++++++++++++++++++++++++------
 net/mac802154/llsec.c           |   1 +
 net/mac802154/tx.c              |  14 ++++--
 13 files changed, 195 insertions(+), 59 deletions(-)
Signature · 1 line
2.5.2
author maintainer
#1 lore raw

PATCH 1/5 mac802154: llsec: fix device deletion from list

This patch adds a missing list_del when a device description will be deleted.

Cc Phoebe Buckheister <[email protected]>
---
 net/mac802154/llsec.c | 1 +
 1 file changed, 1 insertion(+)
net/mac802154/llsec.c +1 -0
index 985e939..7799d3c 100644
@@ -401,6 +401,7 @@ int mac802154_llsec_dev_del(struct mac802154_llsec *sec, __le64 device_addr)
 
 	hash_del_rcu(&pos->bucket_s);
 	hash_del_rcu(&pos->bucket_hw);
+	list_del_rcu(&pos->dev.list);
 	call_rcu(&pos->rcu, llsec_dev_free_rcu);
 
 	return 0;
Signature · 1 line
2.5.2
author maintainer
#2 lore raw

PATCH 2/5 ieee802154: header_ops: fix frame control setting

In reply to Alexander Aring

Sometimes upper-layer protocols wants to generate a new mac header by filling "struct ieee802154_hdr" only. These upper-layers sets for the address settings the source and dest fields, but not the fc fields for indicate the source and dest address mode. This patch changes the "ieee802154_hdr_push" function so the fc address fields are set according the source and dest fields of "struct ieee802154_hdr".

---
 include/net/ieee802154_netdev.h |  2 +-
 net/ieee802154/header_ops.c     | 18 +++++++++---------
 2 files changed, 10 insertions(+), 10 deletions(-)
include/net/ieee802154_netdev.h +1 -1
index 2c10a9f..95a71bc 100644
@@ -99,7 +99,7 @@ struct ieee802154_hdr {
  * hdr->fc will be ignored. this includes the INTRA_PAN bit and the frame
  * version, if SECEN is set.
  */
-int ieee802154_hdr_push(struct sk_buff *skb, const struct ieee802154_hdr *hdr);
+int ieee802154_hdr_push(struct sk_buff *skb, struct ieee802154_hdr *hdr);
 
 /* pulls the entire 802.15.4 header off of the skb, including the security
  * header, and performs pan id decompression
net/ieee802154/header_ops.c +9 -9
index a051b69..d8443b0 100644
@@ -83,35 +83,35 @@ ieee802154_hdr_push_sechdr(u8 *buf, const struct ieee802154_sechdr *hdr)
 }
 
 int
-ieee802154_hdr_push(struct sk_buff *skb, const struct ieee802154_hdr *hdr)
+ieee802154_hdr_push(struct sk_buff *skb, struct ieee802154_hdr *hdr)
 {
 	u8 buf[MAC802154_FRAME_HARD_HEADER_LEN];
 	int pos = 2;
 	int rc;
-	struct ieee802154_hdr_fc fc = hdr->fc;
+	struct ieee802154_hdr_fc *fc = &hdr->fc;
 
 	buf[pos++] = hdr->seq;
 
-	fc.dest_addr_mode = hdr->dest.mode;
+	fc->dest_addr_mode = hdr->dest.mode;
 
 	rc = ieee802154_hdr_push_addr(buf + pos, &hdr->dest, false);
 	if (rc < 0)
 		return -EINVAL;
 	pos += rc;
 
-	fc.source_addr_mode = hdr->source.mode;
+	fc->source_addr_mode = hdr->source.mode;
 
 	if (hdr->source.pan_id == hdr->dest.pan_id &&
 	    hdr->dest.mode != IEEE802154_ADDR_NONE)
-		fc.intra_pan = true;
+		fc->intra_pan = true;
 
-	rc = ieee802154_hdr_push_addr(buf + pos, &hdr->source, fc.intra_pan);
+	rc = ieee802154_hdr_push_addr(buf + pos, &hdr->source, fc->intra_pan);
 	if (rc < 0)
 		return -EINVAL;
 	pos += rc;
 
-	if (fc.security_enabled) {
-		fc.version = 1;
+	if (fc->security_enabled) {
+		fc->version = 1;
 
 		rc = ieee802154_hdr_push_sechdr(buf + pos, &hdr->sec);
 		if (rc < 0)
@@ -120,7 +120,7 @@ ieee802154_hdr_push(struct sk_buff *skb, const struct ieee802154_hdr *hdr)
 		pos += rc;
 	}
 
-	memcpy(buf, &fc, 2);
+	memcpy(buf, fc, 2);
 
 	memcpy(skb_push(skb, pos), buf, pos);
 
Signature · 1 line
2.5.2
author maintainer
#3 lore raw

PATCH 3/5 ieee802154: introduce wpan_dev_header_ops

In reply to Alexander Aring

The current header_ops callback structure of net device are used mostly from 802.15.4 upper-layers. Because this callback structure is a very generic one, which is also used by e.g. DGRAM AF_PACKET sockets, we can't make this callback structure 802.15.4 specific which is currently is.

I saw the smallest "constraint" for calling this callback with dev_hard_header/dev_parse_header by AF_PACKET which assign a 8 byte array for address void pointers. Currently 802.15.4 specific protocols like af802154 and 6LoWPAN will assign the "struct ieee802154_addr" as these parameters which is greater than 8 bytes. The current callback implementation for header_ops.create assumes always a complete "struct ieee802154_addr" which AF_PACKET can't never handled and is greater than 8 bytes.

For that reason we introduce now a "generic" create/parse header_ops callback which allows handling with intra-pan extended addresses only. This allows a small use-case with AF_PACKET to send "somehow" a valid dataframe over DGRAM.

To keeping the current dev_hard_header behaviour we introduce a similar callback structure "wpan_dev_header_ops" which contains 802.15.4 specific upper-layer header creation functionality, which can be called by wpan_dev_hard_header.

---
 include/net/cfg802154.h         | 33 +++++++++++++++
 include/net/ieee802154_netdev.h |  9 ----
 net/ieee802154/6lowpan/tx.c     |  8 ++--
 net/ieee802154/socket.c         |  4 +-
 net/mac802154/iface.c           | 91 +++++++++++++++++++++++++++++++++++------
 5 files changed, 118 insertions(+), 27 deletions(-)
include/net/cfg802154.h +33 -0
index 76b1ffa..242273c 100644
@@ -167,6 +167,26 @@ struct wpan_phy {
 	char priv[0] __aligned(NETDEV_ALIGN);
 };
 
+struct ieee802154_addr {
+	u8 mode;
+	__le16 pan_id;
+	union {
+		__le16 short_addr;
+		__le64 extended_addr;
+	};
+};
+
+struct wpan_dev_header_ops {
+	/* TODO create callback currently assumes ieee802154_mac_cb inside
+	 * skb->cb. This should be changed to give these information as
+	 * parameter.
+	 */
+	int	(*create)(struct sk_buff *skb, struct net_device *dev,
+			  const struct ieee802154_addr *daddr,
+			  const struct ieee802154_addr *saddr,
+			  unsigned int len);
+};
+
 struct wpan_dev {
 	struct wpan_phy *wpan_phy;
 	int iftype;
@@ -175,6 +195,8 @@ struct wpan_dev {
 	struct list_head list;
 	struct net_device *netdev;
 
+	const struct wpan_dev_header_ops *header_ops;
+
 	/* lowpan interface, set when the wpan_dev belongs to one lowpan_dev */
 	struct net_device *lowpan_dev;
 
@@ -205,6 +227,17 @@ struct wpan_dev {
 
 #define to_phy(_dev)	container_of(_dev, struct wpan_phy, dev)
 
+static inline int
+wpan_dev_hard_header(struct sk_buff *skb, struct net_device *dev,
+		     const struct ieee802154_addr *daddr,
+		     const struct ieee802154_addr *saddr,
+		     unsigned int len)
+{
+	struct wpan_dev *wpan_dev = dev->ieee802154_ptr;
+
+	return wpan_dev->header_ops->create(skb, dev, daddr, saddr, len);
+}
+
 struct wpan_phy *
 wpan_phy_new(const struct cfg802154_ops *ops, size_t priv_size);
 static inline void wpan_phy_set_dev(struct wpan_phy *phy, struct device *dev)
include/net/ieee802154_netdev.h +0 -9
index 95a71bc..aebb9d8 100644
@@ -50,15 +50,6 @@ struct ieee802154_sechdr {
 	};
 };
 
-struct ieee802154_addr {
-	u8 mode;
-	__le16 pan_id;
-	union {
-		__le16 short_addr;
-		__le64 extended_addr;
-	};
-};
-
 struct ieee802154_hdr_fc {
 #if defined(__LITTLE_ENDIAN_BITFIELD)
 	u16 type:3,
net/ieee802154/6lowpan/tx.c +4 -4
index 54939d0..6067e06 100644
@@ -87,8 +87,8 @@ lowpan_alloc_frag(struct sk_buff *skb, int size,
 		skb_reset_network_header(frag);
 		*mac_cb(frag) = *mac_cb(skb);
 
-		rc = dev_hard_header(frag, wdev, 0, &master_hdr->dest,
-				     &master_hdr->source, size);
+		rc = wpan_dev_hard_header(frag, wdev, &master_hdr->dest,
+					  &master_hdr->source, size);
 		if (rc < 0) {
 			kfree_skb(frag);
 			return ERR_PTR(rc);
@@ -228,8 +228,8 @@ static int lowpan_header(struct sk_buff *skb, struct net_device *ldev,
 		cb->ackreq = wpan_dev->ackreq;
 	}
 
-	return dev_hard_header(skb, lowpan_dev_info(ldev)->wdev, ETH_P_IPV6,
-			       (void *)&da, (void *)&sa, 0);
+	return wpan_dev_hard_header(skb, lowpan_dev_info(ldev)->wdev, &da, &sa,
+				    0);
 }
 
 netdev_tx_t lowpan_xmit(struct sk_buff *skb, struct net_device *ldev)
net/ieee802154/socket.c +2 -2
index b6eacf3..be77f21 100644
@@ -676,8 +676,8 @@ static int dgram_sendmsg(struct sock *sk, struct msghdr *msg, size_t size)
 	cb->seclevel = ro->seclevel;
 	cb->seclevel_override = ro->seclevel_override;
 
-	err = dev_hard_header(skb, dev, ETH_P_IEEE802154, &dst_addr,
-			      ro->bound ? &ro->src_addr : NULL, size);
+	err = wpan_dev_hard_header(skb, dev, &dst_addr,
+				   ro->bound ? &ro->src_addr : NULL, size);
 	if (err < 0)
 		goto out_skb;
 
net/mac802154/iface.c +79 -12

121 lines not on this page · raw message

Signature · 1 line
2.5.2
author maintainer
#4 lore raw

PATCH 4/5 ieee802154: change needed headroom/tailroom

In reply to Alexander Aring

This patch cleanups needed_headroom, needed_tailroom and hard_header_len fields for wpan and lowpan interfaces.

For wpan interfaces the worst case mac header len should be part of needed_headroom, currently this is set as hard_header_len, but hard_header_len should be set to the minimum header length which xmit call assumes and this is the minimum frame length of 802.15.4. The hard_header_len value will check inside send callbacl of AF_PACKET raw sockets.

For lowpan interfaces, if fragmentation isn't needed the skb will call dev_hard_header for 802154 layer and queue it afterwards. This happens without new skb allocation, so we need the same headroom and tailroom lengths like 802154 inside 802154 6lowpan layer. At least we assume as minimum header length an ipv6 header size.

---
 include/linux/ieee802154.h    | 11 +++++++++++
 include/net/6lowpan.h         |  8 ++++++++
 include/net/mac802154.h       |  8 --------
 net/6lowpan/nhc.h             |  2 --
 net/ieee802154/6lowpan/core.c | 14 +++++++++++---
 net/ieee802154/6lowpan/tx.c   | 12 ++++++++++--
 net/ieee802154/header_ops.c   |  2 +-
 net/mac802154/iface.c         | 17 ++++++++++++++---
 net/mac802154/tx.c            |  3 ---
 9 files changed, 55 insertions(+), 22 deletions(-)
include/linux/ieee802154.h +11 -0
index db01492..205ce4e 100644
@@ -31,6 +31,17 @@
 #define IEEE802154_ACK_PSDU_LEN		5
 #define IEEE802154_MIN_PSDU_LEN		9
 #define IEEE802154_FCS_LEN		2
+#define IEEE802154_MAX_AUTH_TAG_LEN	16
+
+/*  General MAC frame format:
+ *  2 bytes: Frame Control
+ *  1 byte:  Sequence Number
+ * 20 bytes: Addressing fields
+ * 14 bytes: Auxiliary Security Header
+ */
+#define IEEE802154_MAX_HEADER_LEN	(2 + 1 + 20 + 14)
+#define IEEE802154_MIN_HEADER_LEN	(IEEE802154_ACK_PSDU_LEN - \
+					 IEEE802154_FCS_LEN)
 
 #define IEEE802154_PAN_ID_BROADCAST	0xffff
 #define IEEE802154_ADDR_SHORT_BROADCAST	0xffff
include/net/6lowpan.h +8 -0
index eeae5eb..c17f556 100644
@@ -61,6 +61,14 @@
 #define UIP_PROTO_UDP			17 /* ipv6 next header value for UDP */
 #define UIP_FRAGH_LEN			8  /* ipv6 fragment header size */
 
+#define LOWPAN_NHC_MAX_ID_LEN	1
+/* Max IPHC Header len without IPv6 hdr specific inline data.
+ * Useful for getting the "extra" bytes we need at worst case compression.
+ *
+ * LOWPAN_IPHC + CID + LOWPAN_NHC_MAX_ID_LEN
+ */
+#define LOWPAN_IPHC_MAX_HEADER_LEN	(2 + 1 + LOWPAN_NHC_MAX_ID_LEN)
+
 /*
  * ipv6 address based on mac
  * second bit-flip (Universe/Local) is done according RFC2464
include/net/mac802154.h +0 -8
index 32bd7c0..2c47850 100644
@@ -23,14 +23,6 @@
 
 #include <net/cfg802154.h>
 
-/* General MAC frame format:
- *  2 bytes: Frame Control
- *  1 byte:  Sequence Number
- * 20 bytes: Addressing fields
- * 14 bytes: Auxiliary Security Header
- */
-#define MAC802154_FRAME_HARD_HEADER_LEN		(2 + 1 + 20 + 14)
-
 /**
  * enum ieee802154_hw_addr_filt_flags - hardware address filtering flags
  *
net/6lowpan/nhc.h +0 -2
index ed44938..c249f17 100644
@@ -8,8 +8,6 @@
 #include <net/6lowpan.h>
 #include <net/ipv6.h>
 
-#define LOWPAN_NHC_MAX_ID_LEN	1
-
 /**
  * LOWPAN_NHC - helper macro to generate nh id fields and lowpan_nhc struct
  *
net/ieee802154/6lowpan/core.c +11 -3
index 9f0cfa5..44420ed 100644
@@ -104,9 +104,8 @@ static void lowpan_setup(struct net_device *ldev)
 	ldev->addr_len		= IEEE802154_ADDR_LEN;
 	memset(ldev->broadcast, 0xff, IEEE802154_ADDR_LEN);
 	ldev->type		= ARPHRD_6LOWPAN;
-	/* Frame Control + Sequence Number + Address fields + Security Header */
-	ldev->hard_header_len	= 2 + 1 + 20 + 14;
-	ldev->needed_tailroom	= 2; /* FCS */
+	/* We need an ipv6hdr as minimum len when calling xmit */
+	ldev->hard_header_len	= sizeof(struct ipv6hdr);
 	ldev->mtu		= IPV6_MIN_MTU;
 	ldev->priv_flags	|= IFF_NO_QUEUE;
 	ldev->flags		= IFF_BROADCAST | IFF_MULTICAST;
@@ -156,6 +155,15 @@ static int lowpan_newlink(struct net *src_net, struct net_device *ldev,
 	lowpan_dev_info(ldev)->wdev = wdev;
 	/* Set the lowpan hardware address to the wpan hardware address. */
 	memcpy(ldev->dev_addr, wdev->dev_addr, IEEE802154_ADDR_LEN);
+	/* We need headroom for possible wpan_dev_hard_header call and tailroom
+	 * for encryption/fcs handling. The lowpan interface will replace
+	 * the IPv6 header with 6LoWPAN header. At worst case the 6LoWPAN
+	 * header has LOWPAN_IPHC_MAX_HEADER_LEN more bytes than the IPv6
+	 * header.
+	 */
+	ldev->needed_headroom = LOWPAN_IPHC_MAX_HEADER_LEN +
+				wdev->needed_headroom;
+	ldev->needed_tailroom = wdev->needed_tailroom;
 
 	lowpan_netdev_setup(ldev, LOWPAN_LLTYPE_IEEE802154);
 
net/ieee802154/6lowpan/tx.c +10 -2
index 6067e06..7e0563e 100644
@@ -10,6 +10,7 @@
 
 #include <net/6lowpan.h>
 #include <net/ieee802154_netdev.h>
+#include <net/mac802154.h>
 
 #include "6lowpan_i.h"
 
@@ -36,6 +37,13 @@ lowpan_addr_info *lowpan_skb_priv(const struct sk_buff *skb)
 			sizeof(struct lowpan_addr_info));
 }
 
+/* This callback will be called from AF_PACKET and IPv6 stack, the AF_PACKET
+ * sockets gives an 8 byte array for addresses only!
+ *
+ * TODO I think AF_PACKET DGRAM (sending/receiving) RAW (sending) makes no
+ * sense here. We should disable it, the right use-case would be AF_INET6
+ * RAW/DGRAM sockets.
+ */
 int lowpan_header_create(struct sk_buff *skb, struct net_device *ldev,
 			 unsigned short type, const void *_daddr,
 			 const void *_saddr, unsigned int len)
@@ -77,13 +85,13 @@ lowpan_alloc_frag(struct sk_buff *skb, int size,
 	struct sk_buff *frag;
 	int rc;
 
-	frag = alloc_skb(wdev->hard_header_len + wdev->needed_tailroom + size,
+	frag = alloc_skb(wdev->needed_headroom + wdev->needed_tailroom + size,
 			 GFP_ATOMIC);
 
 	if (likely(frag)) {
 		frag->dev = wdev;
 		frag->priority = skb->priority;
-		skb_reserve(frag, wdev->hard_header_len);
+		skb_reserve(frag, wdev->needed_headroom);
 		skb_reset_network_header(frag);
 		*mac_cb(frag) = *mac_cb(skb);
 
net/ieee802154/header_ops.c +1 -1
index d8443b0..c7439f0 100644
@@ -85,7 +85,7 @@ ieee802154_hdr_push_sechdr(u8 *buf, const struct ieee802154_sechdr *hdr)
 int
 ieee802154_hdr_push(struct sk_buff *skb, struct ieee802154_hdr *hdr)
 {
-	u8 buf[MAC802154_FRAME_HARD_HEADER_LEN];
+	u8 buf[IEEE802154_MAX_HEADER_LEN];
 	int pos = 2;
 	int rc;
 	struct ieee802154_hdr_fc *fc = &hdr->fc;
net/mac802154/iface.c +14 -3
index 8afe26d..b5a0936 100644
@@ -537,8 +537,18 @@ static void ieee802154_if_setup(struct net_device *dev)
 	dev->addr_len		= IEEE802154_EXTENDED_ADDR_LEN;
 	memset(dev->broadcast, 0xff, IEEE802154_EXTENDED_ADDR_LEN);
 
-	dev->hard_header_len	= MAC802154_FRAME_HARD_HEADER_LEN;
-	dev->needed_tailroom	= 2 + 16; /* FCS + MIC */
+	/* Let hard_header_len set to IEEE802154_MIN_HEADER_LEN. AF_PACKET
+	 * will not send frames without any payload, but ack frames
+	 * has no payload, so substract one that we can send a 3 bytes
+	 * frame. The xmit callback assumes at least a hard header where two
+	 * bytes fc and sequence field are set.
+	 */
+	dev->hard_header_len	= IEEE802154_MIN_HEADER_LEN - 1;
+	/* The auth_tag header is for security and places in private payload
+	 * room of mac frame which stucks between payload and FCS field.
+	 */
+	dev->needed_tailroom	= IEEE802154_MAX_AUTH_TAG_LEN +
+				  IEEE802154_FCS_LEN;
 	dev->mtu		= IEEE802154_MTU;
 	dev->tx_queue_len	= 300;
 	dev->flags		= IFF_NOARP | IFF_BROADCAST;
@@ -617,7 +627,8 @@ ieee802154_if_add(struct ieee802154_local *local, const char *name,
 	if (!ndev)
 		return ERR_PTR(-ENOMEM);
 
-	ndev->needed_headroom = local->hw.extra_tx_headroom;
+	ndev->needed_headroom = local->hw.extra_tx_headroom +
+				IEEE802154_MAX_HEADER_LEN;
 
 	ret = dev_alloc_name(ndev, ndev->name);
 	if (ret < 0)
net/mac802154/tx.c +0 -3
index 7ed4391..66d7ecb 100644
@@ -77,9 +77,6 @@ ieee802154_tx(struct ieee802154_local *local, struct sk_buff *skb)
 		put_unaligned_le16(crc, skb_put(skb, 2));
 	}
 
-	if (skb_cow_head(skb, local->hw.extra_tx_headroom))
-		goto err_tx;
-
 	/* Stop the netif queue on each sub_if_data object. */
 	ieee802154_stop_queue(&local->hw);
 
Signature · 1 line
2.5.2
author maintainer
#5 lore raw

PATCH 5/5 mac802154: tx: add warning if MTU exceeds

In reply to Alexander Aring

Sending over AF_PACKET RAW sockets we can sending frames which exceeds MTU size. To handling it correct we need to change things in AF_PACKET which knows on RAW sockets an additional FCS is set by hardware or mac802154 transmit functionality.

---
 net/mac802154/tx.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
net/mac802154/tx.c +11 -0
index 66d7ecb..5ee596e 100644
@@ -71,6 +71,17 @@ ieee802154_tx(struct ieee802154_local *local, struct sk_buff *skb)
 	struct net_device *dev = skb->dev;
 	int ret;
 
+	/* This check is for AF_PACKET RAW socket only, which doesn't
+	 * know about the FCS which is set here or by hardware. otherwise
+	 * it should not occur in any case!
+	 *
+	 * TODO: This should be handled in AF_PACKET and return -EMSGSIZE.
+	 */
+	if (skb->len > IEEE802154_MTU - IEEE802154_FCS_LEN) {
+		netdev_warn(dev, "Frame len above MTU limit. Dropped.\n");
+		goto err_tx;
+	}
+
 	if (!(local->hw.flags & IEEE802154_HW_TX_OMIT_CKSUM)) {
 		u16 crc = crc_ccitt(0, skb->data, skb->len);
 
Signature · 1 line
2.5.2
#6 lore raw
In reply to Alexander Aring

Hi Alex,

Quoted 83 lines

this patch series contains at first a little fix for llsec which I currently working on (nl802154 support). The second patch fixes push header if we don't set the fc address modes.

Patch 3 and 4 contains fixes to get AF_PACKET for wpan intefaces working and cleanup the headroom/tailroom hard_header_len fields. This was broken "somehow" before, don't know if I can crash the kernel with that. I tried to figure out what we need to have some AF_PACKET use-case.

AF_PACKET:

AF_PACKET is very generic socket interface and provided RAW and DGRAM sockets.

For RAW sockets:
You need at least 3 bytes frame and it's also possible to send frames above 125, which we usually doesn't support. It will be dropped now at xmit callback. To fix it right we need special handling in AF_PACKET and right FCS extra_len arguments. This will be a new TODO.

For DGRAM sockets:

The semantic scheme for AF_PACKET DGRAM is set some maximum 8 byte destination address and send out the frame. Currently it's broken because we always assume "struct ieee802154_addr" there which is also above 8 bytes. The new "create" callback which is used by AF_PACKET DGRAM sockets assumes now always an extended_addr and doing intra_pan dataframe afterwards, fc fields like ackreq, security is set with fallback defaults.

For what's it's good for?

I think the RAW socket is useful to have and we should replace it with AF802154 RAW sockets. The AF_PACKET mode is usually known and AF802154 RAW sockets should to the same like AF_PACKET RAW sockets. (And I know AF802154 RAW sockets are somehow broken currently.)

The DGRAM sockets has a small use-case if somebody wants to send "somehow" a frame, if you need another destination address or short address then you need AF802154 (or the successor of this socket family). Nevertheless I implement now the create/parse address for extended address only to have something there which works. Not sure if we should really support DGRAM sockets for AF_PACKET because the UAPI has limitations which doesn't fit to 802.15.4 address space.

In general a nice to have is now to create "AF_PACKET RAW sockets" and generate some 6LoWPAN frames in userspace in combination with the fakelb driver. I think we can do a nice testing framework with that. Also in Python, I tested to send out AF_PACKET raw over python. (DGRAM sockets are not supported by python, don't know why).

The tailroom, headroom, hard_header_len values has a new semantic what we mean with that and I hope the core network stack means the same then.

- needed_headroom:
The needed_headroom means we need for callbacks like dev_hard_header at minimum a before allocated headroom which is this size. This is usually the WORST-CASE scenario by calling skb_push, which moves headroom into dataspace (start of buffer). This room is also available inside the xmit callback.

- needed_tailroom:
Same like headroom but for the tail where the FCS is placed.

- hard_header_len:
skb->len, where skb_mac_header is placed should be more than hard_header_len. I saw this for AF_PACKET RAW sockets and this is the minimum lengths which need to be there before calling xmit callback. At our case this is 3 bytes, which is an ACK frame and contains fc fields, already there are also drivers which checks on fc field in driver layer. For lowpan interface we need at least ipv6hdr to uncompress it.

What this patch series does now is to move hard_header_len length (which is maximum size of mac header) to needed_headroom. The hard_header_len is now the minimum size for a mac header. I lookup 802.15.4 upper-layer protocols and changed at points like lowpan hard_header_len to needed_headroom. At AF802154 they use LL_RESERVED_SPACE which does some "needed_headroom + hard_header_len" calculation, so it should be fine.

- Alex

Alexander Aring (5):
mac802154: llsec: fix device deletion from list
ieee802154: header_ops: fix frame control setting
ieee802154: introduce wpan_dev_header_ops
ieee802154: change needed headroom/tailroom
mac802154: tx: add warning if MTU exceeds

Quoted 14 lines
include/linux/ieee802154.h      |  11 ++++
include/net/6lowpan.h           |   8 +++
include/net/cfg802154.h         |  33 ++++++++++++
include/net/ieee802154_netdev.h |  11 +---
include/net/mac802154.h         |   8 ---
net/6lowpan/nhc.h               |   2 -
net/ieee802154/6lowpan/core.c   |  14 ++++--
net/ieee802154/6lowpan/tx.c     |  20 +++++---
net/ieee802154/header_ops.c     |  20 ++++----
net/ieee802154/socket.c         |   4 +-
net/mac802154/iface.c           | 108 ++++++++++++++++++++++++++++++++++------
net/mac802154/llsec.c           |   1 +
net/mac802154/tx.c              |  14 ++++--
13 files changed, 195 insertions(+), 59 deletions(-)

all 5 patches have been applied to bluetooth-next tree.

Regards

Marcel