Skip to content
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

network plugin is broken on v6 only hosts #685

Closed
jaymzh opened this issue Dec 16, 2015 · 9 comments
Closed

network plugin is broken on v6 only hosts #685

jaymzh opened this issue Dec 16, 2015 · 9 comments

Comments

@jaymzh
Copy link
Collaborator

jaymzh commented Dec 16, 2015

  • It can't determine macaddress largely because the code doesn't try:
if family[:name] == "inet"
  ipaddress route[:src]
  macaddress iface[route[:dev]][:addresses].select{|k,v| v["family"]=="lladdr"}.first.first unless iface[route[:dev]][:flags].include? "NOARP"
  else
    ip6address route[:src]
  end
end

Talk about epic clowntown. But even when you ammend that to pick up macaddress there, it won't work and this is because above that it does some route selection magic:

          route = routes.select do |r|
            # selecting routes
            r[:src] and # it has a src field
              iface[r[:dev]] and # the iface exists
              iface[r[:dev]][:addresses].has_key? r[:src] and # the src ip is set on the node
              iface[r[:dev]][:addresses][r[:src]][:scope].downcase != "link" and # this isn't a link level addresse
              ( r[:destination] == "default" or
                ( default_route[:via] and # the default route has a gateway
                  IPAddress(r[:destination]).include? IPAddress(default_route[:via]) # the route matches the gateway
                  )
                )
          end.sort_by do |r|

Which doesn't work because there is no src on your average v6 routes:

default via fe80::290:27ff:fe9d:6015 dev eth0  proto ra  metric 1024  expires 1762sec hoplimit 64 pref medium

So that code doesn't even come close to working. Therefore there's no route to look at so that mac-address selection code can't possibly work.

@jaymzh
Copy link
Collaborator Author

jaymzh commented Dec 16, 2015

This horribleness makes it sorta work for me... but I"m very unclear on 1. How network.rb and linux/network.rb are working together (and somehow both touch the same attr which is crazy to me) or 2. How this routewalking is supposed to work... but maybe this can get someone started:

[phild@dev2373 (master) plugins]$ git diff
diff --git a/lib/ohai/plugins/linux/network.rb b/lib/ohai/plugins/linux/network.rb
index 689001d..7e436b7 100644
--- a/lib/ohai/plugins/linux/network.rb
+++ b/lib/ohai/plugins/linux/network.rb
@@ -406,12 +406,19 @@ Ohai.plugin(:Network) do
             ]
           end.first

-          unless route.nil? or route.empty?
+          if route and !route.empty?
             if family[:name] == "inet"
               ipaddress route[:src]
               macaddress iface[route[:dev]][:addresses].select{|k,v| v["family"]=="lladdr"}.first.first unless iface[route[:dev]][:flags].include? "NOARP"
             else
               ip6address route[:src]
+              macaddress iface[route[:dev]][:addresses].select{|k,v| v["family"]=="lladdr"}.first.first unless iface[route[:dev]][:flags].include? "NOARP"
+            end
+          else
+            if family[:name] == "inet"
+              macaddress iface[default_route[:dev]][:addresses].select{|k,v| v["family"]=="lladdr"}.first.first unless iface[default_route[:dev]][:flags].include? "NOARP"
+            else
+              macaddress iface[default_route[:dev]][:addresses].select{|k,v| v["family"]=="lladdr"}.first.first unless iface[default_route[:dev]][:flags].include? "NOARP"
             end
           end
         end
diff --git a/lib/ohai/plugins/network.rb b/lib/ohai/plugins/network.rb
index bc95a65..d25bd09 100644
--- a/lib/ohai/plugins/network.rb
+++ b/lib/ohai/plugins/network.rb
@@ -159,7 +159,7 @@ Ohai.plugin(:NetworkAddresses) do
           Ohai::Log.debug("unable to detect ip6address")
         else
           ip6address r["ip"]
-          if r["mac"] and macaddress.nil? and ipaddress.nil?
+          if r["mac"] and macaddress.nil?
             Ohai::Log.debug("macaddress set to #{r["mac"]} from the ipv6 setup")
             macaddress r["mac"]
           end

@tas50
Copy link
Contributor

tas50 commented Dec 17, 2015

@tas50
Copy link
Contributor

tas50 commented Dec 17, 2015

@jaymzh Any chance you help me understand the exact network setup you're using? I haven't run IPv6 on Linux before so what someone's setup would look like is a bit unknown to me. Our current tests check for a system running IPv6 only, as in even lo has no IPv4 address. That seems to work as expected. What we're not testing for, and not handling apparently, is IPv4/IPv6 on lo, but only IPv6 on the actual interfaces. I assume that's the more likely scenario for most people and what you're running?

@jaymzh
Copy link
Collaborator Author

jaymzh commented Dec 17, 2015

What do you mean it works as expected - your gist above shows the problem precisely:

https://gist.github.com/tas50/dbb18c4644f8281b29a4#file-gistfile1-txt-L44

And yes, I can send you a private gist with route tables and interface configs if you'd like.

@tas50
Copy link
Contributor

tas50 commented Dec 17, 2015

@jaymzh When I referred to working as expected I meant on an absolutely pure IPv6 only host, which I suspect is not what most IPv6 setups look like. Things are absolutely not working as expected for a simple IPv6 setup. If you want to shoot me a gist at tsmith at chef.io that would really help.

@jaymzh
Copy link
Collaborator Author

jaymzh commented Dec 18, 2015

Done.

@jaymzh
Copy link
Collaborator Author

jaymzh commented Dec 18, 2015

tldr; Generally speaking, 127.0.0.1 is always going to work - you don't need external v4 for that and too many things hard-code it. We have no v4 addr on eth0.

@btm
Copy link
Contributor

btm commented Dec 24, 2015

@jaymzh @tas50 can one of you forward me those route tables? [email protected].

@jaymzh
Copy link
Collaborator Author

jaymzh commented Dec 24, 2015 via email

@tas50 tas50 closed this as completed in #695 Jan 8, 2016
@chef chef locked and limited conversation to collaborators Nov 16, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants