ip6_route.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. /*
  33. * rt6_srcprefs2flags() and rt6_flags2srcprefs() translate
  34. * between IPV6_ADDR_PREFERENCES socket option values
  35. * IPV6_PREFER_SRC_TMP = 0x1
  36. * IPV6_PREFER_SRC_PUBLIC = 0x2
  37. * IPV6_PREFER_SRC_COA = 0x4
  38. * and above RT6_LOOKUP_F_SRCPREF_xxx flags.
  39. */
  40. static inline int rt6_srcprefs2flags(unsigned int srcprefs)
  41. {
  42. /* No need to bitmask because srcprefs have only 3 bits. */
  43. return srcprefs << 3;
  44. }
  45. static inline unsigned int rt6_flags2srcprefs(int flags)
  46. {
  47. return (flags >> 3) & 7;
  48. }
  49. extern void rt6_bind_peer(struct rt6_info *rt, int create);
  50. static inline struct inet_peer *__rt6_get_peer(struct rt6_info *rt, int create)
  51. {
  52. if (rt6_has_peer(rt))
  53. return rt6_peer_ptr(rt);
  54. rt6_bind_peer(rt, create);
  55. return (rt6_has_peer(rt) ? rt6_peer_ptr(rt) : NULL);
  56. }
  57. static inline struct inet_peer *rt6_get_peer(struct rt6_info *rt)
  58. {
  59. return __rt6_get_peer(rt, 0);
  60. }
  61. static inline struct inet_peer *rt6_get_peer_create(struct rt6_info *rt)
  62. {
  63. return __rt6_get_peer(rt, 1);
  64. }
  65. extern void ip6_route_input(struct sk_buff *skb);
  66. extern struct dst_entry * ip6_route_output(struct net *net,
  67. const struct sock *sk,
  68. struct flowi6 *fl6);
  69. extern struct dst_entry * ip6_route_lookup(struct net *net,
  70. struct flowi6 *fl6, int flags);
  71. extern int ip6_route_init(void);
  72. extern void ip6_route_cleanup(void);
  73. extern int ipv6_route_ioctl(struct net *net,
  74. unsigned int cmd,
  75. void __user *arg);
  76. extern int ip6_route_add(struct fib6_config *cfg);
  77. extern int ip6_ins_rt(struct rt6_info *);
  78. extern int ip6_del_rt(struct rt6_info *);
  79. extern int ip6_route_get_saddr(struct net *net,
  80. struct rt6_info *rt,
  81. const struct in6_addr *daddr,
  82. unsigned int prefs,
  83. struct in6_addr *saddr);
  84. extern struct rt6_info *rt6_lookup(struct net *net,
  85. const struct in6_addr *daddr,
  86. const struct in6_addr *saddr,
  87. int oif, int flags);
  88. extern struct dst_entry *icmp6_dst_alloc(struct net_device *dev,
  89. struct neighbour *neigh,
  90. struct flowi6 *fl6);
  91. extern int icmp6_dst_gc(void);
  92. extern void fib6_force_start_gc(struct net *net);
  93. extern struct rt6_info *addrconf_dst_alloc(struct inet6_dev *idev,
  94. const struct in6_addr *addr,
  95. bool anycast);
  96. extern int ip6_dst_hoplimit(struct dst_entry *dst);
  97. /*
  98. * support functions for ND
  99. *
  100. */
  101. extern struct rt6_info * rt6_get_dflt_router(const struct in6_addr *addr,
  102. struct net_device *dev);
  103. extern struct rt6_info * rt6_add_dflt_router(const struct in6_addr *gwaddr,
  104. struct net_device *dev,
  105. unsigned int pref);
  106. extern void rt6_purge_dflt_routers(struct net *net);
  107. extern int rt6_route_rcv(struct net_device *dev,
  108. u8 *opt, int len,
  109. const struct in6_addr *gwaddr);
  110. extern void ip6_update_pmtu(struct sk_buff *skb, struct net *net, __be32 mtu,
  111. int oif, u32 mark);
  112. extern void ip6_sk_update_pmtu(struct sk_buff *skb, struct sock *sk,
  113. __be32 mtu);
  114. extern void ip6_redirect(struct sk_buff *skb, struct net *net, int oif, u32 mark);
  115. extern void ip6_sk_redirect(struct sk_buff *skb, struct sock *sk);
  116. struct netlink_callback;
  117. struct rt6_rtnl_dump_arg {
  118. struct sk_buff *skb;
  119. struct netlink_callback *cb;
  120. struct net *net;
  121. };
  122. extern int rt6_dump_route(struct rt6_info *rt, void *p_arg);
  123. extern void rt6_ifdown(struct net *net, struct net_device *dev);
  124. extern void rt6_mtu_change(struct net_device *dev, unsigned int mtu);
  125. extern void rt6_remove_prefsrc(struct inet6_ifaddr *ifp);
  126. /*
  127. * Store a destination cache entry in a socket
  128. */
  129. static inline void __ip6_dst_store(struct sock *sk, struct dst_entry *dst,
  130. const struct in6_addr *daddr,
  131. const 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 bool ipv6_unicast_destination(const 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