2013-04-08 21:27:48

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH 5/6] mac80211: stringify another plink state

On Mon, 2013-04-08 at 11:06 -0700, Thomas Pedersen wrote:
> The patch "mac80211: stringify mesh peering events" missed
> an opportunity to print the peering state as a string.

Perhaps it's better to use functions for these instead of
indexing in case an index is somehow incorrectly set.

> diff --git a/net/mac80211/mesh_plink.c b/net/mac80211/mesh_plink.c
[]
> @@ -544,8 +544,8 @@ static void mesh_plink_timer(unsigned long data)
> return;
> }
> mpl_dbg(sta->sdata,
> - "Mesh plink timer for %pM fired on state %d\n",
> - sta->sta.addr, sta->plink_state);
> + "Mesh plink timer for %pM fired on state %s\n",
> + sta->sta.addr, mplstates[sta->plink_state]);





2013-04-08 22:19:12

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH 5/6] mac80211: stringify another plink state

On Mon, 2013-04-08 at 14:27 -0700, Joe Perches wrote:
> On Mon, 2013-04-08 at 11:06 -0700, Thomas Pedersen wrote:
> > The patch "mac80211: stringify mesh peering events" missed
> > an opportunity to print the peering state as a string.
>
> Perhaps it's better to use functions for these instead of
> indexing in case an index is somehow incorrectly set.

Maybe:

net/mac80211/mesh_plink.c | 73 +++++++++++++++++++++++++++++++++--------------
1 file changed, 51 insertions(+), 22 deletions(-)

diff --git a/net/mac80211/mesh_plink.c b/net/mac80211/mesh_plink.c
index 937e06f..55d01d4 100644
--- a/net/mac80211/mesh_plink.c
+++ b/net/mac80211/mesh_plink.c
@@ -37,27 +37,55 @@ enum plink_event {
CLS_IGNR
};

-static const char * const mplstates[] = {
- [NL80211_PLINK_LISTEN] = "LISTEN",
- [NL80211_PLINK_OPN_SNT] = "OPN-SNT",
- [NL80211_PLINK_OPN_RCVD] = "OPN-RCVD",
- [NL80211_PLINK_CNF_RCVD] = "CNF_RCVD",
- [NL80211_PLINK_ESTAB] = "ESTAB",
- [NL80211_PLINK_HOLDING] = "HOLDING",
- [NL80211_PLINK_BLOCKED] = "BLOCKED"
-};
+static const char *mplstates(enum nl80211_plink_state state)
+{
+ switch (state) {
+ case NL80211_PLINK_LISTEN:
+ return "LISTEN";
+ case NL80211_PLINK_OPN_SNT:
+ return "OPN-SNT";
+ case NL80211_PLINK_OPN_RCVD:
+ return "OPN-RCVD";
+ case NL80211_PLINK_CNF_RCVD:
+ return "CNF_RCVD";
+ case NL80211_PLINK_ESTAB:
+ return "ESTAB";
+ case NL80211_PLINK_HOLDING:
+ return "HOLDING";
+ case NL80211_PLINK_BLOCKED:
+ return "BLOCKED";
+ default:
+ break;
+ }
+ return "UNKNOWN_PLINK_STATE";
+}

-static const char * const mplevents[] = {
- [PLINK_UNDEFINED] = "NONE",
- [OPN_ACPT] = "OPN_ACPT",
- [OPN_RJCT] = "OPN_RJCT",
- [OPN_IGNR] = "OPN_IGNR",
- [CNF_ACPT] = "CNF_ACPT",
- [CNF_RJCT] = "CNF_RJCT",
- [CNF_IGNR] = "CNF_IGNR",
- [CLS_ACPT] = "CLS_ACPT",
- [CLS_IGNR] = "CLS_IGNR"
-};
+static const char *mplevents(enum plink_event event)
+{
+ switch (event) {
+ case PLINK_UNDEFINED:
+ return "NONE";
+ case OPN_ACPT:
+ return "OPN_ACPT";
+ case OPN_RJCT:
+ return "OPN_RJCT";
+ case OPN_IGNR:
+ return "OPN_IGNR";
+ case CNF_ACPT:
+ return "CNF_ACPT";
+ case CNF_RJCT:
+ return "CNF_RJCT";
+ case CNF_IGNR:
+ return "CNF_IGNR";
+ case CLS_ACPT:
+ return "CLS_ACPT";
+ case CLS_IGNR:
+ return "CLS_IGNR";
+ default:
+ break;
+ }
+ return "UNKNOWN_PLINK_EVENT";
+}

static int mesh_plink_frame_tx(struct ieee80211_sub_if_data *sdata,
enum ieee80211_self_protected_actioncode action,
@@ -841,8 +869,9 @@ void mesh_rx_plink_frame(struct ieee80211_sub_if_data *sdata,
}
}

- mpl_dbg(sdata, "peer %pM in state %s got event %s\n", mgmt->sa,
- mplstates[sta->plink_state], mplevents[event]);
+ mpl_dbg(sdata, "peer %pM in state %d (%s) got event %d (%s)\n",
+ mgmt->sa, sta->plink_state, mplstates(sta->plink_state),
+ event, mplevents(event));
reason = 0;
spin_lock_bh(&sta->lock);
switch (sta->plink_state) {