File tree Expand file tree Collapse file tree 2 files changed +64
-0
lines changed Expand file tree Collapse file tree 2 files changed +64
-0
lines changed Original file line number Diff line number Diff line change
1
+ {
2
+ "plugin" : " custom" ,
3
+ "pluginConfig" : {
4
+ "invoke_interval" : " 86400s" ,
5
+ "timeout" : " 5s" ,
6
+ "max_output_length" : 80 ,
7
+ "concurrency" : 1 ,
8
+ "enable_message_change_based_condition_update" : false
9
+ },
10
+ "source" : " iptables-mode-monitor" ,
11
+ "metricsReporting" : true ,
12
+ "conditions" : [
13
+ {
14
+ "type" : " IPTablesVersionProblem" ,
15
+ "reason" : " IPTablesVersionOK" ,
16
+ "message" : " iptables version ok"
17
+ }
18
+ ],
19
+ "rules" : [
20
+ {
21
+ "type" : " temporary" ,
22
+ "reason" : " IPTablesVersionNotOK" ,
23
+ "path" : " ./config/plugin/iptables_mode.sh" ,
24
+ "timeout" : " 5s"
25
+ },
26
+ {
27
+ "type" : " permanent" ,
28
+ "condition" : " IPTablesVersionProblem" ,
29
+ "reason" : " IPTablesVersionNotOK" ,
30
+ "path" : " ./config/plugin/iptables_mode.sh" ,
31
+ "timeout" : " 5s"
32
+ }
33
+ ]
34
+ }
Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+
3
+ # As of iptables 1.8, the iptables command line clients come in two different versions/modes: "legacy",
4
+ # which uses the kernel iptables API just like iptables 1.6 and earlier did, and "nft", which translates
5
+ # the iptables command-line API into the kernel nftables API.
6
+ # Because they connect to two different subsystems in the kernel, you cannot mix rules from different versions.
7
+ # Ref: https://github.com/kubernetes-sigs/iptables-wrappers
8
+
9
+ readonly OK=0
10
+ readonly NONOK=1
11
+ readonly UNKNOWN=2
12
+
13
+ # based on: https://github.com/kubernetes-sigs/iptables-wrappers/blob/97b01f43a8e8db07840fc4b95e833a37c0d36b12/iptables-wrapper-installer.sh
14
+ readonly num_legacy_lines=$( (iptables-legacy-save || true ; ip6tables-legacy-save || true) 2> /dev/null | grep -c ' ^-' || true)
15
+ readonly num_nft_lines=$( (timeout 5 sh -c " iptables-nft-save; ip6tables-nft-save" || true) 2> /dev/null | grep -c ' ^-' || true)
16
+
17
+
18
+ if [ " $num_legacy_lines " -gt 0 ] && [ " $num_nft_lines " -gt 0 ]; then
19
+ echo " Found rules from both versions, iptables-legacy: ${num_legacy_lines} iptables-nft: ${num_nft_lines} "
20
+ echo $NONOK
21
+ elif [ " $num_legacy_lines " -gt 0 ] && [ " $num_nft_lines " -eq 0 ]; then
22
+ echo " Using iptables-legacy: ${num_legacy_lines} rules"
23
+ echo $OK
24
+ elif [ " $num_legacy_lines " -eq 0 ] && [ " $num_nft_lines " -gt 0 ]; then
25
+ echo " Using iptables-nft: ${num_nft_lines} rules"
26
+ echo $OK
27
+ else
28
+ echo " No iptables rules found"
29
+ echo $UNKNOWN
30
+ fi
You can’t perform that action at this time.
0 commit comments