diff mbox

[v3] mac80211: mesh: fix wrong mesh TTL offset calculation

Message ID 8582518b7f032acfa598faf7d26c765b09149e90.1516842930.git.peter.oh@bowerswilkins.com (mailing list archive)
State Superseded
Delegated to: Johannes Berg
Headers show

Commit Message

Peter Oh Jan. 25, 2018, 1:16 a.m. UTC
From: Peter Oh <peter.oh@bowerswilkins.com>

mesh TTL offset in Mesh Channel Switch Parameters element depends on
not only Secondary Channel Offset element, but also affected by
HT Control field and Wide Bandwidth Channel Switch element.
Use element structure to correct the miscalculation.

Signed-off-by: Peter Oh <peter.oh@bowerswilkins.com>
---
 net/mac80211/mesh.c | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)

Comments

Peter Oh Jan. 25, 2018, 7:01 p.m. UTC | #1
Ignore the patch below for now. Just noticed mesh_chansw_params_ie is 
constance.

will come up with new approach.


Thanks,

Peter


On 01/24/2018 05:16 PM, peter.oh@bowerswilkins.com wrote:
> From: Peter Oh <peter.oh@bowerswilkins.com>
>
> mesh TTL offset in Mesh Channel Switch Parameters element depends on
> not only Secondary Channel Offset element, but also affected by
> HT Control field and Wide Bandwidth Channel Switch element.
> Use element structure to correct the miscalculation.
>
> Signed-off-by: Peter Oh <peter.oh@bowerswilkins.com>
> ---
>   net/mac80211/mesh.c | 17 ++++++-----------
>   1 file changed, 6 insertions(+), 11 deletions(-)
>
> diff --git a/net/mac80211/mesh.c b/net/mac80211/mesh.c
> index 73ac607..6a381cb 100644
> --- a/net/mac80211/mesh.c
> +++ b/net/mac80211/mesh.c
> @@ -1255,13 +1255,12 @@ int ieee80211_mesh_csa_beacon(struct ieee80211_sub_if_data *sdata,
>   }
>   
>   static int mesh_fwd_csa_frame(struct ieee80211_sub_if_data *sdata,
> -			       struct ieee80211_mgmt *mgmt, size_t len)
> +			       struct ieee80211_mgmt *mgmt, size_t len,
> +			       struct ieee802_11_elems *elems)
>   {
>   	struct ieee80211_mgmt *mgmt_fwd;
>   	struct sk_buff *skb;
>   	struct ieee80211_local *local = sdata->local;
> -	u8 *pos = mgmt->u.action.u.chan_switch.variable;
> -	size_t offset_ttl;
>   
>   	skb = dev_alloc_skb(local->tx_headroom + len);
>   	if (!skb)
> @@ -1269,13 +1268,9 @@ static int mesh_fwd_csa_frame(struct ieee80211_sub_if_data *sdata,
>   	skb_reserve(skb, local->tx_headroom);
>   	mgmt_fwd = skb_put(skb, len);
>   
> -	/* offset_ttl is based on whether the secondary channel
> -	 * offset is available or not. Subtract 1 from the mesh TTL
> -	 * and disable the initiator flag before forwarding.
> -	 */
> -	offset_ttl = (len < 42) ? 7 : 10;
> -	*(pos + offset_ttl) -= 1;
> -	*(pos + offset_ttl + 1) &= ~WLAN_EID_CHAN_SWITCH_PARAM_INITIATOR;
> +	elems->mesh_chansw_params_ie->mesh_ttl--;
> +	elems->mesh_chansw_params_ie->mesh_flags &=
> +		~WLAN_EID_CHAN_SWITCH_PARAM_INITIATOR;
>   
>   	memcpy(mgmt_fwd, mgmt, len);
>   	eth_broadcast_addr(mgmt_fwd->da);
> @@ -1323,7 +1318,7 @@ static void mesh_rx_csa_frame(struct ieee80211_sub_if_data *sdata,
>   
>   	/* forward or re-broadcast the CSA frame */
>   	if (fwd_csa) {
> -		if (mesh_fwd_csa_frame(sdata, mgmt, len) < 0)
> +		if (mesh_fwd_csa_frame(sdata, mgmt, len, &elems) < 0)
>   			mcsa_dbg(sdata, "Failed to forward the CSA frame");
>   	}
>   }
Johannes Berg Jan. 25, 2018, 7:48 p.m. UTC | #2
On Thu, 2018-01-25 at 11:01 -0800, Peter Oh wrote:
> Ignore the patch below for now. Just noticed mesh_chansw_params_ie is 
> constance.
> 
Just remove the const?

johannes
kernel test robot Jan. 27, 2018, 9 p.m. UTC | #3
Hi Peter,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on mac80211-next/master]
[also build test ERROR on v4.15-rc9 next-20180126]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/peter-oh-bowerswilkins-com/mac80211-mesh-fix-wrong-mesh-TTL-offset-calculation/20180128-042444
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jberg/mac80211-next.git master
config: i386-randconfig-x070-201804 (attached as .config)
compiler: gcc-7 (Debian 7.2.0-12) 7.2.1 20171025
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All errors (new ones prefixed by >>):

   net//mac80211/mesh.c: In function 'mesh_fwd_csa_frame':
>> net//mac80211/mesh.c:1271:40: error: decrement of member 'mesh_ttl' in read-only object
     elems->mesh_chansw_params_ie->mesh_ttl--;
                                           ^~
>> net//mac80211/mesh.c:1272:43: error: assignment of member 'mesh_flags' in read-only object
     elems->mesh_chansw_params_ie->mesh_flags &=
                                              ^~

vim +/mesh_ttl +1271 net//mac80211/mesh.c

  1256	
  1257	static int mesh_fwd_csa_frame(struct ieee80211_sub_if_data *sdata,
  1258				       struct ieee80211_mgmt *mgmt, size_t len,
  1259				       struct ieee802_11_elems *elems)
  1260	{
  1261		struct ieee80211_mgmt *mgmt_fwd;
  1262		struct sk_buff *skb;
  1263		struct ieee80211_local *local = sdata->local;
  1264	
  1265		skb = dev_alloc_skb(local->tx_headroom + len);
  1266		if (!skb)
  1267			return -ENOMEM;
  1268		skb_reserve(skb, local->tx_headroom);
  1269		mgmt_fwd = skb_put(skb, len);
  1270	
> 1271		elems->mesh_chansw_params_ie->mesh_ttl--;
> 1272		elems->mesh_chansw_params_ie->mesh_flags &=
  1273			~WLAN_EID_CHAN_SWITCH_PARAM_INITIATOR;
  1274	
  1275		memcpy(mgmt_fwd, mgmt, len);
  1276		eth_broadcast_addr(mgmt_fwd->da);
  1277		memcpy(mgmt_fwd->sa, sdata->vif.addr, ETH_ALEN);
  1278		memcpy(mgmt_fwd->bssid, sdata->vif.addr, ETH_ALEN);
  1279	
  1280		ieee80211_tx_skb(sdata, skb);
  1281		return 0;
  1282	}
  1283	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
Peter Oh Jan. 29, 2018, 8:26 p.m. UTC | #4
I have patch v4 which fixes the warning, so we can ignore this warning I 
believe.

Thanks,
Peter
On 01/27/2018 01:00 PM, kbuild test robot wrote:
> Hi Peter,
>
> Thank you for the patch! Yet something to improve:
>
> [auto build test ERROR on mac80211-next/master]
> [also build test ERROR on v4.15-rc9 next-20180126]
> [if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
>
> url:    https://github.com/0day-ci/linux/commits/peter-oh-bowerswilkins-com/mac80211-mesh-fix-wrong-mesh-TTL-offset-calculation/20180128-042444
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/jberg/mac80211-next.git master
> config: i386-randconfig-x070-201804 (attached as .config)
> compiler: gcc-7 (Debian 7.2.0-12) 7.2.1 20171025
> reproduce:
>          # save the attached .config to linux build tree
>          make ARCH=i386
>
> All errors (new ones prefixed by >>):
>
>     net//mac80211/mesh.c: In function 'mesh_fwd_csa_frame':
>>> net//mac80211/mesh.c:1271:40: error: decrement of member 'mesh_ttl' in read-only object
>       elems->mesh_chansw_params_ie->mesh_ttl--;
>                                             ^~
>>> net//mac80211/mesh.c:1272:43: error: assignment of member 'mesh_flags' in read-only object
>       elems->mesh_chansw_params_ie->mesh_flags &=
>                                                ^~
>
> vim +/mesh_ttl +1271 net//mac80211/mesh.c
>
>    1256	
>    1257	static int mesh_fwd_csa_frame(struct ieee80211_sub_if_data *sdata,
>    1258				       struct ieee80211_mgmt *mgmt, size_t len,
>    1259				       struct ieee802_11_elems *elems)
>    1260	{
>    1261		struct ieee80211_mgmt *mgmt_fwd;
>    1262		struct sk_buff *skb;
>    1263		struct ieee80211_local *local = sdata->local;
>    1264	
>    1265		skb = dev_alloc_skb(local->tx_headroom + len);
>    1266		if (!skb)
>    1267			return -ENOMEM;
>    1268		skb_reserve(skb, local->tx_headroom);
>    1269		mgmt_fwd = skb_put(skb, len);
>    1270	
>> 1271		elems->mesh_chansw_params_ie->mesh_ttl--;
>> 1272		elems->mesh_chansw_params_ie->mesh_flags &=
>    1273			~WLAN_EID_CHAN_SWITCH_PARAM_INITIATOR;
>    1274	
>    1275		memcpy(mgmt_fwd, mgmt, len);
>    1276		eth_broadcast_addr(mgmt_fwd->da);
>    1277		memcpy(mgmt_fwd->sa, sdata->vif.addr, ETH_ALEN);
>    1278		memcpy(mgmt_fwd->bssid, sdata->vif.addr, ETH_ALEN);
>    1279	
>    1280		ieee80211_tx_skb(sdata, skb);
>    1281		return 0;
>    1282	}
>    1283	
>
> ---
> 0-DAY kernel test infrastructure                Open Source Technology Center
> https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
diff mbox

Patch

diff --git a/net/mac80211/mesh.c b/net/mac80211/mesh.c
index 73ac607..6a381cb 100644
--- a/net/mac80211/mesh.c
+++ b/net/mac80211/mesh.c
@@ -1255,13 +1255,12 @@  int ieee80211_mesh_csa_beacon(struct ieee80211_sub_if_data *sdata,
 }
 
 static int mesh_fwd_csa_frame(struct ieee80211_sub_if_data *sdata,
-			       struct ieee80211_mgmt *mgmt, size_t len)
+			       struct ieee80211_mgmt *mgmt, size_t len,
+			       struct ieee802_11_elems *elems)
 {
 	struct ieee80211_mgmt *mgmt_fwd;
 	struct sk_buff *skb;
 	struct ieee80211_local *local = sdata->local;
-	u8 *pos = mgmt->u.action.u.chan_switch.variable;
-	size_t offset_ttl;
 
 	skb = dev_alloc_skb(local->tx_headroom + len);
 	if (!skb)
@@ -1269,13 +1268,9 @@  static int mesh_fwd_csa_frame(struct ieee80211_sub_if_data *sdata,
 	skb_reserve(skb, local->tx_headroom);
 	mgmt_fwd = skb_put(skb, len);
 
-	/* offset_ttl is based on whether the secondary channel
-	 * offset is available or not. Subtract 1 from the mesh TTL
-	 * and disable the initiator flag before forwarding.
-	 */
-	offset_ttl = (len < 42) ? 7 : 10;
-	*(pos + offset_ttl) -= 1;
-	*(pos + offset_ttl + 1) &= ~WLAN_EID_CHAN_SWITCH_PARAM_INITIATOR;
+	elems->mesh_chansw_params_ie->mesh_ttl--;
+	elems->mesh_chansw_params_ie->mesh_flags &=
+		~WLAN_EID_CHAN_SWITCH_PARAM_INITIATOR;
 
 	memcpy(mgmt_fwd, mgmt, len);
 	eth_broadcast_addr(mgmt_fwd->da);
@@ -1323,7 +1318,7 @@  static void mesh_rx_csa_frame(struct ieee80211_sub_if_data *sdata,
 
 	/* forward or re-broadcast the CSA frame */
 	if (fwd_csa) {
-		if (mesh_fwd_csa_frame(sdata, mgmt, len) < 0)
+		if (mesh_fwd_csa_frame(sdata, mgmt, len, &elems) < 0)
 			mcsa_dbg(sdata, "Failed to forward the CSA frame");
 	}
 }