Skip to contentSkip to conversation

mac80211: Fix frame classification in AP mode for relayed frames

PATCH In review Helmut Schaa 3 participants 7 messages Dec 19, 2011 – Dec 21, 2011 mac80211

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mac80211: Fix frame classification in AP mode for relayed frames

When mac80211 relays a frame from STA1 to STA2 in AP mode it will get re-classified in the tx path. Unfortunately the frame protocol field is always set to ETH_P_8023 while the classification only kicks in for ETH_P_IP. Hence, a high priority frame from STA1 will be send to STA2 as best effort.

To allow proper re-classification of received frames, set the skb->protocol field to the correct value without using eth_type_trans as that would pull of the ethernet header. Also, set the network header position correctly as otherwise the classification code won't find the IP header.

This means that every frame relayed by a mac80211 AP will be re-classified and might change its traffic class when the associated STA and mac80211 use different 802.1d <-> TID mappings.

---

We could also reuse the TID used by the source STA but I guess we should always classify frames according to our own mapping instead of relying on the associated STAs to do the right thing.

 net/mac80211/rx.c |   19 ++++++++++++++++---
 1 files changed, 16 insertions(+), 3 deletions(-)
net/mac80211/rx.c +16 -3
index bf07d08..8418f66 100644
@@ -1827,10 +1827,23 @@ ieee80211_deliver_skb(struct ieee80211_rx_data *rx)
 	}
 
 	if (xmit_skb) {
-		/* send to wireless media */
-		xmit_skb->protocol = htons(ETH_P_802_3);
-		skb_reset_network_header(xmit_skb);
+		/*
+		 * Send to wireless media
+		 *
+		 * Set protocol field according to the ethernet header
+		 * to allow reclassification of this frame in the tx path.
+		 *
+		 * Don't use eth_type_trans here since it will pull the
+		 * eth header and because we are sure to have an ethernet
+		 * header here.
+		 */
+		ehdr = (struct ethhdr *) xmit_skb->data;
+		if (ntohs(ehdr->h_proto) >= 1536)
+			xmit_skb->protocol = ehdr->h_proto;
+		else
+			xmit_skb->protocol = htons(ETH_P_802_3);
 		skb_reset_mac_header(xmit_skb);
+		skb_set_network_header(xmit_skb, sizeof(struct ethhdr));
 		dev_queue_xmit(xmit_skb);
 	}
 }
Signature · 1 line
1.7.7
maintainer
#1 lore raw
Quoted 16 lines · Helmut Schaa

When mac80211 relays a frame from STA1 to STA2 in AP mode it will get re-classified in the tx path. Unfortunately the frame protocol field is always set to ETH_P_8023 while the classification only kicks in for ETH_P_IP. Hence, a high priority frame from STA1 will be send to STA2 as best effort.

To allow proper re-classification of received frames, set the skb->protocol field to the correct value without using eth_type_trans as that would pull of the ethernet header. Also, set the network header position correctly as otherwise the classification code won't find the IP header.

This means that every frame relayed by a mac80211 AP will be re-classified and might change its traffic class when the associated STA and mac80211 use different 802.1d <-> TID mappings.

Quoted 6 lines

---

We could also reuse the TID used by the source STA but I guess we should always classify frames according to our own mapping instead of relying on the associated STAs to do the right thing.

Not sure that's useful, since we classify almost nothing anyway. If this was somehow hooked up to tc or iptables that would be more useful I guess?

johannes

#2 lore raw
Quoted 17 lines · Johannes Berg
Quoted 16 lines · Helmut Schaa

When mac80211 relays a frame from STA1 to STA2 in AP mode it will get re-classified in the tx path. Unfortunately the frame protocol field is always set to ETH_P_8023 while the classification only kicks in for ETH_P_IP. Hence, a high priority frame from STA1 will be send to STA2 as best effort.

To allow proper re-classification of received frames, set the skb->protocol field to the correct value without using eth_type_trans as that would pull of the ethernet header. Also, set the network header position correctly as otherwise the classification code won't find the IP header.

This means that every frame relayed by a mac80211 AP will be re-classified and might change its traffic class when the associated STA and mac80211 use different 802.1d <-> TID mappings.

