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
:INPUT,POSTROUTING
*mangle
-j SNPT --src-pfx dead::/64 --dst-pfx 1c3::/64;=;OK
-j SNPT --src-pfx dead::beef --dst-pfx 1c3::/64;;FAIL
-j SNPT --src-pfx dead::/64;;FAIL
-j SNPT --dst-pfx dead::/64;;FAIL
-j SNPT;;FAIL
......@@ -128,6 +128,36 @@ static void ah_save(const void *ip, const struct xt_entry_match *match)
printf(" --ahres");
}
static int ah_xlate(struct xt_xlate *xl,
const struct xt_xlate_mt_params *params)
{
const struct ip6t_ah *ahinfo = (struct ip6t_ah *)params->match->data;
char *space = "";
if (!(ahinfo->spis[0] == 0 && ahinfo->spis[1] == 0xFFFFFFFF)) {
xt_xlate_add(xl, "ah spi%s ",
(ahinfo->invflags & IP6T_AH_INV_SPI) ? " !=" : "");
if (ahinfo->spis[0] != ahinfo->spis[1])
xt_xlate_add(xl, "%u-%u", ahinfo->spis[0],
ahinfo->spis[1]);
else
xt_xlate_add(xl, "%u", ahinfo->spis[0]);
space = " ";
}
if (ahinfo->hdrlen != 0 || (ahinfo->invflags & IP6T_AH_INV_LEN)) {
xt_xlate_add(xl, "%sah hdrlength%s %u", space,
(ahinfo->invflags & IP6T_AH_INV_LEN) ? " !=" : "",
ahinfo->hdrlen);
space = " ";
}
if (ahinfo->hdrres != 0)
xt_xlate_add(xl, "%sah reserved %u", space, ahinfo->hdrres);
return 1;
}
static struct xtables_match ah_mt6_reg = {
.name = "ah",
.version = XTABLES_VERSION,
......@@ -140,6 +170,7 @@ static struct xtables_match ah_mt6_reg = {
.save = ah_save,
.x6_parse = ah_parse,
.x6_options = ah_opts,
.xlate = ah_xlate,
};
void
......
:INPUT,FORWARD,OUTPUT
-m ah --ahspi 0;=;OK
-m ah --ahspi 4294967295;=;OK
-m ah --ahspi 0:4294967295;-m ah;OK
-m ah ! --ahspi 0;=;OK
# ERROR: should fail: iptables -A FORWARD -t mangle -j CLASSIFY --set-class 1:-1
# -m ah --ahres;=;OK
# ERROR: line 7 (cannot find: ip6tables -I INPUT -m ah --ahlen 32
# -m ah --ahlen 32;=;OK
-m ah --ahspi -1;;FAIL
-m ah --ahspi 4294967296;;FAIL
-m ah --ahspi invalid;;FAIL
-m ah --ahspi 0:invalid;;FAIL
-m ah --ahspi;;FAIL
-m ah;=;OK
:INPUT,FORWARD,OUTPUT
-m dst --dst-len 0;=;OK
-m dst --dst-opts 149:92,12:12,123:12;=;OK
-m dst ! --dst-len 42;=;OK
-m dst --dst-len 42 --dst-opts 149:92,12:12,123:12;=;OK
:PREROUTING
*raw
-m eui64;=;OK
:INPUT,FORWARD
*filter
-m eui64;=;OK
:OUTPUT
-m eui64;;FAIL
......@@ -173,6 +173,45 @@ static void frag_save(const void *ip, const struct xt_entry_match *match)
printf(" --fraglast");
}
static int frag_xlate(struct xt_xlate *xl,
const struct xt_xlate_mt_params *params)
{
const struct ip6t_frag *fraginfo =
(struct ip6t_frag *)params->match->data;
char *space= "";
if (!(fraginfo->ids[0] == 0 && fraginfo->ids[1] == 0xFFFFFFFF)) {
xt_xlate_add(xl, "frag id %s",
(fraginfo->invflags & IP6T_FRAG_INV_IDS) ?
"!= " : "");
if (fraginfo->ids[0] != fraginfo->ids[1])
xt_xlate_add(xl, "%u-%u", fraginfo->ids[0],
fraginfo->ids[1]);
else
xt_xlate_add(xl, "%u", fraginfo->ids[0]);
space = " ";
}
if (fraginfo->flags & IP6T_FRAG_RES) {
xt_xlate_add(xl, "%sfrag reserved 1", space);
space = " ";
}
if (fraginfo->flags & IP6T_FRAG_FST) {
xt_xlate_add(xl, "%sfrag frag-off 0", space);
space = " ";
}
if (fraginfo->flags & IP6T_FRAG_MF) {
xt_xlate_add(xl, "%sfrag more-fragments 1", space);
space = " ";
}
if (fraginfo->flags & IP6T_FRAG_NMF) {
xt_xlate_add(xl, "%sfrag more-fragments 0", space);
}
return 1;
}
static struct xtables_match frag_mt6_reg = {
.name = "frag",
.version = XTABLES_VERSION,
......@@ -185,6 +224,7 @@ static struct xtables_match frag_mt6_reg = {
.save = frag_save,
.x6_parse = frag_parse,
.x6_options = frag_opts,
.xlate = frag_xlate,
};
void
......
:INPUT,FORWARD,OUTPUT
-m frag --fragid 1:42;=;OK
-m frag --fraglen 42;=;OK
-m frag --fragres;=;OK
-m frag --fragfirst;=;OK
-m frag --fragmore;=;OK
-m frag --fraglast;=;OK
-m frag ! --fragid 1 ! --fraglen 42 --fragres --fragfirst;=;OK
-m frag --fragfirst --fragmore;=;OK
-m frag --fragfirst --fraglast;=;OK
-m frag --fraglast --fragmore;;FAIL
......@@ -164,6 +164,23 @@ static void hbh_save(const void *ip, const struct xt_entry_match *match)
print_options(optinfo->optsnr, (uint16_t *)optinfo->opts);
}
static int hbh_xlate(struct xt_xlate *xl,
const struct xt_xlate_mt_params *params)
{
const struct ip6t_opts *optinfo =
(struct ip6t_opts *)params->match->data;
if (!(optinfo->flags & IP6T_OPTS_LEN) ||
(optinfo->flags & IP6T_OPTS_OPTS))
return 0;
xt_xlate_add(xl, "hbh hdrlength %s%u",
(optinfo->invflags & IP6T_OPTS_INV_LEN) ? "!= " : "",
optinfo->hdrlen);
return 1;
}
static struct xtables_match hbh_mt6_reg = {
.name = "hbh",
.version = XTABLES_VERSION,
......@@ -175,6 +192,7 @@ static struct xtables_match hbh_mt6_reg = {
.save = hbh_save,
.x6_parse = hbh_parse,
.x6_options = hbh_opts,
.xlate = hbh_xlate,
};
void
......
:INPUT,FORWARD,OUTPUT
-m hbh;=;OK
-m hbh --hbh-len 42;=;OK
-m hbh ! --hbh-len 42;=;OK
-m hbh --hbh-len 42 --hbh-opts 1:2,23:42,4:6,8:10,42,23,4:5;=;OK
......@@ -83,6 +83,24 @@ static void hl_save(const void *ip, const struct xt_entry_match *match)
printf(" %s %u", op[info->mode], info->hop_limit);
}
static const char *const op[] = {
[IP6T_HL_EQ] = "",
[IP6T_HL_NE] = "!= ",
[IP6T_HL_LT] = "lt ",
[IP6T_HL_GT] = "gt "
};
static int hl_xlate(struct xt_xlate *xl,
const struct xt_xlate_mt_params *params)
{
const struct ip6t_hl_info *info =
(struct ip6t_hl_info *) params->match->data;
xt_xlate_add(xl, "ip6 hoplimit %s%u", op[info->mode], info->hop_limit);
return 1;
}
#define s struct ip6t_hl_info
static const struct xt_option_entry hl_opts[] = {
{.name = "hl-lt", .id = O_HL_LT, .excl = F_ANY, .type = XTTYPE_UINT8,
......@@ -109,6 +127,7 @@ static struct xtables_match hl_mt6_reg = {
.x6_parse = hl_parse,
.x6_fcheck = hl_check,
.x6_options = hl_opts,
.xlate = hl_xlate,
};
......
:INPUT,FORWARD,OUTPUT
-m hl;;FAIL
-m hl --hl-eq 42;=;OK
-m hl ! --hl-eq 42;=;OK
-m hl --hl-lt 42;=;OK
-m hl --hl-gt 42;=;OK
-m hl --hl-gt 42 --hl-eq 42;;FAIL
-m hl --hl-gt;;FAIL
......@@ -4,6 +4,7 @@
#include <xtables.h>
#include <limits.h> /* INT_MAX in ip6_tables.h */
#include <linux/netfilter_ipv6/ip6_tables.h>
#include <netinet/icmp6.h>
enum {
O_ICMPV6_TYPE = 0,
......@@ -222,6 +223,70 @@ static void icmp6_save(const void *ip, const struct xt_entry_match *match)
printf("/%u", icmpv6->code[0]);
}
#define XT_ICMPV6_TYPE(type) (type - ND_ROUTER_SOLICIT)
static const char *icmp6_type_xlate_array[] = {
[XT_ICMPV6_TYPE(ND_ROUTER_SOLICIT)] = "nd-router-solicit",
[XT_ICMPV6_TYPE(ND_ROUTER_ADVERT)] = "nd-router-advert",
[XT_ICMPV6_TYPE(ND_NEIGHBOR_SOLICIT)] = "nd-neighbor-solicit",
[XT_ICMPV6_TYPE(ND_NEIGHBOR_ADVERT)] = "nd-neighbor-advert",
[XT_ICMPV6_TYPE(ND_REDIRECT)] = "nd-redirect",
};
static const char *icmp6_type_xlate(unsigned int type)
{
if (type < ND_ROUTER_SOLICIT || type > ND_REDIRECT)
return NULL;
return icmp6_type_xlate_array[XT_ICMPV6_TYPE(type)];
}
static unsigned int type_xlate_print(struct xt_xlate *xl, unsigned int icmptype,
unsigned int code_min,
unsigned int code_max)
{
unsigned int i;
const char *type_name;
if (code_min == code_max)
return 0;
type_name = icmp6_type_xlate(icmptype);
if (type_name) {
xt_xlate_add(xl, type_name);
} else {
for (i = 0; i < ARRAY_SIZE(icmpv6_codes); ++i)
if (icmpv6_codes[i].type == icmptype &&
icmpv6_codes[i].code_min == code_min &&
icmpv6_codes[i].code_max == code_max)
break;
if (i != ARRAY_SIZE(icmpv6_codes))
xt_xlate_add(xl, icmpv6_codes[i].name);
else
return 0;
}
return 1;
}
static int icmp6_xlate(struct xt_xlate *xl,
const struct xt_xlate_mt_params *params)
{
const struct ip6t_icmp *info = (struct ip6t_icmp *)params->match->data;
xt_xlate_add(xl, "icmpv6 type%s ",
(info->invflags & IP6T_ICMP_INV) ? " !=" : "");
if (!type_xlate_print(xl, info->type, info->code[0], info->code[1]))
return 0;
xt_xlate_add(xl, " ");
return 1;
}
static struct xtables_match icmp6_mt6_reg = {
.name = "icmp6",
.version = XTABLES_VERSION,
......@@ -234,6 +299,7 @@ static struct xtables_match icmp6_mt6_reg = {
.save = icmp6_save,
.x6_parse = icmp6_parse,
.x6_options = icmp6_opts,
.xlate = icmp6_xlate,
};
void _init(void)
......
:INPUT,FORWARD,OUTPUT
-m icmpv6;;FAIL
-p ipv6-icmp -m icmp6 --icmpv6-type 1/0;=;OK
-p ipv6-icmp -m icmp6 --icmpv6-type 2;=;OK
# cannot use option twice:
-p ipv6-icmp -m icmp6 --icmpv6-type no-route --icmpv6-type packet-too-big;;FAIL
:INPUT,FORWARD,OUTPUT
-m ipv6header --header hop-by-hop;=;OK
-m ipv6header --header hop-by-hop --soft;=;OK
-m ipv6header --header ipv6-nonxt;=;OK
......@@ -202,6 +202,26 @@ static void mh_save(const void *ip, const struct xt_entry_match *match)
printf(" --mh-type %u", mhinfo->types[0]);
}
static int mh_xlate(struct xt_xlate *xl,
const struct xt_xlate_mt_params *params)
{
const struct ip6t_mh *mhinfo = (struct ip6t_mh *)params->match->data;
if (mhinfo->types[0] == 0 && mhinfo->types[1] == 0xff)
return 1;
if (mhinfo->types[0] != mhinfo->types[1])
xt_xlate_add(xl, "mh type %s%u-%u",
mhinfo->invflags & IP6T_MH_INV_TYPE ? "!= " : "",
mhinfo->types[0], mhinfo->types[1]);
else
xt_xlate_add(xl, "mh type %s%u",
mhinfo->invflags & IP6T_MH_INV_TYPE ? "!= " : "",
mhinfo->types[0]);
return 1;
}
static const struct xt_option_entry mh_opts[] = {
{.name = "mh-type", .id = O_MH_TYPE, .type = XTTYPE_STRING,
.flags = XTOPT_INVERT},
......@@ -220,6 +240,7 @@ static struct xtables_match mh_mt6_reg = {
.print = mh_print,
.save = mh_save,
.x6_options = mh_opts,
.xlate = mh_xlate,
};
void _init(void)
......
:INPUT,FORWARD,OUTPUT
-m mh;;FAIL
-p mobility-header -m mh;=;OK
-p mobility-header -m mh --mh-type 1;=;OK
-p mobility-header -m mh ! --mh-type 4;=;OK
-p mobility-header -m mh --mh-type 4:123;=;OK
......@@ -245,6 +245,43 @@ static void rt_save(const void *ip, const struct xt_entry_match *match)
}
static int rt_xlate(struct xt_xlate *xl,
const struct xt_xlate_mt_params *params)
{
const struct ip6t_rt *rtinfo = (struct ip6t_rt *)params->match->data;
char *space = "";
if (rtinfo->flags & IP6T_RT_TYP) {
xt_xlate_add(xl, "rt type%s %u",
(rtinfo->invflags & IP6T_RT_INV_TYP) ? " !=" : "",
rtinfo->rt_type);
space = " ";
}
if (!(rtinfo->segsleft[0] == 0 && rtinfo->segsleft[1] == 0xFFFFFFFF)) {
xt_xlate_add(xl, "%srt seg-left%s ", space,
(rtinfo->invflags & IP6T_RT_INV_SGS) ? " !=" : "");
if (rtinfo->segsleft[0] != rtinfo->segsleft[1])
xt_xlate_add(xl, "%u-%u", rtinfo->segsleft[0],
rtinfo->segsleft[1]);
else
xt_xlate_add(xl, "%u", rtinfo->segsleft[0]);
space = " ";
}
if (rtinfo->flags & IP6T_RT_LEN) {
xt_xlate_add(xl, "%srt hdrlength%s %u", space,
(rtinfo->invflags & IP6T_RT_INV_LEN) ? " !=" : "",
rtinfo->hdrlen);
}
if (rtinfo->flags & (IP6T_RT_RES | IP6T_RT_FST | IP6T_RT_FST_NSTRICT))
return 0;
return 1;
}
static struct xtables_match rt_mt6_reg = {
.name = "rt",
.version = XTABLES_VERSION,
......@@ -257,6 +294,7 @@ static struct xtables_match rt_mt6_reg = {
.print = rt_print,
.save = rt_save,
.x6_options = rt_opts,
.xlate = rt_xlate,
};
void
......
:INPUT,FORWARD,OUTPUT
-m rt --rt-type 0 --rt-segsleft 1:23 --rt-len 42 --rt-0-res;=;OK
-m rt --rt-type 0 ! --rt-segsleft 1:23 ! --rt-len 42 --rt-0-res;=;OK
-m rt ! --rt-type 1 ! --rt-segsleft 12:23 ! --rt-len 42;=;OK
-m rt;=;OK
......@@ -242,6 +242,51 @@ static void DNAT_save(const void *ip, const struct xt_entry_target *target)
}
}
static void print_range_xlate(const struct nf_nat_ipv4_range *r,
struct xt_xlate *xl)
{
if (r->flags & NF_NAT_RANGE_MAP_IPS) {
struct in_addr a;
a.s_addr = r->min_ip;
xt_xlate_add(xl, "%s", xtables_ipaddr_to_numeric(&a));
if (r->max_ip != r->min_ip) {
a.s_addr = r->max_ip;
xt_xlate_add(xl, "-%s", xtables_ipaddr_to_numeric(&a));
}
}
if (r->flags & NF_NAT_RANGE_PROTO_SPECIFIED) {
xt_xlate_add(xl, ":%hu", ntohs(r->min.tcp.port));
if (r->max.tcp.port != r->min.tcp.port)
xt_xlate_add(xl, "-%hu", ntohs(r->max.tcp.port));
}
}
static int DNAT_xlate(struct xt_xlate *xl,
const struct xt_xlate_tg_params *params)
{
const struct ipt_natinfo *info = (const void *)params->target;
unsigned int i = 0;
bool sep_need = false;
const char *sep = " ";
for (i = 0; i < info->mr.rangesize; i++) {
xt_xlate_add(xl, "dnat to ");
print_range_xlate(&info->mr.range[i], xl);
if (info->mr.range[i].flags & NF_NAT_RANGE_PROTO_RANDOM) {
xt_xlate_add(xl, " random");
sep_need = true;
}
if (info->mr.range[i].flags & NF_NAT_RANGE_PERSISTENT) {
if (sep_need)
sep = ",";
xt_xlate_add(xl, "%spersistent", sep);
}
}
return 1;
}
static struct xtables_target dnat_tg_reg = {
.name = "DNAT",
.version = XTABLES_VERSION,
......@@ -254,6 +299,7 @@ static struct xtables_target dnat_tg_reg = {
.print = DNAT_print,
.save = DNAT_save,
.x6_options = DNAT_opts,
.xlate = DNAT_xlate,
};
void _init(void)
......
:PREROUTING
*nat
-j DNAT --to-destination 1.1.1.1;=;OK
-j DNAT --to-destination 1.1.1.1-1.1.1.10;=;OK
-p tcp -j DNAT --to-destination 1.1.1.1:1025-65535;=;OK
-p tcp -j DNAT --to-destination 1.1.1.1-1.1.1.10:1025-65535;=;OK
-p tcp -j DNAT --to-destination 1.1.1.1-1.1.1.10:1025-65536;;FAIL
-j DNAT;;FAIL
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