Skip to content

Commit 32edc40

Browse files
Phoebe Buckheisterdavem330
authored andcommitted
ieee802154: change _cb handling slightly
The current mac_cb handling of ieee802154 is rather awkward and limited. Decompose the single flags field into multiple fields with the meanings of each subfield of the flags field to make future extensions (for example, link-layer security) easier. Also don't set the frame sequence number in upper layers, since that's a thing the MAC is supposed to set on frame transmit - we set it on header creation, but assuming that upper layers do not blindly duplicate our headers, this is fine. Signed-off-by: Phoebe Buckheister <phoebe.buckheister@itwm.fraunhofer.de> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 8c84296 commit 32edc40

5 files changed

Lines changed: 28 additions & 44 deletions

File tree

‎include/net/ieee802154_netdev.h‎

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,9 @@ static inline void ieee802154_addr_to_sa(struct ieee802154_addr_sa *sa,
222222
*/
223223
struct ieee802154_mac_cb {
224224
u8 lqi;
225-
u8 flags;
226-
u8 seq;
225+
u8 type;
226+
bool ackreq;
227+
bool secen;
227228
struct ieee802154_addr source;
228229
struct ieee802154_addr dest;
229230
};
@@ -233,24 +234,12 @@ static inline struct ieee802154_mac_cb *mac_cb(struct sk_buff *skb)
233234
return (struct ieee802154_mac_cb *)skb->cb;
234235
}
235236

236-
#define MAC_CB_FLAG_TYPEMASK ((1 << 3) - 1)
237-
238-
#define MAC_CB_FLAG_ACKREQ (1 << 3)
239-
#define MAC_CB_FLAG_SECEN (1 << 4)
240-
241-
static inline bool mac_cb_is_ackreq(struct sk_buff *skb)
242-
{
243-
return mac_cb(skb)->flags & MAC_CB_FLAG_ACKREQ;
244-
}
245-
246-
static inline bool mac_cb_is_secen(struct sk_buff *skb)
237+
static inline struct ieee802154_mac_cb *mac_cb_init(struct sk_buff *skb)
247238
{
248-
return mac_cb(skb)->flags & MAC_CB_FLAG_SECEN;
249-
}
239+
BUILD_BUG_ON(sizeof(struct ieee802154_mac_cb) > sizeof(skb->cb));
250240

251-
static inline int mac_cb_type(struct sk_buff *skb)
252-
{
253-
return mac_cb(skb)->flags & MAC_CB_FLAG_TYPEMASK;
241+
memset(skb->cb, 0, sizeof(struct ieee802154_mac_cb));
242+
return mac_cb(skb);
254243
}
255244

256245
#define IEEE802154_MAC_SCAN_ED 0

‎net/ieee802154/6lowpan_rtnl.c‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ static int lowpan_header_create(struct sk_buff *skb,
9292
const u8 *saddr = _saddr;
9393
const u8 *daddr = _daddr;
9494
struct ieee802154_addr sa, da;
95+
struct ieee802154_mac_cb *cb = mac_cb_init(skb);
9596

9697
/* TODO:
9798
* if this package isn't ipv6 one, where should it be routed?
@@ -115,8 +116,7 @@ static int lowpan_header_create(struct sk_buff *skb,
115116
* from MAC subif of the 'dev' and 'real_dev' network devices, but
116117
* this isn't implemented in mainline yet, so currently we assign 0xff
117118
*/
118-
mac_cb(skb)->flags = IEEE802154_FC_TYPE_DATA;
119-
mac_cb(skb)->seq = ieee802154_mlme_ops(dev)->get_dsn(dev);
119+
cb->type = IEEE802154_FC_TYPE_DATA;
120120

121121
/* prepare wpan address data */
122122
sa.mode = IEEE802154_ADDR_LONG;
@@ -135,11 +135,10 @@ static int lowpan_header_create(struct sk_buff *skb,
135135
} else {
136136
da.mode = IEEE802154_ADDR_LONG;
137137
da.extended_addr = ieee802154_devaddr_from_raw(daddr);
138-
139-
/* request acknowledgment */
140-
mac_cb(skb)->flags |= MAC_CB_FLAG_ACKREQ;
141138
}
142139

140+
cb->ackreq = !lowpan_is_addr_broadcast(daddr);
141+
143142
return dev_hard_header(skb, lowpan_dev_info(dev)->real_dev,
144143
type, (void *)&da, (void *)&sa, 0);
145144
}

‎net/ieee802154/dgram.c‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ static int dgram_sendmsg(struct kiocb *iocb, struct sock *sk,
209209
struct net_device *dev;
210210
unsigned int mtu;
211211
struct sk_buff *skb;
212+
struct ieee802154_mac_cb *cb;
212213
struct dgram_sock *ro = dgram_sk(sk);
213214
int hlen, tlen;
214215
int err;
@@ -249,18 +250,15 @@ static int dgram_sendmsg(struct kiocb *iocb, struct sock *sk,
249250

250251
skb_reset_network_header(skb);
251252

252-
mac_cb(skb)->flags = IEEE802154_FC_TYPE_DATA;
253-
if (ro->want_ack)
254-
mac_cb(skb)->flags |= MAC_CB_FLAG_ACKREQ;
253+
cb = mac_cb_init(skb);
254+
cb->type = IEEE802154_FC_TYPE_DATA;
255+
cb->ackreq = ro->want_ack;
255256

256-
mac_cb(skb)->seq = ieee802154_mlme_ops(dev)->get_dsn(dev);
257257
err = dev_hard_header(skb, dev, ETH_P_IEEE802154, &ro->dst_addr,
258258
ro->bound ? &ro->src_addr : NULL, size);
259259
if (err < 0)
260260
goto out_skb;
261261

262-
skb_reset_mac_header(skb);
263-
264262
err = memcpy_fromiovec(skb_put(skb, size), msg->msg_iov, size);
265263
if (err < 0)
266264
goto out_skb;

‎net/mac802154/rx.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ mac802154_subif_rx(struct ieee802154_dev *hw, struct sk_buff *skb, u8 lqi)
5959
skb->protocol = htons(ETH_P_IEEE802154);
6060
skb_reset_mac_header(skb);
6161

62-
BUILD_BUG_ON(sizeof(struct ieee802154_mac_cb) > sizeof(skb->cb));
63-
6462
if (!(priv->hw.flags & IEEE802154_HW_OMIT_CKSUM)) {
6563
u16 crc;
6664

‎net/mac802154/wpan.c‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -192,15 +192,17 @@ static int mac802154_header_create(struct sk_buff *skb,
192192
{
193193
struct ieee802154_hdr hdr;
194194
struct mac802154_sub_if_data *priv = netdev_priv(dev);
195+
struct ieee802154_mac_cb *cb = mac_cb(skb);
195196
int hlen;
196197

197198
if (!daddr)
198199
return -EINVAL;
199200

200201
memset(&hdr.fc, 0, sizeof(hdr.fc));
201-
hdr.fc.type = mac_cb_type(skb);
202-
hdr.fc.security_enabled = mac_cb_is_secen(skb);
203-
hdr.fc.ack_request = mac_cb_is_ackreq(skb);
202+
hdr.fc.type = cb->type;
203+
hdr.fc.security_enabled = cb->secen;
204+
hdr.fc.ack_request = cb->ackreq;
205+
hdr.seq = ieee802154_mlme_ops(dev)->get_dsn(dev);
204206

205207
if (!saddr) {
206208
spin_lock_bh(&priv->mib_lock);
@@ -391,12 +393,12 @@ mac802154_subif_frame(struct mac802154_sub_if_data *sdata, struct sk_buff *skb)
391393
sdata->dev->stats.rx_packets++;
392394
sdata->dev->stats.rx_bytes += skb->len;
393395

394-
switch (mac_cb_type(skb)) {
396+
switch (mac_cb(skb)->type) {
395397
case IEEE802154_FC_TYPE_DATA:
396398
return mac802154_process_data(sdata->dev, skb);
397399
default:
398400
pr_warn("ieee802154: bad frame received (type = %d)\n",
399-
mac_cb_type(skb));
401+
mac_cb(skb)->type);
400402
kfree_skb(skb);
401403
return NET_RX_DROP;
402404
}
@@ -423,6 +425,7 @@ static int mac802154_parse_frame_start(struct sk_buff *skb)
423425
{
424426
int hlen;
425427
struct ieee802154_hdr hdr;
428+
struct ieee802154_mac_cb *cb = mac_cb_init(skb);
426429

427430
hlen = ieee802154_hdr_pull(skb, &hdr);
428431
if (hlen < 0)
@@ -433,18 +436,15 @@ static int mac802154_parse_frame_start(struct sk_buff *skb)
433436
pr_debug("fc: %04x dsn: %02x\n", le16_to_cpup((__le16 *)&hdr.fc),
434437
hdr.seq);
435438

436-
mac_cb(skb)->flags = hdr.fc.type;
437-
438-
if (hdr.fc.ack_request)
439-
mac_cb(skb)->flags |= MAC_CB_FLAG_ACKREQ;
440-
if (hdr.fc.security_enabled)
441-
mac_cb(skb)->flags |= MAC_CB_FLAG_SECEN;
439+
cb->type = hdr.fc.type;
440+
cb->ackreq = hdr.fc.ack_request;
441+
cb->secen = hdr.fc.security_enabled;
442442

443443
mac802154_print_addr("destination", &hdr.dest);
444444
mac802154_print_addr("source", &hdr.source);
445445

446-
mac_cb(skb)->source = hdr.source;
447-
mac_cb(skb)->dest = hdr.dest;
446+
cb->source = hdr.source;
447+
cb->dest = hdr.dest;
448448

449449
if (hdr.fc.security_enabled) {
450450
u64 key;

0 commit comments

Comments
 (0)