Back to home page

OSCL-LXR

 
 

    


0001 /* IPv6-specific defines for netfilter. 
0002  * (C)1998 Rusty Russell -- This code is GPL.
0003  * (C)1999 David Jeffery
0004  *   this header was blatantly ripped from netfilter_ipv4.h
0005  *   it's amazing what adding a bunch of 6s can do =8^)
0006  */
0007 #ifndef __LINUX_IP6_NETFILTER_H
0008 #define __LINUX_IP6_NETFILTER_H
0009 
0010 #include <uapi/linux/netfilter_ipv6.h>
0011 #include <net/tcp.h>
0012 
0013 /* Check for an extension */
0014 static inline int
0015 nf_ip6_ext_hdr(u8 nexthdr)
0016 {   return (nexthdr == IPPROTO_HOPOPTS) ||
0017            (nexthdr == IPPROTO_ROUTING) ||
0018            (nexthdr == IPPROTO_FRAGMENT) ||
0019            (nexthdr == IPPROTO_ESP) ||
0020            (nexthdr == IPPROTO_AH) ||
0021            (nexthdr == IPPROTO_NONE) ||
0022            (nexthdr == IPPROTO_DSTOPTS);
0023 }
0024 
0025 /* Extra routing may needed on local out, as the QUEUE target never returns
0026  * control to the table.
0027  */
0028 struct ip6_rt_info {
0029     struct in6_addr daddr;
0030     struct in6_addr saddr;
0031     u_int32_t mark;
0032 };
0033 
0034 struct nf_queue_entry;
0035 struct nf_bridge_frag_data;
0036 
0037 /*
0038  * Hook functions for ipv6 to allow xt_* modules to be built-in even
0039  * if IPv6 is a module.
0040  */
0041 struct nf_ipv6_ops {
0042 #if IS_MODULE(CONFIG_IPV6)
0043     int (*chk_addr)(struct net *net, const struct in6_addr *addr,
0044             const struct net_device *dev, int strict);
0045     int (*route_me_harder)(struct net *net, struct sock *sk, struct sk_buff *skb);
0046     int (*dev_get_saddr)(struct net *net, const struct net_device *dev,
0047                const struct in6_addr *daddr, unsigned int srcprefs,
0048                struct in6_addr *saddr);
0049     int (*route)(struct net *net, struct dst_entry **dst, struct flowi *fl,
0050              bool strict);
0051     u32 (*cookie_init_sequence)(const struct ipv6hdr *iph,
0052                     const struct tcphdr *th, u16 *mssp);
0053     int (*cookie_v6_check)(const struct ipv6hdr *iph,
0054                    const struct tcphdr *th, __u32 cookie);
0055 #endif
0056     void (*route_input)(struct sk_buff *skb);
0057     int (*fragment)(struct net *net, struct sock *sk, struct sk_buff *skb,
0058             int (*output)(struct net *, struct sock *, struct sk_buff *));
0059     int (*reroute)(struct sk_buff *skb, const struct nf_queue_entry *entry);
0060 #if IS_MODULE(CONFIG_IPV6)
0061     int (*br_fragment)(struct net *net, struct sock *sk,
0062                struct sk_buff *skb,
0063                struct nf_bridge_frag_data *data,
0064                int (*output)(struct net *, struct sock *sk,
0065                      const struct nf_bridge_frag_data *data,
0066                      struct sk_buff *));
0067 #endif
0068 };
0069 
0070 #ifdef CONFIG_NETFILTER
0071 #include <net/addrconf.h>
0072 
0073 extern const struct nf_ipv6_ops __rcu *nf_ipv6_ops;
0074 static inline const struct nf_ipv6_ops *nf_get_ipv6_ops(void)
0075 {
0076     return rcu_dereference(nf_ipv6_ops);
0077 }
0078 
0079 static inline int nf_ipv6_chk_addr(struct net *net, const struct in6_addr *addr,
0080                    const struct net_device *dev, int strict)
0081 {
0082 #if IS_MODULE(CONFIG_IPV6)
0083     const struct nf_ipv6_ops *v6_ops = nf_get_ipv6_ops();
0084 
0085     if (!v6_ops)
0086         return 1;
0087 
0088     return v6_ops->chk_addr(net, addr, dev, strict);
0089 #elif IS_BUILTIN(CONFIG_IPV6)
0090     return ipv6_chk_addr(net, addr, dev, strict);
0091 #else
0092     return 1;
0093 #endif
0094 }
0095 
0096 int __nf_ip6_route(struct net *net, struct dst_entry **dst,
0097                    struct flowi *fl, bool strict);
0098 
0099 static inline int nf_ip6_route(struct net *net, struct dst_entry **dst,
0100                    struct flowi *fl, bool strict)
0101 {
0102 #if IS_MODULE(CONFIG_IPV6)
0103     const struct nf_ipv6_ops *v6ops = nf_get_ipv6_ops();
0104 
0105     if (v6ops)
0106         return v6ops->route(net, dst, fl, strict);
0107 
0108     return -EHOSTUNREACH;
0109 #endif
0110 #if IS_BUILTIN(CONFIG_IPV6)
0111     return __nf_ip6_route(net, dst, fl, strict);
0112 #else
0113     return -EHOSTUNREACH;
0114 #endif
0115 }
0116 
0117 #include <net/netfilter/ipv6/nf_defrag_ipv6.h>
0118 
0119 int br_ip6_fragment(struct net *net, struct sock *sk, struct sk_buff *skb,
0120             struct nf_bridge_frag_data *data,
0121             int (*output)(struct net *, struct sock *sk,
0122                   const struct nf_bridge_frag_data *data,
0123                   struct sk_buff *));
0124 
0125 static inline int nf_br_ip6_fragment(struct net *net, struct sock *sk,
0126                      struct sk_buff *skb,
0127                      struct nf_bridge_frag_data *data,
0128                      int (*output)(struct net *, struct sock *sk,
0129                            const struct nf_bridge_frag_data *data,
0130                            struct sk_buff *))
0131 {
0132 #if IS_MODULE(CONFIG_IPV6)
0133     const struct nf_ipv6_ops *v6_ops = nf_get_ipv6_ops();
0134 
0135     if (!v6_ops)
0136         return 1;
0137 
0138     return v6_ops->br_fragment(net, sk, skb, data, output);
0139 #elif IS_BUILTIN(CONFIG_IPV6)
0140     return br_ip6_fragment(net, sk, skb, data, output);
0141 #else
0142     return 1;
0143 #endif
0144 }
0145 
0146 int ip6_route_me_harder(struct net *net, struct sock *sk, struct sk_buff *skb);
0147 
0148 static inline int nf_ip6_route_me_harder(struct net *net, struct sock *sk, struct sk_buff *skb)
0149 {
0150 #if IS_MODULE(CONFIG_IPV6)
0151     const struct nf_ipv6_ops *v6_ops = nf_get_ipv6_ops();
0152 
0153     if (!v6_ops)
0154         return -EHOSTUNREACH;
0155 
0156     return v6_ops->route_me_harder(net, sk, skb);
0157 #elif IS_BUILTIN(CONFIG_IPV6)
0158     return ip6_route_me_harder(net, sk, skb);
0159 #else
0160     return -EHOSTUNREACH;
0161 #endif
0162 }
0163 
0164 static inline u32 nf_ipv6_cookie_init_sequence(const struct ipv6hdr *iph,
0165                            const struct tcphdr *th,
0166                            u16 *mssp)
0167 {
0168 #if IS_ENABLED(CONFIG_SYN_COOKIES)
0169 #if IS_MODULE(CONFIG_IPV6)
0170     const struct nf_ipv6_ops *v6_ops = nf_get_ipv6_ops();
0171 
0172     if (v6_ops)
0173         return v6_ops->cookie_init_sequence(iph, th, mssp);
0174 #elif IS_BUILTIN(CONFIG_IPV6)
0175     return __cookie_v6_init_sequence(iph, th, mssp);
0176 #endif
0177 #endif
0178     return 0;
0179 }
0180 
0181 static inline int nf_cookie_v6_check(const struct ipv6hdr *iph,
0182                      const struct tcphdr *th, __u32 cookie)
0183 {
0184 #if IS_ENABLED(CONFIG_SYN_COOKIES)
0185 #if IS_MODULE(CONFIG_IPV6)
0186     const struct nf_ipv6_ops *v6_ops = nf_get_ipv6_ops();
0187 
0188     if (v6_ops)
0189         return v6_ops->cookie_v6_check(iph, th, cookie);
0190 #elif IS_BUILTIN(CONFIG_IPV6)
0191     return __cookie_v6_check(iph, th, cookie);
0192 #endif
0193 #endif
0194     return 0;
0195 }
0196 
0197 __sum16 nf_ip6_checksum(struct sk_buff *skb, unsigned int hook,
0198             unsigned int dataoff, u_int8_t protocol);
0199 
0200 int ipv6_netfilter_init(void);
0201 void ipv6_netfilter_fini(void);
0202 
0203 #else /* CONFIG_NETFILTER */
0204 static inline int ipv6_netfilter_init(void) { return 0; }
0205 static inline void ipv6_netfilter_fini(void) { return; }
0206 static inline const struct nf_ipv6_ops *nf_get_ipv6_ops(void) { return NULL; }
0207 #endif /* CONFIG_NETFILTER */
0208 
0209 #endif /*__LINUX_IP6_NETFILTER_H*/