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