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