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