summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn McCrae <john.mccrae@progress.com>2023-01-25 15:30:14 +0600
committerGitHub <noreply@github.com>2023-01-25 15:00:14 +0530
commitd908608efb78d86aa1139760db851f3951d23301 (patch)
tree56e69607370a0097ead45cf07a8de5a35b21f70c
parent4df568953f07d5b9936be8931a946334df7d37be (diff)
downloadohai-d908608efb78d86aa1139760db851f3951d23301.tar.gz
Testing new Linux Network Plugin settings ported from Chef-18 (#1778)
Signed-off-by: John McCrae <john.mccrae@progress.com> Remove filter_map which is not available in ruby 2.6 Signed-off-by: Neha Pansare <neha.pansare@progress.com> Update syntax to get array elements exept first Signed-off-by: Neha Pansare <neha.pansare@progress.com> Fix linting, rescue registry call in packages plugin same has been done on main due to which the packages_spec.rb don't fail there https://github.com/chef/ohai/pull/1699/files\#diff-502d0db7f8ed18fe06ed8d24cd73481e897a269069631efcdf90058c8294e0b9R139 Signed-off-by: Neha Pansare <neha.pansare@progress.com>
-rw-r--r--lib/ohai/plugins/linux/network.rb92
-rw-r--r--lib/ohai/plugins/packages.rb2
-rw-r--r--spec/unit/plugins/linux/network_spec.rb252
3 files changed, 314 insertions, 32 deletions
diff --git a/lib/ohai/plugins/linux/network.rb b/lib/ohai/plugins/linux/network.rb
index 8f1274a3..b8618662 100644
--- a/lib/ohai/plugins/linux/network.rb
+++ b/lib/ohai/plugins/linux/network.rb
@@ -80,9 +80,22 @@ Ohai.plugin(:Network) do
line.strip!
logger.trace("Plugin Network: Parsing #{line}")
if /\\/.match?(line)
- parts = line.split('\\')
- route_dest = parts.shift.strip
- route_endings = parts
+ # If we have multipath routing, then the first part will be a normal
+ # looking route:
+ # default proto ra metric 1024 <other options>
+ # Each successive part after that is a hop without those options.
+ # So the first thing we do is grab that first part, and split it into
+ # the route destination ("default"), and the route options.
+ parts = line.split("\\")
+ route_dest, dest_opts = parts.first.split(nil, 2)
+ # Then all the route endings, generally just nexthops.
+ route_endings = parts[1..-1]
+ if dest_opts && !dest_opts.empty?
+ # Route options like proto, metric, etc. only appear once for each
+ # multipath configuration. Prepend this information to the route
+ # endings so the code below will assign the fields properly.
+ route_endings.map! { |e| e.include?("nexthop") ? "#{dest_opts} #{e}" : e }
+ end
elsif line =~ /^([^\s]+)\s(.*)$/
route_dest = $1
route_endings = [$2]
@@ -90,9 +103,24 @@ Ohai.plugin(:Network) do
next
end
route_endings.each do |route_ending|
+ route_entry = Mash.new(destination: route_dest,
+ family: family[:name])
+ route_int = nil
if route_ending =~ /\bdev\s+([^\s]+)\b/
route_int = $1
- else
+ end
+ # does any known interface own the src address?
+ # we try to infer the interface/device from its address if it isn't specified
+ # we want to override the interface set via nexthop but only if possible
+ if line =~ /\bsrc\s+([^\s]+)\b/ && (!route_int || line.include?("nexthop"))
+ # only clobber previously set route_int if we find a match
+ if (match = iface.select { |name, intf| intf.fetch("addresses", {}).any? { |addr, _| addr == $1 } }.keys.first)
+ route_int = match
+ route_entry[:inferred] = true
+ end
+ end
+
+ unless route_int
logger.trace("Plugin Network: Skipping route entry without a device: '#{line}'")
next
end
@@ -103,8 +131,6 @@ Ohai.plugin(:Network) do
next
end
- route_entry = Mash.new(destination: route_dest,
- family: family[:name])
%w{via scope metric proto src}.each do |k|
# http://rubular.com/r/pwTNp65VFf
route_entry[k] = $1 if route_ending =~ /\b#{k}\s+([^\s]+)/
@@ -273,6 +299,30 @@ Ohai.plugin(:Network) do
iface
end
+ # determine offload features for the interface using ethtool
+ def ethernet_offload_parameters(iface)
+ return iface unless ethtool_binary_path
+
+ iface.each_key do |tmp_int|
+ next unless iface[tmp_int][:encapsulation] == "Ethernet"
+
+ so = shell_out("#{ethtool_binary_path} -k #{tmp_int}")
+ Ohai::Log.debug("Plugin Network: Parsing ethtool output: #{so.stdout}")
+ iface[tmp_int]["offload_params"] = {}
+ so.stdout.lines.each do |line|
+ next if line.start_with?("Features for")
+ next if line.strip.nil?
+
+ key, val = line.split(/:\s+/)
+ if val
+ offload_key = key.downcase.strip.tr(" ", "_").to_s
+ iface[tmp_int]["offload_params"][offload_key] = val.downcase.gsub(/\[.*\]/, "").strip.to_s
+ end
+ end
+ end
+ iface
+ end
+
# determine pause parameters for the interface using ethtool
def ethernet_pause_parameters(iface)
return iface unless ethtool_binary_path
@@ -326,6 +376,7 @@ Ohai.plugin(:Network) do
so = shell_out("ip -d -s link")
tmp_int = nil
on_rx = true
+ xdp_mode = nil
so.stdout.lines do |line|
if line =~ IPROUTE_INT_REGEX
tmp_int = $2
@@ -401,6 +452,30 @@ Ohai.plugin(:Network) do
if line =~ /\sstate (\w+)/
iface[tmp_int]["state"] = $1.downcase
end
+
+ if line.include?("xdp")
+ mode = line.scan(/\s(xdp|xdpgeneric|xdpoffload|xdpmulti)\s/).flatten[0]
+ # Fetches and sets the mode from the first line.
+ unless mode.nil?
+ iface[tmp_int][:xdp] = {}
+ if mode.eql?("xdp")
+ # In case of xdpdrv, mode is xdp,
+ # to keep it consistent, keeping mode as xdpdrv.
+ mode = "xdpdrv"
+ end
+ xdp_mode = mode
+ iface[tmp_int][:xdp][:attached] = []
+ end
+
+ if line =~ %r{prog/(\w+) id (\d+) tag (\w+)}
+ mode = $1.eql?("xdp") ? xdp_mode : $1
+ iface[tmp_int][:xdp][:attached] << {
+ mode: mode,
+ id: $2,
+ tag: $3,
+ }
+ end
+ end
end
iface
end
@@ -583,10 +658,12 @@ Ohai.plugin(:Network) do
# sorting the selected routes:
# - getting default routes first
# - then sort by metric
+ # - then sort by if the device was inferred or not (preferring explicit to inferred)
# - then by prefixlen
[
r[:destination] == "default" ? 0 : 1,
r[:metric].nil? ? 0 : r[:metric].to_i,
+ r[:inferred] ? 1 : 0,
# for some reason IPAddress doesn't accept "::/0", it doesn't like prefix==0
# just a quick workaround: use 0 if IPAddress fails
begin
@@ -793,9 +870,10 @@ Ohai.plugin(:Network) do
iface = ethernet_ring_parameters(iface)
iface = ethernet_channel_parameters(iface)
iface = ethernet_coalesce_parameters(iface)
+ iface = ethernet_offload_parameters(iface)
iface = ethernet_driver_info(iface)
iface = ethernet_pause_parameters(iface)
counters[:network][:interfaces] = net_counters
network["interfaces"] = iface
end
-end
+end \ No newline at end of file
diff --git a/lib/ohai/plugins/packages.rb b/lib/ohai/plugins/packages.rb
index 51136898..3245fce9 100644
--- a/lib/ohai/plugins/packages.rb
+++ b/lib/ohai/plugins/packages.rb
@@ -136,7 +136,7 @@ Ohai.plugin(:Packages) do
collect_programs_from_registry_key(Win32::Registry::HKEY_LOCAL_MACHINE, 'Software\Microsoft\Windows\CurrentVersion\Uninstall')
# on 64 bit systems, 32 bit programs are stored here moved before HKEY_CURRENT_USER otherwise it is not collected (impacts both ohai 16 & 17)
collect_programs_from_registry_key(Win32::Registry::HKEY_LOCAL_MACHINE, 'Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall')
- collect_programs_from_registry_key(Win32::Registry::HKEY_CURRENT_USER, 'Software\Microsoft\Windows\CurrentVersion\Uninstall')
+ collect_programs_from_registry_key(Win32::Registry::HKEY_CURRENT_USER, 'Software\Microsoft\Windows\CurrentVersion\Uninstall') rescue nil
# on 64 bit systems, 32 bit programs are stored here
end
diff --git a/spec/unit/plugins/linux/network_spec.rb b/spec/unit/plugins/linux/network_spec.rb
index 54c8d3fb..99eceb70 100644
--- a/spec/unit/plugins/linux/network_spec.rb
+++ b/spec/unit/plugins/linux/network_spec.rb
@@ -33,11 +33,9 @@ describe Ohai::System, "Linux Network Plugin" do
collisions:0 txqueuelen:1000
RX bytes:1392844460 (1.2 GiB) TX bytes:691785313 (659.7 MiB)
Interrupt:16
-
eth0:5 Link encap:Ethernet HWaddr 00:0c:29:41:71:45
inet addr:192.168.5.1 Bcast:192.168.5.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
-
eth0.11 Link encap:Ethernet HWaddr 00:aa:bb:cc:dd:ee
inet addr:192.168.0.16 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::2aa:bbff:fecc:ddee/64 Scope:Link
@@ -48,7 +46,6 @@ describe Ohai::System, "Linux Network Plugin" do
TX packets:3269635153 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1751940374 (1.6 GiB) TX bytes:2195567597 (2.0 GiB)
-
eth0.151 Link encap:Ethernet HWaddr 00:aa:bb:cc:dd:ee
inet addr:10.151.0.16 Bcast:10.151.0.255 Mask:255.255.255.0
inet6 addr: fe80::2aa:bbff:fecc:ddee/64 Scope:Link
@@ -57,7 +54,6 @@ describe Ohai::System, "Linux Network Plugin" do
TX packets:163901336 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:3190792261 (2.9 GiB) TX bytes:755086548 (720.1 MiB)
-
eth0.152 Link encap:Ethernet HWaddr 00:aa:bb:cc:dd:ee
inet addr:10.152.1.16 Bcast:10.152.3.255 Mask:255.255.252.0
inet6 addr: fe80::2aa:bbff:fecc:ddee/64 Scope:Link
@@ -66,7 +62,6 @@ describe Ohai::System, "Linux Network Plugin" do
TX packets:55232 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:664957462 (634.1 MiB) TX bytes:4876434 (4.6 MiB)
-
eth0.153 Link encap:Ethernet HWaddr 00:aa:bb:cc:dd:ee
inet addr:10.153.1.16 Bcast:10.153.3.255 Mask:255.255.252.0
inet6 addr: fe80::2aa:bbff:fecc:ddee/64 Scope:Link
@@ -75,10 +70,8 @@ describe Ohai::System, "Linux Network Plugin" do
TX packets:1798627472 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:4047036732 (3.7 GiB) TX bytes:3451231474 (3.2 GiB)
-
foo:veth0@eth0 Link encap:Ethernet HWaddr ca:b3:73:8b:0c:e4
BROADCAST MULTICAST MTU:1500 Metric:1
-
tun0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
inet addr:172.16.19.39 P-t-P:172.16.19.1 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1418 Metric:1
@@ -86,21 +79,18 @@ describe Ohai::System, "Linux Network Plugin" do
TX packets:13782 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:7377600 (7.0 MiB) TX bytes:1175481 (1.1 MiB)
-
venet0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1418 Metric:1
RX packets:57200 errors:0 dropped:0 overruns:0 frame:0
TX packets:13782 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:7377600 (7.0 MiB) TX bytes:1175481 (1.1 MiB)
-
venet0:0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1418 Metric:1
RX packets:57200 errors:0 dropped:0 overruns:0 frame:0
TX packets:13782 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:7377600 (7.0 MiB) TX bytes:1175481 (1.1 MiB)
-
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
@@ -109,7 +99,6 @@ describe Ohai::System, "Linux Network Plugin" do
TX packets:524 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:35224 (34.3 KiB) TX bytes:35224 (34.3 KiB)
-
eth3 Link encap:Ethernet HWaddr E8:39:35:C5:C8:54
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:13395101 errors:0 dropped:0 overruns:0 frame:0
@@ -117,7 +106,6 @@ describe Ohai::System, "Linux Network Plugin" do
collisions:0 txqueuelen:1000
RX bytes:1325650573 (1.2 GiB) TX bytes:1666310189 (1.5 GiB)
Interrupt:36 Memory:f4800000-f4ffffff
-
eth13 Link encap:Ethernet HWaddr 00:ba:ba:10:21:21
inet addr:10.21.21.21 Bcast:10.21.21.255 Mask:255.255.255.0
inet6 addr: fe80::2ba:baff:fe10:2121/64 Scope:Link
@@ -127,14 +115,12 @@ describe Ohai::System, "Linux Network Plugin" do
collisions:0 txqueuelen:1000
RX bytes:21 (2.1 GiB) TX bytes:21 (2.1 GiB)
Interrupt:21
-
ovs-system Link encap:Ethernet HWaddr 7A:7A:80:80:6C:24
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
-
xapi1 Link encap:Ethernet HWaddr E8:39:35:C5:C8:50
inet addr:192.168.13.34 Bcast:192.168.13.255 Mask:255.255.255.0
UP BROADCAST RUNNING MTU:1500 Metric:1
@@ -142,7 +128,6 @@ describe Ohai::System, "Linux Network Plugin" do
TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:21515031 (20.5 MiB) TX bytes:2052 (2.0 KiB)
-
fwdintf Link encap:Ethernet HWaddr 00:00:00:00:00:0a
inet6 addr: fe80::200:ff:fe00:a/64 Scope:Link
UP RUNNING NOARP MULTICAST MTU:1496 Metric:1
@@ -386,7 +371,6 @@ describe Ohai::System, "Linux Network Plugin" do
RX Mini: 0
RX Jumbo: 0
TX: 8192
-
EOM
end
@@ -403,7 +387,6 @@ describe Ohai::System, "Linux Network Plugin" do
TX: 0
Other: 0
Combined: 16
-
EOM
end
@@ -415,27 +398,32 @@ describe Ohai::System, "Linux Network Plugin" do
sample-interval: 0
pkt-rate-low: 0
pkt-rate-high: 0
-
rx-usecs: 33
rx-frames: 88
rx-usecs-irq: 0
rx-frames-irq: 0
-
tx-usecs: 8
tx-frames: 128
tx-usecs-irq: 0
tx-frames-irq: 0
-
rx-usecs-low: 0
rx-frame-low: 0
tx-usecs-low: 0
tx-frame-low: 0
-
rx-usecs-high: 0
rx-frame-high: 0
tx-usecs-high: 0
tx-frame-high: 0
+ EOM
+ end
+ let(:linux_ethtool_k) do
+ <<~EOM
+ Features for eth0:
+ rx-checksumming: on
+ tx-checksumming: off
+ rx-vlan-offload: on [fixed]
+ rx-gro-hw: off [fixed]
EOM
end
@@ -451,7 +439,6 @@ describe Ohai::System, "Linux Network Plugin" do
supports-eeprom-access: no
supports-register-dump: no
supports-priv-flags: yes
-
EOM
end
@@ -461,11 +448,11 @@ describe Ohai::System, "Linux Network Plugin" do
Autonegotiate: on
RX: off
TX: on
-
EOM
end
before do
+ allow(File).to receive(:exist?).and_call_original
allow(plugin).to receive(:collect_os).and_return(:linux)
allow(plugin).to receive(:shell_out).with("ip addr").and_return(mock_shell_out(0, linux_ip_addr, ""))
@@ -480,6 +467,7 @@ describe Ohai::System, "Linux Network Plugin" do
allow(plugin).to receive(:shell_out).with("arp -an").and_return(mock_shell_out(0, linux_arp_an, ""))
allow(plugin).to receive(:shell_out).with(/ethtool -g/).and_return(mock_shell_out(0, linux_ethtool_g, ""))
allow(plugin).to receive(:shell_out).with(/ethtool -l/).and_return(mock_shell_out(0, linux_ethtool_l, ""))
+ allow(plugin).to receive(:shell_out).with(/ethtool -k/).and_return(mock_shell_out(0, linux_ethtool_k, ""))
allow(plugin).to receive(:shell_out).with(/ethtool -c/).and_return(mock_shell_out(0, linux_ethtool_c, ""))
allow(plugin).to receive(:shell_out).with(/ethtool -i/).and_return(mock_shell_out(0, linux_ethtool_i, ""))
allow(plugin).to receive(:shell_out).with(/ethtool -a/).and_return(mock_shell_out(0, linux_ethtool_a, ""))
@@ -729,6 +717,13 @@ describe Ohai::System, "Linux Network Plugin" do
end
+ it "detects the driver offload features of an ethernet interface" do
+ expect(plugin["network"]["interfaces"]["eth0"]["offload_params"]["rx-checksumming"]).to eq("on")
+ expect(plugin["network"]["interfaces"]["eth0"]["offload_params"]["tx-checksumming"]).to eq("off")
+ expect(plugin["network"]["interfaces"]["eth0"]["offload_params"]["rx-vlan-offload"]).to eq("on")
+ expect(plugin["network"]["interfaces"]["eth0"]["offload_params"]["rx-gro-hw"]).to eq("off")
+ end
+
it "detects the pause frame configuration of an ethernet interface" do
expect(plugin["network"]["interfaces"]["eth0"]["pause_params"]["autonegotiate"]).to eq(true)
expect(plugin["network"]["interfaces"]["eth0"]["pause_params"]["rx"]).to eq(false)
@@ -1200,6 +1195,46 @@ describe Ohai::System, "Linux Network Plugin" do
end
end
+ describe "when there're multipath routes" do
+ let(:linux_ip_route) do
+ <<~EOM
+ 10.5.4.0/24 proto static \\ nexthop via 10.5.4.1 dev eth0 weight 1\\ nexthop via 10.5.4.2 dev eth0 weight 1
+ EOM
+ end
+
+ let(:linux_ip_route_inet6) do
+ <<~EOM
+ default proto ra metric 1024 expires 1797sec \\ nexthop via fe80::c018:50ff:fe41:ca33 dev eth0.11 weight 1 \\ nexthop via fe80::c018:50ff:fe41:ca33 dev eth0 weight 1 pref medium
+ default proto ra metric 1050 expires 1796sec \\ nexthop via fe80::c018:50ff:fe3f:9184 dev eth3 weight 1 \\ nexthop via fe80::c018:50ff:fe3f:9184 dev eth13 weight 1 pref medium
+ EOM
+ end
+
+ before do
+ plugin.run
+ end
+
+ it "completes the run" do
+ expect(plugin.logger).not_to receive(:trace).with(/Plugin linux::network threw exception/)
+ expect(plugin["network"]).not_to be_nil
+ end
+
+ it "sets default ipv6 interface and gateway" do
+ expect(plugin["network"]["default_inet6_interface"]).to eq("eth0")
+ expect(plugin["network"]["default_inet6_gateway"]).to eq("fe80::c018:50ff:fe41:ca33")
+ end
+
+ it "sets the routes properly" do
+ expect(plugin["network"]["interfaces"]["eth0"]["routes"]).to eq([
+ Mash.new( destination: "10.5.4.0/24", family: "inet", proto: "static", via: "10.5.4.1" ),
+ Mash.new( destination: "10.5.4.0/24", family: "inet", proto: "static", via: "10.5.4.2" ),
+ Mash.new( destination: "default", family: "inet6", proto: "ra", via: "fe80::c018:50ff:fe41:ca33", metric: "1024" ),
+ ])
+ expect(plugin["network"]["interfaces"]["eth0.11"]["routes"]).to eq([Mash.new( destination: "default", family: "inet6", proto: "ra", via: "fe80::c018:50ff:fe41:ca33", metric: "1024" )])
+ expect(plugin["network"]["interfaces"]["eth13"]["routes"]).to eq([Mash.new( destination: "default", family: "inet6", proto: "ra", via: "fe80::c018:50ff:fe3f:9184", metric: "1050" )])
+ expect(plugin["network"]["interfaces"]["eth3"]["routes"]).to eq([Mash.new( destination: "default", family: "inet6", proto: "ra", via: "fe80::c018:50ff:fe3f:9184", metric: "1050" )])
+ end
+ end
+
describe "when there's a source field in a local route entry but it isnt in the default route" do
let(:linux_ip_route) do
<<~EOM
@@ -1276,6 +1311,73 @@ describe Ohai::System, "Linux Network Plugin" do
end
end
+ # notes:
+ # route 172.16.19.39 is the addr of tun0 ; see :linux_ifconfig at top of file
+ # route 10.116.201.0/24 is discarded because it is not a default route
+ # route 192.168.0.0/24 is discarded because src 192.168.0.2 does not match eth0 ("Skipping route entry whose src does not match the interface IP")
+ # route 172.16.19.39 is chosen over 10.116.201.254 because its metric is lower (10 < 20)
+ describe "when there's a source field in a local route entry but no dev in the route" do
+ let(:linux_ip_route) do
+ <<~EOM
+ default proto bird src 172.16.19.39 metric 10 \\ nexthop via 10.1.81.1 dev eth0 weight 20
+ default via 10.116.201.254 dev eth0 metric 20 src 10.116.201.74
+ 10.116.201.0/24 dev eth0 proto kernel src 10.116.201.76
+ 192.168.0.0/24 dev eth0 proto kernel src 192.168.0.2
+ EOM
+ end
+ let(:linux_ip_route_inet6) { "" }
+
+ it "maps the no-dev route and sets ipaddress" do
+ plugin.run
+ expect(plugin["ipaddress"]).to eq("172.16.19.39")
+ end
+ end
+
+ # notes:
+ # route 172.16.19.39 is the addr of tun0 ; see :linux_ifconfig at top of file
+ # route 10.116.201.0/24 is discarded because it is not a default route
+ # route 192.168.0.0/24 is discarded because src 192.168.0.2 does not match eth0 ("Skipping route entry whose src does not match the interface IP")
+ # route 10.116.201.254 is chosen over 172.16.19.39 and 10.116.201.1 because its metric is lower (5 < 10, 10)
+ describe "when there's a source field in a local route entry but no dev with a higher priority default route" do
+ let(:linux_ip_route) do
+ <<~EOM
+ default via 10.116.201.254 dev eth0 metric 5 src 10.116.201.74
+ default proto bird src 172.16.19.39 metric 10 \\ nexthop via 10.1.81.1 dev eth0 weight 20
+ default via 10.116.201.1 dev eth0 metric 10 src 10.116.201.1
+ 10.116.201.0/24 dev eth0 proto kernel src 10.116.201.76
+ 192.168.0.0/24 dev eth0 proto kernel src 192.168.0.2
+ EOM
+ end
+ let(:linux_ip_route_inet6) { "" }
+
+ it "maps the dev route and sets ipaddress" do
+ plugin.run
+ expect(plugin["ipaddress"]).to eq("10.116.201.74")
+ end
+ end
+
+ # notes:
+ # route 172.16.19.39 is the addr of tun0 ; see :linux_ifconfig at top of file
+ # route 10.116.201.0/24 is discarded because it is not a default route
+ # route 192.168.0.0/24 is discarded because src 192.168.0.2 does not match eth0 ("Skipping route entry whose src does not match the interface IP")
+ # route 10.116.201.254 is chosen over 172.16.19.39 because routes with an explict device are preferred over ones that are inferred when metrics are equal
+ describe "when there's a source field in a local route entry but no dev, but a dev route with the same metric" do
+ let(:linux_ip_route) do
+ <<~EOM
+ default proto bird src 172.16.19.39 metric 10 \\ nexthop via 10.1.81.1 dev eth0 weight 20
+ default via 10.116.201.254 dev eth0 metric 10 src 10.116.201.74
+ 10.116.201.0/24 dev eth0 proto kernel src 10.116.201.76
+ 192.168.0.0/24 dev eth0 proto kernel src 192.168.0.2
+ EOM
+ end
+ let(:linux_ip_route_inet6) { "" }
+
+ it "maps the dev route and sets ipaddress" do
+ plugin.run
+ expect(plugin["ipaddress"]).to eq("10.116.201.74")
+ end
+ end
+
describe "with a link level default route" do
let(:linux_ip_route) do
<<~EOM
@@ -1574,6 +1676,108 @@ describe Ohai::System, "Linux Network Plugin" do
)
end
end
+
+ describe "gathering xdp counters via ip_link_s_d" do
+ let(:linux_ip_link_s_d) do
+ <<~EOM
+ 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN mode DEFAULT group default
+ link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 promiscuity 0
+ RX: bytes packets errors dropped overrun mcast
+ 35224 524 0 0 0 0
+ TX: bytes packets errors dropped carrier collsns
+ 35224 524 0 0 0 0
+ 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
+ link/ether 12:31:3d:02:be:a2 brd ff:ff:ff:ff:ff:ff promiscuity 0
+ RX: bytes packets errors dropped overrun mcast
+ 1392844460 2659966 0 0 0 0
+ TX: bytes packets errors dropped carrier collsns
+ 691785313 1919690 0 0 0 0
+ 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 xdp qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
+ link/ether 12:31:3d:02:be:a2 brd ff:ff:ff:ff:ff:ff promiscuity 0
+ prog/xdp id 9500 tag 1234567acde1892 jited
+ RX: bytes packets errors dropped overrun mcast
+ 1392844460 2659966 0 0 0 0
+ TX: bytes packets errors dropped carrier collsns
+ 691785313 1919690 0 0 0 0
+ 4: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 xdpgeneric qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
+ link/ether 12:31:3d:02:be:a2 brd ff:ff:ff:ff:ff:ff promiscuity 0
+ prog/xdp id 8400 tag 5234567acde1892 jited
+ RX: bytes packets errors dropped overrun mcast
+ 1392844460 2659966 0 0 0 0
+ TX: bytes packets errors dropped carrier collsns
+ 691785313 1919690 0 0 0 0
+ 5: eth3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 xdpoffload qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
+ link/ether 12:31:3d:02:be:a2 brd ff:ff:ff:ff:ff:ff promiscuity 0
+ prog/xdp id 7400 tag 8234567acde1892
+ RX: bytes packets errors dropped overrun mcast
+ 1392844460 2659966 0 0 0 0
+ TX: bytes packets errors dropped carrier collsns
+ 691785313 1919690 0 0 0 0
+ 6: eth4: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 xdpmulti qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
+ link/ether 12:31:3d:02:be:a2 brd ff:ff:ff:ff:ff:ff promiscuity 0
+ prog/xdpdrv id 7400 tag 8234567acde1892 jited
+ prog/xdpoffload id 5400 tag 5234567acde1892
+ RX: bytes packets errors dropped overrun mcast
+ 1392844460 2659966 0 0 0 0
+ TX: bytes packets errors dropped carrier collsns
+ 691785313 1919690 0 0 0 0
+ EOM
+ end
+ it "adds the xdp information of an interface" do
+ plugin.run
+ expect(plugin["network"]["interfaces"]["lo"]["xdp"]).to be_nil
+ expect(plugin["network"]["interfaces"]["eth0"]["xdp"]).to be_nil
+ expect(plugin["network"]["interfaces"]["eth1"]["xdp"]).to eq(
+ {
+ "attached" => [
+ {
+ mode: "xdpdrv",
+ id: "9500",
+ tag: "1234567acde1892",
+ },
+ ],
+ }
+ )
+ expect(plugin["network"]["interfaces"]["eth2"]["xdp"]).to eq(
+ {
+ "attached" => [
+ {
+ mode: "xdpgeneric",
+ id: "8400",
+ tag: "5234567acde1892",
+ },
+ ],
+ }
+ )
+ expect(plugin["network"]["interfaces"]["eth3"]["xdp"]).to eq(
+ {
+ "attached" => [
+ {
+ mode: "xdpoffload",
+ id: "7400",
+ tag: "8234567acde1892",
+ },
+ ],
+ }
+ )
+ expect(plugin["network"]["interfaces"]["eth4"]["xdp"]).to eq(
+ {
+ "attached" => [
+ {
+ mode: "xdpdrv",
+ id: "7400",
+ tag: "8234567acde1892",
+ },
+ {
+ mode: "xdpoffload",
+ id: "5400",
+ tag: "5234567acde1892",
+ },
+ ],
+ }
+ )
+ end
+ end
end
end
-end
+end \ No newline at end of file