print-enc.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /* $OpenBSD: print-enc.c,v 1.7 2002/02/19 19:39:40 millert Exp $ */
  2. /*
  3. * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996
  4. * The Regents of the University of California. All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that: (1) source code distributions
  8. * retain the above copyright notice and this paragraph in its entirety, (2)
  9. * distributions including binary code include the above copyright notice and
  10. * this paragraph in its entirety in the documentation or other materials
  11. * provided with the distribution, and (3) all advertising materials mentioning
  12. * features or use of this software display the following acknowledgement:
  13. * ``This product includes software developed by the University of California,
  14. * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
  15. * the University nor the names of its contributors may be used to endorse
  16. * or promote products derived from this software without specific prior
  17. * written permission.
  18. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  19. * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  20. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  21. */
  22. /* \summary: OpenBSD IPsec encapsulation BPF layer printer */
  23. #ifdef HAVE_CONFIG_H
  24. #include "config.h"
  25. #endif
  26. #include <netdissect-stdinc.h>
  27. #include "netdissect.h"
  28. #include "extract.h"
  29. /* From $OpenBSD: if_enc.h,v 1.8 2001/06/25 05:14:00 angelos Exp $ */
  30. /*
  31. * The authors of this code are John Ioannidis (ji@tla.org),
  32. * Angelos D. Keromytis (kermit@csd.uch.gr) and
  33. * Niels Provos (provos@physnet.uni-hamburg.de).
  34. *
  35. * This code was written by John Ioannidis for BSD/OS in Athens, Greece,
  36. * in November 1995.
  37. *
  38. * Ported to OpenBSD and NetBSD, with additional transforms, in December 1996,
  39. * by Angelos D. Keromytis.
  40. *
  41. * Additional transforms and features in 1997 and 1998 by Angelos D. Keromytis
  42. * and Niels Provos.
  43. *
  44. * Copyright (C) 1995, 1996, 1997, 1998 by John Ioannidis, Angelos D. Keromytis
  45. * and Niels Provos.
  46. * Copyright (c) 2001, Angelos D. Keromytis.
  47. *
  48. * Permission to use, copy, and modify this software with or without fee
  49. * is hereby granted, provided that this entire notice is included in
  50. * all copies of any software which is or includes a copy or
  51. * modification of this software.
  52. * You may use this code under the GNU public license if you so wish. Please
  53. * contribute changes back to the authors under this freer than GPL license
  54. * so that we may further the use of strong encryption without limitations to
  55. * all.
  56. *
  57. * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR
  58. * IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY
  59. * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE
  60. * MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR
  61. * PURPOSE.
  62. */
  63. #define ENC_HDRLEN 12
  64. /* From $OpenBSD: mbuf.h,v 1.56 2002/01/25 15:50:23 art Exp $ */
  65. #define M_CONF 0x0400 /* packet was encrypted (ESP-transport) */
  66. #define M_AUTH 0x0800 /* packet was authenticated (AH) */
  67. struct enchdr {
  68. uint32_t af;
  69. uint32_t spi;
  70. uint32_t flags;
  71. };
  72. #define ENC_PRINT_TYPE(wh, xf, nam) \
  73. if ((wh) & (xf)) { \
  74. ND_PRINT((ndo, "%s%s", nam, (wh) == (xf) ? "): " : ",")); \
  75. (wh) &= ~(xf); \
  76. }
  77. u_int
  78. enc_if_print(netdissect_options *ndo,
  79. const struct pcap_pkthdr *h, register const u_char *p)
  80. {
  81. register u_int length = h->len;
  82. register u_int caplen = h->caplen;
  83. int flags;
  84. const struct enchdr *hdr;
  85. if (caplen < ENC_HDRLEN) {
  86. ND_PRINT((ndo, "[|enc]"));
  87. goto out;
  88. }
  89. hdr = (const struct enchdr *)p;
  90. flags = hdr->flags;
  91. if (flags == 0)
  92. ND_PRINT((ndo, "(unprotected): "));
  93. else
  94. ND_PRINT((ndo, "("));
  95. ENC_PRINT_TYPE(flags, M_AUTH, "authentic");
  96. ENC_PRINT_TYPE(flags, M_CONF, "confidential");
  97. /* ENC_PRINT_TYPE(flags, M_TUNNEL, "tunnel"); */
  98. ND_PRINT((ndo, "SPI 0x%08x: ", EXTRACT_32BITS(&hdr->spi)));
  99. length -= ENC_HDRLEN;
  100. caplen -= ENC_HDRLEN;
  101. p += ENC_HDRLEN;
  102. switch (hdr->af) {
  103. case AF_INET:
  104. ip_print(ndo, p, length);
  105. break;
  106. #ifdef AF_INET6
  107. case AF_INET6:
  108. ip6_print(ndo, p, length);
  109. break;
  110. #endif
  111. }
  112. out:
  113. return (ENC_HDRLEN);
  114. }
  115. /*
  116. * Local Variables:
  117. * c-style: whitesmith
  118. * c-basic-offset: 8
  119. * End:
  120. */