Source-Changes-HG archive

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

[src/netbsd-1-5]: src/usr.sbin/dhcp/common Pull up revision 1.1.1.11 (request...



details:   https://anonhg.NetBSD.org/src/rev/3978f103158e
branches:  netbsd-1-5
changeset: 491104:3978f103158e
user:      he <he%NetBSD.org@localhost>
date:      Wed Apr 04 20:56:18 2001 +0000

description:
Pull up revision 1.1.1.11 (requested by mellon):
  Update DHCP software to ISC version 3, Beta 2, Patchlevel 23.

diffstat:

 usr.sbin/dhcp/common/icmp.c |  161 +++++++++++++++++++++++++++++++++++--------
 usr.sbin/dhcp/common/nit.c  |    5 +-
 2 files changed, 133 insertions(+), 33 deletions(-)

diffs (255 lines):

diff -r 93a228f066aa -r 3978f103158e usr.sbin/dhcp/common/icmp.c
--- a/usr.sbin/dhcp/common/icmp.c       Wed Apr 04 20:56:15 2001 +0000
+++ b/usr.sbin/dhcp/common/icmp.c       Wed Apr 04 20:56:18 2001 +0000
@@ -4,7 +4,7 @@
    responses. */
 
 /*
- * Copyright (c) 1996-2000 Internet Software Consortium.
+ * Copyright (c) 1996-2001 Internet Software Consortium.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -44,7 +44,7 @@
 
 #ifndef lint
 static char copyright[] =
-"$Id: icmp.c,v 1.1.1.8.2.2 2000/10/18 04:11:05 tv Exp $ Copyright (c) 1996-2000 The Internet Software Consortium.  All rights reserved.\n";
+"$Id: icmp.c,v 1.1.1.8.2.3 2001/04/04 20:56:18 he Exp $ Copyright (c) 1996-2001 The Internet Software Consortium.  All rights reserved.\n";
 #endif /* not lint */
 
 #include "dhcpd.h"
@@ -60,6 +60,11 @@
 static struct icmp_state *icmp_state;
 static omapi_object_type_t *dhcp_type_icmp;
 
+#if defined (TRACING)
+trace_type_t *trace_icmp_input;
+trace_type_t *trace_icmp_output;
+#endif
+
 /* Initialize the ICMP protocol. */
 
 void icmp_startup (routep, handler)
@@ -95,33 +100,48 @@
        new -> type = dhcp_type_icmp;
        new -> icmp_handler = handler;
 
-       /* Get the protocol number (should be 1). */
-       proto = getprotobyname ("icmp");
-       if (proto)
-               protocol = proto -> p_proto;
+#if defined (TRACING)
+       trace_icmp_input = trace_type_register ("icmp-input", (void *)0,
+                                               trace_icmp_input_input,
+                                               trace_icmp_input_stop, MDL);
+       trace_icmp_output = trace_type_register ("icmp-output", (void *)0,
+                                                trace_icmp_output_input,
+                                                trace_icmp_output_stop, MDL);
 
-       /* Get a raw socket for the ICMP protocol. */
-       new -> socket = socket (AF_INET, SOCK_RAW, protocol);
-       if (new -> socket < 0)
-               log_fatal ("unable to create icmp socket: %m");
+       /* If we're playing back a trace file, don't create the socket
+          or set up the callback. */
+       if (!trace_playback ()) {
+#endif
+               /* Get the protocol number (should be 1). */
+               proto = getprotobyname ("icmp");
+               if (proto)
+                       protocol = proto -> p_proto;
+               
+               /* Get a raw socket for the ICMP protocol. */
+               new -> socket = socket (AF_INET, SOCK_RAW, protocol);
+               if (new -> socket < 0)
+                       log_fatal ("unable to create icmp socket: %m");
 
 #if defined (HAVE_SETFD)
-       if (fcntl (new -> socket, F_SETFD, 1) < 0)
-               log_error ("Can't set close-on-exec on icmp socket: %m");
+               if (fcntl (new -> socket, F_SETFD, 1) < 0)
+                       log_error ("Can't set close-on-exec on icmp: %m");
 #endif
 
-       /* Make sure it does routing... */
-       state = 0;
-       if (setsockopt (new -> socket, SOL_SOCKET, SO_DONTROUTE,
-                       (char *)&state, sizeof state) < 0)
-               log_fatal ("Can't disable SO_DONTROUTE on ICMP socket: %m");
+               /* Make sure it does routing... */
+               state = 0;
+               if (setsockopt (new -> socket, SOL_SOCKET, SO_DONTROUTE,
+                               (char *)&state, sizeof state) < 0)
+                       log_fatal ("Can't disable SO_DONTROUTE on ICMP: %m");
 
-       result = omapi_register_io_object ((omapi_object_t *)new,
-                                          icmp_readsocket, 0,
-                                          icmp_echoreply, 0, 0);
-       if (result != ISC_R_SUCCESS)
-               log_fatal ("Can't register icmp handle: %s",
-                          isc_result_totext (result));
+               result = omapi_register_io_object ((omapi_object_t *)new,
+                                                  icmp_readsocket, 0,
+                                                  icmp_echoreply, 0, 0);
+               if (result != ISC_R_SUCCESS)
+                       log_fatal ("Can't register icmp handle: %s",
+                                  isc_result_totext (result));
+#if defined (TRACING)
+       }
+#endif
        icmp_state = new;
 }
 
@@ -140,6 +160,9 @@
        struct sockaddr_in to;
        struct icmp icmp;
        int status;
+#if defined (TRACING)
+       trace_iov_t iov [2];
+#endif
 
        if (!icmp_state)
                log_fatal ("ICMP protocol used before initialization.");
