ip6_route.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. #ifndef _NET_IP6_ROUTE_H
  2. #define _NET_IP6_ROUTE_H
  3. #define IP6_RT_PRIO_USER 1024
  4. #define IP6_RT_PRIO_ADDRCONF 256
  5. struct route_info {
  6. __u8 type;
  7. __u8 length;
  8. __u8 prefix_len;
  9. #if defined(__BIG_ENDIAN_BITFIELD)
  10. __u8 reserved_h:3,
  11. route_pref:2,
  12. reserved_l:3;
  13. #elif defined(__LITTLE_ENDIAN_BITFIELD)
  14. __u8 reserved_l:3,
  15. route_pref:2,
  16. reserved_h:3;
  17. #endif
  18. __be32 lifetime;
  19. __u8 prefix[0]; /* 0,8 or 16 */
  20. };
  21. #include <net/flow.h>
  22. #include <net/ip6_fib.h>
  23. #include <net/sock.h>
  24. #include <linux/ip.h>
  25. #include <linux/ipv6.h>
  26. #define RT6_LOOKUP_F_IFACE 0x00000001
  27. #define RT6_LOOKUP_F_REACHABLE 0x00000002
  28. #define RT6_LOOKUP_F_HAS_SADDR 0x00000004
  29. #define RT6_LOOKUP_F_SRCPREF_TMP 0x00000008
  30. #define RT6_LOOKUP_F_SRCPREF_PUBLIC 0x00000010
  31. #define RT6_LOOKUP_F_SRCPREF_COA 0x00000020
  32. /* We do not (yet ?) support IPv6 jumbograms (RFC 2675)
  33. * Unlike IPv4, hdr->seg_len doesn't include the IPv6 header
  34. */
  35. #define IP6_MAX_MTU (0xFFFF + sizeof(struct ipv6hdr))
  36. /*
  37. * rt6_srcprefs2flags() and rt6_flags2srcprefs() translate
  38. * between IPV6_ADDR_PREFERENCES socket option values
  39. * IPV6_PREFER_SRC_TMP = 0x1
  40. * IPV6_PREFER_SRC_PUBLIC = 0x2
  41. * IPV6_PREFER_SRC_COA = 0x4
  42. * and above RT6_LOOKUP_F_SRCPREF_xxx flags.
  43. */
  44. static inline int rt6_srcprefs2flags(unsigned int srcprefs)
  45. {
  46. /* No need to bitmask because srcprefs have only 3 bits. */
  47. return srcprefs << 3;
  48. }
  49. static inline unsigned int rt6_flags2srcprefs(int flags)
  50. {
  51. return (flags >> 3) & 7;
  52. }
  53. extern void rt6_bind_peer(struct rt6_info *rt,
  54. int create);
  55. static inline struct inet_peer *rt6_get_peer(struct rt6_info *rt)
  56. {
  57. if (rt->rt6i_peer)
  58. return rt->rt6i_peer;
  59. rt6_bind_peer(rt, 0);
  60. return rt->rt6i_peer;
  61. }
  62. extern void ip6_route_input(struct sk_buff *skb);
  63. extern struct dst_entry * ip6_route_output(struct net *net,
  64. const struct sock *sk,
  65. struct flowi6 *fl6);
  66. extern struct dst_entry * ip6_route_lookup(struct net *net,
  67. struct flowi6 *fl6, int flags);
  68. extern int ip6_route_init(void);
  69. extern void ip6_route_cleanup(void);
  70. extern int ipv6_route_ioctl(struct net *net,
  71. unsigned int cmd,
  72. void __user *arg);
  73. extern int ip6_route_add(struct fib6_config *cfg);
  74. extern int ip6_ins_rt(struct rt6_info *);
  75. extern int ip6_del_rt(struct rt6_info *);
  76. extern int ip6_route_get_saddr(struct net *net,
  77. struct rt6_info *rt,
  78. const struct in6_addr *daddr,
  79. unsigned int prefs,
  80. struct in6_addr *saddr);
  81. extern struct rt6_info *rt6_lookup(struct net *net,
  82. const struct in6_addr *daddr,
  83. const struct in6_addr *saddr,
  84. int oif, int flags);
  85. extern struct dst_entry *icmp6_dst_alloc(struct net_device *dev,
  86. struct neighbour *neigh,
  87. struct flowi6 *fl6);
  88. extern int icmp6_dst_gc(void);
  89. extern void fib6_force_start_gc(struct net *net);
  90. extern struct rt6_info *addrconf_dst_alloc(struct inet6_dev *idev,
  91. const struct in6_addr *addr,
  92. bool anycast);
  93. extern int ip6_dst_hoplimit(struct dst_entry *dst);
  94. /*
  95. * support functions for ND
  96. *
  97. */
  98. extern struct rt6_info * rt6_get_dflt_router(const struct in6_addr *addr,
  99. struct net_device *dev);
  100. extern struct rt6_info * rt6_add_dflt_router(const struct in6_addr *gwaddr,
  101. struct net_device *dev,
  102. unsigned int pref);
  103. extern void rt6_purge_dflt_routers(struct net *net);
  104. extern int rt6_route_rcv(struct net_device *dev,
  105. u8 *opt, int len,
  106. const struct in6_addr *gwaddr);
  107. extern void rt6_redirect(const struct in6_addr *dest,
  108. const struct in6_addr *src,
  109. const struct in6_addr *saddr,
  110. struct neighbour *neigh,
  111. u8 *lladdr,
  112. int on_link);
  113. extern void ip6_update_pmtu(struct sk_buff *skb, struct net *net, __be32 mtu,
  114. int oif, u32 mark, kuid_t uid);
  115. extern void ip6_sk_update_pmtu(struct sk_buff *skb, struct sock *sk,
  116. __be32 mtu);
  117. struct netlink_callback;
  118. struct rt6_rtnl_dump_arg {
  119. struct sk_buff *skb;
  120. struct netlink_callback *cb;
  121. struct net *net;
  122. };
  123. extern int rt6_dump_route(struct rt6_info *rt, void *p_arg);
  124. extern void rt6_ifdown(struct net *net, struct net_device *dev);
  125. extern void rt6_mtu_change(struct net_device *dev, unsigned int mtu);
  126. extern void rt6_remove_prefsrc(struct inet6_ifaddr *ifp);
  127. /*
  128. * Store a destination cache entry in a socket
  129. */
  130. static inline void __ip6_dst_store(struct sock *sk, struct dst_entry *dst,
  131. struct in6_addr *daddr, struct in6_addr *saddr)
  132. {
  133. struct ipv6_pinfo *np = inet6_sk(sk);
  134. struct rt6_info *rt = (struct rt6_info *) dst;
  135. sk_setup_caps(sk, dst);
  136. np->daddr_cache = daddr;
  137. #ifdef CONFIG_IPV6_SUBTREES
  138. np->saddr_cache = saddr;
  139. #endif
  140. np->dst_cookie = rt->rt6i_node ? rt->rt6i_node->fn_sernum : 0;
  141. }
  142. static inline void ip6_dst_store(struct sock *sk, struct dst_entry *dst,
  143. struct in6_addr *daddr, struct in6_addr *saddr)
  144. {
  145. spin_lock(&sk->sk_dst_lock);
  146. __ip6_dst_store(sk, dst, daddr, saddr);
  147. spin_unlock(&sk->sk_dst_lock);
  148. }
  149. static inline int ipv6_unicast_destination(struct sk_buff *skb)
  150. {
  151. struct rt6_info *rt = (struct rt6_info *) skb_dst(skb);
  152. return rt->rt6i_flags & RTF_LOCAL;
  153. }
  154. int ip6_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *));
  155. static inline int ip6_skb_dst_mtu(struct sk_buff *skb)
  156. {
  157. struct ipv6_pinfo *np = skb->sk ? inet6_sk(skb->sk) : NULL;
  158. return (np && np->pmtudisc == IPV6_PMTUDISC_PROBE) ?
  159. skb_dst(skb)->dev->mtu : dst_mtu(skb_dst(skb));
  160. }
  161. #endif