File tree Expand file tree Collapse file tree 2 files changed +30
-6
lines changed Expand file tree Collapse file tree 2 files changed +30
-6
lines changed Original file line number Diff line number Diff line change @@ -1481,28 +1481,33 @@ def insync?(is)
14811481 desc <<-PUPPETCODE
14821482 Match the Netfilter mark value associated with the packet. Accepts either of:
14831483 mark/mask or mark. These will be converted to hex if they are not already.
1484+
1485+ match_mark => '0x02'
1486+
1487+ You can also negate a value by putting ! in front. For example:
1488+
1489+ match_mark => '! 0x02'
14841490 PUPPETCODE
14851491 munge do |value |
1486- mark_regex = %r{\A ((?:0x)?[0-9A-F]+)(/)?((?:0x)?[0-9A-F]+)?\z }i
1492+ mark_regex = %r{\A (! \s )?( (?:0x)?[0-9A-F]+)(/)?((?:0x)?[0-9A-F]+)?\z }i
14871493 match = value . to_s . match ( mark_regex )
14881494 if match . nil?
14891495 raise ArgumentError , 'Match MARK value must be integer or hex between 0 and 0xffffffff'
14901496 end
1491- mark = @resource . to_hex32 ( match [ 1 ] )
1497+ mark = @resource . to_hex32 ( match [ 2 ] )
14921498
14931499 # Values that can't be converted to hex.
14941500 # Or contain a trailing slash with no mask.
1495- if mark . nil? || ( mark && match [ 2 ] && match [ 3 ] . nil? )
1501+ if mark . nil? || ( mark && match [ 3 ] && match [ 4 ] . nil? )
14961502 raise ArgumentError , 'Match MARK value must be integer or hex between 0 and 0xffffffff'
14971503 end
14981504
14991505 # There should not be a mask on match_mark
1500- unless match [ 3 ] . nil?
1506+ unless match [ 4 ] . nil?
15011507 raise ArgumentError , 'iptables does not support masks on MARK match rules'
15021508 end
1503- value = mark
15041509
1505- value
1510+ match [ 1 ] ? "! #{ mark } " : mark
15061511 end
15071512 end
15081513
Original file line number Diff line number Diff line change @@ -1251,6 +1251,25 @@ class { '::firewall': }
12511251 expect ( r . stdout ) . to match ( %r{-A INPUT -m mark --mark 0x1 -m comment --comment "503 match_mark - test" -j REJECT --reject-with icmp-port-unreachable} )
12521252 end
12531253 end
1254+
1255+ context 'when ! 0x1' do
1256+ pp1 = <<-PUPPETCODE
1257+ class { '::firewall': }
1258+ firewall { '504 match_mark - negate test':
1259+ proto => 'all',
1260+ match_mark => '! 0x1',
1261+ action => reject,
1262+ }
1263+ PUPPETCODE
1264+ it 'applies' do
1265+ apply_manifest ( pp1 , catch_failures : true )
1266+ end
1267+
1268+ it 'contains the rule' do
1269+ run_shell ( 'iptables-save' ) do |r |
1270+ expect ( r . stdout ) . to match ( %r{-A INPUT -m mark --mark ! 0x1 -m comment --comment "504 match_mark - negate test" -j REJECT --reject-with icmp-port-unreachable} )
1271+ end
1272+ end
12541273 end
12551274 end
12561275
You can’t perform that action at this time.
0 commit comments