| 1 |
table ip nftlb { |
| 2 |
ct helper sip-tcp { |
| 3 |
type "sip" protocol tcp |
| 4 |
l3proto ip |
| 5 |
} |
| 6 |
|
| 7 |
map filter-proto-services { |
| 8 |
type inet_proto . ipv4_addr . inet_service : verdict |
| 9 |
elements = { tcp . 192.168.56.154 . 5060 : goto filter-lb01 } |
| 10 |
} |
| 11 |
|
| 12 |
map nat-proto-services { |
| 13 |
type inet_proto . ipv4_addr . inet_service : verdict |
| 14 |
elements = { tcp . 192.168.56.154 . 5060 : goto nat-lb01 } |
| 15 |
} |
| 16 |
|
| 17 |
map services-back-m { |
| 18 |
type mark : ipv4_addr |
| 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 . th dport vmap @filter-proto-services |
| 25 |
} |
| 26 |
|
| 27 |
chain filter-lb01 { |
| 28 |
ip protocol tcp ct helper set "sip-tcp" |
| 29 |
ct state new ct mark 0x00000000 ct mark set numgen inc mod 10 map { 0-4 : 0x00000001, 5-9 : 0x00000002 } |
| 30 |
} |
| 31 |
|
| 32 |
chain prerouting { |
| 33 |
type nat hook prerouting priority dstnat; policy accept; |
| 34 |
ct state new meta mark 0x00000000 meta mark set ct mark |
| 35 |
ip protocol . ip daddr . th dport vmap @nat-proto-services |
| 36 |
} |
| 37 |
|
| 38 |
chain postrouting { |
| 39 |
type nat hook postrouting priority srcnat; policy accept; |
| 40 |
ct mark 0x00000000 ct mark set meta mark |
| 41 |
ct mark 0x80000000/1 masquerade |
| 42 |
snat to ct mark map @services-back-m |
| 43 |
} |
| 44 |
|
| 45 |
chain nat-lb01 { |
| 46 |
ip protocol tcp dnat to ct mark map { 0x00000001 : 192.168.0.22, 0x00000002 : 192.168.0.23 } |
| 47 |
} |
| 48 |
} |