Codebase list netcfg / 6ce6042
Imported Debian version 1.135 Christian Perrier authored 8 years ago Raphaƫl Hertzog committed 8 years ago
6 changed file(s) with 59 addition(s) and 71 deletion(s). Raw diff Collapse all Expand all
0 netcfg (1.135) unstable; urgency=medium
1
2 [ Philipp Kern ]
3 * ethtool-lite: read the kernel's carrier detection result from sysfs
4 on Linux (Closes: #591012)
5 * Default wireless_security_type to WPA. (Closes: #798373)
6
7 -- Christian Perrier <[email protected]> Tue, 03 Nov 2015 14:03:53 +0100
8
9 netcfg (1.134) unstable; urgency=medium
10
11 * Fix is_layer3_qeth on s390x to avoid bailing out if the network
12 driver is not qeth. (Closes: #798376)
13 * Link against libsubunit to resolve a FTBFS.
14
15 -- Philipp Kern <[email protected]> Mon, 17 Aug 2015 17:12:10 +0200
16
017 netcfg (1.133) unstable; urgency=medium
118
219 [ Samuel Thibault ]
44 Uploaders: Colin Watson <[email protected]>,
55 Christian Perrier <[email protected]>,
66 Philipp Kern <[email protected]>
7 Build-Depends: debhelper (>= 9), dpkg-dev (>= 1.9.0), libdebconfclient0-dev (>= 0.46), libdebian-installer4-dev (>= 0.41), po-debconf (>= 0.5.0), libiw-dev (>= 27+28pre9) [!s390 !s390x !sparc !kfreebsd-any !hurd-any], check
7 Build-Depends: debhelper (>= 9), dpkg-dev (>= 1.9.0), libdebconfclient0-dev (>= 0.46), libdebian-installer4-dev (>= 0.41), po-debconf (>= 0.5.0), libiw-dev (>= 27+28pre9) [!s390 !s390x !sparc !kfreebsd-any !hurd-any], check, libsubunit-dev
88 Vcs-Browser: http://anonscm.debian.org/gitweb/?p=d-i/netcfg.git
99 Vcs-Git: git://anonscm.debian.org/d-i/netcfg.git
1010
6464
6565 Template: netcfg/wireless_security_type
6666 Type: select
67 Default: wpa
6768 Choices-C: wep/open, wpa
6869 __Choices: WEP/Open Network, WPA/WPA2 PSK
6970 # :sl2:
00 /* The best bits of mii-diag and ethtool mixed into one big jelly roll. */
11
22 #include <stdio.h>
3 #include <stdlib.h>
34 #include <string.h>
45 #include <unistd.h>
6 #include <errno.h>
57 #include <net/if.h>
68 #include <sys/types.h>
79 #include <sys/ioctl.h>
2022
2123 #if defined(__linux__)
2224
23 #ifndef ETHTOOL_GLINK
24 # define ETHTOOL_GLINK 0x0000000a
25 #endif
26
27 #ifndef SIOCETHTOOL
28 # define SIOCETHTOOL 0x8946
29 #endif
30
31 struct ethtool_value
32 {
33 u_int32_t cmd;
34 u_int32_t data;
35 };
25 #define SYSCLASSNET "/sys/class/net/"
3626
3727 #elif defined(__FreeBSD_kernel__)
3828
4939 #ifdef TEST
5040 char* iface;
5141 #endif
42
43 #if defined(__linux__)
44 int len = strlen(SYSCLASSNET) + strlen(iface) + strlen("/carrier") + 1;
45 char* filename = malloc(len);
46 snprintf(filename, len, SYSCLASSNET "%s/carrier", iface);
47 FILE* fp = fopen(filename, "r");
48 free(filename);
49
50 char result[2];
51 if (fgets(result, sizeof(result), fp) == NULL) {
52 fclose(fp);
53 if (errno == EINVAL) {
54 di_info("ethtool-lite: %s is down", iface);
55 return DISCONNECTED;
56 }
57 di_error("ethtool-lite: getting carrier failed: %s",
58 strerror(errno));
59 return UNKNOWN;
60 }
61 fclose(fp);
62
63 switch (result[0]) {
64 case '1':
65 di_info("ethtool-lite: %s: carrier up", iface);
66 return CONNECTED;
67 case '0':
68 di_info("ethtool-lite: %s: carrier down", iface);
69 return DISCONNECTED;
70 }
71 di_info("ethtool-lite: %s: could not determine carrier state; got \"%s\"",
72 iface, result);
73 return UNKNOWN;
74 #elif defined(__FreeBSD_kernel__)
5275 int fd = socket(AF_INET, SOCK_DGRAM, 0);
5376
5477 if (fd < 0)
6790 iface = argv[1];
6891 #endif
6992
70 #if defined(__linux__)
71 struct ethtool_value edata;
72 struct ifreq ifr;
73
74 memset (&edata, 0, sizeof(struct ethtool_value));
75 edata.cmd = ETHTOOL_GLINK;
76 ifr.ifr_data = (char *)&edata;
77 strncpy (ifr.ifr_name, iface, IFNAMSIZ);
78
79 if (ioctl (fd, SIOCETHTOOL, &ifr) >= 0)
80 {
81 di_info("ethtool-lite: %s is %sconnected.\n", iface,
82 (edata.data) ? "" : "dis");
83 close(fd);
84 return (edata.data) ? CONNECTED : DISCONNECTED;
85 }
86 else
87 {
88 di_info("ethtool-lite: ethtool ioctl on %s failed\n", iface);
89 u_int16_t *data = (u_int16_t *)&ifr.ifr_data;
90 int ctl;
91 data[0] = 0;
92
93 if (ioctl (fd, 0x8947, &ifr) >= 0)
94 ctl = 0x8948;
95 else if (ioctl (fd, SIOCDEVPRIVATE, &ifr) >= 0)
96 ctl = SIOCDEVPRIVATE + 1;
97 else
98 {
99 di_warning("ethtool-lite: couldn't determine MII ioctl to use for %s\n", iface);
100 close(fd);
101 return UNKNOWN;
102 }
103
104 data[1] = 1;
105
106 if (ioctl (fd, ctl, &ifr) >= 0)
107 {
108 int ret = !(data[3] & 0x0004);
109
110 di_info ("ethtool-lite: %s is %sconnected. (MII)\n", iface,
111 (ret) ? "dis" : "");
112
113 close(fd);
114 return ret ? DISCONNECTED : CONNECTED;
115 }
116 }
117
118 di_warning("ethtool-lite: MII ioctl failed for %s\n", iface);
119
120 #elif defined(__FreeBSD_kernel__)
12193 struct ifmediareq ifmr;
12294
12395 memset(&ifmr, 0, sizeof(ifmr));
128100 close(fd);
129101 return UNKNOWN;
130102 }
103 close(fd);
131104
132105 if (ifmr.ifm_status & IFM_AVALID) {
133106 if (ifmr.ifm_status & IFM_ACTIVE) {
134107 di_info("ethtool-lite: %s is connected.\n", iface);
135 close(fd);
136108 return CONNECTED;
137109 } else {
138110 di_info("ethtool-lite: %s is disconnected.\n", iface);
139 close(fd);
140111 return DISCONNECTED;
141112 }
142113 }
145116 #elif defined(__GNU__)
146117 di_warning("ethtool-lite: unsupported on GNU/Hurd for %s\n", iface);
147118 #endif
148 close(fd);
149119 return UNKNOWN;
150120 }
292292 goto out;
293293 }
294294
295 buf[slen + 1] = '\0';
295 buf[slen] = '\0';
296296
297297 driver = strrchr(buf, '/') + 1;
298298 if (strcmp(driver, "qeth") != 0) {
299 di_error("no qeth found: %s", driver);
299 di_info("no qeth found: %s", driver);
300300 goto out;
301301 }
302302
99 OBJECTS = netcfg-common.o wireless.o ethtool-lite.o ipv6.o write_interface.o
1010
1111 test/run: $(TESTS) $(OBJECTS) test/srunner.o
12 $(CC) -o $@ $^ $(LDOPTS) -lcheck -lm -lpthread -lrt
12 $(CC) -o $@ $^ $(LDOPTS) -lcheck -lsubunit -lm -lpthread -lrt
1313
1414 test: test/run
1515 @echo "----------------------------------------"