Skip to content

Commit 87a93e4

Browse files
alexaringholtmann
authored andcommitted
ieee802154: change needed headroom/tailroom
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. Signed-off-by: Alexander Aring <alex.aring@gmail.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
1 parent 838b83d commit 87a93e4

9 files changed

Lines changed: 55 additions & 22 deletions

File tree

‎include/linux/ieee802154.h‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@
3131
#define IEEE802154_ACK_PSDU_LEN 5
3232
#define IEEE802154_MIN_PSDU_LEN 9
3333
#define IEEE802154_FCS_LEN 2
34+
#define IEEE802154_MAX_AUTH_TAG_LEN 16
35+
36+
/* General MAC frame format:
37+
* 2 bytes: Frame Control
38+
* 1 byte: Sequence Number
39+
* 20 bytes: Addressing fields
40+
* 14 bytes: Auxiliary Security Header
41+
*/
42+
#define IEEE802154_MAX_HEADER_LEN (2 + 1 + 20 + 14)
43+
#define IEEE802154_MIN_HEADER_LEN (IEEE802154_ACK_PSDU_LEN - \
44+
IEEE802154_FCS_LEN)
3445

3546
#define IEEE802154_PAN_ID_BROADCAST 0xffff
3647
#define IEEE802154_ADDR_SHORT_BROADCAST 0xffff

‎include/net/6lowpan.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@
6161
#define UIP_PROTO_UDP 17 /* ipv6 next header value for UDP */
6262
#define UIP_FRAGH_LEN 8 /* ipv6 fragment header size */
6363

64+
#define LOWPAN_NHC_MAX_ID_LEN 1
65+
/* Max IPHC Header len without IPv6 hdr specific inline data.
66+
* Useful for getting the "extra" bytes we need at worst case compression.
67+
*
68+
* LOWPAN_IPHC + CID + LOWPAN_NHC_MAX_ID_LEN
69+
*/
70+
#define LOWPAN_IPHC_MAX_HEADER_LEN (2 + 1 + LOWPAN_NHC_MAX_ID_LEN)
71+
6472
/*
6573
* ipv6 address based on mac
6674
* second bit-flip (Universe/Local) is done according RFC2464

‎include/net/mac802154.h‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,6 @@
2323

2424
#include <net/cfg802154.h>
2525

26-
/* General MAC frame format:
27-
* 2 bytes: Frame Control
28-
* 1 byte: Sequence Number
29-
* 20 bytes: Addressing fields
30-
* 14 bytes: Auxiliary Security Header
31-
*/
32-
#define MAC802154_FRAME_HARD_HEADER_LEN (2 + 1 + 20 + 14)
33-
3426
/**
3527
* enum ieee802154_hw_addr_filt_flags - hardware address filtering flags
3628
*

‎net/6lowpan/nhc.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
#include <net/6lowpan.h>
99
#include <net/ipv6.h>
1010

11-
#define LOWPAN_NHC_MAX_ID_LEN 1
12-
1311
/**
1412
* LOWPAN_NHC - helper macro to generate nh id fields and lowpan_nhc struct
1513
*

‎net/ieee802154/6lowpan/core.c‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,8 @@ static void lowpan_setup(struct net_device *ldev)
104104
ldev->addr_len = IEEE802154_ADDR_LEN;
105105
memset(ldev->broadcast, 0xff, IEEE802154_ADDR_LEN);
106106
ldev->type = ARPHRD_6LOWPAN;
107-
/* Frame Control + Sequence Number + Address fields + Security Header */
108-
ldev->hard_header_len = 2 + 1 + 20 + 14;
109-
ldev->needed_tailroom = 2; /* FCS */
107+
/* We need an ipv6hdr as minimum len when calling xmit */
108+
ldev->hard_header_len = sizeof(struct ipv6hdr);
110109
ldev->mtu = IPV6_MIN_MTU;
111110
ldev->priv_flags |= IFF_NO_QUEUE;
112111
ldev->flags = IFF_BROADCAST | IFF_MULTICAST;
@@ -156,6 +155,15 @@ static int lowpan_newlink(struct net *src_net, struct net_device *ldev,
156155
lowpan_dev_info(ldev)->wdev = wdev;
157156
/* Set the lowpan hardware address to the wpan hardware address. */
158157
memcpy(ldev->dev_addr, wdev->dev_addr, IEEE802154_ADDR_LEN);
158+
/* We need headroom for possible wpan_dev_hard_header call and tailroom
159+
* for encryption/fcs handling. The lowpan interface will replace
160+
* the IPv6 header with 6LoWPAN header. At worst case the 6LoWPAN
161+
* header has LOWPAN_IPHC_MAX_HEADER_LEN more bytes than the IPv6
162+
* header.
163+
*/
164+
ldev->needed_headroom = LOWPAN_IPHC_MAX_HEADER_LEN +
165+
wdev->needed_headroom;
166+
ldev->needed_tailroom = wdev->needed_tailroom;
159167

160168
lowpan_netdev_setup(ldev, LOWPAN_LLTYPE_IEEE802154);
161169

‎net/ieee802154/6lowpan/tx.c‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include <net/6lowpan.h>
1212
#include <net/ieee802154_netdev.h>
13+
#include <net/mac802154.h>
1314

1415
#include "6lowpan_i.h"
1516

@@ -36,6 +37,13 @@ lowpan_addr_info *lowpan_skb_priv(const struct sk_buff *skb)
3637
sizeof(struct lowpan_addr_info));
3738
}
3839

