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 211da177e4SLinus Torvalds #include <net/flow.h> 221da177e4SLinus Torvalds #include <net/ip6_fib.h> 231da177e4SLinus Torvalds #include <net/sock.h> 241da177e4SLinus Torvalds #include <linux/ip.h> 251da177e4SLinus Torvalds #include <linux/ipv6.h> 269bb5a148SYOSHIFUJI Hideaki / 吉藤英明 #include <linux/route.h> 271da177e4SLinus Torvalds 287cbca67cSYOSHIFUJI Hideaki #define RT6_LOOKUP_F_IFACE 0x00000001 297cbca67cSYOSHIFUJI Hideaki #define RT6_LOOKUP_F_REACHABLE 0x00000002 307cbca67cSYOSHIFUJI Hideaki #define RT6_LOOKUP_F_HAS_SADDR 0x00000004 317cbca67cSYOSHIFUJI Hideaki #define RT6_LOOKUP_F_SRCPREF_TMP 0x00000008 327cbca67cSYOSHIFUJI Hideaki #define RT6_LOOKUP_F_SRCPREF_PUBLIC 0x00000010 337cbca67cSYOSHIFUJI Hideaki #define RT6_LOOKUP_F_SRCPREF_COA 0x00000020 3477d16f45SYOSHIFUJI Hideaki 3530f78d8eSEric Dumazet /* We do not (yet ?) support IPv6 jumbograms (RFC 2675) 3630f78d8eSEric Dumazet * Unlike IPv4, hdr->seg_len doesn't include the IPv6 header 3730f78d8eSEric Dumazet */ 3830f78d8eSEric Dumazet #define IP6_MAX_MTU (0xFFFF + sizeof(struct ipv6hdr)) 3930f78d8eSEric Dumazet 400c9a2ac1SYOSHIFUJI Hideaki / 吉藤英明 /* 410c9a2ac1SYOSHIFUJI Hideaki / 吉藤英明 * rt6_srcprefs2flags() and rt6_flags2srcprefs() translate 420c9a2ac1SYOSHIFUJI Hideaki / 吉藤英明 * between IPV6_ADDR_PREFERENCES socket option values 430c9a2ac1SYOSHIFUJI Hideaki / 吉藤英明 * IPV6_PREFER_SRC_TMP = 0x1 440c9a2ac1SYOSHIFUJI Hideaki / 吉藤英明 * IPV6_PREFER_SRC_PUBLIC = 0x2 450c9a2ac1SYOSHIFUJI Hideaki / 吉藤英明 * IPV6_PREFER_SRC_COA = 0x4 460c9a2ac1SYOSHIFUJI Hideaki / 吉藤英明 * and above RT6_LOOKUP_F_SRCPREF_xxx flags. 470c9a2ac1SYOSHIFUJI Hideaki / 吉藤英明 */ 480c9a2ac1SYOSHIFUJI Hideaki / 吉藤英明 static inline int rt6_srcprefs2flags(unsigned int srcprefs) 490c9a2ac1SYOSHIFUJI Hideaki / 吉藤英明 { 500c9a2ac1SYOSHIFUJI Hideaki / 吉藤英明 /* No need to bitmask because srcprefs have only 3 bits. */ 510c9a2ac1SYOSHIFUJI Hideaki / 吉藤英明 return srcprefs << 3; 520c9a2ac1SYOSHIFUJI Hideaki / 吉藤英明 } 530c9a2ac1SYOSHIFUJI Hideaki / 吉藤英明 540c9a2ac1SYOSHIFUJI Hideaki / 吉藤英明 static inline unsigned int rt6_flags2srcprefs(int flags) 550c9a2ac1SYOSHIFUJI Hideaki / 吉藤英明 { 560c9a2ac1SYOSHIFUJI Hideaki / 吉藤英明 return (flags >> 3) & 7; 570c9a2ac1SYOSHIFUJI Hideaki / 吉藤英明 } 581da177e4SLinus Torvalds 5960ea37f7SWang Yufen static inline bool rt6_need_strict(const struct in6_addr *daddr) 6060ea37f7SWang Yufen { 6160ea37f7SWang Yufen return ipv6_addr_type(daddr) & 6260ea37f7SWang Yufen (IPV6_ADDR_MULTICAST | IPV6_ADDR_LINKLOCAL | IPV6_ADDR_LOOPBACK); 6360ea37f7SWang Yufen } 64fbfe95a4SDavid S. Miller 655c3a0fd7SJoe Perches void ip6_route_input(struct sk_buff *skb); 661da177e4SLinus Torvalds 675c3a0fd7SJoe Perches struct dst_entry *ip6_route_output(struct net *net, const struct sock *sk, 684c9483b2SDavid S. Miller struct flowi6 *fl6); 695c3a0fd7SJoe Perches struct dst_entry *ip6_route_lookup(struct net *net, struct flowi6 *fl6, 705c3a0fd7SJoe Perches int flags); 711da177e4SLinus Torvalds 725c3a0fd7SJoe Perches int ip6_route_init(void); 735c3a0fd7SJoe Perches void ip6_route_cleanup(void); 741da177e4SLinus Torvalds 755c3a0fd7SJoe Perches int ipv6_route_ioctl(struct net *net, unsigned int cmd, void __user *arg); 761da177e4SLinus Torvalds 775c3a0fd7SJoe Perches int ip6_route_add(struct fib6_config *cfg); 785c3a0fd7SJoe Perches int ip6_ins_rt(struct rt6_info *); 795c3a0fd7SJoe Perches int ip6_del_rt(struct rt6_info *); 801da177e4SLinus Torvalds 815c3a0fd7SJoe Perches int ip6_route_get_saddr(struct net *net, struct rt6_info *rt, 825c3a0fd7SJoe Perches const struct in6_addr *daddr, unsigned int prefs, 83c3968a85SDaniel Walter struct in6_addr *saddr); 84c3968a85SDaniel Walter 855c3a0fd7SJoe Perches struct rt6_info *rt6_lookup(struct net *net, const struct in6_addr *daddr, 865c3a0fd7SJoe Perches const struct in6_addr *saddr, int oif, int flags); 871da177e4SLinus Torvalds 885c3a0fd7SJoe Perches struct dst_entry *icmp6_dst_alloc(struct net_device *dev, struct flowi6 *fl6); 895c3a0fd7SJoe Perches int icmp6_dst_gc(void); 903b00944cSYOSHIFUJI Hideaki 915c3a0fd7SJoe Perches void fib6_force_start_gc(struct net *net); 921da177e4SLinus Torvalds 935c3a0fd7SJoe Perches struct rt6_info *addrconf_dst_alloc(struct inet6_dev *idev, 945c3a0fd7SJoe Perches const struct in6_addr *addr, bool anycast); 951da177e4SLinus Torvalds 961da177e4SLinus Torvalds /* 971da177e4SLinus Torvalds * support functions for ND 981da177e4SLinus Torvalds * 991da177e4SLinus Torvalds */ 1005c3a0fd7SJoe Perches struct rt6_info *rt6_get_dflt_router(const struct in6_addr *addr, 1011da177e4SLinus Torvalds struct net_device *dev); 1025c3a0fd7SJoe Perches struct rt6_info *rt6_add_dflt_router(const struct in6_addr *gwaddr, 1035c3a0fd7SJoe Perches struct net_device *dev, unsigned int pref); 1041da177e4SLinus Torvalds 1055c3a0fd7SJoe Perches void rt6_purge_dflt_routers(struct net *net); 1061da177e4SLinus Torvalds 1075c3a0fd7SJoe Perches int rt6_route_rcv(struct net_device *dev, u8 *opt, int len, 108b71d1d42SEric Dumazet const struct in6_addr *gwaddr); 10970ceb4f5SYOSHIFUJI Hideaki 1105c3a0fd7SJoe Perches void ip6_update_pmtu(struct sk_buff *skb, struct net *net, __be32 mtu, int oif, 111c92a59ecSDuan Jiong u32 mark); 1125c3a0fd7SJoe Perches void ip6_sk_update_pmtu(struct sk_buff *skb, struct sock *sk, __be32 mtu); 1135c3a0fd7SJoe Perches void ip6_redirect(struct sk_buff *skb, struct net *net, int oif, u32 mark); 1145c3a0fd7SJoe Perches void ip6_redirect_no_header(struct sk_buff *skb, struct net *net, int oif, 1155c3a0fd7SJoe Perches u32 mark); 1165c3a0fd7SJoe Perches void ip6_sk_redirect(struct sk_buff *skb, struct sock *sk); 1171da177e4SLinus Torvalds 1181da177e4SLinus Torvalds struct netlink_callback; 1191da177e4SLinus Torvalds 120fd2c3ef7SEric Dumazet struct rt6_rtnl_dump_arg { 1211b43af54SPatrick McHardy struct sk_buff *skb; 1221b43af54SPatrick McHardy struct netlink_callback *cb; 123191cd582SBrian Haley struct net *net; 1241b43af54SPatrick McHardy }; 1251b43af54SPatrick McHardy 1265c3a0fd7SJoe Perches int rt6_dump_route(struct rt6_info *rt, void *p_arg); 1275c3a0fd7SJoe Perches void rt6_ifdown(struct net *net, struct net_device *dev); 1285c3a0fd7SJoe Perches void rt6_mtu_change(struct net_device *dev, unsigned int mtu); 1295c3a0fd7SJoe Perches void rt6_remove_prefsrc(struct inet6_ifaddr *ifp); 130be7a010dSDuan Jiong void rt6_clean_tohost(struct net *net, struct in6_addr *gateway); 1311da177e4SLinus Torvalds 1321da177e4SLinus Torvalds 1331da177e4SLinus Torvalds /* 1341da177e4SLinus Torvalds * Store a destination cache entry in a socket 1351da177e4SLinus Torvalds */ 136497c615aSHerbert Xu static inline void __ip6_dst_store(struct sock *sk, struct dst_entry *dst, 137d3818c92SEric Dumazet const struct in6_addr *daddr, 138d3818c92SEric Dumazet const struct in6_addr *saddr) 1391da177e4SLinus Torvalds { 1401da177e4SLinus Torvalds struct ipv6_pinfo *np = inet6_sk(sk); 1411da177e4SLinus Torvalds struct rt6_info *rt = (struct rt6_info *) dst; 1421da177e4SLinus Torvalds 143f83ef8c0SHerbert Xu sk_setup_caps(sk, dst); 1441da177e4SLinus Torvalds np->daddr_cache = daddr; 1458e1ef0a9SYOSHIFUJI Hideaki #ifdef CONFIG_IPV6_SUBTREES 1468e1ef0a9SYOSHIFUJI Hideaki np->saddr_cache = saddr; 1478e1ef0a9SYOSHIFUJI Hideaki #endif 1481da177e4SLinus Torvalds np->dst_cookie = rt->rt6i_node ? rt->rt6i_node->fn_sernum : 0; 149497c615aSHerbert Xu } 150497c615aSHerbert Xu 151497c615aSHerbert Xu static inline void ip6_dst_store(struct sock *sk, struct dst_entry *dst, 1528e1ef0a9SYOSHIFUJI Hideaki struct in6_addr *daddr, struct in6_addr *saddr) 153497c615aSHerbert Xu { 154b6c6712aSEric Dumazet spin_lock(&sk->sk_dst_lock); 1558e1ef0a9SYOSHIFUJI Hideaki __ip6_dst_store(sk, dst, daddr, saddr); 156b6c6712aSEric Dumazet spin_unlock(&sk->sk_dst_lock); 1571da177e4SLinus Torvalds } 1581da177e4SLinus Torvalds 159a50feda5SEric Dumazet static inline bool ipv6_unicast_destination(const struct sk_buff *skb) 1601da177e4SLinus Torvalds { 161adf30907SEric Dumazet struct rt6_info *rt = (struct rt6_info *) skb_dst(skb); 1621da177e4SLinus Torvalds 1631da177e4SLinus Torvalds return rt->rt6i_flags & RTF_LOCAL; 1641da177e4SLinus Torvalds } 1651da177e4SLinus Torvalds 166509aba3bSFX Le Bail static inline bool ipv6_anycast_destination(const struct sk_buff *skb) 167509aba3bSFX Le Bail { 168509aba3bSFX Le Bail struct rt6_info *rt = (struct rt6_info *) skb_dst(skb); 169509aba3bSFX Le Bail 170509aba3bSFX Le Bail return rt->rt6i_flags & RTF_ANYCAST; 171509aba3bSFX Le Bail } 172509aba3bSFX Le Bail 173ad0081e4SDavid Stevens int ip6_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *)); 174ad0081e4SDavid Stevens 175ad0081e4SDavid Stevens static inline int ip6_skb_dst_mtu(struct sk_buff *skb) 176ad0081e4SDavid Stevens { 177*f60e5990Shannes@stressinduktion.org struct ipv6_pinfo *np = skb->sk && !dev_recursion_level() ? 178*f60e5990Shannes@stressinduktion.org inet6_sk(skb->sk) : NULL; 179ad0081e4SDavid Stevens 18093b36cf3SHannes Frederic Sowa return (np && np->pmtudisc >= IPV6_PMTUDISC_PROBE) ? 181ad0081e4SDavid Stevens skb_dst(skb)->dev->mtu : dst_mtu(skb_dst(skb)); 182ad0081e4SDavid Stevens } 183ad0081e4SDavid Stevens 18493b36cf3SHannes Frederic Sowa static inline bool ip6_sk_accept_pmtu(const struct sock *sk) 18593b36cf3SHannes Frederic Sowa { 1860b95227aSHannes Frederic Sowa return inet6_sk(sk)->pmtudisc != IPV6_PMTUDISC_INTERFACE && 1870b95227aSHannes Frederic Sowa inet6_sk(sk)->pmtudisc != IPV6_PMTUDISC_OMIT; 1880b95227aSHannes Frederic Sowa } 1890b95227aSHannes Frederic Sowa 19060ff7467SWANG Cong static inline bool ip6_sk_ignore_df(const struct sock *sk) 1910b95227aSHannes Frederic Sowa { 1920b95227aSHannes Frederic Sowa return inet6_sk(sk)->pmtudisc < IPV6_PMTUDISC_DO || 1930b95227aSHannes Frederic Sowa inet6_sk(sk)->pmtudisc == IPV6_PMTUDISC_OMIT; 19493b36cf3SHannes Frederic Sowa } 19593b36cf3SHannes Frederic Sowa 196550bab42SJulian Anastasov static inline struct in6_addr *rt6_nexthop(struct rt6_info *rt) 1979bb5a148SYOSHIFUJI Hideaki / 吉藤英明 { 1989bb5a148SYOSHIFUJI Hideaki / 吉藤英明 return &rt->rt6i_gateway; 1999bb5a148SYOSHIFUJI Hideaki / 吉藤英明 } 2009bb5a148SYOSHIFUJI Hideaki / 吉藤英明 2011da177e4SLinus Torvalds #endif 202