ip6_route.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. #define IP6_RT_PRIO_KERN 512
  6. struct route_info {
  7. __u8 type;
  8. __u8 length;
  9. __u8 prefix_len;
  10. #if defined(__BIG_ENDIAN_BITFIELD)
  11. __u8 reserved_h:3,
  12. route_pref:2,
  13. reserved_l:3;
  14. #elif defined(__LITTLE_ENDIAN_BITFIELD)
  15. __u8 reserved_l:3,
  16. route_pref:2,
  17. reserved_h:3;
  18. #endif
  19. __be32 lifetime;
  20. __u8 prefix[0]; /* 0,8 or 16 */
  21. };
  22. #ifdef __KERNEL__
  23. #include <net/flow.h>
  24. #include <net/ip6_fib.h>
  25. #include <net/sock.h>
  26. #include <linux/ip.h>
  27. #include <linux/ipv6.h>
  28. #define RT6_LOOKUP_F_IFACE 0x00000001
  29. #define RT6_LOOKUP_F_REACHABLE 0x00000002
  30. #define RT6_LOOKUP_F_HAS_SADDR 0x00000004
  31. #define RT6_LOOKUP_F_SRCPREF_TMP 0x00000008
  32. #define RT6_LOOKUP_F_SRCPREF_PUBLIC 0x00000010
  33. #define RT6_LOOKUP_F_SRCPREF_COA 0x00000020
  34. /*
  35. * rt6_srcprefs2flags() and rt6_flags2srcprefs() translate
  36. * between IPV6_ADDR_PREFERENCES socket option values
  37. * IPV6_PREFER_SRC_TMP = 0x1
  38. * IPV6_PREFER_SRC_PUBLIC = 0x2
  39. * IPV6_PREFER_SRC_COA = 0x4
  40. * and above RT6_LOOKUP_F_SRCPREF_xxx flags.
  41. */
  42. static inline int rt6_srcprefs2flags(unsigned int srcprefs)
  43. {
  44. /* No need to bitmask because srcprefs have only 3 bits. */
  45. return srcprefs << 3;
  46. }
  47. static inline unsigned int rt6_flags2srcprefs(int flags)
  48. {
  49. return (flags >> 3) & 7;
  50. }
  51. extern void ip6_route_input(struct sk_buff *skb);
  52. extern struct dst_entry * ip6_route_output(struct net *net,
  53. struct sock *sk,
  54. struct flowi *fl);
  55. extern int ip6_route_init(void);
  56. extern void ip6_route_cleanup(void);
  57. extern int ipv6_route_ioctl(struct net *net,
  58. unsigned int cmd,
  59. void __user *arg);
  60. extern int ip6_route_add(struct fib6_config *cfg);
  61. extern int ip6_ins_rt(struct rt6_info *);
  62. extern int ip6_del_rt(struct rt6_info *);
  63. extern struct rt6_info *rt6_lookup(struct net *net,
  64. const struct in6_addr *daddr,
  65. const struct in6_addr *saddr,
  66. int oif, int flags);
  67. extern struct dst_entry *icmp6_dst_alloc(struct net_device *dev,
  68. struct neighbour *neigh,
  69. const struct in6_addr *addr);
  70. extern int icmp6_dst_gc(void);
  71. extern void fib6_force_start_gc(struct net *net);
  72. extern struct rt6_info *addrconf_dst_alloc(struct inet6_dev *idev,
  73. const struct in6_addr *addr,
  74. int anycast);
  75. extern int ip6_dst_hoplimit(struct dst_entry *dst);
  76. /*
  77. * support functions for ND
  78. *
  79. */
  80. extern struct rt6_info * rt6_get_dflt_router(struct in6_addr *addr,
  81. struct net_device *dev);
  82. extern struct rt6_info * rt6_add_dflt_router(struct in6_addr *gwaddr,
  83. struct net_device *dev,
  84. unsigned int pref);
  85. extern void rt6_purge_dflt_routers(struct net *net);
  86. extern int rt6_route_rcv(struct net_device *dev,
  87. u8 *opt, int len,
  88. struct in6_addr *gwaddr);
  89. extern void rt6_redirect(struct in6_addr *dest,
  90. struct in6_addr *src,
  91. struct in6_addr *saddr,
  92. struct neighbour *neigh,
  93. u8 *lladdr,
  94. int on_link);
  95. extern void rt6_pmtu_discovery(struct in6_addr *daddr,
  96. struct in6_addr *saddr,
  97. struct net_device *dev,
  98. u32 pmtu);
  99. struct netlink_callback;
  100. struct rt6_rtnl_dump_arg {
  101. struct sk_buff *skb;
  102. struct netlink_callback *cb;
  103. struct net *net;
  104. };
  105. extern int rt6_dump_route(struct rt6_info *rt, void *p_arg);
  106. extern void rt6_ifdown(struct net *net, struct net_device *dev);
  107. extern void rt6_mtu_change(struct net_device *dev, unsigned mtu);
  108. /*
  109. * Store a destination cache entry in a socket
  110. */
  111. static inline void __ip6_dst_store(struct sock *sk, struct dst_entry *dst,
  112. struct in6_addr *daddr, struct in6_addr *saddr)
  113. {
  114. struct ipv6_pinfo *np = inet6_sk(sk);
  115. struct rt6_info *rt = (struct rt6_info *) dst;
  116. sk_setup_caps(sk, dst);
  117. np->daddr_cache = daddr;
  118. #ifdef CONFIG_IPV6_SUBTREES
  119. np->saddr_cache = saddr;
  120. #endif
  121. np->dst_cookie = rt->rt6i_node ? rt->rt6i_node->fn_sernum : 0;
  122. }
  123. static inline void ip6_dst_store(struct sock *sk, struct dst_entry *dst,
  124. struct in6_addr *daddr, struct in6_addr *saddr)
  125. {
  126. spin_lock(&sk->sk_dst_lock);
  127. __ip6_dst_store(sk, dst, daddr, saddr);
  128. spin_unlock(&sk->sk_dst_lock);
  129. }
  130. static inline int ipv6_unicast_destination(struct sk_buff *skb)
  131. {
  132. struct rt6_info *rt = (struct rt6_info *) skb_dst(skb);
  133. return rt->rt6i_flags & RTF_LOCAL;
  134. }
  135. #endif
  136. #endif