40+
/* This callback will be called from AF_PACKET and IPv6 stack, the AF_PACKET
41+
* sockets gives an 8 byte array for addresses only!
42+
*
43+
* TODO I think AF_PACKET DGRAM (sending/receiving) RAW (sending) makes no
44+
* sense here. We should disable it, the right use-case would be AF_INET6
45+
* RAW/DGRAM sockets.
46+
*/
3947
int lowpan_header_create(struct sk_buff *skb, struct net_device *ldev,
4048
unsigned short type, const void *_daddr,
4149
const void *_saddr, unsigned int len)
@@ -77,13 +85,13 @@ lowpan_alloc_frag(struct sk_buff *skb, int size,
7785
struct sk_buff *frag;
7886
int rc;
7987

80-
frag = alloc_skb(wdev->hard_header_len + wdev->needed_tailroom + size,
88+
frag = alloc_skb(wdev->needed_headroom + wdev->needed_tailroom + size,
8189
GFP_ATOMIC);
8290

8391
if (likely(frag)) {
8492
frag->dev = wdev;
8593
frag->priority = skb->priority;
86-
skb_reserve(frag, wdev->hard_header_len);
94+
skb_reserve(frag, wdev->needed_headroom);
8795
skb_reset_network_header(frag);
8896
*mac_cb(frag) = *mac_cb(skb);
8997

‎net/ieee802154/header_ops.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ ieee802154_hdr_push_sechdr(u8 *buf, const struct ieee802154_sechdr *hdr)
8585
int
8686
ieee802154_hdr_push(struct sk_buff *skb, struct ieee802154_hdr *hdr)
8787
{
88-
u8 buf[MAC802154_FRAME_HARD_HEADER_LEN];
88+
u8 buf[IEEE802154_MAX_HEADER_LEN];
8989
int pos = 2;
9090
int rc;
9191
struct ieee802154_hdr_fc *fc = &hdr->fc;

‎net/mac802154/iface.c‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -537,8 +537,18 @@ static void ieee802154_if_setup(struct net_device *dev)
537537
dev->addr_len = IEEE802154_EXTENDED_ADDR_LEN;
538538
memset(dev->broadcast, 0xff, IEEE802154_EXTENDED_ADDR_LEN);
539539

540-
dev->hard_header_len = MAC802154_FRAME_HARD_HEADER_LEN;
541-
dev->needed_tailroom = 2 + 16; /* FCS + MIC */
540+
/* Let hard_header_len set to IEEE802154_MIN_HEADER_LEN. AF_PACKET
541+
* will not send frames without any payload, but ack frames
542+
* has no payload, so substract one that we can send a 3 bytes
543+
* frame. The xmit callback assumes at least a hard header where two
544+
* bytes fc and sequence field are set.
545+
*/
546+
dev->hard_header_len = IEEE802154_MIN_HEADER_LEN - 1;
547+
/* The auth_tag header is for security and places in private payload
548+
* room of mac frame which stucks between payload and FCS field.
549+
*/
550+
dev->needed_tailroom = IEEE802154_MAX_AUTH_TAG_LEN +
551+
IEEE802154_FCS_LEN;
542552
dev->mtu = IEEE802154_MTU;
543553
dev->tx_queue_len = 300;
544554
dev->flags = IFF_NOARP | IFF_BROADCAST;
@@ -617,7 +627,8 @@ ieee802154_if_add(struct ieee802154_local *local, const char *name,
617627
if (!ndev)
618628
return ERR_PTR(-ENOMEM);
619629

620-
ndev->needed_headroom = local->hw.extra_tx_headroom;
630+
ndev->needed_headroom = local->hw.extra_tx_headroom +
631+
IEEE802154_MAX_HEADER_LEN;
621632

622633
ret = dev_alloc_name(ndev, ndev->name);
623634
if (ret < 0)

‎net/mac802154/tx.c‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,6 @@ ieee802154_tx(struct ieee802154_local *local, struct sk_buff *skb)
7777
put_unaligned_le16(crc, skb_put(skb, 2));
7878
}
7979

80-
if (skb_cow_head(skb, local->hw.extra_tx_headroom))
81-
goto err_tx;
82-
8380
/* Stop the netif queue on each sub_if_data object. */
8481
ieee802154_stop_queue(&local->hw);
8582

0 commit comments

Comments
 (0)