From 1ffa8d7ef1e7266560933dedd16787eae7c743ec Mon Sep 17 00:00:00 2001 From: Andriy Voskoboinyk Date: Tue, 1 Mar 2016 06:47:21 +0000 Subject: [PATCH] net80211: eliminate copy-paste nearby ieee80211_check_rxseq() Approved by: adrian (mentor) Differential Revision: https://reviews.freebsd.org/D4043 --- sys/net80211/ieee80211_adhoc.c | 19 +------------------ sys/net80211/ieee80211_hostap.c | 19 +------------------ sys/net80211/ieee80211_input.h | 26 +++++++++++++++++++++----- sys/net80211/ieee80211_mesh.c | 19 +------------------ sys/net80211/ieee80211_sta.c | 19 +------------------ sys/net80211/ieee80211_wds.c | 17 +---------------- 6 files changed, 26 insertions(+), 93 deletions(-) diff --git a/sys/net80211/ieee80211_adhoc.c b/sys/net80211/ieee80211_adhoc.c index aa568b69c0bf..a9334d053e1f 100644 --- a/sys/net80211/ieee80211_adhoc.c +++ b/sys/net80211/ieee80211_adhoc.c @@ -302,7 +302,6 @@ adhoc_input(struct ieee80211_node *ni, struct mbuf *m, int hdrspace, need_tap = 1; /* mbuf need to be tapped. */ uint8_t dir, type, subtype, qos; uint8_t *bssid; - uint16_t rxseq; if (m->m_flags & M_AMPDU_MPDU) { /* @@ -421,24 +420,8 @@ adhoc_input(struct ieee80211_node *ni, struct mbuf *m, if (IEEE80211_QOS_HAS_SEQ(wh) && TID_TO_WME_AC(tid) >= WME_AC_VI) ic->ic_wme.wme_hipri_traffic++; - rxseq = le16toh(*(uint16_t *)wh->i_seq); - if (! ieee80211_check_rxseq(ni, wh)) { - /* duplicate, discard */ - IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_INPUT, - bssid, "duplicate", - "seqno <%u,%u> fragno <%u,%u> tid %u", - rxseq >> IEEE80211_SEQ_SEQ_SHIFT, - ni->ni_rxseqs[tid] >> - IEEE80211_SEQ_SEQ_SHIFT, - rxseq & IEEE80211_SEQ_FRAG_MASK, - ni->ni_rxseqs[tid] & - IEEE80211_SEQ_FRAG_MASK, - tid); - vap->iv_stats.is_rx_dup++; - IEEE80211_NODE_STAT(ni, rx_dup); + if (! ieee80211_check_rxseq(ni, wh, bssid)) goto out; - } - ni->ni_rxseqs[tid] = rxseq; } } diff --git a/sys/net80211/ieee80211_hostap.c b/sys/net80211/ieee80211_hostap.c index 2dd1f6895120..1e356dc7ec5d 100644 --- a/sys/net80211/ieee80211_hostap.c +++ b/sys/net80211/ieee80211_hostap.c @@ -485,7 +485,6 @@ hostap_input(struct ieee80211_node *ni, struct mbuf *m, int hdrspace, need_tap = 1; /* mbuf need to be tapped. */ uint8_t dir, type, subtype, qos; uint8_t *bssid; - uint16_t rxseq; if (m->m_flags & M_AMPDU_MPDU) { /* @@ -573,24 +572,8 @@ hostap_input(struct ieee80211_node *ni, struct mbuf *m, if (IEEE80211_QOS_HAS_SEQ(wh) && TID_TO_WME_AC(tid) >= WME_AC_VI) ic->ic_wme.wme_hipri_traffic++; - rxseq = le16toh(*(uint16_t *)wh->i_seq); - if (! ieee80211_check_rxseq(ni, wh)) { - /* duplicate, discard */ - IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_INPUT, - bssid, "duplicate", - "seqno <%u,%u> fragno <%u,%u> tid %u", - rxseq >> IEEE80211_SEQ_SEQ_SHIFT, - ni->ni_rxseqs[tid] >> - IEEE80211_SEQ_SEQ_SHIFT, - rxseq & IEEE80211_SEQ_FRAG_MASK, - ni->ni_rxseqs[tid] & - IEEE80211_SEQ_FRAG_MASK, - tid); - vap->iv_stats.is_rx_dup++; - IEEE80211_NODE_STAT(ni, rx_dup); + if (! ieee80211_check_rxseq(ni, wh, bssid)) goto out; - } - ni->ni_rxseqs[tid] = rxseq; } } diff --git a/sys/net80211/ieee80211_input.h b/sys/net80211/ieee80211_input.h index 72fd25b4ffc9..d051fdb3ea0c 100644 --- a/sys/net80211/ieee80211_input.h +++ b/sys/net80211/ieee80211_input.h @@ -164,12 +164,14 @@ ishtinfooui(const uint8_t *frm) * but a retransmit since the initial packet didn't make it. */ static __inline int -ieee80211_check_rxseq(struct ieee80211_node *ni, struct ieee80211_frame *wh) +ieee80211_check_rxseq(struct ieee80211_node *ni, struct ieee80211_frame *wh, + uint8_t *bssid) { #define SEQ_LEQ(a,b) ((int)((a)-(b)) <= 0) #define SEQ_EQ(a,b) ((int)((a)-(b)) == 0) #define SEQNO(a) ((a) >> IEEE80211_SEQ_SEQ_SHIFT) #define FRAGNO(a) ((a) & IEEE80211_SEQ_FRAG_MASK) + struct ieee80211vap *vap = ni->ni_vap; uint16_t rxseq; uint8_t type, subtype; uint8_t tid; @@ -198,7 +200,7 @@ ieee80211_check_rxseq(struct ieee80211_node *ni, struct ieee80211_frame *wh) /* HT nodes currently doing RX AMPDU are always valid */ if ((ni->ni_flags & IEEE80211_NODE_HT) && (rap->rxa_flags & IEEE80211_AGGR_RUNNING)) - return 1; + goto ok; } /* @@ -216,7 +218,7 @@ ieee80211_check_rxseq(struct ieee80211_node *ni, struct ieee80211_frame *wh) */ if (SEQ_EQ(rxseq, ni->ni_rxseqs[tid]) && (wh->i_fc[1] & IEEE80211_FC1_RETRY)) - return 0; + goto fail; /* * Treat any subsequent frame as fine if the last seen frame * is 4095 and it's not a retransmit for the same sequence @@ -224,7 +226,7 @@ ieee80211_check_rxseq(struct ieee80211_node *ni, struct ieee80211_frame *wh) * fragments w/ sequence number 4095. It shouldn't be seen * in practice, but see the comment above for further info. */ - return 1; + goto ok; } /* @@ -233,9 +235,23 @@ ieee80211_check_rxseq(struct ieee80211_node *ni, struct ieee80211_frame *wh) */ if ((wh->i_fc[1] & IEEE80211_FC1_RETRY) && SEQ_LEQ(rxseq, ni->ni_rxseqs[tid])) - return 0; + goto fail; + +ok: + ni->ni_rxseqs[tid] = rxseq; return 1; + +fail: + /* duplicate, discard */ + IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_INPUT, bssid, "duplicate", + "seqno <%u,%u> fragno <%u,%u> tid %u", + SEQNO(rxseq), SEQNO(ni->ni_rxseqs[tid]), + FRAGNO(rxseq), FRAGNO(ni->ni_rxseqs[tid]), tid); + vap->iv_stats.is_rx_dup++; + IEEE80211_NODE_STAT(ni, rx_dup); + + return 0; #undef SEQ_LEQ #undef SEQ_EQ #undef SEQNO diff --git a/sys/net80211/ieee80211_mesh.c b/sys/net80211/ieee80211_mesh.c index 40253c0247e1..80e2af328a6e 100644 --- a/sys/net80211/ieee80211_mesh.c +++ b/sys/net80211/ieee80211_mesh.c @@ -1537,7 +1537,6 @@ mesh_input(struct ieee80211_node *ni, struct mbuf *m, uint32_t seq; const uint8_t *addr; uint8_t qos[2]; - ieee80211_seq rxseq; KASSERT(ni != NULL, ("null node")); ni->ni_inact = ni->ni_inact_reload; @@ -1582,24 +1581,8 @@ mesh_input(struct ieee80211_node *ni, struct mbuf *m, if (IEEE80211_QOS_HAS_SEQ(wh) && TID_TO_WME_AC(tid) >= WME_AC_VI) ic->ic_wme.wme_hipri_traffic++; - rxseq = le16toh(*(uint16_t *)wh->i_seq); - if (! ieee80211_check_rxseq(ni, wh)) { - /* duplicate, discard */ - IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_INPUT, - wh->i_addr1, "duplicate", - "seqno <%u,%u> fragno <%u,%u> tid %u", - rxseq >> IEEE80211_SEQ_SEQ_SHIFT, - ni->ni_rxseqs[tid] >> - IEEE80211_SEQ_SEQ_SHIFT, - rxseq & IEEE80211_SEQ_FRAG_MASK, - ni->ni_rxseqs[tid] & - IEEE80211_SEQ_FRAG_MASK, - tid); - vap->iv_stats.is_rx_dup++; - IEEE80211_NODE_STAT(ni, rx_dup); + if (! ieee80211_check_rxseq(ni, wh, wh->i_addr1)) goto out; - } - ni->ni_rxseqs[tid] = rxseq; } } #ifdef IEEE80211_DEBUG diff --git a/sys/net80211/ieee80211_sta.c b/sys/net80211/ieee80211_sta.c index 0c0296a1ce43..9f6a4d4de9d6 100644 --- a/sys/net80211/ieee80211_sta.c +++ b/sys/net80211/ieee80211_sta.c @@ -538,7 +538,6 @@ sta_input(struct ieee80211_node *ni, struct mbuf *m, int hdrspace, need_tap = 1; /* mbuf need to be tapped. */ uint8_t dir, type, subtype, qos; uint8_t *bssid; - uint16_t rxseq; if (m->m_flags & M_AMPDU_MPDU) { /* @@ -630,24 +629,8 @@ sta_input(struct ieee80211_node *ni, struct mbuf *m, if (IEEE80211_QOS_HAS_SEQ(wh) && TID_TO_WME_AC(tid) >= WME_AC_VI) ic->ic_wme.wme_hipri_traffic++; - rxseq = le16toh(*(uint16_t *)wh->i_seq); - if (! ieee80211_check_rxseq(ni, wh)) { - /* duplicate, discard */ - IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_INPUT, - bssid, "duplicate", - "seqno <%u,%u> fragno <%u,%u> tid %u", - rxseq >> IEEE80211_SEQ_SEQ_SHIFT, - ni->ni_rxseqs[tid] >> - IEEE80211_SEQ_SEQ_SHIFT, - rxseq & IEEE80211_SEQ_FRAG_MASK, - ni->ni_rxseqs[tid] & - IEEE80211_SEQ_FRAG_MASK, - tid); - vap->iv_stats.is_rx_dup++; - IEEE80211_NODE_STAT(ni, rx_dup); + if (! ieee80211_check_rxseq(ni, wh, bssid)) goto out; - } - ni->ni_rxseqs[tid] = rxseq; } } diff --git a/sys/net80211/ieee80211_wds.c b/sys/net80211/ieee80211_wds.c index a9384d426fae..03d9c6029dcb 100644 --- a/sys/net80211/ieee80211_wds.c +++ b/sys/net80211/ieee80211_wds.c @@ -416,7 +416,6 @@ wds_input(struct ieee80211_node *ni, struct mbuf *m, struct ether_header *eh; int hdrspace, need_tap = 1; /* mbuf need to be tapped. */ uint8_t dir, type, subtype, qos; - uint16_t rxseq; if (m->m_flags & M_AMPDU_MPDU) { /* @@ -494,22 +493,8 @@ wds_input(struct ieee80211_node *ni, struct mbuf *m, if (IEEE80211_QOS_HAS_SEQ(wh) && TID_TO_WME_AC(tid) >= WME_AC_VI) ic->ic_wme.wme_hipri_traffic++; - rxseq = le16toh(*(uint16_t *)wh->i_seq); - if (! ieee80211_check_rxseq(ni, wh)) { - /* duplicate, discard */ - IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_INPUT, - wh->i_addr1, "duplicate", - "seqno <%u,%u> fragno <%u,%u> tid %u", - rxseq >> IEEE80211_SEQ_SEQ_SHIFT, - ni->ni_rxseqs[tid] >> IEEE80211_SEQ_SEQ_SHIFT, - rxseq & IEEE80211_SEQ_FRAG_MASK, - ni->ni_rxseqs[tid] & IEEE80211_SEQ_FRAG_MASK, - tid); - vap->iv_stats.is_rx_dup++; - IEEE80211_NODE_STAT(ni, rx_dup); + if (! ieee80211_check_rxseq(ni, wh, wh->i_addr1)) goto out; - } - ni->ni_rxseqs[tid] = rxseq; } switch (type) { case IEEE80211_FC0_TYPE_DATA: