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/tcpdump Pull up revisions 1.9-1.11 (requested ...



details:   https://anonhg.NetBSD.org/src/rev/b437ee5003f6
branches:  netbsd-1-5
changeset: 491817:b437ee5003f6
user:      he <he%NetBSD.org@localhost>
date:      Sat May 26 21:29:04 2001 +0000

description:
Pull up revisions 1.9-1.11 (requested by itojun):
  Correct A6/DNAME decoder.  Improve decoder for TSIG and multiple
  question section.

diffstat:

 usr.sbin/tcpdump/print-domain.c |  552 ++++++++++++++++++++++++++-------------
 1 files changed, 362 insertions(+), 190 deletions(-)

diffs (truncated from 787 to 300 lines):

diff -r d1d2fabafdc7 -r b437ee5003f6 usr.sbin/tcpdump/print-domain.c
--- a/usr.sbin/tcpdump/print-domain.c   Sat May 26 21:22:47 2001 +0000
+++ b/usr.sbin/tcpdump/print-domain.c   Sat May 26 21:29:04 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: print-domain.c,v 1.8 2000/04/24 13:01:23 itojun Exp $  */
+/*     $NetBSD: print-domain.c,v 1.8.4.1 2001/05/26 21:29:04 he Exp $  */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
@@ -27,7 +27,7 @@
 static const char rcsid[] =
     "@(#) Header: print-domain.c,v 1.39 97/06/13 12:56:28 leres Exp  (LBL)";
 #else
-__RCSID("$NetBSD: print-domain.c,v 1.8 2000/04/24 13:01:23 itojun Exp $");
+__RCSID("$NetBSD: print-domain.c,v 1.8.4.1 2001/05/26 21:29:04 he Exp $");
 #endif
 #endif
 
@@ -35,24 +35,7 @@
 #include <sys/time.h>
 #include <sys/socket.h>
 
-#if __STDC__
-struct mbuf;
-struct rtentry;
-#endif
-#include <net/if.h>
-
 #include <netinet/in.h>
-#include <netinet/in_systm.h>
-#ifdef __NetBSD__
-#include <net/if_ether.h>
-#else
-#include <netinet/if_ether.h>
-#endif
-#include <netinet/ip.h>
-#include <netinet/ip_var.h>
-#include <netinet/udp.h>
-#include <netinet/udp_var.h>
-#include <netinet/tcp.h>
 
 #ifdef NOERROR
 #undef NOERROR                                 /* Solaris sucks */
@@ -60,7 +43,8 @@
 #ifdef NOERROR
 #undef T_UNSPEC                                        /* SINIX does too */
 #endif
-#include <arpa/nameser.h>
+
+#include "nameser.h"
 
 #include <stdio.h>
 #include <string.h>
@@ -69,95 +53,16 @@
 #include "addrtoname.h"
 #include "extract.h"                    /* must come after interface.h */
 
-/* Compatibility */
-#ifndef T_TXT
-#define T_TXT          16              /* text strings */
-#endif
-#ifndef T_RP
-#define T_RP           17              /* responsible person */
-#endif
-#ifndef T_AFSDB
-#define T_AFSDB                18              /* AFS cell database */
-#endif
-#ifndef T_X25
-#define T_X25          19              /* X_25 calling address */
-#endif
-#ifndef T_ISDN
-#define T_ISDN         20              /* ISDN calling address */
-#endif
-#ifndef T_RT
-#define T_RT           21              /* router */
-#endif
-#ifndef T_NSAP
-#define T_NSAP         22              /* NSAP address */
-#endif
-#ifndef T_NSAP_PTR
-#define T_NSAP_PTR     23              /* reverse NSAP lookup (deprecated) */
-#endif
-#ifndef T_SIG
-#define T_SIG          24              /* security signature */
-#endif
-#ifndef T_KEY
-#define T_KEY          25              /* security key */
-#endif
-#ifndef T_PX
-#define T_PX           26              /* X.400 mail mapping */
-#endif
-#ifndef T_GPOS
-#define T_GPOS         27              /* geographical position (withdrawn) */
-#endif
-#ifndef T_AAAA
-#define T_AAAA         28              /* IP6 Address */
-#endif
-#ifndef T_LOC
-#define T_LOC          29              /* Location Information */
-#endif
-#ifndef T_NXT
-#define T_NXT          30              /* Next Valid Name in Zone */
-#endif
-#ifndef T_EID
-#define T_EID          31              /* Endpoint identifier */
-#endif
-#ifndef T_NIMLOC
-#define T_NIMLOC       32              /* Nimrod locator */
-#endif
-#ifndef T_SRV
-#define T_SRV          33              /* Server selection */
-#endif
-#ifndef T_ATMA
-#define T_ATMA         34              /* ATM Address */
-#endif
-#ifndef T_NAPTR
-#define T_NAPTR                35              /* Naming Authority PoinTeR */
-#endif
-#ifndef T_A6
-#define T_A6           38              /* IP6 address (ipngwg-dns-lookups) */
-#endif
-
-#ifndef T_UNSPEC
-#define T_UNSPEC       103             /* Unspecified format (binary data) */
-#endif
-#ifndef T_UNSPECA
-#define T_UNSPECA      104             /* "unspecified ascii". Ugly MIT hack */
-#endif
-
-#ifndef C_CHAOS
-#define C_CHAOS                3               /* for chaos net (MIT) */
-#endif
-#ifndef C_HS
-#define C_HS           4               /* for Hesiod name server (MIT) (XXX) */
-#endif
-
 static char *ns_ops[] = {
-       "", " inv_q", " stat", " op3", " notify", " op5", " op6", " op7",
+       "", " inv_q", " stat", " op3", " notify", " update", " op6", " op7",
        " op8", " updataA", " updateD", " updateDA",
        " updateM", " updateMA", " zoneInit", " zoneRef",
 };
 
 static char *ns_resp[] = {
        "", " FormErr", " ServFail", " NXDomain",
-       " NotImp", " Refused", " Resp6", " Resp7",
-       " Resp8", " Resp9", " Resp10", " Resp11",
+       " NotImp", " Refused", " YXDomain", " YXRRSet",
+       " NXRRSet", " NotAuth", " NotZone", " Resp11",
        " Resp12", " Resp13", " Resp14", " NoChange",
 };
 
@@ -169,8 +74,22 @@
 
        if (((i = *cp++) & INDIR_MASK) == INDIR_MASK)
                return (cp + 1);
+       if (cp >= snapend)
+               return(NULL);
        while (i && cp < snapend) {
-               cp += i;
+               if ((i & INDIR_MASK) == EDNS0_MASK) {
+                       int bitlen, bytelen;
+
+                       if ((i & ~INDIR_MASK) != EDNS0_ELT_BITLABEL)
+                               return(NULL); /* unknown ELT */
+                       if ((bitlen = *cp++) == 0)
+                               bitlen = 256;
+                       bytelen = (bitlen + 7) / 8;
+                       cp += bytelen;
+               } else
+                       cp += i;
+               if (cp >= snapend)
+                       return(NULL);
                i = *cp++;
        }
        return (cp);
@@ -178,26 +97,95 @@
 
 /* print a <domain-name> */
 static const u_char *
-ns_nprint(register const u_char *cp, register const u_char *bp)
+blabel_print(const u_char *cp)
+{
+       int bitlen, slen, b;
+       int truncated = 0;
+       const u_char *bitp, *lim;
+       char tc;
+
+       if (cp >= snapend)
+               return(NULL);
+       if ((bitlen = *cp) == 0)
+               bitlen = 256;
+       slen = (bitlen + 3) / 4;
+       if ((lim = cp + 1 + slen) > snapend) {
+               truncated = 1;
+               lim = snapend;
+       }
+
+       /* print the bit string as a hex string */
+       printf("\\[x");
+       for (bitp = cp + 1, b = bitlen; bitp < lim && b > 7; b -= 8, bitp++)
+               printf("%02x", *bitp);
+       if (bitp == lim)
+               printf("...");
+       else if (b > 4) {
+               tc = *bitp++;
+               printf("%02x", tc & (0xff << (8 - b)));
+       } else if (b > 0) {
+               tc = *bitp++;
+               printf("%1x", ((tc >> 4) & 0x0f) & (0x0f << (4 - b)));
+       }
+       printf("/%d]", bitlen);
+
+       return(truncated ? NULL : lim);
+}
+
+static int
+labellen(const u_char *cp)
 {
        register u_int i;
-       register const u_char *rp;
-       register int compress;
+
+       if (cp >= snapend)
+               return(-1);
+       i = *cp;
+       if ((i & INDIR_MASK) == EDNS0_MASK) {
+               int bitlen, elt;
+
+               if ((elt = (i & ~INDIR_MASK)) != EDNS0_ELT_BITLABEL)
+                       return(-1);
+               if (cp + 1 >= snapend)
+                       return(-1);
+               if ((bitlen = *(cp + 1)) == 0)
+                       bitlen = 256;
+               return(((bitlen + 7) / 8) + 1);
+       } else
+               return(i);
+}
+
+static const u_char *
+ns_nprint(register const u_char *cp, register const u_char *bp)
+{
+       register u_int i, l;
+       register const u_char *rp = NULL;
+       register int compress = 0;
        int chars_processed;
+       int elt;
        int data_size = snapend - bp;
 
-       i = *cp++;
+       if ((l = labellen(cp)) < 0)
+               return(NULL);
+       if (cp >= snapend)
+               return(NULL);
        chars_processed = 1;
-       rp = cp + i;
-       if ((i & INDIR_MASK) == INDIR_MASK) {
-               rp = cp + 1;
-               compress = 1;
-       } else
+       if (((i = *cp++) & INDIR_MASK) != INDIR_MASK) {
                compress = 0;
+               rp = cp + l;
+       }
+
        if (i != 0)
                while (i && cp < snapend) {
                        if ((i & INDIR_MASK) == INDIR_MASK) {
+                               if (!compress) {
+                                       rp = cp + 1;
+                                       compress = 1;
+                               }
                                cp = bp + (((i << 8) | *cp) & 0x3fff);
+                               if (cp >= snapend)
+                                       return(NULL);
+                               if ((l = labellen(cp)) < 0)
+                                       return(NULL);
                                i = *cp++;
                                chars_processed++;
 
@@ -208,22 +196,36 @@
                                 * which means we're looping.
                                 */
                                if (chars_processed >= data_size) {
-                                       fn_printn(cp, 6, "<LOOP>");
-                                       if (!compress)
-                                               rp += i + 1;
-                                       return (rp);
+                                       printf("<LOOP>");
+                                       return (NULL);
                                }
                                continue;
                        }
-                       if (fn_printn(cp, i, snapend))
-                               break;
-                       cp += i;
-                       chars_processed += i;
+                       if ((i & INDIR_MASK) == EDNS0_MASK) {
+                               elt = (i & ~INDIR_MASK);



Home | Main Index | Thread Index | Old Index