Commit dc384c0e authored by Andrei Vagin's avatar Andrei Vagin

netfilter: use ipv4 iptables rules to block IPv4-mapped IPv6 addresses

If ipv6 socket has an IPv4-mapped address, it is used to handle ipv4
connection, so we have to use ipv4 iptables rules to block this
connection.

Reported-by: Mr Jenkins
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent c31d423e
...@@ -47,6 +47,12 @@ void preload_netfilter_modules(void) ...@@ -47,6 +47,12 @@ void preload_netfilter_modules(void)
close_safe(&fd); close_safe(&fd);
} }
/* IPv4-Mapped IPv6 Addresses */
static int ipv6_addr_mapped(u32 *addr)
{
return (addr[2] == htonl(0x0000ffff));
}
static int nf_connection_switch_raw(int family, u32 *src_addr, u16 src_port, static int nf_connection_switch_raw(int family, u32 *src_addr, u16 src_port,
u32 *dst_addr, u16 dst_port, u32 *dst_addr, u16 dst_port,
bool input, bool lock) bool input, bool lock)
...@@ -56,6 +62,12 @@ static int nf_connection_switch_raw(int family, u32 *src_addr, u16 src_port, ...@@ -56,6 +62,12 @@ static int nf_connection_switch_raw(int family, u32 *src_addr, u16 src_port,
char *argv[4] = { "sh", "-c", buf, NULL }; char *argv[4] = { "sh", "-c", buf, NULL };
int ret; int ret;
if (family == AF_INET6 && ipv6_addr_mapped(dst_addr)) {
family = AF_INET;
src_addr = &src_addr[3];
dst_addr = &dst_addr[3];
}
switch (family) { switch (family) {
case AF_INET: case AF_INET:
cmd = iptable_cmd_ipv4; cmd = iptable_cmd_ipv4;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment