Browse Source

apply Andrew's WEP patch, readd mii-diag as ethtool-lite

r21504
tags/1.03
Joshua Kwan 17 years ago
parent
commit
1e41354243
10 changed files with 164 additions and 8 deletions
  1. +1
    -1
      Makefile
  2. +10
    -0
      debian/changelog
  3. +1
    -0
      debian/netcfg-common.templates
  4. +122
    -0
      ethtool-lite.c
  5. +5
    -1
      netcfg-common.c
  6. +1
    -1
      netcfg-dhcp.c
  7. +1
    -1
      netcfg-static.c
  8. +16
    -1
      netcfg.c
  9. +4
    -1
      netcfg.h
  10. +3
    -2
      wireless.c

+ 1
- 1
Makefile View File

@@ -16,7 +16,7 @@ all: $(TARGETS)

netcfg-dhcp: netcfg-dhcp.o dhcp.o
netcfg-static: netcfg-static.o static.o
netcfg: netcfg.o dhcp.o static.o
netcfg: netcfg.o dhcp.o static.o ethtool-lite.o

$(TARGETS): $(COMMON_OBJS)
$(CC) -o $@ $^ $(LDOPTS)


+ 10
- 0
debian/changelog View File

@@ -1,3 +1,13 @@
netcfg (1.03) UNRELEASED; urgency=low

* Joshua Kwan
- mii-diag support is back, but once again, as a function. Hopefully
it works better than the old one. This time, it only chooses a
default interface based on the first connected one it finds.
- Apply Andrew Pollock's WEP key patch. Thanks!

-- Joshua Kwan <joshk@triplehelix.org> Sun, 12 Sep 2004 20:48:48 -0700

netcfg (1.02) unstable; urgency=low

* Colin Watson


+ 1
- 0
debian/netcfg-common.templates View File

@@ -29,6 +29,7 @@ _Description: Name server addresses:
Template: netcfg/choose_interface
Type: select
Choices: ${ifchoices}
Default: ${ifdefault}
_Description: Primary network interface:
Your system has multiple network interfaces. Choose the one to use as
the primary network interface while installing Debian.


+ 122
- 0
ethtool-lite.c View File

@@ -0,0 +1,122 @@
/* The best bits of mii-diag and ethtool mixed into one big jelly roll. */

#include <stdio.h>
#include <string.h>
#include <net/if.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <debian-installer/log.h>

#define CONNECTED 1
#define DISCONNECTED 2
#define UNKNOWN 3

#ifndef ETHTOOL_GLINK
# define ETHTOOL_GLINK 0x0000000a
#endif

#ifndef SIOCETHTOOL
# define SIOCETHTOOL 0x8946
#endif

struct ethtool_value
{
u_int32_t cmd;
u_int32_t data;
};

#ifdef TEST
int main(int argc, char** argv)
#else
int ethtool_lite (char * iface)
#endif
{
struct ethtool_value edata = { .cmd = ETHTOOL_GLINK };
struct ifreq ifr;
#ifdef TEST
char* iface;
#endif
int fd = socket(AF_INET, SOCK_DGRAM, 0);
if (fd < 0)
{
#ifdef TEST
fprintf(stderr, "Error: could not open control socket\n");
return 1;
#else
return UNKNOWN;
#endif
}

#ifdef TEST
if (argc < 2)
{
fprintf(stderr, "Error: must pass an interface name\n");
return 1;
}
iface = argv[1];
#endif
ifr.ifr_data = (void *)&edata;
strncpy (ifr.ifr_name, iface, IFNAMSIZ);
ioctl (fd, SIOCETHTOOL, &ifr);
if (edata.data)
#ifdef TEST
printf("%s is connected.\n", iface);
#else
return CONNECTED;
#endif
else
{
u_int16_t *data = (u_int16_t *)&ifr.ifr_data;
int ctl;
data[0] = 0;

if (ioctl (fd, 0x8947, &ifr) >= 0)
ctl = 0x8948;
else if (ioctl (fd, SIOCDEVPRIVATE, &ifr) >= 0)
ctl = SIOCDEVPRIVATE + 1;
else
{
#ifdef TEST
fprintf(stderr, "Error: couldn't determine MII ioctl to use\n");
return 1;
#else
return UNKNOWN;
#endif
}

data[1] = 1;

if (ioctl (fd, ctl, &ifr) >= 0)
{
#ifdef TEST
printf("%s is %sconnected. (MII)\n", iface,
((data[3] & 0x0004) == 0) ? "dis" : "");
#else
di_info ("%s is %sconnected. (MII)\n", iface,
((data[3] & 0x0004) == 0) ? "dis" : "");
return (((data[3] & 0x004) == 0) + 1);
#endif
}
else
{
#ifdef TEST
fprintf(stderr, "MII ioctl failed\n");
return 1;
#else
di_error("MII ioctl failed\n");
return UNKNOWN;
#endif
}
}

#ifdef TEST
return 0;
#else
return UNKNOWN;
#endif
}

+ 5
- 1
netcfg-common.c View File

@@ -354,7 +354,7 @@ void netcfg_die(struct debconfclient *client)
*/

int netcfg_get_interface(struct debconfclient *client, char **interface,
int *numif)
int *numif, char* defif)
{
char *inter = NULL, **ifs;
size_t len;
@@ -391,6 +391,10 @@ int netcfg_get_interface(struct debconfclient *client, char **interface,
len += newchars + 128;
}
di_snprintfcat(ptr, len, "%s: %s, ", inter, ifdsc);

if (!strcmp(defif, inter))
debconf_subst(client, "netcfg/get_interfaces", "ifdefault", ptr);

free(ifdsc);
}



+ 1
- 1
netcfg-dhcp.c View File

@@ -53,7 +53,7 @@ int main(int argc, char *argv[])
case BACKUP:
return 10;
case GET_INTERFACE:
if (netcfg_get_interface(client, &interface, &num_interfaces))
if (netcfg_get_interface(client, &interface, &num_interfaces, NULL))
state = BACKUP;
else if (! interface || ! num_interfaces)
state = GET_HOSTNAME_ONLY;


+ 1
- 1
netcfg-static.c View File

@@ -51,7 +51,7 @@ int main(int argc, char** argv)
case BACKUP:
return 10;
case GET_INTERFACE:
if (netcfg_get_interface(client, &interface, &num_interfaces))
if (netcfg_get_interface(client, &interface, &num_interfaces, NULL))
state = BACKUP;
else if (! interface || ! num_interfaces)
state = GET_HOSTNAME_ONLY;


+ 16
- 1
netcfg.c View File

@@ -61,6 +61,8 @@ int main(int argc, char *argv[])
enum { BACKUP, GET_INTERFACE, GET_HOSTNAME_ONLY, GET_METHOD, GET_DHCP, GET_STATIC, WCONFIG, WCONFIG_ESSID, WCONFIG_WEP, QUIT } state = GET_INTERFACE;
static struct debconfclient *client;
static int requested_wireless_tools = 0;
char **ifaces;
char *defiface = NULL;
response_t res;

/* initialize libd-i */
@@ -90,7 +92,20 @@ int main(int argc, char *argv[])
case BACKUP:
return 10;
case GET_INTERFACE:
if(netcfg_get_interface(client, &interface, &num_interfaces))
/* Choose a default from ethtool-lite */
get_all_ifs(1, &ifaces);
while (*ifaces)
{
if (ethtool_lite (*ifaces) == 1) /* CONNECTED */
{
defiface = strdup(*ifaces);
break;
}
ifaces++;
}
if(netcfg_get_interface(client, &interface, &num_interfaces, defiface))
state = BACKUP;
else if (! interface || ! num_interfaces)
state = GET_HOSTNAME_ONLY;


+ 4
- 1
netcfg.h View File

@@ -79,7 +79,7 @@ extern FILE *file_open (char *path, const char *opentype);

extern void netcfg_die (struct debconfclient *client);

extern int netcfg_get_interface(struct debconfclient *client, char **interface, int *num_interfaces);
extern int netcfg_get_interface(struct debconfclient *client, char **interface, int *num_interfaces, char* defif);

extern short verify_hostname (char *hname);

@@ -127,4 +127,7 @@ extern void open_sockets (void);
extern void reap_old_files (void);

extern int netcfg_write_resolv (char*, struct in_addr *);

extern int ethtool_lite (char*);

#endif /* _NETCFG_H_ */

+ 3
- 2
wireless.c View File

@@ -217,13 +217,14 @@ int netcfg_wireless_set_wep (struct debconfclient * client, char* iface)

wconf.has_key = 1;
wconf.key_size = keylen;
wconf.key_flags = IW_ENCODE_ENABLED | IW_ENCODE_OPEN;
wconf.key_flags = 0;
strncpy (wconf.key, buf, keylen);

wepkey = strdup(rv);

iw_set_basic_config (wfd, iface, &wconf);
if (iw_set_basic_config (wfd, iface, &wconf) == -1)
fprintf(stderr, "warning: failed to set wep key");

return 0;
}

Loading…
Cancel
Save