Quoted 8 lines
Quoted 6 lines

---

We could also reuse the TID used by the source STA but I guess we should always classify frames according to our own mapping instead of relying on the associated STAs to do the right thing.

Not sure that's useful, since we classify almost nothing anyway.

Currently we only use the IPv4 DSCP field for assigning TIDs to frames. That seems to be sufficient for VOIP traffic at least.

Quoted 2 lines

If this was somehow hooked up to tc or iptables that would be more useful I guess?

Agreed. This would make sense in the future but I don't feel like implementing this right now.

So, you'd prefer to just copy over the TID as used by the source STA (via the priority+256 hack maybe)?

Helmut

maintainer
#3 lore raw
Quoted 9 lines · Helmut Schaa
Quoted 5 lines
Quoted 3 lines

We could also reuse the TID used by the source STA but I guess we should always classify frames according to our own mapping instead of relying on the associated STAs to do the right thing.

Not sure that's useful, since we classify almost nothing anyway.

Currently we only use the IPv4 DSCP field for assigning TIDs to frames. That seems to be sufficient for VOIP traffic at least.

Quoted 8 lines
Quoted 2 lines

If this was somehow hooked up to tc or iptables that would be more useful I guess?

Agreed. This would make sense in the future but I don't feel like implementing this right now.

So, you'd prefer to just copy over the TID as used by the source STA (via the priority+256 hack maybe)?

Seems simpler to me really, at least right now and as default. Not sure, maybe other people have more opinion? :)

I just don't expect anyone to hack the kernel for their local policy, and using what the STA wanted seems OK? If you run wifi networks you kinda trust them already anyway :)

johannes

#4 lore raw
Quoted 20 lines · Johannes Berg
Quoted 9 lines · Helmut Schaa
Quoted 5 lines
Quoted 3 lines

We could also reuse the TID used by the source STA but I guess we should always classify frames according to our own mapping instead of relying on the associated STAs to do the right thing.

Not sure that's useful, since we classify almost nothing anyway.

Currently we only use the IPv4 DSCP field for assigning TIDs to frames. That seems to be sufficient for VOIP traffic at least.

Quoted 8 lines
Quoted 2 lines

If this was somehow hooked up to tc or iptables that would be more useful I guess?

Agreed. This would make sense in the future but I don't feel like implementing this right now.

So, you'd prefer to just copy over the TID as used by the source STA (via the priority+256 hack maybe)?

Quoted 6 lines

Seems simpler to me really, at least right now and as default. Not sure, maybe other people have more opinion? :)

I just don't expect anyone to hack the kernel for their local policy, and using what the STA wanted seems OK? If you run wifi networks you kinda trust them already anyway :)

Fine with me. I'll change the patch to keep the priority the STA used ... Helmut

#5 lore raw
Quoted 11 lines · Helmut Schaa
Quoted 9 lines
Quoted 2 lines

So, you'd prefer to just copy over the TID as used by the source STA (via the priority+256 hack maybe)?

Seems simpler to me really, at least right now and as default. Not sure, maybe other people have more opinion? :)

I just don't expect anyone to hack the kernel for their local policy, and using what the STA wanted seems OK? If you run wifi networks you kinda trust them already anyway :)

Fine with me. I'll change the patch to keep the priority the STA used ...

Done. John, you can drop this one.

Thanks,
Helmut

#6 lore raw
Quoted 7 lines · Helmut Schaa
Quoted 5 lines · Helmut Schaa
Quoted 5 lines
Quoted 2 lines

So, you'd prefer to just copy over the TID as used by the source STA (via the priority+256 hack maybe)?

Seems simpler to me really, at least right now and as default. Not sure, maybe other people have more opinion? :)

Seeing this patch go by triggered me posting one of the patches I've been using in cerowrt, which should appear on linux-wireless as soon as the greylister gets done with me.

I think that much more extensive classification of wireless traffic is highly desirable. In particular, tossing stuff with the TOS interactive bit set into VI helps ssh traffic enormously.

It's the magic number hack that bugs me.

Signature · 5 lines
Dave Täht
SKYPE: davetaht
US Tel: 1-239-829-5608
FR Tel: 0638645374
http://www.bufferbloat.net