Transparent proxy patches, take 4 - userspace
Hi Patrick,
Here is the current version of the iptables (userspace) tproxy patch. After the last round Jan Engelhardt provided all kinds of cleanups and fixes, this is basically based on his work. Thanks a lot, Jan.
Should apply cleanly on top of current SVN.
--- extensions/Makefile | 2 extensions/libipt_TPROXY.man | 21 ++++ extensions/libipt_socket.man | 2 extensions/libxt_TPROXY.c | 155 ++++++++++++++++++++++++++++++++++++ extensions/libxt_socket.c | 39 +++++++++ include/linux/netfilter/xt_TPROXY.h | 16 +++ 6 files changed, 234 insertions(+), 1 deletion(-)
extensions/Makefile +1 -1
@@ -7,7 +7,7 @@ # PF_EXT_SLIB:=ah addrtype conntrack ecn icmp iprange owner policy realm recent tos ttl unclean CLUSTERIP DNAT ECN LOG MASQUERADE MIRROR NETMAP REDIRECT REJECT SAME SNAT TOS TTL ULOG PF6_EXT_SLIB:=ah dst eui64 frag hbh hl icmp6 ipv6header mh owner policy rt HL LOG REJECT -PFX_EXT_SLIB:=connbytes connmark connlimit comment dccp dscp esp hashlimit helper length limit mac mark multiport physdev pkttype quota sctp state statistic standard string tcp tcpmss time u32 udp CLASSIFY CONNMARK DSCP MARK NFLOG NFQUEUE NOTRACK TCPMSS TRACE +PFX_EXT_SLIB:=connbytes connmark connlimit comment dccp dscp esp hashlimit helper length limit mac mark multiport physdev pkttype quota sctp socket state statistic standard string tcp tcpmss time u32 udp CLASSIFY CONNMARK DSCP MARK NFLOG NFQUEUE NOTRACK TCPMSS TPROXY TRACE PF_EXT_SELINUX_SLIB:= PF6_EXT_SELINUX_SLIB:=
extensions/libipt_TPROXY.man new file +21 -0
@@ -0,0 +1,21 @@ +This target is only valid in the \fBmangle\fR table, in the \fBPREROUTING\fR +chain and user-defined chains which are only called from this chain. It +redirects the packet to a local socket without changing the packet header in +any way. It can also change the mark value which can then be used in advanced +routing rules. +It takes three options: +.TP +\fB--on-port\fR \fIport\fR +This specifies a destination port to use. It is a required option, 0 means the +new destination port is the same as the original. This is only valid if the +rule also specifies \fB-p tcp\fR or \fB-p udp\fR. +.TP +\fB--on-ip\fR \fIaddress\fR +This specifies a destination address to use. By default the address is the IP +address of the incoming interface. This is only valid if the rule also +specifies \fB-p tcp\fR or \fR-p udp\fR. +.TP +\fB--tproxy-mark\fR \fIvalue\fR[\fB/\fR\fImask\fR] +Marks packets with the given value/mask. The fwmark value set here can be used +by advanced routing. (Required for transparent proxying to work: otherwise +these packets will get forwarded, which is probably not what you want.)
extensions/libipt_socket.man new file +2 -0
@@ -0,0 +1,2 @@ +This matches if an open socket can be found by doing a socket lookup on the +packet.
extensions/libxt_TPROXY.c new file +155 -0
155 lines not on this page · raw message
extensions/libxt_socket.c new file +39 -0
@@ -0,0 +1,39 @@ +/* +* Shared library add-on to iptables to add early socket matching support. +* +* Copyright (C) 2007 BalaBit IT Ltd. +*/ +#include <stdio.h> +#include <getopt.h> +#include <iptables.h> + +static void socket_help (void ) +{ +printf ("socket v%s has no options\n\n" ,IPTABLES_VERSION ); +} + +static int socket_parse (int c,char **argv,int invert,unsigned int *flags, +const void *entry,struct xt_entry_match **match) +{ +return 0 ; +} + +static void socket_check (unsigned int flags) +{ +} + +static struct xtables_match socket_reg = { + .name ="socket" , + .version =IPTABLES_VERSION , + .family =AF_INET , + .size =XT_ALIGN (0 ), + .userspacesize =XT_ALIGN (0 ), + .parse = socket_parse, + .final_check = socket_check, + .help = socket_help, +}; + +void _init (void ) +{ +xtables_register_match (&socket_reg); +}
include/linux/netfilter/xt_TPROXY.h new file +16 -0
@@ -0,0 +1,16 @@ +#ifndef _XT_TPROXY_H_target +#define _XT_TPROXY_H_target + +/* +* TPROXY target is capable of marking the packet to perform +* redirection. We can get rid of that whenever we get support for +* mutliple targets in the same rule. +*/ +struct xt_tproxy_target_info { +u_int32_t mark_mask; +u_int32_t mark_value; +__be32 laddr; +__be16 lport; +}; + +#endif /* _XT_TPROXY_H_target */