159 lines
4.1 KiB
Diff
159 lines
4.1 KiB
Diff
From aa004563d3951086283f896342ec4b3b96fb8785 Mon Sep 17 00:00:00 2001
|
|
From: Jan Stancek <jstancek@redhat.com>
|
|
Date: Wed, 24 Aug 2011 11:54:30 +0200
|
|
Subject: [PATCH] networkio: check ifc type and carrier in /sys
|
|
|
|
With biosdevname changes it's no longer valid to check
|
|
interface type just by name of interface.
|
|
|
|
This patch will get interface hardware type and carrier from
|
|
/sys/class/net. As in previous implementation, only ethernet
|
|
and token ring can be used, and carrier must be present.
|
|
|
|
Difference is, that now all devices, that match this criteria,
|
|
will get tested, e.g. bridge or tap devices too.
|
|
|
|
Patch aims to resolve these bugs:
|
|
Bug 689823 - [AMTU] "Failed to get list of network interfaces to test."
|
|
https://bugzilla.redhat.com/show_bug.cgi?id=689823
|
|
|
|
Bug 723049 - [RHEL6.0] AMTU Running network tests on interfaces that
|
|
have no link
|
|
https://bugzilla.redhat.com/show_bug.cgi?id=723049
|
|
|
|
Before:
|
|
[root@dell-pem710 amtu-1.0.8]# ./src/amtu -dn
|
|
Executing Network I/O Tests...
|
|
Failed to get list of network interfaces to test.
|
|
|
|
After:
|
|
[root@dell-pem710 amtu-1.0.8]# ./src/amtu -dn
|
|
Executing Network I/O Tests...
|
|
if: lo, type: 772, carrier: 1
|
|
if: em1, type: 1, carrier: 1
|
|
if: em2, type: 1, carrier: 1
|
|
if: em3, type: 1, carrier: -1
|
|
if: em4, type: 1, carrier: -1
|
|
if: lo, type: 772, carrier: 1
|
|
if: em1, type: 1, carrier: 1
|
|
if: lo, type: 772, carrier: 1
|
|
if: em1, type: 1, carrier: 1
|
|
if: em1, type: 1, carrier: 1
|
|
if: em2, type: 1, carrier: 1
|
|
if: em2, type: 1, carrier: 1
|
|
|
|
Interface list to test:
|
|
em1
|
|
em2
|
|
|
|
Signed-off-by: Jan Stancek <jstancek@redhat.com>
|
|
---
|
|
src/networkio.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++---
|
|
1 files changed, 73 insertions(+), 5 deletions(-)
|
|
|
|
diff --git a/src/networkio.c b/src/networkio.c
|
|
index bfa69e8..54f99c3 100644
|
|
--- a/src/networkio.c
|
|
+++ b/src/networkio.c
|
|
@@ -41,6 +41,9 @@
|
|
#include <ifaddrs.h>
|
|
#include <linux/if_ether.h>
|
|
#include <linux/if_packet.h>
|
|
+#include <net/if_arp.h>
|
|
+#include <sys/stat.h>
|
|
+#include <limits.h>
|
|
#include <ctype.h>
|
|
#include <syslog.h>
|
|
#include "amtu.h"
|
|
@@ -143,7 +146,51 @@ int send_packet(struct interface_info *iff)
|
|
close(ssock_fd);
|
|
return 0;
|
|
}
|
|
-
|
|
+
|
|
+int sysfs_present(const char *path)
|
|
+{
|
|
+ struct stat st;
|
|
+ return stat(path, &st);
|
|
+}
|
|
+
|
|
+int get_sysfs_value(const char *sysfs_path)
|
|
+{
|
|
+ FILE *f;
|
|
+ int value = -1;
|
|
+
|
|
+ f = fopen(sysfs_path, "r");
|
|
+ if (f) {
|
|
+ fscanf(f, "%d", &value);
|
|
+ fclose(f);
|
|
+ }
|
|
+
|
|
+ return value;
|
|
+}
|
|
+
|
|
+int get_interface_type(const char *if_name)
|
|
+{
|
|
+ char sysfs_if_type[PATH_MAX];
|
|
+ int type = -1;
|
|
+
|
|
+ if (snprintf(sysfs_if_type, PATH_MAX,
|
|
+ "/sys/class/net/%s/type", if_name) > 0) {
|
|
+ type = get_sysfs_value(sysfs_if_type);
|
|
+ }
|
|
+ return type;
|
|
+}
|
|
+
|
|
+int get_interface_carrier(const char *if_name)
|
|
+{
|
|
+ char sysfs_if_carrier[PATH_MAX];
|
|
+ int carrier = 0;
|
|
+
|
|
+ if (snprintf(sysfs_if_carrier, PATH_MAX,
|
|
+ "/sys/class/net/%s/carrier", if_name) > 0) {
|
|
+ carrier = get_sysfs_value(sysfs_if_carrier);
|
|
+ }
|
|
+ return carrier;
|
|
+}
|
|
+
|
|
/****************************************************************/
|
|
/* */
|
|
/* FUNCTION: get_interfaces */
|
|
@@ -174,10 +221,31 @@ int get_interfaces()
|
|
struct interface_info *np;
|
|
int found = 0;
|
|
|
|
- /* only testing ethernet and tokenring */
|
|
- if ((strncmp(ifa->ifa_name, "eth", 3) != 0) &&
|
|
- (strncmp(ifa->ifa_name, "tr", 2) != 0))
|
|
- continue;
|
|
+ if (sysfs_present("/sys/class/net") == 0) {
|
|
+ int if_type = -1;
|
|
+ int if_carrier = 0;
|
|
+
|
|
+ if_type = get_interface_type(ifa->ifa_name);
|
|
+ if_carrier = get_interface_carrier(ifa->ifa_name);
|
|
+
|
|
+ if (debug)
|
|
+ printf("if: %7s, type: %4d, carrier: %3d\n",
|
|
+ ifa->ifa_name, if_type, if_carrier);
|
|
+
|
|
+ /* only testing ethernet and tokenring */
|
|
+ if (if_type != ARPHRD_ETHER &&
|
|
+ if_type != ARPHRD_IEEE802_TR)
|
|
+ continue;
|
|
+
|
|
+ /* only testing if carrier present */
|
|
+ if (if_carrier != 1)
|
|
+ continue;
|
|
+ } else {
|
|
+ /* with no sysfs, just fall back to old way */
|
|
+ if ((strncmp(ifa->ifa_name, "eth", 3) != 0) &&
|
|
+ (strncmp(ifa->ifa_name, "tr", 2) != 0))
|
|
+ continue;
|
|
+ }
|
|
|
|
/* check family */
|
|
if (ifa->ifa_addr->sa_family != AF_INET &&
|
|
--
|
|
1.7.1
|
|
|