Skip to content

Commit

Permalink
M #-: Change tproxy strategy for handling ARP requests (OpenNebula#3279)
Browse files Browse the repository at this point in the history
- Prevent ARP requests from reaching other HVs
- Rename incorrectly named "comm" to "cmdline"
  • Loading branch information
sk4zuzu authored Oct 29, 2024
1 parent 315896d commit 0bd4511
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
10 changes: 5 additions & 5 deletions src/vnm_mad/remotes/lib/tproxy
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,8 @@ module VNMMAD

class Daemon

def initialize(comm)
@comm = comm
def initialize(cmdline)
@cmdline = cmdline
end

def run(argv = ARGV.dup, &block)
Expand All @@ -346,13 +346,13 @@ module VNMMAD
end
if pid.nil? && ['start', 'restart'].include?(argv[0])
fork do
$0 = @comm
$0 = @cmdline

Process.setsid

$stdin.reopen '/dev/null'

$stdout.reopen "#{LOG_LOCATION}/#{@comm}.log", 'a'
$stdout.reopen "#{LOG_LOCATION}/#{@cmdline}.log", 'a'
$stdout.sync = true

$stderr.reopen $stdout
Expand All @@ -369,7 +369,7 @@ module VNMMAD
o, _, s = Open3.capture3 'ps', '--no-headers', '-wwo', 'pid,cmd', '-C', 'ruby'
o.lines
.map {|line| line.strip.split(' ', 2) }
.find {|_, cmd| cmd == @comm } if s.success?
.find {|_, cmd| cmd == @cmdline } if s.success?
end

end
Expand Down
23 changes: 9 additions & 14 deletions src/vnm_mad/remotes/lib/tproxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,28 +90,23 @@ def self.enable_tproxy(nic, endpoints)

ip_netns_exec(brdev, "ip route replace default dev #{brdev}a")

veth_mac = ip_netns_exec(brdev,
"ip -j link show dev #{brdev}a",
:expect_json => true).dig(0, 0, 'address')

# This is required to avoid 169.254.16.9 address conflicts in case of VNETs
# used on multiple different HV hosts are attached to multiple guest VMs.
# Basically, we short-circuit any 169.254.16.9 communication and
# forcefully redirect every packet destined to 169.254.16.9 to be handled
# locally (regardless of the actual ARP resolution in guest VMs).
# Prevent ARP requests from being propagated to other HV machines.
# It reduces network traffic and ensures that the closest HV handles
# proxied packets.
nft(ERB.new(<<~NFT).result(binding))
table bridge one_tproxy {
chain ch_<%= brdev %> {
type filter hook prerouting priority dstnat; policy accept;
type filter hook forward priority filter; policy accept;
};
};
flush chain bridge one_tproxy ch_<%= brdev %>;
table bridge one_tproxy {
chain ch_<%= brdev %> {
meta ibrname "<%= brdev %>" \
ip daddr 169.254.16.9 \
meta pkttype set host ether daddr set <%= veth_mac %> \
accept;
oifname != "<%= brdev %>b" \
arp operation request \
arp daddr ip 169.254.16.9 \
drop;
};
};
NFT
Expand Down Expand Up @@ -149,7 +144,7 @@ def self.disable_tproxy(nic, endpoints)
nft(ERB.new(<<~NFT).result(binding))
table bridge one_tproxy {
chain ch_<%= brdev %> {
type filter hook prerouting priority dstnat; policy accept;
type filter hook forward priority filter; policy accept;
};
};
delete chain bridge one_tproxy ch_<%= brdev %>;
Expand Down

0 comments on commit 0bd4511

Please sign in to comment.