diff options
author | Matt Phillips <mphillips81@bloomberg.net> | 2022-03-11 13:07:41 -0500 |
---|---|---|
committer | Matt Phillips <mphillips81@bloomberg.net> | 2022-05-16 17:03:51 -0400 |
commit | 88484dd2a15d18150a520061b6a0e7de1c80370d (patch) | |
tree | ebbeb201bcfa46fde0db82507e4b6a8d54926e48 /lib | |
parent | ecac9bc41e7aff16786af373029d685ac7f558d4 (diff) | |
download | ohai-88484dd2a15d18150a520061b6a0e7de1c80370d.tar.gz |
networking/linux: map src only default routes accordingly
in certain configurations a default route can be set via src only / not
dev, but should still be accounted for in terms of calculating the
'favored' default route / what is chosen as ipaddress for a given node.
This change augments the previously added changes to account for nexthop
multipath routing; but only in scenarios src address is set but only in
scenarios src address is set.
Signed-off-by: Matt Phillips <mphillips81@bloomberg.net>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ohai/plugins/linux/network.rb | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/ohai/plugins/linux/network.rb b/lib/ohai/plugins/linux/network.rb index 4a5ddb3c..cbecae86 100644 --- a/lib/ohai/plugins/linux/network.rb +++ b/lib/ohai/plugins/linux/network.rb @@ -103,9 +103,20 @@ Ohai.plugin(:Network) do next end route_endings.each do |route_ending| + route_int = nil if route_ending =~ /\bdev\s+([^\s]+)\b/ route_int = $1 - else + end + # does any known interface own the src address? + # we want to override the interface set via nexthop but only if possible + if line =~ /\bsrc\s+([^\s]+)\b/ && (!route_int || line.include?("nexthop")) + # only clobber previously set route_int if we find a match + if (match = iface.select { |name, intf| intf.fetch("addresses", {}).any? { |addr, _| addr == $1 } }.keys.first) + route_int = match + end + end + + unless route_int logger.trace("Plugin Network: Skipping route entry without a device: '#{line}'") next end |