|
31 | 31 | BLACKLIST = config['BLACKLIST'] |
32 | 32 | COUNTRY_LIST = config['COUNTRY_LIST'] |
33 | 33 | BLOCK_OUTPUT = config['BLOCK_OUTPUT'] |
| 34 | +BLOCK_FORWARD = config['BLOCK_FORWARD'] |
34 | 35 |
|
35 | 36 |
|
36 | 37 | # Correct incorrect YAML parsing of NO (Norway) |
|
42 | 43 | SET_TEMPLATE = ('table inet blackhole {\n\tset ${set_name} {\n\t\ttype ${ip_ver}_addr\n' |
43 | 44 | '\t\tflags interval\n\t\tauto-merge\n\t\telements = { ${ip_list} }\n\t}\n}').expandtabs() |
44 | 45 |
|
| 46 | +FORWARD_TEMPLATE = ('\tchain forward {\n\t\ttype filter hook forward priority -1; policy accept;\n' |
| 47 | + '\t\tct state established,related accept\n' |
| 48 | + '\t\tip saddr @whitelist-v4 counter accept\n' |
| 49 | + '\t\tip6 saddr @whitelist-v6 counter accept\n' |
| 50 | + '\t\tip saddr @blacklist-v4 counter ${block_policy}\n' |
| 51 | + '\t\tip6 saddr @blacklist-v6 counter ${block_policy}\n' |
| 52 | + '\t\t${country_ex_ports_rule}' |
| 53 | + '\t\tip saddr @country-v4 counter ${country_policy}\n' |
| 54 | + '\t\tip6 saddr @country-v6 counter ${country_policy}\n' |
| 55 | + '\t\tcounter\n\t}').expandtabs() |
| 56 | + |
45 | 57 | OUTPUT_TEMPLATE = ('\tchain output {\n\t\ttype filter hook output priority -1; policy accept;\n' |
46 | 58 | '\t\tip daddr @whitelist-v4 counter accept\n' |
47 | 59 | '\t\tip6 daddr @whitelist-v6 counter accept\n' |
|
79 | 91 | else: |
80 | 92 | chain_output = '' |
81 | 93 |
|
| 94 | +if BLOCK_FORWARD: |
| 95 | + chain_forward = Template(FORWARD_TEMPLATE).substitute(block_policy=block_policy, |
| 96 | + country_policy=country_policy, |
| 97 | + country_ex_ports_rule=country_ex_ports_rule) |
| 98 | +else: |
| 99 | + chain_forward = '' |
| 100 | + |
82 | 101 | # Setting urllib |
83 | 102 | ctx = ssl.create_default_context() |
84 | 103 | IGNORE_CERTIFICATE = False |
@@ -106,7 +125,8 @@ def start(): |
106 | 125 | block_policy=block_policy, |
107 | 126 | country_ex_ports_rule=country_ex_ports_rule, |
108 | 127 | country_policy=country_policy, |
109 | | - chain_output=chain_output) |
| 128 | + chain_output=chain_output, |
| 129 | + chain_forward=chain_forward) |
110 | 130 |
|
111 | 131 | run(['nft', '-f', '-'], input=nft_conf.encode(), check=True) |
112 | 132 |
|
|
0 commit comments