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

New upstream version 1.8.1

parent f1f129da
iptables-translate -t filter -A INPUT -j AUDIT --type accept
nft add rule ip filter INPUT counter log level audit
iptables-translate -t filter -A INPUT -j AUDIT --type drop
nft add rule ip filter INPUT counter log level audit
iptables-translate -t filter -A INPUT -j AUDIT --type reject
nft add rule ip filter INPUT counter log level audit
iptables-translate -A OUTPUT -j CLASSIFY --set-class 0:0
nft add rule ip filter OUTPUT counter meta priority set none
iptables-translate -A OUTPUT -j CLASSIFY --set-class ffff:ffff
nft add rule ip filter OUTPUT counter meta priority set root
iptables-translate -A OUTPUT -j CLASSIFY --set-class 1:234
nft add rule ip filter OUTPUT counter meta priority set 1:234
......@@ -31,6 +31,11 @@ struct xt_connmark_target_info {
uint8_t mode;
};
enum {
D_SHIFT_LEFT = 0,
D_SHIFT_RIGHT,
};
enum {
O_SET_MARK = 0,
O_SAVE_MARK,
......@@ -38,6 +43,8 @@ enum {
O_AND_MARK,
O_OR_MARK,
O_XOR_MARK,
O_LEFT_SHIFT_MARK,
O_RIGHT_SHIFT_MARK,
O_SET_XMARK,
O_CTMASK,
O_NFMASK,
......@@ -48,6 +55,8 @@ enum {
F_AND_MARK = 1 << O_AND_MARK,
F_OR_MARK = 1 << O_OR_MARK,
F_XOR_MARK = 1 << O_XOR_MARK,
F_LEFT_SHIFT_MARK = 1 << O_LEFT_SHIFT_MARK,
F_RIGHT_SHIFT_MARK = 1 << O_RIGHT_SHIFT_MARK,
F_SET_XMARK = 1 << O_SET_XMARK,
F_CTMASK = 1 << O_CTMASK,
F_NFMASK = 1 << O_NFMASK,
......@@ -56,6 +65,11 @@ enum {
F_AND_MARK | F_OR_MARK | F_XOR_MARK | F_SET_XMARK,
};
static const char *const xt_connmark_shift_ops[] = {
"left-shift-mark",
"right-shift-mark"
};
static void CONNMARK_help(void)
{
printf(
......@@ -104,6 +118,36 @@ static const struct xt_option_entry connmark_tg_opts[] = {
};
#undef s
#define s struct xt_connmark_tginfo2
static const struct xt_option_entry connmark_tg_opts_v2[] = {
{.name = "set-xmark", .id = O_SET_XMARK, .type = XTTYPE_MARKMASK32,
.excl = F_OP_ANY},
{.name = "set-mark", .id = O_SET_MARK, .type = XTTYPE_MARKMASK32,
.excl = F_OP_ANY},
{.name = "and-mark", .id = O_AND_MARK, .type = XTTYPE_UINT32,
.excl = F_OP_ANY},
{.name = "or-mark", .id = O_OR_MARK, .type = XTTYPE_UINT32,
.excl = F_OP_ANY},
{.name = "xor-mark", .id = O_XOR_MARK, .type = XTTYPE_UINT32,
.excl = F_OP_ANY},
{.name = "save-mark", .id = O_SAVE_MARK, .type = XTTYPE_NONE,
.excl = F_OP_ANY},
{.name = "restore-mark", .id = O_RESTORE_MARK, .type = XTTYPE_NONE,
.excl = F_OP_ANY},
{.name = "left-shift-mark", .id = O_LEFT_SHIFT_MARK, .type = XTTYPE_UINT8,
.min = 0, .max = 32},
{.name = "right-shift-mark", .id = O_RIGHT_SHIFT_MARK, .type = XTTYPE_UINT8,
.min = 0, .max = 32},
{.name = "ctmask", .id = O_CTMASK, .type = XTTYPE_UINT32,
.excl = F_MASK, .flags = XTOPT_PUT, XTOPT_POINTER(s, ctmask)},
{.name = "nfmask", .id = O_NFMASK, .type = XTTYPE_UINT32,
.excl = F_MASK, .flags = XTOPT_PUT, XTOPT_POINTER(s, nfmask)},
{.name = "mask", .id = O_MASK, .type = XTTYPE_UINT32,
.excl = F_CTMASK | F_NFMASK},
XTOPT_TABLEEND,
};
#undef s
static void connmark_tg_help(void)
{
printf(
......@@ -122,6 +166,15 @@ static void connmark_tg_help(void)
);
}
static void connmark_tg_help_v2(void)
{
connmark_tg_help();
printf(
" --left-shift-mark value Left shift the ctmark with bits\n"
" --right-shift-mark value Right shift the ctmark with bits\n"
);
}
static void connmark_tg_init(struct xt_entry_target *target)
{
struct xt_connmark_tginfo1 *info = (void *)target->data;
......@@ -134,6 +187,18 @@ static void connmark_tg_init(struct xt_entry_target *target)
info->nfmask = UINT32_MAX;
}
static void connmark_tg_init_v2(struct xt_entry_target *target)
{
struct xt_connmark_tginfo2 *info;
connmark_tg_init(target);
info = (void *)target->data;
/* Left shift by zero bit by default. */
info->shift_dir = D_SHIFT_LEFT;
info->shift_bits = 0;
}
static void CONNMARK_parse(struct xt_option_call *cb)
{
struct xt_connmark_target_info *markinfo = cb->data;
......@@ -197,6 +262,61 @@ static void connmark_tg_parse(struct xt_option_call *cb)
case O_MASK:
info->nfmask = info->ctmask = cb->val.u32;
break;
default:
break;
}
}
static void connmark_tg_parse_v2(struct xt_option_call *cb)
{
struct xt_connmark_tginfo2 *info = cb->data;
xtables_option_parse(cb);
switch (cb->entry->id) {
case O_SET_XMARK:
info->mode = XT_CONNMARK_SET;
info->ctmark = cb->val.mark;
info->ctmask = cb->val.mask;
break;
case O_SET_MARK:
info->mode = XT_CONNMARK_SET;
info->ctmark = cb->val.mark;
info->ctmask = cb->val.mark | cb->val.mask;
break;
case O_AND_MARK:
info->mode = XT_CONNMARK_SET;
info->ctmark = 0;
info->ctmask = ~cb->val.u32;
break;
case O_OR_MARK:
info->mode = XT_CONNMARK_SET;
info->ctmark = cb->val.u32;
info->ctmask = cb->val.u32;
break;
case O_XOR_MARK:
info->mode = XT_CONNMARK_SET;
info->ctmark = cb->val.u32;
info->ctmask = 0;
break;
case O_SAVE_MARK:
info->mode = XT_CONNMARK_SAVE;
break;
case O_RESTORE_MARK:
info->mode = XT_CONNMARK_RESTORE;
break;
case O_MASK:
info->nfmask = info->ctmask = cb->val.u32;
break;
case O_LEFT_SHIFT_MARK:
info->shift_dir = D_SHIFT_LEFT;
info->shift_bits = cb->val.u8;
break;
case O_RIGHT_SHIFT_MARK:
info->shift_dir = D_SHIFT_RIGHT;
info->shift_bits = cb->val.u8;
break;
default:
break;
}
}
......@@ -291,6 +411,58 @@ connmark_tg_print(const void *ip, const struct xt_entry_target *target,
}
}
static void
connmark_tg_print_v2(const void *ip, const struct xt_entry_target *target,
int numeric)
{
const struct xt_connmark_tginfo2 *info = (const void *)target->data;
const char *shift_op = xt_connmark_shift_ops[info->shift_dir];
switch (info->mode) {
case XT_CONNMARK_SET:
if (info->ctmark == 0)
printf(" CONNMARK and 0x%x",
(unsigned int)(uint32_t)~info->ctmask);
else if (info->ctmark == info->ctmask)
printf(" CONNMARK or 0x%x", info->ctmark);
else if (info->ctmask == 0)
printf(" CONNMARK xor 0x%x", info->ctmark);
else if (info->ctmask == 0xFFFFFFFFU)
printf(" CONNMARK set 0x%x", info->ctmark);
else
printf(" CONNMARK xset 0x%x/0x%x",
info->ctmark, info->ctmask);
break;
case XT_CONNMARK_SAVE:
if (info->nfmask == UINT32_MAX && info->ctmask == UINT32_MAX)
printf(" CONNMARK save");
else if (info->nfmask == info->ctmask)
printf(" CONNMARK save mask 0x%x", info->nfmask);
else
printf(" CONNMARK save nfmask 0x%x ctmask ~0x%x",
info->nfmask, info->ctmask);
break;
case XT_CONNMARK_RESTORE:
if (info->ctmask == UINT32_MAX && info->nfmask == UINT32_MAX)
printf(" CONNMARK restore");
else if (info->ctmask == info->nfmask)
printf(" CONNMARK restore mask 0x%x", info->ctmask);
else
printf(" CONNMARK restore ctmask 0x%x nfmask ~0x%x",
info->ctmask, info->nfmask);
break;
default:
printf(" ERROR: UNKNOWN CONNMARK MODE");
break;
}
if (info->mode <= XT_CONNMARK_RESTORE &&
info->shift_bits != 0) {
printf(" %s %u", shift_op, info->shift_bits);
}
}
static void CONNMARK_save(const void *ip, const struct xt_entry_target *target)
{
const struct xt_connmark_target_info *markinfo =
......@@ -347,6 +519,35 @@ connmark_tg_save(const void *ip, const struct xt_entry_target *target)
}
}
static void
connmark_tg_save_v2(const void *ip, const struct xt_entry_target *target)
{
const struct xt_connmark_tginfo2 *info = (const void *)target->data;
const char *shift_op = xt_connmark_shift_ops[info->shift_dir];
switch (info->mode) {
case XT_CONNMARK_SET:
printf(" --set-xmark 0x%x/0x%x", info->ctmark, info->ctmask);
break;
case XT_CONNMARK_SAVE:
printf(" --save-mark --nfmask 0x%x --ctmask 0x%x",
info->nfmask, info->ctmask);
break;
case XT_CONNMARK_RESTORE:
printf(" --restore-mark --nfmask 0x%x --ctmask 0x%x",
info->nfmask, info->ctmask);
break;
default:
printf(" ERROR: UNKNOWN CONNMARK MODE");
break;
}
if (info->mode <= XT_CONNMARK_RESTORE &&
info->shift_bits != 0) {
printf(" --%s %u", shift_op, info->shift_bits);
}
}
static int connmark_tg_xlate(struct xt_xlate *xl,
const struct xt_xlate_tg_params *params)
{
......@@ -356,7 +557,9 @@ static int connmark_tg_xlate(struct xt_xlate *xl,
switch (info->mode) {
case XT_CONNMARK_SET:
xt_xlate_add(xl, "ct mark set ");
if (info->ctmark == 0)
if (info->ctmask == 0xFFFFFFFFU)
xt_xlate_add(xl, "0x%x ", info->ctmark);
else if (info->ctmark == 0)
xt_xlate_add(xl, "ct mark and 0x%x", ~info->ctmask);
else if (info->ctmark == info->ctmask)
xt_xlate_add(xl, "ct mark or 0x%x",
......@@ -364,8 +567,49 @@ static int connmark_tg_xlate(struct xt_xlate *xl,
else if (info->ctmask == 0)
xt_xlate_add(xl, "ct mark xor 0x%x",
info->ctmark);
else if (info->ctmask == 0xFFFFFFFFU)
else
xt_xlate_add(xl, "ct mark xor 0x%x and 0x%x",
info->ctmark, ~info->ctmask);
break;
case XT_CONNMARK_SAVE:
if (info->nfmask == info->ctmask &&
info->nfmask == UINT32_MAX)
xt_xlate_add(xl, "ct mark set mark");
else
return 0;
break;
case XT_CONNMARK_RESTORE:
if (info->nfmask == info->ctmask &&
info->nfmask == UINT32_MAX)
xt_xlate_add(xl, "meta mark set ct mark");
else
return 0;
break;
}
return 1;
}
static int connmark_tg_xlate_v2(struct xt_xlate *xl,
const struct xt_xlate_tg_params *params)
{
const struct xt_connmark_tginfo2 *info =
(const void *)params->target->data;
const char *shift_op = xt_connmark_shift_ops[info->shift_dir];
switch (info->mode) {
case XT_CONNMARK_SET:
xt_xlate_add(xl, "ct mark set ");
if (info->ctmask == 0xFFFFFFFFU)
xt_xlate_add(xl, "0x%x ", info->ctmark);
else if (info->ctmark == 0)
xt_xlate_add(xl, "ct mark and 0x%x", ~info->ctmask);
else if (info->ctmark == info->ctmask)
xt_xlate_add(xl, "ct mark or 0x%x",
info->ctmark);
else if (info->ctmask == 0)
xt_xlate_add(xl, "ct mark xor 0x%x",
info->ctmark);
else
xt_xlate_add(xl, "ct mark xor 0x%x and 0x%x",
info->ctmark, ~info->ctmask);
......@@ -388,9 +632,13 @@ static int connmark_tg_xlate(struct xt_xlate *xl,
break;
}
if (info->mode <= XT_CONNMARK_RESTORE &&
info->shift_bits != 0) {
xt_xlate_add(xl, " %s %u", shift_op, info->shift_bits);
}
return 1;
}
static struct xtables_target connmark_tg_reg[] = {
{
.family = NFPROTO_UNSPEC,
......@@ -423,6 +671,22 @@ static struct xtables_target connmark_tg_reg[] = {
.x6_options = connmark_tg_opts,
.xlate = connmark_tg_xlate,
},
{
.version = XTABLES_VERSION,
.name = "CONNMARK",
.revision = 2,
.family = NFPROTO_UNSPEC,
.size = XT_ALIGN(sizeof(struct xt_connmark_tginfo2)),
.userspacesize = XT_ALIGN(sizeof(struct xt_connmark_tginfo2)),
.help = connmark_tg_help_v2,
.init = connmark_tg_init_v2,
.print = connmark_tg_print_v2,
.save = connmark_tg_save_v2,
.x6_parse = connmark_tg_parse_v2,
.x6_fcheck = connmark_tg_check,
.x6_options = connmark_tg_opts_v2,
.xlate = connmark_tg_xlate_v2,
},
};
void _init(void)
......
iptables-translate -t mangle -A PREROUTING -j CONNMARK --set-mark 0
nft add rule ip mangle PREROUTING counter ct mark set 0x0
iptables-translate -t mangle -A PREROUTING -j CONNMARK --set-mark 0x16
nft add rule ip mangle PREROUTING counter ct mark set 0x16
iptables-translate -t mangle -A PREROUTING -j CONNMARK --set-xmark 0x16/0x12
nft add rule ip mangle PREROUTING counter ct mark set ct mark xor 0x16 and 0xffffffed
iptables-translate -t mangle -A PREROUTING -j CONNMARK --and-mark 0x16
nft add rule ip mangle PREROUTING counter ct mark set ct mark and 0x16
iptables-translate -t mangle -A PREROUTING -j CONNMARK --or-mark 0x16
nft add rule ip mangle PREROUTING counter ct mark set ct mark or 0x16
iptables-translate -t mangle -A PREROUTING -j CONNMARK --save-mark
nft add rule ip mangle PREROUTING counter ct mark set mark
iptables-translate -t mangle -A PREROUTING -j CONNMARK --restore-mark
nft add rule ip mangle PREROUTING counter meta mark set ct mark
iptables-translate -A OUTPUT -j DSCP --set-dscp 1
nft add rule ip filter OUTPUT counter ip dscp set 0x01
ip6tables-translate -A OUTPUT -j DSCP --set-dscp 6
nft add rule ip6 filter OUTPUT counter ip6 dscp set 0x06
......@@ -53,8 +53,7 @@ static void LED_parse(struct xt_option_call *cb)
xtables_option_parse(cb);
switch (cb->entry->id) {
case O_LED_TRIGGER_ID:
strcpy(led->id, "netfilter-");
strcat(led->id, cb->arg);
snprintf(led->id, sizeof(led->id), "netfilter-%s", cb->arg);
break;
case O_LED_DELAY:
if (strncasecmp(cb->arg, "inf", 3) == 0)
......
......@@ -76,7 +76,7 @@ static void mark_tg_help(void)
" --set-mark value[/mask] Clear bits in mask and OR value into nfmark\n"
" --and-mark bits Binary AND the nfmark with bits\n"
" --or-mark bits Binary OR the nfmark with bits\n"
" --xor-mask bits Binary XOR the nfmark with bits\n"
" --xor-mark bits Binary XOR the nfmark with bits\n"
"\n");
}
......@@ -252,14 +252,14 @@ static int mark_tg_xlate(struct xt_xlate *xl,
xt_xlate_add(xl, "meta mark set ");
if (info->mark == 0)
if (info->mask == 0xffffffffU)
xt_xlate_add(xl, "0x%x ", info->mark);
else if (info->mark == 0)
xt_xlate_add(xl, "mark and 0x%x ", ~info->mask);
else if (info->mark == info->mask)
xt_xlate_add(xl, "mark or 0x%x ", info->mark);
else if (info->mask == 0)
xt_xlate_add(xl, "mark xor 0x%x ", info->mark);
else if (info->mask == 0xffffffffU)
xt_xlate_add(xl, "0x%x ", info->mark);
else
xt_xlate_add(xl, "mark and 0x%x xor 0x%x ", ~info->mask,
info->mark);
......
iptables-translate -t mangle -A OUTPUT -j MARK --set-mark 0
nft add rule ip mangle OUTPUT counter meta mark set 0x0
iptables-translate -t mangle -A OUTPUT -j MARK --set-mark 64
nft add rule ip mangle OUTPUT counter meta mark set 0x40
iptables-translate -t mangle -A OUTPUT -j MARK --set-xmark 0x40/0x32
nft add rule ip mangle OUTPUT counter meta mark set mark and 0xffffffcd xor 0x40
iptables-translate -t mangle -A OUTPUT -j MARK --or-mark 64
nft add rule ip mangle OUTPUT counter meta mark set mark or 0x40
iptables-translate -t mangle -A OUTPUT -j MARK --and-mark 64
nft add rule ip mangle OUTPUT counter meta mark set mark and 0x40
iptables-translate -t mangle -A OUTPUT -j MARK --xor-mark 64
nft add rule ip mangle OUTPUT counter meta mark set mark xor 0x40
iptables-translate -t mangle -A PREROUTING -j MARK --set-mark 0x64
nft add rule ip mangle PREROUTING counter meta mark set 0x64
iptables-translate -t mangle -A PREROUTING -j MARK --and-mark 0x64
nft add rule ip mangle PREROUTING counter meta mark set mark and 0x64
iptables-translate -t mangle -A PREROUTING -j MARK --or-mark 0x64
nft add rule ip mangle PREROUTING counter meta mark set mark or 0x64
......@@ -25,4 +25,10 @@ If option
\fB\-\-random\fP
is used then port mapping will be randomized (kernel >= 2.6.21).
.TP
\fB\-\-random-fully\fP
Full randomize source port mapping
If option
\fB\-\-random-fully\fP
is used then port mapping will be fully randomized (kernel >= 3.13).
.TP
IPv6 support available since Linux kernels >= 3.7.
iptables-translate -A FORWARD -j NFLOG --nflog-group 32 --nflog-prefix "Prefix 1.0"
nft add rule ip filter FORWARD counter log prefix \"Prefix 1.0\" group 32
iptables-translate -A OUTPUT -j NFLOG --nflog-group 30
nft add rule ip filter OUTPUT counter log group 30
iptables-translate -I INPUT -j NFLOG --nflog-threshold 2
nft insert rule ip filter INPUT counter log queue-threshold 2 group 0
iptables-translate -I INPUT -j NFLOG --nflog-size 256
nft insert rule ip filter INPUT counter log snaplen 256 group 0
iptables-translate -I INPUT -j NFLOG --nflog-threshold 25
nft insert rule ip filter INPUT counter log queue-threshold 25 group 0
iptables-translate -t nat -A PREROUTING -p tcp --dport 80 -j NFQUEUE --queue-num 30
nft add rule ip nat PREROUTING tcp dport 80 counter queue num 30
iptables-translate -A FORWARD -j NFQUEUE --queue-num 0 --queue-bypass -p TCP --sport 80
nft add rule ip filter FORWARD tcp sport 80 counter queue num 0 bypass
iptables-translate -A FORWARD -j NFQUEUE --queue-bypass -p TCP --sport 80 --queue-balance 0:3 --queue-cpu-fanout
nft add rule ip filter FORWARD tcp sport 80 counter queue num 0-3 bypass,fanout
......@@ -91,6 +91,19 @@ static void TCPMSS_save(const void *ip, const struct xt_entry_target *target)
printf(" --set-mss %u", mssinfo->mss);
}
static int TCPMSS_xlate(struct xt_xlate *xl,
const struct xt_xlate_tg_params *params)
{
const struct xt_tcpmss_info *mssinfo =
(const struct xt_tcpmss_info *)params->target->data;
if (mssinfo->mss == XT_TCPMSS_CLAMP_PMTU)
xt_xlate_add(xl, "tcp option maxseg size set rt mtu");
else
xt_xlate_add(xl, "tcp option maxseg size set %d", mssinfo->mss);
return 1;
}
static struct xtables_target tcpmss_tg_reg[] = {
{
.family = NFPROTO_IPV4,
......@@ -104,6 +117,7 @@ static struct xtables_target tcpmss_tg_reg[] = {
.x6_parse = TCPMSS_parse,
.x6_fcheck = TCPMSS_check,
.x6_options = TCPMSS4_opts,
.xlate = TCPMSS_xlate,
},
{
.family = NFPROTO_IPV6,
......
iptables-translate -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu
nft add rule ip filter FORWARD tcp flags & (syn|rst) == syn counter tcp option maxseg size set rt mtu
iptables-translate -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --set-mss 90
nft add rule ip filter FORWARD tcp flags & (syn|rst) == syn counter tcp option maxseg size set 90
# iptables-translate -t mangle -A PREROUTING -j TEE --gateway 192.168.0.2 --oif eth0
# nft add rule ip mangle PREROUTING counter dup to 192.168.0.2 device eth0
#
# iptables-translate -t mangle -A PREROUTING -j TEE --gateway 192.168.0.2
# nft add rule ip mangle PREROUTING counter dup to 192.168.0.2
ip6tables-translate -t mangle -A PREROUTING -j TEE --gateway ab12:00a1:1112:acba::
nft add rule ip6 mangle PREROUTING counter dup to ab12:a1:1112:acba::
ip6tables-translate -t mangle -A PREROUTING -j TEE --gateway ab12:00a1:1112:acba:: --oif eth0
nft add rule ip6 mangle PREROUTING counter dup to ab12:a1:1112:acba:: device eth0
......@@ -183,6 +183,30 @@ static void tos_tg_save(const void *ip, const struct xt_entry_target *target)
printf(" --set-tos 0x%02x/0x%02x", info->tos_value, info->tos_mask);
}
static int tos_xlate(struct xt_xlate *xl,
const struct xt_xlate_tg_params *params)
{
const struct ipt_tos_target_info *info =
(struct ipt_tos_target_info *) params->target->data;
uint8_t dscp = info->tos >> 2;
xt_xlate_add(xl, "ip dscp set 0x%02x", dscp);
return 1;
}
static int tos_xlate6(struct xt_xlate *xl,
const struct xt_xlate_tg_params *params)
{
const struct ipt_tos_target_info *info =
(struct ipt_tos_target_info *) params->target->data;
uint8_t dscp = info->tos >> 2;
xt_xlate_add(xl, "ip6 dscp set 0x%02x", dscp);
return 1;
}
static struct xtables_target tos_tg_reg[] = {
{
.version = XTABLES_VERSION,
......@@ -197,6 +221,7 @@ static struct xtables_target tos_tg_reg[] = {
.x6_parse = tos_tg_parse_v0,
.x6_fcheck = tos_tg_check,
.x6_options = tos_tg_opts_v0,
.xlate = tos_xlate,
},
{
.version = XTABLES_VERSION,
......@@ -211,6 +236,7 @@ static struct xtables_target tos_tg_reg[] = {
.x6_parse = tos_tg_parse,
.x6_fcheck = tos_tg_check,
.x6_options = tos_tg_opts,
.xlate = tos_xlate6,
},
};
......
ip6tables-translate -A INPUT -j TOS --set-tos 0x1f
nft add rule ip6 filter INPUT counter ip6 dscp set 0x07
ip6tables-translate -A INPUT -j TOS --set-tos 0xff
nft add rule ip6 filter INPUT counter ip6 dscp set 0x3f
ip6tables-translate -A INPUT -j TOS --set-tos Minimize-Delay
nft add rule ip6 filter INPUT counter ip6 dscp set 0x04
ip6tables-translate -A INPUT -j TOS --set-tos Minimize-Cost
nft add rule ip6 filter INPUT counter ip6 dscp set 0x00
ip6tables-translate -A INPUT -j TOS --set-tos Normal-Service
nft add rule ip6 filter INPUT counter ip6 dscp set 0x00
ip6tables-translate -A INPUT -j TOS --and-tos 0x12
nft add rule ip6 filter INPUT counter ip6 dscp set 0x00
ip6tables-translate -A INPUT -j TOS --or-tos 0x12
nft add rule ip6 filter INPUT counter ip6 dscp set 0x04
ip6tables-translate -A INPUT -j TOS --xor-tos 0x12
nft add rule ip6 filter INPUT counter ip6 dscp set 0x04
iptables-translate -t raw -A PREROUTING -j TRACE
nft add rule ip raw PREROUTING counter nftrace set 1
......@@ -245,6 +245,74 @@ static void addrtype_save_v1(const void *ip, const struct xt_entry_match *match)
printf(" --limit-iface-out");
}
static const char *const rtn_lnames[] = {
"unspec",
"unicast",
"local",
"broadcast",
"anycast",
"multicast",
"blackhole",
"unreachable",
"prohibit",
NULL,
};
static bool multiple_bits_set(uint16_t val)
{
int first = ffs(val);
return first && (val >> first) > 0;
}
static int addrtype_xlate(struct xt_xlate *xl,
const struct xt_xlate_mt_params *params)
{
const struct xt_addrtype_info_v1 *info =
(const void *)params->match->data;
const char *sep = "";
bool need_braces;
uint16_t val;
int i;
xt_xlate_add(xl, "fib ");
if (info->source) {
xt_xlate_add(xl, "saddr ");
val = info->source;
} else {
xt_xlate_add(xl, "daddr ");
val = info->dest;
}
if (info->flags & XT_ADDRTYPE_LIMIT_IFACE_IN)
xt_xlate_add(xl, ". iif ");
else if (info->flags & XT_ADDRTYPE_LIMIT_IFACE_OUT)
xt_xlate_add(xl, ". oif ");
xt_xlate_add(xl, "type ");
if (info->flags & (XT_ADDRTYPE_INVERT_SOURCE | XT_ADDRTYPE_INVERT_DEST))
xt_xlate_add(xl, "!= ");
need_braces = multiple_bits_set(val);
if (need_braces)
xt_xlate_add(xl, "{ ");
for (i = 0; rtn_lnames[i]; i++) {
if (val & (1 << i)) {
xt_xlate_add(xl, "%s%s", sep, rtn_lnames[i]);
sep = ", ";
}
}
if (need_braces)
xt_xlate_add(xl, " }");
return 1;
}
static const struct xt_option_entry addrtype_opts_v0[] = {
{.name = "src-type", .id = O_SRC_TYPE, .type = XTTYPE_STRING,
.flags = XTOPT_INVERT},
......@@ -292,6 +360,7 @@ static struct xtables_match addrtype_mt_reg[] = {
.x6_parse = addrtype_parse_v1,
.x6_fcheck = addrtype_check,
.x6_options = addrtype_opts_v1,
.xlate = addrtype_xlate,
},
};
......
iptables-translate -A INPUT -m addrtype --src-type LOCAL
nft add rule ip filter INPUT fib saddr type local counter
iptables-translate -A INPUT -m addrtype --dst-type LOCAL
nft add rule ip filter INPUT fib daddr type local counter
iptables-translate -A INPUT -m addrtype ! --dst-type ANYCAST,LOCAL
nft add rule ip filter INPUT fib daddr type != { local, anycast } counter
iptables-translate -A INPUT -m addrtype --limit-iface-in --dst-type ANYCAST,LOCAL
nft add rule ip filter INPUT fib daddr . iif type { local, anycast } counter
......@@ -22,6 +22,9 @@
#include <linux/bpf.h>
#endif
#include <linux/magic.h>
#include <linux/unistd.h>
#define BCODE_FILE_MAX_LEN_B 1024
enum {
......@@ -60,7 +63,7 @@ static const struct xt_option_entry bpf_opts_v1[] = {
static int bpf_obj_get(const char *filepath)
{
#if defined HAVE_LINUX_BPF_H && defined __NR_bpf
#if defined HAVE_LINUX_BPF_H && defined __NR_bpf && defined BPF_FS_MAGIC
union bpf_attr attr;
memset(&attr, 0, sizeof(attr));
......
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