From 434b28a16d81d3623d284476ba1b86fb19b6ee07 Mon Sep 17 00:00:00 2001 From: Phil Dibowitz Date: Tue, 19 Dec 2017 18:14:56 -0800 Subject: [linux/network] Tunnel information (#1104) This gathers extra information on tunnel devices. Unfortunately iproute2 is a little inconsistent as to how it prints these out, some are booleans some are key values, but there's no way to tell them apart other than to know, so I parse the ones I know about (from reading the source), and ignore anything else. Note that I didn't add any ifconfig support to the tests. This is for a few reasons: 1. the output in the tests from ifconfig is ancient, ifconfig on linux doesn't look like that anymore, it looks like this: ``` eth0: flags=4163 mtu 1500 inet 10.1.1.2 netmask 255.255.255.0 broadcast 10.1.1.255 inet6 2601:645:c001:56bb::2 prefixlen 64 scopeid 0x0 inet6 fe80::52e5:49ff:fe38:d761 prefixlen 64 scopeid 0x20 ether 50:e5:49:38:d7:61 txqueuelen 1000 (Ethernet) RX packets 203501353 bytes 98738916585 (91.9 GiB) RX errors 0 dropped 559 overruns 0 frame 0 TX packets 1035989265 bytes 1458478887585 (1.3 TiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 ``` And I couldn't find a machine old enough to generate the type of output in the tests *and* have modern ip6tunnel drivers on it. So don't ask. :) 2. Only iproute2 shows the extra tunnel info anyway, so it's not really useful to do have the interface in the ifconfig output. Note I will backport this to Ohai 8 after this is merged. Signed-off-by: Phil Dibowitz --- lib/ohai/plugins/linux/network.rb | 25 ++++++++++++++++++++++ spec/unit/plugins/linux/network_spec.rb | 37 ++++++++++++++++++++++++++++++++- 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/lib/ohai/plugins/linux/network.rb b/lib/ohai/plugins/linux/network.rb index 296941fb..3f1e0b4e 100644 --- a/lib/ohai/plugins/linux/network.rb +++ b/lib/ohai/plugins/linux/network.rb @@ -212,6 +212,31 @@ Ohai.plugin(:Network) do net_counters[tmp_int] = Mash.new unless net_counters[tmp_int] end + if line =~ /^\s+(ip6tnl|ipip)/ + iface[tmp_int][:tunnel_info] = {} + words = line.split + words.each_with_index do |word, index| + case word + when "external" + iface[tmp_int][:tunnel_info][word] = true + when "any", "ipip6", "ip6ip6" + iface[tmp_int][:tunnel_info][:proto] = word + when "remote", + "local", + "encaplimit", + "hoplimit", + "tclass", + "flowlabel", + "addrgenmode", + "numtxqueues", + "numrxqueues", + "gso_max_size", + "gso_max_segs" + iface[tmp_int][:tunnel_info][word] = words[index + 1] + end + end + end + if line =~ /(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/ int = on_rx ? :rx : :tx net_counters[tmp_int][int] = Mash.new unless net_counters[tmp_int][int] diff --git a/spec/unit/plugins/linux/network_spec.rb b/spec/unit/plugins/linux/network_spec.rb index b0c5ad06..a0574da0 100644 --- a/spec/unit/plugins/linux/network_spec.rb +++ b/spec/unit/plugins/linux/network_spec.rb @@ -234,6 +234,10 @@ EOM valid_lft forever preferred_lft forever 13: fwdintf: mtu 1496 qdisc pfifo_fast state UNKNOWN group default qlen 1000 link/ether 00:00:00:00:00:0a brd ff:ff:ff:ff:ff:ff +14: ip6tnl0@NONE: mtu 1452 qdisc noqueue state UNKNOWN group default qlen 1 + link/tunnel6 :: brd :: + inet6 fe80::f47a:2aff:fef0:c6ef/64 scope link + valid_lft forever preferred_lft forever EOM end @@ -294,6 +298,13 @@ EOM 0 0 0 0 0 0 TX: bytes packets errors dropped carrier collsns 140 2 0 1 0 0 +14: ip6tnl0@NONE: mtu 1452 qdisc noop state DOWN mode DEFAULT group default qlen 1 + link/tunnel6 :: brd :: promiscuity 0 + ip6tnl ip6ip6 remote :: local :: encaplimit 0 hoplimit 0 tclass 0x00 flowlabel 0x00000 (flowinfo 0x00000000) addrgenmode eui64 numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535 + RX: bytes packets errors dropped overrun mcast + 0 0 0 0 0 0 + TX: bytes packets errors dropped carrier collsns + 0 0 0 0 0 0 EOM end @@ -546,7 +557,11 @@ EOM end it "detects the interfaces" do - expect(plugin["network"]["interfaces"].keys.sort).to eq(["eth0", "eth0.11", "eth0.151", "eth0.152", "eth0.153", "eth0:5", "eth3", "foo:veth0@eth0", "fwdintf", "lo", "ovs-system", "tun0", "venet0", "venet0:0", "xapi1"]) + if network_method == "iproute2" + expect(plugin["network"]["interfaces"].keys.sort).to eq(["eth0", "eth0.11", "eth0.151", "eth0.152", "eth0.153", "eth0:5", "eth3", "foo:veth0@eth0", "fwdintf", "ip6tnl0", "lo", "ovs-system", "tun0", "venet0", "venet0:0", "xapi1"]) + else + expect(plugin["network"]["interfaces"].keys.sort).to eq(["eth0", "eth0.11", "eth0.151", "eth0.152", "eth0.153", "eth0:5", "eth3", "foo:veth0@eth0", "fwdintf", "lo", "ovs-system", "tun0", "venet0", "venet0:0", "xapi1"]) + end end it "detects the layer one details of an ethernet interface" do @@ -650,6 +665,26 @@ EOM expect(plugin["network"]["interfaces"]["eth0"]["arp"]["10.116.201.1"]).to eq("fe:ff:ff:ff:ff:ff") end + if network_method == "iproute2" + it "detects the tunnel information" do + expect(plugin["network"]["interfaces"]["ip6tnl0"]["tunnel_info"]).to eq( + { + "proto" => "ip6ip6", + "remote" => "::", + "local" => "::", + "encaplimit" => "0", + "hoplimit" => "0", + "tclass" => "0x00", + "flowlabel" => "0x00000", + "addrgenmode" => "eui64", + "numtxqueues" => "1", + "numrxqueues" => "1", + "gso_max_size" => "65536", + "gso_max_segs" => "65535", + } + ) + end + end end describe "gathering interface counters via #{network_method}" do -- cgit v1.2.1