]> The Tcpdump Group git mirrors - tcpdump/commitdiff
print pppOE. From <[email protected]>
authorassar <assar>
Sun, 21 Nov 1999 03:54:24 +0000 (03:54 +0000)
committerassar <assar>
Sun, 21 Nov 1999 03:54:24 +0000 (03:54 +0000)
print-lcp.c [new file with mode: 0644]
print-pppoe.c [new file with mode: 0644]

diff --git a/print-lcp.c b/print-lcp.c
new file mode 100644 (file)
index 0000000..95c4696
--- /dev/null
@@ -0,0 +1,223 @@
+/*
+ * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
+ *     The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that: (1) source code distributions
+ * retain the above copyright notice and this paragraph in its entirety, (2)
+ * distributions including binary code include the above copyright notice and
+ * this paragraph in its entirety in the documentation or other materials
+ * provided with the distribution, and (3) all advertising materials mentioning
+ * features or use of this software display the following acknowledgement:
+ * ``This product includes software developed by the University of California,
+ * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
+ * the University nor the names of its contributors may be used to endorse
+ * or promote products derived from this software without specific prior
+ * written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+#ifndef lint
+static const char rcsid[] =
+"@(#) $Header: /tcpdump/master/tcpdump/Attic/print-lcp.c,v 1.1 1999-11-21 03:54:24 assar Exp $ (LBL)";
+#endif
+
+#include <sys/param.h>
+#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/if_ether.h>
+
+#ifdef HAVE_MEMORY_H
+#include <memory.h>
+#endif
+#include <stdio.h>
+#include <string.h>
+
+#include "interface.h"
+#include "addrtoname.h"
+#include "extract.h"                   /* must come after interface.h */
+#include "ppp.h"
+
+/* Codes */
+enum { 
+  LCP_CONFREQ = 1,
+  LCP_CONFACK = 2,
+  LCP_CONFNAK = 3,
+  LCP_CONFREJ = 4,
+  LCP_TERMREQ = 5,
+  LCP_TERMACK = 6,
+  LCP_CODEREJ = 7,
+  LCP_PROTREJ = 8,
+  LCP_ECHOREQ = 9,
+  LCP_ECHOREP = 10,
+  LCP_DISCARD = 11
+};
+
+static struct tok lcpcode2str[] = {
+  { LCP_CONFREQ, "ConfReq" },
+  { LCP_CONFACK, "ConfAck" },
+  { LCP_CONFNAK, "ConfNak" },
+  { LCP_CONFREJ, "ConfRej" },
+  { LCP_TERMREQ, "TermReq" },
+  { LCP_TERMACK, "TermAck" },
+  { LCP_CODEREJ, "CodeRej" },
+  { LCP_PROTREJ, "ProtRej" },
+  { LCP_ECHOREQ, "EchoReq" },
+  { LCP_ECHOREP, "EchoRep" },
+  { LCP_DISCARD, "Discard" },
+  { 0, NULL }
+};
+
+
+enum {
+  LCP_RESERVED  = 0,
+  LCP_MRU      = 1,
+  LCP_ASYNCMAP  = 2,
+  LCP_AUTHPROTO = 3,
+  LCP_QUALPROTO = 4,
+  LCP_MAGICNUM  = 5,
+  LCP_PCOMP    = 7,
+  LCP_ACFCOMP  = 8,
+  LCP_CALLBACK  = 13
+};
+
+static struct tok lcpoption2str[] = {
+  { LCP_RESERVED, "reserved"},
+  { LCP_MRU, "mru"},
+  { LCP_ASYNCMAP, "asyncmap"},
+  { LCP_AUTHPROTO, "auth"},
+  { LCP_QUALPROTO, "qual"},
+  { LCP_MAGICNUM, "magic"},
+  { LCP_PCOMP, "pcomp"},
+  { LCP_ACFCOMP, "acfcomp"},
+  { LCP_CALLBACK, "callback"},
+  { 0, NULL }
+};
+
+static struct tok lcpauth2str[] = {
+  {0xc023, "PAP"},
+  {0xc223, "CHAP"},
+  { 0, NULL }
+};
+
+static struct tok lcpqual2str[] = {
+  {0xc025, "LQR"},
+  { 0, NULL }
+};
+
+static struct tok lcpchap2str[] = {
+  {0x05, "MD5"},
+  {0x80, "MS"},
+  { 0, NULL }
+};
+
+void
+lcp_print(register const u_char *bp, u_int length, u_int caplen)
+{
+  u_short lcp_code, lcp_id, lcp_length;
+  const u_char *lcp_data;
+
+  lcp_data = bp+4;
+       
+  if (snapend < lcp_data) {
+    printf(" [LCP|]");
+    return;
+  }
+  
+  lcp_code  = bp[0];
+  lcp_id    = bp[1];
+  lcp_length = EXTRACT_16BITS(bp+2);
+
+  printf("LCP %s id=0x%x", tok2str(lcpcode2str, "LCP-#%d", lcp_code), lcp_id);
+  
+  switch(lcp_code) {
+  case LCP_CONFREQ:
+  case LCP_CONFACK:
+  case LCP_CONFNAK:
+  case LCP_CONFREJ:
+    /* Print Options */
+    {
+      u_char lcpopt_type, lcpopt_length;
+      const u_char *p=lcp_data;
+      while (p+2 < lcp_data+lcp_length && p+2 < snapend) {
+       lcpopt_type = p[0];
+       lcpopt_length = p[1];
+       p+=2;
+       printf(" <%s ",tok2str(lcpoption2str, "option-#%d", lcpopt_type), lcpopt_length);
+       if (lcpopt_length)
+         switch (lcpopt_type) {
+         case LCP_MRU:
+           if (snapend < p+2) return;
+           printf("%d",ntohs(*(u_short*)p));
+           if (lcpopt_length != 4) printf(" len=%d!",lcpopt_length);
+           break;
+         case LCP_AUTHPROTO:
+           if (snapend < p+2) return;
+           printf("%s",tok2str(lcpauth2str, "AUTH-%#x", ntohs(*(u_short*)p)));
+           if (lcpopt_length < 4) printf(" len=%d!",lcpopt_length);
+           if (lcpopt_length >= 5 && p < snapend) 
+             printf(" %s",tok2str(lcpchap2str, "%#x", p[0]));
+           break;
+         case LCP_QUALPROTO:
+           if (snapend < p+2) return;
+           printf("%s",tok2str(lcpqual2str, "QUAL-%#x", ntohs(*(u_short*)p)));
+           if (lcpopt_length < 4) printf(" len=%d!",lcpopt_length);
+           /* Print data field of auth? */
+           break;
+         case LCP_ASYNCMAP:
+         case LCP_MAGICNUM:
+           if (snapend < p+4) return;
+           printf("%#x",ntohl(*(u_long*)p));
+           if (lcpopt_length != 6) printf(" len=%d!",lcpopt_length);
+           break;
+         case LCP_PCOMP:
+         case LCP_ACFCOMP:
+         case LCP_RESERVED:
+           if (lcpopt_length != 2) printf(" len=%d!",lcpopt_length);
+           break;
+         default:
+           if (lcpopt_length != 2) printf(" len=%d",lcpopt_length);
+           break;
+         }
+       printf(">");
+       p+=lcpopt_length-2;
+      }
+    }
+    break;
+  case LCP_ECHOREQ:
+  case LCP_ECHOREP:
+  case LCP_DISCARD:
+    if (snapend < lcp_data+4) return;
+    printf(" magic=%#x", ntohl(*(u_long *) lcp_data));
+    lcp_data +=4;
+    break;
+  case LCP_PROTREJ:
+    if (snapend < lcp_data+2) return;
+    printf(" prot=%s", tok2str(ppptype2str, "PROT-%#x", ntohs(*(u_short *) lcp_data)));
+    /* TODO print rejected packet too ? */
+    break;
+  case LCP_CODEREJ:
+    if (snapend < lcp_data+4) return;
+    printf(" ");
+    /* XXX What's caplen? (lcp_print doesn't use it so it doesn't matter here) */
+    lcp_print(lcp_data, (lcp_length+lcp_data > snapend ? snapend-lcp_data : lcp_length), 0);
+    break;
+  case LCP_TERMREQ:
+  case LCP_TERMACK:
+    break;
+  default:
+    break;
+  }
+  
+  return;
+}
diff --git a/print-pppoe.c b/print-pppoe.c
new file mode 100644 (file)
index 0000000..78cfb99
--- /dev/null
@@ -0,0 +1,220 @@
+/*
+ * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
+ *     The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that: (1) source code distributions
+ * retain the above copyright notice and this paragraph in its entirety, (2)
+ * distributions including binary code include the above copyright notice and
+ * this paragraph in its entirety in the documentation or other materials
+ * provided with the distribution, and (3) all advertising materials mentioning
+ * features or use of this software display the following acknowledgement:
+ * ``This product includes software developed by the University of California,
+ * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
+ * the University nor the names of its contributors may be used to endorse
+ * or promote products derived from this software without specific prior
+ * written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+#ifndef lint
+static const char rcsid[] =
+"@(#) $Header: /tcpdump/master/tcpdump/print-pppoe.c,v 1.1 1999-11-21 03:54:24 assar Exp $ (LBL)";
+#endif
+
+#include <sys/param.h>
+#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/if_ether.h>
+
+#ifdef HAVE_MEMORY_H
+#include <memory.h>
+#endif
+#include <stdio.h>
+#include <string.h>
+
+#include "interface.h"
+#include "addrtoname.h"
+#include "ppp.h"
+#include "ethertype.h"
+#include "extract.h"                   /* must come after interface.h */
+
+/* Codes */
+enum { 
+  PPPOE_PADI = 0x09,
+  PPPOE_PADO = 0x07,
+  PPPOE_PADR = 0x19,
+  PPPOE_PADS = 0x65,
+  PPPOE_PADT = 0xa7
+};
+
+static struct tok pppoecode2str[] = {
+  { PPPOE_PADI, "PADI"},
+  { PPPOE_PADO, "PADO"},
+  { PPPOE_PADR, "PADR"},
+  { PPPOE_PADS, "PADS"},
+  { PPPOE_PADT, "PADT"},
+  { 0, ""}, /* PPP Data */
+  { 0, NULL }
+};
+
+/* Tags */
+enum {
+  PPPOE_EOL = 0,
+  PPPOE_SERVICE_NAME = 0x0101,
+  PPPOE_AC_NAME = 0x0102,
+  PPPOE_HOST_UNIQ = 0x0103,
+  PPPOE_AC_COOKIE = 0x0104,
+  PPPOE_VENDOR = 0x0105,
+  PPPOE_RELAY_SID = 0x0110,
+  PPPOE_SERVICE_NAME_ERROR = 0x0201,
+  PPPOE_AC_SYSTEM_ERROR = 0x0202,
+  PPPOE_GENERIC_ERROR = 0x0203,
+};
+
+static struct tok pppoetag2str[] = {
+  { PPPOE_EOL, "EOL"},
+  { PPPOE_SERVICE_NAME, "Service-Name" },
+  { PPPOE_AC_NAME, "AC-Name" },
+  { PPPOE_HOST_UNIQ, "Host-Uniq" },
+  { PPPOE_AC_COOKIE, "AC-Cookie" },
+  { PPPOE_VENDOR, "Vendor-Specific" },
+  { PPPOE_RELAY_SID, "Relay-Session-ID" },
+  { PPPOE_SERVICE_NAME_ERROR, "Service-Name-Error" },
+  { PPPOE_AC_SYSTEM_ERROR, "AC-System-Error" },
+  { PPPOE_GENERIC_ERROR, "Generic-Error" },
+  { 0, NULL}
+};
+
+#define PPPOE_HDRLEN 6
+
+void
+pppoe_print(register const u_char *bp, u_int length, u_int caplen)
+{
+  register const struct ether_header *eh;
+  register u_short pppoe_ver, pppoe_type, pppoe_code, pppoe_sessionid, pppoe_length;
+  const u_char *pppoe_packet, *pppoe_payload;
+
+  eh = (struct ether_header *)packetp;
+  pppoe_packet = packetp+sizeof(struct ether_header);
+  if (pppoe_packet > snapend) {
+    printf("[|pppoe]");
+    return;
+  }
+
+  pppoe_ver  = (pppoe_packet[0]&0xF0)>>4;
+  pppoe_type  = (pppoe_packet[0]&0x0F);
+  pppoe_code = (pppoe_packet[1]);
+  pppoe_sessionid = (EXTRACT_16BITS(pppoe_packet+2));
+  pppoe_length    = (EXTRACT_16BITS(pppoe_packet+4));
+  pppoe_payload = pppoe_packet+6;
+       
+  if (snapend < pppoe_payload) {
+    printf(" truncated PPPoE");
+    return;
+  }
+       
+  if (pppoe_ver != 1) {
+    printf(" [ver %d]",pppoe_ver);
+  }
+  if (pppoe_type != 1) {
+    printf(" [type %d]",pppoe_type);
+  }
+       
+  printf("PPPoE %s", tok2str(pppoecode2str, "PAD-%x", pppoe_code));
+  if (pppoe_code == PPPOE_PADI && pppoe_length > 1484-PPPOE_HDRLEN) {
+    printf(" [len %d!]",pppoe_length);
+  }
+  if (pppoe_sessionid) {
+    printf(" [ses 0x%x]",pppoe_sessionid);
+  }
+
+  if (pppoe_payload + pppoe_length < snapend) {
+    /*
+    printf(" [length %d (%d extra bytes)]", pppoe_length, snapend-pppoe_payload-pppoe_length);
+    {
+      const u_char *x = pppoe_payload+pppoe_length;
+      default_print(x, snapend - x);
+    }
+    */
+    snapend = pppoe_payload+pppoe_length;
+  }
+
+  
+  if (pppoe_code) {
+    /* PPP session packets don't contain tags */
+    u_short tag_type = -1, tag_len;
+    const u_char *p = pppoe_payload;
+
+    /* loop invariant: 
+       p points to next tag, 
+       tag_type is previous tag or -1 for first iteration 
+    */
+    while (tag_type && 
+          p+4 < pppoe_payload + length && 
+          p+4 < snapend) {
+      tag_type = EXTRACT_16BITS(p);
+      tag_len  = EXTRACT_16BITS(p+2);
+      p += 4;
+      /* p points to tag_value */
+
+      if (tag_len) {
+       int isascii = 1;
+       const u_char *v = p;
+
+       for (v=p; v<p+tag_len; v++) 
+         if (*v >= 127 || *v < 32) {
+           isascii = 0;
+           break;
+         }
+       
+       /* TODO print UTF8 decoded text */
+       if (isascii) 
+         printf(" [%s \"%*.*s\"]",
+                tok2str(pppoetag2str, "TAG-0x%x", tag_type),
+                tag_len < 80 ? tag_len : 80,
+                tag_len < 80 ? tag_len : 80,
+                p
+                );
+       else 
+         printf(" [%s UTF8]", tok2str(pppoetag2str, "TAG-0x%x", tag_type));
+      } else
+       printf(" [%s]", tok2str(pppoetag2str, "TAG-0x%x", tag_type));
+      
+      p += tag_len;
+      /* p points to next tag */
+    }
+  } else {
+    u_short ptype;
+    if (pppoe_payload[0] & 0x1) {
+      ptype = pppoe_payload[0];
+      pppoe_payload +=1;
+      pppoe_length  -=1;
+    } else if (pppoe_payload[1] & 0x1) {
+      ptype = ntohs(*(u_short *)pppoe_payload);
+      pppoe_payload +=2;
+      pppoe_length  -=2;
+    } else {
+      printf(" Invalid PPP protocol ID: %x %x", pppoe_payload[0],pppoe_payload[1]);
+      return;
+    }
+    printf(" ");
+    if (ptype == PPP_IP)
+      ip_print(pppoe_payload, pppoe_length);
+    else if (ptype == PPP_LCP) 
+      lcp_print(pppoe_payload, pppoe_length);
+    else
+      printf("%s ", tok2str(ppptype2str, "proto-0x%x", ptype));
+  }
+  return;
+}