Hi,

I modified PPTP & GRE related codes. What I've done are:

  o As per http://www.isi.edu/in-notes/iana/assignments/ethernet-numbers,
    0x880b should be defined as ETHERTYPE_PPP, not ETHERTYPE_PPTP. 

  o PPTP is now identified by GRE Version Number of 1.

  o Key field is now decoded as Payload length and Call ID in case of 
    PPTP. 

  o Checksum and Offset are now decoded if present.

  o In general, length, checksum, offset are not a concern. So they
    are printed in -vv (or more verbose) case. Version number, Key, 
    Call ID (in PPTP  case), Sequence Number, Acknowledge Number 
    (in PPTP case) are now printed by default.

  o Got rid of most part of struct gre, because they are not actually
    used in the code. 

=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=
 +----+----+     
 |.. .|    |     Motonori Shindo
 |_~__|    |     
 | .. |~~_~|     Sr. Systems Engineer
 | .  |    |     CoSine Communications Inc.
 +----+----+     
 C o S i n e     e-mail:  [EMAIL PROTECTED] 
Communications
=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=--=







 

Index: ethertype.h
===================================================================
RCS file: /tcpdump/master/tcpdump/ethertype.h,v
retrieving revision 1.13
diff -c -r1.13 ethertype.h
*** ethertype.h 2001/02/04 02:19:23     1.13
--- ethertype.h 2001/03/11 15:39:41
***************
*** 102,109 ****
  #ifndef ETHERTYPE_IPV6
  #define ETHERTYPE_IPV6                0x86dd
  #endif
! #ifndef ETHERTYPE_PPTP
! #define       ETHERTYPE_PPTP          0x880b
  #endif
  #ifndef ETHERTYPE_PPPOED
  #define ETHERTYPE_PPPOED      0x8863
--- 102,109 ----
  #ifndef ETHERTYPE_IPV6
  #define ETHERTYPE_IPV6                0x86dd
  #endif
! #ifndef ETHERTYPE_PPP
! #define       ETHERTYPE_PPP           0x880b
  #endif
  #ifndef ETHERTYPE_PPPOED
  #define ETHERTYPE_PPPOED      0x8863
Index: print-ether.c
===================================================================
RCS file: /tcpdump/master/tcpdump/print-ether.c,v
retrieving revision 1.62
diff -c -r1.62 print-ether.c
*** print-ether.c       2001/02/04 02:19:23     1.62
--- print-ether.c       2001/03/11 15:39:42
***************
*** 226,233 ****
                pppoe_print(p, length);
                return (1);
   
!       case ETHERTYPE_PPTP:
!               printf("pptp");
                if (length) {
                        printf(": ");
                        ppp_print(p, length);
--- 226,233 ----
                pppoe_print(p, length);
                return (1);
   
!       case ETHERTYPE_PPP:
!               printf("ppp");
                if (length) {
                        printf(": ");
                        ppp_print(p, length);
Index: print-gre.c
===================================================================
RCS file: /tcpdump/master/tcpdump/print-gre.c,v
retrieving revision 1.10
diff -c -r1.10 print-gre.c
*** print-gre.c 2001/02/03 20:21:28     1.10
--- print-gre.c 2001/03/11 15:39:43
***************
*** 45,75 ****
  #include "addrtoname.h"
  #include "extract.h"          /* must come after interface.h */
  
- #define GRE_SIZE (20)
- 
  struct gre {
!       u_short flags;
!       u_short proto;
!       union {
!               struct gre_ckof {
!                       u_short cksum;
!                       u_short offset;
!               }        gre_ckof;
!               u_int32_t key;
!               u_int32_t seq;
!       }     gre_void1;
!       union {
!               u_int32_t key;
!               u_int32_t seq;
!               u_int32_t routing;
!       }     gre_void2;
!       union {
!               u_int32_t seq;
!               u_int32_t routing;
!       }     gre_void3;
!       union {
!               u_int32_t routing;
!       }     gre_void4;
  };
  
  /* RFC 2784 - GRE */
--- 45,53 ----
  #include "addrtoname.h"
  #include "extract.h"          /* must come after interface.h */
  
  struct gre {
!       u_int16_t flags;
!       u_int16_t proto;
  };
  
  /* RFC 2784 - GRE */
***************
*** 85,90 ****
--- 63,69 ----
  #define GRE_sP                0x0800  /* strict source route present */
  #define GRE_RECUR_MASK        0x0700  /* Recursion Control */
  #define GRE_RECUR_SHIFT       8
+ #define GRE_OP                0xc000  /* Offset Present */
  
  /* "Enhanced GRE" from RFC2637 - PPTP */
  #define GRE_AP                0x0080  /* Ack present */
***************
*** 93,107 ****
  
  /*
   * Deencapsulate and print a GRE-tunneled IP datagram
-  *
-  * XXX PPTP needs to interpret the "key" field...
   */
  void
  gre_print(const u_char *bp, u_int length)
  {
        const u_char *cp = bp + 4;
        const struct gre *gre;
!       u_short flags, proto, extracted_ethertype;
  
        gre = (const struct gre *)bp;
  
--- 72,86 ----
  
  /*
   * Deencapsulate and print a GRE-tunneled IP datagram
   */
  void
  gre_print(const u_char *bp, u_int length)
  {
        const u_char *cp = bp + 4;
        const struct gre *gre;
!       u_int16_t flags, proto;
!       u_short ver=0;
!       u_short extracted_ethertype;
  
        gre = (const struct gre *)bp;
  
***************
*** 126,163 ****
                        putchar('A');
                if (flags & GRE_RECUR_MASK)
                        printf("R%x", (flags & GRE_RECUR_MASK) >> GRE_RECUR_SHIFT);
!               if (flags & GRE_VER_MASK)
!                       printf("v%x", flags & GRE_VER_MASK);
                if (flags & GRE_MBZ_MASK)
                        printf("!%x", flags & GRE_MBZ_MASK);
                fputs("] ", stdout);
        }
-       /* Checksum & Offset are present */
-       if ((flags & GRE_CP) | (flags & GRE_RP))
-               cp += 4;
- 
-       /* We don't support routing fields (variable length) now. Punt. */
-       if (flags & GRE_RP)
-               return;
  
!       if (flags & GRE_KP) {
                TCHECK2(*cp, 4);
                if (vflag > 1)
                        printf("K:%08x ", EXTRACT_32BITS(cp));
                cp += 4;        /* skip key */
        }
        if (flags & GRE_SP) {
                TCHECK2(*cp, 4);
!               if (vflag > 1)
!                       printf("S:%08x ", EXTRACT_32BITS(cp));
                cp += 4;        /* skip seq */
        }
!       if (flags & GRE_AP && (flags & GRE_VER_MASK) >= 1) {
                TCHECK2(*cp, 4);
!               if (vflag > 1)
!                       printf("A:%08x ", EXTRACT_32BITS(cp));
                cp += 4;        /* skip ack */
        }
  
        TCHECK(cp[0]);
  
--- 105,154 ----
                        putchar('A');
                if (flags & GRE_RECUR_MASK)
                        printf("R%x", (flags & GRE_RECUR_MASK) >> GRE_RECUR_SHIFT);
!               ver = flags & GRE_VER_MASK;
!               printf("v%u", ver);
!               
                if (flags & GRE_MBZ_MASK)
                        printf("!%x", flags & GRE_MBZ_MASK);
                fputs("] ", stdout);
        }
  
!       if (flags & GRE_CP) {
!               TCHECK2(*cp, 4);
!               if (vflag > 1)
!                       printf("C:%08x ", EXTRACT_32BITS(cp));
!               cp += 4;        /* skip checksum */
!       }
!       if (flags & GRE_OP) {
                TCHECK2(*cp, 4);
                if (vflag > 1)
+                       printf("O:%08x ", EXTRACT_32BITS(cp));
+               cp += 4;        /* skip offset */
+       }
+       if (flags & GRE_KP) {
+               TCHECK2(*cp, 4);
+               if (ver == 1) {         /* PPTP */
+                       if (vflag > 1)
+                               printf("PL:%u ", EXTRACT_16BITS(cp));
+                       printf("ID:%04x ", EXTRACT_16BITS(cp+2));
+               }
+               else 
                        printf("K:%08x ", EXTRACT_32BITS(cp));
                cp += 4;        /* skip key */
        }
        if (flags & GRE_SP) {
                TCHECK2(*cp, 4);
!               printf("S:%u ", EXTRACT_32BITS(cp));
                cp += 4;        /* skip seq */
        }
!       if (flags & GRE_AP && ver >= 1) {
                TCHECK2(*cp, 4);
!               printf("A:%u ", EXTRACT_32BITS(cp));
                cp += 4;        /* skip ack */
        }
+       /* We don't support routing fields (variable length) now. Punt. */
+       if (flags & GRE_RP)
+               return;
  
        TCHECK(cp[0]);
  

Reply via email to