Mercurial > hg > dhcpcd
changeset 36:7b9e6ee0286f draft
Allow Token Ring on Linux
| author | Roy Marples <roy@marples.name> |
|---|---|
| date | Mon, 18 Dec 2006 10:28:32 +0000 |
| parents | f33e29e1609c |
| children | 6a27e2f8816e |
| files | ChangeLog Makefile arp.c interface.c interface.h socket.c |
| diffstat | 6 files changed, 40 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Mon Dec 18 09:43:44 2006 +0000 +++ b/ChangeLog Mon Dec 18 10:28:32 2006 +0000 @@ -1,3 +1,5 @@ +Allow Linux to use Token Ring again as Linux does not have any more hardware +specific code. BPF needs a patch for Token Ring support. Dawin is now reported to work. cleanmetas now inserts a \ when it finds a ' so we get the proper values in our .info files when read by a shell.
--- a/Makefile Mon Dec 18 09:43:44 2006 +0000 +++ b/Makefile Mon Dec 18 10:28:32 2006 +0000 @@ -7,8 +7,7 @@ CFLAGS ?= -O2 -pipe # Loads of nice flags to ensure our code is good -# We define _BSD_SOURCE for maximum portability -CFLAGS += -D_BSD_SOURCE -pedantic -std=c99 \ +CFLAGS += -pedantic -std=c99 \ -Wall -Wunused -Wimplicit -Wshadow -Wformat=2 \ -Wmissing-declarations -Wno-missing-prototypes -Wwrite-strings \ -Wbad-function-cast -Wnested-externs -Wcomment -Winline \ @@ -45,7 +44,7 @@ echo '#define VERSION "$(VERSION)"' > version.h $(dhcpcd_OBJS): - $(CC) $(CFLAGS) -c $*.c + $(CC) -D_BSD_SOURCE $(CFLAGS) -c $*.c all: $(TARGET)
--- a/arp.c Mon Dec 18 09:43:44 2006 +0000 +++ b/arp.c Mon Dec 18 10:28:32 2006 +0000 @@ -151,7 +151,7 @@ if ((unsigned) bytes < sizeof (reply.hdr) + 2 * (4 + reply.hdr.ar_hln)) continue; - ra.c = ar_spa (&reply.hdr); + ra.c = (unsigned char *) ar_spa (&reply.hdr); logger (LOG_ERR, "ARPOP_REPLY received from %s (%s)", inet_ntoa (ra.a), ether_ntoa ((struct ether_addr *) ar_sha (&reply.hdr)));
--- a/interface.c Mon Dec 18 09:43:44 2006 +0000 +++ b/interface.c Mon Dec 18 10:28:32 2006 +0000 @@ -104,6 +104,7 @@ struct ifreq ifr; interface_t *iface; unsigned char hwaddr[ETHER_ADDR_LEN]; + sa_family_t family; #ifndef __linux__ struct ifaddrs *ifap; @@ -130,14 +131,19 @@ us.sa = p->ifa_addr; - if (p->ifa_addr->sa_family != AF_LINK || us.sdl->sdl_type != IFT_ETHER) - { - logger (LOG_ERR, "not Ethernet"); - freeifaddrs (ifap); - return NULL; - } + if (p->ifa_addr->sa_family != AF_LINK + || (us.sdl->sdl_type != IFT_ETHER)) + /* + && us.sdl->sdl_type != IFT_ISO88025)) + */ + { + logger (LOG_ERR, "interface is not Ethernet"); + freeifaddrs (ifap); + return NULL; + } memcpy (hwaddr, us.sdl->sdl_data + us.sdl->sdl_nlen, ETHER_ADDR_LEN); + family = us.sdl->sdl_type; break; } freeifaddrs (ifap); @@ -166,13 +172,15 @@ close (s); return NULL; } - if (ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) + if (ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER && + ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE802_TR) { - logger (LOG_ERR, "interface is not Ethernet"); + logger (LOG_ERR, "interface is not Ethernet or Token Ring"); close (s); return NULL; } memcpy (hwaddr, ifr.ifr_hwaddr.sa_data, ETHER_ADDR_LEN); + family = ifr.ifr_hwaddr.sa_family; #else ifr.ifr_metric = metric; if (ioctl (s, SIOCSIFMETRIC, &ifr) < 0) @@ -206,6 +214,7 @@ snprintf (iface->infofile, PATH_MAX, INFOFILE, ifname); memcpy (&iface->ethernet_address, hwaddr, ETHER_ADDR_LEN); + iface->family = family; iface->arpable = ! (ifr.ifr_flags & (IFF_NOARP | IFF_LOOPBACK)); logger (LOG_INFO, "ethernet address = %s",
--- a/interface.h Mon Dec 18 09:43:44 2006 +0000 +++ b/interface.h Mon Dec 18 10:28:32 2006 +0000 @@ -49,6 +49,7 @@ { char name[IF_NAMESIZE]; struct ether_addr ethernet_address; + sa_family_t family; bool arpable; int fd;
--- a/socket.c Mon Dec 18 09:43:44 2006 +0000 +++ b/socket.c Mon Dec 18 10:28:32 2006 +0000 @@ -29,6 +29,9 @@ #include <netinet/udp.h> #include <netinet/if_ether.h> #include <net/ethernet.h> +#ifndef __linux__ +#include <net/if_types.h> +#endif #include <net/if.h> #include <errno.h> #include <fcntl.h> @@ -314,14 +317,21 @@ int retval = -1; struct iovec iov[2]; - /* We only support ethernet atm */ - struct ether_header hw; - memset (&hw, 0, sizeof (struct ether_header)); - memset (&hw.ether_dhost, 0xff, ETHER_ADDR_LEN); - hw.ether_type = htons (type); + if (iface->family == IFT_ETHER) + { + struct ether_header hw; + memset (&hw, 0, sizeof (struct ether_header)); + memset (&hw.ether_dhost, 0xff, ETHER_ADDR_LEN); + hw.ether_type = htons (type); - iov[0].iov_base = &hw; - iov[0].iov_len = sizeof (struct ether_header); + iov[0].iov_base = &hw; + iov[0].iov_len = sizeof (struct ether_header); + } + else + { + logger (LOG_ERR, "unsupported interace type %d", iface->family); + return -1; + } iov[1].iov_base = (unsigned char *) data; iov[1].iov_len = len;
