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 / 吉藤英明 {
560c9a2ac1SYOSHIFUJI Hideaki / 吉藤英明 /* No need to bitmask because srcprefs have only 3 bits. */
570c9a2ac1SYOSHIFUJI Hideaki / 吉藤英明 return srcprefs << 3;
580c9a2ac1SYOSHIFUJI Hideaki / 吉藤英明 }
590c9a2ac1SYOSHIFUJI Hideaki / 吉藤英明
rt6_flags2srcprefs(int flags)600c9a2ac1SYOSHIFUJI Hideaki / 吉藤英明 static inline unsigned int rt6_flags2srcprefs(int flags)
610c9a2ac1SYOSHIFUJI Hideaki / 吉藤英明 {
620c9a2ac1SYOSHIFUJI Hideaki / 吉藤英明 return (flags >> 3) & 7;
630c9a2ac1SYOSHIFUJI Hideaki / 吉藤英明 }
641da177e4SLinus Torvalds
rt6_need_strict(const struct in6_addr * daddr)6560ea37f7SWang Yufen static inline bool rt6_need_strict(const struct in6_addr *daddr)
6660ea37f7SWang Yufen {
6760ea37f7SWang Yufen return ipv6_addr_type(daddr) &
6860ea37f7SWang Yufen (IPV6_ADDR_MULTICAST | IPV6_ADDR_LINKLOCAL | IPV6_ADDR_LOOPBACK);
6960ea37f7SWang Yufen }
70fbfe95a4SDavid S. Miller
71f88d8ea6SDavid Ahern /* fib entries using a nexthop object can not be coalesced into
72f88d8ea6SDavid Ahern * a multipath route
73f88d8ea6SDavid Ahern */
rt6_qualify_for_ecmp(const struct fib6_info * f6i)7433bd5ac5SDavid Ahern static inline bool rt6_qualify_for_ecmp(const struct fib6_info *f6i)
7533bd5ac5SDavid Ahern {
76be659b8dSDavid Ahern /* the RTF_ADDRCONF flag filters out RA's */
77f88d8ea6SDavid Ahern return !(f6i->fib6_flags & RTF_ADDRCONF) && !f6i->nh &&
781cf844c7SDavid Ahern f6i->fib6_nh->fib_nh_gw_family;
7933bd5ac5SDavid Ahern }
8033bd5ac5SDavid Ahern
815c3a0fd7SJoe Perches void ip6_route_input(struct sk_buff *skb);
82d409b847SMahesh Bandewar struct dst_entry *ip6_route_input_lookup(struct net *net,
83d409b847SMahesh Bandewar struct net_device *dev,
84b75cc8f9SDavid Ahern struct flowi6 *fl6,
85b75cc8f9SDavid Ahern const struct sk_buff *skb, int flags);
861da177e4SLinus Torvalds
876f21c96aSPaolo Abeni struct dst_entry *ip6_route_output_flags(struct net *net, const struct sock *sk,
886f21c96aSPaolo Abeni struct flowi6 *fl6, int flags);
896f21c96aSPaolo Abeni
ip6_route_output(struct net * net,const struct sock * sk,struct flowi6 * fl6)906f21c96aSPaolo Abeni static inline struct dst_entry *ip6_route_output(struct net *net,
916f21c96aSPaolo Abeni const struct sock *sk,
926f21c96aSPaolo Abeni struct flowi6 *fl6)
936f21c96aSPaolo Abeni {
946f21c96aSPaolo Abeni return ip6_route_output_flags(net, sk, fl6, 0);
956f21c96aSPaolo Abeni }
966f21c96aSPaolo Abeni
97d64a1f57SWei Wang /* Only conditionally release dst if flags indicates
98d64a1f57SWei Wang * !RT6_LOOKUP_F_DST_NOREF or dst is in uncached_list.
99d64a1f57SWei Wang */
ip6_rt_put_flags(struct rt6_info * rt,int flags)100d64a1f57SWei Wang static inline void ip6_rt_put_flags(struct rt6_info *rt, int flags)
101d64a1f57SWei Wang {
102d64a1f57SWei Wang if (!(flags & RT6_LOOKUP_F_DST_NOREF) ||
103d288a162SWangyang Guo !list_empty(&rt->dst.rt_uncached))
104d64a1f57SWei Wang ip6_rt_put(rt);
105d64a1f57SWei Wang }
106d64a1f57SWei Wang
1075c3a0fd7SJoe Perches struct dst_entry *ip6_route_lookup(struct net *net, struct flowi6 *fl6,
108b75cc8f9SDavid Ahern const struct sk_buff *skb, int flags);
1099ff74384SDavid Ahern struct rt6_info *ip6_pol_route(struct net *net, struct fib6_table *table,
110b75cc8f9SDavid Ahern int ifindex, struct flowi6 *fl6,
111b75cc8f9SDavid Ahern const struct sk_buff *skb, int flags);
1121da177e4SLinus Torvalds
1132f460933SWANG Cong void ip6_route_init_special_entries(void);
1145c3a0fd7SJoe Perches int ip6_route_init(void);
1155c3a0fd7SJoe Perches void ip6_route_cleanup(void);
1161da177e4SLinus Torvalds
1177c1552daSChristoph Hellwig int ipv6_route_ioctl(struct net *net, unsigned int cmd,
1187c1552daSChristoph Hellwig struct in6_rtmsg *rtmsg);
1191da177e4SLinus Torvalds
120acb54e3cSDavid Ahern int ip6_route_add(struct fib6_config *cfg, gfp_t gfp_flags,
121acb54e3cSDavid Ahern struct netlink_ext_ack *extack);
12293c2fb25SDavid Ahern int ip6_ins_rt(struct net *net, struct fib6_info *f6i);
12311dd74b3SRoopa Prabhu int ip6_del_rt(struct net *net, struct fib6_info *f6i, bool skip_notify);
1241da177e4SLinus Torvalds
12593c2fb25SDavid Ahern void rt6_flush_exceptions(struct fib6_info *f6i);
12693c2fb25SDavid Ahern void rt6_age_exceptions(struct fib6_info *f6i, struct fib6_gc_args *gc_args,
127c757faa8SWei Wang unsigned long now);
12835732d01SWei 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)12993c2fb25SDavid Ahern static inline int ip6_route_get_saddr(struct net *net, struct fib6_info *f6i,
130a2e2ff56SDavid Ahern const struct in6_addr *daddr,
131e7f3e5fbSNicolas Dichtel unsigned int prefs, int l3mdev_index,
132a2e2ff56SDavid Ahern struct in6_addr *saddr)
133a2e2ff56SDavid Ahern {
134e7f3e5fbSNicolas Dichtel struct net_device *l3mdev;
135e7f3e5fbSNicolas Dichtel struct net_device *dev;
136e7f3e5fbSNicolas Dichtel bool same_vrf;
137a2e2ff56SDavid Ahern int err = 0;
138a2e2ff56SDavid Ahern
139e7f3e5fbSNicolas Dichtel rcu_read_lock();
1406fe74941SDavid Ahern
141e7f3e5fbSNicolas Dichtel l3mdev = dev_get_by_index_rcu(net, l3mdev_index);
142e7f3e5fbSNicolas Dichtel if (!f6i || !f6i->fib6_prefsrc.plen || l3mdev)
143e7f3e5fbSNicolas Dichtel dev = f6i ? fib6_info_nh_dev(f6i) : NULL;
144e7f3e5fbSNicolas Dichtel same_vrf = !l3mdev || l3mdev_master_dev_rcu(dev) == l3mdev;
145e7f3e5fbSNicolas Dichtel if (f6i && f6i->fib6_prefsrc.plen && same_vrf)
146e7f3e5fbSNicolas Dichtel *saddr = f6i->fib6_prefsrc.addr;
147e7f3e5fbSNicolas Dichtel else
148e7f3e5fbSNicolas Dichtel err = ipv6_dev_get_saddr(net, same_vrf ? dev : l3mdev, daddr, prefs, saddr);
149e7f3e5fbSNicolas Dichtel
150e7f3e5fbSNicolas Dichtel rcu_read_unlock();
151a2e2ff56SDavid Ahern
152a2e2ff56SDavid Ahern return err;
153a2e2ff56SDavid Ahern }
154c3968a85SDaniel Walter
1555c3a0fd7SJoe Perches struct rt6_info *rt6_lookup(struct net *net, const struct in6_addr *daddr,
156b75cc8f9SDavid Ahern const struct in6_addr *saddr, int oif,
157b75cc8f9SDavid Ahern const struct sk_buff *skb, int flags);
158b4bac172SDavid Ahern u32 rt6_multipath_hash(const struct net *net, const struct flowi6 *fl6,
159b4bac172SDavid Ahern const struct sk_buff *skb, struct flow_keys *hkeys);
1601da177e4SLinus Torvalds
1615c3a0fd7SJoe Perches struct dst_entry *icmp6_dst_alloc(struct net_device *dev, struct flowi6 *fl6);
1623b00944cSYOSHIFUJI Hideaki
1635c3a0fd7SJoe Perches void fib6_force_start_gc(struct net *net);
1641da177e4SLinus Torvalds
165360a9887SDavid Ahern struct fib6_info *addrconf_f6i_alloc(struct net *net, struct inet6_dev *idev,
166acb54e3cSDavid Ahern const struct in6_addr *addr, bool anycast,
1677f6c4039SHangbin Liu gfp_t gfp_flags, struct netlink_ext_ack *extack);
1681da177e4SLinus Torvalds
1699ab179d8SDavid Ahern struct rt6_info *ip6_dst_alloc(struct net *net, struct net_device *dev,
1709ab179d8SDavid Ahern int flags);
1719ab179d8SDavid Ahern
1721da177e4SLinus Torvalds /*
1731da177e4SLinus Torvalds * support functions for ND
1741da177e4SLinus Torvalds *
1751da177e4SLinus Torvalds */
1768d1c802bSDavid Ahern struct fib6_info *rt6_get_dflt_router(struct net *net,
177afb1d4b5SDavid Ahern const struct in6_addr *addr,
1781da177e4SLinus Torvalds struct net_device *dev);
1798d1c802bSDavid Ahern struct fib6_info *rt6_add_dflt_router(struct net *net,
180afb1d4b5SDavid Ahern const struct in6_addr *gwaddr,
1816b2e04bcSPraveen Chaudhary struct net_device *dev, unsigned int pref,
1826b2e04bcSPraveen Chaudhary u32 defrtr_usr_metric);
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)
223*797a4c1fSEric Dumazet return dst_rt6_info(dst);
2241b70d792SDavid Ahern
225*797a4c1fSEric 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
237*797a4c1fSEric 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 {
250*797a4c1fSEric 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 {
258*797a4c1fSEric 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
276fade5641SVadim Fedorenko if (np && 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 {
2870b95227aSHannes Frederic Sowa return inet6_sk(sk)->pmtudisc != IPV6_PMTUDISC_INTERFACE &&
2880b95227aSHannes Frederic Sowa inet6_sk(sk)->pmtudisc != IPV6_PMTUDISC_OMIT;
2890b95227aSHannes Frederic Sowa }
2900b95227aSHannes Frederic Sowa
ip6_sk_ignore_df(const struct sock * sk)29160ff7467SWANG Cong static inline bool ip6_sk_ignore_df(const struct sock *sk)
2920b95227aSHannes Frederic Sowa {
2930b95227aSHannes Frederic Sowa return inet6_sk(sk)->pmtudisc < IPV6_PMTUDISC_DO ||
2940b95227aSHannes Frederic Sowa inet6_sk(sk)->pmtudisc == IPV6_PMTUDISC_OMIT;
29593b36cf3SHannes Frederic Sowa }
29693b36cf3SHannes Frederic Sowa
rt6_nexthop(const struct rt6_info * rt,const struct in6_addr * daddr)2979b1c1ef1SNicolas Dichtel static inline const struct in6_addr *rt6_nexthop(const struct rt6_info *rt,
2989b1c1ef1SNicolas Dichtel const struct in6_addr *daddr)
2999bb5a148SYOSHIFUJI Hideaki / 吉藤英明 {
3002647a9b0SMartin KaFai Lau if (rt->rt6i_flags & RTF_GATEWAY)
3019bb5a148SYOSHIFUJI Hideaki / 吉藤英明 return &rt->rt6i_gateway;
30245e4fd26SMartin KaFai Lau else if (unlikely(rt->rt6i_flags & RTF_CACHE))
3032647a9b0SMartin KaFai Lau return &rt->rt6i_dst.addr;
3042647a9b0SMartin KaFai Lau else
3052647a9b0SMartin KaFai Lau return daddr;
3069bb5a148SYOSHIFUJI Hideaki / 吉藤英明 }
3079bb5a148SYOSHIFUJI Hideaki / 吉藤英明
rt6_duplicate_nexthop(struct fib6_info * a,struct fib6_info * b)3088d1c802bSDavid Ahern static inline bool rt6_duplicate_nexthop(struct fib6_info *a, struct fib6_info *b)
309f06b7549SDavid Ahern {
310f88d8ea6SDavid Ahern struct fib6_nh *nha, *nhb;
311ad1601aeSDavid Ahern
312f88d8ea6SDavid Ahern if (a->nh || b->nh)
313f88d8ea6SDavid Ahern return nexthop_cmp(a->nh, b->nh);
314f88d8ea6SDavid Ahern
315f88d8ea6SDavid Ahern nha = a->fib6_nh;
316f88d8ea6SDavid Ahern nhb = b->fib6_nh;
317ad1601aeSDavid Ahern return nha->fib_nh_dev == nhb->fib_nh_dev &&
318ad1601aeSDavid Ahern ipv6_addr_equal(&nha->fib_nh_gw6, &nhb->fib_nh_gw6) &&
319ad1601aeSDavid Ahern !lwtunnel_cmp_encap(nha->fib_nh_lws, nhb->fib_nh_lws);
320f06b7549SDavid Ahern }
3215e5d6fedSRoopa Prabhu
ip6_dst_mtu_maybe_forward(const struct dst_entry * dst,bool forwarding)322427faee1SVadim Fedorenko static inline unsigned int ip6_dst_mtu_maybe_forward(const struct dst_entry *dst,
323427faee1SVadim Fedorenko bool forwarding)
32407cb9623SFelix Fietkau {
32507cb9623SFelix Fietkau struct inet6_dev *idev;
32607cb9623SFelix Fietkau unsigned int mtu;
32707cb9623SFelix Fietkau
328427faee1SVadim Fedorenko if (!forwarding || dst_metric_locked(dst, RTAX_MTU)) {
32907cb9623SFelix Fietkau mtu = dst_metric_raw(dst, RTAX_MTU);
33007cb9623SFelix Fietkau if (mtu)
331fade5641SVadim Fedorenko goto out;
33207cb9623SFelix Fietkau }
33307cb9623SFelix Fietkau
33407cb9623SFelix Fietkau mtu = IPV6_MIN_MTU;
33507cb9623SFelix Fietkau rcu_read_lock();
33607cb9623SFelix Fietkau idev = __in6_dev_get(dst->dev);
33707cb9623SFelix Fietkau if (idev)
33807cb9623SFelix Fietkau mtu = idev->cnf.mtu6;
33907cb9623SFelix Fietkau rcu_read_unlock();
34007cb9623SFelix Fietkau
341fade5641SVadim Fedorenko out:
342fade5641SVadim Fedorenko return mtu - lwtunnel_headroom(dst->lwtstate, mtu);
34307cb9623SFelix Fietkau }
34407cb9623SFelix Fietkau
345b748f260SDavid Ahern u32 ip6_mtu_from_fib6(const struct fib6_result *res,
346b748f260SDavid Ahern const struct in6_addr *daddr,
347b748f260SDavid Ahern const struct in6_addr *saddr);
348901731b8SDavid Ahern
349f8a1b43bSDavid Ahern struct neighbour *ip6_neigh_lookup(const struct in6_addr *gw,
350f8a1b43bSDavid Ahern struct net_device *dev, struct sk_buff *skb,
351f8a1b43bSDavid Ahern const void *daddr);
3521da177e4SLinus Torvalds #endif
353