diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f4d510d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +SOURCES/v0.8.tar.gz diff --git a/.python-ethtool.metadata b/.python-ethtool.metadata new file mode 100644 index 0000000..6b0b7b4 --- /dev/null +++ b/.python-ethtool.metadata @@ -0,0 +1 @@ +c2edd0be17dc23c3b7d25a4cc498ba36f5d51e18 SOURCES/v0.8.tar.gz diff --git a/README.md b/README.md deleted file mode 100644 index 0e7897f..0000000 --- a/README.md +++ /dev/null @@ -1,5 +0,0 @@ -The master branch has no content - -Look at the c7 branch if you are working with CentOS-7, or the c4/c5/c6 branch for CentOS-4, 5 or 6 - -If you find this file in a distro specific branch, it means that no content has been checked in yet diff --git a/SOURCES/fix-long-interface-names.patch b/SOURCES/fix-long-interface-names.patch new file mode 100644 index 0000000..22d4c3d --- /dev/null +++ b/SOURCES/fix-long-interface-names.patch @@ -0,0 +1,13 @@ +diff --git a/pifconfig.py b/pifconfig.py +index 5557407..dbf9b2b 100755 +--- a/pifconfig.py ++++ b/pifconfig.py +@@ -61,7 +61,7 @@ def bits2netmask(bits): + def show_config(device): + info = ethtool.get_interfaces_info(device)[0] + flags = ethtool.get_flags(device) +- print '%-9.9s' % device, ++ print '%s' % device, + if not (flags & ethtool.IFF_LOOPBACK): + print "HWaddr %s" % ethtool.get_hwaddr(device) + else: diff --git a/SOURCES/python-ethtool-0.6-make-pifconfig-output-all-ipv4-addresses-for-interface.patch b/SOURCES/python-ethtool-0.6-make-pifconfig-output-all-ipv4-addresses-for-interface.patch new file mode 100644 index 0000000..286bac4 --- /dev/null +++ b/SOURCES/python-ethtool-0.6-make-pifconfig-output-all-ipv4-addresses-for-interface.patch @@ -0,0 +1,43 @@ +--- python-ethtool-0.6/pifconfig.py.orig 2013-08-07 17:11:51.483883885 +0200 ++++ python-ethtool-0.6/pifconfig.py 2013-08-07 17:20:31.004075388 +0200 +@@ -14,7 +14,7 @@ + # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + # General Public License for more details. + +-import getopt, ethtool, sys ++import getopt, ethtool, socket, struct, sys + from optparse import OptionParser + + def flags2str(flags): +@@ -54,18 +54,23 @@ + + return string.strip() + ++def bits2netmask(bits): ++ mask = (1<<32) - (1<<32>>bits) ++ return socket.inet_ntoa(struct.pack(">L", mask)) ++ + def show_config(device): +- ipaddr = ethtool.get_ipaddr(device) +- netmask = ethtool.get_netmask(device) ++ info = ethtool.get_interfaces_info(device)[0] + flags = ethtool.get_flags(device) + print '%-9.9s' % device, + if not (flags & ethtool.IFF_LOOPBACK): +- print "HWaddr %s" % ethtool.get_hwaddr(device), +- print ''' +- inet addr:%s''' % ipaddr, +- if not (flags & (ethtool.IFF_LOOPBACK | ethtool.IFF_POINTOPOINT)): +- print "Bcast:%s" % ethtool.get_broadcast(device), +- print ' Mask:%s' % netmask ++ print "HWaddr %s" % ethtool.get_hwaddr(device) ++ else: ++ print ++ for addr in info.get_ipv4_addresses(): ++ print ' inet addr:%s' % addr.address, ++ if not (flags & (ethtool.IFF_LOOPBACK | ethtool.IFF_POINTOPOINT)): ++ print "Bcast:%s" % ethtool.get_broadcast(device), ++ print ' Mask:%s' % bits2netmask(addr.netmask) + for info in ethtool.get_interfaces_info(device): + for addr in info.get_ipv6_addresses(): + print (" inet6 addr: %s/%s Scope: %s" diff --git a/SOURCES/python-ethtool-0.6-return-ipv6-only-interface-names.patch b/SOURCES/python-ethtool-0.6-return-ipv6-only-interface-names.patch new file mode 100644 index 0000000..601ee58 --- /dev/null +++ b/SOURCES/python-ethtool-0.6-return-ipv6-only-interface-names.patch @@ -0,0 +1,76 @@ +--- a/python-ethtool/ethtool.c.orig 2013-08-07 10:37:37.378764077 +0200 ++++ b/python-ethtool/ethtool.c 2013-08-07 10:39:27.111760146 +0200 +@@ -26,6 +26,7 @@ + #include + #include + #include ++#include + + #include "etherinfo_struct.h" + #include "etherinfo_obj.h" +@@ -54,55 +55,24 @@ + static PyObject *get_active_devices(PyObject *self __unused, PyObject *args __unused) + { + PyObject *list; +- int numreqs = 30; +- struct ifconf ifc; +- struct ifreq *ifr; +- int n; ++ struct ifaddrs *ifaddr, *ifa; + +- /* SIOCGIFCONF currently seems to only work properly on AF_INET sockets +- (as of 2.1.128) */ +- /* Open control socket. */ +- int skfd = socket(AF_INET, SOCK_DGRAM, 0); +- +- if (skfd < 0) { ++ if (getifaddrs(&ifaddr) == -1) { + PyErr_SetString(PyExc_OSError, strerror(errno)); + return NULL; + } + +- ifc.ifc_buf = NULL; +- for (;;) { +- ifc.ifc_len = sizeof(struct ifreq) * numreqs; +- ifc.ifc_buf = realloc(ifc.ifc_buf, ifc.ifc_len); +- +- if (ioctl(skfd, SIOCGIFCONF, &ifc) < 0) { +- PyErr_SetString(PyExc_OSError, strerror(errno)); +- free(ifc.ifc_buf); +- close(skfd); +- return NULL; +- } +- +- if (ifc.ifc_len == (int)sizeof(struct ifreq) * numreqs) { +- /* assume it overflowed and try again */ +- numreqs += 10; +- continue; +- } +- break; +- } +- + list = PyList_New(0); +- ifr = ifc.ifc_req; +- for (n = 0; n < ifc.ifc_len; n += sizeof(struct ifreq)) { +- if (!(ioctl(skfd, SIOCGIFFLAGS, ifr) < 0)) +- if (ifr->ifr_flags & IFF_UP) { +- PyObject *str = PyString_FromString(ifr->ifr_name); +- PyList_Append(list, str); +- Py_DECREF(str); +- } +- ifr++; ++ for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) { ++ PyObject *str = PyString_FromString(ifa->ifa_name); ++ /* names are not unique (listed for both ipv4 and ipv6) */ ++ if (!PySequence_Contains(list, str) && (ifa->ifa_flags & (IFF_UP))) { ++ PyList_Append(list, str); ++ } ++ Py_DECREF(str); + } + +- free(ifc.ifc_buf); +- close(skfd); ++ freeifaddrs(ifaddr); + + return list; + } diff --git a/SOURCES/python-ethtool-0.8-check-libnl-return-codes.patch b/SOURCES/python-ethtool-0.8-check-libnl-return-codes.patch new file mode 100644 index 0000000..eacbdfc --- /dev/null +++ b/SOURCES/python-ethtool-0.8-check-libnl-return-codes.patch @@ -0,0 +1,48 @@ +--- a/python-ethtool/etherinfo.c.orig 2014-01-13 13:38:58.716919961 +0100 ++++ b/python-ethtool/etherinfo.c 2014-01-13 13:52:15.838033480 +0100 +@@ -327,6 +327,9 @@ + */ + if( ethinf->index < 0 ) { + link_cache = rtnl_link_alloc_cache(*data->nlc); ++ if( link_cache == NULL ) { ++ return 0; ++ } + ethinf->index = rtnl_link_name2i(link_cache, ethinf->device); + if( ethinf->index < 0 ) { + return 0; +@@ -339,6 +342,9 @@ + case NLQRY_LINK: + /* Extract MAC/hardware address of the interface */ + link_cache = rtnl_link_alloc_cache(*data->nlc); ++ if( link_cache == NULL ) { ++ return 0; ++ } + link = rtnl_link_alloc(); + rtnl_link_set_ifindex(link, ethinf->index); + nl_cache_foreach_filter(link_cache, (struct nl_object *)link, callback_nl_link, ethinf); +@@ -350,7 +356,14 @@ + case NLQRY_ADDR: + /* Extract IP address information */ + addr_cache = rtnl_addr_alloc_cache(*data->nlc); ++ if( addr_cache == NULL ) { ++ return 0; ++ } + addr = rtnl_addr_alloc(); ++ if( addr == NULL ) { ++ nl_cache_free(addr_cache); ++ return 0; ++ } + rtnl_addr_set_ifindex(addr, ethinf->index); + + /* Make sure we don't have any old IPv6 addresses saved */ +@@ -409,7 +422,9 @@ + + /* No earlier connections exists, establish a new one */ + *data->nlc = nl_handle_alloc(); +- nl_connect(*data->nlc, NETLINK_ROUTE); ++ if( nl_connect(*data->nlc, NETLINK_ROUTE) != 0 ) { ++ return 0; ++ } + if( (*data->nlc != NULL) ) { + /* Force O_CLOEXEC flag on the NETLINK socket */ + if( fcntl(nl_socket_get_fd(*data->nlc), F_SETFD, FD_CLOEXEC) == -1 ) { diff --git a/SPECS/python-ethtool.spec b/SPECS/python-ethtool.spec new file mode 100644 index 0000000..eeb5230 --- /dev/null +++ b/SPECS/python-ethtool.spec @@ -0,0 +1,154 @@ +%{!?python_sitearch: %define python_sitearch %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib(1)")} +%{!?python_ver: %define python_ver %(%{__python} -c "import sys ; print sys.version[:3]")} + +Summary: Ethernet settings python bindings +Name: python-ethtool +Version: 0.8 +Release: 7%{?dist} +URL: https://github.com/fedora-python/%{name} +Source: https://github.com/fedora-python/%{name}/archive/v%{version}.tar.gz +Patch0: python-ethtool-0.6-make-pifconfig-output-all-ipv4-addresses-for-interface.patch +Patch1: python-ethtool-0.6-return-ipv6-only-interface-names.patch +# Properly check libnl return codes and don't fall with segfault +Patch2: python-ethtool-0.8-check-libnl-return-codes.patch +# Fix display of long network interface names +# Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1330432 +# Fixed upstream: https://github.com/fedora-python/python-ethtool/pull/31/files +Patch3: fix-long-interface-names.patch + +License: GPLv2 +Group: System Environment/Libraries +BuildRequires: python-devel libnl-devel asciidoc +%if 0%{?rhel} && 0%{?rhel} < 5 +BuildRequires: pkgconfig gcc +%endif +BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) + +%description +Python bindings for the ethtool kernel interface, that allows querying and +changing of Ethernet card settings, such as speed, port, auto-negotiation, and +PCI locations. + +%prep +%setup -q +%patch0 -p1 +%patch1 -p1 +%patch2 -p1 +%patch3 -p1 + +%build +%{__python} setup.py build +a2x -d manpage -f manpage man/pethtool.8.asciidoc +a2x -d manpage -f manpage man/pifconfig.8.asciidoc + +%install +rm -rf %{buildroot} +%{__python} setup.py install --skip-build --root %{buildroot} +mkdir -p %{buildroot}%{_sbindir} %{buildroot}%{_mandir}/man8 +cp -p pethtool.py %{buildroot}%{_sbindir}/pethtool +cp -p pifconfig.py %{buildroot}%{_sbindir}/pifconfig +%{__gzip} -c man/pethtool.8 > %{buildroot}%{_mandir}/man8/pethtool.8.gz +%{__gzip} -c man/pifconfig.8 > %{buildroot}%{_mandir}/man8/pifconfig.8.gz + +%clean +rm -rf %{buildroot} + +%files +%defattr(-,root,root) +%doc COPYING +%{_sbindir}/pethtool +%{_sbindir}/pifconfig +%doc %{_mandir}/man8/* +%{python_sitearch}/ethtool.so +%if "%{python_ver}" >= "2.5" +%{python_sitearch}/*.egg-info +%endif + +%changelog +* Tue Apr 17 2018 Charalampos Stratakis - 0.8-7 +- Fix the URL's to point to the proper upstream repositories +Resolves: rhbz#1502393 + +* Mon Apr 16 2018 Charalampos Stratakis - 0.8-6 +- Fix diplay of long network interface names +Resolves: rhbz#1330432 + +* Fri Jan 24 2014 Daniel Mach - 0.8-5 +- Mass rebuild 2014-01-24 + +* Mon Jan 13 2014 Bohuslav Kabrda - 0.8-4 +- Properly check libnl return codes, don't segfault. +Resolves: rhbz#1051392 + +* Fri Dec 27 2013 Daniel Mach - 0.8-3 +- Mass rebuild 2013-12-27 + +* Thu Nov 07 2013 Bohuslav Kabrda - 0.8-2 +- Fixed reporting of more IPv4 addresses per interface +Resolves: rhbz#1027685 +- Make get_active_devices() return IPv6-only devices, too +Resolves: rhbz#1027678 + +* Tue Feb 19 2013 David Malcolm - 0.8-1 +- 0.8 + +* Thu Feb 14 2013 Fedora Release Engineering - 0.7-5 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_19_Mass_Rebuild + +* Sat Jul 21 2012 Fedora Release Engineering - 0.7-4 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_18_Mass_Rebuild + +* Sat Jan 14 2012 Fedora Release Engineering - 0.7-3 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_17_Mass_Rebuild + +* Wed Apr 13 2011 David Sommerseth - 0.7-2 +- Fixed missing man page packaging + +* Mon Apr 11 2011 David Sommerseth - 0.7-1 +- Fixed several memory leaks (commit aa2c20e697af, abc7f912f66d) +- Improved error checking towards NULL values(commit 4e928d62a8e3) +- Fixed typo in pethtool --help (commit 710766dc722) +- Only open a NETLINK connection when needed (commit 508ffffbb3c) +- Added man page for pifconfig and pethtool (commit 9f0d17aa532, rhbz#638475) +- Force NETLINK socket to close on fork() using FD_CLOEXEC (commit 1680cbeb40e) + +* Tue Feb 08 2011 Fedora Release Engineering - 0.6-2 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_15_Mass_Rebuild + +* Wed Jan 19 2011 David Sommerseth - 0.6-1 +- Don't segfault if we don't receive any address from rtnl_link_get_addr() +- Remove errornous file from MANIFEST +- Added ethtool.version string constant +- Avoid duplicating IPv6 address information +- import sys module in setup.py (Miroslav Suchy) + +* Mon Aug 9 2010 David Sommerseth - 0.5-1 +- Fixed double free issue (commit c52ed2cbdc5b851ebc7b) + +* Wed Apr 28 2010 David Sommerseth - 0.4-1 +- David Sommerseth is now taking over the maintenance of python-ethtool +- New URLs for upstream source code +- Added new API: ethtool.get_interfaces_info() - returns list of etherinfo objects +- Added support retrieving for IPv6 address, using etherinfo::get_ipv6_addresses() + +* Fri Sep 5 2008 Arnaldo Carvalho de Melo - 0.3-2 +- Rewrote build and install sections as part of the fedora review process + BZ #459549 + +* Tue Aug 26 2008 Arnaldo Carvalho de Melo - 0.3-1 +- Add get_flags method from the first python-ethtool contributor, yay +- Add pifconfig command, that mimics the ifconfig tool using the + bindings available + +* Wed Aug 20 2008 Arnaldo Carvalho de Melo - 0.2-1 +- Expand description and summary fields, as part of the fedora + review process. + +* Tue Jun 10 2008 Arnaldo Carvalho de Melo - 0.1-3 +- add dist to the release tag + +* Tue Dec 18 2007 Arnaldo Carvalho de Melo - 0.1-2 +- First build into MRG repo + +* Tue Dec 18 2007 Arnaldo Carvalho de Melo - 0.1-1 +- Get ethtool code from rhpl 0.212