@@ -166,14 +189,41 @@
        icmp.icmp_cksum = wrapsum (checksum ((unsigned char *)&icmp,
                                             sizeof icmp, 0));
 
-       /* Send the ICMP packet... */
-       status = sendto (icmp_state -> socket, (char *)&icmp, sizeof icmp, 0,
-                        (struct sockaddr *)&to, sizeof to);
-       if (status < 0)
-               log_error ("icmp_echorequest %s: %m", inet_ntoa(to.sin_addr));
+#if defined (TRACING)
+       if (trace_playback ()) {
+               char *buf = (char *)0;
+               unsigned buflen = 0;
 
-       if (status != sizeof icmp)
-               return 0;
+               /* Consume the ICMP event. */
+               status = trace_get_packet (&trace_icmp_output, &buflen, &buf);
+               if (status != ISC_R_SUCCESS)
+                       log_error ("icmp_echorequest: %s",
+                                  isc_result_totext (status));
+               if (buf)
+                       dfree (buf, MDL);
+       } else {
+               if (trace_record ()) {
+                       iov [0].buf = (char *)addr;
+                       iov [0].len = sizeof *addr;
+                       iov [1].buf = (char *)&icmp;
+                       iov [1].len = sizeof icmp;
+                       trace_write_packet_iov (trace_icmp_output,
+                                               2, iov, MDL);
+               }
+#endif
+               /* Send the ICMP packet... */
+               status = sendto (icmp_state -> socket,
+                                (char *)&icmp, sizeof icmp, 0,
+                                (struct sockaddr *)&to, sizeof to);
+               if (status < 0)
+                       log_error ("icmp_echorequest %s: %m",
+                                  inet_ntoa(to.sin_addr));
+
+               if (status != sizeof icmp)
+                       return 0;
+#if defined (TRACING)
+       }
+#endif
        return 1;
 }
 
@@ -183,12 +233,15 @@
        struct icmp *icfrom;
        struct ip *ip;
        struct sockaddr_in from;
-       unsigned char icbuf [1500];
+       u_int8_t icbuf [1500];
        int status;
        SOCKLEN_T sl;
        int hlen, len;
        struct iaddr ia;
        struct icmp_state *state;
+#if defined (TRACING)
+       trace_iov_t iov [2];
+#endif
 
        state = (struct icmp_state *)h;
 
@@ -222,7 +275,53 @@
                memcpy (ia.iabuf, &from.sin_addr, sizeof from.sin_addr);
                ia.len = sizeof from.sin_addr;
 
+#if defined (TRACING)
+               if (trace_record ()) {
+                       ia.len = htonl(ia.len);
+                       iov [0].buf = (char *)&ia;
+                       iov [0].len = sizeof ia;
+                       iov [1].buf = (char *)icbuf;
+                       iov [1].len = len;
+                       trace_write_packet_iov (trace_icmp_input, 2, iov, MDL);
+                       ia.len = ntohl(ia.len);
+               }
+#endif
                (*state -> icmp_handler) (ia, icbuf, len);
        }
        return ISC_R_SUCCESS;
 }
+
+#if defined (TRACING)
+void trace_icmp_input_input (trace_type_t *ttype, unsigned length, char *buf)
+{
+       struct iaddr *ia;
+       unsigned len;
+       u_int8_t *icbuf;
+       ia = (struct iaddr *)buf;
+       ia->len = ntohl(ia->len);
+       icbuf = (u_int8_t *)(ia + 1);
+       if (icmp_state -> icmp_handler)
+               (*icmp_state -> icmp_handler) (*ia, icbuf,
+                                              (int)(length - sizeof ia));
+}
+
+void trace_icmp_input_stop (trace_type_t *ttype) { }
+
+void trace_icmp_output_input (trace_type_t *ttype, unsigned length, char *buf)
+{
+       struct icmp *icmp;
+       struct iaddr *ia;
+
+       if (length != (sizeof (*icmp) + (sizeof *ia))) {
+               log_error ("trace_icmp_output_input: data size mismatch %d:%d",
+                          length, (int)((sizeof (*icmp)) + (sizeof *ia)));
+               return;
+       }
+       ia = (struct iaddr *)buf;
+       icmp = (struct icmp *)(ia + 1);
+
+       log_error ("trace_icmp_output_input: unsent ping to %s", piaddr (*ia));
+}
+
+void trace_icmp_output_stop (trace_type_t *ttype) { }
+#endif /* TRACING */
diff -r 93a228f066aa -r 3978f103158e usr.sbin/dhcp/common/nit.c
--- a/usr.sbin/dhcp/common/nit.c        Wed Apr 04 20:56:15 2001 +0000
+++ b/usr.sbin/dhcp/common/nit.c        Wed Apr 04 20:56:18 2001 +0000
@@ -44,7 +44,7 @@
 
 #ifndef lint
 static char copyright[] =
-"$Id: nit.c,v 1.1.1.8.2.1 2000/10/18 04:11:10 tv Exp $ Copyright (c) 1996-2000 The Internet Software Consortium.  All rights reserved.\n";
+"$Id: nit.c,v 1.1.1.8.2.2 2001/04/04 20:56:18 he Exp $ Copyright (c) 1996-2000 The Internet Software Consortium.  All rights reserved.\n";
 #endif /* not lint */
 
 #include "dhcpd.h"
@@ -314,7 +314,8 @@
 
        /* Start with the sockaddr struct... */
        junk = (struct sockaddr *)&hh [0];
-       hbufp = ((unsigned char *)&junk -> sa_data [0]) - &buf [0];
+       hbufp = (((unsigned char *)&junk -> sa_data [0]) -
+                (unsigned char *)&hh[0]);
        ibufp = 0;
 
        /* Assemble the headers... */



Home | Main Index | Thread Index | Old Index