]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - net/netfilter/xt_TPROXY.c
Merge tag 'asoc-fix-v4.13-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/broon...
[mirror_ubuntu-artful-kernel.git] / net / netfilter / xt_TPROXY.c
CommitLineData
e8439270
KK
1/*
2 * Transparent proxy support for Linux/iptables
3 *
6ad78893 4 * Copyright (c) 2006-2010 BalaBit IT Ltd.
e8439270
KK
5 * Author: Balazs Scheidler, Krisztian Kovacs
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 */
ff67e4e4 12#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
e8439270
KK
13#include <linux/module.h>
14#include <linux/skbuff.h>
15#include <linux/ip.h>
16#include <net/checksum.h>
17#include <net/udp.h>
93742cf8 18#include <net/tcp.h>
e8439270 19#include <net/inet_sock.h>
93742cf8 20#include <net/inet_hashtables.h>
cc6eb433 21#include <linux/inetdevice.h>
e8439270
KK
22#include <linux/netfilter/x_tables.h>
23#include <linux/netfilter_ipv4/ip_tables.h>
e8439270
KK
24
25#include <net/netfilter/ipv4/nf_defrag_ipv4.h>
f6318e55 26
c0cd1156 27#if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
f6318e55 28#define XT_TPROXY_HAVE_IPV6 1
cc6eb433
BS
29#include <net/if_inet6.h>
30#include <net/addrconf.h>
93742cf8 31#include <net/inet6_hashtables.h>
cc6eb433 32#include <linux/netfilter_ipv6/ip6_tables.h>
6ad78893 33#include <net/netfilter/ipv6/nf_defrag_ipv6.h>
cc6eb433
BS
34#endif
35
cc6eb433
BS
36#include <linux/netfilter/xt_TPROXY.h>
37
93742cf8
FW
38enum nf_tproxy_lookup_t {
39 NFT_LOOKUP_LISTENER,
40 NFT_LOOKUP_ESTABLISHED,
41};
42
d503b30b
FW
43static bool tproxy_sk_is_transparent(struct sock *sk)
44{
8b580147
ED
45 switch (sk->sk_state) {
46 case TCP_TIME_WAIT:
d503b30b
FW
47 if (inet_twsk(sk)->tw_transparent)
48 return true;
8b580147
ED
49 break;
50 case TCP_NEW_SYN_RECV:
51 if (inet_rsk(inet_reqsk(sk))->no_srccheck)
52 return true;
53 break;
54 default:
55 if (inet_sk(sk)->transparent)
56 return true;
d503b30b 57 }
8b580147
ED
58
59 sock_gen_put(sk);
d503b30b
FW
60 return false;
61}
62
cc6eb433
BS
63static inline __be32
64tproxy_laddr4(struct sk_buff *skb, __be32 user_laddr, __be32 daddr)
65{
66 struct in_device *indev;
67 __be32 laddr;
68
69 if (user_laddr)
70 return user_laddr;
71
72 laddr = 0;
73 rcu_read_lock();
74 indev = __in_dev_get_rcu(skb->dev);
75 for_primary_ifa(indev) {
76 laddr = ifa->ifa_local;
77 break;
78 } endfor_ifa(indev);
79 rcu_read_unlock();
80
81 return laddr ? laddr : daddr;
82}
e8439270 83
93742cf8
FW
84/*
85 * This is used when the user wants to intercept a connection matching
86 * an explicit iptables rule. In this case the sockets are assumed
87 * matching in preference order:
88 *
89 * - match: if there's a fully established connection matching the
90 * _packet_ tuple, it is returned, assuming the redirection
91 * already took place and we process a packet belonging to an
92 * established connection
93 *
94 * - match: if there's a listening socket matching the redirection
95 * (e.g. on-port & on-ip of the connection), it is returned,
96 * regardless if it was bound to 0.0.0.0 or an explicit
97 * address. The reasoning is that if there's an explicit rule, it
98 * does not really matter if the listener is bound to an interface
99 * or to 0. The user already stated that he wants redirection
100 * (since he added the rule).
101 *
102 * Please note that there's an overlap between what a TPROXY target
103 * and a socket match will match. Normally if you have both rules the
104 * "socket" match will be the first one, effectively all packets
105 * belonging to established connections going through that one.
106 */
107static inline struct sock *
a583636a
CG
108nf_tproxy_get_sock_v4(struct net *net, struct sk_buff *skb, void *hp,
109 const u8 protocol,
93742cf8
FW
110 const __be32 saddr, const __be32 daddr,
111 const __be16 sport, const __be16 dport,
112 const struct net_device *in,
113 const enum nf_tproxy_lookup_t lookup_type)
114{
115 struct sock *sk;
a583636a 116 struct tcphdr *tcph;
93742cf8
FW
117
118 switch (protocol) {
119 case IPPROTO_TCP:
120 switch (lookup_type) {
121 case NFT_LOOKUP_LISTENER:
a583636a
CG
122 tcph = hp;
123 sk = inet_lookup_listener(net, &tcp_hashinfo, skb,
124 ip_hdrlen(skb) +
125 __tcp_hdrlen(tcph),
93742cf8
FW
126 saddr, sport,
127 daddr, dport,
128 in->ifindex);
129
41c6d650 130 if (sk && !refcount_inc_not_zero(&sk->sk_refcnt))
dcbe3590 131 sk = NULL;
93742cf8
FW
132 /* NOTE: we return listeners even if bound to
133 * 0.0.0.0, those are filtered out in
134 * xt_socket, since xt_TPROXY needs 0 bound
135 * listeners too
136 */
137 break;
138 case NFT_LOOKUP_ESTABLISHED:
139 sk = inet_lookup_established(net, &tcp_hashinfo,
140 saddr, sport, daddr, dport,
141 in->ifindex);
142 break;
143 default:
144 BUG();
145 }
146 break;
147 case IPPROTO_UDP:
148 sk = udp4_lib_lookup(net, saddr, sport, daddr, dport,
149 in->ifindex);
150 if (sk) {
151 int connected = (sk->sk_state == TCP_ESTABLISHED);
152 int wildcard = (inet_sk(sk)->inet_rcv_saddr == 0);
153
154 /* NOTE: we return listeners even if bound to
155 * 0.0.0.0, those are filtered out in
156 * xt_socket, since xt_TPROXY needs 0 bound
157 * listeners too
158 */
159 if ((lookup_type == NFT_LOOKUP_ESTABLISHED && (!connected || wildcard)) ||
160 (lookup_type == NFT_LOOKUP_LISTENER && connected)) {
161 sock_put(sk);
162 sk = NULL;
163 }
164 }
165 break;
166 default:
167 WARN_ON(1);
168 sk = NULL;
169 }
170
171 pr_debug("tproxy socket lookup: proto %u %08x:%u -> %08x:%u, lookup type: %d, sock %p\n",
172 protocol, ntohl(saddr), ntohs(sport), ntohl(daddr), ntohs(dport), lookup_type, sk);
173
174 return sk;
175}
176
d8b3bfc2 177#ifdef XT_TPROXY_HAVE_IPV6
93742cf8 178static inline struct sock *
a583636a
CG
179nf_tproxy_get_sock_v6(struct net *net, struct sk_buff *skb, int thoff, void *hp,
180 const u8 protocol,
93742cf8
FW
181 const struct in6_addr *saddr, const struct in6_addr *daddr,
182 const __be16 sport, const __be16 dport,
183 const struct net_device *in,
184 const enum nf_tproxy_lookup_t lookup_type)
185{
186 struct sock *sk;
a583636a 187 struct tcphdr *tcph;
93742cf8
FW
188
189 switch (protocol) {
190 case IPPROTO_TCP:
191 switch (lookup_type) {
192 case NFT_LOOKUP_LISTENER:
a583636a
CG
193 tcph = hp;
194 sk = inet6_lookup_listener(net, &tcp_hashinfo, skb,
195 thoff + __tcp_hdrlen(tcph),
93742cf8
FW
196 saddr, sport,
197 daddr, ntohs(dport),
198 in->ifindex);
199
41c6d650 200 if (sk && !refcount_inc_not_zero(&sk->sk_refcnt))
dcbe3590 201 sk = NULL;
93742cf8
FW
202 /* NOTE: we return listeners even if bound to
203 * 0.0.0.0, those are filtered out in
204 * xt_socket, since xt_TPROXY needs 0 bound
205 * listeners too
206 */
207 break;
208 case NFT_LOOKUP_ESTABLISHED:
209 sk = __inet6_lookup_established(net, &tcp_hashinfo,
210 saddr, sport, daddr, ntohs(dport),
211 in->ifindex);
212 break;
213 default:
214 BUG();
215 }
216 break;
217 case IPPROTO_UDP:
218 sk = udp6_lib_lookup(net, saddr, sport, daddr, dport,
219 in->ifindex);
220 if (sk) {
221 int connected = (sk->sk_state == TCP_ESTABLISHED);
efe4208f 222 int wildcard = ipv6_addr_any(&sk->sk_v6_rcv_saddr);
93742cf8
FW
223
224 /* NOTE: we return listeners even if bound to
225 * 0.0.0.0, those are filtered out in
226 * xt_socket, since xt_TPROXY needs 0 bound
227 * listeners too
228 */
229 if ((lookup_type == NFT_LOOKUP_ESTABLISHED && (!connected || wildcard)) ||
230 (lookup_type == NFT_LOOKUP_LISTENER && connected)) {
231 sock_put(sk);
232 sk = NULL;
233 }
234 }
235 break;
236 default:
237 WARN_ON(1);
238 sk = NULL;
239 }
240
241 pr_debug("tproxy socket lookup: proto %u %pI6:%u -> %pI6:%u, lookup type: %d, sock %p\n",
242 protocol, saddr, ntohs(sport), daddr, ntohs(dport), lookup_type, sk);
243
244 return sk;
245}
246#endif
247
106e4c26 248/**
2c53040f 249 * tproxy_handle_time_wait4 - handle IPv4 TCP TIME_WAIT reopen redirections
106e4c26 250 * @skb: The skb being processed.
6ad78893
BS
251 * @laddr: IPv4 address to redirect to or zero.
252 * @lport: TCP port to redirect to or zero.
106e4c26
BS
253 * @sk: The TIME_WAIT TCP socket found by the lookup.
254 *
255 * We have to handle SYN packets arriving to TIME_WAIT sockets
256 * differently: instead of reopening the connection we should rather
257 * redirect the new connection to the proxy if there's a listener
258 * socket present.
259 *
6ad78893 260 * tproxy_handle_time_wait4() consumes the socket reference passed in.
106e4c26
BS
261 *
262 * Returns the listener socket if there's one, the TIME_WAIT socket if
263 * no such listener is found, or NULL if the TCP header is incomplete.
264 */
265static struct sock *
686c9b50
EB
266tproxy_handle_time_wait4(struct net *net, struct sk_buff *skb,
267 __be32 laddr, __be16 lport, struct sock *sk)
106e4c26
BS
268{
269 const struct iphdr *iph = ip_hdr(skb);
106e4c26
BS
270 struct tcphdr _hdr, *hp;
271
272 hp = skb_header_pointer(skb, ip_hdrlen(skb), sizeof(_hdr), &_hdr);
273 if (hp == NULL) {
274 inet_twsk_put(inet_twsk(sk));
275 return NULL;
276 }
277
278 if (hp->syn && !hp->rst && !hp->ack && !hp->fin) {
279 /* SYN to a TIME_WAIT socket, we'd rather redirect it
280 * to a listener socket if there's one */
281 struct sock *sk2;
282
a583636a 283 sk2 = nf_tproxy_get_sock_v4(net, skb, hp, iph->protocol,
6ad78893
BS
284 iph->saddr, laddr ? laddr : iph->daddr,
285 hp->source, lport ? lport : hp->dest,
286 skb->dev, NFT_LOOKUP_LISTENER);
287 if (sk2) {
dbe7faa4 288 inet_twsk_deschedule_put(inet_twsk(sk));
6ad78893
BS
289 sk = sk2;
290 }
291 }
292
293 return sk;
294}
295
fd158d79
FW
296/* assign a socket to the skb -- consumes sk */
297static void
298nf_tproxy_assign_sock(struct sk_buff *skb, struct sock *sk)
299{
300 skb_orphan(skb);
301 skb->sk = sk;
302 skb->destructor = sock_edemux;
303}
304
e8439270 305static unsigned int
686c9b50 306tproxy_tg4(struct net *net, struct sk_buff *skb, __be32 laddr, __be16 lport,
6ad78893 307 u_int32_t mark_mask, u_int32_t mark_value)
e8439270
KK
308{
309 const struct iphdr *iph = ip_hdr(skb);
e8439270
KK
310 struct udphdr _hdr, *hp;
311 struct sock *sk;
312
313 hp = skb_header_pointer(skb, ip_hdrlen(skb), sizeof(_hdr), &_hdr);
314 if (hp == NULL)
315 return NF_DROP;
316
6ad78893
BS
317 /* check if there's an ongoing connection on the packet
318 * addresses, this happens if the redirect already happened
319 * and the current packet belongs to an already established
320 * connection */
a583636a 321 sk = nf_tproxy_get_sock_v4(net, skb, hp, iph->protocol,
106e4c26
BS
322 iph->saddr, iph->daddr,
323 hp->source, hp->dest,
6ad78893 324 skb->dev, NFT_LOOKUP_ESTABLISHED);
106e4c26 325
cc6eb433
BS
326 laddr = tproxy_laddr4(skb, laddr, iph->daddr);
327 if (!lport)
328 lport = hp->dest;
329
106e4c26
BS
330 /* UDP has no TCP_TIME_WAIT state, so we never enter here */
331 if (sk && sk->sk_state == TCP_TIME_WAIT)
6ad78893 332 /* reopening a TIME_WAIT connection needs special handling */
686c9b50 333 sk = tproxy_handle_time_wait4(net, skb, laddr, lport, sk);
106e4c26 334 else if (!sk)
6ad78893
BS
335 /* no, there's no established connection, check if
336 * there's a listener on the redirected addr/port */
a583636a 337 sk = nf_tproxy_get_sock_v4(net, skb, hp, iph->protocol,
cc6eb433
BS
338 iph->saddr, laddr,
339 hp->source, lport,
6ad78893
BS
340 skb->dev, NFT_LOOKUP_LISTENER);
341
342 /* NOTE: assign_sock consumes our sk reference */
d503b30b 343 if (sk && tproxy_sk_is_transparent(sk)) {
6ad78893
BS
344 /* This should be in a separate target, but we don't do multiple
345 targets on the same rule yet */
346 skb->mark = (skb->mark & ~mark_mask) ^ mark_value;
347
348 pr_debug("redirecting: proto %hhu %pI4:%hu -> %pI4:%hu, mark: %x\n",
349 iph->protocol, &iph->daddr, ntohs(hp->dest),
350 &laddr, ntohs(lport), skb->mark);
d503b30b
FW
351
352 nf_tproxy_assign_sock(skb, sk);
6ad78893
BS
353 return NF_ACCEPT;
354 }
355
cc6eb433
BS
356 pr_debug("no socket, dropping: proto %hhu %pI4:%hu -> %pI4:%hu, mark: %x\n",
357 iph->protocol, &iph->saddr, ntohs(hp->source),
358 &iph->daddr, ntohs(hp->dest), skb->mark);
6ad78893
BS
359 return NF_DROP;
360}
361
362static unsigned int
363tproxy_tg4_v0(struct sk_buff *skb, const struct xt_action_param *par)
364{
365 const struct xt_tproxy_target_info *tgi = par->targinfo;
366
613dbd95
PNA
367 return tproxy_tg4(xt_net(par), skb, tgi->laddr, tgi->lport,
368 tgi->mark_mask, tgi->mark_value);
6ad78893
BS
369}
370
371static unsigned int
372tproxy_tg4_v1(struct sk_buff *skb, const struct xt_action_param *par)
373{
374 const struct xt_tproxy_target_info_v1 *tgi = par->targinfo;
375
613dbd95
PNA
376 return tproxy_tg4(xt_net(par), skb, tgi->laddr.ip, tgi->lport,
377 tgi->mark_mask, tgi->mark_value);
6ad78893
BS
378}
379
f6318e55 380#ifdef XT_TPROXY_HAVE_IPV6
cc6eb433
BS
381
382static inline const struct in6_addr *
383tproxy_laddr6(struct sk_buff *skb, const struct in6_addr *user_laddr,
384 const struct in6_addr *daddr)
385{
386 struct inet6_dev *indev;
387 struct inet6_ifaddr *ifa;
388 struct in6_addr *laddr;
389
390 if (!ipv6_addr_any(user_laddr))
391 return user_laddr;
392 laddr = NULL;
393
394 rcu_read_lock();
395 indev = __in6_dev_get(skb->dev);
0c7930e5
LZ
396 if (indev) {
397 read_lock_bh(&indev->lock);
cc6eb433
BS
398 list_for_each_entry(ifa, &indev->addr_list, if_list) {
399 if (ifa->flags & (IFA_F_TENTATIVE | IFA_F_DEPRECATED))
400 continue;
401
402 laddr = &ifa->addr;
403 break;
404 }
0c7930e5
LZ
405 read_unlock_bh(&indev->lock);
406 }
cc6eb433
BS
407 rcu_read_unlock();
408
409 return laddr ? laddr : daddr;
410}
411
412/**
2c53040f 413 * tproxy_handle_time_wait6 - handle IPv6 TCP TIME_WAIT reopen redirections
cc6eb433
BS
414 * @skb: The skb being processed.
415 * @tproto: Transport protocol.
416 * @thoff: Transport protocol header offset.
417 * @par: Iptables target parameters.
418 * @sk: The TIME_WAIT TCP socket found by the lookup.
419 *
420 * We have to handle SYN packets arriving to TIME_WAIT sockets
421 * differently: instead of reopening the connection we should rather
422 * redirect the new connection to the proxy if there's a listener
423 * socket present.
424 *
425 * tproxy_handle_time_wait6() consumes the socket reference passed in.
426 *
427 * Returns the listener socket if there's one, the TIME_WAIT socket if
428 * no such listener is found, or NULL if the TCP header is incomplete.
429 */
430static struct sock *
431tproxy_handle_time_wait6(struct sk_buff *skb, int tproto, int thoff,
432 const struct xt_action_param *par,
433 struct sock *sk)
434{
435 const struct ipv6hdr *iph = ipv6_hdr(skb);
436 struct tcphdr _hdr, *hp;
437 const struct xt_tproxy_target_info_v1 *tgi = par->targinfo;
438
439 hp = skb_header_pointer(skb, thoff, sizeof(_hdr), &_hdr);
440 if (hp == NULL) {
441 inet_twsk_put(inet_twsk(sk));
442 return NULL;
443 }
444
445 if (hp->syn && !hp->rst && !hp->ack && !hp->fin) {
446 /* SYN to a TIME_WAIT socket, we'd rather redirect it
447 * to a listener socket if there's one */
448 struct sock *sk2;
449
613dbd95 450 sk2 = nf_tproxy_get_sock_v6(xt_net(par), skb, thoff, hp, tproto,
cc6eb433
BS
451 &iph->saddr,
452 tproxy_laddr6(skb, &tgi->laddr.in6, &iph->daddr),
453 hp->source,
454 tgi->lport ? tgi->lport : hp->dest,
455 skb->dev, NFT_LOOKUP_LISTENER);
456 if (sk2) {
dbe7faa4 457 inet_twsk_deschedule_put(inet_twsk(sk));
cc6eb433
BS
458 sk = sk2;
459 }
460 }
461
462 return sk;
463}
464
6ad78893
BS
465static unsigned int
466tproxy_tg6_v1(struct sk_buff *skb, const struct xt_action_param *par)
467{
468 const struct ipv6hdr *iph = ipv6_hdr(skb);
469 const struct xt_tproxy_target_info_v1 *tgi = par->targinfo;
470 struct udphdr _hdr, *hp;
471 struct sock *sk;
cc6eb433
BS
472 const struct in6_addr *laddr;
473 __be16 lport;
84018f55 474 int thoff = 0;
6ad78893
BS
475 int tproto;
476
84018f55 477 tproto = ipv6_find_hdr(skb, &thoff, -1, NULL, NULL);
6ad78893
BS
478 if (tproto < 0) {
479 pr_debug("unable to find transport header in IPv6 packet, dropping\n");
480 return NF_DROP;
481 }
482
483 hp = skb_header_pointer(skb, thoff, sizeof(_hdr), &_hdr);
484 if (hp == NULL) {
485 pr_debug("unable to grab transport header contents in IPv6 packet, dropping\n");
486 return NF_DROP;
487 }
488
489 /* check if there's an ongoing connection on the packet
490 * addresses, this happens if the redirect already happened
491 * and the current packet belongs to an already established
492 * connection */
613dbd95 493 sk = nf_tproxy_get_sock_v6(xt_net(par), skb, thoff, hp, tproto,
6ad78893
BS
494 &iph->saddr, &iph->daddr,
495 hp->source, hp->dest,
613dbd95 496 xt_in(par), NFT_LOOKUP_ESTABLISHED);
6ad78893 497
cc6eb433
BS
498 laddr = tproxy_laddr6(skb, &tgi->laddr.in6, &iph->daddr);
499 lport = tgi->lport ? tgi->lport : hp->dest;
500
6ad78893
BS
501 /* UDP has no TCP_TIME_WAIT state, so we never enter here */
502 if (sk && sk->sk_state == TCP_TIME_WAIT)
503 /* reopening a TIME_WAIT connection needs special handling */
504 sk = tproxy_handle_time_wait6(skb, tproto, thoff, par, sk);
505 else if (!sk)
506 /* no there's no established connection, check if
507 * there's a listener on the redirected addr/port */
613dbd95 508 sk = nf_tproxy_get_sock_v6(xt_net(par), skb, thoff, hp,
a583636a 509 tproto, &iph->saddr, laddr,
cc6eb433 510 hp->source, lport,
613dbd95 511 xt_in(par), NFT_LOOKUP_LISTENER);
e8439270
KK
512
513 /* NOTE: assign_sock consumes our sk reference */
d503b30b 514 if (sk && tproxy_sk_is_transparent(sk)) {
e8439270
KK
515 /* This should be in a separate target, but we don't do multiple
516 targets on the same rule yet */
517 skb->mark = (skb->mark & ~tgi->mark_mask) ^ tgi->mark_value;
518
6ad78893 519 pr_debug("redirecting: proto %hhu %pI6:%hu -> %pI6:%hu, mark: %x\n",
cc6eb433
BS
520 tproto, &iph->saddr, ntohs(hp->source),
521 laddr, ntohs(lport), skb->mark);
d503b30b
FW
522
523 nf_tproxy_assign_sock(skb, sk);
e8439270
KK
524 return NF_ACCEPT;
525 }
526
6ad78893 527 pr_debug("no socket, dropping: proto %hhu %pI6:%hu -> %pI6:%hu, mark: %x\n",
cc6eb433
BS
528 tproto, &iph->saddr, ntohs(hp->source),
529 &iph->daddr, ntohs(hp->dest), skb->mark);
530
e8439270
KK
531 return NF_DROP;
532}
533
6ad78893
BS
534static int tproxy_tg6_check(const struct xt_tgchk_param *par)
535{
536 const struct ip6t_ip6 *i = par->entryinfo;
834184b1
FW
537 int err;
538
539 err = nf_defrag_ipv6_enable(par->net);
540 if (err)
541 return err;
6ad78893 542
3d8c6dce
PNA
543 if ((i->proto == IPPROTO_TCP || i->proto == IPPROTO_UDP) &&
544 !(i->invflags & IP6T_INV_PROTO))
6ad78893
BS
545 return 0;
546
547 pr_info("Can be used only in combination with "
548 "either -p tcp or -p udp\n");
549 return -EINVAL;
550}
551#endif
552
553static int tproxy_tg4_check(const struct xt_tgchk_param *par)
e8439270 554{
af5d6dc2 555 const struct ipt_ip *i = par->entryinfo;
834184b1
FW
556 int err;
557
558 err = nf_defrag_ipv4_enable(par->net);
559 if (err)
560 return err;
e8439270
KK
561
562 if ((i->proto == IPPROTO_TCP || i->proto == IPPROTO_UDP)
563 && !(i->invflags & IPT_INV_PROTO))
d6b00a53 564 return 0;
e8439270 565
ff67e4e4 566 pr_info("Can be used only in combination with "
e8439270 567 "either -p tcp or -p udp\n");
d6b00a53 568 return -EINVAL;
e8439270
KK
569}
570
6ad78893
BS
571static struct xt_target tproxy_tg_reg[] __read_mostly = {
572 {
573 .name = "TPROXY",
574 .family = NFPROTO_IPV4,
575 .table = "mangle",
576 .target = tproxy_tg4_v0,
577 .revision = 0,
578 .targetsize = sizeof(struct xt_tproxy_target_info),
579 .checkentry = tproxy_tg4_check,
580 .hooks = 1 << NF_INET_PRE_ROUTING,
581 .me = THIS_MODULE,
582 },
583 {
584 .name = "TPROXY",
585 .family = NFPROTO_IPV4,
586 .table = "mangle",
587 .target = tproxy_tg4_v1,
588 .revision = 1,
589 .targetsize = sizeof(struct xt_tproxy_target_info_v1),
590 .checkentry = tproxy_tg4_check,
591 .hooks = 1 << NF_INET_PRE_ROUTING,
592 .me = THIS_MODULE,
593 },
f6318e55 594#ifdef XT_TPROXY_HAVE_IPV6
6ad78893
BS
595 {
596 .name = "TPROXY",
597 .family = NFPROTO_IPV6,
598 .table = "mangle",
599 .target = tproxy_tg6_v1,
600 .revision = 1,
601 .targetsize = sizeof(struct xt_tproxy_target_info_v1),
602 .checkentry = tproxy_tg6_check,
603 .hooks = 1 << NF_INET_PRE_ROUTING,
604 .me = THIS_MODULE,
605 },
606#endif
607
e8439270
KK
608};
609
610static int __init tproxy_tg_init(void)
611{
6ad78893 612 return xt_register_targets(tproxy_tg_reg, ARRAY_SIZE(tproxy_tg_reg));
e8439270
KK
613}
614
615static void __exit tproxy_tg_exit(void)
616{
6ad78893 617 xt_unregister_targets(tproxy_tg_reg, ARRAY_SIZE(tproxy_tg_reg));
e8439270
KK
618}
619
620module_init(tproxy_tg_init);
621module_exit(tproxy_tg_exit);
622MODULE_LICENSE("GPL");
6ad78893 623MODULE_AUTHOR("Balazs Scheidler, Krisztian Kovacs");
e8439270
KK
624MODULE_DESCRIPTION("Netfilter transparent proxy (TPROXY) target module.");
625MODULE_ALIAS("ipt_TPROXY");
6ad78893 626MODULE_ALIAS("ip6t_TPROXY");