summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryan McLellan <btm@chef.io>2016-01-02 17:10:40 -0800
committerBryan McLellan <btm@chef.io>2016-01-02 17:10:40 -0800
commit6543fa0844f72ced82355424810b33b8de821199 (patch)
treec3b0eafe37ac4a2dbeb02bb95609b518d68cfc77
parentf14ebfbc5fd72160320860d1c15c6aba59f9967b (diff)
downloadohai-6543fa0844f72ced82355424810b33b8de821199.tar.gz
We cannot get ipv6address without src from linux/network at this time
-rw-r--r--lib/ohai/plugins/linux/network.rb5
-rw-r--r--spec/unit/plugins/linux/network_spec.rb30
2 files changed, 20 insertions, 15 deletions
diff --git a/lib/ohai/plugins/linux/network.rb b/lib/ohai/plugins/linux/network.rb
index 6bf0ea47..0bc90ad1 100644
--- a/lib/ohai/plugins/linux/network.rb
+++ b/lib/ohai/plugins/linux/network.rb
@@ -324,6 +324,7 @@ Ohai.plugin(:Network) do
# ipv4/ipv6 routes are different enough that having a single algorithm to select the favored route for both creates unnecessary complexity
# this method attempts to deduce the route that is most important to the user, which is later used to deduce the favored values for {ip,mac,ip6}address
+ # we only consider routes that are default routes, or those routes that get us to the gateway for a default route
def favored_default_route(routes, iface, default_route, family)
routes.select do |r|
if family[:name] == "inet"
@@ -438,6 +439,8 @@ Ohai.plugin(:Network) do
# deduce the default route the user most likely cares about to pick {ip,mac,ip6}address below
favored_route = favored_default_route(routes, iface, default_route, family)
+ # FIXME: This entire block should go away, and the network plugin should be the sole source of {ip,ip6,mac}address
+
# since we're at it, let's populate {ip,mac,ip6}address with the best values
# if we don't set these, the network plugin may set them afterwards
if favored_route && !favored_route.empty?
@@ -447,7 +450,7 @@ Ohai.plugin(:Network) do
Ohai::Log.debug("Overwriting macaddress #{macaddress} with #{m} from interface #{favored_route[:dev]}") if macaddress
macaddress m
elsif family[:name] == "inet6"
- # FIXME: we're going to have to guess here when we don't have source
+ # this rarely does anything since we rarely have src for ipv6, so this usually falls back on the network plugin
ip6address favored_route[:src]
if macaddress
Ohai::Log.debug("Not setting macaddress from ipv6 interface #{favored_route[:dev]} because macaddress is already set")
diff --git a/spec/unit/plugins/linux/network_spec.rb b/spec/unit/plugins/linux/network_spec.rb
index e08de3bf..ab9387ef 100644
--- a/spec/unit/plugins/linux/network_spec.rb
+++ b/spec/unit/plugins/linux/network_spec.rb
@@ -805,7 +805,7 @@ default via 1111:2222:3333:4444::ffff dev eth0.11 metric 1023 src 1111:2222:333
end
end
- describe "when there's a source field in a local route entry" do
+ describe "when there's a source field in a local route entry but it isnt in the default route" do
let(:linux_ip_route) {
'10.116.201.0/24 dev eth0 proto kernel src 10.116.201.76
192.168.5.0/24 dev eth0 proto kernel src 192.168.5.1
@@ -835,6 +835,21 @@ default via 1111:2222:3333:4444::1 dev eth0.11 metric 1024
expect(plugin['ipaddress']).to eq("10.116.201.76")
end
+ # without a source address on the default route we cannot pick the an ipv6 address from the interface
+ # In the future an RFC6724 compliant process should choose ip6address in the network plugin
+ it "does not set ip6address" do
+ plugin.run
+ expect(plugin['ip6address']).to eq(nil)
+ end
+
+ context "with only ipv6 routes" do
+ let(:linux_ip_route) { '' }
+
+ it "sets macaddress to the mac address of the ip6 default interface" do
+ expect(plugin['macaddress']).to eq("00:AA:BB:CC:DD:EE")
+ end
+ end
+
describe "when about to set macaddress" do
it "sets macaddress" do
plugin.run
@@ -861,19 +876,6 @@ default via 172.16.19.1 dev tun0
end
end
end
-
- it "sets ip6address" do
- plugin.run
- expect(plugin['ip6address']).to eq("1111:2222:3333:4444::3")
- end
-
- context "with only ipv6 routes" do
- let(:linux_ip_route) { '' }
-
- it "sets macaddress to the mac address of the ip6 default interface" do
- expect(plugin['macaddress']).to eq("00:AA:BB:CC:DD:EE")
- end
- end
end
describe "with a link level default route" do