-
Notifications
You must be signed in to change notification settings - Fork 496
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
M #-: Add IP Spoofing support for NIC_ALIAS #4764
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -334,6 +334,14 @@ def self.vars(vm, nic, sg_id = nil) | |
vars[:set_sg_out] = "#{vars[:chain]}-#{sg_id}-o" | ||
end | ||
|
||
vars[:nic_aliases] = [] | ||
|
||
unless nic[:alias_ids].nil? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. prefer if !nic[:alias_ids].nil? for single statements There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will change it |
||
nic[:alias_ids].split(',').each do |id| | ||
vars[:nic_aliases] << vm.nic_alias(id) | ||
end | ||
end | ||
|
||
vars | ||
end | ||
|
||
|
@@ -426,6 +434,10 @@ def self.nic_pre(vm, nic) | |
|
||
[:ip, :vrouter_ip].each do |key| | ||
ipv4s << nic[key] if !nic[key].nil? && !nic[key].empty? | ||
vars[:nic_aliases].each do |nic_alias| | ||
ipv4s << nic_alias[key] \ | ||
if !nic_alias[key].nil? && !nic_alias[key].empty? | ||
end | ||
end | ||
|
||
if !ipv4s.empty? | ||
|
@@ -453,6 +465,10 @@ def self.nic_pre(vm, nic) | |
|
||
[:ip6, :ip6_global, :ip6_link, :ip6_ula].each do |key| | ||
ipv6s << nic[key] if !nic[key].nil? && !nic[key].empty? | ||
vars[:nic_aliases].each do |nic_alias| | ||
ipv6s << nic_alias[key] \ | ||
if !nic_alias[key].nil? && !nic_alias[key].empty? | ||
end | ||
end | ||
|
||
if !ipv6s.empty? | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,22 +38,10 @@ def initialize(vm_root, xpath_filter, deploy_id) | |
|
||
@deploy_id = nil if deploy_id == '-' | ||
|
||
nics = VNMNetwork::Nics.new(hypervisor) | ||
|
||
@vm_root.elements.each(xpath_filter) do |nic_element| | ||
nic = nics.new_nic | ||
|
||
nic_build_hash(nic_element, nic) | ||
|
||
if !VNMMAD.pre_action? | ||
nic.get_info(self) | ||
nic.get_tap(self) | ||
end | ||
|
||
nics << nic | ||
end | ||
|
||
@nics = nics | ||
@nics = nics_build(xpath_filter) | ||
@nic_aliases = [] | ||
@nic_aliases = nics_build('TEMPLATE/NIC_ALIAS') \ | ||
if !xpath_filter.nil? && xpath_filter.include?('TEMPLATE/NIC') | ||
end | ||
|
||
# Iterator on each NIC of the VM | ||
|
@@ -65,6 +53,19 @@ def each_nic(block) | |
end | ||
end | ||
|
||
# Get NIC_ALIAS by NIC_ID | ||
# @param element [String] the NIC_ID | ||
# @return [Hash] the NIC_ALIAS | ||
def nic_alias(id) | ||
if @nic_aliases | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. better use exit condition. return nil if @nic_aliases.nil? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will change it |
||
@nic_aliases.each do |the_nic| | ||
return the_nic if the_nic[:nic_id] == id | ||
end | ||
end | ||
|
||
nil | ||
end | ||
|
||
# Access an XML Element of the VM | ||
# @param element [String] element name | ||
# @return [String] value of the element or nil if not found | ||
|
@@ -121,6 +122,27 @@ def nic_build_hash(nic_element, nic) | |
end | ||
end | ||
|
||
# Method to build the list of NIC/NIC_ALIAS | ||
# @param xpath_filter [String] XML NIC/NIC_ALIAS document | ||
def nics_build(xpath_filter) | ||
nics = VNMNetwork::Nics.new(hypervisor) | ||
|
||
@vm_root.elements.each(xpath_filter) do |nic_element| | ||
nic = nics.new_nic | ||
|
||
nic_build_hash(nic_element, nic) | ||
|
||
if !VNMMAD.pre_action? | ||
nic.get_info(self) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do these functions work/make sense for NIC_ALIAS? (when calling it as nics_build('TEMPLATE/NIC_ALIAS') |
||
nic.get_tap(self) | ||
end | ||
|
||
nics << nic | ||
end | ||
|
||
nics | ||
end | ||
|
||
end | ||
|
||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not clean action?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clean action deletes the whole iptables chain included the rules for the parent NIC