11da177e4SLinus Torvalds #ifndef _NET_IP6_ROUTE_H 21da177e4SLinus Torvalds #define _NET_IP6_ROUTE_H 31da177e4SLinus Torvalds 470ceb4f5SYOSHIFUJI Hideaki struct route_info { 570ceb4f5SYOSHIFUJI Hideaki __u8 type; 670ceb4f5SYOSHIFUJI Hideaki __u8 length; 770ceb4f5SYOSHIFUJI Hideaki __u8 prefix_len; 870ceb4f5SYOSHIFUJI Hideaki #if defined(__BIG_ENDIAN_BITFIELD) 970ceb4f5SYOSHIFUJI Hideaki __u8 reserved_h:3, 1070ceb4f5SYOSHIFUJI Hideaki route_pref:2, 1170ceb4f5SYOSHIFUJI Hideaki reserved_l:3; 1270ceb4f5SYOSHIFUJI Hideaki #elif defined(__LITTLE_ENDIAN_BITFIELD) 1370ceb4f5SYOSHIFUJI Hideaki __u8 reserved_l:3, 1470ceb4f5SYOSHIFUJI Hideaki route_pref:2, 1570ceb4f5SYOSHIFUJI Hideaki reserved_h:3; 1670ceb4f5SYOSHIFUJI Hideaki #endif 17e69a4adcSAl Viro __be32 lifetime; 1870ceb4f5SYOSHIFUJI Hideaki __u8 prefix[0]; /* 0,8 or 16 */ 1970ceb4f5SYOSHIFUJI Hideaki }; 2070ceb4f5SYOSHIFUJI Hideaki 21*a2e2ff56SDavid Ahern #include <net/addrconf.h> 221da177e4SLinus Torvalds #include <net/flow.h> 231da177e4SLinus Torvalds #include <net/ip6_fib.h> 241da177e4SLinus Torvalds #include <net/sock.h> 251da177e4SLinus Torvalds #include <linux/ip.h> 261da177e4SLinus Torvalds #include <linux/ipv6.h> 279bb5a148SYOSHIFUJI Hideaki / 吉藤英明 #include <linux/route.h> 281da177e4SLinus Torvalds 297cbca67cSYOSHIFUJI Hideaki #define RT6_LOOKUP_F_IFACE 0x00000001 307cbca67cSYOSHIFUJI Hideaki #define RT6_LOOKUP_F_REACHABLE 0x00000002 317cbca67cSYOSHIFUJI Hideaki #define RT6_LOOKUP_F_HAS_SADDR 0x00000004 327cbca67cSYOSHIFUJI Hideaki #define RT6_LOOKUP_F_SRCPREF_TMP 0x00000008 337cbca67cSYOSHIFUJI Hideaki #define RT6_LOOKUP_F_SRCPREF_PUBLIC 0x00000010 347cbca67cSYOSHIFUJI Hideaki #define RT6_LOOKUP_F_SRCPREF_COA 0x00000020 3577d16f45SYOSHIFUJI Hideaki 3630f78d8eSEric Dumazet /* We do not (yet ?) support IPv6 jumbograms (RFC 2675) 3730f78d8eSEric Dumazet * Unlike IPv4, hdr->seg_len doesn't include the IPv6 header 3830f78d8eSEric Dumazet */ 3930f78d8eSEric Dumazet #define IP6_MAX_MTU (0xFFFF + sizeof(struct ipv6hdr)) 4030f78d8eSEric Dumazet 410c9a2ac1SYOSHIFUJI Hideaki / 吉藤英明 /* 420c9a2ac1SYOSHIFUJI Hideaki / 吉藤英明 * rt6_srcprefs2flags() and rt6_flags2srcprefs() translate 430c9a2ac1SYOSHIFUJI Hideaki / 吉藤英明 * between IPV6_ADDR_PREFERENCES socket option values 440c9a2ac1SYOSHIFUJI Hideaki / 吉藤英明 * IPV6_PREFER_SRC_TMP = 0x1 450c9a2ac1SYOSHIFUJI Hideaki / 吉藤英明 * IPV6_PREFER_SRC_PUBLIC = 0x2 460c9a2ac1SYOSHIFUJI Hideaki / 吉藤英明 * IPV6_PREFER_SRC_COA = 0x4 470c9a2ac1SYOSHIFUJI Hideaki / 吉藤英明 * and above RT6_LOOKUP_F_SRCPREF_xxx flags. 480c9a2ac1SYOSHIFUJI Hideaki / 吉藤英明 */ 490c9a2ac1SYOSHIFUJI Hideaki / 吉藤英明 static inline int rt6_srcprefs2flags(unsigned int srcprefs) 500c9a2ac1SYOSHIFUJI Hideaki / 吉藤英明 { 510c9a2ac1SYOSHIFUJI Hideaki / 吉藤英明 /* No need to bitmask because srcprefs have only 3 bits. */ 520c9a2ac1SYOSHIFUJI Hideaki / 吉藤英明 return srcprefs << 3; 530c9a2ac1SYOSHIFUJI Hideaki / 吉藤英明 } 540c9a2ac1SYOSHIFUJI Hideaki / 吉藤英明 550c9a2ac1SYOSHIFUJI Hideaki / 吉藤英明 static inline unsigned int rt6_flags2srcprefs(int flags) 560c9a2ac1SYOSHIFUJI Hideaki / 吉藤英明 { 570c9a2ac1SYOSHIFUJI Hideaki / 吉藤英明 return (flags >> 3) & 7; 580c9a2ac1SYOSHIFUJI Hideaki / 吉藤英明 } 591da177e4SLinus Torvalds 6060ea37f7SWang Yufen static inline bool rt6_need_strict(const struct in6_addr *daddr) 6160ea37f7SWang Yufen { 6260ea37f7SWang Yufen return ipv6_addr_type(daddr) & 6360ea37f7SWang Yufen (IPV6_ADDR_MULTICAST | IPV6_ADDR_LINKLOCAL | IPV6_ADDR_LOOPBACK); 6460ea37f7SWang Yufen } 65fbfe95a4SDavid S. Miller 665c3a0fd7SJoe Perches void ip6_route_input(struct sk_buff *skb); 671da177e4SLinus Torvalds 686f21c96aSPaolo Abeni struct dst_entry *ip6_route_output_flags(struct net *net, const struct sock *sk, 696f21c96aSPaolo Abeni struct flowi6 *fl6, int flags); 706f21c96aSPaolo Abeni 716f21c96aSPaolo Abeni static inline struct dst_entry *ip6_route_output(struct net *net, 726f21c96aSPaolo Abeni const struct sock *sk, 736f21c96aSPaolo Abeni struct flowi6 *fl6) 746f21c96aSPaolo Abeni { 756f21c96aSPaolo Abeni return ip6_route_output_flags(net, sk, fl6, 0); 766f21c96aSPaolo Abeni } 776f21c96aSPaolo Abeni 785c3a0fd7SJoe Perches struct dst_entry *ip6_route_lookup(struct net *net, struct flowi6 *fl6, 795c3a0fd7SJoe Perches int flags); 809ff74384SDavid Ahern struct rt6_info *ip6_pol_route(struct net *net, struct fib6_table *table, 819ff74384SDavid Ahern int ifindex, struct flowi6 *fl6, int flags); 821da177e4SLinus Torvalds 835c3a0fd7SJoe Perches int ip6_route_init(void); 845c3a0fd7SJoe Perches void ip6_route_cleanup(void); 851da177e4SLinus Torvalds 865c3a0fd7SJoe Perches int ipv6_route_ioctl(struct net *net, unsigned int cmd, void __user *arg); 871da177e4SLinus Torvalds 885c3a0fd7SJoe Perches int ip6_route_add(struct fib6_config *cfg); 895c3a0fd7SJoe Perches int ip6_ins_rt(struct rt6_info *); 905c3a0fd7SJoe Perches int ip6_del_rt(struct rt6_info *); 911da177e4SLinus Torvalds 92*a2e2ff56SDavid Ahern static inline int ip6_route_get_saddr(struct net *net, struct rt6_info *rt, 93*a2e2ff56SDavid Ahern const struct in6_addr *daddr, 94*a2e2ff56SDavid Ahern unsigned int prefs, 95*a2e2ff56SDavid Ahern struct in6_addr *saddr) 96*a2e2ff56SDavid Ahern { 97*a2e2ff56SDavid Ahern struct inet6_dev *idev = 98*a2e2ff56SDavid Ahern rt ? ip6_dst_idev((struct dst_entry *)rt) : NULL; 99*a2e2ff56SDavid Ahern int err = 0; 100*a2e2ff56SDavid Ahern 101*a2e2ff56SDavid Ahern if (rt && rt->rt6i_prefsrc.plen) 102*a2e2ff56SDavid Ahern *saddr = rt->rt6i_prefsrc.addr; 103*a2e2ff56SDavid Ahern else 104*a2e2ff56SDavid Ahern err = ipv6_dev_get_saddr(net, idev ? idev->dev : NULL, 105*a2e2ff56SDavid Ahern daddr, prefs, saddr); 106*a2e2ff56SDavid Ahern 107*a2e2ff56SDavid Ahern return err; 108*a2e2ff56SDavid Ahern } 109c3968a85SDaniel Walter 1105c3a0fd7SJoe Perches struct rt6_info *rt6_lookup(struct net *net, const struct in6_addr *daddr, 1115c3a0fd7SJoe Perches const struct in6_addr *saddr, int oif, int flags); 1121da177e4SLinus Torvalds 1135c3a0fd7SJoe Perches struct dst_entry *icmp6_dst_alloc(struct net_device *dev, struct flowi6 *fl6); 1145c3a0fd7SJoe Perches int icmp6_dst_gc(void); 1153b00944cSYOSHIFUJI Hideaki 1165c3a0fd7SJoe Perches void fib6_force_start_gc(struct net *net); 1171da177e4SLinus Torvalds 1185c3a0fd7SJoe Perches struct rt6_info *addrconf_dst_alloc(struct inet6_dev *idev, 1195c3a0fd7SJoe Perches const struct in6_addr *addr, bool anycast); 1201da177e4SLinus Torvalds 1219ab179d8SDavid Ahern struct rt6_info *ip6_dst_alloc(struct net *net, struct net_device *dev, 1229ab179d8SDavid Ahern int flags); 1239ab179d8SDavid Ahern 1241da177e4SLinus Torvalds /* 1251da177e4SLinus Torvalds * support functions for ND 1261da177e4SLinus Torvalds * 1271da177e4SLinus Torvalds */ 1285c3a0fd7SJoe Perches struct rt6_info *rt6_get_dflt_router(const struct in6_addr *addr, 1291da177e4SLinus Torvalds struct net_device *dev); 1305c3a0fd7SJoe Perches struct rt6_info *rt6_add_dflt_router(const struct in6_addr *gwaddr, 1315c3a0fd7SJoe Perches struct net_device *dev, unsigned int pref); 1321da177e4SLinus Torvalds 1335c3a0fd7SJoe Perches void rt6_purge_dflt_routers(struct net *net); 1341da177e4SLinus Torvalds 1355c3a0fd7SJoe Perches int rt6_route_rcv(struct net_device *dev, u8 *opt, int len, 136b71d1d42SEric Dumazet const struct in6_addr *gwaddr); 13770ceb4f5SYOSHIFUJI Hideaki 1385c3a0fd7SJoe Perches void ip6_update_pmtu(struct sk_buff *skb, struct net *net, __be32 mtu, int oif, 139c92a59ecSDuan Jiong u32 mark); 1405c3a0fd7SJoe Perches void ip6_sk_update_pmtu(struct sk_buff *skb, struct sock *sk, __be32 mtu); 1415c3a0fd7SJoe Perches void ip6_redirect(struct sk_buff *skb, struct net *net, int oif, u32 mark); 1425c3a0fd7SJoe Perches void ip6_redirect_no_header(struct sk_buff *skb, struct net *net, int oif, 1435c3a0fd7SJoe Perches u32 mark); 1445c3a0fd7SJoe Perches void ip6_sk_redirect(struct sk_buff *skb, struct sock *sk); 1451da177e4SLinus Torvalds 1461da177e4SLinus Torvalds struct netlink_callback; 1471da177e4SLinus Torvalds 148fd2c3ef7SEric Dumazet struct rt6_rtnl_dump_arg { 1491b43af54SPatrick McHardy struct sk_buff *skb; 1501b43af54SPatrick McHardy struct netlink_callback *cb; 151191cd582SBrian Haley struct net *net; 1521b43af54SPatrick McHardy }; 1531b43af54SPatrick McHardy 1545c3a0fd7SJoe Perches int rt6_dump_route(struct rt6_info *rt, void *p_arg); 1555c3a0fd7SJoe Perches void rt6_ifdown(struct net *net, struct net_device *dev); 1565c3a0fd7SJoe Perches void rt6_mtu_change(struct net_device *dev, unsigned int mtu); 1575c3a0fd7SJoe Perches void rt6_remove_prefsrc(struct inet6_ifaddr *ifp); 158be7a010dSDuan Jiong void rt6_clean_tohost(struct net *net, struct in6_addr *gateway); 1591da177e4SLinus Torvalds 1601da177e4SLinus Torvalds 1611da177e4SLinus Torvalds /* 1621da177e4SLinus Torvalds * Store a destination cache entry in a socket 1631da177e4SLinus Torvalds */ 1646bd4f355SEric Dumazet static inline void ip6_dst_store(struct sock *sk, struct dst_entry *dst, 165d3818c92SEric Dumazet const struct in6_addr *daddr, 166d3818c92SEric Dumazet const struct in6_addr *saddr) 1671da177e4SLinus Torvalds { 1681da177e4SLinus Torvalds struct ipv6_pinfo *np = inet6_sk(sk); 1691da177e4SLinus Torvalds 1706bd4f355SEric Dumazet np->dst_cookie = rt6_get_cookie((struct rt6_info *)dst); 171f83ef8c0SHerbert Xu sk_setup_caps(sk, dst); 1721da177e4SLinus Torvalds np->daddr_cache = daddr; 1738e1ef0a9SYOSHIFUJI Hideaki #ifdef CONFIG_IPV6_SUBTREES 1748e1ef0a9SYOSHIFUJI Hideaki np->saddr_cache = saddr; 1758e1ef0a9SYOSHIFUJI Hideaki #endif 1761da177e4SLinus Torvalds } 1771da177e4SLinus Torvalds 178a50feda5SEric Dumazet static inline bool ipv6_unicast_destination(const struct sk_buff *skb) 1791da177e4SLinus Torvalds { 180adf30907SEric Dumazet struct rt6_info *rt = (struct rt6_info *) skb_dst(skb); 1811da177e4SLinus Torvalds 1821da177e4SLinus Torvalds return rt->rt6i_flags & RTF_LOCAL; 1831da177e4SLinus Torvalds } 1841da177e4SLinus Torvalds 1852647a9b0SMartin KaFai Lau static inline bool ipv6_anycast_destination(const struct dst_entry *dst, 1862647a9b0SMartin KaFai Lau const struct in6_addr *daddr) 187509aba3bSFX Le Bail { 1882647a9b0SMartin KaFai Lau struct rt6_info *rt = (struct rt6_info *)dst; 189509aba3bSFX Le Bail 1902647a9b0SMartin KaFai Lau return rt->rt6i_flags & RTF_ANYCAST || 1912647a9b0SMartin KaFai Lau (rt->rt6i_dst.plen != 128 && 1922647a9b0SMartin KaFai Lau ipv6_addr_equal(&rt->rt6i_dst.addr, daddr)); 193509aba3bSFX Le Bail } 194509aba3bSFX Le Bail 1957d8c6e39SEric W. Biederman int ip6_fragment(struct net *net, struct sock *sk, struct sk_buff *skb, 1967d8c6e39SEric W. Biederman int (*output)(struct net *, struct sock *, struct sk_buff *)); 197ad0081e4SDavid Stevens 198ad0081e4SDavid Stevens static inline int ip6_skb_dst_mtu(struct sk_buff *skb) 199ad0081e4SDavid Stevens { 200f60e5990Shannes@stressinduktion.org struct ipv6_pinfo *np = skb->sk && !dev_recursion_level() ? 201f60e5990Shannes@stressinduktion.org inet6_sk(skb->sk) : NULL; 202ad0081e4SDavid Stevens 20393b36cf3SHannes Frederic Sowa return (np && np->pmtudisc >= IPV6_PMTUDISC_PROBE) ? 204ad0081e4SDavid Stevens skb_dst(skb)->dev->mtu : dst_mtu(skb_dst(skb)); 205ad0081e4SDavid Stevens } 206ad0081e4SDavid Stevens 20793b36cf3SHannes Frederic Sowa static inline bool ip6_sk_accept_pmtu(const struct sock *sk) 20893b36cf3SHannes Frederic Sowa { 2090b95227aSHannes Frederic Sowa return inet6_sk(sk)->pmtudisc != IPV6_PMTUDISC_INTERFACE && 2100b95227aSHannes Frederic Sowa inet6_sk(sk)->pmtudisc != IPV6_PMTUDISC_OMIT; 2110b95227aSHannes Frederic Sowa } 2120b95227aSHannes Frederic Sowa 21360ff7467SWANG Cong static inline bool ip6_sk_ignore_df(const struct sock *sk) 2140b95227aSHannes Frederic Sowa { 2150b95227aSHannes Frederic Sowa return inet6_sk(sk)->pmtudisc < IPV6_PMTUDISC_DO || 2160b95227aSHannes Frederic Sowa inet6_sk(sk)->pmtudisc == IPV6_PMTUDISC_OMIT; 21793b36cf3SHannes Frederic Sowa } 21893b36cf3SHannes Frederic Sowa 2192647a9b0SMartin KaFai Lau static inline struct in6_addr *rt6_nexthop(struct rt6_info *rt, 2202647a9b0SMartin KaFai Lau struct in6_addr *daddr) 2219bb5a148SYOSHIFUJI Hideaki / 吉藤英明 { 2222647a9b0SMartin KaFai Lau if (rt->rt6i_flags & RTF_GATEWAY) 2239bb5a148SYOSHIFUJI Hideaki / 吉藤英明 return &rt->rt6i_gateway; 22445e4fd26SMartin KaFai Lau else if (unlikely(rt->rt6i_flags & RTF_CACHE)) 2252647a9b0SMartin KaFai Lau return &rt->rt6i_dst.addr; 2262647a9b0SMartin KaFai Lau else 2272647a9b0SMartin KaFai Lau return daddr; 2289bb5a148SYOSHIFUJI Hideaki / 吉藤英明 } 2299bb5a148SYOSHIFUJI Hideaki / 吉藤英明 2301da177e4SLinus Torvalds #endif 231