B B OpenNebula/one#6759: Race condition applying physdev SG rules (#3747)

Signed-off-by: josepselga <jselga@opennebula.io>
This commit is contained in:
Josep Selga authored and GitHub committed 2025-08-07 12:36:31 +02:00
1 parent aa536a4297
commit 1ec2ae7346
2 files changed
+33 -19

No files matched your search

@@ -416,6 +416,8 @@ module SGIPTables
nri6s = []
if bridged
raise "Interface #{nic[:tap]} not available to apply SG rules" unless wait_for_interface(nic[:tap])
nris << "#{base_br} --physdev-out #{nic[:tap]} -j #{chain_in}"
nri6s << "#{base_br} --physdev-out #{nic[:tap]} -j #{chain_in}"
else
@@ -764,6 +766,18 @@ module SGIPTables
commands.run!
end
def self.wait_for_interface(tap, timeout = 3)
path = "/sys/class/net/#{tap}"
waited = 0
until File.exist?(path) || waited >= timeout
sleep 0.1
waited += 0.1
end
File.exist?(path)
end
end
end
+19 -19
View File
@@ -103,34 +103,34 @@ module VNMMAD
# Process the rules for each NIC
process do |nic|
next if attach_nic_id && attach_nic_id != nic[:nic_id]
begin
next if attach_nic_id && attach_nic_id != nic[:nic_id]
# SG not supported for NIC_ALIAS
if nic[:security_groups].nil?
nic[:security_groups] = '0'
@security_group_rules = EMPTY_RULES
end
# SG not supported for NIC_ALIAS
if nic[:security_groups].nil?
nic[:security_groups] = '0'
@security_group_rules = EMPTY_RULES
end
SGIPTables.nic_pre(@bridged, @vm, nic)
SGIPTables.nic_pre(@bridged, @vm, nic)
sg_ids = nic[:security_groups].split(',')
sg_ids = nic[:security_groups].split(',')
sg_ids.each do |sg_id|
rules = @security_group_rules[sg_id]
sg_ids.each do |sg_id|
rules = @security_group_rules[sg_id]
sg = SGIPTables::SecurityGroupIPTables.new(@vm, nic, sg_id, rules)
sg = SGIPTables::SecurityGroupIPTables.new(@vm, nic, sg_id, rules)
begin
sg.process_rules
sg.run!
rescue StandardError => e
unlock
deactivate(do_all)
raise e
end
end
SGIPTables.nic_post(@vm, nic)
SGIPTables.nic_post(@vm, nic)
rescue StandardError => e
unlock
deactivate(do_all)
raise e
end
end
# Process the rules for each NIC_ALIAS