net/ipv4: fib_trie: Avoid cryptic ternary expressions
[linux-2.6-microblaze.git] / net / ipv4 / fib_trie.c
index 5c8a4d2..90f0fc8 100644 (file)
@@ -1,8 +1,5 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *   This program is free software; you can redistribute it and/or
- *   modify it under the terms of the GNU General Public License
- *   as published by the Free Software Foundation; either version
- *   2 of the License, or (at your option) any later version.
  *
  *   Robert Olsson <robert.olsson@its.uu.se> Uppsala Universitet
  *     & Swedish University of Agricultural Sciences.
  * Stefan Nilsson and Matti Tikkanen. Algorithmica, 33(1):19-33, 2002.
  * http://www.csc.kth.se/~snilsson/software/dyntrie2/
  *
- *
  * IP-address lookup using LC-tries. Stefan Nilsson and Gunnar Karlsson
  * IEEE Journal on Selected Areas in Communications, 17(6):1083-1092, June 1999
  *
- *
  * Code from fib_hash has been reused which includes the following header:
  *
- *
  * INET                An implementation of the TCP/IP protocol suite for the LINUX
  *             operating system.  INET is implemented using the  BSD Socket
  *             interface as the means of communication with the user level.
  *
  *             IPv4 FIB: lookup engine and maintenance routines.
  *
- *
  * Authors:    Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
  *
- *             This program is free software; you can redistribute it and/or
- *             modify it under the terms of the GNU General Public License
- *             as published by the Free Software Foundation; either version
- *             2 of the License, or (at your option) any later version.
- *
  * Substantial contributions to this work comes from:
  *
  *             David S. Miller, <davem@davemloft.net>
@@ -350,12 +338,18 @@ static struct tnode *tnode_alloc(int bits)
 
 static inline void empty_child_inc(struct key_vector *n)
 {
-       ++tn_info(n)->empty_children ? : ++tn_info(n)->full_children;
+       tn_info(n)->empty_children++;
+
+       if (!tn_info(n)->empty_children)
+               tn_info(n)->full_children++;
 }
 
 static inline void empty_child_dec(struct key_vector *n)
 {
-       tn_info(n)->empty_children-- ? : tn_info(n)->full_children--;
+       if (!tn_info(n)->empty_children)
+               tn_info(n)->full_children--;
+
+       tn_info(n)->empty_children--;
 }
 
 static struct key_vector *leaf_new(t_key key, struct fib_alias *fa)
@@ -1461,6 +1455,7 @@ found:
                fib_alias_accessed(fa);
                err = fib_props[fa->fa_type].error;
                if (unlikely(err < 0)) {
+out_reject:
 #ifdef CONFIG_IP_FIB_TRIE_STATS
                        this_cpu_inc(stats->semantic_match_passed);
 #endif
@@ -1469,6 +1464,12 @@ found:
                }
                if (fi->fib_flags & RTNH_F_DEAD)
                        continue;
+
+               if (unlikely(fi->nh && nexthop_is_blackhole(fi->nh))) {
+                       err = fib_props[RTN_BLACKHOLE].error;
+                       goto out_reject;
+               }
+
                for (nhsel = 0; nhsel < fib_info_num_path(fi); nhsel++) {
                        struct fib_nh_common *nhc = fib_info_nhc(fi, nhsel);
 
@@ -2724,9 +2725,9 @@ static unsigned int fib_flag_trans(int type, __be32 mask, struct fib_info *fi)
        if (type == RTN_UNREACHABLE || type == RTN_PROHIBIT)
                flags = RTF_REJECT;
        if (fi) {
-               const struct fib_nh *nh = fib_info_nh(fi, 0);
+               const struct fib_nh_common *nhc = fib_info_nhc(fi, 0);
 
-               if (nh->fib_nh_gw4)
+               if (nhc->nhc_gw.ipv4)
                        flags |= RTF_GATEWAY;
        }
        if (mask == htonl(0xFFFFFFFF))
@@ -2773,14 +2774,17 @@ static int fib_route_seq_show(struct seq_file *seq, void *v)
                seq_setwidth(seq, 127);
 
                if (fi) {
-                       struct fib_nh *nh = fib_info_nh(fi, 0);
+                       struct fib_nh_common *nhc = fib_info_nhc(fi, 0);
+                       __be32 gw = 0;
+
+                       if (nhc->nhc_gw_family == AF_INET)
+                               gw = nhc->nhc_gw.ipv4;
 
                        seq_printf(seq,
                                   "%s\t%08X\t%08X\t%04X\t%d\t%u\t"
                                   "%d\t%08X\t%d\t%u\t%u",
-                                  nh->fib_nh_dev ? nh->fib_nh_dev->name : "*",
-                                  prefix,
-                                  nh->fib_nh_gw4, flags, 0, 0,
+                                  nhc->nhc_dev ? nhc->nhc_dev->name : "*",
+                                  prefix, gw, flags, 0, 0,
                                   fi->fib_priority,
                                   mask,
                                   (fi->fib_advmss ?