mka: Refactor the get_*_peer() functions
authorSabrina Dubroca <sd@queasysnail.net>
Mon, 15 Aug 2016 09:43:41 +0000 (11:43 +0200)
committerJouni Malinen <j@w1.fi>
Sun, 28 Aug 2016 16:49:57 +0000 (19:49 +0300)
Add ieee802_1x_kay_get_potential_peer() similarly to the previously used
ieee802_1x_kay_get_live_peer() and use these helper functions more
consistently to avoid multiple implementations of peer lookups.

Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
src/pae/ieee802_1x_kay.c

index 7a31069..c7dd025 100644 (file)
@@ -300,13 +300,35 @@ static struct ieee802_1x_kay_peer * get_peer_mi(struct dl_list *peers,
 
 
 /**
+ * ieee802_1x_kay_get_potential_peer
+ */
+static struct ieee802_1x_kay_peer *
+ieee802_1x_kay_get_potential_peer(
+       struct ieee802_1x_mka_participant *participant, const u8 *mi)
+{
+       return get_peer_mi(&participant->potential_peers, mi);
+}
+
+
+/**
+ * ieee802_1x_kay_get_live_peer
+ */
+static struct ieee802_1x_kay_peer *
+ieee802_1x_kay_get_live_peer(struct ieee802_1x_mka_participant *participant,
+                            const u8 *mi)
+{
+       return get_peer_mi(&participant->live_peers, mi);
+}
+
+
+/**
  * ieee802_1x_kay_is_in_potential_peer
  */
 static Boolean
 ieee802_1x_kay_is_in_potential_peer(
        struct ieee802_1x_mka_participant *participant, const u8 *mi)
 {
-       return get_peer_mi(&participant->potential_peers, mi) != NULL;
+       return ieee802_1x_kay_get_potential_peer(participant, mi) != NULL;
 }
 
 
@@ -317,7 +339,7 @@ static Boolean
 ieee802_1x_kay_is_in_live_peer(
        struct ieee802_1x_mka_participant *participant, const u8 *mi)
 {
-       return get_peer_mi(&participant->live_peers, mi) != NULL;
+       return ieee802_1x_kay_get_live_peer(participant, mi) != NULL;
 }
 
 
@@ -342,22 +364,11 @@ ieee802_1x_kay_get_peer(struct ieee802_1x_mka_participant *participant,
 {
        struct ieee802_1x_kay_peer *peer;
 
-       peer = get_peer_mi(&participant->live_peers, mi);
+       peer = ieee802_1x_kay_get_live_peer(participant, mi);
        if (peer)
                return peer;
 
-       return get_peer_mi(&participant->potential_peers, mi);
-}
-
-
-/**
- * ieee802_1x_kay_get_live_peer
- */
-static struct ieee802_1x_kay_peer *
-ieee802_1x_kay_get_live_peer(struct ieee802_1x_mka_participant *participant,
-                            const u8 *mi)
-{
-       return get_peer_mi(&participant->live_peers, mi);
+       return ieee802_1x_kay_get_potential_peer(participant, mi);
 }
 
 
@@ -605,11 +616,7 @@ ieee802_1x_kay_move_live_peer(struct ieee802_1x_mka_participant *participant,
        struct receive_sc *rxsc;
        u32 sc_ch = 0;
 
-       dl_list_for_each(peer, &participant->potential_peers,
-                        struct ieee802_1x_kay_peer, list) {
-               if (os_memcmp(peer->mi, mi, MI_LEN) == 0)
-                       break;
-       }
+       peer = ieee802_1x_kay_get_potential_peer(participant, mi);
 
        rxsc = ieee802_1x_kay_init_receive_sc(&participant->current_peer_sci,
                                              sc_ch);