]> git.ipfire.org Git - thirdparty/dhcp.git/commitdiff
Support token ring packets.
authorTed Lemon <source@isc.org>
Thu, 27 May 1999 17:43:28 +0000 (17:43 +0000)
committerTed Lemon <source@isc.org>
Thu, 27 May 1999 17:43:28 +0000 (17:43 +0000)
common/Makefile.dist
common/bpf.c
common/lpf.c
common/packet.c
includes/cf/linux.h
includes/dhcpd.h

index 55dd8506c4aca79b4002ac3d763f38c5ab740c53..77c0803a100e67d517f782535ad0f5e75eb70158 100644 (file)
 CATMANPAGES = dhcp-options.cat5 dhcp-contrib.cat5 dhcp-eval.cat5
 SEDMANPAGES = dhcp-options.man5 dhcp-contrib.man5 dhcp-eval.man5
 SRC    = raw.c parse.c nit.c icmp.c dispatch.c conflex.c upf.c bpf.c socket.c \
-        lpf.c dlpi.c packet.c memory.c print.c options.c inet.c convert.c \
-        tree.c tables.c hash.c alloc.c errwarn.c inet_addr.c dns.c \
-        resolv.c execute.c discover.c auth.c
+        lpf.c dlpi.c packet.c tr.c ethernet.c memory.c print.c options.c \
+        inet.c convert.c tree.c tables.c hash.c alloc.c errwarn.c \
+        inet_addr.c dns.c resolv.c execute.c discover.c auth.c
 OBJ    = raw.o parse.o nit.o icmp.o dispatch.o conflex.o upf.o bpf.o socket.o \
-        lpf.o dlpi.o packet.o memory.o print.o options.o inet.o convert.o \
-        tree.o tables.o hash.o alloc.o errwarn.o inet_addr.o dns.o \
-        resolv.o execute.o discover.o auth.o
+        lpf.o dlpi.o packet.o tr.o ethernet.o memory.o print.o options.o \
+        inet.o convert.o tree.o tables.o hash.o alloc.o errwarn.o \
+        inet_addr.o dns.o resolv.o execute.o discover.o auth.o
 MAN    = dhcp-options.5 dhcp-contrib.5 dhcp-eval.5
 
 DEBUG  = -g
index 7b9a29fe4509b3cd9f5a4fa1e4420c65eb086666..1ee65267252a1cdc3a0d3115c2c58b0c3229723b 100644 (file)
@@ -22,7 +22,7 @@
 
 #ifndef lint
 static char copyright[] =
-"$Id: bpf.c,v 1.26 1999/03/16 06:37:48 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium.  All rights reserved.\n";
+"$Id: bpf.c,v 1.27 1999/05/27 17:43:27 mellon Exp $ Copyright (c) 1995, 1996 The Internet Software Consortium.  All rights reserved.\n";
 #endif /* not lint */
 
 #include "dhcpd.h"
@@ -165,6 +165,19 @@ struct bpf_insn dhcp_bpf_filter [] = {
 };
 
 int dhcp_bpf_filter_len = sizeof dhcp_bpf_filter / sizeof (struct bpf_insn);
+struct bpf_insn dhcp_bpf_tr_filter [] = {
+        /* accept all token ring packets due to variable length header */
+        /* if we want to get clever, insert the program here */
+
+       /* If we passed all the tests, ask for the whole packet. */
+       BPF_STMT(BPF_RET+BPF_K, (u_int)-1),
+
+       /* Otherwise, drop it. */
+       BPF_STMT(BPF_RET+BPF_K, 0),
+};
+
+int dhcp_bpf_tr_filter_len = (sizeof dhcp_bpf_tr_filter /
+                             sizeof (struct bpf_insn));
 #endif
 
 #if defined (USE_BPF_RECEIVE)
index af2d58dd1e48fd280a8b6f2818ca107a088f42ea..3d65449e2000b692d8263af85a2b5dfde7821dfe 100644 (file)
@@ -23,7 +23,7 @@
 
 #ifndef lint
 static char copyright[] =
-"$Id: lpf.c,v 1.11 1999/04/12 21:34:37 mellon Exp $ Copyright (c) 1995, 1996, 1998, 1999 The Internet Software Consortium.  All rights reserved.\n";
+"$Id: lpf.c,v 1.12 1999/05/27 17:43:27 mellon Exp $ Copyright (c) 1995, 1996, 1998, 1999 The Internet Software Consortium.  All rights reserved.\n";
 #endif /* not lint */
 
 #include "dhcpd.h"
