The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 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 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 22 | /* \summary: PPP Van Jacobson compression printer */ |
| 23 | |
| 24 | /* specification: RFC 1144 */ |
| 25 | |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 26 | #ifdef HAVE_CONFIG_H |
| 27 | #include "config.h" |
| 28 | #endif |
| 29 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 30 | #include <netdissect-stdinc.h> |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 31 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 32 | #include "netdissect.h" |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 33 | #include "slcompress.h" |
| 34 | #include "ppp.h" |
| 35 | |
| 36 | /* |
| 37 | * XXX - for BSD/OS PPP, what packets get supplied with a PPP header type |
| 38 | * of PPP_VJC and what packets get supplied with a PPP header type of |
| 39 | * PPP_VJNC? PPP_VJNC is for "UNCOMPRESSED_TCP" packets, and PPP_VJC |
| 40 | * is for COMPRESSED_TCP packets (PPP_IP is used for TYPE_IP packets). |
| 41 | * |
| 42 | * RFC 1144 implies that, on the wire, the packet type is *not* needed |
| 43 | * for PPP, as different PPP protocol types can be used; it only needs |
| 44 | * to be put on the wire for SLIP. |
| 45 | * |
| 46 | * It also indicates that, for compressed SLIP: |
| 47 | * |
| 48 | * If the COMPRESSED_TCP bit is set in the first byte, it's |
| 49 | * a COMPRESSED_TCP packet; that byte is the change byte, and |
| 50 | * the COMPRESSED_TCP bit, 0x80, isn't used in the change byte. |
| 51 | * |
| 52 | * If the upper 4 bits of the first byte are 7, it's an |
| 53 | * UNCOMPRESSED_TCP packet; that byte is the first byte of |
| 54 | * the UNCOMPRESSED_TCP modified IP header, with a connection |
| 55 | * number in the protocol field, and with the version field |
| 56 | * being 7, not 4. |
| 57 | * |
| 58 | * Otherwise, the packet is an IPv4 packet (where the upper 4 bits |
| 59 | * of the packet are 4). |
| 60 | * |
| 61 | * So this routine looks as if it's sort-of intended to handle |
| 62 | * compressed SLIP, although it doesn't handle UNCOMPRESSED_TCP |
| 63 | * correctly for that (it doesn't fix the version number and doesn't |
| 64 | * do anything to the protocol field), and doesn't check for COMPRESSED_TCP |
| 65 | * packets correctly for that (you only check the first bit - see |
| 66 | * B.1 in RFC 1144). |
| 67 | * |
| 68 | * But it's called for BSD/OS PPP, not SLIP - perhaps BSD/OS does weird |
| 69 | * things with the headers? |
| 70 | * |
| 71 | * Without a BSD/OS VJC-compressed PPP trace, or knowledge of what the |
| 72 | * BSD/OS VJC code does, we can't say what's the case. |
| 73 | * |
| 74 | * We therefore leave "proto" - which is the PPP protocol type - in place, |
| 75 | * *not* marked as unused, for now, so that GCC warnings about the |
| 76 | * unused argument remind us that we should fix this some day. |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 77 | * |
| 78 | * XXX - also, it fetches the TCP checksum field in COMPRESSED_TCP |
| 79 | * packets directly, rather than with EXTRACT_16BITS(); RFC 1144 says |
| 80 | * it's "the unmodified TCP checksum", which would imply that it's |
| 81 | * big-endian, but perhaps, on the platform where this was developed, |
| 82 | * the packets were munged by the networking stack before being handed |
| 83 | * to the packet capture mechanism. |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 84 | */ |
| 85 | int |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 86 | vjc_print(netdissect_options *ndo, register const char *bp, u_short proto _U_) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 87 | { |
| 88 | int i; |
| 89 | |
| 90 | switch (bp[0] & 0xf0) { |
| 91 | case TYPE_IP: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 92 | if (ndo->ndo_eflag) |
| 93 | ND_PRINT((ndo, "(vjc type=IP) ")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 94 | return PPP_IP; |
| 95 | case TYPE_UNCOMPRESSED_TCP: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 96 | if (ndo->ndo_eflag) |
| 97 | ND_PRINT((ndo, "(vjc type=raw TCP) ")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 98 | return PPP_IP; |
| 99 | case TYPE_COMPRESSED_TCP: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 100 | if (ndo->ndo_eflag) |
| 101 | ND_PRINT((ndo, "(vjc type=compressed TCP) ")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 102 | for (i = 0; i < 8; i++) { |
| 103 | if (bp[1] & (0x80 >> i)) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 104 | ND_PRINT((ndo, "%c", "?CI?SAWU"[i])); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 105 | } |
| 106 | if (bp[1]) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 107 | ND_PRINT((ndo, " ")); |
| 108 | ND_PRINT((ndo, "C=0x%02x ", bp[2])); |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 109 | ND_PRINT((ndo, "sum=0x%04x ", *(const u_short *)&bp[3])); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 110 | return -1; |
| 111 | case TYPE_ERROR: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 112 | if (ndo->ndo_eflag) |
| 113 | ND_PRINT((ndo, "(vjc type=error) ")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 114 | return -1; |
| 115 | default: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 116 | if (ndo->ndo_eflag) |
| 117 | ND_PRINT((ndo, "(vjc type=0x%02x) ", bp[0] & 0xf0)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 118 | return -1; |
| 119 | } |
| 120 | } |