xref: /dflybsd-src/contrib/tcpdump/print-vjc.c (revision 59c07fbdf8168fa08c76c515186d561b5a92690c)
141c99275SPeter Avalos /*
241c99275SPeter Avalos  * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996, 1997
341c99275SPeter Avalos  *	The Regents of the University of California.  All rights reserved.
441c99275SPeter Avalos  *
541c99275SPeter Avalos  * Redistribution and use in source and binary forms, with or without
641c99275SPeter Avalos  * modification, are permitted provided that: (1) source code distributions
741c99275SPeter Avalos  * retain the above copyright notice and this paragraph in its entirety, (2)
841c99275SPeter Avalos  * distributions including binary code include the above copyright notice and
941c99275SPeter Avalos  * this paragraph in its entirety in the documentation or other materials
1041c99275SPeter Avalos  * provided with the distribution, and (3) all advertising materials mentioning
1141c99275SPeter Avalos  * features or use of this software display the following acknowledgement:
1241c99275SPeter Avalos  * ``This product includes software developed by the University of California,
1341c99275SPeter Avalos  * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
1441c99275SPeter Avalos  * the University nor the names of its contributors may be used to endorse
1541c99275SPeter Avalos  * or promote products derived from this software without specific prior
1641c99275SPeter Avalos  * written permission.
1741c99275SPeter Avalos  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
1841c99275SPeter Avalos  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
1941c99275SPeter Avalos  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
2041c99275SPeter Avalos  */
2141c99275SPeter Avalos 
22411677aeSAaron LI /* \summary: PPP Van Jacobson compression printer */
23411677aeSAaron LI 
24411677aeSAaron LI /* specification: RFC 1144 */
25411677aeSAaron LI 
2641c99275SPeter Avalos #ifdef HAVE_CONFIG_H
27*ed775ee7SAntonio Huete Jimenez #include <config.h>
2841c99275SPeter Avalos #endif
2941c99275SPeter Avalos 
30*ed775ee7SAntonio Huete Jimenez #include "netdissect-stdinc.h"
3141c99275SPeter Avalos 
32411677aeSAaron LI #include "netdissect.h"
33*ed775ee7SAntonio Huete Jimenez #include "extract.h"
3441c99275SPeter Avalos #include "slcompress.h"
3541c99275SPeter Avalos #include "ppp.h"
3641c99275SPeter Avalos 
3741c99275SPeter Avalos /*
3841c99275SPeter Avalos  * XXX - for BSD/OS PPP, what packets get supplied with a PPP header type
3941c99275SPeter Avalos  * of PPP_VJC and what packets get supplied with a PPP header type of
4041c99275SPeter Avalos  * PPP_VJNC?  PPP_VJNC is for "UNCOMPRESSED_TCP" packets, and PPP_VJC
4141c99275SPeter Avalos  * is for COMPRESSED_TCP packets (PPP_IP is used for TYPE_IP packets).
4241c99275SPeter Avalos  *
4341c99275SPeter Avalos  * RFC 1144 implies that, on the wire, the packet type is *not* needed
4441c99275SPeter Avalos  * for PPP, as different PPP protocol types can be used; it only needs
4541c99275SPeter Avalos  * to be put on the wire for SLIP.
4641c99275SPeter Avalos  *
4741c99275SPeter Avalos  * It also indicates that, for compressed SLIP:
4841c99275SPeter Avalos  *
4941c99275SPeter Avalos  *	If the COMPRESSED_TCP bit is set in the first byte, it's
5041c99275SPeter Avalos  *	a COMPRESSED_TCP packet; that byte is the change byte, and
5141c99275SPeter Avalos  *	the COMPRESSED_TCP bit, 0x80, isn't used in the change byte.
5241c99275SPeter Avalos  *
5341c99275SPeter Avalos  *	If the upper 4 bits of the first byte are 7, it's an
5441c99275SPeter Avalos  *	UNCOMPRESSED_TCP packet; that byte is the first byte of
5541c99275SPeter Avalos  *	the UNCOMPRESSED_TCP modified IP header, with a connection
5641c99275SPeter Avalos  *	number in the protocol field, and with the version field
5741c99275SPeter Avalos  *	being 7, not 4.
5841c99275SPeter Avalos  *
5941c99275SPeter Avalos  *	Otherwise, the packet is an IPv4 packet (where the upper 4 bits
6041c99275SPeter Avalos  *	of the packet are 4).
6141c99275SPeter Avalos  *
6241c99275SPeter Avalos  * So this routine looks as if it's sort-of intended to handle
6341c99275SPeter Avalos  * compressed SLIP, although it doesn't handle UNCOMPRESSED_TCP
6441c99275SPeter Avalos  * correctly for that (it doesn't fix the version number and doesn't
6541c99275SPeter Avalos  * do anything to the protocol field), and doesn't check for COMPRESSED_TCP
6641c99275SPeter Avalos  * packets correctly for that (you only check the first bit - see
6741c99275SPeter Avalos  * B.1 in RFC 1144).
6841c99275SPeter Avalos  *
6941c99275SPeter Avalos  * But it's called for BSD/OS PPP, not SLIP - perhaps BSD/OS does weird
7041c99275SPeter Avalos  * things with the headers?
7141c99275SPeter Avalos  *
7241c99275SPeter Avalos  * Without a BSD/OS VJC-compressed PPP trace, or knowledge of what the
7341c99275SPeter Avalos  * BSD/OS VJC code does, we can't say what's the case.
7441c99275SPeter Avalos  *
7541c99275SPeter Avalos  * We therefore leave "proto" - which is the PPP protocol type - in place,
7641c99275SPeter Avalos  * *not* marked as unused, for now, so that GCC warnings about the
7741c99275SPeter Avalos  * unused argument remind us that we should fix this some day.
78411677aeSAaron LI  *
79411677aeSAaron LI  * XXX - also, it fetches the TCP checksum field in COMPRESSED_TCP
80*ed775ee7SAntonio Huete Jimenez  * packets with GET_HE_U_2, rather than with GET_BE_U_2(); RFC 1144 says
81411677aeSAaron LI  * it's "the unmodified TCP checksum", which would imply that it's
82411677aeSAaron LI  * big-endian, but perhaps, on the platform where this was developed,
83411677aeSAaron LI  * the packets were munged by the networking stack before being handed
84411677aeSAaron LI  * to the packet capture mechanism.
8541c99275SPeter Avalos  */
8641c99275SPeter Avalos int
vjc_print(netdissect_options * ndo,const u_char * bp,u_short proto _U_)87*ed775ee7SAntonio Huete Jimenez vjc_print(netdissect_options *ndo, const u_char *bp, u_short proto _U_)
8841c99275SPeter Avalos {
8941c99275SPeter Avalos 	int i;
9041c99275SPeter Avalos 
91*ed775ee7SAntonio Huete Jimenez 	ndo->ndo_protocol = "vjc";
92*ed775ee7SAntonio Huete Jimenez 	switch (GET_U_1(bp) & 0xf0) {
9341c99275SPeter Avalos 	case TYPE_IP:
94411677aeSAaron LI 		if (ndo->ndo_eflag)
95*ed775ee7SAntonio Huete Jimenez 			ND_PRINT("(vjc type=IP) ");
9641c99275SPeter Avalos 		return PPP_IP;
9741c99275SPeter Avalos 	case TYPE_UNCOMPRESSED_TCP:
98411677aeSAaron LI 		if (ndo->ndo_eflag)
99*ed775ee7SAntonio Huete Jimenez 			ND_PRINT("(vjc type=raw TCP) ");
10041c99275SPeter Avalos 		return PPP_IP;
10141c99275SPeter Avalos 	case TYPE_COMPRESSED_TCP:
102411677aeSAaron LI 		if (ndo->ndo_eflag)
103*ed775ee7SAntonio Huete Jimenez 			ND_PRINT("(vjc type=compressed TCP) ");
10441c99275SPeter Avalos 		for (i = 0; i < 8; i++) {
105*ed775ee7SAntonio Huete Jimenez 			if (GET_U_1(bp + 1) & (0x80 >> i))
106*ed775ee7SAntonio Huete Jimenez 				ND_PRINT("%c", "?CI?SAWU"[i]);
10741c99275SPeter Avalos 		}
108*ed775ee7SAntonio Huete Jimenez 		if (GET_U_1(bp + 1))
109*ed775ee7SAntonio Huete Jimenez 			ND_PRINT(" ");
110*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("C=0x%02x ", GET_U_1(bp + 2));
111*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("sum=0x%04x ", GET_HE_U_2(bp + 3));
11241c99275SPeter Avalos 		return -1;
11341c99275SPeter Avalos 	case TYPE_ERROR:
114411677aeSAaron LI 		if (ndo->ndo_eflag)
115*ed775ee7SAntonio Huete Jimenez 			ND_PRINT("(vjc type=error) ");
11641c99275SPeter Avalos 		return -1;
11741c99275SPeter Avalos 	default:
118411677aeSAaron LI 		if (ndo->ndo_eflag)
119*ed775ee7SAntonio Huete Jimenez 			ND_PRINT("(vjc type=0x%02x) ", GET_U_1(bp) & 0xf0);
12041c99275SPeter Avalos 		return -1;
12141c99275SPeter Avalos 	}
12241c99275SPeter Avalos }
123