* complete PPP support.
*/
+/* \summary: Point to Point Protocol (PPP) printer */
+
/*
* TODO:
* o resolve XXX as much as possible
* o BAP support
*/
-#define NETDISSECT_REWORKED
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
-#include <tcpdump-stdinc.h>
+#include <netdissect-stdinc.h>
#ifdef __bsdi__
#include <net/slcompress.h>
#include <stdlib.h>
-#include "interface.h"
+#include "netdissect.h"
#include "extract.h"
#include "addrtoname.h"
#include "ppp.h"
ND_PRINT((ndo, " (length bogus, should be >= 6)"));
return len;
}
- ND_TCHECK2(*(p + 2), 3);
+ ND_TCHECK_24BITS(p + 2);
ND_PRINT((ndo, ": Vendor: %s (%u)",
tok2str(oui_values,"Unknown",EXTRACT_24BITS(p+2)),
EXTRACT_24BITS(p + 2)));
ND_PRINT((ndo, " (length bogus, should be = 4)"));
return len;
}
- ND_TCHECK2(*(p + 2), 2);
+ ND_TCHECK_16BITS(p + 2);
ND_PRINT((ndo, ": %u", EXTRACT_16BITS(p + 2)));
break;
case LCPOPT_ACCM:
ND_PRINT((ndo, " (length bogus, should be = 6)"));
return len;
}
- ND_TCHECK2(*(p + 2), 4);
+ ND_TCHECK_32BITS(p + 2);
ND_PRINT((ndo, ": 0x%08x", EXTRACT_32BITS(p + 2)));
break;
case LCPOPT_AP:
ND_PRINT((ndo, " (length bogus, should be >= 4)"));
return len;
}
- ND_TCHECK2(*(p + 2), 2);
+ ND_TCHECK_16BITS(p + 2);
ND_PRINT((ndo, ": %s", tok2str(ppptype2str, "Unknown Auth Proto (0x04x)", EXTRACT_16BITS(p + 2))));
switch (EXTRACT_16BITS(p+2)) {
ND_PRINT((ndo, " (length bogus, should be >= 4)"));
return 0;
}
- ND_TCHECK2(*(p + 2), 2);
+ ND_TCHECK_16BITS(p+2);
if (EXTRACT_16BITS(p+2) == PPP_LQM)
ND_PRINT((ndo, ": LQR"));
else
ND_PRINT((ndo, " (length bogus, should be = 6)"));
return 0;
}
- ND_TCHECK2(*(p + 2), 4);
+ ND_TCHECK_32BITS(p + 2);
ND_PRINT((ndo, ": 0x%08x", EXTRACT_32BITS(p + 2)));
break;
case LCPOPT_PFC:
ND_PRINT((ndo, " (length bogus, should be = 4)"));
return 0;
}
- ND_TCHECK2(*(p + 2), 2);
+ ND_TCHECK_16BITS(p + 2);
ND_PRINT((ndo, ": 0x%04x", EXTRACT_16BITS(p + 2)));
break;
case LCPOPT_CBACK:
ND_PRINT((ndo, " (length bogus, should be = 4)"));
return 0;
}
- ND_TCHECK2(*(p + 2), 2);
+ ND_TCHECK_16BITS(p + 2);
ND_PRINT((ndo, ": %u", EXTRACT_16BITS(p + 2)));
break;
case LCPOPT_MLED:
static void
handle_mlppp(netdissect_options *ndo,
- const u_char *p, int length) {
-
+ const u_char *p, int length)
+{
if (!ndo->ndo_eflag)
ND_PRINT((ndo, "MLPPP, "));
+ if (length < 2) {
+ ND_PRINT((ndo, "[|mlppp]"));
+ return;
+ }
+ if (!ND_TTEST_16BITS(p)) {
+ ND_PRINT((ndo, "[|mlppp]"));
+ return;
+ }
+
ND_PRINT((ndo, "seq 0x%03x, Flags [%s], length %u",
(EXTRACT_16BITS(p))&0x0fff, /* only support 12-Bit sequence space for now */
bittok2str(ppp_ml_flag_values, "none", *p & 0xc0),
switch (code) {
case PAP_AREQ:
+ /* A valid Authenticate-Request is 6 or more octets long. */
+ if (len < 6)
+ goto trunc;
if (length - (p - p0) < 1)
return;
ND_TCHECK(*p);
break;
case PAP_AACK:
case PAP_ANAK:
+ /* Although some implementations ignore truncation at
+ * this point and at least one generates a truncated
+ * packet, RFC 1334 section 2.2.2 clearly states that
+ * both AACK and ANAK are at least 5 bytes long.
+ */
+ if (len < 5)
+ goto trunc;
if (length - (p - p0) < 1)
return;
ND_TCHECK(*p);
ND_PRINT((ndo, " (length bogus, should be >= 4)"));
return 0;
}
- ND_TCHECK2(*(p + 2), 2);
+ ND_TCHECK_16BITS(p+2);
compproto = EXTRACT_16BITS(p+2);
ND_PRINT((ndo, ": %s (0x%02x):",
ND_PRINT((ndo, " (length bogus, should be >= 3)"));
return len;
}
- ND_TCHECK2(*(p + 2), 1);
+ ND_TCHECK(p[2]);
ND_PRINT((ndo, ": Version: %u, Dictionary Bits: %u",
p[2] >> 5, p[2] & 0x1f));
break;
ND_PRINT((ndo, " (length bogus, should be >= 4)"));
return len;
}
- ND_TCHECK2(*(p + 2), 1);
+ ND_TCHECK(p[3]);
ND_PRINT((ndo, ": Features: %u, PxP: %s, History: %u, #CTX-ID: %u",
(p[2] & 0xc0) >> 6,
(p[2] & 0x20) ? "Enabled" : "Disabled",
ND_PRINT((ndo, " (length bogus, should be >= 4)"));
return len;
}
- ND_TCHECK2(*(p + 2), 1);
+ ND_TCHECK(p[3]);
ND_PRINT((ndo, ": Window: %uK, Method: %s (0x%x), MBZ: %u, CHK: %u",
(p[2] & 0xf0) >> 4,
- ((p[2] & 0x0f) == 8) ? "zlib" : "unkown",
+ ((p[2] & 0x0f) == 8) ? "zlib" : "unknown",
p[2] & 0x0f, (p[3] & 0xfc) >> 2, p[3] & 0x03));
break;
ND_PRINT((ndo, " (length bogus, should be = 6)"));
return len;
}
- ND_TCHECK2(*(p + 2), 4);
+ ND_TCHECK_32BITS(p + 2);
ND_PRINT((ndo, ": Magic-Num 0x%08x", EXTRACT_32BITS(p + 2)));
break;
default:
ppp_hdlc(netdissect_options *ndo,
const u_char *p, int length)
{
- u_char *b, *s, *t, c;
+ u_char *b, *t, c;
+ const u_char *s;
int i, proto;
const void *se;
if (length <= 0)
return;
- b = (uint8_t *)malloc(length);
+ b = (u_char *)malloc(length);
if (b == NULL)
return;
* Do this so that we dont overwrite the original packet
* contents.
*/
- for (s = (u_char *)p, t = b, i = length; i > 0; i--) {
+ for (s = p, t = b, i = length; i > 0 && ND_TTEST(*s); i--) {
c = *s++;
if (c == 0x7d) {
- if (i > 1) {
- i--;
- c = *s++ ^ 0x20;
- } else
- continue;
+ if (i <= 1 || !ND_TTEST(*s))
+ break;
+ i--;
+ c = *s++ ^ 0x20;
}
*t++ = c;
}
ipx_print(ndo, p, length);
break;
case PPP_OSI:
- isoclns_print(ndo, p, length, length);
+ isoclns_print(ndo, p, length);
break;
case PPP_MPLS_UCAST:
case PPP_MPLS_MCAST:
return (chdlc_if_print(ndo, h, p));
default:
+ if (caplen < 4) {
+ ND_PRINT((ndo, "[|ppp]"));
+ return (caplen);
+ }
+
if (ndo->ndo_eflag)
ND_PRINT((ndo, "%02x %02x %d ", p[0], p[1], length));
p += 2;