nl80211/mac80211: mesh: add hop count to mpath info
authorJulan Hsu <julanhsu@google.com>
Tue, 15 Jan 2019 23:28:42 +0000 (15:28 -0800)
committerJohannes Berg <johannes.berg@intel.com>
Sat, 19 Jan 2019 08:54:36 +0000 (09:54 +0100)
Expose hop count to destination information in mpath info

Signed-off-by: Julan Hsu <julanhsu@google.com>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
include/net/cfg80211.h
include/uapi/linux/nl80211.h
net/mac80211/cfg.c
net/mac80211/mesh_hwmp.c
net/wireless/nl80211.c

index 1691f52fcc8072e76cf8f8b5bd154394a27458fc..37816786d3e128a1550a6fd109e49f9d69edb4c5 100644 (file)
@@ -1429,6 +1429,7 @@ enum monitor_flags {
  * @MPATH_INFO_DISCOVERY_TIMEOUT: @discovery_timeout filled
  * @MPATH_INFO_DISCOVERY_RETRIES: @discovery_retries filled
  * @MPATH_INFO_FLAGS: @flags filled
+ * @MPATH_INFO_HOP_COUNT: @hop_count filled
  */
 enum mpath_info_flags {
        MPATH_INFO_FRAME_QLEN           = BIT(0),
@@ -1438,6 +1439,7 @@ enum mpath_info_flags {
        MPATH_INFO_DISCOVERY_TIMEOUT    = BIT(4),
        MPATH_INFO_DISCOVERY_RETRIES    = BIT(5),
        MPATH_INFO_FLAGS                = BIT(6),
+       MPATH_INFO_HOP_COUNT            = BIT(7)
 };
 
 /**
@@ -1457,6 +1459,7 @@ enum mpath_info_flags {
  *     This number should increase every time the list of mesh paths
  *     changes, i.e. when a station is added or removed, so that
  *     userspace can tell whether it got a consistent snapshot.
+ * @hop_count: hops to destination
  */
 struct mpath_info {
        u32 filled;
@@ -1467,6 +1470,7 @@ struct mpath_info {
        u32 discovery_timeout;
        u8 discovery_retries;
        u8 flags;
+       u8 hop_count;
 
        int generation;
 };
index ebe79e12c82e9c42e5158c1fca157e862fb8dc30..213a1d7c10636c3beaed2cdb3b981a419d9ac4e7 100644 (file)
@@ -3287,6 +3287,7 @@ enum nl80211_mpath_flags {
  *     &enum nl80211_mpath_flags;
  * @NL80211_MPATH_INFO_DISCOVERY_TIMEOUT: total path discovery timeout, in msec
  * @NL80211_MPATH_INFO_DISCOVERY_RETRIES: mesh path discovery retries
+ * @NL80211_MPATH_INFO_HOP_COUNT: hop count to destination
  * @NL80211_MPATH_INFO_MAX: highest mesh path information attribute number
  *     currently defind
  * @__NL80211_MPATH_INFO_AFTER_LAST: internal use
@@ -3300,6 +3301,7 @@ enum nl80211_mpath_info {
        NL80211_MPATH_INFO_FLAGS,
        NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
        NL80211_MPATH_INFO_DISCOVERY_RETRIES,
+       NL80211_MPATH_INFO_HOP_COUNT,
 
        /* keep last */
        __NL80211_MPATH_INFO_AFTER_LAST,
index 83ee573b18043647f2a7e7aab47022ac665044dd..52cbaaf5caeab505b85d8d3f26f86bf50168f606 100644 (file)
@@ -1745,7 +1745,8 @@ static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
                        MPATH_INFO_EXPTIME |
                        MPATH_INFO_DISCOVERY_TIMEOUT |
                        MPATH_INFO_DISCOVERY_RETRIES |
-                       MPATH_INFO_FLAGS;
+                       MPATH_INFO_FLAGS |
+                       MPATH_INFO_HOP_COUNT;
 
        pinfo->frame_qlen = mpath->frame_queue.qlen;
        pinfo->sn = mpath->sn;
@@ -1765,6 +1766,7 @@ static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
                pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
        if (mpath->flags & MESH_PATH_RESOLVED)
                pinfo->flags |= NL80211_MPATH_FLAG_RESOLVED;
+       pinfo->hop_count = mpath->hop_count;
 }
 
 static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
index 6950cd0bf5940a0bc76ea0f3bc283c4a1cac7963..6d1190b3332f99ce51cc6c1a04392111749cb28b 100644 (file)
@@ -386,6 +386,7 @@ static u32 hwmp_route_info_get(struct ieee80211_sub_if_data *sdata,
        unsigned long orig_lifetime, exp_time;
        u32 last_hop_metric, new_metric;
        bool process = true;
+       u8 hopcount;
 
        rcu_read_lock();
        sta = sta_info_get(sdata, mgmt->sa);
@@ -404,6 +405,7 @@ static u32 hwmp_route_info_get(struct ieee80211_sub_if_data *sdata,
                orig_sn = PREQ_IE_ORIG_SN(hwmp_ie);
                orig_lifetime = PREQ_IE_LIFETIME(hwmp_ie);
                orig_metric = PREQ_IE_METRIC(hwmp_ie);
+               hopcount = PREQ_IE_HOPCOUNT(hwmp_ie) + 1;
                break;
        case MPATH_PREP:
                /* Originator here refers to the MP that was the target in the
@@ -415,6 +417,7 @@ static u32 hwmp_route_info_get(struct ieee80211_sub_if_data *sdata,
                orig_sn = PREP_IE_TARGET_SN(hwmp_ie);
                orig_lifetime = PREP_IE_LIFETIME(hwmp_ie);
                orig_metric = PREP_IE_METRIC(hwmp_ie);
+               hopcount = PREP_IE_HOPCOUNT(hwmp_ie) + 1;
                break;
        default:
                rcu_read_unlock();
@@ -482,6 +485,7 @@ static u32 hwmp_route_info_get(struct ieee80211_sub_if_data *sdata,
                        mpath->sn = orig_sn;
                        mpath->exp_time = time_after(mpath->exp_time, exp_time)
                                          ?  mpath->exp_time : exp_time;
+                       mpath->hop_count = hopcount;
                        mesh_path_activate(mpath);
                        spin_unlock_bh(&mpath->state_lock);
                        ewma_mesh_fail_avg_init(&sta->mesh->fail_avg);
@@ -523,6 +527,7 @@ static u32 hwmp_route_info_get(struct ieee80211_sub_if_data *sdata,
                        mpath->metric = last_hop_metric;
                        mpath->exp_time = time_after(mpath->exp_time, exp_time)
                                          ?  mpath->exp_time : exp_time;
+                       mpath->hop_count = 1;
                        mesh_path_activate(mpath);
                        spin_unlock_bh(&mpath->state_lock);
                        ewma_mesh_fail_avg_init(&sta->mesh->fail_avg);
index a89688929b1683a4843cd09c602bc8ac6e9e6f2a..159125e16c793792f66e5f6fec1c06ecec50bfae 100644 (file)
@@ -5827,7 +5827,10 @@ static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
                         pinfo->discovery_timeout)) ||
            ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
             nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
-                       pinfo->discovery_retries)))
+                       pinfo->discovery_retries)) ||
+           ((pinfo->filled & MPATH_INFO_HOP_COUNT) &&
+            nla_put_u8(msg, NL80211_MPATH_INFO_HOP_COUNT,
+                       pinfo->hop_count)))
                goto nla_put_failure;
 
        nla_nest_end(msg, pinfoattr);