wifi: mac80211: expand __ieee80211_data_to_8023() status
authorJohannes Berg <johannes.berg@intel.com>
Mon, 25 Sep 2023 15:25:11 +0000 (17:25 +0200)
committerJohannes Berg <johannes.berg@intel.com>
Tue, 26 Sep 2023 07:16:47 +0000 (09:16 +0200)
Make __ieee80211_data_to_8023() return more individual drop
reasons instead of just doing RX_DROP_U_INVALID_8023.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
net/mac80211/drop.h
net/mac80211/rx.c

index 3acc21ae9c69d37854c87e959e00f77be6502701..12a6f0e9eca64c8489ecb4f6653a7551c9b889a9 100644 (file)
@@ -62,6 +62,10 @@ typedef unsigned int __bitwise ieee80211_rx_result;
        R(RX_DROP_U_SHORT_CMAC)                 \
        R(RX_DROP_U_SHORT_CMAC256)              \
        R(RX_DROP_U_SHORT_GMAC)                 \
+       R(RX_DROP_U_UNEXPECTED_VLAN_4ADDR)      \
+       R(RX_DROP_U_UNEXPECTED_STA_4ADDR)       \
+       R(RX_DROP_U_UNEXPECTED_VLAN_MCAST)      \
+       R(RX_DROP_U_NOT_PORT_CONTROL)           \
 /* this line for the trailing \ - add before this */
 
 /* having two enums allows for checking ieee80211_rx_result use with sparse */
index ff98681c70e3373e5ce7ee76a8740bf3de43f8f8..fb2d4a7436be67b192f49add7b904bbead9a98b6 100644 (file)
@@ -2476,7 +2476,7 @@ static int ieee80211_drop_unencrypted_mgmt(struct ieee80211_rx_data *rx)
        return 0;
 }
 
-static int
+static ieee80211_rx_result
 __ieee80211_data_to_8023(struct ieee80211_rx_data *rx, bool *port_control)
 {
        struct ieee80211_sub_if_data *sdata = rx->sdata;
@@ -2488,32 +2488,31 @@ __ieee80211_data_to_8023(struct ieee80211_rx_data *rx, bool *port_control)
        *port_control = false;
        if (ieee80211_has_a4(hdr->frame_control) &&
            sdata->vif.type == NL80211_IFTYPE_AP_VLAN && !sdata->u.vlan.sta)
-               return -1;
+               return RX_DROP_U_UNEXPECTED_VLAN_4ADDR;
 
        if (sdata->vif.type == NL80211_IFTYPE_STATION &&
            !!sdata->u.mgd.use_4addr != !!ieee80211_has_a4(hdr->frame_control)) {
-
                if (!sdata->u.mgd.use_4addr)
-                       return -1;
+                       return RX_DROP_U_UNEXPECTED_STA_4ADDR;
                else if (!ether_addr_equal(hdr->addr1, sdata->vif.addr))
                        check_port_control = true;
        }
 
        if (is_multicast_ether_addr(hdr->addr1) &&
            sdata->vif.type == NL80211_IFTYPE_AP_VLAN && sdata->u.vlan.sta)
-               return -1;
+               return RX_DROP_U_UNEXPECTED_VLAN_MCAST;
 
        ret = ieee80211_data_to_8023(rx->skb, sdata->vif.addr, sdata->vif.type);
        if (ret < 0)
-               return ret;
+               return RX_DROP_U_INVALID_8023;
 
        ehdr = (struct ethhdr *) rx->skb->data;
        if (ehdr->h_proto == rx->sdata->control_port_protocol)
                *port_control = true;
        else if (check_port_control)
-               return -1;
+               return RX_DROP_U_NOT_PORT_CONTROL;
 
-       return 0;
+       return RX_CONTINUE;
 }
 
 bool ieee80211_is_our_addr(struct ieee80211_sub_if_data *sdata,
@@ -3124,7 +3123,6 @@ ieee80211_rx_h_data(struct ieee80211_rx_data *rx)
        __le16 fc = hdr->frame_control;
        ieee80211_rx_result res;
        bool port_control;
-       int err;
 
        if (unlikely(!ieee80211_is_data(hdr->frame_control)))
                return RX_CONTINUE;
@@ -3145,9 +3143,9 @@ ieee80211_rx_h_data(struct ieee80211_rx_data *rx)
                return RX_DROP_MONITOR;
        }
 
-       err = __ieee80211_data_to_8023(rx, &port_control);
-       if (unlikely(err))
-               return RX_DROP_U_INVALID_8023;
+       res = __ieee80211_data_to_8023(rx, &port_control);
+       if (unlikely(res != RX_CONTINUE))
+               return res;
 
        res = ieee80211_rx_mesh_data(rx->sdata, rx->sta, rx->skb);
        if (res != RX_CONTINUE)