Skip to contentSkip to conversation

Assign next hop address to pending mesh frames once the path is resolved.

PATCH Superseded Javier Cardona 2 participants 5 messages Jul 8, 2009 – Jul 9, 2009 mac80211

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Assign next hop address to pending mesh frames once the path is resolved.

Regression. Frames transmitted when a mesh path was wating to be resolved were being transmitted with an invalid Receiver Address.

---
 net/mac80211/mesh.h         |    2 +-
 net/mac80211/mesh_pathtbl.c |   18 +++++++++++++++++-
 2 files changed, 18 insertions(+), 2 deletions(-)
net/mac80211/mesh.h +1 -1
index 2a2ed18..1827725 100644
@@ -61,7 +61,7 @@ enum mesh_path_flags {
  * 	retry
  * @discovery_retries: number of discovery retries
  * @flags: mesh path flags, as specified on &enum mesh_path_flags
- * @state_lock: mesh pat state lock
+ * @state_lock: mesh path state lock
  *
  *
  * The combination of dst and sdata is unique in the mesh path table. Since the
net/mac80211/mesh_pathtbl.c +17 -1
index ae98766..75a13ee 100644
@@ -55,7 +55,23 @@ static DEFINE_RWLOCK(pathtbl_resize_lock);
  */
 void mesh_path_assign_nexthop(struct mesh_path *mpath, struct sta_info *sta)
 {
-	rcu_assign_pointer(mpath->next_hop, sta);
+	struct sk_buff *skb, *skb_first = NULL;
+	struct ieee80211_hdr *hdr;
+
+	rcu_read_lock();
+	mpath->next_hop = sta;
+
+	while ((skb = skb_dequeue(&mpath->frame_queue)) != skb_first) {
+		if (!skb_first)
+			skb_first = skb;
+		hdr = (struct ieee80211_hdr *) skb->data;
+		memcpy(hdr->addr1, sta->sta.addr, ETH_ALEN);
+		skb_queue_tail(&mpath->frame_queue, skb);
+	}
+	if (skb_first)
+		skb_queue_tail(&mpath->frame_queue, skb_first);
+
+	rcu_read_unlock();
 }
 
 
Signature · 1 line
1.5.4.3
maintainer
#1 lore raw
Quoted 11 lines · Javier Cardona

Regression. Frames transmitted when a mesh path was wating to be resolved were being transmitted with an invalid Receiver Address.

net/mac80211/mesh_pathtbl.c +7 -1
-	rcu_assign_pointer(mpath->next_hop, sta);
+	struct sk_buff *skb, *skb_first = NULL;
+	struct ieee80211_hdr *hdr;
+
+	rcu_read_lock();
+	mpath->next_hop = sta;
+
+	while ((skb = skb_dequeue(&mpath->frame_queue)) != skb_first) {

net/mac80211/mesh_pathtbl.c static DEFINE_RWLOCK(pathtbl_resize_lock); · line 74

Quoted 10 lines
net/mac80211/mesh_pathtbl.c +10 -0
+		if (!skb_first)
+			skb_first = skb;
+		hdr = (struct ieee80211_hdr *) skb->data;
+		memcpy(hdr->addr1, sta->sta.addr, ETH_ALEN);
+		skb_queue_tail(&mpath->frame_queue, skb);
+	}
+	if (skb_first)
+		skb_queue_tail(&mpath->frame_queue, skb_first);
+
+	rcu_read_unlock();

Since skb queues have a locks, why use rcu too?

Also I think you should probably use a different pattern -- this looks prone to breakage, maybe something like

	sk_buff_head tmpq;
	unsigned long flags;

	__skb_queue_head_init(&tmpq);

	spin_lock_irqsave(&frame_queue->lock);

	while (skb = __skb_dequeue(&frame_queue)) {
		hdr = (struct ieee80211_hdr *) skb->data;
		memcpy(hdr->addr1, sta->sta.addr, ETH_ALEN);
		__skb_queue_tail(&tmpq, skb);
	}

	skb_queue_splice(&tmpq, frame_queue);
	spin_unlock_irqrestore(&frame_queue->lock);

johannes

#2 lore raw

Johannes,

Quoted 16 lines · Johannes Berg
Quoted 15 lines · Javier Cardona

Regression.  Frames transmitted when a mesh path was wating to be resolved were being transmitted with an invalid Receiver Address.

-     rcu_assign_pointer(mpath->next_hop, sta);
+     struct sk_buff *skb, *skb_first = NULL;
+     struct ieee80211_hdr *hdr;

net/mac80211/mesh_pathtbl.c +9 -0
+
+     rcu_read_lock();
+     mpath->next_hop = sta;
+
+     while ((skb = skb_dequeue(&mpath->frame_queue)) != skb_first) {
+             if (!skb_first)
+                     skb_first = skb;
+             hdr = (struct ieee80211_hdr *) skb->data;
+             memcpy(hdr->addr1, sta->sta.addr, ETH_ALEN);
Quoted 8 lines
Quoted 6 lines

+             skb_queue_tail(&mpath->frame_queue, skb);
+     }
+     if (skb_first)
+             skb_queue_tail(&mpath->frame_queue, skb_first); +
+     rcu_read_unlock();

Since skb queues have a locks, why use rcu too?

The some mpath members are rcu protected. I thought I had to extend the rcu section to cover both mpath->next_hop and mpath->frame_queue. But now I see that the latter does not need protection, so I'll revert that to just rcu_assign_pointer(mpath->next_hop, sta);

Quoted 10 lines

Also I think you should probably use a different pattern -- this looks prone to breakage, maybe something like

       sk_buff_head tmpq;
       unsigned long flags;

       __skb_queue_head_init(&tmpq);

       spin_lock_irqsave(&frame_queue->lock);

Quoted 8 lines

       while (skb = __skb_dequeue(&frame_queue)) { hdr = (struct ieee80211_hdr *) skb->data; memcpy(hdr->addr1, sta->sta.addr, ETH_ALEN); __skb_queue_tail(&tmpq, skb);
       }

       skb_queue_splice(&tmpq, frame_queue); spin_unlock_irqrestore(&frame_queue->lock);

Oh, nice, cleaner and less locking. v2 will follow shortly.

Thanks!

Javier

Signature · 3 lines
Javier Cardona
cozybit Inc.
http://www.cozybit.com
#3 lore raw

PATCH v2 1/1 Assign next hop address to pending mesh frames once the path is resolved.

In reply to Johannes Berg

Regression. Frames transmitted when a mesh path was wating to be resolved were being transmitted with an invalid Receiver Address.

[Changes since v1]

Suggested by Johannes:
- Improved frame_queue traversal
- Narower RCU scope

---
 net/mac80211/mesh_pathtbl.c |   18 ++++++++++++++++++
 1 files changed, 18 insertions(+), 0 deletions(-)
net/mac80211/mesh_pathtbl.c +18 -0
index ae98766..1981af9 100644
@@ -55,7 +55,25 @@ static DEFINE_RWLOCK(pathtbl_resize_lock);
  */
 void mesh_path_assign_nexthop(struct mesh_path *mpath, struct sta_info *sta)
 {
+	struct sk_buff *skb;
+	struct ieee80211_hdr *hdr;
+	struct sk_buff_head tmpq;
+	unsigned long flags;
+
 	rcu_assign_pointer(mpath->next_hop, sta);
+
+	__skb_queue_head_init(&tmpq);
+
+	spin_lock_irqsave(&mpath->frame_queue.lock, flags);
+
+	while ((skb = __skb_dequeue(&mpath->frame_queue)) != NULL) {
+		hdr = (struct ieee80211_hdr *) skb->data;
+		memcpy(hdr->addr1, sta->sta.addr, ETH_ALEN);
+		__skb_queue_tail(&tmpq, skb);
+	}
+
+	skb_queue_splice(&tmpq, &mpath->frame_queue);
+	spin_unlock_irqrestore(&mpath->frame_queue.lock, flags);
 }
 
 
Signature · 1 line
1.5.4.3
maintainer Reviewed-by on v2 1/1
#4 lore raw
Quoted 11 lines · Javier Cardona

Regression. Frames transmitted when a mesh path was wating to be resolved were being transmitted with an invalid Receiver Address.

[Changes since v1]

Suggested by Johannes:
- Improved frame_queue traversal
- Narower RCU scope

Quoted 34 lines
---
 net/mac80211/mesh_pathtbl.c |   18 ++++++++++++++++++
 1 files changed, 18 insertions(+), 0 deletions(-)
net/mac80211/mesh_pathtbl.c +18 -0
index ae98766..1981af9 100644
@@ -55,7 +55,25 @@ static DEFINE_RWLOCK(pathtbl_resize_lock);
  */
 void mesh_path_assign_nexthop(struct mesh_path *mpath, struct sta_info *sta)
 {
+	struct sk_buff *skb;
+	struct ieee80211_hdr *hdr;
+	struct sk_buff_head tmpq;
+	unsigned long flags;
+
 	rcu_assign_pointer(mpath->next_hop, sta);
+
+	__skb_queue_head_init(&tmpq);
+
+	spin_lock_irqsave(&mpath->frame_queue.lock, flags);
+
+	while ((skb = __skb_dequeue(&mpath->frame_queue)) != NULL) {
+		hdr = (struct ieee80211_hdr *) skb->data;
+		memcpy(hdr->addr1, sta->sta.addr, ETH_ALEN);
+		__skb_queue_tail(&tmpq, skb);
+	}
+
+	skb_queue_splice(&tmpq, &mpath->frame_queue);
+	spin_unlock_irqrestore(&mpath->frame_queue.lock, flags);
 }