netfilter_ipv6.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /* IPv6-specific defines for netfilter.
  2. * (C)1998 Rusty Russell -- This code is GPL.
  3. * (C)1999 David Jeffery
  4. * this header was blatantly ripped from netfilter_ipv4.h
  5. * it's amazing what adding a bunch of 6s can do =8^)
  6. */
  7. #ifndef __LINUX_IP6_NETFILTER_H
  8. #define __LINUX_IP6_NETFILTER_H
  9. #include <uapi/linux/netfilter_ipv6.h>
  10. #include <net/tcp.h>
  11. /* Check for an extension */
  12. static inline int
  13. nf_ip6_ext_hdr(u8 nexthdr)
  14. { return (nexthdr == IPPROTO_HOPOPTS) ||
  15. (nexthdr == IPPROTO_ROUTING) ||
  16. (nexthdr == IPPROTO_FRAGMENT) ||
  17. (nexthdr == IPPROTO_ESP) ||
  18. (nexthdr == IPPROTO_AH) ||
  19. (nexthdr == IPPROTO_NONE) ||
  20. (nexthdr == IPPROTO_DSTOPTS);
  21. }
  22. /* Extra routing may needed on local out, as the QUEUE target never returns
  23. * control to the table.
  24. */
  25. struct ip6_rt_info {
  26. struct in6_addr daddr;
  27. struct in6_addr saddr;
  28. u_int32_t mark;
  29. };
  30. struct nf_queue_entry;
  31. struct nf_bridge_frag_data;
  32. /*
  33. * Hook functions for ipv6 to allow xt_* modules to be built-in even
  34. * if IPv6 is a module.
  35. */
  36. struct nf_ipv6_ops {
  37. #if IS_MODULE(CONFIG_IPV6)
  38. int (*chk_addr)(struct net *net, const struct in6_addr *addr,
  39. const struct net_device *dev, int strict);
  40. int (*route_me_harder)(struct net *net, struct sock *sk, struct sk_buff *skb);
  41. int (*dev_get_saddr)(struct net *net, const struct net_device *dev,
  42. const struct in6_addr *daddr, unsigned int srcprefs,
  43. struct in6_addr *saddr);
  44. int (*route)(struct net *net, struct dst_entry **dst, struct flowi *fl,
  45. bool strict);
  46. u32 (*cookie_init_sequence)(const struct ipv6hdr *iph,
  47. const struct tcphdr *th, u16 *mssp);
  48. int (*cookie_v6_check)(const struct ipv6hdr *iph,
  49. const struct tcphdr *th, __u32 cookie);
  50. #endif
  51. void (*route_input)(struct sk_buff *skb);
  52. int (*fragment)(struct net *net, struct sock *sk, struct sk_buff *skb,
  53. int (*output)(struct net *, struct sock *, struct sk_buff *));
  54. int (*reroute)(struct sk_buff *skb, const struct nf_queue_entry *entry);
  55. #if IS_MODULE(CONFIG_IPV6)
  56. int (*br_fragment)(struct net *net, struct sock *sk,
  57. struct sk_buff *skb,
  58. struct nf_bridge_frag_data *data,
  59. int (*output)(struct net *, struct sock *sk,
  60. const struct nf_bridge_frag_data *data,
  61. struct sk_buff *));
  62. #endif
  63. };
  64. #ifdef CONFIG_NETFILTER
  65. #include <net/addrconf.h>
  66. extern const struct nf_ipv6_ops __rcu *nf_ipv6_ops;
  67. static inline const struct nf_ipv6_ops *nf_get_ipv6_ops(void)
  68. {
  69. return rcu_dereference(nf_ipv6_ops);
  70. }
  71. static inline int nf_ipv6_chk_addr(struct net *net, const struct in6_addr *addr,
  72. const struct net_device *dev, int strict)
  73. {
  74. #if IS_MODULE(CONFIG_IPV6)
  75. const struct nf_ipv6_ops *v6_ops = nf_get_ipv6_ops();
  76. if (!v6_ops)
  77. return 1;
  78. return v6_ops->chk_addr(net, addr, dev, strict);
  79. #elif IS_BUILTIN(CONFIG_IPV6)
  80. return ipv6_chk_addr(net, addr, dev, strict);
  81. #else
  82. return 1;
  83. #endif
  84. }
  85. int __nf_ip6_route(struct net *net, struct dst_entry **dst,
  86. struct flowi *fl, bool strict);
  87. static inline int nf_ip6_route(struct net *net, struct dst_entry **dst,
  88. struct flowi *fl, bool strict)
  89. {
  90. #if IS_MODULE(CONFIG_IPV6)
  91. const struct nf_ipv6_ops *v6ops = nf_get_ipv6_ops();
  92. if (v6ops)
  93. return v6ops->route(net, dst, fl, strict);
  94. return -EHOSTUNREACH;
  95. #endif
  96. #if IS_BUILTIN(CONFIG_IPV6)
  97. return __nf_ip6_route(net, dst, fl, strict);
  98. #else
  99. return -EHOSTUNREACH;
  100. #endif
  101. }
  102. #include <net/netfilter/ipv6/nf_defrag_ipv6.h>
  103. int br_ip6_fragment(struct net *net, struct sock *sk, struct sk_buff *skb,
  104. struct nf_bridge_frag_data *data,
  105. int (*output)(struct net *, struct sock *sk,
  106. const struct nf_bridge_frag_data *data,
  107. struct sk_buff *));
  108. static inline int nf_br_ip6_fragment(struct net *net, struct sock *sk,
  109. struct sk_buff *skb,
  110. struct nf_bridge_frag_data *data,
  111. int (*output)(struct net *, struct sock *sk,
  112. const struct nf_bridge_frag_data *data,
  113. struct sk_buff *))
  114. {
  115. #if IS_MODULE(CONFIG_IPV6)
  116. const struct nf_ipv6_ops *v6_ops = nf_get_ipv6_ops();
  117. if (!v6_ops)
  118. return 1;
  119. return v6_ops->br_fragment(net, sk, skb, data, output);
  120. #elif IS_BUILTIN(CONFIG_IPV6)
  121. return br_ip6_fragment(net, sk, skb, data, output);
  122. #else
  123. return 1;
  124. #endif
  125. }
  126. int ip6_route_me_harder(struct net *net, struct sock *sk, struct sk_buff *skb);
  127. static inline int nf_ip6_route_me_harder(struct net *net, struct sock *sk, struct sk_buff *skb)
  128. {
  129. #if IS_MODULE(CONFIG_IPV6)
  130. const struct nf_ipv6_ops *v6_ops = nf_get_ipv6_ops();
  131. if (!v6_ops)
  132. return -EHOSTUNREACH;
  133. return v6_ops->route_me_harder(net, sk, skb);
  134. #elif IS_BUILTIN(CONFIG_IPV6)
  135. return ip6_route_me_harder(net, sk, skb);
  136. #else
  137. return -EHOSTUNREACH;
  138. #endif
  139. }
  140. static inline u32 nf_ipv6_cookie_init_sequence(const struct ipv6hdr *iph,
  141. const struct tcphdr *th,
  142. u16 *mssp)
  143. {
  144. #if IS_ENABLED(CONFIG_SYN_COOKIES)
  145. #if IS_MODULE(CONFIG_IPV6)
  146. const struct nf_ipv6_ops *v6_ops = nf_get_ipv6_ops();
  147. if (v6_ops)
  148. return v6_ops->cookie_init_sequence(iph, th, mssp);
  149. #elif IS_BUILTIN(CONFIG_IPV6)
  150. return __cookie_v6_init_sequence(iph, th, mssp);
  151. #endif
  152. #endif
  153. return 0;
  154. }
  155. static inline int nf_cookie_v6_check(const struct ipv6hdr *iph,
  156. const struct tcphdr *th, __u32 cookie)
  157. {
  158. #if IS_ENABLED(CONFIG_SYN_COOKIES)
  159. #if IS_MODULE(CONFIG_IPV6)
  160. const struct nf_ipv6_ops *v6_ops = nf_get_ipv6_ops();
  161. if (v6_ops)
  162. return v6_ops->cookie_v6_check(iph, th, cookie);
  163. #elif IS_BUILTIN(CONFIG_IPV6)
  164. return __cookie_v6_check(iph, th, cookie);
  165. #endif
  166. #endif
  167. return 0;
  168. }
  169. __sum16 nf_ip6_checksum(struct sk_buff *skb, unsigned int hook,
  170. unsigned int dataoff, u_int8_t protocol);
  171. int ipv6_netfilter_init(void);
  172. void ipv6_netfilter_fini(void);
  173. #else /* CONFIG_NETFILTER */
  174. static inline int ipv6_netfilter_init(void) { return 0; }
  175. static inline void ipv6_netfilter_fini(void) { return; }
  176. static inline const struct nf_ipv6_ops *nf_get_ipv6_ops(void) { return NULL; }
  177. #endif /* CONFIG_NETFILTER */
  178. #endif /*__LINUX_IP6_NETFILTER_H*/