@@ -125,15 +125,36 @@ void if_register_send (info)
    in bpf includes... */
 extern struct sock_filter dhcp_bpf_filter [];
 extern int dhcp_bpf_filter_len;
+extern struct sock_filter dhcp_bpf_tr_filter [];
+extern int dhcp_bpf_tr_filter_len;
 
 void if_register_receive (info)
        struct interface_info *info;
 {
-       struct sock_fprog p;
-
        /* Open a LPF device and hang it on this interface... */
        info -> rfdesc = if_register_lpf (info);
 
+       if (info -> hw_address.htype == HTYPE_IEEE802)
+               lpf_tr_filter_setup (info);
+       else
+               lpf_gen_filter_setup (info);
+
+       if (!quiet_interface_discovery)
+               note ("Listening on LPF/%s/%s%s%s",
+                     info -> name,
+                     print_hw_addr (info -> hw_address.htype,
+                                    info -> hw_address.hlen,
+                                    info -> hw_address.haddr),
+                     (info -> shared_network ? "/" : ""),
+                     (info -> shared_network ?
+                      info -> shared_network -> name : ""));
+}
+
+static void lpf_gen_filter_setup (info)
+       struct interface_info *info;
+{
+       struct sock_fprog p;
+
        /* Set up the bpf filter program structure.    This is defined in
           bpf.c */
        p.len = dhcp_bpf_filter_len;
@@ -149,20 +170,40 @@ void if_register_receive (info)
                if (errno == ENOPROTOOPT || errno == EPROTONOSUPPORT ||
                    errno == ESOCKTNOSUPPORT || errno == EPFNOSUPPORT ||
                    errno == EAFNOSUPPORT)
-                       log_fatal ("socket: %m - make sure %s %s!",
+                       error ("socket: %m - make sure %s %s!",
                               "CONFIG_PACKET and CONFIG_FILTER are defined",
                               "in your kernel configuration");
-               log_fatal ("Can't install packet filter program: %m");
+               error ("Can't install packet filter program: %m");
+       }
+}
+
+static void lpf_tr_filter_setup (info)
+       struct interface_info *info;
+{
+       struct sock_fprog p;
+
+       /* Set up the bpf filter program structure.    This is defined in
+          bpf.c */
+       p.len = dhcp_bpf_tr_filter_len;
+       p.filter = dhcp_bpf_tr_filter;
+
+        /* Patch the server port into the LPF  program...
+          XXX changes to filter program may require changes
+          XXX to the insn number(s) used below!
+          XXX Token ring filter is null - when/if we have a filter 
+          XXX that's not, we'll need this code.
+          XXX dhcp_bpf_filter [?].k = ntohs (local_port); */
+
+       if (setsockopt (info -> rfdesc, SOL_SOCKET, SO_ATTACH_FILTER, &p,
+                       sizeof p) < 0) {
+               if (errno == ENOPROTOOPT || errno == EPROTONOSUPPORT ||
+                   errno == ESOCKTNOSUPPORT || errno == EPFNOSUPPORT ||
+                   errno == EAFNOSUPPORT)
+                       error ("socket: %m - make sure %s %s!",
+                              "CONFIG_PACKET and CONFIG_FILTER are defined",
+                              "in your kernel configuration");
+               error ("Can't install packet filter program: %m");
        }
-       if (!quiet_interface_discovery)
-               log_info ("Listening on LPF/%s/%s%s%s",
-                     info -> name,
-                     print_hw_addr (info -> hw_address.htype,
-                                    info -> hw_address.hlen,
-                                    info -> hw_address.haddr),
-                     (info -> shared_network ? "/" : ""),
-                     (info -> shared_network ?
-                      info -> shared_network -> name : ""));
 }
 #endif /* USE_LPF_RECEIVE */
 
index ea81580e8745f9af816cd13123d67735937de50b..e432de5e73897cc390cac22fed7f5789ed97ae62 100644 (file)
@@ -22,7 +22,7 @@
 
 #ifndef lint
 static char copyright[] =
-"$Id: packet.c,v 1.26 1999/04/23 22:15:43 mellon Exp $ Copyright (c) 1996 The Internet Software Consortium.  All rights reserved.\n";
+"$Id: packet.c,v 1.27 1999/05/27 17:43:27 mellon Exp $ Copyright (c) 1996 The Internet Software Consortium.  All rights reserved.\n";
 #endif /* not lint */
 
 #include "dhcpd.h"
