From: Roy Marples Date: Mon, 18 Dec 2006 10:28:32 +0000 (+0000) Subject: Allow Token Ring on Linux X-Git-Tag: v3.2.3~338 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=75e3d557128403b15929b25330de5ba2ae0d0a45;p=thirdparty%2Fdhcpcd.git Allow Token Ring on Linux --- diff --git a/ChangeLog b/ChangeLog index 09e8006e..47a72cca 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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. diff --git a/Makefile b/Makefile index 955340c2..a432927d 100644 --- a/Makefile +++ b/Makefile @@ -7,8 +7,7 @@ INSTALL ?= install 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 @@ version.h: echo '#define VERSION "$(VERSION)"' > version.h $(dhcpcd_OBJS): - $(CC) $(CFLAGS) -c $*.c + $(CC) -D_BSD_SOURCE $(CFLAGS) -c $*.c all: $(TARGET) diff --git a/arp.c b/arp.c index 5cf8d072..c895fa54 100644 --- a/arp.c +++ b/arp.c @@ -151,7 +151,7 @@ int arp_check (interface_t *iface, struct in_addr address) 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))); diff --git a/interface.c b/interface.c index b819f7a3..ea9d674c 100644 --- a/interface.c +++ b/interface.c @@ -104,6 +104,7 @@ interface_t *read_interface (const char *ifname, int metric) 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 @@ interface_t *read_interface (const char *ifname, int metric) 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 @@ interface_t *read_interface (const char *ifname, int metric) 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 @@ interface_t *read_interface (const char *ifname, int metric) 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", diff --git a/interface.h b/interface.h index 31e1046c..bc1eaefb 100644 --- a/interface.h +++ b/interface.h @@ -49,6 +49,7 @@ typedef struct interface_t { char name[IF_NAMESIZE]; struct ether_addr ethernet_address; + sa_family_t family; bool arpable; int fd; diff --git a/socket.c b/socket.c index 10df6d18..3c4cd4ac 100644 --- a/socket.c +++ b/socket.c @@ -29,6 +29,9 @@ #include #include #include +#ifndef __linux__ +#include +#endif #include #include #include @@ -314,14 +317,21 @@ int send_packet (const interface_t *iface, int type, 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;