netfilter: nft_set_rbtree: Introduce and use nft_rbtree_interval_start()
authorStefano Brivio <sbrivio@redhat.com>
Sun, 22 Mar 2020 02:22:00 +0000 (03:22 +0100)
committerPablo Neira Ayuso <pablo@netfilter.org>
Tue, 24 Mar 2020 18:59:30 +0000 (19:59 +0100)
Replace negations of nft_rbtree_interval_end() with a new helper,
nft_rbtree_interval_start(), wherever this helps to visualise the
problem at hand, that is, for all the occurrences except for the
comparison against given flags in __nft_rbtree_get().

This gets especially useful in the next patch.

Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
net/netfilter/nft_set_rbtree.c

index 5000b93..85572b2 100644 (file)
@@ -33,6 +33,11 @@ static bool nft_rbtree_interval_end(const struct nft_rbtree_elem *rbe)
               (*nft_set_ext_flags(&rbe->ext) & NFT_SET_ELEM_INTERVAL_END);
 }
 
+static bool nft_rbtree_interval_start(const struct nft_rbtree_elem *rbe)
+{
+       return !nft_rbtree_interval_end(rbe);
+}
+
 static bool nft_rbtree_equal(const struct nft_set *set, const void *this,
                             const struct nft_rbtree_elem *interval)
 {
@@ -64,7 +69,7 @@ static bool __nft_rbtree_lookup(const struct net *net, const struct nft_set *set
                        if (interval &&
                            nft_rbtree_equal(set, this, interval) &&
                            nft_rbtree_interval_end(rbe) &&
-                           !nft_rbtree_interval_end(interval))
+                           nft_rbtree_interval_start(interval))
                                continue;
                        interval = rbe;
                } else if (d > 0)
@@ -89,7 +94,7 @@ static bool __nft_rbtree_lookup(const struct net *net, const struct nft_set *set
 
        if (set->flags & NFT_SET_INTERVAL && interval != NULL &&
            nft_set_elem_active(&interval->ext, genmask) &&
-           !nft_rbtree_interval_end(interval)) {
+           nft_rbtree_interval_start(interval)) {
                *ext = &interval->ext;
                return true;
        }
@@ -224,9 +229,9 @@ static int __nft_rbtree_insert(const struct net *net, const struct nft_set *set,
                        p = &parent->rb_right;
                else {
                        if (nft_rbtree_interval_end(rbe) &&
-                           !nft_rbtree_interval_end(new)) {
+                           nft_rbtree_interval_start(new)) {
                                p = &parent->rb_left;
-                       } else if (!nft_rbtree_interval_end(rbe) &&
+                       } else if (nft_rbtree_interval_start(rbe) &&
                                   nft_rbtree_interval_end(new)) {
                                p = &parent->rb_right;
                        } else if (nft_set_elem_active(&rbe->ext, genmask)) {
@@ -317,10 +322,10 @@ static void *nft_rbtree_deactivate(const struct net *net,
                        parent = parent->rb_right;
                else {
                        if (nft_rbtree_interval_end(rbe) &&
-                           !nft_rbtree_interval_end(this)) {
+                           nft_rbtree_interval_start(this)) {
                                parent = parent->rb_left;
                                continue;
-                       } else if (!nft_rbtree_interval_end(rbe) &&
+                       } else if (nft_rbtree_interval_start(rbe) &&
                                   nft_rbtree_interval_end(this)) {
                                parent = parent->rb_right;
                                continue;