@@ -93,35 +93,19 @@ u_int32_t wrapsum (sum)
 }
 
 #ifdef PACKET_ASSEMBLY
-/* Assemble an hardware header... */
-/* XXX currently only supports ethernet; doesn't check for other types. */
-
 void assemble_hw_header (interface, buf, bufix, to)
        struct interface_info *interface;
        unsigned char *buf;
        int *bufix;
        struct hardware *to;
 {
-       struct ether_header eh;
-
-       if (to && to -> hlen == 6) /* XXX */
-               memcpy (eh.ether_dhost, to -> haddr, sizeof eh.ether_dhost);
+#if defined (HAVE_TR_SUPPORT)
+       if (info -> hw_address.htype == HTYPE_IEEE802)
+               assemble_tr_header (interface, buf, bufix, to);
        else
-               memset (eh.ether_dhost, 0xff, sizeof (eh.ether_dhost));
-       if (interface -> hw_address.hlen == sizeof (eh.ether_shost))
-               memcpy (eh.ether_shost, interface -> hw_address.haddr,
-                       sizeof (eh.ether_shost));
-       else
-               memset (eh.ether_shost, 0x00, sizeof (eh.ether_shost));
-
-#ifdef BROKEN_FREEBSD_BPF /* Fixed in FreeBSD 2.2 */
-       eh.ether_type = ETHERTYPE_IP;
-#else
-       eh.ether_type = htons (ETHERTYPE_IP);
 #endif
+               assemble_ethernet_header (interface, buf, bufix, to);
 
-       memcpy (&buf [*bufix], &eh, sizeof eh);
-       *bufix += sizeof eh;
 }
 
 /* UDP header and IP header assembled together for convenience. */
@@ -195,19 +179,12 @@ ssize_t decode_hw_header (interface, buf, bufix, from)
      int bufix;
      struct hardware *from;
 {
-  struct ether_header eh;
-
-  memcpy (&eh, buf + bufix, sizeof eh);
-
-#ifdef USERLAND_FILTER
-  if (ntohs (eh.ether_type) != ETHERTYPE_IP)
-         return -1;
+#if defined (HAVE_TR_SUPPORT)
+       if (info -> hw_address.htype == HTYPE_IEEE802)
+               return decode_tr_header (interface, buf, bufix, from);
+       else
 #endif
-  memcpy (from -> haddr, eh.ether_shost, sizeof (eh.ether_shost));
-  from -> htype = ARPHRD_ETHER;
-  from -> hlen = sizeof eh.ether_shost;
-
-  return sizeof eh;
+               return decode_ethernet_header (interface, buf, bufix, from);
 }
 
 /* UDP header and IP header decoded together for convenience. */
index 9f0cab818a5aa1c7ee0617d9583f7397fcf53338..c46fe064e4ee1c645605c88db99c4759ca7c15f6 100644 (file)
@@ -106,6 +106,7 @@ extern int h_errno;
 #  define LINUX_SLASHPROC_DISCOVERY
 #  define PROCDEV_DEVICE "/proc/net/dev"
 #  define HAVE_ARPHRD_TUNNEL
+#  define HAVE_TR_SUPPORT
 # endif
 # define HAVE_ARPHRD_METRICOM
 # define HAVE_ARPHRD_IEEE802
index 8bd4bbc1dc19fbc0a10c9907201dc4dfcc857357..5f6e8435ba6b877dd7a7b0c27f3d618d36e854ab 100644 (file)
@@ -1372,6 +1372,20 @@ ssize_t decode_udp_ip_header PROTO ((struct interface_info *, unsigned char *,
                                     int, struct sockaddr_in *,
                                     unsigned char *, int));
 
+/* ethernet.c */
+void assemble_ethernet_header PROTO ((struct interface_info *, unsigned char *,
+                                     int *, struct hardware *));
+ssize_t decode_ethernet_header PROTO ((struct interface_info *,
+                                      unsigned char *,
+                                      int, struct hardware *));
+
+/* tr.c */
+void assemble_tr_header PROTO ((struct interface_info *, unsigned char *,
+                               int *, struct hardware *));
+ssize_t decode_tr_header PROTO ((struct interface_info *,
+                                unsigned char *,
+                                int, struct hardware *));
+
 /* dhxpxlt.c */
 void convert_statement PROTO ((FILE *));
 void convert_host_statement PROTO ((FILE *, jrefproto));