Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MODULES-9801 - fix negated physdev #858

Merged
merged 1 commit into from
Sep 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/puppet/provider/firewall/iptables.rb
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ def self.rule_to_hash(line, table, counter)
values.insert(ind, "-m addrtype --dst-type \"#{types.join(';')}\" ")
end
# the actual rule will have the ! mark before the option.
values = values.gsub(%r{(!)\s*(-\S+)\s*(\S*)}, '\2 "\1 \3"')
values = values.gsub(%r{(!)\s*(-\S+)\s*(\S*)}, '\2 "\1 \3"') unless values.include?('--physdev')
# we do a similar thing for negated address masks (source and destination).
values = values.gsub(%r{(?<=\s)(-\S+) (!)\s?(\S*)}, '\1 "\2 \3"')
# fix negated physdev rules
Expand Down Expand Up @@ -473,6 +473,8 @@ def self.rule_to_hash(line, table, counter)
# only replace those -f that are not followed by an l to
# distinguish between -f and the '-f' inside of --tcp-flags.
values.sub(%r{\s-f(?!l)(?=.*--comment)}, ' -f true')
elsif resource_map[bool].eql?(%r{'--physdev-is-\S+'})
values.sub(%r{'#{resource_map[bool]} "! "'}, "#{resource_map[bool]} true")
else
# append `true` to booleans that are not already negated (followed by "!")
values.sub(%r{#{resource_map[bool]}(?! "!")}, "#{resource_map[bool]} true")
Expand Down
11 changes: 11 additions & 0 deletions spec/fixtures/iptables/conversion_hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,17 @@
src_type: ['! LOCAL'],
},
},
'physdev_negated' => {
line: '-A cali-POSTROUTING -o tunl0 -m comment --comment "010 cali:JHlpT-eSqR1TvyYm" -m physdev ! --physdev-is-in -j MASQUERADE',
table: 'filter',
params: {
chain: 'cali-POSTROUTING',
outiface: 'tunl0',
name: '010 cali:JHlpT-eSqR1TvyYm',
jump: 'MASQUERADE',
physdev_is_in: '! ',
},
},
'addrtype_multiple' => {
line: '-A cali-POSTROUTING -o tunl0 -m comment --comment "000 cali:JHlpT-eSqR1TvyYm" -m addrtype ! --src-type LOCAL --limit-iface-out -m addrtype --src-type LOCAL -j MASQUERADE',
table: 'filter',
Expand Down