^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #ifndef _NET_IP6_ROUTE_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #define _NET_IP6_ROUTE_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) struct route_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) __u8 type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) __u8 length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) __u8 prefix_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #if defined(__BIG_ENDIAN_BITFIELD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) __u8 reserved_h:3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) route_pref:2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) reserved_l:3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #elif defined(__LITTLE_ENDIAN_BITFIELD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) __u8 reserved_l:3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) route_pref:2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) reserved_h:3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) __be32 lifetime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) __u8 prefix[]; /* 0,8 or 16 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <net/addrconf.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <net/flow.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <net/ip6_fib.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <net/sock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <net/lwtunnel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/ip.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/ipv6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/route.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <net/nexthop.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #define RT6_LOOKUP_F_IFACE 0x00000001
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #define RT6_LOOKUP_F_REACHABLE 0x00000002
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #define RT6_LOOKUP_F_HAS_SADDR 0x00000004
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #define RT6_LOOKUP_F_SRCPREF_TMP 0x00000008
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #define RT6_LOOKUP_F_SRCPREF_PUBLIC 0x00000010
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #define RT6_LOOKUP_F_SRCPREF_COA 0x00000020
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #define RT6_LOOKUP_F_IGNORE_LINKSTATE 0x00000040
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #define RT6_LOOKUP_F_DST_NOREF 0x00000080
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) /* We do not (yet ?) support IPv6 jumbograms (RFC 2675)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * Unlike IPv4, hdr->seg_len doesn't include the IPv6 header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #define IP6_MAX_MTU (0xFFFF + sizeof(struct ipv6hdr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * rt6_srcprefs2flags() and rt6_flags2srcprefs() translate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * between IPV6_ADDR_PREFERENCES socket option values
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * IPV6_PREFER_SRC_TMP = 0x1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * IPV6_PREFER_SRC_PUBLIC = 0x2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * IPV6_PREFER_SRC_COA = 0x4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * and above RT6_LOOKUP_F_SRCPREF_xxx flags.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) static inline int rt6_srcprefs2flags(unsigned int srcprefs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) /* No need to bitmask because srcprefs have only 3 bits. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) return srcprefs << 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) static inline unsigned int rt6_flags2srcprefs(int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) return (flags >> 3) & 7;
^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) static inline bool rt6_need_strict(const struct in6_addr *daddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) return ipv6_addr_type(daddr) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) (IPV6_ADDR_MULTICAST | IPV6_ADDR_LINKLOCAL | IPV6_ADDR_LOOPBACK);
^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) /* fib entries using a nexthop object can not be coalesced into
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) * a multipath route
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) static inline bool rt6_qualify_for_ecmp(const struct fib6_info *f6i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) /* the RTF_ADDRCONF flag filters out RA's */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) return !(f6i->fib6_flags & RTF_ADDRCONF) && !f6i->nh &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) f6i->fib6_nh->fib_nh_gw_family;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) void ip6_route_input(struct sk_buff *skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) struct dst_entry *ip6_route_input_lookup(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) struct flowi6 *fl6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) const struct sk_buff *skb, int flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) struct dst_entry *ip6_route_output_flags_noref(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) const struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) struct flowi6 *fl6, int flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) struct dst_entry *ip6_route_output_flags(struct net *net, const struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) struct flowi6 *fl6, int flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) static inline struct dst_entry *ip6_route_output(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) const struct sock *sk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) struct flowi6 *fl6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) return ip6_route_output_flags(net, sk, fl6, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) /* Only conditionally release dst if flags indicates
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) * !RT6_LOOKUP_F_DST_NOREF or dst is in uncached_list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) static inline void ip6_rt_put_flags(struct rt6_info *rt, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) if (!(flags & RT6_LOOKUP_F_DST_NOREF) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) !list_empty(&rt->rt6i_uncached))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) ip6_rt_put(rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) struct dst_entry *ip6_route_lookup(struct net *net, struct flowi6 *fl6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) const struct sk_buff *skb, int flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) struct rt6_info *ip6_pol_route(struct net *net, struct fib6_table *table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) int ifindex, struct flowi6 *fl6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) const struct sk_buff *skb, int flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) void ip6_route_init_special_entries(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) int ip6_route_init(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) void ip6_route_cleanup(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) int ipv6_route_ioctl(struct net *net, unsigned int cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) struct in6_rtmsg *rtmsg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) int ip6_route_add(struct fib6_config *cfg, gfp_t gfp_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) struct netlink_ext_ack *extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) int ip6_ins_rt(struct net *net, struct fib6_info *f6i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) int ip6_del_rt(struct net *net, struct fib6_info *f6i, bool skip_notify);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) void rt6_flush_exceptions(struct fib6_info *f6i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) void rt6_age_exceptions(struct fib6_info *f6i, struct fib6_gc_args *gc_args,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) unsigned long now);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) static inline int ip6_route_get_saddr(struct net *net, struct fib6_info *f6i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) const struct in6_addr *daddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) unsigned int prefs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) struct in6_addr *saddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) if (f6i && f6i->fib6_prefsrc.plen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) *saddr = f6i->fib6_prefsrc.addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) struct net_device *dev = f6i ? fib6_info_nh_dev(f6i) : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) err = ipv6_dev_get_saddr(net, dev, daddr, prefs, saddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) struct rt6_info *rt6_lookup(struct net *net, const struct in6_addr *daddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) const struct in6_addr *saddr, int oif,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) const struct sk_buff *skb, int flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) u32 rt6_multipath_hash(const struct net *net, const struct flowi6 *fl6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) const struct sk_buff *skb, struct flow_keys *hkeys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) struct dst_entry *icmp6_dst_alloc(struct net_device *dev, struct flowi6 *fl6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) void fib6_force_start_gc(struct net *net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) struct fib6_info *addrconf_f6i_alloc(struct net *net, struct inet6_dev *idev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) const struct in6_addr *addr, bool anycast,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) gfp_t gfp_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) struct rt6_info *ip6_dst_alloc(struct net *net, struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) int flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) * support functions for ND
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) struct fib6_info *rt6_get_dflt_router(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) const struct in6_addr *addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) struct net_device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) struct fib6_info *rt6_add_dflt_router(struct net *net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) const struct in6_addr *gwaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) struct net_device *dev, unsigned int pref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) void rt6_purge_dflt_routers(struct net *net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) int rt6_route_rcv(struct net_device *dev, u8 *opt, int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) const struct in6_addr *gwaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) void ip6_update_pmtu(struct sk_buff *skb, struct net *net, __be32 mtu, int oif,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) u32 mark, kuid_t uid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) void ip6_sk_update_pmtu(struct sk_buff *skb, struct sock *sk, __be32 mtu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) void ip6_redirect(struct sk_buff *skb, struct net *net, int oif, u32 mark,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) kuid_t uid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) void ip6_redirect_no_header(struct sk_buff *skb, struct net *net, int oif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) void ip6_sk_redirect(struct sk_buff *skb, struct sock *sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) struct netlink_callback;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) struct rt6_rtnl_dump_arg {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) struct netlink_callback *cb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) struct net *net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) struct fib_dump_filter filter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) int rt6_dump_route(struct fib6_info *f6i, void *p_arg, unsigned int skip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) void rt6_mtu_change(struct net_device *dev, unsigned int mtu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) void rt6_remove_prefsrc(struct inet6_ifaddr *ifp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) void rt6_clean_tohost(struct net *net, struct in6_addr *gateway);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) void rt6_sync_up(struct net_device *dev, unsigned char nh_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) void rt6_disable_ip(struct net_device *dev, unsigned long event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) void rt6_sync_down_dev(struct net_device *dev, unsigned long event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) void rt6_multipath_rebalance(struct fib6_info *f6i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) void rt6_uncached_list_add(struct rt6_info *rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) void rt6_uncached_list_del(struct rt6_info *rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) static inline const struct rt6_info *skb_rt6_info(const struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) const struct dst_entry *dst = skb_dst(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) const struct rt6_info *rt6 = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) if (dst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) rt6 = container_of(dst, struct rt6_info, dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) return rt6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) * Store a destination cache entry in a socket
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) static inline void ip6_dst_store(struct sock *sk, struct dst_entry *dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) const struct in6_addr *daddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) const struct in6_addr *saddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) struct ipv6_pinfo *np = inet6_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) np->dst_cookie = rt6_get_cookie((struct rt6_info *)dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) sk_setup_caps(sk, dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) np->daddr_cache = daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) #ifdef CONFIG_IPV6_SUBTREES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) np->saddr_cache = saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) #endif
^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) void ip6_sk_dst_store_flow(struct sock *sk, struct dst_entry *dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) const struct flowi6 *fl6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) static inline bool ipv6_unicast_destination(const struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) struct rt6_info *rt = (struct rt6_info *) skb_dst(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) return rt->rt6i_flags & RTF_LOCAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) static inline bool ipv6_anycast_destination(const struct dst_entry *dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) const struct in6_addr *daddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) struct rt6_info *rt = (struct rt6_info *)dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) return rt->rt6i_flags & RTF_ANYCAST ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) (rt->rt6i_dst.plen < 127 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) !(rt->rt6i_flags & (RTF_GATEWAY | RTF_NONEXTHOP)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) ipv6_addr_equal(&rt->rt6i_dst.addr, daddr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) int ip6_fragment(struct net *net, struct sock *sk, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) int (*output)(struct net *, struct sock *, struct sk_buff *));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) static inline unsigned int ip6_skb_dst_mtu(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) unsigned int mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) struct ipv6_pinfo *np = skb->sk && !dev_recursion_level() ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) inet6_sk(skb->sk) : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) if (np && np->pmtudisc >= IPV6_PMTUDISC_PROBE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) mtu = READ_ONCE(skb_dst(skb)->dev->mtu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) mtu -= lwtunnel_headroom(skb_dst(skb)->lwtstate, mtu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) mtu = dst_mtu(skb_dst(skb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) return mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) static inline bool ip6_sk_accept_pmtu(const struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) return inet6_sk(sk)->pmtudisc != IPV6_PMTUDISC_INTERFACE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) inet6_sk(sk)->pmtudisc != IPV6_PMTUDISC_OMIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) static inline bool ip6_sk_ignore_df(const struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) return inet6_sk(sk)->pmtudisc < IPV6_PMTUDISC_DO ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) inet6_sk(sk)->pmtudisc == IPV6_PMTUDISC_OMIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) static inline const struct in6_addr *rt6_nexthop(const struct rt6_info *rt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) const struct in6_addr *daddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) if (rt->rt6i_flags & RTF_GATEWAY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) return &rt->rt6i_gateway;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) else if (unlikely(rt->rt6i_flags & RTF_CACHE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) return &rt->rt6i_dst.addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) return daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) static inline bool rt6_duplicate_nexthop(struct fib6_info *a, struct fib6_info *b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) struct fib6_nh *nha, *nhb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) if (a->nh || b->nh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) return nexthop_cmp(a->nh, b->nh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) nha = a->fib6_nh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) nhb = b->fib6_nh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) return nha->fib_nh_dev == nhb->fib_nh_dev &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) ipv6_addr_equal(&nha->fib_nh_gw6, &nhb->fib_nh_gw6) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) !lwtunnel_cmp_encap(nha->fib_nh_lws, nhb->fib_nh_lws);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) static inline unsigned int ip6_dst_mtu_forward(const struct dst_entry *dst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) struct inet6_dev *idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) unsigned int mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) if (dst_metric_locked(dst, RTAX_MTU)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) mtu = dst_metric_raw(dst, RTAX_MTU);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) if (mtu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) goto out;
^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) mtu = IPV6_MIN_MTU;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) idev = __in6_dev_get(dst->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) if (idev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) mtu = idev->cnf.mtu6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) return mtu - lwtunnel_headroom(dst->lwtstate, mtu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) u32 ip6_mtu_from_fib6(const struct fib6_result *res,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) const struct in6_addr *daddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) const struct in6_addr *saddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) struct neighbour *ip6_neigh_lookup(const struct in6_addr *gw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) struct net_device *dev, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) const void *daddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) #endif