diff options
author | Daniil Baturin <daniil@baturin.org> | 2014-10-30 05:08:53 +0600 |
---|---|---|
committer | Daniil Baturin <daniil@baturin.org> | 2014-10-30 05:08:53 +0600 |
commit | 7a5a8500091589f0ede3d5a1dbc8b6b4b3fabf1d (patch) | |
tree | fddf140c7fd91bdbd581738d592292315f155d75 /scripts | |
parent | 5f32c6830b1b3eda523ae451435ff26e04c1612f (diff) | |
parent | 2f97a9155cda583132408bbd29637010386177ed (diff) | |
download | vyatta-cfg-system-7a5a8500091589f0ede3d5a1dbc8b6b4b3fabf1d.tar.gz vyatta-cfg-system-7a5a8500091589f0ede3d5a1dbc8b6b4b3fabf1d.zip |
Merge pull request #28 from jhendryUK/ethernet_tso_options
Bug #365: Ethernet tso options
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/vyatta-interfaces.pl | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/scripts/vyatta-interfaces.pl b/scripts/vyatta-interfaces.pl index c455bb74..621596a0 100755 --- a/scripts/vyatta-interfaces.pl +++ b/scripts/vyatta-interfaces.pl @@ -50,7 +50,7 @@ my ($dev, $mac, $mac_update); my %skip_interface; my ($check_name, $show_names, $vif_name, $warn_name); my ($check_up, $dhcp_command, $allowed_speed); -my (@speed_duplex, @addr_commit, @check_speed); +my (@speed_duplex, @addr_commit, @check_speed, @offload_option); sub usage { print <<EOF; @@ -62,6 +62,7 @@ Usage: $0 --dev=<interface> --check=<type> $0 --dev=<interface> --check-speed=speed,duplex $0 --dev=<interface> --allowed-speed $0 --dev=<interface> --isup + $0 --dev=<interface> --offload-settings={tcp,udp,segmentation,receive} {value} $0 --show=<type> EOF exit 1; @@ -81,6 +82,7 @@ GetOptions("valid-addr-commit=s{,}" => \@addr_commit, "speed-duplex=s{2}" => \@speed_duplex, "check-speed=s{2}" => \@check_speed, "allowed-speed" => \$allowed_speed, + "offload-settings=s{2}" => \@offload_option, ) or usage(); is_valid_addr_commit($dev, @addr_commit) if (@addr_commit); @@ -94,6 +96,7 @@ is_up($dev) if ($check_up); set_speed_duplex($dev, @speed_duplex) if (@speed_duplex); check_speed_duplex($dev, @check_speed) if (@check_speed); allowed_speed($dev) if ($allowed_speed); +set_offload_setting($dev, @offload_option) if (@offload_option); exit 0; sub is_ip_configured { @@ -571,3 +574,42 @@ sub allowed_speed { close $ethtool; print 'auto ', join(' ', sort keys %speeds), "\n"; } + +sub get_offload_setting { + my ($dev, $option) = @_; + my ($val); + + open( my $ethtool, '-|', "$ETHTOOL -k $dev 2>&1" ) or die "ethtool failed: $!\n"; + while (<$ethtool>) { + next if ($_ !~ m/$option:/); + chomp; + $val = (split(/: /, $_))[1]; + } + close $ethtool; + return ($val); + +} + +sub set_offload_setting { + my ($intf, $option, $nvalue) = @_; + die "Missing --dev argument\n" unless $intf; + + my $ovalue = get_offload_setting($intf, $option); + + my %ethtool_opts = ( 'generic-receive-offload' => 'gro', + 'generic-segmentation-offload' => 'gso', + 'tcp-segmentation-offload' => 'tso', + 'udp-fragmentation-offload' => 'ufo', + ); + + if (defined($nvalue) && $nvalue ne $ovalue) { + my $cmd = "$ETHTOOL -K $intf $ethtool_opts{$option} $nvalue"; + + system($cmd); + if ($? >> 8) { + die "exec of $ETHTOOL failed: '$cmd'"; + } + } + +} + |