Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/dist/dhcp Use packet length from IP header instead of packet...



details:   https://anonhg.NetBSD.org/src/rev/95213fc9d1c4
branches:  trunk
changeset: 570610:95213fc9d1c4
user:      perry <perry%NetBSD.org@localhost>
date:      Fri Oct 22 05:22:39 2004 +0000

description:
Use packet length from IP header instead of packet length from BPF
header.
Patches given to me by Ted Lemon.
This avoids using potentially garbage data returned if the ethernet
driver returns a packet that's too long.

diffstat:

 dist/dhcp/common/bpf.c     |  9 +++++----
 dist/dhcp/common/packet.c  |  6 ++++--
 dist/dhcp/includes/dhcpd.h |  2 +-
 3 files changed, 10 insertions(+), 7 deletions(-)

diffs (91 lines):

diff -r c533189ed6ed -r 95213fc9d1c4 dist/dhcp/common/bpf.c
--- a/dist/dhcp/common/bpf.c    Thu Oct 21 21:53:58 2004 +0000
+++ b/dist/dhcp/common/bpf.c    Fri Oct 22 05:22:39 2004 +0000
@@ -47,7 +47,7 @@
 
 #ifndef lint
 static char copyright[] =
-"$Id: bpf.c,v 1.7 2004/04/10 17:53:05 darrenr Exp $ Copyright (c) 1995-2002 The Internet Software Consortium.  All rights reserved.\n";
+"$Id: bpf.c,v 1.8 2004/10/22 05:22:39 perry Exp $ Copyright (c) 1995-2002 The Internet Software Consortium.  All rights reserved.\n";
 #endif /* not lint */
 
 #include "dhcpd.h"
@@ -415,6 +415,7 @@
        int length = 0;
        int offset = 0;
        struct bpf_hdr hdr;
+       unsigned paylen;
 
        /* All this complexity is because BPF doesn't guarantee
           that only one packet will be returned at a time.   We're
@@ -507,7 +508,7 @@
                                               interface -> rbuf_offset,
                                               from,
                                               (unsigned char *)0,
-                                              hdr.bh_caplen);
+                                              hdr.bh_caplen, &paylen);
 
                /* If the IP or UDP checksum was bad, skip the packet... */
                if (offset < 0) {
@@ -531,11 +532,11 @@
 
                /* Copy out the data in the packet... */
                memcpy (buf, interface -> rbuf + interface -> rbuf_offset,
-                       hdr.bh_caplen);
+                       paylen);
                interface -> rbuf_offset =
                        BPF_WORDALIGN (interface -> rbuf_offset +
                                       hdr.bh_caplen);
-               return hdr.bh_caplen;
+               return paylen;
        } while (!length);
        return 0;
 }
diff -r c533189ed6ed -r 95213fc9d1c4 dist/dhcp/common/packet.c
--- a/dist/dhcp/common/packet.c Thu Oct 21 21:53:58 2004 +0000
+++ b/dist/dhcp/common/packet.c Fri Oct 22 05:22:39 2004 +0000
@@ -42,7 +42,7 @@
 
 #ifndef lint
 static char copyright[] =
-"$Id: packet.c,v 1.4 2003/10/24 05:30:33 mellon Exp $ Copyright (c) 1996-2002 The Internet Software Consortium.  All rights reserved.\n";
+"$Id: packet.c,v 1.5 2004/10/22 05:22:39 perry Exp $ Copyright (c) 1996-2002 The Internet Software Consortium.  All rights reserved.\n";
 #endif /* not lint */
 
 #include "dhcpd.h"
@@ -219,13 +219,14 @@
 
 /* UDP header and IP header decoded together for convenience. */
 
-ssize_t decode_udp_ip_header (interface, buf, bufix, from, data, buflen)
+ssize_t decode_udp_ip_header (interface, buf, bufix, from, data, buflen, rbuflen)
        struct interface_info *interface;
        unsigned char *buf;
        unsigned bufix;
        struct sockaddr_in *from;
        unsigned char *data;
        unsigned buflen;
+       unsigned *rbuflen;
 {
   struct ip *ip;
   struct udphdr *udp;
@@ -343,6 +344,7 @@
   /* Copy out the port... */
   memcpy (&from -> sin_port, &udp -> uh_sport, sizeof udp -> uh_sport);
 
+  *rbuflen = ntohs (ip->ip_len) - ip_len - sizeof *udp;
   return ip_len + sizeof *udp;
 }
 #endif /* PACKET_DECODING */
diff -r c533189ed6ed -r 95213fc9d1c4 dist/dhcp/includes/dhcpd.h
--- a/dist/dhcp/includes/dhcpd.h        Thu Oct 21 21:53:58 2004 +0000
+++ b/dist/dhcp/includes/dhcpd.h        Fri Oct 22 05:22:39 2004 +0000
@@ -1940,7 +1940,7 @@
                                 unsigned, struct hardware *));
 ssize_t decode_udp_ip_header PROTO ((struct interface_info *, unsigned char *,
                                     unsigned, struct sockaddr_in *,
-                                    unsigned char *, unsigned));
+                                    unsigned char *, unsigned, unsigned *));
 
 /* ethernet.c */
 void assemble_ethernet_header PROTO ((struct interface_info *, unsigned char *,



Home | Main Index | Thread Index | Old Index