Commit dd6b25de authored by Arturo Borrero Gonzalez's avatar Arturo Borrero Gonzalez
Browse files

Merge tag 'upstream/1.6.0+snapshot20161117'

Upstream version 1.6.0+snapshot20161117
parents 8fceaf37 7b095084
......@@ -17,6 +17,9 @@ A prefix string to include in the log message, up to 64 characters
long, useful for distinguishing messages in the logs.
.TP
\fB\-\-nflog\-range\fP \fIsize\fP
This option has never worked, use --nflog-size instead
.TP
\fB\-\-nflog\-size\fP \fIsize\fP
The number of bytes to be copied to userspace (only applicable for
nfnetlink_log). nfnetlink_log instances may specify their own
range, this option overrides it.
......
:INPUT,FORWARD,OUTPUT
-j NFLOG --nflog-group 1;=;OK
-j NFLOG --nflog-group 65535;=;OK
-j NFLOG --nflog-group 65536;;FAIL
-j NFLOG --nflog-group 0;-j NFLOG;OK
-j NFLOG --nflog-range 1;=;OK
-j NFLOG --nflog-range 4294967295;=;OK
-j NFLOG --nflog-range 4294967296;;FAIL
-j NFLOG --nflog-range -1;;FAIL
-j NFLOG --nflog-size 0;=;OK
-j NFLOG --nflog-size 1;=;OK
-j NFLOG --nflog-size 4294967295;=;OK
-j NFLOG --nflog-size 4294967296;;FAIL
-j NFLOG --nflog-size -1;;FAIL
# ERROR: cannot find: iptables -I INPUT -j NFLOG --nflog-prefix xxxxxx [...]
# -j NFLOG --nflog-prefix xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;=;OK
# ERROR: should fail: iptables -A INPUT -j NFLOG --nflog-prefix xxxxxxx [...]
# -j NFLOG --nflog-prefix xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;;FAIL
-j NFLOG --nflog-threshold 1;=;OK
# ERROR: line 13 (should fail: iptables -A INPUT -j NFLOG --nflog-threshold 0
# -j NFLOG --nflog-threshold 0;;FAIL
-j NFLOG --nflog-threshold 65535;=;OK
-j NFLOG --nflog-threshold 65536;;FAIL
-j NFLOG;=;OK
......@@ -30,23 +30,32 @@ static void NFQUEUE_help(void)
static void NFQUEUE_help_v1(void)
{
NFQUEUE_help();
printf(
"NFQUEUE target options\n"
" --queue-num value Send packet to QUEUE number <value>.\n"
" Valid queue numbers are 0-65535\n"
" --queue-balance first:last Balance flows between queues <value> to <value>.\n");
}
static void NFQUEUE_help_v2(void)
{
NFQUEUE_help_v1();
printf(
"NFQUEUE target options\n"
" --queue-num value Send packet to QUEUE number <value>.\n"
" Valid queue numbers are 0-65535\n"
" --queue-balance first:last Balance flows between queues <value> to <value>.\n"
" --queue-bypass Bypass Queueing if no queue instance exists.\n"
" --queue-cpu-fanout Use current CPU (no hashing)\n");
}
static void NFQUEUE_help_v3(void)
{
NFQUEUE_help_v2();
printf(
"NFQUEUE target options\n"
" --queue-num value Send packet to QUEUE number <value>.\n"
" Valid queue numbers are 0-65535\n"
" --queue-balance first:last Balance flows between queues <value> to <value>.\n"
" --queue-bypass Bypass Queueing if no queue instance exists.\n"
" --queue-cpu-fanout Use current CPU (no hashing)\n");
}
......@@ -95,11 +104,23 @@ static void NFQUEUE_parse_v1(struct xt_option_call *cb)
static void NFQUEUE_parse_v2(struct xt_option_call *cb)
{
struct xt_NFQ_info_v2 *info = cb->data;
const uint16_t *r = cb->val.u16_range;
NFQUEUE_parse_v1(cb);
xtables_option_parse(cb);
switch (cb->entry->id) {
case O_QUEUE_BALANCE:
if (cb->nvals != 2)
xtables_error(PARAMETER_PROBLEM,
"Bad range \"%s\"", cb->arg);
if (r[0] >= r[1])
xtables_error(PARAMETER_PROBLEM,
"%u should be less than %u",
r[0], r[1]);
info->queuenum = r[0];
info->queues_total = r[1] - r[0] + 1;
break;
case O_QUEUE_BYPASS:
info->bypass = 1;
info->bypass |= NFQ_FLAG_BYPASS;
break;
}
}
......@@ -107,9 +128,24 @@ static void NFQUEUE_parse_v2(struct xt_option_call *cb)
static void NFQUEUE_parse_v3(struct xt_option_call *cb)
{
struct xt_NFQ_info_v3 *info = cb->data;
const uint16_t *r = cb->val.u16_range;
NFQUEUE_parse_v2(cb);
xtables_option_parse(cb);
switch (cb->entry->id) {
case O_QUEUE_BALANCE:
if (cb->nvals != 2)
xtables_error(PARAMETER_PROBLEM,
"Bad range \"%s\"", cb->arg);
if (r[0] >= r[1])
xtables_error(PARAMETER_PROBLEM,
"%u should be less than %u",
r[0], r[1]);
info->queuenum = r[0];
info->queues_total = r[1] - r[0] + 1;
break;
case O_QUEUE_BYPASS:
info->flags |= NFQ_FLAG_BYPASS;
break;
case O_QUEUE_CPU_FANOUT:
info->flags |= NFQ_FLAG_CPU_FANOUT;
break;
......@@ -142,8 +178,14 @@ static void NFQUEUE_print_v2(const void *ip,
const struct xt_entry_target *target, int numeric)
{
const struct xt_NFQ_info_v2 *info = (void *) target->data;
unsigned int last = info->queues_total;
if (last > 1) {
last += info->queuenum - 1;
printf(" NFQUEUE balance %u:%u", info->queuenum, last);
} else
printf(" NFQUEUE num %u", info->queuenum);
NFQUEUE_print_v1(ip, target, numeric);
if (info->bypass & NFQ_FLAG_BYPASS)
printf(" bypass");
}
......@@ -152,8 +194,17 @@ static void NFQUEUE_print_v3(const void *ip,
const struct xt_entry_target *target, int numeric)
{
const struct xt_NFQ_info_v3 *info = (void *)target->data;
unsigned int last = info->queues_total;
if (last > 1) {
last += info->queuenum - 1;
printf(" NFQUEUE balance %u:%u", info->queuenum, last);
} else
printf(" NFQUEUE num %u", info->queuenum);
if (info->flags & NFQ_FLAG_BYPASS)
printf(" bypass");
NFQUEUE_print_v2(ip, target, numeric);
if (info->flags & NFQ_FLAG_CPU_FANOUT)
printf(" cpu-fanout");
}
......@@ -182,8 +233,13 @@ static void NFQUEUE_save_v1(const void *ip, const struct xt_entry_target *target
static void NFQUEUE_save_v2(const void *ip, const struct xt_entry_target *target)
{
const struct xt_NFQ_info_v2 *info = (void *) target->data;
unsigned int last = info->queues_total;
NFQUEUE_save_v1(ip, target);
if (last > 1) {
last += info->queuenum - 1;
printf(" --queue-balance %u:%u", info->queuenum, last);
} else
printf(" --queue-num %u", info->queuenum);
if (info->bypass & NFQ_FLAG_BYPASS)
printf(" --queue-bypass");
......@@ -193,8 +249,17 @@ static void NFQUEUE_save_v3(const void *ip,
const struct xt_entry_target *target)
{
const struct xt_NFQ_info_v3 *info = (void *)target->data;
unsigned int last = info->queues_total;
if (last > 1) {
last += info->queuenum - 1;
printf(" --queue-balance %u:%u", info->queuenum, last);
} else
printf(" --queue-num %u", info->queuenum);
if (info->flags & NFQ_FLAG_BYPASS)
printf(" --queue-bypass");
NFQUEUE_save_v2(ip, target);
if (info->flags & NFQ_FLAG_CPU_FANOUT)
printf(" --queue-cpu-fanout");
}
......@@ -205,6 +270,73 @@ static void NFQUEUE_init_v1(struct xt_entry_target *t)
tinfo->queues_total = 1;
}
static int NFQUEUE_xlate(struct xt_xlate *xl,
const struct xt_xlate_tg_params *params)
{
const struct xt_NFQ_info *tinfo =
(const struct xt_NFQ_info *)params->target->data;
xt_xlate_add(xl, "queue num %u ", tinfo->queuenum);
return 1;
}
static int NFQUEUE_xlate_v1(struct xt_xlate *xl,
const struct xt_xlate_tg_params *params)
{
const struct xt_NFQ_info_v1 *tinfo = (const void *)params->target->data;
unsigned int last = tinfo->queues_total;
if (last > 1) {
last += tinfo->queuenum - 1;
xt_xlate_add(xl, "queue num %u-%u ", tinfo->queuenum, last);
} else {
xt_xlate_add(xl, "queue num %u ", tinfo->queuenum);
}
return 1;
}
static int NFQUEUE_xlate_v2(struct xt_xlate *xl,
const struct xt_xlate_tg_params *params)
{
const struct xt_NFQ_info_v2 *info = (void *)params->target->data;
unsigned int last = info->queues_total;
if (last > 1) {
last += info->queuenum - 1;
xt_xlate_add(xl, "queue num %u-%u ", info->queuenum, last);
} else
xt_xlate_add(xl, "queue num %u ", info->queuenum);
if (info->bypass & NFQ_FLAG_BYPASS)
xt_xlate_add(xl, "bypass");
return 1;
}
static int NFQUEUE_xlate_v3(struct xt_xlate *xl,
const struct xt_xlate_tg_params *params)
{
const struct xt_NFQ_info_v3 *info = (void *)params->target->data;
unsigned int last = info->queues_total;
if (last > 1) {
last += info->queuenum - 1;
xt_xlate_add(xl, "queue num %u-%u ", info->queuenum, last);
} else
xt_xlate_add(xl, "queue num %u ", info->queuenum);
if (info->flags & NFQ_FLAG_BYPASS)
xt_xlate_add(xl, "bypass");
if (info->flags & NFQ_FLAG_CPU_FANOUT)
xt_xlate_add(xl, "%sfanout ",
info->flags & NFQ_FLAG_BYPASS ? "," : "");
return 1;
}
static struct xtables_target nfqueue_targets[] = {
{
.family = NFPROTO_UNSPEC,
......@@ -216,7 +348,8 @@ static struct xtables_target nfqueue_targets[] = {
.print = NFQUEUE_print,
.save = NFQUEUE_save,
.x6_parse = NFQUEUE_parse,
.x6_options = NFQUEUE_opts
.x6_options = NFQUEUE_opts,
.xlate = NFQUEUE_xlate,
},{
.family = NFPROTO_UNSPEC,
.revision = 1,
......@@ -230,6 +363,7 @@ static struct xtables_target nfqueue_targets[] = {
.save = NFQUEUE_save_v1,
.x6_parse = NFQUEUE_parse_v1,
.x6_options = NFQUEUE_opts,
.xlate = NFQUEUE_xlate_v1,
},{
.family = NFPROTO_UNSPEC,
.revision = 2,
......@@ -243,6 +377,7 @@ static struct xtables_target nfqueue_targets[] = {
.save = NFQUEUE_save_v2,
.x6_parse = NFQUEUE_parse_v2,
.x6_options = NFQUEUE_opts,
.xlate = NFQUEUE_xlate_v2,
},{
.family = NFPROTO_UNSPEC,
.revision = 3,
......@@ -256,6 +391,7 @@ static struct xtables_target nfqueue_targets[] = {
.save = NFQUEUE_save_v3,
.x6_parse = NFQUEUE_parse_v3,
.x6_options = NFQUEUE_opts,
.xlate = NFQUEUE_xlate_v3,
}
};
......
:INPUT,FORWARD,OUTPUT
-j NFQUEUE;=;OK
-j NFQUEUE --queue-num 0;=;OK
-j NFQUEUE --queue-num 65535;=;OK
-j NFQUEUE --queue-num 65536;;FAIL
-j NFQUEUE --queue-num -1;;FAIL
# it says "NFQUEUE: number of total queues is 0", overflow in NFQUEUE_parse_v1?
# ERROR: cannot load: iptables -A INPUT -j NFQUEUE --queue-balance 0:65535
# -j NFQUEUE --queue-balance 0:65535;=;OK
-j NFQUEUE --queue-balance 0:65536;;FAIL
-j NFQUEUE --queue-balance -1:65535;;FAIL
-j NFQUEUE --queue-num 10 --queue-bypass;=;OK
-j NFQUEUE --queue-balance 0:6 --queue-cpu-fanout --queue-bypass;-j NFQUEUE --queue-balance 0:6 --queue-bypass --queue-cpu-fanout;OK
-j NFQUEUE --queue-bypass --queue-balance 0:6 --queue-cpu-fanout;-j NFQUEUE --queue-balance 0:6 --queue-bypass --queue-cpu-fanout;OK
-j NFQUEUE --queue-balance 0:6 --queue-bypass;=;OK
-j NFQUEUE --queue-bypass;-j NFQUEUE --queue-num 0 --queue-bypass;OK
:PREROUTING,OUTPUT
*raw
# ERROR: cannot find: iptables -I PREROUTING -t raw -j NOTRACK
#-j NOTRACK;=;OK
:INPUT,FORWARD,OUTPUT
-j RATEEST --rateest-name RE1 --rateest-interval 250.0ms --rateest-ewmalog 500.0ms;=;OK
:INPUT,FORWARD,OUTPUT
# fails: foo does not exist
-j SET --add-set foo src,dst;;FAIL
:INPUT,FORWARD
-j SYNPROXY --sack-perm --timestamp --mss 1460 --wscale 9;;FAIL
-p tcp -m tcp --dport 42 -m conntrack --ctstate INVALID,UNTRACKED -j SYNPROXY --sack-perm --timestamp --wscale 9 --mss 1460;=;OK
:FORWARD,OUTPUT,POSTROUTING
*mangle
-j TCPMSS;;FAIL
-p tcp -j TCPMSS --set-mss 42;;FAIL
-p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK SYN -j TCPMSS --set-mss 42;=;OK
-p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK SYN -j TCPMSS --clamp-mss-to-pmtu;=;OK
......@@ -12,6 +12,21 @@
#ifndef TCPOPT_MD5SIG
# define TCPOPT_MD5SIG 19
#endif
#ifndef TCPOPT_MAXSEG
# define TCPOPT_MAXSEG 2
#endif
#ifndef TCPOPT_WINDOW
# define TCPOPT_WINDOW 3
#endif
#ifndef TCPOPT_SACK_PERMITTED
# define TCPOPT_SACK_PERMITTED 4
#endif
#ifndef TCPOPT_SACK
# define TCPOPT_SACK 5
#endif
#ifndef TCPOPT_TIMESTAMP
# define TCPOPT_TIMESTAMP 8
#endif
enum {
O_STRIP_OPTION = 0,
......
:PREROUTING,INPUT,FORWARD,OUTPUT,POSTROUTING
*mangle
-j TCPOPTSTRIP;;FAIL
-p tcp -j TCPOPTSTRIP;=;OK
-p tcp -j TCPOPTSTRIP --strip-options 2,3,4,5,6,7;=;OK
-p tcp -j TCPOPTSTRIP --strip-options 0;;FAIL
-p tcp -j TCPOPTSTRIP --strip-options 1;;FAIL
-p tcp -j TCPOPTSTRIP --strip-options 1,2;;FAIL
......@@ -92,6 +92,40 @@ static void tee_tg6_save(const void *ip, const struct xt_entry_target *target)
printf(" --oif %s", info->oif);
}
static int tee_tg_xlate(struct xt_xlate *xl,
const struct xt_xlate_tg_params *params)
{
const struct xt_tee_tginfo *info = (const void *)params->target->data;
if (params->numeric)
xt_xlate_add(xl, "dup to %s",
xtables_ipaddr_to_numeric(&info->gw.in));
else
xt_xlate_add(xl, "dup to %s",
xtables_ipaddr_to_anyname(&info->gw.in));
if (*info->oif != '\0')
xt_xlate_add(xl, " device %s", info->oif);
return 1;
}
static int tee_tg6_xlate(struct xt_xlate *xl,
const struct xt_xlate_tg_params *params)
{
const struct xt_tee_tginfo *info = (const void *)params->target->data;
if (params->numeric)
xt_xlate_add(xl, "dup to %s",
xtables_ip6addr_to_numeric(&info->gw.in6));
else
xt_xlate_add(xl, "dup to %s",
xtables_ip6addr_to_anyname(&info->gw.in6));
if (*info->oif != '\0')
xt_xlate_add(xl, " device %s", info->oif);
return 1;
}
static struct xtables_target tee_tg_reg[] = {
{
.name = "TEE",
......@@ -105,6 +139,7 @@ static struct xtables_target tee_tg_reg[] = {
.save = tee_tg_save,
.x6_parse = xtables_option_parse,
.x6_options = tee_tg_opts,
.xlate = tee_tg_xlate,
},
{
.name = "TEE",
......@@ -118,6 +153,7 @@ static struct xtables_target tee_tg_reg[] = {
.save = tee_tg6_save,
.x6_parse = xtables_option_parse,
.x6_options = tee_tg_opts,
.xlate = tee_tg6_xlate,
},
};
......
:INPUT,FORWARD,OUTPUT
-j TEE --gateway 1.1.1.1;=;OK
-j TEE ! --gateway 1.1.1.1;;FAIL
-j TEE;;FAIL
:PREROUTING,INPUT,FORWARD,OUTPUT,POSTROUTING
*mangle
-j TOS --set-tos 0x1f;=;OK
-j TOS --set-tos 0x1f/0x1f;=;OK
# maximum TOS is 0x1f (5 bits)
# ERROR: should fail: iptables -A PREROUTING -t mangle -j TOS --set-tos 0xff
# -j TOS --set-tos 0xff;;FAIL
-j TOS --set-tos Minimize-Delay;-j TOS --set-tos 0x10;OK
-j TOS --set-tos Maximize-Throughput;-j TOS --set-tos 0x08;OK
-j TOS --set-tos Maximize-Reliability;-j TOS --set-tos 0x04;OK
-j TOS --set-tos Minimize-Cost;-j TOS --set-tos 0x02;OK
-j TOS --set-tos Normal-Service;-j TOS --set-tos 0x00;OK
-j TOS --and-tos 0x12;-j TOS --set-tos 0x00/0xed;OK
-j TOS --or-tos 0x12;-j TOS --set-tos 0x12/0x12;OK
-j TOS --xor-tos 0x12;-j TOS --set-tos 0x12/0x00;OK
-j TOS;;FAIL
:PREROUTING
*mangle
-j TPROXY --on-port 12345 --on-ip 10.0.0.1 --tproxy-mark 0x23/0xff;;FAIL
-p udp -j TPROXY --on-port 12345 --on-ip 10.0.0.1 --tproxy-mark 0x23/0xff;=;OK
-p tcp -m tcp --dport 2342 -j TPROXY --on-port 12345 --on-ip 10.0.0.1 --tproxy-mark 0x23/0xff;=;OK
......@@ -7,12 +7,20 @@
#include <xtables.h>
#include <linux/netfilter/x_tables.h>
static int trace_xlate(struct xt_xlate *xl,
const struct xt_xlate_tg_params *params)
{
xt_xlate_add(xl, "nftrace set 1");
return 1;
}
static struct xtables_target trace_target = {
.family = NFPROTO_UNSPEC,
.name = "TRACE",
.version = XTABLES_VERSION,
.size = XT_ALIGN(0),
.userspacesize = XT_ALIGN(0),
.xlate = trace_xlate,
};
void _init(void)
......
:PREROUTING,OUTPUT
*raw
-j TRACE;=;OK
:INPUT,FORWARD,OUTPUT
-m addrtype;;FAIL
-m addrtype --src-type wrong;;FAIL
-m addrtype --src-type UNSPEC;=;OK
-m addrtype --dst-type UNSPEC;=;OK
-m addrtype --src-type LOCAL --dst-type LOCAL;=;OK
-m addrtype --dst-type UNSPEC;=;OK
-m addrtype --limit-iface-in;;FAIL
-m addrtype --limit-iface-out;;FAIL
-m addrtype --limit-iface-in --limit-iface-out;;FAIL
-m addrtype --src-type LOCAL --limit-iface-in --limit-iface-out;;FAIL
:INPUT
-m addrtype --src-type LOCAL --limit-iface-in;=;OK
-m addrtype --dst-type LOCAL --limit-iface-in;=;OK
:OUTPUT
-m addrtype --src-type LOCAL --limit-iface-out;=;OK
-m addrtype --dst-type LOCAL --limit-iface-out;=;OK
......@@ -31,4 +31,17 @@ Or instead, you can invoke the nfbpf_compile utility.
.IP
iptables \-A OUTPUT \-m bpf \-\-bytecode "`nfbpf_compile RAW 'ip proto 6'`" \-j ACCEPT
.PP
Or use tcpdump -ddd. In that case, generate BPF targeting a device with the
same data link type as the xtables match. Iptables passes packets from the
network layer up, without mac layer. Select a device with data link type RAW,
such as a tun device:
.IP
ip tuntap add tun0 mode tun
.br
ip link set tun0 up
.br
tcpdump -ddd -i tun0 ip proto 6
.PP
See tcpdump -L -i $dev for a list of known data link types for a given device.
.PP
You may want to learn more about BPF from FreeBSD's bpf(4) manpage.
:INPUT,FORWARD,OUTPUT
-m bpf --bytecode "4,48 0 0 9,21 0 1 6,6 0 0 1,6 0 0 0";=;OK
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