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