summaryrefslogtreecommitdiff
path: root/data/templates/firewall/nftables-cgnat.j2
blob: 79a8e3d5a4afbd6c6f2f341db3bf9d8358916f6b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/sbin/nft -f

add table ip cgnat
flush table ip cgnat

add map ip cgnat tcp_nat_map { type ipv4_addr: interval ipv4_addr . inet_service ; flags interval ;}
add map ip cgnat udp_nat_map { type ipv4_addr: interval ipv4_addr . inet_service ; flags interval ;}
add map ip cgnat icmp_nat_map { type ipv4_addr: interval ipv4_addr . inet_service ; flags interval ;}
add map ip cgnat other_nat_map { type ipv4_addr: interval ipv4_addr ; flags interval ;}
flush map ip cgnat tcp_nat_map
flush map ip cgnat udp_nat_map
flush map ip cgnat icmp_nat_map
flush map ip cgnat other_nat_map

table ip cgnat {
    map tcp_nat_map {
        type ipv4_addr : interval ipv4_addr . inet_service
        flags interval
        elements = { {{ proto_map_elements }} }
    }

    map udp_nat_map {
        type ipv4_addr : interval ipv4_addr . inet_service
        flags interval
        elements = { {{ proto_map_elements }} }
    }

    map icmp_nat_map {
        type ipv4_addr : interval ipv4_addr . inet_service
        flags interval
        elements = { {{ proto_map_elements }} }
    }

    map other_nat_map {
        type ipv4_addr : interval ipv4_addr
        flags interval
        elements = { {{ other_map_elements }} }
    }

    chain POSTROUTING {
        type nat hook postrouting priority srcnat; policy accept;
        ip protocol tcp counter snat ip to ip saddr map @tcp_nat_map
        ip protocol udp counter snat ip to ip saddr map @udp_nat_map
        ip protocol icmp counter snat ip to ip saddr map @icmp_nat_map
        counter snat ip to ip saddr map @other_nat_map
    }
}