diff options
| -rwxr-xr-x | ethtool-cmd.py | 136 | ||||
| -rw-r--r-- | rpm/SPECS/python-ethtool.spec | 3 |
2 files changed, 139 insertions, 0 deletions
diff --git a/ethtool-cmd.py b/ethtool-cmd.py new file mode 100755 index 0000000..421e066 --- /dev/null +++ b/ethtool-cmd.py @@ -0,0 +1,136 @@ +#! /usr/bin/python +# -*- python -*- +# -*- coding: utf-8 -*- +# Copyright (C) 2008 Red Hat Inc. +# +# This application is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; version 2. +# +# This application is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. + +import getopt, ethtool, sys + +def usage(): + print '''Usage: ethtool [OPTIONS] [<interface>] + -h|--help Give this help list + -i|--driver Show driver information + -k|--show-offload Get protocol offload information + -K|--offload Set protocol offload + [ tso on|off ]''' + +tab = "" + +def printtab(msg): + print tab + msg + +def show_offload(interface, args = None): + try: + sg = ethtool.get_sg(interface) and "on" or "off" + except IOError: + sg = "not supported" + + try: + tso = ethtool.get_tso(interface) and "on" or "off" + except IOError: + tso = "not supported" + + try: + ufo = ethtool.get_ufo(interface) and "on" or "off" + except IOError: + ufo = "not supported" + + try: + gso = ethtool.get_gso(interface) and "on" or "off" + except IOError: + gso = "not supported" + + printtab("scatter-gather: %s" % sg) + printtab("tcp segmentation offload: %s" % tso) + printtab("udp fragmentation offload: %s" % ufo) + printtab("generic segmentation offload: %s" % gso) + +def set_offload(interface, args): + cmd, value = [a.lower() for a in args] + + if cmd == "tso": + value = value == "on" and 1 or 0 + try: + ethtool.set_tso(interface, value) + except: + pass + +def show_driver(interface, args = None): + try: + driver = ethtool.get_module(interface) + except IOError: + driver = "not implemented" + + try: + bus = ethtool.get_businfo(interface) + except IOError: + bus = "not available" + + printtab("driver: %s" % driver) + printtab("bus-info: %s" % bus) + +def run_cmd(cmd, interface, args): + global tab + if not interface: + tab = " " + for interface in ethtool.get_devices(): + print "%s:" % interface + cmd(interface, args) + else: + cmd(interface, args) + +def run_cmd_noargs(cmd, args): + if args: + run_cmd(cmd, args[0], None) + else: + run_cmd(cmd, None, None) + +def main(): + try: + opts, args = getopt.getopt(sys.argv[1:], + "hikK", + ("help", + "driver", + "show-offload", + "offload")) + except getopt.GetoptError, err: + usage() + print str(err) + sys.exit(2) + + if not opts: + usage() + sys.exit(0) + + for o, a in opts: + if o in ("-h", "--help"): + usage() + return + elif o in ("-i", "--driver"): + run_cmd_noargs(show_driver, args) + break + elif o in ("-k", "--show-offload"): + run_cmd_noargs(show_offload, args) + break + elif o in ("-K", "--offload"): + if len(args) == 2: + interface = None + elif len(args) == 3: + interface = args[0] + args = args[1:] + else: + usage() + sys.exit(1) + run_cmd(set_offload, interface, args) + break + +if __name__ == '__main__': + main() diff --git a/rpm/SPECS/python-ethtool.spec b/rpm/SPECS/python-ethtool.spec index 06a744f..84340a2 100644 --- a/rpm/SPECS/python-ethtool.spec +++ b/rpm/SPECS/python-ethtool.spec @@ -19,6 +19,8 @@ ethtool python bindings %install rm -rf %{buildroot} make DESTDIR=%{buildroot} install +mkdir -p %{buildroot}%{_sbindir} +cp -f ethtool-cmd.py %{buildroot}%{_sbindir}/pethtool %clean rm -rf %{buildroot} @@ -26,6 +28,7 @@ rm -rf %{buildroot} %files %defattr(-,root,root) %doc COPYING +%{_sbindir}/pethtool %{python_sitearch}/ethtool.so %changelog |
