Skip to content

Commit 20cf10d

Browse files
committed
add option for backend-filter OR-matching and usage of pre-existing acls
1 parent a8f7ea0 commit 20cf10d

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

defaults/main/1_main.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,8 @@ defaults_frontend_route:
191191
filter_not_asn: []
192192
filter_ip: []
193193
filter_not_ip: []
194+
# use pre-existing acls for less duplicate config
195+
filter_acl: []
196+
filter_not_acl: []
197+
198+
filter_match_or: false # only one filter needs to match (pe: country or IP => [domain AND country] OR [domain AND ip])

filter_plugins/utils.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ def build_route(cls, fe_cnf: dict, be_cnf: dict, be_name: str) -> list:
8989
lines.append(f"acl {var_prefix}_not_ip src {' '.join(cls.ensure_list(be_cnf['filter_not_ip']))}")
9090
to_match.append(f'!{var_prefix}_not_ip')
9191

92+
if len(be_cnf['filter_acl']) > 0:
93+
to_match.extend(cls.ensure_list(be_cnf['filter_acl']))
94+
95+
if len(be_cnf['filter_not_acl']) > 0:
96+
to_match.extend([f'!{a}' for a in cls.ensure_list(be_cnf['filter_acl'])])
97+
9298
if cls.is_truthy(fe_cnf['geoip']['enable']):
9399
if cls.is_truthy(fe_cnf['geoip']['country']):
94100
if len(be_cnf['filter_country']) > 0:
@@ -121,7 +127,20 @@ def build_route(cls, fe_cnf: dict, be_cnf: dict, be_name: str) -> list:
121127
to_match.append(f'!{var_prefix}_not_asn')
122128

123129
if len(to_match) > 0:
124-
lines.append(f"use_backend {be_name} if {' '.join(to_match)}")
130+
if cls.is_truthy(be_cnf['filter_match_or']):
131+
to_match_or = []
132+
if len(be_cnf['domains']) == 0:
133+
to_match_or = to_match
134+
135+
else:
136+
d = to_match[0]
137+
for m in to_match[1:]:
138+
to_match_or.append(f'{d} {m}')
139+
140+
lines.append(f"use_backend {be_name} if {' || '.join(to_match_or)}")
141+
142+
else:
143+
lines.append(f"use_backend {be_name} if {' '.join(to_match)}")
125144

126145
else:
127146
lines.append(f"use_backend {be_name}")

0 commit comments

Comments
 (0)