2018-01-25 01:16:27

by Peter Oh

[permalink] [raw]
Subject: [PATCH v3] mac80211: mesh: fix wrong mesh TTL offset calculation

From: Peter Oh <[email protected]>

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 <[email protected]>
---
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");
}
}
--
2.7.4


2018-01-25 19:48:22

by Johannes Berg

[permalink] [raw]
Subject: Re: [PATCH v3] mac80211: mesh: fix wrong mesh TTL offset calculation

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

2018-01-25 19:01:53

by Peter Oh

[permalink] [raw]
Subject: Re: [PATCH v3] mac80211: mesh: fix wrong mesh TTL offset calculation

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, [email protected] wrote:
> From: Peter Oh <[email protected]>
>
> 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 <[email protected]>
> ---
> 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");
> }
> }

2018-01-29 20:26:52

by Peter Oh

[permalink] [raw]
Subject: Re: [PATCH v3] mac80211: mesh: fix wrong mesh TTL offset calculation

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

2018-01-27 21:01:40

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH v3] mac80211: mesh: fix wrong mesh TTL offset calculation

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


Attachments:
(No filename) (2.27 kB)
.config.gz (24.35 kB)
Download all attachments