summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2020-08-03 21:41:05 -0700
committerGitHub <noreply@github.com>2020-08-03 21:41:05 -0700
commit29e5199d6ddbc0028c6ea461225d3dcb29fe8cf1 (patch)
tree5a36b76e8414c56a13ca109c25cbae1fd01b2a4e
parenta2891c01cfc3452839d137eb0c74a2fd298f1a93 (diff)
parent7a69596b6b3ec02f09d7f43b57c615e4a1c06881 (diff)
downloadohai-29e5199d6ddbc0028c6ea461225d3dcb29fe8cf1.tar.gz
Merge pull request #1485 from cooperlees/route_is_valid_default_route_af
Add Address Family Check to route_is_valid_default_route?
-rw-r--r--lib/ohai/plugins/linux/network.rb10
-rw-r--r--spec/unit/plugins/linux/network_spec.rb9
2 files changed, 18 insertions, 1 deletions
diff --git a/lib/ohai/plugins/linux/network.rb b/lib/ohai/plugins/linux/network.rb
index 0e24c88f..7d0d2de8 100644
--- a/lib/ohai/plugins/linux/network.rb
+++ b/lib/ohai/plugins/linux/network.rb
@@ -516,8 +516,16 @@ Ohai.plugin(:Network) do
# if the route destination is a default route, it's good
return true if route[:destination] == "default"
+ return false if default_route[:via].nil?
+
+ dest_ipaddr = IPAddress(route[:destination])
+ default_route_via = IPAddress(default_route[:via])
+
+ # check if nexthop is the same address family
+ return false if dest_ipaddr.ipv4? != default_route_via.ipv4?
+
# the default route has a gateway and the route matches the gateway
- !default_route[:via].nil? && IPAddress(route[:destination]).include?(IPAddress(default_route[:via]))
+ dest_ipaddr.include?(default_route_via)
end
# ipv4/ipv6 routes are different enough that having a single algorithm to select the favored route for both creates unnecessary complexity
diff --git a/spec/unit/plugins/linux/network_spec.rb b/spec/unit/plugins/linux/network_spec.rb
index c384b9b0..70b1ec45 100644
--- a/spec/unit/plugins/linux/network_spec.rb
+++ b/spec/unit/plugins/linux/network_spec.rb
@@ -608,6 +608,15 @@ describe Ohai::System, "Linux Network Plugin" do
expect(plugin.route_is_valid_default_route?(route, default_route)).to eq(false)
end
end
+
+ context "when route and default_route via have different address family" do
+ let(:route) { { destination: "10.0.0.0/24" } }
+ let(:default_route) { { via: "fe80::69" } }
+
+ it "returns false" do
+ expect(plugin.route_is_valid_default_route?(route, default_route)).to eq(false)
+ end
+ end
end
end