Commit 706c32c9 authored by Arturo Borrero Gonzalez's avatar Arturo Borrero Gonzalez
Browse files

Update upstream source from tag 'upstream/1.6.2'

Update to upstream version '1.6.2'
with Debian dir 709e57568379856beca5301ab2678ceffca94a99
parents a82b926a 5beab31f
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) ...@@ -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); 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[] = { static struct xtables_target tos_tg_reg[] = {
{ {
.version = XTABLES_VERSION, .version = XTABLES_VERSION,
...@@ -197,6 +221,7 @@ static struct xtables_target tos_tg_reg[] = { ...@@ -197,6 +221,7 @@ static struct xtables_target tos_tg_reg[] = {
.x6_parse = tos_tg_parse_v0, .x6_parse = tos_tg_parse_v0,
.x6_fcheck = tos_tg_check, .x6_fcheck = tos_tg_check,
.x6_options = tos_tg_opts_v0, .x6_options = tos_tg_opts_v0,
.xlate = tos_xlate,
}, },
{ {
.version = XTABLES_VERSION, .version = XTABLES_VERSION,
...@@ -211,6 +236,7 @@ static struct xtables_target tos_tg_reg[] = { ...@@ -211,6 +236,7 @@ static struct xtables_target tos_tg_reg[] = {
.x6_parse = tos_tg_parse, .x6_parse = tos_tg_parse,
.x6_fcheck = tos_tg_check, .x6_fcheck = tos_tg_check,
.x6_options = tos_tg_opts, .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) ...@@ -245,6 +245,74 @@ static void addrtype_save_v1(const void *ip, const struct xt_entry_match *match)
printf(" --limit-iface-out"); 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[] = { static const struct xt_option_entry addrtype_opts_v0[] = {
{.name = "src-type", .id = O_SRC_TYPE, .type = XTTYPE_STRING, {.name = "src-type", .id = O_SRC_TYPE, .type = XTTYPE_STRING,
.flags = XTOPT_INVERT}, .flags = XTOPT_INVERT},
...@@ -292,6 +360,7 @@ static struct xtables_match addrtype_mt_reg[] = { ...@@ -292,6 +360,7 @@ static struct xtables_match addrtype_mt_reg[] = {
.x6_parse = addrtype_parse_v1, .x6_parse = addrtype_parse_v1,
.x6_fcheck = addrtype_check, .x6_fcheck = addrtype_check,
.x6_options = addrtype_opts_v1, .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,8 @@ ...@@ -22,6 +22,8 @@
#include <linux/bpf.h> #include <linux/bpf.h>
#endif #endif
#include <linux/unistd.h>
#define BCODE_FILE_MAX_LEN_B 1024 #define BCODE_FILE_MAX_LEN_B 1024
enum { enum {
......
iptables-translate -t filter -A INPUT -m cgroup --cgroup 0 -j ACCEPT
nft add rule ip filter INPUT meta cgroup 0 counter accept
iptables-translate -t filter -A INPUT -m cgroup ! --cgroup 0 -j ACCEPT
nft add rule ip filter INPUT meta cgroup != 0 counter accept
...@@ -126,6 +126,56 @@ cluster_save(const void *ip, const struct xt_entry_match *match) ...@@ -126,6 +126,56 @@ cluster_save(const void *ip, const struct xt_entry_match *match)
info->total_nodes, info->hash_seed); info->total_nodes, info->hash_seed);
} }
static int cluster_xlate(struct xt_xlate *xl,
const struct xt_xlate_mt_params *params)
{
int node, shift_value = 1, comma_needed = 0;
uint32_t temp_node_mask, node_id = 0, needs_set = 0;
const struct xt_cluster_match_info *info = (void *)params->match->data;
const char *jhash_st = "jhash ct original saddr mod";
const char *pkttype_st = "meta pkttype set host";
if (!(info->node_mask & (info->node_mask - 1))) {
if (info->node_mask <= 2)
xt_xlate_add(xl, "%s %u seed 0x%08x eq %u %s", jhash_st,
info->total_nodes, info->hash_seed,
info->node_mask, pkttype_st);
else {
temp_node_mask = info->node_mask;
while (1) {
temp_node_mask = temp_node_mask >> shift_value;
node_id++;
if (temp_node_mask == 0)
break;
}
xt_xlate_add(xl, "%s %u seed 0x%08x eq %u %s", jhash_st,
info->total_nodes, info->hash_seed,
node_id, pkttype_st);
}
} else {
xt_xlate_add(xl, "%s %u seed 0x%08x ", jhash_st,
info->total_nodes, info->hash_seed);
for (node = 0; node < 32; node++) {
if (info->node_mask & (1 << node)) {
if (needs_set == 0) {
xt_xlate_add(xl, "{ ");
needs_set = 1;
}
if (comma_needed)
xt_xlate_add(xl, ", ");
xt_xlate_add(xl, "%u", node);
comma_needed++;
}
}
if (needs_set)
xt_xlate_add(xl, " }");
xt_xlate_add(xl, " %s", pkttype_st);
}
return 1;
}
static struct xtables_match cluster_mt_reg = { static struct xtables_match cluster_mt_reg = {
.family = NFPROTO_UNSPEC, .family = NFPROTO_UNSPEC,
.name = "cluster", .name = "cluster",
...@@ -138,6 +188,7 @@ static struct xtables_match cluster_mt_reg = { ...@@ -138,6 +188,7 @@ static struct xtables_match cluster_mt_reg = {
.x6_parse = cluster_parse, .x6_parse = cluster_parse,
.x6_fcheck = cluster_check, .x6_fcheck = cluster_check,
.x6_options = cluster_opts, .x6_options = cluster_opts,
.xlate = cluster_xlate,
}; };
void _init(void) void _init(void)
......
iptables-translate -A PREROUTING -t mangle -i eth1 -m cluster --cluster-total-nodes 2 --cluster-local-node 1 --cluster-hash-seed 0xdeadbeef -j MARK --set-mark 0xffff
nft add rule ip mangle PREROUTING iifname eth1 jhash ct original saddr mod 2 seed 0xdeadbeef eq 1 meta pkttype set host counter meta mark set 0xffff
iptables-translate -A PREROUTING -t mangle -i eth1 -m cluster --cluster-total-nodes 1 --cluster-local-node 1 --cluster-hash-seed 0xdeadbeef -j MARK --set-mark 0xffff
nft add rule ip mangle PREROUTING iifname eth1 jhash ct original saddr mod 1 seed 0xdeadbeef eq 1 meta pkttype set host counter meta mark set 0xffff
iptables-translate -A PREROUTING -t mangle -i eth1 -m cluster --cluster-total-nodes 2 --cluster-local-nodemask 1 --cluster-hash-seed 0xdeadbeef -j MARK --set-mark 0xffff
nft add rule ip mangle PREROUTING iifname eth1 jhash ct original saddr mod 2 seed 0xdeadbeef eq 1 meta pkttype set host counter meta mark set 0xffff
iptables-translate -A PREROUTING -t mangle -i eth1 -m cluster --cluster-total-nodes 1 --cluster-local-nodemask 1 --cluster-hash-seed 0xdeadbeef -j MARK --set-mark 0xffff
nft add rule ip mangle PREROUTING iifname eth1 jhash ct original saddr mod 1 seed 0xdeadbeef eq 1 meta pkttype set host counter meta mark set 0xffff
iptables-translate -A PREROUTING -t mangle -i eth1 -m cluster --cluster-total-nodes 32 --cluster-local-node 32 --cluster-hash-seed 0xdeadbeef -j MARK --set-mark 0xffff
nft add rule ip mangle PREROUTING iifname eth1 jhash ct original saddr mod 32 seed 0xdeadbeef eq 32 meta pkttype set host counter meta mark set 0xffff
iptables-translate -A PREROUTING -t mangle -i eth1 -m cluster --cluster-total-nodes 32 --cluster-local-nodemask 32 --cluster-hash-seed 0xdeadbeef -j MARK --set-mark 0xffff
nft add rule ip mangle PREROUTING iifname eth1 jhash ct original saddr mod 32 seed 0xdeadbeef eq 6 meta pkttype set host counter meta mark set 0xffff
iptables-translate -A PREROUTING -t mangle -i eth1 -m cluster --cluster-total-nodes 32 --cluster-local-nodemask 5 --cluster-hash-seed 0xdeadbeef -j MARK --set-mark 0xffff
nft add rule ip mangle PREROUTING iifname eth1 jhash ct original saddr mod 32 seed 0xdeadbeef { 0, 2 } meta pkttype set host counter meta mark set 0xffff
iptables-translate -A PREROUTING -t mangle -i eth1 -m cluster --cluster-total-nodes 7 --cluster-local-nodemask 9 --cluster-hash-seed 0xdeadbeef -j MARK --set-mark 0xffff
nft add rule ip mangle PREROUTING iifname eth1 jhash ct original saddr mod 7 seed 0xdeadbeef { 0, 3 } meta pkttype set host counter meta mark set 0xffff
iptables-translate -A PREROUTING -t mangle -i eth1 -m cluster --cluster-total-nodes 7 --cluster-local-node 5 --cluster-hash-seed 0xdeadbeef -j MARK --set-mark 0xffff
nft add rule ip mangle PREROUTING iifname eth1 jhash ct original saddr mod 7 seed 0xdeadbeef eq 5 meta pkttype set host counter meta mark set 0xffff
iptables-translate -A INPUT -s 192.168.0.0 -m comment --comment "A privatized IP block"
nft add rule ip filter INPUT ip saddr 192.168.0.0 counter comment \"A privatized IP block\"
iptables-translate -A INPUT -p tcp -m tcp --sport http -s 192.168.0.0/16 -d 192.168.0.0/16 -j LONGNACCEPT -m comment --comment "foobar"
nft add rule ip filter INPUT ip saddr 192.168.0.0/16 ip daddr 192.168.0.0/16 tcp sport 80 counter jump LONGNACCEPT comment \"foobar\"
iptables-translate -A FORWARD -p tcp -m tcp --sport http -s 192.168.0.0/16 -d 192.168.0.0/16 -j DROP -m comment --comment singlecomment
nft add rule ip filter FORWARD ip saddr 192.168.0.0/16 ip daddr 192.168.0.0/16 tcp sport 80 counter drop comment \"singlecomment\"
iptables-translate -A OUTPUT -m connbytes --connbytes 200 --connbytes-dir original --connbytes-mode packets
nft add rule ip filter OUTPUT ct original packets ge 200 counter
iptables-translate -A OUTPUT -m connbytes ! --connbytes 200 --connbytes-dir reply --connbytes-mode packets
nft add rule ip filter OUTPUT ct reply packets lt 200 counter
iptables-translate -A OUTPUT -m connbytes --connbytes 200:600 --connbytes-dir both --connbytes-mode bytes
nft add rule ip filter OUTPUT ct bytes 200-600 counter
iptables-translate -A OUTPUT -m connbytes ! --connbytes 200:600 --connbytes-dir both --connbytes-mode bytes
nft add rule ip filter OUTPUT ct bytes != 200-600 counter
iptables-translate -A OUTPUT -m connbytes --connbytes 200:200 --connbytes-dir both --connbytes-mode avgpkt
nft add rule ip filter OUTPUT ct avgpkt 200 counter
iptables-translate -A INPUT -m connlabel --label bit40
nft add rule ip filter INPUT ct label bit40 counter
iptables-translate -A INPUT -m connlabel ! --label bit40 --set
nft add rule ip filter INPUT ct label set bit40 ct label and bit40 != bit40 counter
iptables-translate -A INPUT -m connmark --mark 2 -j ACCEPT
nft add rule ip filter INPUT ct mark 0x2 counter accept
iptables-translate -A INPUT -m connmark ! --mark 2 -j ACCEPT
nft add rule ip filter INPUT ct mark != 0x2 counter accept
iptables-translate -A INPUT -m connmark --mark 10/10 -j ACCEPT
nft add rule ip filter INPUT ct mark and 0xa == 0xa counter accept
iptables-translate -A INPUT -m connmark ! --mark 10/10 -j ACCEPT
nft add rule ip filter INPUT ct mark and 0xa != 0xa counter accept
iptables-translate -t mangle -A PREROUTING -p tcp --dport 40 -m connmark --mark 0x40
nft add rule ip mangle PREROUTING tcp dport 40 ct mark 0x40 counter
iptables-translate -t filter -A INPUT -m conntrack --ctstate NEW,RELATED -j ACCEPT
nft add rule ip filter INPUT ct state new,related counter accept
ip6tables-translate -t filter -A INPUT -m conntrack ! --ctstate NEW,RELATED -j ACCEPT
nft add rule ip6 filter INPUT ct state != new,related counter accept
iptables-translate -t filter -A INPUT -m conntrack --ctproto UDP -j ACCEPT
nft add rule ip filter INPUT ct original protocol 17 counter accept
iptables-translate -t filter -A INPUT -m conntrack ! --ctproto UDP -j ACCEPT
nft add rule ip filter INPUT ct original protocol != 17 counter accept
iptables-translate -t filter -A INPUT -m conntrack --ctorigsrc 10.100.2.131 -j ACCEPT
nft add rule ip filter INPUT ct original saddr 10.100.2.131 counter accept
iptables-translate -t filter -A INPUT -m conntrack --ctorigsrc 10.100.0.0/255.255.0.0 -j ACCEPT
nft add rule ip filter INPUT ct original saddr 10.100.0.0/16 counter accept
iptables-translate -t filter -A INPUT -m conntrack --ctorigdst 10.100.2.131 -j ACCEPT
nft add rule ip filter INPUT ct original daddr 10.100.2.131 counter accept
iptables-translate -t filter -A INPUT -m conntrack --ctreplsrc 10.100.2.131 -j ACCEPT
nft add rule ip filter INPUT ct reply saddr 10.100.2.131 counter accept
iptables-translate -t filter -A INPUT -m conntrack --ctrepldst 10.100.2.131 -j ACCEPT
nft add rule ip filter INPUT ct reply daddr 10.100.2.131 counter accept
iptables-translate -t filter -A INPUT -m conntrack --ctproto tcp --ctorigsrcport 443:444 -j ACCEPT
nft add rule ip filter INPUT ct original protocol 6 ct original proto-src 443-444 counter accept
iptables-translate -t filter -A INPUT -m conntrack ! --ctstatus CONFIRMED -j ACCEPT
nft add rule ip filter INPUT ct status != confirmed counter accept
iptables-translate -t filter -A INPUT -m conntrack --ctexpire 3 -j ACCEPT
nft add rule ip filter INPUT ct expiration 3 counter accept
iptables-translate -t filter -A INPUT -m conntrack --ctdir ORIGINAL -j ACCEPT
nft add rule ip filter INPUT ct direction original counter accept
iptables-translate -t filter -A INPUT -m conntrack --ctstate NEW --ctproto tcp --ctorigsrc 192.168.0.1 --ctorigdst 192.168.0.1 --ctreplsrc 192.168.0.1 --ctrepldst 192.168.0.1 --ctorigsrcport 12 --ctorigdstport 14 --ctreplsrcport 16 --ctrepldstport 18 --ctexpire 10 --ctstatus SEEN_REPLY --ctdir ORIGINAL -j ACCEPT
nft add rule ip filter INPUT ct direction original ct original protocol 6 ct state new ct status seen-reply ct expiration 10 ct original saddr 192.168.0.1 ct original daddr 192.168.0.1 ct reply saddr 192.168.0.1 ct reply daddr 192.168.0.1 ct original proto-src 12 ct original proto-dst 14 ct reply proto-src 16 ct reply proto-dst 18 counter accept
iptables-translate -A INPUT -p tcp --dport 80 -m cpu --cpu 0 -j ACCEPT
nft add rule ip filter INPUT tcp dport 80 cpu 0 counter accept
iptables-translate -A INPUT -p tcp --dport 80 -m cpu ! --cpu 1 -j ACCEPT
nft add rule ip filter INPUT tcp dport 80 cpu != 1 counter accept
iptables-translate -A INPUT -p dccp -m dccp --sport 100
nft add rule ip filter INPUT dccp sport 100 counter
iptables-translate -A INPUT -p dccp -m dccp --dport 100:200
nft add rule ip filter INPUT dccp dport 100-200 counter
iptables-translate -A INPUT -p dccp -m dccp ! --dport 100
nft add rule ip filter INPUT dccp dport != 100 counter
iptables-translate -A INPUT -p dccp -m dccp --dport 100 --dccp-types REQUEST,RESPONSE,DATA,ACK,DATAACK,CLOSEREQ,CLOSE,SYNC,SYNCACK
nft add rule ip filter INPUT dccp dport 100 dccp type {request, response, data, ack, dataack, closereq, close, sync, syncack} counter
iptables-translate -A INPUT -p dccp -m dccp --sport 200 --dport 100
nft add rule ip filter INPUT dccp sport 200 dport 100 counter
iptables-translate -A FORWARD -m devgroup --src-group 0x2 -j ACCEPT
nft add rule ip filter FORWARD iifgroup 0x2 counter accept
iptables-translate -A FORWARD -m devgroup --dst-group 0xc/0xc -j ACCEPT
nft add rule ip filter FORWARD oifgroup and 0xc == 0xc counter accept
iptables-translate -t mangle -A PREROUTING -p tcp --dport 46000 -m devgroup --src-group 23 -j ACCEPT
nft add rule ip mangle PREROUTING tcp dport 46000 iifgroup 0x17 counter accept
iptables-translate -A FORWARD -m devgroup ! --dst-group 0xc/0xc -j ACCEPT
nft add rule ip filter FORWARD oifgroup and 0xc != 0xc counter accept
iptables-translate -A FORWARD -m devgroup ! --src-group 0x2 -j ACCEPT
nft add rule ip filter FORWARD iifgroup != 0x2 counter accept
iptables-translate -A FORWARD -m devgroup ! --src-group 0x2 --dst-group 0xc/0xc -j ACCEPT
nft add rule ip filter FORWARD iifgroup != 0x2 oifgroup and 0xc != 0xc counter accept
iptables-translate -t filter -A INPUT -m dscp --dscp 0x32 -j ACCEPT
nft add rule ip filter INPUT ip dscp 0x32 counter accept
ip6tables-translate -t filter -A INPUT -m dscp ! --dscp 0x32 -j ACCEPT
nft add rule ip6 filter INPUT ip6 dscp != 0x32 counter accept
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