mac80211: track and share mesh BSSes among interfaces

Add a new global list of mesh BSSes for this host.  Each struct
mesh_local_bss contains parameters specific to a mesh instance,
as well as a list of interfaces participating in the MBSS.  This
will enable lookup of other interfaces on the host participating
in the same mesh.

Signed-off-by: Bob Copeland <bob@cozybit.com>

v2:
	drop can_share and don't add unshared MBSS to
	global list (Johannes)
mac80211: mesh: add function to tx on all other mbss ifaces

Add a function to rebroadcast mcast/bcast frames on other
interfaces when multiple interfaces are shared in an mbss.

Signed-off-by: Bob Copeland <bob@cozybit.com>
mac80211: use all MBSS interfaces for path selection

Change the HWMP path selection code to establish paths using
all interfaces participating in a shared mbss.  This means that
group-addressed action frames like PREQ will go out on each
interface, while individually addressed frames use whichever
interface has the destination as a peer.

When processing received frames, consider it a match if any
local interface in the mbss matches the target address.

Finally, mesh_path_lookup() now scans the path table on each
interface until a path (if any) is found so that paths can
be shared among the interfaces.

[ PERR/unicast frame handling fixes from Thomas Pedersen ]

Signed-off-by: Bob Copeland <bob@cozybit.com>

v2:
	kernel-doc fixes (Johannes)
mac80211: assign outgoing interface with nexthop

When updated mpath routing info is found, the new route
may be on a different interface (in the case of MBSS
sharing).

Signed-off-by: Thomas Pedersen <thomas@cozybit.com>
mac80211: forward frames on correct mbss-shared interface

A forwarded frame may have a destination STA which resides
on a vif other than the RX interface. Have
mesh_nexthop_lookup() fill in the right outgoing sdata in
the skb control block.

Also update the congestion detection logic to take into
account a possibly different outgoing interface.

Signed-off-by: Thomas Pedersen <thomas@cozybit.com>
mac80211: make RMC per-mbss

The RMC was previously per-sdata, but it is sufficient for
one of the interfaces in a local mbss to receive a
multicast frame once.

Once multiple interfaces share the same mesh data forwarding
duties, we may inadvertently create a multicast routing loop
and have a corner case where a multicast frame is
retransmitted a few times too many.

Signed-off-by: Thomas Pedersen <thomas@cozybit.com>
mac80211: forward group frames on mbss-shared interfaces

When multiple local interfaces are in the same MBSS, we should
forward group-directed data frames received on one interface
for transmit on the other interfaces, so that the frames may be
seen on other channels.

Signed-off-by: Bob Copeland <bob@cozybit.com>
mac80211: add shared-mbss transmit path

Transmit locally-originated group data frames on every interface
so that members of the mesh on every channel will see the frame.

For individually-addressed frames, when we resolve the next
hop, the outgoing interface might be different than the
originator if the best path is on a different channel.
Requeue such frames on the correct interface's pending queue.

Signed-off-by: Bob Copeland <bob@cozybit.com>
mac08211: add shared-mbss receive path handling

If a destination interface is participating in a shared mbss, then
receive data frames on the correct interface (or all for mcast) when
passing frames to upper layers.

Signed-off-by: Bob Copeland <bob@cozybit.com>
{nl,mac}80211: specify MBSS sharing on/off

Allow the user to choose whether a newly joined MBSS
should be shared with other matching interfaces.

Signed-off-by: Thomas Pedersen <thomas@cozybit.com>
{nl,mac}80211: allow mpath dump to span local MBSS

Allow the user to specify a flag
NL80211_ATTR_MPATH_DUMP_MBSS along with an mpath dump
request to dump all paths in the interface's mbss.

Signed-off-by: Thomas Pedersen <thomas@cozybit.com>
mac80211: handle headroom for multi-if mesh

When an MBSS is shared across multiple interfaces, the
headroom requirements may differ. Handle this by
indicating the max headroom of all PHYs in the mesh to
each member netdev, so at TX time sufficient headroom
space is guaranteed to be available regardless of whether
an interface switch takes place.

In the forwarding path, just allocate up to max mbss
headroom before looking up the outgoing interface, which
may require a reallocation anyway.

Signed-off-by: Thomas Pedersen <thomas@cozybit.com>
mac80211: set mesh formation field properly

Cap max peerings at 63 in accordance with IEEE-2012 8.4.2.100.7.
Triggers a beacon regeneration every time the number of peerings changes.
Previously this would only happen if the "accepting peerings" bit changed.

Signed-off-by: Jacob Minshall <jacob@cozybit.com>
mac80211: fix mesh deadlock

The patch "cfg80211/mac80211: use cfg80211 wdev mutex in
mac80211" introduced several deadlocks by converting the
ifmsh->mtx to wdev->mtx. Solve these by:

1. drop the cancel_work_sync() in ieee80211_stop_mesh().
   Instead make the mesh work conditional on whether the mesh
   is running or not.
2. lock the mesh work with sdata_lock() to protect beacon
   updates and prevent races with wdev->mesh_id_len or
   cfg80211.

Signed-off-by: Thomas Pedersen <thomas@cozybit.com>
mac80211: update mesh beacon on workqueue

Fixes yet another deadlock on calling sta_info_flush()
with the sdata_lock() held. Should make it easier to
reason about locking in the future, since the sdata_lock()
is now held on all mesh work.

Signed-off-by: Thomas Pedersen <thomas@cozybit.com>