| 1 |
table ip nftlb { |
| 2 |
map filter-proto-services { |
| 3 |
type inet_proto . ipv4_addr . inet_service : verdict |
| 4 |
elements = { udp . 192.168.0.100 . 53 : goto filter-lb02, |
| 5 |
tcp . 192.168.0.100 . 80 : goto filter-lb01 } |
| 6 |
} |
| 7 |
|
| 8 |
map nat-proto-services { |
| 9 |
type inet_proto . ipv4_addr . inet_service : verdict |
| 10 |
elements = { udp . 192.168.0.100 . 53 : goto nat-lb02, |
| 11 |
tcp . 192.168.0.100 . 80 : goto nat-lb01 } |
| 12 |
} |
| 13 |
|
| 14 |
map services-back-m { |
| 15 |
type mark : ipv4_addr |
| 16 |
} |
| 17 |
|
| 18 |
chain filter { |
| 19 |
type filter hook prerouting priority mangle; policy accept; |
| 20 |
meta mark 0x00000000 meta mark set ct mark |
| 21 |
ip protocol . ip daddr . th dport vmap @filter-proto-services |
| 22 |
} |
| 23 |
|
| 24 |
chain filter-lb01 { |
| 25 |
ct state new ct mark 0x00000000 ct mark set jhash ip daddr mod 10 map { 0-4 : 0x00000001, 5-9 : 0x00000002 } |
| 26 |
} |
| 27 |
|
| 28 |
chain prerouting { |
| 29 |
type nat hook prerouting priority dstnat; policy accept; |
| 30 |
ct state new meta mark 0x00000000 meta mark set ct mark |
| 31 |
ip protocol . ip daddr . th dport vmap @nat-proto-services |
| 32 |
} |
| 33 |
|
| 34 |
chain postrouting { |
| 35 |
type nat hook postrouting priority srcnat; policy accept; |
| 36 |
ct mark 0x00000000 ct mark set meta mark |
| 37 |
ct mark 0x80000000/1 masquerade |
| 38 |
snat to ct mark map @services-back-m |
| 39 |
} |
| 40 |
|
| 41 |
chain nat-lb01 { |
| 42 |
ip protocol tcp dnat to ct mark map { 0x00000001 : 192.168.0.10, 0x00000002 : 192.168.0.11 } |
| 43 |
} |
| 44 |
|
| 45 |
chain filter-lb02 { |
| 46 |
ct state new ct mark 0x00000000 meta iiftype ether ct mark set jhash ip saddr . udp sport . ether saddr mod 10 map { 0-4 : 0x00000003, 5-9 : 0x00000004 } |
| 47 |
} |
| 48 |
|
| 49 |
chain nat-lb02 { |
| 50 |
ip protocol udp dnat to ct mark map { 0x00000003 : 192.168.0.10, 0x00000004 : 192.168.0.11 } |
| 51 |
} |
| 52 |
} |