summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2021-04-02 09:39:31 -0700
committerGitHub <noreply@github.com>2021-04-02 09:39:31 -0700
commit4097e2b1da652e6060d2b61fc8f0b0b3b88492c4 (patch)
treea4e22cc3860cff366ff949c69c3efb9938576b04
parent74bde1d4b0fafb6192d1e1b135c13a37a80b2fb6 (diff)
parent2fc35fbcbcfe7e2f3dad8f425d8307a6f216d011 (diff)
downloadohai-4097e2b1da652e6060d2b61fc8f0b0b3b88492c4.tar.gz
Merge pull request #1637 from zalokhan/eth-offloads
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/ohai/plugins/linux/network.rb25
-rw-r--r--spec/unit/plugins/linux/network_spec.rb19
2 files changed, 44 insertions, 0 deletions
diff --git a/lib/ohai/plugins/linux/network.rb b/lib/ohai/plugins/linux/network.rb
index 8f1274a3..713b9c16 100644
--- a/lib/ohai/plugins/linux/network.rb
+++ b/lib/ohai/plugins/linux/network.rb
@@ -273,6 +273,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
@@ -793,6 +817,7 @@ 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
diff --git a/spec/unit/plugins/linux/network_spec.rb b/spec/unit/plugins/linux/network_spec.rb
index 54c8d3fb..16c6f235 100644
--- a/spec/unit/plugins/linux/network_spec.rb
+++ b/spec/unit/plugins/linux/network_spec.rb
@@ -439,6 +439,17 @@ describe Ohai::System, "Linux Network Plugin" do
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
+
let(:linux_ethtool_i) do
<<~EOM
driver: mlx5_core
@@ -480,6 +491,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 +741,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)