^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) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Authors:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Pedro Roque <roque@di.fc.ul.pt>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #ifndef _IP6_FIB_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #define _IP6_FIB_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/ipv6_route.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/rtnetlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/notifier.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/android_kabi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <net/dst.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <net/flow.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <net/ip_fib.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <net/netlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <net/inetpeer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <net/fib_notifier.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/indirect_call_wrapper.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #ifdef CONFIG_IPV6_MULTIPLE_TABLES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #define FIB6_TABLE_HASHSZ 256
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define FIB6_TABLE_HASHSZ 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define RT6_DEBUG 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #if RT6_DEBUG >= 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #define RT6_TRACE(x...) pr_debug(x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #define RT6_TRACE(x...) do { ; } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) struct rt6_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) struct fib6_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) struct fib6_config {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) u32 fc_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) u32 fc_metric;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) int fc_dst_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) int fc_src_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) int fc_ifindex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) u32 fc_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) u32 fc_protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) u16 fc_type; /* only 8 bits are used */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) u16 fc_delete_all_nh : 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) fc_ignore_dev_down:1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) __unused : 14;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) u32 fc_nh_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) struct in6_addr fc_dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) struct in6_addr fc_src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) struct in6_addr fc_prefsrc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) struct in6_addr fc_gateway;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) unsigned long fc_expires;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) struct nlattr *fc_mx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) int fc_mx_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) int fc_mp_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) struct nlattr *fc_mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) struct nl_info fc_nlinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) struct nlattr *fc_encap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) u16 fc_encap_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) bool fc_is_fdb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) ANDROID_KABI_RESERVE(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) struct fib6_node {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) struct fib6_node __rcu *parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) struct fib6_node __rcu *left;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) struct fib6_node __rcu *right;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) #ifdef CONFIG_IPV6_SUBTREES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) struct fib6_node __rcu *subtree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) struct fib6_info __rcu *leaf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) __u16 fn_bit; /* bit key */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) __u16 fn_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) int fn_sernum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) struct fib6_info __rcu *rr_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) struct rcu_head rcu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) ANDROID_KABI_RESERVE(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) struct fib6_gc_args {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) int timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) int more;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) #ifndef CONFIG_IPV6_SUBTREES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) #define FIB6_SUBTREE(fn) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) static inline bool fib6_routes_require_src(const struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) return false;
^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) static inline void fib6_routes_require_src_inc(struct net *net) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) static inline void fib6_routes_require_src_dec(struct net *net) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) static inline bool fib6_routes_require_src(const struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) return net->ipv6.fib6_routes_require_src > 0;
^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) static inline void fib6_routes_require_src_inc(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) net->ipv6.fib6_routes_require_src++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) static inline void fib6_routes_require_src_dec(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) net->ipv6.fib6_routes_require_src--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) #define FIB6_SUBTREE(fn) (rcu_dereference_protected((fn)->subtree, 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) * routing information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) struct rt6key {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) struct in6_addr addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) int plen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) struct fib6_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) struct rt6_exception_bucket {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) struct hlist_head chain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) int depth;
^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 rt6_exception {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) struct hlist_node hlist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) struct rt6_info *rt6i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) unsigned long stamp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) struct rcu_head rcu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) #define FIB6_EXCEPTION_BUCKET_SIZE_SHIFT 10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) #define FIB6_EXCEPTION_BUCKET_SIZE (1 << FIB6_EXCEPTION_BUCKET_SIZE_SHIFT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) #define FIB6_MAX_DEPTH 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) struct fib6_nh {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) struct fib_nh_common nh_common;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) #ifdef CONFIG_IPV6_ROUTER_PREF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) unsigned long last_probe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) struct rt6_info * __percpu *rt6i_pcpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) struct rt6_exception_bucket __rcu *rt6i_exception_bucket;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) struct fib6_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) struct fib6_table *fib6_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) struct fib6_info __rcu *fib6_next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) struct fib6_node __rcu *fib6_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) /* Multipath routes:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) * siblings is a list of fib6_info that have the same metric/weight,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) * destination, but not the same gateway. nsiblings is just a cache
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) * to speed up lookup.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) struct list_head fib6_siblings;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) struct list_head nh_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) unsigned int fib6_nsiblings;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) refcount_t fib6_ref;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) unsigned long expires;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) struct dst_metrics *fib6_metrics;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) #define fib6_pmtu fib6_metrics->metrics[RTAX_MTU-1]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) struct rt6key fib6_dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) u32 fib6_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) struct rt6key fib6_src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) struct rt6key fib6_prefsrc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) u32 fib6_metric;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) u8 fib6_protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) u8 fib6_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) u8 should_flush:1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) dst_nocount:1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) dst_nopolicy:1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) fib6_destroying:1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) offload:1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) trap:1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) unused:2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) struct rcu_head rcu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) struct nexthop *nh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) ANDROID_KABI_RESERVE(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) struct fib6_nh fib6_nh[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) struct rt6_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) struct dst_entry dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) struct fib6_info __rcu *from;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) int sernum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) struct rt6key rt6i_dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) struct rt6key rt6i_src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) struct in6_addr rt6i_gateway;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) struct inet6_dev *rt6i_idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) u32 rt6i_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) struct list_head rt6i_uncached;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) struct uncached_list *rt6i_uncached_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) /* more non-fragment space at head required */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) unsigned short rt6i_nfheader_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) ANDROID_KABI_RESERVE(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) struct fib6_result {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) struct fib6_nh *nh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) struct fib6_info *f6i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) u32 fib6_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) u8 fib6_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) struct rt6_info *rt6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) #define for_each_fib6_node_rt_rcu(fn) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) for (rt = rcu_dereference((fn)->leaf); rt; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) rt = rcu_dereference(rt->fib6_next))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) #define for_each_fib6_walker_rt(w) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) for (rt = (w)->leaf; rt; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) rt = rcu_dereference_protected(rt->fib6_next, 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) static inline struct inet6_dev *ip6_dst_idev(struct dst_entry *dst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) return ((struct rt6_info *)dst)->rt6i_idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) static inline bool fib6_requires_src(const struct fib6_info *rt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) return rt->fib6_src.plen > 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) static inline void fib6_clean_expires(struct fib6_info *f6i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) f6i->fib6_flags &= ~RTF_EXPIRES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) f6i->expires = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) static inline void fib6_set_expires(struct fib6_info *f6i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) unsigned long expires)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) f6i->expires = expires;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) f6i->fib6_flags |= RTF_EXPIRES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) static inline bool fib6_check_expired(const struct fib6_info *f6i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) if (f6i->fib6_flags & RTF_EXPIRES)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) return time_after(jiffies, f6i->expires);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) /* Function to safely get fn->sernum for passed in rt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) * and store result in passed in cookie.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) * Return true if we can get cookie safely
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) * Return false if not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) static inline bool fib6_get_cookie_safe(const struct fib6_info *f6i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) u32 *cookie)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) struct fib6_node *fn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) bool status = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) fn = rcu_dereference(f6i->fib6_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) if (fn) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) *cookie = READ_ONCE(fn->fn_sernum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) /* pairs with smp_wmb() in fib6_update_sernum_upto_root() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) smp_rmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) status = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) static inline u32 rt6_get_cookie(const struct rt6_info *rt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) struct fib6_info *from;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) u32 cookie = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) if (rt->sernum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) return rt->sernum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) from = rcu_dereference(rt->from);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) if (from)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) fib6_get_cookie_safe(from, &cookie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) return cookie;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) static inline void ip6_rt_put(struct rt6_info *rt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) /* dst_release() accepts a NULL parameter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) * We rely on dst being first structure in struct rt6_info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) BUILD_BUG_ON(offsetof(struct rt6_info, dst) != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) dst_release(&rt->dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) struct fib6_info *fib6_info_alloc(gfp_t gfp_flags, bool with_fib6_nh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) void fib6_info_destroy_rcu(struct rcu_head *head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) static inline void fib6_info_hold(struct fib6_info *f6i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) refcount_inc(&f6i->fib6_ref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) static inline bool fib6_info_hold_safe(struct fib6_info *f6i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) return refcount_inc_not_zero(&f6i->fib6_ref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) static inline void fib6_info_release(struct fib6_info *f6i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) if (f6i && refcount_dec_and_test(&f6i->fib6_ref))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) call_rcu(&f6i->rcu, fib6_info_destroy_rcu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) static inline void fib6_info_hw_flags_set(struct fib6_info *f6i, bool offload,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) bool trap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) f6i->offload = offload;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) f6i->trap = trap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) enum fib6_walk_state {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) #ifdef CONFIG_IPV6_SUBTREES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) FWS_S,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) FWS_L,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) FWS_R,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) FWS_C,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) FWS_U
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) struct fib6_walker {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) struct list_head lh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) struct fib6_node *root, *node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) struct fib6_info *leaf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) enum fib6_walk_state state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) unsigned int skip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) unsigned int count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) unsigned int skip_in_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) int (*func)(struct fib6_walker *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) void *args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) struct rt6_statistics {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) __u32 fib_nodes; /* all fib6 nodes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) __u32 fib_route_nodes; /* intermediate nodes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) __u32 fib_rt_entries; /* rt entries in fib table */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) __u32 fib_rt_cache; /* cached rt entries in exception table */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) __u32 fib_discarded_routes; /* total number of routes delete */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) /* The following stats are not protected by any lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) atomic_t fib_rt_alloc; /* total number of routes alloced */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) atomic_t fib_rt_uncache; /* rt entries in uncached list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) #define RTN_TL_ROOT 0x0001
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) #define RTN_ROOT 0x0002 /* tree root node */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) #define RTN_RTINFO 0x0004 /* node with valid routing info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) * priority levels (or metrics)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) *
^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)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) struct fib6_table {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) struct hlist_node tb6_hlist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) u32 tb6_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) spinlock_t tb6_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) struct fib6_node tb6_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) struct inet_peer_base tb6_peers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) unsigned int flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) unsigned int fib_seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) #define RT6_TABLE_HAS_DFLT_ROUTER BIT(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) #define RT6_TABLE_UNSPEC RT_TABLE_UNSPEC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) #define RT6_TABLE_MAIN RT_TABLE_MAIN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) #define RT6_TABLE_DFLT RT6_TABLE_MAIN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) #define RT6_TABLE_INFO RT6_TABLE_MAIN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) #define RT6_TABLE_PREFIX RT6_TABLE_MAIN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) #ifdef CONFIG_IPV6_MULTIPLE_TABLES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) #define FIB6_TABLE_MIN 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) #define FIB6_TABLE_MAX RT_TABLE_MAX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) #define RT6_TABLE_LOCAL RT_TABLE_LOCAL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) #define FIB6_TABLE_MIN RT_TABLE_MAIN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) #define FIB6_TABLE_MAX FIB6_TABLE_MIN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) #define RT6_TABLE_LOCAL RT6_TABLE_MAIN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) typedef struct rt6_info *(*pol_lookup_t)(struct net *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) struct fib6_table *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) struct flowi6 *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) const struct sk_buff *, int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) struct fib6_entry_notifier_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) struct fib_notifier_info info; /* must be first */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) struct fib6_info *rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) unsigned int nsiblings;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) * exported functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) struct fib6_table *fib6_get_table(struct net *net, u32 id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) struct fib6_table *fib6_new_table(struct net *net, u32 id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) struct dst_entry *fib6_rule_lookup(struct net *net, struct flowi6 *fl6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) const struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) int flags, pol_lookup_t lookup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) /* called with rcu lock held; can return error pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) * caller needs to select path
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) int fib6_lookup(struct net *net, int oif, struct flowi6 *fl6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) struct fib6_result *res, int flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) /* called with rcu lock held; caller needs to select path */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) int fib6_table_lookup(struct net *net, struct fib6_table *table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) int oif, struct flowi6 *fl6, struct fib6_result *res,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) int strict);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) void fib6_select_path(const struct net *net, struct fib6_result *res,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) struct flowi6 *fl6, int oif, bool have_oif_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) const struct sk_buff *skb, int strict);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) struct fib6_node *fib6_node_lookup(struct fib6_node *root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) const struct in6_addr *daddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) const struct in6_addr *saddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) struct fib6_node *fib6_locate(struct fib6_node *root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) const struct in6_addr *daddr, int dst_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) const struct in6_addr *saddr, int src_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) bool exact_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) void fib6_clean_all(struct net *net, int (*func)(struct fib6_info *, void *arg),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) void *arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) void fib6_clean_all_skip_notify(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) int (*func)(struct fib6_info *, void *arg),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) void *arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) int fib6_add(struct fib6_node *root, struct fib6_info *rt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) struct nl_info *info, struct netlink_ext_ack *extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) int fib6_del(struct fib6_info *rt, struct nl_info *info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) static inline
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) void rt6_get_prefsrc(const struct rt6_info *rt, struct in6_addr *addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) const struct fib6_info *from;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) from = rcu_dereference(rt->from);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) if (from) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) *addr = from->fib6_prefsrc.addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) struct in6_addr in6_zero = {};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) *addr = in6_zero;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) int fib6_nh_init(struct net *net, struct fib6_nh *fib6_nh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) struct fib6_config *cfg, gfp_t gfp_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) struct netlink_ext_ack *extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) void fib6_nh_release(struct fib6_nh *fib6_nh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) int call_fib6_entry_notifiers(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) enum fib_event_type event_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) struct fib6_info *rt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) struct netlink_ext_ack *extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) int call_fib6_multipath_entry_notifiers(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) enum fib_event_type event_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) struct fib6_info *rt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) unsigned int nsiblings,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) struct netlink_ext_ack *extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) int call_fib6_entry_notifiers_replace(struct net *net, struct fib6_info *rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) void fib6_rt_update(struct net *net, struct fib6_info *rt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) struct nl_info *info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) void inet6_rt_notify(int event, struct fib6_info *rt, struct nl_info *info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) unsigned int flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) void fib6_run_gc(unsigned long expires, struct net *net, bool force);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) void fib6_gc_cleanup(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) int fib6_init(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) struct ipv6_route_iter {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) struct seq_net_private p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) struct fib6_walker w;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) loff_t skip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) struct fib6_table *tbl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) int sernum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) extern const struct seq_operations ipv6_route_seq_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) int call_fib6_notifier(struct notifier_block *nb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) enum fib_event_type event_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) struct fib_notifier_info *info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) int call_fib6_notifiers(struct net *net, enum fib_event_type event_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) struct fib_notifier_info *info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) int __net_init fib6_notifier_init(struct net *net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) void __net_exit fib6_notifier_exit(struct net *net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) unsigned int fib6_tables_seq_read(struct net *net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) int fib6_tables_dump(struct net *net, struct notifier_block *nb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) struct netlink_ext_ack *extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) void fib6_update_sernum(struct net *net, struct fib6_info *rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) void fib6_update_sernum_upto_root(struct net *net, struct fib6_info *rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) void fib6_update_sernum_stub(struct net *net, struct fib6_info *f6i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) void fib6_metric_set(struct fib6_info *f6i, int metric, u32 val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) static inline bool fib6_metric_locked(struct fib6_info *f6i, int metric)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) return !!(f6i->fib6_metrics->metrics[RTAX_LOCK - 1] & (1 << metric));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) #if IS_BUILTIN(CONFIG_IPV6) && defined(CONFIG_BPF_SYSCALL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) struct bpf_iter__ipv6_route {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) __bpf_md_ptr(struct bpf_iter_meta *, meta);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) __bpf_md_ptr(struct fib6_info *, rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) INDIRECT_CALLABLE_DECLARE(struct rt6_info *ip6_pol_route_output(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) struct fib6_table *table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) struct flowi6 *fl6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) const struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) int flags));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) INDIRECT_CALLABLE_DECLARE(struct rt6_info *ip6_pol_route_input(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) struct fib6_table *table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) struct flowi6 *fl6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) const struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) int flags));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) INDIRECT_CALLABLE_DECLARE(struct rt6_info *__ip6_route_redirect(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) struct fib6_table *table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) struct flowi6 *fl6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) const struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) int flags));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) INDIRECT_CALLABLE_DECLARE(struct rt6_info *ip6_pol_route_lookup(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) struct fib6_table *table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) struct flowi6 *fl6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) const struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) int flags));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) static inline struct rt6_info *pol_lookup_func(pol_lookup_t lookup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) struct fib6_table *table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) struct flowi6 *fl6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) const struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) return INDIRECT_CALL_4(lookup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) ip6_pol_route_output,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) ip6_pol_route_input,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) ip6_pol_route_lookup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) __ip6_route_redirect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) net, table, fl6, skb, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) #ifdef CONFIG_IPV6_MULTIPLE_TABLES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) static inline bool fib6_has_custom_rules(const struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) return net->ipv6.fib6_has_custom_rules;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) int fib6_rules_init(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) void fib6_rules_cleanup(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) bool fib6_rule_default(const struct fib_rule *rule);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) int fib6_rules_dump(struct net *net, struct notifier_block *nb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) struct netlink_ext_ack *extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) unsigned int fib6_rules_seq_read(struct net *net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) static inline bool fib6_rules_early_flow_dissect(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) struct flowi6 *fl6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) struct flow_keys *flkeys)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) unsigned int flag = FLOW_DISSECTOR_F_STOP_AT_ENCAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) if (!net->ipv6.fib6_rules_require_fldissect)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) skb_flow_dissect_flow_keys(skb, flkeys, flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) fl6->fl6_sport = flkeys->ports.src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) fl6->fl6_dport = flkeys->ports.dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) fl6->flowi6_proto = flkeys->basic.ip_proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) static inline bool fib6_has_custom_rules(const struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) static inline int fib6_rules_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) static inline void fib6_rules_cleanup(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) return ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) static inline bool fib6_rule_default(const struct fib_rule *rule)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) static inline int fib6_rules_dump(struct net *net, struct notifier_block *nb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) static inline unsigned int fib6_rules_seq_read(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) static inline bool fib6_rules_early_flow_dissect(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) struct flowi6 *fl6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) struct flow_keys *flkeys)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) #endif