1*b636d99dSDavid van Moolenbroek /*
2*b636d99dSDavid van Moolenbroek * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996, 1997
3*b636d99dSDavid van Moolenbroek * The Regents of the University of California. All rights reserved.
4*b636d99dSDavid van Moolenbroek *
5*b636d99dSDavid van Moolenbroek * Redistribution and use in source and binary forms, with or without
6*b636d99dSDavid van Moolenbroek * modification, are permitted provided that: (1) source code distributions
7*b636d99dSDavid van Moolenbroek * retain the above copyright notice and this paragraph in its entirety, (2)
8*b636d99dSDavid van Moolenbroek * distributions including binary code include the above copyright notice and
9*b636d99dSDavid van Moolenbroek * this paragraph in its entirety in the documentation or other materials
10*b636d99dSDavid van Moolenbroek * provided with the distribution, and (3) all advertising materials mentioning
11*b636d99dSDavid van Moolenbroek * features or use of this software display the following acknowledgement:
12*b636d99dSDavid van Moolenbroek * ``This product includes software developed by the University of California,
13*b636d99dSDavid van Moolenbroek * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14*b636d99dSDavid van Moolenbroek * the University nor the names of its contributors may be used to endorse
15*b636d99dSDavid van Moolenbroek * or promote products derived from this software without specific prior
16*b636d99dSDavid van Moolenbroek * written permission.
17*b636d99dSDavid van Moolenbroek * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18*b636d99dSDavid van Moolenbroek * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19*b636d99dSDavid van Moolenbroek * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20*b636d99dSDavid van Moolenbroek */
21*b636d99dSDavid van Moolenbroek
22*b636d99dSDavid van Moolenbroek #include <sys/cdefs.h>
23*b636d99dSDavid van Moolenbroek #ifndef lint
24*b636d99dSDavid van Moolenbroek __RCSID("$NetBSD: print-vjc.c,v 1.4 2014/11/20 03:05:03 christos Exp $");
25*b636d99dSDavid van Moolenbroek #endif
26*b636d99dSDavid van Moolenbroek
27*b636d99dSDavid van Moolenbroek #define NETDISSECT_REWORKED
28*b636d99dSDavid van Moolenbroek #ifdef HAVE_CONFIG_H
29*b636d99dSDavid van Moolenbroek #include "config.h"
30*b636d99dSDavid van Moolenbroek #endif
31*b636d99dSDavid van Moolenbroek
32*b636d99dSDavid van Moolenbroek #include <tcpdump-stdinc.h>
33*b636d99dSDavid van Moolenbroek
34*b636d99dSDavid van Moolenbroek #include "interface.h"
35*b636d99dSDavid van Moolenbroek #include "slcompress.h"
36*b636d99dSDavid van Moolenbroek #include "ppp.h"
37*b636d99dSDavid van Moolenbroek
38*b636d99dSDavid van Moolenbroek /*
39*b636d99dSDavid van Moolenbroek * XXX - for BSD/OS PPP, what packets get supplied with a PPP header type
40*b636d99dSDavid van Moolenbroek * of PPP_VJC and what packets get supplied with a PPP header type of
41*b636d99dSDavid van Moolenbroek * PPP_VJNC? PPP_VJNC is for "UNCOMPRESSED_TCP" packets, and PPP_VJC
42*b636d99dSDavid van Moolenbroek * is for COMPRESSED_TCP packets (PPP_IP is used for TYPE_IP packets).
43*b636d99dSDavid van Moolenbroek *
44*b636d99dSDavid van Moolenbroek * RFC 1144 implies that, on the wire, the packet type is *not* needed
45*b636d99dSDavid van Moolenbroek * for PPP, as different PPP protocol types can be used; it only needs
46*b636d99dSDavid van Moolenbroek * to be put on the wire for SLIP.
47*b636d99dSDavid van Moolenbroek *
48*b636d99dSDavid van Moolenbroek * It also indicates that, for compressed SLIP:
49*b636d99dSDavid van Moolenbroek *
50*b636d99dSDavid van Moolenbroek * If the COMPRESSED_TCP bit is set in the first byte, it's
51*b636d99dSDavid van Moolenbroek * a COMPRESSED_TCP packet; that byte is the change byte, and
52*b636d99dSDavid van Moolenbroek * the COMPRESSED_TCP bit, 0x80, isn't used in the change byte.
53*b636d99dSDavid van Moolenbroek *
54*b636d99dSDavid van Moolenbroek * If the upper 4 bits of the first byte are 7, it's an
55*b636d99dSDavid van Moolenbroek * UNCOMPRESSED_TCP packet; that byte is the first byte of
56*b636d99dSDavid van Moolenbroek * the UNCOMPRESSED_TCP modified IP header, with a connection
57*b636d99dSDavid van Moolenbroek * number in the protocol field, and with the version field
58*b636d99dSDavid van Moolenbroek * being 7, not 4.
59*b636d99dSDavid van Moolenbroek *
60*b636d99dSDavid van Moolenbroek * Otherwise, the packet is an IPv4 packet (where the upper 4 bits
61*b636d99dSDavid van Moolenbroek * of the packet are 4).
62*b636d99dSDavid van Moolenbroek *
63*b636d99dSDavid van Moolenbroek * So this routine looks as if it's sort-of intended to handle
64*b636d99dSDavid van Moolenbroek * compressed SLIP, although it doesn't handle UNCOMPRESSED_TCP
65*b636d99dSDavid van Moolenbroek * correctly for that (it doesn't fix the version number and doesn't
66*b636d99dSDavid van Moolenbroek * do anything to the protocol field), and doesn't check for COMPRESSED_TCP
67*b636d99dSDavid van Moolenbroek * packets correctly for that (you only check the first bit - see
68*b636d99dSDavid van Moolenbroek * B.1 in RFC 1144).
69*b636d99dSDavid van Moolenbroek *
70*b636d99dSDavid van Moolenbroek * But it's called for BSD/OS PPP, not SLIP - perhaps BSD/OS does weird
71*b636d99dSDavid van Moolenbroek * things with the headers?
72*b636d99dSDavid van Moolenbroek *
73*b636d99dSDavid van Moolenbroek * Without a BSD/OS VJC-compressed PPP trace, or knowledge of what the
74*b636d99dSDavid van Moolenbroek * BSD/OS VJC code does, we can't say what's the case.
75*b636d99dSDavid van Moolenbroek *
76*b636d99dSDavid van Moolenbroek * We therefore leave "proto" - which is the PPP protocol type - in place,
77*b636d99dSDavid van Moolenbroek * *not* marked as unused, for now, so that GCC warnings about the
78*b636d99dSDavid van Moolenbroek * unused argument remind us that we should fix this some day.
79*b636d99dSDavid van Moolenbroek */
80*b636d99dSDavid van Moolenbroek int
vjc_print(netdissect_options * ndo,register const char * bp,u_short proto _U_)81*b636d99dSDavid van Moolenbroek vjc_print(netdissect_options *ndo, register const char *bp, u_short proto _U_)
82*b636d99dSDavid van Moolenbroek {
83*b636d99dSDavid van Moolenbroek int i;
84*b636d99dSDavid van Moolenbroek
85*b636d99dSDavid van Moolenbroek switch (bp[0] & 0xf0) {
86*b636d99dSDavid van Moolenbroek case TYPE_IP:
87*b636d99dSDavid van Moolenbroek if (ndo->ndo_eflag)
88*b636d99dSDavid van Moolenbroek ND_PRINT((ndo, "(vjc type=IP) "));
89*b636d99dSDavid van Moolenbroek return PPP_IP;
90*b636d99dSDavid van Moolenbroek case TYPE_UNCOMPRESSED_TCP:
91*b636d99dSDavid van Moolenbroek if (ndo->ndo_eflag)
92*b636d99dSDavid van Moolenbroek ND_PRINT((ndo, "(vjc type=raw TCP) "));
93*b636d99dSDavid van Moolenbroek return PPP_IP;
94*b636d99dSDavid van Moolenbroek case TYPE_COMPRESSED_TCP:
95*b636d99dSDavid van Moolenbroek if (ndo->ndo_eflag)
96*b636d99dSDavid van Moolenbroek ND_PRINT((ndo, "(vjc type=compressed TCP) "));
97*b636d99dSDavid van Moolenbroek for (i = 0; i < 8; i++) {
98*b636d99dSDavid van Moolenbroek if (bp[1] & (0x80 >> i))
99*b636d99dSDavid van Moolenbroek ND_PRINT((ndo, "%c", "?CI?SAWU"[i]));
100*b636d99dSDavid van Moolenbroek }
101*b636d99dSDavid van Moolenbroek if (bp[1])
102*b636d99dSDavid van Moolenbroek ND_PRINT((ndo, " "));
103*b636d99dSDavid van Moolenbroek ND_PRINT((ndo, "C=0x%02x ", bp[2]));
104*b636d99dSDavid van Moolenbroek ND_PRINT((ndo, "sum=0x%04x ", *(u_short *)&bp[3]));
105*b636d99dSDavid van Moolenbroek return -1;
106*b636d99dSDavid van Moolenbroek case TYPE_ERROR:
107*b636d99dSDavid van Moolenbroek if (ndo->ndo_eflag)
108*b636d99dSDavid van Moolenbroek ND_PRINT((ndo, "(vjc type=error) "));
109*b636d99dSDavid van Moolenbroek return -1;
110*b636d99dSDavid van Moolenbroek default:
111*b636d99dSDavid van Moolenbroek if (ndo->ndo_eflag)
112*b636d99dSDavid van Moolenbroek ND_PRINT((ndo, "(vjc type=0x%02x) ", bp[0] & 0xf0));
113*b636d99dSDavid van Moolenbroek return -1;
114*b636d99dSDavid van Moolenbroek }
115*b636d99dSDavid van Moolenbroek }
116