diff options
author | Cooper Lees <me@cooperlees.com> | 2020-06-24 11:53:28 -0700 |
---|---|---|
committer | Cooper Lees <me@cooperlees.com> | 2020-06-24 12:46:21 -0700 |
commit | d83afc7244cf63be9f27cb424ba754245c2ecbcf (patch) | |
tree | 25633e896bea23c165daf6f92f102d74ee91b103 | |
parent | ae23ca40a68b58dbff20e20a47105c265ceb0ce2 (diff) | |
download | ohai-d83afc7244cf63be9f27cb424ba754245c2ecbcf.tar.gz |
Linux network plugin: Handle IPv6 next hops for IPv4 routes
- Add handling for `via` where the inet6 address family is specified
- Add rspec test to show working
Addresses part of #1474
Signed-off-by: Cooper Lees <me@cooperlees.com>
-rw-r--r-- | lib/ohai/plugins/linux/network.rb | 4 | ||||
-rw-r--r-- | spec/unit/plugins/linux/network_spec.rb | 18 |
2 files changed, 22 insertions, 0 deletions
diff --git a/lib/ohai/plugins/linux/network.rb b/lib/ohai/plugins/linux/network.rb index e92c149a..87ee4808 100644 --- a/lib/ohai/plugins/linux/network.rb +++ b/lib/ohai/plugins/linux/network.rb @@ -105,6 +105,10 @@ Ohai.plugin(:Network) do route_entry = Mash.new(destination: route_dest, family: family[:name]) %w{via scope metric proto src}.each do |k| + if k == 'via' && route_ending =~ /\bvia\sinet6\s+([^\s]+)/ + route_entry[k] = $1 + next + end # http://rubular.com/r/pwTNp65VFf route_entry[k] = $1 if route_ending =~ /\b#{k}\s+([^\s]+)/ end diff --git a/spec/unit/plugins/linux/network_spec.rb b/spec/unit/plugins/linux/network_spec.rb index 8aa11336..f10e3e88 100644 --- a/spec/unit/plugins/linux/network_spec.rb +++ b/spec/unit/plugins/linux/network_spec.rb @@ -1500,6 +1500,24 @@ describe Ohai::System, "Linux Network Plugin" do expect(plugin["network"]["interfaces"]["eth0.11"]["vlan"]["flags"]).to eq([ "REORDER_HDR" ]) end end + + # Test we can handle IPv4 with inet6 IPv6 next hops + describe "using IPv6 next hops for IPv4 routes" do + let(:linux_ip_route) do + <<~EOM + default via inet6 fe80::69 dev eth0 metric 69 + EOM + end + + it "expect an IPv6 next hop and not keyword inet6" do + expect(plugin["network"]["interfaces"]["eth0"]["routes"]).to eq( + [ + {"destination"=>"default", "family"=>"inet", "metric" => "69", "via"=>"fe80::69"}, + {"destination"=>"fe80::/64", "family"=>"inet6", "metric"=>"256", "proto"=>"kernel"}, + ] + ) + end + end end end end |