]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Allow Token Ring on Linux
authorRoy Marples <roy@marples.name>
Mon, 18 Dec 2006 10:28:32 +0000 (10:28 +0000)
committerRoy Marples <roy@marples.name>
Mon, 18 Dec 2006 10:28:32 +0000 (10:28 +0000)
ChangeLog
Makefile
arp.c
interface.c
interface.h
socket.c

index 09e8006e98a2773b67b211bb5d3c0941bb54c2b2..47a72cca0e1c202eff09e2514ba31d1f45abb582 100644 (file)
--- 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.
index 955340c289eabe09ee286f2f266ac4c1bd31e139..a432927d8c19a60598af3ff2966198b0c0c13571 100644 (file)
--- 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 5cf8d072e0cbe208d7bb2ecc3698e76441daa2c6..c895fa549126aae5c73a6a0997ea3163edafca44 100644 (file)
--- 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)));
index b819f7a3828ad0aa5b568cf2996e9db1845f02a1..ea9d674ccf01d5f058b7907d97d35d78298b626f 100644 (file)
@@ -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",
index 31e1046c63cad86a24650d096df7f218a34bfb56..bc1eaefb74e50d8e81df95ebcc87826b77a07bc1 100644 (file)
@@ -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;
index 10df6d1826a00f4976e8c7a84fff992eda474b4f..3c4cd4ac4151450b3c4fe895f9a2d86d8f63aba9 100644 (file)
--- a/socket.c
+++ b/socket.c
@@ -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 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;