xref: /freebsd/contrib/tcpdump/print-vjc.c (revision 3340d77368116708ab5b5b95acf6c9c710528300)
1b0453382SBill Fenner /*
2b0453382SBill Fenner  * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996, 1997
3b0453382SBill Fenner  *	The Regents of the University of California.  All rights reserved.
4b0453382SBill Fenner  *
5b0453382SBill Fenner  * Redistribution and use in source and binary forms, with or without
6b0453382SBill Fenner  * modification, are permitted provided that: (1) source code distributions
7b0453382SBill Fenner  * retain the above copyright notice and this paragraph in its entirety, (2)
8b0453382SBill Fenner  * distributions including binary code include the above copyright notice and
9b0453382SBill Fenner  * this paragraph in its entirety in the documentation or other materials
10b0453382SBill Fenner  * provided with the distribution, and (3) all advertising materials mentioning
11b0453382SBill Fenner  * features or use of this software display the following acknowledgement:
12b0453382SBill Fenner  * ``This product includes software developed by the University of California,
13b0453382SBill Fenner  * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14b0453382SBill Fenner  * the University nor the names of its contributors may be used to endorse
15b0453382SBill Fenner  * or promote products derived from this software without specific prior
16b0453382SBill Fenner  * written permission.
17b0453382SBill Fenner  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18b0453382SBill Fenner  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19b0453382SBill Fenner  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20b0453382SBill Fenner  */
21b0453382SBill Fenner 
22*3340d773SGleb Smirnoff /* \summary: PPP Van Jacobson compression printer */
23*3340d773SGleb Smirnoff 
24*3340d773SGleb Smirnoff /* specification: RFC 1144 */
25*3340d773SGleb Smirnoff 
26b0453382SBill Fenner #ifdef HAVE_CONFIG_H
27b0453382SBill Fenner #include "config.h"
28b0453382SBill Fenner #endif
29b0453382SBill Fenner 
30*3340d773SGleb Smirnoff #include <netdissect-stdinc.h>
31b0453382SBill Fenner 
32*3340d773SGleb Smirnoff #include "netdissect.h"
33685295f4SBill Fenner #include "slcompress.h"
34685295f4SBill Fenner #include "ppp.h"
35685295f4SBill Fenner 
365b0fe478SBruce M Simpson /*
375b0fe478SBruce M Simpson  * XXX - for BSD/OS PPP, what packets get supplied with a PPP header type
385b0fe478SBruce M Simpson  * of PPP_VJC and what packets get supplied with a PPP header type of
395b0fe478SBruce M Simpson  * PPP_VJNC?  PPP_VJNC is for "UNCOMPRESSED_TCP" packets, and PPP_VJC
405b0fe478SBruce M Simpson  * is for COMPRESSED_TCP packets (PPP_IP is used for TYPE_IP packets).
415b0fe478SBruce M Simpson  *
425b0fe478SBruce M Simpson  * RFC 1144 implies that, on the wire, the packet type is *not* needed
435b0fe478SBruce M Simpson  * for PPP, as different PPP protocol types can be used; it only needs
445b0fe478SBruce M Simpson  * to be put on the wire for SLIP.
455b0fe478SBruce M Simpson  *
465b0fe478SBruce M Simpson  * It also indicates that, for compressed SLIP:
475b0fe478SBruce M Simpson  *
485b0fe478SBruce M Simpson  *	If the COMPRESSED_TCP bit is set in the first byte, it's
495b0fe478SBruce M Simpson  *	a COMPRESSED_TCP packet; that byte is the change byte, and
505b0fe478SBruce M Simpson  *	the COMPRESSED_TCP bit, 0x80, isn't used in the change byte.
515b0fe478SBruce M Simpson  *
525b0fe478SBruce M Simpson  *	If the upper 4 bits of the first byte are 7, it's an
535b0fe478SBruce M Simpson  *	UNCOMPRESSED_TCP packet; that byte is the first byte of
545b0fe478SBruce M Simpson  *	the UNCOMPRESSED_TCP modified IP header, with a connection
555b0fe478SBruce M Simpson  *	number in the protocol field, and with the version field
565b0fe478SBruce M Simpson  *	being 7, not 4.
575b0fe478SBruce M Simpson  *
585b0fe478SBruce M Simpson  *	Otherwise, the packet is an IPv4 packet (where the upper 4 bits
595b0fe478SBruce M Simpson  *	of the packet are 4).
605b0fe478SBruce M Simpson  *
615b0fe478SBruce M Simpson  * So this routine looks as if it's sort-of intended to handle
625b0fe478SBruce M Simpson  * compressed SLIP, although it doesn't handle UNCOMPRESSED_TCP
635b0fe478SBruce M Simpson  * correctly for that (it doesn't fix the version number and doesn't
645b0fe478SBruce M Simpson  * do anything to the protocol field), and doesn't check for COMPRESSED_TCP
655b0fe478SBruce M Simpson  * packets correctly for that (you only check the first bit - see
665b0fe478SBruce M Simpson  * B.1 in RFC 1144).
675b0fe478SBruce M Simpson  *
685b0fe478SBruce M Simpson  * But it's called for BSD/OS PPP, not SLIP - perhaps BSD/OS does weird
695b0fe478SBruce M Simpson  * things with the headers?
705b0fe478SBruce M Simpson  *
715b0fe478SBruce M Simpson  * Without a BSD/OS VJC-compressed PPP trace, or knowledge of what the
725b0fe478SBruce M Simpson  * BSD/OS VJC code does, we can't say what's the case.
735b0fe478SBruce M Simpson  *
745b0fe478SBruce M Simpson  * We therefore leave "proto" - which is the PPP protocol type - in place,
755b0fe478SBruce M Simpson  * *not* marked as unused, for now, so that GCC warnings about the
765b0fe478SBruce M Simpson  * unused argument remind us that we should fix this some day.
77*3340d773SGleb Smirnoff  *
78*3340d773SGleb Smirnoff  * XXX - also, it fetches the TCP checksum field in COMPRESSED_TCP
79*3340d773SGleb Smirnoff  * packets directly, rather than with EXTRACT_16BITS(); RFC 1144 says
80*3340d773SGleb Smirnoff  * it's "the unmodified TCP checksum", which would imply that it's
81*3340d773SGleb Smirnoff  * big-endian, but perhaps, on the platform where this was developed,
82*3340d773SGleb Smirnoff  * the packets were munged by the networking stack before being handed
83*3340d773SGleb Smirnoff  * to the packet capture mechanism.
845b0fe478SBruce M Simpson  */
85b0453382SBill Fenner int
863c602fabSXin LI vjc_print(netdissect_options *ndo, register const char *bp, u_short proto _U_)
87b0453382SBill Fenner {
88b0453382SBill Fenner 	int i;
89b0453382SBill Fenner 
90b0453382SBill Fenner 	switch (bp[0] & 0xf0) {
91b0453382SBill Fenner 	case TYPE_IP:
923c602fabSXin LI 		if (ndo->ndo_eflag)
933c602fabSXin LI 			ND_PRINT((ndo, "(vjc type=IP) "));
94b0453382SBill Fenner 		return PPP_IP;
95b0453382SBill Fenner 	case TYPE_UNCOMPRESSED_TCP:
963c602fabSXin LI 		if (ndo->ndo_eflag)
973c602fabSXin LI 			ND_PRINT((ndo, "(vjc type=raw TCP) "));
98b0453382SBill Fenner 		return PPP_IP;
99b0453382SBill Fenner 	case TYPE_COMPRESSED_TCP:
1003c602fabSXin LI 		if (ndo->ndo_eflag)
1013c602fabSXin LI 			ND_PRINT((ndo, "(vjc type=compressed TCP) "));
102b0453382SBill Fenner 		for (i = 0; i < 8; i++) {
103b0453382SBill Fenner 			if (bp[1] & (0x80 >> i))
1043c602fabSXin LI 				ND_PRINT((ndo, "%c", "?CI?SAWU"[i]));
105b0453382SBill Fenner 		}
106b0453382SBill Fenner 		if (bp[1])
1073c602fabSXin LI 			ND_PRINT((ndo, " "));
1083c602fabSXin LI 		ND_PRINT((ndo, "C=0x%02x ", bp[2]));
109*3340d773SGleb Smirnoff 		ND_PRINT((ndo, "sum=0x%04x ", *(const u_short *)&bp[3]));
110b0453382SBill Fenner 		return -1;
111b0453382SBill Fenner 	case TYPE_ERROR:
1123c602fabSXin LI 		if (ndo->ndo_eflag)
1133c602fabSXin LI 			ND_PRINT((ndo, "(vjc type=error) "));
114b0453382SBill Fenner 		return -1;
115b0453382SBill Fenner 	default:
1163c602fabSXin LI 		if (ndo->ndo_eflag)
1173c602fabSXin LI 			ND_PRINT((ndo, "(vjc type=0x%02x) ", bp[0] & 0xf0));
118b0453382SBill Fenner 		return -1;
119b0453382SBill Fenner 	}
120b0453382SBill Fenner }
121