^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Linux INET6 implementation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Forwarding Information Database
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Authors:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Pedro Roque <roque@di.fc.ul.pt>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Changes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Yuji SEKIYA @USAGI: Support default route on router node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * remove ip6_null_entry from the top of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * routing table.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * Ville Nuorvala: Fixed routing subtrees.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define pr_fmt(fmt) "IPv6: " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/net.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/route.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/in6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <net/ip.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <net/ipv6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <net/ndisc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <net/addrconf.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <net/lwtunnel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <net/fib_notifier.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <net/ip6_fib.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <net/ip6_route.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) static struct kmem_cache *fib6_node_kmem __read_mostly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) struct fib6_cleaner {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) struct fib6_walker w;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) struct net *net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) int (*func)(struct fib6_info *, void *arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) int sernum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) void *arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) bool skip_notify;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #ifdef CONFIG_IPV6_SUBTREES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #define FWS_INIT FWS_S
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #define FWS_INIT FWS_L
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) static struct fib6_info *fib6_find_prefix(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) struct fib6_table *table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) struct fib6_node *fn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) static struct fib6_node *fib6_repair_tree(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) struct fib6_table *table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) struct fib6_node *fn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) static int fib6_walk(struct net *net, struct fib6_walker *w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) static int fib6_walk_continue(struct fib6_walker *w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * A routing update causes an increase of the serial number on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) * affected subtree. This allows for cached routes to be asynchronously
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) * tested when modifications are made to the destination cache as a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * result of redirects, path MTU changes, etc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) static void fib6_gc_timer_cb(struct timer_list *t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) #define FOR_WALKERS(net, w) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) list_for_each_entry(w, &(net)->ipv6.fib6_walkers, lh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) static void fib6_walker_link(struct net *net, struct fib6_walker *w)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) write_lock_bh(&net->ipv6.fib6_walker_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) list_add(&w->lh, &net->ipv6.fib6_walkers);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) write_unlock_bh(&net->ipv6.fib6_walker_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) static void fib6_walker_unlink(struct net *net, struct fib6_walker *w)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) write_lock_bh(&net->ipv6.fib6_walker_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) list_del(&w->lh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) write_unlock_bh(&net->ipv6.fib6_walker_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) static int fib6_new_sernum(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) int new, old;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) old = atomic_read(&net->ipv6.fib6_sernum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) new = old < INT_MAX ? old + 1 : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) } while (atomic_cmpxchg(&net->ipv6.fib6_sernum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) old, new) != old);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) return new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) FIB6_NO_SERNUM_CHANGE = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) void fib6_update_sernum(struct net *net, struct fib6_info *f6i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) struct fib6_node *fn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) fn = rcu_dereference_protected(f6i->fib6_node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) lockdep_is_held(&f6i->fib6_table->tb6_lock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) if (fn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) WRITE_ONCE(fn->fn_sernum, fib6_new_sernum(net));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) * Auxiliary address test functions for the radix tree.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) * These assume a 32bit processor (although it will work on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) * 64bit processors)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) * test bit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) #if defined(__LITTLE_ENDIAN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) # define BITOP_BE32_SWIZZLE (0x1F & ~7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) # define BITOP_BE32_SWIZZLE 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) static __be32 addr_bit_set(const void *token, int fn_bit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) const __be32 *addr = token;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) * Here,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) * 1 << ((~fn_bit ^ BITOP_BE32_SWIZZLE) & 0x1f)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) * is optimized version of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) * htonl(1 << ((~fn_bit)&0x1F))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) * See include/asm-generic/bitops/le.h.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) return (__force __be32)(1 << ((~fn_bit ^ BITOP_BE32_SWIZZLE) & 0x1f)) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) addr[fn_bit >> 5];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) struct fib6_info *fib6_info_alloc(gfp_t gfp_flags, bool with_fib6_nh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) struct fib6_info *f6i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) size_t sz = sizeof(*f6i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) if (with_fib6_nh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) sz += sizeof(struct fib6_nh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) f6i = kzalloc(sz, gfp_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) if (!f6i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) /* fib6_siblings is a union with nh_list, so this initializes both */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) INIT_LIST_HEAD(&f6i->fib6_siblings);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) refcount_set(&f6i->fib6_ref, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) return f6i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) void fib6_info_destroy_rcu(struct rcu_head *head)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) struct fib6_info *f6i = container_of(head, struct fib6_info, rcu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) WARN_ON(f6i->fib6_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) if (f6i->nh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) nexthop_put(f6i->nh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) fib6_nh_release(f6i->fib6_nh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) ip_fib_metrics_put(f6i->fib6_metrics);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) kfree(f6i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) EXPORT_SYMBOL_GPL(fib6_info_destroy_rcu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) static struct fib6_node *node_alloc(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) struct fib6_node *fn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) fn = kmem_cache_zalloc(fib6_node_kmem, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) if (fn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) net->ipv6.rt6_stats->fib_nodes++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) return fn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) static void node_free_immediate(struct net *net, struct fib6_node *fn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) kmem_cache_free(fib6_node_kmem, fn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) net->ipv6.rt6_stats->fib_nodes--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) static void node_free_rcu(struct rcu_head *head)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) struct fib6_node *fn = container_of(head, struct fib6_node, rcu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) kmem_cache_free(fib6_node_kmem, fn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) static void node_free(struct net *net, struct fib6_node *fn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) call_rcu(&fn->rcu, node_free_rcu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) net->ipv6.rt6_stats->fib_nodes--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) static void fib6_free_table(struct fib6_table *table)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) inetpeer_invalidate_tree(&table->tb6_peers);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) kfree(table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) static void fib6_link_table(struct net *net, struct fib6_table *tb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) unsigned int h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) * Initialize table lock at a single place to give lockdep a key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) * tables aren't visible prior to being linked to the list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) spin_lock_init(&tb->tb6_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) h = tb->tb6_id & (FIB6_TABLE_HASHSZ - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) * No protection necessary, this is the only list mutatation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) * operation, tables never disappear once they exist.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) hlist_add_head_rcu(&tb->tb6_hlist, &net->ipv6.fib_table_hash[h]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) #ifdef CONFIG_IPV6_MULTIPLE_TABLES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) static struct fib6_table *fib6_alloc_table(struct net *net, u32 id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) struct fib6_table *table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) table = kzalloc(sizeof(*table), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) if (table) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) table->tb6_id = id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) rcu_assign_pointer(table->tb6_root.leaf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) net->ipv6.fib6_null_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) table->tb6_root.fn_flags = RTN_ROOT | RTN_TL_ROOT | RTN_RTINFO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) inet_peer_base_init(&table->tb6_peers);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) return table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) struct fib6_table *fib6_new_table(struct net *net, u32 id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) struct fib6_table *tb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) if (id == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) id = RT6_TABLE_MAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) tb = fib6_get_table(net, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) if (tb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) return tb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) tb = fib6_alloc_table(net, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) if (tb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) fib6_link_table(net, tb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) return tb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) EXPORT_SYMBOL_GPL(fib6_new_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) struct fib6_table *fib6_get_table(struct net *net, u32 id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) struct fib6_table *tb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) struct hlist_head *head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) unsigned int h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) if (id == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) id = RT6_TABLE_MAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) h = id & (FIB6_TABLE_HASHSZ - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) head = &net->ipv6.fib_table_hash[h];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) hlist_for_each_entry_rcu(tb, head, tb6_hlist) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) if (tb->tb6_id == id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) return tb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) EXPORT_SYMBOL_GPL(fib6_get_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) static void __net_init fib6_tables_init(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) fib6_link_table(net, net->ipv6.fib6_main_tbl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) fib6_link_table(net, net->ipv6.fib6_local_tbl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) struct fib6_table *fib6_new_table(struct net *net, u32 id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) return fib6_get_table(net, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) struct fib6_table *fib6_get_table(struct net *net, u32 id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) return net->ipv6.fib6_main_tbl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) struct dst_entry *fib6_rule_lookup(struct net *net, struct flowi6 *fl6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) const struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) int flags, pol_lookup_t lookup)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) struct rt6_info *rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) rt = pol_lookup_func(lookup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) net, net->ipv6.fib6_main_tbl, fl6, skb, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) if (rt->dst.error == -EAGAIN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) ip6_rt_put_flags(rt, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) rt = net->ipv6.ip6_null_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) if (!(flags & RT6_LOOKUP_F_DST_NOREF))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) dst_hold(&rt->dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) return &rt->dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) /* called with rcu lock held; no reference taken on fib6_info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) int fib6_lookup(struct net *net, int oif, struct flowi6 *fl6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) struct fib6_result *res, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) return fib6_table_lookup(net, net->ipv6.fib6_main_tbl, oif, fl6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) res, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) static void __net_init fib6_tables_init(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) fib6_link_table(net, net->ipv6.fib6_main_tbl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) unsigned int fib6_tables_seq_read(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) unsigned int h, fib_seq = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) for (h = 0; h < FIB6_TABLE_HASHSZ; h++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) struct hlist_head *head = &net->ipv6.fib_table_hash[h];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) struct fib6_table *tb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) hlist_for_each_entry_rcu(tb, head, tb6_hlist)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) fib_seq += tb->fib_seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) return fib_seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) static int call_fib6_entry_notifier(struct notifier_block *nb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) enum fib_event_type event_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) struct fib6_info *rt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) struct fib6_entry_notifier_info info = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) .info.extack = extack,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) .rt = rt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) return call_fib6_notifier(nb, event_type, &info.info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) static int call_fib6_multipath_entry_notifier(struct notifier_block *nb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) enum fib_event_type event_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) struct fib6_info *rt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) unsigned int nsiblings,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) struct fib6_entry_notifier_info info = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) .info.extack = extack,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) .rt = rt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) .nsiblings = nsiblings,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) return call_fib6_notifier(nb, event_type, &info.info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) int call_fib6_entry_notifiers(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) enum fib_event_type event_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) struct fib6_info *rt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) struct fib6_entry_notifier_info info = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) .info.extack = extack,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) .rt = rt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) rt->fib6_table->fib_seq++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) return call_fib6_notifiers(net, event_type, &info.info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) int call_fib6_multipath_entry_notifiers(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) enum fib_event_type event_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) struct fib6_info *rt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) unsigned int nsiblings,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) struct fib6_entry_notifier_info info = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) .info.extack = extack,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) .rt = rt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) .nsiblings = nsiblings,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) rt->fib6_table->fib_seq++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) return call_fib6_notifiers(net, event_type, &info.info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) int call_fib6_entry_notifiers_replace(struct net *net, struct fib6_info *rt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) struct fib6_entry_notifier_info info = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) .rt = rt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) .nsiblings = rt->fib6_nsiblings,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) rt->fib6_table->fib_seq++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) return call_fib6_notifiers(net, FIB_EVENT_ENTRY_REPLACE, &info.info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) struct fib6_dump_arg {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) struct net *net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) struct notifier_block *nb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) struct netlink_ext_ack *extack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) static int fib6_rt_dump(struct fib6_info *rt, struct fib6_dump_arg *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) enum fib_event_type fib_event = FIB_EVENT_ENTRY_REPLACE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) if (!rt || rt == arg->net->ipv6.fib6_null_entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) if (rt->fib6_nsiblings)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) err = call_fib6_multipath_entry_notifier(arg->nb, fib_event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) rt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) rt->fib6_nsiblings,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) arg->extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) err = call_fib6_entry_notifier(arg->nb, fib_event, rt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) arg->extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) static int fib6_node_dump(struct fib6_walker *w)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) err = fib6_rt_dump(w->leaf, w->args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) w->leaf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) static int fib6_table_dump(struct net *net, struct fib6_table *tb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) struct fib6_walker *w)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) w->root = &tb->tb6_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) spin_lock_bh(&tb->tb6_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) err = fib6_walk(net, w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) spin_unlock_bh(&tb->tb6_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) /* Called with rcu_read_lock() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) int fib6_tables_dump(struct net *net, struct notifier_block *nb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) struct fib6_dump_arg arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) struct fib6_walker *w;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) unsigned int h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) w = kzalloc(sizeof(*w), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) if (!w)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) w->func = fib6_node_dump;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) arg.net = net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) arg.nb = nb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) arg.extack = extack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) w->args = &arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) for (h = 0; h < FIB6_TABLE_HASHSZ; h++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) struct hlist_head *head = &net->ipv6.fib_table_hash[h];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) struct fib6_table *tb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) hlist_for_each_entry_rcu(tb, head, tb6_hlist) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) err = fib6_table_dump(net, tb, w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) kfree(w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) static int fib6_dump_node(struct fib6_walker *w)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) int res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) struct fib6_info *rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) for_each_fib6_walker_rt(w) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) res = rt6_dump_route(rt, w->args, w->skip_in_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) if (res >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) /* Frame is full, suspend walking */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) w->leaf = rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) /* We'll restart from this node, so if some routes were
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) * already dumped, skip them next time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) w->skip_in_node += res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) w->skip_in_node = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) /* Multipath routes are dumped in one route with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) * RTA_MULTIPATH attribute. Jump 'rt' to point to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) * last sibling of this route (no need to dump the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) * sibling routes again)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) if (rt->fib6_nsiblings)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) rt = list_last_entry(&rt->fib6_siblings,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) struct fib6_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) fib6_siblings);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) w->leaf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) static void fib6_dump_end(struct netlink_callback *cb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) struct net *net = sock_net(cb->skb->sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) struct fib6_walker *w = (void *)cb->args[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) if (w) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) if (cb->args[4]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) cb->args[4] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) fib6_walker_unlink(net, w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) cb->args[2] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) kfree(w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) cb->done = (void *)cb->args[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) cb->args[1] = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) static int fib6_dump_done(struct netlink_callback *cb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) fib6_dump_end(cb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) return cb->done ? cb->done(cb) : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) static int fib6_dump_table(struct fib6_table *table, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) struct netlink_callback *cb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) struct net *net = sock_net(skb->sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) struct fib6_walker *w;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) int res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) w = (void *)cb->args[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) w->root = &table->tb6_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) if (cb->args[4] == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) w->count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) w->skip = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) w->skip_in_node = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) spin_lock_bh(&table->tb6_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) res = fib6_walk(net, w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) spin_unlock_bh(&table->tb6_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) if (res > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) cb->args[4] = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) cb->args[5] = READ_ONCE(w->root->fn_sernum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) int sernum = READ_ONCE(w->root->fn_sernum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) if (cb->args[5] != sernum) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) /* Begin at the root if the tree changed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) cb->args[5] = sernum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) w->state = FWS_INIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) w->node = w->root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) w->skip = w->count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) w->skip_in_node = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) w->skip = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) spin_lock_bh(&table->tb6_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) res = fib6_walk_continue(w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) spin_unlock_bh(&table->tb6_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) if (res <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) fib6_walker_unlink(net, w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) cb->args[4] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) static int inet6_dump_fib(struct sk_buff *skb, struct netlink_callback *cb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) struct rt6_rtnl_dump_arg arg = { .filter.dump_exceptions = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) .filter.dump_routes = true };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) const struct nlmsghdr *nlh = cb->nlh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) struct net *net = sock_net(skb->sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) unsigned int h, s_h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) unsigned int e = 0, s_e;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) struct fib6_walker *w;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) struct fib6_table *tb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) struct hlist_head *head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) int res = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) if (cb->strict_check) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) err = ip_valid_fib_dump_req(net, nlh, &arg.filter, cb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) } else if (nlmsg_len(nlh) >= sizeof(struct rtmsg)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) struct rtmsg *rtm = nlmsg_data(nlh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) if (rtm->rtm_flags & RTM_F_PREFIX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) arg.filter.flags = RTM_F_PREFIX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) w = (void *)cb->args[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) if (!w) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) /* New dump:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) * 1. hook callback destructor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) cb->args[3] = (long)cb->done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) cb->done = fib6_dump_done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) * 2. allocate and initialize walker.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) w = kzalloc(sizeof(*w), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) if (!w)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) w->func = fib6_dump_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) cb->args[2] = (long)w;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) arg.skb = skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) arg.cb = cb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) arg.net = net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) w->args = &arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) if (arg.filter.table_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) tb = fib6_get_table(net, arg.filter.table_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) if (!tb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) if (rtnl_msg_family(cb->nlh) != PF_INET6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) NL_SET_ERR_MSG_MOD(cb->extack, "FIB table does not exist");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) if (!cb->args[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) res = fib6_dump_table(tb, skb, cb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) if (!res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) cb->args[0] = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) s_h = cb->args[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) s_e = cb->args[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) for (h = s_h; h < FIB6_TABLE_HASHSZ; h++, s_e = 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) e = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) head = &net->ipv6.fib_table_hash[h];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) hlist_for_each_entry_rcu(tb, head, tb6_hlist) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) if (e < s_e)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) goto next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) res = fib6_dump_table(tb, skb, cb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) if (res != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) next:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) e++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) cb->args[1] = e;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) cb->args[0] = h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) res = res < 0 ? res : skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) if (res <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) fib6_dump_end(cb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) void fib6_metric_set(struct fib6_info *f6i, int metric, u32 val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) if (!f6i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) if (f6i->fib6_metrics == &dst_default_metrics) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) struct dst_metrics *p = kzalloc(sizeof(*p), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) if (!p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) refcount_set(&p->refcnt, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) f6i->fib6_metrics = p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) f6i->fib6_metrics->metrics[metric - 1] = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) * Routing Table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) * return the appropriate node for a routing tree "add" operation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) * by either creating and inserting or by returning an existing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) * node.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) static struct fib6_node *fib6_add_1(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) struct fib6_table *table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) struct fib6_node *root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) struct in6_addr *addr, int plen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) int offset, int allow_create,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) int replace_required,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) struct fib6_node *fn, *in, *ln;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) struct fib6_node *pn = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) struct rt6key *key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) int bit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) __be32 dir = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) RT6_TRACE("fib6_add_1\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) /* insert node in tree */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) fn = root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) struct fib6_info *leaf = rcu_dereference_protected(fn->leaf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) lockdep_is_held(&table->tb6_lock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) key = (struct rt6key *)((u8 *)leaf + offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) * Prefix match
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) if (plen < fn->fn_bit ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) !ipv6_prefix_equal(&key->addr, addr, fn->fn_bit)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) if (!allow_create) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) if (replace_required) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) NL_SET_ERR_MSG(extack,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) "Can not replace route - no match found");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) pr_warn("Can't replace route, no match found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) return ERR_PTR(-ENOENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) pr_warn("NLM_F_CREATE should be set when creating new route\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) goto insert_above;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) * Exact match ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) if (plen == fn->fn_bit) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) /* clean up an intermediate node */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) if (!(fn->fn_flags & RTN_RTINFO)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) RCU_INIT_POINTER(fn->leaf, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) fib6_info_release(leaf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) /* remove null_entry in the root node */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) } else if (fn->fn_flags & RTN_TL_ROOT &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) rcu_access_pointer(fn->leaf) ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) net->ipv6.fib6_null_entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) RCU_INIT_POINTER(fn->leaf, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) return fn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) * We have more bits to go
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) /* Try to walk down on tree. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) dir = addr_bit_set(addr, fn->fn_bit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) pn = fn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) fn = dir ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) rcu_dereference_protected(fn->right,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) lockdep_is_held(&table->tb6_lock)) :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) rcu_dereference_protected(fn->left,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) lockdep_is_held(&table->tb6_lock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) } while (fn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) if (!allow_create) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) /* We should not create new node because
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) * NLM_F_REPLACE was specified without NLM_F_CREATE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) * I assume it is safe to require NLM_F_CREATE when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) * REPLACE flag is used! Later we may want to remove the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) * check for replace_required, because according
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) * to netlink specification, NLM_F_CREATE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) * MUST be specified if new route is created.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) * That would keep IPv6 consistent with IPv4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) if (replace_required) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) NL_SET_ERR_MSG(extack,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) "Can not replace route - no match found");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) pr_warn("Can't replace route, no match found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) return ERR_PTR(-ENOENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) pr_warn("NLM_F_CREATE should be set when creating new route\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) * We walked to the bottom of tree.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) * Create new leaf node without children.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) ln = node_alloc(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) if (!ln)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) ln->fn_bit = plen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) RCU_INIT_POINTER(ln->parent, pn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) if (dir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) rcu_assign_pointer(pn->right, ln);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) rcu_assign_pointer(pn->left, ln);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) return ln;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) insert_above:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) * split since we don't have a common prefix anymore or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) * we have a less significant route.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) * we've to insert an intermediate node on the list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) * this new node will point to the one we need to create
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) * and the current
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) pn = rcu_dereference_protected(fn->parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) lockdep_is_held(&table->tb6_lock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) /* find 1st bit in difference between the 2 addrs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) See comment in __ipv6_addr_diff: bit may be an invalid value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) but if it is >= plen, the value is ignored in any case.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) bit = __ipv6_addr_diff(addr, &key->addr, sizeof(*addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) * (intermediate)[in]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) * / \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) * (new leaf node)[ln] (old node)[fn]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) if (plen > bit) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) in = node_alloc(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) ln = node_alloc(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) if (!in || !ln) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) if (in)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) node_free_immediate(net, in);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) if (ln)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) node_free_immediate(net, ln);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) * new intermediate node.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) * RTN_RTINFO will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) * be off since that an address that chooses one of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) * the branches would not match less specific routes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) * in the other branch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) in->fn_bit = bit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) RCU_INIT_POINTER(in->parent, pn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) in->leaf = fn->leaf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) fib6_info_hold(rcu_dereference_protected(in->leaf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) lockdep_is_held(&table->tb6_lock)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) /* update parent pointer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) if (dir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) rcu_assign_pointer(pn->right, in);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) rcu_assign_pointer(pn->left, in);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) ln->fn_bit = plen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) RCU_INIT_POINTER(ln->parent, in);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) rcu_assign_pointer(fn->parent, in);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) if (addr_bit_set(addr, bit)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) rcu_assign_pointer(in->right, ln);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) rcu_assign_pointer(in->left, fn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) rcu_assign_pointer(in->left, ln);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) rcu_assign_pointer(in->right, fn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) } else { /* plen <= bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) * (new leaf node)[ln]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) * / \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) * (old node)[fn] NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) ln = node_alloc(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) if (!ln)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) ln->fn_bit = plen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) RCU_INIT_POINTER(ln->parent, pn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) if (addr_bit_set(&key->addr, plen))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) RCU_INIT_POINTER(ln->right, fn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) RCU_INIT_POINTER(ln->left, fn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) rcu_assign_pointer(fn->parent, ln);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) if (dir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) rcu_assign_pointer(pn->right, ln);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) rcu_assign_pointer(pn->left, ln);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) return ln;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) static void __fib6_drop_pcpu_from(struct fib6_nh *fib6_nh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) const struct fib6_info *match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) const struct fib6_table *table)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) int cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) if (!fib6_nh->rt6i_pcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) /* release the reference to this fib entry from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) * all of its cached pcpu routes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) for_each_possible_cpu(cpu) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) struct rt6_info **ppcpu_rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) struct rt6_info *pcpu_rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) ppcpu_rt = per_cpu_ptr(fib6_nh->rt6i_pcpu, cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) pcpu_rt = *ppcpu_rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) /* only dropping the 'from' reference if the cached route
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) * is using 'match'. The cached pcpu_rt->from only changes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) * from a fib6_info to NULL (ip6_dst_destroy); it can never
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) * change from one fib6_info reference to another
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) if (pcpu_rt && rcu_access_pointer(pcpu_rt->from) == match) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) struct fib6_info *from;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) from = xchg((__force struct fib6_info **)&pcpu_rt->from, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) fib6_info_release(from);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) struct fib6_nh_pcpu_arg {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) struct fib6_info *from;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) const struct fib6_table *table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) static int fib6_nh_drop_pcpu_from(struct fib6_nh *nh, void *_arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) struct fib6_nh_pcpu_arg *arg = _arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) __fib6_drop_pcpu_from(nh, arg->from, arg->table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) static void fib6_drop_pcpu_from(struct fib6_info *f6i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) const struct fib6_table *table)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) /* Make sure rt6_make_pcpu_route() wont add other percpu routes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) * while we are cleaning them here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) f6i->fib6_destroying = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) mb(); /* paired with the cmpxchg() in rt6_make_pcpu_route() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) if (f6i->nh) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) struct fib6_nh_pcpu_arg arg = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) .from = f6i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) .table = table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) nexthop_for_each_fib6_nh(f6i->nh, fib6_nh_drop_pcpu_from,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) &arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) struct fib6_nh *fib6_nh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) fib6_nh = f6i->fib6_nh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) __fib6_drop_pcpu_from(fib6_nh, f6i, table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) static void fib6_purge_rt(struct fib6_info *rt, struct fib6_node *fn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) struct fib6_table *table = rt->fib6_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) /* Flush all cached dst in exception table */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) rt6_flush_exceptions(rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) fib6_drop_pcpu_from(rt, table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) if (rt->nh && !list_empty(&rt->nh_list))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) list_del_init(&rt->nh_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) if (refcount_read(&rt->fib6_ref) != 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) /* This route is used as dummy address holder in some split
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) * nodes. It is not leaked, but it still holds other resources,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) * which must be released in time. So, scan ascendant nodes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) * and replace dummy references to this route with references
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) * to still alive ones.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) while (fn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) struct fib6_info *leaf = rcu_dereference_protected(fn->leaf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) lockdep_is_held(&table->tb6_lock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) struct fib6_info *new_leaf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) if (!(fn->fn_flags & RTN_RTINFO) && leaf == rt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) new_leaf = fib6_find_prefix(net, table, fn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) fib6_info_hold(new_leaf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) rcu_assign_pointer(fn->leaf, new_leaf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) fib6_info_release(rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) fn = rcu_dereference_protected(fn->parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) lockdep_is_held(&table->tb6_lock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) * Insert routing information in a node.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) static int fib6_add_rt2node(struct fib6_node *fn, struct fib6_info *rt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) struct nl_info *info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) struct fib6_info *leaf = rcu_dereference_protected(fn->leaf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) lockdep_is_held(&rt->fib6_table->tb6_lock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) struct fib6_info *iter = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) struct fib6_info __rcu **ins;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) struct fib6_info __rcu **fallback_ins = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) int replace = (info->nlh &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) (info->nlh->nlmsg_flags & NLM_F_REPLACE));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) int add = (!info->nlh ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) (info->nlh->nlmsg_flags & NLM_F_CREATE));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) int found = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) bool rt_can_ecmp = rt6_qualify_for_ecmp(rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) bool notify_sibling_rt = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) u16 nlflags = NLM_F_EXCL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) if (info->nlh && (info->nlh->nlmsg_flags & NLM_F_APPEND))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) nlflags |= NLM_F_APPEND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) ins = &fn->leaf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) for (iter = leaf; iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) iter = rcu_dereference_protected(iter->fib6_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) lockdep_is_held(&rt->fib6_table->tb6_lock))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) * Search for duplicates
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) if (iter->fib6_metric == rt->fib6_metric) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) * Same priority level
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) if (info->nlh &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) (info->nlh->nlmsg_flags & NLM_F_EXCL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) return -EEXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) nlflags &= ~NLM_F_EXCL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) if (replace) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) if (rt_can_ecmp == rt6_qualify_for_ecmp(iter)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) found++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) fallback_ins = fallback_ins ?: ins;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) goto next_iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) if (rt6_duplicate_nexthop(iter, rt)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) if (rt->fib6_nsiblings)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) rt->fib6_nsiblings = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) if (!(iter->fib6_flags & RTF_EXPIRES))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) return -EEXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) if (!(rt->fib6_flags & RTF_EXPIRES))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) fib6_clean_expires(iter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) fib6_set_expires(iter, rt->expires);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) if (rt->fib6_pmtu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) fib6_metric_set(iter, RTAX_MTU,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) rt->fib6_pmtu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) return -EEXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) /* If we have the same destination and the same metric,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) * but not the same gateway, then the route we try to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) * add is sibling to this route, increment our counter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) * of siblings, and later we will add our route to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) * list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) * Only static routes (which don't have flag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) * RTF_EXPIRES) are used for ECMPv6.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) * To avoid long list, we only had siblings if the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) * route have a gateway.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) if (rt_can_ecmp &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) rt6_qualify_for_ecmp(iter))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) rt->fib6_nsiblings++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) if (iter->fib6_metric > rt->fib6_metric)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) next_iter:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) ins = &iter->fib6_next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) if (fallback_ins && !found) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) /* No matching route with same ecmp-able-ness found, replace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) * first matching route
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) ins = fallback_ins;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) iter = rcu_dereference_protected(*ins,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) lockdep_is_held(&rt->fib6_table->tb6_lock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) found++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) /* Reset round-robin state, if necessary */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) if (ins == &fn->leaf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) fn->rr_ptr = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) /* Link this route to others same route. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) if (rt->fib6_nsiblings) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) unsigned int fib6_nsiblings;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) struct fib6_info *sibling, *temp_sibling;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) /* Find the first route that have the same metric */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) sibling = leaf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) notify_sibling_rt = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) while (sibling) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) if (sibling->fib6_metric == rt->fib6_metric &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) rt6_qualify_for_ecmp(sibling)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) list_add_tail(&rt->fib6_siblings,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) &sibling->fib6_siblings);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) sibling = rcu_dereference_protected(sibling->fib6_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) lockdep_is_held(&rt->fib6_table->tb6_lock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) notify_sibling_rt = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) /* For each sibling in the list, increment the counter of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) * siblings. BUG() if counters does not match, list of siblings
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) * is broken!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) fib6_nsiblings = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) list_for_each_entry_safe(sibling, temp_sibling,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) &rt->fib6_siblings, fib6_siblings) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) sibling->fib6_nsiblings++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) BUG_ON(sibling->fib6_nsiblings != rt->fib6_nsiblings);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) fib6_nsiblings++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) BUG_ON(fib6_nsiblings != rt->fib6_nsiblings);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) rt6_multipath_rebalance(temp_sibling);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) * insert node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) if (!replace) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) if (!add)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) pr_warn("NLM_F_CREATE should be set when creating new route\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) add:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) nlflags |= NLM_F_CREATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) /* The route should only be notified if it is the first
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) * route in the node or if it is added as a sibling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) * route to the first route in the node.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) if (!info->skip_notify_kernel &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) (notify_sibling_rt || ins == &fn->leaf)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) enum fib_event_type fib_event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) if (notify_sibling_rt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) fib_event = FIB_EVENT_ENTRY_APPEND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) fib_event = FIB_EVENT_ENTRY_REPLACE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) err = call_fib6_entry_notifiers(info->nl_net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) fib_event, rt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) struct fib6_info *sibling, *next_sibling;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) /* If the route has siblings, then it first
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) * needs to be unlinked from them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) if (!rt->fib6_nsiblings)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) list_for_each_entry_safe(sibling, next_sibling,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) &rt->fib6_siblings,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) fib6_siblings)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) sibling->fib6_nsiblings--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) rt->fib6_nsiblings = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) list_del_init(&rt->fib6_siblings);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) rt6_multipath_rebalance(next_sibling);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) rcu_assign_pointer(rt->fib6_next, iter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) fib6_info_hold(rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) rcu_assign_pointer(rt->fib6_node, fn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) rcu_assign_pointer(*ins, rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) if (!info->skip_notify)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) inet6_rt_notify(RTM_NEWROUTE, rt, info, nlflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) info->nl_net->ipv6.rt6_stats->fib_rt_entries++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) if (!(fn->fn_flags & RTN_RTINFO)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) info->nl_net->ipv6.rt6_stats->fib_route_nodes++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) fn->fn_flags |= RTN_RTINFO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) int nsiblings;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) if (!found) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) if (add)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) goto add;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) pr_warn("NLM_F_REPLACE set, but no existing node found!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) if (!info->skip_notify_kernel && ins == &fn->leaf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) err = call_fib6_entry_notifiers(info->nl_net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) FIB_EVENT_ENTRY_REPLACE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) rt, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) fib6_info_hold(rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) rcu_assign_pointer(rt->fib6_node, fn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) rt->fib6_next = iter->fib6_next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) rcu_assign_pointer(*ins, rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) if (!info->skip_notify)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) inet6_rt_notify(RTM_NEWROUTE, rt, info, NLM_F_REPLACE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) if (!(fn->fn_flags & RTN_RTINFO)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) info->nl_net->ipv6.rt6_stats->fib_route_nodes++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) fn->fn_flags |= RTN_RTINFO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) nsiblings = iter->fib6_nsiblings;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) iter->fib6_node = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) fib6_purge_rt(iter, fn, info->nl_net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) if (rcu_access_pointer(fn->rr_ptr) == iter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) fn->rr_ptr = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) fib6_info_release(iter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) if (nsiblings) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) /* Replacing an ECMP route, remove all siblings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) ins = &rt->fib6_next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) iter = rcu_dereference_protected(*ins,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) lockdep_is_held(&rt->fib6_table->tb6_lock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) while (iter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) if (iter->fib6_metric > rt->fib6_metric)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) if (rt6_qualify_for_ecmp(iter)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) *ins = iter->fib6_next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) iter->fib6_node = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) fib6_purge_rt(iter, fn, info->nl_net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) if (rcu_access_pointer(fn->rr_ptr) == iter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) fn->rr_ptr = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) fib6_info_release(iter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) nsiblings--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) info->nl_net->ipv6.rt6_stats->fib_rt_entries--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) ins = &iter->fib6_next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) iter = rcu_dereference_protected(*ins,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) lockdep_is_held(&rt->fib6_table->tb6_lock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) WARN_ON(nsiblings != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) static void fib6_start_gc(struct net *net, struct fib6_info *rt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) if (!timer_pending(&net->ipv6.ip6_fib_timer) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) (rt->fib6_flags & RTF_EXPIRES))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) mod_timer(&net->ipv6.ip6_fib_timer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) jiffies + net->ipv6.sysctl.ip6_rt_gc_interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) void fib6_force_start_gc(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) if (!timer_pending(&net->ipv6.ip6_fib_timer))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) mod_timer(&net->ipv6.ip6_fib_timer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) jiffies + net->ipv6.sysctl.ip6_rt_gc_interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) static void __fib6_update_sernum_upto_root(struct fib6_info *rt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) int sernum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) struct fib6_node *fn = rcu_dereference_protected(rt->fib6_node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) lockdep_is_held(&rt->fib6_table->tb6_lock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) /* paired with smp_rmb() in rt6_get_cookie_safe() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) smp_wmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) while (fn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) WRITE_ONCE(fn->fn_sernum, sernum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) fn = rcu_dereference_protected(fn->parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) lockdep_is_held(&rt->fib6_table->tb6_lock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) void fib6_update_sernum_upto_root(struct net *net, struct fib6_info *rt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) __fib6_update_sernum_upto_root(rt, fib6_new_sernum(net));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) /* allow ipv4 to update sernum via ipv6_stub */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) void fib6_update_sernum_stub(struct net *net, struct fib6_info *f6i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) spin_lock_bh(&f6i->fib6_table->tb6_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) fib6_update_sernum_upto_root(net, f6i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) spin_unlock_bh(&f6i->fib6_table->tb6_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) * Add routing information to the routing tree.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) * <destination addr>/<source addr>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) * with source addr info in sub-trees
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) * Need to own table->tb6_lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) int fib6_add(struct fib6_node *root, struct fib6_info *rt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) struct nl_info *info, struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) struct fib6_table *table = rt->fib6_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) struct fib6_node *fn, *pn = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) int err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) int allow_create = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) int replace_required = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) if (info->nlh) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) if (!(info->nlh->nlmsg_flags & NLM_F_CREATE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) allow_create = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) if (info->nlh->nlmsg_flags & NLM_F_REPLACE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) replace_required = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) if (!allow_create && !replace_required)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) pr_warn("RTM_NEWROUTE with no NLM_F_CREATE or NLM_F_REPLACE\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) fn = fib6_add_1(info->nl_net, table, root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) &rt->fib6_dst.addr, rt->fib6_dst.plen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) offsetof(struct fib6_info, fib6_dst), allow_create,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) replace_required, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) if (IS_ERR(fn)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) err = PTR_ERR(fn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) fn = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) pn = fn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) #ifdef CONFIG_IPV6_SUBTREES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) if (rt->fib6_src.plen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) struct fib6_node *sn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) if (!rcu_access_pointer(fn->subtree)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) struct fib6_node *sfn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) * Create subtree.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) * fn[main tree]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) * |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) * sfn[subtree root]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) * \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) * sn[new leaf node]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) /* Create subtree root node */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) sfn = node_alloc(info->nl_net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) if (!sfn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) goto failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) fib6_info_hold(info->nl_net->ipv6.fib6_null_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) rcu_assign_pointer(sfn->leaf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) info->nl_net->ipv6.fib6_null_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) sfn->fn_flags = RTN_ROOT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) /* Now add the first leaf node to new subtree */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) sn = fib6_add_1(info->nl_net, table, sfn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) &rt->fib6_src.addr, rt->fib6_src.plen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) offsetof(struct fib6_info, fib6_src),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) allow_create, replace_required, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) if (IS_ERR(sn)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) /* If it is failed, discard just allocated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) root, and then (in failure) stale node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) in main tree.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) node_free_immediate(info->nl_net, sfn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) err = PTR_ERR(sn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) goto failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) /* Now link new subtree to main tree */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) rcu_assign_pointer(sfn->parent, fn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) rcu_assign_pointer(fn->subtree, sfn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) sn = fib6_add_1(info->nl_net, table, FIB6_SUBTREE(fn),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) &rt->fib6_src.addr, rt->fib6_src.plen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) offsetof(struct fib6_info, fib6_src),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) allow_create, replace_required, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) if (IS_ERR(sn)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) err = PTR_ERR(sn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) goto failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) if (!rcu_access_pointer(fn->leaf)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) if (fn->fn_flags & RTN_TL_ROOT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) /* put back null_entry for root node */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) rcu_assign_pointer(fn->leaf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) info->nl_net->ipv6.fib6_null_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) fib6_info_hold(rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) rcu_assign_pointer(fn->leaf, rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) fn = sn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) err = fib6_add_rt2node(fn, rt, info, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) if (!err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) if (rt->nh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) list_add(&rt->nh_list, &rt->nh->f6i_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) __fib6_update_sernum_upto_root(rt, fib6_new_sernum(info->nl_net));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) fib6_start_gc(info->nl_net, rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) #ifdef CONFIG_IPV6_SUBTREES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) * If fib6_add_1 has cleared the old leaf pointer in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) * super-tree leaf node we have to find a new one for it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) if (pn != fn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) struct fib6_info *pn_leaf =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) rcu_dereference_protected(pn->leaf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) lockdep_is_held(&table->tb6_lock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) if (pn_leaf == rt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) pn_leaf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) RCU_INIT_POINTER(pn->leaf, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) fib6_info_release(rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) if (!pn_leaf && !(pn->fn_flags & RTN_RTINFO)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) pn_leaf = fib6_find_prefix(info->nl_net, table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) pn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) #if RT6_DEBUG >= 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) if (!pn_leaf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) WARN_ON(!pn_leaf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) pn_leaf =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) info->nl_net->ipv6.fib6_null_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) fib6_info_hold(pn_leaf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) rcu_assign_pointer(pn->leaf, pn_leaf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) goto failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) } else if (fib6_requires_src(rt)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) fib6_routes_require_src_inc(info->nl_net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) failure:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) /* fn->leaf could be NULL and fib6_repair_tree() needs to be called if:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) * 1. fn is an intermediate node and we failed to add the new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) * route to it in both subtree creation failure and fib6_add_rt2node()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) * failure case.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) * 2. fn is the root node in the table and we fail to add the first
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) * default route to it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) if (fn &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) (!(fn->fn_flags & (RTN_RTINFO|RTN_ROOT)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) (fn->fn_flags & RTN_TL_ROOT &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) !rcu_access_pointer(fn->leaf))))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) fib6_repair_tree(info->nl_net, table, fn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) * Routing tree lookup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) struct lookup_args {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) int offset; /* key offset on fib6_info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) const struct in6_addr *addr; /* search key */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) static struct fib6_node *fib6_node_lookup_1(struct fib6_node *root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) struct lookup_args *args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) struct fib6_node *fn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) __be32 dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) if (unlikely(args->offset == 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) * Descend on a tree
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) fn = root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) struct fib6_node *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) dir = addr_bit_set(args->addr, fn->fn_bit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) next = dir ? rcu_dereference(fn->right) :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) rcu_dereference(fn->left);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) if (next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) fn = next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) while (fn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) struct fib6_node *subtree = FIB6_SUBTREE(fn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) if (subtree || fn->fn_flags & RTN_RTINFO) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) struct fib6_info *leaf = rcu_dereference(fn->leaf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) struct rt6key *key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) if (!leaf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) goto backtrack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) key = (struct rt6key *) ((u8 *)leaf + args->offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) if (ipv6_prefix_equal(&key->addr, args->addr, key->plen)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) #ifdef CONFIG_IPV6_SUBTREES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) if (subtree) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) struct fib6_node *sfn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) sfn = fib6_node_lookup_1(subtree,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) args + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) if (!sfn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) goto backtrack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) fn = sfn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) if (fn->fn_flags & RTN_RTINFO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) return fn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) backtrack:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) if (fn->fn_flags & RTN_ROOT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) fn = rcu_dereference(fn->parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) /* called with rcu_read_lock() held
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) struct fib6_node *fib6_node_lookup(struct fib6_node *root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) const struct in6_addr *daddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) const struct in6_addr *saddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) struct fib6_node *fn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) struct lookup_args args[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) .offset = offsetof(struct fib6_info, fib6_dst),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) .addr = daddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) #ifdef CONFIG_IPV6_SUBTREES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) .offset = offsetof(struct fib6_info, fib6_src),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) .addr = saddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) .offset = 0, /* sentinel */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) fn = fib6_node_lookup_1(root, daddr ? args : args + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) if (!fn || fn->fn_flags & RTN_TL_ROOT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) fn = root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) return fn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) * Get node with specified destination prefix (and source prefix,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) * if subtrees are used)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) * exact_match == true means we try to find fn with exact match of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) * the passed in prefix addr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) * exact_match == false means we try to find fn with longest prefix
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) * match of the passed in prefix addr. This is useful for finding fn
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) * for cached route as it will be stored in the exception table under
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) * the node with longest prefix length.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) static struct fib6_node *fib6_locate_1(struct fib6_node *root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) const struct in6_addr *addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) int plen, int offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) bool exact_match)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) struct fib6_node *fn, *prev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) for (fn = root; fn ; ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) struct fib6_info *leaf = rcu_dereference(fn->leaf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) struct rt6key *key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) /* This node is being deleted */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) if (!leaf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) if (plen <= fn->fn_bit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) goto next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) key = (struct rt6key *)((u8 *)leaf + offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) * Prefix match
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) if (plen < fn->fn_bit ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) !ipv6_prefix_equal(&key->addr, addr, fn->fn_bit))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) if (plen == fn->fn_bit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) return fn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) if (fn->fn_flags & RTN_RTINFO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) prev = fn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) next:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) * We have more bits to go
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) if (addr_bit_set(addr, fn->fn_bit))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) fn = rcu_dereference(fn->right);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) fn = rcu_dereference(fn->left);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) if (exact_match)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) return prev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) struct fib6_node *fib6_locate(struct fib6_node *root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) const struct in6_addr *daddr, int dst_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) const struct in6_addr *saddr, int src_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) bool exact_match)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) struct fib6_node *fn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) fn = fib6_locate_1(root, daddr, dst_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) offsetof(struct fib6_info, fib6_dst),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) exact_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) #ifdef CONFIG_IPV6_SUBTREES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) if (src_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) WARN_ON(saddr == NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) if (fn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) struct fib6_node *subtree = FIB6_SUBTREE(fn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) if (subtree) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) fn = fib6_locate_1(subtree, saddr, src_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) offsetof(struct fib6_info, fib6_src),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) exact_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) if (fn && fn->fn_flags & RTN_RTINFO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) return fn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) * Deletion
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) static struct fib6_info *fib6_find_prefix(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) struct fib6_table *table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) struct fib6_node *fn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) struct fib6_node *child_left, *child_right;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) if (fn->fn_flags & RTN_ROOT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) return net->ipv6.fib6_null_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) while (fn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) child_left = rcu_dereference_protected(fn->left,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) lockdep_is_held(&table->tb6_lock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) child_right = rcu_dereference_protected(fn->right,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) lockdep_is_held(&table->tb6_lock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) if (child_left)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) return rcu_dereference_protected(child_left->leaf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) lockdep_is_held(&table->tb6_lock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) if (child_right)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) return rcu_dereference_protected(child_right->leaf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) lockdep_is_held(&table->tb6_lock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) fn = FIB6_SUBTREE(fn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) * Called to trim the tree of intermediate nodes when possible. "fn"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) * is the node we want to try and remove.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) * Need to own table->tb6_lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) static struct fib6_node *fib6_repair_tree(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) struct fib6_table *table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) struct fib6_node *fn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) int children;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) int nstate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) struct fib6_node *child;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) struct fib6_walker *w;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) int iter = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) /* Set fn->leaf to null_entry for root node. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) if (fn->fn_flags & RTN_TL_ROOT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) rcu_assign_pointer(fn->leaf, net->ipv6.fib6_null_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) return fn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) struct fib6_node *fn_r = rcu_dereference_protected(fn->right,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) lockdep_is_held(&table->tb6_lock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) struct fib6_node *fn_l = rcu_dereference_protected(fn->left,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) lockdep_is_held(&table->tb6_lock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) struct fib6_node *pn = rcu_dereference_protected(fn->parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) lockdep_is_held(&table->tb6_lock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) struct fib6_node *pn_r = rcu_dereference_protected(pn->right,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) lockdep_is_held(&table->tb6_lock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) struct fib6_node *pn_l = rcu_dereference_protected(pn->left,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) lockdep_is_held(&table->tb6_lock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) struct fib6_info *fn_leaf = rcu_dereference_protected(fn->leaf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) lockdep_is_held(&table->tb6_lock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) struct fib6_info *pn_leaf = rcu_dereference_protected(pn->leaf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) lockdep_is_held(&table->tb6_lock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) struct fib6_info *new_fn_leaf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) RT6_TRACE("fixing tree: plen=%d iter=%d\n", fn->fn_bit, iter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) iter++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) WARN_ON(fn->fn_flags & RTN_RTINFO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) WARN_ON(fn->fn_flags & RTN_TL_ROOT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) WARN_ON(fn_leaf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) children = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) child = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) if (fn_r) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) child = fn_r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) children |= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) if (fn_l) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) child = fn_l;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) children |= 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) if (children == 3 || FIB6_SUBTREE(fn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) #ifdef CONFIG_IPV6_SUBTREES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) /* Subtree root (i.e. fn) may have one child */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) || (children && fn->fn_flags & RTN_ROOT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) new_fn_leaf = fib6_find_prefix(net, table, fn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) #if RT6_DEBUG >= 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) if (!new_fn_leaf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) WARN_ON(!new_fn_leaf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) new_fn_leaf = net->ipv6.fib6_null_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) fib6_info_hold(new_fn_leaf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) rcu_assign_pointer(fn->leaf, new_fn_leaf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) return pn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) #ifdef CONFIG_IPV6_SUBTREES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) if (FIB6_SUBTREE(pn) == fn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) WARN_ON(!(fn->fn_flags & RTN_ROOT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) RCU_INIT_POINTER(pn->subtree, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) nstate = FWS_L;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) WARN_ON(fn->fn_flags & RTN_ROOT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) if (pn_r == fn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) rcu_assign_pointer(pn->right, child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) else if (pn_l == fn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) rcu_assign_pointer(pn->left, child);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) #if RT6_DEBUG >= 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) WARN_ON(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) if (child)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) rcu_assign_pointer(child->parent, pn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) nstate = FWS_R;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) #ifdef CONFIG_IPV6_SUBTREES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) read_lock(&net->ipv6.fib6_walker_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) FOR_WALKERS(net, w) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) if (!child) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) if (w->node == fn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) RT6_TRACE("W %p adjusted by delnode 1, s=%d/%d\n", w, w->state, nstate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) w->node = pn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) w->state = nstate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) if (w->node == fn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) w->node = child;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) if (children&2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) RT6_TRACE("W %p adjusted by delnode 2, s=%d\n", w, w->state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) w->state = w->state >= FWS_R ? FWS_U : FWS_INIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) RT6_TRACE("W %p adjusted by delnode 2, s=%d\n", w, w->state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) w->state = w->state >= FWS_C ? FWS_U : FWS_INIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) read_unlock(&net->ipv6.fib6_walker_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) node_free(net, fn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) if (pn->fn_flags & RTN_RTINFO || FIB6_SUBTREE(pn))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) return pn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) RCU_INIT_POINTER(pn->leaf, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) fib6_info_release(pn_leaf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) fn = pn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) static void fib6_del_route(struct fib6_table *table, struct fib6_node *fn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) struct fib6_info __rcu **rtp, struct nl_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) struct fib6_info *leaf, *replace_rt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) struct fib6_walker *w;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) struct fib6_info *rt = rcu_dereference_protected(*rtp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) lockdep_is_held(&table->tb6_lock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) struct net *net = info->nl_net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) bool notify_del = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) RT6_TRACE("fib6_del_route\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) /* If the deleted route is the first in the node and it is not part of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) * a multipath route, then we need to replace it with the next route
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) * in the node, if exists.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) leaf = rcu_dereference_protected(fn->leaf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) lockdep_is_held(&table->tb6_lock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) if (leaf == rt && !rt->fib6_nsiblings) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) if (rcu_access_pointer(rt->fib6_next))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) replace_rt = rcu_dereference_protected(rt->fib6_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) lockdep_is_held(&table->tb6_lock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) notify_del = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) /* Unlink it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) *rtp = rt->fib6_next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) rt->fib6_node = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) net->ipv6.rt6_stats->fib_rt_entries--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) net->ipv6.rt6_stats->fib_discarded_routes++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) /* Reset round-robin state, if necessary */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) if (rcu_access_pointer(fn->rr_ptr) == rt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) fn->rr_ptr = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) /* Remove this entry from other siblings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) if (rt->fib6_nsiblings) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) struct fib6_info *sibling, *next_sibling;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) /* The route is deleted from a multipath route. If this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) * multipath route is the first route in the node, then we need
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) * to emit a delete notification. Otherwise, we need to skip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) * the notification.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) if (rt->fib6_metric == leaf->fib6_metric &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) rt6_qualify_for_ecmp(leaf))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) notify_del = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) list_for_each_entry_safe(sibling, next_sibling,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) &rt->fib6_siblings, fib6_siblings)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) sibling->fib6_nsiblings--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) rt->fib6_nsiblings = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) list_del_init(&rt->fib6_siblings);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) rt6_multipath_rebalance(next_sibling);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) /* Adjust walkers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) read_lock(&net->ipv6.fib6_walker_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) FOR_WALKERS(net, w) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) if (w->state == FWS_C && w->leaf == rt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) RT6_TRACE("walker %p adjusted by delroute\n", w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) w->leaf = rcu_dereference_protected(rt->fib6_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) lockdep_is_held(&table->tb6_lock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) if (!w->leaf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) w->state = FWS_U;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) read_unlock(&net->ipv6.fib6_walker_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) /* If it was last route, call fib6_repair_tree() to:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) * 1. For root node, put back null_entry as how the table was created.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) * 2. For other nodes, expunge its radix tree node.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) if (!rcu_access_pointer(fn->leaf)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) if (!(fn->fn_flags & RTN_TL_ROOT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) fn->fn_flags &= ~RTN_RTINFO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) net->ipv6.rt6_stats->fib_route_nodes--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) fn = fib6_repair_tree(net, table, fn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) fib6_purge_rt(rt, fn, net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) if (!info->skip_notify_kernel) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) if (notify_del)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) call_fib6_entry_notifiers(net, FIB_EVENT_ENTRY_DEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) rt, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) else if (replace_rt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) call_fib6_entry_notifiers_replace(net, replace_rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) if (!info->skip_notify)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) inet6_rt_notify(RTM_DELROUTE, rt, info, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) fib6_info_release(rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) /* Need to own table->tb6_lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) int fib6_del(struct fib6_info *rt, struct nl_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) struct net *net = info->nl_net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) struct fib6_info __rcu **rtp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) struct fib6_info __rcu **rtp_next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) struct fib6_table *table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) struct fib6_node *fn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) if (rt == net->ipv6.fib6_null_entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) table = rt->fib6_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) fn = rcu_dereference_protected(rt->fib6_node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) lockdep_is_held(&table->tb6_lock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011) if (!fn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) WARN_ON(!(fn->fn_flags & RTN_RTINFO));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) * Walk the leaf entries looking for ourself
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) for (rtp = &fn->leaf; *rtp; rtp = rtp_next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) struct fib6_info *cur = rcu_dereference_protected(*rtp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) lockdep_is_held(&table->tb6_lock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) if (rt == cur) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024) if (fib6_requires_src(cur))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) fib6_routes_require_src_dec(info->nl_net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) fib6_del_route(table, fn, rtp, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029) rtp_next = &cur->fib6_next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035) * Tree traversal function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) * Certainly, it is not interrupt safe.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) * However, it is internally reenterable wrt itself and fib6_add/fib6_del.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039) * It means, that we can modify tree during walking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040) * and use this function for garbage collection, clone pruning,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041) * cleaning tree when a device goes down etc. etc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) * It guarantees that every node will be traversed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044) * and that it will be traversed only once.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046) * Callback function w->func may return:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047) * 0 -> continue walking.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048) * positive value -> walking is suspended (used by tree dumps,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) * and probably by gc, if it will be split to several slices)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) * negative value -> terminate walking.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052) * The function itself returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053) * 0 -> walk is complete.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) * >0 -> walk is incomplete (i.e. suspended)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055) * <0 -> walk is terminated by an error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057) * This function is called with tb6_lock held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060) static int fib6_walk_continue(struct fib6_walker *w)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) struct fib6_node *fn, *pn, *left, *right;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064) /* w->root should always be table->tb6_root */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065) WARN_ON_ONCE(!(w->root->fn_flags & RTN_TL_ROOT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068) fn = w->node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069) if (!fn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072) switch (w->state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073) #ifdef CONFIG_IPV6_SUBTREES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) case FWS_S:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075) if (FIB6_SUBTREE(fn)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076) w->node = FIB6_SUBTREE(fn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079) w->state = FWS_L;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) case FWS_L:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083) left = rcu_dereference_protected(fn->left, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084) if (left) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085) w->node = left;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) w->state = FWS_INIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089) w->state = FWS_R;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091) case FWS_R:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092) right = rcu_dereference_protected(fn->right, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093) if (right) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094) w->node = right;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095) w->state = FWS_INIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098) w->state = FWS_C;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099) w->leaf = rcu_dereference_protected(fn->leaf, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) case FWS_C:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102) if (w->leaf && fn->fn_flags & RTN_RTINFO) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105) if (w->skip) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106) w->skip--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107) goto skip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110) err = w->func(w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114) w->count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117) skip:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118) w->state = FWS_U;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120) case FWS_U:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121) if (fn == w->root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123) pn = rcu_dereference_protected(fn->parent, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124) left = rcu_dereference_protected(pn->left, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125) right = rcu_dereference_protected(pn->right, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126) w->node = pn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127) #ifdef CONFIG_IPV6_SUBTREES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128) if (FIB6_SUBTREE(pn) == fn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129) WARN_ON(!(fn->fn_flags & RTN_ROOT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130) w->state = FWS_L;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134) if (left == fn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135) w->state = FWS_R;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138) if (right == fn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139) w->state = FWS_C;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140) w->leaf = rcu_dereference_protected(w->node->leaf, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143) #if RT6_DEBUG >= 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144) WARN_ON(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150) static int fib6_walk(struct net *net, struct fib6_walker *w)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152) int res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154) w->state = FWS_INIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155) w->node = w->root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157) fib6_walker_link(net, w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158) res = fib6_walk_continue(w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159) if (res <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160) fib6_walker_unlink(net, w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164) static int fib6_clean_node(struct fib6_walker *w)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166) int res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167) struct fib6_info *rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168) struct fib6_cleaner *c = container_of(w, struct fib6_cleaner, w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169) struct nl_info info = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170) .nl_net = c->net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171) .skip_notify = c->skip_notify,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174) if (c->sernum != FIB6_NO_SERNUM_CHANGE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175) READ_ONCE(w->node->fn_sernum) != c->sernum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176) WRITE_ONCE(w->node->fn_sernum, c->sernum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178) if (!c->func) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179) WARN_ON_ONCE(c->sernum == FIB6_NO_SERNUM_CHANGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180) w->leaf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184) for_each_fib6_walker_rt(w) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2185) res = c->func(rt, c->arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2186) if (res == -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2187) w->leaf = rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2188) res = fib6_del(rt, &info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2189) if (res) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2190) #if RT6_DEBUG >= 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2191) pr_debug("%s: del failed: rt=%p@%p err=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2192) __func__, rt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2193) rcu_access_pointer(rt->fib6_node),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2194) res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2195) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2196) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2197) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2198) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2199) } else if (res == -2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2200) if (WARN_ON(!rt->fib6_nsiblings))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2201) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2202) rt = list_last_entry(&rt->fib6_siblings,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2203) struct fib6_info, fib6_siblings);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2204) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2206) WARN_ON(res != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2208) w->leaf = rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2209) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2212) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2213) * Convenient frontend to tree walker.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2214) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2215) * func is called on each route.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2216) * It may return -2 -> skip multipath route.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2217) * -1 -> delete this route.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2218) * 0 -> continue walking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2219) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2221) static void fib6_clean_tree(struct net *net, struct fib6_node *root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2222) int (*func)(struct fib6_info *, void *arg),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2223) int sernum, void *arg, bool skip_notify)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2224) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2225) struct fib6_cleaner c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2227) c.w.root = root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2228) c.w.func = fib6_clean_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2229) c.w.count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2230) c.w.skip = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2231) c.w.skip_in_node = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2232) c.func = func;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2233) c.sernum = sernum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2234) c.arg = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2235) c.net = net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2236) c.skip_notify = skip_notify;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2238) fib6_walk(net, &c.w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2241) static void __fib6_clean_all(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2242) int (*func)(struct fib6_info *, void *),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2243) int sernum, void *arg, bool skip_notify)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2244) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2245) struct fib6_table *table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2246) struct hlist_head *head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2247) unsigned int h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2249) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2250) for (h = 0; h < FIB6_TABLE_HASHSZ; h++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2251) head = &net->ipv6.fib_table_hash[h];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2252) hlist_for_each_entry_rcu(table, head, tb6_hlist) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2253) spin_lock_bh(&table->tb6_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2254) fib6_clean_tree(net, &table->tb6_root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2255) func, sernum, arg, skip_notify);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2256) spin_unlock_bh(&table->tb6_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2258) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2259) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2262) void fib6_clean_all(struct net *net, int (*func)(struct fib6_info *, void *),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2263) void *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2264) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2265) __fib6_clean_all(net, func, FIB6_NO_SERNUM_CHANGE, arg, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2266) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2268) void fib6_clean_all_skip_notify(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2269) int (*func)(struct fib6_info *, void *),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2270) void *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2271) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2272) __fib6_clean_all(net, func, FIB6_NO_SERNUM_CHANGE, arg, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2275) static void fib6_flush_trees(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2276) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2277) int new_sernum = fib6_new_sernum(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2279) __fib6_clean_all(net, NULL, new_sernum, NULL, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2282) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2283) * Garbage collection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2284) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2286) static int fib6_age(struct fib6_info *rt, void *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2287) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2288) struct fib6_gc_args *gc_args = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2289) unsigned long now = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2291) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2292) * check addrconf expiration here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2293) * Routes are expired even if they are in use.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2294) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2296) if (rt->fib6_flags & RTF_EXPIRES && rt->expires) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2297) if (time_after(now, rt->expires)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2298) RT6_TRACE("expiring %p\n", rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2299) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2301) gc_args->more++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2302) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2304) /* Also age clones in the exception table.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2305) * Note, that clones are aged out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2306) * only if they are not in use now.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2307) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2308) rt6_age_exceptions(rt, gc_args, now);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2310) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2313) void fib6_run_gc(unsigned long expires, struct net *net, bool force)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2314) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2315) struct fib6_gc_args gc_args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2316) unsigned long now;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2318) if (force) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2319) spin_lock_bh(&net->ipv6.fib6_gc_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2320) } else if (!spin_trylock_bh(&net->ipv6.fib6_gc_lock)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2321) mod_timer(&net->ipv6.ip6_fib_timer, jiffies + HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2322) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2324) gc_args.timeout = expires ? (int)expires :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2325) net->ipv6.sysctl.ip6_rt_gc_interval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2326) gc_args.more = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2328) fib6_clean_all(net, fib6_age, &gc_args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2329) now = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2330) net->ipv6.ip6_rt_last_gc = now;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2331)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2332) if (gc_args.more)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2333) mod_timer(&net->ipv6.ip6_fib_timer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2334) round_jiffies(now
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2335) + net->ipv6.sysctl.ip6_rt_gc_interval));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2336) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2337) del_timer(&net->ipv6.ip6_fib_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2338) spin_unlock_bh(&net->ipv6.fib6_gc_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2339) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2341) static void fib6_gc_timer_cb(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2342) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2343) struct net *arg = from_timer(arg, t, ipv6.ip6_fib_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2344)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2345) fib6_run_gc(0, arg, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2346) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2348) static int __net_init fib6_net_init(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2349) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2350) size_t size = sizeof(struct hlist_head) * FIB6_TABLE_HASHSZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2351) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2353) err = fib6_notifier_init(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2354) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2355) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2357) spin_lock_init(&net->ipv6.fib6_gc_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2358) rwlock_init(&net->ipv6.fib6_walker_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2359) INIT_LIST_HEAD(&net->ipv6.fib6_walkers);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2360) timer_setup(&net->ipv6.ip6_fib_timer, fib6_gc_timer_cb, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2361)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2362) net->ipv6.rt6_stats = kzalloc(sizeof(*net->ipv6.rt6_stats), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2363) if (!net->ipv6.rt6_stats)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2364) goto out_timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2366) /* Avoid false sharing : Use at least a full cache line */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2367) size = max_t(size_t, size, L1_CACHE_BYTES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2369) net->ipv6.fib_table_hash = kzalloc(size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2370) if (!net->ipv6.fib_table_hash)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2371) goto out_rt6_stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2373) net->ipv6.fib6_main_tbl = kzalloc(sizeof(*net->ipv6.fib6_main_tbl),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2374) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2375) if (!net->ipv6.fib6_main_tbl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2376) goto out_fib_table_hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2378) net->ipv6.fib6_main_tbl->tb6_id = RT6_TABLE_MAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2379) rcu_assign_pointer(net->ipv6.fib6_main_tbl->tb6_root.leaf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2380) net->ipv6.fib6_null_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2381) net->ipv6.fib6_main_tbl->tb6_root.fn_flags =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2382) RTN_ROOT | RTN_TL_ROOT | RTN_RTINFO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2383) inet_peer_base_init(&net->ipv6.fib6_main_tbl->tb6_peers);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2385) #ifdef CONFIG_IPV6_MULTIPLE_TABLES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2386) net->ipv6.fib6_local_tbl = kzalloc(sizeof(*net->ipv6.fib6_local_tbl),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2387) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2388) if (!net->ipv6.fib6_local_tbl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2389) goto out_fib6_main_tbl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2390) net->ipv6.fib6_local_tbl->tb6_id = RT6_TABLE_LOCAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2391) rcu_assign_pointer(net->ipv6.fib6_local_tbl->tb6_root.leaf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2392) net->ipv6.fib6_null_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2393) net->ipv6.fib6_local_tbl->tb6_root.fn_flags =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2394) RTN_ROOT | RTN_TL_ROOT | RTN_RTINFO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2395) inet_peer_base_init(&net->ipv6.fib6_local_tbl->tb6_peers);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2396) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2397) fib6_tables_init(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2399) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2400)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2401) #ifdef CONFIG_IPV6_MULTIPLE_TABLES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2402) out_fib6_main_tbl:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2403) kfree(net->ipv6.fib6_main_tbl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2404) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2405) out_fib_table_hash:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2406) kfree(net->ipv6.fib_table_hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2407) out_rt6_stats:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2408) kfree(net->ipv6.rt6_stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2409) out_timer:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2410) fib6_notifier_exit(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2411) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2412) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2414) static void fib6_net_exit(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2415) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2416) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2418) del_timer_sync(&net->ipv6.ip6_fib_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2420) for (i = 0; i < FIB6_TABLE_HASHSZ; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2421) struct hlist_head *head = &net->ipv6.fib_table_hash[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2422) struct hlist_node *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2423) struct fib6_table *tb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2424)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2425) hlist_for_each_entry_safe(tb, tmp, head, tb6_hlist) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2426) hlist_del(&tb->tb6_hlist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2427) fib6_free_table(tb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2428) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2429) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2431) kfree(net->ipv6.fib_table_hash);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2432) kfree(net->ipv6.rt6_stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2433) fib6_notifier_exit(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2434) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2435)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2436) static struct pernet_operations fib6_net_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2437) .init = fib6_net_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2438) .exit = fib6_net_exit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2439) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2441) int __init fib6_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2442) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2443) int ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2444)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2445) fib6_node_kmem = kmem_cache_create("fib6_nodes",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2446) sizeof(struct fib6_node),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2447) 0, SLAB_HWCACHE_ALIGN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2448) NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2449) if (!fib6_node_kmem)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2450) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2452) ret = register_pernet_subsys(&fib6_net_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2453) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2454) goto out_kmem_cache_create;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2455)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2456) ret = rtnl_register_module(THIS_MODULE, PF_INET6, RTM_GETROUTE, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2457) inet6_dump_fib, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2458) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2459) goto out_unregister_subsys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2460)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2461) __fib6_flush_trees = fib6_flush_trees;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2462) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2463) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2465) out_unregister_subsys:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2466) unregister_pernet_subsys(&fib6_net_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2467) out_kmem_cache_create:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2468) kmem_cache_destroy(fib6_node_kmem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2469) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2470) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2471)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2472) void fib6_gc_cleanup(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2473) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2474) unregister_pernet_subsys(&fib6_net_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2475) kmem_cache_destroy(fib6_node_kmem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2476) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2477)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2478) #ifdef CONFIG_PROC_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2479) static int ipv6_route_native_seq_show(struct seq_file *seq, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2480) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2481) struct fib6_info *rt = v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2482) struct ipv6_route_iter *iter = seq->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2483) struct fib6_nh *fib6_nh = rt->fib6_nh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2484) unsigned int flags = rt->fib6_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2485) const struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2486)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2487) if (rt->nh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2488) fib6_nh = nexthop_fib6_nh_bh(rt->nh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2489)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2490) seq_printf(seq, "%pi6 %02x ", &rt->fib6_dst.addr, rt->fib6_dst.plen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2491)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2492) #ifdef CONFIG_IPV6_SUBTREES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2493) seq_printf(seq, "%pi6 %02x ", &rt->fib6_src.addr, rt->fib6_src.plen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2494) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2495) seq_puts(seq, "00000000000000000000000000000000 00 ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2496) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2497) if (fib6_nh->fib_nh_gw_family) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2498) flags |= RTF_GATEWAY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2499) seq_printf(seq, "%pi6", &fib6_nh->fib_nh_gw6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2500) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2501) seq_puts(seq, "00000000000000000000000000000000");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2502) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2504) dev = fib6_nh->fib_nh_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2505) seq_printf(seq, " %08x %08x %08x %08x %8s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2506) rt->fib6_metric, refcount_read(&rt->fib6_ref), 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2507) flags, dev ? dev->name : "");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2508) iter->w.leaf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2509) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2510) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2511)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2512) static int ipv6_route_yield(struct fib6_walker *w)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2513) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2514) struct ipv6_route_iter *iter = w->args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2515)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2516) if (!iter->skip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2517) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2518)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2519) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2520) iter->w.leaf = rcu_dereference_protected(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2521) iter->w.leaf->fib6_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2522) lockdep_is_held(&iter->tbl->tb6_lock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2523) iter->skip--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2524) if (!iter->skip && iter->w.leaf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2525) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2526) } while (iter->w.leaf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2527)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2528) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2529) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2530)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2531) static void ipv6_route_seq_setup_walk(struct ipv6_route_iter *iter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2532) struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2533) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2534) memset(&iter->w, 0, sizeof(iter->w));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2535) iter->w.func = ipv6_route_yield;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2536) iter->w.root = &iter->tbl->tb6_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2537) iter->w.state = FWS_INIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2538) iter->w.node = iter->w.root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2539) iter->w.args = iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2540) iter->sernum = READ_ONCE(iter->w.root->fn_sernum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2541) INIT_LIST_HEAD(&iter->w.lh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2542) fib6_walker_link(net, &iter->w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2543) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2544)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2545) static struct fib6_table *ipv6_route_seq_next_table(struct fib6_table *tbl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2546) struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2547) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2548) unsigned int h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2549) struct hlist_node *node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2550)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2551) if (tbl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2552) h = (tbl->tb6_id & (FIB6_TABLE_HASHSZ - 1)) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2553) node = rcu_dereference_bh(hlist_next_rcu(&tbl->tb6_hlist));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2554) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2555) h = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2556) node = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2557) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2558)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2559) while (!node && h < FIB6_TABLE_HASHSZ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2560) node = rcu_dereference_bh(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2561) hlist_first_rcu(&net->ipv6.fib_table_hash[h++]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2562) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2563) return hlist_entry_safe(node, struct fib6_table, tb6_hlist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2564) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2565)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2566) static void ipv6_route_check_sernum(struct ipv6_route_iter *iter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2567) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2568) int sernum = READ_ONCE(iter->w.root->fn_sernum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2569)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2570) if (iter->sernum != sernum) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2571) iter->sernum = sernum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2572) iter->w.state = FWS_INIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2573) iter->w.node = iter->w.root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2574) WARN_ON(iter->w.skip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2575) iter->w.skip = iter->w.count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2576) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2577) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2578)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2579) static void *ipv6_route_seq_next(struct seq_file *seq, void *v, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2580) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2581) int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2582) struct fib6_info *n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2583) struct net *net = seq_file_net(seq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2584) struct ipv6_route_iter *iter = seq->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2585)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2586) ++(*pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2587) if (!v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2588) goto iter_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2589)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2590) n = rcu_dereference_bh(((struct fib6_info *)v)->fib6_next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2591) if (n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2592) return n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2593)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2594) iter_table:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2595) ipv6_route_check_sernum(iter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2596) spin_lock_bh(&iter->tbl->tb6_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2597) r = fib6_walk_continue(&iter->w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2598) spin_unlock_bh(&iter->tbl->tb6_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2599) if (r > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2600) return iter->w.leaf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2601) } else if (r < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2602) fib6_walker_unlink(net, &iter->w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2603) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2604) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2605) fib6_walker_unlink(net, &iter->w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2606)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2607) iter->tbl = ipv6_route_seq_next_table(iter->tbl, net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2608) if (!iter->tbl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2609) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2610)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2611) ipv6_route_seq_setup_walk(iter, net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2612) goto iter_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2613) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2614)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2615) static void *ipv6_route_seq_start(struct seq_file *seq, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2616) __acquires(RCU_BH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2617) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2618) struct net *net = seq_file_net(seq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2619) struct ipv6_route_iter *iter = seq->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2620)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2621) rcu_read_lock_bh();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2622) iter->tbl = ipv6_route_seq_next_table(NULL, net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2623) iter->skip = *pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2624)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2625) if (iter->tbl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2626) loff_t p = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2627)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2628) ipv6_route_seq_setup_walk(iter, net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2629) return ipv6_route_seq_next(seq, NULL, &p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2630) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2631) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2632) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2633) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2634)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2635) static bool ipv6_route_iter_active(struct ipv6_route_iter *iter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2636) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2637) struct fib6_walker *w = &iter->w;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2638) return w->node && !(w->state == FWS_U && w->node == w->root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2639) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2640)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2641) static void ipv6_route_native_seq_stop(struct seq_file *seq, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2642) __releases(RCU_BH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2643) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2644) struct net *net = seq_file_net(seq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2645) struct ipv6_route_iter *iter = seq->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2646)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2647) if (ipv6_route_iter_active(iter))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2648) fib6_walker_unlink(net, &iter->w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2649)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2650) rcu_read_unlock_bh();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2651) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2652)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2653) #if IS_BUILTIN(CONFIG_IPV6) && defined(CONFIG_BPF_SYSCALL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2654) static int ipv6_route_prog_seq_show(struct bpf_prog *prog,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2655) struct bpf_iter_meta *meta,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2656) void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2657) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2658) struct bpf_iter__ipv6_route ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2659)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2660) ctx.meta = meta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2661) ctx.rt = v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2662) return bpf_iter_run_prog(prog, &ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2663) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2664)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2665) static int ipv6_route_seq_show(struct seq_file *seq, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2666) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2667) struct ipv6_route_iter *iter = seq->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2668) struct bpf_iter_meta meta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2669) struct bpf_prog *prog;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2670) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2671)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2672) meta.seq = seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2673) prog = bpf_iter_get_info(&meta, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2674) if (!prog)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2675) return ipv6_route_native_seq_show(seq, v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2676)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2677) ret = ipv6_route_prog_seq_show(prog, &meta, v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2678) iter->w.leaf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2679)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2680) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2681) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2682)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2683) static void ipv6_route_seq_stop(struct seq_file *seq, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2684) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2685) struct bpf_iter_meta meta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2686) struct bpf_prog *prog;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2687)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2688) if (!v) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2689) meta.seq = seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2690) prog = bpf_iter_get_info(&meta, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2691) if (prog)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2692) (void)ipv6_route_prog_seq_show(prog, &meta, v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2693) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2694)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2695) ipv6_route_native_seq_stop(seq, v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2696) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2697) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2698) static int ipv6_route_seq_show(struct seq_file *seq, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2699) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2700) return ipv6_route_native_seq_show(seq, v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2701) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2702)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2703) static void ipv6_route_seq_stop(struct seq_file *seq, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2704) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2705) ipv6_route_native_seq_stop(seq, v);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2706) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2707) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2708)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2709) const struct seq_operations ipv6_route_seq_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2710) .start = ipv6_route_seq_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2711) .next = ipv6_route_seq_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2712) .stop = ipv6_route_seq_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2713) .show = ipv6_route_seq_show
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2714) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2715) #endif /* CONFIG_PROC_FS */