Skip to content

Commit

Permalink
solairs11_network: Handle solaris 11 zone interfaces
Browse files Browse the repository at this point in the history
PHYSRUNNING is now a valid flag for an interface.

The Solaris 11 zones "route -n get default” command output returns the
interface name, net0, but not the specific instance net0:2. The output
changed from Solaris 10 to Solaris 11. Use the verbose output
"route -v -n get default" to find the interface index and use the
name and index to find the full interface name from the ifconfig -a
output.
  • Loading branch information
MarkGibbons committed Feb 18, 2016
1 parent afa2500 commit dd869ae
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 25 deletions.
57 changes: 37 additions & 20 deletions lib/ohai/plugins/solaris2/network.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,37 @@

# EXAMPLE SOLARIS IFCONFIG OUTPUT; CURRENTLY, ONLY SIMPLE STUFF IS SUPPORTED (E.G., NO TUNNELS)
# DEAR SUN: YOU GET AN F FOR YOUR IFCONFIG
#lo0:3: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu 8232 index 1
# lo0:3: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu 8232 index 1
# inet 127.0.0.1 netmask ff000000
#e1000g0:3: flags=201000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4,CoS> mtu 1500 index 3
# e1000g0:3: flags=201000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4,CoS> mtu 1500 index 3
# inet 72.2.115.28 netmask ffffff80 broadcast 72.2.115.127
#e1000g2:1: flags=201000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4,CoS> mtu 1500 index 4
# e1000g2:1: flags=201000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4,CoS> mtu 1500 index 4
# inet 10.2.115.28 netmask ffffff80 broadcast 10.2.115.127
# inet6 2001:0db8:3c4d:55:a00:20ff:fe8e:f3ad/64
#ip.tun0: flags=2200851<UP,POINTOPOINT,RUNNING,MULTICAST,NONUD,IPv6> mtu 1480 index 3
# ip.tun0: flags=2200851<UP,POINTOPOINT,RUNNING,MULTICAST,NONUD,IPv6> mtu 1480 index 3
# inet tunnel src 109.146.85.57 tunnel dst 109.146.85.212
# tunnel security settings --> use 'ipsecconf -ln -i ip.tun1'
# tunnel hop limit 60
# inet6 fe80::6d92:5539/10 --> fe80::6d92:55d4
#ip.tun0:1: flags=2200851<UP,POINTOPOINT,RUNNING,MULTICAST,NONUD,IPv6> mtu 1480 index 3
# ip.tun0:1: flags=2200851<UP,POINTOPOINT,RUNNING,MULTICAST,NONUD,IPv6> mtu 1480 index 3
# inet6 2::45/128 --> 2::46
#lo0: flags=1000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4> mtu 8232 index 1
# lo0: flags=1000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4> mtu 8232 index 1
# inet 127.0.0.1 netmask ff000000
#eri0: flags=1004843<UP,BROADCAST,RUNNING,MULTICAST,DHCP,IPv4> mtu 1500 \
#index 2
# eri0: flags=1004843<UP,BROADCAST,RUNNING,MULTICAST,DHCP,IPv4> mtu 1500 \
# index 2
# inet 172.17.128.208 netmask ffffff00 broadcast 172.17.128.255
#ip6.tun0: flags=10008d1<UP,POINTOPOINT,RUNNING,NOARP,MULTICAST,IPv4> \
#mtu 1460
# ip6.tun0: flags=10008d1<UP,POINTOPOINT,RUNNING,NOARP,MULTICAST,IPv4> \
# mtu 1460
# index 3
# inet6 tunnel src fe80::1 tunnel dst fe80::2
# tunnel security settings --> use 'ipsecconf -ln -i ip.tun1'
# tunnel hop limit 60 tunnel encapsulation limit 4
# inet 10.0.0.208 --> 10.0.0.210 netmask ff000000
#qfe1: flags=2000841<UP,RUNNING,MULTICAST,IPv6> mtu 1500 index 3
# qfe1: flags=2000841<UP,RUNNING,MULTICAST,IPv6> mtu 1500 index 3
# usesrc vni0
# inet6 fe80::203:baff:fe17:4be0/10
# ether 0:3:ba:17:4b:e0
#vni0: flags=2002210041<UP,RUNNING,NOXMIT,NONUD,IPv6,VIRTUAL> mtu 0
# vni0: flags=2002210041<UP,RUNNING,NOXMIT,NONUD,IPv6,VIRTUAL> mtu 0
# index 5
# srcof qfe1
# inet6 fe80::203:baff:fe17:4444/128
Expand All @@ -58,7 +58,7 @@
dmfe e1000g efe elxl emlxs eri hermon hme hxge igb
iprb ipw iwh iwi iwk iwp ixgb ixgbe mwl mxfe myri10ge
nge ntxn nxge pcn platform qfe qlc ral rge rtls rtw rwd
rwn sfe tavor vr wpi xge yge} unless defined?(ETHERNET_ENCAPS)
rwn sfe tavor vr wpi xge yge } unless defined?(ETHERNET_ENCAPS)

Ohai.plugin(:Network) do
provides "network", "network/interfaces"
Expand All @@ -79,6 +79,15 @@ def arpname_to_ifname(iface, arpname)
nil
end

def partial_interface_name(iface, part_name, index)
iface.each do |name, attrs|
next unless attrs && attrs.respond_to?(:[])
return name if /^#{part_name}($|:)/.match(name) && attrs[:index] == index
end

nil
end

collect_data(:solaris2) do
require "scanf"

Expand All @@ -97,10 +106,10 @@ def arpname_to_ifname(iface, arpname)
iface[cint] = Mash.new unless iface[cint]
iface[cint][:mtu] = $2
iface[cint][:index] = $3
if line =~ / flags\=\d+\<((ADDRCONF|ANYCAST|BROADCAST|CoS|DEPRECATED|DHCP|DUPLICATE|FAILED|FIXEDMTU|INACTIVE|L3PROTECT|LOOPBACK|MIP|MULTI_BCAST|MULTICAST|NOARP|NOFAILOVER|NOLOCAL|NONUD|NORTEXCH|NOXMIT|OFFLINE|POINTOPOINT|PREFERRED|PRIVATE|ROUTER|RUNNING|STANDBY|TEMPORARY|UNNUMBERED|UP|VIRTUAL|XRESOLV|IPv4|IPv6|,)+)\>\s/
if line =~ / flags\=\d+\<((ADDRCONF|ANYCAST|BROADCAST|CoS|DEPRECATED|DHCP|DUPLICATE|FAILED|FIXEDMTU|INACTIVE|L3PROTECT|LOOPBACK|MIP|MULTI_BCAST|MULTICAST|NOARP|NOFAILOVER|NOLOCAL|NONUD|NORTEXCH|NOXMIT|OFFLINE|PHYSRUNNING|POINTOPOINT|PREFERRED|PRIVATE|ROUTER|RUNNING|STANDBY|TEMPORARY|UNNUMBERED|UP|VIRTUAL|XRESOLV|IPv4|IPv6|,)+)\>\s/
flags = $1.split(",")
else
flags = Array.new
flags = []
end
iface[cint][:flags] = flags.flatten
if cint =~ /^(\w+)(\d+.*)/
Expand Down Expand Up @@ -156,16 +165,24 @@ def arpname_to_ifname(iface, arpname)

network[:interfaces] = iface

so = shell_out("route -n get default")
so = shell_out("route -v -n get default")
so.stdout.lines do |line|
matches = /interface: (\S+)/.match(line)
matches = /interface: (?<name>\S+)\s+index\s+(?<index>\d+)/.match(line)
if matches
Ohai::Log.debug("found gateway device: #{$1}")
network[:default_interface] = matches[1]
network[:default_interface] =
case
when iface[matches[:name]]
matches[:name]
when int_name = partial_interface_name(iface, matches[:name], matches[:index])
int_name
else
matches[:name]
end
Ohai::Log.debug("found interface device: #{network[:default_interface]} #{matches[:name]}")
end
matches = /gateway: (\S+)/.match(line)
if matches
Ohai::Log.debug("found gateway: #{$1}")
Ohai::Log.debug("found gateway: #{matches[1]}")
network[:default_gateway] = matches[1]
end
end
Expand Down
41 changes: 36 additions & 5 deletions spec/unit/plugins/solaris2/network_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
net0: flags=40201000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4,CoS,L3PROTECT> mtu 1500 index 2
inet 37.153.96.148 netmask fffffe00 broadcast 37.153.97.255
ether 90:b8:d0:16:9b:97
net1:1: flags=100001000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4,PHYSRUNNING> mtu 1500 index 2
inet 10.16.125.36 netmask fffffe00 broadcast 10.16.125.255
ether 90:b8:d0:16:9b:97
ip.tun0: flags=2200851<UP,POINTOPOINT,RUNNING,MULTICAST,NONUD,IPv6> mtu 1480 index 3
inet tunnel src 109.146.85.57 tunnel dst 109.146.85.212
tunnel security settings --> use 'ipsecconf -ln -i ip.tun1'
Expand Down Expand Up @@ -103,7 +106,18 @@
destination: default
mask: default
gateway: 10.13.37.1
interface: e1000g0
interface: e1000g0 index 3
flags: <UP,GATEWAY,DONE,STATIC>
recvpipe sendpipe ssthresh rtt,ms rttvar,ms hopcount mtu expire
0 0 0 0 0 0 1500 0
ROUTE_GET

@solaris11_route_get = <<-ROUTE_GET
route to: default
destination: default
mask: default
gateway: 10.13.37.1
interface: net1 index 2
flags: <UP,GATEWAY,DONE,STATIC>
recvpipe sendpipe ssthresh rtt,ms rttvar,ms hopcount mtu expire
0 0 0 0 0 0 1500 0
Expand All @@ -117,13 +131,13 @@

allow(@plugin).to receive(:shell_out).with("ifconfig -a").and_return(mock_shell_out(0, @solaris_route_get, ""))
allow(@plugin).to receive(:shell_out).with("arp -an").and_return(mock_shell_out(0, @solaris_arp_rn, ""))
allow(@plugin).to receive(:shell_out).with("route -n get default").and_return(mock_shell_out(0, @soalris_route_get, ""))
allow(@plugin).to receive(:shell_out).with("route -v -n get default").and_return(mock_shell_out(0, @solaris_route_get, ""))
end

describe "gathering IP layer address info" do
before do
@stdout = double("Pipe, stdout, cmd=`route get default`", :read => @solaris_route_get)
allow(@plugin).to receive(:shell_out).with("route -n get default").and_return(mock_shell_out(0, @solaris_route_get, ""))
allow(@plugin).to receive(:shell_out).with("route -v -n get default").and_return(mock_shell_out(0, @solaris_route_get, ""))
allow(@plugin).to receive(:shell_out).with("ifconfig -a").and_return(mock_shell_out(0, @solaris_ifconfig, ""))
@plugin.run
end
Expand All @@ -133,7 +147,7 @@
end

it "detects the interfaces" do
expect(@plugin["network"]["interfaces"].keys.sort).to eq(["e1000g0:3", "e1000g2:1", "eri0", "ip.tun0", "ip.tun0:1", "lo0", "lo0:3", "net0", "qfe1"])
expect(@plugin["network"]["interfaces"].keys.sort).to eq(["e1000g0:3", "e1000g2:1", "eri0", "ip.tun0", "ip.tun0:1", "lo0", "lo0:3", "net0", "net1:1", "qfe1"])
end

it "detects the ip addresses of the interfaces" do
Expand All @@ -149,12 +163,29 @@
end
end

describe "gathering solaris 11 zone IP layer address info" do
before do
@stdout = double("Pipe, stdout, cmd=`route get default`", :read => @solaris11_route_get)
allow(@plugin).to receive(:shell_out).with("route -v -n get default").and_return(mock_shell_out(0, @solaris11_route_get, ""))
allow(@plugin).to receive(:shell_out).with("ifconfig -a").and_return(mock_shell_out(0, @solaris_ifconfig, ""))
@plugin.run
end

it "finds the flags for a PHYSRUNNING interface" do
expect(@plugin[:network][:interfaces]["net1:1"][:flags]).to eq(%w{ UP BROADCAST RUNNING MULTICAST IPv4 PHYSRUNNING })
end

it "finds the default interface for a solaris 11 zone" do
expect(@plugin[:network][:default_interface]).to eq("net1:1")
end
end

# TODO: specs for the arp -an stuff, check that it correctly adds the MAC addr to the right iface, etc.

describe "setting the node's default IP address attribute" do
before do
@stdout = double("Pipe, stdout, cmd=`route get default`", :read => @solaris_route_get)
allow(@plugin).to receive(:shell_out).with("route -n get default").and_return(mock_shell_out(0, @solaris_route_get, ""))
allow(@plugin).to receive(:shell_out).with("route -v -n get default").and_return(mock_shell_out(0, @solaris_route_get, ""))
@plugin.run
end

Expand Down

0 comments on commit dd869ae

Please sign in to comment.