xref: /linux/include/net/ip6_route.h (revision a1ff5a7d78a036d6c2178ee5acd6ba4946243800)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
21da177e4SLinus Torvalds #ifndef _NET_IP6_ROUTE_H
31da177e4SLinus Torvalds #define _NET_IP6_ROUTE_H
41da177e4SLinus Torvalds 
5949d6b40SJakub Kicinski #include <net/addrconf.h>
6949d6b40SJakub Kicinski #include <net/flow.h>
7949d6b40SJakub Kicinski #include <net/ip6_fib.h>
8949d6b40SJakub Kicinski #include <net/sock.h>
9949d6b40SJakub Kicinski #include <net/lwtunnel.h>
10949d6b40SJakub Kicinski #include <linux/ip.h>
11949d6b40SJakub Kicinski #include <linux/ipv6.h>
12949d6b40SJakub Kicinski #include <linux/route.h>
13949d6b40SJakub Kicinski #include <net/nexthop.h>
14949d6b40SJakub Kicinski 
1570ceb4f5SYOSHIFUJI Hideaki struct route_info {
1670ceb4f5SYOSHIFUJI Hideaki 	__u8			type;
1770ceb4f5SYOSHIFUJI Hideaki 	__u8			length;
1870ceb4f5SYOSHIFUJI Hideaki 	__u8			prefix_len;
1970ceb4f5SYOSHIFUJI Hideaki #if defined(__BIG_ENDIAN_BITFIELD)
2070ceb4f5SYOSHIFUJI Hideaki 	__u8			reserved_h:3,
2170ceb4f5SYOSHIFUJI Hideaki 				route_pref:2,
2270ceb4f5SYOSHIFUJI Hideaki 				reserved_l:3;
2370ceb4f5SYOSHIFUJI Hideaki #elif defined(__LITTLE_ENDIAN_BITFIELD)
2470ceb4f5SYOSHIFUJI Hideaki 	__u8			reserved_l:3,
2570ceb4f5SYOSHIFUJI Hideaki 				route_pref:2,
2670ceb4f5SYOSHIFUJI Hideaki 				reserved_h:3;
2770ceb4f5SYOSHIFUJI Hideaki #endif
28e69a4adcSAl Viro 	__be32			lifetime;
29207644f5SGustavo A. R. Silva 	__u8			prefix[];	/* 0,8 or 16 */
3070ceb4f5SYOSHIFUJI Hideaki };
3170ceb4f5SYOSHIFUJI Hideaki 
327cbca67cSYOSHIFUJI Hideaki #define RT6_LOOKUP_F_IFACE		0x00000001
337cbca67cSYOSHIFUJI Hideaki #define RT6_LOOKUP_F_REACHABLE		0x00000002
347cbca67cSYOSHIFUJI Hideaki #define RT6_LOOKUP_F_HAS_SADDR		0x00000004
357cbca67cSYOSHIFUJI Hideaki #define RT6_LOOKUP_F_SRCPREF_TMP	0x00000008
367cbca67cSYOSHIFUJI Hideaki #define RT6_LOOKUP_F_SRCPREF_PUBLIC	0x00000010
377cbca67cSYOSHIFUJI Hideaki #define RT6_LOOKUP_F_SRCPREF_COA	0x00000020
38d5d32e4bSDavid Ahern #define RT6_LOOKUP_F_IGNORE_LINKSTATE	0x00000040
390e09edccSWei Wang #define RT6_LOOKUP_F_DST_NOREF		0x00000080
4077d16f45SYOSHIFUJI Hideaki 
4130f78d8eSEric Dumazet /* We do not (yet ?) support IPv6 jumbograms (RFC 2675)
4230f78d8eSEric Dumazet  * Unlike IPv4, hdr->seg_len doesn't include the IPv6 header
4330f78d8eSEric Dumazet  */
4430f78d8eSEric Dumazet #define IP6_MAX_MTU (0xFFFF + sizeof(struct ipv6hdr))
4530f78d8eSEric Dumazet 
460c9a2ac1SYOSHIFUJI Hideaki / 吉藤英明 /*
470c9a2ac1SYOSHIFUJI Hideaki / 吉藤英明  * rt6_srcprefs2flags() and rt6_flags2srcprefs() translate
480c9a2ac1SYOSHIFUJI Hideaki / 吉藤英明  * between IPV6_ADDR_PREFERENCES socket option values
490c9a2ac1SYOSHIFUJI Hideaki / 吉藤英明  *	IPV6_PREFER_SRC_TMP    = 0x1
500c9a2ac1SYOSHIFUJI Hideaki / 吉藤英明  *	IPV6_PREFER_SRC_PUBLIC = 0x2
510c9a2ac1SYOSHIFUJI Hideaki / 吉藤英明  *	IPV6_PREFER_SRC_COA    = 0x4
520c9a2ac1SYOSHIFUJI Hideaki / 吉藤英明  * and above RT6_LOOKUP_F_SRCPREF_xxx flags.
530c9a2ac1SYOSHIFUJI Hideaki / 吉藤英明  */
rt6_srcprefs2flags(unsigned int srcprefs)540c9a2ac1SYOSHIFUJI Hideaki / 吉藤英明 static inline int rt6_srcprefs2flags(unsigned int srcprefs)
550c9a2ac1SYOSHIFUJI Hideaki / 吉藤英明 {
56fa17a6d8SEric Dumazet 	return (srcprefs & IPV6_PREFER_SRC_MASK) << 3;
570c9a2ac1SYOSHIFUJI Hideaki / 吉藤英明 }
580c9a2ac1SYOSHIFUJI Hideaki / 吉藤英明 
rt6_flags2srcprefs(int flags)590c9a2ac1SYOSHIFUJI Hideaki / 吉藤英明 static inline unsigned int rt6_flags2srcprefs(int flags)
600c9a2ac1SYOSHIFUJI Hideaki / 吉藤英明 {
61fa17a6d8SEric Dumazet 	return (flags >> 3) & IPV6_PREFER_SRC_MASK;
620c9a2ac1SYOSHIFUJI Hideaki / 吉藤英明 }
631da177e4SLinus Torvalds 
rt6_need_strict(const struct in6_addr * daddr)6460ea37f7SWang Yufen static inline bool rt6_need_strict(const struct in6_addr *daddr)
6560ea37f7SWang Yufen {
6660ea37f7SWang Yufen 	return ipv6_addr_type(daddr) &
6760ea37f7SWang Yufen 		(IPV6_ADDR_MULTICAST | IPV6_ADDR_LINKLOCAL | IPV6_ADDR_LOOPBACK);
6860ea37f7SWang Yufen }
69fbfe95a4SDavid S. Miller 
70f88d8ea6SDavid Ahern /* fib entries using a nexthop object can not be coalesced into
71f88d8ea6SDavid Ahern  * a multipath route
72f88d8ea6SDavid Ahern  */
rt6_qualify_for_ecmp(const struct fib6_info * f6i)7333bd5ac5SDavid Ahern static inline bool rt6_qualify_for_ecmp(const struct fib6_info *f6i)
7433bd5ac5SDavid Ahern {
75be659b8dSDavid Ahern 	/* the RTF_ADDRCONF flag filters out RA's */
76f88d8ea6SDavid Ahern 	return !(f6i->fib6_flags & RTF_ADDRCONF) && !f6i->nh &&
771cf844c7SDavid Ahern 		f6i->fib6_nh->fib_nh_gw_family;
7833bd5ac5SDavid Ahern }
7933bd5ac5SDavid Ahern 
805c3a0fd7SJoe Perches void ip6_route_input(struct sk_buff *skb);
81d409b847SMahesh Bandewar struct dst_entry *ip6_route_input_lookup(struct net *net,
82d409b847SMahesh Bandewar 					 struct net_device *dev,
83b75cc8f9SDavid Ahern 					 struct flowi6 *fl6,
84b75cc8f9SDavid Ahern 					 const struct sk_buff *skb, int flags);
851da177e4SLinus Torvalds 
866f21c96aSPaolo Abeni struct dst_entry *ip6_route_output_flags(struct net *net, const struct sock *sk,
876f21c96aSPaolo Abeni 					 struct flowi6 *fl6, int flags);
886f21c96aSPaolo Abeni 
ip6_route_output(struct net * net,const struct sock * sk,struct flowi6 * fl6)896f21c96aSPaolo Abeni static inline struct dst_entry *ip6_route_output(struct net *net,
906f21c96aSPaolo Abeni 						 const struct sock *sk,
916f21c96aSPaolo Abeni 						 struct flowi6 *fl6)
926f21c96aSPaolo Abeni {
936f21c96aSPaolo Abeni 	return ip6_route_output_flags(net, sk, fl6, 0);
946f21c96aSPaolo Abeni }
956f21c96aSPaolo Abeni 
96d64a1f57SWei Wang /* Only conditionally release dst if flags indicates
97d64a1f57SWei Wang  * !RT6_LOOKUP_F_DST_NOREF or dst is in uncached_list.
98d64a1f57SWei Wang  */
ip6_rt_put_flags(struct rt6_info * rt,int flags)99d64a1f57SWei Wang static inline void ip6_rt_put_flags(struct rt6_info *rt, int flags)
100d64a1f57SWei Wang {
101d64a1f57SWei Wang 	if (!(flags & RT6_LOOKUP_F_DST_NOREF) ||
102d288a162SWangyang Guo 	    !list_empty(&rt->dst.rt_uncached))
103d64a1f57SWei Wang 		ip6_rt_put(rt);
104d64a1f57SWei Wang }
105d64a1f57SWei Wang 
1065c3a0fd7SJoe Perches struct dst_entry *ip6_route_lookup(struct net *net, struct flowi6 *fl6,
107b75cc8f9SDavid Ahern 				   const struct sk_buff *skb, int flags);
1089ff74384SDavid Ahern struct rt6_info *ip6_pol_route(struct net *net, struct fib6_table *table,
109b75cc8f9SDavid Ahern 			       int ifindex, struct flowi6 *fl6,
110b75cc8f9SDavid Ahern 			       const struct sk_buff *skb, int flags);
1111da177e4SLinus Torvalds 
1122f460933SWANG Cong void ip6_route_init_special_entries(void);
1135c3a0fd7SJoe Perches int ip6_route_init(void);
1145c3a0fd7SJoe Perches void ip6_route_cleanup(void);
1151da177e4SLinus Torvalds 
1167c1552daSChristoph Hellwig int ipv6_route_ioctl(struct net *net, unsigned int cmd,
1177c1552daSChristoph Hellwig 		struct in6_rtmsg *rtmsg);
1181da177e4SLinus Torvalds 
119acb54e3cSDavid Ahern int ip6_route_add(struct fib6_config *cfg, gfp_t gfp_flags,
120acb54e3cSDavid Ahern 		  struct netlink_ext_ack *extack);
12193c2fb25SDavid Ahern int ip6_ins_rt(struct net *net, struct fib6_info *f6i);
12211dd74b3SRoopa Prabhu int ip6_del_rt(struct net *net, struct fib6_info *f6i, bool skip_notify);
1231da177e4SLinus Torvalds 
12493c2fb25SDavid Ahern void rt6_flush_exceptions(struct fib6_info *f6i);
12593c2fb25SDavid Ahern void rt6_age_exceptions(struct fib6_info *f6i, struct fib6_gc_args *gc_args,
126c757faa8SWei Wang 			unsigned long now);
12735732d01SWei Wang 
ip6_route_get_saddr(struct net * net,struct fib6_info * f6i,const struct in6_addr * daddr,unsigned int prefs,int l3mdev_index,struct in6_addr * saddr)12893c2fb25SDavid Ahern static inline int ip6_route_get_saddr(struct net *net, struct fib6_info *f6i,
129a2e2ff56SDavid Ahern 				      const struct in6_addr *daddr,
130*252442f2SNicolas Dichtel 				      unsigned int prefs, int l3mdev_index,
131a2e2ff56SDavid Ahern 				      struct in6_addr *saddr)
132a2e2ff56SDavid Ahern {
133*252442f2SNicolas Dichtel 	struct net_device *l3mdev;
134*252442f2SNicolas Dichtel 	struct net_device *dev;
135*252442f2SNicolas Dichtel 	bool same_vrf;
136a2e2ff56SDavid Ahern 	int err = 0;
137a2e2ff56SDavid Ahern 
138*252442f2SNicolas Dichtel 	rcu_read_lock();
1396fe74941SDavid Ahern 
140*252442f2SNicolas Dichtel 	l3mdev = dev_get_by_index_rcu(net, l3mdev_index);
141*252442f2SNicolas Dichtel 	if (!f6i || !f6i->fib6_prefsrc.plen || l3mdev)
142*252442f2SNicolas Dichtel 		dev = f6i ? fib6_info_nh_dev(f6i) : NULL;
143*252442f2SNicolas Dichtel 	same_vrf = !l3mdev || l3mdev_master_dev_rcu(dev) == l3mdev;
144*252442f2SNicolas Dichtel 	if (f6i && f6i->fib6_prefsrc.plen && same_vrf)
145*252442f2SNicolas Dichtel 		*saddr = f6i->fib6_prefsrc.addr;
146*252442f2SNicolas Dichtel 	else
147*252442f2SNicolas Dichtel 		err = ipv6_dev_get_saddr(net, same_vrf ? dev : l3mdev, daddr, prefs, saddr);
148*252442f2SNicolas Dichtel 
149*252442f2SNicolas Dichtel 	rcu_read_unlock();
150a2e2ff56SDavid Ahern 
151a2e2ff56SDavid Ahern 	return err;
152a2e2ff56SDavid Ahern }
153c3968a85SDaniel Walter 
1545c3a0fd7SJoe Perches struct rt6_info *rt6_lookup(struct net *net, const struct in6_addr *daddr,
155b75cc8f9SDavid Ahern 			    const struct in6_addr *saddr, int oif,
156b75cc8f9SDavid Ahern 			    const struct sk_buff *skb, int flags);
157b4bac172SDavid Ahern u32 rt6_multipath_hash(const struct net *net, const struct flowi6 *fl6,
158b4bac172SDavid Ahern 		       const struct sk_buff *skb, struct flow_keys *hkeys);
1591da177e4SLinus Torvalds 
1605c3a0fd7SJoe Perches struct dst_entry *icmp6_dst_alloc(struct net_device *dev, struct flowi6 *fl6);
1613b00944cSYOSHIFUJI Hideaki 
1625c3a0fd7SJoe Perches void fib6_force_start_gc(struct net *net);
1631da177e4SLinus Torvalds 
164360a9887SDavid Ahern struct fib6_info *addrconf_f6i_alloc(struct net *net, struct inet6_dev *idev,
165acb54e3cSDavid Ahern 				     const struct in6_addr *addr, bool anycast,
1667f6c4039SHangbin Liu 				     gfp_t gfp_flags, struct netlink_ext_ack *extack);
1671da177e4SLinus Torvalds 
1689ab179d8SDavid Ahern struct rt6_info *ip6_dst_alloc(struct net *net, struct net_device *dev,
1699ab179d8SDavid Ahern 			       int flags);
1709ab179d8SDavid Ahern 
1711da177e4SLinus Torvalds /*
1721da177e4SLinus Torvalds  *	support functions for ND
1731da177e4SLinus Torvalds  *
1741da177e4SLinus Torvalds  */
1758d1c802bSDavid Ahern struct fib6_info *rt6_get_dflt_router(struct net *net,
176afb1d4b5SDavid Ahern 				     const struct in6_addr *addr,
1771da177e4SLinus Torvalds 				     struct net_device *dev);
1788d1c802bSDavid Ahern struct fib6_info *rt6_add_dflt_router(struct net *net,
179afb1d4b5SDavid Ahern 				     const struct in6_addr *gwaddr,
1806b2e04bcSPraveen Chaudhary 				     struct net_device *dev, unsigned int pref,
181129e406eSKui-Feng Lee 				     u32 defrtr_usr_metric,
182129e406eSKui-Feng Lee 				     int lifetime);
1831da177e4SLinus Torvalds 
1845c3a0fd7SJoe Perches void rt6_purge_dflt_routers(struct net *net);
1851da177e4SLinus Torvalds 
1865c3a0fd7SJoe Perches int rt6_route_rcv(struct net_device *dev, u8 *opt, int len,
187b71d1d42SEric Dumazet 		  const struct in6_addr *gwaddr);
18870ceb4f5SYOSHIFUJI Hideaki 
1895c3a0fd7SJoe Perches void ip6_update_pmtu(struct sk_buff *skb, struct net *net, __be32 mtu, int oif,
190e2d118a1SLorenzo Colitti 		     u32 mark, kuid_t uid);
1915c3a0fd7SJoe Perches void ip6_sk_update_pmtu(struct sk_buff *skb, struct sock *sk, __be32 mtu);
192e2d118a1SLorenzo Colitti void ip6_redirect(struct sk_buff *skb, struct net *net, int oif, u32 mark,
193e2d118a1SLorenzo Colitti 		  kuid_t uid);
194d456336dSMaciej Żenczykowski void ip6_redirect_no_header(struct sk_buff *skb, struct net *net, int oif);
1955c3a0fd7SJoe Perches void ip6_sk_redirect(struct sk_buff *skb, struct sock *sk);
1961da177e4SLinus Torvalds 
1971da177e4SLinus Torvalds struct netlink_callback;
1981da177e4SLinus Torvalds 
199fd2c3ef7SEric Dumazet struct rt6_rtnl_dump_arg {
2001b43af54SPatrick McHardy 	struct sk_buff *skb;
2011b43af54SPatrick McHardy 	struct netlink_callback *cb;
202191cd582SBrian Haley 	struct net *net;
2034724676dSDavid Ahern 	struct fib_dump_filter filter;
2041b43af54SPatrick McHardy };
2051b43af54SPatrick McHardy 
2061e47b483SStefano Brivio int rt6_dump_route(struct fib6_info *f6i, void *p_arg, unsigned int skip);
2075c3a0fd7SJoe Perches void rt6_mtu_change(struct net_device *dev, unsigned int mtu);
2085c3a0fd7SJoe Perches void rt6_remove_prefsrc(struct inet6_ifaddr *ifp);
209be7a010dSDuan Jiong void rt6_clean_tohost(struct net *net, struct in6_addr *gateway);
210ecc5663cSDavid Ahern void rt6_sync_up(struct net_device *dev, unsigned char nh_flags);
2114c981e28SIdo Schimmel void rt6_disable_ip(struct net_device *dev, unsigned long event);
21227c6fa73SIdo Schimmel void rt6_sync_down_dev(struct net_device *dev, unsigned long event);
21393c2fb25SDavid Ahern void rt6_multipath_rebalance(struct fib6_info *f6i);
2141da177e4SLinus Torvalds 
215510c321bSXin Long void rt6_uncached_list_add(struct rt6_info *rt);
216510c321bSXin Long void rt6_uncached_list_del(struct rt6_info *rt);
217510c321bSXin Long 
skb_rt6_info(const struct sk_buff * skb)2181b70d792SDavid Ahern static inline const struct rt6_info *skb_rt6_info(const struct sk_buff *skb)
2191b70d792SDavid Ahern {
2201b70d792SDavid Ahern 	const struct dst_entry *dst = skb_dst(skb);
2211b70d792SDavid Ahern 
2221b70d792SDavid Ahern 	if (dst)
223e8dfd42cSEric Dumazet 		return dst_rt6_info(dst);
2241b70d792SDavid Ahern 
225e8dfd42cSEric Dumazet 	return NULL;
2261b70d792SDavid Ahern }
2271da177e4SLinus Torvalds 
2281da177e4SLinus Torvalds /*
2291da177e4SLinus Torvalds  *	Store a destination cache entry in a socket
2301da177e4SLinus Torvalds  */
ip6_dst_store(struct sock * sk,struct dst_entry * dst,const struct in6_addr * daddr,const struct in6_addr * saddr)2316bd4f355SEric Dumazet static inline void ip6_dst_store(struct sock *sk, struct dst_entry *dst,
232d3818c92SEric Dumazet 				 const struct in6_addr *daddr,
233d3818c92SEric Dumazet 				 const struct in6_addr *saddr)
2341da177e4SLinus Torvalds {
2351da177e4SLinus Torvalds 	struct ipv6_pinfo *np = inet6_sk(sk);
2361da177e4SLinus Torvalds 
237e8dfd42cSEric Dumazet 	np->dst_cookie = rt6_get_cookie(dst_rt6_info(dst));
238f83ef8c0SHerbert Xu 	sk_setup_caps(sk, dst);
2391da177e4SLinus Torvalds 	np->daddr_cache = daddr;
2408e1ef0a9SYOSHIFUJI Hideaki #ifdef CONFIG_IPV6_SUBTREES
2418e1ef0a9SYOSHIFUJI Hideaki 	np->saddr_cache = saddr;
2428e1ef0a9SYOSHIFUJI Hideaki #endif
2431da177e4SLinus Torvalds }
2441da177e4SLinus Torvalds 
2457d6850f7SAlexey Kodanev void ip6_sk_dst_store_flow(struct sock *sk, struct dst_entry *dst,
2467d6850f7SAlexey Kodanev 			   const struct flowi6 *fl6);
2477d6850f7SAlexey Kodanev 
ipv6_unicast_destination(const struct sk_buff * skb)248a50feda5SEric Dumazet static inline bool ipv6_unicast_destination(const struct sk_buff *skb)
2491da177e4SLinus Torvalds {
250e8dfd42cSEric Dumazet 	const struct rt6_info *rt = dst_rt6_info(skb_dst(skb));
2511da177e4SLinus Torvalds 
2521da177e4SLinus Torvalds 	return rt->rt6i_flags & RTF_LOCAL;
2531da177e4SLinus Torvalds }
2541da177e4SLinus Torvalds 
ipv6_anycast_destination(const struct dst_entry * dst,const struct in6_addr * daddr)2552647a9b0SMartin KaFai Lau static inline bool ipv6_anycast_destination(const struct dst_entry *dst,
2562647a9b0SMartin KaFai Lau 					    const struct in6_addr *daddr)
257509aba3bSFX Le Bail {
258e8dfd42cSEric Dumazet 	const struct rt6_info *rt = dst_rt6_info(dst);
259509aba3bSFX Le Bail 
2602647a9b0SMartin KaFai Lau 	return rt->rt6i_flags & RTF_ANYCAST ||
261ccdb2d17SVincent Bernat 		(rt->rt6i_dst.plen < 127 &&
26203e2a984STim Stallard 		 !(rt->rt6i_flags & (RTF_GATEWAY | RTF_NONEXTHOP)) &&
2632647a9b0SMartin KaFai Lau 		 ipv6_addr_equal(&rt->rt6i_dst.addr, daddr));
264509aba3bSFX Le Bail }
265509aba3bSFX Le Bail 
2667d8c6e39SEric W. Biederman int ip6_fragment(struct net *net, struct sock *sk, struct sk_buff *skb,
2677d8c6e39SEric W. Biederman 		 int (*output)(struct net *, struct sock *, struct sk_buff *));
268ad0081e4SDavid Stevens 
ip6_skb_dst_mtu(const struct sk_buff * skb)2698d22679dSEric Dumazet static inline unsigned int ip6_skb_dst_mtu(const struct sk_buff *skb)
270ad0081e4SDavid Stevens {
2718d22679dSEric Dumazet 	const struct ipv6_pinfo *np = skb->sk && !dev_recursion_level() ?
2728d22679dSEric Dumazet 				inet6_sk(skb->sk) : NULL;
2738d22679dSEric Dumazet 	const struct dst_entry *dst = skb_dst(skb);
27440391467SAntoine Tenart 	unsigned int mtu;
275fade5641SVadim Fedorenko 
2766b724bc4SEric Dumazet 	if (np && READ_ONCE(np->pmtudisc) >= IPV6_PMTUDISC_PROBE) {
2778d22679dSEric Dumazet 		mtu = READ_ONCE(dst->dev->mtu);
2788d22679dSEric Dumazet 		mtu -= lwtunnel_headroom(dst->lwtstate, mtu);
2798d22679dSEric Dumazet 	} else {
2808d22679dSEric Dumazet 		mtu = dst_mtu(dst);
2818d22679dSEric Dumazet 	}
282fade5641SVadim Fedorenko 	return mtu;
283ad0081e4SDavid Stevens }
284ad0081e4SDavid Stevens 
ip6_sk_accept_pmtu(const struct sock * sk)28593b36cf3SHannes Frederic Sowa static inline bool ip6_sk_accept_pmtu(const struct sock *sk)
28693b36cf3SHannes Frederic Sowa {
2876b724bc4SEric Dumazet 	u8 pmtudisc = READ_ONCE(inet6_sk(sk)->pmtudisc);
2886b724bc4SEric Dumazet 
2896b724bc4SEric Dumazet 	return pmtudisc != IPV6_PMTUDISC_INTERFACE &&
2906b724bc4SEric Dumazet 	       pmtudisc != IPV6_PMTUDISC_OMIT;
2910b95227aSHannes Frederic Sowa }
2920b95227aSHannes Frederic Sowa 
ip6_sk_ignore_df(const struct sock * sk)29360ff7467SWANG Cong static inline bool ip6_sk_ignore_df(const struct sock *sk)
2940b95227aSHannes Frederic Sowa {
2956b724bc4SEric Dumazet 	u8 pmtudisc = READ_ONCE(inet6_sk(sk)->pmtudisc);
2966b724bc4SEric Dumazet 
2976b724bc4SEric Dumazet 	return pmtudisc < IPV6_PMTUDISC_DO ||
2986b724bc4SEric Dumazet 	       pmtudisc == IPV6_PMTUDISC_OMIT;
29993b36cf3SHannes Frederic Sowa }
30093b36cf3SHannes Frederic Sowa 
rt6_nexthop(const struct rt6_info * rt,const struct in6_addr * daddr)3019b1c1ef1SNicolas Dichtel static inline const struct in6_addr *rt6_nexthop(const struct rt6_info *rt,
3029b1c1ef1SNicolas Dichtel 						 const struct in6_addr *daddr)
3039bb5a148SYOSHIFUJI Hideaki / 吉藤英明 {
3042647a9b0SMartin KaFai Lau 	if (rt->rt6i_flags & RTF_GATEWAY)
3059bb5a148SYOSHIFUJI Hideaki / 吉藤英明 		return &rt->rt6i_gateway;
30645e4fd26SMartin KaFai Lau 	else if (unlikely(rt->rt6i_flags & RTF_CACHE))
3072647a9b0SMartin KaFai Lau 		return &rt->rt6i_dst.addr;
3082647a9b0SMartin KaFai Lau 	else
3092647a9b0SMartin KaFai Lau 		return daddr;
3109bb5a148SYOSHIFUJI Hideaki / 吉藤英明 }
3119bb5a148SYOSHIFUJI Hideaki / 吉藤英明 
rt6_duplicate_nexthop(struct fib6_info * a,struct fib6_info * b)3128d1c802bSDavid Ahern static inline bool rt6_duplicate_nexthop(struct fib6_info *a, struct fib6_info *b)
313f06b7549SDavid Ahern {
314f88d8ea6SDavid Ahern 	struct fib6_nh *nha, *nhb;
315ad1601aeSDavid Ahern 
316f88d8ea6SDavid Ahern 	if (a->nh || b->nh)
317f88d8ea6SDavid Ahern 		return nexthop_cmp(a->nh, b->nh);
318f88d8ea6SDavid Ahern 
319f88d8ea6SDavid Ahern 	nha = a->fib6_nh;
320f88d8ea6SDavid Ahern 	nhb = b->fib6_nh;
321ad1601aeSDavid Ahern 	return nha->fib_nh_dev == nhb->fib_nh_dev &&
322ad1601aeSDavid Ahern 	       ipv6_addr_equal(&nha->fib_nh_gw6, &nhb->fib_nh_gw6) &&
323ad1601aeSDavid Ahern 	       !lwtunnel_cmp_encap(nha->fib_nh_lws, nhb->fib_nh_lws);
324f06b7549SDavid Ahern }
3255e5d6fedSRoopa Prabhu 
ip6_dst_mtu_maybe_forward(const struct dst_entry * dst,bool forwarding)326427faee1SVadim Fedorenko static inline unsigned int ip6_dst_mtu_maybe_forward(const struct dst_entry *dst,
327427faee1SVadim Fedorenko 						     bool forwarding)
32807cb9623SFelix Fietkau {
32907cb9623SFelix Fietkau 	struct inet6_dev *idev;
33007cb9623SFelix Fietkau 	unsigned int mtu;
33107cb9623SFelix Fietkau 
332427faee1SVadim Fedorenko 	if (!forwarding || dst_metric_locked(dst, RTAX_MTU)) {
33307cb9623SFelix Fietkau 		mtu = dst_metric_raw(dst, RTAX_MTU);
33407cb9623SFelix Fietkau 		if (mtu)
335fade5641SVadim Fedorenko 			goto out;
33607cb9623SFelix Fietkau 	}
33707cb9623SFelix Fietkau 
33807cb9623SFelix Fietkau 	mtu = IPV6_MIN_MTU;
33907cb9623SFelix Fietkau 	rcu_read_lock();
34007cb9623SFelix Fietkau 	idev = __in6_dev_get(dst->dev);
34107cb9623SFelix Fietkau 	if (idev)
342e7135f48SEric Dumazet 		mtu = READ_ONCE(idev->cnf.mtu6);
34307cb9623SFelix Fietkau 	rcu_read_unlock();
34407cb9623SFelix Fietkau 
345fade5641SVadim Fedorenko out:
346fade5641SVadim Fedorenko 	return mtu - lwtunnel_headroom(dst->lwtstate, mtu);
34707cb9623SFelix Fietkau }
34807cb9623SFelix Fietkau 
349b748f260SDavid Ahern u32 ip6_mtu_from_fib6(const struct fib6_result *res,
350b748f260SDavid Ahern 		      const struct in6_addr *daddr,
351b748f260SDavid Ahern 		      const struct in6_addr *saddr);
352901731b8SDavid Ahern 
353f8a1b43bSDavid Ahern struct neighbour *ip6_neigh_lookup(const struct in6_addr *gw,
354f8a1b43bSDavid Ahern 				   struct net_device *dev, struct sk_buff *skb,
355f8a1b43bSDavid Ahern 				   const void *daddr);
3561da177e4SLinus Torvalds #endif
357