]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
batman-adv: Switch to bitmap helper for aggregation handling
authorSven Eckelmann <sven@narfation.org>
Sun, 2 Feb 2025 16:04:11 +0000 (17:04 +0100)
committerSimon Wunderlich <sw@simonwunderlich.de>
Sat, 22 Feb 2025 10:36:25 +0000 (11:36 +0100)
The aggregation code duplicates code which already exists in the the bitops
and bitmap helper. By switching to the bitmap helpers, operating on larger
aggregations becomes possible without touching the different portions of
the code which read/modify direct_link_flags.

Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
net/batman-adv/bat_iv_ogm.c
net/batman-adv/main.h
net/batman-adv/types.h

index b715f7343ffddcbba271274996decced6217f268..87c1af540457b2a71a0254a9e0ec966d6132b8be 100644 (file)
@@ -355,7 +355,7 @@ static void batadv_iv_ogm_send_to_if(struct batadv_forw_packet *forw_packet,
                /* we might have aggregated direct link packets with an
                 * ordinary base packet
                 */
-               if (forw_packet->direct_link_flags & BIT(packet_num) &&
+               if (test_bit(packet_num, forw_packet->direct_link_flags) &&
                    forw_packet->if_incoming == hard_iface)
                        batadv_ogm_packet->flags |= BATADV_DIRECTLINK;
                else
@@ -460,6 +460,7 @@ batadv_iv_ogm_can_aggregate(const struct batadv_ogm_packet *new_bat_ogm_packet,
         * - the send time is within our MAX_AGGREGATION_MS time
         * - the resulting packet won't be bigger than
         *   MAX_AGGREGATION_BYTES
+        * - the number of packets is lower than MAX_AGGREGATION_PACKETS
         * otherwise aggregation is not possible
         */
        if (!time_before(send_time, forw_packet->send_time) ||
@@ -469,7 +470,7 @@ batadv_iv_ogm_can_aggregate(const struct batadv_ogm_packet *new_bat_ogm_packet,
        if (aggregated_bytes > BATADV_MAX_AGGREGATION_BYTES)
                return false;
 
-       if (packet_num >= BITS_PER_TYPE(forw_packet->direct_link_flags))
+       if (packet_num >= BATADV_MAX_AGGREGATION_PACKETS)
                return false;
 
        /* packet is not leaving on the same interface. */
@@ -578,12 +579,13 @@ static void batadv_iv_ogm_aggregate_new(const unsigned char *packet_buff,
        memcpy(skb_buff, packet_buff, packet_len);
 
        forw_packet_aggr->own = own_packet;
-       forw_packet_aggr->direct_link_flags = BATADV_NO_FLAGS;
+       bitmap_zero(forw_packet_aggr->direct_link_flags,
+                   BATADV_MAX_AGGREGATION_PACKETS);
        forw_packet_aggr->send_time = send_time;
 
        /* save packet direct link flag status */
        if (direct_link)
-               forw_packet_aggr->direct_link_flags |= 1;
+               set_bit(0, forw_packet_aggr->direct_link_flags);
 
        INIT_DELAYED_WORK(&forw_packet_aggr->delayed_work,
                          batadv_iv_send_outstanding_bat_ogm_packet);
@@ -596,17 +598,14 @@ static void batadv_iv_ogm_aggregate(struct batadv_forw_packet *forw_packet_aggr,
                                    const unsigned char *packet_buff,
                                    int packet_len, bool direct_link)
 {
-       unsigned long new_direct_link_flag;
-
        skb_put_data(forw_packet_aggr->skb, packet_buff, packet_len);
        forw_packet_aggr->packet_len += packet_len;
        forw_packet_aggr->num_packets++;
 
        /* save packet direct link flag status */
-       if (direct_link) {
-               new_direct_link_flag = BIT(forw_packet_aggr->num_packets);
-               forw_packet_aggr->direct_link_flags |= new_direct_link_flag;
-       }
+       if (direct_link)
+               set_bit(forw_packet_aggr->num_packets,
+                       forw_packet_aggr->direct_link_flags);
 }
 
 /**
index c08c96b5b8b13f0ab92c2692e36f69cfff226815..67af435ee04e110bec00dacf4c8ecb20f7e9a924 100644 (file)
  */
 #define BATADV_TQ_SIMILARITY_THRESHOLD 50
 
+#define BATADV_MAX_AGGREGATION_PACKETS 32
 #define BATADV_MAX_AGGREGATION_BYTES 512
 #define BATADV_MAX_AGGREGATION_MS 100
 
index b222f8a80ed920f222a9c8b9848654150912c029..0ca0fc072fc9c1bac810d2a166ee2942f8176720 100644 (file)
@@ -2139,7 +2139,7 @@ struct batadv_forw_packet {
        u16 packet_len;
 
        /** @direct_link_flags: direct link flags for aggregated OGM packets */
-       u32 direct_link_flags;
+       DECLARE_BITMAP(direct_link_flags, BATADV_MAX_AGGREGATION_PACKETS);
 
        /** @num_packets: counter for aggregated OGMv1 packets */
        u8 num_packets;