| 1 |
table ip nftlb { |
| 2 |
map filter-services { |
| 3 |
type inet_proto . ipv4_addr : verdict |
| 4 |
elements = { tcp . 192.168.0.100 : goto filter-lb01, |
| 5 |
udp . 192.168.0.100 : goto filter-lb01, |
| 6 |
sctp . 192.168.0.100 : goto filter-lb01 } |
| 7 |
} |
| 8 |
|
| 9 |
map nat-services { |
| 10 |
type inet_proto . ipv4_addr : verdict |
| 11 |
elements = { tcp . 192.168.0.100 : goto nat-lb01, |
| 12 |
udp . 192.168.0.100 : goto nat-lb01, |
| 13 |
sctp . 192.168.0.100 : goto nat-lb01 } |
| 14 |
} |
| 15 |
|
| 16 |
map services-back-m { |
| 17 |
type mark : ipv4_addr |
| 18 |
elements = { 0x00000200 : 192.168.0.101, 0x00000201 : 192.168.0.101 } |
| 19 |
} |
| 20 |
|
| 21 |
chain filter { |
| 22 |
type filter hook prerouting priority mangle; policy accept; |
| 23 |
meta mark 0x00000000 meta mark set ct mark |
| 24 |
ip protocol . ip daddr vmap @filter-services |
| 25 |
} |
| 26 |
|
| 27 |
chain filter-lb01 { |
| 28 |
ct state new ct mark 0x00000000 ct mark set numgen random mod 10 map { 0-4 : 0x00000200, 5-9 : 0x00000201 } |
| 29 |
} |
| 30 |
|
| 31 |
chain prerouting { |
| 32 |
type nat hook prerouting priority dstnat; policy accept; |
| 33 |
ct state new meta mark 0x00000000 meta mark set ct mark |
| 34 |
ip protocol . ip daddr vmap @nat-services |
| 35 |
} |
| 36 |
|
| 37 |
chain postrouting { |
| 38 |
type nat hook postrouting priority srcnat; policy accept; |
| 39 |
ct mark 0x00000000 ct mark set meta mark |
| 40 |
ct mark 0x80000000/1 masquerade |
| 41 |
snat to ct mark map @services-back-m |
| 42 |
} |
| 43 |
|
| 44 |
chain nat-lb01 { |
| 45 |
dnat to ct mark map { 0x00000200 : 192.168.0.10, 0x00000201 : 192.168.0.11 } |
| 46 |
} |
| 47 |
} |