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
223340d773SGleb Smirnoff /* \summary: PPP Van Jacobson compression printer */
233340d773SGleb Smirnoff
243340d773SGleb Smirnoff /* specification: RFC 1144 */
253340d773SGleb Smirnoff
26*ee67461eSJoseph Mingrone #include <config.h>
27b0453382SBill Fenner
28*ee67461eSJoseph Mingrone #include "netdissect-stdinc.h"
29b0453382SBill Fenner
303340d773SGleb Smirnoff #include "netdissect.h"
31*ee67461eSJoseph Mingrone #include "extract.h"
32685295f4SBill Fenner #include "slcompress.h"
33685295f4SBill Fenner #include "ppp.h"
34685295f4SBill Fenner
355b0fe478SBruce M Simpson /*
365b0fe478SBruce M Simpson * XXX - for BSD/OS PPP, what packets get supplied with a PPP header type
375b0fe478SBruce M Simpson * of PPP_VJC and what packets get supplied with a PPP header type of
385b0fe478SBruce M Simpson * PPP_VJNC? PPP_VJNC is for "UNCOMPRESSED_TCP" packets, and PPP_VJC
395b0fe478SBruce M Simpson * is for COMPRESSED_TCP packets (PPP_IP is used for TYPE_IP packets).
405b0fe478SBruce M Simpson *
415b0fe478SBruce M Simpson * RFC 1144 implies that, on the wire, the packet type is *not* needed
425b0fe478SBruce M Simpson * for PPP, as different PPP protocol types can be used; it only needs
435b0fe478SBruce M Simpson * to be put on the wire for SLIP.
445b0fe478SBruce M Simpson *
455b0fe478SBruce M Simpson * It also indicates that, for compressed SLIP:
465b0fe478SBruce M Simpson *
475b0fe478SBruce M Simpson * If the COMPRESSED_TCP bit is set in the first byte, it's
485b0fe478SBruce M Simpson * a COMPRESSED_TCP packet; that byte is the change byte, and
495b0fe478SBruce M Simpson * the COMPRESSED_TCP bit, 0x80, isn't used in the change byte.
505b0fe478SBruce M Simpson *
515b0fe478SBruce M Simpson * If the upper 4 bits of the first byte are 7, it's an
525b0fe478SBruce M Simpson * UNCOMPRESSED_TCP packet; that byte is the first byte of
535b0fe478SBruce M Simpson * the UNCOMPRESSED_TCP modified IP header, with a connection
545b0fe478SBruce M Simpson * number in the protocol field, and with the version field
555b0fe478SBruce M Simpson * being 7, not 4.
565b0fe478SBruce M Simpson *
575b0fe478SBruce M Simpson * Otherwise, the packet is an IPv4 packet (where the upper 4 bits
585b0fe478SBruce M Simpson * of the packet are 4).
595b0fe478SBruce M Simpson *
605b0fe478SBruce M Simpson * So this routine looks as if it's sort-of intended to handle
615b0fe478SBruce M Simpson * compressed SLIP, although it doesn't handle UNCOMPRESSED_TCP
625b0fe478SBruce M Simpson * correctly for that (it doesn't fix the version number and doesn't
635b0fe478SBruce M Simpson * do anything to the protocol field), and doesn't check for COMPRESSED_TCP
645b0fe478SBruce M Simpson * packets correctly for that (you only check the first bit - see
655b0fe478SBruce M Simpson * B.1 in RFC 1144).
665b0fe478SBruce M Simpson *
675b0fe478SBruce M Simpson * But it's called for BSD/OS PPP, not SLIP - perhaps BSD/OS does weird
685b0fe478SBruce M Simpson * things with the headers?
695b0fe478SBruce M Simpson *
705b0fe478SBruce M Simpson * Without a BSD/OS VJC-compressed PPP trace, or knowledge of what the
715b0fe478SBruce M Simpson * BSD/OS VJC code does, we can't say what's the case.
725b0fe478SBruce M Simpson *
735b0fe478SBruce M Simpson * We therefore leave "proto" - which is the PPP protocol type - in place,
745b0fe478SBruce M Simpson * *not* marked as unused, for now, so that GCC warnings about the
755b0fe478SBruce M Simpson * unused argument remind us that we should fix this some day.
763340d773SGleb Smirnoff *
773340d773SGleb Smirnoff * XXX - also, it fetches the TCP checksum field in COMPRESSED_TCP
78*ee67461eSJoseph Mingrone * packets with GET_HE_U_2, rather than with GET_BE_U_2(); RFC 1144 says
793340d773SGleb Smirnoff * it's "the unmodified TCP checksum", which would imply that it's
803340d773SGleb Smirnoff * big-endian, but perhaps, on the platform where this was developed,
813340d773SGleb Smirnoff * the packets were munged by the networking stack before being handed
823340d773SGleb Smirnoff * to the packet capture mechanism.
835b0fe478SBruce M Simpson */
84b0453382SBill Fenner int
vjc_print(netdissect_options * ndo,const u_char * bp,u_short proto _U_)85*ee67461eSJoseph Mingrone vjc_print(netdissect_options *ndo, const u_char *bp, u_short proto _U_)
86b0453382SBill Fenner {
87b0453382SBill Fenner int i;
88b0453382SBill Fenner
89*ee67461eSJoseph Mingrone ndo->ndo_protocol = "vjc";
90*ee67461eSJoseph Mingrone switch (GET_U_1(bp) & 0xf0) {
91b0453382SBill Fenner case TYPE_IP:
923c602fabSXin LI if (ndo->ndo_eflag)
93*ee67461eSJoseph Mingrone ND_PRINT("(vjc type=IP) ");
94b0453382SBill Fenner return PPP_IP;
95b0453382SBill Fenner case TYPE_UNCOMPRESSED_TCP:
963c602fabSXin LI if (ndo->ndo_eflag)
97*ee67461eSJoseph Mingrone ND_PRINT("(vjc type=raw TCP) ");
98b0453382SBill Fenner return PPP_IP;
99b0453382SBill Fenner case TYPE_COMPRESSED_TCP:
1003c602fabSXin LI if (ndo->ndo_eflag)
101*ee67461eSJoseph Mingrone ND_PRINT("(vjc type=compressed TCP) ");
102b0453382SBill Fenner for (i = 0; i < 8; i++) {
103*ee67461eSJoseph Mingrone if (GET_U_1(bp + 1) & (0x80 >> i))
104*ee67461eSJoseph Mingrone ND_PRINT("%c", "?CI?SAWU"[i]);
105b0453382SBill Fenner }
106*ee67461eSJoseph Mingrone if (GET_U_1(bp + 1))
107*ee67461eSJoseph Mingrone ND_PRINT(" ");
108*ee67461eSJoseph Mingrone ND_PRINT("C=0x%02x ", GET_U_1(bp + 2));
109*ee67461eSJoseph Mingrone ND_PRINT("sum=0x%04x ", GET_HE_U_2(bp + 3));
110b0453382SBill Fenner return -1;
111b0453382SBill Fenner case TYPE_ERROR:
1123c602fabSXin LI if (ndo->ndo_eflag)
113*ee67461eSJoseph Mingrone ND_PRINT("(vjc type=error) ");
114b0453382SBill Fenner return -1;
115b0453382SBill Fenner default:
1163c602fabSXin LI if (ndo->ndo_eflag)
117*ee67461eSJoseph Mingrone ND_PRINT("(vjc type=0x%02x) ", GET_U_1(bp) & 0xf0);
118b0453382SBill Fenner return -1;
119b0453382SBill Fenner }
120b0453382SBill Fenner }
121