From: Ted Lemon Date: Thu, 27 May 1999 17:43:28 +0000 (+0000) Subject: Support token ring packets. X-Git-Tag: V3-ALPHA-19990527~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7d29d66d884e2b6fb688e3b3ab802c7e65527d9e;p=thirdparty%2Fdhcp.git Support token ring packets. --- diff --git a/common/Makefile.dist b/common/Makefile.dist index 55dd8506c..77c0803a1 100644 --- a/common/Makefile.dist +++ b/common/Makefile.dist @@ -20,13 +20,13 @@ 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 diff --git a/common/bpf.c b/common/bpf.c index 7b9a29fe4..1ee652672 100644 --- a/common/bpf.c +++ b/common/bpf.c @@ -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) diff --git a/common/lpf.c b/common/lpf.c index af2d58dd1..3d65449e2 100644 --- a/common/lpf.c +++ b/common/lpf.c @@ -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 */ diff --git a/common/packet.c b/common/packet.c index ea81580e8..e432de5e7 100644 --- a/common/packet.c +++ b/common/packet.c @@ -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. */ diff --git a/includes/cf/linux.h b/includes/cf/linux.h index 9f0cab818..c46fe064e 100644 --- a/includes/cf/linux.h +++ b/includes/cf/linux.h @@ -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 diff --git a/includes/dhcpd.h b/includes/dhcpd.h index 8bd4bbc1d..5f6e8435b 100644 --- a/includes/dhcpd.h +++ b/includes/dhcpd.h @@ -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));