works enough for now
This commit is contained in:
commit
c04a9a752a
12 changed files with 178 additions and 0 deletions
29
compiler/nat.py
Normal file
29
compiler/nat.py
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import hashlib
|
||||
|
||||
def rule_id(service_name: str, kind: str) -> int:
|
||||
h = hashlib.sha1(f"{service_name}:{kind}".encode()).hexdigest()
|
||||
return(int(h[:4], 16)) # here's hoping
|
||||
|
||||
def build_nat_rules(services, cfg):
|
||||
rules = []
|
||||
|
||||
for s in services:
|
||||
rid_wan = rule_id(s.name, "dnat_wan")
|
||||
rid_hairpin = rule_id(s.name, "dnat_hairpin")
|
||||
|
||||
rules.append({
|
||||
"id": rid_wan,
|
||||
"service": s,
|
||||
"cfg": cfg,
|
||||
"kind": "dnat_wan",
|
||||
})
|
||||
|
||||
if "nat" in s.exposure:
|
||||
rules.append({
|
||||
"id": rid_hairpin,
|
||||
"service": s,
|
||||
"cfg": cfg,
|
||||
"kind": "dnat_hairpin",
|
||||
})
|
||||
|
||||
return(rules)
|
||||
Loading…
Add table
Add a link
Reference in a new issue