print-vjc.c 4.4 KB

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