ip6_route.h 5.5 KB

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